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