For PR950:
[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 was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file exposes the class definitions of all of the subclasses of the
11 // Instruction class.  This is meant to be an easy way to get access to all
12 // instruction subclasses.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_INSTRUCTIONS_H
17 #define LLVM_INSTRUCTIONS_H
18
19 #include "llvm/InstrTypes.h"
20
21 namespace llvm {
22
23 class BasicBlock;
24 class ConstantInt;
25 class PointerType;
26 class PackedType;
27
28 //===----------------------------------------------------------------------===//
29 //                             AllocationInst Class
30 //===----------------------------------------------------------------------===//
31
32 /// AllocationInst - This class is the common base class of MallocInst and
33 /// AllocaInst.
34 ///
35 class AllocationInst : public UnaryInstruction {
36   unsigned Alignment;
37 protected:
38   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
39                  const std::string &Name = "", Instruction *InsertBefore = 0);
40   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
41                  const std::string &Name, BasicBlock *InsertAtEnd);
42 public:
43   // Out of line virtual method, so the vtable, etc has a home.
44   virtual ~AllocationInst();
45
46   /// isArrayAllocation - Return true if there is an allocation size parameter
47   /// to the allocation instruction that is not 1.
48   ///
49   bool isArrayAllocation() const;
50
51   /// getArraySize - Get the number of element allocated, for a simple
52   /// allocation of a single element, this will return a constant 1 value.
53   ///
54   inline const Value *getArraySize() const { return getOperand(0); }
55   inline Value *getArraySize() { return getOperand(0); }
56
57   /// getType - Overload to return most specific pointer type
58   ///
59   inline const PointerType *getType() const {
60     return reinterpret_cast<const PointerType*>(Instruction::getType());
61   }
62
63   /// getAllocatedType - Return the type that is being allocated by the
64   /// instruction.
65   ///
66   const Type *getAllocatedType() const;
67
68   /// getAlignment - Return the alignment of the memory that is being allocated
69   /// by the instruction.
70   ///
71   unsigned getAlignment() const { return Alignment; }
72   void setAlignment(unsigned Align) {
73     assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
74     Alignment = Align;
75   }
76
77   virtual Instruction *clone() const = 0;
78
79   // Methods for support type inquiry through isa, cast, and dyn_cast:
80   static inline bool classof(const AllocationInst *) { return true; }
81   static inline bool classof(const Instruction *I) {
82     return I->getOpcode() == Instruction::Alloca ||
83            I->getOpcode() == Instruction::Malloc;
84   }
85   static inline bool classof(const Value *V) {
86     return isa<Instruction>(V) && classof(cast<Instruction>(V));
87   }
88 };
89
90
91 //===----------------------------------------------------------------------===//
92 //                                MallocInst Class
93 //===----------------------------------------------------------------------===//
94
95 /// MallocInst - an instruction to allocated memory on the heap
96 ///
97 class MallocInst : public AllocationInst {
98   MallocInst(const MallocInst &MI);
99 public:
100   explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
101                       const std::string &Name = "",
102                       Instruction *InsertBefore = 0)
103     : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
104   MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
105              BasicBlock *InsertAtEnd)
106     : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
107
108   MallocInst(const Type *Ty, const std::string &Name,
109              Instruction *InsertBefore = 0)
110     : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
111   MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
112     : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
113
114   MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
115              const std::string &Name, BasicBlock *InsertAtEnd)
116     : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
117   MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
118                       const std::string &Name = "",
119                       Instruction *InsertBefore = 0)
120     : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
121
122   virtual MallocInst *clone() const;
123
124   // Methods for support type inquiry through isa, cast, and dyn_cast:
125   static inline bool classof(const MallocInst *) { return true; }
126   static inline bool classof(const Instruction *I) {
127     return (I->getOpcode() == Instruction::Malloc);
128   }
129   static inline bool classof(const Value *V) {
130     return isa<Instruction>(V) && classof(cast<Instruction>(V));
131   }
132 };
133
134
135 //===----------------------------------------------------------------------===//
136 //                                AllocaInst Class
137 //===----------------------------------------------------------------------===//
138
139 /// AllocaInst - an instruction to allocate memory on the stack
140 ///
141 class AllocaInst : public AllocationInst {
142   AllocaInst(const AllocaInst &);
143 public:
144   explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
145                       const std::string &Name = "",
146                       Instruction *InsertBefore = 0)
147     : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
148   AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
149              BasicBlock *InsertAtEnd)
150     : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
151
152   AllocaInst(const Type *Ty, const std::string &Name,
153              Instruction *InsertBefore = 0)
154     : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
155   AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
156     : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
157
158   AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
159              const std::string &Name = "", Instruction *InsertBefore = 0)
160     : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
161   AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
162              const std::string &Name, BasicBlock *InsertAtEnd)
163     : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
164
165   virtual AllocaInst *clone() const;
166
167   // Methods for support type inquiry through isa, cast, and dyn_cast:
168   static inline bool classof(const AllocaInst *) { return true; }
169   static inline bool classof(const Instruction *I) {
170     return (I->getOpcode() == Instruction::Alloca);
171   }
172   static inline bool classof(const Value *V) {
173     return isa<Instruction>(V) && classof(cast<Instruction>(V));
174   }
175 };
176
177
178 //===----------------------------------------------------------------------===//
179 //                                 FreeInst Class
180 //===----------------------------------------------------------------------===//
181
182 /// FreeInst - an instruction to deallocate memory
183 ///
184 class FreeInst : public UnaryInstruction {
185   void AssertOK();
186 public:
187   explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
188   FreeInst(Value *Ptr, BasicBlock *InsertAfter);
189
190   virtual FreeInst *clone() const;
191
192   virtual bool mayWriteToMemory() const { return true; }
193
194   // Methods for support type inquiry through isa, cast, and dyn_cast:
195   static inline bool classof(const FreeInst *) { return true; }
196   static inline bool classof(const Instruction *I) {
197     return (I->getOpcode() == Instruction::Free);
198   }
199   static inline bool classof(const Value *V) {
200     return isa<Instruction>(V) && classof(cast<Instruction>(V));
201   }
202 };
203
204
205 //===----------------------------------------------------------------------===//
206 //                                LoadInst Class
207 //===----------------------------------------------------------------------===//
208
209 /// LoadInst - an instruction for reading from memory.  This uses the
210 /// SubclassData field in Value to store whether or not the load is volatile.
211 ///
212 class LoadInst : public UnaryInstruction {
213   LoadInst(const LoadInst &LI)
214     : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
215     setVolatile(LI.isVolatile());
216
217 #ifndef NDEBUG
218     AssertOK();
219 #endif
220   }
221   void AssertOK();
222 public:
223   LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
224   LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
225   explicit LoadInst(Value *Ptr, const std::string &Name = "",
226                     bool isVolatile = false, Instruction *InsertBefore = 0);
227   LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
228            BasicBlock *InsertAtEnd);
229
230   /// isVolatile - Return true if this is a load from a volatile memory
231   /// location.
232   ///
233   bool isVolatile() const { return SubclassData; }
234
235   /// setVolatile - Specify whether this is a volatile load or not.
236   ///
237   void setVolatile(bool V) { SubclassData = V; }
238
239   virtual LoadInst *clone() const;
240
241   virtual bool mayWriteToMemory() const { return isVolatile(); }
242
243   Value *getPointerOperand() { return getOperand(0); }
244   const Value *getPointerOperand() const { return getOperand(0); }
245   static unsigned getPointerOperandIndex() { return 0U; }
246
247   // Methods for support type inquiry through isa, cast, and dyn_cast:
248   static inline bool classof(const LoadInst *) { return true; }
249   static inline bool classof(const Instruction *I) {
250     return I->getOpcode() == Instruction::Load;
251   }
252   static inline bool classof(const Value *V) {
253     return isa<Instruction>(V) && classof(cast<Instruction>(V));
254   }
255 };
256
257
258 //===----------------------------------------------------------------------===//
259 //                                StoreInst Class
260 //===----------------------------------------------------------------------===//
261
262 /// StoreInst - an instruction for storing to memory
263 ///
264 class StoreInst : public Instruction {
265   Use Ops[2];
266   StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
267     Ops[0].init(SI.Ops[0], this);
268     Ops[1].init(SI.Ops[1], this);
269     setVolatile(SI.isVolatile());
270 #ifndef NDEBUG
271     AssertOK();
272 #endif
273   }
274   void AssertOK();
275 public:
276   StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
277   StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
278   StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
279             Instruction *InsertBefore = 0);
280   StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
281
282
283   /// isVolatile - Return true if this is a load from a volatile memory
284   /// location.
285   ///
286   bool isVolatile() const { return SubclassData; }
287
288   /// setVolatile - Specify whether this is a volatile load or not.
289   ///
290   void setVolatile(bool V) { SubclassData = V; }
291
292   /// Transparently provide more efficient getOperand methods.
293   Value *getOperand(unsigned i) const {
294     assert(i < 2 && "getOperand() out of range!");
295     return Ops[i];
296   }
297   void setOperand(unsigned i, Value *Val) {
298     assert(i < 2 && "setOperand() out of range!");
299     Ops[i] = Val;
300   }
301   unsigned getNumOperands() const { return 2; }
302
303
304   virtual StoreInst *clone() const;
305
306   virtual bool mayWriteToMemory() const { return true; }
307
308   Value *getPointerOperand() { return getOperand(1); }
309   const Value *getPointerOperand() const { return getOperand(1); }
310   static unsigned getPointerOperandIndex() { return 1U; }
311
312   // Methods for support type inquiry through isa, cast, and dyn_cast:
313   static inline bool classof(const StoreInst *) { return true; }
314   static inline bool classof(const Instruction *I) {
315     return I->getOpcode() == Instruction::Store;
316   }
317   static inline bool classof(const Value *V) {
318     return isa<Instruction>(V) && classof(cast<Instruction>(V));
319   }
320 };
321
322
323 //===----------------------------------------------------------------------===//
324 //                             GetElementPtrInst Class
325 //===----------------------------------------------------------------------===//
326
327 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
328 /// access elements of arrays and structs
329 ///
330 class GetElementPtrInst : public Instruction {
331   GetElementPtrInst(const GetElementPtrInst &GEPI)
332     : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
333                   0, GEPI.getNumOperands()) {
334     Use *OL = OperandList = new Use[NumOperands];
335     Use *GEPIOL = GEPI.OperandList;
336     for (unsigned i = 0, E = NumOperands; i != E; ++i)
337       OL[i].init(GEPIOL[i], this);
338   }
339   void init(Value *Ptr, const std::vector<Value*> &Idx);
340   void init(Value *Ptr, Value *Idx0, Value *Idx1);
341   void init(Value *Ptr, Value *Idx);
342 public:
343   /// Constructors - Create a getelementptr instruction with a base pointer an
344   /// list of indices.  The first ctor can optionally insert before an existing
345   /// instruction, the second appends the new instruction to the specified
346   /// BasicBlock.
347   GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
348                     const std::string &Name = "", Instruction *InsertBefore =0);
349   GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
350                     const std::string &Name, BasicBlock *InsertAtEnd);
351
352   /// Constructors - These two constructors are convenience methods because one
353   /// and two index getelementptr instructions are so common.
354   GetElementPtrInst(Value *Ptr, Value *Idx,
355                     const std::string &Name = "", Instruction *InsertBefore =0);
356   GetElementPtrInst(Value *Ptr, Value *Idx,
357                     const std::string &Name, BasicBlock *InsertAtEnd);
358   GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
359                     const std::string &Name = "", Instruction *InsertBefore =0);
360   GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
361                     const std::string &Name, BasicBlock *InsertAtEnd);
362   ~GetElementPtrInst();
363
364   virtual GetElementPtrInst *clone() const;
365
366   // getType - Overload to return most specific pointer type...
367   inline const PointerType *getType() const {
368     return reinterpret_cast<const PointerType*>(Instruction::getType());
369   }
370
371   /// getIndexedType - Returns the type of the element that would be loaded with
372   /// a load instruction with the specified parameters.
373   ///
374   /// A null type is returned if the indices are invalid for the specified
375   /// pointer type.
376   ///
377   static const Type *getIndexedType(const Type *Ptr,
378                                     const std::vector<Value*> &Indices,
379                                     bool AllowStructLeaf = false);
380   static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
381                                     bool AllowStructLeaf = false);
382   static const Type *getIndexedType(const Type *Ptr, Value *Idx);
383
384   inline op_iterator       idx_begin()       { return op_begin()+1; }
385   inline const_op_iterator idx_begin() const { return op_begin()+1; }
386   inline op_iterator       idx_end()         { return op_end(); }
387   inline const_op_iterator idx_end()   const { return op_end(); }
388
389   Value *getPointerOperand() {
390     return getOperand(0);
391   }
392   const Value *getPointerOperand() const {
393     return getOperand(0);
394   }
395   static unsigned getPointerOperandIndex() {
396     return 0U;                      // get index for modifying correct operand
397   }
398
399   inline unsigned getNumIndices() const {  // Note: always non-negative
400     return getNumOperands() - 1;
401   }
402
403   inline bool hasIndices() const {
404     return getNumOperands() > 1;
405   }
406
407   // Methods for support type inquiry through isa, cast, and dyn_cast:
408   static inline bool classof(const GetElementPtrInst *) { return true; }
409   static inline bool classof(const Instruction *I) {
410     return (I->getOpcode() == Instruction::GetElementPtr);
411   }
412   static inline bool classof(const Value *V) {
413     return isa<Instruction>(V) && classof(cast<Instruction>(V));
414   }
415 };
416
417 //===----------------------------------------------------------------------===//
418 //                               ICmpInst Class
419 //===----------------------------------------------------------------------===//
420
421 /// This instruction compares its operands according to the predicate given
422 /// to the constructor. It only operates on integers, pointers, or packed 
423 /// vectors of integrals. The two operands must be the same type.
424 /// @brief Represent an integer comparison operator.
425 class ICmpInst: public CmpInst {
426 public:
427   /// This enumeration lists the possible predicates for the ICmpInst. The
428   /// values in the range 0-31 are reserved for FCmpInst while values in the
429   /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
430   /// predicate values are not overlapping between the classes.
431   enum Predicate {
432     ICMP_EQ  = 32,    ///< equal
433     ICMP_NE  = 33,    ///< not equal
434     ICMP_UGT = 34,    ///< unsigned greater than
435     ICMP_UGE = 35,    ///< unsigned greater or equal
436     ICMP_ULT = 36,    ///< unsigned less than
437     ICMP_ULE = 37,    ///< unsigned less or equal
438     ICMP_SGT = 38,    ///< signed greater than
439     ICMP_SGE = 39,    ///< signed greater or equal
440     ICMP_SLT = 40,    ///< signed less than
441     ICMP_SLE = 41,    ///< signed less or equal
442     FIRST_ICMP_PREDICATE = ICMP_EQ,
443     LAST_ICMP_PREDICATE = ICMP_SLE
444   };
445
446   /// @brief Constructor with insert-before-instruction semantics.
447   ICmpInst(
448     Predicate pred,  ///< The predicate to use for the comparison
449     Value *LHS,      ///< The left-hand-side of the expression
450     Value *RHS,      ///< The right-hand-side of the expression
451     const std::string &Name = "",  ///< Name of the instruction
452     Instruction *InsertBefore = 0  ///< Where to insert
453   ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
454   }
455
456   /// @brief Constructor with insert-at-block-end semantics.
457   ICmpInst(
458     Predicate pred, ///< The predicate to use for the comparison
459     Value *LHS,     ///< The left-hand-side of the expression
460     Value *RHS,     ///< The right-hand-side of the expression
461     const std::string &Name,  ///< Name of the instruction
462     BasicBlock *InsertAtEnd   ///< Block to insert into.
463   ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
464   }
465
466   /// @brief Return the predicate for this instruction.
467   Predicate getPredicate() const { return Predicate(SubclassData); }
468
469   /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
470   /// @returns the inverse predicate for the instruction's current predicate. 
471   /// @brief Return the inverse of the instruction's predicate.
472   Predicate getInversePredicate() const {
473     return getInversePredicate(getPredicate());
474   }
475
476   /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
477   /// @returns the inverse predicate for predicate provided in \p pred. 
478   /// @brief Return the inverse of a given predicate
479   static Predicate getInversePredicate(Predicate pred);
480
481   /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
482   /// @returns the predicate that would be the result of exchanging the two 
483   /// operands of the ICmpInst instruction without changing the result 
484   /// produced.  
485   /// @brief Return the predicate as if the operands were swapped
486   Predicate getSwappedPredicate() const {
487     return getSwappedPredicate(getPredicate());
488   }
489
490   /// This is a static version that you can use without an instruction 
491   /// available.
492   /// @brief Return the predicate as if the operands were swapped.
493   static Predicate getSwappedPredicate(Predicate Opcode);
494
495   /// This also tests for commutativity. If isEquality() returns true then
496   /// the predicate is also commutative. Only the equality predicates are
497   /// commutative.
498   /// @returns true if the predicate of this instruction is EQ or NE.
499   /// @brief Determine if this is an equality predicate.
500   bool isEquality() const {
501     return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
502   }
503   bool isCommutative() const { return isEquality(); }
504
505   /// @returns true if the predicate is relational (not EQ or NE). 
506   /// @brief Determine if this a relational predicate.
507   bool isRelational() const {
508     return !isEquality();
509   }
510
511   /// Exchange the two operands to this instruction in such a way that it does
512   /// not modify the semantics of the instruction. The predicate value may be
513   /// changed to retain the same result if the predicate is order dependent
514   /// (e.g. ult). 
515   /// @brief Swap operands and adjust predicate.
516   void swapOperands() {
517     SubclassData = getSwappedPredicate();
518     std::swap(Ops[0], Ops[1]);
519   }
520
521   // Methods for support type inquiry through isa, cast, and dyn_cast:
522   static inline bool classof(const ICmpInst *) { return true; }
523   static inline bool classof(const Instruction *I) {
524     return I->getOpcode() == Instruction::ICmp;
525   }
526   static inline bool classof(const Value *V) {
527     return isa<Instruction>(V) && classof(cast<Instruction>(V));
528   }
529 };
530
531 //===----------------------------------------------------------------------===//
532 //                               FCmpInst Class
533 //===----------------------------------------------------------------------===//
534
535 /// This instruction compares its operands according to the predicate given
536 /// to the constructor. It only operates on floating point values or packed     
537 /// vectors of floating point values. The operands must be identical types.
538 /// @brief Represents a floating point comparison operator.
539 class FCmpInst: public CmpInst {
540 public:
541   /// This enumeration lists the possible predicates for the FCmpInst. Values
542   /// in the range 0-31 are reserved for FCmpInst.
543   enum Predicate {
544     // Opcode        U L G E    Intuitive operation
545     FCMP_FALSE = 0, ///<  0 0 0 0    Always false (always folded)
546     FCMP_OEQ   = 1, ///<  0 0 0 1    True if ordered and equal
547     FCMP_OGT   = 2, ///<  0 0 1 0    True if ordered and greater than
548     FCMP_OGE   = 3, ///<  0 0 1 1    True if ordered and greater than or equal
549     FCMP_OLT   = 4, ///<  0 1 0 0    True if ordered and less than
550     FCMP_OLE   = 5, ///<  0 1 0 1    True if ordered and less than or equal
551     FCMP_ONE   = 6, ///<  0 1 1 0    True if ordered and operands are unequal
552     FCMP_ORD   = 7, ///<  0 1 1 1    True if ordered (no nans)
553     FCMP_UNO   = 8, ///<  1 0 0 0    True if unordered: isnan(X) | isnan(Y)
554     FCMP_UEQ   = 9, ///<  1 0 0 1    True if unordered or equal
555     FCMP_UGT   =10, ///<  1 0 1 0    True if unordered or greater than
556     FCMP_UGE   =11, ///<  1 0 1 1    True if unordered, greater than, or equal
557     FCMP_ULT   =12, ///<  1 1 0 0    True if unordered or less than
558     FCMP_ULE   =13, ///<  1 1 0 1    True if unordered, less than, or equal
559     FCMP_UNE   =14, ///<  1 1 1 0    True if unordered or not equal
560     FCMP_TRUE  =15, ///<  1 1 1 1    Always true (always folded)
561     FIRST_FCMP_PREDICATE = FCMP_FALSE,
562     LAST_FCMP_PREDICATE = FCMP_TRUE
563   };
564
565   /// @brief Constructor with insert-before-instruction semantics.
566   FCmpInst(
567     Predicate pred,  ///< The predicate to use for the comparison
568     Value *LHS,      ///< The left-hand-side of the expression
569     Value *RHS,      ///< The right-hand-side of the expression
570     const std::string &Name = "",  ///< Name of the instruction
571     Instruction *InsertBefore = 0  ///< Where to insert
572   ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
573   }
574
575   /// @brief Constructor with insert-at-block-end semantics.
576   FCmpInst(
577     Predicate pred, ///< The predicate to use for the comparison
578     Value *LHS,     ///< The left-hand-side of the expression
579     Value *RHS,     ///< The right-hand-side of the expression
580     const std::string &Name,  ///< Name of the instruction
581     BasicBlock *InsertAtEnd   ///< Block to insert into.
582   ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
583   }
584
585   /// @brief Return the predicate for this instruction.
586   Predicate getPredicate() const { return Predicate(SubclassData); }
587
588   /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
589   /// @returns the inverse predicate for the instructions current predicate. 
590   /// @brief Return the inverse of the predicate
591   Predicate getInversePredicate() const {
592     return getInversePredicate(getPredicate());
593   }
594
595   /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
596   /// @returns the inverse predicate for \p pred.
597   /// @brief Return the inverse of a given predicate
598   static Predicate getInversePredicate(Predicate pred);
599
600   /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
601   /// @returns the predicate that would be the result of exchanging the two 
602   /// operands of the ICmpInst instruction without changing the result 
603   /// produced.  
604   /// @brief Return the predicate as if the operands were swapped
605   Predicate getSwappedPredicate() const {
606     return getSwappedPredicate(getPredicate());
607   }
608
609   /// This is a static version that you can use without an instruction 
610   /// available.
611   /// @brief Return the predicate as if the operands were swapped.
612   static Predicate getSwappedPredicate(Predicate Opcode);
613
614   /// This also tests for commutativity. If isEquality() returns true then
615   /// the predicate is also commutative. Only the equality predicates are
616   /// commutative.
617   /// @returns true if the predicate of this instruction is EQ or NE.
618   /// @brief Determine if this is an equality predicate.
619   bool isEquality() const {
620     return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
621            SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
622   }
623   bool isCommutative() const { return isEquality(); }
624
625   /// @returns true if the predicate is relational (not EQ or NE). 
626   /// @brief Determine if this a relational predicate.
627   bool isRelational() const { return !isEquality(); }
628
629   /// Exchange the two operands to this instruction in such a way that it does
630   /// not modify the semantics of the instruction. The predicate value may be
631   /// changed to retain the same result if the predicate is order dependent
632   /// (e.g. ult). 
633   /// @brief Swap operands and adjust predicate.
634   void swapOperands() {
635     SubclassData = getSwappedPredicate();
636     std::swap(Ops[0], Ops[1]);
637   }
638
639   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
640   static inline bool classof(const FCmpInst *) { return true; }
641   static inline bool classof(const Instruction *I) {
642     return I->getOpcode() == Instruction::FCmp;
643   }
644   static inline bool classof(const Value *V) {
645     return isa<Instruction>(V) && classof(cast<Instruction>(V));
646   }
647 };
648
649
650 //===----------------------------------------------------------------------===//
651 //                            SetCondInst Class
652 //===----------------------------------------------------------------------===//
653
654 /// SetCondInst class - Represent a setCC operator, where CC is eq, ne, lt, gt,
655 /// le, or ge.
656 ///
657 class SetCondInst : public BinaryOperator {
658 public:
659   SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
660               const std::string &Name = "", Instruction *InsertBefore = 0);
661   SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
662               const std::string &Name, BasicBlock *InsertAtEnd);
663
664   /// getInverseCondition - Return the inverse of the current condition opcode.
665   /// For example seteq -> setne, setgt -> setle, setlt -> setge, etc...
666   ///
667   BinaryOps getInverseCondition() const {
668     return getInverseCondition(getOpcode());
669   }
670
671   /// getInverseCondition - Static version that you can use without an
672   /// instruction available.
673   ///
674   static BinaryOps getInverseCondition(BinaryOps Opcode);
675
676   /// getSwappedCondition - Return the condition opcode that would be the result
677   /// of exchanging the two operands of the setcc instruction without changing
678   /// the result produced.  Thus, seteq->seteq, setle->setge, setlt->setgt, etc.
679   ///
680   BinaryOps getSwappedCondition() const {
681     return getSwappedCondition(getOpcode());
682   }
683
684   /// getSwappedCondition - Static version that you can use without an
685   /// instruction available.
686   ///
687   static BinaryOps getSwappedCondition(BinaryOps Opcode);
688
689   /// isEquality - Return true if this comparison is an ==/!= comparison.
690   ///
691   bool isEquality() const {
692     return getOpcode() == SetEQ || getOpcode() == SetNE;
693   }
694
695   /// isRelational - Return true if this comparison is a </>/<=/>= comparison.
696   ///
697   bool isRelational() const {
698     return !isEquality();
699   }
700
701   // Methods for support type inquiry through isa, cast, and dyn_cast:
702   static inline bool classof(const SetCondInst *) { return true; }
703   static inline bool classof(const Instruction *I) {
704     return I->getOpcode() == SetEQ || I->getOpcode() == SetNE ||
705            I->getOpcode() == SetLE || I->getOpcode() == SetGE ||
706            I->getOpcode() == SetLT || I->getOpcode() == SetGT;
707   }
708   static inline bool classof(const Value *V) {
709     return isa<Instruction>(V) && classof(cast<Instruction>(V));
710   }
711 };
712
713
714 //===----------------------------------------------------------------------===//
715 //                                 CallInst Class
716 //===----------------------------------------------------------------------===//
717
718 /// CallInst - This class represents a function call, abstracting a target
719 /// machine's calling convention.  This class uses low bit of the SubClassData
720 /// field to indicate whether or not this is a tail call.  The rest of the bits
721 /// hold the calling convention of the call.
722 ///
723 class CallInst : public Instruction {
724   CallInst(const CallInst &CI);
725   void init(Value *Func, const std::vector<Value*> &Params);
726   void init(Value *Func, Value *Actual1, Value *Actual2);
727   void init(Value *Func, Value *Actual);
728   void init(Value *Func);
729
730 public:
731   CallInst(Value *F, const std::vector<Value*> &Par,
732            const std::string &Name = "", Instruction *InsertBefore = 0);
733   CallInst(Value *F, const std::vector<Value*> &Par,
734            const std::string &Name, BasicBlock *InsertAtEnd);
735
736   // Alternate CallInst ctors w/ two actuals, w/ one actual and no
737   // actuals, respectively.
738   CallInst(Value *F, Value *Actual1, Value *Actual2,
739            const std::string& Name = "", Instruction *InsertBefore = 0);
740   CallInst(Value *F, Value *Actual1, Value *Actual2,
741            const std::string& Name, BasicBlock *InsertAtEnd);
742   CallInst(Value *F, Value *Actual, const std::string& Name = "",
743            Instruction *InsertBefore = 0);
744   CallInst(Value *F, Value *Actual, const std::string& Name,
745            BasicBlock *InsertAtEnd);
746   explicit CallInst(Value *F, const std::string &Name = "",
747                     Instruction *InsertBefore = 0);
748   CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
749   ~CallInst();
750
751   virtual CallInst *clone() const;
752   bool mayWriteToMemory() const { return true; }
753
754   bool isTailCall() const           { return SubclassData & 1; }
755   void setTailCall(bool isTailCall = true) {
756     SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
757   }
758
759   /// getCallingConv/setCallingConv - Get or set the calling convention of this
760   /// function call.
761   unsigned getCallingConv() const { return SubclassData >> 1; }
762   void setCallingConv(unsigned CC) {
763     SubclassData = (SubclassData & 1) | (CC << 1);
764   }
765
766   /// getCalledFunction - Return the function being called by this instruction
767   /// if it is a direct call.  If it is a call through a function pointer,
768   /// return null.
769   Function *getCalledFunction() const {
770     return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
771   }
772
773   // getCalledValue - Get a pointer to a method that is invoked by this inst.
774   inline const Value *getCalledValue() const { return getOperand(0); }
775   inline       Value *getCalledValue()       { return getOperand(0); }
776
777   // Methods for support type inquiry through isa, cast, and dyn_cast:
778   static inline bool classof(const CallInst *) { return true; }
779   static inline bool classof(const Instruction *I) {
780     return I->getOpcode() == Instruction::Call;
781   }
782   static inline bool classof(const Value *V) {
783     return isa<Instruction>(V) && classof(cast<Instruction>(V));
784   }
785 };
786
787
788 //===----------------------------------------------------------------------===//
789 //                                 ShiftInst Class
790 //===----------------------------------------------------------------------===//
791
792 /// ShiftInst - This class represents left and right shift instructions.
793 ///
794 class ShiftInst : public Instruction {
795   Use Ops[2];
796   ShiftInst(const ShiftInst &SI)
797     : Instruction(SI.getType(), SI.getOpcode(), Ops, 2) {
798     Ops[0].init(SI.Ops[0], this);
799     Ops[1].init(SI.Ops[1], this);
800   }
801   void init(OtherOps Opcode, Value *S, Value *SA) {
802     assert((Opcode == Shl || Opcode == LShr || Opcode == AShr) && 
803       "ShiftInst Opcode invalid!");
804     Ops[0].init(S, this);
805     Ops[1].init(SA, this);
806   }
807
808 public:
809   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
810             Instruction *InsertBefore = 0)
811     : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertBefore) {
812     init(Opcode, S, SA);
813   }
814   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
815             BasicBlock *InsertAtEnd)
816     : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertAtEnd) {
817     init(Opcode, S, SA);
818   }
819
820   OtherOps getOpcode() const {
821     return static_cast<OtherOps>(Instruction::getOpcode());
822   }
823
824   /// Transparently provide more efficient getOperand methods.
825   Value *getOperand(unsigned i) const {
826     assert(i < 2 && "getOperand() out of range!");
827     return Ops[i];
828   }
829   void setOperand(unsigned i, Value *Val) {
830     assert(i < 2 && "setOperand() out of range!");
831     Ops[i] = Val;
832   }
833   unsigned getNumOperands() const { return 2; }
834
835   /// isLogicalShift - Return true if this is a logical shift left or a logical
836   /// shift right.
837   bool isLogicalShift() const {
838     unsigned opcode = getOpcode();
839     return opcode == Instruction::Shl || opcode == Instruction::LShr;
840   }
841
842
843   /// isArithmeticShift - Return true if this is a sign-extending shift right
844   /// operation.
845   bool isArithmeticShift() const {
846     return !isLogicalShift();
847   }
848
849
850   virtual ShiftInst *clone() const;
851
852   // Methods for support type inquiry through isa, cast, and dyn_cast:
853   static inline bool classof(const ShiftInst *) { return true; }
854   static inline bool classof(const Instruction *I) {
855     return (I->getOpcode() == Instruction::LShr) |
856            (I->getOpcode() == Instruction::AShr) |
857            (I->getOpcode() == Instruction::Shl);
858   }
859   static inline bool classof(const Value *V) {
860     return isa<Instruction>(V) && classof(cast<Instruction>(V));
861   }
862 };
863
864 //===----------------------------------------------------------------------===//
865 //                               SelectInst Class
866 //===----------------------------------------------------------------------===//
867
868 /// SelectInst - This class represents the LLVM 'select' instruction.
869 ///
870 class SelectInst : public Instruction {
871   Use Ops[3];
872
873   void init(Value *C, Value *S1, Value *S2) {
874     Ops[0].init(C, this);
875     Ops[1].init(S1, this);
876     Ops[2].init(S2, this);
877   }
878
879   SelectInst(const SelectInst &SI)
880     : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
881     init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
882   }
883 public:
884   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
885              Instruction *InsertBefore = 0)
886     : Instruction(S1->getType(), Instruction::Select, Ops, 3,
887                   Name, InsertBefore) {
888     init(C, S1, S2);
889   }
890   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
891              BasicBlock *InsertAtEnd)
892     : Instruction(S1->getType(), Instruction::Select, Ops, 3,
893                   Name, InsertAtEnd) {
894     init(C, S1, S2);
895   }
896
897   Value *getCondition() const { return Ops[0]; }
898   Value *getTrueValue() const { return Ops[1]; }
899   Value *getFalseValue() const { return Ops[2]; }
900
901   /// Transparently provide more efficient getOperand methods.
902   Value *getOperand(unsigned i) const {
903     assert(i < 3 && "getOperand() out of range!");
904     return Ops[i];
905   }
906   void setOperand(unsigned i, Value *Val) {
907     assert(i < 3 && "setOperand() out of range!");
908     Ops[i] = Val;
909   }
910   unsigned getNumOperands() const { return 3; }
911
912   OtherOps getOpcode() const {
913     return static_cast<OtherOps>(Instruction::getOpcode());
914   }
915
916   virtual SelectInst *clone() const;
917
918   // Methods for support type inquiry through isa, cast, and dyn_cast:
919   static inline bool classof(const SelectInst *) { return true; }
920   static inline bool classof(const Instruction *I) {
921     return I->getOpcode() == Instruction::Select;
922   }
923   static inline bool classof(const Value *V) {
924     return isa<Instruction>(V) && classof(cast<Instruction>(V));
925   }
926 };
927
928 //===----------------------------------------------------------------------===//
929 //                                VAArgInst Class
930 //===----------------------------------------------------------------------===//
931
932 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
933 /// an argument of the specified type given a va_list and increments that list
934 ///
935 class VAArgInst : public UnaryInstruction {
936   VAArgInst(const VAArgInst &VAA)
937     : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
938 public:
939   VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
940              Instruction *InsertBefore = 0)
941     : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
942   }
943   VAArgInst(Value *List, const Type *Ty, const std::string &Name,
944             BasicBlock *InsertAtEnd)
945     : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
946   }
947
948   virtual VAArgInst *clone() const;
949   bool mayWriteToMemory() const { return true; }
950
951   // Methods for support type inquiry through isa, cast, and dyn_cast:
952   static inline bool classof(const VAArgInst *) { return true; }
953   static inline bool classof(const Instruction *I) {
954     return I->getOpcode() == VAArg;
955   }
956   static inline bool classof(const Value *V) {
957     return isa<Instruction>(V) && classof(cast<Instruction>(V));
958   }
959 };
960
961 //===----------------------------------------------------------------------===//
962 //                                ExtractElementInst Class
963 //===----------------------------------------------------------------------===//
964
965 /// ExtractElementInst - This instruction extracts a single (scalar)
966 /// element from a PackedType value
967 ///
968 class ExtractElementInst : public Instruction {
969   Use Ops[2];
970   ExtractElementInst(const ExtractElementInst &EE) :
971     Instruction(EE.getType(), ExtractElement, Ops, 2) {
972     Ops[0].init(EE.Ops[0], this);
973     Ops[1].init(EE.Ops[1], this);
974   }
975
976 public:
977   ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
978                      Instruction *InsertBefore = 0);
979   ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
980                      Instruction *InsertBefore = 0);
981   ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
982                      BasicBlock *InsertAtEnd);
983   ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
984                      BasicBlock *InsertAtEnd);
985
986   /// isValidOperands - Return true if an extractelement instruction can be
987   /// formed with the specified operands.
988   static bool isValidOperands(const Value *Vec, const Value *Idx);
989
990   virtual ExtractElementInst *clone() const;
991
992   virtual bool mayWriteToMemory() const { return false; }
993
994   /// Transparently provide more efficient getOperand methods.
995   Value *getOperand(unsigned i) const {
996     assert(i < 2 && "getOperand() out of range!");
997     return Ops[i];
998   }
999   void setOperand(unsigned i, Value *Val) {
1000     assert(i < 2 && "setOperand() out of range!");
1001     Ops[i] = Val;
1002   }
1003   unsigned getNumOperands() const { return 2; }
1004
1005   // Methods for support type inquiry through isa, cast, and dyn_cast:
1006   static inline bool classof(const ExtractElementInst *) { return true; }
1007   static inline bool classof(const Instruction *I) {
1008     return I->getOpcode() == Instruction::ExtractElement;
1009   }
1010   static inline bool classof(const Value *V) {
1011     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1012   }
1013 };
1014
1015 //===----------------------------------------------------------------------===//
1016 //                                InsertElementInst Class
1017 //===----------------------------------------------------------------------===//
1018
1019 /// InsertElementInst - This instruction inserts a single (scalar)
1020 /// element into a PackedType value
1021 ///
1022 class InsertElementInst : public Instruction {
1023   Use Ops[3];
1024   InsertElementInst(const InsertElementInst &IE);
1025 public:
1026   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1027                     const std::string &Name = "",Instruction *InsertBefore = 0);
1028   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1029                     const std::string &Name = "",Instruction *InsertBefore = 0);
1030   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1031                     const std::string &Name, BasicBlock *InsertAtEnd);
1032   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1033                     const std::string &Name, BasicBlock *InsertAtEnd);
1034
1035   /// isValidOperands - Return true if an insertelement instruction can be
1036   /// formed with the specified operands.
1037   static bool isValidOperands(const Value *Vec, const Value *NewElt,
1038                               const Value *Idx);
1039
1040   virtual InsertElementInst *clone() const;
1041
1042   virtual bool mayWriteToMemory() const { return false; }
1043
1044   /// getType - Overload to return most specific packed type.
1045   ///
1046   inline const PackedType *getType() const {
1047     return reinterpret_cast<const PackedType*>(Instruction::getType());
1048   }
1049
1050   /// Transparently provide more efficient getOperand methods.
1051   Value *getOperand(unsigned i) const {
1052     assert(i < 3 && "getOperand() out of range!");
1053     return Ops[i];
1054   }
1055   void setOperand(unsigned i, Value *Val) {
1056     assert(i < 3 && "setOperand() out of range!");
1057     Ops[i] = Val;
1058   }
1059   unsigned getNumOperands() const { return 3; }
1060
1061   // Methods for support type inquiry through isa, cast, and dyn_cast:
1062   static inline bool classof(const InsertElementInst *) { return true; }
1063   static inline bool classof(const Instruction *I) {
1064     return I->getOpcode() == Instruction::InsertElement;
1065   }
1066   static inline bool classof(const Value *V) {
1067     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1068   }
1069 };
1070
1071 //===----------------------------------------------------------------------===//
1072 //                           ShuffleVectorInst Class
1073 //===----------------------------------------------------------------------===//
1074
1075 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1076 /// input vectors.
1077 ///
1078 class ShuffleVectorInst : public Instruction {
1079   Use Ops[3];
1080   ShuffleVectorInst(const ShuffleVectorInst &IE);
1081 public:
1082   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1083                     const std::string &Name = "", Instruction *InsertBefor = 0);
1084   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1085                     const std::string &Name, BasicBlock *InsertAtEnd);
1086
1087   /// isValidOperands - Return true if a shufflevector instruction can be
1088   /// formed with the specified operands.
1089   static bool isValidOperands(const Value *V1, const Value *V2,
1090                               const Value *Mask);
1091
1092   virtual ShuffleVectorInst *clone() const;
1093
1094   virtual bool mayWriteToMemory() const { return false; }
1095
1096   /// getType - Overload to return most specific packed type.
1097   ///
1098   inline const PackedType *getType() const {
1099     return reinterpret_cast<const PackedType*>(Instruction::getType());
1100   }
1101
1102   /// Transparently provide more efficient getOperand methods.
1103   Value *getOperand(unsigned i) const {
1104     assert(i < 3 && "getOperand() out of range!");
1105     return Ops[i];
1106   }
1107   void setOperand(unsigned i, Value *Val) {
1108     assert(i < 3 && "setOperand() out of range!");
1109     Ops[i] = Val;
1110   }
1111   unsigned getNumOperands() const { return 3; }
1112
1113   // Methods for support type inquiry through isa, cast, and dyn_cast:
1114   static inline bool classof(const ShuffleVectorInst *) { return true; }
1115   static inline bool classof(const Instruction *I) {
1116     return I->getOpcode() == Instruction::ShuffleVector;
1117   }
1118   static inline bool classof(const Value *V) {
1119     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1120   }
1121 };
1122
1123
1124 //===----------------------------------------------------------------------===//
1125 //                               PHINode Class
1126 //===----------------------------------------------------------------------===//
1127
1128 // PHINode - The PHINode class is used to represent the magical mystical PHI
1129 // node, that can not exist in nature, but can be synthesized in a computer
1130 // scientist's overactive imagination.
1131 //
1132 class PHINode : public Instruction {
1133   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
1134   /// the number actually in use.
1135   unsigned ReservedSpace;
1136   PHINode(const PHINode &PN);
1137 public:
1138   explicit PHINode(const Type *Ty, const std::string &Name = "",
1139                    Instruction *InsertBefore = 0)
1140     : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
1141       ReservedSpace(0) {
1142   }
1143
1144   PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
1145     : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
1146       ReservedSpace(0) {
1147   }
1148
1149   ~PHINode();
1150
1151   /// reserveOperandSpace - This method can be used to avoid repeated
1152   /// reallocation of PHI operand lists by reserving space for the correct
1153   /// number of operands before adding them.  Unlike normal vector reserves,
1154   /// this method can also be used to trim the operand space.
1155   void reserveOperandSpace(unsigned NumValues) {
1156     resizeOperands(NumValues*2);
1157   }
1158
1159   virtual PHINode *clone() const;
1160
1161   /// getNumIncomingValues - Return the number of incoming edges
1162   ///
1163   unsigned getNumIncomingValues() const { return getNumOperands()/2; }
1164
1165   /// getIncomingValue - Return incoming value number x
1166   ///
1167   Value *getIncomingValue(unsigned i) const {
1168     assert(i*2 < getNumOperands() && "Invalid value number!");
1169     return getOperand(i*2);
1170   }
1171   void setIncomingValue(unsigned i, Value *V) {
1172     assert(i*2 < getNumOperands() && "Invalid value number!");
1173     setOperand(i*2, V);
1174   }
1175   unsigned getOperandNumForIncomingValue(unsigned i) {
1176     return i*2;
1177   }
1178
1179   /// getIncomingBlock - Return incoming basic block number x
1180   ///
1181   BasicBlock *getIncomingBlock(unsigned i) const {
1182     return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
1183   }
1184   void setIncomingBlock(unsigned i, BasicBlock *BB) {
1185     setOperand(i*2+1, reinterpret_cast<Value*>(BB));
1186   }
1187   unsigned getOperandNumForIncomingBlock(unsigned i) {
1188     return i*2+1;
1189   }
1190
1191   /// addIncoming - Add an incoming value to the end of the PHI list
1192   ///
1193   void addIncoming(Value *V, BasicBlock *BB) {
1194     assert(getType() == V->getType() &&
1195            "All operands to PHI node must be the same type as the PHI node!");
1196     unsigned OpNo = NumOperands;
1197     if (OpNo+2 > ReservedSpace)
1198       resizeOperands(0);  // Get more space!
1199     // Initialize some new operands.
1200     NumOperands = OpNo+2;
1201     OperandList[OpNo].init(V, this);
1202     OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
1203   }
1204
1205   /// removeIncomingValue - Remove an incoming value.  This is useful if a
1206   /// predecessor basic block is deleted.  The value removed is returned.
1207   ///
1208   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1209   /// is true), the PHI node is destroyed and any uses of it are replaced with
1210   /// dummy values.  The only time there should be zero incoming values to a PHI
1211   /// node is when the block is dead, so this strategy is sound.
1212   ///
1213   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1214
1215   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1216     int Idx = getBasicBlockIndex(BB);
1217     assert(Idx >= 0 && "Invalid basic block argument to remove!");
1218     return removeIncomingValue(Idx, DeletePHIIfEmpty);
1219   }
1220
1221   /// getBasicBlockIndex - Return the first index of the specified basic
1222   /// block in the value list for this PHI.  Returns -1 if no instance.
1223   ///
1224   int getBasicBlockIndex(const BasicBlock *BB) const {
1225     Use *OL = OperandList;
1226     for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
1227       if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
1228     return -1;
1229   }
1230
1231   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1232     return getIncomingValue(getBasicBlockIndex(BB));
1233   }
1234
1235   /// hasConstantValue - If the specified PHI node always merges together the
1236   /// same value, return the value, otherwise return null.
1237   ///
1238   Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
1239
1240   /// Methods for support type inquiry through isa, cast, and dyn_cast:
1241   static inline bool classof(const PHINode *) { return true; }
1242   static inline bool classof(const Instruction *I) {
1243     return I->getOpcode() == Instruction::PHI;
1244   }
1245   static inline bool classof(const Value *V) {
1246     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1247   }
1248  private:
1249   void resizeOperands(unsigned NumOperands);
1250 };
1251
1252 //===----------------------------------------------------------------------===//
1253 //                               ReturnInst Class
1254 //===----------------------------------------------------------------------===//
1255
1256 //===---------------------------------------------------------------------------
1257 /// ReturnInst - Return a value (possibly void), from a function.  Execution
1258 /// does not continue in this function any longer.
1259 ///
1260 class ReturnInst : public TerminatorInst {
1261   Use RetVal;  // Possibly null retval.
1262   ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
1263                                                     RI.getNumOperands()) {
1264     if (RI.getNumOperands())
1265       RetVal.init(RI.RetVal, this);
1266   }
1267
1268   void init(Value *RetVal);
1269
1270 public:
1271   // ReturnInst constructors:
1272   // ReturnInst()                  - 'ret void' instruction
1273   // ReturnInst(    null)          - 'ret void' instruction
1274   // ReturnInst(Value* X)          - 'ret X'    instruction
1275   // ReturnInst(    null, Inst *)  - 'ret void' instruction, insert before I
1276   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
1277   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of BB
1278   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of BB
1279   //
1280   // NOTE: If the Value* passed is of type void then the constructor behaves as
1281   // if it was passed NULL.
1282   explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
1283     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
1284     init(retVal);
1285   }
1286   ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
1287     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1288     init(retVal);
1289   }
1290   explicit ReturnInst(BasicBlock *InsertAtEnd)
1291     : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1292   }
1293
1294   virtual ReturnInst *clone() const;
1295
1296   // Transparently provide more efficient getOperand methods.
1297   Value *getOperand(unsigned i) const {
1298     assert(i < getNumOperands() && "getOperand() out of range!");
1299     return RetVal;
1300   }
1301   void setOperand(unsigned i, Value *Val) {
1302     assert(i < getNumOperands() && "setOperand() out of range!");
1303     RetVal = Val;
1304   }
1305
1306   Value *getReturnValue() const { return RetVal; }
1307
1308   unsigned getNumSuccessors() const { return 0; }
1309
1310   // Methods for support type inquiry through isa, cast, and dyn_cast:
1311   static inline bool classof(const ReturnInst *) { return true; }
1312   static inline bool classof(const Instruction *I) {
1313     return (I->getOpcode() == Instruction::Ret);
1314   }
1315   static inline bool classof(const Value *V) {
1316     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1317   }
1318  private:
1319   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1320   virtual unsigned getNumSuccessorsV() const;
1321   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1322 };
1323
1324 //===----------------------------------------------------------------------===//
1325 //                               BranchInst Class
1326 //===----------------------------------------------------------------------===//
1327
1328 //===---------------------------------------------------------------------------
1329 /// BranchInst - Conditional or Unconditional Branch instruction.
1330 ///
1331 class BranchInst : public TerminatorInst {
1332   /// Ops list - Branches are strange.  The operands are ordered:
1333   ///  TrueDest, FalseDest, Cond.  This makes some accessors faster because
1334   /// they don't have to check for cond/uncond branchness.
1335   Use Ops[3];
1336   BranchInst(const BranchInst &BI);
1337   void AssertOK();
1338 public:
1339   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1340   // BranchInst(BB *B)                           - 'br B'
1341   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
1342   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
1343   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1344   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
1345   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
1346   explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
1347     : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
1348     assert(IfTrue != 0 && "Branch destination may not be null!");
1349     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1350   }
1351   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1352              Instruction *InsertBefore = 0)
1353     : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
1354     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1355     Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1356     Ops[2].init(Cond, this);
1357 #ifndef NDEBUG
1358     AssertOK();
1359 #endif
1360   }
1361
1362   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1363     : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
1364     assert(IfTrue != 0 && "Branch destination may not be null!");
1365     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1366   }
1367
1368   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1369              BasicBlock *InsertAtEnd)
1370     : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
1371     Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1372     Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1373     Ops[2].init(Cond, this);
1374 #ifndef NDEBUG
1375     AssertOK();
1376 #endif
1377   }
1378
1379
1380   /// Transparently provide more efficient getOperand methods.
1381   Value *getOperand(unsigned i) const {
1382     assert(i < getNumOperands() && "getOperand() out of range!");
1383     return Ops[i];
1384   }
1385   void setOperand(unsigned i, Value *Val) {
1386     assert(i < getNumOperands() && "setOperand() out of range!");
1387     Ops[i] = Val;
1388   }
1389
1390   virtual BranchInst *clone() const;
1391
1392   inline bool isUnconditional() const { return getNumOperands() == 1; }
1393   inline bool isConditional()   const { return getNumOperands() == 3; }
1394
1395   inline Value *getCondition() const {
1396     assert(isConditional() && "Cannot get condition of an uncond branch!");
1397     return getOperand(2);
1398   }
1399
1400   void setCondition(Value *V) {
1401     assert(isConditional() && "Cannot set condition of unconditional branch!");
1402     setOperand(2, V);
1403   }
1404
1405   // setUnconditionalDest - Change the current branch to an unconditional branch
1406   // targeting the specified block.
1407   // FIXME: Eliminate this ugly method.
1408   void setUnconditionalDest(BasicBlock *Dest) {
1409     if (isConditional()) {  // Convert this to an uncond branch.
1410       NumOperands = 1;
1411       Ops[1].set(0);
1412       Ops[2].set(0);
1413     }
1414     setOperand(0, reinterpret_cast<Value*>(Dest));
1415   }
1416
1417   unsigned getNumSuccessors() const { return 1+isConditional(); }
1418
1419   BasicBlock *getSuccessor(unsigned i) const {
1420     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1421     return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1422                       cast<BasicBlock>(getOperand(1));
1423   }
1424
1425   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1426     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1427     setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1428   }
1429
1430   // Methods for support type inquiry through isa, cast, and dyn_cast:
1431   static inline bool classof(const BranchInst *) { return true; }
1432   static inline bool classof(const Instruction *I) {
1433     return (I->getOpcode() == Instruction::Br);
1434   }
1435   static inline bool classof(const Value *V) {
1436     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1437   }
1438 private:
1439   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1440   virtual unsigned getNumSuccessorsV() const;
1441   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1442 };
1443
1444 //===----------------------------------------------------------------------===//
1445 //                               SwitchInst Class
1446 //===----------------------------------------------------------------------===//
1447
1448 //===---------------------------------------------------------------------------
1449 /// SwitchInst - Multiway switch
1450 ///
1451 class SwitchInst : public TerminatorInst {
1452   unsigned ReservedSpace;
1453   // Operand[0]    = Value to switch on
1454   // Operand[1]    = Default basic block destination
1455   // Operand[2n  ] = Value to match
1456   // Operand[2n+1] = BasicBlock to go to on match
1457   SwitchInst(const SwitchInst &RI);
1458   void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1459   void resizeOperands(unsigned No);
1460 public:
1461   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1462   /// switch on and a default destination.  The number of additional cases can
1463   /// be specified here to make memory allocation more efficient.  This
1464   /// constructor can also autoinsert before another instruction.
1465   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1466              Instruction *InsertBefore = 0)
1467     : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1468     init(Value, Default, NumCases);
1469   }
1470
1471   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1472   /// switch on and a default destination.  The number of additional cases can
1473   /// be specified here to make memory allocation more efficient.  This
1474   /// constructor also autoinserts at the end of the specified BasicBlock.
1475   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1476              BasicBlock *InsertAtEnd)
1477     : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1478     init(Value, Default, NumCases);
1479   }
1480   ~SwitchInst();
1481
1482
1483   // Accessor Methods for Switch stmt
1484   inline Value *getCondition() const { return getOperand(0); }
1485   void setCondition(Value *V) { setOperand(0, V); }
1486
1487   inline BasicBlock *getDefaultDest() const {
1488     return cast<BasicBlock>(getOperand(1));
1489   }
1490
1491   /// getNumCases - return the number of 'cases' in this switch instruction.
1492   /// Note that case #0 is always the default case.
1493   unsigned getNumCases() const {
1494     return getNumOperands()/2;
1495   }
1496
1497   /// getCaseValue - Return the specified case value.  Note that case #0, the
1498   /// default destination, does not have a case value.
1499   ConstantInt *getCaseValue(unsigned i) {
1500     assert(i && i < getNumCases() && "Illegal case value to get!");
1501     return getSuccessorValue(i);
1502   }
1503
1504   /// getCaseValue - Return the specified case value.  Note that case #0, the
1505   /// default destination, does not have a case value.
1506   const ConstantInt *getCaseValue(unsigned i) const {
1507     assert(i && i < getNumCases() && "Illegal case value to get!");
1508     return getSuccessorValue(i);
1509   }
1510
1511   /// findCaseValue - Search all of the case values for the specified constant.
1512   /// If it is explicitly handled, return the case number of it, otherwise
1513   /// return 0 to indicate that it is handled by the default handler.
1514   unsigned findCaseValue(const ConstantInt *C) const {
1515     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1516       if (getCaseValue(i) == C)
1517         return i;
1518     return 0;
1519   }
1520
1521   /// findCaseDest - Finds the unique case value for a given successor. Returns
1522   /// null if the successor is not found, not unique, or is the default case.
1523   ConstantInt *findCaseDest(BasicBlock *BB) {
1524     if (BB == getDefaultDest()) return NULL;
1525
1526     ConstantInt *CI = NULL;
1527     for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1528       if (getSuccessor(i) == BB) {
1529         if (CI) return NULL;   // Multiple cases lead to BB.
1530         else CI = getCaseValue(i);
1531       }
1532     }
1533     return CI;
1534   }
1535
1536   /// addCase - Add an entry to the switch instruction...
1537   ///
1538   void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1539
1540   /// removeCase - This method removes the specified successor from the switch
1541   /// instruction.  Note that this cannot be used to remove the default
1542   /// destination (successor #0).
1543   ///
1544   void removeCase(unsigned idx);
1545
1546   virtual SwitchInst *clone() const;
1547
1548   unsigned getNumSuccessors() const { return getNumOperands()/2; }
1549   BasicBlock *getSuccessor(unsigned idx) const {
1550     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1551     return cast<BasicBlock>(getOperand(idx*2+1));
1552   }
1553   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1554     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1555     setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1556   }
1557
1558   // getSuccessorValue - Return the value associated with the specified
1559   // successor.
1560   inline ConstantInt *getSuccessorValue(unsigned idx) const {
1561     assert(idx < getNumSuccessors() && "Successor # out of range!");
1562     return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1563   }
1564
1565   // Methods for support type inquiry through isa, cast, and dyn_cast:
1566   static inline bool classof(const SwitchInst *) { return true; }
1567   static inline bool classof(const Instruction *I) {
1568     return I->getOpcode() == Instruction::Switch;
1569   }
1570   static inline bool classof(const Value *V) {
1571     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1572   }
1573 private:
1574   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1575   virtual unsigned getNumSuccessorsV() const;
1576   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1577 };
1578
1579 //===----------------------------------------------------------------------===//
1580 //                               InvokeInst Class
1581 //===----------------------------------------------------------------------===//
1582
1583 //===---------------------------------------------------------------------------
1584
1585 /// InvokeInst - Invoke instruction.  The SubclassData field is used to hold the
1586 /// calling convention of the call.
1587 ///
1588 class InvokeInst : public TerminatorInst {
1589   InvokeInst(const InvokeInst &BI);
1590   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1591             const std::vector<Value*> &Params);
1592 public:
1593   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1594              const std::vector<Value*> &Params, const std::string &Name = "",
1595              Instruction *InsertBefore = 0);
1596   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1597              const std::vector<Value*> &Params, const std::string &Name,
1598              BasicBlock *InsertAtEnd);
1599   ~InvokeInst();
1600
1601   virtual InvokeInst *clone() const;
1602
1603   bool mayWriteToMemory() const { return true; }
1604
1605   /// getCallingConv/setCallingConv - Get or set the calling convention of this
1606   /// function call.
1607   unsigned getCallingConv() const { return SubclassData; }
1608   void setCallingConv(unsigned CC) {
1609     SubclassData = CC;
1610   }
1611
1612   /// getCalledFunction - Return the function called, or null if this is an
1613   /// indirect function invocation.
1614   ///
1615   Function *getCalledFunction() const {
1616     return dyn_cast<Function>(getOperand(0));
1617   }
1618
1619   // getCalledValue - Get a pointer to a function that is invoked by this inst.
1620   inline Value *getCalledValue() const { return getOperand(0); }
1621
1622   // get*Dest - Return the destination basic blocks...
1623   BasicBlock *getNormalDest() const {
1624     return cast<BasicBlock>(getOperand(1));
1625   }
1626   BasicBlock *getUnwindDest() const {
1627     return cast<BasicBlock>(getOperand(2));
1628   }
1629   void setNormalDest(BasicBlock *B) {
1630     setOperand(1, reinterpret_cast<Value*>(B));
1631   }
1632
1633   void setUnwindDest(BasicBlock *B) {
1634     setOperand(2, reinterpret_cast<Value*>(B));
1635   }
1636
1637   inline BasicBlock *getSuccessor(unsigned i) const {
1638     assert(i < 2 && "Successor # out of range for invoke!");
1639     return i == 0 ? getNormalDest() : getUnwindDest();
1640   }
1641
1642   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1643     assert(idx < 2 && "Successor # out of range for invoke!");
1644     setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1645   }
1646
1647   unsigned getNumSuccessors() const { return 2; }
1648
1649   // Methods for support type inquiry through isa, cast, and dyn_cast:
1650   static inline bool classof(const InvokeInst *) { return true; }
1651   static inline bool classof(const Instruction *I) {
1652     return (I->getOpcode() == Instruction::Invoke);
1653   }
1654   static inline bool classof(const Value *V) {
1655     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1656   }
1657 private:
1658   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1659   virtual unsigned getNumSuccessorsV() const;
1660   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1661 };
1662
1663
1664 //===----------------------------------------------------------------------===//
1665 //                              UnwindInst Class
1666 //===----------------------------------------------------------------------===//
1667
1668 //===---------------------------------------------------------------------------
1669 /// UnwindInst - Immediately exit the current function, unwinding the stack
1670 /// until an invoke instruction is found.
1671 ///
1672 class UnwindInst : public TerminatorInst {
1673 public:
1674   explicit UnwindInst(Instruction *InsertBefore = 0)
1675     : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1676   }
1677   explicit UnwindInst(BasicBlock *InsertAtEnd)
1678     : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1679   }
1680
1681   virtual UnwindInst *clone() const;
1682
1683   unsigned getNumSuccessors() const { return 0; }
1684
1685   // Methods for support type inquiry through isa, cast, and dyn_cast:
1686   static inline bool classof(const UnwindInst *) { return true; }
1687   static inline bool classof(const Instruction *I) {
1688     return I->getOpcode() == Instruction::Unwind;
1689   }
1690   static inline bool classof(const Value *V) {
1691     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1692   }
1693 private:
1694   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1695   virtual unsigned getNumSuccessorsV() const;
1696   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1697 };
1698
1699 //===----------------------------------------------------------------------===//
1700 //                           UnreachableInst Class
1701 //===----------------------------------------------------------------------===//
1702
1703 //===---------------------------------------------------------------------------
1704 /// UnreachableInst - This function has undefined behavior.  In particular, the
1705 /// presence of this instruction indicates some higher level knowledge that the
1706 /// end of the block cannot be reached.
1707 ///
1708 class UnreachableInst : public TerminatorInst {
1709 public:
1710   explicit UnreachableInst(Instruction *InsertBefore = 0)
1711     : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1712   }
1713   explicit UnreachableInst(BasicBlock *InsertAtEnd)
1714     : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1715   }
1716
1717   virtual UnreachableInst *clone() const;
1718
1719   unsigned getNumSuccessors() const { return 0; }
1720
1721   // Methods for support type inquiry through isa, cast, and dyn_cast:
1722   static inline bool classof(const UnreachableInst *) { return true; }
1723   static inline bool classof(const Instruction *I) {
1724     return I->getOpcode() == Instruction::Unreachable;
1725   }
1726   static inline bool classof(const Value *V) {
1727     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1728   }
1729 private:
1730   virtual BasicBlock *getSuccessorV(unsigned idx) const;
1731   virtual unsigned getNumSuccessorsV() const;
1732   virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1733 };
1734
1735 //===----------------------------------------------------------------------===//
1736 //                                 TruncInst Class
1737 //===----------------------------------------------------------------------===//
1738
1739 /// @brief This class represents a truncation of integer types.
1740 class TruncInst : public CastInst {
1741   /// Private copy constructor
1742   TruncInst(const TruncInst &CI)
1743     : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1744   }
1745 public:
1746   /// @brief Constructor with insert-before-instruction semantics
1747   TruncInst(
1748     Value *S,                     ///< The value to be truncated
1749     const Type *Ty,               ///< The (smaller) type to truncate to
1750     const std::string &Name = "", ///< A name for the new instruction
1751     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1752   );
1753
1754   /// @brief Constructor with insert-at-end-of-block semantics
1755   TruncInst(
1756     Value *S,                     ///< The value to be truncated
1757     const Type *Ty,               ///< The (smaller) type to truncate to
1758     const std::string &Name,      ///< A name for the new instruction
1759     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1760   );
1761
1762   /// @brief Clone an identical TruncInst
1763   virtual CastInst *clone() const;
1764
1765   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1766   static inline bool classof(const TruncInst *) { return true; }
1767   static inline bool classof(const Instruction *I) {
1768     return I->getOpcode() == Trunc;
1769   }
1770   static inline bool classof(const Value *V) {
1771     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1772   }
1773 };
1774
1775 //===----------------------------------------------------------------------===//
1776 //                                 ZExtInst Class
1777 //===----------------------------------------------------------------------===//
1778
1779 /// @brief This class represents zero extension of integer types.
1780 class ZExtInst : public CastInst {
1781   /// @brief Private copy constructor
1782   ZExtInst(const ZExtInst &CI)
1783     : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1784   }
1785 public:
1786   /// @brief Constructor with insert-before-instruction semantics
1787   ZExtInst(
1788     Value *S,                     ///< The value to be zero extended
1789     const Type *Ty,               ///< The type to zero extend to
1790     const std::string &Name = "", ///< A name for the new instruction
1791     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1792   );
1793
1794   /// @brief Constructor with insert-at-end semantics.
1795   ZExtInst(
1796     Value *S,                     ///< The value to be zero extended
1797     const Type *Ty,               ///< The type to zero extend to
1798     const std::string &Name,      ///< A name for the new instruction
1799     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1800   );
1801
1802   /// @brief Clone an identical ZExtInst
1803   virtual CastInst *clone() const;
1804
1805   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1806   static inline bool classof(const ZExtInst *) { return true; }
1807   static inline bool classof(const Instruction *I) {
1808     return I->getOpcode() == ZExt;
1809   }
1810   static inline bool classof(const Value *V) {
1811     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1812   }
1813 };
1814
1815 //===----------------------------------------------------------------------===//
1816 //                                 SExtInst Class
1817 //===----------------------------------------------------------------------===//
1818
1819 /// @brief This class represents a sign extension of integer types.
1820 class SExtInst : public CastInst {
1821   /// @brief Private copy constructor
1822   SExtInst(const SExtInst &CI)
1823     : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1824   }
1825 public:
1826   /// @brief Constructor with insert-before-instruction semantics
1827   SExtInst(
1828     Value *S,                     ///< The value to be sign extended
1829     const Type *Ty,               ///< The type to sign extend to
1830     const std::string &Name = "", ///< A name for the new instruction
1831     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1832   );
1833
1834   /// @brief Constructor with insert-at-end-of-block semantics
1835   SExtInst(
1836     Value *S,                     ///< The value to be sign extended
1837     const Type *Ty,               ///< The type to sign extend to
1838     const std::string &Name,      ///< A name for the new instruction
1839     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1840   );
1841
1842   /// @brief Clone an identical SExtInst
1843   virtual CastInst *clone() const;
1844
1845   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1846   static inline bool classof(const SExtInst *) { return true; }
1847   static inline bool classof(const Instruction *I) {
1848     return I->getOpcode() == SExt;
1849   }
1850   static inline bool classof(const Value *V) {
1851     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1852   }
1853 };
1854
1855 //===----------------------------------------------------------------------===//
1856 //                                 FPTruncInst Class
1857 //===----------------------------------------------------------------------===//
1858
1859 /// @brief This class represents a truncation of floating point types.
1860 class FPTruncInst : public CastInst {
1861   FPTruncInst(const FPTruncInst &CI)
1862     : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1863   }
1864 public:
1865   /// @brief Constructor with insert-before-instruction semantics
1866   FPTruncInst(
1867     Value *S,                     ///< The value to be truncated
1868     const Type *Ty,               ///< The type to truncate to
1869     const std::string &Name = "", ///< A name for the new instruction
1870     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1871   );
1872
1873   /// @brief Constructor with insert-before-instruction semantics
1874   FPTruncInst(
1875     Value *S,                     ///< The value to be truncated
1876     const Type *Ty,               ///< The type to truncate to
1877     const std::string &Name,      ///< A name for the new instruction
1878     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1879   );
1880
1881   /// @brief Clone an identical FPTruncInst
1882   virtual CastInst *clone() const;
1883
1884   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1885   static inline bool classof(const FPTruncInst *) { return true; }
1886   static inline bool classof(const Instruction *I) {
1887     return I->getOpcode() == FPTrunc;
1888   }
1889   static inline bool classof(const Value *V) {
1890     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1891   }
1892 };
1893
1894 //===----------------------------------------------------------------------===//
1895 //                                 FPExtInst Class
1896 //===----------------------------------------------------------------------===//
1897
1898 /// @brief This class represents an extension of floating point types.
1899 class FPExtInst : public CastInst {
1900   FPExtInst(const FPExtInst &CI)
1901     : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1902   }
1903 public:
1904   /// @brief Constructor with insert-before-instruction semantics
1905   FPExtInst(
1906     Value *S,                     ///< The value to be extended
1907     const Type *Ty,               ///< The type to extend to
1908     const std::string &Name = "", ///< A name for the new instruction
1909     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1910   );
1911
1912   /// @brief Constructor with insert-at-end-of-block semantics
1913   FPExtInst(
1914     Value *S,                     ///< The value to be extended
1915     const Type *Ty,               ///< The type to extend to
1916     const std::string &Name,      ///< A name for the new instruction
1917     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1918   );
1919
1920   /// @brief Clone an identical FPExtInst
1921   virtual CastInst *clone() const;
1922
1923   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1924   static inline bool classof(const FPExtInst *) { return true; }
1925   static inline bool classof(const Instruction *I) {
1926     return I->getOpcode() == FPExt;
1927   }
1928   static inline bool classof(const Value *V) {
1929     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1930   }
1931 };
1932
1933 //===----------------------------------------------------------------------===//
1934 //                                 UIToFPInst Class
1935 //===----------------------------------------------------------------------===//
1936
1937 /// @brief This class represents a cast unsigned integer to floating point.
1938 class UIToFPInst : public CastInst {
1939   UIToFPInst(const UIToFPInst &CI)
1940     : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1941   }
1942 public:
1943   /// @brief Constructor with insert-before-instruction semantics
1944   UIToFPInst(
1945     Value *S,                     ///< The value to be converted
1946     const Type *Ty,               ///< The type to convert to
1947     const std::string &Name = "", ///< A name for the new instruction
1948     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1949   );
1950
1951   /// @brief Constructor with insert-at-end-of-block semantics
1952   UIToFPInst(
1953     Value *S,                     ///< The value to be converted
1954     const Type *Ty,               ///< The type to convert to
1955     const std::string &Name,      ///< A name for the new instruction
1956     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1957   );
1958
1959   /// @brief Clone an identical UIToFPInst
1960   virtual CastInst *clone() const;
1961
1962   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1963   static inline bool classof(const UIToFPInst *) { return true; }
1964   static inline bool classof(const Instruction *I) {
1965     return I->getOpcode() == UIToFP;
1966   }
1967   static inline bool classof(const Value *V) {
1968     return isa<Instruction>(V) && classof(cast<Instruction>(V));
1969   }
1970 };
1971
1972 //===----------------------------------------------------------------------===//
1973 //                                 SIToFPInst Class
1974 //===----------------------------------------------------------------------===//
1975
1976 /// @brief This class represents a cast from signed integer to floating point.
1977 class SIToFPInst : public CastInst {
1978   SIToFPInst(const SIToFPInst &CI)
1979     : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1980   }
1981 public:
1982   /// @brief Constructor with insert-before-instruction semantics
1983   SIToFPInst(
1984     Value *S,                     ///< The value to be converted
1985     const Type *Ty,               ///< The type to convert to
1986     const std::string &Name = "", ///< A name for the new instruction
1987     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1988   );
1989
1990   /// @brief Constructor with insert-at-end-of-block semantics
1991   SIToFPInst(
1992     Value *S,                     ///< The value to be converted
1993     const Type *Ty,               ///< The type to convert to
1994     const std::string &Name,      ///< A name for the new instruction
1995     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
1996   );
1997
1998   /// @brief Clone an identical SIToFPInst
1999   virtual CastInst *clone() const;
2000
2001   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2002   static inline bool classof(const SIToFPInst *) { return true; }
2003   static inline bool classof(const Instruction *I) {
2004     return I->getOpcode() == SIToFP;
2005   }
2006   static inline bool classof(const Value *V) {
2007     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2008   }
2009 };
2010
2011 //===----------------------------------------------------------------------===//
2012 //                                 FPToUIInst Class
2013 //===----------------------------------------------------------------------===//
2014
2015 /// @brief This class represents a cast from floating point to unsigned integer
2016 class FPToUIInst  : public CastInst {
2017   FPToUIInst(const FPToUIInst &CI)
2018     : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
2019   }
2020 public:
2021   /// @brief Constructor with insert-before-instruction semantics
2022   FPToUIInst(
2023     Value *S,                     ///< The value to be converted
2024     const Type *Ty,               ///< The type to convert to
2025     const std::string &Name = "", ///< A name for the new instruction
2026     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2027   );
2028
2029   /// @brief Constructor with insert-at-end-of-block semantics
2030   FPToUIInst(
2031     Value *S,                     ///< The value to be converted
2032     const Type *Ty,               ///< The type to convert to
2033     const std::string &Name,      ///< A name for the new instruction
2034     BasicBlock *InsertAtEnd       ///< Where to insert the new instruction
2035   );
2036
2037   /// @brief Clone an identical FPToUIInst
2038   virtual CastInst *clone() const;
2039
2040   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2041   static inline bool classof(const FPToUIInst *) { return true; }
2042   static inline bool classof(const Instruction *I) {
2043     return I->getOpcode() == FPToUI;
2044   }
2045   static inline bool classof(const Value *V) {
2046     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2047   }
2048 };
2049
2050 //===----------------------------------------------------------------------===//
2051 //                                 FPToSIInst Class
2052 //===----------------------------------------------------------------------===//
2053
2054 /// @brief This class represents a cast from floating point to signed integer.
2055 class FPToSIInst  : public CastInst {
2056   FPToSIInst(const FPToSIInst &CI)
2057     : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2058   }
2059 public:
2060   /// @brief Constructor with insert-before-instruction semantics
2061   FPToSIInst(
2062     Value *S,                     ///< The value to be converted
2063     const Type *Ty,               ///< The type to convert to
2064     const std::string &Name = "", ///< A name for the new instruction
2065     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2066   );
2067
2068   /// @brief Constructor with insert-at-end-of-block semantics
2069   FPToSIInst(
2070     Value *S,                     ///< The value to be converted
2071     const Type *Ty,               ///< The type to convert to
2072     const std::string &Name,      ///< A name for the new instruction
2073     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2074   );
2075
2076   /// @brief Clone an identical FPToSIInst
2077   virtual CastInst *clone() const;
2078
2079   /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2080   static inline bool classof(const FPToSIInst *) { return true; }
2081   static inline bool classof(const Instruction *I) {
2082     return I->getOpcode() == FPToSI;
2083   }
2084   static inline bool classof(const Value *V) {
2085     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2086   }
2087 };
2088
2089 //===----------------------------------------------------------------------===//
2090 //                                 IntToPtrInst Class
2091 //===----------------------------------------------------------------------===//
2092
2093 /// @brief This class represents a cast from an integer to a pointer.
2094 class IntToPtrInst : public CastInst {
2095   IntToPtrInst(const IntToPtrInst &CI)
2096     : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
2097   }
2098 public:
2099   /// @brief Constructor with insert-before-instruction semantics
2100   IntToPtrInst(
2101     Value *S,                     ///< The value to be converted
2102     const Type *Ty,               ///< The type to convert to
2103     const std::string &Name = "", ///< A name for the new instruction
2104     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2105   );
2106
2107   /// @brief Constructor with insert-at-end-of-block semantics
2108   IntToPtrInst(
2109     Value *S,                     ///< The value to be converted
2110     const Type *Ty,               ///< The type to convert to
2111     const std::string &Name,      ///< A name for the new instruction
2112     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2113   );
2114
2115   /// @brief Clone an identical IntToPtrInst
2116   virtual CastInst *clone() const;
2117
2118   // Methods for support type inquiry through isa, cast, and dyn_cast:
2119   static inline bool classof(const IntToPtrInst *) { return true; }
2120   static inline bool classof(const Instruction *I) {
2121     return I->getOpcode() == IntToPtr;
2122   }
2123   static inline bool classof(const Value *V) {
2124     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2125   }
2126 };
2127
2128 //===----------------------------------------------------------------------===//
2129 //                                 PtrToIntInst Class
2130 //===----------------------------------------------------------------------===//
2131
2132 /// @brief This class represents a cast from a pointer to an integer
2133 class PtrToIntInst : public CastInst {
2134   PtrToIntInst(const PtrToIntInst &CI)
2135     : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
2136   }
2137 public:
2138   /// @brief Constructor with insert-before-instruction semantics
2139   PtrToIntInst(
2140     Value *S,                     ///< The value to be converted
2141     const Type *Ty,               ///< The type to convert to
2142     const std::string &Name = "", ///< A name for the new instruction
2143     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2144   );
2145
2146   /// @brief Constructor with insert-at-end-of-block semantics
2147   PtrToIntInst(
2148     Value *S,                     ///< The value to be converted
2149     const Type *Ty,               ///< The type to convert to
2150     const std::string &Name,      ///< A name for the new instruction
2151     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2152   );
2153
2154   /// @brief Clone an identical PtrToIntInst
2155   virtual CastInst *clone() const;
2156
2157   // Methods for support type inquiry through isa, cast, and dyn_cast:
2158   static inline bool classof(const PtrToIntInst *) { return true; }
2159   static inline bool classof(const Instruction *I) {
2160     return I->getOpcode() == PtrToInt;
2161   }
2162   static inline bool classof(const Value *V) {
2163     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2164   }
2165 };
2166
2167 //===----------------------------------------------------------------------===//
2168 //                             BitCastInst Class
2169 //===----------------------------------------------------------------------===//
2170
2171 /// @brief This class represents a no-op cast from one type to another.
2172 class BitCastInst : public CastInst {
2173   BitCastInst(const BitCastInst &CI)
2174     : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2175   }
2176 public:
2177   /// @brief Constructor with insert-before-instruction semantics
2178   BitCastInst(
2179     Value *S,                     ///< The value to be casted
2180     const Type *Ty,               ///< The type to casted to
2181     const std::string &Name = "", ///< A name for the new instruction
2182     Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2183   );
2184
2185   /// @brief Constructor with insert-at-end-of-block semantics
2186   BitCastInst(
2187     Value *S,                     ///< The value to be casted
2188     const Type *Ty,               ///< The type to casted to
2189     const std::string &Name,      ///< A name for the new instruction
2190     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
2191   );
2192
2193   /// @brief Clone an identical BitCastInst
2194   virtual CastInst *clone() const;
2195
2196   // Methods for support type inquiry through isa, cast, and dyn_cast:
2197   static inline bool classof(const BitCastInst *) { return true; }
2198   static inline bool classof(const Instruction *I) {
2199     return I->getOpcode() == BitCast;
2200   }
2201   static inline bool classof(const Value *V) {
2202     return isa<Instruction>(V) && classof(cast<Instruction>(V));
2203   }
2204 };
2205
2206 } // End llvm namespace
2207
2208 #endif