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