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