Clean up uses of switch instructions so they are not dependent on the operand orderin...
[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   inline op_iterator       idx_begin()       { return op_begin()+1; }
780   inline const_op_iterator idx_begin() const { return op_begin()+1; }
781   inline op_iterator       idx_end()         { return op_end(); }
782   inline const_op_iterator idx_end()   const { return op_end(); }
783
784   Value *getPointerOperand() {
785     return getOperand(0);
786   }
787   const Value *getPointerOperand() const {
788     return getOperand(0);
789   }
790   static unsigned getPointerOperandIndex() {
791     return 0U;                      // get index for modifying correct operand
792   }
793
794   unsigned getPointerAddressSpace() const {
795     return cast<PointerType>(getType())->getAddressSpace();
796   }
797
798   /// getPointerOperandType - Method to return the pointer operand as a
799   /// PointerType.
800   PointerType *getPointerOperandType() const {
801     return reinterpret_cast<PointerType*>(getPointerOperand()->getType());
802   }
803
804
805   unsigned getNumIndices() const {  // Note: always non-negative
806     return getNumOperands() - 1;
807   }
808
809   bool hasIndices() const {
810     return getNumOperands() > 1;
811   }
812
813   /// hasAllZeroIndices - Return true if all of the indices of this GEP are
814   /// zeros.  If so, the result pointer and the first operand have the same
815   /// value, just potentially different types.
816   bool hasAllZeroIndices() const;
817
818   /// hasAllConstantIndices - Return true if all of the indices of this GEP are
819   /// constant integers.  If so, the result pointer and the first operand have
820   /// a constant offset between them.
821   bool hasAllConstantIndices() const;
822
823   /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
824   /// See LangRef.html for the meaning of inbounds on a getelementptr.
825   void setIsInBounds(bool b = true);
826
827   /// isInBounds - Determine whether the GEP has the inbounds flag.
828   bool isInBounds() const;
829
830   // Methods for support type inquiry through isa, cast, and dyn_cast:
831   static inline bool classof(const GetElementPtrInst *) { return true; }
832   static inline bool classof(const Instruction *I) {
833     return (I->getOpcode() == Instruction::GetElementPtr);
834   }
835   static inline bool classof(const Value *V) {
836     return isa<Instruction>(V) && classof(cast<Instruction>(V));
837   }
838 };
839
840 template <>
841 struct OperandTraits<GetElementPtrInst> :
842   public VariadicOperandTraits<GetElementPtrInst, 1> {
843 };
844
845 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
846                                      ArrayRef<Value *> IdxList,
847                                      unsigned Values,
848                                      const Twine &NameStr,
849                                      Instruction *InsertBefore)
850   : Instruction(PointerType::get(checkGEPType(
851                                    getIndexedType(Ptr->getType(), IdxList)),
852                                  cast<PointerType>(Ptr->getType())
853                                    ->getAddressSpace()),
854                 GetElementPtr,
855                 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
856                 Values, InsertBefore) {
857   init(Ptr, IdxList, NameStr);
858 }
859 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
860                                      ArrayRef<Value *> IdxList,
861                                      unsigned Values,
862                                      const Twine &NameStr,
863                                      BasicBlock *InsertAtEnd)
864   : Instruction(PointerType::get(checkGEPType(
865                                    getIndexedType(Ptr->getType(), IdxList)),
866                                  cast<PointerType>(Ptr->getType())
867                                    ->getAddressSpace()),
868                 GetElementPtr,
869                 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
870                 Values, InsertAtEnd) {
871   init(Ptr, IdxList, NameStr);
872 }
873
874
875 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
876
877
878 //===----------------------------------------------------------------------===//
879 //                               ICmpInst Class
880 //===----------------------------------------------------------------------===//
881
882 /// This instruction compares its operands according to the predicate given
883 /// to the constructor. It only operates on integers or pointers. The operands
884 /// must be identical types.
885 /// @brief Represent an integer comparison operator.
886 class ICmpInst: public CmpInst {
887 protected:
888   /// @brief Clone an identical ICmpInst
889   virtual ICmpInst *clone_impl() const;
890 public:
891   /// @brief Constructor with insert-before-instruction semantics.
892   ICmpInst(
893     Instruction *InsertBefore,  ///< Where to insert
894     Predicate pred,  ///< The predicate to use for the comparison
895     Value *LHS,      ///< The left-hand-side of the expression
896     Value *RHS,      ///< The right-hand-side of the expression
897     const Twine &NameStr = ""  ///< Name of the instruction
898   ) : CmpInst(makeCmpResultType(LHS->getType()),
899               Instruction::ICmp, pred, LHS, RHS, NameStr,
900               InsertBefore) {
901     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
902            pred <= CmpInst::LAST_ICMP_PREDICATE &&
903            "Invalid ICmp predicate value");
904     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
905           "Both operands to ICmp instruction are not of the same type!");
906     // Check that the operands are the right type
907     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
908             getOperand(0)->getType()->isPointerTy()) &&
909            "Invalid operand types for ICmp instruction");
910   }
911
912   /// @brief Constructor with insert-at-end semantics.
913   ICmpInst(
914     BasicBlock &InsertAtEnd, ///< Block to insert into.
915     Predicate pred,  ///< The predicate to use for the comparison
916     Value *LHS,      ///< The left-hand-side of the expression
917     Value *RHS,      ///< The right-hand-side of the expression
918     const Twine &NameStr = ""  ///< Name of the instruction
919   ) : CmpInst(makeCmpResultType(LHS->getType()),
920               Instruction::ICmp, pred, LHS, RHS, NameStr,
921               &InsertAtEnd) {
922     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
923           pred <= CmpInst::LAST_ICMP_PREDICATE &&
924           "Invalid ICmp predicate value");
925     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
926           "Both operands to ICmp instruction are not of the same type!");
927     // Check that the operands are the right type
928     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
929             getOperand(0)->getType()->isPointerTy()) &&
930            "Invalid operand types for ICmp instruction");
931   }
932
933   /// @brief Constructor with no-insertion semantics
934   ICmpInst(
935     Predicate pred, ///< The predicate to use for the comparison
936     Value *LHS,     ///< The left-hand-side of the expression
937     Value *RHS,     ///< The right-hand-side of the expression
938     const Twine &NameStr = "" ///< Name of the instruction
939   ) : CmpInst(makeCmpResultType(LHS->getType()),
940               Instruction::ICmp, pred, LHS, RHS, NameStr) {
941     assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
942            pred <= CmpInst::LAST_ICMP_PREDICATE &&
943            "Invalid ICmp predicate value");
944     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
945           "Both operands to ICmp instruction are not of the same type!");
946     // Check that the operands are the right type
947     assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
948             getOperand(0)->getType()->isPointerTy()) &&
949            "Invalid operand types for ICmp instruction");
950   }
951
952   /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
953   /// @returns the predicate that would be the result if the operand were
954   /// regarded as signed.
955   /// @brief Return the signed version of the predicate
956   Predicate getSignedPredicate() const {
957     return getSignedPredicate(getPredicate());
958   }
959
960   /// This is a static version that you can use without an instruction.
961   /// @brief Return the signed version of the predicate.
962   static Predicate getSignedPredicate(Predicate pred);
963
964   /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
965   /// @returns the predicate that would be the result if the operand were
966   /// regarded as unsigned.
967   /// @brief Return the unsigned version of the predicate
968   Predicate getUnsignedPredicate() const {
969     return getUnsignedPredicate(getPredicate());
970   }
971
972   /// This is a static version that you can use without an instruction.
973   /// @brief Return the unsigned version of the predicate.
974   static Predicate getUnsignedPredicate(Predicate pred);
975
976   /// isEquality - Return true if this predicate is either EQ or NE.  This also
977   /// tests for commutativity.
978   static bool isEquality(Predicate P) {
979     return P == ICMP_EQ || P == ICMP_NE;
980   }
981
982   /// isEquality - Return true if this predicate is either EQ or NE.  This also
983   /// tests for commutativity.
984   bool isEquality() const {
985     return isEquality(getPredicate());
986   }
987
988   /// @returns true if the predicate of this ICmpInst is commutative
989   /// @brief Determine if this relation is commutative.
990   bool isCommutative() const { return isEquality(); }
991
992   /// isRelational - Return true if the predicate is relational (not EQ or NE).
993   ///
994   bool isRelational() const {
995     return !isEquality();
996   }
997
998   /// isRelational - Return true if the predicate is relational (not EQ or NE).
999   ///
1000   static bool isRelational(Predicate P) {
1001     return !isEquality(P);
1002   }
1003
1004   /// Initialize a set of values that all satisfy the predicate with C.
1005   /// @brief Make a ConstantRange for a relation with a constant value.
1006   static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
1007
1008   /// Exchange the two operands to this instruction in such a way that it does
1009   /// not modify the semantics of the instruction. The predicate value may be
1010   /// changed to retain the same result if the predicate is order dependent
1011   /// (e.g. ult).
1012   /// @brief Swap operands and adjust predicate.
1013   void swapOperands() {
1014     setPredicate(getSwappedPredicate());
1015     Op<0>().swap(Op<1>());
1016   }
1017
1018   // Methods for support type inquiry through isa, cast, and dyn_cast:
1019   static inline bool classof(const ICmpInst *) { return true; }
1020   static inline bool classof(const Instruction *I) {
1021     return I->getOpcode() == Instruction::ICmp;
1022   }
1023   static inline bool classof(const Value *V) {
1024     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1025   }
1026
1027 };
1028
1029 //===----------------------------------------------------------------------===//
1030 //                               FCmpInst Class
1031 //===----------------------------------------------------------------------===//
1032
1033 /// This instruction compares its operands according to the predicate given
1034 /// to the constructor. It only operates on floating point values or packed
1035 /// vectors of floating point values. The operands must be identical types.
1036 /// @brief Represents a floating point comparison operator.
1037 class FCmpInst: public CmpInst {
1038 protected:
1039   /// @brief Clone an identical FCmpInst
1040   virtual FCmpInst *clone_impl() const;
1041 public:
1042   /// @brief Constructor with insert-before-instruction semantics.
1043   FCmpInst(
1044     Instruction *InsertBefore, ///< Where to insert
1045     Predicate pred,  ///< The predicate to use for the comparison
1046     Value *LHS,      ///< The left-hand-side of the expression
1047     Value *RHS,      ///< The right-hand-side of the expression
1048     const Twine &NameStr = ""  ///< Name of the instruction
1049   ) : CmpInst(makeCmpResultType(LHS->getType()),
1050               Instruction::FCmp, pred, LHS, RHS, NameStr,
1051               InsertBefore) {
1052     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1053            "Invalid FCmp predicate value");
1054     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1055            "Both operands to FCmp instruction are not of the same type!");
1056     // Check that the operands are the right type
1057     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1058            "Invalid operand types for FCmp instruction");
1059   }
1060
1061   /// @brief Constructor with insert-at-end semantics.
1062   FCmpInst(
1063     BasicBlock &InsertAtEnd, ///< Block to insert into.
1064     Predicate pred,  ///< The predicate to use for the comparison
1065     Value *LHS,      ///< The left-hand-side of the expression
1066     Value *RHS,      ///< The right-hand-side of the expression
1067     const Twine &NameStr = ""  ///< Name of the instruction
1068   ) : CmpInst(makeCmpResultType(LHS->getType()),
1069               Instruction::FCmp, pred, LHS, RHS, NameStr,
1070               &InsertAtEnd) {
1071     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1072            "Invalid FCmp predicate value");
1073     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1074            "Both operands to FCmp instruction are not of the same type!");
1075     // Check that the operands are the right type
1076     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1077            "Invalid operand types for FCmp instruction");
1078   }
1079
1080   /// @brief Constructor with no-insertion semantics
1081   FCmpInst(
1082     Predicate pred, ///< The predicate to use for the comparison
1083     Value *LHS,     ///< The left-hand-side of the expression
1084     Value *RHS,     ///< The right-hand-side of the expression
1085     const Twine &NameStr = "" ///< Name of the instruction
1086   ) : CmpInst(makeCmpResultType(LHS->getType()),
1087               Instruction::FCmp, pred, LHS, RHS, NameStr) {
1088     assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1089            "Invalid FCmp predicate value");
1090     assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1091            "Both operands to FCmp instruction are not of the same type!");
1092     // Check that the operands are the right type
1093     assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
1094            "Invalid operand types for FCmp instruction");
1095   }
1096
1097   /// @returns true if the predicate of this instruction is EQ or NE.
1098   /// @brief Determine if this is an equality predicate.
1099   bool isEquality() const {
1100     return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
1101            getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
1102   }
1103
1104   /// @returns true if the predicate of this instruction is commutative.
1105   /// @brief Determine if this is a commutative predicate.
1106   bool isCommutative() const {
1107     return isEquality() ||
1108            getPredicate() == FCMP_FALSE ||
1109            getPredicate() == FCMP_TRUE ||
1110            getPredicate() == FCMP_ORD ||
1111            getPredicate() == FCMP_UNO;
1112   }
1113
1114   /// @returns true if the predicate is relational (not EQ or NE).
1115   /// @brief Determine if this a relational predicate.
1116   bool isRelational() const { return !isEquality(); }
1117
1118   /// Exchange the two operands to this instruction in such a way that it does
1119   /// not modify the semantics of the instruction. The predicate value may be
1120   /// changed to retain the same result if the predicate is order dependent
1121   /// (e.g. ult).
1122   /// @brief Swap operands and adjust predicate.
1123   void swapOperands() {
1124     setPredicate(getSwappedPredicate());
1125     Op<0>().swap(Op<1>());
1126   }
1127
1128   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1129   static inline bool classof(const FCmpInst *) { return true; }
1130   static inline bool classof(const Instruction *I) {
1131     return I->getOpcode() == Instruction::FCmp;
1132   }
1133   static inline bool classof(const Value *V) {
1134     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1135   }
1136 };
1137
1138 //===----------------------------------------------------------------------===//
1139 /// CallInst - This class represents a function call, abstracting a target
1140 /// machine's calling convention.  This class uses low bit of the SubClassData
1141 /// field to indicate whether or not this is a tail call.  The rest of the bits
1142 /// hold the calling convention of the call.
1143 ///
1144 class CallInst : public Instruction {
1145   AttrListPtr AttributeList; ///< parameter attributes for call
1146   CallInst(const CallInst &CI);
1147   void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
1148   void init(Value *Func, const Twine &NameStr);
1149
1150   /// Construct a CallInst given a range of arguments.
1151   /// @brief Construct a CallInst from a range of arguments
1152   inline CallInst(Value *Func, ArrayRef<Value *> Args,
1153                   const Twine &NameStr, Instruction *InsertBefore);
1154
1155   /// Construct a CallInst given a range of arguments.
1156   /// @brief Construct a CallInst from a range of arguments
1157   inline CallInst(Value *Func, ArrayRef<Value *> Args,
1158                   const Twine &NameStr, BasicBlock *InsertAtEnd);
1159
1160   CallInst(Value *F, Value *Actual, const Twine &NameStr,
1161            Instruction *InsertBefore);
1162   CallInst(Value *F, Value *Actual, const Twine &NameStr,
1163            BasicBlock *InsertAtEnd);
1164   explicit CallInst(Value *F, const Twine &NameStr,
1165                     Instruction *InsertBefore);
1166   CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1167 protected:
1168   virtual CallInst *clone_impl() const;
1169 public:
1170   static CallInst *Create(Value *Func,
1171                           ArrayRef<Value *> Args,
1172                           const Twine &NameStr = "",
1173                           Instruction *InsertBefore = 0) {
1174     return new(unsigned(Args.size() + 1))
1175       CallInst(Func, Args, NameStr, InsertBefore);
1176   }
1177   static CallInst *Create(Value *Func,
1178                           ArrayRef<Value *> Args,
1179                           const Twine &NameStr, BasicBlock *InsertAtEnd) {
1180     return new(unsigned(Args.size() + 1))
1181       CallInst(Func, Args, NameStr, InsertAtEnd);
1182   }
1183   static CallInst *Create(Value *F, const Twine &NameStr = "",
1184                           Instruction *InsertBefore = 0) {
1185     return new(1) CallInst(F, NameStr, InsertBefore);
1186   }
1187   static CallInst *Create(Value *F, const Twine &NameStr,
1188                           BasicBlock *InsertAtEnd) {
1189     return new(1) CallInst(F, NameStr, InsertAtEnd);
1190   }
1191   /// CreateMalloc - Generate the IR for a call to malloc:
1192   /// 1. Compute the malloc call's argument as the specified type's size,
1193   ///    possibly multiplied by the array size if the array size is not
1194   ///    constant 1.
1195   /// 2. Call malloc with that argument.
1196   /// 3. Bitcast the result of the malloc call to the specified type.
1197   static Instruction *CreateMalloc(Instruction *InsertBefore,
1198                                    Type *IntPtrTy, Type *AllocTy,
1199                                    Value *AllocSize, Value *ArraySize = 0,
1200                                    Function* MallocF = 0,
1201                                    const Twine &Name = "");
1202   static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
1203                                    Type *IntPtrTy, Type *AllocTy,
1204                                    Value *AllocSize, Value *ArraySize = 0,
1205                                    Function* MallocF = 0,
1206                                    const Twine &Name = "");
1207   /// CreateFree - Generate the IR for a call to the builtin free function.
1208   static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
1209   static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
1210
1211   ~CallInst();
1212
1213   bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
1214   void setTailCall(bool isTC = true) {
1215     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
1216                                unsigned(isTC));
1217   }
1218
1219   /// Provide fast operand accessors
1220   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1221
1222   /// getNumArgOperands - Return the number of call arguments.
1223   ///
1224   unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1225
1226   /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1227   ///
1228   Value *getArgOperand(unsigned i) const { return getOperand(i); }
1229   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1230
1231   /// getCallingConv/setCallingConv - Get or set the calling convention of this
1232   /// function call.
1233   CallingConv::ID getCallingConv() const {
1234     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
1235   }
1236   void setCallingConv(CallingConv::ID CC) {
1237     setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
1238                                (static_cast<unsigned>(CC) << 1));
1239   }
1240
1241   /// getAttributes - Return the parameter attributes for this call.
1242   ///
1243   const AttrListPtr &getAttributes() const { return AttributeList; }
1244
1245   /// setAttributes - Set the parameter attributes for this call.
1246   ///
1247   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
1248
1249   /// addAttribute - adds the attribute to the list of attributes.
1250   void addAttribute(unsigned i, Attributes attr);
1251
1252   /// removeAttribute - removes the attribute from the list of attributes.
1253   void removeAttribute(unsigned i, Attributes attr);
1254
1255   /// @brief Determine whether the call or the callee has the given attribute.
1256   bool paramHasAttr(unsigned i, Attributes attr) const;
1257
1258   /// @brief Extract the alignment for a call or parameter (0=unknown).
1259   unsigned getParamAlignment(unsigned i) const {
1260     return AttributeList.getParamAlignment(i);
1261   }
1262
1263   /// @brief Return true if the call should not be inlined.
1264   bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
1265   void setIsNoInline(bool Value = true) {
1266     if (Value) addAttribute(~0, Attribute::NoInline);
1267     else removeAttribute(~0, Attribute::NoInline);
1268   }
1269
1270   /// @brief Determine if the call does not access memory.
1271   bool doesNotAccessMemory() const {
1272     return paramHasAttr(~0, Attribute::ReadNone);
1273   }
1274   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
1275     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
1276     else removeAttribute(~0, Attribute::ReadNone);
1277   }
1278
1279   /// @brief Determine if the call does not access or only reads memory.
1280   bool onlyReadsMemory() const {
1281     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
1282   }
1283   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
1284     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
1285     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
1286   }
1287
1288   /// @brief Determine if the call cannot return.
1289   bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
1290   void setDoesNotReturn(bool DoesNotReturn = true) {
1291     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
1292     else removeAttribute(~0, Attribute::NoReturn);
1293   }
1294
1295   /// @brief Determine if the call cannot unwind.
1296   bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
1297   void setDoesNotThrow(bool DoesNotThrow = true) {
1298     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
1299     else removeAttribute(~0, Attribute::NoUnwind);
1300   }
1301
1302   /// @brief Determine if the call returns a structure through first
1303   /// pointer argument.
1304   bool hasStructRetAttr() const {
1305     // Be friendly and also check the callee.
1306     return paramHasAttr(1, Attribute::StructRet);
1307   }
1308
1309   /// @brief Determine if any call argument is an aggregate passed by value.
1310   bool hasByValArgument() const {
1311     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1312   }
1313
1314   /// getCalledFunction - Return the function called, or null if this is an
1315   /// indirect function invocation.
1316   ///
1317   Function *getCalledFunction() const {
1318     return dyn_cast<Function>(Op<-1>());
1319   }
1320
1321   /// getCalledValue - Get a pointer to the function that is invoked by this
1322   /// instruction.
1323   const Value *getCalledValue() const { return Op<-1>(); }
1324         Value *getCalledValue()       { return Op<-1>(); }
1325
1326   /// setCalledFunction - Set the function called.
1327   void setCalledFunction(Value* Fn) {
1328     Op<-1>() = Fn;
1329   }
1330
1331   /// isInlineAsm - Check if this call is an inline asm statement.
1332   bool isInlineAsm() const {
1333     return isa<InlineAsm>(Op<-1>());
1334   }
1335
1336   // Methods for support type inquiry through isa, cast, and dyn_cast:
1337   static inline bool classof(const CallInst *) { return true; }
1338   static inline bool classof(const Instruction *I) {
1339     return I->getOpcode() == Instruction::Call;
1340   }
1341   static inline bool classof(const Value *V) {
1342     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1343   }
1344 private:
1345   // Shadow Instruction::setInstructionSubclassData with a private forwarding
1346   // method so that subclasses cannot accidentally use it.
1347   void setInstructionSubclassData(unsigned short D) {
1348     Instruction::setInstructionSubclassData(D);
1349   }
1350 };
1351
1352 template <>
1353 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
1354 };
1355
1356 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1357                    const Twine &NameStr, BasicBlock *InsertAtEnd)
1358   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1359                                    ->getElementType())->getReturnType(),
1360                 Instruction::Call,
1361                 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1362                 unsigned(Args.size() + 1), InsertAtEnd) {
1363   init(Func, Args, NameStr);
1364 }
1365
1366 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
1367                    const Twine &NameStr, Instruction *InsertBefore)
1368   : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1369                                    ->getElementType())->getReturnType(),
1370                 Instruction::Call,
1371                 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1372                 unsigned(Args.size() + 1), InsertBefore) {
1373   init(Func, Args, NameStr);
1374 }
1375
1376
1377 // Note: if you get compile errors about private methods then
1378 //       please update your code to use the high-level operand
1379 //       interfaces. See line 943 above.
1380 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1381
1382 //===----------------------------------------------------------------------===//
1383 //                               SelectInst Class
1384 //===----------------------------------------------------------------------===//
1385
1386 /// SelectInst - This class represents the LLVM 'select' instruction.
1387 ///
1388 class SelectInst : public Instruction {
1389   void init(Value *C, Value *S1, Value *S2) {
1390     assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
1391     Op<0>() = C;
1392     Op<1>() = S1;
1393     Op<2>() = S2;
1394   }
1395
1396   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1397              Instruction *InsertBefore)
1398     : Instruction(S1->getType(), Instruction::Select,
1399                   &Op<0>(), 3, InsertBefore) {
1400     init(C, S1, S2);
1401     setName(NameStr);
1402   }
1403   SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
1404              BasicBlock *InsertAtEnd)
1405     : Instruction(S1->getType(), Instruction::Select,
1406                   &Op<0>(), 3, InsertAtEnd) {
1407     init(C, S1, S2);
1408     setName(NameStr);
1409   }
1410 protected:
1411   virtual SelectInst *clone_impl() const;
1412 public:
1413   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1414                             const Twine &NameStr = "",
1415                             Instruction *InsertBefore = 0) {
1416     return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
1417   }
1418   static SelectInst *Create(Value *C, Value *S1, Value *S2,
1419                             const Twine &NameStr,
1420                             BasicBlock *InsertAtEnd) {
1421     return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
1422   }
1423
1424   const Value *getCondition() const { return Op<0>(); }
1425   const Value *getTrueValue() const { return Op<1>(); }
1426   const Value *getFalseValue() const { return Op<2>(); }
1427   Value *getCondition() { return Op<0>(); }
1428   Value *getTrueValue() { return Op<1>(); }
1429   Value *getFalseValue() { return Op<2>(); }
1430
1431   /// areInvalidOperands - Return a string if the specified operands are invalid
1432   /// for a select operation, otherwise return null.
1433   static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
1434
1435   /// Transparently provide more efficient getOperand methods.
1436   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1437
1438   OtherOps getOpcode() const {
1439     return static_cast<OtherOps>(Instruction::getOpcode());
1440   }
1441
1442   // Methods for support type inquiry through isa, cast, and dyn_cast:
1443   static inline bool classof(const SelectInst *) { return true; }
1444   static inline bool classof(const Instruction *I) {
1445     return I->getOpcode() == Instruction::Select;
1446   }
1447   static inline bool classof(const Value *V) {
1448     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1449   }
1450 };
1451
1452 template <>
1453 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
1454 };
1455
1456 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1457
1458 //===----------------------------------------------------------------------===//
1459 //                                VAArgInst Class
1460 //===----------------------------------------------------------------------===//
1461
1462 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
1463 /// an argument of the specified type given a va_list and increments that list
1464 ///
1465 class VAArgInst : public UnaryInstruction {
1466 protected:
1467   virtual VAArgInst *clone_impl() const;
1468
1469 public:
1470   VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
1471              Instruction *InsertBefore = 0)
1472     : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
1473     setName(NameStr);
1474   }
1475   VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
1476             BasicBlock *InsertAtEnd)
1477     : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
1478     setName(NameStr);
1479   }
1480
1481   Value *getPointerOperand() { return getOperand(0); }
1482   const Value *getPointerOperand() const { return getOperand(0); }
1483   static unsigned getPointerOperandIndex() { return 0U; }
1484
1485   // Methods for support type inquiry through isa, cast, and dyn_cast:
1486   static inline bool classof(const VAArgInst *) { return true; }
1487   static inline bool classof(const Instruction *I) {
1488     return I->getOpcode() == VAArg;
1489   }
1490   static inline bool classof(const Value *V) {
1491     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1492   }
1493 };
1494
1495 //===----------------------------------------------------------------------===//
1496 //                                ExtractElementInst Class
1497 //===----------------------------------------------------------------------===//
1498
1499 /// ExtractElementInst - This instruction extracts a single (scalar)
1500 /// element from a VectorType value
1501 ///
1502 class ExtractElementInst : public Instruction {
1503   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
1504                      Instruction *InsertBefore = 0);
1505   ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
1506                      BasicBlock *InsertAtEnd);
1507 protected:
1508   virtual ExtractElementInst *clone_impl() const;
1509
1510 public:
1511   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1512                                    const Twine &NameStr = "",
1513                                    Instruction *InsertBefore = 0) {
1514     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1515   }
1516   static ExtractElementInst *Create(Value *Vec, Value *Idx,
1517                                    const Twine &NameStr,
1518                                    BasicBlock *InsertAtEnd) {
1519     return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1520   }
1521
1522   /// isValidOperands - Return true if an extractelement instruction can be
1523   /// formed with the specified operands.
1524   static bool isValidOperands(const Value *Vec, const Value *Idx);
1525
1526   Value *getVectorOperand() { return Op<0>(); }
1527   Value *getIndexOperand() { return Op<1>(); }
1528   const Value *getVectorOperand() const { return Op<0>(); }
1529   const Value *getIndexOperand() const { return Op<1>(); }
1530
1531   VectorType *getVectorOperandType() const {
1532     return reinterpret_cast<VectorType*>(getVectorOperand()->getType());
1533   }
1534
1535
1536   /// Transparently provide more efficient getOperand methods.
1537   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1538
1539   // Methods for support type inquiry through isa, cast, and dyn_cast:
1540   static inline bool classof(const ExtractElementInst *) { return true; }
1541   static inline bool classof(const Instruction *I) {
1542     return I->getOpcode() == Instruction::ExtractElement;
1543   }
1544   static inline bool classof(const Value *V) {
1545     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1546   }
1547 };
1548
1549 template <>
1550 struct OperandTraits<ExtractElementInst> :
1551   public FixedNumOperandTraits<ExtractElementInst, 2> {
1552 };
1553
1554 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1555
1556 //===----------------------------------------------------------------------===//
1557 //                                InsertElementInst Class
1558 //===----------------------------------------------------------------------===//
1559
1560 /// InsertElementInst - This instruction inserts a single (scalar)
1561 /// element into a VectorType value
1562 ///
1563 class InsertElementInst : public Instruction {
1564   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1565                     const Twine &NameStr = "",
1566                     Instruction *InsertBefore = 0);
1567   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1568                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1569 protected:
1570   virtual InsertElementInst *clone_impl() const;
1571
1572 public:
1573   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1574                                    const Twine &NameStr = "",
1575                                    Instruction *InsertBefore = 0) {
1576     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
1577   }
1578   static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1579                                    const Twine &NameStr,
1580                                    BasicBlock *InsertAtEnd) {
1581     return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
1582   }
1583
1584   /// isValidOperands - Return true if an insertelement instruction can be
1585   /// formed with the specified operands.
1586   static bool isValidOperands(const Value *Vec, const Value *NewElt,
1587                               const Value *Idx);
1588
1589   /// getType - Overload to return most specific vector type.
1590   ///
1591   VectorType *getType() const {
1592     return reinterpret_cast<VectorType*>(Instruction::getType());
1593   }
1594
1595   /// Transparently provide more efficient getOperand methods.
1596   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1597
1598   // Methods for support type inquiry through isa, cast, and dyn_cast:
1599   static inline bool classof(const InsertElementInst *) { return true; }
1600   static inline bool classof(const Instruction *I) {
1601     return I->getOpcode() == Instruction::InsertElement;
1602   }
1603   static inline bool classof(const Value *V) {
1604     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1605   }
1606 };
1607
1608 template <>
1609 struct OperandTraits<InsertElementInst> :
1610   public FixedNumOperandTraits<InsertElementInst, 3> {
1611 };
1612
1613 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1614
1615 //===----------------------------------------------------------------------===//
1616 //                           ShuffleVectorInst Class
1617 //===----------------------------------------------------------------------===//
1618
1619 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1620 /// input vectors.
1621 ///
1622 class ShuffleVectorInst : public Instruction {
1623 protected:
1624   virtual ShuffleVectorInst *clone_impl() const;
1625
1626 public:
1627   // allocate space for exactly three operands
1628   void *operator new(size_t s) {
1629     return User::operator new(s, 3);
1630   }
1631   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1632                     const Twine &NameStr = "",
1633                     Instruction *InsertBefor = 0);
1634   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1635                     const Twine &NameStr, BasicBlock *InsertAtEnd);
1636
1637   /// isValidOperands - Return true if a shufflevector instruction can be
1638   /// formed with the specified operands.
1639   static bool isValidOperands(const Value *V1, const Value *V2,
1640                               const Value *Mask);
1641
1642   /// getType - Overload to return most specific vector type.
1643   ///
1644   VectorType *getType() const {
1645     return reinterpret_cast<VectorType*>(Instruction::getType());
1646   }
1647
1648   /// Transparently provide more efficient getOperand methods.
1649   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1650
1651   /// getMaskValue - Return the index from the shuffle mask for the specified
1652   /// output result.  This is either -1 if the element is undef or a number less
1653   /// than 2*numelements.
1654   int getMaskValue(unsigned i) const;
1655
1656   // Methods for support type inquiry through isa, cast, and dyn_cast:
1657   static inline bool classof(const ShuffleVectorInst *) { return true; }
1658   static inline bool classof(const Instruction *I) {
1659     return I->getOpcode() == Instruction::ShuffleVector;
1660   }
1661   static inline bool classof(const Value *V) {
1662     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1663   }
1664 };
1665
1666 template <>
1667 struct OperandTraits<ShuffleVectorInst> :
1668   public FixedNumOperandTraits<ShuffleVectorInst, 3> {
1669 };
1670
1671 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
1672
1673 //===----------------------------------------------------------------------===//
1674 //                                ExtractValueInst Class
1675 //===----------------------------------------------------------------------===//
1676
1677 /// ExtractValueInst - This instruction extracts a struct member or array
1678 /// element value from an aggregate value.
1679 ///
1680 class ExtractValueInst : public UnaryInstruction {
1681   SmallVector<unsigned, 4> Indices;
1682
1683   ExtractValueInst(const ExtractValueInst &EVI);
1684   void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
1685
1686   /// Constructors - Create a extractvalue instruction with a base aggregate
1687   /// value and a list of indices.  The first ctor can optionally insert before
1688   /// an existing instruction, the second appends the new instruction to the
1689   /// specified BasicBlock.
1690   inline ExtractValueInst(Value *Agg,
1691                           ArrayRef<unsigned> Idxs,
1692                           const Twine &NameStr,
1693                           Instruction *InsertBefore);
1694   inline ExtractValueInst(Value *Agg,
1695                           ArrayRef<unsigned> Idxs,
1696                           const Twine &NameStr, BasicBlock *InsertAtEnd);
1697
1698   // allocate space for exactly one operand
1699   void *operator new(size_t s) {
1700     return User::operator new(s, 1);
1701   }
1702 protected:
1703   virtual ExtractValueInst *clone_impl() const;
1704
1705 public:
1706   static ExtractValueInst *Create(Value *Agg,
1707                                   ArrayRef<unsigned> Idxs,
1708                                   const Twine &NameStr = "",
1709                                   Instruction *InsertBefore = 0) {
1710     return new
1711       ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
1712   }
1713   static ExtractValueInst *Create(Value *Agg,
1714                                   ArrayRef<unsigned> Idxs,
1715                                   const Twine &NameStr,
1716                                   BasicBlock *InsertAtEnd) {
1717     return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
1718   }
1719
1720   /// getIndexedType - Returns the type of the element that would be extracted
1721   /// with an extractvalue instruction with the specified parameters.
1722   ///
1723   /// Null is returned if the indices are invalid for the specified type.
1724   static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
1725
1726   typedef const unsigned* idx_iterator;
1727   inline idx_iterator idx_begin() const { return Indices.begin(); }
1728   inline idx_iterator idx_end()   const { return Indices.end(); }
1729
1730   Value *getAggregateOperand() {
1731     return getOperand(0);
1732   }
1733   const Value *getAggregateOperand() const {
1734     return getOperand(0);
1735   }
1736   static unsigned getAggregateOperandIndex() {
1737     return 0U;                      // get index for modifying correct operand
1738   }
1739
1740   ArrayRef<unsigned> getIndices() const {
1741     return Indices;
1742   }
1743
1744   unsigned getNumIndices() const {
1745     return (unsigned)Indices.size();
1746   }
1747
1748   bool hasIndices() const {
1749     return true;
1750   }
1751
1752   // Methods for support type inquiry through isa, cast, and dyn_cast:
1753   static inline bool classof(const ExtractValueInst *) { return true; }
1754   static inline bool classof(const Instruction *I) {
1755     return I->getOpcode() == Instruction::ExtractValue;
1756   }
1757   static inline bool classof(const Value *V) {
1758     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1759   }
1760 };
1761
1762 ExtractValueInst::ExtractValueInst(Value *Agg,
1763                                    ArrayRef<unsigned> Idxs,
1764                                    const Twine &NameStr,
1765                                    Instruction *InsertBefore)
1766   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1767                      ExtractValue, Agg, InsertBefore) {
1768   init(Idxs, NameStr);
1769 }
1770 ExtractValueInst::ExtractValueInst(Value *Agg,
1771                                    ArrayRef<unsigned> Idxs,
1772                                    const Twine &NameStr,
1773                                    BasicBlock *InsertAtEnd)
1774   : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
1775                      ExtractValue, Agg, InsertAtEnd) {
1776   init(Idxs, NameStr);
1777 }
1778
1779
1780 //===----------------------------------------------------------------------===//
1781 //                                InsertValueInst Class
1782 //===----------------------------------------------------------------------===//
1783
1784 /// InsertValueInst - This instruction inserts a struct field of array element
1785 /// value into an aggregate value.
1786 ///
1787 class InsertValueInst : public Instruction {
1788   SmallVector<unsigned, 4> Indices;
1789
1790   void *operator new(size_t, unsigned); // Do not implement
1791   InsertValueInst(const InsertValueInst &IVI);
1792   void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
1793             const Twine &NameStr);
1794
1795   /// Constructors - Create a insertvalue instruction with a base aggregate
1796   /// value, a value to insert, and a list of indices.  The first ctor can
1797   /// optionally insert before an existing instruction, the second appends
1798   /// the new instruction to the specified BasicBlock.
1799   inline InsertValueInst(Value *Agg, Value *Val,
1800                          ArrayRef<unsigned> Idxs,
1801                          const Twine &NameStr,
1802                          Instruction *InsertBefore);
1803   inline InsertValueInst(Value *Agg, Value *Val,
1804                          ArrayRef<unsigned> Idxs,
1805                          const Twine &NameStr, BasicBlock *InsertAtEnd);
1806
1807   /// Constructors - These two constructors are convenience methods because one
1808   /// and two index insertvalue instructions are so common.
1809   InsertValueInst(Value *Agg, Value *Val,
1810                   unsigned Idx, const Twine &NameStr = "",
1811                   Instruction *InsertBefore = 0);
1812   InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
1813                   const Twine &NameStr, BasicBlock *InsertAtEnd);
1814 protected:
1815   virtual InsertValueInst *clone_impl() const;
1816 public:
1817   // allocate space for exactly two operands
1818   void *operator new(size_t s) {
1819     return User::operator new(s, 2);
1820   }
1821
1822   static InsertValueInst *Create(Value *Agg, Value *Val,
1823                                  ArrayRef<unsigned> Idxs,
1824                                  const Twine &NameStr = "",
1825                                  Instruction *InsertBefore = 0) {
1826     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
1827   }
1828   static InsertValueInst *Create(Value *Agg, Value *Val,
1829                                  ArrayRef<unsigned> Idxs,
1830                                  const Twine &NameStr,
1831                                  BasicBlock *InsertAtEnd) {
1832     return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
1833   }
1834
1835   /// Transparently provide more efficient getOperand methods.
1836   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1837
1838   typedef const unsigned* idx_iterator;
1839   inline idx_iterator idx_begin() const { return Indices.begin(); }
1840   inline idx_iterator idx_end()   const { return Indices.end(); }
1841
1842   Value *getAggregateOperand() {
1843     return getOperand(0);
1844   }
1845   const Value *getAggregateOperand() const {
1846     return getOperand(0);
1847   }
1848   static unsigned getAggregateOperandIndex() {
1849     return 0U;                      // get index for modifying correct operand
1850   }
1851
1852   Value *getInsertedValueOperand() {
1853     return getOperand(1);
1854   }
1855   const Value *getInsertedValueOperand() const {
1856     return getOperand(1);
1857   }
1858   static unsigned getInsertedValueOperandIndex() {
1859     return 1U;                      // get index for modifying correct operand
1860   }
1861
1862   ArrayRef<unsigned> getIndices() const {
1863     return Indices;
1864   }
1865
1866   unsigned getNumIndices() const {
1867     return (unsigned)Indices.size();
1868   }
1869
1870   bool hasIndices() const {
1871     return true;
1872   }
1873
1874   // Methods for support type inquiry through isa, cast, and dyn_cast:
1875   static inline bool classof(const InsertValueInst *) { return true; }
1876   static inline bool classof(const Instruction *I) {
1877     return I->getOpcode() == Instruction::InsertValue;
1878   }
1879   static inline bool classof(const Value *V) {
1880     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1881   }
1882 };
1883
1884 template <>
1885 struct OperandTraits<InsertValueInst> :
1886   public FixedNumOperandTraits<InsertValueInst, 2> {
1887 };
1888
1889 InsertValueInst::InsertValueInst(Value *Agg,
1890                                  Value *Val,
1891                                  ArrayRef<unsigned> Idxs,
1892                                  const Twine &NameStr,
1893                                  Instruction *InsertBefore)
1894   : Instruction(Agg->getType(), InsertValue,
1895                 OperandTraits<InsertValueInst>::op_begin(this),
1896                 2, InsertBefore) {
1897   init(Agg, Val, Idxs, NameStr);
1898 }
1899 InsertValueInst::InsertValueInst(Value *Agg,
1900                                  Value *Val,
1901                                  ArrayRef<unsigned> Idxs,
1902                                  const Twine &NameStr,
1903                                  BasicBlock *InsertAtEnd)
1904   : Instruction(Agg->getType(), InsertValue,
1905                 OperandTraits<InsertValueInst>::op_begin(this),
1906                 2, InsertAtEnd) {
1907   init(Agg, Val, Idxs, NameStr);
1908 }
1909
1910 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1911
1912 //===----------------------------------------------------------------------===//
1913 //                               PHINode Class
1914 //===----------------------------------------------------------------------===//
1915
1916 // PHINode - The PHINode class is used to represent the magical mystical PHI
1917 // node, that can not exist in nature, but can be synthesized in a computer
1918 // scientist's overactive imagination.
1919 //
1920 class PHINode : public Instruction {
1921   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
1922   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
1923   /// the number actually in use.
1924   unsigned ReservedSpace;
1925   PHINode(const PHINode &PN);
1926   // allocate space for exactly zero operands
1927   void *operator new(size_t s) {
1928     return User::operator new(s, 0);
1929   }
1930   explicit PHINode(Type *Ty, unsigned NumReservedValues,
1931                    const Twine &NameStr = "", Instruction *InsertBefore = 0)
1932     : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1933       ReservedSpace(NumReservedValues) {
1934     setName(NameStr);
1935     OperandList = allocHungoffUses(ReservedSpace);
1936   }
1937
1938   PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
1939           BasicBlock *InsertAtEnd)
1940     : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1941       ReservedSpace(NumReservedValues) {
1942     setName(NameStr);
1943     OperandList = allocHungoffUses(ReservedSpace);
1944   }
1945 protected:
1946   // allocHungoffUses - this is more complicated than the generic
1947   // User::allocHungoffUses, because we have to allocate Uses for the incoming
1948   // values and pointers to the incoming blocks, all in one allocation.
1949   Use *allocHungoffUses(unsigned) const;
1950
1951   virtual PHINode *clone_impl() const;
1952 public:
1953   /// Constructors - NumReservedValues is a hint for the number of incoming
1954   /// edges that this phi node will have (use 0 if you really have no idea).
1955   static PHINode *Create(Type *Ty, unsigned NumReservedValues,
1956                          const Twine &NameStr = "",
1957                          Instruction *InsertBefore = 0) {
1958     return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
1959   }
1960   static PHINode *Create(Type *Ty, unsigned NumReservedValues, 
1961                          const Twine &NameStr, BasicBlock *InsertAtEnd) {
1962     return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
1963   }
1964   ~PHINode();
1965
1966   /// Provide fast operand accessors
1967   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1968
1969   // Block iterator interface. This provides access to the list of incoming
1970   // basic blocks, which parallels the list of incoming values.
1971
1972   typedef BasicBlock **block_iterator;
1973   typedef BasicBlock * const *const_block_iterator;
1974
1975   block_iterator block_begin() {
1976     Use::UserRef *ref =
1977       reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
1978     return reinterpret_cast<block_iterator>(ref + 1);
1979   }
1980
1981   const_block_iterator block_begin() const {
1982     const Use::UserRef *ref =
1983       reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
1984     return reinterpret_cast<const_block_iterator>(ref + 1);
1985   }
1986
1987   block_iterator block_end() {
1988     return block_begin() + getNumOperands();
1989   }
1990
1991   const_block_iterator block_end() const {
1992     return block_begin() + getNumOperands();
1993   }
1994
1995   /// getNumIncomingValues - Return the number of incoming edges
1996   ///
1997   unsigned getNumIncomingValues() const { return getNumOperands(); }
1998
1999   /// getIncomingValue - Return incoming value number x
2000   ///
2001   Value *getIncomingValue(unsigned i) const {
2002     return getOperand(i);
2003   }
2004   void setIncomingValue(unsigned i, Value *V) {
2005     setOperand(i, V);
2006   }
2007   static unsigned getOperandNumForIncomingValue(unsigned i) {
2008     return i;
2009   }
2010   static unsigned getIncomingValueNumForOperand(unsigned i) {
2011     return i;
2012   }
2013
2014   /// getIncomingBlock - Return incoming basic block number @p i.
2015   ///
2016   BasicBlock *getIncomingBlock(unsigned i) const {
2017     return block_begin()[i];
2018   }
2019
2020   /// getIncomingBlock - Return incoming basic block corresponding
2021   /// to an operand of the PHI.
2022   ///
2023   BasicBlock *getIncomingBlock(const Use &U) const {
2024     assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
2025     return getIncomingBlock(unsigned(&U - op_begin()));
2026   }
2027
2028   /// getIncomingBlock - Return incoming basic block corresponding
2029   /// to value use iterator.
2030   ///
2031   template <typename U>
2032   BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
2033     return getIncomingBlock(I.getUse());
2034   }
2035
2036   void setIncomingBlock(unsigned i, BasicBlock *BB) {
2037     block_begin()[i] = BB;
2038   }
2039
2040   /// addIncoming - Add an incoming value to the end of the PHI list
2041   ///
2042   void addIncoming(Value *V, BasicBlock *BB) {
2043     assert(V && "PHI node got a null value!");
2044     assert(BB && "PHI node got a null basic block!");
2045     assert(getType() == V->getType() &&
2046            "All operands to PHI node must be the same type as the PHI node!");
2047     if (NumOperands == ReservedSpace)
2048       growOperands();  // Get more space!
2049     // Initialize some new operands.
2050     ++NumOperands;
2051     setIncomingValue(NumOperands - 1, V);
2052     setIncomingBlock(NumOperands - 1, BB);
2053   }
2054
2055   /// removeIncomingValue - Remove an incoming value.  This is useful if a
2056   /// predecessor basic block is deleted.  The value removed is returned.
2057   ///
2058   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2059   /// is true), the PHI node is destroyed and any uses of it are replaced with
2060   /// dummy values.  The only time there should be zero incoming values to a PHI
2061   /// node is when the block is dead, so this strategy is sound.
2062   ///
2063   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2064
2065   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2066     int Idx = getBasicBlockIndex(BB);
2067     assert(Idx >= 0 && "Invalid basic block argument to remove!");
2068     return removeIncomingValue(Idx, DeletePHIIfEmpty);
2069   }
2070
2071   /// getBasicBlockIndex - Return the first index of the specified basic
2072   /// block in the value list for this PHI.  Returns -1 if no instance.
2073   ///
2074   int getBasicBlockIndex(const BasicBlock *BB) const {
2075     for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2076       if (block_begin()[i] == BB)
2077         return i;
2078     return -1;
2079   }
2080
2081   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2082     int Idx = getBasicBlockIndex(BB);
2083     assert(Idx >= 0 && "Invalid basic block argument!");
2084     return getIncomingValue(Idx);
2085   }
2086
2087   /// hasConstantValue - If the specified PHI node always merges together the
2088   /// same value, return the value, otherwise return null.
2089   Value *hasConstantValue() const;
2090
2091   /// Methods for support type inquiry through isa, cast, and dyn_cast:
2092   static inline bool classof(const PHINode *) { return true; }
2093   static inline bool classof(const Instruction *I) {
2094     return I->getOpcode() == Instruction::PHI;
2095   }
2096   static inline bool classof(const Value *V) {
2097     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2098   }
2099  private:
2100   void growOperands();
2101 };
2102
2103 template <>
2104 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2105 };
2106
2107 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
2108
2109 //===----------------------------------------------------------------------===//
2110 //                           LandingPadInst Class
2111 //===----------------------------------------------------------------------===//
2112
2113 //===---------------------------------------------------------------------------
2114 /// LandingPadInst - The landingpad instruction holds all of the information
2115 /// necessary to generate correct exception handling. The landingpad instruction
2116 /// cannot be moved from the top of a landing pad block, which itself is
2117 /// accessible only from the 'unwind' edge of an invoke. This uses the
2118 /// SubclassData field in Value to store whether or not the landingpad is a
2119 /// cleanup.
2120 ///
2121 class LandingPadInst : public Instruction {
2122   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
2123   /// the number actually in use.
2124   unsigned ReservedSpace;
2125   LandingPadInst(const LandingPadInst &LP);
2126 public:
2127   enum ClauseType { Catch, Filter };
2128 private:
2129   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2130   // Allocate space for exactly zero operands.
2131   void *operator new(size_t s) {
2132     return User::operator new(s, 0);
2133   }
2134   void growOperands(unsigned Size);
2135   void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
2136
2137   explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2138                           unsigned NumReservedValues, const Twine &NameStr,
2139                           Instruction *InsertBefore);
2140   explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
2141                           unsigned NumReservedValues, const Twine &NameStr,
2142                           BasicBlock *InsertAtEnd);
2143 protected:
2144   virtual LandingPadInst *clone_impl() const;
2145 public:
2146   /// Constructors - NumReservedClauses is a hint for the number of incoming
2147   /// clauses that this landingpad will have (use 0 if you really have no idea).
2148   static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2149                                 unsigned NumReservedClauses,
2150                                 const Twine &NameStr = "",
2151                                 Instruction *InsertBefore = 0);
2152   static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
2153                                 unsigned NumReservedClauses,
2154                                 const Twine &NameStr, BasicBlock *InsertAtEnd);
2155   ~LandingPadInst();
2156
2157   /// Provide fast operand accessors
2158   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2159
2160   /// getPersonalityFn - Get the personality function associated with this
2161   /// landing pad.
2162   Value *getPersonalityFn() const { return getOperand(0); }
2163
2164   /// isCleanup - Return 'true' if this landingpad instruction is a
2165   /// cleanup. I.e., it should be run when unwinding even if its landing pad
2166   /// doesn't catch the exception.
2167   bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
2168
2169   /// setCleanup - Indicate that this landingpad instruction is a cleanup.
2170   void setCleanup(bool V) {
2171     setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
2172                                (V ? 1 : 0));
2173   }
2174
2175   /// addClause - Add a catch or filter clause to the landing pad.
2176   void addClause(Value *ClauseVal);
2177
2178   /// getClause - Get the value of the clause at index Idx. Use isCatch/isFilter
2179   /// to determine what type of clause this is.
2180   Value *getClause(unsigned Idx) const { return OperandList[Idx + 1]; }
2181
2182   /// isCatch - Return 'true' if the clause and index Idx is a catch clause.
2183   bool isCatch(unsigned Idx) const {
2184     return !isa<ArrayType>(OperandList[Idx + 1]->getType());
2185   }
2186
2187   /// isFilter - Return 'true' if the clause and index Idx is a filter clause.
2188   bool isFilter(unsigned Idx) const {
2189     return isa<ArrayType>(OperandList[Idx + 1]->getType());
2190   }
2191
2192   /// getNumClauses - Get the number of clauses for this landing pad.
2193   unsigned getNumClauses() const { return getNumOperands() - 1; }
2194
2195   /// reserveClauses - Grow the size of the operand list to accomodate the new
2196   /// number of clauses.
2197   void reserveClauses(unsigned Size) { growOperands(Size); }
2198
2199   // Methods for support type inquiry through isa, cast, and dyn_cast:
2200   static inline bool classof(const LandingPadInst *) { return true; }
2201   static inline bool classof(const Instruction *I) {
2202     return I->getOpcode() == Instruction::LandingPad;
2203   }
2204   static inline bool classof(const Value *V) {
2205     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2206   }
2207 };
2208
2209 template <>
2210 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
2211 };
2212
2213 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
2214
2215 //===----------------------------------------------------------------------===//
2216 //                               ReturnInst Class
2217 //===----------------------------------------------------------------------===//
2218
2219 //===---------------------------------------------------------------------------
2220 /// ReturnInst - Return a value (possibly void), from a function.  Execution
2221 /// does not continue in this function any longer.
2222 ///
2223 class ReturnInst : public TerminatorInst {
2224   ReturnInst(const ReturnInst &RI);
2225
2226 private:
2227   // ReturnInst constructors:
2228   // ReturnInst()                  - 'ret void' instruction
2229   // ReturnInst(    null)          - 'ret void' instruction
2230   // ReturnInst(Value* X)          - 'ret X'    instruction
2231   // ReturnInst(    null, Inst *I) - 'ret void' instruction, insert before I
2232   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
2233   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of B
2234   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of B
2235   //
2236   // NOTE: If the Value* passed is of type void then the constructor behaves as
2237   // if it was passed NULL.
2238   explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2239                       Instruction *InsertBefore = 0);
2240   ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2241   explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2242 protected:
2243   virtual ReturnInst *clone_impl() const;
2244 public:
2245   static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2246                             Instruction *InsertBefore = 0) {
2247     return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2248   }
2249   static ReturnInst* Create(LLVMContext &C, Value *retVal,
2250                             BasicBlock *InsertAtEnd) {
2251     return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2252   }
2253   static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2254     return new(0) ReturnInst(C, InsertAtEnd);
2255   }
2256   virtual ~ReturnInst();
2257
2258   /// Provide fast operand accessors
2259   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2260
2261   /// Convenience accessor. Returns null if there is no return value.
2262   Value *getReturnValue() const {
2263     return getNumOperands() != 0 ? getOperand(0) : 0;
2264   }
2265
2266   unsigned getNumSuccessors() const { return 0; }
2267
2268   // Methods for support type inquiry through isa, cast, and dyn_cast:
2269   static inline bool classof(const ReturnInst *) { return true; }
2270   static inline bool classof(const Instruction *I) {
2271     return (I->getOpcode() == Instruction::Ret);
2272   }
2273   static inline bool classof(const Value *V) {
2274     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2275   }
2276  private:
2277   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2278   virtual unsigned getNumSuccessorsV() const;
2279   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2280 };
2281
2282 template <>
2283 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
2284 };
2285
2286 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2287
2288 //===----------------------------------------------------------------------===//
2289 //                               BranchInst Class
2290 //===----------------------------------------------------------------------===//
2291
2292 //===---------------------------------------------------------------------------
2293 /// BranchInst - Conditional or Unconditional Branch instruction.
2294 ///
2295 class BranchInst : public TerminatorInst {
2296   /// Ops list - Branches are strange.  The operands are ordered:
2297   ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
2298   /// they don't have to check for cond/uncond branchness. These are mostly
2299   /// accessed relative from op_end().
2300   BranchInst(const BranchInst &BI);
2301   void AssertOK();
2302   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2303   // BranchInst(BB *B)                           - 'br B'
2304   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
2305   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
2306   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2307   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
2308   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
2309   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
2310   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2311              Instruction *InsertBefore = 0);
2312   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
2313   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
2314              BasicBlock *InsertAtEnd);
2315 protected:
2316   virtual BranchInst *clone_impl() const;
2317 public:
2318   static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2319     return new(1) BranchInst(IfTrue, InsertBefore);
2320   }
2321   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2322                             Value *Cond, Instruction *InsertBefore = 0) {
2323     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2324   }
2325   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2326     return new(1) BranchInst(IfTrue, InsertAtEnd);
2327   }
2328   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2329                             Value *Cond, BasicBlock *InsertAtEnd) {
2330     return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2331   }
2332
2333   /// Transparently provide more efficient getOperand methods.
2334   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2335
2336   bool isUnconditional() const { return getNumOperands() == 1; }
2337   bool isConditional()   const { return getNumOperands() == 3; }
2338
2339   Value *getCondition() const {
2340     assert(isConditional() && "Cannot get condition of an uncond branch!");
2341     return Op<-3>();
2342   }
2343
2344   void setCondition(Value *V) {
2345     assert(isConditional() && "Cannot set condition of unconditional branch!");
2346     Op<-3>() = V;
2347   }
2348
2349   unsigned getNumSuccessors() const { return 1+isConditional(); }
2350
2351   BasicBlock *getSuccessor(unsigned i) const {
2352     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
2353     return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
2354   }
2355
2356   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2357     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
2358     *(&Op<-1>() - idx) = (Value*)NewSucc;
2359   }
2360
2361   // Methods for support type inquiry through isa, cast, and dyn_cast:
2362   static inline bool classof(const BranchInst *) { return true; }
2363   static inline bool classof(const Instruction *I) {
2364     return (I->getOpcode() == Instruction::Br);
2365   }
2366   static inline bool classof(const Value *V) {
2367     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2368   }
2369 private:
2370   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2371   virtual unsigned getNumSuccessorsV() const;
2372   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2373 };
2374
2375 template <>
2376 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2377 };
2378
2379 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2380
2381 //===----------------------------------------------------------------------===//
2382 //                               SwitchInst Class
2383 //===----------------------------------------------------------------------===//
2384
2385 //===---------------------------------------------------------------------------
2386 /// SwitchInst - Multiway switch
2387 ///
2388 class SwitchInst : public TerminatorInst {
2389   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2390   unsigned ReservedSpace;
2391   // Operand[0]    = Value to switch on
2392   // Operand[1]    = Default basic block destination
2393   // Operand[2n  ] = Value to match
2394   // Operand[2n+1] = BasicBlock to go to on match
2395   SwitchInst(const SwitchInst &SI);
2396   void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
2397   void growOperands();
2398   // allocate space for exactly zero operands
2399   void *operator new(size_t s) {
2400     return User::operator new(s, 0);
2401   }
2402   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2403   /// switch on and a default destination.  The number of additional cases can
2404   /// be specified here to make memory allocation more efficient.  This
2405   /// constructor can also autoinsert before another instruction.
2406   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2407              Instruction *InsertBefore);
2408
2409   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2410   /// switch on and a default destination.  The number of additional cases can
2411   /// be specified here to make memory allocation more efficient.  This
2412   /// constructor also autoinserts at the end of the specified BasicBlock.
2413   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
2414              BasicBlock *InsertAtEnd);
2415 protected:
2416   virtual SwitchInst *clone_impl() const;
2417 public:
2418   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2419                             unsigned NumCases, Instruction *InsertBefore = 0) {
2420     return new SwitchInst(Value, Default, NumCases, InsertBefore);
2421   }
2422   static SwitchInst *Create(Value *Value, BasicBlock *Default,
2423                             unsigned NumCases, BasicBlock *InsertAtEnd) {
2424     return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
2425   }
2426   ~SwitchInst();
2427
2428   /// Provide fast operand accessors
2429   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2430
2431   // Accessor Methods for Switch stmt
2432   Value *getCondition() const { return getOperand(0); }
2433   void setCondition(Value *V) { setOperand(0, V); }
2434
2435   BasicBlock *getDefaultDest() const {
2436     return cast<BasicBlock>(getOperand(1));
2437   }
2438
2439   /// getNumCases - return the number of 'cases' in this switch instruction.
2440   /// Note that case #0 is always the default case.
2441   unsigned getNumCases() const {
2442     return getNumOperands()/2;
2443   }
2444
2445   /// getCaseValue - Return the specified case value.  Note that case #0, the
2446   /// default destination, does not have a case value.
2447   ConstantInt *getCaseValue(unsigned i) {
2448     assert(i && i < getNumCases() && "Illegal case value to get!");
2449     return getSuccessorValue(i);
2450   }
2451
2452   /// getCaseValue - Return the specified case value.  Note that case #0, the
2453   /// default destination, does not have a case value.
2454   const ConstantInt *getCaseValue(unsigned i) const {
2455     assert(i && i < getNumCases() && "Illegal case value to get!");
2456     return getSuccessorValue(i);
2457   }
2458
2459   /// findCaseValue - Search all of the case values for the specified constant.
2460   /// If it is explicitly handled, return the case number of it, otherwise
2461   /// return 0 to indicate that it is handled by the default handler.
2462   unsigned findCaseValue(const ConstantInt *C) const {
2463     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2464       if (getCaseValue(i) == C)
2465         return i;
2466     return 0;
2467   }
2468
2469   /// findCaseDest - Finds the unique case value for a given successor. Returns
2470   /// null if the successor is not found, not unique, or is the default case.
2471   ConstantInt *findCaseDest(BasicBlock *BB) {
2472     if (BB == getDefaultDest()) return NULL;
2473
2474     ConstantInt *CI = NULL;
2475     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2476       if (getSuccessor(i) == BB) {
2477         if (CI) return NULL;   // Multiple cases lead to BB.
2478         else CI = getCaseValue(i);
2479       }
2480     }
2481     return CI;
2482   }
2483
2484   /// addCase - Add an entry to the switch instruction...
2485   ///
2486   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
2487
2488   /// removeCase - This method removes the specified successor from the switch
2489   /// instruction.  Note that this cannot be used to remove the default
2490   /// destination (successor #0). Also note that this operation may reorder the
2491   /// remaining cases at index idx and above.
2492   ///
2493   void removeCase(unsigned idx);
2494
2495   unsigned getNumSuccessors() const { return getNumOperands()/2; }
2496   BasicBlock *getSuccessor(unsigned idx) const {
2497     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2498     return cast<BasicBlock>(getOperand(idx*2+1));
2499   }
2500   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2501     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
2502     setOperand(idx*2+1, (Value*)NewSucc);
2503   }
2504
2505   // getSuccessorValue - Return the value associated with the specified
2506   // successor.
2507   ConstantInt *getSuccessorValue(unsigned idx) const {
2508     assert(idx < getNumSuccessors() && "Successor # out of range!");
2509     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
2510   }
2511
2512   // setSuccessorValue - Updates the value associated with the specified
2513   // successor.
2514   void setSuccessorValue(unsigned idx, ConstantInt* SuccessorValue) {
2515     assert(idx < getNumSuccessors() && "Successor # out of range!");
2516     setOperand(idx*2, reinterpret_cast<Value*>(SuccessorValue));
2517   }
2518
2519   // Methods for support type inquiry through isa, cast, and dyn_cast:
2520   static inline bool classof(const SwitchInst *) { return true; }
2521   static inline bool classof(const Instruction *I) {
2522     return I->getOpcode() == Instruction::Switch;
2523   }
2524   static inline bool classof(const Value *V) {
2525     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2526   }
2527 private:
2528   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2529   virtual unsigned getNumSuccessorsV() const;
2530   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2531 };
2532
2533 template <>
2534 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
2535 };
2536
2537 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2538
2539
2540 //===----------------------------------------------------------------------===//
2541 //                             IndirectBrInst Class
2542 //===----------------------------------------------------------------------===//
2543
2544 //===---------------------------------------------------------------------------
2545 /// IndirectBrInst - Indirect Branch Instruction.
2546 ///
2547 class IndirectBrInst : public TerminatorInst {
2548   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2549   unsigned ReservedSpace;
2550   // Operand[0]    = Value to switch on
2551   // Operand[1]    = Default basic block destination
2552   // Operand[2n  ] = Value to match
2553   // Operand[2n+1] = BasicBlock to go to on match
2554   IndirectBrInst(const IndirectBrInst &IBI);
2555   void init(Value *Address, unsigned NumDests);
2556   void growOperands();
2557   // allocate space for exactly zero operands
2558   void *operator new(size_t s) {
2559     return User::operator new(s, 0);
2560   }
2561   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2562   /// Address to jump to.  The number of expected destinations can be specified
2563   /// here to make memory allocation more efficient.  This constructor can also
2564   /// autoinsert before another instruction.
2565   IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
2566
2567   /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2568   /// Address to jump to.  The number of expected destinations can be specified
2569   /// here to make memory allocation more efficient.  This constructor also
2570   /// autoinserts at the end of the specified BasicBlock.
2571   IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
2572 protected:
2573   virtual IndirectBrInst *clone_impl() const;
2574 public:
2575   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2576                                 Instruction *InsertBefore = 0) {
2577     return new IndirectBrInst(Address, NumDests, InsertBefore);
2578   }
2579   static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2580                                 BasicBlock *InsertAtEnd) {
2581     return new IndirectBrInst(Address, NumDests, InsertAtEnd);
2582   }
2583   ~IndirectBrInst();
2584
2585   /// Provide fast operand accessors.
2586   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2587
2588   // Accessor Methods for IndirectBrInst instruction.
2589   Value *getAddress() { return getOperand(0); }
2590   const Value *getAddress() const { return getOperand(0); }
2591   void setAddress(Value *V) { setOperand(0, V); }
2592
2593
2594   /// getNumDestinations - return the number of possible destinations in this
2595   /// indirectbr instruction.
2596   unsigned getNumDestinations() const { return getNumOperands()-1; }
2597
2598   /// getDestination - Return the specified destination.
2599   BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2600   const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
2601
2602   /// addDestination - Add a destination.
2603   ///
2604   void addDestination(BasicBlock *Dest);
2605
2606   /// removeDestination - This method removes the specified successor from the
2607   /// indirectbr instruction.
2608   void removeDestination(unsigned i);
2609
2610   unsigned getNumSuccessors() const { return getNumOperands()-1; }
2611   BasicBlock *getSuccessor(unsigned i) const {
2612     return cast<BasicBlock>(getOperand(i+1));
2613   }
2614   void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2615     setOperand(i+1, (Value*)NewSucc);
2616   }
2617
2618   // Methods for support type inquiry through isa, cast, and dyn_cast:
2619   static inline bool classof(const IndirectBrInst *) { return true; }
2620   static inline bool classof(const Instruction *I) {
2621     return I->getOpcode() == Instruction::IndirectBr;
2622   }
2623   static inline bool classof(const Value *V) {
2624     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2625   }
2626 private:
2627   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2628   virtual unsigned getNumSuccessorsV() const;
2629   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2630 };
2631
2632 template <>
2633 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
2634 };
2635
2636 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
2637
2638
2639 //===----------------------------------------------------------------------===//
2640 //                               InvokeInst Class
2641 //===----------------------------------------------------------------------===//
2642
2643 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
2644 /// calling convention of the call.
2645 ///
2646 class InvokeInst : public TerminatorInst {
2647   AttrListPtr AttributeList;
2648   InvokeInst(const InvokeInst &BI);
2649   void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2650             ArrayRef<Value *> Args, const Twine &NameStr);
2651
2652   /// Construct an InvokeInst given a range of arguments.
2653   ///
2654   /// @brief Construct an InvokeInst from a range of arguments
2655   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2656                     ArrayRef<Value *> Args, unsigned Values,
2657                     const Twine &NameStr, Instruction *InsertBefore);
2658
2659   /// Construct an InvokeInst given a range of arguments.
2660   ///
2661   /// @brief Construct an InvokeInst from a range of arguments
2662   inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2663                     ArrayRef<Value *> Args, unsigned Values,
2664                     const Twine &NameStr, BasicBlock *InsertAtEnd);
2665 protected:
2666   virtual InvokeInst *clone_impl() const;
2667 public:
2668   static InvokeInst *Create(Value *Func,
2669                             BasicBlock *IfNormal, BasicBlock *IfException,
2670                             ArrayRef<Value *> Args, const Twine &NameStr = "",
2671                             Instruction *InsertBefore = 0) {
2672     unsigned Values = unsigned(Args.size()) + 3;
2673     return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2674                                   Values, NameStr, InsertBefore);
2675   }
2676   static InvokeInst *Create(Value *Func,
2677                             BasicBlock *IfNormal, BasicBlock *IfException,
2678                             ArrayRef<Value *> Args, const Twine &NameStr,
2679                             BasicBlock *InsertAtEnd) {
2680     unsigned Values = unsigned(Args.size()) + 3;
2681     return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
2682                                   Values, NameStr, InsertAtEnd);
2683   }
2684
2685   /// Provide fast operand accessors
2686   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2687
2688   /// getNumArgOperands - Return the number of invoke arguments.
2689   ///
2690   unsigned getNumArgOperands() const { return getNumOperands() - 3; }
2691
2692   /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2693   ///
2694   Value *getArgOperand(unsigned i) const { return getOperand(i); }
2695   void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
2696
2697   /// getCallingConv/setCallingConv - Get or set the calling convention of this
2698   /// function call.
2699   CallingConv::ID getCallingConv() const {
2700     return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
2701   }
2702   void setCallingConv(CallingConv::ID CC) {
2703     setInstructionSubclassData(static_cast<unsigned>(CC));
2704   }
2705
2706   /// getAttributes - Return the parameter attributes for this invoke.
2707   ///
2708   const AttrListPtr &getAttributes() const { return AttributeList; }
2709
2710   /// setAttributes - Set the parameter attributes for this invoke.
2711   ///
2712   void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
2713
2714   /// addAttribute - adds the attribute to the list of attributes.
2715   void addAttribute(unsigned i, Attributes attr);
2716
2717   /// removeAttribute - removes the attribute from the list of attributes.
2718   void removeAttribute(unsigned i, Attributes attr);
2719
2720   /// @brief Determine whether the call or the callee has the given attribute.
2721   bool paramHasAttr(unsigned i, Attributes attr) const;
2722
2723   /// @brief Extract the alignment for a call or parameter (0=unknown).
2724   unsigned getParamAlignment(unsigned i) const {
2725     return AttributeList.getParamAlignment(i);
2726   }
2727
2728   /// @brief Return true if the call should not be inlined.
2729   bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
2730   void setIsNoInline(bool Value = true) {
2731     if (Value) addAttribute(~0, Attribute::NoInline);
2732     else removeAttribute(~0, Attribute::NoInline);
2733   }
2734
2735   /// @brief Determine if the call does not access memory.
2736   bool doesNotAccessMemory() const {
2737     return paramHasAttr(~0, Attribute::ReadNone);
2738   }
2739   void setDoesNotAccessMemory(bool NotAccessMemory = true) {
2740     if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2741     else removeAttribute(~0, Attribute::ReadNone);
2742   }
2743
2744   /// @brief Determine if the call does not access or only reads memory.
2745   bool onlyReadsMemory() const {
2746     return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
2747   }
2748   void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
2749     if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2750     else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
2751   }
2752
2753   /// @brief Determine if the call cannot return.
2754   bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
2755   void setDoesNotReturn(bool DoesNotReturn = true) {
2756     if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2757     else removeAttribute(~0, Attribute::NoReturn);
2758   }
2759
2760   /// @brief Determine if the call cannot unwind.
2761   bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
2762   void setDoesNotThrow(bool DoesNotThrow = true) {
2763     if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2764     else removeAttribute(~0, Attribute::NoUnwind);
2765   }
2766
2767   /// @brief Determine if the call returns a structure through first
2768   /// pointer argument.
2769   bool hasStructRetAttr() const {
2770     // Be friendly and also check the callee.
2771     return paramHasAttr(1, Attribute::StructRet);
2772   }
2773
2774   /// @brief Determine if any call argument is an aggregate passed by value.
2775   bool hasByValArgument() const {
2776     return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2777   }
2778
2779   /// getCalledFunction - Return the function called, or null if this is an
2780   /// indirect function invocation.
2781   ///
2782   Function *getCalledFunction() const {
2783     return dyn_cast<Function>(Op<-3>());
2784   }
2785
2786   /// getCalledValue - Get a pointer to the function that is invoked by this
2787   /// instruction
2788   const Value *getCalledValue() const { return Op<-3>(); }
2789         Value *getCalledValue()       { return Op<-3>(); }
2790
2791   /// setCalledFunction - Set the function called.
2792   void setCalledFunction(Value* Fn) {
2793     Op<-3>() = Fn;
2794   }
2795
2796   // get*Dest - Return the destination basic blocks...
2797   BasicBlock *getNormalDest() const {
2798     return cast<BasicBlock>(Op<-2>());
2799   }
2800   BasicBlock *getUnwindDest() const {
2801     return cast<BasicBlock>(Op<-1>());
2802   }
2803   void setNormalDest(BasicBlock *B) {
2804     Op<-2>() = reinterpret_cast<Value*>(B);
2805   }
2806   void setUnwindDest(BasicBlock *B) {
2807     Op<-1>() = reinterpret_cast<Value*>(B);
2808   }
2809
2810   /// getLandingPadInst - Get the landingpad instruction from the landing pad
2811   /// block (the unwind destination).
2812   LandingPadInst *getLandingPadInst() const;
2813
2814   BasicBlock *getSuccessor(unsigned i) const {
2815     assert(i < 2 && "Successor # out of range for invoke!");
2816     return i == 0 ? getNormalDest() : getUnwindDest();
2817   }
2818
2819   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
2820     assert(idx < 2 && "Successor # out of range for invoke!");
2821     *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
2822   }
2823
2824   unsigned getNumSuccessors() const { return 2; }
2825
2826   // Methods for support type inquiry through isa, cast, and dyn_cast:
2827   static inline bool classof(const InvokeInst *) { return true; }
2828   static inline bool classof(const Instruction *I) {
2829     return (I->getOpcode() == Instruction::Invoke);
2830   }
2831   static inline bool classof(const Value *V) {
2832     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2833   }
2834
2835 private:
2836   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2837   virtual unsigned getNumSuccessorsV() const;
2838   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2839
2840   // Shadow Instruction::setInstructionSubclassData with a private forwarding
2841   // method so that subclasses cannot accidentally use it.
2842   void setInstructionSubclassData(unsigned short D) {
2843     Instruction::setInstructionSubclassData(D);
2844   }
2845 };
2846
2847 template <>
2848 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
2849 };
2850
2851 InvokeInst::InvokeInst(Value *Func,
2852                        BasicBlock *IfNormal, BasicBlock *IfException,
2853                        ArrayRef<Value *> Args, unsigned Values,
2854                        const Twine &NameStr, Instruction *InsertBefore)
2855   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2856                                       ->getElementType())->getReturnType(),
2857                    Instruction::Invoke,
2858                    OperandTraits<InvokeInst>::op_end(this) - Values,
2859                    Values, InsertBefore) {
2860   init(Func, IfNormal, IfException, Args, NameStr);
2861 }
2862 InvokeInst::InvokeInst(Value *Func,
2863                        BasicBlock *IfNormal, BasicBlock *IfException,
2864                        ArrayRef<Value *> Args, unsigned Values,
2865                        const Twine &NameStr, BasicBlock *InsertAtEnd)
2866   : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2867                                       ->getElementType())->getReturnType(),
2868                    Instruction::Invoke,
2869                    OperandTraits<InvokeInst>::op_end(this) - Values,
2870                    Values, InsertAtEnd) {
2871   init(Func, IfNormal, IfException, Args, NameStr);
2872 }
2873
2874 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
2875
2876 //===----------------------------------------------------------------------===//
2877 //                              UnwindInst Class
2878 //===----------------------------------------------------------------------===//
2879
2880 //===---------------------------------------------------------------------------
2881 /// UnwindInst - Immediately exit the current function, unwinding the stack
2882 /// until an invoke instruction is found.
2883 ///
2884 class UnwindInst : public TerminatorInst {
2885   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2886 protected:
2887   virtual UnwindInst *clone_impl() const;
2888 public:
2889   // allocate space for exactly zero operands
2890   void *operator new(size_t s) {
2891     return User::operator new(s, 0);
2892   }
2893   explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2894   explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2895
2896   unsigned getNumSuccessors() const { return 0; }
2897
2898   // Methods for support type inquiry through isa, cast, and dyn_cast:
2899   static inline bool classof(const UnwindInst *) { return true; }
2900   static inline bool classof(const Instruction *I) {
2901     return I->getOpcode() == Instruction::Unwind;
2902   }
2903   static inline bool classof(const Value *V) {
2904     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2905   }
2906 private:
2907   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2908   virtual unsigned getNumSuccessorsV() const;
2909   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2910 };
2911
2912 //===----------------------------------------------------------------------===//
2913 //                              ResumeInst Class
2914 //===----------------------------------------------------------------------===//
2915
2916 //===---------------------------------------------------------------------------
2917 /// ResumeInst - Resume the propagation of an exception.
2918 ///
2919 class ResumeInst : public TerminatorInst {
2920   ResumeInst(const ResumeInst &RI);
2921
2922   explicit ResumeInst(Value *Exn, Instruction *InsertBefore=0);
2923   ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
2924 protected:
2925   virtual ResumeInst *clone_impl() const;
2926 public:
2927   static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = 0) {
2928     return new(1) ResumeInst(Exn, InsertBefore);
2929   }
2930   static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
2931     return new(1) ResumeInst(Exn, InsertAtEnd);
2932   }
2933
2934   /// Provide fast operand accessors
2935   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2936
2937   /// Convenience accessor.
2938   Value *getValue() const { return Op<0>(); }
2939
2940   unsigned getNumSuccessors() const { return 0; }
2941
2942   // Methods for support type inquiry through isa, cast, and dyn_cast:
2943   static inline bool classof(const ResumeInst *) { return true; }
2944   static inline bool classof(const Instruction *I) {
2945     return I->getOpcode() == Instruction::Resume;
2946   }
2947   static inline bool classof(const Value *V) {
2948     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2949   }
2950 private:
2951   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2952   virtual unsigned getNumSuccessorsV() const;
2953   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2954 };
2955
2956 template <>
2957 struct OperandTraits<ResumeInst> :
2958     public FixedNumOperandTraits<ResumeInst, 1> {
2959 };
2960
2961 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
2962
2963 //===----------------------------------------------------------------------===//
2964 //                           UnreachableInst Class
2965 //===----------------------------------------------------------------------===//
2966
2967 //===---------------------------------------------------------------------------
2968 /// UnreachableInst - This function has undefined behavior.  In particular, the
2969 /// presence of this instruction indicates some higher level knowledge that the
2970 /// end of the block cannot be reached.
2971 ///
2972 class UnreachableInst : public TerminatorInst {
2973   void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
2974 protected:
2975   virtual UnreachableInst *clone_impl() const;
2976
2977 public:
2978   // allocate space for exactly zero operands
2979   void *operator new(size_t s) {
2980     return User::operator new(s, 0);
2981   }
2982   explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2983   explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2984
2985   unsigned getNumSuccessors() const { return 0; }
2986
2987   // Methods for support type inquiry through isa, cast, and dyn_cast:
2988   static inline bool classof(const UnreachableInst *) { return true; }
2989   static inline bool classof(const Instruction *I) {
2990     return I->getOpcode() == Instruction::Unreachable;
2991   }
2992   static inline bool classof(const Value *V) {
2993     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2994   }
2995 private:
2996   virtual BasicBlock *getSuccessorV(unsigned idx) const;
2997   virtual unsigned getNumSuccessorsV() const;
2998   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2999 };
3000
3001 //===----------------------------------------------------------------------===//
3002 //                                 TruncInst Class
3003 //===----------------------------------------------------------------------===//
3004
3005 /// @brief This class represents a truncation of integer types.
3006 class TruncInst : public CastInst {
3007 protected:
3008   /// @brief Clone an identical TruncInst
3009   virtual TruncInst *clone_impl() const;
3010
3011 public:
3012   /// @brief Constructor with insert-before-instruction semantics
3013   TruncInst(
3014     Value *S,                     ///< The value to be truncated
3015     Type *Ty,               ///< The (smaller) type to truncate to
3016     const Twine &NameStr = "",    ///< A name for the new instruction
3017     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3018   );
3019
3020   /// @brief Constructor with insert-at-end-of-block semantics
3021   TruncInst(
3022     Value *S,                     ///< The value to be truncated
3023     Type *Ty,               ///< The (smaller) type to truncate to
3024     const Twine &NameStr,         ///< A name for the new instruction
3025     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3026   );
3027
3028   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3029   static inline bool classof(const TruncInst *) { return true; }
3030   static inline bool classof(const Instruction *I) {
3031     return I->getOpcode() == Trunc;
3032   }
3033   static inline bool classof(const Value *V) {
3034     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3035   }
3036 };
3037
3038 //===----------------------------------------------------------------------===//
3039 //                                 ZExtInst Class
3040 //===----------------------------------------------------------------------===//
3041
3042 /// @brief This class represents zero extension of integer types.
3043 class ZExtInst : public CastInst {
3044 protected:
3045   /// @brief Clone an identical ZExtInst
3046   virtual ZExtInst *clone_impl() const;
3047
3048 public:
3049   /// @brief Constructor with insert-before-instruction semantics
3050   ZExtInst(
3051     Value *S,                     ///< The value to be zero extended
3052     Type *Ty,               ///< The type to zero extend to
3053     const Twine &NameStr = "",    ///< A name for the new instruction
3054     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3055   );
3056
3057   /// @brief Constructor with insert-at-end semantics.
3058   ZExtInst(
3059     Value *S,                     ///< The value to be zero extended
3060     Type *Ty,               ///< The type to zero extend to
3061     const Twine &NameStr,         ///< A name for the new instruction
3062     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3063   );
3064
3065   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3066   static inline bool classof(const ZExtInst *) { return true; }
3067   static inline bool classof(const Instruction *I) {
3068     return I->getOpcode() == ZExt;
3069   }
3070   static inline bool classof(const Value *V) {
3071     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3072   }
3073 };
3074
3075 //===----------------------------------------------------------------------===//
3076 //                                 SExtInst Class
3077 //===----------------------------------------------------------------------===//
3078
3079 /// @brief This class represents a sign extension of integer types.
3080 class SExtInst : public CastInst {
3081 protected:
3082   /// @brief Clone an identical SExtInst
3083   virtual SExtInst *clone_impl() const;
3084
3085 public:
3086   /// @brief Constructor with insert-before-instruction semantics
3087   SExtInst(
3088     Value *S,                     ///< The value to be sign extended
3089     Type *Ty,               ///< The type to sign extend to
3090     const Twine &NameStr = "",    ///< A name for the new instruction
3091     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3092   );
3093
3094   /// @brief Constructor with insert-at-end-of-block semantics
3095   SExtInst(
3096     Value *S,                     ///< The value to be sign extended
3097     Type *Ty,               ///< The type to sign extend to
3098     const Twine &NameStr,         ///< A name for the new instruction
3099     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3100   );
3101
3102   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3103   static inline bool classof(const SExtInst *) { return true; }
3104   static inline bool classof(const Instruction *I) {
3105     return I->getOpcode() == SExt;
3106   }
3107   static inline bool classof(const Value *V) {
3108     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3109   }
3110 };
3111
3112 //===----------------------------------------------------------------------===//
3113 //                                 FPTruncInst Class
3114 //===----------------------------------------------------------------------===//
3115
3116 /// @brief This class represents a truncation of floating point types.
3117 class FPTruncInst : public CastInst {
3118 protected:
3119   /// @brief Clone an identical FPTruncInst
3120   virtual FPTruncInst *clone_impl() const;
3121
3122 public:
3123   /// @brief Constructor with insert-before-instruction semantics
3124   FPTruncInst(
3125     Value *S,                     ///< The value to be truncated
3126     Type *Ty,               ///< The type to truncate to
3127     const Twine &NameStr = "",    ///< A name for the new instruction
3128     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3129   );
3130
3131   /// @brief Constructor with insert-before-instruction semantics
3132   FPTruncInst(
3133     Value *S,                     ///< The value to be truncated
3134     Type *Ty,               ///< The type to truncate to
3135     const Twine &NameStr,         ///< A name for the new instruction
3136     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3137   );
3138
3139   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3140   static inline bool classof(const FPTruncInst *) { return true; }
3141   static inline bool classof(const Instruction *I) {
3142     return I->getOpcode() == FPTrunc;
3143   }
3144   static inline bool classof(const Value *V) {
3145     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3146   }
3147 };
3148
3149 //===----------------------------------------------------------------------===//
3150 //                                 FPExtInst Class
3151 //===----------------------------------------------------------------------===//
3152
3153 /// @brief This class represents an extension of floating point types.
3154 class FPExtInst : public CastInst {
3155 protected:
3156   /// @brief Clone an identical FPExtInst
3157   virtual FPExtInst *clone_impl() const;
3158
3159 public:
3160   /// @brief Constructor with insert-before-instruction semantics
3161   FPExtInst(
3162     Value *S,                     ///< The value to be extended
3163     Type *Ty,               ///< The type to extend to
3164     const Twine &NameStr = "",    ///< A name for the new instruction
3165     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3166   );
3167
3168   /// @brief Constructor with insert-at-end-of-block semantics
3169   FPExtInst(
3170     Value *S,                     ///< The value to be extended
3171     Type *Ty,               ///< The type to extend to
3172     const Twine &NameStr,         ///< A name for the new instruction
3173     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3174   );
3175
3176   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3177   static inline bool classof(const FPExtInst *) { return true; }
3178   static inline bool classof(const Instruction *I) {
3179     return I->getOpcode() == FPExt;
3180   }
3181   static inline bool classof(const Value *V) {
3182     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3183   }
3184 };
3185
3186 //===----------------------------------------------------------------------===//
3187 //                                 UIToFPInst Class
3188 //===----------------------------------------------------------------------===//
3189
3190 /// @brief This class represents a cast unsigned integer to floating point.
3191 class UIToFPInst : public CastInst {
3192 protected:
3193   /// @brief Clone an identical UIToFPInst
3194   virtual UIToFPInst *clone_impl() const;
3195
3196 public:
3197   /// @brief Constructor with insert-before-instruction semantics
3198   UIToFPInst(
3199     Value *S,                     ///< The value to be converted
3200     Type *Ty,               ///< The type to convert to
3201     const Twine &NameStr = "",    ///< A name for the new instruction
3202     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3203   );
3204
3205   /// @brief Constructor with insert-at-end-of-block semantics
3206   UIToFPInst(
3207     Value *S,                     ///< The value to be converted
3208     Type *Ty,               ///< The type to convert to
3209     const Twine &NameStr,         ///< A name for the new instruction
3210     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3211   );
3212
3213   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3214   static inline bool classof(const UIToFPInst *) { return true; }
3215   static inline bool classof(const Instruction *I) {
3216     return I->getOpcode() == UIToFP;
3217   }
3218   static inline bool classof(const Value *V) {
3219     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3220   }
3221 };
3222
3223 //===----------------------------------------------------------------------===//
3224 //                                 SIToFPInst Class
3225 //===----------------------------------------------------------------------===//
3226
3227 /// @brief This class represents a cast from signed integer to floating point.
3228 class SIToFPInst : public CastInst {
3229 protected:
3230   /// @brief Clone an identical SIToFPInst
3231   virtual SIToFPInst *clone_impl() const;
3232
3233 public:
3234   /// @brief Constructor with insert-before-instruction semantics
3235   SIToFPInst(
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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3240   );
3241
3242   /// @brief Constructor with insert-at-end-of-block semantics
3243   SIToFPInst(
3244     Value *S,                     ///< The value to be converted
3245     Type *Ty,               ///< The type to convert to
3246     const Twine &NameStr,         ///< A name for the new instruction
3247     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3248   );
3249
3250   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3251   static inline bool classof(const SIToFPInst *) { return true; }
3252   static inline bool classof(const Instruction *I) {
3253     return I->getOpcode() == SIToFP;
3254   }
3255   static inline bool classof(const Value *V) {
3256     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3257   }
3258 };
3259
3260 //===----------------------------------------------------------------------===//
3261 //                                 FPToUIInst Class
3262 //===----------------------------------------------------------------------===//
3263
3264 /// @brief This class represents a cast from floating point to unsigned integer
3265 class FPToUIInst  : public CastInst {
3266 protected:
3267   /// @brief Clone an identical FPToUIInst
3268   virtual FPToUIInst *clone_impl() const;
3269
3270 public:
3271   /// @brief Constructor with insert-before-instruction semantics
3272   FPToUIInst(
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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3277   );
3278
3279   /// @brief Constructor with insert-at-end-of-block semantics
3280   FPToUIInst(
3281     Value *S,                     ///< The value to be converted
3282     Type *Ty,               ///< The type to convert to
3283     const Twine &NameStr,         ///< A name for the new instruction
3284     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
3285   );
3286
3287   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3288   static inline bool classof(const FPToUIInst *) { return true; }
3289   static inline bool classof(const Instruction *I) {
3290     return I->getOpcode() == FPToUI;
3291   }
3292   static inline bool classof(const Value *V) {
3293     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3294   }
3295 };
3296
3297 //===----------------------------------------------------------------------===//
3298 //                                 FPToSIInst Class
3299 //===----------------------------------------------------------------------===//
3300
3301 /// @brief This class represents a cast from floating point to signed integer.
3302 class FPToSIInst  : public CastInst {
3303 protected:
3304   /// @brief Clone an identical FPToSIInst
3305   virtual FPToSIInst *clone_impl() const;
3306
3307 public:
3308   /// @brief Constructor with insert-before-instruction semantics
3309   FPToSIInst(
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     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3314   );
3315
3316   /// @brief Constructor with insert-at-end-of-block semantics
3317   FPToSIInst(
3318     Value *S,                     ///< The value to be converted
3319     Type *Ty,               ///< The type to convert to
3320     const Twine &NameStr,         ///< A name for the new instruction
3321     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3322   );
3323
3324   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3325   static inline bool classof(const FPToSIInst *) { return true; }
3326   static inline bool classof(const Instruction *I) {
3327     return I->getOpcode() == FPToSI;
3328   }
3329   static inline bool classof(const Value *V) {
3330     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3331   }
3332 };
3333
3334 //===----------------------------------------------------------------------===//
3335 //                                 IntToPtrInst Class
3336 //===----------------------------------------------------------------------===//
3337
3338 /// @brief This class represents a cast from an integer to a pointer.
3339 class IntToPtrInst : public CastInst {
3340 public:
3341   /// @brief Constructor with insert-before-instruction semantics
3342   IntToPtrInst(
3343     Value *S,                     ///< The value to be converted
3344     Type *Ty,               ///< The type to convert to
3345     const Twine &NameStr = "",    ///< A name for the new instruction
3346     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3347   );
3348
3349   /// @brief Constructor with insert-at-end-of-block semantics
3350   IntToPtrInst(
3351     Value *S,                     ///< The value to be converted
3352     Type *Ty,               ///< The type to convert to
3353     const Twine &NameStr,         ///< A name for the new instruction
3354     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3355   );
3356
3357   /// @brief Clone an identical IntToPtrInst
3358   virtual IntToPtrInst *clone_impl() const;
3359
3360   // Methods for support type inquiry through isa, cast, and dyn_cast:
3361   static inline bool classof(const IntToPtrInst *) { return true; }
3362   static inline bool classof(const Instruction *I) {
3363     return I->getOpcode() == IntToPtr;
3364   }
3365   static inline bool classof(const Value *V) {
3366     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3367   }
3368 };
3369
3370 //===----------------------------------------------------------------------===//
3371 //                                 PtrToIntInst Class
3372 //===----------------------------------------------------------------------===//
3373
3374 /// @brief This class represents a cast from a pointer to an integer
3375 class PtrToIntInst : public CastInst {
3376 protected:
3377   /// @brief Clone an identical PtrToIntInst
3378   virtual PtrToIntInst *clone_impl() const;
3379
3380 public:
3381   /// @brief Constructor with insert-before-instruction semantics
3382   PtrToIntInst(
3383     Value *S,                     ///< The value to be converted
3384     Type *Ty,               ///< The type to convert to
3385     const Twine &NameStr = "",    ///< A name for the new instruction
3386     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3387   );
3388
3389   /// @brief Constructor with insert-at-end-of-block semantics
3390   PtrToIntInst(
3391     Value *S,                     ///< The value to be converted
3392     Type *Ty,               ///< The type to convert to
3393     const Twine &NameStr,         ///< A name for the new instruction
3394     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3395   );
3396
3397   // Methods for support type inquiry through isa, cast, and dyn_cast:
3398   static inline bool classof(const PtrToIntInst *) { return true; }
3399   static inline bool classof(const Instruction *I) {
3400     return I->getOpcode() == PtrToInt;
3401   }
3402   static inline bool classof(const Value *V) {
3403     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3404   }
3405 };
3406
3407 //===----------------------------------------------------------------------===//
3408 //                             BitCastInst Class
3409 //===----------------------------------------------------------------------===//
3410
3411 /// @brief This class represents a no-op cast from one type to another.
3412 class BitCastInst : public CastInst {
3413 protected:
3414   /// @brief Clone an identical BitCastInst
3415   virtual BitCastInst *clone_impl() const;
3416
3417 public:
3418   /// @brief Constructor with insert-before-instruction semantics
3419   BitCastInst(
3420     Value *S,                     ///< The value to be casted
3421     Type *Ty,               ///< The type to casted to
3422     const Twine &NameStr = "",    ///< A name for the new instruction
3423     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3424   );
3425
3426   /// @brief Constructor with insert-at-end-of-block semantics
3427   BitCastInst(
3428     Value *S,                     ///< The value to be casted
3429     Type *Ty,               ///< The type to casted to
3430     const Twine &NameStr,         ///< A name for the new instruction
3431     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
3432   );
3433
3434   // Methods for support type inquiry through isa, cast, and dyn_cast:
3435   static inline bool classof(const BitCastInst *) { return true; }
3436   static inline bool classof(const Instruction *I) {
3437     return I->getOpcode() == BitCast;
3438   }
3439   static inline bool classof(const Value *V) {
3440     return isa<Instruction>(V) && classof(cast<Instruction>(V));
3441   }
3442 };
3443
3444 } // End llvm namespace
3445
3446 #endif