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