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