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 | // |
Chris Lattner | 7ed47a1 | 2007-12-29 19:59:42 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // 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 | |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 19 | #include <iterator> |
| 20 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 21 | #include "llvm/InstrTypes.h" |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 22 | #include "llvm/DerivedTypes.h" |
Dale Johannesen | 0d51e7e | 2008-02-19 21:38:47 +0000 | [diff] [blame] | 23 | #include "llvm/ParameterAttributes.h" |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 24 | #include "llvm/BasicBlock.h" |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 25 | |
| 26 | namespace llvm { |
| 27 | |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 28 | class ConstantInt; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 29 | class PointerType; |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 30 | class VectorType; |
Reid Spencer | 3da4384 | 2007-02-28 22:00:54 +0000 | [diff] [blame] | 31 | class ConstantRange; |
| 32 | class APInt; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 33 | |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | // AllocationInst Class |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
| 38 | /// AllocationInst - This class is the common base class of MallocInst and |
| 39 | /// AllocaInst. |
| 40 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 41 | class AllocationInst : public UnaryInstruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 42 | protected: |
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 = "", Instruction *InsertBefore = 0); |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 45 | AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 46 | const std::string &Name, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 47 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 48 | // Out of line virtual method, so the vtable, etc. has a home. |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 49 | virtual ~AllocationInst(); |
| 50 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 51 | /// isArrayAllocation - Return true if there is an allocation size parameter |
| 52 | /// to the allocation instruction that is not 1. |
| 53 | /// |
| 54 | bool isArrayAllocation() const; |
| 55 | |
| 56 | /// getArraySize - Get the number of element allocated, for a simple |
| 57 | /// allocation of a single element, this will return a constant 1 value. |
| 58 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 59 | const Value *getArraySize() const { return getOperand(0); } |
| 60 | Value *getArraySize() { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 61 | |
| 62 | /// getType - Overload to return most specific pointer type |
| 63 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 64 | const PointerType *getType() const { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 65 | return reinterpret_cast<const PointerType*>(Instruction::getType()); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /// getAllocatedType - Return the type that is being allocated by the |
| 69 | /// instruction. |
| 70 | /// |
| 71 | const Type *getAllocatedType() const; |
| 72 | |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 73 | /// getAlignment - Return the alignment of the memory that is being allocated |
| 74 | /// by the instruction. |
| 75 | /// |
Dan Gohman | 5283707 | 2008-03-24 16:55:58 +0000 | [diff] [blame] | 76 | unsigned getAlignment() const { return (1u << SubclassData) >> 1; } |
| 77 | void setAlignment(unsigned Align); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 78 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 79 | virtual Instruction *clone() const = 0; |
| 80 | |
| 81 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 82 | static inline bool classof(const AllocationInst *) { return true; } |
| 83 | static inline bool classof(const Instruction *I) { |
| 84 | return I->getOpcode() == Instruction::Alloca || |
| 85 | I->getOpcode() == Instruction::Malloc; |
| 86 | } |
| 87 | static inline bool classof(const Value *V) { |
| 88 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | |
| 93 | //===----------------------------------------------------------------------===// |
| 94 | // MallocInst Class |
| 95 | //===----------------------------------------------------------------------===// |
| 96 | |
| 97 | /// MallocInst - an instruction to allocated memory on the heap |
| 98 | /// |
| 99 | class MallocInst : public AllocationInst { |
| 100 | MallocInst(const MallocInst &MI); |
| 101 | public: |
| 102 | explicit MallocInst(const Type *Ty, Value *ArraySize = 0, |
| 103 | const std::string &Name = "", |
| 104 | Instruction *InsertBefore = 0) |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 105 | : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {} |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 106 | MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name, |
| 107 | BasicBlock *InsertAtEnd) |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 108 | : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {} |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 109 | |
| 110 | MallocInst(const Type *Ty, const std::string &Name, |
| 111 | Instruction *InsertBefore = 0) |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 112 | : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {} |
| 113 | MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
| 114 | : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {} |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 115 | |
| 116 | MallocInst(const Type *Ty, Value *ArraySize, unsigned Align, |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 117 | const std::string &Name, BasicBlock *InsertAtEnd) |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 118 | : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {} |
| 119 | MallocInst(const Type *Ty, Value *ArraySize, unsigned Align, |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 120 | const std::string &Name = "", |
| 121 | Instruction *InsertBefore = 0) |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 122 | : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {} |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 123 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 124 | virtual MallocInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 125 | |
| 126 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 127 | static inline bool classof(const MallocInst *) { return true; } |
| 128 | static inline bool classof(const Instruction *I) { |
| 129 | return (I->getOpcode() == Instruction::Malloc); |
| 130 | } |
| 131 | static inline bool classof(const Value *V) { |
| 132 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | |
| 137 | //===----------------------------------------------------------------------===// |
| 138 | // AllocaInst Class |
| 139 | //===----------------------------------------------------------------------===// |
| 140 | |
| 141 | /// AllocaInst - an instruction to allocate memory on the stack |
| 142 | /// |
| 143 | class AllocaInst : public AllocationInst { |
| 144 | AllocaInst(const AllocaInst &); |
| 145 | public: |
| 146 | explicit AllocaInst(const Type *Ty, Value *ArraySize = 0, |
| 147 | const std::string &Name = "", |
| 148 | Instruction *InsertBefore = 0) |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 149 | : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {} |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 150 | AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name, |
| 151 | BasicBlock *InsertAtEnd) |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 152 | : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {} |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 153 | |
| 154 | AllocaInst(const Type *Ty, const std::string &Name, |
| 155 | Instruction *InsertBefore = 0) |
| 156 | : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {} |
| 157 | AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
| 158 | : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {} |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 159 | |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 160 | AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align, |
| 161 | const std::string &Name = "", Instruction *InsertBefore = 0) |
| 162 | : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {} |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 163 | AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align, |
| 164 | const std::string &Name, BasicBlock *InsertAtEnd) |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 165 | : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {} |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 166 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 167 | virtual AllocaInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 168 | |
| 169 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 170 | static inline bool classof(const AllocaInst *) { return true; } |
| 171 | static inline bool classof(const Instruction *I) { |
| 172 | return (I->getOpcode() == Instruction::Alloca); |
| 173 | } |
| 174 | static inline bool classof(const Value *V) { |
| 175 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 176 | } |
| 177 | }; |
| 178 | |
| 179 | |
| 180 | //===----------------------------------------------------------------------===// |
| 181 | // FreeInst Class |
| 182 | //===----------------------------------------------------------------------===// |
| 183 | |
| 184 | /// FreeInst - an instruction to deallocate memory |
| 185 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 186 | class FreeInst : public UnaryInstruction { |
| 187 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 188 | public: |
| 189 | explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0); |
| 190 | FreeInst(Value *Ptr, BasicBlock *InsertAfter); |
| 191 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 192 | virtual FreeInst *clone() const; |
Owen Anderson | c9edf0b | 2007-07-06 23:13:31 +0000 | [diff] [blame] | 193 | |
| 194 | // Accessor methods for consistency with other memory operations |
| 195 | Value *getPointerOperand() { return getOperand(0); } |
| 196 | const Value *getPointerOperand() const { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 197 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 198 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 199 | static inline bool classof(const FreeInst *) { return true; } |
| 200 | static inline bool classof(const Instruction *I) { |
| 201 | return (I->getOpcode() == Instruction::Free); |
| 202 | } |
| 203 | static inline bool classof(const Value *V) { |
| 204 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 205 | } |
| 206 | }; |
| 207 | |
| 208 | |
| 209 | //===----------------------------------------------------------------------===// |
| 210 | // LoadInst Class |
| 211 | //===----------------------------------------------------------------------===// |
| 212 | |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 213 | /// LoadInst - an instruction for reading from memory. This uses the |
| 214 | /// 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] | 215 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 216 | class LoadInst : public UnaryInstruction { |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 217 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 218 | LoadInst(const LoadInst &LI) |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 219 | : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) { |
| 220 | setVolatile(LI.isVolatile()); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 221 | setAlignment(LI.getAlignment()); |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 222 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 223 | #ifndef NDEBUG |
| 224 | AssertOK(); |
| 225 | #endif |
| 226 | } |
| 227 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 228 | public: |
| 229 | LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore); |
| 230 | LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 231 | LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false, |
| 232 | Instruction *InsertBefore = 0); |
| 233 | LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align, |
Chris Lattner | f00042a | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 234 | Instruction *InsertBefore = 0); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 235 | LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, |
| 236 | BasicBlock *InsertAtEnd); |
Dan Gohman | 6ab2d18 | 2007-07-18 20:51:11 +0000 | [diff] [blame] | 237 | LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align, |
| 238 | BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 239 | |
Chris Lattner | f00042a | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 240 | LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore); |
| 241 | LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 242 | explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false, |
Chris Lattner | f00042a | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 243 | Instruction *InsertBefore = 0); |
| 244 | LoadInst(Value *Ptr, const char *Name, bool isVolatile, |
| 245 | BasicBlock *InsertAtEnd); |
| 246 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 247 | /// isVolatile - Return true if this is a load from a volatile memory |
| 248 | /// location. |
| 249 | /// |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 250 | bool isVolatile() const { return SubclassData & 1; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 251 | |
| 252 | /// setVolatile - Specify whether this is a volatile load or not. |
| 253 | /// |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 254 | void setVolatile(bool V) { |
Hartmut Kaiser | efd4a51 | 2007-10-17 14:56:40 +0000 | [diff] [blame] | 255 | SubclassData = (SubclassData & ~1) | (V ? 1 : 0); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 256 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 257 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 258 | virtual LoadInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 259 | |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 260 | /// getAlignment - Return the alignment of the access that is being performed |
| 261 | /// |
| 262 | unsigned getAlignment() const { |
Christopher Lamb | 032507d | 2007-04-22 22:22:02 +0000 | [diff] [blame] | 263 | return (1 << (SubclassData>>1)) >> 1; |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | void setAlignment(unsigned Align); |
| 267 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 268 | Value *getPointerOperand() { return getOperand(0); } |
| 269 | const Value *getPointerOperand() const { return getOperand(0); } |
| 270 | static unsigned getPointerOperandIndex() { return 0U; } |
| 271 | |
| 272 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 273 | static inline bool classof(const LoadInst *) { return true; } |
| 274 | static inline bool classof(const Instruction *I) { |
| 275 | return I->getOpcode() == Instruction::Load; |
| 276 | } |
| 277 | static inline bool classof(const Value *V) { |
| 278 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 279 | } |
| 280 | }; |
| 281 | |
| 282 | |
| 283 | //===----------------------------------------------------------------------===// |
| 284 | // StoreInst Class |
| 285 | //===----------------------------------------------------------------------===// |
| 286 | |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 287 | /// StoreInst - an instruction for storing to memory |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 288 | /// |
| 289 | class StoreInst : public Instruction { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 290 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 291 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 292 | StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, |
| 293 | &Op<0>(), 2) { |
| 294 | Op<0>().init(SI.Op<0>(), this); |
| 295 | Op<1>().init(SI.Op<1>(), this); |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 296 | setVolatile(SI.isVolatile()); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 297 | setAlignment(SI.getAlignment()); |
| 298 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 299 | #ifndef NDEBUG |
| 300 | AssertOK(); |
| 301 | #endif |
| 302 | } |
| 303 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 304 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 305 | // allocate space for exactly two operands |
| 306 | void *operator new(size_t s) { |
| 307 | return User::operator new(s, 2); |
| 308 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 309 | StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore); |
| 310 | StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd); |
| 311 | StoreInst(Value *Val, Value *Ptr, bool isVolatile = false, |
| 312 | Instruction *InsertBefore = 0); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 313 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, |
| 314 | unsigned Align, Instruction *InsertBefore = 0); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 315 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd); |
Dan Gohman | 6ab2d18 | 2007-07-18 20:51:11 +0000 | [diff] [blame] | 316 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, |
| 317 | unsigned Align, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 318 | |
| 319 | |
| 320 | /// isVolatile - Return true if this is a load from a volatile memory |
| 321 | /// location. |
| 322 | /// |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 323 | bool isVolatile() const { return SubclassData & 1; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 324 | |
| 325 | /// setVolatile - Specify whether this is a volatile load or not. |
| 326 | /// |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 327 | void setVolatile(bool V) { |
Hartmut Kaiser | efd4a51 | 2007-10-17 14:56:40 +0000 | [diff] [blame] | 328 | SubclassData = (SubclassData & ~1) | (V ? 1 : 0); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 329 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 330 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 331 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 332 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 333 | |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 334 | /// getAlignment - Return the alignment of the access that is being performed |
| 335 | /// |
| 336 | unsigned getAlignment() const { |
Christopher Lamb | 032507d | 2007-04-22 22:22:02 +0000 | [diff] [blame] | 337 | return (1 << (SubclassData>>1)) >> 1; |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | void setAlignment(unsigned Align); |
| 341 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 342 | virtual StoreInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 343 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 344 | Value *getPointerOperand() { return getOperand(1); } |
| 345 | const Value *getPointerOperand() const { return getOperand(1); } |
| 346 | static unsigned getPointerOperandIndex() { return 1U; } |
| 347 | |
| 348 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 349 | static inline bool classof(const StoreInst *) { return true; } |
| 350 | static inline bool classof(const Instruction *I) { |
| 351 | return I->getOpcode() == Instruction::Store; |
| 352 | } |
| 353 | static inline bool classof(const Value *V) { |
| 354 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 355 | } |
| 356 | }; |
| 357 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 358 | template <> |
| 359 | struct OperandTraits<StoreInst> : FixedNumOperandTraits<2> { |
| 360 | }; |
| 361 | |
| 362 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value) |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 363 | |
| 364 | //===----------------------------------------------------------------------===// |
| 365 | // GetElementPtrInst Class |
| 366 | //===----------------------------------------------------------------------===// |
| 367 | |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 368 | // checkType - Simple wrapper function to give a better assertion failure |
| 369 | // message on bad indexes for a gep instruction. |
| 370 | // |
| 371 | static inline const Type *checkType(const Type *Ty) { |
| 372 | assert(Ty && "Invalid GetElementPtrInst indices for type!"); |
| 373 | return Ty; |
| 374 | } |
| 375 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 376 | /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to |
| 377 | /// access elements of arrays and structs |
| 378 | /// |
| 379 | class GetElementPtrInst : public Instruction { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 380 | GetElementPtrInst(const GetElementPtrInst &GEPI); |
Chris Lattner | 6ffbe17 | 2007-01-31 19:47:18 +0000 | [diff] [blame] | 381 | void init(Value *Ptr, Value* const *Idx, unsigned NumIdx); |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 382 | void init(Value *Ptr, Value *Idx); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 383 | |
| 384 | template<typename InputIterator> |
| 385 | void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd, |
| 386 | const std::string &Name, |
| 387 | // This argument ensures that we have an iterator we can |
| 388 | // do arithmetic on in constant time |
| 389 | std::random_access_iterator_tag) { |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 390 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 391 | |
| 392 | if (NumIdx > 0) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 393 | // This requires that the iterator points to contiguous memory. |
| 394 | init(Ptr, &*IdxBegin, NumIdx); // FIXME: for the general case |
| 395 | // we have to build an array here |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 396 | } |
| 397 | else { |
| 398 | init(Ptr, 0, NumIdx); |
| 399 | } |
| 400 | |
| 401 | setName(Name); |
| 402 | } |
| 403 | |
| 404 | /// getIndexedType - Returns the type of the element that would be loaded with |
| 405 | /// a load instruction with the specified parameters. |
| 406 | /// |
| 407 | /// A null type is returned if the indices are invalid for the specified |
| 408 | /// pointer type. |
| 409 | /// |
| 410 | static const Type *getIndexedType(const Type *Ptr, |
| 411 | Value* const *Idx, unsigned NumIdx, |
| 412 | bool AllowStructLeaf = false); |
| 413 | |
| 414 | template<typename InputIterator> |
| 415 | static const Type *getIndexedType(const Type *Ptr, |
| 416 | InputIterator IdxBegin, |
| 417 | InputIterator IdxEnd, |
| 418 | bool AllowStructLeaf, |
| 419 | // This argument ensures that we |
| 420 | // have an iterator we can do |
| 421 | // arithmetic on in constant time |
| 422 | std::random_access_iterator_tag) { |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 423 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 424 | |
| 425 | if (NumIdx > 0) { |
| 426 | // This requires that the iterator points to contiguous memory. |
| 427 | return(getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx, |
| 428 | AllowStructLeaf)); |
| 429 | } |
| 430 | else { |
| 431 | return(getIndexedType(Ptr, (Value *const*)0, NumIdx, AllowStructLeaf)); |
| 432 | } |
| 433 | } |
| 434 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 435 | /// Constructors - Create a getelementptr instruction with a base pointer an |
| 436 | /// list of indices. The first ctor can optionally insert before an existing |
| 437 | /// instruction, the second appends the new instruction to the specified |
| 438 | /// BasicBlock. |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 439 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 440 | inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, |
| 441 | InputIterator IdxEnd, |
| 442 | unsigned Values, |
| 443 | const std::string &Name, |
| 444 | Instruction *InsertBefore); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 445 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 446 | inline GetElementPtrInst(Value *Ptr, |
| 447 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 448 | unsigned Values, |
| 449 | const std::string &Name, BasicBlock *InsertAtEnd); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 450 | |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 451 | /// Constructors - These two constructors are convenience methods because one |
| 452 | /// and two index getelementptr instructions are so common. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 453 | GetElementPtrInst(Value *Ptr, Value *Idx, const std::string &Name = "", |
| 454 | Instruction *InsertBefore = 0); |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 455 | GetElementPtrInst(Value *Ptr, Value *Idx, |
| 456 | const std::string &Name, BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 457 | public: |
| 458 | template<typename InputIterator> |
| 459 | static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin, |
| 460 | InputIterator IdxEnd, |
| 461 | const std::string &Name = "", |
| 462 | Instruction *InsertBefore = 0) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 463 | typename std::iterator_traits<InputIterator>::difference_type Values = |
| 464 | 1 + std::distance(IdxBegin, IdxEnd); |
| 465 | return new(Values) |
| 466 | GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 467 | } |
| 468 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 469 | static GetElementPtrInst *Create(Value *Ptr, |
| 470 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 471 | const std::string &Name, |
| 472 | BasicBlock *InsertAtEnd) { |
| 473 | typename std::iterator_traits<InputIterator>::difference_type Values = |
| 474 | 1 + std::distance(IdxBegin, IdxEnd); |
| 475 | return new(Values) |
| 476 | GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 479 | /// Constructors - These two creators are convenience methods because one |
| 480 | /// index getelementptr instructions are so common. |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 481 | static GetElementPtrInst *Create(Value *Ptr, Value *Idx, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 482 | const std::string &Name = "", |
| 483 | Instruction *InsertBefore = 0) { |
| 484 | return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 485 | } |
| 486 | static GetElementPtrInst *Create(Value *Ptr, Value *Idx, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 487 | const std::string &Name, |
| 488 | BasicBlock *InsertAtEnd) { |
| 489 | return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 490 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 491 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 492 | virtual GetElementPtrInst *clone() const; |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 493 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 494 | /// Transparently provide more efficient getOperand methods. |
| 495 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 496 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 497 | // getType - Overload to return most specific pointer type... |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 498 | const PointerType *getType() const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 499 | return reinterpret_cast<const PointerType*>(Instruction::getType()); |
| 500 | } |
| 501 | |
| 502 | /// getIndexedType - Returns the type of the element that would be loaded with |
| 503 | /// a load instruction with the specified parameters. |
| 504 | /// |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 505 | /// 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] | 506 | /// pointer type. |
| 507 | /// |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 508 | template<typename InputIterator> |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 509 | static const Type *getIndexedType(const Type *Ptr, |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 510 | InputIterator IdxBegin, |
| 511 | InputIterator IdxEnd, |
| 512 | bool AllowStructLeaf = false) { |
| 513 | return(getIndexedType(Ptr, IdxBegin, IdxEnd, AllowStructLeaf, |
| 514 | typename std::iterator_traits<InputIterator>:: |
| 515 | iterator_category())); |
| 516 | } |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 517 | static const Type *getIndexedType(const Type *Ptr, Value *Idx); |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 518 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 519 | inline op_iterator idx_begin() { return op_begin()+1; } |
| 520 | inline const_op_iterator idx_begin() const { return op_begin()+1; } |
| 521 | inline op_iterator idx_end() { return op_end(); } |
| 522 | inline const_op_iterator idx_end() const { return op_end(); } |
| 523 | |
| 524 | Value *getPointerOperand() { |
| 525 | return getOperand(0); |
| 526 | } |
| 527 | const Value *getPointerOperand() const { |
| 528 | return getOperand(0); |
| 529 | } |
| 530 | static unsigned getPointerOperandIndex() { |
| 531 | return 0U; // get index for modifying correct operand |
| 532 | } |
| 533 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 534 | unsigned getNumIndices() const { // Note: always non-negative |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 535 | return getNumOperands() - 1; |
| 536 | } |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 537 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 538 | bool hasIndices() const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 539 | return getNumOperands() > 1; |
| 540 | } |
Chris Lattner | 6f771d4 | 2007-04-14 00:12:57 +0000 | [diff] [blame] | 541 | |
| 542 | /// hasAllZeroIndices - Return true if all of the indices of this GEP are |
| 543 | /// zeros. If so, the result pointer and the first operand have the same |
| 544 | /// value, just potentially different types. |
| 545 | bool hasAllZeroIndices() const; |
Chris Lattner | 6b0974c | 2007-04-27 20:35:56 +0000 | [diff] [blame] | 546 | |
| 547 | /// hasAllConstantIndices - Return true if all of the indices of this GEP are |
| 548 | /// constant integers. If so, the result pointer and the first operand have |
| 549 | /// a constant offset between them. |
| 550 | bool hasAllConstantIndices() const; |
| 551 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 552 | |
| 553 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 554 | static inline bool classof(const GetElementPtrInst *) { return true; } |
| 555 | static inline bool classof(const Instruction *I) { |
| 556 | return (I->getOpcode() == Instruction::GetElementPtr); |
| 557 | } |
| 558 | static inline bool classof(const Value *V) { |
| 559 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 560 | } |
| 561 | }; |
| 562 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 563 | template <> |
| 564 | struct OperandTraits<GetElementPtrInst> : VariadicOperandTraits<1> { |
| 565 | }; |
| 566 | |
| 567 | template<typename InputIterator> |
| 568 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, |
| 569 | InputIterator IdxBegin, |
| 570 | InputIterator IdxEnd, |
| 571 | unsigned Values, |
| 572 | const std::string &Name, |
| 573 | Instruction *InsertBefore) |
| 574 | : Instruction(PointerType::get(checkType( |
| 575 | getIndexedType(Ptr->getType(), |
| 576 | IdxBegin, IdxEnd, true)), |
| 577 | cast<PointerType>(Ptr->getType()) |
| 578 | ->getAddressSpace()), |
| 579 | GetElementPtr, |
| 580 | OperandTraits<GetElementPtrInst>::op_end(this) - Values, |
| 581 | Values, InsertBefore) { |
| 582 | init(Ptr, IdxBegin, IdxEnd, Name, |
| 583 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 584 | } |
| 585 | template<typename InputIterator> |
| 586 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, |
| 587 | InputIterator IdxBegin, |
| 588 | InputIterator IdxEnd, |
| 589 | unsigned Values, |
| 590 | const std::string &Name, |
| 591 | BasicBlock *InsertAtEnd) |
| 592 | : Instruction(PointerType::get(checkType( |
| 593 | getIndexedType(Ptr->getType(), |
| 594 | IdxBegin, IdxEnd, true)), |
| 595 | cast<PointerType>(Ptr->getType()) |
| 596 | ->getAddressSpace()), |
| 597 | GetElementPtr, |
| 598 | OperandTraits<GetElementPtrInst>::op_end(this) - Values, |
| 599 | Values, InsertAtEnd) { |
| 600 | init(Ptr, IdxBegin, IdxEnd, Name, |
| 601 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 602 | } |
| 603 | |
| 604 | |
| 605 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value) |
| 606 | |
| 607 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 608 | //===----------------------------------------------------------------------===// |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 609 | // ICmpInst Class |
| 610 | //===----------------------------------------------------------------------===// |
| 611 | |
| 612 | /// This instruction compares its operands according to the predicate given |
| 613 | /// to the constructor. It only operates on integers, pointers, or packed |
| 614 | /// vectors of integrals. The two operands must be the same type. |
| 615 | /// @brief Represent an integer comparison operator. |
| 616 | class ICmpInst: public CmpInst { |
| 617 | public: |
| 618 | /// This enumeration lists the possible predicates for the ICmpInst. The |
| 619 | /// values in the range 0-31 are reserved for FCmpInst while values in the |
| 620 | /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the |
| 621 | /// predicate values are not overlapping between the classes. |
| 622 | enum Predicate { |
| 623 | ICMP_EQ = 32, ///< equal |
| 624 | ICMP_NE = 33, ///< not equal |
| 625 | ICMP_UGT = 34, ///< unsigned greater than |
| 626 | ICMP_UGE = 35, ///< unsigned greater or equal |
| 627 | ICMP_ULT = 36, ///< unsigned less than |
| 628 | ICMP_ULE = 37, ///< unsigned less or equal |
| 629 | ICMP_SGT = 38, ///< signed greater than |
| 630 | ICMP_SGE = 39, ///< signed greater or equal |
| 631 | ICMP_SLT = 40, ///< signed less than |
| 632 | ICMP_SLE = 41, ///< signed less or equal |
| 633 | FIRST_ICMP_PREDICATE = ICMP_EQ, |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 634 | LAST_ICMP_PREDICATE = ICMP_SLE, |
| 635 | BAD_ICMP_PREDICATE = ICMP_SLE + 1 |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 636 | }; |
| 637 | |
| 638 | /// @brief Constructor with insert-before-instruction semantics. |
| 639 | ICmpInst( |
| 640 | Predicate pred, ///< The predicate to use for the comparison |
| 641 | Value *LHS, ///< The left-hand-side of the expression |
| 642 | Value *RHS, ///< The right-hand-side of the expression |
| 643 | const std::string &Name = "", ///< Name of the instruction |
| 644 | Instruction *InsertBefore = 0 ///< Where to insert |
| 645 | ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) { |
| 646 | } |
| 647 | |
| 648 | /// @brief Constructor with insert-at-block-end semantics. |
| 649 | ICmpInst( |
| 650 | Predicate pred, ///< The predicate to use for the comparison |
| 651 | Value *LHS, ///< The left-hand-side of the expression |
| 652 | Value *RHS, ///< The right-hand-side of the expression |
| 653 | const std::string &Name, ///< Name of the instruction |
| 654 | BasicBlock *InsertAtEnd ///< Block to insert into. |
| 655 | ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) { |
| 656 | } |
| 657 | |
| 658 | /// @brief Return the predicate for this instruction. |
| 659 | Predicate getPredicate() const { return Predicate(SubclassData); } |
| 660 | |
Chris Lattner | b769d56 | 2007-01-14 19:41:24 +0000 | [diff] [blame] | 661 | /// @brief Set the predicate for this instruction to the specified value. |
| 662 | void setPredicate(Predicate P) { SubclassData = P; } |
| 663 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 664 | /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc. |
| 665 | /// @returns the inverse predicate for the instruction's current predicate. |
| 666 | /// @brief Return the inverse of the instruction's predicate. |
| 667 | Predicate getInversePredicate() const { |
| 668 | return getInversePredicate(getPredicate()); |
| 669 | } |
| 670 | |
| 671 | /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc. |
| 672 | /// @returns the inverse predicate for predicate provided in \p pred. |
| 673 | /// @brief Return the inverse of a given predicate |
| 674 | static Predicate getInversePredicate(Predicate pred); |
| 675 | |
| 676 | /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc. |
| 677 | /// @returns the predicate that would be the result of exchanging the two |
| 678 | /// operands of the ICmpInst instruction without changing the result |
| 679 | /// produced. |
| 680 | /// @brief Return the predicate as if the operands were swapped |
| 681 | Predicate getSwappedPredicate() const { |
| 682 | return getSwappedPredicate(getPredicate()); |
| 683 | } |
| 684 | |
| 685 | /// This is a static version that you can use without an instruction |
| 686 | /// available. |
| 687 | /// @brief Return the predicate as if the operands were swapped. |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 688 | static Predicate getSwappedPredicate(Predicate pred); |
| 689 | |
| 690 | /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc. |
| 691 | /// @returns the predicate that would be the result if the operand were |
| 692 | /// regarded as signed. |
| 693 | /// @brief Return the signed version of the predicate |
| 694 | Predicate getSignedPredicate() const { |
| 695 | return getSignedPredicate(getPredicate()); |
| 696 | } |
| 697 | |
| 698 | /// This is a static version that you can use without an instruction. |
| 699 | /// @brief Return the signed version of the predicate. |
| 700 | static Predicate getSignedPredicate(Predicate pred); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 701 | |
Nick Lewycky | 4189a53 | 2008-01-28 03:48:02 +0000 | [diff] [blame] | 702 | /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc. |
| 703 | /// @returns the predicate that would be the result if the operand were |
| 704 | /// regarded as unsigned. |
| 705 | /// @brief Return the unsigned version of the predicate |
| 706 | Predicate getUnsignedPredicate() const { |
| 707 | return getUnsignedPredicate(getPredicate()); |
| 708 | } |
| 709 | |
| 710 | /// This is a static version that you can use without an instruction. |
| 711 | /// @brief Return the unsigned version of the predicate. |
| 712 | static Predicate getUnsignedPredicate(Predicate pred); |
| 713 | |
Chris Lattner | c2bfadb | 2007-11-22 23:43:29 +0000 | [diff] [blame] | 714 | /// isEquality - Return true if this predicate is either EQ or NE. This also |
| 715 | /// tests for commutativity. |
| 716 | static bool isEquality(Predicate P) { |
| 717 | return P == ICMP_EQ || P == ICMP_NE; |
| 718 | } |
| 719 | |
| 720 | /// isEquality - Return true if this predicate is either EQ or NE. This also |
| 721 | /// tests for commutativity. |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 722 | bool isEquality() const { |
Chris Lattner | c2bfadb | 2007-11-22 23:43:29 +0000 | [diff] [blame] | 723 | return isEquality(getPredicate()); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 724 | } |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 725 | |
| 726 | /// @returns true if the predicate of this ICmpInst is commutative |
| 727 | /// @brief Determine if this relation is commutative. |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 728 | bool isCommutative() const { return isEquality(); } |
| 729 | |
Chris Lattner | c2bfadb | 2007-11-22 23:43:29 +0000 | [diff] [blame] | 730 | /// isRelational - Return true if the predicate is relational (not EQ or NE). |
| 731 | /// |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 732 | bool isRelational() const { |
| 733 | return !isEquality(); |
| 734 | } |
| 735 | |
Chris Lattner | c2bfadb | 2007-11-22 23:43:29 +0000 | [diff] [blame] | 736 | /// isRelational - Return true if the predicate is relational (not EQ or NE). |
| 737 | /// |
| 738 | static bool isRelational(Predicate P) { |
| 739 | return !isEquality(P); |
| 740 | } |
| 741 | |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 742 | /// @returns true if the predicate of this ICmpInst is signed, false otherwise |
| 743 | /// @brief Determine if this instruction's predicate is signed. |
Chris Lattner | 5bda9e4 | 2007-09-15 06:51:03 +0000 | [diff] [blame] | 744 | bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); } |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 745 | |
| 746 | /// @returns true if the predicate provided is signed, false otherwise |
| 747 | /// @brief Determine if the predicate is signed. |
| 748 | static bool isSignedPredicate(Predicate pred); |
| 749 | |
Reid Spencer | 3da4384 | 2007-02-28 22:00:54 +0000 | [diff] [blame] | 750 | /// Initialize a set of values that all satisfy the predicate with C. |
| 751 | /// @brief Make a ConstantRange for a relation with a constant value. |
| 752 | static ConstantRange makeConstantRange(Predicate pred, const APInt &C); |
| 753 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 754 | /// Exchange the two operands to this instruction in such a way that it does |
| 755 | /// not modify the semantics of the instruction. The predicate value may be |
| 756 | /// changed to retain the same result if the predicate is order dependent |
| 757 | /// (e.g. ult). |
| 758 | /// @brief Swap operands and adjust predicate. |
| 759 | void swapOperands() { |
| 760 | SubclassData = getSwappedPredicate(); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 761 | std::swap(Op<0>(), Op<1>()); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 762 | } |
| 763 | |
Chris Lattner | cd406fe | 2007-08-24 20:48:18 +0000 | [diff] [blame] | 764 | virtual ICmpInst *clone() const; |
| 765 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 766 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 767 | static inline bool classof(const ICmpInst *) { return true; } |
| 768 | static inline bool classof(const Instruction *I) { |
| 769 | return I->getOpcode() == Instruction::ICmp; |
| 770 | } |
| 771 | static inline bool classof(const Value *V) { |
| 772 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 773 | } |
| 774 | }; |
| 775 | |
| 776 | //===----------------------------------------------------------------------===// |
| 777 | // FCmpInst Class |
| 778 | //===----------------------------------------------------------------------===// |
| 779 | |
| 780 | /// This instruction compares its operands according to the predicate given |
| 781 | /// to the constructor. It only operates on floating point values or packed |
| 782 | /// vectors of floating point values. The operands must be identical types. |
| 783 | /// @brief Represents a floating point comparison operator. |
| 784 | class FCmpInst: public CmpInst { |
| 785 | public: |
| 786 | /// This enumeration lists the possible predicates for the FCmpInst. Values |
| 787 | /// in the range 0-31 are reserved for FCmpInst. |
| 788 | enum Predicate { |
| 789 | // Opcode U L G E Intuitive operation |
| 790 | FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded) |
| 791 | FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal |
| 792 | FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than |
| 793 | FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal |
| 794 | FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than |
| 795 | FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal |
| 796 | FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal |
| 797 | FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans) |
| 798 | FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y) |
| 799 | FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal |
| 800 | FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than |
| 801 | FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal |
| 802 | FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than |
| 803 | FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal |
| 804 | FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal |
| 805 | FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded) |
| 806 | FIRST_FCMP_PREDICATE = FCMP_FALSE, |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 807 | LAST_FCMP_PREDICATE = FCMP_TRUE, |
| 808 | BAD_FCMP_PREDICATE = FCMP_TRUE + 1 |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 809 | }; |
| 810 | |
| 811 | /// @brief Constructor with insert-before-instruction semantics. |
| 812 | FCmpInst( |
| 813 | Predicate pred, ///< The predicate to use for the comparison |
| 814 | Value *LHS, ///< The left-hand-side of the expression |
| 815 | Value *RHS, ///< The right-hand-side of the expression |
| 816 | const std::string &Name = "", ///< Name of the instruction |
| 817 | Instruction *InsertBefore = 0 ///< Where to insert |
| 818 | ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) { |
| 819 | } |
| 820 | |
| 821 | /// @brief Constructor with insert-at-block-end semantics. |
| 822 | FCmpInst( |
| 823 | Predicate pred, ///< The predicate to use for the comparison |
| 824 | Value *LHS, ///< The left-hand-side of the expression |
| 825 | Value *RHS, ///< The right-hand-side of the expression |
| 826 | const std::string &Name, ///< Name of the instruction |
| 827 | BasicBlock *InsertAtEnd ///< Block to insert into. |
| 828 | ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) { |
| 829 | } |
| 830 | |
| 831 | /// @brief Return the predicate for this instruction. |
| 832 | Predicate getPredicate() const { return Predicate(SubclassData); } |
| 833 | |
Chris Lattner | b769d56 | 2007-01-14 19:41:24 +0000 | [diff] [blame] | 834 | /// @brief Set the predicate for this instruction to the specified value. |
| 835 | void setPredicate(Predicate P) { SubclassData = P; } |
| 836 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 837 | /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc. |
| 838 | /// @returns the inverse predicate for the instructions current predicate. |
| 839 | /// @brief Return the inverse of the predicate |
| 840 | Predicate getInversePredicate() const { |
| 841 | return getInversePredicate(getPredicate()); |
| 842 | } |
| 843 | |
| 844 | /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc. |
| 845 | /// @returns the inverse predicate for \p pred. |
| 846 | /// @brief Return the inverse of a given predicate |
| 847 | static Predicate getInversePredicate(Predicate pred); |
| 848 | |
| 849 | /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc. |
| 850 | /// @returns the predicate that would be the result of exchanging the two |
| 851 | /// operands of the ICmpInst instruction without changing the result |
| 852 | /// produced. |
| 853 | /// @brief Return the predicate as if the operands were swapped |
| 854 | Predicate getSwappedPredicate() const { |
| 855 | return getSwappedPredicate(getPredicate()); |
| 856 | } |
| 857 | |
| 858 | /// This is a static version that you can use without an instruction |
| 859 | /// available. |
| 860 | /// @brief Return the predicate as if the operands were swapped. |
| 861 | static Predicate getSwappedPredicate(Predicate Opcode); |
| 862 | |
| 863 | /// This also tests for commutativity. If isEquality() returns true then |
| 864 | /// the predicate is also commutative. Only the equality predicates are |
| 865 | /// commutative. |
| 866 | /// @returns true if the predicate of this instruction is EQ or NE. |
| 867 | /// @brief Determine if this is an equality predicate. |
| 868 | bool isEquality() const { |
| 869 | return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE || |
| 870 | SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE; |
| 871 | } |
| 872 | bool isCommutative() const { return isEquality(); } |
| 873 | |
| 874 | /// @returns true if the predicate is relational (not EQ or NE). |
| 875 | /// @brief Determine if this a relational predicate. |
| 876 | bool isRelational() const { return !isEquality(); } |
| 877 | |
| 878 | /// Exchange the two operands to this instruction in such a way that it does |
| 879 | /// not modify the semantics of the instruction. The predicate value may be |
| 880 | /// changed to retain the same result if the predicate is order dependent |
| 881 | /// (e.g. ult). |
| 882 | /// @brief Swap operands and adjust predicate. |
| 883 | void swapOperands() { |
| 884 | SubclassData = getSwappedPredicate(); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 885 | std::swap(Op<0>(), Op<1>()); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 886 | } |
| 887 | |
Chris Lattner | cd406fe | 2007-08-24 20:48:18 +0000 | [diff] [blame] | 888 | virtual FCmpInst *clone() const; |
| 889 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 890 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 891 | static inline bool classof(const FCmpInst *) { return true; } |
| 892 | static inline bool classof(const Instruction *I) { |
| 893 | return I->getOpcode() == Instruction::FCmp; |
| 894 | } |
| 895 | static inline bool classof(const Value *V) { |
| 896 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 897 | } |
| 898 | }; |
| 899 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 900 | //===----------------------------------------------------------------------===// |
| 901 | // CallInst Class |
| 902 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 903 | /// CallInst - This class represents a function call, abstracting a target |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 904 | /// machine's calling convention. This class uses low bit of the SubClassData |
| 905 | /// field to indicate whether or not this is a tail call. The rest of the bits |
| 906 | /// hold the calling convention of the call. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 907 | /// |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 908 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 909 | class CallInst : public Instruction { |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 910 | PAListPtr ParamAttrs; ///< parameter attributes for call |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 911 | CallInst(const CallInst &CI); |
Chris Lattner | d54f432 | 2007-02-13 00:58:44 +0000 | [diff] [blame] | 912 | void init(Value *Func, Value* const *Params, unsigned NumParams); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 913 | void init(Value *Func, Value *Actual1, Value *Actual2); |
| 914 | void init(Value *Func, Value *Actual); |
| 915 | void init(Value *Func); |
| 916 | |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 917 | template<typename InputIterator> |
| 918 | void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
| 919 | const std::string &Name, |
| 920 | // This argument ensures that we have an iterator we can |
| 921 | // do arithmetic on in constant time |
| 922 | std::random_access_iterator_tag) { |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 923 | unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd); |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 924 | |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 925 | // This requires that the iterator points to contiguous memory. |
| 926 | init(Func, NumArgs ? &*ArgBegin : 0, NumArgs); |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 927 | setName(Name); |
| 928 | } |
| 929 | |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 930 | /// Construct a CallInst given a range of arguments. InputIterator |
| 931 | /// must be a random-access iterator pointing to contiguous storage |
| 932 | /// (e.g. a std::vector<>::iterator). Checks are made for |
| 933 | /// random-accessness but not for contiguous storage as that would |
| 934 | /// incur runtime overhead. |
| 935 | /// @brief Construct a CallInst from a range of arguments |
| 936 | template<typename InputIterator> |
| 937 | CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 938 | const std::string &Name, Instruction *InsertBefore); |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 939 | |
| 940 | /// Construct a CallInst given a range of arguments. InputIterator |
| 941 | /// must be a random-access iterator pointing to contiguous storage |
| 942 | /// (e.g. a std::vector<>::iterator). Checks are made for |
| 943 | /// random-accessness but not for contiguous storage as that would |
| 944 | /// incur runtime overhead. |
| 945 | /// @brief Construct a CallInst from a range of arguments |
| 946 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 947 | inline CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
| 948 | const std::string &Name, BasicBlock *InsertAtEnd); |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 949 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 950 | CallInst(Value *F, Value *Actual, const std::string& Name, |
| 951 | Instruction *InsertBefore); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 952 | CallInst(Value *F, Value *Actual, const std::string& Name, |
| 953 | BasicBlock *InsertAtEnd); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 954 | explicit CallInst(Value *F, const std::string &Name, |
| 955 | Instruction *InsertBefore); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 956 | CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 957 | public: |
| 958 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 959 | static CallInst *Create(Value *Func, |
| 960 | InputIterator ArgBegin, InputIterator ArgEnd, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 961 | const std::string &Name = "", |
| 962 | Instruction *InsertBefore = 0) { |
| 963 | return new(ArgEnd - ArgBegin + 1) |
| 964 | CallInst(Func, ArgBegin, ArgEnd, Name, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 965 | } |
| 966 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 967 | static CallInst *Create(Value *Func, |
| 968 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 969 | const std::string &Name, BasicBlock *InsertAtEnd) { |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 970 | return new(ArgEnd - ArgBegin + 1) |
| 971 | CallInst(Func, ArgBegin, ArgEnd, Name, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 972 | } |
| 973 | static CallInst *Create(Value *F, Value *Actual, const std::string& Name = "", |
| 974 | Instruction *InsertBefore = 0) { |
| 975 | return new(2) CallInst(F, Actual, Name, InsertBefore); |
| 976 | } |
| 977 | static CallInst *Create(Value *F, Value *Actual, const std::string& Name, |
| 978 | BasicBlock *InsertAtEnd) { |
| 979 | return new(2) CallInst(F, Actual, Name, InsertAtEnd); |
| 980 | } |
| 981 | static CallInst *Create(Value *F, const std::string &Name = "", |
| 982 | Instruction *InsertBefore = 0) { |
| 983 | return new(1) CallInst(F, Name, InsertBefore); |
| 984 | } |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 985 | static CallInst *Create(Value *F, const std::string &Name, |
| 986 | BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 987 | return new(1) CallInst(F, Name, InsertAtEnd); |
| 988 | } |
| 989 | |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 990 | ~CallInst(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 991 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 992 | virtual CallInst *clone() const; |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 993 | |
| 994 | /// Provide fast operand accessors |
| 995 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Chris Lattner | bb5493d | 2007-02-15 23:15:00 +0000 | [diff] [blame] | 996 | |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 997 | bool isTailCall() const { return SubclassData & 1; } |
| 998 | void setTailCall(bool isTailCall = true) { |
Jeff Cohen | 39cef60 | 2005-05-07 02:44:04 +0000 | [diff] [blame] | 999 | SubclassData = (SubclassData & ~1) | unsigned(isTailCall); |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | /// getCallingConv/setCallingConv - Get or set the calling convention of this |
| 1003 | /// function call. |
| 1004 | unsigned getCallingConv() const { return SubclassData >> 1; } |
| 1005 | void setCallingConv(unsigned CC) { |
| 1006 | SubclassData = (SubclassData & 1) | (CC << 1); |
| 1007 | } |
Chris Lattner | ddb6db4 | 2005-05-06 05:51:46 +0000 | [diff] [blame] | 1008 | |
Chris Lattner | 041221c | 2008-03-13 04:33:03 +0000 | [diff] [blame] | 1009 | /// getParamAttrs - Return the parameter attributes for this call. |
| 1010 | /// |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 1011 | const PAListPtr &getParamAttrs() const { return ParamAttrs; } |
Reid Spencer | 4746ecf | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 1012 | |
Chris Lattner | 041221c | 2008-03-13 04:33:03 +0000 | [diff] [blame] | 1013 | /// setParamAttrs - Sets the parameter attributes for this call. |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 1014 | void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; } |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 1015 | |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 1016 | /// @brief Determine whether the call or the callee has the given attribute. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1017 | bool paramHasAttr(unsigned i, unsigned attr) const; |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 1018 | |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 1019 | /// @brief Extract the alignment for a call or parameter (0=unknown). |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1020 | unsigned getParamAlignment(unsigned i) const { |
| 1021 | return ParamAttrs.getParamAlignment(i); |
| 1022 | } |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 1023 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1024 | /// @brief Determine if the call does not access memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1025 | bool doesNotAccessMemory() const { |
| 1026 | return paramHasAttr(0, ParamAttr::ReadNone); |
| 1027 | } |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 1028 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1029 | /// @brief Determine if the call does not access or only reads memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1030 | bool onlyReadsMemory() const { |
| 1031 | return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly); |
| 1032 | } |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 1033 | |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 1034 | /// @brief Determine if the call cannot return. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1035 | bool doesNotReturn() const { |
| 1036 | return paramHasAttr(0, ParamAttr::NoReturn); |
| 1037 | } |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 1038 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1039 | /// @brief Determine if the call cannot unwind. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1040 | bool doesNotThrow() const { |
| 1041 | return paramHasAttr(0, ParamAttr::NoUnwind); |
| 1042 | } |
Duncan Sands | f0c3354 | 2007-12-19 21:13:37 +0000 | [diff] [blame] | 1043 | void setDoesNotThrow(bool doesNotThrow = true); |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1044 | |
Devang Patel | 41e2397 | 2008-03-03 21:46:28 +0000 | [diff] [blame] | 1045 | /// @brief Determine if the call returns a structure through first |
| 1046 | /// pointer argument. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1047 | bool hasStructRetAttr() const { |
| 1048 | // Be friendly and also check the callee. |
| 1049 | return paramHasAttr(1, ParamAttr::StructRet); |
| 1050 | } |
Reid Spencer | 4746ecf | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 1051 | |
Evan Cheng | f4a5498 | 2008-01-12 18:57:32 +0000 | [diff] [blame] | 1052 | /// @brief Determine if any call argument is an aggregate passed by value. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1053 | bool hasByValArgument() const { |
| 1054 | return ParamAttrs.hasAttrSomewhere(ParamAttr::ByVal); |
| 1055 | } |
Evan Cheng | f4a5498 | 2008-01-12 18:57:32 +0000 | [diff] [blame] | 1056 | |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 1057 | /// getCalledFunction - Return the function being called by this instruction |
| 1058 | /// if it is a direct call. If it is a call through a function pointer, |
| 1059 | /// return null. |
| 1060 | Function *getCalledFunction() const { |
Dan Gohman | 11a7dbf | 2007-09-24 15:46:02 +0000 | [diff] [blame] | 1061 | return dyn_cast<Function>(getOperand(0)); |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 1062 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1063 | |
Reid Spencer | c25ec25 | 2006-12-29 04:10:59 +0000 | [diff] [blame] | 1064 | /// getCalledValue - Get a pointer to the function that is invoked by this |
| 1065 | /// instruction |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1066 | const Value *getCalledValue() const { return getOperand(0); } |
| 1067 | Value *getCalledValue() { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1068 | |
| 1069 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1070 | static inline bool classof(const CallInst *) { return true; } |
| 1071 | static inline bool classof(const Instruction *I) { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1072 | return I->getOpcode() == Instruction::Call; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1073 | } |
| 1074 | static inline bool classof(const Value *V) { |
| 1075 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1076 | } |
| 1077 | }; |
| 1078 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1079 | template <> |
| 1080 | struct OperandTraits<CallInst> : VariadicOperandTraits<1> { |
| 1081 | }; |
| 1082 | |
| 1083 | template<typename InputIterator> |
| 1084 | CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
| 1085 | const std::string &Name, BasicBlock *InsertAtEnd) |
| 1086 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 1087 | ->getElementType())->getReturnType(), |
| 1088 | Instruction::Call, |
| 1089 | OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1), |
| 1090 | ArgEnd - ArgBegin + 1, InsertAtEnd) { |
| 1091 | init(Func, ArgBegin, ArgEnd, Name, |
| 1092 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 1093 | } |
| 1094 | |
| 1095 | template<typename InputIterator> |
| 1096 | CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
| 1097 | const std::string &Name, Instruction *InsertBefore) |
| 1098 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 1099 | ->getElementType())->getReturnType(), |
| 1100 | Instruction::Call, |
| 1101 | OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1), |
| 1102 | ArgEnd - ArgBegin + 1, InsertBefore) { |
| 1103 | init(Func, ArgBegin, ArgEnd, Name, |
| 1104 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 1105 | } |
| 1106 | |
| 1107 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value) |
| 1108 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1109 | //===----------------------------------------------------------------------===// |
| 1110 | // SelectInst Class |
| 1111 | //===----------------------------------------------------------------------===// |
| 1112 | |
| 1113 | /// SelectInst - This class represents the LLVM 'select' instruction. |
| 1114 | /// |
| 1115 | class SelectInst : public Instruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1116 | void init(Value *C, Value *S1, Value *S2) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1117 | Op<0>() = C; |
| 1118 | Op<1>() = S1; |
| 1119 | Op<2>() = S2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1122 | SelectInst(const SelectInst &SI) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1123 | : Instruction(SI.getType(), SI.getOpcode(), &Op<0>(), 3) { |
| 1124 | init(SI.Op<0>(), SI.Op<1>(), SI.Op<2>()); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1125 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1126 | SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name, |
| 1127 | Instruction *InsertBefore) |
| 1128 | : Instruction(S1->getType(), Instruction::Select, |
| 1129 | &Op<0>(), 3, InsertBefore) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1130 | init(C, S1, S2); |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1131 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1132 | } |
| 1133 | SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name, |
| 1134 | BasicBlock *InsertAtEnd) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1135 | : Instruction(S1->getType(), Instruction::Select, |
| 1136 | &Op<0>(), 3, InsertAtEnd) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1137 | init(C, S1, S2); |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1138 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1139 | } |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1140 | public: |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1141 | static SelectInst *Create(Value *C, Value *S1, Value *S2, |
| 1142 | const std::string &Name = "", |
| 1143 | Instruction *InsertBefore = 0) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1144 | return new(3) SelectInst(C, S1, S2, Name, InsertBefore); |
| 1145 | } |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1146 | static SelectInst *Create(Value *C, Value *S1, Value *S2, |
| 1147 | const std::string &Name, BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1148 | return new(3) SelectInst(C, S1, S2, Name, InsertAtEnd); |
| 1149 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1150 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1151 | Value *getCondition() const { return Op<0>(); } |
| 1152 | Value *getTrueValue() const { return Op<1>(); } |
| 1153 | Value *getFalseValue() const { return Op<2>(); } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1154 | |
| 1155 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1156 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1157 | |
| 1158 | OtherOps getOpcode() const { |
| 1159 | return static_cast<OtherOps>(Instruction::getOpcode()); |
| 1160 | } |
| 1161 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1162 | virtual SelectInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1163 | |
| 1164 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1165 | static inline bool classof(const SelectInst *) { return true; } |
| 1166 | static inline bool classof(const Instruction *I) { |
| 1167 | return I->getOpcode() == Instruction::Select; |
| 1168 | } |
| 1169 | static inline bool classof(const Value *V) { |
| 1170 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1171 | } |
| 1172 | }; |
| 1173 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1174 | template <> |
| 1175 | struct OperandTraits<SelectInst> : FixedNumOperandTraits<3> { |
| 1176 | }; |
| 1177 | |
| 1178 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value) |
| 1179 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1180 | //===----------------------------------------------------------------------===// |
| 1181 | // VAArgInst Class |
| 1182 | //===----------------------------------------------------------------------===// |
| 1183 | |
| 1184 | /// VAArgInst - This class represents the va_arg llvm instruction, which returns |
Andrew Lenharth | f542821 | 2005-06-18 18:31:30 +0000 | [diff] [blame] | 1185 | /// 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] | 1186 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1187 | class VAArgInst : public UnaryInstruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1188 | VAArgInst(const VAArgInst &VAA) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1189 | : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {} |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1190 | public: |
| 1191 | VAArgInst(Value *List, const Type *Ty, const std::string &Name = "", |
| 1192 | Instruction *InsertBefore = 0) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1193 | : UnaryInstruction(Ty, VAArg, List, InsertBefore) { |
Chris Lattner | f00042a | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 1194 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1195 | } |
| 1196 | VAArgInst(Value *List, const Type *Ty, const std::string &Name, |
| 1197 | BasicBlock *InsertAtEnd) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1198 | : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) { |
Chris Lattner | f00042a | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 1199 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1202 | virtual VAArgInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1203 | |
| 1204 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1205 | static inline bool classof(const VAArgInst *) { return true; } |
| 1206 | static inline bool classof(const Instruction *I) { |
| 1207 | return I->getOpcode() == VAArg; |
| 1208 | } |
| 1209 | static inline bool classof(const Value *V) { |
| 1210 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1211 | } |
| 1212 | }; |
| 1213 | |
| 1214 | //===----------------------------------------------------------------------===// |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1215 | // ExtractElementInst Class |
| 1216 | //===----------------------------------------------------------------------===// |
| 1217 | |
| 1218 | /// ExtractElementInst - This instruction extracts a single (scalar) |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1219 | /// element from a VectorType value |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1220 | /// |
| 1221 | class ExtractElementInst : public Instruction { |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1222 | ExtractElementInst(const ExtractElementInst &EE) : |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1223 | Instruction(EE.getType(), ExtractElement, &Op<0>(), 2) { |
| 1224 | Op<0>().init(EE.Op<0>(), this); |
| 1225 | Op<1>().init(EE.Op<1>(), this); |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1229 | // allocate space for exactly two operands |
| 1230 | void *operator new(size_t s) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1231 | return User::operator new(s, 2); // FIXME: "unsigned Idx" forms of ctor? |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1232 | } |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1233 | ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "", |
| 1234 | Instruction *InsertBefore = 0); |
Chris Lattner | 06a248c2 | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1235 | ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "", |
| 1236 | Instruction *InsertBefore = 0); |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1237 | ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name, |
| 1238 | BasicBlock *InsertAtEnd); |
Chris Lattner | 06a248c2 | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1239 | ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name, |
| 1240 | BasicBlock *InsertAtEnd); |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1241 | |
Chris Lattner | fa49584 | 2006-04-08 04:04:54 +0000 | [diff] [blame] | 1242 | /// isValidOperands - Return true if an extractelement instruction can be |
| 1243 | /// formed with the specified operands. |
| 1244 | static bool isValidOperands(const Value *Vec, const Value *Idx); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1245 | |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1246 | virtual ExtractElementInst *clone() const; |
| 1247 | |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1248 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1249 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1250 | |
| 1251 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1252 | static inline bool classof(const ExtractElementInst *) { return true; } |
| 1253 | static inline bool classof(const Instruction *I) { |
| 1254 | return I->getOpcode() == Instruction::ExtractElement; |
| 1255 | } |
| 1256 | static inline bool classof(const Value *V) { |
| 1257 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1258 | } |
| 1259 | }; |
| 1260 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1261 | template <> |
| 1262 | struct OperandTraits<ExtractElementInst> : FixedNumOperandTraits<2> { |
| 1263 | }; |
| 1264 | |
| 1265 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value) |
| 1266 | |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1267 | //===----------------------------------------------------------------------===// |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1268 | // InsertElementInst Class |
| 1269 | //===----------------------------------------------------------------------===// |
| 1270 | |
| 1271 | /// InsertElementInst - This instruction inserts a single (scalar) |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1272 | /// element into a VectorType value |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1273 | /// |
| 1274 | class InsertElementInst : public Instruction { |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1275 | InsertElementInst(const InsertElementInst &IE); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1276 | InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, |
| 1277 | const std::string &Name = "",Instruction *InsertBefore = 0); |
| 1278 | InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx, |
| 1279 | const std::string &Name = "",Instruction *InsertBefore = 0); |
| 1280 | InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, |
| 1281 | const std::string &Name, BasicBlock *InsertAtEnd); |
| 1282 | InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx, |
| 1283 | const std::string &Name, BasicBlock *InsertAtEnd); |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1284 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1285 | static InsertElementInst *Create(const InsertElementInst &IE) { |
| 1286 | return new(IE.getNumOperands()) InsertElementInst(IE); |
| 1287 | } |
| 1288 | static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1289 | const std::string &Name = "", |
| 1290 | Instruction *InsertBefore = 0) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1291 | return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore); |
| 1292 | } |
| 1293 | static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1294 | const std::string &Name = "", |
| 1295 | Instruction *InsertBefore = 0) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1296 | return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1297 | } |
| 1298 | static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1299 | const std::string &Name, |
| 1300 | BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1301 | return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd); |
| 1302 | } |
| 1303 | static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1304 | const std::string &Name, |
| 1305 | BasicBlock *InsertAtEnd) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1306 | return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1307 | } |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1308 | |
Chris Lattner | fa49584 | 2006-04-08 04:04:54 +0000 | [diff] [blame] | 1309 | /// isValidOperands - Return true if an insertelement instruction can be |
| 1310 | /// formed with the specified operands. |
| 1311 | static bool isValidOperands(const Value *Vec, const Value *NewElt, |
| 1312 | const Value *Idx); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1313 | |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1314 | virtual InsertElementInst *clone() const; |
| 1315 | |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1316 | /// getType - Overload to return most specific vector type. |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1317 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1318 | const VectorType *getType() const { |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1319 | return reinterpret_cast<const VectorType*>(Instruction::getType()); |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1320 | } |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1321 | |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1322 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1323 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1324 | |
| 1325 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1326 | static inline bool classof(const InsertElementInst *) { return true; } |
| 1327 | static inline bool classof(const Instruction *I) { |
| 1328 | return I->getOpcode() == Instruction::InsertElement; |
| 1329 | } |
| 1330 | static inline bool classof(const Value *V) { |
| 1331 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1332 | } |
| 1333 | }; |
| 1334 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1335 | template <> |
| 1336 | struct OperandTraits<InsertElementInst> : FixedNumOperandTraits<3> { |
| 1337 | }; |
| 1338 | |
| 1339 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value) |
| 1340 | |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1341 | //===----------------------------------------------------------------------===// |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1342 | // ShuffleVectorInst Class |
| 1343 | //===----------------------------------------------------------------------===// |
| 1344 | |
| 1345 | /// ShuffleVectorInst - This instruction constructs a fixed permutation of two |
| 1346 | /// input vectors. |
| 1347 | /// |
| 1348 | class ShuffleVectorInst : public Instruction { |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1349 | ShuffleVectorInst(const ShuffleVectorInst &IE); |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1350 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1351 | // allocate space for exactly three operands |
| 1352 | void *operator new(size_t s) { |
| 1353 | return User::operator new(s, 3); |
| 1354 | } |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1355 | ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
| 1356 | const std::string &Name = "", Instruction *InsertBefor = 0); |
| 1357 | ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
| 1358 | const std::string &Name, BasicBlock *InsertAtEnd); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1359 | |
Chris Lattner | fa49584 | 2006-04-08 04:04:54 +0000 | [diff] [blame] | 1360 | /// isValidOperands - Return true if a shufflevector instruction can be |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1361 | /// formed with the specified operands. |
| 1362 | static bool isValidOperands(const Value *V1, const Value *V2, |
| 1363 | const Value *Mask); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1364 | |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1365 | virtual ShuffleVectorInst *clone() const; |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1366 | |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1367 | /// getType - Overload to return most specific vector type. |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1368 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1369 | const VectorType *getType() const { |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1370 | return reinterpret_cast<const VectorType*>(Instruction::getType()); |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1371 | } |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1372 | |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1373 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1374 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Chris Lattner | 8728f19 | 2008-03-02 05:28:33 +0000 | [diff] [blame] | 1375 | |
| 1376 | /// getMaskValue - Return the index from the shuffle mask for the specified |
| 1377 | /// output result. This is either -1 if the element is undef or a number less |
| 1378 | /// than 2*numelements. |
| 1379 | int getMaskValue(unsigned i) const; |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1380 | |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1381 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1382 | static inline bool classof(const ShuffleVectorInst *) { return true; } |
| 1383 | static inline bool classof(const Instruction *I) { |
| 1384 | return I->getOpcode() == Instruction::ShuffleVector; |
| 1385 | } |
| 1386 | static inline bool classof(const Value *V) { |
| 1387 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1388 | } |
| 1389 | }; |
| 1390 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1391 | template <> |
| 1392 | struct OperandTraits<ShuffleVectorInst> : FixedNumOperandTraits<3> { |
| 1393 | }; |
| 1394 | |
| 1395 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value) |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1396 | |
| 1397 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1398 | // PHINode Class |
| 1399 | //===----------------------------------------------------------------------===// |
| 1400 | |
| 1401 | // PHINode - The PHINode class is used to represent the magical mystical PHI |
| 1402 | // node, that can not exist in nature, but can be synthesized in a computer |
| 1403 | // scientist's overactive imagination. |
| 1404 | // |
| 1405 | class PHINode : public Instruction { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1406 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1407 | /// ReservedSpace - The number of operands actually allocated. NumOperands is |
| 1408 | /// the number actually in use. |
| 1409 | unsigned ReservedSpace; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1410 | PHINode(const PHINode &PN); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1411 | // allocate space for exactly zero operands |
| 1412 | void *operator new(size_t s) { |
| 1413 | return User::operator new(s, 0); |
| 1414 | } |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1415 | explicit PHINode(const Type *Ty, const std::string &Name = "", |
| 1416 | Instruction *InsertBefore = 0) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1417 | : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore), |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1418 | ReservedSpace(0) { |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1419 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1423 | : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd), |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1424 | ReservedSpace(0) { |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1425 | setName(Name); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1426 | } |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1427 | public: |
| 1428 | static PHINode *Create(const Type *Ty, const std::string &Name = "", |
| 1429 | Instruction *InsertBefore = 0) { |
| 1430 | return new PHINode(Ty, Name, InsertBefore); |
| 1431 | } |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1432 | static PHINode *Create(const Type *Ty, const std::string &Name, |
| 1433 | BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1434 | return new PHINode(Ty, Name, InsertAtEnd); |
| 1435 | } |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 1436 | ~PHINode(); |
| 1437 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1438 | /// reserveOperandSpace - This method can be used to avoid repeated |
| 1439 | /// reallocation of PHI operand lists by reserving space for the correct |
| 1440 | /// number of operands before adding them. Unlike normal vector reserves, |
| 1441 | /// this method can also be used to trim the operand space. |
| 1442 | void reserveOperandSpace(unsigned NumValues) { |
| 1443 | resizeOperands(NumValues*2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1446 | virtual PHINode *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1447 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1448 | /// Provide fast operand accessors |
| 1449 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 1450 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1451 | /// getNumIncomingValues - Return the number of incoming edges |
| 1452 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1453 | unsigned getNumIncomingValues() const { return getNumOperands()/2; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1454 | |
Reid Spencer | c773de6 | 2006-05-19 19:07:54 +0000 | [diff] [blame] | 1455 | /// getIncomingValue - Return incoming value number x |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1456 | /// |
| 1457 | Value *getIncomingValue(unsigned i) const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1458 | assert(i*2 < getNumOperands() && "Invalid value number!"); |
| 1459 | return getOperand(i*2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1460 | } |
| 1461 | void setIncomingValue(unsigned i, Value *V) { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1462 | assert(i*2 < getNumOperands() && "Invalid value number!"); |
| 1463 | setOperand(i*2, V); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1464 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1465 | unsigned getOperandNumForIncomingValue(unsigned i) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1466 | return i*2; |
| 1467 | } |
| 1468 | |
Reid Spencer | c773de6 | 2006-05-19 19:07:54 +0000 | [diff] [blame] | 1469 | /// getIncomingBlock - Return incoming basic block number x |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1470 | /// |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1471 | BasicBlock *getIncomingBlock(unsigned i) const { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1472 | return static_cast<BasicBlock*>(getOperand(i*2+1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1473 | } |
| 1474 | void setIncomingBlock(unsigned i, BasicBlock *BB) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1475 | setOperand(i*2+1, BB); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1476 | } |
| 1477 | unsigned getOperandNumForIncomingBlock(unsigned i) { |
| 1478 | return i*2+1; |
| 1479 | } |
| 1480 | |
| 1481 | /// addIncoming - Add an incoming value to the end of the PHI list |
| 1482 | /// |
| 1483 | void addIncoming(Value *V, BasicBlock *BB) { |
Anton Korobeynikov | 351b0d4 | 2008-02-27 22:37:28 +0000 | [diff] [blame] | 1484 | assert(V && "PHI node got a null value!"); |
| 1485 | assert(BB && "PHI node got a null basic block!"); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1486 | assert(getType() == V->getType() && |
| 1487 | "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] | 1488 | unsigned OpNo = NumOperands; |
| 1489 | if (OpNo+2 > ReservedSpace) |
| 1490 | resizeOperands(0); // Get more space! |
| 1491 | // Initialize some new operands. |
| 1492 | NumOperands = OpNo+2; |
| 1493 | OperandList[OpNo].init(V, this); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1494 | OperandList[OpNo+1].init(BB, this); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1495 | } |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1496 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1497 | /// removeIncomingValue - Remove an incoming value. This is useful if a |
| 1498 | /// predecessor basic block is deleted. The value removed is returned. |
| 1499 | /// |
| 1500 | /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty |
| 1501 | /// is true), the PHI node is destroyed and any uses of it are replaced with |
| 1502 | /// dummy values. The only time there should be zero incoming values to a PHI |
| 1503 | /// node is when the block is dead, so this strategy is sound. |
| 1504 | /// |
| 1505 | Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true); |
| 1506 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1507 | Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1508 | int Idx = getBasicBlockIndex(BB); |
| 1509 | assert(Idx >= 0 && "Invalid basic block argument to remove!"); |
| 1510 | return removeIncomingValue(Idx, DeletePHIIfEmpty); |
| 1511 | } |
| 1512 | |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1513 | /// getBasicBlockIndex - Return the first index of the specified basic |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1514 | /// block in the value list for this PHI. Returns -1 if no instance. |
| 1515 | /// |
| 1516 | int getBasicBlockIndex(const BasicBlock *BB) const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1517 | Use *OL = OperandList; |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1518 | for (unsigned i = 0, e = getNumOperands(); i != e; i += 2) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1519 | if (OL[i+1].get() == BB) return i/2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1520 | return -1; |
| 1521 | } |
| 1522 | |
| 1523 | Value *getIncomingValueForBlock(const BasicBlock *BB) const { |
| 1524 | return getIncomingValue(getBasicBlockIndex(BB)); |
| 1525 | } |
| 1526 | |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1527 | /// hasConstantValue - If the specified PHI node always merges together the |
Nate Begeman | a83ba0f | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 1528 | /// same value, return the value, otherwise return null. |
| 1529 | /// |
Chris Lattner | 9acbd61 | 2005-08-05 00:49:06 +0000 | [diff] [blame] | 1530 | Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const; |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1531 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1532 | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1533 | static inline bool classof(const PHINode *) { return true; } |
| 1534 | static inline bool classof(const Instruction *I) { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1535 | return I->getOpcode() == Instruction::PHI; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1536 | } |
| 1537 | static inline bool classof(const Value *V) { |
| 1538 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1539 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1540 | private: |
| 1541 | void resizeOperands(unsigned NumOperands); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1542 | }; |
| 1543 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1544 | template <> |
| 1545 | struct OperandTraits<PHINode> : HungoffOperandTraits<2> { |
| 1546 | }; |
| 1547 | |
| 1548 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value) |
| 1549 | |
| 1550 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1551 | //===----------------------------------------------------------------------===// |
| 1552 | // ReturnInst Class |
| 1553 | //===----------------------------------------------------------------------===// |
| 1554 | |
| 1555 | //===--------------------------------------------------------------------------- |
| 1556 | /// ReturnInst - Return a value (possibly void), from a function. Execution |
| 1557 | /// does not continue in this function any longer. |
| 1558 | /// |
| 1559 | class ReturnInst : public TerminatorInst { |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1560 | ReturnInst(const ReturnInst &RI); |
Devang Patel | fea9830 | 2008-02-26 19:15:26 +0000 | [diff] [blame] | 1561 | void init(Value * const* retVals, unsigned N); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1562 | |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1563 | private: |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1564 | // ReturnInst constructors: |
| 1565 | // ReturnInst() - 'ret void' instruction |
Alkis Evlogimenos | 859804f | 2004-11-17 21:02:25 +0000 | [diff] [blame] | 1566 | // ReturnInst( null) - 'ret void' instruction |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1567 | // ReturnInst(Value* X) - 'ret X' instruction |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1568 | // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1569 | // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1570 | // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B |
| 1571 | // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B |
Devang Patel | e6be34a | 2008-02-27 01:20:54 +0000 | [diff] [blame] | 1572 | // ReturnInst(Value* X, N) - 'ret X,X+1...X+N-1' instruction |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1573 | // ReturnInst(Value* X, N, Inst *I) - 'ret X,X+1...X+N-1', insert before I |
| 1574 | // ReturnInst(Value* X, N, BB *B) - 'ret X,X+1...X+N-1', insert @ end of B |
Alkis Evlogimenos | 859804f | 2004-11-17 21:02:25 +0000 | [diff] [blame] | 1575 | // |
| 1576 | // NOTE: If the Value* passed is of type void then the constructor behaves as |
| 1577 | // if it was passed NULL. |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1578 | explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0); |
| 1579 | ReturnInst(Value *retVal, BasicBlock *InsertAtEnd); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1580 | ReturnInst(Value * const* retVals, unsigned N, Instruction *InsertBefore = 0); |
Devang Patel | f4511cd | 2008-02-26 19:38:17 +0000 | [diff] [blame] | 1581 | ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd); |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1582 | explicit ReturnInst(BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1583 | public: |
| 1584 | static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) { |
| 1585 | return new(!!retVal) ReturnInst(retVal, InsertBefore); |
| 1586 | } |
| 1587 | static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) { |
| 1588 | return new(!!retVal) ReturnInst(retVal, InsertAtEnd); |
| 1589 | } |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1590 | static ReturnInst* Create(Value * const* retVals, unsigned N, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1591 | Instruction *InsertBefore = 0) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1592 | return new(N) ReturnInst(retVals, N, InsertBefore); |
| 1593 | } |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1594 | static ReturnInst* Create(Value * const* retVals, unsigned N, |
| 1595 | BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1596 | return new(N) ReturnInst(retVals, N, InsertAtEnd); |
| 1597 | } |
| 1598 | static ReturnInst* Create(BasicBlock *InsertAtEnd) { |
| 1599 | return new(0) ReturnInst(InsertAtEnd); |
| 1600 | } |
Devang Patel | 57ef4f4 | 2008-02-23 00:35:18 +0000 | [diff] [blame] | 1601 | virtual ~ReturnInst(); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1602 | inline void operator delete(void*); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1603 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1604 | virtual ReturnInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1605 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1606 | /// Provide fast operand accessors |
| 1607 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Devang Patel | 64d4e61 | 2008-02-26 17:56:20 +0000 | [diff] [blame] | 1608 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1609 | /// Convenience accessor |
Devang Patel | 1eafa06 | 2008-03-11 17:35:03 +0000 | [diff] [blame] | 1610 | Value *getReturnValue(unsigned n = 0) const { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1611 | return n < getNumOperands() |
| 1612 | ? getOperand(n) |
| 1613 | : 0; |
Devang Patel | 1eafa06 | 2008-03-11 17:35:03 +0000 | [diff] [blame] | 1614 | } |
| 1615 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1616 | unsigned getNumSuccessors() const { return 0; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1617 | |
| 1618 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1619 | static inline bool classof(const ReturnInst *) { return true; } |
| 1620 | static inline bool classof(const Instruction *I) { |
| 1621 | return (I->getOpcode() == Instruction::Ret); |
| 1622 | } |
| 1623 | static inline bool classof(const Value *V) { |
| 1624 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1625 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1626 | private: |
| 1627 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 1628 | virtual unsigned getNumSuccessorsV() const; |
| 1629 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1630 | }; |
| 1631 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1632 | template <> |
| 1633 | struct OperandTraits<ReturnInst> : VariadicOperandTraits<> { |
| 1634 | }; |
| 1635 | |
| 1636 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value) |
| 1637 | void ReturnInst::operator delete(void *it) { |
| 1638 | ReturnInst* me(static_cast<ReturnInst*>(it)); |
| 1639 | Use::zap(OperandTraits<ReturnInst>::op_begin(me), |
| 1640 | OperandTraits<ReturnInst>::op_end(me), |
| 1641 | true); |
| 1642 | } |
| 1643 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1644 | //===----------------------------------------------------------------------===// |
| 1645 | // BranchInst Class |
| 1646 | //===----------------------------------------------------------------------===// |
| 1647 | |
| 1648 | //===--------------------------------------------------------------------------- |
| 1649 | /// BranchInst - Conditional or Unconditional Branch instruction. |
| 1650 | /// |
| 1651 | class BranchInst : public TerminatorInst { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1652 | /// Ops list - Branches are strange. The operands are ordered: |
| 1653 | /// TrueDest, FalseDest, Cond. This makes some accessors faster because |
| 1654 | /// they don't have to check for cond/uncond branchness. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1655 | BranchInst(const BranchInst &BI); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1656 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1657 | // BranchInst constructors (where {B, T, F} are blocks, and C is a condition): |
| 1658 | // BranchInst(BB *B) - 'br B' |
| 1659 | // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F' |
| 1660 | // BranchInst(BB* B, Inst *I) - 'br B' insert before I |
| 1661 | // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I |
| 1662 | // BranchInst(BB* B, BB *I) - 'br B' insert at end |
| 1663 | // 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] | 1664 | explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1665 | BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1666 | Instruction *InsertBefore = 0); |
| 1667 | BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1668 | BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1669 | BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1670 | public: |
| 1671 | static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) { |
| 1672 | return new(1) BranchInst(IfTrue, InsertBefore); |
| 1673 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1674 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, |
| 1675 | Value *Cond, Instruction *InsertBefore = 0) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1676 | return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore); |
| 1677 | } |
| 1678 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) { |
| 1679 | return new(1) BranchInst(IfTrue, InsertAtEnd); |
| 1680 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1681 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, |
| 1682 | Value *Cond, BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1683 | return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd); |
| 1684 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1685 | |
Bill Wendling | d2a5a2a | 2008-05-10 10:58:07 +0000 | [diff] [blame^] | 1686 | ~BranchInst() { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1687 | if (NumOperands == 1) |
Bill Wendling | d2a5a2a | 2008-05-10 10:58:07 +0000 | [diff] [blame^] | 1688 | NumOperands = (unsigned)(uintptr_t)((Use*)this - OperandList); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1691 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1692 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1693 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1694 | virtual BranchInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1695 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1696 | bool isUnconditional() const { return getNumOperands() == 1; } |
| 1697 | bool isConditional() const { return getNumOperands() == 3; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1698 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1699 | Value *getCondition() const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1700 | assert(isConditional() && "Cannot get condition of an uncond branch!"); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1701 | return getOperand(2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | void setCondition(Value *V) { |
| 1705 | assert(isConditional() && "Cannot set condition of unconditional branch!"); |
| 1706 | setOperand(2, V); |
| 1707 | } |
| 1708 | |
| 1709 | // setUnconditionalDest - Change the current branch to an unconditional branch |
| 1710 | // targeting the specified block. |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1711 | // FIXME: Eliminate this ugly method. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1712 | void setUnconditionalDest(BasicBlock *Dest) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1713 | Op<0>() = Dest; |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1714 | if (isConditional()) { // Convert this to an uncond branch. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1715 | Op<1>().set(0); |
| 1716 | Op<2>().set(0); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1717 | NumOperands = 1; |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1718 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1721 | unsigned getNumSuccessors() const { return 1+isConditional(); } |
| 1722 | |
| 1723 | BasicBlock *getSuccessor(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1724 | assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); |
Dan Gohman | b96039e | 2007-05-11 20:59:29 +0000 | [diff] [blame] | 1725 | return cast<BasicBlock>(getOperand(i)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1728 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1729 | assert(idx < getNumSuccessors() && "Successor # out of range for Branch!"); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1730 | setOperand(idx, NewSucc); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1731 | } |
| 1732 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1733 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1734 | static inline bool classof(const BranchInst *) { return true; } |
| 1735 | static inline bool classof(const Instruction *I) { |
| 1736 | return (I->getOpcode() == Instruction::Br); |
| 1737 | } |
| 1738 | static inline bool classof(const Value *V) { |
| 1739 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1740 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1741 | private: |
| 1742 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 1743 | virtual unsigned getNumSuccessorsV() const; |
| 1744 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1745 | }; |
| 1746 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1747 | template <> |
| 1748 | struct OperandTraits<BranchInst> : HungoffOperandTraits<> { |
| 1749 | // we need to access operands via OperandList, since |
| 1750 | // the NumOperands may change from 3 to 1 |
| 1751 | static inline void *allocate(unsigned); // FIXME |
| 1752 | }; |
| 1753 | |
| 1754 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value) |
| 1755 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1756 | //===----------------------------------------------------------------------===// |
| 1757 | // SwitchInst Class |
| 1758 | //===----------------------------------------------------------------------===// |
| 1759 | |
| 1760 | //===--------------------------------------------------------------------------- |
| 1761 | /// SwitchInst - Multiway switch |
| 1762 | /// |
| 1763 | class SwitchInst : public TerminatorInst { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1764 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1765 | unsigned ReservedSpace; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1766 | // Operand[0] = Value to switch on |
| 1767 | // Operand[1] = Default basic block destination |
| 1768 | // Operand[2n ] = Value to match |
| 1769 | // Operand[2n+1] = BasicBlock to go to on match |
| 1770 | SwitchInst(const SwitchInst &RI); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1771 | void init(Value *Value, BasicBlock *Default, unsigned NumCases); |
| 1772 | void resizeOperands(unsigned No); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1773 | // allocate space for exactly zero operands |
| 1774 | void *operator new(size_t s) { |
| 1775 | return User::operator new(s, 0); |
| 1776 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1777 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to |
| 1778 | /// switch on and a default destination. The number of additional cases can |
| 1779 | /// be specified here to make memory allocation more efficient. This |
| 1780 | /// constructor can also autoinsert before another instruction. |
| 1781 | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1782 | Instruction *InsertBefore = 0); |
| 1783 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1784 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to |
| 1785 | /// switch on and a default destination. The number of additional cases can |
| 1786 | /// be specified here to make memory allocation more efficient. This |
| 1787 | /// constructor also autoinserts at the end of the specified BasicBlock. |
| 1788 | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1789 | BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1790 | public: |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1791 | static SwitchInst *Create(Value *Value, BasicBlock *Default, |
| 1792 | unsigned NumCases, Instruction *InsertBefore = 0) { |
| 1793 | return new SwitchInst(Value, Default, NumCases, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1794 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1795 | static SwitchInst *Create(Value *Value, BasicBlock *Default, |
| 1796 | unsigned NumCases, BasicBlock *InsertAtEnd) { |
| 1797 | return new SwitchInst(Value, Default, NumCases, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1798 | } |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 1799 | ~SwitchInst(); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1800 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1801 | /// Provide fast operand accessors |
| 1802 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 1803 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1804 | // Accessor Methods for Switch stmt |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1805 | Value *getCondition() const { return getOperand(0); } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1806 | void setCondition(Value *V) { setOperand(0, V); } |
Chris Lattner | bfaf88a | 2004-12-10 20:35:47 +0000 | [diff] [blame] | 1807 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1808 | BasicBlock *getDefaultDest() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1809 | return cast<BasicBlock>(getOperand(1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | /// getNumCases - return the number of 'cases' in this switch instruction. |
| 1813 | /// Note that case #0 is always the default case. |
| 1814 | unsigned getNumCases() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1815 | return getNumOperands()/2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | /// getCaseValue - Return the specified case value. Note that case #0, the |
| 1819 | /// default destination, does not have a case value. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 1820 | ConstantInt *getCaseValue(unsigned i) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1821 | assert(i && i < getNumCases() && "Illegal case value to get!"); |
| 1822 | return getSuccessorValue(i); |
| 1823 | } |
| 1824 | |
| 1825 | /// getCaseValue - Return the specified case value. Note that case #0, the |
| 1826 | /// default destination, does not have a case value. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 1827 | const ConstantInt *getCaseValue(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1828 | assert(i && i < getNumCases() && "Illegal case value to get!"); |
| 1829 | return getSuccessorValue(i); |
| 1830 | } |
| 1831 | |
| 1832 | /// findCaseValue - Search all of the case values for the specified constant. |
| 1833 | /// If it is explicitly handled, return the case number of it, otherwise |
| 1834 | /// return 0 to indicate that it is handled by the default handler. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 1835 | unsigned findCaseValue(const ConstantInt *C) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1836 | for (unsigned i = 1, e = getNumCases(); i != e; ++i) |
| 1837 | if (getCaseValue(i) == C) |
| 1838 | return i; |
| 1839 | return 0; |
| 1840 | } |
| 1841 | |
Nick Lewycky | 011f184 | 2006-09-18 19:03:59 +0000 | [diff] [blame] | 1842 | /// findCaseDest - Finds the unique case value for a given successor. Returns |
| 1843 | /// null if the successor is not found, not unique, or is the default case. |
| 1844 | ConstantInt *findCaseDest(BasicBlock *BB) { |
Nick Lewycky | d791544 | 2006-09-18 20:44:37 +0000 | [diff] [blame] | 1845 | if (BB == getDefaultDest()) return NULL; |
| 1846 | |
Nick Lewycky | 011f184 | 2006-09-18 19:03:59 +0000 | [diff] [blame] | 1847 | ConstantInt *CI = NULL; |
| 1848 | for (unsigned i = 1, e = getNumCases(); i != e; ++i) { |
| 1849 | if (getSuccessor(i) == BB) { |
| 1850 | if (CI) return NULL; // Multiple cases lead to BB. |
| 1851 | else CI = getCaseValue(i); |
| 1852 | } |
| 1853 | } |
| 1854 | return CI; |
| 1855 | } |
| 1856 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1857 | /// addCase - Add an entry to the switch instruction... |
| 1858 | /// |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 1859 | void addCase(ConstantInt *OnVal, BasicBlock *Dest); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1860 | |
| 1861 | /// removeCase - This method removes the specified successor from the switch |
| 1862 | /// instruction. Note that this cannot be used to remove the default |
| 1863 | /// destination (successor #0). |
| 1864 | /// |
| 1865 | void removeCase(unsigned idx); |
| 1866 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1867 | virtual SwitchInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1868 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1869 | unsigned getNumSuccessors() const { return getNumOperands()/2; } |
| 1870 | BasicBlock *getSuccessor(unsigned idx) const { |
| 1871 | assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!"); |
| 1872 | return cast<BasicBlock>(getOperand(idx*2+1)); |
| 1873 | } |
| 1874 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1875 | assert(idx < getNumSuccessors() && "Successor # out of range for switch!"); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1876 | setOperand(idx*2+1, NewSucc); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1877 | } |
| 1878 | |
| 1879 | // getSuccessorValue - Return the value associated with the specified |
| 1880 | // successor. |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1881 | ConstantInt *getSuccessorValue(unsigned idx) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1882 | assert(idx < getNumSuccessors() && "Successor # out of range!"); |
Reid Spencer | edd5d9e | 2005-05-15 16:13:11 +0000 | [diff] [blame] | 1883 | return reinterpret_cast<ConstantInt*>(getOperand(idx*2)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1884 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1885 | |
| 1886 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1887 | static inline bool classof(const SwitchInst *) { return true; } |
| 1888 | static inline bool classof(const Instruction *I) { |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 1889 | return I->getOpcode() == Instruction::Switch; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1890 | } |
| 1891 | static inline bool classof(const Value *V) { |
| 1892 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1893 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1894 | private: |
| 1895 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 1896 | virtual unsigned getNumSuccessorsV() const; |
| 1897 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1898 | }; |
| 1899 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1900 | template <> |
| 1901 | struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> { |
| 1902 | }; |
| 1903 | |
| 1904 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value) |
| 1905 | |
| 1906 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1907 | //===----------------------------------------------------------------------===// |
| 1908 | // InvokeInst Class |
| 1909 | //===----------------------------------------------------------------------===// |
| 1910 | |
| 1911 | //===--------------------------------------------------------------------------- |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 1912 | |
| 1913 | /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the |
| 1914 | /// calling convention of the call. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1915 | /// |
| 1916 | class InvokeInst : public TerminatorInst { |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 1917 | PAListPtr ParamAttrs; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1918 | InvokeInst(const InvokeInst &BI); |
| 1919 | void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, |
Chris Lattner | d2dd150 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 1920 | Value* const *Args, unsigned NumArgs); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 1921 | |
| 1922 | template<typename InputIterator> |
| 1923 | void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
| 1924 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 1925 | const std::string &Name, |
| 1926 | // This argument ensures that we have an iterator we can |
| 1927 | // do arithmetic on in constant time |
| 1928 | std::random_access_iterator_tag) { |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 1929 | unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 1930 | |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 1931 | // This requires that the iterator points to contiguous memory. |
| 1932 | init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 1933 | setName(Name); |
| 1934 | } |
| 1935 | |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 1936 | /// Construct an InvokeInst given a range of arguments. |
| 1937 | /// InputIterator must be a random-access iterator pointing to |
| 1938 | /// contiguous storage (e.g. a std::vector<>::iterator). Checks are |
| 1939 | /// made for random-accessness but not for contiguous storage as |
| 1940 | /// that would incur runtime overhead. |
| 1941 | /// |
| 1942 | /// @brief Construct an InvokeInst from a range of arguments |
| 1943 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1944 | inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
| 1945 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 1946 | unsigned Values, |
| 1947 | const std::string &Name, Instruction *InsertBefore); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 1948 | |
| 1949 | /// Construct an InvokeInst given a range of arguments. |
| 1950 | /// InputIterator must be a random-access iterator pointing to |
| 1951 | /// contiguous storage (e.g. a std::vector<>::iterator). Checks are |
| 1952 | /// made for random-accessness but not for contiguous storage as |
| 1953 | /// that would incur runtime overhead. |
| 1954 | /// |
| 1955 | /// @brief Construct an InvokeInst from a range of arguments |
| 1956 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1957 | inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
| 1958 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 1959 | unsigned Values, |
| 1960 | const std::string &Name, BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1961 | public: |
| 1962 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1963 | static InvokeInst *Create(Value *Func, |
| 1964 | BasicBlock *IfNormal, BasicBlock *IfException, |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1965 | InputIterator ArgBegin, InputIterator ArgEnd, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1966 | const std::string &Name = "", |
| 1967 | Instruction *InsertBefore = 0) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1968 | unsigned Values(ArgEnd - ArgBegin + 3); |
| 1969 | return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, |
| 1970 | Values, Name, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1971 | } |
| 1972 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1973 | static InvokeInst *Create(Value *Func, |
| 1974 | BasicBlock *IfNormal, BasicBlock *IfException, |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1975 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 1976 | const std::string &Name, BasicBlock *InsertAtEnd) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1977 | unsigned Values(ArgEnd - ArgBegin + 3); |
| 1978 | return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, |
| 1979 | Values, Name, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1980 | } |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 1981 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1982 | virtual InvokeInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1983 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1984 | /// Provide fast operand accessors |
| 1985 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 1986 | |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 1987 | /// getCallingConv/setCallingConv - Get or set the calling convention of this |
| 1988 | /// function call. |
| 1989 | unsigned getCallingConv() const { return SubclassData; } |
| 1990 | void setCallingConv(unsigned CC) { |
| 1991 | SubclassData = CC; |
| 1992 | } |
| 1993 | |
Chris Lattner | 041221c | 2008-03-13 04:33:03 +0000 | [diff] [blame] | 1994 | /// getParamAttrs - Return the parameter attributes for this invoke. |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 1995 | /// |
| 1996 | const PAListPtr &getParamAttrs() const { return ParamAttrs; } |
Reid Spencer | fa3e912 | 2007-04-09 18:00:57 +0000 | [diff] [blame] | 1997 | |
Chris Lattner | 041221c | 2008-03-13 04:33:03 +0000 | [diff] [blame] | 1998 | /// setParamAttrs - Set the parameter attributes for this invoke. |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 1999 | /// |
| 2000 | void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; } |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 2001 | |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 2002 | /// @brief Determine whether the call or the callee has the given attribute. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2003 | bool paramHasAttr(unsigned i, ParameterAttributes attr) const; |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 2004 | |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 2005 | /// @brief Extract the alignment for a call or parameter (0=unknown). |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2006 | unsigned getParamAlignment(unsigned i) const { |
| 2007 | return ParamAttrs.getParamAlignment(i); |
| 2008 | } |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 2009 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2010 | /// @brief Determine if the call does not access memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2011 | bool doesNotAccessMemory() const { |
| 2012 | return paramHasAttr(0, ParamAttr::ReadNone); |
| 2013 | } |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2014 | |
| 2015 | /// @brief Determine if the call does not access or only reads memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2016 | bool onlyReadsMemory() const { |
| 2017 | return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly); |
| 2018 | } |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2019 | |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 2020 | /// @brief Determine if the call cannot return. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2021 | bool doesNotReturn() const { |
| 2022 | return paramHasAttr(0, ParamAttr::NoReturn); |
| 2023 | } |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 2024 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2025 | /// @brief Determine if the call cannot unwind. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2026 | bool doesNotThrow() const { |
| 2027 | return paramHasAttr(0, ParamAttr::NoUnwind); |
| 2028 | } |
Duncan Sands | f0c3354 | 2007-12-19 21:13:37 +0000 | [diff] [blame] | 2029 | void setDoesNotThrow(bool doesNotThrow = true); |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2030 | |
Devang Patel | 41e2397 | 2008-03-03 21:46:28 +0000 | [diff] [blame] | 2031 | /// @brief Determine if the call returns a structure through first |
| 2032 | /// pointer argument. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2033 | bool hasStructRetAttr() const { |
| 2034 | // Be friendly and also check the callee. |
| 2035 | return paramHasAttr(1, ParamAttr::StructRet); |
| 2036 | } |
Reid Spencer | fa3e912 | 2007-04-09 18:00:57 +0000 | [diff] [blame] | 2037 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2038 | /// getCalledFunction - Return the function called, or null if this is an |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 2039 | /// indirect function invocation. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2040 | /// |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 2041 | Function *getCalledFunction() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2042 | return dyn_cast<Function>(getOperand(0)); |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 2043 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2044 | |
| 2045 | // getCalledValue - Get a pointer to a function that is invoked by this inst. |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2046 | Value *getCalledValue() const { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2047 | |
| 2048 | // get*Dest - Return the destination basic blocks... |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2049 | BasicBlock *getNormalDest() const { |
| 2050 | return cast<BasicBlock>(getOperand(1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2051 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2052 | BasicBlock *getUnwindDest() const { |
| 2053 | return cast<BasicBlock>(getOperand(2)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2054 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2055 | void setNormalDest(BasicBlock *B) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2056 | setOperand(1, B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2059 | void setUnwindDest(BasicBlock *B) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2060 | setOperand(2, B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2063 | BasicBlock *getSuccessor(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2064 | assert(i < 2 && "Successor # out of range for invoke!"); |
| 2065 | return i == 0 ? getNormalDest() : getUnwindDest(); |
| 2066 | } |
| 2067 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2068 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2069 | assert(idx < 2 && "Successor # out of range for invoke!"); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2070 | setOperand(idx+1, NewSucc); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2071 | } |
| 2072 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2073 | unsigned getNumSuccessors() const { return 2; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2074 | |
| 2075 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2076 | static inline bool classof(const InvokeInst *) { return true; } |
| 2077 | static inline bool classof(const Instruction *I) { |
| 2078 | return (I->getOpcode() == Instruction::Invoke); |
| 2079 | } |
| 2080 | static inline bool classof(const Value *V) { |
| 2081 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2082 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2083 | private: |
| 2084 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2085 | virtual unsigned getNumSuccessorsV() const; |
| 2086 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2087 | }; |
| 2088 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2089 | template <> |
| 2090 | struct OperandTraits<InvokeInst> : VariadicOperandTraits<3> { |
| 2091 | }; |
| 2092 | |
| 2093 | template<typename InputIterator> |
| 2094 | InvokeInst::InvokeInst(Value *Func, |
| 2095 | BasicBlock *IfNormal, BasicBlock *IfException, |
| 2096 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2097 | unsigned Values, |
| 2098 | const std::string &Name, Instruction *InsertBefore) |
| 2099 | : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 2100 | ->getElementType())->getReturnType(), |
| 2101 | Instruction::Invoke, |
| 2102 | OperandTraits<InvokeInst>::op_end(this) - Values, |
| 2103 | Values, InsertBefore) { |
| 2104 | init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, |
| 2105 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 2106 | } |
| 2107 | template<typename InputIterator> |
| 2108 | InvokeInst::InvokeInst(Value *Func, |
| 2109 | BasicBlock *IfNormal, BasicBlock *IfException, |
| 2110 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2111 | unsigned Values, |
| 2112 | const std::string &Name, BasicBlock *InsertAtEnd) |
| 2113 | : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 2114 | ->getElementType())->getReturnType(), |
| 2115 | Instruction::Invoke, |
| 2116 | OperandTraits<InvokeInst>::op_end(this) - Values, |
| 2117 | Values, InsertAtEnd) { |
| 2118 | init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, |
| 2119 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 2120 | } |
| 2121 | |
| 2122 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value) |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2123 | |
| 2124 | //===----------------------------------------------------------------------===// |
| 2125 | // UnwindInst Class |
| 2126 | //===----------------------------------------------------------------------===// |
| 2127 | |
| 2128 | //===--------------------------------------------------------------------------- |
| 2129 | /// UnwindInst - Immediately exit the current function, unwinding the stack |
| 2130 | /// until an invoke instruction is found. |
| 2131 | /// |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2132 | class UnwindInst : public TerminatorInst { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2133 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2134 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2135 | // allocate space for exactly zero operands |
| 2136 | void *operator new(size_t s) { |
| 2137 | return User::operator new(s, 0); |
| 2138 | } |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2139 | explicit UnwindInst(Instruction *InsertBefore = 0); |
| 2140 | explicit UnwindInst(BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2141 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 2142 | virtual UnwindInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2143 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2144 | unsigned getNumSuccessors() const { return 0; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2145 | |
| 2146 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2147 | static inline bool classof(const UnwindInst *) { return true; } |
| 2148 | static inline bool classof(const Instruction *I) { |
| 2149 | return I->getOpcode() == Instruction::Unwind; |
| 2150 | } |
| 2151 | static inline bool classof(const Value *V) { |
| 2152 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2153 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2154 | private: |
| 2155 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2156 | virtual unsigned getNumSuccessorsV() const; |
| 2157 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2158 | }; |
| 2159 | |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2160 | //===----------------------------------------------------------------------===// |
| 2161 | // UnreachableInst Class |
| 2162 | //===----------------------------------------------------------------------===// |
| 2163 | |
| 2164 | //===--------------------------------------------------------------------------- |
| 2165 | /// UnreachableInst - This function has undefined behavior. In particular, the |
| 2166 | /// presence of this instruction indicates some higher level knowledge that the |
| 2167 | /// end of the block cannot be reached. |
| 2168 | /// |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2169 | class UnreachableInst : public TerminatorInst { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2170 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2171 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2172 | // allocate space for exactly zero operands |
| 2173 | void *operator new(size_t s) { |
| 2174 | return User::operator new(s, 0); |
| 2175 | } |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2176 | explicit UnreachableInst(Instruction *InsertBefore = 0); |
| 2177 | explicit UnreachableInst(BasicBlock *InsertAtEnd); |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2178 | |
| 2179 | virtual UnreachableInst *clone() const; |
| 2180 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2181 | unsigned getNumSuccessors() const { return 0; } |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2182 | |
| 2183 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2184 | static inline bool classof(const UnreachableInst *) { return true; } |
| 2185 | static inline bool classof(const Instruction *I) { |
| 2186 | return I->getOpcode() == Instruction::Unreachable; |
| 2187 | } |
| 2188 | static inline bool classof(const Value *V) { |
| 2189 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2190 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2191 | private: |
| 2192 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2193 | virtual unsigned getNumSuccessorsV() const; |
| 2194 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2195 | }; |
| 2196 | |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2197 | //===----------------------------------------------------------------------===// |
| 2198 | // TruncInst Class |
| 2199 | //===----------------------------------------------------------------------===// |
| 2200 | |
| 2201 | /// @brief This class represents a truncation of integer types. |
| 2202 | class TruncInst : public CastInst { |
| 2203 | /// Private copy constructor |
| 2204 | TruncInst(const TruncInst &CI) |
| 2205 | : CastInst(CI.getType(), Trunc, CI.getOperand(0)) { |
| 2206 | } |
| 2207 | public: |
| 2208 | /// @brief Constructor with insert-before-instruction semantics |
| 2209 | TruncInst( |
| 2210 | Value *S, ///< The value to be truncated |
| 2211 | const Type *Ty, ///< The (smaller) type to truncate to |
| 2212 | const std::string &Name = "", ///< A name for the new instruction |
| 2213 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2214 | ); |
| 2215 | |
| 2216 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2217 | TruncInst( |
| 2218 | Value *S, ///< The value to be truncated |
| 2219 | const Type *Ty, ///< The (smaller) type to truncate to |
| 2220 | const std::string &Name, ///< A name for the new instruction |
| 2221 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2222 | ); |
| 2223 | |
| 2224 | /// @brief Clone an identical TruncInst |
| 2225 | virtual CastInst *clone() const; |
| 2226 | |
| 2227 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2228 | static inline bool classof(const TruncInst *) { return true; } |
| 2229 | static inline bool classof(const Instruction *I) { |
| 2230 | return I->getOpcode() == Trunc; |
| 2231 | } |
| 2232 | static inline bool classof(const Value *V) { |
| 2233 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2234 | } |
| 2235 | }; |
| 2236 | |
| 2237 | //===----------------------------------------------------------------------===// |
| 2238 | // ZExtInst Class |
| 2239 | //===----------------------------------------------------------------------===// |
| 2240 | |
| 2241 | /// @brief This class represents zero extension of integer types. |
| 2242 | class ZExtInst : public CastInst { |
| 2243 | /// @brief Private copy constructor |
| 2244 | ZExtInst(const ZExtInst &CI) |
| 2245 | : CastInst(CI.getType(), ZExt, CI.getOperand(0)) { |
| 2246 | } |
| 2247 | public: |
| 2248 | /// @brief Constructor with insert-before-instruction semantics |
| 2249 | ZExtInst( |
| 2250 | Value *S, ///< The value to be zero extended |
| 2251 | const Type *Ty, ///< The type to zero extend to |
| 2252 | const std::string &Name = "", ///< A name for the new instruction |
| 2253 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2254 | ); |
| 2255 | |
| 2256 | /// @brief Constructor with insert-at-end semantics. |
| 2257 | ZExtInst( |
| 2258 | Value *S, ///< The value to be zero extended |
| 2259 | const Type *Ty, ///< The type to zero extend to |
| 2260 | const std::string &Name, ///< A name for the new instruction |
| 2261 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2262 | ); |
| 2263 | |
| 2264 | /// @brief Clone an identical ZExtInst |
| 2265 | virtual CastInst *clone() const; |
| 2266 | |
| 2267 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2268 | static inline bool classof(const ZExtInst *) { return true; } |
| 2269 | static inline bool classof(const Instruction *I) { |
| 2270 | return I->getOpcode() == ZExt; |
| 2271 | } |
| 2272 | static inline bool classof(const Value *V) { |
| 2273 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2274 | } |
| 2275 | }; |
| 2276 | |
| 2277 | //===----------------------------------------------------------------------===// |
| 2278 | // SExtInst Class |
| 2279 | //===----------------------------------------------------------------------===// |
| 2280 | |
| 2281 | /// @brief This class represents a sign extension of integer types. |
| 2282 | class SExtInst : public CastInst { |
| 2283 | /// @brief Private copy constructor |
| 2284 | SExtInst(const SExtInst &CI) |
| 2285 | : CastInst(CI.getType(), SExt, CI.getOperand(0)) { |
| 2286 | } |
| 2287 | public: |
| 2288 | /// @brief Constructor with insert-before-instruction semantics |
| 2289 | SExtInst( |
| 2290 | Value *S, ///< The value to be sign extended |
| 2291 | const Type *Ty, ///< The type to sign extend to |
| 2292 | const std::string &Name = "", ///< A name for the new instruction |
| 2293 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2294 | ); |
| 2295 | |
| 2296 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2297 | SExtInst( |
| 2298 | Value *S, ///< The value to be sign extended |
| 2299 | const Type *Ty, ///< The type to sign extend to |
| 2300 | const std::string &Name, ///< A name for the new instruction |
| 2301 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2302 | ); |
| 2303 | |
| 2304 | /// @brief Clone an identical SExtInst |
| 2305 | virtual CastInst *clone() const; |
| 2306 | |
| 2307 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2308 | static inline bool classof(const SExtInst *) { return true; } |
| 2309 | static inline bool classof(const Instruction *I) { |
| 2310 | return I->getOpcode() == SExt; |
| 2311 | } |
| 2312 | static inline bool classof(const Value *V) { |
| 2313 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2314 | } |
| 2315 | }; |
| 2316 | |
| 2317 | //===----------------------------------------------------------------------===// |
| 2318 | // FPTruncInst Class |
| 2319 | //===----------------------------------------------------------------------===// |
| 2320 | |
| 2321 | /// @brief This class represents a truncation of floating point types. |
| 2322 | class FPTruncInst : public CastInst { |
| 2323 | FPTruncInst(const FPTruncInst &CI) |
| 2324 | : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) { |
| 2325 | } |
| 2326 | public: |
| 2327 | /// @brief Constructor with insert-before-instruction semantics |
| 2328 | FPTruncInst( |
| 2329 | Value *S, ///< The value to be truncated |
| 2330 | const Type *Ty, ///< The type to truncate to |
| 2331 | const std::string &Name = "", ///< A name for the new instruction |
| 2332 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2333 | ); |
| 2334 | |
| 2335 | /// @brief Constructor with insert-before-instruction semantics |
| 2336 | FPTruncInst( |
| 2337 | Value *S, ///< The value to be truncated |
| 2338 | const Type *Ty, ///< The type to truncate to |
| 2339 | const std::string &Name, ///< A name for the new instruction |
| 2340 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2341 | ); |
| 2342 | |
| 2343 | /// @brief Clone an identical FPTruncInst |
| 2344 | virtual CastInst *clone() const; |
| 2345 | |
| 2346 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2347 | static inline bool classof(const FPTruncInst *) { return true; } |
| 2348 | static inline bool classof(const Instruction *I) { |
| 2349 | return I->getOpcode() == FPTrunc; |
| 2350 | } |
| 2351 | static inline bool classof(const Value *V) { |
| 2352 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2353 | } |
| 2354 | }; |
| 2355 | |
| 2356 | //===----------------------------------------------------------------------===// |
| 2357 | // FPExtInst Class |
| 2358 | //===----------------------------------------------------------------------===// |
| 2359 | |
| 2360 | /// @brief This class represents an extension of floating point types. |
| 2361 | class FPExtInst : public CastInst { |
| 2362 | FPExtInst(const FPExtInst &CI) |
| 2363 | : CastInst(CI.getType(), FPExt, CI.getOperand(0)) { |
| 2364 | } |
| 2365 | public: |
| 2366 | /// @brief Constructor with insert-before-instruction semantics |
| 2367 | FPExtInst( |
| 2368 | Value *S, ///< The value to be extended |
| 2369 | const Type *Ty, ///< The type to extend to |
| 2370 | const std::string &Name = "", ///< A name for the new instruction |
| 2371 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2372 | ); |
| 2373 | |
| 2374 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2375 | FPExtInst( |
| 2376 | Value *S, ///< The value to be extended |
| 2377 | const Type *Ty, ///< The type to extend to |
| 2378 | const std::string &Name, ///< A name for the new instruction |
| 2379 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2380 | ); |
| 2381 | |
| 2382 | /// @brief Clone an identical FPExtInst |
| 2383 | virtual CastInst *clone() const; |
| 2384 | |
| 2385 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2386 | static inline bool classof(const FPExtInst *) { return true; } |
| 2387 | static inline bool classof(const Instruction *I) { |
| 2388 | return I->getOpcode() == FPExt; |
| 2389 | } |
| 2390 | static inline bool classof(const Value *V) { |
| 2391 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2392 | } |
| 2393 | }; |
| 2394 | |
| 2395 | //===----------------------------------------------------------------------===// |
| 2396 | // UIToFPInst Class |
| 2397 | //===----------------------------------------------------------------------===// |
| 2398 | |
| 2399 | /// @brief This class represents a cast unsigned integer to floating point. |
| 2400 | class UIToFPInst : public CastInst { |
| 2401 | UIToFPInst(const UIToFPInst &CI) |
| 2402 | : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) { |
| 2403 | } |
| 2404 | public: |
| 2405 | /// @brief Constructor with insert-before-instruction semantics |
| 2406 | UIToFPInst( |
| 2407 | Value *S, ///< The value to be converted |
| 2408 | const Type *Ty, ///< The type to convert to |
| 2409 | const std::string &Name = "", ///< A name for the new instruction |
| 2410 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2411 | ); |
| 2412 | |
| 2413 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2414 | UIToFPInst( |
| 2415 | Value *S, ///< The value to be converted |
| 2416 | const Type *Ty, ///< The type to convert to |
| 2417 | const std::string &Name, ///< A name for the new instruction |
| 2418 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2419 | ); |
| 2420 | |
| 2421 | /// @brief Clone an identical UIToFPInst |
| 2422 | virtual CastInst *clone() const; |
| 2423 | |
| 2424 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2425 | static inline bool classof(const UIToFPInst *) { return true; } |
| 2426 | static inline bool classof(const Instruction *I) { |
| 2427 | return I->getOpcode() == UIToFP; |
| 2428 | } |
| 2429 | static inline bool classof(const Value *V) { |
| 2430 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2431 | } |
| 2432 | }; |
| 2433 | |
| 2434 | //===----------------------------------------------------------------------===// |
| 2435 | // SIToFPInst Class |
| 2436 | //===----------------------------------------------------------------------===// |
| 2437 | |
| 2438 | /// @brief This class represents a cast from signed integer to floating point. |
| 2439 | class SIToFPInst : public CastInst { |
| 2440 | SIToFPInst(const SIToFPInst &CI) |
| 2441 | : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) { |
| 2442 | } |
| 2443 | public: |
| 2444 | /// @brief Constructor with insert-before-instruction semantics |
| 2445 | SIToFPInst( |
| 2446 | Value *S, ///< The value to be converted |
| 2447 | const Type *Ty, ///< The type to convert to |
| 2448 | const std::string &Name = "", ///< A name for the new instruction |
| 2449 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2450 | ); |
| 2451 | |
| 2452 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2453 | SIToFPInst( |
| 2454 | Value *S, ///< The value to be converted |
| 2455 | const Type *Ty, ///< The type to convert to |
| 2456 | const std::string &Name, ///< A name for the new instruction |
| 2457 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2458 | ); |
| 2459 | |
| 2460 | /// @brief Clone an identical SIToFPInst |
| 2461 | virtual CastInst *clone() const; |
| 2462 | |
| 2463 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2464 | static inline bool classof(const SIToFPInst *) { return true; } |
| 2465 | static inline bool classof(const Instruction *I) { |
| 2466 | return I->getOpcode() == SIToFP; |
| 2467 | } |
| 2468 | static inline bool classof(const Value *V) { |
| 2469 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2470 | } |
| 2471 | }; |
| 2472 | |
| 2473 | //===----------------------------------------------------------------------===// |
| 2474 | // FPToUIInst Class |
| 2475 | //===----------------------------------------------------------------------===// |
| 2476 | |
| 2477 | /// @brief This class represents a cast from floating point to unsigned integer |
| 2478 | class FPToUIInst : public CastInst { |
| 2479 | FPToUIInst(const FPToUIInst &CI) |
| 2480 | : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) { |
| 2481 | } |
| 2482 | public: |
| 2483 | /// @brief Constructor with insert-before-instruction semantics |
| 2484 | FPToUIInst( |
| 2485 | Value *S, ///< The value to be converted |
| 2486 | const Type *Ty, ///< The type to convert to |
| 2487 | const std::string &Name = "", ///< A name for the new instruction |
| 2488 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2489 | ); |
| 2490 | |
| 2491 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2492 | FPToUIInst( |
| 2493 | Value *S, ///< The value to be converted |
| 2494 | const Type *Ty, ///< The type to convert to |
| 2495 | const std::string &Name, ///< A name for the new instruction |
| 2496 | BasicBlock *InsertAtEnd ///< Where to insert the new instruction |
| 2497 | ); |
| 2498 | |
| 2499 | /// @brief Clone an identical FPToUIInst |
| 2500 | virtual CastInst *clone() const; |
| 2501 | |
| 2502 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2503 | static inline bool classof(const FPToUIInst *) { return true; } |
| 2504 | static inline bool classof(const Instruction *I) { |
| 2505 | return I->getOpcode() == FPToUI; |
| 2506 | } |
| 2507 | static inline bool classof(const Value *V) { |
| 2508 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2509 | } |
| 2510 | }; |
| 2511 | |
| 2512 | //===----------------------------------------------------------------------===// |
| 2513 | // FPToSIInst Class |
| 2514 | //===----------------------------------------------------------------------===// |
| 2515 | |
| 2516 | /// @brief This class represents a cast from floating point to signed integer. |
| 2517 | class FPToSIInst : public CastInst { |
| 2518 | FPToSIInst(const FPToSIInst &CI) |
| 2519 | : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) { |
| 2520 | } |
| 2521 | public: |
| 2522 | /// @brief Constructor with insert-before-instruction semantics |
| 2523 | FPToSIInst( |
| 2524 | Value *S, ///< The value to be converted |
| 2525 | const Type *Ty, ///< The type to convert to |
| 2526 | const std::string &Name = "", ///< A name for the new instruction |
| 2527 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2528 | ); |
| 2529 | |
| 2530 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2531 | FPToSIInst( |
| 2532 | Value *S, ///< The value to be converted |
| 2533 | const Type *Ty, ///< The type to convert to |
| 2534 | const std::string &Name, ///< A name for the new instruction |
| 2535 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2536 | ); |
| 2537 | |
| 2538 | /// @brief Clone an identical FPToSIInst |
| 2539 | virtual CastInst *clone() const; |
| 2540 | |
| 2541 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2542 | static inline bool classof(const FPToSIInst *) { return true; } |
| 2543 | static inline bool classof(const Instruction *I) { |
| 2544 | return I->getOpcode() == FPToSI; |
| 2545 | } |
| 2546 | static inline bool classof(const Value *V) { |
| 2547 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2548 | } |
| 2549 | }; |
| 2550 | |
| 2551 | //===----------------------------------------------------------------------===// |
| 2552 | // IntToPtrInst Class |
| 2553 | //===----------------------------------------------------------------------===// |
| 2554 | |
| 2555 | /// @brief This class represents a cast from an integer to a pointer. |
| 2556 | class IntToPtrInst : public CastInst { |
| 2557 | IntToPtrInst(const IntToPtrInst &CI) |
| 2558 | : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) { |
| 2559 | } |
| 2560 | public: |
| 2561 | /// @brief Constructor with insert-before-instruction semantics |
| 2562 | IntToPtrInst( |
| 2563 | Value *S, ///< The value to be converted |
| 2564 | const Type *Ty, ///< The type to convert to |
| 2565 | const std::string &Name = "", ///< A name for the new instruction |
| 2566 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2567 | ); |
| 2568 | |
| 2569 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2570 | IntToPtrInst( |
| 2571 | Value *S, ///< The value to be converted |
| 2572 | const Type *Ty, ///< The type to convert to |
| 2573 | const std::string &Name, ///< A name for the new instruction |
| 2574 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2575 | ); |
| 2576 | |
| 2577 | /// @brief Clone an identical IntToPtrInst |
| 2578 | virtual CastInst *clone() const; |
| 2579 | |
| 2580 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2581 | static inline bool classof(const IntToPtrInst *) { return true; } |
| 2582 | static inline bool classof(const Instruction *I) { |
| 2583 | return I->getOpcode() == IntToPtr; |
| 2584 | } |
| 2585 | static inline bool classof(const Value *V) { |
| 2586 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2587 | } |
| 2588 | }; |
| 2589 | |
| 2590 | //===----------------------------------------------------------------------===// |
| 2591 | // PtrToIntInst Class |
| 2592 | //===----------------------------------------------------------------------===// |
| 2593 | |
| 2594 | /// @brief This class represents a cast from a pointer to an integer |
| 2595 | class PtrToIntInst : public CastInst { |
| 2596 | PtrToIntInst(const PtrToIntInst &CI) |
| 2597 | : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) { |
| 2598 | } |
| 2599 | public: |
| 2600 | /// @brief Constructor with insert-before-instruction semantics |
| 2601 | PtrToIntInst( |
| 2602 | Value *S, ///< The value to be converted |
| 2603 | const Type *Ty, ///< The type to convert to |
| 2604 | const std::string &Name = "", ///< A name for the new instruction |
| 2605 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2606 | ); |
| 2607 | |
| 2608 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2609 | PtrToIntInst( |
| 2610 | Value *S, ///< The value to be converted |
| 2611 | const Type *Ty, ///< The type to convert to |
| 2612 | const std::string &Name, ///< A name for the new instruction |
| 2613 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2614 | ); |
| 2615 | |
| 2616 | /// @brief Clone an identical PtrToIntInst |
| 2617 | virtual CastInst *clone() const; |
| 2618 | |
| 2619 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2620 | static inline bool classof(const PtrToIntInst *) { return true; } |
| 2621 | static inline bool classof(const Instruction *I) { |
| 2622 | return I->getOpcode() == PtrToInt; |
| 2623 | } |
| 2624 | static inline bool classof(const Value *V) { |
| 2625 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2626 | } |
| 2627 | }; |
| 2628 | |
| 2629 | //===----------------------------------------------------------------------===// |
| 2630 | // BitCastInst Class |
| 2631 | //===----------------------------------------------------------------------===// |
| 2632 | |
| 2633 | /// @brief This class represents a no-op cast from one type to another. |
| 2634 | class BitCastInst : public CastInst { |
| 2635 | BitCastInst(const BitCastInst &CI) |
| 2636 | : CastInst(CI.getType(), BitCast, CI.getOperand(0)) { |
| 2637 | } |
| 2638 | public: |
| 2639 | /// @brief Constructor with insert-before-instruction semantics |
| 2640 | BitCastInst( |
| 2641 | Value *S, ///< The value to be casted |
| 2642 | const Type *Ty, ///< The type to casted to |
| 2643 | const std::string &Name = "", ///< A name for the new instruction |
| 2644 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2645 | ); |
| 2646 | |
| 2647 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2648 | BitCastInst( |
| 2649 | Value *S, ///< The value to be casted |
| 2650 | const Type *Ty, ///< The type to casted to |
| 2651 | const std::string &Name, ///< A name for the new instruction |
| 2652 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2653 | ); |
| 2654 | |
| 2655 | /// @brief Clone an identical BitCastInst |
| 2656 | virtual CastInst *clone() const; |
| 2657 | |
| 2658 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2659 | static inline bool classof(const BitCastInst *) { return true; } |
| 2660 | static inline bool classof(const Instruction *I) { |
| 2661 | return I->getOpcode() == BitCast; |
| 2662 | } |
| 2663 | static inline bool classof(const Value *V) { |
| 2664 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2665 | } |
| 2666 | }; |
| 2667 | |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 2668 | //===----------------------------------------------------------------------===// |
| 2669 | // GetResultInst Class |
| 2670 | //===----------------------------------------------------------------------===// |
| 2671 | |
| 2672 | /// GetResultInst - This instruction extracts individual result value from |
| 2673 | /// aggregate value, where aggregate value is returned by CallInst. |
| 2674 | /// |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2675 | class GetResultInst : public /*FIXME: Unary*/Instruction { |
| 2676 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Devang Patel | 23755d8 | 2008-02-20 19:10:47 +0000 | [diff] [blame] | 2677 | unsigned Idx; |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 2678 | GetResultInst(const GetResultInst &GRI) : |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2679 | Instruction(GRI.getType(), Instruction::GetResult, &Op<0>(), 1) { |
| 2680 | Op<0>().init(GRI.Op<0>(), this); |
Devang Patel | 23755d8 | 2008-02-20 19:10:47 +0000 | [diff] [blame] | 2681 | Idx = GRI.Idx; |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2685 | // allocate space for exactly one operand |
| 2686 | void *operator new(size_t s) { |
| 2687 | return User::operator new(s, 1); |
| 2688 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2689 | GetResultInst(Value *Aggr, unsigned index, |
| 2690 | const std::string &Name = "", |
| 2691 | Instruction *InsertBefore = 0); |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 2692 | |
| 2693 | /// isValidOperands - Return true if an getresult instruction can be |
| 2694 | /// formed with the specified operands. |
Devang Patel | 23755d8 | 2008-02-20 19:10:47 +0000 | [diff] [blame] | 2695 | static bool isValidOperands(const Value *Aggr, unsigned index); |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 2696 | |
| 2697 | virtual GetResultInst *clone() const; |
| 2698 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2699 | Value *getAggregateValue() { |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 2700 | return getOperand(0); |
| 2701 | } |
Devang Patel | 2d2ae34 | 2008-02-20 18:36:16 +0000 | [diff] [blame] | 2702 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2703 | const Value *getAggregateValue() const { |
Devang Patel | 2d2ae34 | 2008-02-20 18:36:16 +0000 | [diff] [blame] | 2704 | return getOperand(0); |
| 2705 | } |
| 2706 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2707 | unsigned getIndex() const { |
Devang Patel | 23755d8 | 2008-02-20 19:10:47 +0000 | [diff] [blame] | 2708 | return Idx; |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 2709 | } |
| 2710 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2711 | /// Provide fast operand accessors |
| 2712 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 2713 | |
| 2714 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2715 | static inline bool classof(const GetResultInst *) { return true; } |
| 2716 | static inline bool classof(const Instruction *I) { |
| 2717 | return (I->getOpcode() == Instruction::GetResult); |
| 2718 | } |
| 2719 | static inline bool classof(const Value *V) { |
| 2720 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2721 | } |
| 2722 | }; |
| 2723 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2724 | // FIXME: these are redundant if GetResultInst < UnaryInstruction |
| 2725 | template <> |
| 2726 | struct OperandTraits<GetResultInst> : FixedNumOperandTraits<1> { |
| 2727 | }; |
| 2728 | |
| 2729 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetResultInst, Value) |
| 2730 | |
| 2731 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2732 | } // End llvm namespace |
Chris Lattner | a892a3a | 2003-01-27 22:08:52 +0000 | [diff] [blame] | 2733 | |
| 2734 | #endif |