LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Instructions.h

Go to the documentation of this file.
00001 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file exposes the class definitions of all of the subclasses of the
00011 // Instruction class.  This is meant to be an easy way to get access to all
00012 // instruction subclasses.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_INSTRUCTIONS_H
00017 #define LLVM_INSTRUCTIONS_H
00018 
00019 #include "llvm/Instruction.h"
00020 #include "llvm/InstrTypes.h"
00021 
00022 namespace llvm {
00023 
00024 class BasicBlock;
00025 class PointerType;
00026 
00027 //===----------------------------------------------------------------------===//
00028 //                             AllocationInst Class
00029 //===----------------------------------------------------------------------===//
00030 
00031 /// AllocationInst - This class is the common base class of MallocInst and
00032 /// AllocaInst.
00033 ///
00034 class AllocationInst : public Instruction {
00035 protected:
00036   void init(const Type *Ty, Value *ArraySize, unsigned iTy);
00037   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, 
00038      const std::string &Name = "", Instruction *InsertBefore = 0);
00039   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, 
00040      const std::string &Name, BasicBlock *InsertAtEnd);
00041 
00042 public:
00043 
00044   /// isArrayAllocation - Return true if there is an allocation size parameter
00045   /// to the allocation instruction that is not 1.
00046   ///
00047   bool isArrayAllocation() const;
00048 
00049   /// getArraySize - Get the number of element allocated, for a simple
00050   /// allocation of a single element, this will return a constant 1 value.
00051   ///
00052   inline const Value *getArraySize() const { return Operands[0]; }
00053   inline Value *getArraySize() { return Operands[0]; }
00054 
00055   /// getType - Overload to return most specific pointer type
00056   ///
00057   inline const PointerType *getType() const {
00058     return reinterpret_cast<const PointerType*>(Instruction::getType()); 
00059   }
00060 
00061   /// getAllocatedType - Return the type that is being allocated by the
00062   /// instruction.
00063   ///
00064   const Type *getAllocatedType() const;
00065 
00066   virtual Instruction *clone() const = 0;
00067 
00068   // Methods for support type inquiry through isa, cast, and dyn_cast:
00069   static inline bool classof(const AllocationInst *) { return true; }
00070   static inline bool classof(const Instruction *I) {
00071     return I->getOpcode() == Instruction::Alloca ||
00072            I->getOpcode() == Instruction::Malloc;
00073   }
00074   static inline bool classof(const Value *V) {
00075     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00076   }
00077 };
00078 
00079 
00080 //===----------------------------------------------------------------------===//
00081 //                                MallocInst Class
00082 //===----------------------------------------------------------------------===//
00083 
00084 /// MallocInst - an instruction to allocated memory on the heap
00085 ///
00086 class MallocInst : public AllocationInst {
00087   MallocInst(const MallocInst &MI);
00088 public:
00089   explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
00090                       const std::string &Name = "",
00091                       Instruction *InsertBefore = 0)
00092     : AllocationInst(Ty, ArraySize, Malloc, Name, InsertBefore) {}
00093   MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
00094              BasicBlock *InsertAtEnd)
00095     : AllocationInst(Ty, ArraySize, Malloc, Name, InsertAtEnd) {}
00096 
00097   virtual MallocInst *clone() const;
00098 
00099   // Methods for support type inquiry through isa, cast, and dyn_cast:
00100   static inline bool classof(const MallocInst *) { return true; }
00101   static inline bool classof(const Instruction *I) {
00102     return (I->getOpcode() == Instruction::Malloc);
00103   }
00104   static inline bool classof(const Value *V) {
00105     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00106   }
00107 };
00108 
00109 
00110 //===----------------------------------------------------------------------===//
00111 //                                AllocaInst Class
00112 //===----------------------------------------------------------------------===//
00113 
00114 /// AllocaInst - an instruction to allocate memory on the stack
00115 ///
00116 class AllocaInst : public AllocationInst {
00117   AllocaInst(const AllocaInst &);
00118 public:
00119   explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
00120                       const std::string &Name = "",
00121                       Instruction *InsertBefore = 0)
00122     : AllocationInst(Ty, ArraySize, Alloca, Name, InsertBefore) {}
00123   AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
00124              BasicBlock *InsertAtEnd)
00125     : AllocationInst(Ty, ArraySize, Alloca, Name, InsertAtEnd) {}
00126 
00127   virtual AllocaInst *clone() const;
00128 
00129   // Methods for support type inquiry through isa, cast, and dyn_cast:
00130   static inline bool classof(const AllocaInst *) { return true; }
00131   static inline bool classof(const Instruction *I) {
00132     return (I->getOpcode() == Instruction::Alloca);
00133   }
00134   static inline bool classof(const Value *V) {
00135     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00136   }
00137 };
00138 
00139 
00140 //===----------------------------------------------------------------------===//
00141 //                                 FreeInst Class
00142 //===----------------------------------------------------------------------===//
00143 
00144 /// FreeInst - an instruction to deallocate memory
00145 ///
00146 class FreeInst : public Instruction {
00147   void init(Value *Ptr);
00148 
00149 public:
00150   explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
00151   FreeInst(Value *Ptr, BasicBlock *InsertAfter);
00152 
00153   virtual FreeInst *clone() const;
00154 
00155   virtual bool mayWriteToMemory() const { return true; }
00156 
00157   // Methods for support type inquiry through isa, cast, and dyn_cast:
00158   static inline bool classof(const FreeInst *) { return true; }
00159   static inline bool classof(const Instruction *I) {
00160     return (I->getOpcode() == Instruction::Free);
00161   }
00162   static inline bool classof(const Value *V) {
00163     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00164   }
00165 };
00166 
00167 
00168 //===----------------------------------------------------------------------===//
00169 //                                LoadInst Class
00170 //===----------------------------------------------------------------------===//
00171 
00172 /// LoadInst - an instruction for reading from memory 
00173 ///
00174 class LoadInst : public Instruction {
00175   LoadInst(const LoadInst &LI) : Instruction(LI.getType(), Load) {
00176     Volatile = LI.isVolatile();
00177     init(LI.Operands[0]);
00178   }
00179   bool Volatile;   // True if this is a volatile load
00180   void init(Value *Ptr);
00181 public:
00182   LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
00183   LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
00184   LoadInst(Value *Ptr, const std::string &Name = "", bool isVolatile = false,
00185            Instruction *InsertBefore = 0);
00186   LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
00187            BasicBlock *InsertAtEnd);
00188 
00189   /// isVolatile - Return true if this is a load from a volatile memory
00190   /// location.
00191   ///
00192   bool isVolatile() const { return Volatile; }
00193 
00194   /// setVolatile - Specify whether this is a volatile load or not.
00195   ///
00196   void setVolatile(bool V) { Volatile = V; }
00197 
00198   virtual LoadInst *clone() const;
00199 
00200   virtual bool mayWriteToMemory() const { return isVolatile(); }
00201 
00202   Value *getPointerOperand() { return getOperand(0); }
00203   const Value *getPointerOperand() const { return getOperand(0); }
00204   static unsigned getPointerOperandIndex() { return 0U; }
00205 
00206   // Methods for support type inquiry through isa, cast, and dyn_cast:
00207   static inline bool classof(const LoadInst *) { return true; }
00208   static inline bool classof(const Instruction *I) {
00209     return I->getOpcode() == Instruction::Load;
00210   }
00211   static inline bool classof(const Value *V) {
00212     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00213   }
00214 };
00215 
00216 
00217 //===----------------------------------------------------------------------===//
00218 //                                StoreInst Class
00219 //===----------------------------------------------------------------------===//
00220 
00221 /// StoreInst - an instruction for storing to memory 
00222 ///
00223 class StoreInst : public Instruction {
00224   StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store) {
00225     Volatile = SI.isVolatile();
00226     init(SI.Operands[0], SI.Operands[1]);
00227   }
00228   bool Volatile;   // True if this is a volatile store
00229   void init(Value *Val, Value *Ptr);
00230 public:
00231   StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
00232   StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
00233   StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
00234             Instruction *InsertBefore = 0);
00235   StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
00236 
00237 
00238   /// isVolatile - Return true if this is a load from a volatile memory
00239   /// location.
00240   ///
00241   bool isVolatile() const { return Volatile; }
00242 
00243   /// setVolatile - Specify whether this is a volatile load or not.
00244   ///
00245   void setVolatile(bool V) { Volatile = V; }
00246 
00247   virtual StoreInst *clone() const;
00248 
00249   virtual bool mayWriteToMemory() const { return true; }
00250 
00251   Value *getPointerOperand() { return getOperand(1); }
00252   const Value *getPointerOperand() const { return getOperand(1); }
00253   static unsigned getPointerOperandIndex() { return 1U; }
00254 
00255   // Methods for support type inquiry through isa, cast, and dyn_cast:
00256   static inline bool classof(const StoreInst *) { return true; }
00257   static inline bool classof(const Instruction *I) {
00258     return I->getOpcode() == Instruction::Store;
00259   }
00260   static inline bool classof(const Value *V) {
00261     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00262   }
00263 };
00264 
00265 
00266 //===----------------------------------------------------------------------===//
00267 //                             GetElementPtrInst Class
00268 //===----------------------------------------------------------------------===//
00269 
00270 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
00271 /// access elements of arrays and structs
00272 ///
00273 class GetElementPtrInst : public Instruction {
00274   GetElementPtrInst(const GetElementPtrInst &EPI)
00275     : Instruction((static_cast<const Instruction*>(&EPI)->getType()),
00276                   GetElementPtr) {
00277     Operands.reserve(EPI.Operands.size());
00278     for (unsigned i = 0, E = (unsigned)EPI.Operands.size(); i != E; ++i)
00279       Operands.push_back(Use(EPI.Operands[i], this));
00280   }
00281   void init(Value *Ptr, const std::vector<Value*> &Idx);
00282   void init(Value *Ptr, Value *Idx0, Value *Idx1);
00283 public:
00284   /// Constructors - Create a getelementptr instruction with a base pointer an
00285   /// list of indices.  The first ctor can optionally insert before an existing
00286   /// instruction, the second appends the new instruction to the specified
00287   /// BasicBlock.
00288   GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
00289         const std::string &Name = "", Instruction *InsertBefore =0);
00290   GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
00291         const std::string &Name, BasicBlock *InsertAtEnd);
00292 
00293   /// Constructors - These two constructors are convenience methods because two
00294   /// index getelementptr instructions are so common.
00295   GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
00296         const std::string &Name = "", Instruction *InsertBefore =0);
00297   GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
00298         const std::string &Name, BasicBlock *InsertAtEnd);
00299 
00300   virtual GetElementPtrInst *clone() const;
00301   
00302   // getType - Overload to return most specific pointer type...
00303   inline const PointerType *getType() const {
00304     return reinterpret_cast<const PointerType*>(Instruction::getType());
00305   }
00306 
00307   /// getIndexedType - Returns the type of the element that would be loaded with
00308   /// a load instruction with the specified parameters.
00309   ///
00310   /// A null type is returned if the indices are invalid for the specified 
00311   /// pointer type.
00312   ///
00313   static const Type *getIndexedType(const Type *Ptr, 
00314             const std::vector<Value*> &Indices,
00315             bool AllowStructLeaf = false);
00316   static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
00317             bool AllowStructLeaf = false);
00318   
00319   inline op_iterator       idx_begin()       { return op_begin()+1; }
00320   inline const_op_iterator idx_begin() const { return op_begin()+1; }
00321   inline op_iterator       idx_end()         { return op_end(); }
00322   inline const_op_iterator idx_end()   const { return op_end(); }
00323 
00324   Value *getPointerOperand() {
00325     return getOperand(0);
00326   }
00327   const Value *getPointerOperand() const {
00328     return getOperand(0);
00329   }
00330   static unsigned getPointerOperandIndex() {
00331     return 0U;                      // get index for modifying correct operand
00332   }
00333 
00334   inline unsigned getNumIndices() const {  // Note: always non-negative
00335     return getNumOperands() - 1;
00336   }
00337   
00338   inline bool hasIndices() const {
00339     return getNumOperands() > 1;
00340   }
00341 
00342   // Methods for support type inquiry through isa, cast, and dyn_cast:
00343   static inline bool classof(const GetElementPtrInst *) { return true; }
00344   static inline bool classof(const Instruction *I) {
00345     return (I->getOpcode() == Instruction::GetElementPtr);
00346   }
00347   static inline bool classof(const Value *V) {
00348     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00349   }
00350 };
00351 
00352 //===----------------------------------------------------------------------===//
00353 //                            SetCondInst Class
00354 //===----------------------------------------------------------------------===//
00355 
00356 /// SetCondInst class - Represent a setCC operator, where CC is eq, ne, lt, gt,
00357 /// le, or ge.
00358 ///
00359 class SetCondInst : public BinaryOperator {
00360 public:
00361   SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
00362         const std::string &Name = "", Instruction *InsertBefore = 0);
00363   SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
00364         const std::string &Name, BasicBlock *InsertAtEnd);
00365 
00366   /// getInverseCondition - Return the inverse of the current condition opcode.
00367   /// For example seteq -> setne, setgt -> setle, setlt -> setge, etc...
00368   ///
00369   BinaryOps getInverseCondition() const {
00370     return getInverseCondition(getOpcode());
00371   }
00372 
00373   /// getInverseCondition - Static version that you can use without an
00374   /// instruction available.
00375   ///
00376   static BinaryOps getInverseCondition(BinaryOps Opcode);
00377 
00378   /// getSwappedCondition - Return the condition opcode that would be the result
00379   /// of exchanging the two operands of the setcc instruction without changing
00380   /// the result produced.  Thus, seteq->seteq, setle->setge, setlt->setgt, etc.
00381   ///
00382   BinaryOps getSwappedCondition() const {
00383     return getSwappedCondition(getOpcode());
00384   }
00385 
00386   /// getSwappedCondition - Static version that you can use without an
00387   /// instruction available.
00388   ///
00389   static BinaryOps getSwappedCondition(BinaryOps Opcode);
00390 
00391 
00392   // Methods for support type inquiry through isa, cast, and dyn_cast:
00393   static inline bool classof(const SetCondInst *) { return true; }
00394   static inline bool classof(const Instruction *I) {
00395     return I->getOpcode() == SetEQ || I->getOpcode() == SetNE ||
00396            I->getOpcode() == SetLE || I->getOpcode() == SetGE ||
00397            I->getOpcode() == SetLT || I->getOpcode() == SetGT;
00398   }
00399   static inline bool classof(const Value *V) {
00400     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00401   }
00402 };
00403 
00404 //===----------------------------------------------------------------------===//
00405 //                                 CastInst Class
00406 //===----------------------------------------------------------------------===//
00407 
00408 /// CastInst - This class represents a cast from Operand[0] to the type of
00409 /// the instruction (i->getType()).
00410 ///
00411 class CastInst : public Instruction {
00412   CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
00413     Operands.reserve(1);
00414     Operands.push_back(Use(CI.Operands[0], this));
00415   }
00416   void init(Value *S) {
00417     Operands.reserve(1);
00418     Operands.push_back(Use(S, this));
00419   }
00420 public:
00421   CastInst(Value *S, const Type *Ty, const std::string &Name = "",
00422            Instruction *InsertBefore = 0)
00423     : Instruction(Ty, Cast, Name, InsertBefore) {
00424     init(S);
00425   }
00426   CastInst(Value *S, const Type *Ty, const std::string &Name,
00427            BasicBlock *InsertAtEnd)
00428     : Instruction(Ty, Cast, Name, InsertAtEnd) {
00429     init(S);
00430   }
00431 
00432   virtual CastInst *clone() const;
00433 
00434   // Methods for support type inquiry through isa, cast, and dyn_cast:
00435   static inline bool classof(const CastInst *) { return true; }
00436   static inline bool classof(const Instruction *I) {
00437     return I->getOpcode() == Cast;
00438   }
00439   static inline bool classof(const Value *V) {
00440     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00441   }
00442 };
00443 
00444 
00445 //===----------------------------------------------------------------------===//
00446 //                                 CallInst Class
00447 //===----------------------------------------------------------------------===//
00448 
00449 /// CallInst - This class represents a function call, abstracting a target
00450 /// machine's calling convention.
00451 ///
00452 class CallInst : public Instruction {
00453   CallInst(const CallInst &CI);
00454   void init(Value *Func, const std::vector<Value*> &Params);
00455   void init(Value *Func, Value *Actual1, Value *Actual2);
00456   void init(Value *Func, Value *Actual);
00457   void init(Value *Func);
00458 
00459 public:
00460   CallInst(Value *F, const std::vector<Value*> &Par,
00461            const std::string &Name = "", Instruction *InsertBefore = 0);
00462   CallInst(Value *F, const std::vector<Value*> &Par,
00463            const std::string &Name, BasicBlock *InsertAtEnd);
00464 
00465   // Alternate CallInst ctors w/ two actuals, w/ one actual and no
00466   // actuals, respectively.
00467   CallInst(Value *F, Value *Actual1, Value *Actual2,
00468            const std::string& Name = "", Instruction *InsertBefore = 0);
00469   CallInst(Value *F, Value *Actual1, Value *Actual2,
00470            const std::string& Name, BasicBlock *InsertAtEnd);
00471   CallInst(Value *F, Value *Actual, const std::string& Name = "",
00472            Instruction *InsertBefore = 0);
00473   CallInst(Value *F, Value *Actual, const std::string& Name,
00474            BasicBlock *InsertAtEnd);
00475   explicit CallInst(Value *F, const std::string &Name = "", 
00476                     Instruction *InsertBefore = 0);
00477   explicit CallInst(Value *F, const std::string &Name, 
00478                     BasicBlock *InsertAtEnd);
00479 
00480   virtual CallInst *clone() const;
00481   bool mayWriteToMemory() const { return true; }
00482 
00483   /// getCalledFunction - Return the function being called by this instruction
00484   /// if it is a direct call.  If it is a call through a function pointer,
00485   /// return null.
00486   Function *getCalledFunction() const {
00487     return dyn_cast<Function>(Operands[0]);
00488   }
00489 
00490   // getCalledValue - Get a pointer to a method that is invoked by this inst.
00491   inline const Value *getCalledValue() const { return Operands[0]; }
00492   inline       Value *getCalledValue()       { return Operands[0]; }
00493 
00494   // Methods for support type inquiry through isa, cast, and dyn_cast:
00495   static inline bool classof(const CallInst *) { return true; }
00496   static inline bool classof(const Instruction *I) {
00497     return I->getOpcode() == Instruction::Call; 
00498   }
00499   static inline bool classof(const Value *V) {
00500     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00501   }
00502 };
00503 
00504 
00505 //===----------------------------------------------------------------------===//
00506 //                                 ShiftInst Class
00507 //===----------------------------------------------------------------------===//
00508 
00509 /// ShiftInst - This class represents left and right shift instructions.
00510 ///
00511 class ShiftInst : public Instruction {
00512   ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
00513     Operands.reserve(2);
00514     Operands.push_back(Use(SI.Operands[0], this));
00515     Operands.push_back(Use(SI.Operands[1], this));
00516   }
00517   void init(OtherOps Opcode, Value *S, Value *SA) {
00518     assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
00519     Operands.reserve(2);
00520     Operands.push_back(Use(S, this));
00521     Operands.push_back(Use(SA, this));
00522   }
00523 
00524 public:
00525   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
00526             Instruction *InsertBefore = 0)
00527     : Instruction(S->getType(), Opcode, Name, InsertBefore) {
00528     init(Opcode, S, SA);
00529   }
00530   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
00531             BasicBlock *InsertAtEnd)
00532     : Instruction(S->getType(), Opcode, Name, InsertAtEnd) {
00533     init(Opcode, S, SA);
00534   }
00535 
00536   OtherOps getOpcode() const {
00537     return static_cast<OtherOps>(Instruction::getOpcode());
00538   }
00539 
00540   virtual ShiftInst *clone() const;
00541 
00542   // Methods for support type inquiry through isa, cast, and dyn_cast:
00543   static inline bool classof(const ShiftInst *) { return true; }
00544   static inline bool classof(const Instruction *I) {
00545     return (I->getOpcode() == Instruction::Shr) | 
00546            (I->getOpcode() == Instruction::Shl);
00547   }
00548   static inline bool classof(const Value *V) {
00549     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00550   }
00551 };
00552 
00553 //===----------------------------------------------------------------------===//
00554 //                               SelectInst Class
00555 //===----------------------------------------------------------------------===//
00556 
00557 /// SelectInst - This class represents the LLVM 'select' instruction.
00558 ///
00559 class SelectInst : public Instruction {
00560   SelectInst(const SelectInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
00561     Operands.reserve(3);
00562     Operands.push_back(Use(SI.Operands[0], this));
00563     Operands.push_back(Use(SI.Operands[1], this));
00564     Operands.push_back(Use(SI.Operands[2], this));
00565   }
00566   void init(Value *C, Value *S1, Value *S2) {
00567     Operands.reserve(3);
00568     Operands.push_back(Use(C, this));
00569     Operands.push_back(Use(S1, this));
00570     Operands.push_back(Use(S2, this));
00571   }
00572 
00573 public:
00574   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
00575              Instruction *InsertBefore = 0)
00576     : Instruction(S1->getType(), Instruction::Select, Name, InsertBefore) {
00577     init(C, S1, S2);
00578   }
00579   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
00580              BasicBlock *InsertAtEnd)
00581     : Instruction(S1->getType(), Instruction::Select, Name, InsertAtEnd) {
00582     init(C, S1, S2);
00583   }
00584 
00585   Value *getCondition() const { return Operands[0]; }
00586   Value *getTrueValue() const { return Operands[1]; }
00587   Value *getFalseValue() const { return Operands[2]; }
00588 
00589   OtherOps getOpcode() const {
00590     return static_cast<OtherOps>(Instruction::getOpcode());
00591   }
00592 
00593   virtual SelectInst *clone() const;
00594 
00595   // Methods for support type inquiry through isa, cast, and dyn_cast:
00596   static inline bool classof(const SelectInst *) { return true; }
00597   static inline bool classof(const Instruction *I) {
00598     return I->getOpcode() == Instruction::Select;
00599   }
00600   static inline bool classof(const Value *V) {
00601     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00602   }
00603 };
00604 
00605 
00606 //===----------------------------------------------------------------------===//
00607 //                                VANextInst Class
00608 //===----------------------------------------------------------------------===//
00609 
00610 /// VANextInst - This class represents the va_next llvm instruction, which
00611 /// advances a vararg list passed an argument of the specified type, returning
00612 /// the resultant list.
00613 ///
00614 class VANextInst : public Instruction {
00615   PATypeHolder ArgTy;
00616   void init(Value *List) {
00617     Operands.reserve(1);
00618     Operands.push_back(Use(List, this));
00619   }
00620   VANextInst(const VANextInst &VAN)
00621     : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) {
00622     init(VAN.Operands[0]);
00623   }
00624 
00625 public:
00626   VANextInst(Value *List, const Type *Ty, const std::string &Name = "",
00627              Instruction *InsertBefore = 0)
00628     : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) {
00629     init(List);
00630   }
00631   VANextInst(Value *List, const Type *Ty, const std::string &Name,
00632              BasicBlock *InsertAtEnd)
00633     : Instruction(List->getType(), VANext, Name, InsertAtEnd), ArgTy(Ty) {
00634     init(List);
00635   }
00636 
00637   const Type *getArgType() const { return ArgTy; }
00638 
00639   virtual VANextInst *clone() const;
00640 
00641   // Methods for support type inquiry through isa, cast, and dyn_cast:
00642   static inline bool classof(const VANextInst *) { return true; }
00643   static inline bool classof(const Instruction *I) {
00644     return I->getOpcode() == VANext;
00645   }
00646   static inline bool classof(const Value *V) {
00647     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00648   }
00649 };
00650 
00651 
00652 //===----------------------------------------------------------------------===//
00653 //                                VAArgInst Class
00654 //===----------------------------------------------------------------------===//
00655 
00656 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
00657 /// an argument of the specified type given a va_list.
00658 ///
00659 class VAArgInst : public Instruction {
00660   void init(Value* List) {
00661     Operands.reserve(1);
00662     Operands.push_back(Use(List, this));
00663   }
00664   VAArgInst(const VAArgInst &VAA)
00665     : Instruction(VAA.getType(), VAArg) {
00666     init(VAA.Operands[0]);
00667   }
00668 public:
00669   VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
00670              Instruction *InsertBefore = 0)
00671     : Instruction(Ty, VAArg, Name, InsertBefore) {
00672     init(List);
00673   }
00674   VAArgInst(Value *List, const Type *Ty, const std::string &Name,
00675             BasicBlock *InsertAtEnd)
00676     : Instruction(Ty, VAArg, Name, InsertAtEnd) {
00677     init(List);
00678   }
00679 
00680   virtual VAArgInst *clone() const;
00681 
00682   // Methods for support type inquiry through isa, cast, and dyn_cast:
00683   static inline bool classof(const VAArgInst *) { return true; }
00684   static inline bool classof(const Instruction *I) {
00685     return I->getOpcode() == VAArg;
00686   }
00687   static inline bool classof(const Value *V) {
00688     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00689   }
00690 };
00691 
00692 //===----------------------------------------------------------------------===//
00693 //                               PHINode Class
00694 //===----------------------------------------------------------------------===//
00695 
00696 // PHINode - The PHINode class is used to represent the magical mystical PHI
00697 // node, that can not exist in nature, but can be synthesized in a computer
00698 // scientist's overactive imagination.
00699 //
00700 class PHINode : public Instruction {
00701   PHINode(const PHINode &PN);
00702 public:
00703   PHINode(const Type *Ty, const std::string &Name = "",
00704           Instruction *InsertBefore = 0)
00705     : Instruction(Ty, Instruction::PHI, Name, InsertBefore) {
00706   }
00707 
00708   PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
00709     : Instruction(Ty, Instruction::PHI, Name, InsertAtEnd) {
00710   }
00711 
00712   virtual PHINode *clone() const;
00713 
00714   /// getNumIncomingValues - Return the number of incoming edges
00715   ///
00716   unsigned getNumIncomingValues() const { return (unsigned)Operands.size()/2; }
00717 
00718   /// getIncomingValue - Return incoming value #x
00719   ///
00720   Value *getIncomingValue(unsigned i) const {
00721     assert(i*2 < Operands.size() && "Invalid value number!");
00722     return Operands[i*2];
00723   }
00724   void setIncomingValue(unsigned i, Value *V) {
00725     assert(i*2 < Operands.size() && "Invalid value number!");
00726     Operands[i*2] = V;
00727   }
00728   inline unsigned getOperandNumForIncomingValue(unsigned i) {
00729     return i*2;
00730   }
00731 
00732   /// getIncomingBlock - Return incoming basic block #x
00733   ///
00734   BasicBlock *getIncomingBlock(unsigned i) const { 
00735     assert(i*2+1 < Operands.size() && "Invalid value number!");
00736     return reinterpret_cast<BasicBlock*>(Operands[i*2+1].get());
00737   }
00738   void setIncomingBlock(unsigned i, BasicBlock *BB) {
00739     assert(i*2+1 < Operands.size() && "Invalid value number!");
00740     Operands[i*2+1] = reinterpret_cast<Value*>(BB);
00741   }
00742   unsigned getOperandNumForIncomingBlock(unsigned i) {
00743     return i*2+1;
00744   }
00745 
00746   /// addIncoming - Add an incoming value to the end of the PHI list
00747   ///
00748   void addIncoming(Value *V, BasicBlock *BB) {
00749     assert(getType() == V->getType() &&
00750            "All operands to PHI node must be the same type as the PHI node!");
00751     Operands.push_back(Use(V, this));
00752     Operands.push_back(Use(reinterpret_cast<Value*>(BB), this));
00753   }
00754   
00755   /// removeIncomingValue - Remove an incoming value.  This is useful if a
00756   /// predecessor basic block is deleted.  The value removed is returned.
00757   ///
00758   /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
00759   /// is true), the PHI node is destroyed and any uses of it are replaced with
00760   /// dummy values.  The only time there should be zero incoming values to a PHI
00761   /// node is when the block is dead, so this strategy is sound.
00762   ///
00763   Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
00764 
00765   Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
00766     int Idx = getBasicBlockIndex(BB);
00767     assert(Idx >= 0 && "Invalid basic block argument to remove!");
00768     return removeIncomingValue(Idx, DeletePHIIfEmpty);
00769   }
00770 
00771   /// getBasicBlockIndex - Return the first index of the specified basic 
00772   /// block in the value list for this PHI.  Returns -1 if no instance.
00773   ///
00774   int getBasicBlockIndex(const BasicBlock *BB) const {
00775     for (unsigned i = 0; i < Operands.size()/2; ++i) 
00776       if (getIncomingBlock(i) == BB) return i;
00777     return -1;
00778   }
00779 
00780   Value *getIncomingValueForBlock(const BasicBlock *BB) const {
00781     return getIncomingValue(getBasicBlockIndex(BB));
00782   }
00783 
00784   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00785   static inline bool classof(const PHINode *) { return true; }
00786   static inline bool classof(const Instruction *I) {
00787     return I->getOpcode() == Instruction::PHI; 
00788   }
00789   static inline bool classof(const Value *V) {
00790     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00791   }
00792 };
00793 
00794 //===----------------------------------------------------------------------===//
00795 //                               ReturnInst Class
00796 //===----------------------------------------------------------------------===//
00797 
00798 //===---------------------------------------------------------------------------
00799 /// ReturnInst - Return a value (possibly void), from a function.  Execution
00800 /// does not continue in this function any longer.
00801 ///
00802 class ReturnInst : public TerminatorInst {
00803   ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret) {
00804     if (RI.Operands.size()) {
00805       assert(RI.Operands.size() == 1 && "Return insn can only have 1 operand!");
00806       Operands.reserve(1);
00807       Operands.push_back(Use(RI.Operands[0], this));
00808     }
00809   }
00810 
00811   void init(Value *RetVal);
00812 
00813 public:
00814   // ReturnInst constructors:
00815   // ReturnInst()                  - 'ret void' instruction
00816   // ReturnInst(    null)          - 'ret void' instruction
00817   // ReturnInst(Value* X)          - 'ret X'    instruction
00818   // ReturnInst(    null, Inst *)  - 'ret void' instruction, insert before I
00819   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
00820   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of BB
00821   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of BB
00822   //
00823   // NOTE: If the Value* passed is of type void then the constructor behaves as
00824   // if it was passed NULL.
00825   ReturnInst(Value *RetVal = 0, Instruction *InsertBefore = 0)
00826     : TerminatorInst(Instruction::Ret, InsertBefore) {
00827     init(RetVal);
00828   }
00829   ReturnInst(Value *RetVal, BasicBlock *InsertAtEnd)
00830     : TerminatorInst(Instruction::Ret, InsertAtEnd) {
00831     init(RetVal);
00832   }
00833   ReturnInst(BasicBlock *InsertAtEnd)
00834     : TerminatorInst(Instruction::Ret, InsertAtEnd) {
00835   }
00836 
00837   virtual ReturnInst *clone() const;
00838 
00839   inline const Value *getReturnValue() const {
00840     return Operands.size() ? Operands[0].get() : 0; 
00841   }
00842   inline       Value *getReturnValue()       {
00843     return Operands.size() ? Operands[0].get() : 0;
00844   }
00845 
00846   virtual const BasicBlock *getSuccessor(unsigned idx) const {
00847     assert(0 && "ReturnInst has no successors!");
00848     abort();
00849     return 0;
00850   }
00851   virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc);
00852   virtual unsigned getNumSuccessors() const { return 0; }
00853 
00854   // Methods for support type inquiry through isa, cast, and dyn_cast:
00855   static inline bool classof(const ReturnInst *) { return true; }
00856   static inline bool classof(const Instruction *I) {
00857     return (I->getOpcode() == Instruction::Ret);
00858   }
00859   static inline bool classof(const Value *V) {
00860     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00861   }
00862 };
00863 
00864 //===----------------------------------------------------------------------===//
00865 //                               BranchInst Class
00866 //===----------------------------------------------------------------------===//
00867 
00868 //===---------------------------------------------------------------------------
00869 /// BranchInst - Conditional or Unconditional Branch instruction.
00870 ///
00871 class BranchInst : public TerminatorInst {
00872   BranchInst(const BranchInst &BI);
00873   void init(BasicBlock *IfTrue);
00874   void init(BasicBlock *True, BasicBlock *False, Value *Cond);
00875 public:
00876   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
00877   // BranchInst(BB *B)                           - 'br B'
00878   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
00879   // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
00880   // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
00881   // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
00882   // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
00883   BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
00884     : TerminatorInst(Instruction::Br, InsertBefore) {
00885     init(IfTrue);
00886   }
00887   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
00888              Instruction *InsertBefore = 0)
00889     : TerminatorInst(Instruction::Br, InsertBefore) {
00890     init(IfTrue, IfFalse, Cond);
00891   }
00892 
00893   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
00894     : TerminatorInst(Instruction::Br, InsertAtEnd) {
00895     init(IfTrue);
00896   }
00897 
00898   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
00899              BasicBlock *InsertAtEnd)
00900     : TerminatorInst(Instruction::Br, InsertAtEnd) {
00901     init(IfTrue, IfFalse, Cond);
00902   }
00903 
00904   virtual BranchInst *clone() const;
00905 
00906   inline bool isUnconditional() const { return Operands.size() == 1; }
00907   inline bool isConditional()   const { return Operands.size() == 3; }
00908 
00909   inline Value *getCondition() const {
00910     assert(isConditional() && "Cannot get condition of an uncond branch!");
00911     return Operands[2].get();
00912   }
00913 
00914   void setCondition(Value *V) {
00915     assert(isConditional() && "Cannot set condition of unconditional branch!");
00916     setOperand(2, V);
00917   }
00918 
00919   // setUnconditionalDest - Change the current branch to an unconditional branch
00920   // targeting the specified block.
00921   //
00922   void setUnconditionalDest(BasicBlock *Dest) {
00923     if (isConditional()) Operands.erase(Operands.begin()+1, Operands.end());
00924     Operands[0] = reinterpret_cast<Value*>(Dest);
00925   }
00926 
00927   virtual const BasicBlock *getSuccessor(unsigned i) const {
00928     assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
00929     return (i == 0) ? cast<BasicBlock>(Operands[0].get()) : 
00930                       cast<BasicBlock>(Operands[1].get());
00931   }
00932   inline BasicBlock *getSuccessor(unsigned idx) {
00933     const BranchInst *BI = this;
00934     return const_cast<BasicBlock*>(BI->getSuccessor(idx));
00935   }
00936 
00937   virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
00938     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
00939     Operands[idx] = reinterpret_cast<Value*>(NewSucc);
00940   }
00941 
00942   virtual unsigned getNumSuccessors() const { return 1+isConditional(); }
00943 
00944   // Methods for support type inquiry through isa, cast, and dyn_cast:
00945   static inline bool classof(const BranchInst *) { return true; }
00946   static inline bool classof(const Instruction *I) {
00947     return (I->getOpcode() == Instruction::Br);
00948   }
00949   static inline bool classof(const Value *V) {
00950     return isa<Instruction>(V) && classof(cast<Instruction>(V));
00951   }
00952 };
00953 
00954 //===----------------------------------------------------------------------===//
00955 //                               SwitchInst Class
00956 //===----------------------------------------------------------------------===//
00957 
00958 //===---------------------------------------------------------------------------
00959 /// SwitchInst - Multiway switch
00960 ///
00961 class SwitchInst : public TerminatorInst {
00962   // Operand[0]    = Value to switch on
00963   // Operand[1]    = Default basic block destination
00964   // Operand[2n  ] = Value to match
00965   // Operand[2n+1] = BasicBlock to go to on match
00966   SwitchInst(const SwitchInst &RI);
00967   void init(Value *Value, BasicBlock *Default);
00968 
00969 public:
00970   SwitchInst(Value *Value, BasicBlock *Default, Instruction *InsertBefore = 0) 
00971     : TerminatorInst(Instruction::Switch, InsertBefore) {
00972     init(Value, Default);
00973   }
00974   SwitchInst(Value *Value, BasicBlock *Default, BasicBlock  *InsertAtEnd) 
00975     : TerminatorInst(Instruction::Switch, InsertAtEnd) {
00976     init(Value, Default);
00977   }
00978 
00979   virtual SwitchInst *clone() const;
00980 
00981   // Accessor Methods for Switch stmt
00982   //
00983   inline const Value *getCondition() const { return Operands[0]; }
00984   inline       Value *getCondition()       { return Operands[0]; }
00985   inline const BasicBlock *getDefaultDest() const {
00986     return cast<BasicBlock>(Operands[1].get());
00987   }
00988   inline       BasicBlock *getDefaultDest()       {
00989     return cast<BasicBlock>(Operands[1].get());
00990   }
00991 
00992   /// getNumCases - return the number of 'cases' in this switch instruction.
00993   /// Note that case #0 is always the default case.
00994   unsigned getNumCases() const {
00995     return (unsigned)Operands.size()/2;
00996   }
00997 
00998   /// getCaseValue - Return the specified case value.  Note that case #0, the
00999   /// default destination, does not have a case value.
01000   Constant *getCaseValue(unsigned i) {
01001     assert(i && i < getNumCases() && "Illegal case value to get!");
01002     return getSuccessorValue(i);
01003   }
01004 
01005   /// getCaseValue - Return the specified case value.  Note that case #0, the
01006   /// default destination, does not have a case value.
01007   const Constant *getCaseValue(unsigned i) const {
01008     assert(i && i < getNumCases() && "Illegal case value to get!");
01009     return getSuccessorValue(i);
01010   }
01011 
01012   /// findCaseValue - Search all of the case values for the specified constant.
01013   /// If it is explicitly handled, return the case number of it, otherwise
01014   /// return 0 to indicate that it is handled by the default handler.
01015   unsigned findCaseValue(const Constant *C) const {
01016     for (unsigned i = 1, e = getNumCases(); i != e; ++i)
01017       if (getCaseValue(i) == C)
01018         return i;
01019     return 0;
01020   }
01021 
01022   /// addCase - Add an entry to the switch instruction...
01023   ///
01024   void addCase(Constant *OnVal, BasicBlock *Dest);
01025 
01026   /// removeCase - This method removes the specified successor from the switch
01027   /// instruction.  Note that this cannot be used to remove the default
01028   /// destination (successor #0).
01029   ///
01030   void removeCase(unsigned idx);
01031 
01032   virtual const BasicBlock *getSuccessor(unsigned idx) const {
01033     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
01034     return cast<BasicBlock>(Operands[idx*2+1].get());
01035   }
01036   inline BasicBlock *getSuccessor(unsigned idx) {
01037     assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
01038     return cast<BasicBlock>(Operands[idx*2+1].get());
01039   }
01040 
01041   virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
01042     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
01043     Operands[idx*2+1] = reinterpret_cast<Value*>(NewSucc);
01044   }
01045 
01046   // getSuccessorValue - Return the value associated with the specified
01047   // successor.
01048   inline const Constant *getSuccessorValue(unsigned idx) const {
01049     assert(idx < getNumSuccessors() && "Successor # out of range!");
01050     return cast<Constant>(Operands[idx*2].get());
01051   }
01052   inline Constant *getSuccessorValue(unsigned idx) {
01053     assert(idx < getNumSuccessors() && "Successor # out of range!");
01054     return cast<Constant>(Operands[idx*2].get());
01055   }
01056   virtual unsigned getNumSuccessors() const { return (unsigned)Operands.size()/2; }
01057 
01058   // Methods for support type inquiry through isa, cast, and dyn_cast:
01059   static inline bool classof(const SwitchInst *) { return true; }
01060   static inline bool classof(const Instruction *I) {
01061     return (I->getOpcode() == Instruction::Switch);
01062   }
01063   static inline bool classof(const Value *V) {
01064     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01065   }
01066 };
01067 
01068 //===----------------------------------------------------------------------===//
01069 //                               InvokeInst Class
01070 //===----------------------------------------------------------------------===//
01071 
01072 //===---------------------------------------------------------------------------
01073 /// InvokeInst - Invoke instruction
01074 ///
01075 class InvokeInst : public TerminatorInst {
01076   InvokeInst(const InvokeInst &BI);
01077   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
01078             const std::vector<Value*> &Params);
01079 public:
01080   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
01081        const std::vector<Value*> &Params, const std::string &Name = "",
01082              Instruction *InsertBefore = 0);
01083   InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
01084        const std::vector<Value*> &Params, const std::string &Name,
01085              BasicBlock *InsertAtEnd);
01086 
01087   virtual InvokeInst *clone() const;
01088 
01089   bool mayWriteToMemory() const { return true; }
01090 
01091   /// getCalledFunction - Return the function called, or null if this is an
01092   /// indirect function invocation.
01093   ///
01094   Function *getCalledFunction() const {
01095     return dyn_cast<Function>(Operands[0]);
01096   }
01097 
01098   // getCalledValue - Get a pointer to a function that is invoked by this inst.
01099   inline const Value *getCalledValue() const { return Operands[0]; }
01100   inline       Value *getCalledValue()       { return Operands[0]; }
01101 
01102   // get*Dest - Return the destination basic blocks...
01103   inline const BasicBlock *getNormalDest() const {
01104     return cast<BasicBlock>(Operands[1].get());
01105   }
01106   inline       BasicBlock *getNormalDest() {
01107     return cast<BasicBlock>(Operands[1].get());
01108   }
01109   inline const BasicBlock *getUnwindDest() const {
01110     return cast<BasicBlock>(Operands[2].get());
01111   }
01112   inline       BasicBlock *getUnwindDest() {
01113     return cast<BasicBlock>(Operands[2].get());
01114   }
01115 
01116   inline void setNormalDest(BasicBlock *B){
01117     Operands[1] = reinterpret_cast<Value*>(B);
01118   }
01119 
01120   inline void setUnwindDest(BasicBlock *B){
01121     Operands[2] = reinterpret_cast<Value*>(B);
01122   }
01123 
01124   virtual const BasicBlock *getSuccessor(unsigned i) const {
01125     assert(i < 2 && "Successor # out of range for invoke!");
01126     return i == 0 ? getNormalDest() : getUnwindDest();
01127   }
01128   inline BasicBlock *getSuccessor(unsigned i) {
01129     assert(i < 2 && "Successor # out of range for invoke!");
01130     return i == 0 ? getNormalDest() : getUnwindDest();
01131   }
01132 
01133   virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
01134     assert(idx < 2 && "Successor # out of range for invoke!");
01135     Operands[idx+1] = reinterpret_cast<Value*>(NewSucc);
01136   }
01137 
01138   virtual unsigned getNumSuccessors() const { return 2; }
01139 
01140   // Methods for support type inquiry through isa, cast, and dyn_cast:
01141   static inline bool classof(const InvokeInst *) { return true; }
01142   static inline bool classof(const Instruction *I) {
01143     return (I->getOpcode() == Instruction::Invoke);
01144   }
01145   static inline bool classof(const Value *V) {
01146     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01147   }
01148 };
01149 
01150 
01151 //===----------------------------------------------------------------------===//
01152 //                              UnwindInst Class
01153 //===----------------------------------------------------------------------===//
01154 
01155 //===---------------------------------------------------------------------------
01156 /// UnwindInst - Immediately exit the current function, unwinding the stack
01157 /// until an invoke instruction is found.
01158 ///
01159 class UnwindInst : public TerminatorInst {
01160 public:
01161   UnwindInst(Instruction *InsertBefore = 0)
01162     : TerminatorInst(Instruction::Unwind, InsertBefore) {
01163   }
01164   UnwindInst(BasicBlock *InsertAtEnd)
01165     : TerminatorInst(Instruction::Unwind, InsertAtEnd) {
01166   }
01167 
01168   virtual UnwindInst *clone() const;
01169 
01170   virtual const BasicBlock *getSuccessor(unsigned idx) const {
01171     assert(0 && "UnwindInst has no successors!");
01172     abort();
01173     return 0;
01174   }
01175   virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc);
01176   virtual unsigned getNumSuccessors() const { return 0; }
01177 
01178   // Methods for support type inquiry through isa, cast, and dyn_cast:
01179   static inline bool classof(const UnwindInst *) { return true; }
01180   static inline bool classof(const Instruction *I) {
01181     return I->getOpcode() == Instruction::Unwind;
01182   }
01183   static inline bool classof(const Value *V) {
01184     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01185   }
01186 };
01187 
01188 //===----------------------------------------------------------------------===//
01189 //                           UnreachableInst Class
01190 //===----------------------------------------------------------------------===//
01191 
01192 //===---------------------------------------------------------------------------
01193 /// UnreachableInst - This function has undefined behavior.  In particular, the
01194 /// presence of this instruction indicates some higher level knowledge that the
01195 /// end of the block cannot be reached.
01196 ///
01197 class UnreachableInst : public TerminatorInst {
01198 public:
01199   UnreachableInst(Instruction *InsertBefore = 0)
01200     : TerminatorInst(Instruction::Unreachable, InsertBefore) {
01201   }
01202   UnreachableInst(BasicBlock *InsertAtEnd)
01203     : TerminatorInst(Instruction::Unreachable, InsertAtEnd) {
01204   }
01205 
01206   virtual UnreachableInst *clone() const;
01207 
01208   virtual const BasicBlock *getSuccessor(unsigned idx) const {
01209     assert(0 && "UnreachableInst has no successors!");
01210     abort();
01211     return 0;
01212   }
01213   virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc);
01214   virtual unsigned getNumSuccessors() const { return 0; }
01215 
01216   // Methods for support type inquiry through isa, cast, and dyn_cast:
01217   static inline bool classof(const UnreachableInst *) { return true; }
01218   static inline bool classof(const Instruction *I) {
01219     return I->getOpcode() == Instruction::Unreachable;
01220   }
01221   static inline bool classof(const Value *V) {
01222     return isa<Instruction>(V) && classof(cast<Instruction>(V));
01223   }
01224 };
01225 
01226 } // End llvm namespace
01227 
01228 #endif