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