Chris Lattner | a892a3a | 2003-01-27 22:08:52 +0000 | [diff] [blame] | 1 | //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===// |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 2 | // |
John Criswell | 6fbcc26 | 2003-10-20 20:19:47 +0000 | [diff] [blame] | 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. |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 7 | // |
John Criswell | 6fbcc26 | 2003-10-20 20:19:47 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | a892a3a | 2003-01-27 22:08:52 +0000 | [diff] [blame] | 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 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 19 | #include "llvm/Instruction.h" |
| 20 | #include "llvm/InstrTypes.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 24 | class BasicBlock; |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 25 | class ConstantInt; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 26 | class PointerType; |
| 27 | |
| 28 | //===----------------------------------------------------------------------===// |
| 29 | // AllocationInst Class |
| 30 | //===----------------------------------------------------------------------===// |
| 31 | |
| 32 | /// AllocationInst - This class is the common base class of MallocInst and |
| 33 | /// AllocaInst. |
| 34 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 35 | class AllocationInst : public UnaryInstruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 36 | protected: |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 37 | AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 38 | const std::string &Name = "", Instruction *InsertBefore = 0); |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 39 | AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 40 | const std::string &Name, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 41 | |
| 42 | public: |
| 43 | |
| 44 | /// isArrayAllocation - Return true if there is an allocation size parameter |
| 45 | /// to the allocation instruction that is not 1. |
| 46 | /// |
| 47 | bool isArrayAllocation() const; |
| 48 | |
| 49 | /// getArraySize - Get the number of element allocated, for a simple |
| 50 | /// allocation of a single element, this will return a constant 1 value. |
| 51 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 52 | inline const Value *getArraySize() const { return getOperand(0); } |
| 53 | inline Value *getArraySize() { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 54 | |
| 55 | /// getType - Overload to return most specific pointer type |
| 56 | /// |
| 57 | inline const PointerType *getType() const { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 58 | return reinterpret_cast<const PointerType*>(Instruction::getType()); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /// getAllocatedType - Return the type that is being allocated by the |
| 62 | /// instruction. |
| 63 | /// |
| 64 | const Type *getAllocatedType() const; |
| 65 | |
| 66 | virtual Instruction *clone() const = 0; |
| 67 | |
| 68 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 69 | static inline bool classof(const AllocationInst *) { return true; } |
| 70 | static inline bool classof(const Instruction *I) { |
| 71 | return I->getOpcode() == Instruction::Alloca || |
| 72 | I->getOpcode() == Instruction::Malloc; |
| 73 | } |
| 74 | static inline bool classof(const Value *V) { |
| 75 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | |
| 80 | //===----------------------------------------------------------------------===// |
| 81 | // MallocInst Class |
| 82 | //===----------------------------------------------------------------------===// |
| 83 | |
| 84 | /// MallocInst - an instruction to allocated memory on the heap |
| 85 | /// |
| 86 | class MallocInst : public AllocationInst { |
| 87 | MallocInst(const MallocInst &MI); |
| 88 | public: |
| 89 | explicit MallocInst(const Type *Ty, Value *ArraySize = 0, |
| 90 | const std::string &Name = "", |
| 91 | Instruction *InsertBefore = 0) |
| 92 | : AllocationInst(Ty, ArraySize, Malloc, Name, InsertBefore) {} |
| 93 | MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name, |
| 94 | BasicBlock *InsertAtEnd) |
| 95 | : AllocationInst(Ty, ArraySize, Malloc, Name, InsertAtEnd) {} |
| 96 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 97 | virtual MallocInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 98 | |
| 99 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 100 | static inline bool classof(const MallocInst *) { return true; } |
| 101 | static inline bool classof(const Instruction *I) { |
| 102 | return (I->getOpcode() == Instruction::Malloc); |
| 103 | } |
| 104 | static inline bool classof(const Value *V) { |
| 105 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 106 | } |
| 107 | }; |
| 108 | |
| 109 | |
| 110 | //===----------------------------------------------------------------------===// |
| 111 | // AllocaInst Class |
| 112 | //===----------------------------------------------------------------------===// |
| 113 | |
| 114 | /// AllocaInst - an instruction to allocate memory on the stack |
| 115 | /// |
| 116 | class AllocaInst : public AllocationInst { |
| 117 | AllocaInst(const AllocaInst &); |
| 118 | public: |
| 119 | explicit AllocaInst(const Type *Ty, Value *ArraySize = 0, |
| 120 | const std::string &Name = "", |
| 121 | Instruction *InsertBefore = 0) |
| 122 | : AllocationInst(Ty, ArraySize, Alloca, Name, InsertBefore) {} |
| 123 | AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name, |
| 124 | BasicBlock *InsertAtEnd) |
| 125 | : AllocationInst(Ty, ArraySize, Alloca, Name, InsertAtEnd) {} |
| 126 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 127 | virtual AllocaInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 128 | |
| 129 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 130 | static inline bool classof(const AllocaInst *) { return true; } |
| 131 | static inline bool classof(const Instruction *I) { |
| 132 | return (I->getOpcode() == Instruction::Alloca); |
| 133 | } |
| 134 | static inline bool classof(const Value *V) { |
| 135 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 136 | } |
| 137 | }; |
| 138 | |
| 139 | |
| 140 | //===----------------------------------------------------------------------===// |
| 141 | // FreeInst Class |
| 142 | //===----------------------------------------------------------------------===// |
| 143 | |
| 144 | /// FreeInst - an instruction to deallocate memory |
| 145 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 146 | class FreeInst : public UnaryInstruction { |
| 147 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 148 | public: |
| 149 | explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0); |
| 150 | FreeInst(Value *Ptr, BasicBlock *InsertAfter); |
| 151 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 152 | virtual FreeInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 153 | |
| 154 | virtual bool mayWriteToMemory() const { return true; } |
| 155 | |
| 156 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 157 | static inline bool classof(const FreeInst *) { return true; } |
| 158 | static inline bool classof(const Instruction *I) { |
| 159 | return (I->getOpcode() == Instruction::Free); |
| 160 | } |
| 161 | static inline bool classof(const Value *V) { |
| 162 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 163 | } |
| 164 | }; |
| 165 | |
| 166 | |
| 167 | //===----------------------------------------------------------------------===// |
| 168 | // LoadInst Class |
| 169 | //===----------------------------------------------------------------------===// |
| 170 | |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 171 | /// LoadInst - an instruction for reading from memory. This uses the |
| 172 | /// SubclassData field in Value to store whether or not the load is volatile. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 173 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 174 | class LoadInst : public UnaryInstruction { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 175 | LoadInst(const LoadInst &LI) |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 176 | : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) { |
| 177 | setVolatile(LI.isVolatile()); |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 178 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 179 | #ifndef NDEBUG |
| 180 | AssertOK(); |
| 181 | #endif |
| 182 | } |
| 183 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 184 | public: |
| 185 | LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore); |
| 186 | LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd); |
| 187 | LoadInst(Value *Ptr, const std::string &Name = "", bool isVolatile = false, |
| 188 | Instruction *InsertBefore = 0); |
| 189 | LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, |
| 190 | BasicBlock *InsertAtEnd); |
| 191 | |
| 192 | /// isVolatile - Return true if this is a load from a volatile memory |
| 193 | /// location. |
| 194 | /// |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 195 | bool isVolatile() const { return SubclassData; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 196 | |
| 197 | /// setVolatile - Specify whether this is a volatile load or not. |
| 198 | /// |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 199 | void setVolatile(bool V) { SubclassData = V; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 200 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 201 | virtual LoadInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 202 | |
| 203 | virtual bool mayWriteToMemory() const { return isVolatile(); } |
| 204 | |
| 205 | Value *getPointerOperand() { return getOperand(0); } |
| 206 | const Value *getPointerOperand() const { return getOperand(0); } |
| 207 | static unsigned getPointerOperandIndex() { return 0U; } |
| 208 | |
| 209 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 210 | static inline bool classof(const LoadInst *) { return true; } |
| 211 | static inline bool classof(const Instruction *I) { |
| 212 | return I->getOpcode() == Instruction::Load; |
| 213 | } |
| 214 | static inline bool classof(const Value *V) { |
| 215 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 216 | } |
| 217 | }; |
| 218 | |
| 219 | |
| 220 | //===----------------------------------------------------------------------===// |
| 221 | // StoreInst Class |
| 222 | //===----------------------------------------------------------------------===// |
| 223 | |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 224 | /// StoreInst - an instruction for storing to memory |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 225 | /// |
| 226 | class StoreInst : public Instruction { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 227 | Use Ops[2]; |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 228 | StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 229 | Ops[0].init(SI.Ops[0], this); |
| 230 | Ops[1].init(SI.Ops[1], this); |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 231 | setVolatile(SI.isVolatile()); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 232 | #ifndef NDEBUG |
| 233 | AssertOK(); |
| 234 | #endif |
| 235 | } |
| 236 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 237 | public: |
| 238 | StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore); |
| 239 | StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd); |
| 240 | StoreInst(Value *Val, Value *Ptr, bool isVolatile = false, |
| 241 | Instruction *InsertBefore = 0); |
| 242 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd); |
| 243 | |
| 244 | |
| 245 | /// isVolatile - Return true if this is a load from a volatile memory |
| 246 | /// location. |
| 247 | /// |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 248 | bool isVolatile() const { return SubclassData; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 249 | |
| 250 | /// setVolatile - Specify whether this is a volatile load or not. |
| 251 | /// |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 252 | void setVolatile(bool V) { SubclassData = V; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 253 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 254 | /// Transparently provide more efficient getOperand methods. |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 255 | Value *getOperand(unsigned i) const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 256 | assert(i < 2 && "getOperand() out of range!"); |
| 257 | return Ops[i]; |
| 258 | } |
| 259 | void setOperand(unsigned i, Value *Val) { |
| 260 | assert(i < 2 && "setOperand() out of range!"); |
| 261 | Ops[i] = Val; |
| 262 | } |
| 263 | unsigned getNumOperands() const { return 2; } |
| 264 | |
| 265 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 266 | virtual StoreInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 267 | |
| 268 | virtual bool mayWriteToMemory() const { return true; } |
| 269 | |
| 270 | Value *getPointerOperand() { return getOperand(1); } |
| 271 | const Value *getPointerOperand() const { return getOperand(1); } |
| 272 | static unsigned getPointerOperandIndex() { return 1U; } |
| 273 | |
| 274 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 275 | static inline bool classof(const StoreInst *) { return true; } |
| 276 | static inline bool classof(const Instruction *I) { |
| 277 | return I->getOpcode() == Instruction::Store; |
| 278 | } |
| 279 | static inline bool classof(const Value *V) { |
| 280 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 281 | } |
| 282 | }; |
| 283 | |
| 284 | |
| 285 | //===----------------------------------------------------------------------===// |
| 286 | // GetElementPtrInst Class |
| 287 | //===----------------------------------------------------------------------===// |
| 288 | |
| 289 | /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to |
| 290 | /// access elements of arrays and structs |
| 291 | /// |
| 292 | class GetElementPtrInst : public Instruction { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 293 | GetElementPtrInst(const GetElementPtrInst &GEPI) |
| 294 | : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr, |
| 295 | 0, GEPI.getNumOperands()) { |
| 296 | Use *OL = OperandList = new Use[NumOperands]; |
| 297 | Use *GEPIOL = GEPI.OperandList; |
| 298 | for (unsigned i = 0, E = NumOperands; i != E; ++i) |
| 299 | OL[i].init(GEPIOL[i], this); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 300 | } |
| 301 | void init(Value *Ptr, const std::vector<Value*> &Idx); |
| 302 | void init(Value *Ptr, Value *Idx0, Value *Idx1); |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 303 | void init(Value *Ptr, Value *Idx); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 304 | public: |
| 305 | /// Constructors - Create a getelementptr instruction with a base pointer an |
| 306 | /// list of indices. The first ctor can optionally insert before an existing |
| 307 | /// instruction, the second appends the new instruction to the specified |
| 308 | /// BasicBlock. |
| 309 | GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 310 | const std::string &Name = "", Instruction *InsertBefore =0); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 311 | GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 312 | const std::string &Name, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 313 | |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 314 | /// Constructors - These two constructors are convenience methods because one |
| 315 | /// and two index getelementptr instructions are so common. |
| 316 | GetElementPtrInst(Value *Ptr, Value *Idx, |
| 317 | const std::string &Name = "", Instruction *InsertBefore =0); |
| 318 | GetElementPtrInst(Value *Ptr, Value *Idx, |
| 319 | const std::string &Name, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 320 | GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 321 | const std::string &Name = "", Instruction *InsertBefore =0); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 322 | GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 323 | const std::string &Name, BasicBlock *InsertAtEnd); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 324 | ~GetElementPtrInst(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 325 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 326 | virtual GetElementPtrInst *clone() const; |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 327 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 328 | // getType - Overload to return most specific pointer type... |
| 329 | inline const PointerType *getType() const { |
| 330 | return reinterpret_cast<const PointerType*>(Instruction::getType()); |
| 331 | } |
| 332 | |
| 333 | /// getIndexedType - Returns the type of the element that would be loaded with |
| 334 | /// a load instruction with the specified parameters. |
| 335 | /// |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 336 | /// A null type is returned if the indices are invalid for the specified |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 337 | /// pointer type. |
| 338 | /// |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 339 | static const Type *getIndexedType(const Type *Ptr, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 340 | const std::vector<Value*> &Indices, |
| 341 | bool AllowStructLeaf = false); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 342 | static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 343 | bool AllowStructLeaf = false); |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 344 | static const Type *getIndexedType(const Type *Ptr, Value *Idx); |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 345 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 346 | inline op_iterator idx_begin() { return op_begin()+1; } |
| 347 | inline const_op_iterator idx_begin() const { return op_begin()+1; } |
| 348 | inline op_iterator idx_end() { return op_end(); } |
| 349 | inline const_op_iterator idx_end() const { return op_end(); } |
| 350 | |
| 351 | Value *getPointerOperand() { |
| 352 | return getOperand(0); |
| 353 | } |
| 354 | const Value *getPointerOperand() const { |
| 355 | return getOperand(0); |
| 356 | } |
| 357 | static unsigned getPointerOperandIndex() { |
| 358 | return 0U; // get index for modifying correct operand |
| 359 | } |
| 360 | |
| 361 | inline unsigned getNumIndices() const { // Note: always non-negative |
| 362 | return getNumOperands() - 1; |
| 363 | } |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 364 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 365 | inline bool hasIndices() const { |
| 366 | return getNumOperands() > 1; |
| 367 | } |
| 368 | |
| 369 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 370 | static inline bool classof(const GetElementPtrInst *) { return true; } |
| 371 | static inline bool classof(const Instruction *I) { |
| 372 | return (I->getOpcode() == Instruction::GetElementPtr); |
| 373 | } |
| 374 | static inline bool classof(const Value *V) { |
| 375 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 376 | } |
| 377 | }; |
| 378 | |
| 379 | //===----------------------------------------------------------------------===// |
| 380 | // SetCondInst Class |
| 381 | //===----------------------------------------------------------------------===// |
| 382 | |
| 383 | /// SetCondInst class - Represent a setCC operator, where CC is eq, ne, lt, gt, |
| 384 | /// le, or ge. |
| 385 | /// |
| 386 | class SetCondInst : public BinaryOperator { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 387 | public: |
| 388 | SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 389 | const std::string &Name = "", Instruction *InsertBefore = 0); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 390 | SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 391 | const std::string &Name, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 392 | |
| 393 | /// getInverseCondition - Return the inverse of the current condition opcode. |
| 394 | /// For example seteq -> setne, setgt -> setle, setlt -> setge, etc... |
| 395 | /// |
| 396 | BinaryOps getInverseCondition() const { |
| 397 | return getInverseCondition(getOpcode()); |
| 398 | } |
| 399 | |
| 400 | /// getInverseCondition - Static version that you can use without an |
| 401 | /// instruction available. |
| 402 | /// |
| 403 | static BinaryOps getInverseCondition(BinaryOps Opcode); |
| 404 | |
| 405 | /// getSwappedCondition - Return the condition opcode that would be the result |
| 406 | /// of exchanging the two operands of the setcc instruction without changing |
| 407 | /// the result produced. Thus, seteq->seteq, setle->setge, setlt->setgt, etc. |
| 408 | /// |
| 409 | BinaryOps getSwappedCondition() const { |
| 410 | return getSwappedCondition(getOpcode()); |
| 411 | } |
| 412 | |
| 413 | /// getSwappedCondition - Static version that you can use without an |
| 414 | /// instruction available. |
| 415 | /// |
| 416 | static BinaryOps getSwappedCondition(BinaryOps Opcode); |
| 417 | |
| 418 | |
| 419 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 420 | static inline bool classof(const SetCondInst *) { return true; } |
| 421 | static inline bool classof(const Instruction *I) { |
| 422 | return I->getOpcode() == SetEQ || I->getOpcode() == SetNE || |
| 423 | I->getOpcode() == SetLE || I->getOpcode() == SetGE || |
| 424 | I->getOpcode() == SetLT || I->getOpcode() == SetGT; |
| 425 | } |
| 426 | static inline bool classof(const Value *V) { |
| 427 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 428 | } |
| 429 | }; |
| 430 | |
| 431 | //===----------------------------------------------------------------------===// |
| 432 | // CastInst Class |
| 433 | //===----------------------------------------------------------------------===// |
| 434 | |
| 435 | /// CastInst - This class represents a cast from Operand[0] to the type of |
| 436 | /// the instruction (i->getType()). |
| 437 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 438 | class CastInst : public UnaryInstruction { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 439 | CastInst(const CastInst &CI) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 440 | : UnaryInstruction(CI.getType(), Cast, CI.getOperand(0)) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 441 | } |
| 442 | public: |
| 443 | CastInst(Value *S, const Type *Ty, const std::string &Name = "", |
| 444 | Instruction *InsertBefore = 0) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 445 | : UnaryInstruction(Ty, Cast, S, Name, InsertBefore) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 446 | } |
| 447 | CastInst(Value *S, const Type *Ty, const std::string &Name, |
| 448 | BasicBlock *InsertAtEnd) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 449 | : UnaryInstruction(Ty, Cast, S, Name, InsertAtEnd) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 452 | virtual CastInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 453 | |
| 454 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 455 | static inline bool classof(const CastInst *) { return true; } |
| 456 | static inline bool classof(const Instruction *I) { |
| 457 | return I->getOpcode() == Cast; |
| 458 | } |
| 459 | static inline bool classof(const Value *V) { |
| 460 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 461 | } |
| 462 | }; |
| 463 | |
| 464 | |
| 465 | //===----------------------------------------------------------------------===// |
| 466 | // CallInst Class |
| 467 | //===----------------------------------------------------------------------===// |
| 468 | |
| 469 | /// CallInst - This class represents a function call, abstracting a target |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 470 | /// machine's calling convention. This class uses low bit of the SubClassData |
| 471 | /// field to indicate whether or not this is a tail call. The rest of the bits |
| 472 | /// hold the calling convention of the call. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 473 | /// |
| 474 | class CallInst : public Instruction { |
| 475 | CallInst(const CallInst &CI); |
| 476 | void init(Value *Func, const std::vector<Value*> &Params); |
| 477 | void init(Value *Func, Value *Actual1, Value *Actual2); |
| 478 | void init(Value *Func, Value *Actual); |
| 479 | void init(Value *Func); |
| 480 | |
| 481 | public: |
| 482 | CallInst(Value *F, const std::vector<Value*> &Par, |
| 483 | const std::string &Name = "", Instruction *InsertBefore = 0); |
| 484 | CallInst(Value *F, const std::vector<Value*> &Par, |
| 485 | const std::string &Name, BasicBlock *InsertAtEnd); |
| 486 | |
| 487 | // Alternate CallInst ctors w/ two actuals, w/ one actual and no |
| 488 | // actuals, respectively. |
| 489 | CallInst(Value *F, Value *Actual1, Value *Actual2, |
| 490 | const std::string& Name = "", Instruction *InsertBefore = 0); |
| 491 | CallInst(Value *F, Value *Actual1, Value *Actual2, |
| 492 | const std::string& Name, BasicBlock *InsertAtEnd); |
| 493 | CallInst(Value *F, Value *Actual, const std::string& Name = "", |
| 494 | Instruction *InsertBefore = 0); |
| 495 | CallInst(Value *F, Value *Actual, const std::string& Name, |
| 496 | BasicBlock *InsertAtEnd); |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 497 | explicit CallInst(Value *F, const std::string &Name = "", |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 498 | Instruction *InsertBefore = 0); |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 499 | explicit CallInst(Value *F, const std::string &Name, |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 500 | BasicBlock *InsertAtEnd); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 501 | ~CallInst(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 502 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 503 | virtual CallInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 504 | bool mayWriteToMemory() const { return true; } |
| 505 | |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 506 | bool isTailCall() const { return SubclassData & 1; } |
| 507 | void setTailCall(bool isTailCall = true) { |
| 508 | SubclassData = (SubclassData & ~1) | isTailCall; |
| 509 | } |
| 510 | |
| 511 | /// getCallingConv/setCallingConv - Get or set the calling convention of this |
| 512 | /// function call. |
| 513 | unsigned getCallingConv() const { return SubclassData >> 1; } |
| 514 | void setCallingConv(unsigned CC) { |
| 515 | SubclassData = (SubclassData & 1) | (CC << 1); |
| 516 | } |
Chris Lattner | ddb6db4 | 2005-05-06 05:51:46 +0000 | [diff] [blame] | 517 | |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 518 | /// getCalledFunction - Return the function being called by this instruction |
| 519 | /// if it is a direct call. If it is a call through a function pointer, |
| 520 | /// return null. |
| 521 | Function *getCalledFunction() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 522 | return (Function*)dyn_cast<Function>(getOperand(0)); |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 523 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 524 | |
| 525 | // getCalledValue - Get a pointer to a method that is invoked by this inst. |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 526 | inline const Value *getCalledValue() const { return getOperand(0); } |
| 527 | inline Value *getCalledValue() { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 528 | |
| 529 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 530 | static inline bool classof(const CallInst *) { return true; } |
| 531 | static inline bool classof(const Instruction *I) { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 532 | return I->getOpcode() == Instruction::Call; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 533 | } |
| 534 | static inline bool classof(const Value *V) { |
| 535 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 536 | } |
| 537 | }; |
| 538 | |
| 539 | |
| 540 | //===----------------------------------------------------------------------===// |
| 541 | // ShiftInst Class |
| 542 | //===----------------------------------------------------------------------===// |
| 543 | |
| 544 | /// ShiftInst - This class represents left and right shift instructions. |
| 545 | /// |
| 546 | class ShiftInst : public Instruction { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 547 | Use Ops[2]; |
| 548 | ShiftInst(const ShiftInst &SI) |
| 549 | : Instruction(SI.getType(), SI.getOpcode(), Ops, 2) { |
| 550 | Ops[0].init(SI.Ops[0], this); |
| 551 | Ops[1].init(SI.Ops[1], this); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 552 | } |
| 553 | void init(OtherOps Opcode, Value *S, Value *SA) { |
| 554 | assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!"); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 555 | Ops[0].init(S, this); |
| 556 | Ops[1].init(SA, this); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | public: |
| 560 | ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "", |
| 561 | Instruction *InsertBefore = 0) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 562 | : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertBefore) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 563 | init(Opcode, S, SA); |
| 564 | } |
| 565 | ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name, |
| 566 | BasicBlock *InsertAtEnd) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 567 | : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertAtEnd) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 568 | init(Opcode, S, SA); |
| 569 | } |
| 570 | |
| 571 | OtherOps getOpcode() const { |
| 572 | return static_cast<OtherOps>(Instruction::getOpcode()); |
| 573 | } |
| 574 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 575 | /// Transparently provide more efficient getOperand methods. |
| 576 | Value *getOperand(unsigned i) const { |
| 577 | assert(i < 2 && "getOperand() out of range!"); |
| 578 | return Ops[i]; |
| 579 | } |
| 580 | void setOperand(unsigned i, Value *Val) { |
| 581 | assert(i < 2 && "setOperand() out of range!"); |
| 582 | Ops[i] = Val; |
| 583 | } |
| 584 | unsigned getNumOperands() const { return 2; } |
| 585 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 586 | virtual ShiftInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 587 | |
| 588 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 589 | static inline bool classof(const ShiftInst *) { return true; } |
| 590 | static inline bool classof(const Instruction *I) { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 591 | return (I->getOpcode() == Instruction::Shr) | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 592 | (I->getOpcode() == Instruction::Shl); |
| 593 | } |
| 594 | static inline bool classof(const Value *V) { |
| 595 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 596 | } |
| 597 | }; |
| 598 | |
| 599 | //===----------------------------------------------------------------------===// |
| 600 | // SelectInst Class |
| 601 | //===----------------------------------------------------------------------===// |
| 602 | |
| 603 | /// SelectInst - This class represents the LLVM 'select' instruction. |
| 604 | /// |
| 605 | class SelectInst : public Instruction { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 606 | Use Ops[3]; |
| 607 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 608 | void init(Value *C, Value *S1, Value *S2) { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 609 | Ops[0].init(C, this); |
| 610 | Ops[1].init(S1, this); |
| 611 | Ops[2].init(S2, this); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 612 | } |
| 613 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 614 | SelectInst(const SelectInst &SI) |
| 615 | : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) { |
| 616 | init(SI.Ops[0], SI.Ops[1], SI.Ops[2]); |
| 617 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 618 | public: |
| 619 | SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "", |
| 620 | Instruction *InsertBefore = 0) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 621 | : Instruction(S1->getType(), Instruction::Select, Ops, 3, |
| 622 | Name, InsertBefore) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 623 | init(C, S1, S2); |
| 624 | } |
| 625 | SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name, |
| 626 | BasicBlock *InsertAtEnd) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 627 | : Instruction(S1->getType(), Instruction::Select, Ops, 3, |
| 628 | Name, InsertAtEnd) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 629 | init(C, S1, S2); |
| 630 | } |
| 631 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 632 | Value *getCondition() const { return Ops[0]; } |
| 633 | Value *getTrueValue() const { return Ops[1]; } |
| 634 | Value *getFalseValue() const { return Ops[2]; } |
| 635 | |
| 636 | /// Transparently provide more efficient getOperand methods. |
| 637 | Value *getOperand(unsigned i) const { |
| 638 | assert(i < 3 && "getOperand() out of range!"); |
| 639 | return Ops[i]; |
| 640 | } |
| 641 | void setOperand(unsigned i, Value *Val) { |
| 642 | assert(i < 3 && "setOperand() out of range!"); |
| 643 | Ops[i] = Val; |
| 644 | } |
| 645 | unsigned getNumOperands() const { return 3; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 646 | |
| 647 | OtherOps getOpcode() const { |
| 648 | return static_cast<OtherOps>(Instruction::getOpcode()); |
| 649 | } |
| 650 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 651 | virtual SelectInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 652 | |
| 653 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 654 | static inline bool classof(const SelectInst *) { return true; } |
| 655 | static inline bool classof(const Instruction *I) { |
| 656 | return I->getOpcode() == Instruction::Select; |
| 657 | } |
| 658 | static inline bool classof(const Value *V) { |
| 659 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 660 | } |
| 661 | }; |
| 662 | |
| 663 | |
| 664 | //===----------------------------------------------------------------------===// |
| 665 | // VANextInst Class |
| 666 | //===----------------------------------------------------------------------===// |
| 667 | |
| 668 | /// VANextInst - This class represents the va_next llvm instruction, which |
| 669 | /// advances a vararg list passed an argument of the specified type, returning |
| 670 | /// the resultant list. |
| 671 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 672 | class VANextInst : public UnaryInstruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 673 | PATypeHolder ArgTy; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 674 | VANextInst(const VANextInst &VAN) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 675 | : UnaryInstruction(VAN.getType(), VANext, VAN.getOperand(0)), |
| 676 | ArgTy(VAN.getArgType()) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | public: |
| 680 | VANextInst(Value *List, const Type *Ty, const std::string &Name = "", |
| 681 | Instruction *InsertBefore = 0) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 682 | : UnaryInstruction(List->getType(), VANext, List, Name, InsertBefore), |
| 683 | ArgTy(Ty) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 684 | } |
| 685 | VANextInst(Value *List, const Type *Ty, const std::string &Name, |
| 686 | BasicBlock *InsertAtEnd) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 687 | : UnaryInstruction(List->getType(), VANext, List, Name, InsertAtEnd), |
| 688 | ArgTy(Ty) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | const Type *getArgType() const { return ArgTy; } |
| 692 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 693 | virtual VANextInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 694 | |
| 695 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 696 | static inline bool classof(const VANextInst *) { return true; } |
| 697 | static inline bool classof(const Instruction *I) { |
| 698 | return I->getOpcode() == VANext; |
| 699 | } |
| 700 | static inline bool classof(const Value *V) { |
| 701 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 702 | } |
| 703 | }; |
| 704 | |
| 705 | |
| 706 | //===----------------------------------------------------------------------===// |
| 707 | // VAArgInst Class |
| 708 | //===----------------------------------------------------------------------===// |
| 709 | |
| 710 | /// VAArgInst - This class represents the va_arg llvm instruction, which returns |
| 711 | /// an argument of the specified type given a va_list. |
| 712 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 713 | class VAArgInst : public UnaryInstruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 714 | VAArgInst(const VAArgInst &VAA) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 715 | : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {} |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 716 | public: |
| 717 | VAArgInst(Value *List, const Type *Ty, const std::string &Name = "", |
| 718 | Instruction *InsertBefore = 0) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 719 | : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 720 | } |
| 721 | VAArgInst(Value *List, const Type *Ty, const std::string &Name, |
| 722 | BasicBlock *InsertAtEnd) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 723 | : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 726 | virtual VAArgInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 727 | |
| 728 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 729 | static inline bool classof(const VAArgInst *) { return true; } |
| 730 | static inline bool classof(const Instruction *I) { |
| 731 | return I->getOpcode() == VAArg; |
| 732 | } |
| 733 | static inline bool classof(const Value *V) { |
| 734 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 735 | } |
| 736 | }; |
| 737 | |
| 738 | //===----------------------------------------------------------------------===// |
| 739 | // PHINode Class |
| 740 | //===----------------------------------------------------------------------===// |
| 741 | |
| 742 | // PHINode - The PHINode class is used to represent the magical mystical PHI |
| 743 | // node, that can not exist in nature, but can be synthesized in a computer |
| 744 | // scientist's overactive imagination. |
| 745 | // |
| 746 | class PHINode : public Instruction { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 747 | /// ReservedSpace - The number of operands actually allocated. NumOperands is |
| 748 | /// the number actually in use. |
| 749 | unsigned ReservedSpace; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 750 | PHINode(const PHINode &PN); |
| 751 | public: |
| 752 | PHINode(const Type *Ty, const std::string &Name = "", |
| 753 | Instruction *InsertBefore = 0) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 754 | : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore), |
| 755 | ReservedSpace(0) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 759 | : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd), |
| 760 | ReservedSpace(0) { |
| 761 | } |
| 762 | |
| 763 | ~PHINode(); |
| 764 | |
| 765 | /// reserveOperandSpace - This method can be used to avoid repeated |
| 766 | /// reallocation of PHI operand lists by reserving space for the correct |
| 767 | /// number of operands before adding them. Unlike normal vector reserves, |
| 768 | /// this method can also be used to trim the operand space. |
| 769 | void reserveOperandSpace(unsigned NumValues) { |
| 770 | resizeOperands(NumValues*2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 771 | } |
| 772 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 773 | virtual PHINode *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 774 | |
| 775 | /// getNumIncomingValues - Return the number of incoming edges |
| 776 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 777 | unsigned getNumIncomingValues() const { return getNumOperands()/2; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 778 | |
| 779 | /// getIncomingValue - Return incoming value #x |
| 780 | /// |
| 781 | Value *getIncomingValue(unsigned i) const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 782 | assert(i*2 < getNumOperands() && "Invalid value number!"); |
| 783 | return getOperand(i*2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 784 | } |
| 785 | void setIncomingValue(unsigned i, Value *V) { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 786 | assert(i*2 < getNumOperands() && "Invalid value number!"); |
| 787 | setOperand(i*2, V); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 788 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 789 | unsigned getOperandNumForIncomingValue(unsigned i) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 790 | return i*2; |
| 791 | } |
| 792 | |
| 793 | /// getIncomingBlock - Return incoming basic block #x |
| 794 | /// |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 795 | BasicBlock *getIncomingBlock(unsigned i) const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 796 | return reinterpret_cast<BasicBlock*>(getOperand(i*2+1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 797 | } |
| 798 | void setIncomingBlock(unsigned i, BasicBlock *BB) { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 799 | setOperand(i*2+1, reinterpret_cast<Value*>(BB)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 800 | } |
| 801 | unsigned getOperandNumForIncomingBlock(unsigned i) { |
| 802 | return i*2+1; |
| 803 | } |
| 804 | |
| 805 | /// addIncoming - Add an incoming value to the end of the PHI list |
| 806 | /// |
| 807 | void addIncoming(Value *V, BasicBlock *BB) { |
| 808 | assert(getType() == V->getType() && |
| 809 | "All operands to PHI node must be the same type as the PHI node!"); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 810 | unsigned OpNo = NumOperands; |
| 811 | if (OpNo+2 > ReservedSpace) |
| 812 | resizeOperands(0); // Get more space! |
| 813 | // Initialize some new operands. |
| 814 | NumOperands = OpNo+2; |
| 815 | OperandList[OpNo].init(V, this); |
| 816 | OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 817 | } |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 818 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 819 | /// removeIncomingValue - Remove an incoming value. This is useful if a |
| 820 | /// predecessor basic block is deleted. The value removed is returned. |
| 821 | /// |
| 822 | /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty |
| 823 | /// is true), the PHI node is destroyed and any uses of it are replaced with |
| 824 | /// dummy values. The only time there should be zero incoming values to a PHI |
| 825 | /// node is when the block is dead, so this strategy is sound. |
| 826 | /// |
| 827 | Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true); |
| 828 | |
| 829 | Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){ |
| 830 | int Idx = getBasicBlockIndex(BB); |
| 831 | assert(Idx >= 0 && "Invalid basic block argument to remove!"); |
| 832 | return removeIncomingValue(Idx, DeletePHIIfEmpty); |
| 833 | } |
| 834 | |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 835 | /// getBasicBlockIndex - Return the first index of the specified basic |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 836 | /// block in the value list for this PHI. Returns -1 if no instance. |
| 837 | /// |
| 838 | int getBasicBlockIndex(const BasicBlock *BB) const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 839 | Use *OL = OperandList; |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 840 | for (unsigned i = 0, e = getNumOperands(); i != e; i += 2) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 841 | if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 842 | return -1; |
| 843 | } |
| 844 | |
| 845 | Value *getIncomingValueForBlock(const BasicBlock *BB) const { |
| 846 | return getIncomingValue(getBasicBlockIndex(BB)); |
| 847 | } |
| 848 | |
| 849 | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
| 850 | static inline bool classof(const PHINode *) { return true; } |
| 851 | static inline bool classof(const Instruction *I) { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 852 | return I->getOpcode() == Instruction::PHI; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 853 | } |
| 854 | static inline bool classof(const Value *V) { |
| 855 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 856 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 857 | private: |
| 858 | void resizeOperands(unsigned NumOperands); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 859 | }; |
| 860 | |
| 861 | //===----------------------------------------------------------------------===// |
| 862 | // ReturnInst Class |
| 863 | //===----------------------------------------------------------------------===// |
| 864 | |
| 865 | //===--------------------------------------------------------------------------- |
| 866 | /// ReturnInst - Return a value (possibly void), from a function. Execution |
| 867 | /// does not continue in this function any longer. |
| 868 | /// |
| 869 | class ReturnInst : public TerminatorInst { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 870 | Use RetVal; // Possibly null retval. |
| 871 | ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal, |
| 872 | RI.getNumOperands()) { |
| 873 | if (RI.getNumOperands()) |
| 874 | RetVal.init(RI.RetVal, this); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Alkis Evlogimenos | 859804f | 2004-11-17 21:02:25 +0000 | [diff] [blame] | 877 | void init(Value *RetVal); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 878 | |
| 879 | public: |
| 880 | // ReturnInst constructors: |
| 881 | // ReturnInst() - 'ret void' instruction |
Alkis Evlogimenos | 859804f | 2004-11-17 21:02:25 +0000 | [diff] [blame] | 882 | // ReturnInst( null) - 'ret void' instruction |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 883 | // ReturnInst(Value* X) - 'ret X' instruction |
| 884 | // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I |
| 885 | // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I |
| 886 | // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB |
| 887 | // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB |
Alkis Evlogimenos | 859804f | 2004-11-17 21:02:25 +0000 | [diff] [blame] | 888 | // |
| 889 | // NOTE: If the Value* passed is of type void then the constructor behaves as |
| 890 | // if it was passed NULL. |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 891 | ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0) |
| 892 | : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) { |
| 893 | init(retVal); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 894 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 895 | ReturnInst(Value *retVal, BasicBlock *InsertAtEnd) |
| 896 | : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) { |
| 897 | init(retVal); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 898 | } |
| 899 | ReturnInst(BasicBlock *InsertAtEnd) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 900 | : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 901 | } |
| 902 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 903 | virtual ReturnInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 904 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 905 | // Transparently provide more efficient getOperand methods. |
| 906 | Value *getOperand(unsigned i) const { |
| 907 | assert(i < getNumOperands() && "getOperand() out of range!"); |
| 908 | return RetVal; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 909 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 910 | void setOperand(unsigned i, Value *Val) { |
| 911 | assert(i < getNumOperands() && "setOperand() out of range!"); |
| 912 | RetVal = Val; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 915 | Value *getReturnValue() const { return RetVal; } |
| 916 | |
| 917 | unsigned getNumSuccessors() const { return 0; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 918 | |
| 919 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 920 | static inline bool classof(const ReturnInst *) { return true; } |
| 921 | static inline bool classof(const Instruction *I) { |
| 922 | return (I->getOpcode() == Instruction::Ret); |
| 923 | } |
| 924 | static inline bool classof(const Value *V) { |
| 925 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 926 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 927 | private: |
| 928 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 929 | virtual unsigned getNumSuccessorsV() const; |
| 930 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 931 | }; |
| 932 | |
| 933 | //===----------------------------------------------------------------------===// |
| 934 | // BranchInst Class |
| 935 | //===----------------------------------------------------------------------===// |
| 936 | |
| 937 | //===--------------------------------------------------------------------------- |
| 938 | /// BranchInst - Conditional or Unconditional Branch instruction. |
| 939 | /// |
| 940 | class BranchInst : public TerminatorInst { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 941 | /// Ops list - Branches are strange. The operands are ordered: |
| 942 | /// TrueDest, FalseDest, Cond. This makes some accessors faster because |
| 943 | /// they don't have to check for cond/uncond branchness. |
| 944 | Use Ops[3]; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 945 | BranchInst(const BranchInst &BI); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 946 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 947 | public: |
| 948 | // BranchInst constructors (where {B, T, F} are blocks, and C is a condition): |
| 949 | // BranchInst(BB *B) - 'br B' |
| 950 | // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F' |
| 951 | // BranchInst(BB* B, Inst *I) - 'br B' insert before I |
| 952 | // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I |
| 953 | // BranchInst(BB* B, BB *I) - 'br B' insert at end |
| 954 | // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end |
| 955 | BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 956 | : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) { |
| 957 | assert(IfTrue != 0 && "Branch destination may not be null!"); |
| 958 | Ops[0].init(reinterpret_cast<Value*>(IfTrue), this); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 959 | } |
| 960 | BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
| 961 | Instruction *InsertBefore = 0) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 962 | : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) { |
| 963 | Ops[0].init(reinterpret_cast<Value*>(IfTrue), this); |
| 964 | Ops[1].init(reinterpret_cast<Value*>(IfFalse), this); |
| 965 | Ops[2].init(Cond, this); |
| 966 | #ifndef NDEBUG |
| 967 | AssertOK(); |
| 968 | #endif |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 972 | : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) { |
| 973 | assert(IfTrue != 0 && "Branch destination may not be null!"); |
| 974 | Ops[0].init(reinterpret_cast<Value*>(IfTrue), this); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
| 978 | BasicBlock *InsertAtEnd) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 979 | : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) { |
| 980 | Ops[0].init(reinterpret_cast<Value*>(IfTrue), this); |
| 981 | Ops[1].init(reinterpret_cast<Value*>(IfFalse), this); |
| 982 | Ops[2].init(Cond, this); |
| 983 | #ifndef NDEBUG |
| 984 | AssertOK(); |
| 985 | #endif |
| 986 | } |
| 987 | |
| 988 | |
| 989 | /// Transparently provide more efficient getOperand methods. |
| 990 | Value *getOperand(unsigned i) const { |
| 991 | assert(i < getNumOperands() && "getOperand() out of range!"); |
| 992 | return Ops[i]; |
| 993 | } |
| 994 | void setOperand(unsigned i, Value *Val) { |
| 995 | assert(i < getNumOperands() && "setOperand() out of range!"); |
| 996 | Ops[i] = Val; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 997 | } |
| 998 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 999 | virtual BranchInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1000 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1001 | inline bool isUnconditional() const { return getNumOperands() == 1; } |
| 1002 | inline bool isConditional() const { return getNumOperands() == 3; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1003 | |
| 1004 | inline Value *getCondition() const { |
| 1005 | assert(isConditional() && "Cannot get condition of an uncond branch!"); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1006 | return getOperand(2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | void setCondition(Value *V) { |
| 1010 | assert(isConditional() && "Cannot set condition of unconditional branch!"); |
| 1011 | setOperand(2, V); |
| 1012 | } |
| 1013 | |
| 1014 | // setUnconditionalDest - Change the current branch to an unconditional branch |
| 1015 | // targeting the specified block. |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1016 | // FIXME: Eliminate this ugly method. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1017 | void setUnconditionalDest(BasicBlock *Dest) { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1018 | if (isConditional()) { // Convert this to an uncond branch. |
| 1019 | NumOperands = 1; |
| 1020 | Ops[1].set(0); |
| 1021 | Ops[2].set(0); |
| 1022 | } |
| 1023 | setOperand(0, reinterpret_cast<Value*>(Dest)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1026 | unsigned getNumSuccessors() const { return 1+isConditional(); } |
| 1027 | |
| 1028 | BasicBlock *getSuccessor(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1029 | assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1030 | return (i == 0) ? cast<BasicBlock>(getOperand(0)) : |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1031 | cast<BasicBlock>(getOperand(1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1034 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1035 | assert(idx < getNumSuccessors() && "Successor # out of range for Branch!"); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1036 | setOperand(idx, reinterpret_cast<Value*>(NewSucc)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1039 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1040 | static inline bool classof(const BranchInst *) { return true; } |
| 1041 | static inline bool classof(const Instruction *I) { |
| 1042 | return (I->getOpcode() == Instruction::Br); |
| 1043 | } |
| 1044 | static inline bool classof(const Value *V) { |
| 1045 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1046 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1047 | private: |
| 1048 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 1049 | virtual unsigned getNumSuccessorsV() const; |
| 1050 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1051 | }; |
| 1052 | |
| 1053 | //===----------------------------------------------------------------------===// |
| 1054 | // SwitchInst Class |
| 1055 | //===----------------------------------------------------------------------===// |
| 1056 | |
| 1057 | //===--------------------------------------------------------------------------- |
| 1058 | /// SwitchInst - Multiway switch |
| 1059 | /// |
| 1060 | class SwitchInst : public TerminatorInst { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1061 | unsigned ReservedSpace; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1062 | // Operand[0] = Value to switch on |
| 1063 | // Operand[1] = Default basic block destination |
| 1064 | // Operand[2n ] = Value to match |
| 1065 | // Operand[2n+1] = BasicBlock to go to on match |
| 1066 | SwitchInst(const SwitchInst &RI); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1067 | void init(Value *Value, BasicBlock *Default, unsigned NumCases); |
| 1068 | void resizeOperands(unsigned No); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1069 | public: |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1070 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to |
| 1071 | /// switch on and a default destination. The number of additional cases can |
| 1072 | /// be specified here to make memory allocation more efficient. This |
| 1073 | /// constructor can also autoinsert before another instruction. |
| 1074 | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1075 | Instruction *InsertBefore = 0) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1076 | : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) { |
| 1077 | init(Value, Default, NumCases); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1080 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to |
| 1081 | /// switch on and a default destination. The number of additional cases can |
| 1082 | /// be specified here to make memory allocation more efficient. This |
| 1083 | /// constructor also autoinserts at the end of the specified BasicBlock. |
| 1084 | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1085 | BasicBlock *InsertAtEnd) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1086 | : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) { |
| 1087 | init(Value, Default, NumCases); |
| 1088 | } |
| 1089 | ~SwitchInst(); |
| 1090 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1091 | |
| 1092 | // Accessor Methods for Switch stmt |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1093 | inline Value *getCondition() const { return getOperand(0); } |
| 1094 | void setCondition(Value *V) { setOperand(0, V); } |
Chris Lattner | bfaf88a | 2004-12-10 20:35:47 +0000 | [diff] [blame] | 1095 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1096 | inline BasicBlock *getDefaultDest() const { |
| 1097 | return cast<BasicBlock>(getOperand(1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | /// getNumCases - return the number of 'cases' in this switch instruction. |
| 1101 | /// Note that case #0 is always the default case. |
| 1102 | unsigned getNumCases() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1103 | return getNumOperands()/2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | /// getCaseValue - Return the specified case value. Note that case #0, the |
| 1107 | /// default destination, does not have a case value. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 1108 | ConstantInt *getCaseValue(unsigned i) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1109 | assert(i && i < getNumCases() && "Illegal case value to get!"); |
| 1110 | return getSuccessorValue(i); |
| 1111 | } |
| 1112 | |
| 1113 | /// getCaseValue - Return the specified case value. Note that case #0, the |
| 1114 | /// default destination, does not have a case value. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 1115 | const ConstantInt *getCaseValue(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1116 | assert(i && i < getNumCases() && "Illegal case value to get!"); |
| 1117 | return getSuccessorValue(i); |
| 1118 | } |
| 1119 | |
| 1120 | /// findCaseValue - Search all of the case values for the specified constant. |
| 1121 | /// If it is explicitly handled, return the case number of it, otherwise |
| 1122 | /// return 0 to indicate that it is handled by the default handler. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 1123 | unsigned findCaseValue(const ConstantInt *C) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1124 | for (unsigned i = 1, e = getNumCases(); i != e; ++i) |
| 1125 | if (getCaseValue(i) == C) |
| 1126 | return i; |
| 1127 | return 0; |
| 1128 | } |
| 1129 | |
| 1130 | /// addCase - Add an entry to the switch instruction... |
| 1131 | /// |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 1132 | void addCase(ConstantInt *OnVal, BasicBlock *Dest); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1133 | |
| 1134 | /// removeCase - This method removes the specified successor from the switch |
| 1135 | /// instruction. Note that this cannot be used to remove the default |
| 1136 | /// destination (successor #0). |
| 1137 | /// |
| 1138 | void removeCase(unsigned idx); |
| 1139 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1140 | virtual SwitchInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1141 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1142 | unsigned getNumSuccessors() const { return getNumOperands()/2; } |
| 1143 | BasicBlock *getSuccessor(unsigned idx) const { |
| 1144 | assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!"); |
| 1145 | return cast<BasicBlock>(getOperand(idx*2+1)); |
| 1146 | } |
| 1147 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1148 | assert(idx < getNumSuccessors() && "Successor # out of range for switch!"); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1149 | setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | // getSuccessorValue - Return the value associated with the specified |
| 1153 | // successor. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 1154 | inline ConstantInt *getSuccessorValue(unsigned idx) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1155 | assert(idx < getNumSuccessors() && "Successor # out of range!"); |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 1156 | return (ConstantInt*)getOperand(idx*2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1157 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1158 | |
| 1159 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1160 | static inline bool classof(const SwitchInst *) { return true; } |
| 1161 | static inline bool classof(const Instruction *I) { |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 1162 | return I->getOpcode() == Instruction::Switch; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1163 | } |
| 1164 | static inline bool classof(const Value *V) { |
| 1165 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1166 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1167 | private: |
| 1168 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 1169 | virtual unsigned getNumSuccessorsV() const; |
| 1170 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1171 | }; |
| 1172 | |
| 1173 | //===----------------------------------------------------------------------===// |
| 1174 | // InvokeInst Class |
| 1175 | //===----------------------------------------------------------------------===// |
| 1176 | |
| 1177 | //===--------------------------------------------------------------------------- |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 1178 | |
| 1179 | /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the |
| 1180 | /// calling convention of the call. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1181 | /// |
| 1182 | class InvokeInst : public TerminatorInst { |
| 1183 | InvokeInst(const InvokeInst &BI); |
| 1184 | void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, |
| 1185 | const std::vector<Value*> &Params); |
| 1186 | public: |
| 1187 | InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 1188 | const std::vector<Value*> &Params, const std::string &Name = "", |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1189 | Instruction *InsertBefore = 0); |
| 1190 | InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 1191 | const std::vector<Value*> &Params, const std::string &Name, |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1192 | BasicBlock *InsertAtEnd); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1193 | ~InvokeInst(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1194 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1195 | virtual InvokeInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1196 | |
| 1197 | bool mayWriteToMemory() const { return true; } |
| 1198 | |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 1199 | /// getCallingConv/setCallingConv - Get or set the calling convention of this |
| 1200 | /// function call. |
| 1201 | unsigned getCallingConv() const { return SubclassData; } |
| 1202 | void setCallingConv(unsigned CC) { |
| 1203 | SubclassData = CC; |
| 1204 | } |
| 1205 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1206 | /// getCalledFunction - Return the function called, or null if this is an |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 1207 | /// indirect function invocation. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1208 | /// |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 1209 | Function *getCalledFunction() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1210 | return dyn_cast<Function>(getOperand(0)); |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 1211 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1212 | |
| 1213 | // getCalledValue - Get a pointer to a function that is invoked by this inst. |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1214 | inline Value *getCalledValue() const { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1215 | |
| 1216 | // get*Dest - Return the destination basic blocks... |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1217 | BasicBlock *getNormalDest() const { |
| 1218 | return cast<BasicBlock>(getOperand(1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1219 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1220 | BasicBlock *getUnwindDest() const { |
| 1221 | return cast<BasicBlock>(getOperand(2)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1222 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1223 | void setNormalDest(BasicBlock *B) { |
| 1224 | setOperand(1, reinterpret_cast<Value*>(B)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1227 | void setUnwindDest(BasicBlock *B) { |
| 1228 | setOperand(2, reinterpret_cast<Value*>(B)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1231 | inline BasicBlock *getSuccessor(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1232 | assert(i < 2 && "Successor # out of range for invoke!"); |
| 1233 | return i == 0 ? getNormalDest() : getUnwindDest(); |
| 1234 | } |
| 1235 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1236 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1237 | assert(idx < 2 && "Successor # out of range for invoke!"); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1238 | setOperand(idx+1, reinterpret_cast<Value*>(NewSucc)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1241 | unsigned getNumSuccessors() const { return 2; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1242 | |
| 1243 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1244 | static inline bool classof(const InvokeInst *) { return true; } |
| 1245 | static inline bool classof(const Instruction *I) { |
| 1246 | return (I->getOpcode() == Instruction::Invoke); |
| 1247 | } |
| 1248 | static inline bool classof(const Value *V) { |
| 1249 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1250 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1251 | private: |
| 1252 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 1253 | virtual unsigned getNumSuccessorsV() const; |
| 1254 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1255 | }; |
| 1256 | |
| 1257 | |
| 1258 | //===----------------------------------------------------------------------===// |
| 1259 | // UnwindInst Class |
| 1260 | //===----------------------------------------------------------------------===// |
| 1261 | |
| 1262 | //===--------------------------------------------------------------------------- |
| 1263 | /// UnwindInst - Immediately exit the current function, unwinding the stack |
| 1264 | /// until an invoke instruction is found. |
| 1265 | /// |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 1266 | class UnwindInst : public TerminatorInst { |
| 1267 | public: |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1268 | UnwindInst(Instruction *InsertBefore = 0) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1269 | : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1270 | } |
| 1271 | UnwindInst(BasicBlock *InsertAtEnd) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1272 | : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1275 | virtual UnwindInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1276 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1277 | unsigned getNumSuccessors() const { return 0; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1278 | |
| 1279 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1280 | static inline bool classof(const UnwindInst *) { return true; } |
| 1281 | static inline bool classof(const Instruction *I) { |
| 1282 | return I->getOpcode() == Instruction::Unwind; |
| 1283 | } |
| 1284 | static inline bool classof(const Value *V) { |
| 1285 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1286 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1287 | private: |
| 1288 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 1289 | virtual unsigned getNumSuccessorsV() const; |
| 1290 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1291 | }; |
| 1292 | |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 1293 | //===----------------------------------------------------------------------===// |
| 1294 | // UnreachableInst Class |
| 1295 | //===----------------------------------------------------------------------===// |
| 1296 | |
| 1297 | //===--------------------------------------------------------------------------- |
| 1298 | /// UnreachableInst - This function has undefined behavior. In particular, the |
| 1299 | /// presence of this instruction indicates some higher level knowledge that the |
| 1300 | /// end of the block cannot be reached. |
| 1301 | /// |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 1302 | class UnreachableInst : public TerminatorInst { |
| 1303 | public: |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 1304 | UnreachableInst(Instruction *InsertBefore = 0) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1305 | : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) { |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 1306 | } |
| 1307 | UnreachableInst(BasicBlock *InsertAtEnd) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1308 | : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) { |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | virtual UnreachableInst *clone() const; |
| 1312 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1313 | unsigned getNumSuccessors() const { return 0; } |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 1314 | |
| 1315 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1316 | static inline bool classof(const UnreachableInst *) { return true; } |
| 1317 | static inline bool classof(const Instruction *I) { |
| 1318 | return I->getOpcode() == Instruction::Unreachable; |
| 1319 | } |
| 1320 | static inline bool classof(const Value *V) { |
| 1321 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1322 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1323 | private: |
| 1324 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 1325 | virtual unsigned getNumSuccessorsV() const; |
| 1326 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 1327 | }; |
| 1328 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1329 | } // End llvm namespace |
Chris Lattner | a892a3a | 2003-01-27 22:08:52 +0000 | [diff] [blame] | 1330 | |
| 1331 | #endif |