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 | /// |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 407 | /// Null is returned if the indices are invalid for the specified |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 408 | /// pointer type. |
| 409 | /// |
| 410 | static const Type *getIndexedType(const Type *Ptr, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 411 | Value* const *Idx, unsigned NumIdx); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 412 | |
| 413 | template<typename InputIterator> |
| 414 | static const Type *getIndexedType(const Type *Ptr, |
| 415 | InputIterator IdxBegin, |
| 416 | InputIterator IdxEnd, |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 417 | // This argument ensures that we |
| 418 | // have an iterator we can do |
| 419 | // arithmetic on in constant time |
| 420 | std::random_access_iterator_tag) { |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 421 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 422 | |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 423 | if (NumIdx > 0) |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 424 | // This requires that the iterator points to contiguous memory. |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 425 | return getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx); |
| 426 | else |
| 427 | return getIndexedType(Ptr, (Value *const*)0, NumIdx); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 430 | /// Constructors - Create a getelementptr instruction with a base pointer an |
| 431 | /// list of indices. The first ctor can optionally insert before an existing |
| 432 | /// instruction, the second appends the new instruction to the specified |
| 433 | /// BasicBlock. |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 434 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 435 | inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, |
| 436 | InputIterator IdxEnd, |
| 437 | unsigned Values, |
| 438 | const std::string &Name, |
| 439 | Instruction *InsertBefore); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 440 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 441 | inline GetElementPtrInst(Value *Ptr, |
| 442 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 443 | unsigned Values, |
| 444 | const std::string &Name, BasicBlock *InsertAtEnd); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 445 | |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 446 | /// Constructors - These two constructors are convenience methods because one |
| 447 | /// and two index getelementptr instructions are so common. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 448 | GetElementPtrInst(Value *Ptr, Value *Idx, const std::string &Name = "", |
| 449 | Instruction *InsertBefore = 0); |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 450 | GetElementPtrInst(Value *Ptr, Value *Idx, |
| 451 | const std::string &Name, BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 452 | public: |
| 453 | template<typename InputIterator> |
| 454 | static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin, |
| 455 | InputIterator IdxEnd, |
| 456 | const std::string &Name = "", |
| 457 | Instruction *InsertBefore = 0) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 458 | typename std::iterator_traits<InputIterator>::difference_type Values = |
| 459 | 1 + std::distance(IdxBegin, IdxEnd); |
| 460 | return new(Values) |
| 461 | GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 462 | } |
| 463 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 464 | static GetElementPtrInst *Create(Value *Ptr, |
| 465 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 466 | const std::string &Name, |
| 467 | BasicBlock *InsertAtEnd) { |
| 468 | typename std::iterator_traits<InputIterator>::difference_type Values = |
| 469 | 1 + std::distance(IdxBegin, IdxEnd); |
| 470 | return new(Values) |
| 471 | GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 474 | /// Constructors - These two creators are convenience methods because one |
| 475 | /// index getelementptr instructions are so common. |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 476 | static GetElementPtrInst *Create(Value *Ptr, Value *Idx, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 477 | const std::string &Name = "", |
| 478 | Instruction *InsertBefore = 0) { |
| 479 | return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 480 | } |
| 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 | BasicBlock *InsertAtEnd) { |
| 484 | return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 485 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 486 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 487 | virtual GetElementPtrInst *clone() const; |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 488 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 489 | /// Transparently provide more efficient getOperand methods. |
| 490 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 491 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 492 | // getType - Overload to return most specific pointer type... |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 493 | const PointerType *getType() const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 494 | return reinterpret_cast<const PointerType*>(Instruction::getType()); |
| 495 | } |
| 496 | |
| 497 | /// getIndexedType - Returns the type of the element that would be loaded with |
| 498 | /// a load instruction with the specified parameters. |
| 499 | /// |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 500 | /// Null is returned if the indices are invalid for the specified |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 501 | /// pointer type. |
| 502 | /// |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 503 | template<typename InputIterator> |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 504 | static const Type *getIndexedType(const Type *Ptr, |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 505 | InputIterator IdxBegin, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 506 | InputIterator IdxEnd) { |
| 507 | return getIndexedType(Ptr, IdxBegin, IdxEnd, |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 508 | typename std::iterator_traits<InputIterator>:: |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 509 | iterator_category()); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 510 | } |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 511 | static const Type *getIndexedType(const Type *Ptr, Value *Idx); |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 512 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 513 | inline op_iterator idx_begin() { return op_begin()+1; } |
| 514 | inline const_op_iterator idx_begin() const { return op_begin()+1; } |
| 515 | inline op_iterator idx_end() { return op_end(); } |
| 516 | inline const_op_iterator idx_end() const { return op_end(); } |
| 517 | |
| 518 | Value *getPointerOperand() { |
| 519 | return getOperand(0); |
| 520 | } |
| 521 | const Value *getPointerOperand() const { |
| 522 | return getOperand(0); |
| 523 | } |
| 524 | static unsigned getPointerOperandIndex() { |
| 525 | return 0U; // get index for modifying correct operand |
| 526 | } |
| 527 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 528 | unsigned getNumIndices() const { // Note: always non-negative |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 529 | return getNumOperands() - 1; |
| 530 | } |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 531 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 532 | bool hasIndices() const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 533 | return getNumOperands() > 1; |
| 534 | } |
Chris Lattner | 6f771d4 | 2007-04-14 00:12:57 +0000 | [diff] [blame] | 535 | |
| 536 | /// hasAllZeroIndices - Return true if all of the indices of this GEP are |
| 537 | /// zeros. If so, the result pointer and the first operand have the same |
| 538 | /// value, just potentially different types. |
| 539 | bool hasAllZeroIndices() const; |
Chris Lattner | 6b0974c | 2007-04-27 20:35:56 +0000 | [diff] [blame] | 540 | |
| 541 | /// hasAllConstantIndices - Return true if all of the indices of this GEP are |
| 542 | /// constant integers. If so, the result pointer and the first operand have |
| 543 | /// a constant offset between them. |
| 544 | bool hasAllConstantIndices() const; |
| 545 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 546 | |
| 547 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 548 | static inline bool classof(const GetElementPtrInst *) { return true; } |
| 549 | static inline bool classof(const Instruction *I) { |
| 550 | return (I->getOpcode() == Instruction::GetElementPtr); |
| 551 | } |
| 552 | static inline bool classof(const Value *V) { |
| 553 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 554 | } |
| 555 | }; |
| 556 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 557 | template <> |
| 558 | struct OperandTraits<GetElementPtrInst> : VariadicOperandTraits<1> { |
| 559 | }; |
| 560 | |
| 561 | template<typename InputIterator> |
| 562 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, |
| 563 | InputIterator IdxBegin, |
| 564 | InputIterator IdxEnd, |
| 565 | unsigned Values, |
| 566 | const std::string &Name, |
| 567 | Instruction *InsertBefore) |
| 568 | : Instruction(PointerType::get(checkType( |
| 569 | getIndexedType(Ptr->getType(), |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 570 | IdxBegin, IdxEnd)), |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 571 | cast<PointerType>(Ptr->getType()) |
| 572 | ->getAddressSpace()), |
| 573 | GetElementPtr, |
| 574 | OperandTraits<GetElementPtrInst>::op_end(this) - Values, |
| 575 | Values, InsertBefore) { |
| 576 | init(Ptr, IdxBegin, IdxEnd, Name, |
| 577 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 578 | } |
| 579 | template<typename InputIterator> |
| 580 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, |
| 581 | InputIterator IdxBegin, |
| 582 | InputIterator IdxEnd, |
| 583 | unsigned Values, |
| 584 | const std::string &Name, |
| 585 | BasicBlock *InsertAtEnd) |
| 586 | : Instruction(PointerType::get(checkType( |
| 587 | getIndexedType(Ptr->getType(), |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 588 | IdxBegin, IdxEnd)), |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 589 | cast<PointerType>(Ptr->getType()) |
| 590 | ->getAddressSpace()), |
| 591 | GetElementPtr, |
| 592 | OperandTraits<GetElementPtrInst>::op_end(this) - Values, |
| 593 | Values, InsertAtEnd) { |
| 594 | init(Ptr, IdxBegin, IdxEnd, Name, |
| 595 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 596 | } |
| 597 | |
| 598 | |
| 599 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value) |
| 600 | |
| 601 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 602 | //===----------------------------------------------------------------------===// |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 603 | // ICmpInst Class |
| 604 | //===----------------------------------------------------------------------===// |
| 605 | |
| 606 | /// This instruction compares its operands according to the predicate given |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 607 | /// to the constructor. It only operates on integers or pointers. The operands |
| 608 | /// must be identical types. |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 609 | /// @brief Represent an integer comparison operator. |
| 610 | class ICmpInst: public CmpInst { |
| 611 | public: |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 612 | /// @brief Constructor with insert-before-instruction semantics. |
| 613 | ICmpInst( |
| 614 | Predicate pred, ///< The predicate to use for the comparison |
| 615 | Value *LHS, ///< The left-hand-side of the expression |
| 616 | Value *RHS, ///< The right-hand-side of the expression |
| 617 | const std::string &Name = "", ///< Name of the instruction |
| 618 | Instruction *InsertBefore = 0 ///< Where to insert |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 619 | ) : CmpInst(Type::Int1Ty, Instruction::ICmp, pred, LHS, RHS, Name, |
| 620 | InsertBefore) { |
| 621 | assert(pred >= CmpInst::FIRST_ICMP_PREDICATE && |
| 622 | pred <= CmpInst::LAST_ICMP_PREDICATE && |
| 623 | "Invalid ICmp predicate value"); |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 624 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 625 | "Both operands to ICmp instruction are not of the same type!"); |
| 626 | // Check that the operands are the right type |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 627 | assert((getOperand(0)->getType()->isInteger() || |
| 628 | isa<PointerType>(getOperand(0)->getType())) && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 629 | "Invalid operand types for ICmp instruction"); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | /// @brief Constructor with insert-at-block-end semantics. |
| 633 | ICmpInst( |
| 634 | Predicate pred, ///< The predicate to use for the comparison |
| 635 | Value *LHS, ///< The left-hand-side of the expression |
| 636 | Value *RHS, ///< The right-hand-side of the expression |
| 637 | const std::string &Name, ///< Name of the instruction |
| 638 | BasicBlock *InsertAtEnd ///< Block to insert into. |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 639 | ) : CmpInst(Type::Int1Ty, Instruction::ICmp, pred, LHS, RHS, Name, |
| 640 | InsertAtEnd) { |
| 641 | assert(pred >= CmpInst::FIRST_ICMP_PREDICATE && |
| 642 | pred <= CmpInst::LAST_ICMP_PREDICATE && |
| 643 | "Invalid ICmp predicate value"); |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 644 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 645 | "Both operands to ICmp instruction are not of the same type!"); |
| 646 | // Check that the operands are the right type |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 647 | assert((getOperand(0)->getType()->isInteger() || |
| 648 | isa<PointerType>(getOperand(0)->getType())) && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 649 | "Invalid operand types for ICmp instruction"); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | /// @brief Return the predicate for this instruction. |
| 653 | Predicate getPredicate() const { return Predicate(SubclassData); } |
| 654 | |
Chris Lattner | b769d56 | 2007-01-14 19:41:24 +0000 | [diff] [blame] | 655 | /// @brief Set the predicate for this instruction to the specified value. |
| 656 | void setPredicate(Predicate P) { SubclassData = P; } |
| 657 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 658 | /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc. |
| 659 | /// @returns the inverse predicate for the instruction's current predicate. |
| 660 | /// @brief Return the inverse of the instruction's predicate. |
| 661 | Predicate getInversePredicate() const { |
| 662 | return getInversePredicate(getPredicate()); |
| 663 | } |
| 664 | |
| 665 | /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc. |
| 666 | /// @returns the inverse predicate for predicate provided in \p pred. |
| 667 | /// @brief Return the inverse of a given predicate |
| 668 | static Predicate getInversePredicate(Predicate pred); |
| 669 | |
| 670 | /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc. |
| 671 | /// @returns the predicate that would be the result of exchanging the two |
| 672 | /// operands of the ICmpInst instruction without changing the result |
| 673 | /// produced. |
| 674 | /// @brief Return the predicate as if the operands were swapped |
| 675 | Predicate getSwappedPredicate() const { |
| 676 | return getSwappedPredicate(getPredicate()); |
| 677 | } |
| 678 | |
| 679 | /// This is a static version that you can use without an instruction |
| 680 | /// available. |
| 681 | /// @brief Return the predicate as if the operands were swapped. |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 682 | static Predicate getSwappedPredicate(Predicate pred); |
| 683 | |
| 684 | /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc. |
| 685 | /// @returns the predicate that would be the result if the operand were |
| 686 | /// regarded as signed. |
| 687 | /// @brief Return the signed version of the predicate |
| 688 | Predicate getSignedPredicate() const { |
| 689 | return getSignedPredicate(getPredicate()); |
| 690 | } |
| 691 | |
| 692 | /// This is a static version that you can use without an instruction. |
| 693 | /// @brief Return the signed version of the predicate. |
| 694 | static Predicate getSignedPredicate(Predicate pred); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 695 | |
Nick Lewycky | 4189a53 | 2008-01-28 03:48:02 +0000 | [diff] [blame] | 696 | /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc. |
| 697 | /// @returns the predicate that would be the result if the operand were |
| 698 | /// regarded as unsigned. |
| 699 | /// @brief Return the unsigned version of the predicate |
| 700 | Predicate getUnsignedPredicate() const { |
| 701 | return getUnsignedPredicate(getPredicate()); |
| 702 | } |
| 703 | |
| 704 | /// This is a static version that you can use without an instruction. |
| 705 | /// @brief Return the unsigned version of the predicate. |
| 706 | static Predicate getUnsignedPredicate(Predicate pred); |
| 707 | |
Chris Lattner | c2bfadb | 2007-11-22 23:43:29 +0000 | [diff] [blame] | 708 | /// isEquality - Return true if this predicate is either EQ or NE. This also |
| 709 | /// tests for commutativity. |
| 710 | static bool isEquality(Predicate P) { |
| 711 | return P == ICMP_EQ || P == ICMP_NE; |
| 712 | } |
| 713 | |
| 714 | /// isEquality - Return true if this predicate is either EQ or NE. This also |
| 715 | /// tests for commutativity. |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 716 | bool isEquality() const { |
Chris Lattner | c2bfadb | 2007-11-22 23:43:29 +0000 | [diff] [blame] | 717 | return isEquality(getPredicate()); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 718 | } |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 719 | |
| 720 | /// @returns true if the predicate of this ICmpInst is commutative |
| 721 | /// @brief Determine if this relation is commutative. |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 722 | bool isCommutative() const { return isEquality(); } |
| 723 | |
Chris Lattner | c2bfadb | 2007-11-22 23:43:29 +0000 | [diff] [blame] | 724 | /// isRelational - Return true if the predicate is relational (not EQ or NE). |
| 725 | /// |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 726 | bool isRelational() const { |
| 727 | return !isEquality(); |
| 728 | } |
| 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 | /// |
| 732 | static bool isRelational(Predicate P) { |
| 733 | return !isEquality(P); |
| 734 | } |
| 735 | |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 736 | /// @returns true if the predicate of this ICmpInst is signed, false otherwise |
| 737 | /// @brief Determine if this instruction's predicate is signed. |
Chris Lattner | 5bda9e4 | 2007-09-15 06:51:03 +0000 | [diff] [blame] | 738 | bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); } |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 739 | |
| 740 | /// @returns true if the predicate provided is signed, false otherwise |
| 741 | /// @brief Determine if the predicate is signed. |
| 742 | static bool isSignedPredicate(Predicate pred); |
| 743 | |
Nick Lewycky | fc1efbb | 2008-05-17 07:33:39 +0000 | [diff] [blame^] | 744 | /// @returns true if the specified compare predicate is |
| 745 | /// true when both operands are equal... |
| 746 | /// @brief Determine if the icmp is true when both operands are equal |
| 747 | static bool isTrueWhenEqual(ICmpInst::Predicate pred) { |
| 748 | return pred == ICmpInst::ICMP_EQ || pred == ICmpInst::ICMP_UGE || |
| 749 | pred == ICmpInst::ICMP_SGE || pred == ICmpInst::ICMP_ULE || |
| 750 | pred == ICmpInst::ICMP_SLE; |
| 751 | } |
| 752 | |
| 753 | /// @returns true if the specified compare instruction is |
| 754 | /// true when both operands are equal... |
| 755 | /// @brief Determine if the ICmpInst returns true when both operands are equal |
| 756 | bool isTrueWhenEqual() { |
| 757 | return isTrueWhenEqual(getPredicate()); |
| 758 | } |
| 759 | |
Reid Spencer | 3da4384 | 2007-02-28 22:00:54 +0000 | [diff] [blame] | 760 | /// Initialize a set of values that all satisfy the predicate with C. |
| 761 | /// @brief Make a ConstantRange for a relation with a constant value. |
| 762 | static ConstantRange makeConstantRange(Predicate pred, const APInt &C); |
| 763 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 764 | /// Exchange the two operands to this instruction in such a way that it does |
| 765 | /// not modify the semantics of the instruction. The predicate value may be |
| 766 | /// changed to retain the same result if the predicate is order dependent |
| 767 | /// (e.g. ult). |
| 768 | /// @brief Swap operands and adjust predicate. |
| 769 | void swapOperands() { |
| 770 | SubclassData = getSwappedPredicate(); |
Gabor Greif | 94fb68b | 2008-05-13 22:51:52 +0000 | [diff] [blame] | 771 | Op<0>().swap(Op<1>()); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Chris Lattner | cd406fe | 2007-08-24 20:48:18 +0000 | [diff] [blame] | 774 | virtual ICmpInst *clone() const; |
| 775 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 776 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 777 | static inline bool classof(const ICmpInst *) { return true; } |
| 778 | static inline bool classof(const Instruction *I) { |
| 779 | return I->getOpcode() == Instruction::ICmp; |
| 780 | } |
| 781 | static inline bool classof(const Value *V) { |
| 782 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 783 | } |
| 784 | }; |
| 785 | |
| 786 | //===----------------------------------------------------------------------===// |
| 787 | // FCmpInst Class |
| 788 | //===----------------------------------------------------------------------===// |
| 789 | |
| 790 | /// This instruction compares its operands according to the predicate given |
| 791 | /// to the constructor. It only operates on floating point values or packed |
| 792 | /// vectors of floating point values. The operands must be identical types. |
| 793 | /// @brief Represents a floating point comparison operator. |
| 794 | class FCmpInst: public CmpInst { |
| 795 | public: |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 796 | /// @brief Constructor with insert-before-instruction semantics. |
| 797 | FCmpInst( |
| 798 | Predicate pred, ///< The predicate to use for the comparison |
| 799 | Value *LHS, ///< The left-hand-side of the expression |
| 800 | Value *RHS, ///< The right-hand-side of the expression |
| 801 | const std::string &Name = "", ///< Name of the instruction |
| 802 | Instruction *InsertBefore = 0 ///< Where to insert |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 803 | ) : CmpInst(Type::Int1Ty, Instruction::FCmp, pred, LHS, RHS, Name, |
| 804 | InsertBefore) { |
| 805 | assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && |
| 806 | "Invalid FCmp predicate value"); |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 807 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 808 | "Both operands to FCmp instruction are not of the same type!"); |
| 809 | // Check that the operands are the right type |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 810 | assert(getOperand(0)->getType()->isFloatingPoint() && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 811 | "Invalid operand types for FCmp instruction"); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | /// @brief Constructor with insert-at-block-end semantics. |
| 815 | FCmpInst( |
| 816 | Predicate pred, ///< The predicate to use for the comparison |
| 817 | Value *LHS, ///< The left-hand-side of the expression |
| 818 | Value *RHS, ///< The right-hand-side of the expression |
| 819 | const std::string &Name, ///< Name of the instruction |
| 820 | BasicBlock *InsertAtEnd ///< Block to insert into. |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 821 | ) : CmpInst(Type::Int1Ty, Instruction::FCmp, pred, LHS, RHS, Name, |
| 822 | InsertAtEnd) { |
| 823 | assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && |
| 824 | "Invalid FCmp predicate value"); |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 825 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 826 | "Both operands to FCmp instruction are not of the same type!"); |
| 827 | // Check that the operands are the right type |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 828 | assert(getOperand(0)->getType()->isFloatingPoint() && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 829 | "Invalid operand types for FCmp instruction"); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | /// @brief Return the predicate for this instruction. |
| 833 | Predicate getPredicate() const { return Predicate(SubclassData); } |
| 834 | |
Chris Lattner | b769d56 | 2007-01-14 19:41:24 +0000 | [diff] [blame] | 835 | /// @brief Set the predicate for this instruction to the specified value. |
| 836 | void setPredicate(Predicate P) { SubclassData = P; } |
| 837 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 838 | /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc. |
| 839 | /// @returns the inverse predicate for the instructions current predicate. |
| 840 | /// @brief Return the inverse of the predicate |
| 841 | Predicate getInversePredicate() const { |
| 842 | return getInversePredicate(getPredicate()); |
| 843 | } |
| 844 | |
| 845 | /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc. |
| 846 | /// @returns the inverse predicate for \p pred. |
| 847 | /// @brief Return the inverse of a given predicate |
| 848 | static Predicate getInversePredicate(Predicate pred); |
| 849 | |
| 850 | /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc. |
| 851 | /// @returns the predicate that would be the result of exchanging the two |
| 852 | /// operands of the ICmpInst instruction without changing the result |
| 853 | /// produced. |
| 854 | /// @brief Return the predicate as if the operands were swapped |
| 855 | Predicate getSwappedPredicate() const { |
| 856 | return getSwappedPredicate(getPredicate()); |
| 857 | } |
| 858 | |
| 859 | /// This is a static version that you can use without an instruction |
| 860 | /// available. |
| 861 | /// @brief Return the predicate as if the operands were swapped. |
| 862 | static Predicate getSwappedPredicate(Predicate Opcode); |
| 863 | |
| 864 | /// This also tests for commutativity. If isEquality() returns true then |
| 865 | /// the predicate is also commutative. Only the equality predicates are |
| 866 | /// commutative. |
| 867 | /// @returns true if the predicate of this instruction is EQ or NE. |
| 868 | /// @brief Determine if this is an equality predicate. |
| 869 | bool isEquality() const { |
| 870 | return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE || |
| 871 | SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE; |
| 872 | } |
| 873 | bool isCommutative() const { return isEquality(); } |
| 874 | |
| 875 | /// @returns true if the predicate is relational (not EQ or NE). |
| 876 | /// @brief Determine if this a relational predicate. |
| 877 | bool isRelational() const { return !isEquality(); } |
| 878 | |
| 879 | /// Exchange the two operands to this instruction in such a way that it does |
| 880 | /// not modify the semantics of the instruction. The predicate value may be |
| 881 | /// changed to retain the same result if the predicate is order dependent |
| 882 | /// (e.g. ult). |
| 883 | /// @brief Swap operands and adjust predicate. |
| 884 | void swapOperands() { |
| 885 | SubclassData = getSwappedPredicate(); |
Gabor Greif | 94fb68b | 2008-05-13 22:51:52 +0000 | [diff] [blame] | 886 | Op<0>().swap(Op<1>()); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 887 | } |
| 888 | |
Chris Lattner | cd406fe | 2007-08-24 20:48:18 +0000 | [diff] [blame] | 889 | virtual FCmpInst *clone() const; |
| 890 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 891 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 892 | static inline bool classof(const FCmpInst *) { return true; } |
| 893 | static inline bool classof(const Instruction *I) { |
| 894 | return I->getOpcode() == Instruction::FCmp; |
| 895 | } |
| 896 | static inline bool classof(const Value *V) { |
| 897 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 898 | } |
| 899 | }; |
| 900 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 901 | //===----------------------------------------------------------------------===// |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 902 | // VICmpInst Class |
| 903 | //===----------------------------------------------------------------------===// |
| 904 | |
| 905 | /// This instruction compares its operands according to the predicate given |
| 906 | /// to the constructor. It only operates on vectors of integers. |
| 907 | /// The operands must be identical types. |
| 908 | /// @brief Represents a vector integer comparison operator. |
| 909 | class VICmpInst: public CmpInst { |
| 910 | public: |
| 911 | /// @brief Constructor with insert-before-instruction semantics. |
| 912 | VICmpInst( |
| 913 | Predicate pred, ///< The predicate to use for the comparison |
| 914 | Value *LHS, ///< The left-hand-side of the expression |
| 915 | Value *RHS, ///< The right-hand-side of the expression |
| 916 | const std::string &Name = "", ///< Name of the instruction |
| 917 | Instruction *InsertBefore = 0 ///< Where to insert |
| 918 | ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, Name, |
| 919 | InsertBefore) { |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 920 | assert(pred >= CmpInst::FIRST_ICMP_PREDICATE && |
| 921 | pred <= CmpInst::LAST_ICMP_PREDICATE && |
| 922 | "Invalid VICmp predicate value"); |
| 923 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
| 924 | "Both operands to VICmp instruction are not of the same type!"); |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | /// @brief Constructor with insert-at-block-end semantics. |
| 928 | VICmpInst( |
| 929 | Predicate pred, ///< The predicate to use for the comparison |
| 930 | Value *LHS, ///< The left-hand-side of the expression |
| 931 | Value *RHS, ///< The right-hand-side of the expression |
| 932 | const std::string &Name, ///< Name of the instruction |
| 933 | BasicBlock *InsertAtEnd ///< Block to insert into. |
| 934 | ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, Name, |
| 935 | InsertAtEnd) { |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 936 | assert(pred >= CmpInst::FIRST_ICMP_PREDICATE && |
| 937 | pred <= CmpInst::LAST_ICMP_PREDICATE && |
| 938 | "Invalid VICmp predicate value"); |
| 939 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
| 940 | "Both operands to VICmp instruction are not of the same type!"); |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | /// @brief Return the predicate for this instruction. |
| 944 | Predicate getPredicate() const { return Predicate(SubclassData); } |
| 945 | |
| 946 | virtual VICmpInst *clone() const; |
| 947 | |
| 948 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 949 | static inline bool classof(const VICmpInst *) { return true; } |
| 950 | static inline bool classof(const Instruction *I) { |
| 951 | return I->getOpcode() == Instruction::VICmp; |
| 952 | } |
| 953 | static inline bool classof(const Value *V) { |
| 954 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 955 | } |
| 956 | }; |
| 957 | |
| 958 | //===----------------------------------------------------------------------===// |
| 959 | // VFCmpInst Class |
| 960 | //===----------------------------------------------------------------------===// |
| 961 | |
| 962 | /// This instruction compares its operands according to the predicate given |
| 963 | /// to the constructor. It only operates on vectors of floating point values. |
| 964 | /// The operands must be identical types. |
| 965 | /// @brief Represents a vector floating point comparison operator. |
| 966 | class VFCmpInst: public CmpInst { |
| 967 | public: |
| 968 | /// @brief Constructor with insert-before-instruction semantics. |
| 969 | VFCmpInst( |
| 970 | Predicate pred, ///< The predicate to use for the comparison |
| 971 | Value *LHS, ///< The left-hand-side of the expression |
| 972 | Value *RHS, ///< The right-hand-side of the expression |
| 973 | const std::string &Name = "", ///< Name of the instruction |
| 974 | Instruction *InsertBefore = 0 ///< Where to insert |
| 975 | ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())), |
| 976 | Instruction::VFCmp, pred, LHS, RHS, Name, InsertBefore) { |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 977 | assert(pred <= CmpInst::LAST_FCMP_PREDICATE && |
| 978 | "Invalid VFCmp predicate value"); |
| 979 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
| 980 | "Both operands to VFCmp instruction are not of the same type!"); |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | /// @brief Constructor with insert-at-block-end semantics. |
| 984 | VFCmpInst( |
| 985 | Predicate pred, ///< The predicate to use for the comparison |
| 986 | Value *LHS, ///< The left-hand-side of the expression |
| 987 | Value *RHS, ///< The right-hand-side of the expression |
| 988 | const std::string &Name, ///< Name of the instruction |
| 989 | BasicBlock *InsertAtEnd ///< Block to insert into. |
| 990 | ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())), |
| 991 | Instruction::VFCmp, pred, LHS, RHS, Name, InsertAtEnd) { |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 992 | assert(pred <= CmpInst::LAST_FCMP_PREDICATE && |
| 993 | "Invalid VFCmp predicate value"); |
| 994 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
| 995 | "Both operands to VFCmp instruction are not of the same type!"); |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | /// @brief Return the predicate for this instruction. |
| 999 | Predicate getPredicate() const { return Predicate(SubclassData); } |
| 1000 | |
| 1001 | virtual VFCmpInst *clone() const; |
| 1002 | |
| 1003 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1004 | static inline bool classof(const VFCmpInst *) { return true; } |
| 1005 | static inline bool classof(const Instruction *I) { |
| 1006 | return I->getOpcode() == Instruction::VFCmp; |
| 1007 | } |
| 1008 | static inline bool classof(const Value *V) { |
| 1009 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1010 | } |
| 1011 | }; |
| 1012 | |
| 1013 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1014 | // CallInst Class |
| 1015 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1016 | /// CallInst - This class represents a function call, abstracting a target |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 1017 | /// machine's calling convention. This class uses low bit of the SubClassData |
| 1018 | /// field to indicate whether or not this is a tail call. The rest of the bits |
| 1019 | /// hold the calling convention of the call. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1020 | /// |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 1021 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1022 | class CallInst : public Instruction { |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 1023 | PAListPtr ParamAttrs; ///< parameter attributes for call |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1024 | CallInst(const CallInst &CI); |
Chris Lattner | d54f432 | 2007-02-13 00:58:44 +0000 | [diff] [blame] | 1025 | void init(Value *Func, Value* const *Params, unsigned NumParams); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1026 | void init(Value *Func, Value *Actual1, Value *Actual2); |
| 1027 | void init(Value *Func, Value *Actual); |
| 1028 | void init(Value *Func); |
| 1029 | |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 1030 | template<typename InputIterator> |
| 1031 | void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
| 1032 | const std::string &Name, |
| 1033 | // This argument ensures that we have an iterator we can |
| 1034 | // do arithmetic on in constant time |
| 1035 | std::random_access_iterator_tag) { |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 1036 | unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd); |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 1037 | |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 1038 | // This requires that the iterator points to contiguous memory. |
| 1039 | init(Func, NumArgs ? &*ArgBegin : 0, NumArgs); |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 1040 | setName(Name); |
| 1041 | } |
| 1042 | |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 1043 | /// Construct a CallInst given a range of arguments. InputIterator |
| 1044 | /// must be a random-access iterator pointing to contiguous storage |
| 1045 | /// (e.g. a std::vector<>::iterator). Checks are made for |
| 1046 | /// random-accessness but not for contiguous storage as that would |
| 1047 | /// incur runtime overhead. |
| 1048 | /// @brief Construct a CallInst from a range of arguments |
| 1049 | template<typename InputIterator> |
| 1050 | CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1051 | const std::string &Name, Instruction *InsertBefore); |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 1052 | |
| 1053 | /// Construct a CallInst given a range of arguments. InputIterator |
| 1054 | /// must be a random-access iterator pointing to contiguous storage |
| 1055 | /// (e.g. a std::vector<>::iterator). Checks are made for |
| 1056 | /// random-accessness but not for contiguous storage as that would |
| 1057 | /// incur runtime overhead. |
| 1058 | /// @brief Construct a CallInst from a range of arguments |
| 1059 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1060 | inline CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
| 1061 | const std::string &Name, BasicBlock *InsertAtEnd); |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 1062 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1063 | CallInst(Value *F, Value *Actual, const std::string& Name, |
| 1064 | Instruction *InsertBefore); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1065 | CallInst(Value *F, Value *Actual, const std::string& Name, |
| 1066 | BasicBlock *InsertAtEnd); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1067 | explicit CallInst(Value *F, const std::string &Name, |
| 1068 | Instruction *InsertBefore); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1069 | CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1070 | public: |
| 1071 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1072 | static CallInst *Create(Value *Func, |
| 1073 | InputIterator ArgBegin, InputIterator ArgEnd, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1074 | const std::string &Name = "", |
| 1075 | Instruction *InsertBefore = 0) { |
Bill Wendling | c2e7353 | 2008-05-10 19:59:59 +0000 | [diff] [blame] | 1076 | return new((unsigned)(ArgEnd - ArgBegin + 1)) |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1077 | CallInst(Func, ArgBegin, ArgEnd, Name, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1078 | } |
| 1079 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1080 | static CallInst *Create(Value *Func, |
| 1081 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 1082 | const std::string &Name, BasicBlock *InsertAtEnd) { |
Bill Wendling | c2e7353 | 2008-05-10 19:59:59 +0000 | [diff] [blame] | 1083 | return new((unsigned)(ArgEnd - ArgBegin + 1)) |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1084 | CallInst(Func, ArgBegin, ArgEnd, Name, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1085 | } |
| 1086 | static CallInst *Create(Value *F, Value *Actual, const std::string& Name = "", |
| 1087 | Instruction *InsertBefore = 0) { |
| 1088 | return new(2) CallInst(F, Actual, Name, InsertBefore); |
| 1089 | } |
| 1090 | static CallInst *Create(Value *F, Value *Actual, const std::string& Name, |
| 1091 | BasicBlock *InsertAtEnd) { |
| 1092 | return new(2) CallInst(F, Actual, Name, InsertAtEnd); |
| 1093 | } |
| 1094 | static CallInst *Create(Value *F, const std::string &Name = "", |
| 1095 | Instruction *InsertBefore = 0) { |
| 1096 | return new(1) CallInst(F, Name, InsertBefore); |
| 1097 | } |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 1098 | static CallInst *Create(Value *F, const std::string &Name, |
| 1099 | BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1100 | return new(1) CallInst(F, Name, InsertAtEnd); |
| 1101 | } |
| 1102 | |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 1103 | ~CallInst(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1104 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1105 | virtual CallInst *clone() const; |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1106 | |
| 1107 | /// Provide fast operand accessors |
| 1108 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Chris Lattner | bb5493d | 2007-02-15 23:15:00 +0000 | [diff] [blame] | 1109 | |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 1110 | bool isTailCall() const { return SubclassData & 1; } |
| 1111 | void setTailCall(bool isTailCall = true) { |
Jeff Cohen | 39cef60 | 2005-05-07 02:44:04 +0000 | [diff] [blame] | 1112 | SubclassData = (SubclassData & ~1) | unsigned(isTailCall); |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | /// getCallingConv/setCallingConv - Get or set the calling convention of this |
| 1116 | /// function call. |
| 1117 | unsigned getCallingConv() const { return SubclassData >> 1; } |
| 1118 | void setCallingConv(unsigned CC) { |
| 1119 | SubclassData = (SubclassData & 1) | (CC << 1); |
| 1120 | } |
Chris Lattner | ddb6db4 | 2005-05-06 05:51:46 +0000 | [diff] [blame] | 1121 | |
Chris Lattner | 041221c | 2008-03-13 04:33:03 +0000 | [diff] [blame] | 1122 | /// getParamAttrs - Return the parameter attributes for this call. |
| 1123 | /// |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 1124 | const PAListPtr &getParamAttrs() const { return ParamAttrs; } |
Reid Spencer | 4746ecf | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 1125 | |
Chris Lattner | 041221c | 2008-03-13 04:33:03 +0000 | [diff] [blame] | 1126 | /// setParamAttrs - Sets the parameter attributes for this call. |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 1127 | void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; } |
Eric Christopher | 0bf7b41 | 2008-05-16 20:39:43 +0000 | [diff] [blame] | 1128 | |
| 1129 | /// addParamAttr - adds the attribute to the list of attributes. |
| 1130 | void addParamAttr(unsigned i, ParameterAttributes attr); |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 1131 | |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 1132 | /// @brief Determine whether the call or the callee has the given attribute. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1133 | bool paramHasAttr(unsigned i, unsigned attr) const; |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 1134 | |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 1135 | /// @brief Extract the alignment for a call or parameter (0=unknown). |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1136 | unsigned getParamAlignment(unsigned i) const { |
| 1137 | return ParamAttrs.getParamAlignment(i); |
| 1138 | } |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 1139 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1140 | /// @brief Determine if the call does not access memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1141 | bool doesNotAccessMemory() const { |
| 1142 | return paramHasAttr(0, ParamAttr::ReadNone); |
| 1143 | } |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 1144 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1145 | /// @brief Determine if the call does not access or only reads memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1146 | bool onlyReadsMemory() const { |
| 1147 | return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly); |
| 1148 | } |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 1149 | |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 1150 | /// @brief Determine if the call cannot return. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1151 | bool doesNotReturn() const { |
| 1152 | return paramHasAttr(0, ParamAttr::NoReturn); |
| 1153 | } |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 1154 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1155 | /// @brief Determine if the call cannot unwind. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1156 | bool doesNotThrow() const { |
| 1157 | return paramHasAttr(0, ParamAttr::NoUnwind); |
| 1158 | } |
Duncan Sands | f0c3354 | 2007-12-19 21:13:37 +0000 | [diff] [blame] | 1159 | void setDoesNotThrow(bool doesNotThrow = true); |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1160 | |
Devang Patel | 41e2397 | 2008-03-03 21:46:28 +0000 | [diff] [blame] | 1161 | /// @brief Determine if the call returns a structure through first |
| 1162 | /// pointer argument. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1163 | bool hasStructRetAttr() const { |
| 1164 | // Be friendly and also check the callee. |
| 1165 | return paramHasAttr(1, ParamAttr::StructRet); |
| 1166 | } |
Reid Spencer | 4746ecf | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 1167 | |
Evan Cheng | f4a5498 | 2008-01-12 18:57:32 +0000 | [diff] [blame] | 1168 | /// @brief Determine if any call argument is an aggregate passed by value. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1169 | bool hasByValArgument() const { |
| 1170 | return ParamAttrs.hasAttrSomewhere(ParamAttr::ByVal); |
| 1171 | } |
Evan Cheng | f4a5498 | 2008-01-12 18:57:32 +0000 | [diff] [blame] | 1172 | |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 1173 | /// getCalledFunction - Return the function being called by this instruction |
| 1174 | /// if it is a direct call. If it is a call through a function pointer, |
| 1175 | /// return null. |
| 1176 | Function *getCalledFunction() const { |
Dan Gohman | 11a7dbf | 2007-09-24 15:46:02 +0000 | [diff] [blame] | 1177 | return dyn_cast<Function>(getOperand(0)); |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 1178 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1179 | |
Reid Spencer | c25ec25 | 2006-12-29 04:10:59 +0000 | [diff] [blame] | 1180 | /// getCalledValue - Get a pointer to the function that is invoked by this |
| 1181 | /// instruction |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1182 | const Value *getCalledValue() const { return getOperand(0); } |
| 1183 | Value *getCalledValue() { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1184 | |
| 1185 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1186 | static inline bool classof(const CallInst *) { return true; } |
| 1187 | static inline bool classof(const Instruction *I) { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1188 | return I->getOpcode() == Instruction::Call; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1189 | } |
| 1190 | static inline bool classof(const Value *V) { |
| 1191 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1192 | } |
| 1193 | }; |
| 1194 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1195 | template <> |
| 1196 | struct OperandTraits<CallInst> : VariadicOperandTraits<1> { |
| 1197 | }; |
| 1198 | |
| 1199 | template<typename InputIterator> |
| 1200 | CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
| 1201 | const std::string &Name, BasicBlock *InsertAtEnd) |
| 1202 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 1203 | ->getElementType())->getReturnType(), |
| 1204 | Instruction::Call, |
| 1205 | OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1), |
Bill Wendling | 1b2f729 | 2008-05-10 11:26:52 +0000 | [diff] [blame] | 1206 | (unsigned)(ArgEnd - ArgBegin + 1), InsertAtEnd) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1207 | init(Func, ArgBegin, ArgEnd, Name, |
| 1208 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 1209 | } |
| 1210 | |
| 1211 | template<typename InputIterator> |
| 1212 | CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
| 1213 | const std::string &Name, Instruction *InsertBefore) |
| 1214 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 1215 | ->getElementType())->getReturnType(), |
| 1216 | Instruction::Call, |
| 1217 | OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1), |
Bill Wendling | 1b2f729 | 2008-05-10 11:26:52 +0000 | [diff] [blame] | 1218 | (unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1219 | init(Func, ArgBegin, ArgEnd, Name, |
| 1220 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 1221 | } |
| 1222 | |
| 1223 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value) |
| 1224 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1225 | //===----------------------------------------------------------------------===// |
| 1226 | // SelectInst Class |
| 1227 | //===----------------------------------------------------------------------===// |
| 1228 | |
| 1229 | /// SelectInst - This class represents the LLVM 'select' instruction. |
| 1230 | /// |
| 1231 | class SelectInst : public Instruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1232 | void init(Value *C, Value *S1, Value *S2) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1233 | Op<0>() = C; |
| 1234 | Op<1>() = S1; |
| 1235 | Op<2>() = S2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1238 | SelectInst(const SelectInst &SI) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1239 | : Instruction(SI.getType(), SI.getOpcode(), &Op<0>(), 3) { |
| 1240 | init(SI.Op<0>(), SI.Op<1>(), SI.Op<2>()); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1241 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1242 | SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name, |
| 1243 | Instruction *InsertBefore) |
| 1244 | : Instruction(S1->getType(), Instruction::Select, |
| 1245 | &Op<0>(), 3, InsertBefore) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1246 | init(C, S1, S2); |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1247 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1248 | } |
| 1249 | SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name, |
| 1250 | BasicBlock *InsertAtEnd) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1251 | : Instruction(S1->getType(), Instruction::Select, |
| 1252 | &Op<0>(), 3, InsertAtEnd) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1253 | init(C, S1, S2); |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1254 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1255 | } |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1256 | public: |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1257 | static SelectInst *Create(Value *C, Value *S1, Value *S2, |
| 1258 | const std::string &Name = "", |
| 1259 | Instruction *InsertBefore = 0) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1260 | return new(3) SelectInst(C, S1, S2, Name, InsertBefore); |
| 1261 | } |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1262 | static SelectInst *Create(Value *C, Value *S1, Value *S2, |
| 1263 | const std::string &Name, BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1264 | return new(3) SelectInst(C, S1, S2, Name, InsertAtEnd); |
| 1265 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1266 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1267 | Value *getCondition() const { return Op<0>(); } |
| 1268 | Value *getTrueValue() const { return Op<1>(); } |
| 1269 | Value *getFalseValue() const { return Op<2>(); } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1270 | |
| 1271 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1272 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1273 | |
| 1274 | OtherOps getOpcode() const { |
| 1275 | return static_cast<OtherOps>(Instruction::getOpcode()); |
| 1276 | } |
| 1277 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1278 | virtual SelectInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1279 | |
| 1280 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1281 | static inline bool classof(const SelectInst *) { return true; } |
| 1282 | static inline bool classof(const Instruction *I) { |
| 1283 | return I->getOpcode() == Instruction::Select; |
| 1284 | } |
| 1285 | static inline bool classof(const Value *V) { |
| 1286 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1287 | } |
| 1288 | }; |
| 1289 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1290 | template <> |
| 1291 | struct OperandTraits<SelectInst> : FixedNumOperandTraits<3> { |
| 1292 | }; |
| 1293 | |
| 1294 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value) |
| 1295 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1296 | //===----------------------------------------------------------------------===// |
| 1297 | // VAArgInst Class |
| 1298 | //===----------------------------------------------------------------------===// |
| 1299 | |
| 1300 | /// VAArgInst - This class represents the va_arg llvm instruction, which returns |
Andrew Lenharth | f542821 | 2005-06-18 18:31:30 +0000 | [diff] [blame] | 1301 | /// 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] | 1302 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1303 | class VAArgInst : public UnaryInstruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1304 | VAArgInst(const VAArgInst &VAA) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1305 | : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {} |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1306 | public: |
| 1307 | VAArgInst(Value *List, const Type *Ty, const std::string &Name = "", |
| 1308 | Instruction *InsertBefore = 0) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1309 | : UnaryInstruction(Ty, VAArg, List, InsertBefore) { |
Chris Lattner | f00042a | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 1310 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1311 | } |
| 1312 | VAArgInst(Value *List, const Type *Ty, const std::string &Name, |
| 1313 | BasicBlock *InsertAtEnd) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1314 | : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) { |
Chris Lattner | f00042a | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 1315 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1318 | virtual VAArgInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1319 | |
| 1320 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1321 | static inline bool classof(const VAArgInst *) { return true; } |
| 1322 | static inline bool classof(const Instruction *I) { |
| 1323 | return I->getOpcode() == VAArg; |
| 1324 | } |
| 1325 | static inline bool classof(const Value *V) { |
| 1326 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1327 | } |
| 1328 | }; |
| 1329 | |
| 1330 | //===----------------------------------------------------------------------===// |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1331 | // ExtractElementInst Class |
| 1332 | //===----------------------------------------------------------------------===// |
| 1333 | |
| 1334 | /// ExtractElementInst - This instruction extracts a single (scalar) |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1335 | /// element from a VectorType value |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1336 | /// |
| 1337 | class ExtractElementInst : public Instruction { |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1338 | ExtractElementInst(const ExtractElementInst &EE) : |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1339 | Instruction(EE.getType(), ExtractElement, &Op<0>(), 2) { |
| 1340 | Op<0>().init(EE.Op<0>(), this); |
| 1341 | Op<1>().init(EE.Op<1>(), this); |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1345 | // allocate space for exactly two operands |
| 1346 | void *operator new(size_t s) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1347 | return User::operator new(s, 2); // FIXME: "unsigned Idx" forms of ctor? |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1348 | } |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1349 | ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "", |
| 1350 | Instruction *InsertBefore = 0); |
Chris Lattner | 06a248c2 | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1351 | ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "", |
| 1352 | Instruction *InsertBefore = 0); |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1353 | ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name, |
| 1354 | BasicBlock *InsertAtEnd); |
Chris Lattner | 06a248c2 | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1355 | ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name, |
| 1356 | BasicBlock *InsertAtEnd); |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1357 | |
Chris Lattner | fa49584 | 2006-04-08 04:04:54 +0000 | [diff] [blame] | 1358 | /// isValidOperands - Return true if an extractelement instruction can be |
| 1359 | /// formed with the specified operands. |
| 1360 | static bool isValidOperands(const Value *Vec, const Value *Idx); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1361 | |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1362 | virtual ExtractElementInst *clone() const; |
| 1363 | |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1364 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1365 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1366 | |
| 1367 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1368 | static inline bool classof(const ExtractElementInst *) { return true; } |
| 1369 | static inline bool classof(const Instruction *I) { |
| 1370 | return I->getOpcode() == Instruction::ExtractElement; |
| 1371 | } |
| 1372 | static inline bool classof(const Value *V) { |
| 1373 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1374 | } |
| 1375 | }; |
| 1376 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1377 | template <> |
| 1378 | struct OperandTraits<ExtractElementInst> : FixedNumOperandTraits<2> { |
| 1379 | }; |
| 1380 | |
| 1381 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value) |
| 1382 | |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1383 | //===----------------------------------------------------------------------===// |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1384 | // InsertElementInst Class |
| 1385 | //===----------------------------------------------------------------------===// |
| 1386 | |
| 1387 | /// InsertElementInst - This instruction inserts a single (scalar) |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1388 | /// element into a VectorType value |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1389 | /// |
| 1390 | class InsertElementInst : public Instruction { |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1391 | InsertElementInst(const InsertElementInst &IE); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1392 | InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, |
| 1393 | const std::string &Name = "",Instruction *InsertBefore = 0); |
| 1394 | InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx, |
| 1395 | const std::string &Name = "",Instruction *InsertBefore = 0); |
| 1396 | InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, |
| 1397 | const std::string &Name, BasicBlock *InsertAtEnd); |
| 1398 | InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx, |
| 1399 | const std::string &Name, BasicBlock *InsertAtEnd); |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1400 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1401 | static InsertElementInst *Create(const InsertElementInst &IE) { |
| 1402 | return new(IE.getNumOperands()) InsertElementInst(IE); |
| 1403 | } |
| 1404 | static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1405 | const std::string &Name = "", |
| 1406 | Instruction *InsertBefore = 0) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1407 | return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore); |
| 1408 | } |
| 1409 | static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1410 | const std::string &Name = "", |
| 1411 | Instruction *InsertBefore = 0) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1412 | return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1413 | } |
| 1414 | static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1415 | const std::string &Name, |
| 1416 | BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1417 | return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd); |
| 1418 | } |
| 1419 | static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1420 | const std::string &Name, |
| 1421 | BasicBlock *InsertAtEnd) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1422 | return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1423 | } |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1424 | |
Chris Lattner | fa49584 | 2006-04-08 04:04:54 +0000 | [diff] [blame] | 1425 | /// isValidOperands - Return true if an insertelement instruction can be |
| 1426 | /// formed with the specified operands. |
| 1427 | static bool isValidOperands(const Value *Vec, const Value *NewElt, |
| 1428 | const Value *Idx); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1429 | |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1430 | virtual InsertElementInst *clone() const; |
| 1431 | |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1432 | /// getType - Overload to return most specific vector type. |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1433 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1434 | const VectorType *getType() const { |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1435 | return reinterpret_cast<const VectorType*>(Instruction::getType()); |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1436 | } |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1437 | |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1438 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1439 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1440 | |
| 1441 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1442 | static inline bool classof(const InsertElementInst *) { return true; } |
| 1443 | static inline bool classof(const Instruction *I) { |
| 1444 | return I->getOpcode() == Instruction::InsertElement; |
| 1445 | } |
| 1446 | static inline bool classof(const Value *V) { |
| 1447 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1448 | } |
| 1449 | }; |
| 1450 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1451 | template <> |
| 1452 | struct OperandTraits<InsertElementInst> : FixedNumOperandTraits<3> { |
| 1453 | }; |
| 1454 | |
| 1455 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value) |
| 1456 | |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1457 | //===----------------------------------------------------------------------===// |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1458 | // ShuffleVectorInst Class |
| 1459 | //===----------------------------------------------------------------------===// |
| 1460 | |
| 1461 | /// ShuffleVectorInst - This instruction constructs a fixed permutation of two |
| 1462 | /// input vectors. |
| 1463 | /// |
| 1464 | class ShuffleVectorInst : public Instruction { |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1465 | ShuffleVectorInst(const ShuffleVectorInst &IE); |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1466 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1467 | // allocate space for exactly three operands |
| 1468 | void *operator new(size_t s) { |
| 1469 | return User::operator new(s, 3); |
| 1470 | } |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1471 | ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
| 1472 | const std::string &Name = "", Instruction *InsertBefor = 0); |
| 1473 | ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
| 1474 | const std::string &Name, BasicBlock *InsertAtEnd); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1475 | |
Chris Lattner | fa49584 | 2006-04-08 04:04:54 +0000 | [diff] [blame] | 1476 | /// isValidOperands - Return true if a shufflevector instruction can be |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1477 | /// formed with the specified operands. |
| 1478 | static bool isValidOperands(const Value *V1, const Value *V2, |
| 1479 | const Value *Mask); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1480 | |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1481 | virtual ShuffleVectorInst *clone() const; |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1482 | |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1483 | /// getType - Overload to return most specific vector type. |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1484 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1485 | const VectorType *getType() const { |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1486 | return reinterpret_cast<const VectorType*>(Instruction::getType()); |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1487 | } |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1488 | |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1489 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1490 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Chris Lattner | 8728f19 | 2008-03-02 05:28:33 +0000 | [diff] [blame] | 1491 | |
| 1492 | /// getMaskValue - Return the index from the shuffle mask for the specified |
| 1493 | /// output result. This is either -1 if the element is undef or a number less |
| 1494 | /// than 2*numelements. |
| 1495 | int getMaskValue(unsigned i) const; |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1496 | |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1497 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1498 | static inline bool classof(const ShuffleVectorInst *) { return true; } |
| 1499 | static inline bool classof(const Instruction *I) { |
| 1500 | return I->getOpcode() == Instruction::ShuffleVector; |
| 1501 | } |
| 1502 | static inline bool classof(const Value *V) { |
| 1503 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1504 | } |
| 1505 | }; |
| 1506 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1507 | template <> |
| 1508 | struct OperandTraits<ShuffleVectorInst> : FixedNumOperandTraits<3> { |
| 1509 | }; |
| 1510 | |
| 1511 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value) |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1512 | |
| 1513 | //===----------------------------------------------------------------------===// |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1514 | // ExtractValueInst Class |
| 1515 | //===----------------------------------------------------------------------===// |
| 1516 | |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1517 | /// ExtractValueInst - This instruction extracts a struct member or array |
| 1518 | /// element value from an aggregate value. |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1519 | /// |
| 1520 | class ExtractValueInst : public Instruction { |
| 1521 | ExtractValueInst(const ExtractValueInst &EVI); |
| 1522 | void init(Value *Agg, Value* const *Idx, unsigned NumIdx); |
| 1523 | void init(Value *Agg, Value *Idx); |
| 1524 | |
| 1525 | template<typename InputIterator> |
| 1526 | void init(Value *Agg, InputIterator IdxBegin, InputIterator IdxEnd, |
| 1527 | const std::string &Name, |
| 1528 | // This argument ensures that we have an iterator we can |
| 1529 | // do arithmetic on in constant time |
| 1530 | std::random_access_iterator_tag) { |
| 1531 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
| 1532 | |
| 1533 | if (NumIdx > 0) { |
| 1534 | // This requires that the iterator points to contiguous memory. |
| 1535 | init(Agg, &*IdxBegin, NumIdx); // FIXME: for the general case |
| 1536 | // we have to build an array here |
| 1537 | } |
| 1538 | else { |
| 1539 | init(Agg, 0, NumIdx); |
| 1540 | } |
| 1541 | |
| 1542 | setName(Name); |
| 1543 | } |
| 1544 | |
| 1545 | /// getIndexedType - Returns the type of the element that would be extracted |
| 1546 | /// with an extractvalue instruction with the specified parameters. |
| 1547 | /// |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1548 | /// Null is returned if the indices are invalid for the specified |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1549 | /// pointer type. |
| 1550 | /// |
| 1551 | static const Type *getIndexedType(const Type *Agg, |
| 1552 | Value* const *Idx, unsigned NumIdx); |
| 1553 | |
| 1554 | template<typename InputIterator> |
| 1555 | static const Type *getIndexedType(const Type *Ptr, |
| 1556 | InputIterator IdxBegin, |
| 1557 | InputIterator IdxEnd, |
| 1558 | // This argument ensures that we |
| 1559 | // have an iterator we can do |
| 1560 | // arithmetic on in constant time |
| 1561 | std::random_access_iterator_tag) { |
| 1562 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
| 1563 | |
| 1564 | if (NumIdx > 0) |
| 1565 | // This requires that the iterator points to contiguous memory. |
| 1566 | return getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx); |
| 1567 | else |
| 1568 | return getIndexedType(Ptr, (Value *const*)0, NumIdx); |
| 1569 | } |
| 1570 | |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1571 | /// Constructors - Create a extractvalue instruction with a base aggregate |
| 1572 | /// value and a list of indices. The first ctor can optionally insert before |
| 1573 | /// an existing instruction, the second appends the new instruction to the |
| 1574 | /// specified BasicBlock. |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1575 | template<typename InputIterator> |
| 1576 | inline ExtractValueInst(Value *Agg, InputIterator IdxBegin, |
| 1577 | InputIterator IdxEnd, |
| 1578 | unsigned Values, |
| 1579 | const std::string &Name, |
| 1580 | Instruction *InsertBefore); |
| 1581 | template<typename InputIterator> |
| 1582 | inline ExtractValueInst(Value *Agg, |
| 1583 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 1584 | unsigned Values, |
| 1585 | const std::string &Name, BasicBlock *InsertAtEnd); |
| 1586 | |
| 1587 | /// Constructors - These two constructors are convenience methods because one |
| 1588 | /// and two index extractvalue instructions are so common. |
| 1589 | ExtractValueInst(Value *Agg, Value *Idx, const std::string &Name = "", |
| 1590 | Instruction *InsertBefore = 0); |
| 1591 | ExtractValueInst(Value *Agg, Value *Idx, |
| 1592 | const std::string &Name, BasicBlock *InsertAtEnd); |
| 1593 | public: |
| 1594 | template<typename InputIterator> |
| 1595 | static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin, |
| 1596 | InputIterator IdxEnd, |
| 1597 | const std::string &Name = "", |
| 1598 | Instruction *InsertBefore = 0) { |
| 1599 | typename std::iterator_traits<InputIterator>::difference_type Values = |
| 1600 | 1 + std::distance(IdxBegin, IdxEnd); |
| 1601 | return new(Values) |
| 1602 | ExtractValueInst(Agg, IdxBegin, IdxEnd, Values, Name, InsertBefore); |
| 1603 | } |
| 1604 | template<typename InputIterator> |
| 1605 | static ExtractValueInst *Create(Value *Agg, |
| 1606 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 1607 | const std::string &Name, |
| 1608 | BasicBlock *InsertAtEnd) { |
| 1609 | typename std::iterator_traits<InputIterator>::difference_type Values = |
| 1610 | 1 + std::distance(IdxBegin, IdxEnd); |
| 1611 | return new(Values) |
| 1612 | ExtractValueInst(Agg, IdxBegin, IdxEnd, Values, Name, InsertAtEnd); |
| 1613 | } |
| 1614 | |
| 1615 | /// Constructors - These two creators are convenience methods because one |
| 1616 | /// index extractvalue instructions are much more common than those with |
| 1617 | /// more than one. |
| 1618 | static ExtractValueInst *Create(Value *Agg, Value *Idx, |
| 1619 | const std::string &Name = "", |
| 1620 | Instruction *InsertBefore = 0) { |
| 1621 | return new(2) ExtractValueInst(Agg, Idx, Name, InsertBefore); |
| 1622 | } |
| 1623 | static ExtractValueInst *Create(Value *Agg, Value *Idx, |
| 1624 | const std::string &Name, |
| 1625 | BasicBlock *InsertAtEnd) { |
| 1626 | return new(2) ExtractValueInst(Agg, Idx, Name, InsertAtEnd); |
| 1627 | } |
| 1628 | |
| 1629 | virtual ExtractValueInst *clone() const; |
| 1630 | |
| 1631 | /// Transparently provide more efficient getOperand methods. |
| 1632 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 1633 | |
| 1634 | // getType - Overload to return most specific pointer type... |
| 1635 | const PointerType *getType() const { |
| 1636 | return reinterpret_cast<const PointerType*>(Instruction::getType()); |
| 1637 | } |
| 1638 | |
| 1639 | /// getIndexedType - Returns the type of the element that would be extracted |
| 1640 | /// with an extractvalue instruction with the specified parameters. |
| 1641 | /// |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1642 | /// Null is returned if the indices are invalid for the specified |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1643 | /// pointer type. |
| 1644 | /// |
| 1645 | template<typename InputIterator> |
| 1646 | static const Type *getIndexedType(const Type *Ptr, |
| 1647 | InputIterator IdxBegin, |
| 1648 | InputIterator IdxEnd) { |
| 1649 | return getIndexedType(Ptr, IdxBegin, IdxEnd, |
| 1650 | typename std::iterator_traits<InputIterator>:: |
| 1651 | iterator_category()); |
| 1652 | } |
| 1653 | static const Type *getIndexedType(const Type *Ptr, Value *Idx); |
| 1654 | |
| 1655 | inline op_iterator idx_begin() { return op_begin()+1; } |
| 1656 | inline const_op_iterator idx_begin() const { return op_begin()+1; } |
| 1657 | inline op_iterator idx_end() { return op_end(); } |
| 1658 | inline const_op_iterator idx_end() const { return op_end(); } |
| 1659 | |
| 1660 | Value *getAggregateOperand() { |
| 1661 | return getOperand(0); |
| 1662 | } |
| 1663 | const Value *getAggregateOperand() const { |
| 1664 | return getOperand(0); |
| 1665 | } |
| 1666 | static unsigned getAggregateOperandIndex() { |
| 1667 | return 0U; // get index for modifying correct operand |
| 1668 | } |
| 1669 | |
| 1670 | unsigned getNumIndices() const { // Note: always non-negative |
| 1671 | return getNumOperands() - 1; |
| 1672 | } |
| 1673 | |
| 1674 | bool hasIndices() const { |
| 1675 | return getNumOperands() > 1; |
| 1676 | } |
| 1677 | |
| 1678 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1679 | static inline bool classof(const ExtractValueInst *) { return true; } |
| 1680 | static inline bool classof(const Instruction *I) { |
| 1681 | return I->getOpcode() == Instruction::ExtractValue; |
| 1682 | } |
| 1683 | static inline bool classof(const Value *V) { |
| 1684 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1685 | } |
| 1686 | }; |
| 1687 | |
| 1688 | template <> |
| 1689 | struct OperandTraits<ExtractValueInst> : VariadicOperandTraits<1> { |
| 1690 | }; |
| 1691 | |
| 1692 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractValueInst, Value) |
| 1693 | |
| 1694 | //===----------------------------------------------------------------------===// |
| 1695 | // InsertValueInst Class |
| 1696 | //===----------------------------------------------------------------------===// |
| 1697 | |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1698 | /// InsertValueInst - This instruction inserts a struct field of array element |
| 1699 | /// value into an aggregate value. |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1700 | /// |
| 1701 | class InsertValueInst : public Instruction { |
| 1702 | InsertValueInst(const InsertValueInst &IVI); |
| 1703 | void init(Value *Agg, Value *Val, Value* const *Idx, unsigned NumIdx); |
| 1704 | void init(Value *Agg, Value *Val, Value *Idx); |
| 1705 | |
| 1706 | template<typename InputIterator> |
| 1707 | void init(Value *Agg, Value *Val, |
| 1708 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 1709 | const std::string &Name, |
| 1710 | // This argument ensures that we have an iterator we can |
| 1711 | // do arithmetic on in constant time |
| 1712 | std::random_access_iterator_tag) { |
| 1713 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
| 1714 | |
| 1715 | if (NumIdx > 0) { |
| 1716 | // This requires that the iterator points to contiguous memory. |
| 1717 | init(Agg, Val, &*IdxBegin, NumIdx); // FIXME: for the general case |
| 1718 | // we have to build an array here |
| 1719 | } |
| 1720 | else { |
| 1721 | init(Agg, Val, 0, NumIdx); |
| 1722 | } |
| 1723 | |
| 1724 | setName(Name); |
| 1725 | } |
| 1726 | |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1727 | /// Constructors - Create a insertvalue instruction with a base aggregate |
| 1728 | /// value, a value to insert, and a list of indices. The first ctor can |
| 1729 | /// optionally insert before an existing instruction, the second appends |
| 1730 | /// the new instruction to the specified BasicBlock. |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1731 | template<typename InputIterator> |
| 1732 | inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin, |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1733 | InputIterator IdxEnd, |
| 1734 | unsigned Values, |
| 1735 | const std::string &Name, |
| 1736 | Instruction *InsertBefore); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1737 | template<typename InputIterator> |
| 1738 | inline InsertValueInst(Value *Agg, Value *Val, |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1739 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 1740 | unsigned Values, |
| 1741 | const std::string &Name, BasicBlock *InsertAtEnd); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1742 | |
| 1743 | /// Constructors - These two constructors are convenience methods because one |
| 1744 | /// and two index insertvalue instructions are so common. |
| 1745 | InsertValueInst(Value *Agg, Value *Val, |
| 1746 | Value *Idx, const std::string &Name = "", |
| 1747 | Instruction *InsertBefore = 0); |
| 1748 | InsertValueInst(Value *Agg, Value *Val, Value *Idx, |
| 1749 | const std::string &Name, BasicBlock *InsertAtEnd); |
| 1750 | public: |
| 1751 | template<typename InputIterator> |
| 1752 | static InsertValueInst *Create(Value *Agg, Value *Val, InputIterator IdxBegin, |
| 1753 | InputIterator IdxEnd, |
| 1754 | const std::string &Name = "", |
| 1755 | Instruction *InsertBefore = 0) { |
| 1756 | typename std::iterator_traits<InputIterator>::difference_type Values = |
| 1757 | 1 + std::distance(IdxBegin, IdxEnd); |
| 1758 | return new(Values) |
| 1759 | InsertValueInst(Agg, Val, IdxBegin, IdxEnd, Values, Name, InsertBefore); |
| 1760 | } |
| 1761 | template<typename InputIterator> |
| 1762 | static InsertValueInst *Create(Value *Agg, Value *Val, |
| 1763 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 1764 | const std::string &Name, |
| 1765 | BasicBlock *InsertAtEnd) { |
| 1766 | typename std::iterator_traits<InputIterator>::difference_type Values = |
| 1767 | 1 + std::distance(IdxBegin, IdxEnd); |
| 1768 | return new(Values) |
| 1769 | InsertValueInst(Agg, Val, IdxBegin, IdxEnd, Values, Name, InsertAtEnd); |
| 1770 | } |
| 1771 | |
| 1772 | /// Constructors - These two creators are convenience methods because one |
| 1773 | /// index insertvalue instructions are much more common than those with |
| 1774 | /// more than one. |
| 1775 | static InsertValueInst *Create(Value *Agg, Value *Val, Value *Idx, |
| 1776 | const std::string &Name = "", |
| 1777 | Instruction *InsertBefore = 0) { |
| 1778 | return new(3) InsertValueInst(Agg, Val, Idx, Name, InsertBefore); |
| 1779 | } |
| 1780 | static InsertValueInst *Create(Value *Agg, Value *Val, Value *Idx, |
| 1781 | const std::string &Name, |
| 1782 | BasicBlock *InsertAtEnd) { |
| 1783 | return new(3) InsertValueInst(Agg, Val, Idx, Name, InsertAtEnd); |
| 1784 | } |
| 1785 | |
| 1786 | virtual InsertValueInst *clone() const; |
| 1787 | |
| 1788 | /// Transparently provide more efficient getOperand methods. |
| 1789 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 1790 | |
| 1791 | // getType - Overload to return most specific pointer type... |
| 1792 | const PointerType *getType() const { |
| 1793 | return reinterpret_cast<const PointerType*>(Instruction::getType()); |
| 1794 | } |
| 1795 | |
| 1796 | inline op_iterator idx_begin() { return op_begin()+1; } |
| 1797 | inline const_op_iterator idx_begin() const { return op_begin()+1; } |
| 1798 | inline op_iterator idx_end() { return op_end(); } |
| 1799 | inline const_op_iterator idx_end() const { return op_end(); } |
| 1800 | |
| 1801 | Value *getAggregateOperand() { |
| 1802 | return getOperand(0); |
| 1803 | } |
| 1804 | const Value *getAggregateOperand() const { |
| 1805 | return getOperand(0); |
| 1806 | } |
| 1807 | static unsigned getAggregateOperandIndex() { |
| 1808 | return 0U; // get index for modifying correct operand |
| 1809 | } |
| 1810 | |
| 1811 | Value *getInsertedValueOperand() { |
| 1812 | return getOperand(1); |
| 1813 | } |
| 1814 | const Value *getInsertedValueOperand() const { |
| 1815 | return getOperand(1); |
| 1816 | } |
| 1817 | static unsigned getInsertedValueOperandIndex() { |
| 1818 | return 1U; // get index for modifying correct operand |
| 1819 | } |
| 1820 | |
| 1821 | unsigned getNumIndices() const { // Note: always non-negative |
| 1822 | return getNumOperands() - 2; |
| 1823 | } |
| 1824 | |
| 1825 | bool hasIndices() const { |
| 1826 | return getNumOperands() > 2; |
| 1827 | } |
| 1828 | |
| 1829 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1830 | static inline bool classof(const InsertValueInst *) { return true; } |
| 1831 | static inline bool classof(const Instruction *I) { |
| 1832 | return I->getOpcode() == Instruction::InsertValue; |
| 1833 | } |
| 1834 | static inline bool classof(const Value *V) { |
| 1835 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1836 | } |
| 1837 | }; |
| 1838 | |
| 1839 | template <> |
| 1840 | struct OperandTraits<InsertValueInst> : VariadicOperandTraits<2> { |
| 1841 | }; |
| 1842 | |
| 1843 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value) |
| 1844 | |
| 1845 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1846 | // PHINode Class |
| 1847 | //===----------------------------------------------------------------------===// |
| 1848 | |
| 1849 | // PHINode - The PHINode class is used to represent the magical mystical PHI |
| 1850 | // node, that can not exist in nature, but can be synthesized in a computer |
| 1851 | // scientist's overactive imagination. |
| 1852 | // |
| 1853 | class PHINode : public Instruction { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1854 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1855 | /// ReservedSpace - The number of operands actually allocated. NumOperands is |
| 1856 | /// the number actually in use. |
| 1857 | unsigned ReservedSpace; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1858 | PHINode(const PHINode &PN); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1859 | // allocate space for exactly zero operands |
| 1860 | void *operator new(size_t s) { |
| 1861 | return User::operator new(s, 0); |
| 1862 | } |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1863 | explicit PHINode(const Type *Ty, const std::string &Name = "", |
| 1864 | Instruction *InsertBefore = 0) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1865 | : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore), |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1866 | ReservedSpace(0) { |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1867 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1871 | : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd), |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1872 | ReservedSpace(0) { |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1873 | setName(Name); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1874 | } |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1875 | public: |
| 1876 | static PHINode *Create(const Type *Ty, const std::string &Name = "", |
| 1877 | Instruction *InsertBefore = 0) { |
| 1878 | return new PHINode(Ty, Name, InsertBefore); |
| 1879 | } |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1880 | static PHINode *Create(const Type *Ty, const std::string &Name, |
| 1881 | BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1882 | return new PHINode(Ty, Name, InsertAtEnd); |
| 1883 | } |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 1884 | ~PHINode(); |
| 1885 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1886 | /// reserveOperandSpace - This method can be used to avoid repeated |
| 1887 | /// reallocation of PHI operand lists by reserving space for the correct |
| 1888 | /// number of operands before adding them. Unlike normal vector reserves, |
| 1889 | /// this method can also be used to trim the operand space. |
| 1890 | void reserveOperandSpace(unsigned NumValues) { |
| 1891 | resizeOperands(NumValues*2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1892 | } |
| 1893 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1894 | virtual PHINode *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1895 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1896 | /// Provide fast operand accessors |
| 1897 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 1898 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1899 | /// getNumIncomingValues - Return the number of incoming edges |
| 1900 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1901 | unsigned getNumIncomingValues() const { return getNumOperands()/2; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1902 | |
Reid Spencer | c773de6 | 2006-05-19 19:07:54 +0000 | [diff] [blame] | 1903 | /// getIncomingValue - Return incoming value number x |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1904 | /// |
| 1905 | Value *getIncomingValue(unsigned i) const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1906 | assert(i*2 < getNumOperands() && "Invalid value number!"); |
| 1907 | return getOperand(i*2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1908 | } |
| 1909 | void setIncomingValue(unsigned i, Value *V) { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1910 | assert(i*2 < getNumOperands() && "Invalid value number!"); |
| 1911 | setOperand(i*2, V); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1912 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1913 | unsigned getOperandNumForIncomingValue(unsigned i) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1914 | return i*2; |
| 1915 | } |
| 1916 | |
Reid Spencer | c773de6 | 2006-05-19 19:07:54 +0000 | [diff] [blame] | 1917 | /// getIncomingBlock - Return incoming basic block number x |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1918 | /// |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1919 | BasicBlock *getIncomingBlock(unsigned i) const { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1920 | return static_cast<BasicBlock*>(getOperand(i*2+1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1921 | } |
| 1922 | void setIncomingBlock(unsigned i, BasicBlock *BB) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1923 | setOperand(i*2+1, BB); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1924 | } |
| 1925 | unsigned getOperandNumForIncomingBlock(unsigned i) { |
| 1926 | return i*2+1; |
| 1927 | } |
| 1928 | |
| 1929 | /// addIncoming - Add an incoming value to the end of the PHI list |
| 1930 | /// |
| 1931 | void addIncoming(Value *V, BasicBlock *BB) { |
Anton Korobeynikov | 351b0d4 | 2008-02-27 22:37:28 +0000 | [diff] [blame] | 1932 | assert(V && "PHI node got a null value!"); |
| 1933 | assert(BB && "PHI node got a null basic block!"); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1934 | assert(getType() == V->getType() && |
| 1935 | "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] | 1936 | unsigned OpNo = NumOperands; |
| 1937 | if (OpNo+2 > ReservedSpace) |
| 1938 | resizeOperands(0); // Get more space! |
| 1939 | // Initialize some new operands. |
| 1940 | NumOperands = OpNo+2; |
| 1941 | OperandList[OpNo].init(V, this); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1942 | OperandList[OpNo+1].init(BB, this); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1943 | } |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1944 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1945 | /// removeIncomingValue - Remove an incoming value. This is useful if a |
| 1946 | /// predecessor basic block is deleted. The value removed is returned. |
| 1947 | /// |
| 1948 | /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty |
| 1949 | /// is true), the PHI node is destroyed and any uses of it are replaced with |
| 1950 | /// dummy values. The only time there should be zero incoming values to a PHI |
| 1951 | /// node is when the block is dead, so this strategy is sound. |
| 1952 | /// |
| 1953 | Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true); |
| 1954 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1955 | Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1956 | int Idx = getBasicBlockIndex(BB); |
| 1957 | assert(Idx >= 0 && "Invalid basic block argument to remove!"); |
| 1958 | return removeIncomingValue(Idx, DeletePHIIfEmpty); |
| 1959 | } |
| 1960 | |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1961 | /// getBasicBlockIndex - Return the first index of the specified basic |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1962 | /// block in the value list for this PHI. Returns -1 if no instance. |
| 1963 | /// |
| 1964 | int getBasicBlockIndex(const BasicBlock *BB) const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1965 | Use *OL = OperandList; |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1966 | for (unsigned i = 0, e = getNumOperands(); i != e; i += 2) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1967 | if (OL[i+1].get() == BB) return i/2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1968 | return -1; |
| 1969 | } |
| 1970 | |
| 1971 | Value *getIncomingValueForBlock(const BasicBlock *BB) const { |
| 1972 | return getIncomingValue(getBasicBlockIndex(BB)); |
| 1973 | } |
| 1974 | |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1975 | /// hasConstantValue - If the specified PHI node always merges together the |
Nate Begeman | a83ba0f | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 1976 | /// same value, return the value, otherwise return null. |
| 1977 | /// |
Chris Lattner | 9acbd61 | 2005-08-05 00:49:06 +0000 | [diff] [blame] | 1978 | Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const; |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1979 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1980 | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1981 | static inline bool classof(const PHINode *) { return true; } |
| 1982 | static inline bool classof(const Instruction *I) { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1983 | return I->getOpcode() == Instruction::PHI; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1984 | } |
| 1985 | static inline bool classof(const Value *V) { |
| 1986 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1987 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1988 | private: |
| 1989 | void resizeOperands(unsigned NumOperands); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1990 | }; |
| 1991 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1992 | template <> |
| 1993 | struct OperandTraits<PHINode> : HungoffOperandTraits<2> { |
| 1994 | }; |
| 1995 | |
| 1996 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value) |
| 1997 | |
| 1998 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1999 | //===----------------------------------------------------------------------===// |
| 2000 | // ReturnInst Class |
| 2001 | //===----------------------------------------------------------------------===// |
| 2002 | |
| 2003 | //===--------------------------------------------------------------------------- |
| 2004 | /// ReturnInst - Return a value (possibly void), from a function. Execution |
| 2005 | /// does not continue in this function any longer. |
| 2006 | /// |
| 2007 | class ReturnInst : public TerminatorInst { |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2008 | ReturnInst(const ReturnInst &RI); |
Devang Patel | fea9830 | 2008-02-26 19:15:26 +0000 | [diff] [blame] | 2009 | void init(Value * const* retVals, unsigned N); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2010 | |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2011 | private: |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2012 | // ReturnInst constructors: |
| 2013 | // ReturnInst() - 'ret void' instruction |
Alkis Evlogimenos | 859804f | 2004-11-17 21:02:25 +0000 | [diff] [blame] | 2014 | // ReturnInst( null) - 'ret void' instruction |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2015 | // ReturnInst(Value* X) - 'ret X' instruction |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2016 | // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2017 | // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2018 | // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B |
| 2019 | // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B |
Devang Patel | e6be34a | 2008-02-27 01:20:54 +0000 | [diff] [blame] | 2020 | // ReturnInst(Value* X, N) - 'ret X,X+1...X+N-1' instruction |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2021 | // ReturnInst(Value* X, N, Inst *I) - 'ret X,X+1...X+N-1', insert before I |
| 2022 | // 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] | 2023 | // |
| 2024 | // NOTE: If the Value* passed is of type void then the constructor behaves as |
| 2025 | // if it was passed NULL. |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2026 | explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0); |
| 2027 | ReturnInst(Value *retVal, BasicBlock *InsertAtEnd); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2028 | ReturnInst(Value * const* retVals, unsigned N, Instruction *InsertBefore = 0); |
Devang Patel | f4511cd | 2008-02-26 19:38:17 +0000 | [diff] [blame] | 2029 | ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd); |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2030 | explicit ReturnInst(BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2031 | public: |
| 2032 | static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) { |
| 2033 | return new(!!retVal) ReturnInst(retVal, InsertBefore); |
| 2034 | } |
| 2035 | static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) { |
| 2036 | return new(!!retVal) ReturnInst(retVal, InsertAtEnd); |
| 2037 | } |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 2038 | static ReturnInst* Create(Value * const* retVals, unsigned N, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2039 | Instruction *InsertBefore = 0) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2040 | return new(N) ReturnInst(retVals, N, InsertBefore); |
| 2041 | } |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 2042 | static ReturnInst* Create(Value * const* retVals, unsigned N, |
| 2043 | BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2044 | return new(N) ReturnInst(retVals, N, InsertAtEnd); |
| 2045 | } |
| 2046 | static ReturnInst* Create(BasicBlock *InsertAtEnd) { |
| 2047 | return new(0) ReturnInst(InsertAtEnd); |
| 2048 | } |
Devang Patel | 57ef4f4 | 2008-02-23 00:35:18 +0000 | [diff] [blame] | 2049 | virtual ~ReturnInst(); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2050 | inline void operator delete(void*); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2051 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 2052 | virtual ReturnInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2053 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2054 | /// Provide fast operand accessors |
| 2055 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Devang Patel | 64d4e61 | 2008-02-26 17:56:20 +0000 | [diff] [blame] | 2056 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2057 | /// Convenience accessor |
Devang Patel | 1eafa06 | 2008-03-11 17:35:03 +0000 | [diff] [blame] | 2058 | Value *getReturnValue(unsigned n = 0) const { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2059 | return n < getNumOperands() |
| 2060 | ? getOperand(n) |
| 2061 | : 0; |
Devang Patel | 1eafa06 | 2008-03-11 17:35:03 +0000 | [diff] [blame] | 2062 | } |
| 2063 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2064 | unsigned getNumSuccessors() const { return 0; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2065 | |
| 2066 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2067 | static inline bool classof(const ReturnInst *) { return true; } |
| 2068 | static inline bool classof(const Instruction *I) { |
| 2069 | return (I->getOpcode() == Instruction::Ret); |
| 2070 | } |
| 2071 | static inline bool classof(const Value *V) { |
| 2072 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2073 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2074 | private: |
| 2075 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2076 | virtual unsigned getNumSuccessorsV() const; |
| 2077 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2078 | }; |
| 2079 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2080 | template <> |
| 2081 | struct OperandTraits<ReturnInst> : VariadicOperandTraits<> { |
| 2082 | }; |
| 2083 | |
| 2084 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value) |
| 2085 | void ReturnInst::operator delete(void *it) { |
| 2086 | ReturnInst* me(static_cast<ReturnInst*>(it)); |
| 2087 | Use::zap(OperandTraits<ReturnInst>::op_begin(me), |
| 2088 | OperandTraits<ReturnInst>::op_end(me), |
| 2089 | true); |
| 2090 | } |
| 2091 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2092 | //===----------------------------------------------------------------------===// |
| 2093 | // BranchInst Class |
| 2094 | //===----------------------------------------------------------------------===// |
| 2095 | |
| 2096 | //===--------------------------------------------------------------------------- |
| 2097 | /// BranchInst - Conditional or Unconditional Branch instruction. |
| 2098 | /// |
| 2099 | class BranchInst : public TerminatorInst { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2100 | /// Ops list - Branches are strange. The operands are ordered: |
| 2101 | /// TrueDest, FalseDest, Cond. This makes some accessors faster because |
| 2102 | /// they don't have to check for cond/uncond branchness. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2103 | BranchInst(const BranchInst &BI); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2104 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2105 | // BranchInst constructors (where {B, T, F} are blocks, and C is a condition): |
| 2106 | // BranchInst(BB *B) - 'br B' |
| 2107 | // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F' |
| 2108 | // BranchInst(BB* B, Inst *I) - 'br B' insert before I |
| 2109 | // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I |
| 2110 | // BranchInst(BB* B, BB *I) - 'br B' insert at end |
| 2111 | // 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] | 2112 | explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2113 | BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2114 | Instruction *InsertBefore = 0); |
| 2115 | BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2116 | BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2117 | BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2118 | public: |
| 2119 | static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) { |
| 2120 | return new(1) BranchInst(IfTrue, InsertBefore); |
| 2121 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2122 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, |
| 2123 | Value *Cond, Instruction *InsertBefore = 0) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2124 | return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore); |
| 2125 | } |
| 2126 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) { |
| 2127 | return new(1) BranchInst(IfTrue, InsertAtEnd); |
| 2128 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2129 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, |
| 2130 | Value *Cond, BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2131 | return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd); |
| 2132 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2133 | |
Bill Wendling | d2a5a2a | 2008-05-10 10:58:07 +0000 | [diff] [blame] | 2134 | ~BranchInst() { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2135 | if (NumOperands == 1) |
Bill Wendling | c2e7353 | 2008-05-10 19:59:59 +0000 | [diff] [blame] | 2136 | NumOperands = (unsigned)((Use*)this - OperandList); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2137 | } |
| 2138 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2139 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2140 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
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 BranchInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2143 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2144 | bool isUnconditional() const { return getNumOperands() == 1; } |
| 2145 | bool isConditional() const { return getNumOperands() == 3; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2146 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2147 | Value *getCondition() const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2148 | assert(isConditional() && "Cannot get condition of an uncond branch!"); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2149 | return getOperand(2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | void setCondition(Value *V) { |
| 2153 | assert(isConditional() && "Cannot set condition of unconditional branch!"); |
| 2154 | setOperand(2, V); |
| 2155 | } |
| 2156 | |
| 2157 | // setUnconditionalDest - Change the current branch to an unconditional branch |
| 2158 | // targeting the specified block. |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2159 | // FIXME: Eliminate this ugly method. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2160 | void setUnconditionalDest(BasicBlock *Dest) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2161 | Op<0>() = Dest; |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2162 | if (isConditional()) { // Convert this to an uncond branch. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2163 | Op<1>().set(0); |
| 2164 | Op<2>().set(0); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2165 | NumOperands = 1; |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2166 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2167 | } |
| 2168 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2169 | unsigned getNumSuccessors() const { return 1+isConditional(); } |
| 2170 | |
| 2171 | BasicBlock *getSuccessor(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2172 | assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); |
Dan Gohman | b96039e | 2007-05-11 20:59:29 +0000 | [diff] [blame] | 2173 | return cast<BasicBlock>(getOperand(i)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2176 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2177 | assert(idx < getNumSuccessors() && "Successor # out of range for Branch!"); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2178 | setOperand(idx, NewSucc); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2179 | } |
| 2180 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2181 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2182 | static inline bool classof(const BranchInst *) { return true; } |
| 2183 | static inline bool classof(const Instruction *I) { |
| 2184 | return (I->getOpcode() == Instruction::Br); |
| 2185 | } |
| 2186 | static inline bool classof(const Value *V) { |
| 2187 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2188 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2189 | private: |
| 2190 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2191 | virtual unsigned getNumSuccessorsV() const; |
| 2192 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2193 | }; |
| 2194 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2195 | template <> |
| 2196 | struct OperandTraits<BranchInst> : HungoffOperandTraits<> { |
| 2197 | // we need to access operands via OperandList, since |
| 2198 | // the NumOperands may change from 3 to 1 |
| 2199 | static inline void *allocate(unsigned); // FIXME |
| 2200 | }; |
| 2201 | |
| 2202 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value) |
| 2203 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2204 | //===----------------------------------------------------------------------===// |
| 2205 | // SwitchInst Class |
| 2206 | //===----------------------------------------------------------------------===// |
| 2207 | |
| 2208 | //===--------------------------------------------------------------------------- |
| 2209 | /// SwitchInst - Multiway switch |
| 2210 | /// |
| 2211 | class SwitchInst : public TerminatorInst { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2212 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2213 | unsigned ReservedSpace; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2214 | // Operand[0] = Value to switch on |
| 2215 | // Operand[1] = Default basic block destination |
| 2216 | // Operand[2n ] = Value to match |
| 2217 | // Operand[2n+1] = BasicBlock to go to on match |
| 2218 | SwitchInst(const SwitchInst &RI); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2219 | void init(Value *Value, BasicBlock *Default, unsigned NumCases); |
| 2220 | void resizeOperands(unsigned No); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2221 | // allocate space for exactly zero operands |
| 2222 | void *operator new(size_t s) { |
| 2223 | return User::operator new(s, 0); |
| 2224 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2225 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to |
| 2226 | /// switch on and a default destination. The number of additional cases can |
| 2227 | /// be specified here to make memory allocation more efficient. This |
| 2228 | /// constructor can also autoinsert before another instruction. |
| 2229 | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2230 | Instruction *InsertBefore = 0); |
| 2231 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2232 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to |
| 2233 | /// switch on and a default destination. The number of additional cases can |
| 2234 | /// be specified here to make memory allocation more efficient. This |
| 2235 | /// constructor also autoinserts at the end of the specified BasicBlock. |
| 2236 | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2237 | BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2238 | public: |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2239 | static SwitchInst *Create(Value *Value, BasicBlock *Default, |
| 2240 | unsigned NumCases, Instruction *InsertBefore = 0) { |
| 2241 | return new SwitchInst(Value, Default, NumCases, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2242 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2243 | static SwitchInst *Create(Value *Value, BasicBlock *Default, |
| 2244 | unsigned NumCases, BasicBlock *InsertAtEnd) { |
| 2245 | return new SwitchInst(Value, Default, NumCases, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2246 | } |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 2247 | ~SwitchInst(); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2248 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2249 | /// Provide fast operand accessors |
| 2250 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 2251 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2252 | // Accessor Methods for Switch stmt |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2253 | Value *getCondition() const { return getOperand(0); } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2254 | void setCondition(Value *V) { setOperand(0, V); } |
Chris Lattner | bfaf88a | 2004-12-10 20:35:47 +0000 | [diff] [blame] | 2255 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2256 | BasicBlock *getDefaultDest() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2257 | return cast<BasicBlock>(getOperand(1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | /// getNumCases - return the number of 'cases' in this switch instruction. |
| 2261 | /// Note that case #0 is always the default case. |
| 2262 | unsigned getNumCases() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2263 | return getNumOperands()/2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | /// getCaseValue - Return the specified case value. Note that case #0, the |
| 2267 | /// default destination, does not have a case value. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2268 | ConstantInt *getCaseValue(unsigned i) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2269 | assert(i && i < getNumCases() && "Illegal case value to get!"); |
| 2270 | return getSuccessorValue(i); |
| 2271 | } |
| 2272 | |
| 2273 | /// getCaseValue - Return the specified case value. Note that case #0, the |
| 2274 | /// default destination, does not have a case value. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2275 | const ConstantInt *getCaseValue(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2276 | assert(i && i < getNumCases() && "Illegal case value to get!"); |
| 2277 | return getSuccessorValue(i); |
| 2278 | } |
| 2279 | |
| 2280 | /// findCaseValue - Search all of the case values for the specified constant. |
| 2281 | /// If it is explicitly handled, return the case number of it, otherwise |
| 2282 | /// return 0 to indicate that it is handled by the default handler. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2283 | unsigned findCaseValue(const ConstantInt *C) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2284 | for (unsigned i = 1, e = getNumCases(); i != e; ++i) |
| 2285 | if (getCaseValue(i) == C) |
| 2286 | return i; |
| 2287 | return 0; |
| 2288 | } |
| 2289 | |
Nick Lewycky | 011f184 | 2006-09-18 19:03:59 +0000 | [diff] [blame] | 2290 | /// findCaseDest - Finds the unique case value for a given successor. Returns |
| 2291 | /// null if the successor is not found, not unique, or is the default case. |
| 2292 | ConstantInt *findCaseDest(BasicBlock *BB) { |
Nick Lewycky | d791544 | 2006-09-18 20:44:37 +0000 | [diff] [blame] | 2293 | if (BB == getDefaultDest()) return NULL; |
| 2294 | |
Nick Lewycky | 011f184 | 2006-09-18 19:03:59 +0000 | [diff] [blame] | 2295 | ConstantInt *CI = NULL; |
| 2296 | for (unsigned i = 1, e = getNumCases(); i != e; ++i) { |
| 2297 | if (getSuccessor(i) == BB) { |
| 2298 | if (CI) return NULL; // Multiple cases lead to BB. |
| 2299 | else CI = getCaseValue(i); |
| 2300 | } |
| 2301 | } |
| 2302 | return CI; |
| 2303 | } |
| 2304 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2305 | /// addCase - Add an entry to the switch instruction... |
| 2306 | /// |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2307 | void addCase(ConstantInt *OnVal, BasicBlock *Dest); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2308 | |
| 2309 | /// removeCase - This method removes the specified successor from the switch |
| 2310 | /// instruction. Note that this cannot be used to remove the default |
| 2311 | /// destination (successor #0). |
| 2312 | /// |
| 2313 | void removeCase(unsigned idx); |
| 2314 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2315 | virtual SwitchInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2316 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2317 | unsigned getNumSuccessors() const { return getNumOperands()/2; } |
| 2318 | BasicBlock *getSuccessor(unsigned idx) const { |
| 2319 | assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!"); |
| 2320 | return cast<BasicBlock>(getOperand(idx*2+1)); |
| 2321 | } |
| 2322 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2323 | assert(idx < getNumSuccessors() && "Successor # out of range for switch!"); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2324 | setOperand(idx*2+1, NewSucc); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | // getSuccessorValue - Return the value associated with the specified |
| 2328 | // successor. |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2329 | ConstantInt *getSuccessorValue(unsigned idx) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2330 | assert(idx < getNumSuccessors() && "Successor # out of range!"); |
Reid Spencer | edd5d9e | 2005-05-15 16:13:11 +0000 | [diff] [blame] | 2331 | return reinterpret_cast<ConstantInt*>(getOperand(idx*2)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2332 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2333 | |
| 2334 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2335 | static inline bool classof(const SwitchInst *) { return true; } |
| 2336 | static inline bool classof(const Instruction *I) { |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2337 | return I->getOpcode() == Instruction::Switch; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2338 | } |
| 2339 | static inline bool classof(const Value *V) { |
| 2340 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2341 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2342 | private: |
| 2343 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2344 | virtual unsigned getNumSuccessorsV() const; |
| 2345 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2346 | }; |
| 2347 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2348 | template <> |
| 2349 | struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> { |
| 2350 | }; |
| 2351 | |
| 2352 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value) |
| 2353 | |
| 2354 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2355 | //===----------------------------------------------------------------------===// |
| 2356 | // InvokeInst Class |
| 2357 | //===----------------------------------------------------------------------===// |
| 2358 | |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 2359 | /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the |
| 2360 | /// calling convention of the call. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2361 | /// |
| 2362 | class InvokeInst : public TerminatorInst { |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 2363 | PAListPtr ParamAttrs; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2364 | InvokeInst(const InvokeInst &BI); |
| 2365 | void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, |
Chris Lattner | d2dd150 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 2366 | Value* const *Args, unsigned NumArgs); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2367 | |
| 2368 | template<typename InputIterator> |
| 2369 | void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
| 2370 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2371 | const std::string &Name, |
| 2372 | // This argument ensures that we have an iterator we can |
| 2373 | // do arithmetic on in constant time |
| 2374 | std::random_access_iterator_tag) { |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 2375 | unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2376 | |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 2377 | // This requires that the iterator points to contiguous memory. |
| 2378 | init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2379 | setName(Name); |
| 2380 | } |
| 2381 | |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2382 | /// Construct an InvokeInst given a range of arguments. |
| 2383 | /// InputIterator must be a random-access iterator pointing to |
| 2384 | /// contiguous storage (e.g. a std::vector<>::iterator). Checks are |
| 2385 | /// made for random-accessness but not for contiguous storage as |
| 2386 | /// that would incur runtime overhead. |
| 2387 | /// |
| 2388 | /// @brief Construct an InvokeInst from a range of arguments |
| 2389 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2390 | inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
| 2391 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2392 | unsigned Values, |
| 2393 | const std::string &Name, Instruction *InsertBefore); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2394 | |
| 2395 | /// Construct an InvokeInst given a range of arguments. |
| 2396 | /// InputIterator must be a random-access iterator pointing to |
| 2397 | /// contiguous storage (e.g. a std::vector<>::iterator). Checks are |
| 2398 | /// made for random-accessness but not for contiguous storage as |
| 2399 | /// that would incur runtime overhead. |
| 2400 | /// |
| 2401 | /// @brief Construct an InvokeInst from a range of arguments |
| 2402 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2403 | inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
| 2404 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2405 | unsigned Values, |
| 2406 | const std::string &Name, BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2407 | public: |
| 2408 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2409 | static InvokeInst *Create(Value *Func, |
| 2410 | BasicBlock *IfNormal, BasicBlock *IfException, |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2411 | InputIterator ArgBegin, InputIterator ArgEnd, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 2412 | const std::string &Name = "", |
| 2413 | Instruction *InsertBefore = 0) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2414 | unsigned Values(ArgEnd - ArgBegin + 3); |
| 2415 | return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, |
| 2416 | Values, Name, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2417 | } |
| 2418 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2419 | static InvokeInst *Create(Value *Func, |
| 2420 | BasicBlock *IfNormal, BasicBlock *IfException, |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2421 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2422 | const std::string &Name, BasicBlock *InsertAtEnd) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2423 | unsigned Values(ArgEnd - ArgBegin + 3); |
| 2424 | return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, |
| 2425 | Values, Name, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2426 | } |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2427 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 2428 | virtual InvokeInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2429 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2430 | /// Provide fast operand accessors |
| 2431 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 2432 | |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 2433 | /// getCallingConv/setCallingConv - Get or set the calling convention of this |
| 2434 | /// function call. |
| 2435 | unsigned getCallingConv() const { return SubclassData; } |
| 2436 | void setCallingConv(unsigned CC) { |
| 2437 | SubclassData = CC; |
| 2438 | } |
| 2439 | |
Chris Lattner | 041221c | 2008-03-13 04:33:03 +0000 | [diff] [blame] | 2440 | /// getParamAttrs - Return the parameter attributes for this invoke. |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 2441 | /// |
| 2442 | const PAListPtr &getParamAttrs() const { return ParamAttrs; } |
Reid Spencer | fa3e912 | 2007-04-09 18:00:57 +0000 | [diff] [blame] | 2443 | |
Chris Lattner | 041221c | 2008-03-13 04:33:03 +0000 | [diff] [blame] | 2444 | /// setParamAttrs - Set the parameter attributes for this invoke. |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 2445 | /// |
| 2446 | void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; } |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 2447 | |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 2448 | /// @brief Determine whether the call or the callee has the given attribute. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2449 | bool paramHasAttr(unsigned i, ParameterAttributes attr) const; |
Eric Christopher | 0bf7b41 | 2008-05-16 20:39:43 +0000 | [diff] [blame] | 2450 | |
| 2451 | /// addParamAttr - adds the attribute to the list of attributes. |
| 2452 | void addParamAttr(unsigned i, ParameterAttributes attr); |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 2453 | |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 2454 | /// @brief Extract the alignment for a call or parameter (0=unknown). |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2455 | unsigned getParamAlignment(unsigned i) const { |
| 2456 | return ParamAttrs.getParamAlignment(i); |
| 2457 | } |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 2458 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2459 | /// @brief Determine if the call does not access memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2460 | bool doesNotAccessMemory() const { |
| 2461 | return paramHasAttr(0, ParamAttr::ReadNone); |
| 2462 | } |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2463 | |
| 2464 | /// @brief Determine if the call does not access or only reads memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2465 | bool onlyReadsMemory() const { |
| 2466 | return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly); |
| 2467 | } |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2468 | |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 2469 | /// @brief Determine if the call cannot return. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2470 | bool doesNotReturn() const { |
| 2471 | return paramHasAttr(0, ParamAttr::NoReturn); |
| 2472 | } |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 2473 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2474 | /// @brief Determine if the call cannot unwind. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2475 | bool doesNotThrow() const { |
| 2476 | return paramHasAttr(0, ParamAttr::NoUnwind); |
| 2477 | } |
Duncan Sands | f0c3354 | 2007-12-19 21:13:37 +0000 | [diff] [blame] | 2478 | void setDoesNotThrow(bool doesNotThrow = true); |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2479 | |
Devang Patel | 41e2397 | 2008-03-03 21:46:28 +0000 | [diff] [blame] | 2480 | /// @brief Determine if the call returns a structure through first |
| 2481 | /// pointer argument. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2482 | bool hasStructRetAttr() const { |
| 2483 | // Be friendly and also check the callee. |
| 2484 | return paramHasAttr(1, ParamAttr::StructRet); |
| 2485 | } |
Reid Spencer | fa3e912 | 2007-04-09 18:00:57 +0000 | [diff] [blame] | 2486 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2487 | /// getCalledFunction - Return the function called, or null if this is an |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 2488 | /// indirect function invocation. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2489 | /// |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 2490 | Function *getCalledFunction() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2491 | return dyn_cast<Function>(getOperand(0)); |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 2492 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2493 | |
| 2494 | // 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] | 2495 | Value *getCalledValue() const { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2496 | |
| 2497 | // get*Dest - Return the destination basic blocks... |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2498 | BasicBlock *getNormalDest() const { |
| 2499 | return cast<BasicBlock>(getOperand(1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2500 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2501 | BasicBlock *getUnwindDest() const { |
| 2502 | return cast<BasicBlock>(getOperand(2)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2503 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2504 | void setNormalDest(BasicBlock *B) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2505 | setOperand(1, B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2506 | } |
| 2507 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2508 | void setUnwindDest(BasicBlock *B) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2509 | setOperand(2, B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2510 | } |
| 2511 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2512 | BasicBlock *getSuccessor(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2513 | assert(i < 2 && "Successor # out of range for invoke!"); |
| 2514 | return i == 0 ? getNormalDest() : getUnwindDest(); |
| 2515 | } |
| 2516 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2517 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2518 | assert(idx < 2 && "Successor # out of range for invoke!"); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2519 | setOperand(idx+1, NewSucc); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2520 | } |
| 2521 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2522 | unsigned getNumSuccessors() const { return 2; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2523 | |
| 2524 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2525 | static inline bool classof(const InvokeInst *) { return true; } |
| 2526 | static inline bool classof(const Instruction *I) { |
| 2527 | return (I->getOpcode() == Instruction::Invoke); |
| 2528 | } |
| 2529 | static inline bool classof(const Value *V) { |
| 2530 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2531 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2532 | private: |
| 2533 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2534 | virtual unsigned getNumSuccessorsV() const; |
| 2535 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2536 | }; |
| 2537 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2538 | template <> |
| 2539 | struct OperandTraits<InvokeInst> : VariadicOperandTraits<3> { |
| 2540 | }; |
| 2541 | |
| 2542 | template<typename InputIterator> |
| 2543 | InvokeInst::InvokeInst(Value *Func, |
| 2544 | BasicBlock *IfNormal, BasicBlock *IfException, |
| 2545 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2546 | unsigned Values, |
| 2547 | const std::string &Name, Instruction *InsertBefore) |
| 2548 | : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 2549 | ->getElementType())->getReturnType(), |
| 2550 | Instruction::Invoke, |
| 2551 | OperandTraits<InvokeInst>::op_end(this) - Values, |
| 2552 | Values, InsertBefore) { |
| 2553 | init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, |
| 2554 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 2555 | } |
| 2556 | template<typename InputIterator> |
| 2557 | InvokeInst::InvokeInst(Value *Func, |
| 2558 | BasicBlock *IfNormal, BasicBlock *IfException, |
| 2559 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2560 | unsigned Values, |
| 2561 | const std::string &Name, BasicBlock *InsertAtEnd) |
| 2562 | : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 2563 | ->getElementType())->getReturnType(), |
| 2564 | Instruction::Invoke, |
| 2565 | OperandTraits<InvokeInst>::op_end(this) - Values, |
| 2566 | Values, InsertAtEnd) { |
| 2567 | init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, |
| 2568 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 2569 | } |
| 2570 | |
| 2571 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value) |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2572 | |
| 2573 | //===----------------------------------------------------------------------===// |
| 2574 | // UnwindInst Class |
| 2575 | //===----------------------------------------------------------------------===// |
| 2576 | |
| 2577 | //===--------------------------------------------------------------------------- |
| 2578 | /// UnwindInst - Immediately exit the current function, unwinding the stack |
| 2579 | /// until an invoke instruction is found. |
| 2580 | /// |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2581 | class UnwindInst : public TerminatorInst { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2582 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2583 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2584 | // allocate space for exactly zero operands |
| 2585 | void *operator new(size_t s) { |
| 2586 | return User::operator new(s, 0); |
| 2587 | } |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2588 | explicit UnwindInst(Instruction *InsertBefore = 0); |
| 2589 | explicit UnwindInst(BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2590 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 2591 | virtual UnwindInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2592 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2593 | unsigned getNumSuccessors() const { return 0; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2594 | |
| 2595 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2596 | static inline bool classof(const UnwindInst *) { return true; } |
| 2597 | static inline bool classof(const Instruction *I) { |
| 2598 | return I->getOpcode() == Instruction::Unwind; |
| 2599 | } |
| 2600 | static inline bool classof(const Value *V) { |
| 2601 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2602 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2603 | private: |
| 2604 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2605 | virtual unsigned getNumSuccessorsV() const; |
| 2606 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2607 | }; |
| 2608 | |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2609 | //===----------------------------------------------------------------------===// |
| 2610 | // UnreachableInst Class |
| 2611 | //===----------------------------------------------------------------------===// |
| 2612 | |
| 2613 | //===--------------------------------------------------------------------------- |
| 2614 | /// UnreachableInst - This function has undefined behavior. In particular, the |
| 2615 | /// presence of this instruction indicates some higher level knowledge that the |
| 2616 | /// end of the block cannot be reached. |
| 2617 | /// |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2618 | class UnreachableInst : public TerminatorInst { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2619 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2620 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2621 | // allocate space for exactly zero operands |
| 2622 | void *operator new(size_t s) { |
| 2623 | return User::operator new(s, 0); |
| 2624 | } |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2625 | explicit UnreachableInst(Instruction *InsertBefore = 0); |
| 2626 | explicit UnreachableInst(BasicBlock *InsertAtEnd); |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2627 | |
| 2628 | virtual UnreachableInst *clone() const; |
| 2629 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2630 | unsigned getNumSuccessors() const { return 0; } |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2631 | |
| 2632 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2633 | static inline bool classof(const UnreachableInst *) { return true; } |
| 2634 | static inline bool classof(const Instruction *I) { |
| 2635 | return I->getOpcode() == Instruction::Unreachable; |
| 2636 | } |
| 2637 | static inline bool classof(const Value *V) { |
| 2638 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2639 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2640 | private: |
| 2641 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2642 | virtual unsigned getNumSuccessorsV() const; |
| 2643 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2644 | }; |
| 2645 | |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2646 | //===----------------------------------------------------------------------===// |
| 2647 | // TruncInst Class |
| 2648 | //===----------------------------------------------------------------------===// |
| 2649 | |
| 2650 | /// @brief This class represents a truncation of integer types. |
| 2651 | class TruncInst : public CastInst { |
| 2652 | /// Private copy constructor |
| 2653 | TruncInst(const TruncInst &CI) |
| 2654 | : CastInst(CI.getType(), Trunc, CI.getOperand(0)) { |
| 2655 | } |
| 2656 | public: |
| 2657 | /// @brief Constructor with insert-before-instruction semantics |
| 2658 | TruncInst( |
| 2659 | Value *S, ///< The value to be truncated |
| 2660 | const Type *Ty, ///< The (smaller) type to truncate to |
| 2661 | const std::string &Name = "", ///< A name for the new instruction |
| 2662 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2663 | ); |
| 2664 | |
| 2665 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2666 | TruncInst( |
| 2667 | Value *S, ///< The value to be truncated |
| 2668 | const Type *Ty, ///< The (smaller) type to truncate to |
| 2669 | const std::string &Name, ///< A name for the new instruction |
| 2670 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2671 | ); |
| 2672 | |
| 2673 | /// @brief Clone an identical TruncInst |
| 2674 | virtual CastInst *clone() const; |
| 2675 | |
| 2676 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2677 | static inline bool classof(const TruncInst *) { return true; } |
| 2678 | static inline bool classof(const Instruction *I) { |
| 2679 | return I->getOpcode() == Trunc; |
| 2680 | } |
| 2681 | static inline bool classof(const Value *V) { |
| 2682 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2683 | } |
| 2684 | }; |
| 2685 | |
| 2686 | //===----------------------------------------------------------------------===// |
| 2687 | // ZExtInst Class |
| 2688 | //===----------------------------------------------------------------------===// |
| 2689 | |
| 2690 | /// @brief This class represents zero extension of integer types. |
| 2691 | class ZExtInst : public CastInst { |
| 2692 | /// @brief Private copy constructor |
| 2693 | ZExtInst(const ZExtInst &CI) |
| 2694 | : CastInst(CI.getType(), ZExt, CI.getOperand(0)) { |
| 2695 | } |
| 2696 | public: |
| 2697 | /// @brief Constructor with insert-before-instruction semantics |
| 2698 | ZExtInst( |
| 2699 | Value *S, ///< The value to be zero extended |
| 2700 | const Type *Ty, ///< The type to zero extend to |
| 2701 | const std::string &Name = "", ///< A name for the new instruction |
| 2702 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2703 | ); |
| 2704 | |
| 2705 | /// @brief Constructor with insert-at-end semantics. |
| 2706 | ZExtInst( |
| 2707 | Value *S, ///< The value to be zero extended |
| 2708 | const Type *Ty, ///< The type to zero extend to |
| 2709 | const std::string &Name, ///< A name for the new instruction |
| 2710 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2711 | ); |
| 2712 | |
| 2713 | /// @brief Clone an identical ZExtInst |
| 2714 | virtual CastInst *clone() const; |
| 2715 | |
| 2716 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2717 | static inline bool classof(const ZExtInst *) { return true; } |
| 2718 | static inline bool classof(const Instruction *I) { |
| 2719 | return I->getOpcode() == ZExt; |
| 2720 | } |
| 2721 | static inline bool classof(const Value *V) { |
| 2722 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2723 | } |
| 2724 | }; |
| 2725 | |
| 2726 | //===----------------------------------------------------------------------===// |
| 2727 | // SExtInst Class |
| 2728 | //===----------------------------------------------------------------------===// |
| 2729 | |
| 2730 | /// @brief This class represents a sign extension of integer types. |
| 2731 | class SExtInst : public CastInst { |
| 2732 | /// @brief Private copy constructor |
| 2733 | SExtInst(const SExtInst &CI) |
| 2734 | : CastInst(CI.getType(), SExt, CI.getOperand(0)) { |
| 2735 | } |
| 2736 | public: |
| 2737 | /// @brief Constructor with insert-before-instruction semantics |
| 2738 | SExtInst( |
| 2739 | Value *S, ///< The value to be sign extended |
| 2740 | const Type *Ty, ///< The type to sign extend to |
| 2741 | const std::string &Name = "", ///< A name for the new instruction |
| 2742 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2743 | ); |
| 2744 | |
| 2745 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2746 | SExtInst( |
| 2747 | Value *S, ///< The value to be sign extended |
| 2748 | const Type *Ty, ///< The type to sign extend to |
| 2749 | const std::string &Name, ///< A name for the new instruction |
| 2750 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2751 | ); |
| 2752 | |
| 2753 | /// @brief Clone an identical SExtInst |
| 2754 | virtual CastInst *clone() const; |
| 2755 | |
| 2756 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2757 | static inline bool classof(const SExtInst *) { return true; } |
| 2758 | static inline bool classof(const Instruction *I) { |
| 2759 | return I->getOpcode() == SExt; |
| 2760 | } |
| 2761 | static inline bool classof(const Value *V) { |
| 2762 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2763 | } |
| 2764 | }; |
| 2765 | |
| 2766 | //===----------------------------------------------------------------------===// |
| 2767 | // FPTruncInst Class |
| 2768 | //===----------------------------------------------------------------------===// |
| 2769 | |
| 2770 | /// @brief This class represents a truncation of floating point types. |
| 2771 | class FPTruncInst : public CastInst { |
| 2772 | FPTruncInst(const FPTruncInst &CI) |
| 2773 | : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) { |
| 2774 | } |
| 2775 | public: |
| 2776 | /// @brief Constructor with insert-before-instruction semantics |
| 2777 | FPTruncInst( |
| 2778 | Value *S, ///< The value to be truncated |
| 2779 | const Type *Ty, ///< The type to truncate to |
| 2780 | const std::string &Name = "", ///< A name for the new instruction |
| 2781 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2782 | ); |
| 2783 | |
| 2784 | /// @brief Constructor with insert-before-instruction semantics |
| 2785 | FPTruncInst( |
| 2786 | Value *S, ///< The value to be truncated |
| 2787 | const Type *Ty, ///< The type to truncate to |
| 2788 | const std::string &Name, ///< A name for the new instruction |
| 2789 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2790 | ); |
| 2791 | |
| 2792 | /// @brief Clone an identical FPTruncInst |
| 2793 | virtual CastInst *clone() const; |
| 2794 | |
| 2795 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2796 | static inline bool classof(const FPTruncInst *) { return true; } |
| 2797 | static inline bool classof(const Instruction *I) { |
| 2798 | return I->getOpcode() == FPTrunc; |
| 2799 | } |
| 2800 | static inline bool classof(const Value *V) { |
| 2801 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2802 | } |
| 2803 | }; |
| 2804 | |
| 2805 | //===----------------------------------------------------------------------===// |
| 2806 | // FPExtInst Class |
| 2807 | //===----------------------------------------------------------------------===// |
| 2808 | |
| 2809 | /// @brief This class represents an extension of floating point types. |
| 2810 | class FPExtInst : public CastInst { |
| 2811 | FPExtInst(const FPExtInst &CI) |
| 2812 | : CastInst(CI.getType(), FPExt, CI.getOperand(0)) { |
| 2813 | } |
| 2814 | public: |
| 2815 | /// @brief Constructor with insert-before-instruction semantics |
| 2816 | FPExtInst( |
| 2817 | Value *S, ///< The value to be extended |
| 2818 | const Type *Ty, ///< The type to extend to |
| 2819 | const std::string &Name = "", ///< A name for the new instruction |
| 2820 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2821 | ); |
| 2822 | |
| 2823 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2824 | FPExtInst( |
| 2825 | Value *S, ///< The value to be extended |
| 2826 | const Type *Ty, ///< The type to extend to |
| 2827 | const std::string &Name, ///< A name for the new instruction |
| 2828 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2829 | ); |
| 2830 | |
| 2831 | /// @brief Clone an identical FPExtInst |
| 2832 | virtual CastInst *clone() const; |
| 2833 | |
| 2834 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2835 | static inline bool classof(const FPExtInst *) { return true; } |
| 2836 | static inline bool classof(const Instruction *I) { |
| 2837 | return I->getOpcode() == FPExt; |
| 2838 | } |
| 2839 | static inline bool classof(const Value *V) { |
| 2840 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2841 | } |
| 2842 | }; |
| 2843 | |
| 2844 | //===----------------------------------------------------------------------===// |
| 2845 | // UIToFPInst Class |
| 2846 | //===----------------------------------------------------------------------===// |
| 2847 | |
| 2848 | /// @brief This class represents a cast unsigned integer to floating point. |
| 2849 | class UIToFPInst : public CastInst { |
| 2850 | UIToFPInst(const UIToFPInst &CI) |
| 2851 | : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) { |
| 2852 | } |
| 2853 | public: |
| 2854 | /// @brief Constructor with insert-before-instruction semantics |
| 2855 | UIToFPInst( |
| 2856 | Value *S, ///< The value to be converted |
| 2857 | const Type *Ty, ///< The type to convert to |
| 2858 | const std::string &Name = "", ///< A name for the new instruction |
| 2859 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2860 | ); |
| 2861 | |
| 2862 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2863 | UIToFPInst( |
| 2864 | Value *S, ///< The value to be converted |
| 2865 | const Type *Ty, ///< The type to convert to |
| 2866 | const std::string &Name, ///< A name for the new instruction |
| 2867 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2868 | ); |
| 2869 | |
| 2870 | /// @brief Clone an identical UIToFPInst |
| 2871 | virtual CastInst *clone() const; |
| 2872 | |
| 2873 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2874 | static inline bool classof(const UIToFPInst *) { return true; } |
| 2875 | static inline bool classof(const Instruction *I) { |
| 2876 | return I->getOpcode() == UIToFP; |
| 2877 | } |
| 2878 | static inline bool classof(const Value *V) { |
| 2879 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2880 | } |
| 2881 | }; |
| 2882 | |
| 2883 | //===----------------------------------------------------------------------===// |
| 2884 | // SIToFPInst Class |
| 2885 | //===----------------------------------------------------------------------===// |
| 2886 | |
| 2887 | /// @brief This class represents a cast from signed integer to floating point. |
| 2888 | class SIToFPInst : public CastInst { |
| 2889 | SIToFPInst(const SIToFPInst &CI) |
| 2890 | : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) { |
| 2891 | } |
| 2892 | public: |
| 2893 | /// @brief Constructor with insert-before-instruction semantics |
| 2894 | SIToFPInst( |
| 2895 | Value *S, ///< The value to be converted |
| 2896 | const Type *Ty, ///< The type to convert to |
| 2897 | const std::string &Name = "", ///< A name for the new instruction |
| 2898 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2899 | ); |
| 2900 | |
| 2901 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2902 | SIToFPInst( |
| 2903 | Value *S, ///< The value to be converted |
| 2904 | const Type *Ty, ///< The type to convert to |
| 2905 | const std::string &Name, ///< A name for the new instruction |
| 2906 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2907 | ); |
| 2908 | |
| 2909 | /// @brief Clone an identical SIToFPInst |
| 2910 | virtual CastInst *clone() const; |
| 2911 | |
| 2912 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2913 | static inline bool classof(const SIToFPInst *) { return true; } |
| 2914 | static inline bool classof(const Instruction *I) { |
| 2915 | return I->getOpcode() == SIToFP; |
| 2916 | } |
| 2917 | static inline bool classof(const Value *V) { |
| 2918 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2919 | } |
| 2920 | }; |
| 2921 | |
| 2922 | //===----------------------------------------------------------------------===// |
| 2923 | // FPToUIInst Class |
| 2924 | //===----------------------------------------------------------------------===// |
| 2925 | |
| 2926 | /// @brief This class represents a cast from floating point to unsigned integer |
| 2927 | class FPToUIInst : public CastInst { |
| 2928 | FPToUIInst(const FPToUIInst &CI) |
| 2929 | : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) { |
| 2930 | } |
| 2931 | public: |
| 2932 | /// @brief Constructor with insert-before-instruction semantics |
| 2933 | FPToUIInst( |
| 2934 | Value *S, ///< The value to be converted |
| 2935 | const Type *Ty, ///< The type to convert to |
| 2936 | const std::string &Name = "", ///< A name for the new instruction |
| 2937 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2938 | ); |
| 2939 | |
| 2940 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2941 | FPToUIInst( |
| 2942 | Value *S, ///< The value to be converted |
| 2943 | const Type *Ty, ///< The type to convert to |
| 2944 | const std::string &Name, ///< A name for the new instruction |
| 2945 | BasicBlock *InsertAtEnd ///< Where to insert the new instruction |
| 2946 | ); |
| 2947 | |
| 2948 | /// @brief Clone an identical FPToUIInst |
| 2949 | virtual CastInst *clone() const; |
| 2950 | |
| 2951 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2952 | static inline bool classof(const FPToUIInst *) { return true; } |
| 2953 | static inline bool classof(const Instruction *I) { |
| 2954 | return I->getOpcode() == FPToUI; |
| 2955 | } |
| 2956 | static inline bool classof(const Value *V) { |
| 2957 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2958 | } |
| 2959 | }; |
| 2960 | |
| 2961 | //===----------------------------------------------------------------------===// |
| 2962 | // FPToSIInst Class |
| 2963 | //===----------------------------------------------------------------------===// |
| 2964 | |
| 2965 | /// @brief This class represents a cast from floating point to signed integer. |
| 2966 | class FPToSIInst : public CastInst { |
| 2967 | FPToSIInst(const FPToSIInst &CI) |
| 2968 | : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) { |
| 2969 | } |
| 2970 | public: |
| 2971 | /// @brief Constructor with insert-before-instruction semantics |
| 2972 | FPToSIInst( |
| 2973 | Value *S, ///< The value to be converted |
| 2974 | const Type *Ty, ///< The type to convert to |
| 2975 | const std::string &Name = "", ///< A name for the new instruction |
| 2976 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2977 | ); |
| 2978 | |
| 2979 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2980 | FPToSIInst( |
| 2981 | Value *S, ///< The value to be converted |
| 2982 | const Type *Ty, ///< The type to convert to |
| 2983 | const std::string &Name, ///< A name for the new instruction |
| 2984 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2985 | ); |
| 2986 | |
| 2987 | /// @brief Clone an identical FPToSIInst |
| 2988 | virtual CastInst *clone() const; |
| 2989 | |
| 2990 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2991 | static inline bool classof(const FPToSIInst *) { return true; } |
| 2992 | static inline bool classof(const Instruction *I) { |
| 2993 | return I->getOpcode() == FPToSI; |
| 2994 | } |
| 2995 | static inline bool classof(const Value *V) { |
| 2996 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2997 | } |
| 2998 | }; |
| 2999 | |
| 3000 | //===----------------------------------------------------------------------===// |
| 3001 | // IntToPtrInst Class |
| 3002 | //===----------------------------------------------------------------------===// |
| 3003 | |
| 3004 | /// @brief This class represents a cast from an integer to a pointer. |
| 3005 | class IntToPtrInst : public CastInst { |
| 3006 | IntToPtrInst(const IntToPtrInst &CI) |
| 3007 | : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) { |
| 3008 | } |
| 3009 | public: |
| 3010 | /// @brief Constructor with insert-before-instruction semantics |
| 3011 | IntToPtrInst( |
| 3012 | Value *S, ///< The value to be converted |
| 3013 | const Type *Ty, ///< The type to convert to |
| 3014 | const std::string &Name = "", ///< A name for the new instruction |
| 3015 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 3016 | ); |
| 3017 | |
| 3018 | /// @brief Constructor with insert-at-end-of-block semantics |
| 3019 | IntToPtrInst( |
| 3020 | Value *S, ///< The value to be converted |
| 3021 | const Type *Ty, ///< The type to convert to |
| 3022 | const std::string &Name, ///< A name for the new instruction |
| 3023 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 3024 | ); |
| 3025 | |
| 3026 | /// @brief Clone an identical IntToPtrInst |
| 3027 | virtual CastInst *clone() const; |
| 3028 | |
| 3029 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 3030 | static inline bool classof(const IntToPtrInst *) { return true; } |
| 3031 | static inline bool classof(const Instruction *I) { |
| 3032 | return I->getOpcode() == IntToPtr; |
| 3033 | } |
| 3034 | static inline bool classof(const Value *V) { |
| 3035 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 3036 | } |
| 3037 | }; |
| 3038 | |
| 3039 | //===----------------------------------------------------------------------===// |
| 3040 | // PtrToIntInst Class |
| 3041 | //===----------------------------------------------------------------------===// |
| 3042 | |
| 3043 | /// @brief This class represents a cast from a pointer to an integer |
| 3044 | class PtrToIntInst : public CastInst { |
| 3045 | PtrToIntInst(const PtrToIntInst &CI) |
| 3046 | : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) { |
| 3047 | } |
| 3048 | public: |
| 3049 | /// @brief Constructor with insert-before-instruction semantics |
| 3050 | PtrToIntInst( |
| 3051 | Value *S, ///< The value to be converted |
| 3052 | const Type *Ty, ///< The type to convert to |
| 3053 | const std::string &Name = "", ///< A name for the new instruction |
| 3054 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 3055 | ); |
| 3056 | |
| 3057 | /// @brief Constructor with insert-at-end-of-block semantics |
| 3058 | PtrToIntInst( |
| 3059 | Value *S, ///< The value to be converted |
| 3060 | const Type *Ty, ///< The type to convert to |
| 3061 | const std::string &Name, ///< A name for the new instruction |
| 3062 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 3063 | ); |
| 3064 | |
| 3065 | /// @brief Clone an identical PtrToIntInst |
| 3066 | virtual CastInst *clone() const; |
| 3067 | |
| 3068 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 3069 | static inline bool classof(const PtrToIntInst *) { return true; } |
| 3070 | static inline bool classof(const Instruction *I) { |
| 3071 | return I->getOpcode() == PtrToInt; |
| 3072 | } |
| 3073 | static inline bool classof(const Value *V) { |
| 3074 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 3075 | } |
| 3076 | }; |
| 3077 | |
| 3078 | //===----------------------------------------------------------------------===// |
| 3079 | // BitCastInst Class |
| 3080 | //===----------------------------------------------------------------------===// |
| 3081 | |
| 3082 | /// @brief This class represents a no-op cast from one type to another. |
| 3083 | class BitCastInst : public CastInst { |
| 3084 | BitCastInst(const BitCastInst &CI) |
| 3085 | : CastInst(CI.getType(), BitCast, CI.getOperand(0)) { |
| 3086 | } |
| 3087 | public: |
| 3088 | /// @brief Constructor with insert-before-instruction semantics |
| 3089 | BitCastInst( |
| 3090 | Value *S, ///< The value to be casted |
| 3091 | const Type *Ty, ///< The type to casted to |
| 3092 | const std::string &Name = "", ///< A name for the new instruction |
| 3093 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 3094 | ); |
| 3095 | |
| 3096 | /// @brief Constructor with insert-at-end-of-block semantics |
| 3097 | BitCastInst( |
| 3098 | Value *S, ///< The value to be casted |
| 3099 | const Type *Ty, ///< The type to casted to |
| 3100 | const std::string &Name, ///< A name for the new instruction |
| 3101 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 3102 | ); |
| 3103 | |
| 3104 | /// @brief Clone an identical BitCastInst |
| 3105 | virtual CastInst *clone() const; |
| 3106 | |
| 3107 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 3108 | static inline bool classof(const BitCastInst *) { return true; } |
| 3109 | static inline bool classof(const Instruction *I) { |
| 3110 | return I->getOpcode() == BitCast; |
| 3111 | } |
| 3112 | static inline bool classof(const Value *V) { |
| 3113 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 3114 | } |
| 3115 | }; |
| 3116 | |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3117 | //===----------------------------------------------------------------------===// |
| 3118 | // GetResultInst Class |
| 3119 | //===----------------------------------------------------------------------===// |
| 3120 | |
| 3121 | /// GetResultInst - This instruction extracts individual result value from |
| 3122 | /// aggregate value, where aggregate value is returned by CallInst. |
| 3123 | /// |
Gabor Greif | d6a2218 | 2008-05-13 07:09:08 +0000 | [diff] [blame] | 3124 | class GetResultInst : public UnaryInstruction { |
Devang Patel | 23755d8 | 2008-02-20 19:10:47 +0000 | [diff] [blame] | 3125 | unsigned Idx; |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3126 | GetResultInst(const GetResultInst &GRI) : |
Gabor Greif | d6a2218 | 2008-05-13 07:09:08 +0000 | [diff] [blame] | 3127 | UnaryInstruction(GRI.getType(), Instruction::GetResult, GRI.getOperand(0)), |
| 3128 | Idx(GRI.Idx) { |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | public: |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 3132 | GetResultInst(Value *Aggr, unsigned index, |
| 3133 | const std::string &Name = "", |
| 3134 | Instruction *InsertBefore = 0); |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3135 | |
| 3136 | /// isValidOperands - Return true if an getresult instruction can be |
| 3137 | /// formed with the specified operands. |
Devang Patel | 23755d8 | 2008-02-20 19:10:47 +0000 | [diff] [blame] | 3138 | static bool isValidOperands(const Value *Aggr, unsigned index); |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3139 | |
| 3140 | virtual GetResultInst *clone() const; |
| 3141 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 3142 | Value *getAggregateValue() { |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3143 | return getOperand(0); |
| 3144 | } |
Devang Patel | 2d2ae34 | 2008-02-20 18:36:16 +0000 | [diff] [blame] | 3145 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 3146 | const Value *getAggregateValue() const { |
Devang Patel | 2d2ae34 | 2008-02-20 18:36:16 +0000 | [diff] [blame] | 3147 | return getOperand(0); |
| 3148 | } |
| 3149 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 3150 | unsigned getIndex() const { |
Devang Patel | 23755d8 | 2008-02-20 19:10:47 +0000 | [diff] [blame] | 3151 | return Idx; |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3152 | } |
| 3153 | |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3154 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 3155 | static inline bool classof(const GetResultInst *) { return true; } |
| 3156 | static inline bool classof(const Instruction *I) { |
| 3157 | return (I->getOpcode() == Instruction::GetResult); |
| 3158 | } |
| 3159 | static inline bool classof(const Value *V) { |
| 3160 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 3161 | } |
| 3162 | }; |
| 3163 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 3164 | } // End llvm namespace |
Chris Lattner | a892a3a | 2003-01-27 22:08:52 +0000 | [diff] [blame] | 3165 | |
| 3166 | #endif |