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