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