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