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