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