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