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