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