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