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