Remove a weird static helper from the GEP instruction and just directly
[oota-llvm.git] / include / llvm / Instructions.h
1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class.  This is meant to be an easy way to get access to all
12 // instruction subclasses.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_INSTRUCTIONS_H
17 #define LLVM_INSTRUCTIONS_H
18
19 #include "llvm/InstrTypes.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Attributes.h"
22 #include "llvm/CallingConv.h"
23 #include "llvm/Support/IntegersSubset.h"
24 #include "llvm/Support/IntegersSubsetMapping.h"
25 #include "llvm/ADT/ArrayRef.h"
26 #include "llvm/ADT/SmallVector.h"
27 #include "llvm/Support/ErrorHandling.h"
28 #include <iterator>
29
30 namespace llvm {
31
32 class ConstantInt;
33 class ConstantRange;
34 class APInt;
35 class LLVMContext;
36
37 enum AtomicOrdering {
38   NotAtomic = 0,
39   Unordered = 1,
40   Monotonic = 2,
41   // Consume = 3,  // Not specified yet.
42   Acquire = 4,
43   Release = 5,
44   AcquireRelease = 6,
45   SequentiallyConsistent = 7
46 };
47
48 enum SynchronizationScope {
49   SingleThread = 0,
50   CrossThread = 1
51 };
52
53 //===----------------------------------------------------------------------===//
54 //                                AllocaInst Class
55 //===----------------------------------------------------------------------===//
56
57 /// AllocaInst - an instruction to allocate memory on the stack
58 ///
59 class AllocaInst : public UnaryInstruction {
60 protected:
61   virtual AllocaInst *clone_impl() const;
62 public:
63   explicit AllocaInst(Type *Ty, Value *ArraySize = 0,
64                       const Twine &Name = "", Instruction *InsertBefore = 0);
65   AllocaInst(Type *Ty, Value *ArraySize,
66              const Twine &Name, BasicBlock *InsertAtEnd);
67
68   AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
69   AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
70
71   AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
72              const Twine &Name = "", Instruction *InsertBefore = 0);
73   AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
74              const Twine &Name, BasicBlock *InsertAtEnd);
75
76   // Out of line virtual method, so the vtable, etc. has a home.
77   virtual ~AllocaInst();
78
79   /// isArrayAllocation - Return true if there is an allocation size parameter
80   /// to the allocation instruction that is not 1.
81   ///
82   bool isArrayAllocation() const;
83
84   /// getArraySize - Get the number of elements allocated. For a simple
85   /// allocation of a single element, this will return a constant 1 value.
86   ///
87   const Value *getArraySize() const { return getOperand(0); }
88   Value *getArraySize() { return getOperand(0); }
89
90   /// getType - Overload to return most specific pointer type
91   ///
92   PointerType *getType() const {
93     return reinterpret_cast<PointerType*>(Instruction::getType());
94   }
95
96   /// getAllocatedType - Return the type that is being allocated by the
97   /// instruction.
98   ///
99   Type *getAllocatedType() const;
100
101   /// getAlignment - Return the alignment of the memory that is being allocated
102   /// by the instruction.
103   ///
104   unsigned getAlignment() const {
105     return (1u << getSubclassDataFromInstruction()) >> 1;
106   }
107   void setAlignment(unsigned Align);
108
109   /// isStaticAlloca - Return true if this alloca is in the entry block of the
110   /// function and is a constant size.  If so, the code generator will fold it
111   /// into the prolog/epilog code, so it is basically free.
112   bool isStaticAlloca() const;
113
114   // Methods for support type inquiry through isa, cast, and dyn_cast:
115   static inline bool classof(const Instruction *I) {
116     return (I->getOpcode() == Instruction::Alloca);
117   }
118   static inline bool classof(const Value *V) {
119     return isa<Instruction>(V) && classof(cast<Instruction>(V));
120   }
121 private:
122   // Shadow Instruction::setInstructionSubclassData with a private forwarding
123   // method so that subclasses cannot accidentally use it.
124   void setInstructionSubclassData(unsigned short D) {
125     Instruction::setInstructionSubclassData(D);
126   }
127 };
128
129
130 //===----------------------------------------------------------------------===//
131 //                                LoadInst Class
132 //===----------------------------------------------------------------------===//
133
134 /// LoadInst - an instruction for reading from memory.  This uses the
135 /// SubclassData field in Value to store whether or not the load is volatile.
136 ///
137 class LoadInst : public UnaryInstruction {
138   void AssertOK();
139 protected:
140   virtual LoadInst *clone_impl() const;
141 public:
142   LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
143   LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
144   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
145            Instruction *InsertBefore = 0);
146   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
147            BasicBlock *InsertAtEnd);
148   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
149            unsigned Align, Instruction *InsertBefore = 0);
150   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
151            unsigned Align, BasicBlock *InsertAtEnd);
152   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
153            unsigned Align, AtomicOrdering Order,
154            SynchronizationScope SynchScope = CrossThread,
155            Instruction *InsertBefore = 0);
156   LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
157            unsigned Align, AtomicOrdering Order,
158            SynchronizationScope SynchScope,
159            BasicBlock *InsertAtEnd);
160
161   LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
162   LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
163   explicit LoadInst(Value *Ptr, const char *NameStr = 0,
164                     bool isVolatile = false,  Instruction *InsertBefore = 0);
165   LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
166            BasicBlock *InsertAtEnd);
167
168   /// isVolatile - Return true if this is a load from a volatile memory
169   /// location.
170   ///
171   bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
172
173   /// setVolatile - Specify whether this is a volatile load or not.
174   ///
175   void setVolatile(bool V) {
176     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
177                                (V ? 1 : 0));
178   }
179
180   /// getAlignment - Return the alignment of the access that is being performed
181   ///
182   unsigned getAlignment() const {
183     return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
184   }
185
186   void setAlignment(unsigned Align);
187
188   /// Returns the ordering effect of this fence.
189   AtomicOrdering getOrdering() const {
190     return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
191   }
192
193   /// Set the ordering constraint on this load. May not be Release or
194   /// AcquireRelease.
195   void setOrdering(AtomicOrdering Ordering) {
196     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
197                                (Ordering << 7));
198   }
199
200   SynchronizationScope getSynchScope() const {
201     return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
202   }
203
204   /// Specify whether this load is ordered with respect to all
205   /// concurrently executing threads, or only with respect to signal handlers
206   /// executing in the same thread.
207   void setSynchScope(SynchronizationScope xthread) {
208     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
209                                (xthread << 6));
210   }
211
212   bool isAtomic() const { return getOrdering() != NotAtomic; }
213   void setAtomic(AtomicOrdering Ordering,
214                  SynchronizationScope SynchScope = CrossThread) {
215     setOrdering(Ordering);
216     setSynchScope(SynchScope);
217   }
218
219   bool isSimple() const { return !isAtomic() && !isVolatile(); }
220   bool isUnordered() const {
221     return getOrdering() <= Unordered && !isVolatile();
222   }
223
224   Value *getPointerOperand() { return getOperand(0); }
225   const Value *getPointerOperand() const { return getOperand(0); }
226   static unsigned getPointerOperandIndex() { return 0U; }
227
228   unsigned getPointerAddressSpace() const {
229     return getPointerOperand()->getType()->getPointerAddressSpace();
230   }
231
232
233   // Methods for support type inquiry through isa, cast, and dyn_cast:
234   static inline bool classof(const Instruction *I) {
235     return I->getOpcode() == Instruction::Load;
236   }
237   static inline bool classof(const Value *V) {
238     return isa<Instruction>(V) && classof(cast<Instruction>(V));
239   }
240 private:
241   // Shadow Instruction::setInstructionSubclassData with a private forwarding
242   // method so that subclasses cannot accidentally use it.
243   void setInstructionSubclassData(unsigned short D) {
244     Instruction::setInstructionSubclassData(D);
245   }
246 };
247
248
249 //===----------------------------------------------------------------------===//
250 //                                StoreInst Class
251 //===----------------------------------------------------------------------===//
252
253 /// StoreInst - an instruction for storing to memory
254 ///
255 class StoreInst : public Instruction {
256   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
257   void AssertOK();
258 protected:
259   virtual StoreInst *clone_impl() const;
260 public:
261   // allocate space for exactly two operands
262   void *operator new(size_t s) {
263     return User::operator new(s, 2);
264   }
265   StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
266   StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
267   StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
268             Instruction *InsertBefore = 0);
269   StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
270   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
271             unsigned Align, Instruction *InsertBefore = 0);
272   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
273             unsigned Align, BasicBlock *InsertAtEnd);
274   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
275             unsigned Align, AtomicOrdering Order,
276             SynchronizationScope SynchScope = CrossThread,
277             Instruction *InsertBefore = 0);
278   StoreInst(Value *Val, Value *Ptr, bool isVolatile,
279             unsigned Align, AtomicOrdering Order,
280             SynchronizationScope SynchScope,
281             BasicBlock *InsertAtEnd);
282           
283
284   /// isVolatile - Return true if this is a store to a volatile memory
285   /// location.
286   ///
287   bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
288
289   /// setVolatile - Specify whether this is a volatile store or not.
290   ///
291   void setVolatile(bool V) {
292     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
293                                (V ? 1 : 0));
294   }
295
296   /// Transparently provide more efficient getOperand methods.
297   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
298
299   /// getAlignment - Return the alignment of the access that is being performed
300   ///
301   unsigned getAlignment() const {
302     return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
303   }
304
305   void setAlignment(unsigned Align);
306
307   /// Returns the ordering effect of this store.
308   AtomicOrdering getOrdering() const {
309     return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
310   }
311
312   /// Set the ordering constraint on this store.  May not be Acquire or
313   /// AcquireRelease.
314   void setOrdering(AtomicOrdering Ordering) {
315     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
316                                (Ordering << 7));
317   }
318
319   SynchronizationScope getSynchScope() const {
320     return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
321   }
322
323   /// Specify whether this store instruction is ordered with respect to all
324   /// concurrently executing threads, or only with respect to signal handlers
325   /// executing in the same thread.
326   void setSynchScope(SynchronizationScope xthread) {
327     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
328                                (xthread << 6));
329   }
330
331   bool isAtomic() const { return getOrdering() != NotAtomic; }
332   void setAtomic(AtomicOrdering Ordering,
333                  SynchronizationScope SynchScope = CrossThread) {
334     setOrdering(Ordering);
335     setSynchScope(SynchScope);
336   }
337
338   bool isSimple() const { return !isAtomic() && !isVolatile(); }
339   bool isUnordered() const {
340     return getOrdering() <= Unordered && !isVolatile();
341   }
342
343   Value *getValueOperand() { return getOperand(0); }
344   const Value *getValueOperand() const { return getOperand(0); }
345
346   Value *getPointerOperand() { return getOperand(1); }
347   const Value *getPointerOperand() const { return getOperand(1); }
348   static unsigned getPointerOperandIndex() { return 1U; }
349
350   unsigned getPointerAddressSpace() const {
351     return getPointerOperand()->getType()->getPointerAddressSpace();
352   }
353
354   // Methods for support type inquiry through isa, cast, and dyn_cast:
355   static inline bool classof(const Instruction *I) {
356     return I->getOpcode() == Instruction::Store;
357   }
358   static inline bool classof(const Value *V) {
359     return isa<Instruction>(V) && classof(cast<Instruction>(V));
360   }
361 private:
362   // Shadow Instruction::setInstructionSubclassData with a private forwarding
363   // method so that subclasses cannot accidentally use it.
364   void setInstructionSubclassData(unsigned short D) {
365     Instruction::setInstructionSubclassData(D);
366   }
367 };
368
369 template <>
370 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
371 };
372
373 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
374
375 //===----------------------------------------------------------------------===//
376 //                                FenceInst Class
377 //===----------------------------------------------------------------------===//
378
379 /// FenceInst - an instruction for ordering other memory operations
380 ///
381 class FenceInst : public Instruction {
382   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
383   void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
384 protected:
385   virtual FenceInst *clone_impl() const;
386 public:
387   // allocate space for exactly zero operands
388   void *operator new(size_t s) {
389     return User::operator new(s, 0);
390   }
391
392   // Ordering may only be Acquire, Release, AcquireRelease, or
393   // SequentiallyConsistent.
394   FenceInst(LLVMContext &C, AtomicOrdering Ordering,
395             SynchronizationScope SynchScope = CrossThread,
396             Instruction *InsertBefore = 0);
397   FenceInst(LLVMContext &C, AtomicOrdering Ordering,
398             SynchronizationScope SynchScope,
399             BasicBlock *InsertAtEnd);
400
401   /// Returns the ordering effect of this fence.
402   AtomicOrdering getOrdering() const {
403     return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
404   }
405
406   /// Set the ordering constraint on this fence.  May only be Acquire, Release,
407   /// AcquireRelease, or SequentiallyConsistent.
408   void setOrdering(AtomicOrdering Ordering) {
409     setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
410                                (Ordering << 1));
411   }
412
413   SynchronizationScope getSynchScope() const {
414     return SynchronizationScope(getSubclassDataFromInstruction() & 1);
415   }
416
417   /// Specify whether this fence orders other operations with respect to all
418   /// concurrently executing threads, or only with respect to signal handlers
419   /// executing in the same thread.
420   void setSynchScope(SynchronizationScope xthread) {
421     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
422                                xthread);
423   }
424
425   // Methods for support type inquiry through isa, cast, and dyn_cast:
426   static inline bool classof(const Instruction *I) {
427     return I->getOpcode() == Instruction::Fence;
428   }
429   static inline bool classof(const Value *V) {
430     return isa<Instruction>(V) && classof(cast<Instruction>(V));
431   }
432 private:
433   // Shadow Instruction::setInstructionSubclassData with a private forwarding
434   // method so that subclasses cannot accidentally use it.
435   void setInstructionSubclassData(unsigned short D) {
436     Instruction::setInstructionSubclassData(D);
437   }
438 };
439
440 //===----------------------------------------------------------------------===//
441 //                                AtomicCmpXchgInst Class
442 //===----------------------------------------------------------------------===//
443
444 /// AtomicCmpXchgInst - an instruction that atomically checks whether a
445 /// specified value is in a memory location, and, if it is, stores a new value
446 /// there.  Returns the value that was loaded.
447 ///
448 class AtomicCmpXchgInst : public Instruction {
449   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
450   void Init(Value *Ptr, Value *Cmp, Value *NewVal,
451             AtomicOrdering Ordering, SynchronizationScope SynchScope);
452 protected:
453   virtual AtomicCmpXchgInst *clone_impl() const;
454 public:
455   // allocate space for exactly three operands
456   void *operator new(size_t s) {
457     return User::operator new(s, 3);
458   }
459   AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
460                     AtomicOrdering Ordering, SynchronizationScope SynchScope,
461                     Instruction *InsertBefore = 0);
462   AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
463                     AtomicOrdering Ordering, SynchronizationScope SynchScope,
464                     BasicBlock *InsertAtEnd);
465
466   /// isVolatile - Return true if this is a cmpxchg from a volatile memory
467   /// location.
468   ///
469   bool isVolatile() const {
470     return getSubclassDataFromInstruction() & 1;
471   }
472
473   /// setVolatile - Specify whether this is a volatile cmpxchg.
474   ///
475   void setVolatile(bool V) {
476      setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
477                                 (unsigned)V);
478   }
479
480   /// Transparently provide more efficient getOperand methods.
481   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
482
483   /// Set the ordering constraint on this cmpxchg.
484   void setOrdering(AtomicOrdering Ordering) {
485     assert(Ordering != NotAtomic &&
486            "CmpXchg instructions can only be atomic.");
487     setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
488                                (Ordering << 2));
489   }
490
491   /// Specify whether this cmpxchg is atomic and orders other operations with
492   /// respect to all concurrently executing threads, or only with respect to
493   /// signal handlers executing in the same thread.
494   void setSynchScope(SynchronizationScope SynchScope) {
495     setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
496                                (SynchScope << 1));
497   }
498
499   /// Returns the ordering constraint on this cmpxchg.
500   AtomicOrdering getOrdering() const {
501     return AtomicOrdering(getSubclassDataFromInstruction() >> 2);
502   }
503
504   /// Returns whether this cmpxchg is atomic between threads or only within a
505   /// single thread.
506   SynchronizationScope getSynchScope() const {
507     return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
508   }
509
510   Value *getPointerOperand() { return getOperand(0); }
511   const Value *getPointerOperand() const { return getOperand(0); }
512   static unsigned getPointerOperandIndex() { return 0U; }
513
514   Value *getCompareOperand() { return getOperand(1); }
515   const Value *getCompareOperand() const { return getOperand(1); }
516   
517   Value *getNewValOperand() { return getOperand(2); }
518   const Value *getNewValOperand() const { return getOperand(2); }
519   
520   unsigned getPointerAddressSpace() const {
521     return getPointerOperand()->getType()->getPointerAddressSpace();
522   }
523   
524   // Methods for support type inquiry through isa, cast, and dyn_cast:
525   static inline bool classof(const Instruction *I) {
526     return I->getOpcode() == Instruction::AtomicCmpXchg;
527   }
528   static inline bool classof(const Value *V) {
529     return isa<Instruction>(V) && classof(cast<Instruction>(V));
530   }
531 private:
532   // Shadow Instruction::setInstructionSubclassData with a private forwarding
533   // method so that subclasses cannot accidentally use it.
534   void setInstructionSubclassData(unsigned short D) {
535     Instruction::setInstructionSubclassData(D);
536   }
537 };
538
539 template <>
540 struct OperandTraits<AtomicCmpXchgInst> :
541     public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
542 };
543
544 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
545
546 //===----------------------------------------------------------------------===//
547 //                                AtomicRMWInst Class
548 //===----------------------------------------------------------------------===//
549
550 /// AtomicRMWInst - an instruction that atomically reads a memory location,
551 /// combines it with another value, and then stores the result back.  Returns
552 /// the old value.
553 ///
554 class AtomicRMWInst : public Instruction {
555   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
556 protected:
557   virtual AtomicRMWInst *clone_impl() const;
558 public:
559   /// This enumeration lists the possible modifications atomicrmw can make.  In
560   /// the descriptions, 'p' is the pointer to the instruction's memory location,
561   /// 'old' is the initial value of *p, and 'v' is the other value passed to the
562   /// instruction.  These instructions always return 'old'.
563   enum BinOp {
564     /// *p = v
565     Xchg,
566     /// *p = old + v
567     Add,
568     /// *p = old - v
569     Sub,
570     /// *p = old & v
571     And,
572     /// *p = ~old & v
573     Nand,
574     /// *p = old | v
575     Or,
576     /// *p = old ^ v
577     Xor,
578     /// *p = old >signed v ? old : v
579     Max,
580     /// *p = old <signed v ? old : v
581     Min,
582     /// *p = old >unsigned v ? old : v
583     UMax,
584     /// *p = old <unsigned v ? old : v
585     UMin,
586
587     FIRST_BINOP = Xchg,
588     LAST_BINOP = UMin,
589     BAD_BINOP
590   };
591
592   // allocate space for exactly two operands
593   void *operator new(size_t s) {
594     return User::operator new(s, 2);
595   }
596   AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
597                 AtomicOrdering Ordering, SynchronizationScope SynchScope,
598                 Instruction *InsertBefore = 0);
599   AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
600                 AtomicOrdering Ordering, SynchronizationScope SynchScope,
601                 BasicBlock *InsertAtEnd);
602
603   BinOp getOperation() const {
604     return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
605   }
606
607   void setOperation(BinOp Operation) {
608     unsigned short SubclassData = getSubclassDataFromInstruction();
609     setInstructionSubclassData((SubclassData & 31) |
610                                (Operation << 5));
611   }
612
613   /// isVolatile - Return true if this is a RMW on a volatile memory location.
614   ///
615   bool isVolatile() const {
616     return getSubclassDataFromInstruction() & 1;
617   }
618
619   /// setVolatile - Specify whether this is a volatile RMW or not.
620   ///
621   void setVolatile(bool V) {
622      setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
623                                 (unsigned)V);
624   }
625
626   /// Transparently provide more efficient getOperand methods.
627   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
628
629   /// Set the ordering constraint on this RMW.
630   void setOrdering(AtomicOrdering Ordering) {
631     assert(Ordering != NotAtomic &&
632            "atomicrmw instructions can only be atomic.");
633     setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
634                                (Ordering << 2));
635   }
636
637   /// Specify whether this RMW orders other operations with respect to all
638   /// concurrently executing threads, or only with respect to signal handlers
639   /// executing in the same thread.
640   void setSynchScope(SynchronizationScope SynchScope) {
641     setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
642                                (SynchScope << 1));
643   }
644
645   /// Returns the ordering constraint on this RMW.
646   AtomicOrdering getOrdering() const {
647     return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
648   }
649
650   /// Returns whether this RMW is atomic between threads or only within a
651   /// single thread.
652   SynchronizationScope getSynchScope() const {
653     return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
654   }
655
656   Value *getPointerOperand() { return getOperand(0); }
657   const Value *getPointerOperand() const { return getOperand(0); }
658   static unsigned getPointerOperandIndex() { return 0U; }
659
660   Value *getValOperand() { return getOperand(1); }
661   const Value *getValOperand() const { return getOperand(1); }
662
663   unsigned getPointerAddressSpace() const {
664     return getPointerOperand()->getType()->getPointerAddressSpace();
665   }
666
667   // Methods for support type inquiry through isa, cast, and dyn_cast:
668   static inline bool classof(const Instruction *I) {
669     return I->getOpcode() == Instruction::AtomicRMW;
670   }
671   static inline bool classof(const Value *V) {
672     return isa<Instruction>(V) && classof(cast<Instruction>(V));
673   }
674 private:
675   void Init(BinOp Operation, Value *Ptr, Value *Val,
676             AtomicOrdering Ordering, SynchronizationScope SynchScope);
677   // Shadow Instruction::setInstructionSubclassData with a private forwarding
678   // method so that subclasses cannot accidentally use it.
679   void setInstructionSubclassData(unsigned short D) {
680     Instruction::setInstructionSubclassData(D);
681   }
682 };
683
684 template <>
685 struct OperandTraits<AtomicRMWInst>
686     : public FixedNumOperandTraits<AtomicRMWInst,2> {
687 };
688
689 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
690
691 //===----------------------------------------------------------------------===//
692 //                             GetElementPtrInst Class
693 //===----------------------------------------------------------------------===//
694
695 // checkGEPType - Simple wrapper function to give a better assertion failure
696 // message on bad indexes for a gep instruction.
697 //
698 inline Type *checkGEPType(Type *Ty) {
699   assert(Ty && "Invalid GetElementPtrInst indices for type!");
700   return Ty;
701 }
702
703 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
704 /// access elements of arrays and structs
705 ///
706 class GetElementPtrInst : public Instruction {
707   GetElementPtrInst(const GetElementPtrInst &GEPI);
708   void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
709
710   /// Constructors - Create a getelementptr instruction with a base pointer an
711   /// list of indices. The first ctor can optionally insert before an existing
712   /// instruction, the second appends the new instruction to the specified
713   /// BasicBlock.
714   inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
715                            unsigned Values, const Twine &NameStr,
716                            Instruction *InsertBefore);
717   inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
718                            unsigned Values, const Twine &NameStr,
719                            BasicBlock *InsertAtEnd);
720 protected:
721   virtual GetElementPtrInst *clone_impl() const;
722 public:
723   static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
724                                    const Twine &NameStr = "",
725                                    Instruction *InsertBefore = 0) {
726     unsigned Values = 1 + unsigned(IdxList.size());
727     return new(Values)
728       GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
729   }
730   static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
731                                    const Twine &NameStr,
732                                    BasicBlock *InsertAtEnd) {
733     unsigned Values = 1 + unsigned(IdxList.size());
734     return new(Values)
735       GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
736   }
737
738   /// Create an "inbounds" getelementptr. See the documentation for the
739   /// "inbounds" flag in LangRef.html for details.
740   static GetElementPtrInst *CreateInBounds(Value *Ptr,
741                                            ArrayRef<Value *> IdxList,
742                                            const Twine &NameStr = "",
743                                            Instruction *InsertBefore = 0) {
744     GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
745     GEP->setIsInBounds(true);
746     return GEP;
747   }
748   static GetElementPtrInst *CreateInBounds(Value *Ptr,
749                                            ArrayRef<Value *> IdxList,
750                                            const Twine &NameStr,
751                                            BasicBlock *InsertAtEnd) {
752     GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
753     GEP->setIsInBounds(true);
754     return GEP;
755   }
756
757   /// Transparently provide more efficient getOperand methods.
758   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
759
760   // getType - Overload to return most specific pointer type...
761   PointerType *getType() const {
762     return reinterpret_cast<PointerType*>(Instruction::getType());
763   }
764
765   /// getIndexedType - Returns the type of the element that would be loaded with
766   /// a load instruction with the specified parameters.
767   ///
768   /// Null is returned if the indices are invalid for the specified
769   /// pointer type.
770   ///
771   static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
772   static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
773   static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
774
775   inline op_iterator       idx_begin()       { return op_begin()+1; }
776   inline const_op_iterator idx_begin() const { return op_begin()+1; }
777   inline op_iterator       idx_end()         { return op_end(); }
778   inline const_op_iterator idx_end()   const { return op_end(); }
779
780   Value *getPointerOperand() {
781     return getOperand(0);
782   }
783   const Value *getPointerOperand() const {
784     return getOperand(0);
785   }
786   static unsigned getPointerOperandIndex() {
787     return 0U;    // get index for modifying correct operand.
788   }
789
790   /// getPointerOperandType - Method to return the pointer operand as a
791   /// PointerType.
792   Type *getPointerOperandType() const {
793     return getPointerOperand()->getType();
794   }
795
796   unsigned getPointerAddressSpace() const {
797     return getPointerOperandType()->getPointerAddressSpace();
798   }
799
800   /// GetGEPReturnType - Returns the pointer type returned by the GEP
801   /// instruction, which may be a vector of pointers.
802   static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
803     Type *PtrTy = PointerType::get(checkGEPType(
804                                    getIndexedType(Ptr->getType(), IdxList)),
805                                    Ptr->getType()->getPointerAddressSpace());
806     // Vector GEP
807     if (Ptr->getType()->isVectorTy()) {
808       unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements();
809       return VectorType::get(PtrTy, NumElem);
810     }
811
812     // Scalar GEP
813     return PtrTy;
814   }
815
816   unsigned getNumIndices() const {  // Note: always non-negative
817     return getNumOperands() - 1;
818   }
819
820   bool hasIndices() const {
821     return getNumOperands() > 1;
822   }
823
824   /// hasAllZeroIndices - Return true if all of the indices of this GEP are
825   /// zeros.  If so, the result pointer and the first operand have the same
826   /// value, just potentially different types.
827   bool hasAllZeroIndices() const;
828
829   /// hasAllConstantIndices - Return true if all of the indices of this GEP are
830   /// constant integers.  If so, the result pointer and the first operand have
831   /// a constant offset between them.
832   bool hasAllConstantIndices() const;
833
834   /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
835   /// See LangRef.html for the meaning of inbounds on a getelementptr.
836   void setIsInBounds(bool b = true);
837
838   /// isInBounds - Determine whether the GEP has the inbounds flag.
839   bool isInBounds() const;
840
841   // Methods for support type inquiry through isa, cast, and dyn_cast:
842   static inline bool classof(const Instruction *I) {
843     return (I->getOpcode() == Instruction::GetElementPtr);
844   }
845   static inline bool classof(const Value *V) {
846     return isa<Instruction>(V) && classof(cast<Instruction>(V));
847   }
848 };
849
850 template <>
851 struct OperandTraits<GetElementPtrInst> :
852   public VariadicOperandTraits<GetElementPtrInst, 1> {
853 };
854
855 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
856                                      ArrayRef<Value *> IdxList,
857                                      unsigned Values,
858                                      const Twine &NameStr,
859                                      Instruction *InsertBefore)
860   : Instruction(getGEPReturnType(Ptr, IdxList),
861                 GetElementPtr,
862                 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
863                 Values, InsertBefore) {
864   init(Ptr, IdxList, NameStr);
865 }
866 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
867                                      ArrayRef<Value *> IdxList,
868                                      unsigned Values,
869                                      const Twine &NameStr,
870                                      BasicBlock *InsertAtEnd)
871   : Instruction(getGEPReturnType(Ptr, IdxList),
872                 GetElementPtr,
873                 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
874                 Values, InsertAtEnd) {
875   init(Ptr, IdxList, NameStr);
876 }
877
878
879 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
880
881
882 //===----------------------------------------------------------------------===//
883 //                               ICmpInst Class
884 //===----------------------------------------------------------------------===//
885
886 /// This instruction compares its operands according to the predicate given
887 /// to the constructor. It only operates on integers or pointers. The operands
888 /// must be identical types.
889 /// \brief Represent an integer comparison operator.
890 class ICmpInst: public CmpInst {
891 protected:
892   /// \brief Clone an identical ICmpInst
893   virtual ICmpInst *clone_impl() const;
894 public:
895   /// \brief Constructor with insert-before-instruction semantics.
896   ICmpInst(
897     Instruction *InsertBefore,  ///< Where to insert
898     Predicate pred,  ///< The predicate to use for the comparison
899     Value *LHS,      ///< The left-hand-side of the expression
900     Value *RHS,      ///< The right-hand-side of the expression
901     const Twine &NameStr = ""  ///< Name of the instruction
902   ) : CmpInst(makeCmpResultType(LHS->getType()),
903               Instruction::ICmp, pred, LHS, RHS, NameStr,
904               InsertBefore) {
905     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
906            pred <= CmpInst::LAST_ICMP_PREDICATE &&
907            "Invalid ICmp predicate value");
908     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
909           "Both operands to ICmp instruction are not of the same type!");
910     // Check that the operands are the right type
911     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
912             getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
913            "Invalid operand types for ICmp instruction");
914   }
915
916   /// \brief Constructor with insert-at-end semantics.
917   ICmpInst(
918     BasicBlock &InsertAtEnd, ///< Block to insert into.
919     Predicate pred,  ///< The predicate to use for the comparison
920     Value *LHS,      ///< The left-hand-side of the expression
921     Value *RHS,      ///< The right-hand-side of the expression
922     const Twine &NameStr = ""  ///< Name of the instruction
923   ) : CmpInst(makeCmpResultType(LHS->getType()),
924               Instruction::ICmp, pred, LHS, RHS, NameStr,
925               &InsertAtEnd) {
926     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
927           pred <= CmpInst::LAST_ICMP_PREDICATE &&
928           "Invalid ICmp predicate value");
929     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
930           "Both operands to ICmp instruction are not of the same type!");
931     // Check that the operands are the right type
932     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
933             getOperand(0)->getType()->isPointerTy()) &&
934            "Invalid operand types for ICmp instruction");
935   }
936
937   /// \brief Constructor with no-insertion semantics
938   ICmpInst(
939     Predicate pred, ///< The predicate to use for the comparison
940     Value *LHS,     ///< The left-hand-side of the expression
941     Value *RHS,     ///< The right-hand-side of the expression
942     const Twine &NameStr = "" ///< Name of the instruction
943   ) : CmpInst(makeCmpResultType(LHS->getType()),
944               Instruction::ICmp, pred, LHS, RHS, NameStr) {
945     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
946            pred <= CmpInst::LAST_ICMP_PREDICATE &&
947            "Invalid ICmp predicate value");
948     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
949           "Both operands to ICmp instruction are not of the same type!");
950     // Check that the operands are the right type
951     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
952             getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
953            "Invalid operand types for ICmp instruction");
954   }
955
956   /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
957   /// @returns the predicate that would be the result if the operand were
958   /// regarded as signed.
959   /// \brief Return the signed version of the predicate
960   Predicate getSignedPredicate() const {
961     return getSignedPredicate(getPredicate());
962   }
963
964   /// This is a static version that you can use without an instruction.
965   /// \brief Return the signed version of the predicate.
966   static Predicate getSignedPredicate(Predicate pred);
967
968   /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
969   /// @returns the predicate that would be the result if the operand were
970   /// regarded as unsigned.
971   /// \brief Return the unsigned version of the predicate
972   Predicate getUnsignedPredicate() const {
973     return getUnsignedPredicate(getPredicate());
974   }
975
976   /// This is a static version that you can use without an instruction.
977   /// \brief Return the unsigned version of the predicate.
978   static Predicate getUnsignedPredicate(Predicate pred);
979
980   /// isEquality - Return true if this predicate is either EQ or NE.  This also
981   /// tests for commutativity.
982   static bool isEquality(Predicate P) {
983     return P == ICMP_EQ || P == ICMP_NE;
984   }
985
986   /// isEquality - Return true if this predicate is either EQ or NE.  This also
987   /// tests for commutativity.
988   bool isEquality() const {
989     return isEquality(getPredicate());
990   }
991
992   /// @returns true if the predicate of this ICmpInst is commutative
993   /// \brief Determine if this relation is commutative.
994   bool isCommutative() const { return isEquality(); }
995
996   /// isRelational - Return true if the predicate is relational (not EQ or NE).
997   ///
998   bool isRelational() const {
999     return !isEquality();
1000   }
1001
1002   /// isRelational - Return true if the predicate is relational (not EQ or NE).
1003   ///
1004   static bool isRelational(Predicate P) {
1005     return !isEquality(P);
1006   }
1007
1008   /// Initialize a set of values that all satisfy the predicate with C.
1009   /// \brief Make a ConstantRange for a relation with a constant value.
1010   static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
1011
1012   /// Exchange the two operands to this instruction in such a way that it does
1013   /// not modify the semantics of the instruction. The predicate value may be
1014   /// changed to retain the same result if the predicate is order dependent
1015   /// (e.g. ult).
1016   /// \brief Swap operands and adjust predicate.
1017   void swapOperands() {
1018     setPredicate(getSwappedPredicate());
1019     Op<0>().swap(Op<1>());
1020   }
1021
1022   // Methods for support type inquiry through isa, cast, and dyn_cast:
1023   static inline bool classof(const Instruction *I) {
1024     return I->getOpcode() == Instruction::ICmp;
1025   }
1026   static inline bool classof(const Value *V) {
1027     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1028   }
1029
1030 };
1031
1032 //===----------------------------------------------------------------------===//
1033 //                               FCmpInst Class
1034 //===----------------------------------------------------------------------===//
1035
1036 /// This instruction compares its operands according to the predicate given
1037 /// to the constructor. It only operates on floating point values or packed
1038 /// vectors of floating point values. The operands must be identical types.
1039 /// \brief Represents a floating point comparison operator.
1040 class FCmpInst: public CmpInst {
1041 protected:
1042   /// \brief Clone an identical FCmpInst
1043   virtual FCmpInst *clone_impl() const;
1044 public:
1045   /// \brief Constructor with insert-before-instruction semantics.
1046   FCmpInst(
1047     Instruction *InsertBefore, ///< Where to insert
1048     Predicate pred,  ///< The predicate to use for the comparison
1049     Value *LHS,      ///< The left-hand-side of the expression
1050     Value *RHS,      ///< The right-hand-side of the expression
1051     const Twine &NameStr = ""  ///< Name of the instruction
1052   ) : CmpInst(makeCmpResultType(LHS->getType()),
1053               Instruction::FCmp, pred, LHS, RHS, NameStr,
1054               InsertBefore) {
1055     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1056            "Invalid FCmp predicate value");
1057     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1058            "Both operands to FCmp instruction are not of the same type!");
1059     // Check that the operands are the right type
1060     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1061            "Invalid operand types for FCmp instruction");
1062   }
1063
1064   /// \brief Constructor with insert-at-end semantics.
1065   FCmpInst(
1066     BasicBlock &InsertAtEnd, ///< Block to insert into.
1067     Predicate pred,  ///< The predicate to use for the comparison
1068     Value *LHS,      ///< The left-hand-side of the expression
1069     Value *RHS,      ///< The right-hand-side of the expression
1070     const Twine &NameStr = ""  ///< Name of the instruction
1071   ) : CmpInst(makeCmpResultType(LHS->getType()),
1072               Instruction::FCmp, pred, LHS, RHS, NameStr,
1073               &InsertAtEnd) {
1074     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1075            "Invalid FCmp predicate value");
1076     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1077            "Both operands to FCmp instruction are not of the same type!");
1078     // Check that the operands are the right type
1079     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1080            "Invalid operand types for FCmp instruction");
1081   }
1082
1083   /// \brief Constructor with no-insertion semantics
1084   FCmpInst(
1085     Predicate pred, ///< The predicate to use for the comparison
1086     Value *LHS,     ///< The left-hand-side of the expression
1087     Value *RHS,     ///< The right-hand-side of the expression
1088     const Twine &NameStr = "" ///< Name of the instruction
1089   ) : CmpInst(makeCmpResultType(LHS->getType()),
1090               Instruction::FCmp, pred, LHS, RHS, NameStr) {
1091     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1092            "Invalid FCmp predicate value");
1093     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1094            "Both operands to FCmp instruction are not of the same type!");
1095     // Check that the operands are the right type
1096     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1097            "Invalid operand types for FCmp instruction");
1098   }
1099
1100   /// @returns true if the predicate of this instruction is EQ or NE.
1101   /// \brief Determine if this is an equality predicate.
1102   bool isEquality() const {
1103     return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
1104            getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
1105   }
1106
1107   /// @returns true if the predicate of this instruction is commutative.
1108   /// \brief Determine if this is a commutative predicate.
1109   bool isCommutative() const {
1110     return isEquality() ||
1111            getPredicate() == FCMP_FALSE ||
1112            getPredicate() == FCMP_TRUE ||
1113            getPredicate() == FCMP_ORD ||
1114            getPredicate() == FCMP_UNO;
1115   }
1116
1117   /// @returns true if the predicate is relational (not EQ or NE).
1118   /// \brief Determine if this a relational predicate.
1119   bool isRelational() const { return !isEquality(); }
1120
1121   /// Exchange the two operands to this instruction in such a way that it does
1122   /// not modify the semantics of the instruction. The predicate value may be
1123   /// changed to retain the same result if the predicate is order dependent
1124   /// (e.g. ult).
1125   /// \brief Swap operands and adjust predicate.
1126   void swapOperands() {
1127     setPredicate(getSwappedPredicate());
1128     Op<0>().swap(Op<1>());
1129   }
1130
1131   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
1132   static inline bool classof(const Instruction *I) {
1133     return I->getOpcode() == Instruction::FCmp;
1134   }
1135   static inline bool classof(const Value *V) {
1136     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1137   }
1138 };
1139
1140 //===----------------------------------------------------------------------===//
1141 /// CallInst - This class represents a function call, abstracting a target
1142 /// machine's calling convention.  This class uses low bit of the SubClassData
1143 /// field to indicate whether or not this is a tail call.  The rest of the bits
1144 /// hold the calling convention of the call.
1145 ///
1146 class CallInst : public Instruction {
1147   AttrListPtr AttributeList; ///< parameter attributes for call
1148   CallInst(const CallInst &CI);
1149   void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
1150   void init(Value *Func, const Twine &NameStr);
1151
1152   /// Construct a CallInst given a range of arguments.
1153   /// \brief Construct a CallInst from a range of arguments
1154   inline CallInst(Value *Func, ArrayRef<Value *> Args,
1155                   const Twine &NameStr, Instruction *InsertBefore);
1156
1157   /// Construct a CallInst given a range of arguments.
1158   /// \brief Construct a CallInst from a range of arguments
1159   inline CallInst(Value *Func, ArrayRef<Value *> Args,
1160                   const Twine &NameStr, BasicBlock *InsertAtEnd);
1161
1162   CallInst(Value *F, Value *Actual, const Twine &NameStr,
1163            Instruction *InsertBefore);
1164   CallInst(Value *F, Value *Actual, const Twine &NameStr,
1165            BasicBlock *InsertAtEnd);
1166   explicit CallInst(Value *F, const Twine &NameStr,
1167                     Instruction *InsertBefore);
1168   CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1169 protected:
1170   virtual CallInst *clone_impl() const;
1171 public:
1172   static CallInst *Create(Value *Func,
1173                           ArrayRef<Value *> Args,
1174                           const Twine &NameStr = "",
1175                           Instruction *InsertBefore = 0) {
1176     return new(unsigned(Args.size() + 1))
1177       CallInst(Func, Args, NameStr, InsertBefore);
1178   }
1179   static CallInst *Create(Value *Func,
1180                           ArrayRef<Value *> Args,
1181                           const Twine &NameStr, BasicBlock *InsertAtEnd) {
1182     return new(unsigned(Args.size() + 1))
1183       CallInst(Func, Args, NameStr, InsertAtEnd);
1184   }
1185   static CallInst *Create(Value *F, const Twine &NameStr = "",
1186                           Instruction *InsertBefore = 0) {
1187     return new(1) CallInst(F, NameStr, InsertBefore);
1188   }
1189   static CallInst *Create(Value *F, const Twine &NameStr,
1190                           BasicBlock *InsertAtEnd) {
1191     return new(1) CallInst(F, NameStr, InsertAtEnd);
1192   }
1193   /// CreateMalloc - Generate the IR for a call to malloc:
1194   /// 1. Compute the malloc call's argument as the specified type's size,
1195   ///    possibly multiplied by the array size if the array size is not
1196   ///    constant 1.
1197   /// 2. Call malloc with that argument.
1198   /// 3. Bitcast the result of the malloc call to the specified type.
1199   static Instruction *CreateMalloc(Instruction *InsertBefore,
1200                                    Type *IntPtrTy, Type *AllocTy,
1201                                    Value *AllocSize, Value *ArraySize = 0,
1202                                    Function* MallocF = 0,
1203                                    const Twine &Name = "");
1204   static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1205                                    Type *IntPtrTy, Type *AllocTy,
1206                                    Value *AllocSize, Value *ArraySize = 0,
1207                                    Function* MallocF = 0,
1208                                    const Twine &Name = "");
1209   /// CreateFree - Generate the IR for a call to the builtin free function.
1210   static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
1211   static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
1212
1213   ~CallInst();
1214
1215   bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
1216   void setTailCall(bool isTC = true) {
1217     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
1218                                unsigned(isTC));
1219   }
1220
1221   /// Provide fast operand accessors
1222   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1223
1224   /// getNumArgOperands - Return the number of call arguments.
1225   ///
1226   unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1227
1228   /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1229   ///
1230   Value *getArgOperand(unsigned i) const { return getOperand(i); }
1231   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1232
1233   /// getCallingConv/setCallingConv - Get or set the calling convention of this
1234   /// function call.
1235   CallingConv::ID getCallingConv() const {
1236     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
1237   }
1238   void setCallingConv(CallingConv::ID CC) {
1239     setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
1240                                (static_cast<unsigned>(CC) << 1));
1241   }
1242
1243   /// getAttributes - Return the parameter attributes for this call.
1244   ///
1245   const AttrListPtr &getAttributes() const { return AttributeList; }
1246
1247   /// setAttributes - Set the parameter attributes for this call.
1248   ///
1249   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
1250
1251   /// addAttribute - adds the attribute to the list of attributes.
1252   void addAttribute(unsigned i, Attributes attr);
1253
1254   /// removeAttribute - removes the attribute from the list of attributes.
1255   void removeAttribute(unsigned i, Attributes attr);
1256
1257   /// \brief Determine whether this call has the given attribute.
1258   bool hasFnAttr(Attributes::AttrVal A) const;
1259
1260   /// \brief Determine whether the call or the callee has the given attributes.
1261   bool paramHasAttr(unsigned i, Attributes::AttrVal A) const;
1262
1263   /// \brief Extract the alignment for a call or parameter (0=unknown).
1264   unsigned getParamAlignment(unsigned i) const {
1265     return AttributeList.getParamAlignment(i);
1266   }
1267
1268   /// \brief Return true if the call should not be inlined.
1269   bool isNoInline() const { return hasFnAttr(Attributes::NoInline); }
1270   void setIsNoInline() {
1271     addAttribute(AttrListPtr::FunctionIndex,
1272                  Attributes::get(getContext(), Attributes::NoInline));
1273   }
1274
1275   /// \brief Return true if the call can return twice
1276   bool canReturnTwice() const {
1277     return hasFnAttr(Attributes::ReturnsTwice);
1278   }
1279   void setCanReturnTwice() {
1280     addAttribute(AttrListPtr::FunctionIndex,
1281                  Attributes::get(getContext(), Attributes::ReturnsTwice));
1282   }
1283
1284   /// \brief Determine if the call does not access memory.
1285   bool doesNotAccessMemory() const {
1286     return hasFnAttr(Attributes::ReadNone);
1287   }
1288   void setDoesNotAccessMemory() {
1289     addAttribute(AttrListPtr::FunctionIndex,
1290                  Attributes::get(getContext(), Attributes::ReadNone));
1291   }
1292
1293   /// \brief Determine if the call does not access or only reads memory.
1294   bool onlyReadsMemory() const {
1295     return doesNotAccessMemory() || hasFnAttr(Attributes::ReadOnly);
1296   }
1297   void setOnlyReadsMemory() {
1298     addAttribute(AttrListPtr::FunctionIndex,
1299                  Attributes::get(getContext(), Attributes::ReadOnly));
1300   }
1301
1302   /// \brief Determine if the call cannot return.
1303   bool doesNotReturn() const { return hasFnAttr(Attributes::NoReturn); }
1304   void setDoesNotReturn() {
1305     addAttribute(AttrListPtr::FunctionIndex,
1306                  Attributes::get(getContext(), Attributes::NoReturn));
1307   }
1308
1309   /// \brief Determine if the call cannot unwind.
1310   bool doesNotThrow() const { return hasFnAttr(Attributes::NoUnwind); }
1311   void setDoesNotThrow() {
1312     addAttribute(AttrListPtr::FunctionIndex,
1313                  Attributes::get(getContext(), Attributes::NoUnwind));
1314   }
1315
1316   /// \brief Determine if the call returns a structure through first
1317   /// pointer argument.
1318   bool hasStructRetAttr() const {
1319     // Be friendly and also check the callee.
1320     return paramHasAttr(1, Attributes::StructRet);
1321   }
1322
1323   /// \brief Determine if any call argument is an aggregate passed by value.
1324   bool hasByValArgument() const {
1325     for (unsigned I = 0, E = AttributeList.getNumAttrs(); I != E; ++I)
1326       if (AttributeList.getAttributesAtIndex(I).hasAttribute(Attributes::ByVal))
1327         return true;
1328     return false;
1329   }
1330
1331   /// getCalledFunction - Return the function called, or null if this is an
1332   /// indirect function invocation.
1333   ///
1334   Function *getCalledFunction() const {
1335     return dyn_cast<Function>(Op<-1>());
1336   }
1337
1338   /// getCalledValue - Get a pointer to the function that is invoked by this
1339   /// instruction.
1340   const Value *getCalledValue() const { return Op<-1>(); }
1341         Value *getCalledValue()       { return Op<-1>(); }
1342
1343   /// setCalledFunction - Set the function called.
1344   void setCalledFunction(Value* Fn) {
1345     Op<-1>() = Fn;
1346   }
1347
1348   /// isInlineAsm - Check if this call is an inline asm statement.
1349   bool isInlineAsm() const {
1350     return isa<InlineAsm>(Op<-1>());
1351   }
1352
1353   // Methods for support type inquiry through isa, cast, and dyn_cast:
1354   static inline bool classof(const Instruction *I) {
1355     return I->getOpcode() == Instruction::Call;
1356   }
1357   static inline bool classof(const Value *V) {
1358     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1359   }
1360 private:
1361   // Shadow Instruction::setInstructionSubclassData with a private forwarding
1362   // method so that subclasses cannot accidentally use it.
1363   void setInstructionSubclassData(unsigned short D) {
1364     Instruction::setInstructionSubclassData(D);
1365   }
1366 };
1367
1368 template <>
1369 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1370 };
1371
1372 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1373                    const Twine &NameStr, BasicBlock *InsertAtEnd)
1374   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1375                                    ->getElementType())->getReturnType(),
1376                 Instruction::Call,
1377                 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1378                 unsigned(Args.size() + 1), InsertAtEnd) {
1379   init(Func, Args, NameStr);
1380 }
1381
1382 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1383                    const Twine &NameStr, Instruction *InsertBefore)
1384   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1385                                    ->getElementType())->getReturnType(),
1386                 Instruction::Call,
1387                 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1388                 unsigned(Args.size() + 1), InsertBefore) {
1389   init(Func, Args, NameStr);
1390 }
1391
1392
1393 // Note: if you get compile errors about private methods then
1394 //       please update your code to use the high-level operand
1395 //       interfaces. See line 943 above.
1396 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1397
1398 //===----------------------------------------------------------------------===//
1399 //                               SelectInst Class
1400 //===----------------------------------------------------------------------===//
1401
1402 /// SelectInst - This class represents the LLVM 'select' instruction.
1403 ///
1404 class SelectInst : public Instruction {
1405   void init(Value *C, Value *S1, Value *S2) {
1406     assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1407     Op<0>() = C;
1408     Op<1>() = S1;
1409     Op<2>() = S2;
1410   }
1411
1412   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1413              Instruction *InsertBefore)
1414     : Instruction(S1->getType(), Instruction::Select,
1415                   &Op<0>(), 3, InsertBefore) {
1416     init(C, S1, S2);
1417     setName(NameStr);
1418   }
1419   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1420              BasicBlock *InsertAtEnd)
1421     : Instruction(S1->getType(), Instruction::Select,
1422                   &Op<0>(), 3, InsertAtEnd) {
1423     init(C, S1, S2);
1424     setName(NameStr);
1425   }
1426 protected:
1427   virtual SelectInst *clone_impl() const;
1428 public:
1429   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1430                             const Twine &NameStr = "",
1431                             Instruction *InsertBefore = 0) {
1432     return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1433   }
1434   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1435                             const Twine &NameStr,
1436                             BasicBlock *InsertAtEnd) {
1437     return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1438   }
1439
1440   const Value *getCondition() const { return Op<0>(); }
1441   const Value *getTrueValue() const { return Op<1>(); }
1442   const Value *getFalseValue() const { return Op<2>(); }
1443   Value *getCondition() { return Op<0>(); }
1444   Value *getTrueValue() { return Op<1>(); }
1445   Value *getFalseValue() { return Op<2>(); }
1446
1447   /// areInvalidOperands - Return a string if the specified operands are invalid
1448   /// for a select operation, otherwise return null.
1449   static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1450
1451   /// Transparently provide more efficient getOperand methods.
1452   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1453
1454   OtherOps getOpcode() const {
1455     return static_cast<OtherOps>(Instruction::getOpcode());
1456   }
1457
1458   // Methods for support type inquiry through isa, cast, and dyn_cast:
1459   static inline bool classof(const Instruction *I) {
1460     return I->getOpcode() == Instruction::Select;
1461   }
1462   static inline bool classof(const Value *V) {
1463     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1464   }
1465 };
1466
1467 template <>
1468 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1469 };
1470
1471 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1472
1473 //===----------------------------------------------------------------------===//
1474 //                                VAArgInst Class
1475 //===----------------------------------------------------------------------===//
1476
1477 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1478 /// an argument of the specified type given a va_list and increments that list
1479 ///
1480 class VAArgInst : public UnaryInstruction {
1481 protected:
1482   virtual VAArgInst *clone_impl() const;
1483
1484 public:
1485   VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1486              Instruction *InsertBefore = 0)
1487     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1488     setName(NameStr);
1489   }
1490   VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1491             BasicBlock *InsertAtEnd)
1492     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1493     setName(NameStr);
1494   }
1495
1496   Value *getPointerOperand() { return getOperand(0); }
1497   const Value *getPointerOperand() const { return getOperand(0); }
1498   static unsigned getPointerOperandIndex() { return 0U; }
1499
1500   // Methods for support type inquiry through isa, cast, and dyn_cast:
1501   static inline bool classof(const Instruction *I) {
1502     return I->getOpcode() == VAArg;
1503   }
1504   static inline bool classof(const Value *V) {
1505     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1506   }
1507 };
1508
1509 //===----------------------------------------------------------------------===//
1510 //                                ExtractElementInst Class
1511 //===----------------------------------------------------------------------===//
1512
1513 /// ExtractElementInst - This instruction extracts a single (scalar)
1514 /// element from a VectorType value
1515 ///
1516 class ExtractElementInst : public Instruction {
1517   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1518                      Instruction *InsertBefore = 0);
1519   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1520                      BasicBlock *InsertAtEnd);
1521 protected:
1522   virtual ExtractElementInst *clone_impl() const;
1523
1524 public:
1525   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1526                                    const Twine &NameStr = "",
1527                                    Instruction *InsertBefore = 0) {
1528     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1529   }
1530   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1531                                    const Twine &NameStr,
1532                                    BasicBlock *InsertAtEnd) {
1533     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1534   }
1535
1536   /// isValidOperands - Return true if an extractelement instruction can be
1537   /// formed with the specified operands.
1538   static bool isValidOperands(const Value *Vec, const Value *Idx);
1539
1540   Value *getVectorOperand() { return Op<0>(); }
1541   Value *getIndexOperand() { return Op<1>(); }
1542   const Value *getVectorOperand() const { return Op<0>(); }
1543   const Value *getIndexOperand() const { return Op<1>(); }
1544
1545   VectorType *getVectorOperandType() const {
1546     return reinterpret_cast<VectorType*>(getVectorOperand()->getType());
1547   }
1548
1549
1550   /// Transparently provide more efficient getOperand methods.
1551   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1552
1553   // Methods for support type inquiry through isa, cast, and dyn_cast:
1554   static inline bool classof(const Instruction *I) {
1555     return I->getOpcode() == Instruction::ExtractElement;
1556   }
1557   static inline bool classof(const Value *V) {
1558     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1559   }
1560 };
1561
1562 template <>
1563 struct OperandTraits<ExtractElementInst> :
1564   public FixedNumOperandTraits<ExtractElementInst, 2> {
1565 };
1566
1567 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1568
1569 //===----------------------------------------------------------------------===//
1570 //                                InsertElementInst Class
1571 //===----------------------------------------------------------------------===//
1572
1573 /// InsertElementInst - This instruction inserts a single (scalar)
1574 /// element into a VectorType value
1575 ///
1576 class InsertElementInst : public Instruction {
1577   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1578                     const Twine &NameStr = "",
1579                     Instruction *InsertBefore = 0);
1580   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1581                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1582 protected:
1583   virtual InsertElementInst *clone_impl() const;
1584
1585 public:
1586   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1587                                    const Twine &NameStr = "",
1588                                    Instruction *InsertBefore = 0) {
1589     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1590   }
1591   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1592                                    const Twine &NameStr,
1593                                    BasicBlock *InsertAtEnd) {
1594     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1595   }
1596
1597   /// isValidOperands - Return true if an insertelement instruction can be
1598   /// formed with the specified operands.
1599   static bool isValidOperands(const Value *Vec, const Value *NewElt,
1600                               const Value *Idx);
1601
1602   /// getType - Overload to return most specific vector type.
1603   ///
1604   VectorType *getType() const {
1605     return reinterpret_cast<VectorType*>(Instruction::getType());
1606   }
1607
1608   /// Transparently provide more efficient getOperand methods.
1609   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1610
1611   // Methods for support type inquiry through isa, cast, and dyn_cast:
1612   static inline bool classof(const Instruction *I) {
1613     return I->getOpcode() == Instruction::InsertElement;
1614   }
1615   static inline bool classof(const Value *V) {
1616     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1617   }
1618 };
1619
1620 template <>
1621 struct OperandTraits<InsertElementInst> :
1622   public FixedNumOperandTraits<InsertElementInst, 3> {
1623 };
1624
1625 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1626
1627 //===----------------------------------------------------------------------===//
1628 //                           ShuffleVectorInst Class
1629 //===----------------------------------------------------------------------===//
1630
1631 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1632 /// input vectors.
1633 ///
1634 class ShuffleVectorInst : public Instruction {
1635 protected:
1636   virtual ShuffleVectorInst *clone_impl() const;
1637
1638 public:
1639   // allocate space for exactly three operands
1640   void *operator new(size_t s) {
1641     return User::operator new(s, 3);
1642   }
1643   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1644                     const Twine &NameStr = "",
1645                     Instruction *InsertBefor = 0);
1646   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1647                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1648
1649   /// isValidOperands - Return true if a shufflevector instruction can be
1650   /// formed with the specified operands.
1651   static bool isValidOperands(const Value *V1, const Value *V2,
1652                               const Value *Mask);
1653
1654   /// getType - Overload to return most specific vector type.
1655   ///
1656   VectorType *getType() const {
1657     return reinterpret_cast<VectorType*>(Instruction::getType());
1658   }
1659
1660   /// Transparently provide more efficient getOperand methods.
1661   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1662
1663   Constant *getMask() const {
1664     return reinterpret_cast<Constant*>(getOperand(2));
1665   }
1666   
1667   /// getMaskValue - Return the index from the shuffle mask for the specified
1668   /// output result.  This is either -1 if the element is undef or a number less
1669   /// than 2*numelements.
1670   static int getMaskValue(Constant *Mask, unsigned i);
1671
1672   int getMaskValue(unsigned i) const {
1673     return getMaskValue(getMask(), i);
1674   }
1675   
1676   /// getShuffleMask - Return the full mask for this instruction, where each
1677   /// element is the element number and undef's are returned as -1.
1678   static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
1679
1680   void getShuffleMask(SmallVectorImpl<int> &Result) const {
1681     return getShuffleMask(getMask(), Result);
1682   }
1683
1684   SmallVector<int, 16> getShuffleMask() const {
1685     SmallVector<int, 16> Mask;
1686     getShuffleMask(Mask);
1687     return Mask;
1688   }
1689
1690
1691   // Methods for support type inquiry through isa, cast, and dyn_cast:
1692   static inline bool classof(const Instruction *I) {
1693     return I->getOpcode() == Instruction::ShuffleVector;
1694   }
1695   static inline bool classof(const Value *V) {
1696     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1697   }
1698 };
1699
1700 template <>
1701 struct OperandTraits<ShuffleVectorInst> :
1702   public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1703 };
1704
1705 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1706
1707 //===----------------------------------------------------------------------===//
1708 //                                ExtractValueInst Class
1709 //===----------------------------------------------------------------------===//
1710
1711 /// ExtractValueInst - This instruction extracts a struct member or array
1712 /// element value from an aggregate value.
1713 ///
1714 class ExtractValueInst : public UnaryInstruction {
1715   SmallVector<unsigned, 4> Indices;
1716
1717   ExtractValueInst(const ExtractValueInst &EVI);
1718   void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1719
1720   /// Constructors - Create a extractvalue instruction with a base aggregate
1721   /// value and a list of indices.  The first ctor can optionally insert before
1722   /// an existing instruction, the second appends the new instruction to the
1723   /// specified BasicBlock.
1724   inline ExtractValueInst(Value *Agg,
1725                           ArrayRef<unsigned> Idxs,
1726                           const Twine &NameStr,
1727                           Instruction *InsertBefore);
1728   inline ExtractValueInst(Value *Agg,
1729                           ArrayRef<unsigned> Idxs,
1730                           const Twine &NameStr, BasicBlock *InsertAtEnd);
1731
1732   // allocate space for exactly one operand
1733   void *operator new(size_t s) {
1734     return User::operator new(s, 1);
1735   }
1736 protected:
1737   virtual ExtractValueInst *clone_impl() const;
1738
1739 public:
1740   static ExtractValueInst *Create(Value *Agg,
1741                                   ArrayRef<unsigned> Idxs,
1742                                   const Twine &NameStr = "",
1743                                   Instruction *InsertBefore = 0) {
1744     return new
1745       ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1746   }
1747   static ExtractValueInst *Create(Value *Agg,
1748                                   ArrayRef<unsigned> Idxs,
1749                                   const Twine &NameStr,
1750                                   BasicBlock *InsertAtEnd) {
1751     return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1752   }
1753
1754   /// getIndexedType - Returns the type of the element that would be extracted
1755   /// with an extractvalue instruction with the specified parameters.
1756   ///
1757   /// Null is returned if the indices are invalid for the specified type.
1758   static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1759
1760   typedef const unsigned* idx_iterator;
1761   inline idx_iterator idx_begin() const { return Indices.begin(); }
1762   inline idx_iterator idx_end()   const { return Indices.end(); }
1763
1764   Value *getAggregateOperand() {
1765     return getOperand(0);
1766   }
1767   const Value *getAggregateOperand() const {
1768     return getOperand(0);
1769   }
1770   static unsigned getAggregateOperandIndex() {
1771     return 0U;                      // get index for modifying correct operand
1772   }
1773
1774   ArrayRef<unsigned> getIndices() const {
1775     return Indices;
1776   }
1777
1778   unsigned getNumIndices() const {
1779     return (unsigned)Indices.size();
1780   }
1781
1782   bool hasIndices() const {
1783     return true;
1784   }
1785
1786   // Methods for support type inquiry through isa, cast, and dyn_cast:
1787   static inline bool classof(const Instruction *I) {
1788     return I->getOpcode() == Instruction::ExtractValue;
1789   }
1790   static inline bool classof(const Value *V) {
1791     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1792   }
1793 };
1794
1795 ExtractValueInst::ExtractValueInst(Value *Agg,
1796                                    ArrayRef<unsigned> Idxs,
1797                                    const Twine &NameStr,
1798                                    Instruction *InsertBefore)
1799   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1800                      ExtractValue, Agg, InsertBefore) {
1801   init(Idxs, NameStr);
1802 }
1803 ExtractValueInst::ExtractValueInst(Value *Agg,
1804                                    ArrayRef<unsigned> Idxs,
1805                                    const Twine &NameStr,
1806                                    BasicBlock *InsertAtEnd)
1807   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1808                      ExtractValue, Agg, InsertAtEnd) {
1809   init(Idxs, NameStr);
1810 }
1811
1812
1813 //===----------------------------------------------------------------------===//
1814 //                                InsertValueInst Class
1815 //===----------------------------------------------------------------------===//
1816
1817 /// InsertValueInst - This instruction inserts a struct field of array element
1818 /// value into an aggregate value.
1819 ///
1820 class InsertValueInst : public Instruction {
1821   SmallVector<unsigned, 4> Indices;
1822
1823   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1824   InsertValueInst(const InsertValueInst &IVI);
1825   void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1826             const Twine &NameStr);
1827
1828   /// Constructors - Create a insertvalue instruction with a base aggregate
1829   /// value, a value to insert, and a list of indices.  The first ctor can
1830   /// optionally insert before an existing instruction, the second appends
1831   /// the new instruction to the specified BasicBlock.
1832   inline InsertValueInst(Value *Agg, Value *Val,
1833                          ArrayRef<unsigned> Idxs,
1834                          const Twine &NameStr,
1835                          Instruction *InsertBefore);
1836   inline InsertValueInst(Value *Agg, Value *Val,
1837                          ArrayRef<unsigned> Idxs,
1838                          const Twine &NameStr, BasicBlock *InsertAtEnd);
1839
1840   /// Constructors - These two constructors are convenience methods because one
1841   /// and two index insertvalue instructions are so common.
1842   InsertValueInst(Value *Agg, Value *Val,
1843                   unsigned Idx, const Twine &NameStr = "",
1844                   Instruction *InsertBefore = 0);
1845   InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1846                   const Twine &NameStr, BasicBlock *InsertAtEnd);
1847 protected:
1848   virtual InsertValueInst *clone_impl() const;
1849 public:
1850   // allocate space for exactly two operands
1851   void *operator new(size_t s) {
1852     return User::operator new(s, 2);
1853   }
1854
1855   static InsertValueInst *Create(Value *Agg, Value *Val,
1856                                  ArrayRef<unsigned> Idxs,
1857                                  const Twine &NameStr = "",
1858                                  Instruction *InsertBefore = 0) {
1859     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1860   }
1861   static InsertValueInst *Create(Value *Agg, Value *Val,
1862                                  ArrayRef<unsigned> Idxs,
1863                                  const Twine &NameStr,
1864                                  BasicBlock *InsertAtEnd) {
1865     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1866   }
1867
1868   /// Transparently provide more efficient getOperand methods.
1869   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1870
1871   typedef const unsigned* idx_iterator;
1872   inline idx_iterator idx_begin() const { return Indices.begin(); }
1873   inline idx_iterator idx_end()   const { return Indices.end(); }
1874
1875   Value *getAggregateOperand() {
1876     return getOperand(0);
1877   }
1878   const Value *getAggregateOperand() const {
1879     return getOperand(0);
1880   }
1881   static unsigned getAggregateOperandIndex() {
1882     return 0U;                      // get index for modifying correct operand
1883   }
1884
1885   Value *getInsertedValueOperand() {
1886     return getOperand(1);
1887   }
1888   const Value *getInsertedValueOperand() const {
1889     return getOperand(1);
1890   }
1891   static unsigned getInsertedValueOperandIndex() {
1892     return 1U;                      // get index for modifying correct operand
1893   }
1894
1895   ArrayRef<unsigned> getIndices() const {
1896     return Indices;
1897   }
1898
1899   unsigned getNumIndices() const {
1900     return (unsigned)Indices.size();
1901   }
1902
1903   bool hasIndices() const {
1904     return true;
1905   }
1906
1907   // Methods for support type inquiry through isa, cast, and dyn_cast:
1908   static inline bool classof(const Instruction *I) {
1909     return I->getOpcode() == Instruction::InsertValue;
1910   }
1911   static inline bool classof(const Value *V) {
1912     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1913   }
1914 };
1915
1916 template <>
1917 struct OperandTraits<InsertValueInst> :
1918   public FixedNumOperandTraits<InsertValueInst, 2> {
1919 };
1920
1921 InsertValueInst::InsertValueInst(Value *Agg,
1922                                  Value *Val,
1923                                  ArrayRef<unsigned> Idxs,
1924                                  const Twine &NameStr,
1925                                  Instruction *InsertBefore)
1926   : Instruction(Agg->getType(), InsertValue,
1927                 OperandTraits<InsertValueInst>::op_begin(this),
1928                 2, InsertBefore) {
1929   init(Agg, Val, Idxs, NameStr);
1930 }
1931 InsertValueInst::InsertValueInst(Value *Agg,
1932                                  Value *Val,
1933                                  ArrayRef<unsigned> Idxs,
1934                                  const Twine &NameStr,
1935                                  BasicBlock *InsertAtEnd)
1936   : Instruction(Agg->getType(), InsertValue,
1937                 OperandTraits<InsertValueInst>::op_begin(this),
1938                 2, InsertAtEnd) {
1939   init(Agg, Val, Idxs, NameStr);
1940 }
1941
1942 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1943
1944 //===----------------------------------------------------------------------===//
1945 //                               PHINode Class
1946 //===----------------------------------------------------------------------===//
1947
1948 // PHINode - The PHINode class is used to represent the magical mystical PHI
1949 // node, that can not exist in nature, but can be synthesized in a computer
1950 // scientist's overactive imagination.
1951 //
1952 class PHINode : public Instruction {
1953   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1954   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
1955   /// the number actually in use.
1956   unsigned ReservedSpace;
1957   PHINode(const PHINode &PN);
1958   // allocate space for exactly zero operands
1959   void *operator new(size_t s) {
1960     return User::operator new(s, 0);
1961   }
1962   explicit PHINode(Type *Ty, unsigned NumReservedValues,
1963                    const Twine &NameStr = "", Instruction *InsertBefore = 0)
1964     : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1965       ReservedSpace(NumReservedValues) {
1966     setName(NameStr);
1967     OperandList = allocHungoffUses(ReservedSpace);
1968   }
1969
1970   PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
1971           BasicBlock *InsertAtEnd)
1972     : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1973       ReservedSpace(NumReservedValues) {
1974     setName(NameStr);
1975     OperandList = allocHungoffUses(ReservedSpace);
1976   }
1977 protected:
1978   // allocHungoffUses - this is more complicated than the generic
1979   // User::allocHungoffUses, because we have to allocate Uses for the incoming
1980   // values and pointers to the incoming blocks, all in one allocation.
1981   Use *allocHungoffUses(unsigned) const;
1982
1983   virtual PHINode *clone_impl() const;
1984 public:
1985   /// Constructors - NumReservedValues is a hint for the number of incoming
1986   /// edges that this phi node will have (use 0 if you really have no idea).
1987   static PHINode *Create(Type *Ty, unsigned NumReservedValues,
1988                          const Twine &NameStr = "",
1989                          Instruction *InsertBefore = 0) {
1990     return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
1991   }
1992   static PHINode *Create(Type *Ty, unsigned NumReservedValues, 
1993                          const Twine &NameStr, BasicBlock *InsertAtEnd) {
1994     return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
1995   }
1996   ~PHINode();
1997
1998   /// Provide fast operand accessors
1999   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2000
2001   // Block iterator interface. This provides access to the list of incoming
2002   // basic blocks, which parallels the list of incoming values.
2003
2004   typedef BasicBlock **block_iterator;
2005   typedef BasicBlock * const *const_block_iterator;
2006
2007   block_iterator block_begin() {
2008     Use::UserRef *ref =
2009       reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2010     return reinterpret_cast<block_iterator>(ref + 1);
2011   }
2012
2013   const_block_iterator block_begin() const {
2014     const Use::UserRef *ref =
2015       reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2016     return reinterpret_cast<const_block_iterator>(ref + 1);
2017   }
2018
2019   block_iterator block_end() {
2020     return block_begin() + getNumOperands();
2021   }
2022
2023   const_block_iterator block_end() const {
2024     return block_begin() + getNumOperands();
2025   }
2026
2027   /// getNumIncomingValues - Return the number of incoming edges
2028   ///
2029   unsigned getNumIncomingValues() const { return getNumOperands(); }
2030
2031   /// getIncomingValue - Return incoming value number x
2032   ///
2033   Value *getIncomingValue(unsigned i) const {
2034     return getOperand(i);
2035   }
2036   void setIncomingValue(unsigned i, Value *V) {
2037     setOperand(i, V);
2038   }
2039   static unsigned getOperandNumForIncomingValue(unsigned i) {
2040     return i;
2041   }
2042   static unsigned getIncomingValueNumForOperand(unsigned i) {
2043     return i;
2044   }
2045
2046   /// getIncomingBlock - Return incoming basic block number @p i.
2047   ///
2048   BasicBlock *getIncomingBlock(unsigned i) const {
2049     return block_begin()[i];
2050   }
2051
2052   /// getIncomingBlock - Return incoming basic block corresponding
2053   /// to an operand of the PHI.
2054   ///
2055   BasicBlock *getIncomingBlock(const Use &U) const {
2056     assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2057     return getIncomingBlock(unsigned(&U - op_begin()));
2058   }
2059
2060   /// getIncomingBlock - Return incoming basic block corresponding
2061   /// to value use iterator.
2062   ///
2063   template <typename U>
2064   BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
2065     return getIncomingBlock(I.getUse());
2066   }
2067
2068   void setIncomingBlock(unsigned i, BasicBlock *BB) {
2069     block_begin()[i] = BB;
2070   }
2071
2072   /// addIncoming - Add an incoming value to the end of the PHI list
2073   ///
2074   void addIncoming(Value *V, BasicBlock *BB) {
2075     assert(V && "PHI node got a null value!");
2076     assert(BB && "PHI node got a null basic block!");
2077     assert(getType() == V->getType() &&
2078            "All operands to PHI node must be the same type as the PHI node!");
2079     if (NumOperands == ReservedSpace)
2080       growOperands();  // Get more space!
2081     // Initialize some new operands.
2082     ++NumOperands;
2083     setIncomingValue(NumOperands - 1, V);
2084     setIncomingBlock(NumOperands - 1, BB);
2085   }
2086
2087   /// removeIncomingValue - Remove an incoming value.  This is useful if a
2088   /// predecessor basic block is deleted.  The value removed is returned.
2089   ///
2090   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2091   /// is true), the PHI node is destroyed and any uses of it are replaced with
2092   /// dummy values.  The only time there should be zero incoming values to a PHI
2093   /// node is when the block is dead, so this strategy is sound.
2094   ///
2095   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2096
2097   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2098     int Idx = getBasicBlockIndex(BB);
2099     assert(Idx >= 0 && "Invalid basic block argument to remove!");
2100     return removeIncomingValue(Idx, DeletePHIIfEmpty);
2101   }
2102
2103   /// getBasicBlockIndex - Return the first index of the specified basic
2104   /// block in the value list for this PHI.  Returns -1 if no instance.
2105   ///
2106   int getBasicBlockIndex(const BasicBlock *BB) const {
2107     for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2108       if (block_begin()[i] == BB)
2109         return i;
2110     return -1;
2111   }
2112
2113   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2114     int Idx = getBasicBlockIndex(BB);
2115     assert(Idx >= 0 && "Invalid basic block argument!");
2116     return getIncomingValue(Idx);
2117   }
2118
2119   /// hasConstantValue - If the specified PHI node always merges together the
2120   /// same value, return the value, otherwise return null.
2121   Value *hasConstantValue() const;
2122
2123   /// Methods for support type inquiry through isa, cast, and dyn_cast:
2124   static inline bool classof(const Instruction *I) {
2125     return I->getOpcode() == Instruction::PHI;
2126   }
2127   static inline bool classof(const Value *V) {
2128     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2129   }
2130  private:
2131   void growOperands();
2132 };
2133
2134 template <>
2135 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2136 };
2137
2138 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2139
2140 //===----------------------------------------------------------------------===//
2141 //                           LandingPadInst Class
2142 //===----------------------------------------------------------------------===//
2143
2144 //===---------------------------------------------------------------------------
2145 /// LandingPadInst - The landingpad instruction holds all of the information
2146 /// necessary to generate correct exception handling. The landingpad instruction
2147 /// cannot be moved from the top of a landing pad block, which itself is
2148 /// accessible only from the 'unwind' edge of an invoke. This uses the
2149 /// SubclassData field in Value to store whether or not the landingpad is a
2150 /// cleanup.
2151 ///
2152 class LandingPadInst : public Instruction {
2153   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
2154   /// the number actually in use.
2155   unsigned ReservedSpace;
2156   LandingPadInst(const LandingPadInst &LP);
2157 public:
2158   enum ClauseType { Catch, Filter };
2159 private:
2160   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2161   // Allocate space for exactly zero operands.
2162   void *operator new(size_t s) {
2163     return User::operator new(s, 0);
2164   }
2165   void growOperands(unsigned Size);
2166   void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
2167
2168   explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2169                           unsigned NumReservedValues, const Twine &NameStr,
2170                           Instruction *InsertBefore);
2171   explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2172                           unsigned NumReservedValues, const Twine &NameStr,
2173                           BasicBlock *InsertAtEnd);
2174 protected:
2175   virtual LandingPadInst *clone_impl() const;
2176 public:
2177   /// Constructors - NumReservedClauses is a hint for the number of incoming
2178   /// clauses that this landingpad will have (use 0 if you really have no idea).
2179   static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2180                                 unsigned NumReservedClauses,
2181                                 const Twine &NameStr = "",
2182                                 Instruction *InsertBefore = 0);
2183   static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2184                                 unsigned NumReservedClauses,
2185                                 const Twine &NameStr, BasicBlock *InsertAtEnd);
2186   ~LandingPadInst();
2187
2188   /// Provide fast operand accessors
2189   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2190
2191   /// getPersonalityFn - Get the personality function associated with this
2192   /// landing pad.
2193   Value *getPersonalityFn() const { return getOperand(0); }
2194
2195   /// isCleanup - Return 'true' if this landingpad instruction is a
2196   /// cleanup. I.e., it should be run when unwinding even if its landing pad
2197   /// doesn't catch the exception.
2198   bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2199
2200   /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2201   void setCleanup(bool V) {
2202     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2203                                (V ? 1 : 0));
2204   }
2205
2206   /// addClause - Add a catch or filter clause to the landing pad.
2207   void addClause(Value *ClauseVal);
2208
2209   /// getClause - Get the value of the clause at index Idx. Use isCatch/isFilter
2210   /// to determine what type of clause this is.
2211   Value *getClause(unsigned Idx) const { return OperandList[Idx + 1]; }
2212
2213   /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2214   bool isCatch(unsigned Idx) const {
2215     return !isa<ArrayType>(OperandList[Idx + 1]->getType());
2216   }
2217
2218   /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2219   bool isFilter(unsigned Idx) const {
2220     return isa<ArrayType>(OperandList[Idx + 1]->getType());
2221   }
2222
2223   /// getNumClauses - Get the number of clauses for this landing pad.
2224   unsigned getNumClauses() const { return getNumOperands() - 1; }
2225
2226   /// reserveClauses - Grow the size of the operand list to accommodate the new
2227   /// number of clauses.
2228   void reserveClauses(unsigned Size) { growOperands(Size); }
2229
2230   // Methods for support type inquiry through isa, cast, and dyn_cast:
2231   static inline bool classof(const Instruction *I) {
2232     return I->getOpcode() == Instruction::LandingPad;
2233   }
2234   static inline bool classof(const Value *V) {
2235     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2236   }
2237 };
2238
2239 template <>
2240 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
2241 };
2242
2243 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2244
2245 //===----------------------------------------------------------------------===//
2246 //                               ReturnInst Class
2247 //===----------------------------------------------------------------------===//
2248
2249 //===---------------------------------------------------------------------------
2250 /// ReturnInst - Return a value (possibly void), from a function.  Execution
2251 /// does not continue in this function any longer.
2252 ///
2253 class ReturnInst : public TerminatorInst {
2254   ReturnInst(const ReturnInst &RI);
2255
2256 private:
2257   // ReturnInst constructors:
2258   // ReturnInst()                  - 'ret void' instruction
2259   // ReturnInst(    null)          - 'ret void' instruction
2260   // ReturnInst(Value* X)          - 'ret X'    instruction
2261   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
2262   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
2263   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
2264   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
2265   //
2266   // NOTE: If the Value* passed is of type void then the constructor behaves as
2267   // if it was passed NULL.
2268   explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2269                       Instruction *InsertBefore = 0);
2270   ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2271   explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2272 protected:
2273   virtual ReturnInst *clone_impl() const;
2274 public:
2275   static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2276                             Instruction *InsertBefore = 0) {
2277     return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2278   }
2279   static ReturnInst* Create(LLVMContext &C, Value *retVal,
2280                             BasicBlock *InsertAtEnd) {
2281     return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2282   }
2283   static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2284     return new(0) ReturnInst(C, InsertAtEnd);
2285   }
2286   virtual ~ReturnInst();
2287
2288   /// Provide fast operand accessors
2289   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2290
2291   /// Convenience accessor. Returns null if there is no return value.
2292   Value *getReturnValue() const {
2293     return getNumOperands() != 0 ? getOperand(0) : 0;
2294   }
2295
2296   unsigned getNumSuccessors() const { return 0; }
2297
2298   // Methods for support type inquiry through isa, cast, and dyn_cast:
2299   static inline bool classof(const Instruction *I) {
2300     return (I->getOpcode() == Instruction::Ret);
2301   }
2302   static inline bool classof(const Value *V) {
2303     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2304   }
2305  private:
2306   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2307   virtual unsigned getNumSuccessorsV() const;
2308   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2309 };
2310
2311 template <>
2312 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2313 };
2314
2315 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2316
2317 //===----------------------------------------------------------------------===//
2318 //                               BranchInst Class
2319 //===----------------------------------------------------------------------===//
2320
2321 //===---------------------------------------------------------------------------
2322 /// BranchInst - Conditional or Unconditional Branch instruction.
2323 ///
2324 class BranchInst : public TerminatorInst {
2325   /// Ops list - Branches are strange.  The operands are ordered:
2326   ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
2327   /// they don't have to check for cond/uncond branchness. These are mostly
2328   /// accessed relative from op_end().
2329   BranchInst(const BranchInst &BI);
2330   void AssertOK();
2331   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2332   // BranchInst(BB *B)                           - 'br B'
2333   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
2334   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
2335   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2336   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
2337   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
2338   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2339   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2340              Instruction *InsertBefore = 0);
2341   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2342   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2343              BasicBlock *InsertAtEnd);
2344 protected:
2345   virtual BranchInst *clone_impl() const;
2346 public:
2347   static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2348     return new(1) BranchInst(IfTrue, InsertBefore);
2349   }
2350   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2351                             Value *Cond, Instruction *InsertBefore = 0) {
2352     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2353   }
2354   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2355     return new(1) BranchInst(IfTrue, InsertAtEnd);
2356   }
2357   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2358                             Value *Cond, BasicBlock *InsertAtEnd) {
2359     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2360   }
2361
2362   /// Transparently provide more efficient getOperand methods.
2363   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2364
2365   bool isUnconditional() const { return getNumOperands() == 1; }
2366   bool isConditional()   const { return getNumOperands() == 3; }
2367
2368   Value *getCondition() const {
2369     assert(isConditional() && "Cannot get condition of an uncond branch!");
2370     return Op<-3>();
2371   }
2372
2373   void setCondition(Value *V) {
2374     assert(isConditional() && "Cannot set condition of unconditional branch!");
2375     Op<-3>() = V;
2376   }
2377
2378   unsigned getNumSuccessors() const { return 1+isConditional(); }
2379
2380   BasicBlock *getSuccessor(unsigned i) const {
2381     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2382     return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2383   }
2384
2385   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2386     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2387     *(&Op<-1>() - idx) = (Value*)NewSucc;
2388   }
2389
2390   /// \brief Swap the successors of this branch instruction.
2391   ///
2392   /// Swaps the successors of the branch instruction. This also swaps any
2393   /// branch weight metadata associated with the instruction so that it
2394   /// continues to map correctly to each operand.
2395   void swapSuccessors();
2396
2397   // Methods for support type inquiry through isa, cast, and dyn_cast:
2398   static inline bool classof(const Instruction *I) {
2399     return (I->getOpcode() == Instruction::Br);
2400   }
2401   static inline bool classof(const Value *V) {
2402     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2403   }
2404 private:
2405   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2406   virtual unsigned getNumSuccessorsV() const;
2407   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2408 };
2409
2410 template <>
2411 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2412 };
2413
2414 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2415
2416 //===----------------------------------------------------------------------===//
2417 //                               SwitchInst Class
2418 //===----------------------------------------------------------------------===//
2419
2420 //===---------------------------------------------------------------------------
2421 /// SwitchInst - Multiway switch
2422 ///
2423 class SwitchInst : public TerminatorInst {
2424   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2425   unsigned ReservedSpace;
2426   // Operands format:
2427   // Operand[0]    = Value to switch on
2428   // Operand[1]    = Default basic block destination
2429   // Operand[2n  ] = Value to match
2430   // Operand[2n+1] = BasicBlock to go to on match
2431   
2432   // Store case values separately from operands list. We needn't User-Use
2433   // concept here, since it is just a case value, it will always constant,
2434   // and case value couldn't reused with another instructions/values.
2435   // Additionally:
2436   // It allows us to use custom type for case values that is not inherited
2437   // from Value. Since case value is a complex type that implements
2438   // the subset of integers, we needn't extract sub-constants within
2439   // slow getAggregateElement method.
2440   // For case values we will use std::list to by two reasons:
2441   // 1. It allows to add/remove cases without whole collection reallocation.
2442   // 2. In most of cases we needn't random access.
2443   // Currently case values are also stored in Operands List, but it will moved
2444   // out in future commits.
2445   typedef std::list<IntegersSubset> Subsets;
2446   typedef Subsets::iterator SubsetsIt;
2447   typedef Subsets::const_iterator SubsetsConstIt;
2448   
2449   Subsets TheSubsets;
2450   
2451   SwitchInst(const SwitchInst &SI);
2452   void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2453   void growOperands();
2454   // allocate space for exactly zero operands
2455   void *operator new(size_t s) {
2456     return User::operator new(s, 0);
2457   }
2458   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2459   /// switch on and a default destination.  The number of additional cases can
2460   /// be specified here to make memory allocation more efficient.  This
2461   /// constructor can also autoinsert before another instruction.
2462   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2463              Instruction *InsertBefore);
2464
2465   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2466   /// switch on and a default destination.  The number of additional cases can
2467   /// be specified here to make memory allocation more efficient.  This
2468   /// constructor also autoinserts at the end of the specified BasicBlock.
2469   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2470              BasicBlock *InsertAtEnd);
2471 protected:
2472   virtual SwitchInst *clone_impl() const;
2473 public:
2474   
2475   // FIXME: Currently there are a lot of unclean template parameters,
2476   // we need to make refactoring in future.
2477   // All these parameters are used to implement both iterator and const_iterator
2478   // without code duplication.
2479   // SwitchInstTy may be "const SwitchInst" or "SwitchInst"
2480   // ConstantIntTy may be "const ConstantInt" or "ConstantInt"
2481   // SubsetsItTy may be SubsetsConstIt or SubsetsIt
2482   // BasicBlockTy may be "const BasicBlock" or "BasicBlock"
2483   template <class SwitchInstTy, class ConstantIntTy,
2484             class SubsetsItTy, class BasicBlockTy> 
2485     class CaseIteratorT;
2486
2487   typedef CaseIteratorT<const SwitchInst, const ConstantInt,
2488                         SubsetsConstIt, const BasicBlock> ConstCaseIt;
2489   class CaseIt;
2490   
2491   // -2
2492   static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
2493   
2494   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2495                             unsigned NumCases, Instruction *InsertBefore = 0) {
2496     return new SwitchInst(Value, Default, NumCases, InsertBefore);
2497   }
2498   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2499                             unsigned NumCases, BasicBlock *InsertAtEnd) {
2500     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2501   }
2502   
2503   ~SwitchInst();
2504
2505   /// Provide fast operand accessors
2506   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2507
2508   // Accessor Methods for Switch stmt
2509   Value *getCondition() const { return getOperand(0); }
2510   void setCondition(Value *V) { setOperand(0, V); }
2511
2512   BasicBlock *getDefaultDest() const {
2513     return cast<BasicBlock>(getOperand(1));
2514   }
2515
2516   void setDefaultDest(BasicBlock *DefaultCase) {
2517     setOperand(1, reinterpret_cast<Value*>(DefaultCase));
2518   }
2519
2520   /// getNumCases - return the number of 'cases' in this switch instruction,
2521   /// except the default case
2522   unsigned getNumCases() const {
2523     return getNumOperands()/2 - 1;
2524   }
2525
2526   /// Returns a read/write iterator that points to the first
2527   /// case in SwitchInst.
2528   CaseIt case_begin() {
2529     return CaseIt(this, 0, TheSubsets.begin());
2530   }
2531   /// Returns a read-only iterator that points to the first
2532   /// case in the SwitchInst.
2533   ConstCaseIt case_begin() const {
2534     return ConstCaseIt(this, 0, TheSubsets.begin());
2535   }
2536   
2537   /// Returns a read/write iterator that points one past the last
2538   /// in the SwitchInst.
2539   CaseIt case_end() {
2540     return CaseIt(this, getNumCases(), TheSubsets.end());
2541   }
2542   /// Returns a read-only iterator that points one past the last
2543   /// in the SwitchInst.
2544   ConstCaseIt case_end() const {
2545     return ConstCaseIt(this, getNumCases(), TheSubsets.end());
2546   }
2547   /// Returns an iterator that points to the default case.
2548   /// Note: this iterator allows to resolve successor only. Attempt
2549   /// to resolve case value causes an assertion.
2550   /// Also note, that increment and decrement also causes an assertion and
2551   /// makes iterator invalid. 
2552   CaseIt case_default() {
2553     return CaseIt(this, DefaultPseudoIndex, TheSubsets.end());
2554   }
2555   ConstCaseIt case_default() const {
2556     return ConstCaseIt(this, DefaultPseudoIndex, TheSubsets.end());
2557   }
2558   
2559   /// findCaseValue - Search all of the case values for the specified constant.
2560   /// If it is explicitly handled, return the case iterator of it, otherwise
2561   /// return default case iterator to indicate
2562   /// that it is handled by the default handler.
2563   CaseIt findCaseValue(const ConstantInt *C) {
2564     for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
2565       if (i.getCaseValueEx().isSatisfies(IntItem::fromConstantInt(C)))
2566         return i;
2567     return case_default();
2568   }
2569   ConstCaseIt findCaseValue(const ConstantInt *C) const {
2570     for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
2571       if (i.getCaseValueEx().isSatisfies(IntItem::fromConstantInt(C)))
2572         return i;
2573     return case_default();
2574   }    
2575   
2576   /// findCaseDest - Finds the unique case value for a given successor. Returns
2577   /// null if the successor is not found, not unique, or is the default case.
2578   ConstantInt *findCaseDest(BasicBlock *BB) {
2579     if (BB == getDefaultDest()) return NULL;
2580
2581     ConstantInt *CI = NULL;
2582     for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
2583       if (i.getCaseSuccessor() == BB) {
2584         if (CI) return NULL;   // Multiple cases lead to BB.
2585         else CI = i.getCaseValue();
2586       }
2587     }
2588     return CI;
2589   }
2590
2591   /// addCase - Add an entry to the switch instruction...
2592   /// @deprecated
2593   /// Note:
2594   /// This action invalidates case_end(). Old case_end() iterator will
2595   /// point to the added case.
2596   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2597   
2598   /// addCase - Add an entry to the switch instruction.
2599   /// Note:
2600   /// This action invalidates case_end(). Old case_end() iterator will
2601   /// point to the added case.
2602   void addCase(IntegersSubset& OnVal, BasicBlock *Dest);
2603
2604   /// removeCase - This method removes the specified case and its successor
2605   /// from the switch instruction. Note that this operation may reorder the
2606   /// remaining cases at index idx and above.
2607   /// Note:
2608   /// This action invalidates iterators for all cases following the one removed,
2609   /// including the case_end() iterator.
2610   void removeCase(CaseIt& i);
2611
2612   unsigned getNumSuccessors() const { return getNumOperands()/2; }
2613   BasicBlock *getSuccessor(unsigned idx) const {
2614     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2615     return cast<BasicBlock>(getOperand(idx*2+1));
2616   }
2617   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2618     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2619     setOperand(idx*2+1, (Value*)NewSucc);
2620   }
2621   
2622   uint16_t hash() const {
2623     uint32_t NumberOfCases = (uint32_t)getNumCases();
2624     uint16_t Hash = (0xFFFF & NumberOfCases) ^ (NumberOfCases >> 16);
2625     for (ConstCaseIt i = case_begin(), e = case_end();
2626          i != e; ++i) {
2627       uint32_t NumItems = (uint32_t)i.getCaseValueEx().getNumItems(); 
2628       Hash = (Hash << 1) ^ (0xFFFF & NumItems) ^ (NumItems >> 16);
2629     }
2630     return Hash;
2631   }  
2632   
2633   // Case iterators definition.
2634
2635   template <class SwitchInstTy, class ConstantIntTy,
2636             class SubsetsItTy, class BasicBlockTy> 
2637   class CaseIteratorT {
2638   protected:
2639     
2640     SwitchInstTy *SI;
2641     unsigned long Index;
2642     SubsetsItTy SubsetIt;
2643     
2644     /// Initializes case iterator for given SwitchInst and for given
2645     /// case number.    
2646     friend class SwitchInst;
2647     CaseIteratorT(SwitchInstTy *SI, unsigned SuccessorIndex,
2648                   SubsetsItTy CaseValueIt) {
2649       this->SI = SI;
2650       Index = SuccessorIndex;
2651       this->SubsetIt = CaseValueIt;
2652     }
2653     
2654   public:
2655     typedef typename SubsetsItTy::reference IntegersSubsetRef;
2656     typedef CaseIteratorT<SwitchInstTy, ConstantIntTy,
2657                           SubsetsItTy, BasicBlockTy> Self;
2658     
2659     CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
2660           this->SI = SI;
2661           Index = CaseNum;
2662           SubsetIt = SI->TheSubsets.begin();
2663           std::advance(SubsetIt, CaseNum);
2664         }
2665         
2666     
2667     /// Initializes case iterator for given SwitchInst and for given
2668     /// TerminatorInst's successor index.
2669     static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
2670       assert(SuccessorIndex < SI->getNumSuccessors() &&
2671              "Successor index # out of range!");    
2672       return SuccessorIndex != 0 ? 
2673              Self(SI, SuccessorIndex - 1) :
2674              Self(SI, DefaultPseudoIndex);       
2675     }
2676     
2677     /// Resolves case value for current case.
2678     /// @deprecated
2679     ConstantIntTy *getCaseValue() {
2680       assert(Index < SI->getNumCases() && "Index out the number of cases.");
2681       IntegersSubsetRef CaseRanges = *SubsetIt;
2682       
2683       // FIXME: Currently we work with ConstantInt based cases.
2684       // So return CaseValue as ConstantInt.
2685       return CaseRanges.getSingleNumber(0).toConstantInt();
2686     }
2687
2688     /// Resolves case value for current case.
2689     IntegersSubsetRef getCaseValueEx() {
2690       assert(Index < SI->getNumCases() && "Index out the number of cases.");
2691       return *SubsetIt;
2692     }
2693     
2694     /// Resolves successor for current case.
2695     BasicBlockTy *getCaseSuccessor() {
2696       assert((Index < SI->getNumCases() ||
2697               Index == DefaultPseudoIndex) &&
2698              "Index out the number of cases.");
2699       return SI->getSuccessor(getSuccessorIndex());      
2700     }
2701     
2702     /// Returns number of current case.
2703     unsigned getCaseIndex() const { return Index; }
2704     
2705     /// Returns TerminatorInst's successor index for current case successor.
2706     unsigned getSuccessorIndex() const {
2707       assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
2708              "Index out the number of cases.");
2709       return Index != DefaultPseudoIndex ? Index + 1 : 0;
2710     }
2711     
2712     Self operator++() {
2713       // Check index correctness after increment.
2714       // Note: Index == getNumCases() means end().
2715       assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
2716       ++Index;
2717       if (Index == 0)
2718         SubsetIt = SI->TheSubsets.begin();
2719       else
2720         ++SubsetIt;
2721       return *this;
2722     }
2723     Self operator++(int) {
2724       Self tmp = *this;
2725       ++(*this);
2726       return tmp;
2727     }
2728     Self operator--() { 
2729       // Check index correctness after decrement.
2730       // Note: Index == getNumCases() means end().
2731       // Also allow "-1" iterator here. That will became valid after ++.
2732       unsigned NumCases = SI->getNumCases();
2733       assert((Index == 0 || Index-1 <= NumCases) &&
2734              "Index out the number of cases.");
2735       --Index;
2736       if (Index == NumCases) {
2737         SubsetIt = SI->TheSubsets.end();
2738         return *this;
2739       }
2740         
2741       if (Index != -1UL)
2742         --SubsetIt;
2743       
2744       return *this;
2745     }
2746     Self operator--(int) {
2747       Self tmp = *this;
2748       --(*this);
2749       return tmp;
2750     }
2751     bool operator==(const Self& RHS) const {
2752       assert(RHS.SI == SI && "Incompatible operators.");
2753       return RHS.Index == Index;
2754     }
2755     bool operator!=(const Self& RHS) const {
2756       assert(RHS.SI == SI && "Incompatible operators.");
2757       return RHS.Index != Index;
2758     }
2759   };
2760
2761   class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt,
2762                                       SubsetsIt, BasicBlock> {
2763     typedef CaseIteratorT<SwitchInst, ConstantInt, SubsetsIt, BasicBlock>
2764       ParentTy;
2765     
2766   protected:
2767     friend class SwitchInst;
2768     CaseIt(SwitchInst *SI, unsigned CaseNum, SubsetsIt SubsetIt) :
2769       ParentTy(SI, CaseNum, SubsetIt) {}
2770     
2771     void updateCaseValueOperand(IntegersSubset& V) {
2772       SI->setOperand(2 + Index*2, reinterpret_cast<Value*>((Constant*)V));      
2773     }
2774   
2775   public:
2776
2777     CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}    
2778     
2779     CaseIt(const ParentTy& Src) : ParentTy(Src) {}
2780
2781     /// Sets the new value for current case.    
2782     /// @deprecated.
2783     void setValue(ConstantInt *V) {
2784       assert(Index < SI->getNumCases() && "Index out the number of cases.");
2785       IntegersSubsetToBB Mapping;
2786       // FIXME: Currently we work with ConstantInt based cases.
2787       // So inititalize IntItem container directly from ConstantInt.
2788       Mapping.add(IntItem::fromConstantInt(V));
2789       *SubsetIt = Mapping.getCase();
2790       updateCaseValueOperand(*SubsetIt);
2791     }
2792     
2793     /// Sets the new value for current case.
2794     void setValueEx(IntegersSubset& V) {
2795       assert(Index < SI->getNumCases() && "Index out the number of cases.");
2796       *SubsetIt = V;
2797       updateCaseValueOperand(*SubsetIt);   
2798     }
2799     
2800     /// Sets the new successor for current case.
2801     void setSuccessor(BasicBlock *S) {
2802       SI->setSuccessor(getSuccessorIndex(), S);      
2803     }
2804   };
2805
2806   // Methods for support type inquiry through isa, cast, and dyn_cast:
2807
2808   static inline bool classof(const Instruction *I) {
2809     return I->getOpcode() == Instruction::Switch;
2810   }
2811   static inline bool classof(const Value *V) {
2812     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2813   }
2814 private:
2815   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2816   virtual unsigned getNumSuccessorsV() const;
2817   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2818 };
2819
2820 template <>
2821 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2822 };
2823
2824 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2825
2826
2827 //===----------------------------------------------------------------------===//
2828 //                             IndirectBrInst Class
2829 //===----------------------------------------------------------------------===//
2830
2831 //===---------------------------------------------------------------------------
2832 /// IndirectBrInst - Indirect Branch Instruction.
2833 ///
2834 class IndirectBrInst : public TerminatorInst {
2835   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2836   unsigned ReservedSpace;
2837   // Operand[0]    = Value to switch on
2838   // Operand[1]    = Default basic block destination
2839   // Operand[2n  ] = Value to match
2840   // Operand[2n+1] = BasicBlock to go to on match
2841   IndirectBrInst(const IndirectBrInst &IBI);
2842   void init(Value *Address, unsigned NumDests);
2843   void growOperands();
2844   // allocate space for exactly zero operands
2845   void *operator new(size_t s) {
2846     return User::operator new(s, 0);
2847   }
2848   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2849   /// Address to jump to.  The number of expected destinations can be specified
2850   /// here to make memory allocation more efficient.  This constructor can also
2851   /// autoinsert before another instruction.
2852   IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2853
2854   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2855   /// Address to jump to.  The number of expected destinations can be specified
2856   /// here to make memory allocation more efficient.  This constructor also
2857   /// autoinserts at the end of the specified BasicBlock.
2858   IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2859 protected:
2860   virtual IndirectBrInst *clone_impl() const;
2861 public:
2862   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2863                                 Instruction *InsertBefore = 0) {
2864     return new IndirectBrInst(Address, NumDests, InsertBefore);
2865   }
2866   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2867                                 BasicBlock *InsertAtEnd) {
2868     return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2869   }
2870   ~IndirectBrInst();
2871
2872   /// Provide fast operand accessors.
2873   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2874
2875   // Accessor Methods for IndirectBrInst instruction.
2876   Value *getAddress() { return getOperand(0); }
2877   const Value *getAddress() const { return getOperand(0); }
2878   void setAddress(Value *V) { setOperand(0, V); }
2879
2880
2881   /// getNumDestinations - return the number of possible destinations in this
2882   /// indirectbr instruction.
2883   unsigned getNumDestinations() const { return getNumOperands()-1; }
2884
2885   /// getDestination - Return the specified destination.
2886   BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2887   const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2888
2889   /// addDestination - Add a destination.
2890   ///
2891   void addDestination(BasicBlock *Dest);
2892
2893   /// removeDestination - This method removes the specified successor from the
2894   /// indirectbr instruction.
2895   void removeDestination(unsigned i);
2896
2897   unsigned getNumSuccessors() const { return getNumOperands()-1; }
2898   BasicBlock *getSuccessor(unsigned i) const {
2899     return cast<BasicBlock>(getOperand(i+1));
2900   }
2901   void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2902     setOperand(i+1, (Value*)NewSucc);
2903   }
2904
2905   // Methods for support type inquiry through isa, cast, and dyn_cast:
2906   static inline bool classof(const Instruction *I) {
2907     return I->getOpcode() == Instruction::IndirectBr;
2908   }
2909   static inline bool classof(const Value *V) {
2910     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2911   }
2912 private:
2913   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2914   virtual unsigned getNumSuccessorsV() const;
2915   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2916 };
2917
2918 template <>
2919 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2920 };
2921
2922 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2923
2924
2925 //===----------------------------------------------------------------------===//
2926 //                               InvokeInst Class
2927 //===----------------------------------------------------------------------===//
2928
2929 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
2930 /// calling convention of the call.
2931 ///
2932 class InvokeInst : public TerminatorInst {
2933   AttrListPtr AttributeList;
2934   InvokeInst(const InvokeInst &BI);
2935   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2936             ArrayRef<Value *> Args, const Twine &NameStr);
2937
2938   /// Construct an InvokeInst given a range of arguments.
2939   ///
2940   /// \brief Construct an InvokeInst from a range of arguments
2941   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2942                     ArrayRef<Value *> Args, unsigned Values,
2943                     const Twine &NameStr, Instruction *InsertBefore);
2944
2945   /// Construct an InvokeInst given a range of arguments.
2946   ///
2947   /// \brief Construct an InvokeInst from a range of arguments
2948   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2949                     ArrayRef<Value *> Args, unsigned Values,
2950                     const Twine &NameStr, BasicBlock *InsertAtEnd);
2951 protected:
2952   virtual InvokeInst *clone_impl() const;
2953 public:
2954   static InvokeInst *Create(Value *Func,
2955                             BasicBlock *IfNormal, BasicBlock *IfException,
2956                             ArrayRef<Value *> Args, const Twine &NameStr = "",
2957                             Instruction *InsertBefore = 0) {
2958     unsigned Values = unsigned(Args.size()) + 3;
2959     return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2960                                   Values, NameStr, InsertBefore);
2961   }
2962   static InvokeInst *Create(Value *Func,
2963                             BasicBlock *IfNormal, BasicBlock *IfException,
2964                             ArrayRef<Value *> Args, const Twine &NameStr,
2965                             BasicBlock *InsertAtEnd) {
2966     unsigned Values = unsigned(Args.size()) + 3;
2967     return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2968                                   Values, NameStr, InsertAtEnd);
2969   }
2970
2971   /// Provide fast operand accessors
2972   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2973
2974   /// getNumArgOperands - Return the number of invoke arguments.
2975   ///
2976   unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2977
2978   /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2979   ///
2980   Value *getArgOperand(unsigned i) const { return getOperand(i); }
2981   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2982
2983   /// getCallingConv/setCallingConv - Get or set the calling convention of this
2984   /// function call.
2985   CallingConv::ID getCallingConv() const {
2986     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2987   }
2988   void setCallingConv(CallingConv::ID CC) {
2989     setInstructionSubclassData(static_cast<unsigned>(CC));
2990   }
2991
2992   /// getAttributes - Return the parameter attributes for this invoke.
2993   ///
2994   const AttrListPtr &getAttributes() const { return AttributeList; }
2995
2996   /// setAttributes - Set the parameter attributes for this invoke.
2997   ///
2998   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2999
3000   /// addAttribute - adds the attribute to the list of attributes.
3001   void addAttribute(unsigned i, Attributes attr);
3002
3003   /// removeAttribute - removes the attribute from the list of attributes.
3004   void removeAttribute(unsigned i, Attributes attr);
3005
3006   /// \brief Determine whether this call has the NoAlias attribute.
3007   bool hasFnAttr(Attributes::AttrVal A) const;
3008
3009   /// \brief Determine whether the call or the callee has the given attributes.
3010   bool paramHasAttr(unsigned i, Attributes::AttrVal A) const;
3011
3012   /// \brief Extract the alignment for a call or parameter (0=unknown).
3013   unsigned getParamAlignment(unsigned i) const {
3014     return AttributeList.getParamAlignment(i);
3015   }
3016
3017   /// \brief Return true if the call should not be inlined.
3018   bool isNoInline() const { return hasFnAttr(Attributes::NoInline); }
3019   void setIsNoInline() {
3020     addAttribute(AttrListPtr::FunctionIndex,
3021                  Attributes::get(getContext(), Attributes::NoInline));
3022   }
3023
3024   /// \brief Determine if the call does not access memory.
3025   bool doesNotAccessMemory() const {
3026     return hasFnAttr(Attributes::ReadNone);
3027   }
3028   void setDoesNotAccessMemory() {
3029     addAttribute(AttrListPtr::FunctionIndex,
3030                  Attributes::get(getContext(), Attributes::ReadNone));
3031   }
3032
3033   /// \brief Determine if the call does not access or only reads memory.
3034   bool onlyReadsMemory() const {
3035     return doesNotAccessMemory() || hasFnAttr(Attributes::ReadOnly);
3036   }
3037   void setOnlyReadsMemory() {
3038     addAttribute(AttrListPtr::FunctionIndex,
3039                  Attributes::get(getContext(), Attributes::ReadOnly));
3040   }
3041
3042   /// \brief Determine if the call cannot return.
3043   bool doesNotReturn() const { return hasFnAttr(Attributes::NoReturn); }
3044   void setDoesNotReturn() {
3045     addAttribute(AttrListPtr::FunctionIndex,
3046                  Attributes::get(getContext(), Attributes::NoReturn));
3047   }
3048
3049   /// \brief Determine if the call cannot unwind.
3050   bool doesNotThrow() const { return hasFnAttr(Attributes::NoUnwind); }
3051   void setDoesNotThrow() {
3052     addAttribute(AttrListPtr::FunctionIndex,
3053                  Attributes::get(getContext(), Attributes::NoUnwind));
3054   }
3055
3056   /// \brief Determine if the call returns a structure through first
3057   /// pointer argument.
3058   bool hasStructRetAttr() const {
3059     // Be friendly and also check the callee.
3060     return paramHasAttr(1, Attributes::StructRet);
3061   }
3062
3063   /// \brief Determine if any call argument is an aggregate passed by value.
3064   bool hasByValArgument() const {
3065     for (unsigned I = 0, E = AttributeList.getNumAttrs(); I != E; ++I)
3066       if (AttributeList.getAttributesAtIndex(I).hasAttribute(Attributes::ByVal))
3067         return true;
3068     return false;
3069   }
3070
3071   /// getCalledFunction - Return the function called, or null if this is an
3072   /// indirect function invocation.
3073   ///
3074   Function *getCalledFunction() const {
3075     return dyn_cast<Function>(Op<-3>());
3076   }
3077
3078   /// getCalledValue - Get a pointer to the function that is invoked by this
3079   /// instruction
3080   const Value *getCalledValue() const { return Op<-3>(); }
3081         Value *getCalledValue()       { return Op<-3>(); }
3082
3083   /// setCalledFunction - Set the function called.
3084   void setCalledFunction(Value* Fn) {
3085     Op<-3>() = Fn;
3086   }
3087
3088   // get*Dest - Return the destination basic blocks...
3089   BasicBlock *getNormalDest() const {
3090     return cast<BasicBlock>(Op<-2>());
3091   }
3092   BasicBlock *getUnwindDest() const {
3093     return cast<BasicBlock>(Op<-1>());
3094   }
3095   void setNormalDest(BasicBlock *B) {
3096     Op<-2>() = reinterpret_cast<Value*>(B);
3097   }
3098   void setUnwindDest(BasicBlock *B) {
3099     Op<-1>() = reinterpret_cast<Value*>(B);
3100   }
3101
3102   /// getLandingPadInst - Get the landingpad instruction from the landing pad
3103   /// block (the unwind destination).
3104   LandingPadInst *getLandingPadInst() const;
3105
3106   BasicBlock *getSuccessor(unsigned i) const {
3107     assert(i < 2 && "Successor # out of range for invoke!");
3108     return i == 0 ? getNormalDest() : getUnwindDest();
3109   }
3110
3111   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3112     assert(idx < 2 && "Successor # out of range for invoke!");
3113     *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
3114   }
3115
3116   unsigned getNumSuccessors() const { return 2; }
3117
3118   // Methods for support type inquiry through isa, cast, and dyn_cast:
3119   static inline bool classof(const Instruction *I) {
3120     return (I->getOpcode() == Instruction::Invoke);
3121   }
3122   static inline bool classof(const Value *V) {
3123     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3124   }
3125
3126 private:
3127   virtual BasicBlock *getSuccessorV(unsigned idx) const;
3128   virtual unsigned getNumSuccessorsV() const;
3129   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3130
3131   // Shadow Instruction::setInstructionSubclassData with a private forwarding
3132   // method so that subclasses cannot accidentally use it.
3133   void setInstructionSubclassData(unsigned short D) {
3134     Instruction::setInstructionSubclassData(D);
3135   }
3136 };
3137
3138 template <>
3139 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
3140 };
3141
3142 InvokeInst::InvokeInst(Value *Func,
3143                        BasicBlock *IfNormal, BasicBlock *IfException,
3144                        ArrayRef<Value *> Args, unsigned Values,
3145                        const Twine &NameStr, Instruction *InsertBefore)
3146   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3147                                       ->getElementType())->getReturnType(),
3148                    Instruction::Invoke,
3149                    OperandTraits<InvokeInst>::op_end(this) - Values,
3150                    Values, InsertBefore) {
3151   init(Func, IfNormal, IfException, Args, NameStr);
3152 }
3153 InvokeInst::InvokeInst(Value *Func,
3154                        BasicBlock *IfNormal, BasicBlock *IfException,
3155                        ArrayRef<Value *> Args, unsigned Values,
3156                        const Twine &NameStr, BasicBlock *InsertAtEnd)
3157   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3158                                       ->getElementType())->getReturnType(),
3159                    Instruction::Invoke,
3160                    OperandTraits<InvokeInst>::op_end(this) - Values,
3161                    Values, InsertAtEnd) {
3162   init(Func, IfNormal, IfException, Args, NameStr);
3163 }
3164
3165 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
3166
3167 //===----------------------------------------------------------------------===//
3168 //                              ResumeInst Class
3169 //===----------------------------------------------------------------------===//
3170
3171 //===---------------------------------------------------------------------------
3172 /// ResumeInst - Resume the propagation of an exception.
3173 ///
3174 class ResumeInst : public TerminatorInst {
3175   ResumeInst(const ResumeInst &RI);
3176
3177   explicit ResumeInst(Value *Exn, Instruction *InsertBefore=0);
3178   ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
3179 protected:
3180   virtual ResumeInst *clone_impl() const;
3181 public:
3182   static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = 0) {
3183     return new(1) ResumeInst(Exn, InsertBefore);
3184   }
3185   static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
3186     return new(1) ResumeInst(Exn, InsertAtEnd);
3187   }
3188
3189   /// Provide fast operand accessors
3190   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3191
3192   /// Convenience accessor.
3193   Value *getValue() const { return Op<0>(); }
3194
3195   unsigned getNumSuccessors() const { return 0; }
3196
3197   // Methods for support type inquiry through isa, cast, and dyn_cast:
3198   static inline bool classof(const Instruction *I) {
3199     return I->getOpcode() == Instruction::Resume;
3200   }
3201   static inline bool classof(const Value *V) {
3202     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3203   }
3204 private:
3205   virtual BasicBlock *getSuccessorV(unsigned idx) const;
3206   virtual unsigned getNumSuccessorsV() const;
3207   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3208 };
3209
3210 template <>
3211 struct OperandTraits<ResumeInst> :
3212     public FixedNumOperandTraits<ResumeInst, 1> {
3213 };
3214
3215 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
3216
3217 //===----------------------------------------------------------------------===//
3218 //                           UnreachableInst Class
3219 //===----------------------------------------------------------------------===//
3220
3221 //===---------------------------------------------------------------------------
3222 /// UnreachableInst - This function has undefined behavior.  In particular, the
3223 /// presence of this instruction indicates some higher level knowledge that the
3224 /// end of the block cannot be reached.
3225 ///
3226 class UnreachableInst : public TerminatorInst {
3227   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
3228 protected:
3229   virtual UnreachableInst *clone_impl() const;
3230
3231 public:
3232   // allocate space for exactly zero operands
3233   void *operator new(size_t s) {
3234     return User::operator new(s, 0);
3235   }
3236   explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
3237   explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
3238
3239   unsigned getNumSuccessors() const { return 0; }
3240
3241   // Methods for support type inquiry through isa, cast, and dyn_cast:
3242   static inline bool classof(const Instruction *I) {
3243     return I->getOpcode() == Instruction::Unreachable;
3244   }
3245   static inline bool classof(const Value *V) {
3246     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3247   }
3248 private:
3249   virtual BasicBlock *getSuccessorV(unsigned idx) const;
3250   virtual unsigned getNumSuccessorsV() const;
3251   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3252 };
3253
3254 //===----------------------------------------------------------------------===//
3255 //                                 TruncInst Class
3256 //===----------------------------------------------------------------------===//
3257
3258 /// \brief This class represents a truncation of integer types.
3259 class TruncInst : public CastInst {
3260 protected:
3261   /// \brief Clone an identical TruncInst
3262   virtual TruncInst *clone_impl() const;
3263
3264 public:
3265   /// \brief Constructor with insert-before-instruction semantics
3266   TruncInst(
3267     Value *S,                     ///< The value to be truncated
3268     Type *Ty,               ///< The (smaller) type to truncate to
3269     const Twine &NameStr = "",    ///< A name for the new instruction
3270     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3271   );
3272
3273   /// \brief Constructor with insert-at-end-of-block semantics
3274   TruncInst(
3275     Value *S,                     ///< The value to be truncated
3276     Type *Ty,               ///< The (smaller) type to truncate to
3277     const Twine &NameStr,         ///< A name for the new instruction
3278     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3279   );
3280
3281   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3282   static inline bool classof(const Instruction *I) {
3283     return I->getOpcode() == Trunc;
3284   }
3285   static inline bool classof(const Value *V) {
3286     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3287   }
3288 };
3289
3290 //===----------------------------------------------------------------------===//
3291 //                                 ZExtInst Class
3292 //===----------------------------------------------------------------------===//
3293
3294 /// \brief This class represents zero extension of integer types.
3295 class ZExtInst : public CastInst {
3296 protected:
3297   /// \brief Clone an identical ZExtInst
3298   virtual ZExtInst *clone_impl() const;
3299
3300 public:
3301   /// \brief Constructor with insert-before-instruction semantics
3302   ZExtInst(
3303     Value *S,                     ///< The value to be zero extended
3304     Type *Ty,               ///< The type to zero extend to
3305     const Twine &NameStr = "",    ///< A name for the new instruction
3306     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3307   );
3308
3309   /// \brief Constructor with insert-at-end semantics.
3310   ZExtInst(
3311     Value *S,                     ///< The value to be zero extended
3312     Type *Ty,               ///< The type to zero extend to
3313     const Twine &NameStr,         ///< A name for the new instruction
3314     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3315   );
3316
3317   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3318   static inline bool classof(const Instruction *I) {
3319     return I->getOpcode() == ZExt;
3320   }
3321   static inline bool classof(const Value *V) {
3322     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3323   }
3324 };
3325
3326 //===----------------------------------------------------------------------===//
3327 //                                 SExtInst Class
3328 //===----------------------------------------------------------------------===//
3329
3330 /// \brief This class represents a sign extension of integer types.
3331 class SExtInst : public CastInst {
3332 protected:
3333   /// \brief Clone an identical SExtInst
3334   virtual SExtInst *clone_impl() const;
3335
3336 public:
3337   /// \brief Constructor with insert-before-instruction semantics
3338   SExtInst(
3339     Value *S,                     ///< The value to be sign extended
3340     Type *Ty,               ///< The type to sign extend to
3341     const Twine &NameStr = "",    ///< A name for the new instruction
3342     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3343   );
3344
3345   /// \brief Constructor with insert-at-end-of-block semantics
3346   SExtInst(
3347     Value *S,                     ///< The value to be sign extended
3348     Type *Ty,               ///< The type to sign extend to
3349     const Twine &NameStr,         ///< A name for the new instruction
3350     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3351   );
3352
3353   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3354   static inline bool classof(const Instruction *I) {
3355     return I->getOpcode() == SExt;
3356   }
3357   static inline bool classof(const Value *V) {
3358     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3359   }
3360 };
3361
3362 //===----------------------------------------------------------------------===//
3363 //                                 FPTruncInst Class
3364 //===----------------------------------------------------------------------===//
3365
3366 /// \brief This class represents a truncation of floating point types.
3367 class FPTruncInst : public CastInst {
3368 protected:
3369   /// \brief Clone an identical FPTruncInst
3370   virtual FPTruncInst *clone_impl() const;
3371
3372 public:
3373   /// \brief Constructor with insert-before-instruction semantics
3374   FPTruncInst(
3375     Value *S,                     ///< The value to be truncated
3376     Type *Ty,               ///< The type to truncate to
3377     const Twine &NameStr = "",    ///< A name for the new instruction
3378     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3379   );
3380
3381   /// \brief Constructor with insert-before-instruction semantics
3382   FPTruncInst(
3383     Value *S,                     ///< The value to be truncated
3384     Type *Ty,               ///< The type to truncate to
3385     const Twine &NameStr,         ///< A name for the new instruction
3386     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3387   );
3388
3389   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3390   static inline bool classof(const Instruction *I) {
3391     return I->getOpcode() == FPTrunc;
3392   }
3393   static inline bool classof(const Value *V) {
3394     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3395   }
3396 };
3397
3398 //===----------------------------------------------------------------------===//
3399 //                                 FPExtInst Class
3400 //===----------------------------------------------------------------------===//
3401
3402 /// \brief This class represents an extension of floating point types.
3403 class FPExtInst : public CastInst {
3404 protected:
3405   /// \brief Clone an identical FPExtInst
3406   virtual FPExtInst *clone_impl() const;
3407
3408 public:
3409   /// \brief Constructor with insert-before-instruction semantics
3410   FPExtInst(
3411     Value *S,                     ///< The value to be extended
3412     Type *Ty,               ///< The type to extend to
3413     const Twine &NameStr = "",    ///< A name for the new instruction
3414     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3415   );
3416
3417   /// \brief Constructor with insert-at-end-of-block semantics
3418   FPExtInst(
3419     Value *S,                     ///< The value to be extended
3420     Type *Ty,               ///< The type to extend to
3421     const Twine &NameStr,         ///< A name for the new instruction
3422     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3423   );
3424
3425   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3426   static inline bool classof(const Instruction *I) {
3427     return I->getOpcode() == FPExt;
3428   }
3429   static inline bool classof(const Value *V) {
3430     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3431   }
3432 };
3433
3434 //===----------------------------------------------------------------------===//
3435 //                                 UIToFPInst Class
3436 //===----------------------------------------------------------------------===//
3437
3438 /// \brief This class represents a cast unsigned integer to floating point.
3439 class UIToFPInst : public CastInst {
3440 protected:
3441   /// \brief Clone an identical UIToFPInst
3442   virtual UIToFPInst *clone_impl() const;
3443
3444 public:
3445   /// \brief Constructor with insert-before-instruction semantics
3446   UIToFPInst(
3447     Value *S,                     ///< The value to be converted
3448     Type *Ty,               ///< The type to convert to
3449     const Twine &NameStr = "",    ///< A name for the new instruction
3450     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3451   );
3452
3453   /// \brief Constructor with insert-at-end-of-block semantics
3454   UIToFPInst(
3455     Value *S,                     ///< The value to be converted
3456     Type *Ty,               ///< The type to convert to
3457     const Twine &NameStr,         ///< A name for the new instruction
3458     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3459   );
3460
3461   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3462   static inline bool classof(const Instruction *I) {
3463     return I->getOpcode() == UIToFP;
3464   }
3465   static inline bool classof(const Value *V) {
3466     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3467   }
3468 };
3469
3470 //===----------------------------------------------------------------------===//
3471 //                                 SIToFPInst Class
3472 //===----------------------------------------------------------------------===//
3473
3474 /// \brief This class represents a cast from signed integer to floating point.
3475 class SIToFPInst : public CastInst {
3476 protected:
3477   /// \brief Clone an identical SIToFPInst
3478   virtual SIToFPInst *clone_impl() const;
3479
3480 public:
3481   /// \brief Constructor with insert-before-instruction semantics
3482   SIToFPInst(
3483     Value *S,                     ///< The value to be converted
3484     Type *Ty,               ///< The type to convert to
3485     const Twine &NameStr = "",    ///< A name for the new instruction
3486     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3487   );
3488
3489   /// \brief Constructor with insert-at-end-of-block semantics
3490   SIToFPInst(
3491     Value *S,                     ///< The value to be converted
3492     Type *Ty,               ///< The type to convert to
3493     const Twine &NameStr,         ///< A name for the new instruction
3494     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3495   );
3496
3497   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3498   static inline bool classof(const Instruction *I) {
3499     return I->getOpcode() == SIToFP;
3500   }
3501   static inline bool classof(const Value *V) {
3502     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3503   }
3504 };
3505
3506 //===----------------------------------------------------------------------===//
3507 //                                 FPToUIInst Class
3508 //===----------------------------------------------------------------------===//
3509
3510 /// \brief This class represents a cast from floating point to unsigned integer
3511 class FPToUIInst  : public CastInst {
3512 protected:
3513   /// \brief Clone an identical FPToUIInst
3514   virtual FPToUIInst *clone_impl() const;
3515
3516 public:
3517   /// \brief Constructor with insert-before-instruction semantics
3518   FPToUIInst(
3519     Value *S,                     ///< The value to be converted
3520     Type *Ty,               ///< The type to convert to
3521     const Twine &NameStr = "",    ///< A name for the new instruction
3522     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3523   );
3524
3525   /// \brief Constructor with insert-at-end-of-block semantics
3526   FPToUIInst(
3527     Value *S,                     ///< The value to be converted
3528     Type *Ty,               ///< The type to convert to
3529     const Twine &NameStr,         ///< A name for the new instruction
3530     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
3531   );
3532
3533   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3534   static inline bool classof(const Instruction *I) {
3535     return I->getOpcode() == FPToUI;
3536   }
3537   static inline bool classof(const Value *V) {
3538     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3539   }
3540 };
3541
3542 //===----------------------------------------------------------------------===//
3543 //                                 FPToSIInst Class
3544 //===----------------------------------------------------------------------===//
3545
3546 /// \brief This class represents a cast from floating point to signed integer.
3547 class FPToSIInst  : public CastInst {
3548 protected:
3549   /// \brief Clone an identical FPToSIInst
3550   virtual FPToSIInst *clone_impl() const;
3551
3552 public:
3553   /// \brief Constructor with insert-before-instruction semantics
3554   FPToSIInst(
3555     Value *S,                     ///< The value to be converted
3556     Type *Ty,               ///< The type to convert to
3557     const Twine &NameStr = "",    ///< A name for the new instruction
3558     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3559   );
3560
3561   /// \brief Constructor with insert-at-end-of-block semantics
3562   FPToSIInst(
3563     Value *S,                     ///< The value to be converted
3564     Type *Ty,               ///< The type to convert to
3565     const Twine &NameStr,         ///< A name for the new instruction
3566     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3567   );
3568
3569   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
3570   static inline bool classof(const Instruction *I) {
3571     return I->getOpcode() == FPToSI;
3572   }
3573   static inline bool classof(const Value *V) {
3574     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3575   }
3576 };
3577
3578 //===----------------------------------------------------------------------===//
3579 //                                 IntToPtrInst Class
3580 //===----------------------------------------------------------------------===//
3581
3582 /// \brief This class represents a cast from an integer to a pointer.
3583 class IntToPtrInst : public CastInst {
3584 public:
3585   /// \brief Constructor with insert-before-instruction semantics
3586   IntToPtrInst(
3587     Value *S,                     ///< The value to be converted
3588     Type *Ty,               ///< The type to convert to
3589     const Twine &NameStr = "",    ///< A name for the new instruction
3590     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3591   );
3592
3593   /// \brief Constructor with insert-at-end-of-block semantics
3594   IntToPtrInst(
3595     Value *S,                     ///< The value to be converted
3596     Type *Ty,               ///< The type to convert to
3597     const Twine &NameStr,         ///< A name for the new instruction
3598     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3599   );
3600
3601   /// \brief Clone an identical IntToPtrInst
3602   virtual IntToPtrInst *clone_impl() const;
3603
3604   /// \brief return the address space of the pointer.
3605   unsigned getAddressSpace() const {
3606     return getType()->getPointerAddressSpace();
3607   }
3608
3609   // Methods for support type inquiry through isa, cast, and dyn_cast:
3610   static inline bool classof(const Instruction *I) {
3611     return I->getOpcode() == IntToPtr;
3612   }
3613   static inline bool classof(const Value *V) {
3614     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3615   }
3616 };
3617
3618 //===----------------------------------------------------------------------===//
3619 //                                 PtrToIntInst Class
3620 //===----------------------------------------------------------------------===//
3621
3622 /// \brief This class represents a cast from a pointer to an integer
3623 class PtrToIntInst : public CastInst {
3624 protected:
3625   /// \brief Clone an identical PtrToIntInst
3626   virtual PtrToIntInst *clone_impl() const;
3627
3628 public:
3629   /// \brief Constructor with insert-before-instruction semantics
3630   PtrToIntInst(
3631     Value *S,                     ///< The value to be converted
3632     Type *Ty,               ///< The type to convert to
3633     const Twine &NameStr = "",    ///< A name for the new instruction
3634     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3635   );
3636
3637   /// \brief Constructor with insert-at-end-of-block semantics
3638   PtrToIntInst(
3639     Value *S,                     ///< The value to be converted
3640     Type *Ty,               ///< The type to convert to
3641     const Twine &NameStr,         ///< A name for the new instruction
3642     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3643   );
3644
3645   /// \brief return the address space of the pointer.
3646   unsigned getPointerAddressSpace() const {
3647     return getOperand(0)->getType()->getPointerAddressSpace();
3648   }
3649
3650   // Methods for support type inquiry through isa, cast, and dyn_cast:
3651   static inline bool classof(const Instruction *I) {
3652     return I->getOpcode() == PtrToInt;
3653   }
3654   static inline bool classof(const Value *V) {
3655     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3656   }
3657 };
3658
3659 //===----------------------------------------------------------------------===//
3660 //                             BitCastInst Class
3661 //===----------------------------------------------------------------------===//
3662
3663 /// \brief This class represents a no-op cast from one type to another.
3664 class BitCastInst : public CastInst {
3665 protected:
3666   /// \brief Clone an identical BitCastInst
3667   virtual BitCastInst *clone_impl() const;
3668
3669 public:
3670   /// \brief Constructor with insert-before-instruction semantics
3671   BitCastInst(
3672     Value *S,                     ///< The value to be casted
3673     Type *Ty,               ///< The type to casted to
3674     const Twine &NameStr = "",    ///< A name for the new instruction
3675     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3676   );
3677
3678   /// \brief Constructor with insert-at-end-of-block semantics
3679   BitCastInst(
3680     Value *S,                     ///< The value to be casted
3681     Type *Ty,               ///< The type to casted to
3682     const Twine &NameStr,         ///< A name for the new instruction
3683     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3684   );
3685
3686   // Methods for support type inquiry through isa, cast, and dyn_cast:
3687   static inline bool classof(const Instruction *I) {
3688     return I->getOpcode() == BitCast;
3689   }
3690   static inline bool classof(const Value *V) {
3691     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3692   }
3693 };
3694
3695 } // End llvm namespace
3696
3697 #endif