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