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