bed828a88551ea77b35d60e12fd89e6d121a0b3a
[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) LLVM_DELETED_FUNCTION;
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) LLVM_DELETED_FUNCTION;
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) LLVM_DELETED_FUNCTION;
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) LLVM_DELETED_FUNCTION;
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 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 this call has the given attribute.
1271   bool fnHasNoAliasAttr() const;
1272   bool fnHasNoInlineAttr() const;
1273   bool fnHasNoReturnAttr() const;
1274   bool fnHasNoUnwindAttr() const;
1275   bool fnHasReadNoneAttr() const;
1276   bool fnHasReadOnlyAttr() const;
1277   bool fnHasReturnsTwiceAttr() const;
1278
1279   /// \brief Return true if this call has the given attribute.
1280   bool hasFnAttr(Attributes N) const {
1281     return paramHasAttr(~0, N);
1282   }
1283
1284   /// @brief Determine whether the call or the callee has the given attributes.
1285   bool paramHasByValAttr(unsigned i) const;
1286   bool paramHasInRegAttr(unsigned i) const;
1287   bool paramHasNestAttr(unsigned i) const;
1288   bool paramHasNoAliasAttr(unsigned i) const;
1289   bool paramHasNoCaptureAttr(unsigned i) const;
1290   bool paramHasSExtAttr(unsigned i) const;
1291   bool paramHasStructRetAttr(unsigned i) const;
1292   bool paramHasZExtAttr(unsigned i) const;
1293
1294   /// @brief Determine whether the call or the callee has the given attribute.
1295   bool paramHasAttr(unsigned i, Attributes attr) const;
1296
1297   /// @brief Extract the alignment for a call or parameter (0=unknown).
1298   unsigned getParamAlignment(unsigned i) const {
1299     return AttributeList.getParamAlignment(i);
1300   }
1301
1302   /// @brief Return true if the call should not be inlined.
1303   bool isNoInline() const { return fnHasNoInlineAttr(); }
1304   void setIsNoInline(bool Value = true) {
1305     if (Value) addAttribute(~0, Attribute::NoInline);
1306     else removeAttribute(~0, Attribute::NoInline);
1307   }
1308
1309   /// @brief Return true if the call can return twice
1310   bool canReturnTwice() const {
1311     return fnHasReturnsTwiceAttr();
1312   }
1313   void setCanReturnTwice(bool Value = true) {
1314     if (Value) addAttribute(~0, Attribute::ReturnsTwice);
1315     else removeAttribute(~0, Attribute::ReturnsTwice);
1316   }
1317
1318   /// @brief Determine if the call does not access memory.
1319   bool doesNotAccessMemory() const {
1320     return fnHasReadNoneAttr();
1321   }
1322   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
1323     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
1324     else removeAttribute(~0, Attribute::ReadNone);
1325   }
1326
1327   /// @brief Determine if the call does not access or only reads memory.
1328   bool onlyReadsMemory() const {
1329     return doesNotAccessMemory() || fnHasReadOnlyAttr();
1330   }
1331   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
1332     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
1333     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
1334   }
1335
1336   /// @brief Determine if the call cannot return.
1337   bool doesNotReturn() const { return fnHasNoReturnAttr(); }
1338   void setDoesNotReturn(bool DoesNotReturn = true) {
1339     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
1340     else removeAttribute(~0, Attribute::NoReturn);
1341   }
1342
1343   /// @brief Determine if the call cannot unwind.
1344   bool doesNotThrow() const { return fnHasNoUnwindAttr(); }
1345   void setDoesNotThrow(bool DoesNotThrow = true) {
1346     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
1347     else removeAttribute(~0, Attribute::NoUnwind);
1348   }
1349
1350   /// @brief Determine if the call returns a structure through first
1351   /// pointer argument.
1352   bool hasStructRetAttr() const {
1353     // Be friendly and also check the callee.
1354     return paramHasStructRetAttr(1);
1355   }
1356
1357   /// @brief Determine if any call argument is an aggregate passed by value.
1358   bool hasByValArgument() const {
1359     for (unsigned I = 0, E = AttributeList.getNumAttrs(); I != E; ++I)
1360       if (AttributeList.getAttributesAtIndex(I).hasByValAttr())
1361         return true;
1362     return false;
1363   }
1364
1365   /// getCalledFunction - Return the function called, or null if this is an
1366   /// indirect function invocation.
1367   ///
1368   Function *getCalledFunction() const {
1369     return dyn_cast<Function>(Op<-1>());
1370   }
1371
1372   /// getCalledValue - Get a pointer to the function that is invoked by this
1373   /// instruction.
1374   const Value *getCalledValue() const { return Op<-1>(); }
1375         Value *getCalledValue()       { return Op<-1>(); }
1376
1377   /// setCalledFunction - Set the function called.
1378   void setCalledFunction(Value* Fn) {
1379     Op<-1>() = Fn;
1380   }
1381
1382   /// isInlineAsm - Check if this call is an inline asm statement.
1383   bool isInlineAsm() const {
1384     return isa<InlineAsm>(Op<-1>());
1385   }
1386
1387   // Methods for support type inquiry through isa, cast, and dyn_cast:
1388   static inline bool classof(const CallInst *) { return true; }
1389   static inline bool classof(const Instruction *I) {
1390     return I->getOpcode() == Instruction::Call;
1391   }
1392   static inline bool classof(const Value *V) {
1393     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1394   }
1395 private:
1396   // Shadow Instruction::setInstructionSubclassData with a private forwarding
1397   // method so that subclasses cannot accidentally use it.
1398   void setInstructionSubclassData(unsigned short D) {
1399     Instruction::setInstructionSubclassData(D);
1400   }
1401 };
1402
1403 template <>
1404 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1405 };
1406
1407 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1408                    const Twine &NameStr, BasicBlock *InsertAtEnd)
1409   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1410                                    ->getElementType())->getReturnType(),
1411                 Instruction::Call,
1412                 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1413                 unsigned(Args.size() + 1), InsertAtEnd) {
1414   init(Func, Args, NameStr);
1415 }
1416
1417 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1418                    const Twine &NameStr, Instruction *InsertBefore)
1419   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1420                                    ->getElementType())->getReturnType(),
1421                 Instruction::Call,
1422                 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1423                 unsigned(Args.size() + 1), InsertBefore) {
1424   init(Func, Args, NameStr);
1425 }
1426
1427
1428 // Note: if you get compile errors about private methods then
1429 //       please update your code to use the high-level operand
1430 //       interfaces. See line 943 above.
1431 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1432
1433 //===----------------------------------------------------------------------===//
1434 //                               SelectInst Class
1435 //===----------------------------------------------------------------------===//
1436
1437 /// SelectInst - This class represents the LLVM 'select' instruction.
1438 ///
1439 class SelectInst : public Instruction {
1440   void init(Value *C, Value *S1, Value *S2) {
1441     assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1442     Op<0>() = C;
1443     Op<1>() = S1;
1444     Op<2>() = S2;
1445   }
1446
1447   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1448              Instruction *InsertBefore)
1449     : Instruction(S1->getType(), Instruction::Select,
1450                   &Op<0>(), 3, InsertBefore) {
1451     init(C, S1, S2);
1452     setName(NameStr);
1453   }
1454   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1455              BasicBlock *InsertAtEnd)
1456     : Instruction(S1->getType(), Instruction::Select,
1457                   &Op<0>(), 3, InsertAtEnd) {
1458     init(C, S1, S2);
1459     setName(NameStr);
1460   }
1461 protected:
1462   virtual SelectInst *clone_impl() const;
1463 public:
1464   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1465                             const Twine &NameStr = "",
1466                             Instruction *InsertBefore = 0) {
1467     return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1468   }
1469   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1470                             const Twine &NameStr,
1471                             BasicBlock *InsertAtEnd) {
1472     return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1473   }
1474
1475   const Value *getCondition() const { return Op<0>(); }
1476   const Value *getTrueValue() const { return Op<1>(); }
1477   const Value *getFalseValue() const { return Op<2>(); }
1478   Value *getCondition() { return Op<0>(); }
1479   Value *getTrueValue() { return Op<1>(); }
1480   Value *getFalseValue() { return Op<2>(); }
1481
1482   /// areInvalidOperands - Return a string if the specified operands are invalid
1483   /// for a select operation, otherwise return null.
1484   static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1485
1486   /// Transparently provide more efficient getOperand methods.
1487   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1488
1489   OtherOps getOpcode() const {
1490     return static_cast<OtherOps>(Instruction::getOpcode());
1491   }
1492
1493   // Methods for support type inquiry through isa, cast, and dyn_cast:
1494   static inline bool classof(const SelectInst *) { return true; }
1495   static inline bool classof(const Instruction *I) {
1496     return I->getOpcode() == Instruction::Select;
1497   }
1498   static inline bool classof(const Value *V) {
1499     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1500   }
1501 };
1502
1503 template <>
1504 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1505 };
1506
1507 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1508
1509 //===----------------------------------------------------------------------===//
1510 //                                VAArgInst Class
1511 //===----------------------------------------------------------------------===//
1512
1513 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1514 /// an argument of the specified type given a va_list and increments that list
1515 ///
1516 class VAArgInst : public UnaryInstruction {
1517 protected:
1518   virtual VAArgInst *clone_impl() const;
1519
1520 public:
1521   VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1522              Instruction *InsertBefore = 0)
1523     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1524     setName(NameStr);
1525   }
1526   VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1527             BasicBlock *InsertAtEnd)
1528     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1529     setName(NameStr);
1530   }
1531
1532   Value *getPointerOperand() { return getOperand(0); }
1533   const Value *getPointerOperand() const { return getOperand(0); }
1534   static unsigned getPointerOperandIndex() { return 0U; }
1535
1536   // Methods for support type inquiry through isa, cast, and dyn_cast:
1537   static inline bool classof(const VAArgInst *) { return true; }
1538   static inline bool classof(const Instruction *I) {
1539     return I->getOpcode() == VAArg;
1540   }
1541   static inline bool classof(const Value *V) {
1542     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1543   }
1544 };
1545
1546 //===----------------------------------------------------------------------===//
1547 //                                ExtractElementInst Class
1548 //===----------------------------------------------------------------------===//
1549
1550 /// ExtractElementInst - This instruction extracts a single (scalar)
1551 /// element from a VectorType value
1552 ///
1553 class ExtractElementInst : public Instruction {
1554   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1555                      Instruction *InsertBefore = 0);
1556   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1557                      BasicBlock *InsertAtEnd);
1558 protected:
1559   virtual ExtractElementInst *clone_impl() const;
1560
1561 public:
1562   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1563                                    const Twine &NameStr = "",
1564                                    Instruction *InsertBefore = 0) {
1565     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1566   }
1567   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1568                                    const Twine &NameStr,
1569                                    BasicBlock *InsertAtEnd) {
1570     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1571   }
1572
1573   /// isValidOperands - Return true if an extractelement instruction can be
1574   /// formed with the specified operands.
1575   static bool isValidOperands(const Value *Vec, const Value *Idx);
1576
1577   Value *getVectorOperand() { return Op<0>(); }
1578   Value *getIndexOperand() { return Op<1>(); }
1579   const Value *getVectorOperand() const { return Op<0>(); }
1580   const Value *getIndexOperand() const { return Op<1>(); }
1581
1582   VectorType *getVectorOperandType() const {
1583     return reinterpret_cast<VectorType*>(getVectorOperand()->getType());
1584   }
1585
1586
1587   /// Transparently provide more efficient getOperand methods.
1588   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1589
1590   // Methods for support type inquiry through isa, cast, and dyn_cast:
1591   static inline bool classof(const ExtractElementInst *) { return true; }
1592   static inline bool classof(const Instruction *I) {
1593     return I->getOpcode() == Instruction::ExtractElement;
1594   }
1595   static inline bool classof(const Value *V) {
1596     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1597   }
1598 };
1599
1600 template <>
1601 struct OperandTraits<ExtractElementInst> :
1602   public FixedNumOperandTraits<ExtractElementInst, 2> {
1603 };
1604
1605 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1606
1607 //===----------------------------------------------------------------------===//
1608 //                                InsertElementInst Class
1609 //===----------------------------------------------------------------------===//
1610
1611 /// InsertElementInst - This instruction inserts a single (scalar)
1612 /// element into a VectorType value
1613 ///
1614 class InsertElementInst : public Instruction {
1615   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1616                     const Twine &NameStr = "",
1617                     Instruction *InsertBefore = 0);
1618   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1619                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1620 protected:
1621   virtual InsertElementInst *clone_impl() const;
1622
1623 public:
1624   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1625                                    const Twine &NameStr = "",
1626                                    Instruction *InsertBefore = 0) {
1627     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1628   }
1629   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1630                                    const Twine &NameStr,
1631                                    BasicBlock *InsertAtEnd) {
1632     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1633   }
1634
1635   /// isValidOperands - Return true if an insertelement instruction can be
1636   /// formed with the specified operands.
1637   static bool isValidOperands(const Value *Vec, const Value *NewElt,
1638                               const Value *Idx);
1639
1640   /// getType - Overload to return most specific vector type.
1641   ///
1642   VectorType *getType() const {
1643     return reinterpret_cast<VectorType*>(Instruction::getType());
1644   }
1645
1646   /// Transparently provide more efficient getOperand methods.
1647   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1648
1649   // Methods for support type inquiry through isa, cast, and dyn_cast:
1650   static inline bool classof(const InsertElementInst *) { return true; }
1651   static inline bool classof(const Instruction *I) {
1652     return I->getOpcode() == Instruction::InsertElement;
1653   }
1654   static inline bool classof(const Value *V) {
1655     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1656   }
1657 };
1658
1659 template <>
1660 struct OperandTraits<InsertElementInst> :
1661   public FixedNumOperandTraits<InsertElementInst, 3> {
1662 };
1663
1664 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1665
1666 //===----------------------------------------------------------------------===//
1667 //                           ShuffleVectorInst Class
1668 //===----------------------------------------------------------------------===//
1669
1670 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1671 /// input vectors.
1672 ///
1673 class ShuffleVectorInst : public Instruction {
1674 protected:
1675   virtual ShuffleVectorInst *clone_impl() const;
1676
1677 public:
1678   // allocate space for exactly three operands
1679   void *operator new(size_t s) {
1680     return User::operator new(s, 3);
1681   }
1682   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1683                     const Twine &NameStr = "",
1684                     Instruction *InsertBefor = 0);
1685   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1686                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1687
1688   /// isValidOperands - Return true if a shufflevector instruction can be
1689   /// formed with the specified operands.
1690   static bool isValidOperands(const Value *V1, const Value *V2,
1691                               const Value *Mask);
1692
1693   /// getType - Overload to return most specific vector type.
1694   ///
1695   VectorType *getType() const {
1696     return reinterpret_cast<VectorType*>(Instruction::getType());
1697   }
1698
1699   /// Transparently provide more efficient getOperand methods.
1700   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1701
1702   Constant *getMask() const {
1703     return reinterpret_cast<Constant*>(getOperand(2));
1704   }
1705   
1706   /// getMaskValue - Return the index from the shuffle mask for the specified
1707   /// output result.  This is either -1 if the element is undef or a number less
1708   /// than 2*numelements.
1709   static int getMaskValue(Constant *Mask, unsigned i);
1710
1711   int getMaskValue(unsigned i) const {
1712     return getMaskValue(getMask(), i);
1713   }
1714   
1715   /// getShuffleMask - Return the full mask for this instruction, where each
1716   /// element is the element number and undef's are returned as -1.
1717   static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
1718
1719   void getShuffleMask(SmallVectorImpl<int> &Result) const {
1720     return getShuffleMask(getMask(), Result);
1721   }
1722
1723   SmallVector<int, 16> getShuffleMask() const {
1724     SmallVector<int, 16> Mask;
1725     getShuffleMask(Mask);
1726     return Mask;
1727   }
1728
1729
1730   // Methods for support type inquiry through isa, cast, and dyn_cast:
1731   static inline bool classof(const ShuffleVectorInst *) { return true; }
1732   static inline bool classof(const Instruction *I) {
1733     return I->getOpcode() == Instruction::ShuffleVector;
1734   }
1735   static inline bool classof(const Value *V) {
1736     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1737   }
1738 };
1739
1740 template <>
1741 struct OperandTraits<ShuffleVectorInst> :
1742   public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1743 };
1744
1745 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1746
1747 //===----------------------------------------------------------------------===//
1748 //                                ExtractValueInst Class
1749 //===----------------------------------------------------------------------===//
1750
1751 /// ExtractValueInst - This instruction extracts a struct member or array
1752 /// element value from an aggregate value.
1753 ///
1754 class ExtractValueInst : public UnaryInstruction {
1755   SmallVector<unsigned, 4> Indices;
1756
1757   ExtractValueInst(const ExtractValueInst &EVI);
1758   void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1759
1760   /// Constructors - Create a extractvalue instruction with a base aggregate
1761   /// value and a list of indices.  The first ctor can optionally insert before
1762   /// an existing instruction, the second appends the new instruction to the
1763   /// specified BasicBlock.
1764   inline ExtractValueInst(Value *Agg,
1765                           ArrayRef<unsigned> Idxs,
1766                           const Twine &NameStr,
1767                           Instruction *InsertBefore);
1768   inline ExtractValueInst(Value *Agg,
1769                           ArrayRef<unsigned> Idxs,
1770                           const Twine &NameStr, BasicBlock *InsertAtEnd);
1771
1772   // allocate space for exactly one operand
1773   void *operator new(size_t s) {
1774     return User::operator new(s, 1);
1775   }
1776 protected:
1777   virtual ExtractValueInst *clone_impl() const;
1778
1779 public:
1780   static ExtractValueInst *Create(Value *Agg,
1781                                   ArrayRef<unsigned> Idxs,
1782                                   const Twine &NameStr = "",
1783                                   Instruction *InsertBefore = 0) {
1784     return new
1785       ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1786   }
1787   static ExtractValueInst *Create(Value *Agg,
1788                                   ArrayRef<unsigned> Idxs,
1789                                   const Twine &NameStr,
1790                                   BasicBlock *InsertAtEnd) {
1791     return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1792   }
1793
1794   /// getIndexedType - Returns the type of the element that would be extracted
1795   /// with an extractvalue instruction with the specified parameters.
1796   ///
1797   /// Null is returned if the indices are invalid for the specified type.
1798   static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1799
1800   typedef const unsigned* idx_iterator;
1801   inline idx_iterator idx_begin() const { return Indices.begin(); }
1802   inline idx_iterator idx_end()   const { return Indices.end(); }
1803
1804   Value *getAggregateOperand() {
1805     return getOperand(0);
1806   }
1807   const Value *getAggregateOperand() const {
1808     return getOperand(0);
1809   }
1810   static unsigned getAggregateOperandIndex() {
1811     return 0U;                      // get index for modifying correct operand
1812   }
1813
1814   ArrayRef<unsigned> getIndices() const {
1815     return Indices;
1816   }
1817
1818   unsigned getNumIndices() const {
1819     return (unsigned)Indices.size();
1820   }
1821
1822   bool hasIndices() const {
1823     return true;
1824   }
1825
1826   // Methods for support type inquiry through isa, cast, and dyn_cast:
1827   static inline bool classof(const ExtractValueInst *) { return true; }
1828   static inline bool classof(const Instruction *I) {
1829     return I->getOpcode() == Instruction::ExtractValue;
1830   }
1831   static inline bool classof(const Value *V) {
1832     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1833   }
1834 };
1835
1836 ExtractValueInst::ExtractValueInst(Value *Agg,
1837                                    ArrayRef<unsigned> Idxs,
1838                                    const Twine &NameStr,
1839                                    Instruction *InsertBefore)
1840   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1841                      ExtractValue, Agg, InsertBefore) {
1842   init(Idxs, NameStr);
1843 }
1844 ExtractValueInst::ExtractValueInst(Value *Agg,
1845                                    ArrayRef<unsigned> Idxs,
1846                                    const Twine &NameStr,
1847                                    BasicBlock *InsertAtEnd)
1848   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1849                      ExtractValue, Agg, InsertAtEnd) {
1850   init(Idxs, NameStr);
1851 }
1852
1853
1854 //===----------------------------------------------------------------------===//
1855 //                                InsertValueInst Class
1856 //===----------------------------------------------------------------------===//
1857
1858 /// InsertValueInst - This instruction inserts a struct field of array element
1859 /// value into an aggregate value.
1860 ///
1861 class InsertValueInst : public Instruction {
1862   SmallVector<unsigned, 4> Indices;
1863
1864   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1865   InsertValueInst(const InsertValueInst &IVI);
1866   void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1867             const Twine &NameStr);
1868
1869   /// Constructors - Create a insertvalue instruction with a base aggregate
1870   /// value, a value to insert, and a list of indices.  The first ctor can
1871   /// optionally insert before an existing instruction, the second appends
1872   /// the new instruction to the specified BasicBlock.
1873   inline InsertValueInst(Value *Agg, Value *Val,
1874                          ArrayRef<unsigned> Idxs,
1875                          const Twine &NameStr,
1876                          Instruction *InsertBefore);
1877   inline InsertValueInst(Value *Agg, Value *Val,
1878                          ArrayRef<unsigned> Idxs,
1879                          const Twine &NameStr, BasicBlock *InsertAtEnd);
1880
1881   /// Constructors - These two constructors are convenience methods because one
1882   /// and two index insertvalue instructions are so common.
1883   InsertValueInst(Value *Agg, Value *Val,
1884                   unsigned Idx, const Twine &NameStr = "",
1885                   Instruction *InsertBefore = 0);
1886   InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1887                   const Twine &NameStr, BasicBlock *InsertAtEnd);
1888 protected:
1889   virtual InsertValueInst *clone_impl() const;
1890 public:
1891   // allocate space for exactly two operands
1892   void *operator new(size_t s) {
1893     return User::operator new(s, 2);
1894   }
1895
1896   static InsertValueInst *Create(Value *Agg, Value *Val,
1897                                  ArrayRef<unsigned> Idxs,
1898                                  const Twine &NameStr = "",
1899                                  Instruction *InsertBefore = 0) {
1900     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1901   }
1902   static InsertValueInst *Create(Value *Agg, Value *Val,
1903                                  ArrayRef<unsigned> Idxs,
1904                                  const Twine &NameStr,
1905                                  BasicBlock *InsertAtEnd) {
1906     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1907   }
1908
1909   /// Transparently provide more efficient getOperand methods.
1910   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1911
1912   typedef const unsigned* idx_iterator;
1913   inline idx_iterator idx_begin() const { return Indices.begin(); }
1914   inline idx_iterator idx_end()   const { return Indices.end(); }
1915
1916   Value *getAggregateOperand() {
1917     return getOperand(0);
1918   }
1919   const Value *getAggregateOperand() const {
1920     return getOperand(0);
1921   }
1922   static unsigned getAggregateOperandIndex() {
1923     return 0U;                      // get index for modifying correct operand
1924   }
1925
1926   Value *getInsertedValueOperand() {
1927     return getOperand(1);
1928   }
1929   const Value *getInsertedValueOperand() const {
1930     return getOperand(1);
1931   }
1932   static unsigned getInsertedValueOperandIndex() {
1933     return 1U;                      // get index for modifying correct operand
1934   }
1935
1936   ArrayRef<unsigned> getIndices() const {
1937     return Indices;
1938   }
1939
1940   unsigned getNumIndices() const {
1941     return (unsigned)Indices.size();
1942   }
1943
1944   bool hasIndices() const {
1945     return true;
1946   }
1947
1948   // Methods for support type inquiry through isa, cast, and dyn_cast:
1949   static inline bool classof(const InsertValueInst *) { return true; }
1950   static inline bool classof(const Instruction *I) {
1951     return I->getOpcode() == Instruction::InsertValue;
1952   }
1953   static inline bool classof(const Value *V) {
1954     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1955   }
1956 };
1957
1958 template <>
1959 struct OperandTraits<InsertValueInst> :
1960   public FixedNumOperandTraits<InsertValueInst, 2> {
1961 };
1962
1963 InsertValueInst::InsertValueInst(Value *Agg,
1964                                  Value *Val,
1965                                  ArrayRef<unsigned> Idxs,
1966                                  const Twine &NameStr,
1967                                  Instruction *InsertBefore)
1968   : Instruction(Agg->getType(), InsertValue,
1969                 OperandTraits<InsertValueInst>::op_begin(this),
1970                 2, InsertBefore) {
1971   init(Agg, Val, Idxs, NameStr);
1972 }
1973 InsertValueInst::InsertValueInst(Value *Agg,
1974                                  Value *Val,
1975                                  ArrayRef<unsigned> Idxs,
1976                                  const Twine &NameStr,
1977                                  BasicBlock *InsertAtEnd)
1978   : Instruction(Agg->getType(), InsertValue,
1979                 OperandTraits<InsertValueInst>::op_begin(this),
1980                 2, InsertAtEnd) {
1981   init(Agg, Val, Idxs, NameStr);
1982 }
1983
1984 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1985
1986 //===----------------------------------------------------------------------===//
1987 //                               PHINode Class
1988 //===----------------------------------------------------------------------===//
1989
1990 // PHINode - The PHINode class is used to represent the magical mystical PHI
1991 // node, that can not exist in nature, but can be synthesized in a computer
1992 // scientist's overactive imagination.
1993 //
1994 class PHINode : public Instruction {
1995   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
1996   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
1997   /// the number actually in use.
1998   unsigned ReservedSpace;
1999   PHINode(const PHINode &PN);
2000   // allocate space for exactly zero operands
2001   void *operator new(size_t s) {
2002     return User::operator new(s, 0);
2003   }
2004   explicit PHINode(Type *Ty, unsigned NumReservedValues,
2005                    const Twine &NameStr = "", Instruction *InsertBefore = 0)
2006     : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
2007       ReservedSpace(NumReservedValues) {
2008     setName(NameStr);
2009     OperandList = allocHungoffUses(ReservedSpace);
2010   }
2011
2012   PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
2013           BasicBlock *InsertAtEnd)
2014     : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
2015       ReservedSpace(NumReservedValues) {
2016     setName(NameStr);
2017     OperandList = allocHungoffUses(ReservedSpace);
2018   }
2019 protected:
2020   // allocHungoffUses - this is more complicated than the generic
2021   // User::allocHungoffUses, because we have to allocate Uses for the incoming
2022   // values and pointers to the incoming blocks, all in one allocation.
2023   Use *allocHungoffUses(unsigned) const;
2024
2025   virtual PHINode *clone_impl() const;
2026 public:
2027   /// Constructors - NumReservedValues is a hint for the number of incoming
2028   /// edges that this phi node will have (use 0 if you really have no idea).
2029   static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2030                          const Twine &NameStr = "",
2031                          Instruction *InsertBefore = 0) {
2032     return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2033   }
2034   static PHINode *Create(Type *Ty, unsigned NumReservedValues, 
2035                          const Twine &NameStr, BasicBlock *InsertAtEnd) {
2036     return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2037   }
2038   ~PHINode();
2039
2040   /// Provide fast operand accessors
2041   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2042
2043   // Block iterator interface. This provides access to the list of incoming
2044   // basic blocks, which parallels the list of incoming values.
2045
2046   typedef BasicBlock **block_iterator;
2047   typedef BasicBlock * const *const_block_iterator;
2048
2049   block_iterator block_begin() {
2050     Use::UserRef *ref =
2051       reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2052     return reinterpret_cast<block_iterator>(ref + 1);
2053   }
2054
2055   const_block_iterator block_begin() const {
2056     const Use::UserRef *ref =
2057       reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2058     return reinterpret_cast<const_block_iterator>(ref + 1);
2059   }
2060
2061   block_iterator block_end() {
2062     return block_begin() + getNumOperands();
2063   }
2064
2065   const_block_iterator block_end() const {
2066     return block_begin() + getNumOperands();
2067   }
2068
2069   /// getNumIncomingValues - Return the number of incoming edges
2070   ///
2071   unsigned getNumIncomingValues() const { return getNumOperands(); }
2072
2073   /// getIncomingValue - Return incoming value number x
2074   ///
2075   Value *getIncomingValue(unsigned i) const {
2076     return getOperand(i);
2077   }
2078   void setIncomingValue(unsigned i, Value *V) {
2079     setOperand(i, V);
2080   }
2081   static unsigned getOperandNumForIncomingValue(unsigned i) {
2082     return i;
2083   }
2084   static unsigned getIncomingValueNumForOperand(unsigned i) {
2085     return i;
2086   }
2087
2088   /// getIncomingBlock - Return incoming basic block number @p i.
2089   ///
2090   BasicBlock *getIncomingBlock(unsigned i) const {
2091     return block_begin()[i];
2092   }
2093
2094   /// getIncomingBlock - Return incoming basic block corresponding
2095   /// to an operand of the PHI.
2096   ///
2097   BasicBlock *getIncomingBlock(const Use &U) const {
2098     assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2099     return getIncomingBlock(unsigned(&U - op_begin()));
2100   }
2101
2102   /// getIncomingBlock - Return incoming basic block corresponding
2103   /// to value use iterator.
2104   ///
2105   template <typename U>
2106   BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
2107     return getIncomingBlock(I.getUse());
2108   }
2109
2110   void setIncomingBlock(unsigned i, BasicBlock *BB) {
2111     block_begin()[i] = BB;
2112   }
2113
2114   /// addIncoming - Add an incoming value to the end of the PHI list
2115   ///
2116   void addIncoming(Value *V, BasicBlock *BB) {
2117     assert(V && "PHI node got a null value!");
2118     assert(BB && "PHI node got a null basic block!");
2119     assert(getType() == V->getType() &&
2120            "All operands to PHI node must be the same type as the PHI node!");
2121     if (NumOperands == ReservedSpace)
2122       growOperands();  // Get more space!
2123     // Initialize some new operands.
2124     ++NumOperands;
2125     setIncomingValue(NumOperands - 1, V);
2126     setIncomingBlock(NumOperands - 1, BB);
2127   }
2128
2129   /// removeIncomingValue - Remove an incoming value.  This is useful if a
2130   /// predecessor basic block is deleted.  The value removed is returned.
2131   ///
2132   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2133   /// is true), the PHI node is destroyed and any uses of it are replaced with
2134   /// dummy values.  The only time there should be zero incoming values to a PHI
2135   /// node is when the block is dead, so this strategy is sound.
2136   ///
2137   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2138
2139   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2140     int Idx = getBasicBlockIndex(BB);
2141     assert(Idx >= 0 && "Invalid basic block argument to remove!");
2142     return removeIncomingValue(Idx, DeletePHIIfEmpty);
2143   }
2144
2145   /// getBasicBlockIndex - Return the first index of the specified basic
2146   /// block in the value list for this PHI.  Returns -1 if no instance.
2147   ///
2148   int getBasicBlockIndex(const BasicBlock *BB) const {
2149     for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2150       if (block_begin()[i] == BB)
2151         return i;
2152     return -1;
2153   }
2154
2155   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2156     int Idx = getBasicBlockIndex(BB);
2157     assert(Idx >= 0 && "Invalid basic block argument!");
2158     return getIncomingValue(Idx);
2159   }
2160
2161   /// hasConstantValue - If the specified PHI node always merges together the
2162   /// same value, return the value, otherwise return null.
2163   Value *hasConstantValue() const;
2164
2165   /// Methods for support type inquiry through isa, cast, and dyn_cast:
2166   static inline bool classof(const PHINode *) { return true; }
2167   static inline bool classof(const Instruction *I) {
2168     return I->getOpcode() == Instruction::PHI;
2169   }
2170   static inline bool classof(const Value *V) {
2171     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2172   }
2173  private:
2174   void growOperands();
2175 };
2176
2177 template <>
2178 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2179 };
2180
2181 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2182
2183 //===----------------------------------------------------------------------===//
2184 //                           LandingPadInst Class
2185 //===----------------------------------------------------------------------===//
2186
2187 //===---------------------------------------------------------------------------
2188 /// LandingPadInst - The landingpad instruction holds all of the information
2189 /// necessary to generate correct exception handling. The landingpad instruction
2190 /// cannot be moved from the top of a landing pad block, which itself is
2191 /// accessible only from the 'unwind' edge of an invoke. This uses the
2192 /// SubclassData field in Value to store whether or not the landingpad is a
2193 /// cleanup.
2194 ///
2195 class LandingPadInst : public Instruction {
2196   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
2197   /// the number actually in use.
2198   unsigned ReservedSpace;
2199   LandingPadInst(const LandingPadInst &LP);
2200 public:
2201   enum ClauseType { Catch, Filter };
2202 private:
2203   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2204   // Allocate space for exactly zero operands.
2205   void *operator new(size_t s) {
2206     return User::operator new(s, 0);
2207   }
2208   void growOperands(unsigned Size);
2209   void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
2210
2211   explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2212                           unsigned NumReservedValues, const Twine &NameStr,
2213                           Instruction *InsertBefore);
2214   explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2215                           unsigned NumReservedValues, const Twine &NameStr,
2216                           BasicBlock *InsertAtEnd);
2217 protected:
2218   virtual LandingPadInst *clone_impl() const;
2219 public:
2220   /// Constructors - NumReservedClauses is a hint for the number of incoming
2221   /// clauses that this landingpad will have (use 0 if you really have no idea).
2222   static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2223                                 unsigned NumReservedClauses,
2224                                 const Twine &NameStr = "",
2225                                 Instruction *InsertBefore = 0);
2226   static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2227                                 unsigned NumReservedClauses,
2228                                 const Twine &NameStr, BasicBlock *InsertAtEnd);
2229   ~LandingPadInst();
2230
2231   /// Provide fast operand accessors
2232   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2233
2234   /// getPersonalityFn - Get the personality function associated with this
2235   /// landing pad.
2236   Value *getPersonalityFn() const { return getOperand(0); }
2237
2238   /// isCleanup - Return 'true' if this landingpad instruction is a
2239   /// cleanup. I.e., it should be run when unwinding even if its landing pad
2240   /// doesn't catch the exception.
2241   bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2242
2243   /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2244   void setCleanup(bool V) {
2245     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2246                                (V ? 1 : 0));
2247   }
2248
2249   /// addClause - Add a catch or filter clause to the landing pad.
2250   void addClause(Value *ClauseVal);
2251
2252   /// getClause - Get the value of the clause at index Idx. Use isCatch/isFilter
2253   /// to determine what type of clause this is.
2254   Value *getClause(unsigned Idx) const { return OperandList[Idx + 1]; }
2255
2256   /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2257   bool isCatch(unsigned Idx) const {
2258     return !isa<ArrayType>(OperandList[Idx + 1]->getType());
2259   }
2260
2261   /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2262   bool isFilter(unsigned Idx) const {
2263     return isa<ArrayType>(OperandList[Idx + 1]->getType());
2264   }
2265
2266   /// getNumClauses - Get the number of clauses for this landing pad.
2267   unsigned getNumClauses() const { return getNumOperands() - 1; }
2268
2269   /// reserveClauses - Grow the size of the operand list to accommodate the new
2270   /// number of clauses.
2271   void reserveClauses(unsigned Size) { growOperands(Size); }
2272
2273   // Methods for support type inquiry through isa, cast, and dyn_cast:
2274   static inline bool classof(const LandingPadInst *) { return true; }
2275   static inline bool classof(const Instruction *I) {
2276     return I->getOpcode() == Instruction::LandingPad;
2277   }
2278   static inline bool classof(const Value *V) {
2279     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2280   }
2281 };
2282
2283 template <>
2284 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
2285 };
2286
2287 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2288
2289 //===----------------------------------------------------------------------===//
2290 //                               ReturnInst Class
2291 //===----------------------------------------------------------------------===//
2292
2293 //===---------------------------------------------------------------------------
2294 /// ReturnInst - Return a value (possibly void), from a function.  Execution
2295 /// does not continue in this function any longer.
2296 ///
2297 class ReturnInst : public TerminatorInst {
2298   ReturnInst(const ReturnInst &RI);
2299
2300 private:
2301   // ReturnInst constructors:
2302   // ReturnInst()                  - 'ret void' instruction
2303   // ReturnInst(    null)          - 'ret void' instruction
2304   // ReturnInst(Value* X)          - 'ret X'    instruction
2305   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
2306   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
2307   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
2308   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
2309   //
2310   // NOTE: If the Value* passed is of type void then the constructor behaves as
2311   // if it was passed NULL.
2312   explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2313                       Instruction *InsertBefore = 0);
2314   ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2315   explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2316 protected:
2317   virtual ReturnInst *clone_impl() const;
2318 public:
2319   static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2320                             Instruction *InsertBefore = 0) {
2321     return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2322   }
2323   static ReturnInst* Create(LLVMContext &C, Value *retVal,
2324                             BasicBlock *InsertAtEnd) {
2325     return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2326   }
2327   static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2328     return new(0) ReturnInst(C, InsertAtEnd);
2329   }
2330   virtual ~ReturnInst();
2331
2332   /// Provide fast operand accessors
2333   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2334
2335   /// Convenience accessor. Returns null if there is no return value.
2336   Value *getReturnValue() const {
2337     return getNumOperands() != 0 ? getOperand(0) : 0;
2338   }
2339
2340   unsigned getNumSuccessors() const { return 0; }
2341
2342   // Methods for support type inquiry through isa, cast, and dyn_cast:
2343   static inline bool classof(const ReturnInst *) { return true; }
2344   static inline bool classof(const Instruction *I) {
2345     return (I->getOpcode() == Instruction::Ret);
2346   }
2347   static inline bool classof(const Value *V) {
2348     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2349   }
2350  private:
2351   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2352   virtual unsigned getNumSuccessorsV() const;
2353   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2354 };
2355
2356 template <>
2357 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2358 };
2359
2360 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2361
2362 //===----------------------------------------------------------------------===//
2363 //                               BranchInst Class
2364 //===----------------------------------------------------------------------===//
2365
2366 //===---------------------------------------------------------------------------
2367 /// BranchInst - Conditional or Unconditional Branch instruction.
2368 ///
2369 class BranchInst : public TerminatorInst {
2370   /// Ops list - Branches are strange.  The operands are ordered:
2371   ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
2372   /// they don't have to check for cond/uncond branchness. These are mostly
2373   /// accessed relative from op_end().
2374   BranchInst(const BranchInst &BI);
2375   void AssertOK();
2376   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2377   // BranchInst(BB *B)                           - 'br B'
2378   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
2379   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
2380   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2381   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
2382   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
2383   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2384   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2385              Instruction *InsertBefore = 0);
2386   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2387   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2388              BasicBlock *InsertAtEnd);
2389 protected:
2390   virtual BranchInst *clone_impl() const;
2391 public:
2392   static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2393     return new(1) BranchInst(IfTrue, InsertBefore);
2394   }
2395   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2396                             Value *Cond, Instruction *InsertBefore = 0) {
2397     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2398   }
2399   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2400     return new(1) BranchInst(IfTrue, InsertAtEnd);
2401   }
2402   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2403                             Value *Cond, BasicBlock *InsertAtEnd) {
2404     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2405   }
2406
2407   /// Transparently provide more efficient getOperand methods.
2408   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2409
2410   bool isUnconditional() const { return getNumOperands() == 1; }
2411   bool isConditional()   const { return getNumOperands() == 3; }
2412
2413   Value *getCondition() const {
2414     assert(isConditional() && "Cannot get condition of an uncond branch!");
2415     return Op<-3>();
2416   }
2417
2418   void setCondition(Value *V) {
2419     assert(isConditional() && "Cannot set condition of unconditional branch!");
2420     Op<-3>() = V;
2421   }
2422
2423   unsigned getNumSuccessors() const { return 1+isConditional(); }
2424
2425   BasicBlock *getSuccessor(unsigned i) const {
2426     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2427     return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2428   }
2429
2430   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2431     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2432     *(&Op<-1>() - idx) = (Value*)NewSucc;
2433   }
2434
2435   /// \brief Swap the successors of this branch instruction.
2436   ///
2437   /// Swaps the successors of the branch instruction. This also swaps any
2438   /// branch weight metadata associated with the instruction so that it
2439   /// continues to map correctly to each operand.
2440   void swapSuccessors();
2441
2442   // Methods for support type inquiry through isa, cast, and dyn_cast:
2443   static inline bool classof(const BranchInst *) { return true; }
2444   static inline bool classof(const Instruction *I) {
2445     return (I->getOpcode() == Instruction::Br);
2446   }
2447   static inline bool classof(const Value *V) {
2448     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2449   }
2450 private:
2451   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2452   virtual unsigned getNumSuccessorsV() const;
2453   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2454 };
2455
2456 template <>
2457 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2458 };
2459
2460 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2461
2462 //===----------------------------------------------------------------------===//
2463 //                               SwitchInst Class
2464 //===----------------------------------------------------------------------===//
2465
2466 //===---------------------------------------------------------------------------
2467 /// SwitchInst - Multiway switch
2468 ///
2469 class SwitchInst : public TerminatorInst {
2470   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2471   unsigned ReservedSpace;
2472   // Operands format:
2473   // Operand[0]    = Value to switch on
2474   // Operand[1]    = Default basic block destination
2475   // Operand[2n  ] = Value to match
2476   // Operand[2n+1] = BasicBlock to go to on match
2477   
2478   // Store case values separately from operands list. We needn't User-Use
2479   // concept here, since it is just a case value, it will always constant,
2480   // and case value couldn't reused with another instructions/values.
2481   // Additionally:
2482   // It allows us to use custom type for case values that is not inherited
2483   // from Value. Since case value is a complex type that implements
2484   // the subset of integers, we needn't extract sub-constants within
2485   // slow getAggregateElement method.
2486   // For case values we will use std::list to by two reasons:
2487   // 1. It allows to add/remove cases without whole collection reallocation.
2488   // 2. In most of cases we needn't random access.
2489   // Currently case values are also stored in Operands List, but it will moved
2490   // out in future commits.
2491   typedef std::list<IntegersSubset> Subsets;
2492   typedef Subsets::iterator SubsetsIt;
2493   typedef Subsets::const_iterator SubsetsConstIt;
2494   
2495   Subsets TheSubsets;
2496   
2497   SwitchInst(const SwitchInst &SI);
2498   void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2499   void growOperands();
2500   // allocate space for exactly zero operands
2501   void *operator new(size_t s) {
2502     return User::operator new(s, 0);
2503   }
2504   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2505   /// switch on and a default destination.  The number of additional cases can
2506   /// be specified here to make memory allocation more efficient.  This
2507   /// constructor can also autoinsert before another instruction.
2508   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2509              Instruction *InsertBefore);
2510
2511   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2512   /// switch on and a default destination.  The number of additional cases can
2513   /// be specified here to make memory allocation more efficient.  This
2514   /// constructor also autoinserts at the end of the specified BasicBlock.
2515   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2516              BasicBlock *InsertAtEnd);
2517 protected:
2518   virtual SwitchInst *clone_impl() const;
2519 public:
2520   
2521   // FIXME: Currently there are a lot of unclean template parameters,
2522   // we need to make refactoring in future.
2523   // All these parameters are used to implement both iterator and const_iterator
2524   // without code duplication.
2525   // SwitchInstTy may be "const SwitchInst" or "SwitchInst"
2526   // ConstantIntTy may be "const ConstantInt" or "ConstantInt"
2527   // SubsetsItTy may be SubsetsConstIt or SubsetsIt
2528   // BasicBlockTy may be "const BasicBlock" or "BasicBlock"
2529   template <class SwitchInstTy, class ConstantIntTy,
2530             class SubsetsItTy, class BasicBlockTy> 
2531     class CaseIteratorT;
2532
2533   typedef CaseIteratorT<const SwitchInst, const ConstantInt,
2534                         SubsetsConstIt, const BasicBlock> ConstCaseIt;
2535   class CaseIt;
2536   
2537   // -2
2538   static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
2539   
2540   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2541                             unsigned NumCases, Instruction *InsertBefore = 0) {
2542     return new SwitchInst(Value, Default, NumCases, InsertBefore);
2543   }
2544   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2545                             unsigned NumCases, BasicBlock *InsertAtEnd) {
2546     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2547   }
2548   
2549   ~SwitchInst();
2550
2551   /// Provide fast operand accessors
2552   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2553
2554   // Accessor Methods for Switch stmt
2555   Value *getCondition() const { return getOperand(0); }
2556   void setCondition(Value *V) { setOperand(0, V); }
2557
2558   BasicBlock *getDefaultDest() const {
2559     return cast<BasicBlock>(getOperand(1));
2560   }
2561
2562   void setDefaultDest(BasicBlock *DefaultCase) {
2563     setOperand(1, reinterpret_cast<Value*>(DefaultCase));
2564   }
2565
2566   /// getNumCases - return the number of 'cases' in this switch instruction,
2567   /// except the default case
2568   unsigned getNumCases() const {
2569     return getNumOperands()/2 - 1;
2570   }
2571
2572   /// Returns a read/write iterator that points to the first
2573   /// case in SwitchInst.
2574   CaseIt case_begin() {
2575     return CaseIt(this, 0, TheSubsets.begin());
2576   }
2577   /// Returns a read-only iterator that points to the first
2578   /// case in the SwitchInst.
2579   ConstCaseIt case_begin() const {
2580     return ConstCaseIt(this, 0, TheSubsets.begin());
2581   }
2582   
2583   /// Returns a read/write iterator that points one past the last
2584   /// in the SwitchInst.
2585   CaseIt case_end() {
2586     return CaseIt(this, getNumCases(), TheSubsets.end());
2587   }
2588   /// Returns a read-only iterator that points one past the last
2589   /// in the SwitchInst.
2590   ConstCaseIt case_end() const {
2591     return ConstCaseIt(this, getNumCases(), TheSubsets.end());
2592   }
2593   /// Returns an iterator that points to the default case.
2594   /// Note: this iterator allows to resolve successor only. Attempt
2595   /// to resolve case value causes an assertion.
2596   /// Also note, that increment and decrement also causes an assertion and
2597   /// makes iterator invalid. 
2598   CaseIt case_default() {
2599     return CaseIt(this, DefaultPseudoIndex, TheSubsets.end());
2600   }
2601   ConstCaseIt case_default() const {
2602     return ConstCaseIt(this, DefaultPseudoIndex, TheSubsets.end());
2603   }
2604   
2605   /// findCaseValue - Search all of the case values for the specified constant.
2606   /// If it is explicitly handled, return the case iterator of it, otherwise
2607   /// return default case iterator to indicate
2608   /// that it is handled by the default handler.
2609   CaseIt findCaseValue(const ConstantInt *C) {
2610     for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
2611       if (i.getCaseValueEx().isSatisfies(IntItem::fromConstantInt(C)))
2612         return i;
2613     return case_default();
2614   }
2615   ConstCaseIt findCaseValue(const ConstantInt *C) const {
2616     for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
2617       if (i.getCaseValueEx().isSatisfies(IntItem::fromConstantInt(C)))
2618         return i;
2619     return case_default();
2620   }    
2621   
2622   /// findCaseDest - Finds the unique case value for a given successor. Returns
2623   /// null if the successor is not found, not unique, or is the default case.
2624   ConstantInt *findCaseDest(BasicBlock *BB) {
2625     if (BB == getDefaultDest()) return NULL;
2626
2627     ConstantInt *CI = NULL;
2628     for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
2629       if (i.getCaseSuccessor() == BB) {
2630         if (CI) return NULL;   // Multiple cases lead to BB.
2631         else CI = i.getCaseValue();
2632       }
2633     }
2634     return CI;
2635   }
2636
2637   /// addCase - Add an entry to the switch instruction...
2638   /// @deprecated
2639   /// Note:
2640   /// This action invalidates case_end(). Old case_end() iterator will
2641   /// point to the added case.
2642   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2643   
2644   /// addCase - Add an entry to the switch instruction.
2645   /// Note:
2646   /// This action invalidates case_end(). Old case_end() iterator will
2647   /// point to the added case.
2648   void addCase(IntegersSubset& OnVal, BasicBlock *Dest);
2649
2650   /// removeCase - This method removes the specified case and its successor
2651   /// from the switch instruction. Note that this operation may reorder the
2652   /// remaining cases at index idx and above.
2653   /// Note:
2654   /// This action invalidates iterators for all cases following the one removed,
2655   /// including the case_end() iterator.
2656   void removeCase(CaseIt& i);
2657
2658   unsigned getNumSuccessors() const { return getNumOperands()/2; }
2659   BasicBlock *getSuccessor(unsigned idx) const {
2660     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2661     return cast<BasicBlock>(getOperand(idx*2+1));
2662   }
2663   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2664     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2665     setOperand(idx*2+1, (Value*)NewSucc);
2666   }
2667   
2668   uint16_t hash() const {
2669     uint32_t NumberOfCases = (uint32_t)getNumCases();
2670     uint16_t Hash = (0xFFFF & NumberOfCases) ^ (NumberOfCases >> 16);
2671     for (ConstCaseIt i = case_begin(), e = case_end();
2672          i != e; ++i) {
2673       uint32_t NumItems = (uint32_t)i.getCaseValueEx().getNumItems(); 
2674       Hash = (Hash << 1) ^ (0xFFFF & NumItems) ^ (NumItems >> 16);
2675     }
2676     return Hash;
2677   }  
2678   
2679   // Case iterators definition.
2680
2681   template <class SwitchInstTy, class ConstantIntTy,
2682             class SubsetsItTy, class BasicBlockTy> 
2683   class CaseIteratorT {
2684   protected:
2685     
2686     SwitchInstTy *SI;
2687     unsigned long Index;
2688     SubsetsItTy SubsetIt;
2689     
2690     /// Initializes case iterator for given SwitchInst and for given
2691     /// case number.    
2692     friend class SwitchInst;
2693     CaseIteratorT(SwitchInstTy *SI, unsigned SuccessorIndex,
2694                   SubsetsItTy CaseValueIt) {
2695       this->SI = SI;
2696       Index = SuccessorIndex;
2697       this->SubsetIt = CaseValueIt;
2698     }
2699     
2700   public:
2701     typedef typename SubsetsItTy::reference IntegersSubsetRef;
2702     typedef CaseIteratorT<SwitchInstTy, ConstantIntTy,
2703                           SubsetsItTy, BasicBlockTy> Self;
2704     
2705     CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
2706           this->SI = SI;
2707           Index = CaseNum;
2708           SubsetIt = SI->TheSubsets.begin();
2709           std::advance(SubsetIt, CaseNum);
2710         }
2711         
2712     
2713     /// Initializes case iterator for given SwitchInst and for given
2714     /// TerminatorInst's successor index.
2715     static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
2716       assert(SuccessorIndex < SI->getNumSuccessors() &&
2717              "Successor index # out of range!");    
2718       return SuccessorIndex != 0 ? 
2719              Self(SI, SuccessorIndex - 1) :
2720              Self(SI, DefaultPseudoIndex);       
2721     }
2722     
2723     /// Resolves case value for current case.
2724     /// @deprecated
2725     ConstantIntTy *getCaseValue() {
2726       assert(Index < SI->getNumCases() && "Index out the number of cases.");
2727       IntegersSubsetRef CaseRanges = *SubsetIt;
2728       
2729       // FIXME: Currently we work with ConstantInt based cases.
2730       // So return CaseValue as ConstantInt.
2731       return CaseRanges.getSingleNumber(0).toConstantInt();
2732     }
2733
2734     /// Resolves case value for current case.
2735     IntegersSubsetRef getCaseValueEx() {
2736       assert(Index < SI->getNumCases() && "Index out the number of cases.");
2737       return *SubsetIt;
2738     }
2739     
2740     /// Resolves successor for current case.
2741     BasicBlockTy *getCaseSuccessor() {
2742       assert((Index < SI->getNumCases() ||
2743               Index == DefaultPseudoIndex) &&
2744              "Index out the number of cases.");
2745       return SI->getSuccessor(getSuccessorIndex());      
2746     }
2747     
2748     /// Returns number of current case.
2749     unsigned getCaseIndex() const { return Index; }
2750     
2751     /// Returns TerminatorInst's successor index for current case successor.
2752     unsigned getSuccessorIndex() const {
2753       assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
2754              "Index out the number of cases.");
2755       return Index != DefaultPseudoIndex ? Index + 1 : 0;
2756     }
2757     
2758     Self operator++() {
2759       // Check index correctness after increment.
2760       // Note: Index == getNumCases() means end().
2761       assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
2762       ++Index;
2763       if (Index == 0)
2764         SubsetIt = SI->TheSubsets.begin();
2765       else
2766         ++SubsetIt;
2767       return *this;
2768     }
2769     Self operator++(int) {
2770       Self tmp = *this;
2771       ++(*this);
2772       return tmp;
2773     }
2774     Self operator--() { 
2775       // Check index correctness after decrement.
2776       // Note: Index == getNumCases() means end().
2777       // Also allow "-1" iterator here. That will became valid after ++.
2778       unsigned NumCases = SI->getNumCases();
2779       assert((Index == 0 || Index-1 <= NumCases) &&
2780              "Index out the number of cases.");
2781       --Index;
2782       if (Index == NumCases) {
2783         SubsetIt = SI->TheSubsets.end();
2784         return *this;
2785       }
2786         
2787       if (Index != -1UL)
2788         --SubsetIt;
2789       
2790       return *this;
2791     }
2792     Self operator--(int) {
2793       Self tmp = *this;
2794       --(*this);
2795       return tmp;
2796     }
2797     bool operator==(const Self& RHS) const {
2798       assert(RHS.SI == SI && "Incompatible operators.");
2799       return RHS.Index == Index;
2800     }
2801     bool operator!=(const Self& RHS) const {
2802       assert(RHS.SI == SI && "Incompatible operators.");
2803       return RHS.Index != Index;
2804     }
2805   };
2806
2807   class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt,
2808                                       SubsetsIt, BasicBlock> {
2809     typedef CaseIteratorT<SwitchInst, ConstantInt, SubsetsIt, BasicBlock>
2810       ParentTy;
2811     
2812   protected:
2813     friend class SwitchInst;
2814     CaseIt(SwitchInst *SI, unsigned CaseNum, SubsetsIt SubsetIt) :
2815       ParentTy(SI, CaseNum, SubsetIt) {}
2816     
2817     void updateCaseValueOperand(IntegersSubset& V) {
2818       SI->setOperand(2 + Index*2, reinterpret_cast<Value*>((Constant*)V));      
2819     }
2820   
2821   public:
2822
2823     CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}    
2824     
2825     CaseIt(const ParentTy& Src) : ParentTy(Src) {}
2826
2827     /// Sets the new value for current case.    
2828     /// @deprecated.
2829     void setValue(ConstantInt *V) {
2830       assert(Index < SI->getNumCases() && "Index out the number of cases.");
2831       IntegersSubsetToBB Mapping;
2832       // FIXME: Currently we work with ConstantInt based cases.
2833       // So inititalize IntItem container directly from ConstantInt.
2834       Mapping.add(IntItem::fromConstantInt(V));
2835       *SubsetIt = Mapping.getCase();
2836       updateCaseValueOperand(*SubsetIt);
2837     }
2838     
2839     /// Sets the new value for current case.
2840     void setValueEx(IntegersSubset& V) {
2841       assert(Index < SI->getNumCases() && "Index out the number of cases.");
2842       *SubsetIt = V;
2843       updateCaseValueOperand(*SubsetIt);   
2844     }
2845     
2846     /// Sets the new successor for current case.
2847     void setSuccessor(BasicBlock *S) {
2848       SI->setSuccessor(getSuccessorIndex(), S);      
2849     }
2850   };
2851
2852   // Methods for support type inquiry through isa, cast, and dyn_cast:
2853
2854   static inline bool classof(const SwitchInst *) { return true; }
2855   static inline bool classof(const Instruction *I) {
2856     return I->getOpcode() == Instruction::Switch;
2857   }
2858   static inline bool classof(const Value *V) {
2859     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2860   }
2861 private:
2862   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2863   virtual unsigned getNumSuccessorsV() const;
2864   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2865 };
2866
2867 template <>
2868 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2869 };
2870
2871 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2872
2873
2874 //===----------------------------------------------------------------------===//
2875 //                             IndirectBrInst Class
2876 //===----------------------------------------------------------------------===//
2877
2878 //===---------------------------------------------------------------------------
2879 /// IndirectBrInst - Indirect Branch Instruction.
2880 ///
2881 class IndirectBrInst : public TerminatorInst {
2882   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
2883   unsigned ReservedSpace;
2884   // Operand[0]    = Value to switch on
2885   // Operand[1]    = Default basic block destination
2886   // Operand[2n  ] = Value to match
2887   // Operand[2n+1] = BasicBlock to go to on match
2888   IndirectBrInst(const IndirectBrInst &IBI);
2889   void init(Value *Address, unsigned NumDests);
2890   void growOperands();
2891   // allocate space for exactly zero operands
2892   void *operator new(size_t s) {
2893     return User::operator new(s, 0);
2894   }
2895   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2896   /// Address to jump to.  The number of expected destinations can be specified
2897   /// here to make memory allocation more efficient.  This constructor can also
2898   /// autoinsert before another instruction.
2899   IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2900
2901   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2902   /// Address to jump to.  The number of expected destinations can be specified
2903   /// here to make memory allocation more efficient.  This constructor also
2904   /// autoinserts at the end of the specified BasicBlock.
2905   IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2906 protected:
2907   virtual IndirectBrInst *clone_impl() const;
2908 public:
2909   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2910                                 Instruction *InsertBefore = 0) {
2911     return new IndirectBrInst(Address, NumDests, InsertBefore);
2912   }
2913   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2914                                 BasicBlock *InsertAtEnd) {
2915     return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2916   }
2917   ~IndirectBrInst();
2918
2919   /// Provide fast operand accessors.
2920   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2921
2922   // Accessor Methods for IndirectBrInst instruction.
2923   Value *getAddress() { return getOperand(0); }
2924   const Value *getAddress() const { return getOperand(0); }
2925   void setAddress(Value *V) { setOperand(0, V); }
2926
2927
2928   /// getNumDestinations - return the number of possible destinations in this
2929   /// indirectbr instruction.
2930   unsigned getNumDestinations() const { return getNumOperands()-1; }
2931
2932   /// getDestination - Return the specified destination.
2933   BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2934   const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2935
2936   /// addDestination - Add a destination.
2937   ///
2938   void addDestination(BasicBlock *Dest);
2939
2940   /// removeDestination - This method removes the specified successor from the
2941   /// indirectbr instruction.
2942   void removeDestination(unsigned i);
2943
2944   unsigned getNumSuccessors() const { return getNumOperands()-1; }
2945   BasicBlock *getSuccessor(unsigned i) const {
2946     return cast<BasicBlock>(getOperand(i+1));
2947   }
2948   void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2949     setOperand(i+1, (Value*)NewSucc);
2950   }
2951
2952   // Methods for support type inquiry through isa, cast, and dyn_cast:
2953   static inline bool classof(const IndirectBrInst *) { return true; }
2954   static inline bool classof(const Instruction *I) {
2955     return I->getOpcode() == Instruction::IndirectBr;
2956   }
2957   static inline bool classof(const Value *V) {
2958     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2959   }
2960 private:
2961   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2962   virtual unsigned getNumSuccessorsV() const;
2963   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2964 };
2965
2966 template <>
2967 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2968 };
2969
2970 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2971
2972
2973 //===----------------------------------------------------------------------===//
2974 //                               InvokeInst Class
2975 //===----------------------------------------------------------------------===//
2976
2977 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
2978 /// calling convention of the call.
2979 ///
2980 class InvokeInst : public TerminatorInst {
2981   AttrListPtr AttributeList;
2982   InvokeInst(const InvokeInst &BI);
2983   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2984             ArrayRef<Value *> Args, const Twine &NameStr);
2985
2986   /// Construct an InvokeInst given a range of arguments.
2987   ///
2988   /// @brief Construct an InvokeInst from a range of arguments
2989   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2990                     ArrayRef<Value *> Args, unsigned Values,
2991                     const Twine &NameStr, Instruction *InsertBefore);
2992
2993   /// Construct an InvokeInst given a range of arguments.
2994   ///
2995   /// @brief Construct an InvokeInst from a range of arguments
2996   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2997                     ArrayRef<Value *> Args, unsigned Values,
2998                     const Twine &NameStr, BasicBlock *InsertAtEnd);
2999 protected:
3000   virtual InvokeInst *clone_impl() const;
3001 public:
3002   static InvokeInst *Create(Value *Func,
3003                             BasicBlock *IfNormal, BasicBlock *IfException,
3004                             ArrayRef<Value *> Args, const Twine &NameStr = "",
3005                             Instruction *InsertBefore = 0) {
3006     unsigned Values = unsigned(Args.size()) + 3;
3007     return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
3008                                   Values, NameStr, InsertBefore);
3009   }
3010   static InvokeInst *Create(Value *Func,
3011                             BasicBlock *IfNormal, BasicBlock *IfException,
3012                             ArrayRef<Value *> Args, const Twine &NameStr,
3013                             BasicBlock *InsertAtEnd) {
3014     unsigned Values = unsigned(Args.size()) + 3;
3015     return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
3016                                   Values, NameStr, InsertAtEnd);
3017   }
3018
3019   /// Provide fast operand accessors
3020   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3021
3022   /// getNumArgOperands - Return the number of invoke arguments.
3023   ///
3024   unsigned getNumArgOperands() const { return getNumOperands() - 3; }
3025
3026   /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
3027   ///
3028   Value *getArgOperand(unsigned i) const { return getOperand(i); }
3029   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
3030
3031   /// getCallingConv/setCallingConv - Get or set the calling convention of this
3032   /// function call.
3033   CallingConv::ID getCallingConv() const {
3034     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
3035   }
3036   void setCallingConv(CallingConv::ID CC) {
3037     setInstructionSubclassData(static_cast<unsigned>(CC));
3038   }
3039
3040   /// getAttributes - Return the parameter attributes for this invoke.
3041   ///
3042   const AttrListPtr &getAttributes() const { return AttributeList; }
3043
3044   /// setAttributes - Set the parameter attributes for this invoke.
3045   ///
3046   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
3047
3048   /// addAttribute - adds the attribute to the list of attributes.
3049   void addAttribute(unsigned i, Attributes attr);
3050
3051   /// removeAttribute - removes the attribute from the list of attributes.
3052   void removeAttribute(unsigned i, Attributes attr);
3053
3054   /// @brief Determine whether this call has the NoAlias attribute.
3055   bool fnHasNoAliasAttr() const;
3056   bool fnHasNoInlineAttr() const;
3057   bool fnHasNoReturnAttr() const;
3058   bool fnHasNoUnwindAttr() const;
3059   bool fnHasReadNoneAttr() const;
3060   bool fnHasReadOnlyAttr() const;
3061   bool fnHasReturnsTwiceAttr() const;
3062
3063   /// \brief Return true if this call has the given attribute.
3064   bool hasFnAttr(Attributes N) const {
3065     return paramHasAttr(~0, N);
3066   }
3067
3068   /// @brief Determine whether the call or the callee has the given attributes.
3069   bool paramHasSExtAttr(unsigned i) const;
3070   bool paramHasZExtAttr(unsigned i) const;
3071   bool paramHasInRegAttr(unsigned i) const;
3072   bool paramHasStructRetAttr(unsigned i) const;
3073   bool paramHasNestAttr(unsigned i) const;
3074   bool paramHasByValAttr(unsigned i) const;
3075   bool paramHasNoAliasAttr(unsigned i) const;
3076   bool paramHasNoCaptureAttr(unsigned i) const;
3077
3078   /// @brief Determine whether the call or the callee has the given attribute.
3079   bool paramHasAttr(unsigned i, Attributes attr) const;
3080
3081   /// @brief Extract the alignment for a call or parameter (0=unknown).
3082   unsigned getParamAlignment(unsigned i) const {
3083     return AttributeList.getParamAlignment(i);
3084   }
3085
3086   /// @brief Return true if the call should not be inlined.
3087   bool isNoInline() const { return fnHasNoInlineAttr(); }
3088   void setIsNoInline(bool Value = true) {
3089     if (Value) addAttribute(~0, Attribute::NoInline);
3090     else removeAttribute(~0, Attribute::NoInline);
3091   }
3092
3093   /// @brief Determine if the call does not access memory.
3094   bool doesNotAccessMemory() const {
3095     return fnHasReadNoneAttr();
3096   }
3097   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
3098     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
3099     else removeAttribute(~0, Attribute::ReadNone);
3100   }
3101
3102   /// @brief Determine if the call does not access or only reads memory.
3103   bool onlyReadsMemory() const {
3104     return doesNotAccessMemory() || fnHasReadOnlyAttr();
3105   }
3106   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
3107     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
3108     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
3109   }
3110
3111   /// @brief Determine if the call cannot return.
3112   bool doesNotReturn() const { return fnHasNoReturnAttr(); }
3113   void setDoesNotReturn(bool DoesNotReturn = true) {
3114     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
3115     else removeAttribute(~0, Attribute::NoReturn);
3116   }
3117
3118   /// @brief Determine if the call cannot unwind.
3119   bool doesNotThrow() const { return fnHasNoUnwindAttr(); }
3120   void setDoesNotThrow(bool DoesNotThrow = true) {
3121     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
3122     else removeAttribute(~0, Attribute::NoUnwind);
3123   }
3124
3125   /// @brief Determine if the call returns a structure through first
3126   /// pointer argument.
3127   bool hasStructRetAttr() const {
3128     // Be friendly and also check the callee.
3129     return paramHasStructRetAttr(1);
3130   }
3131
3132   /// @brief Determine if any call argument is an aggregate passed by value.
3133   bool hasByValArgument() const {
3134     for (unsigned I = 0, E = AttributeList.getNumAttrs(); I != E; ++I)
3135       if (AttributeList.getAttributesAtIndex(I).hasByValAttr())
3136         return true;
3137     return false;
3138   }
3139
3140   /// getCalledFunction - Return the function called, or null if this is an
3141   /// indirect function invocation.
3142   ///
3143   Function *getCalledFunction() const {
3144     return dyn_cast<Function>(Op<-3>());
3145   }
3146
3147   /// getCalledValue - Get a pointer to the function that is invoked by this
3148   /// instruction
3149   const Value *getCalledValue() const { return Op<-3>(); }
3150         Value *getCalledValue()       { return Op<-3>(); }
3151
3152   /// setCalledFunction - Set the function called.
3153   void setCalledFunction(Value* Fn) {
3154     Op<-3>() = Fn;
3155   }
3156
3157   // get*Dest - Return the destination basic blocks...
3158   BasicBlock *getNormalDest() const {
3159     return cast<BasicBlock>(Op<-2>());
3160   }
3161   BasicBlock *getUnwindDest() const {
3162     return cast<BasicBlock>(Op<-1>());
3163   }
3164   void setNormalDest(BasicBlock *B) {
3165     Op<-2>() = reinterpret_cast<Value*>(B);
3166   }
3167   void setUnwindDest(BasicBlock *B) {
3168     Op<-1>() = reinterpret_cast<Value*>(B);
3169   }
3170
3171   /// getLandingPadInst - Get the landingpad instruction from the landing pad
3172   /// block (the unwind destination).
3173   LandingPadInst *getLandingPadInst() const;
3174
3175   BasicBlock *getSuccessor(unsigned i) const {
3176     assert(i < 2 && "Successor # out of range for invoke!");
3177     return i == 0 ? getNormalDest() : getUnwindDest();
3178   }
3179
3180   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3181     assert(idx < 2 && "Successor # out of range for invoke!");
3182     *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
3183   }
3184
3185   unsigned getNumSuccessors() const { return 2; }
3186
3187   // Methods for support type inquiry through isa, cast, and dyn_cast:
3188   static inline bool classof(const InvokeInst *) { return true; }
3189   static inline bool classof(const Instruction *I) {
3190     return (I->getOpcode() == Instruction::Invoke);
3191   }
3192   static inline bool classof(const Value *V) {
3193     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3194   }
3195
3196 private:
3197   virtual BasicBlock *getSuccessorV(unsigned idx) const;
3198   virtual unsigned getNumSuccessorsV() const;
3199   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3200
3201   // Shadow Instruction::setInstructionSubclassData with a private forwarding
3202   // method so that subclasses cannot accidentally use it.
3203   void setInstructionSubclassData(unsigned short D) {
3204     Instruction::setInstructionSubclassData(D);
3205   }
3206 };
3207
3208 template <>
3209 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
3210 };
3211
3212 InvokeInst::InvokeInst(Value *Func,
3213                        BasicBlock *IfNormal, BasicBlock *IfException,
3214                        ArrayRef<Value *> Args, unsigned Values,
3215                        const Twine &NameStr, Instruction *InsertBefore)
3216   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3217                                       ->getElementType())->getReturnType(),
3218                    Instruction::Invoke,
3219                    OperandTraits<InvokeInst>::op_end(this) - Values,
3220                    Values, InsertBefore) {
3221   init(Func, IfNormal, IfException, Args, NameStr);
3222 }
3223 InvokeInst::InvokeInst(Value *Func,
3224                        BasicBlock *IfNormal, BasicBlock *IfException,
3225                        ArrayRef<Value *> Args, unsigned Values,
3226                        const Twine &NameStr, BasicBlock *InsertAtEnd)
3227   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
3228                                       ->getElementType())->getReturnType(),
3229                    Instruction::Invoke,
3230                    OperandTraits<InvokeInst>::op_end(this) - Values,
3231                    Values, InsertAtEnd) {
3232   init(Func, IfNormal, IfException, Args, NameStr);
3233 }
3234
3235 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
3236
3237 //===----------------------------------------------------------------------===//
3238 //                              ResumeInst Class
3239 //===----------------------------------------------------------------------===//
3240
3241 //===---------------------------------------------------------------------------
3242 /// ResumeInst - Resume the propagation of an exception.
3243 ///
3244 class ResumeInst : public TerminatorInst {
3245   ResumeInst(const ResumeInst &RI);
3246
3247   explicit ResumeInst(Value *Exn, Instruction *InsertBefore=0);
3248   ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
3249 protected:
3250   virtual ResumeInst *clone_impl() const;
3251 public:
3252   static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = 0) {
3253     return new(1) ResumeInst(Exn, InsertBefore);
3254   }
3255   static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
3256     return new(1) ResumeInst(Exn, InsertAtEnd);
3257   }
3258
3259   /// Provide fast operand accessors
3260   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3261
3262   /// Convenience accessor.
3263   Value *getValue() const { return Op<0>(); }
3264
3265   unsigned getNumSuccessors() const { return 0; }
3266
3267   // Methods for support type inquiry through isa, cast, and dyn_cast:
3268   static inline bool classof(const ResumeInst *) { return true; }
3269   static inline bool classof(const Instruction *I) {
3270     return I->getOpcode() == Instruction::Resume;
3271   }
3272   static inline bool classof(const Value *V) {
3273     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3274   }
3275 private:
3276   virtual BasicBlock *getSuccessorV(unsigned idx) const;
3277   virtual unsigned getNumSuccessorsV() const;
3278   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3279 };
3280
3281 template <>
3282 struct OperandTraits<ResumeInst> :
3283     public FixedNumOperandTraits<ResumeInst, 1> {
3284 };
3285
3286 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
3287
3288 //===----------------------------------------------------------------------===//
3289 //                           UnreachableInst Class
3290 //===----------------------------------------------------------------------===//
3291
3292 //===---------------------------------------------------------------------------
3293 /// UnreachableInst - This function has undefined behavior.  In particular, the
3294 /// presence of this instruction indicates some higher level knowledge that the
3295 /// end of the block cannot be reached.
3296 ///
3297 class UnreachableInst : public TerminatorInst {
3298   void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
3299 protected:
3300   virtual UnreachableInst *clone_impl() const;
3301
3302 public:
3303   // allocate space for exactly zero operands
3304   void *operator new(size_t s) {
3305     return User::operator new(s, 0);
3306   }
3307   explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
3308   explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
3309
3310   unsigned getNumSuccessors() const { return 0; }
3311
3312   // Methods for support type inquiry through isa, cast, and dyn_cast:
3313   static inline bool classof(const UnreachableInst *) { return true; }
3314   static inline bool classof(const Instruction *I) {
3315     return I->getOpcode() == Instruction::Unreachable;
3316   }
3317   static inline bool classof(const Value *V) {
3318     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3319   }
3320 private:
3321   virtual BasicBlock *getSuccessorV(unsigned idx) const;
3322   virtual unsigned getNumSuccessorsV() const;
3323   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
3324 };
3325
3326 //===----------------------------------------------------------------------===//
3327 //                                 TruncInst Class
3328 //===----------------------------------------------------------------------===//
3329
3330 /// @brief This class represents a truncation of integer types.
3331 class TruncInst : public CastInst {
3332 protected:
3333   /// @brief Clone an identical TruncInst
3334   virtual TruncInst *clone_impl() const;
3335
3336 public:
3337   /// @brief Constructor with insert-before-instruction semantics
3338   TruncInst(
3339     Value *S,                     ///< The value to be truncated
3340     Type *Ty,               ///< The (smaller) type to truncate to
3341     const Twine &NameStr = "",    ///< A name for the new instruction
3342     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3343   );
3344
3345   /// @brief Constructor with insert-at-end-of-block semantics
3346   TruncInst(
3347     Value *S,                     ///< The value to be truncated
3348     Type *Ty,               ///< The (smaller) type to truncate to
3349     const Twine &NameStr,         ///< A name for the new instruction
3350     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3351   );
3352
3353   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3354   static inline bool classof(const TruncInst *) { return true; }
3355   static inline bool classof(const Instruction *I) {
3356     return I->getOpcode() == Trunc;
3357   }
3358   static inline bool classof(const Value *V) {
3359     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3360   }
3361 };
3362
3363 //===----------------------------------------------------------------------===//
3364 //                                 ZExtInst Class
3365 //===----------------------------------------------------------------------===//
3366
3367 /// @brief This class represents zero extension of integer types.
3368 class ZExtInst : public CastInst {
3369 protected:
3370   /// @brief Clone an identical ZExtInst
3371   virtual ZExtInst *clone_impl() const;
3372
3373 public:
3374   /// @brief Constructor with insert-before-instruction semantics
3375   ZExtInst(
3376     Value *S,                     ///< The value to be zero extended
3377     Type *Ty,               ///< The type to zero extend to
3378     const Twine &NameStr = "",    ///< A name for the new instruction
3379     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3380   );
3381
3382   /// @brief Constructor with insert-at-end semantics.
3383   ZExtInst(
3384     Value *S,                     ///< The value to be zero extended
3385     Type *Ty,               ///< The type to zero extend to
3386     const Twine &NameStr,         ///< A name for the new instruction
3387     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3388   );
3389
3390   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3391   static inline bool classof(const ZExtInst *) { return true; }
3392   static inline bool classof(const Instruction *I) {
3393     return I->getOpcode() == ZExt;
3394   }
3395   static inline bool classof(const Value *V) {
3396     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3397   }
3398 };
3399
3400 //===----------------------------------------------------------------------===//
3401 //                                 SExtInst Class
3402 //===----------------------------------------------------------------------===//
3403
3404 /// @brief This class represents a sign extension of integer types.
3405 class SExtInst : public CastInst {
3406 protected:
3407   /// @brief Clone an identical SExtInst
3408   virtual SExtInst *clone_impl() const;
3409
3410 public:
3411   /// @brief Constructor with insert-before-instruction semantics
3412   SExtInst(
3413     Value *S,                     ///< The value to be sign extended
3414     Type *Ty,               ///< The type to sign extend to
3415     const Twine &NameStr = "",    ///< A name for the new instruction
3416     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3417   );
3418
3419   /// @brief Constructor with insert-at-end-of-block semantics
3420   SExtInst(
3421     Value *S,                     ///< The value to be sign extended
3422     Type *Ty,               ///< The type to sign extend to
3423     const Twine &NameStr,         ///< A name for the new instruction
3424     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3425   );
3426
3427   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3428   static inline bool classof(const SExtInst *) { return true; }
3429   static inline bool classof(const Instruction *I) {
3430     return I->getOpcode() == SExt;
3431   }
3432   static inline bool classof(const Value *V) {
3433     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3434   }
3435 };
3436
3437 //===----------------------------------------------------------------------===//
3438 //                                 FPTruncInst Class
3439 //===----------------------------------------------------------------------===//
3440
3441 /// @brief This class represents a truncation of floating point types.
3442 class FPTruncInst : public CastInst {
3443 protected:
3444   /// @brief Clone an identical FPTruncInst
3445   virtual FPTruncInst *clone_impl() const;
3446
3447 public:
3448   /// @brief Constructor with insert-before-instruction semantics
3449   FPTruncInst(
3450     Value *S,                     ///< The value to be truncated
3451     Type *Ty,               ///< The type to truncate to
3452     const Twine &NameStr = "",    ///< A name for the new instruction
3453     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3454   );
3455
3456   /// @brief Constructor with insert-before-instruction semantics
3457   FPTruncInst(
3458     Value *S,                     ///< The value to be truncated
3459     Type *Ty,               ///< The type to truncate to
3460     const Twine &NameStr,         ///< A name for the new instruction
3461     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3462   );
3463
3464   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3465   static inline bool classof(const FPTruncInst *) { return true; }
3466   static inline bool classof(const Instruction *I) {
3467     return I->getOpcode() == FPTrunc;
3468   }
3469   static inline bool classof(const Value *V) {
3470     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3471   }
3472 };
3473
3474 //===----------------------------------------------------------------------===//
3475 //                                 FPExtInst Class
3476 //===----------------------------------------------------------------------===//
3477
3478 /// @brief This class represents an extension of floating point types.
3479 class FPExtInst : public CastInst {
3480 protected:
3481   /// @brief Clone an identical FPExtInst
3482   virtual FPExtInst *clone_impl() const;
3483
3484 public:
3485   /// @brief Constructor with insert-before-instruction semantics
3486   FPExtInst(
3487     Value *S,                     ///< The value to be extended
3488     Type *Ty,               ///< The type to extend to
3489     const Twine &NameStr = "",    ///< A name for the new instruction
3490     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3491   );
3492
3493   /// @brief Constructor with insert-at-end-of-block semantics
3494   FPExtInst(
3495     Value *S,                     ///< The value to be extended
3496     Type *Ty,               ///< The type to extend to
3497     const Twine &NameStr,         ///< A name for the new instruction
3498     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3499   );
3500
3501   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3502   static inline bool classof(const FPExtInst *) { return true; }
3503   static inline bool classof(const Instruction *I) {
3504     return I->getOpcode() == FPExt;
3505   }
3506   static inline bool classof(const Value *V) {
3507     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3508   }
3509 };
3510
3511 //===----------------------------------------------------------------------===//
3512 //                                 UIToFPInst Class
3513 //===----------------------------------------------------------------------===//
3514
3515 /// @brief This class represents a cast unsigned integer to floating point.
3516 class UIToFPInst : public CastInst {
3517 protected:
3518   /// @brief Clone an identical UIToFPInst
3519   virtual UIToFPInst *clone_impl() const;
3520
3521 public:
3522   /// @brief Constructor with insert-before-instruction semantics
3523   UIToFPInst(
3524     Value *S,                     ///< The value to be converted
3525     Type *Ty,               ///< The type to convert to
3526     const Twine &NameStr = "",    ///< A name for the new instruction
3527     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3528   );
3529
3530   /// @brief Constructor with insert-at-end-of-block semantics
3531   UIToFPInst(
3532     Value *S,                     ///< The value to be converted
3533     Type *Ty,               ///< The type to convert to
3534     const Twine &NameStr,         ///< A name for the new instruction
3535     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3536   );
3537
3538   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3539   static inline bool classof(const UIToFPInst *) { return true; }
3540   static inline bool classof(const Instruction *I) {
3541     return I->getOpcode() == UIToFP;
3542   }
3543   static inline bool classof(const Value *V) {
3544     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3545   }
3546 };
3547
3548 //===----------------------------------------------------------------------===//
3549 //                                 SIToFPInst Class
3550 //===----------------------------------------------------------------------===//
3551
3552 /// @brief This class represents a cast from signed integer to floating point.
3553 class SIToFPInst : public CastInst {
3554 protected:
3555   /// @brief Clone an identical SIToFPInst
3556   virtual SIToFPInst *clone_impl() const;
3557
3558 public:
3559   /// @brief Constructor with insert-before-instruction semantics
3560   SIToFPInst(
3561     Value *S,                     ///< The value to be converted
3562     Type *Ty,               ///< The type to convert to
3563     const Twine &NameStr = "",    ///< A name for the new instruction
3564     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3565   );
3566
3567   /// @brief Constructor with insert-at-end-of-block semantics
3568   SIToFPInst(
3569     Value *S,                     ///< The value to be converted
3570     Type *Ty,               ///< The type to convert to
3571     const Twine &NameStr,         ///< A name for the new instruction
3572     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3573   );
3574
3575   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3576   static inline bool classof(const SIToFPInst *) { return true; }
3577   static inline bool classof(const Instruction *I) {
3578     return I->getOpcode() == SIToFP;
3579   }
3580   static inline bool classof(const Value *V) {
3581     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3582   }
3583 };
3584
3585 //===----------------------------------------------------------------------===//
3586 //                                 FPToUIInst Class
3587 //===----------------------------------------------------------------------===//
3588
3589 /// @brief This class represents a cast from floating point to unsigned integer
3590 class FPToUIInst  : public CastInst {
3591 protected:
3592   /// @brief Clone an identical FPToUIInst
3593   virtual FPToUIInst *clone_impl() const;
3594
3595 public:
3596   /// @brief Constructor with insert-before-instruction semantics
3597   FPToUIInst(
3598     Value *S,                     ///< The value to be converted
3599     Type *Ty,               ///< The type to convert to
3600     const Twine &NameStr = "",    ///< A name for the new instruction
3601     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3602   );
3603
3604   /// @brief Constructor with insert-at-end-of-block semantics
3605   FPToUIInst(
3606     Value *S,                     ///< The value to be converted
3607     Type *Ty,               ///< The type to convert to
3608     const Twine &NameStr,         ///< A name for the new instruction
3609     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
3610   );
3611
3612   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3613   static inline bool classof(const FPToUIInst *) { return true; }
3614   static inline bool classof(const Instruction *I) {
3615     return I->getOpcode() == FPToUI;
3616   }
3617   static inline bool classof(const Value *V) {
3618     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3619   }
3620 };
3621
3622 //===----------------------------------------------------------------------===//
3623 //                                 FPToSIInst Class
3624 //===----------------------------------------------------------------------===//
3625
3626 /// @brief This class represents a cast from floating point to signed integer.
3627 class FPToSIInst  : public CastInst {
3628 protected:
3629   /// @brief Clone an identical FPToSIInst
3630   virtual FPToSIInst *clone_impl() const;
3631
3632 public:
3633   /// @brief Constructor with insert-before-instruction semantics
3634   FPToSIInst(
3635     Value *S,                     ///< The value to be converted
3636     Type *Ty,               ///< The type to convert to
3637     const Twine &NameStr = "",    ///< A name for the new instruction
3638     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3639   );
3640
3641   /// @brief Constructor with insert-at-end-of-block semantics
3642   FPToSIInst(
3643     Value *S,                     ///< The value to be converted
3644     Type *Ty,               ///< The type to convert to
3645     const Twine &NameStr,         ///< A name for the new instruction
3646     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3647   );
3648
3649   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3650   static inline bool classof(const FPToSIInst *) { return true; }
3651   static inline bool classof(const Instruction *I) {
3652     return I->getOpcode() == FPToSI;
3653   }
3654   static inline bool classof(const Value *V) {
3655     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3656   }
3657 };
3658
3659 //===----------------------------------------------------------------------===//
3660 //                                 IntToPtrInst Class
3661 //===----------------------------------------------------------------------===//
3662
3663 /// @brief This class represents a cast from an integer to a pointer.
3664 class IntToPtrInst : public CastInst {
3665 public:
3666   /// @brief Constructor with insert-before-instruction semantics
3667   IntToPtrInst(
3668     Value *S,                     ///< The value to be converted
3669     Type *Ty,               ///< The type to convert to
3670     const Twine &NameStr = "",    ///< A name for the new instruction
3671     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3672   );
3673
3674   /// @brief Constructor with insert-at-end-of-block semantics
3675   IntToPtrInst(
3676     Value *S,                     ///< The value to be converted
3677     Type *Ty,               ///< The type to convert to
3678     const Twine &NameStr,         ///< A name for the new instruction
3679     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3680   );
3681
3682   /// @brief Clone an identical IntToPtrInst
3683   virtual IntToPtrInst *clone_impl() const;
3684
3685   // Methods for support type inquiry through isa, cast, and dyn_cast:
3686   static inline bool classof(const IntToPtrInst *) { return true; }
3687   static inline bool classof(const Instruction *I) {
3688     return I->getOpcode() == IntToPtr;
3689   }
3690   static inline bool classof(const Value *V) {
3691     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3692   }
3693 };
3694
3695 //===----------------------------------------------------------------------===//
3696 //                                 PtrToIntInst Class
3697 //===----------------------------------------------------------------------===//
3698
3699 /// @brief This class represents a cast from a pointer to an integer
3700 class PtrToIntInst : public CastInst {
3701 protected:
3702   /// @brief Clone an identical PtrToIntInst
3703   virtual PtrToIntInst *clone_impl() const;
3704
3705 public:
3706   /// @brief Constructor with insert-before-instruction semantics
3707   PtrToIntInst(
3708     Value *S,                     ///< The value to be converted
3709     Type *Ty,               ///< The type to convert to
3710     const Twine &NameStr = "",    ///< A name for the new instruction
3711     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3712   );
3713
3714   /// @brief Constructor with insert-at-end-of-block semantics
3715   PtrToIntInst(
3716     Value *S,                     ///< The value to be converted
3717     Type *Ty,               ///< The type to convert to
3718     const Twine &NameStr,         ///< A name for the new instruction
3719     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3720   );
3721
3722   // Methods for support type inquiry through isa, cast, and dyn_cast:
3723   static inline bool classof(const PtrToIntInst *) { return true; }
3724   static inline bool classof(const Instruction *I) {
3725     return I->getOpcode() == PtrToInt;
3726   }
3727   static inline bool classof(const Value *V) {
3728     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3729   }
3730 };
3731
3732 //===----------------------------------------------------------------------===//
3733 //                             BitCastInst Class
3734 //===----------------------------------------------------------------------===//
3735
3736 /// @brief This class represents a no-op cast from one type to another.
3737 class BitCastInst : public CastInst {
3738 protected:
3739   /// @brief Clone an identical BitCastInst
3740   virtual BitCastInst *clone_impl() const;
3741
3742 public:
3743   /// @brief Constructor with insert-before-instruction semantics
3744   BitCastInst(
3745     Value *S,                     ///< The value to be casted
3746     Type *Ty,               ///< The type to casted to
3747     const Twine &NameStr = "",    ///< A name for the new instruction
3748     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3749   );
3750
3751   /// @brief Constructor with insert-at-end-of-block semantics
3752   BitCastInst(
3753     Value *S,                     ///< The value to be casted
3754     Type *Ty,               ///< The type to casted to
3755     const Twine &NameStr,         ///< A name for the new instruction
3756     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3757   );
3758
3759   // Methods for support type inquiry through isa, cast, and dyn_cast:
3760   static inline bool classof(const BitCastInst *) { return true; }
3761   static inline bool classof(const Instruction *I) {
3762     return I->getOpcode() == BitCast;
3763   }
3764   static inline bool classof(const Value *V) {
3765     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3766   }
3767 };
3768
3769 } // End llvm namespace
3770
3771 #endif