Chris Lattner | a892a3a | 2003-01-27 22:08:52 +0000 | [diff] [blame] | 1 | //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===// |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 2 | // |
John Criswell | 6fbcc26 | 2003-10-20 20:19:47 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 7ed47a1 | 2007-12-29 19:59:42 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 7 | // |
John Criswell | 6fbcc26 | 2003-10-20 20:19:47 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | a892a3a | 2003-01-27 22:08:52 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file exposes the class definitions of all of the subclasses of the |
| 11 | // Instruction class. This is meant to be an easy way to get access to all |
| 12 | // instruction subclasses. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef LLVM_INSTRUCTIONS_H |
| 17 | #define LLVM_INSTRUCTIONS_H |
| 18 | |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 19 | #include <iterator> |
| 20 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 21 | #include "llvm/InstrTypes.h" |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 22 | #include "llvm/DerivedTypes.h" |
Dale Johannesen | 0d51e7e | 2008-02-19 21:38:47 +0000 | [diff] [blame] | 23 | #include "llvm/ParameterAttributes.h" |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 24 | #include "llvm/BasicBlock.h" |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 25 | |
| 26 | namespace llvm { |
| 27 | |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 28 | class ConstantInt; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 29 | class PointerType; |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 30 | class VectorType; |
Reid Spencer | 3da4384 | 2007-02-28 22:00:54 +0000 | [diff] [blame] | 31 | class ConstantRange; |
| 32 | class APInt; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 33 | |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | // AllocationInst Class |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
| 38 | /// AllocationInst - This class is the common base class of MallocInst and |
| 39 | /// AllocaInst. |
| 40 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 41 | class AllocationInst : public UnaryInstruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 42 | protected: |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 43 | AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 44 | const std::string &Name = "", Instruction *InsertBefore = 0); |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 45 | AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align, |
Misha Brukman | 9110286 | 2005-03-16 03:46:55 +0000 | [diff] [blame] | 46 | const std::string &Name, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 47 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 48 | // Out of line virtual method, so the vtable, etc. has a home. |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 49 | virtual ~AllocationInst(); |
| 50 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 51 | /// isArrayAllocation - Return true if there is an allocation size parameter |
| 52 | /// to the allocation instruction that is not 1. |
| 53 | /// |
| 54 | bool isArrayAllocation() const; |
| 55 | |
| 56 | /// getArraySize - Get the number of element allocated, for a simple |
| 57 | /// allocation of a single element, this will return a constant 1 value. |
| 58 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 59 | const Value *getArraySize() const { return getOperand(0); } |
| 60 | Value *getArraySize() { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 61 | |
| 62 | /// getType - Overload to return most specific pointer type |
| 63 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 64 | const PointerType *getType() const { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 65 | return reinterpret_cast<const PointerType*>(Instruction::getType()); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /// getAllocatedType - Return the type that is being allocated by the |
| 69 | /// instruction. |
| 70 | /// |
| 71 | const Type *getAllocatedType() const; |
| 72 | |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 73 | /// getAlignment - Return the alignment of the memory that is being allocated |
| 74 | /// by the instruction. |
| 75 | /// |
Dan Gohman | 5283707 | 2008-03-24 16:55:58 +0000 | [diff] [blame] | 76 | unsigned getAlignment() const { return (1u << SubclassData) >> 1; } |
| 77 | void setAlignment(unsigned Align); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 78 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 79 | virtual Instruction *clone() const = 0; |
| 80 | |
| 81 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 82 | static inline bool classof(const AllocationInst *) { return true; } |
| 83 | static inline bool classof(const Instruction *I) { |
| 84 | return I->getOpcode() == Instruction::Alloca || |
| 85 | I->getOpcode() == Instruction::Malloc; |
| 86 | } |
| 87 | static inline bool classof(const Value *V) { |
| 88 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | |
| 93 | //===----------------------------------------------------------------------===// |
| 94 | // MallocInst Class |
| 95 | //===----------------------------------------------------------------------===// |
| 96 | |
| 97 | /// MallocInst - an instruction to allocated memory on the heap |
| 98 | /// |
| 99 | class MallocInst : public AllocationInst { |
| 100 | MallocInst(const MallocInst &MI); |
| 101 | public: |
| 102 | explicit MallocInst(const Type *Ty, Value *ArraySize = 0, |
| 103 | const std::string &Name = "", |
| 104 | Instruction *InsertBefore = 0) |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 105 | : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {} |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 106 | MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name, |
| 107 | BasicBlock *InsertAtEnd) |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 108 | : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {} |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 109 | |
| 110 | MallocInst(const Type *Ty, const std::string &Name, |
| 111 | Instruction *InsertBefore = 0) |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 112 | : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {} |
| 113 | MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
| 114 | : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {} |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 115 | |
| 116 | MallocInst(const Type *Ty, Value *ArraySize, unsigned Align, |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 117 | const std::string &Name, BasicBlock *InsertAtEnd) |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 118 | : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {} |
| 119 | MallocInst(const Type *Ty, Value *ArraySize, unsigned Align, |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 120 | const std::string &Name = "", |
| 121 | Instruction *InsertBefore = 0) |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 122 | : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {} |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 123 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 124 | virtual MallocInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 125 | |
| 126 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 127 | static inline bool classof(const MallocInst *) { return true; } |
| 128 | static inline bool classof(const Instruction *I) { |
| 129 | return (I->getOpcode() == Instruction::Malloc); |
| 130 | } |
| 131 | static inline bool classof(const Value *V) { |
| 132 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | |
| 137 | //===----------------------------------------------------------------------===// |
| 138 | // AllocaInst Class |
| 139 | //===----------------------------------------------------------------------===// |
| 140 | |
| 141 | /// AllocaInst - an instruction to allocate memory on the stack |
| 142 | /// |
| 143 | class AllocaInst : public AllocationInst { |
| 144 | AllocaInst(const AllocaInst &); |
| 145 | public: |
| 146 | explicit AllocaInst(const Type *Ty, Value *ArraySize = 0, |
| 147 | const std::string &Name = "", |
| 148 | Instruction *InsertBefore = 0) |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 149 | : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {} |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 150 | AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name, |
| 151 | BasicBlock *InsertAtEnd) |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 152 | : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {} |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 153 | |
| 154 | AllocaInst(const Type *Ty, const std::string &Name, |
| 155 | Instruction *InsertBefore = 0) |
| 156 | : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {} |
| 157 | AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
| 158 | : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {} |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 159 | |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 160 | AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align, |
| 161 | const std::string &Name = "", Instruction *InsertBefore = 0) |
| 162 | : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {} |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 163 | AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align, |
| 164 | const std::string &Name, BasicBlock *InsertAtEnd) |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 165 | : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {} |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 166 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 167 | virtual AllocaInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 168 | |
| 169 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 170 | static inline bool classof(const AllocaInst *) { return true; } |
| 171 | static inline bool classof(const Instruction *I) { |
| 172 | return (I->getOpcode() == Instruction::Alloca); |
| 173 | } |
| 174 | static inline bool classof(const Value *V) { |
| 175 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 176 | } |
| 177 | }; |
| 178 | |
| 179 | |
| 180 | //===----------------------------------------------------------------------===// |
| 181 | // FreeInst Class |
| 182 | //===----------------------------------------------------------------------===// |
| 183 | |
| 184 | /// FreeInst - an instruction to deallocate memory |
| 185 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 186 | class FreeInst : public UnaryInstruction { |
| 187 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 188 | public: |
| 189 | explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0); |
| 190 | FreeInst(Value *Ptr, BasicBlock *InsertAfter); |
| 191 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 192 | virtual FreeInst *clone() const; |
Owen Anderson | c9edf0b | 2007-07-06 23:13:31 +0000 | [diff] [blame] | 193 | |
| 194 | // Accessor methods for consistency with other memory operations |
| 195 | Value *getPointerOperand() { return getOperand(0); } |
| 196 | const Value *getPointerOperand() const { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 197 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 198 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 199 | static inline bool classof(const FreeInst *) { return true; } |
| 200 | static inline bool classof(const Instruction *I) { |
| 201 | return (I->getOpcode() == Instruction::Free); |
| 202 | } |
| 203 | static inline bool classof(const Value *V) { |
| 204 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 205 | } |
| 206 | }; |
| 207 | |
| 208 | |
| 209 | //===----------------------------------------------------------------------===// |
| 210 | // LoadInst Class |
| 211 | //===----------------------------------------------------------------------===// |
| 212 | |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 213 | /// LoadInst - an instruction for reading from memory. This uses the |
| 214 | /// SubclassData field in Value to store whether or not the load is volatile. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 215 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 216 | class LoadInst : public UnaryInstruction { |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 217 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 218 | LoadInst(const LoadInst &LI) |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 219 | : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) { |
| 220 | setVolatile(LI.isVolatile()); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 221 | setAlignment(LI.getAlignment()); |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 222 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 223 | #ifndef NDEBUG |
| 224 | AssertOK(); |
| 225 | #endif |
| 226 | } |
| 227 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 228 | public: |
| 229 | LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore); |
| 230 | LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 231 | LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false, |
| 232 | Instruction *InsertBefore = 0); |
| 233 | LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align, |
Chris Lattner | f00042a | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 234 | Instruction *InsertBefore = 0); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 235 | LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, |
| 236 | BasicBlock *InsertAtEnd); |
Dan Gohman | 6ab2d18 | 2007-07-18 20:51:11 +0000 | [diff] [blame] | 237 | LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align, |
| 238 | BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 239 | |
Chris Lattner | f00042a | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 240 | LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore); |
| 241 | LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 242 | explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false, |
Chris Lattner | f00042a | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 243 | Instruction *InsertBefore = 0); |
| 244 | LoadInst(Value *Ptr, const char *Name, bool isVolatile, |
| 245 | BasicBlock *InsertAtEnd); |
| 246 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 247 | /// isVolatile - Return true if this is a load from a volatile memory |
| 248 | /// location. |
| 249 | /// |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 250 | bool isVolatile() const { return SubclassData & 1; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 251 | |
| 252 | /// setVolatile - Specify whether this is a volatile load or not. |
| 253 | /// |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 254 | void setVolatile(bool V) { |
Hartmut Kaiser | efd4a51 | 2007-10-17 14:56:40 +0000 | [diff] [blame] | 255 | SubclassData = (SubclassData & ~1) | (V ? 1 : 0); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 256 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 257 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 258 | virtual LoadInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 259 | |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 260 | /// getAlignment - Return the alignment of the access that is being performed |
| 261 | /// |
| 262 | unsigned getAlignment() const { |
Christopher Lamb | 032507d | 2007-04-22 22:22:02 +0000 | [diff] [blame] | 263 | return (1 << (SubclassData>>1)) >> 1; |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | void setAlignment(unsigned Align); |
| 267 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 268 | Value *getPointerOperand() { return getOperand(0); } |
| 269 | const Value *getPointerOperand() const { return getOperand(0); } |
| 270 | static unsigned getPointerOperandIndex() { return 0U; } |
| 271 | |
| 272 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 273 | static inline bool classof(const LoadInst *) { return true; } |
| 274 | static inline bool classof(const Instruction *I) { |
| 275 | return I->getOpcode() == Instruction::Load; |
| 276 | } |
| 277 | static inline bool classof(const Value *V) { |
| 278 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 279 | } |
| 280 | }; |
| 281 | |
| 282 | |
| 283 | //===----------------------------------------------------------------------===// |
| 284 | // StoreInst Class |
| 285 | //===----------------------------------------------------------------------===// |
| 286 | |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 287 | /// StoreInst - an instruction for storing to memory |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 288 | /// |
| 289 | class StoreInst : public Instruction { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 290 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 291 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 292 | StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, |
| 293 | &Op<0>(), 2) { |
| 294 | Op<0>().init(SI.Op<0>(), this); |
| 295 | Op<1>().init(SI.Op<1>(), this); |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 296 | setVolatile(SI.isVolatile()); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 297 | setAlignment(SI.getAlignment()); |
| 298 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 299 | #ifndef NDEBUG |
| 300 | AssertOK(); |
| 301 | #endif |
| 302 | } |
| 303 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 304 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 305 | // allocate space for exactly two operands |
| 306 | void *operator new(size_t s) { |
| 307 | return User::operator new(s, 2); |
| 308 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 309 | StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore); |
| 310 | StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd); |
| 311 | StoreInst(Value *Val, Value *Ptr, bool isVolatile = false, |
| 312 | Instruction *InsertBefore = 0); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 313 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, |
| 314 | unsigned Align, Instruction *InsertBefore = 0); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 315 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd); |
Dan Gohman | 6ab2d18 | 2007-07-18 20:51:11 +0000 | [diff] [blame] | 316 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, |
| 317 | unsigned Align, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 318 | |
| 319 | |
| 320 | /// isVolatile - Return true if this is a load from a volatile memory |
| 321 | /// location. |
| 322 | /// |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 323 | bool isVolatile() const { return SubclassData & 1; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 324 | |
| 325 | /// setVolatile - Specify whether this is a volatile load or not. |
| 326 | /// |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 327 | void setVolatile(bool V) { |
Hartmut Kaiser | efd4a51 | 2007-10-17 14:56:40 +0000 | [diff] [blame] | 328 | SubclassData = (SubclassData & ~1) | (V ? 1 : 0); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 329 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 330 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 331 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 332 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 333 | |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 334 | /// getAlignment - Return the alignment of the access that is being performed |
| 335 | /// |
| 336 | unsigned getAlignment() const { |
Christopher Lamb | 032507d | 2007-04-22 22:22:02 +0000 | [diff] [blame] | 337 | return (1 << (SubclassData>>1)) >> 1; |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | void setAlignment(unsigned Align); |
| 341 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 342 | virtual StoreInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 343 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 344 | Value *getPointerOperand() { return getOperand(1); } |
| 345 | const Value *getPointerOperand() const { return getOperand(1); } |
| 346 | static unsigned getPointerOperandIndex() { return 1U; } |
| 347 | |
| 348 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 349 | static inline bool classof(const StoreInst *) { return true; } |
| 350 | static inline bool classof(const Instruction *I) { |
| 351 | return I->getOpcode() == Instruction::Store; |
| 352 | } |
| 353 | static inline bool classof(const Value *V) { |
| 354 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 355 | } |
| 356 | }; |
| 357 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 358 | template <> |
| 359 | struct OperandTraits<StoreInst> : FixedNumOperandTraits<2> { |
| 360 | }; |
| 361 | |
| 362 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value) |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 363 | |
| 364 | //===----------------------------------------------------------------------===// |
| 365 | // GetElementPtrInst Class |
| 366 | //===----------------------------------------------------------------------===// |
| 367 | |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 368 | // checkType - Simple wrapper function to give a better assertion failure |
| 369 | // message on bad indexes for a gep instruction. |
| 370 | // |
| 371 | static inline const Type *checkType(const Type *Ty) { |
| 372 | assert(Ty && "Invalid GetElementPtrInst indices for type!"); |
| 373 | return Ty; |
| 374 | } |
| 375 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 376 | /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to |
| 377 | /// access elements of arrays and structs |
| 378 | /// |
| 379 | class GetElementPtrInst : public Instruction { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 380 | GetElementPtrInst(const GetElementPtrInst &GEPI); |
Chris Lattner | 6ffbe17 | 2007-01-31 19:47:18 +0000 | [diff] [blame] | 381 | void init(Value *Ptr, Value* const *Idx, unsigned NumIdx); |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 382 | void init(Value *Ptr, Value *Idx); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 383 | |
| 384 | template<typename InputIterator> |
| 385 | void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd, |
| 386 | const std::string &Name, |
| 387 | // This argument ensures that we have an iterator we can |
| 388 | // do arithmetic on in constant time |
| 389 | std::random_access_iterator_tag) { |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 390 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 391 | |
| 392 | if (NumIdx > 0) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 393 | // This requires that the iterator points to contiguous memory. |
| 394 | init(Ptr, &*IdxBegin, NumIdx); // FIXME: for the general case |
| 395 | // we have to build an array here |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 396 | } |
| 397 | else { |
| 398 | init(Ptr, 0, NumIdx); |
| 399 | } |
| 400 | |
| 401 | setName(Name); |
| 402 | } |
| 403 | |
| 404 | /// getIndexedType - Returns the type of the element that would be loaded with |
| 405 | /// a load instruction with the specified parameters. |
| 406 | /// |
| 407 | /// A null type is returned if the indices are invalid for the specified |
| 408 | /// pointer type. |
| 409 | /// |
| 410 | static const Type *getIndexedType(const Type *Ptr, |
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 | /// |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 500 | /// A null type is returned if the indices are invalid for the specified |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 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; } |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 1112 | |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 1113 | /// @brief Determine whether the call or the callee has the given attribute. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1114 | bool paramHasAttr(unsigned i, unsigned attr) const; |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 1115 | |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 1116 | /// @brief Extract the alignment for a call or parameter (0=unknown). |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1117 | unsigned getParamAlignment(unsigned i) const { |
| 1118 | return ParamAttrs.getParamAlignment(i); |
| 1119 | } |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 1120 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1121 | /// @brief Determine if the call does not access memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1122 | bool doesNotAccessMemory() const { |
| 1123 | return paramHasAttr(0, ParamAttr::ReadNone); |
| 1124 | } |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 1125 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1126 | /// @brief Determine if the call does not access or only reads memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1127 | bool onlyReadsMemory() const { |
| 1128 | return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly); |
| 1129 | } |
Chris Lattner | 50ee9dd | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 1130 | |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 1131 | /// @brief Determine if the call cannot return. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1132 | bool doesNotReturn() const { |
| 1133 | return paramHasAttr(0, ParamAttr::NoReturn); |
| 1134 | } |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 1135 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1136 | /// @brief Determine if the call cannot unwind. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1137 | bool doesNotThrow() const { |
| 1138 | return paramHasAttr(0, ParamAttr::NoUnwind); |
| 1139 | } |
Duncan Sands | f0c3354 | 2007-12-19 21:13:37 +0000 | [diff] [blame] | 1140 | void setDoesNotThrow(bool doesNotThrow = true); |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1141 | |
Devang Patel | 41e2397 | 2008-03-03 21:46:28 +0000 | [diff] [blame] | 1142 | /// @brief Determine if the call returns a structure through first |
| 1143 | /// pointer argument. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1144 | bool hasStructRetAttr() const { |
| 1145 | // Be friendly and also check the callee. |
| 1146 | return paramHasAttr(1, ParamAttr::StructRet); |
| 1147 | } |
Reid Spencer | 4746ecf | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 1148 | |
Evan Cheng | f4a5498 | 2008-01-12 18:57:32 +0000 | [diff] [blame] | 1149 | /// @brief Determine if any call argument is an aggregate passed by value. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1150 | bool hasByValArgument() const { |
| 1151 | return ParamAttrs.hasAttrSomewhere(ParamAttr::ByVal); |
| 1152 | } |
Evan Cheng | f4a5498 | 2008-01-12 18:57:32 +0000 | [diff] [blame] | 1153 | |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 1154 | /// getCalledFunction - Return the function being called by this instruction |
| 1155 | /// if it is a direct call. If it is a call through a function pointer, |
| 1156 | /// return null. |
| 1157 | Function *getCalledFunction() const { |
Dan Gohman | 11a7dbf | 2007-09-24 15:46:02 +0000 | [diff] [blame] | 1158 | return dyn_cast<Function>(getOperand(0)); |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 1159 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1160 | |
Reid Spencer | c25ec25 | 2006-12-29 04:10:59 +0000 | [diff] [blame] | 1161 | /// getCalledValue - Get a pointer to the function that is invoked by this |
| 1162 | /// instruction |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1163 | const Value *getCalledValue() const { return getOperand(0); } |
| 1164 | Value *getCalledValue() { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1165 | |
| 1166 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1167 | static inline bool classof(const CallInst *) { return true; } |
| 1168 | static inline bool classof(const Instruction *I) { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1169 | return I->getOpcode() == Instruction::Call; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1170 | } |
| 1171 | static inline bool classof(const Value *V) { |
| 1172 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1173 | } |
| 1174 | }; |
| 1175 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1176 | template <> |
| 1177 | struct OperandTraits<CallInst> : VariadicOperandTraits<1> { |
| 1178 | }; |
| 1179 | |
| 1180 | template<typename InputIterator> |
| 1181 | CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
| 1182 | const std::string &Name, BasicBlock *InsertAtEnd) |
| 1183 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 1184 | ->getElementType())->getReturnType(), |
| 1185 | Instruction::Call, |
| 1186 | OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1), |
Bill Wendling | 1b2f729 | 2008-05-10 11:26:52 +0000 | [diff] [blame] | 1187 | (unsigned)(ArgEnd - ArgBegin + 1), InsertAtEnd) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1188 | init(Func, ArgBegin, ArgEnd, Name, |
| 1189 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 1190 | } |
| 1191 | |
| 1192 | template<typename InputIterator> |
| 1193 | CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
| 1194 | const std::string &Name, Instruction *InsertBefore) |
| 1195 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 1196 | ->getElementType())->getReturnType(), |
| 1197 | Instruction::Call, |
| 1198 | OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1), |
Bill Wendling | 1b2f729 | 2008-05-10 11:26:52 +0000 | [diff] [blame] | 1199 | (unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1200 | init(Func, ArgBegin, ArgEnd, Name, |
| 1201 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 1202 | } |
| 1203 | |
| 1204 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value) |
| 1205 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1206 | //===----------------------------------------------------------------------===// |
| 1207 | // SelectInst Class |
| 1208 | //===----------------------------------------------------------------------===// |
| 1209 | |
| 1210 | /// SelectInst - This class represents the LLVM 'select' instruction. |
| 1211 | /// |
| 1212 | class SelectInst : public Instruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1213 | void init(Value *C, Value *S1, Value *S2) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1214 | Op<0>() = C; |
| 1215 | Op<1>() = S1; |
| 1216 | Op<2>() = S2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1219 | SelectInst(const SelectInst &SI) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1220 | : Instruction(SI.getType(), SI.getOpcode(), &Op<0>(), 3) { |
| 1221 | init(SI.Op<0>(), SI.Op<1>(), SI.Op<2>()); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1222 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1223 | SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name, |
| 1224 | Instruction *InsertBefore) |
| 1225 | : Instruction(S1->getType(), Instruction::Select, |
| 1226 | &Op<0>(), 3, InsertBefore) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1227 | init(C, S1, S2); |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1228 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1229 | } |
| 1230 | SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name, |
| 1231 | BasicBlock *InsertAtEnd) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1232 | : Instruction(S1->getType(), Instruction::Select, |
| 1233 | &Op<0>(), 3, InsertAtEnd) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1234 | init(C, S1, S2); |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1235 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1236 | } |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1237 | public: |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1238 | static SelectInst *Create(Value *C, Value *S1, Value *S2, |
| 1239 | const std::string &Name = "", |
| 1240 | Instruction *InsertBefore = 0) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1241 | return new(3) SelectInst(C, S1, S2, Name, InsertBefore); |
| 1242 | } |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1243 | static SelectInst *Create(Value *C, Value *S1, Value *S2, |
| 1244 | const std::string &Name, BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1245 | return new(3) SelectInst(C, S1, S2, Name, InsertAtEnd); |
| 1246 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1247 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1248 | Value *getCondition() const { return Op<0>(); } |
| 1249 | Value *getTrueValue() const { return Op<1>(); } |
| 1250 | Value *getFalseValue() const { return Op<2>(); } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1251 | |
| 1252 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1253 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1254 | |
| 1255 | OtherOps getOpcode() const { |
| 1256 | return static_cast<OtherOps>(Instruction::getOpcode()); |
| 1257 | } |
| 1258 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1259 | virtual SelectInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1260 | |
| 1261 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1262 | static inline bool classof(const SelectInst *) { return true; } |
| 1263 | static inline bool classof(const Instruction *I) { |
| 1264 | return I->getOpcode() == Instruction::Select; |
| 1265 | } |
| 1266 | static inline bool classof(const Value *V) { |
| 1267 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1268 | } |
| 1269 | }; |
| 1270 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1271 | template <> |
| 1272 | struct OperandTraits<SelectInst> : FixedNumOperandTraits<3> { |
| 1273 | }; |
| 1274 | |
| 1275 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value) |
| 1276 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1277 | //===----------------------------------------------------------------------===// |
| 1278 | // VAArgInst Class |
| 1279 | //===----------------------------------------------------------------------===// |
| 1280 | |
| 1281 | /// VAArgInst - This class represents the va_arg llvm instruction, which returns |
Andrew Lenharth | f542821 | 2005-06-18 18:31:30 +0000 | [diff] [blame] | 1282 | /// 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] | 1283 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1284 | class VAArgInst : public UnaryInstruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1285 | VAArgInst(const VAArgInst &VAA) |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1286 | : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {} |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1287 | public: |
| 1288 | VAArgInst(Value *List, const Type *Ty, const std::string &Name = "", |
| 1289 | Instruction *InsertBefore = 0) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1290 | : UnaryInstruction(Ty, VAArg, List, InsertBefore) { |
Chris Lattner | f00042a | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 1291 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1292 | } |
| 1293 | VAArgInst(Value *List, const Type *Ty, const std::string &Name, |
| 1294 | BasicBlock *InsertAtEnd) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1295 | : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) { |
Chris Lattner | f00042a | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 1296 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1299 | virtual VAArgInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1300 | |
| 1301 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1302 | static inline bool classof(const VAArgInst *) { return true; } |
| 1303 | static inline bool classof(const Instruction *I) { |
| 1304 | return I->getOpcode() == VAArg; |
| 1305 | } |
| 1306 | static inline bool classof(const Value *V) { |
| 1307 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1308 | } |
| 1309 | }; |
| 1310 | |
| 1311 | //===----------------------------------------------------------------------===// |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1312 | // ExtractElementInst Class |
| 1313 | //===----------------------------------------------------------------------===// |
| 1314 | |
| 1315 | /// ExtractElementInst - This instruction extracts a single (scalar) |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1316 | /// element from a VectorType value |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1317 | /// |
| 1318 | class ExtractElementInst : public Instruction { |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1319 | ExtractElementInst(const ExtractElementInst &EE) : |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1320 | Instruction(EE.getType(), ExtractElement, &Op<0>(), 2) { |
| 1321 | Op<0>().init(EE.Op<0>(), this); |
| 1322 | Op<1>().init(EE.Op<1>(), this); |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1326 | // allocate space for exactly two operands |
| 1327 | void *operator new(size_t s) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1328 | return User::operator new(s, 2); // FIXME: "unsigned Idx" forms of ctor? |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1329 | } |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1330 | ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "", |
| 1331 | Instruction *InsertBefore = 0); |
Chris Lattner | 06a248c2 | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1332 | ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "", |
| 1333 | Instruction *InsertBefore = 0); |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1334 | ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name, |
| 1335 | BasicBlock *InsertAtEnd); |
Chris Lattner | 06a248c2 | 2006-10-05 06:24:58 +0000 | [diff] [blame] | 1336 | ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name, |
| 1337 | BasicBlock *InsertAtEnd); |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1338 | |
Chris Lattner | fa49584 | 2006-04-08 04:04:54 +0000 | [diff] [blame] | 1339 | /// isValidOperands - Return true if an extractelement instruction can be |
| 1340 | /// formed with the specified operands. |
| 1341 | static bool isValidOperands(const Value *Vec, const Value *Idx); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1342 | |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1343 | virtual ExtractElementInst *clone() const; |
| 1344 | |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1345 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1346 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1347 | |
| 1348 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1349 | static inline bool classof(const ExtractElementInst *) { return true; } |
| 1350 | static inline bool classof(const Instruction *I) { |
| 1351 | return I->getOpcode() == Instruction::ExtractElement; |
| 1352 | } |
| 1353 | static inline bool classof(const Value *V) { |
| 1354 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1355 | } |
| 1356 | }; |
| 1357 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1358 | template <> |
| 1359 | struct OperandTraits<ExtractElementInst> : FixedNumOperandTraits<2> { |
| 1360 | }; |
| 1361 | |
| 1362 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value) |
| 1363 | |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1364 | //===----------------------------------------------------------------------===// |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1365 | // InsertElementInst Class |
| 1366 | //===----------------------------------------------------------------------===// |
| 1367 | |
| 1368 | /// InsertElementInst - This instruction inserts a single (scalar) |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1369 | /// element into a VectorType value |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1370 | /// |
| 1371 | class InsertElementInst : public Instruction { |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1372 | InsertElementInst(const InsertElementInst &IE); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1373 | InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, |
| 1374 | const std::string &Name = "",Instruction *InsertBefore = 0); |
| 1375 | InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx, |
| 1376 | const std::string &Name = "",Instruction *InsertBefore = 0); |
| 1377 | InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, |
| 1378 | const std::string &Name, BasicBlock *InsertAtEnd); |
| 1379 | InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx, |
| 1380 | const std::string &Name, BasicBlock *InsertAtEnd); |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1381 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1382 | static InsertElementInst *Create(const InsertElementInst &IE) { |
| 1383 | return new(IE.getNumOperands()) InsertElementInst(IE); |
| 1384 | } |
| 1385 | static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1386 | const std::string &Name = "", |
| 1387 | Instruction *InsertBefore = 0) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1388 | return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore); |
| 1389 | } |
| 1390 | static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1391 | const std::string &Name = "", |
| 1392 | Instruction *InsertBefore = 0) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1393 | return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1394 | } |
| 1395 | static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1396 | const std::string &Name, |
| 1397 | BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1398 | return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd); |
| 1399 | } |
| 1400 | static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1401 | const std::string &Name, |
| 1402 | BasicBlock *InsertAtEnd) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1403 | return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1404 | } |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1405 | |
Chris Lattner | fa49584 | 2006-04-08 04:04:54 +0000 | [diff] [blame] | 1406 | /// isValidOperands - Return true if an insertelement instruction can be |
| 1407 | /// formed with the specified operands. |
| 1408 | static bool isValidOperands(const Value *Vec, const Value *NewElt, |
| 1409 | const Value *Idx); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1410 | |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1411 | virtual InsertElementInst *clone() const; |
| 1412 | |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1413 | /// getType - Overload to return most specific vector type. |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1414 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1415 | const VectorType *getType() const { |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1416 | return reinterpret_cast<const VectorType*>(Instruction::getType()); |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1417 | } |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1418 | |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1419 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1420 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1421 | |
| 1422 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1423 | static inline bool classof(const InsertElementInst *) { return true; } |
| 1424 | static inline bool classof(const Instruction *I) { |
| 1425 | return I->getOpcode() == Instruction::InsertElement; |
| 1426 | } |
| 1427 | static inline bool classof(const Value *V) { |
| 1428 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1429 | } |
| 1430 | }; |
| 1431 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1432 | template <> |
| 1433 | struct OperandTraits<InsertElementInst> : FixedNumOperandTraits<3> { |
| 1434 | }; |
| 1435 | |
| 1436 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value) |
| 1437 | |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1438 | //===----------------------------------------------------------------------===// |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1439 | // ShuffleVectorInst Class |
| 1440 | //===----------------------------------------------------------------------===// |
| 1441 | |
| 1442 | /// ShuffleVectorInst - This instruction constructs a fixed permutation of two |
| 1443 | /// input vectors. |
| 1444 | /// |
| 1445 | class ShuffleVectorInst : public Instruction { |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1446 | ShuffleVectorInst(const ShuffleVectorInst &IE); |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1447 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1448 | // allocate space for exactly three operands |
| 1449 | void *operator new(size_t s) { |
| 1450 | return User::operator new(s, 3); |
| 1451 | } |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1452 | ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
| 1453 | const std::string &Name = "", Instruction *InsertBefor = 0); |
| 1454 | ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
| 1455 | const std::string &Name, BasicBlock *InsertAtEnd); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1456 | |
Chris Lattner | fa49584 | 2006-04-08 04:04:54 +0000 | [diff] [blame] | 1457 | /// isValidOperands - Return true if a shufflevector instruction can be |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1458 | /// formed with the specified operands. |
| 1459 | static bool isValidOperands(const Value *V1, const Value *V2, |
| 1460 | const Value *Mask); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1461 | |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1462 | virtual ShuffleVectorInst *clone() const; |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1463 | |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1464 | /// getType - Overload to return most specific vector type. |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1465 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1466 | const VectorType *getType() const { |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1467 | return reinterpret_cast<const VectorType*>(Instruction::getType()); |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1468 | } |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1469 | |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1470 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1471 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Chris Lattner | 8728f19 | 2008-03-02 05:28:33 +0000 | [diff] [blame] | 1472 | |
| 1473 | /// getMaskValue - Return the index from the shuffle mask for the specified |
| 1474 | /// output result. This is either -1 if the element is undef or a number less |
| 1475 | /// than 2*numelements. |
| 1476 | int getMaskValue(unsigned i) const; |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1477 | |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1478 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1479 | static inline bool classof(const ShuffleVectorInst *) { return true; } |
| 1480 | static inline bool classof(const Instruction *I) { |
| 1481 | return I->getOpcode() == Instruction::ShuffleVector; |
| 1482 | } |
| 1483 | static inline bool classof(const Value *V) { |
| 1484 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1485 | } |
| 1486 | }; |
| 1487 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1488 | template <> |
| 1489 | struct OperandTraits<ShuffleVectorInst> : FixedNumOperandTraits<3> { |
| 1490 | }; |
| 1491 | |
| 1492 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value) |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1493 | |
| 1494 | //===----------------------------------------------------------------------===// |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame^] | 1495 | // ExtractValueInst Class |
| 1496 | //===----------------------------------------------------------------------===// |
| 1497 | |
| 1498 | /// ExtractValueInst - This instruction extracts a value |
| 1499 | /// from an aggregate value |
| 1500 | /// |
| 1501 | class ExtractValueInst : public Instruction { |
| 1502 | ExtractValueInst(const ExtractValueInst &EVI); |
| 1503 | void init(Value *Agg, Value* const *Idx, unsigned NumIdx); |
| 1504 | void init(Value *Agg, Value *Idx); |
| 1505 | |
| 1506 | template<typename InputIterator> |
| 1507 | void init(Value *Agg, InputIterator IdxBegin, InputIterator IdxEnd, |
| 1508 | const std::string &Name, |
| 1509 | // This argument ensures that we have an iterator we can |
| 1510 | // do arithmetic on in constant time |
| 1511 | std::random_access_iterator_tag) { |
| 1512 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
| 1513 | |
| 1514 | if (NumIdx > 0) { |
| 1515 | // This requires that the iterator points to contiguous memory. |
| 1516 | init(Agg, &*IdxBegin, NumIdx); // FIXME: for the general case |
| 1517 | // we have to build an array here |
| 1518 | } |
| 1519 | else { |
| 1520 | init(Agg, 0, NumIdx); |
| 1521 | } |
| 1522 | |
| 1523 | setName(Name); |
| 1524 | } |
| 1525 | |
| 1526 | /// getIndexedType - Returns the type of the element that would be extracted |
| 1527 | /// with an extractvalue instruction with the specified parameters. |
| 1528 | /// |
| 1529 | /// A null type is returned if the indices are invalid for the specified |
| 1530 | /// pointer type. |
| 1531 | /// |
| 1532 | static const Type *getIndexedType(const Type *Agg, |
| 1533 | Value* const *Idx, unsigned NumIdx); |
| 1534 | |
| 1535 | template<typename InputIterator> |
| 1536 | static const Type *getIndexedType(const Type *Ptr, |
| 1537 | InputIterator IdxBegin, |
| 1538 | InputIterator IdxEnd, |
| 1539 | // This argument ensures that we |
| 1540 | // have an iterator we can do |
| 1541 | // arithmetic on in constant time |
| 1542 | std::random_access_iterator_tag) { |
| 1543 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
| 1544 | |
| 1545 | if (NumIdx > 0) |
| 1546 | // This requires that the iterator points to contiguous memory. |
| 1547 | return getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx); |
| 1548 | else |
| 1549 | return getIndexedType(Ptr, (Value *const*)0, NumIdx); |
| 1550 | } |
| 1551 | |
| 1552 | /// Constructors - Create a extractvalue instruction with a base pointer an |
| 1553 | /// list of indices. The first ctor can optionally insert before an existing |
| 1554 | /// instruction, the second appends the new instruction to the specified |
| 1555 | /// BasicBlock. |
| 1556 | template<typename InputIterator> |
| 1557 | inline ExtractValueInst(Value *Agg, InputIterator IdxBegin, |
| 1558 | InputIterator IdxEnd, |
| 1559 | unsigned Values, |
| 1560 | const std::string &Name, |
| 1561 | Instruction *InsertBefore); |
| 1562 | template<typename InputIterator> |
| 1563 | inline ExtractValueInst(Value *Agg, |
| 1564 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 1565 | unsigned Values, |
| 1566 | const std::string &Name, BasicBlock *InsertAtEnd); |
| 1567 | |
| 1568 | /// Constructors - These two constructors are convenience methods because one |
| 1569 | /// and two index extractvalue instructions are so common. |
| 1570 | ExtractValueInst(Value *Agg, Value *Idx, const std::string &Name = "", |
| 1571 | Instruction *InsertBefore = 0); |
| 1572 | ExtractValueInst(Value *Agg, Value *Idx, |
| 1573 | const std::string &Name, BasicBlock *InsertAtEnd); |
| 1574 | public: |
| 1575 | template<typename InputIterator> |
| 1576 | static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin, |
| 1577 | InputIterator IdxEnd, |
| 1578 | const std::string &Name = "", |
| 1579 | Instruction *InsertBefore = 0) { |
| 1580 | typename std::iterator_traits<InputIterator>::difference_type Values = |
| 1581 | 1 + std::distance(IdxBegin, IdxEnd); |
| 1582 | return new(Values) |
| 1583 | ExtractValueInst(Agg, IdxBegin, IdxEnd, Values, Name, InsertBefore); |
| 1584 | } |
| 1585 | template<typename InputIterator> |
| 1586 | static ExtractValueInst *Create(Value *Agg, |
| 1587 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 1588 | const std::string &Name, |
| 1589 | BasicBlock *InsertAtEnd) { |
| 1590 | typename std::iterator_traits<InputIterator>::difference_type Values = |
| 1591 | 1 + std::distance(IdxBegin, IdxEnd); |
| 1592 | return new(Values) |
| 1593 | ExtractValueInst(Agg, IdxBegin, IdxEnd, Values, Name, InsertAtEnd); |
| 1594 | } |
| 1595 | |
| 1596 | /// Constructors - These two creators are convenience methods because one |
| 1597 | /// index extractvalue instructions are much more common than those with |
| 1598 | /// more than one. |
| 1599 | static ExtractValueInst *Create(Value *Agg, Value *Idx, |
| 1600 | const std::string &Name = "", |
| 1601 | Instruction *InsertBefore = 0) { |
| 1602 | return new(2) ExtractValueInst(Agg, Idx, Name, InsertBefore); |
| 1603 | } |
| 1604 | static ExtractValueInst *Create(Value *Agg, Value *Idx, |
| 1605 | const std::string &Name, |
| 1606 | BasicBlock *InsertAtEnd) { |
| 1607 | return new(2) ExtractValueInst(Agg, Idx, Name, InsertAtEnd); |
| 1608 | } |
| 1609 | |
| 1610 | virtual ExtractValueInst *clone() const; |
| 1611 | |
| 1612 | /// Transparently provide more efficient getOperand methods. |
| 1613 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 1614 | |
| 1615 | // getType - Overload to return most specific pointer type... |
| 1616 | const PointerType *getType() const { |
| 1617 | return reinterpret_cast<const PointerType*>(Instruction::getType()); |
| 1618 | } |
| 1619 | |
| 1620 | /// getIndexedType - Returns the type of the element that would be extracted |
| 1621 | /// with an extractvalue instruction with the specified parameters. |
| 1622 | /// |
| 1623 | /// A null type is returned if the indices are invalid for the specified |
| 1624 | /// pointer type. |
| 1625 | /// |
| 1626 | template<typename InputIterator> |
| 1627 | static const Type *getIndexedType(const Type *Ptr, |
| 1628 | InputIterator IdxBegin, |
| 1629 | InputIterator IdxEnd) { |
| 1630 | return getIndexedType(Ptr, IdxBegin, IdxEnd, |
| 1631 | typename std::iterator_traits<InputIterator>:: |
| 1632 | iterator_category()); |
| 1633 | } |
| 1634 | static const Type *getIndexedType(const Type *Ptr, Value *Idx); |
| 1635 | |
| 1636 | inline op_iterator idx_begin() { return op_begin()+1; } |
| 1637 | inline const_op_iterator idx_begin() const { return op_begin()+1; } |
| 1638 | inline op_iterator idx_end() { return op_end(); } |
| 1639 | inline const_op_iterator idx_end() const { return op_end(); } |
| 1640 | |
| 1641 | Value *getAggregateOperand() { |
| 1642 | return getOperand(0); |
| 1643 | } |
| 1644 | const Value *getAggregateOperand() const { |
| 1645 | return getOperand(0); |
| 1646 | } |
| 1647 | static unsigned getAggregateOperandIndex() { |
| 1648 | return 0U; // get index for modifying correct operand |
| 1649 | } |
| 1650 | |
| 1651 | unsigned getNumIndices() const { // Note: always non-negative |
| 1652 | return getNumOperands() - 1; |
| 1653 | } |
| 1654 | |
| 1655 | bool hasIndices() const { |
| 1656 | return getNumOperands() > 1; |
| 1657 | } |
| 1658 | |
| 1659 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1660 | static inline bool classof(const ExtractValueInst *) { return true; } |
| 1661 | static inline bool classof(const Instruction *I) { |
| 1662 | return I->getOpcode() == Instruction::ExtractValue; |
| 1663 | } |
| 1664 | static inline bool classof(const Value *V) { |
| 1665 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1666 | } |
| 1667 | }; |
| 1668 | |
| 1669 | template <> |
| 1670 | struct OperandTraits<ExtractValueInst> : VariadicOperandTraits<1> { |
| 1671 | }; |
| 1672 | |
| 1673 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractValueInst, Value) |
| 1674 | |
| 1675 | //===----------------------------------------------------------------------===// |
| 1676 | // InsertValueInst Class |
| 1677 | //===----------------------------------------------------------------------===// |
| 1678 | |
| 1679 | /// InsertValueInst - This instruction extracts a value |
| 1680 | /// from an aggregate value |
| 1681 | /// |
| 1682 | class InsertValueInst : public Instruction { |
| 1683 | InsertValueInst(const InsertValueInst &IVI); |
| 1684 | void init(Value *Agg, Value *Val, Value* const *Idx, unsigned NumIdx); |
| 1685 | void init(Value *Agg, Value *Val, Value *Idx); |
| 1686 | |
| 1687 | template<typename InputIterator> |
| 1688 | void init(Value *Agg, Value *Val, |
| 1689 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 1690 | const std::string &Name, |
| 1691 | // This argument ensures that we have an iterator we can |
| 1692 | // do arithmetic on in constant time |
| 1693 | std::random_access_iterator_tag) { |
| 1694 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
| 1695 | |
| 1696 | if (NumIdx > 0) { |
| 1697 | // This requires that the iterator points to contiguous memory. |
| 1698 | init(Agg, Val, &*IdxBegin, NumIdx); // FIXME: for the general case |
| 1699 | // we have to build an array here |
| 1700 | } |
| 1701 | else { |
| 1702 | init(Agg, Val, 0, NumIdx); |
| 1703 | } |
| 1704 | |
| 1705 | setName(Name); |
| 1706 | } |
| 1707 | |
| 1708 | /// Constructors - Create a insertvalue instruction with a base pointer an |
| 1709 | /// list of indices. The first ctor can optionally insert before an existing |
| 1710 | /// instruction, the second appends the new instruction to the specified |
| 1711 | /// BasicBlock. |
| 1712 | template<typename InputIterator> |
| 1713 | inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin, |
| 1714 | InputIterator IdxEnd, |
| 1715 | unsigned Values, |
| 1716 | const std::string &Name, |
| 1717 | Instruction *InsertBefore); |
| 1718 | template<typename InputIterator> |
| 1719 | inline InsertValueInst(Value *Agg, Value *Val, |
| 1720 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 1721 | unsigned Values, |
| 1722 | const std::string &Name, BasicBlock *InsertAtEnd); |
| 1723 | |
| 1724 | /// Constructors - These two constructors are convenience methods because one |
| 1725 | /// and two index insertvalue instructions are so common. |
| 1726 | InsertValueInst(Value *Agg, Value *Val, |
| 1727 | Value *Idx, const std::string &Name = "", |
| 1728 | Instruction *InsertBefore = 0); |
| 1729 | InsertValueInst(Value *Agg, Value *Val, Value *Idx, |
| 1730 | const std::string &Name, BasicBlock *InsertAtEnd); |
| 1731 | public: |
| 1732 | template<typename InputIterator> |
| 1733 | static InsertValueInst *Create(Value *Agg, Value *Val, InputIterator IdxBegin, |
| 1734 | InputIterator IdxEnd, |
| 1735 | const std::string &Name = "", |
| 1736 | Instruction *InsertBefore = 0) { |
| 1737 | typename std::iterator_traits<InputIterator>::difference_type Values = |
| 1738 | 1 + std::distance(IdxBegin, IdxEnd); |
| 1739 | return new(Values) |
| 1740 | InsertValueInst(Agg, Val, IdxBegin, IdxEnd, Values, Name, InsertBefore); |
| 1741 | } |
| 1742 | template<typename InputIterator> |
| 1743 | static InsertValueInst *Create(Value *Agg, Value *Val, |
| 1744 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 1745 | const std::string &Name, |
| 1746 | BasicBlock *InsertAtEnd) { |
| 1747 | typename std::iterator_traits<InputIterator>::difference_type Values = |
| 1748 | 1 + std::distance(IdxBegin, IdxEnd); |
| 1749 | return new(Values) |
| 1750 | InsertValueInst(Agg, Val, IdxBegin, IdxEnd, Values, Name, InsertAtEnd); |
| 1751 | } |
| 1752 | |
| 1753 | /// Constructors - These two creators are convenience methods because one |
| 1754 | /// index insertvalue instructions are much more common than those with |
| 1755 | /// more than one. |
| 1756 | static InsertValueInst *Create(Value *Agg, Value *Val, Value *Idx, |
| 1757 | const std::string &Name = "", |
| 1758 | Instruction *InsertBefore = 0) { |
| 1759 | return new(3) InsertValueInst(Agg, Val, Idx, Name, InsertBefore); |
| 1760 | } |
| 1761 | static InsertValueInst *Create(Value *Agg, Value *Val, Value *Idx, |
| 1762 | const std::string &Name, |
| 1763 | BasicBlock *InsertAtEnd) { |
| 1764 | return new(3) InsertValueInst(Agg, Val, Idx, Name, InsertAtEnd); |
| 1765 | } |
| 1766 | |
| 1767 | virtual InsertValueInst *clone() const; |
| 1768 | |
| 1769 | /// Transparently provide more efficient getOperand methods. |
| 1770 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 1771 | |
| 1772 | // getType - Overload to return most specific pointer type... |
| 1773 | const PointerType *getType() const { |
| 1774 | return reinterpret_cast<const PointerType*>(Instruction::getType()); |
| 1775 | } |
| 1776 | |
| 1777 | inline op_iterator idx_begin() { return op_begin()+1; } |
| 1778 | inline const_op_iterator idx_begin() const { return op_begin()+1; } |
| 1779 | inline op_iterator idx_end() { return op_end(); } |
| 1780 | inline const_op_iterator idx_end() const { return op_end(); } |
| 1781 | |
| 1782 | Value *getAggregateOperand() { |
| 1783 | return getOperand(0); |
| 1784 | } |
| 1785 | const Value *getAggregateOperand() const { |
| 1786 | return getOperand(0); |
| 1787 | } |
| 1788 | static unsigned getAggregateOperandIndex() { |
| 1789 | return 0U; // get index for modifying correct operand |
| 1790 | } |
| 1791 | |
| 1792 | Value *getInsertedValueOperand() { |
| 1793 | return getOperand(1); |
| 1794 | } |
| 1795 | const Value *getInsertedValueOperand() const { |
| 1796 | return getOperand(1); |
| 1797 | } |
| 1798 | static unsigned getInsertedValueOperandIndex() { |
| 1799 | return 1U; // get index for modifying correct operand |
| 1800 | } |
| 1801 | |
| 1802 | unsigned getNumIndices() const { // Note: always non-negative |
| 1803 | return getNumOperands() - 2; |
| 1804 | } |
| 1805 | |
| 1806 | bool hasIndices() const { |
| 1807 | return getNumOperands() > 2; |
| 1808 | } |
| 1809 | |
| 1810 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1811 | static inline bool classof(const InsertValueInst *) { return true; } |
| 1812 | static inline bool classof(const Instruction *I) { |
| 1813 | return I->getOpcode() == Instruction::InsertValue; |
| 1814 | } |
| 1815 | static inline bool classof(const Value *V) { |
| 1816 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1817 | } |
| 1818 | }; |
| 1819 | |
| 1820 | template <> |
| 1821 | struct OperandTraits<InsertValueInst> : VariadicOperandTraits<2> { |
| 1822 | }; |
| 1823 | |
| 1824 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value) |
| 1825 | |
| 1826 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1827 | // PHINode Class |
| 1828 | //===----------------------------------------------------------------------===// |
| 1829 | |
| 1830 | // PHINode - The PHINode class is used to represent the magical mystical PHI |
| 1831 | // node, that can not exist in nature, but can be synthesized in a computer |
| 1832 | // scientist's overactive imagination. |
| 1833 | // |
| 1834 | class PHINode : public Instruction { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1835 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1836 | /// ReservedSpace - The number of operands actually allocated. NumOperands is |
| 1837 | /// the number actually in use. |
| 1838 | unsigned ReservedSpace; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1839 | PHINode(const PHINode &PN); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1840 | // allocate space for exactly zero operands |
| 1841 | void *operator new(size_t s) { |
| 1842 | return User::operator new(s, 0); |
| 1843 | } |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1844 | explicit PHINode(const Type *Ty, const std::string &Name = "", |
| 1845 | Instruction *InsertBefore = 0) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1846 | : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore), |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1847 | ReservedSpace(0) { |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1848 | setName(Name); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1852 | : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd), |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1853 | ReservedSpace(0) { |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1854 | setName(Name); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1855 | } |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1856 | public: |
| 1857 | static PHINode *Create(const Type *Ty, const std::string &Name = "", |
| 1858 | Instruction *InsertBefore = 0) { |
| 1859 | return new PHINode(Ty, Name, InsertBefore); |
| 1860 | } |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1861 | static PHINode *Create(const Type *Ty, const std::string &Name, |
| 1862 | BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1863 | return new PHINode(Ty, Name, InsertAtEnd); |
| 1864 | } |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 1865 | ~PHINode(); |
| 1866 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1867 | /// reserveOperandSpace - This method can be used to avoid repeated |
| 1868 | /// reallocation of PHI operand lists by reserving space for the correct |
| 1869 | /// number of operands before adding them. Unlike normal vector reserves, |
| 1870 | /// this method can also be used to trim the operand space. |
| 1871 | void reserveOperandSpace(unsigned NumValues) { |
| 1872 | resizeOperands(NumValues*2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 1875 | virtual PHINode *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1876 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1877 | /// Provide fast operand accessors |
| 1878 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 1879 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1880 | /// getNumIncomingValues - Return the number of incoming edges |
| 1881 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1882 | unsigned getNumIncomingValues() const { return getNumOperands()/2; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1883 | |
Reid Spencer | c773de6 | 2006-05-19 19:07:54 +0000 | [diff] [blame] | 1884 | /// getIncomingValue - Return incoming value number x |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1885 | /// |
| 1886 | Value *getIncomingValue(unsigned i) const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1887 | assert(i*2 < getNumOperands() && "Invalid value number!"); |
| 1888 | return getOperand(i*2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1889 | } |
| 1890 | void setIncomingValue(unsigned i, Value *V) { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1891 | assert(i*2 < getNumOperands() && "Invalid value number!"); |
| 1892 | setOperand(i*2, V); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1893 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1894 | unsigned getOperandNumForIncomingValue(unsigned i) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1895 | return i*2; |
| 1896 | } |
| 1897 | |
Reid Spencer | c773de6 | 2006-05-19 19:07:54 +0000 | [diff] [blame] | 1898 | /// getIncomingBlock - Return incoming basic block number x |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1899 | /// |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1900 | BasicBlock *getIncomingBlock(unsigned i) const { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1901 | return static_cast<BasicBlock*>(getOperand(i*2+1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1902 | } |
| 1903 | void setIncomingBlock(unsigned i, BasicBlock *BB) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1904 | setOperand(i*2+1, BB); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1905 | } |
| 1906 | unsigned getOperandNumForIncomingBlock(unsigned i) { |
| 1907 | return i*2+1; |
| 1908 | } |
| 1909 | |
| 1910 | /// addIncoming - Add an incoming value to the end of the PHI list |
| 1911 | /// |
| 1912 | void addIncoming(Value *V, BasicBlock *BB) { |
Anton Korobeynikov | 351b0d4 | 2008-02-27 22:37:28 +0000 | [diff] [blame] | 1913 | assert(V && "PHI node got a null value!"); |
| 1914 | assert(BB && "PHI node got a null basic block!"); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1915 | assert(getType() == V->getType() && |
| 1916 | "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] | 1917 | unsigned OpNo = NumOperands; |
| 1918 | if (OpNo+2 > ReservedSpace) |
| 1919 | resizeOperands(0); // Get more space! |
| 1920 | // Initialize some new operands. |
| 1921 | NumOperands = OpNo+2; |
| 1922 | OperandList[OpNo].init(V, this); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1923 | OperandList[OpNo+1].init(BB, this); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1924 | } |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1925 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1926 | /// removeIncomingValue - Remove an incoming value. This is useful if a |
| 1927 | /// predecessor basic block is deleted. The value removed is returned. |
| 1928 | /// |
| 1929 | /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty |
| 1930 | /// is true), the PHI node is destroyed and any uses of it are replaced with |
| 1931 | /// dummy values. The only time there should be zero incoming values to a PHI |
| 1932 | /// node is when the block is dead, so this strategy is sound. |
| 1933 | /// |
| 1934 | Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true); |
| 1935 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1936 | Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1937 | int Idx = getBasicBlockIndex(BB); |
| 1938 | assert(Idx >= 0 && "Invalid basic block argument to remove!"); |
| 1939 | return removeIncomingValue(Idx, DeletePHIIfEmpty); |
| 1940 | } |
| 1941 | |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1942 | /// getBasicBlockIndex - Return the first index of the specified basic |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1943 | /// block in the value list for this PHI. Returns -1 if no instance. |
| 1944 | /// |
| 1945 | int getBasicBlockIndex(const BasicBlock *BB) const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1946 | Use *OL = OperandList; |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1947 | for (unsigned i = 0, e = getNumOperands(); i != e; i += 2) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1948 | if (OL[i+1].get() == BB) return i/2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1949 | return -1; |
| 1950 | } |
| 1951 | |
| 1952 | Value *getIncomingValueForBlock(const BasicBlock *BB) const { |
| 1953 | return getIncomingValue(getBasicBlockIndex(BB)); |
| 1954 | } |
| 1955 | |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1956 | /// hasConstantValue - If the specified PHI node always merges together the |
Nate Begeman | a83ba0f | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 1957 | /// same value, return the value, otherwise return null. |
| 1958 | /// |
Chris Lattner | 9acbd61 | 2005-08-05 00:49:06 +0000 | [diff] [blame] | 1959 | Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const; |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1960 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1961 | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1962 | static inline bool classof(const PHINode *) { return true; } |
| 1963 | static inline bool classof(const Instruction *I) { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1964 | return I->getOpcode() == Instruction::PHI; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1965 | } |
| 1966 | static inline bool classof(const Value *V) { |
| 1967 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1968 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1969 | private: |
| 1970 | void resizeOperands(unsigned NumOperands); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1971 | }; |
| 1972 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1973 | template <> |
| 1974 | struct OperandTraits<PHINode> : HungoffOperandTraits<2> { |
| 1975 | }; |
| 1976 | |
| 1977 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value) |
| 1978 | |
| 1979 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1980 | //===----------------------------------------------------------------------===// |
| 1981 | // ReturnInst Class |
| 1982 | //===----------------------------------------------------------------------===// |
| 1983 | |
| 1984 | //===--------------------------------------------------------------------------- |
| 1985 | /// ReturnInst - Return a value (possibly void), from a function. Execution |
| 1986 | /// does not continue in this function any longer. |
| 1987 | /// |
| 1988 | class ReturnInst : public TerminatorInst { |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1989 | ReturnInst(const ReturnInst &RI); |
Devang Patel | fea9830 | 2008-02-26 19:15:26 +0000 | [diff] [blame] | 1990 | void init(Value * const* retVals, unsigned N); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1991 | |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1992 | private: |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1993 | // ReturnInst constructors: |
| 1994 | // ReturnInst() - 'ret void' instruction |
Alkis Evlogimenos | 859804f | 2004-11-17 21:02:25 +0000 | [diff] [blame] | 1995 | // ReturnInst( null) - 'ret void' instruction |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1996 | // ReturnInst(Value* X) - 'ret X' instruction |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1997 | // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1998 | // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1999 | // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B |
| 2000 | // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B |
Devang Patel | e6be34a | 2008-02-27 01:20:54 +0000 | [diff] [blame] | 2001 | // ReturnInst(Value* X, N) - 'ret X,X+1...X+N-1' instruction |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2002 | // ReturnInst(Value* X, N, Inst *I) - 'ret X,X+1...X+N-1', insert before I |
| 2003 | // 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] | 2004 | // |
| 2005 | // NOTE: If the Value* passed is of type void then the constructor behaves as |
| 2006 | // if it was passed NULL. |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2007 | explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0); |
| 2008 | ReturnInst(Value *retVal, BasicBlock *InsertAtEnd); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2009 | ReturnInst(Value * const* retVals, unsigned N, Instruction *InsertBefore = 0); |
Devang Patel | f4511cd | 2008-02-26 19:38:17 +0000 | [diff] [blame] | 2010 | ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd); |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2011 | explicit ReturnInst(BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2012 | public: |
| 2013 | static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) { |
| 2014 | return new(!!retVal) ReturnInst(retVal, InsertBefore); |
| 2015 | } |
| 2016 | static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) { |
| 2017 | return new(!!retVal) ReturnInst(retVal, InsertAtEnd); |
| 2018 | } |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 2019 | static ReturnInst* Create(Value * const* retVals, unsigned N, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2020 | Instruction *InsertBefore = 0) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2021 | return new(N) ReturnInst(retVals, N, InsertBefore); |
| 2022 | } |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 2023 | static ReturnInst* Create(Value * const* retVals, unsigned N, |
| 2024 | BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2025 | return new(N) ReturnInst(retVals, N, InsertAtEnd); |
| 2026 | } |
| 2027 | static ReturnInst* Create(BasicBlock *InsertAtEnd) { |
| 2028 | return new(0) ReturnInst(InsertAtEnd); |
| 2029 | } |
Devang Patel | 57ef4f4 | 2008-02-23 00:35:18 +0000 | [diff] [blame] | 2030 | virtual ~ReturnInst(); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2031 | inline void operator delete(void*); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2032 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 2033 | virtual ReturnInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2034 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2035 | /// Provide fast operand accessors |
| 2036 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Devang Patel | 64d4e61 | 2008-02-26 17:56:20 +0000 | [diff] [blame] | 2037 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2038 | /// Convenience accessor |
Devang Patel | 1eafa06 | 2008-03-11 17:35:03 +0000 | [diff] [blame] | 2039 | Value *getReturnValue(unsigned n = 0) const { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2040 | return n < getNumOperands() |
| 2041 | ? getOperand(n) |
| 2042 | : 0; |
Devang Patel | 1eafa06 | 2008-03-11 17:35:03 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2045 | unsigned getNumSuccessors() const { return 0; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2046 | |
| 2047 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2048 | static inline bool classof(const ReturnInst *) { return true; } |
| 2049 | static inline bool classof(const Instruction *I) { |
| 2050 | return (I->getOpcode() == Instruction::Ret); |
| 2051 | } |
| 2052 | static inline bool classof(const Value *V) { |
| 2053 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2054 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2055 | private: |
| 2056 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2057 | virtual unsigned getNumSuccessorsV() const; |
| 2058 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2059 | }; |
| 2060 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2061 | template <> |
| 2062 | struct OperandTraits<ReturnInst> : VariadicOperandTraits<> { |
| 2063 | }; |
| 2064 | |
| 2065 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value) |
| 2066 | void ReturnInst::operator delete(void *it) { |
| 2067 | ReturnInst* me(static_cast<ReturnInst*>(it)); |
| 2068 | Use::zap(OperandTraits<ReturnInst>::op_begin(me), |
| 2069 | OperandTraits<ReturnInst>::op_end(me), |
| 2070 | true); |
| 2071 | } |
| 2072 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2073 | //===----------------------------------------------------------------------===// |
| 2074 | // BranchInst Class |
| 2075 | //===----------------------------------------------------------------------===// |
| 2076 | |
| 2077 | //===--------------------------------------------------------------------------- |
| 2078 | /// BranchInst - Conditional or Unconditional Branch instruction. |
| 2079 | /// |
| 2080 | class BranchInst : public TerminatorInst { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2081 | /// Ops list - Branches are strange. The operands are ordered: |
| 2082 | /// TrueDest, FalseDest, Cond. This makes some accessors faster because |
| 2083 | /// they don't have to check for cond/uncond branchness. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2084 | BranchInst(const BranchInst &BI); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2085 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2086 | // BranchInst constructors (where {B, T, F} are blocks, and C is a condition): |
| 2087 | // BranchInst(BB *B) - 'br B' |
| 2088 | // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F' |
| 2089 | // BranchInst(BB* B, Inst *I) - 'br B' insert before I |
| 2090 | // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I |
| 2091 | // BranchInst(BB* B, BB *I) - 'br B' insert at end |
| 2092 | // 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] | 2093 | explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2094 | BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2095 | Instruction *InsertBefore = 0); |
| 2096 | BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd); |
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 | BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2099 | public: |
| 2100 | static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) { |
| 2101 | return new(1) BranchInst(IfTrue, InsertBefore); |
| 2102 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2103 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, |
| 2104 | Value *Cond, Instruction *InsertBefore = 0) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2105 | return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore); |
| 2106 | } |
| 2107 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) { |
| 2108 | return new(1) BranchInst(IfTrue, InsertAtEnd); |
| 2109 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2110 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, |
| 2111 | Value *Cond, BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2112 | return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd); |
| 2113 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2114 | |
Bill Wendling | d2a5a2a | 2008-05-10 10:58:07 +0000 | [diff] [blame] | 2115 | ~BranchInst() { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2116 | if (NumOperands == 1) |
Bill Wendling | c2e7353 | 2008-05-10 19:59:59 +0000 | [diff] [blame] | 2117 | NumOperands = (unsigned)((Use*)this - OperandList); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2118 | } |
| 2119 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2120 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2121 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2122 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 2123 | virtual BranchInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2124 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2125 | bool isUnconditional() const { return getNumOperands() == 1; } |
| 2126 | bool isConditional() const { return getNumOperands() == 3; } |
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 | Value *getCondition() const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2129 | assert(isConditional() && "Cannot get condition of an uncond branch!"); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2130 | return getOperand(2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | void setCondition(Value *V) { |
| 2134 | assert(isConditional() && "Cannot set condition of unconditional branch!"); |
| 2135 | setOperand(2, V); |
| 2136 | } |
| 2137 | |
| 2138 | // setUnconditionalDest - Change the current branch to an unconditional branch |
| 2139 | // targeting the specified block. |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2140 | // FIXME: Eliminate this ugly method. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2141 | void setUnconditionalDest(BasicBlock *Dest) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2142 | Op<0>() = Dest; |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2143 | if (isConditional()) { // Convert this to an uncond branch. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2144 | Op<1>().set(0); |
| 2145 | Op<2>().set(0); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2146 | NumOperands = 1; |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2147 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2150 | unsigned getNumSuccessors() const { return 1+isConditional(); } |
| 2151 | |
| 2152 | BasicBlock *getSuccessor(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2153 | assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); |
Dan Gohman | b96039e | 2007-05-11 20:59:29 +0000 | [diff] [blame] | 2154 | return cast<BasicBlock>(getOperand(i)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2157 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2158 | assert(idx < getNumSuccessors() && "Successor # out of range for Branch!"); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2159 | setOperand(idx, NewSucc); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2160 | } |
| 2161 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2162 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2163 | static inline bool classof(const BranchInst *) { return true; } |
| 2164 | static inline bool classof(const Instruction *I) { |
| 2165 | return (I->getOpcode() == Instruction::Br); |
| 2166 | } |
| 2167 | static inline bool classof(const Value *V) { |
| 2168 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2169 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2170 | private: |
| 2171 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2172 | virtual unsigned getNumSuccessorsV() const; |
| 2173 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2174 | }; |
| 2175 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2176 | template <> |
| 2177 | struct OperandTraits<BranchInst> : HungoffOperandTraits<> { |
| 2178 | // we need to access operands via OperandList, since |
| 2179 | // the NumOperands may change from 3 to 1 |
| 2180 | static inline void *allocate(unsigned); // FIXME |
| 2181 | }; |
| 2182 | |
| 2183 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value) |
| 2184 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2185 | //===----------------------------------------------------------------------===// |
| 2186 | // SwitchInst Class |
| 2187 | //===----------------------------------------------------------------------===// |
| 2188 | |
| 2189 | //===--------------------------------------------------------------------------- |
| 2190 | /// SwitchInst - Multiway switch |
| 2191 | /// |
| 2192 | class SwitchInst : public TerminatorInst { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2193 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2194 | unsigned ReservedSpace; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2195 | // Operand[0] = Value to switch on |
| 2196 | // Operand[1] = Default basic block destination |
| 2197 | // Operand[2n ] = Value to match |
| 2198 | // Operand[2n+1] = BasicBlock to go to on match |
| 2199 | SwitchInst(const SwitchInst &RI); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2200 | void init(Value *Value, BasicBlock *Default, unsigned NumCases); |
| 2201 | void resizeOperands(unsigned No); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2202 | // allocate space for exactly zero operands |
| 2203 | void *operator new(size_t s) { |
| 2204 | return User::operator new(s, 0); |
| 2205 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2206 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to |
| 2207 | /// switch on and a default destination. The number of additional cases can |
| 2208 | /// be specified here to make memory allocation more efficient. This |
| 2209 | /// constructor can also autoinsert before another instruction. |
| 2210 | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2211 | Instruction *InsertBefore = 0); |
| 2212 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2213 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to |
| 2214 | /// switch on and a default destination. The number of additional cases can |
| 2215 | /// be specified here to make memory allocation more efficient. This |
| 2216 | /// constructor also autoinserts at the end of the specified BasicBlock. |
| 2217 | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2218 | BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2219 | public: |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2220 | static SwitchInst *Create(Value *Value, BasicBlock *Default, |
| 2221 | unsigned NumCases, Instruction *InsertBefore = 0) { |
| 2222 | return new SwitchInst(Value, Default, NumCases, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2223 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2224 | static SwitchInst *Create(Value *Value, BasicBlock *Default, |
| 2225 | unsigned NumCases, BasicBlock *InsertAtEnd) { |
| 2226 | return new SwitchInst(Value, Default, NumCases, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2227 | } |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 2228 | ~SwitchInst(); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2229 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2230 | /// Provide fast operand accessors |
| 2231 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 2232 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2233 | // Accessor Methods for Switch stmt |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2234 | Value *getCondition() const { return getOperand(0); } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2235 | void setCondition(Value *V) { setOperand(0, V); } |
Chris Lattner | bfaf88a | 2004-12-10 20:35:47 +0000 | [diff] [blame] | 2236 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2237 | BasicBlock *getDefaultDest() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2238 | return cast<BasicBlock>(getOperand(1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | /// getNumCases - return the number of 'cases' in this switch instruction. |
| 2242 | /// Note that case #0 is always the default case. |
| 2243 | unsigned getNumCases() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2244 | return getNumOperands()/2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | /// getCaseValue - Return the specified case value. Note that case #0, the |
| 2248 | /// default destination, does not have a case value. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2249 | ConstantInt *getCaseValue(unsigned i) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2250 | assert(i && i < getNumCases() && "Illegal case value to get!"); |
| 2251 | return getSuccessorValue(i); |
| 2252 | } |
| 2253 | |
| 2254 | /// getCaseValue - Return the specified case value. Note that case #0, the |
| 2255 | /// default destination, does not have a case value. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2256 | const ConstantInt *getCaseValue(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2257 | assert(i && i < getNumCases() && "Illegal case value to get!"); |
| 2258 | return getSuccessorValue(i); |
| 2259 | } |
| 2260 | |
| 2261 | /// findCaseValue - Search all of the case values for the specified constant. |
| 2262 | /// If it is explicitly handled, return the case number of it, otherwise |
| 2263 | /// return 0 to indicate that it is handled by the default handler. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2264 | unsigned findCaseValue(const ConstantInt *C) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2265 | for (unsigned i = 1, e = getNumCases(); i != e; ++i) |
| 2266 | if (getCaseValue(i) == C) |
| 2267 | return i; |
| 2268 | return 0; |
| 2269 | } |
| 2270 | |
Nick Lewycky | 011f184 | 2006-09-18 19:03:59 +0000 | [diff] [blame] | 2271 | /// findCaseDest - Finds the unique case value for a given successor. Returns |
| 2272 | /// null if the successor is not found, not unique, or is the default case. |
| 2273 | ConstantInt *findCaseDest(BasicBlock *BB) { |
Nick Lewycky | d791544 | 2006-09-18 20:44:37 +0000 | [diff] [blame] | 2274 | if (BB == getDefaultDest()) return NULL; |
| 2275 | |
Nick Lewycky | 011f184 | 2006-09-18 19:03:59 +0000 | [diff] [blame] | 2276 | ConstantInt *CI = NULL; |
| 2277 | for (unsigned i = 1, e = getNumCases(); i != e; ++i) { |
| 2278 | if (getSuccessor(i) == BB) { |
| 2279 | if (CI) return NULL; // Multiple cases lead to BB. |
| 2280 | else CI = getCaseValue(i); |
| 2281 | } |
| 2282 | } |
| 2283 | return CI; |
| 2284 | } |
| 2285 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2286 | /// addCase - Add an entry to the switch instruction... |
| 2287 | /// |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2288 | void addCase(ConstantInt *OnVal, BasicBlock *Dest); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2289 | |
| 2290 | /// removeCase - This method removes the specified successor from the switch |
| 2291 | /// instruction. Note that this cannot be used to remove the default |
| 2292 | /// destination (successor #0). |
| 2293 | /// |
| 2294 | void removeCase(unsigned idx); |
| 2295 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2296 | virtual SwitchInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2297 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2298 | unsigned getNumSuccessors() const { return getNumOperands()/2; } |
| 2299 | BasicBlock *getSuccessor(unsigned idx) const { |
| 2300 | assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!"); |
| 2301 | return cast<BasicBlock>(getOperand(idx*2+1)); |
| 2302 | } |
| 2303 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2304 | assert(idx < getNumSuccessors() && "Successor # out of range for switch!"); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2305 | setOperand(idx*2+1, NewSucc); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | // getSuccessorValue - Return the value associated with the specified |
| 2309 | // successor. |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2310 | ConstantInt *getSuccessorValue(unsigned idx) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2311 | assert(idx < getNumSuccessors() && "Successor # out of range!"); |
Reid Spencer | edd5d9e | 2005-05-15 16:13:11 +0000 | [diff] [blame] | 2312 | return reinterpret_cast<ConstantInt*>(getOperand(idx*2)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2313 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2314 | |
| 2315 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2316 | static inline bool classof(const SwitchInst *) { return true; } |
| 2317 | static inline bool classof(const Instruction *I) { |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2318 | return I->getOpcode() == Instruction::Switch; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2319 | } |
| 2320 | static inline bool classof(const Value *V) { |
| 2321 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2322 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2323 | private: |
| 2324 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2325 | virtual unsigned getNumSuccessorsV() const; |
| 2326 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2327 | }; |
| 2328 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2329 | template <> |
| 2330 | struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> { |
| 2331 | }; |
| 2332 | |
| 2333 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value) |
| 2334 | |
| 2335 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2336 | //===----------------------------------------------------------------------===// |
| 2337 | // InvokeInst Class |
| 2338 | //===----------------------------------------------------------------------===// |
| 2339 | |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 2340 | /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the |
| 2341 | /// calling convention of the call. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2342 | /// |
| 2343 | class InvokeInst : public TerminatorInst { |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 2344 | PAListPtr ParamAttrs; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2345 | InvokeInst(const InvokeInst &BI); |
| 2346 | void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, |
Chris Lattner | d2dd150 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 2347 | Value* const *Args, unsigned NumArgs); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2348 | |
| 2349 | template<typename InputIterator> |
| 2350 | void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
| 2351 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2352 | const std::string &Name, |
| 2353 | // This argument ensures that we have an iterator we can |
| 2354 | // do arithmetic on in constant time |
| 2355 | std::random_access_iterator_tag) { |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 2356 | unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2357 | |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 2358 | // This requires that the iterator points to contiguous memory. |
| 2359 | init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2360 | setName(Name); |
| 2361 | } |
| 2362 | |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2363 | /// Construct an InvokeInst given a range of arguments. |
| 2364 | /// InputIterator must be a random-access iterator pointing to |
| 2365 | /// contiguous storage (e.g. a std::vector<>::iterator). Checks are |
| 2366 | /// made for random-accessness but not for contiguous storage as |
| 2367 | /// that would incur runtime overhead. |
| 2368 | /// |
| 2369 | /// @brief Construct an InvokeInst from a range of arguments |
| 2370 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2371 | inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
| 2372 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2373 | unsigned Values, |
| 2374 | const std::string &Name, Instruction *InsertBefore); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2375 | |
| 2376 | /// Construct an InvokeInst given a range of arguments. |
| 2377 | /// InputIterator must be a random-access iterator pointing to |
| 2378 | /// contiguous storage (e.g. a std::vector<>::iterator). Checks are |
| 2379 | /// made for random-accessness but not for contiguous storage as |
| 2380 | /// that would incur runtime overhead. |
| 2381 | /// |
| 2382 | /// @brief Construct an InvokeInst from a range of arguments |
| 2383 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2384 | inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
| 2385 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2386 | unsigned Values, |
| 2387 | const std::string &Name, BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2388 | public: |
| 2389 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2390 | static InvokeInst *Create(Value *Func, |
| 2391 | BasicBlock *IfNormal, BasicBlock *IfException, |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2392 | InputIterator ArgBegin, InputIterator ArgEnd, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 2393 | const std::string &Name = "", |
| 2394 | Instruction *InsertBefore = 0) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2395 | unsigned Values(ArgEnd - ArgBegin + 3); |
| 2396 | return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, |
| 2397 | Values, Name, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2398 | } |
| 2399 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2400 | static InvokeInst *Create(Value *Func, |
| 2401 | BasicBlock *IfNormal, BasicBlock *IfException, |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2402 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2403 | const std::string &Name, BasicBlock *InsertAtEnd) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2404 | unsigned Values(ArgEnd - ArgBegin + 3); |
| 2405 | return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, |
| 2406 | Values, Name, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2407 | } |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2408 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 2409 | virtual InvokeInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2410 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2411 | /// Provide fast operand accessors |
| 2412 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 2413 | |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 2414 | /// getCallingConv/setCallingConv - Get or set the calling convention of this |
| 2415 | /// function call. |
| 2416 | unsigned getCallingConv() const { return SubclassData; } |
| 2417 | void setCallingConv(unsigned CC) { |
| 2418 | SubclassData = CC; |
| 2419 | } |
| 2420 | |
Chris Lattner | 041221c | 2008-03-13 04:33:03 +0000 | [diff] [blame] | 2421 | /// getParamAttrs - Return the parameter attributes for this invoke. |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 2422 | /// |
| 2423 | const PAListPtr &getParamAttrs() const { return ParamAttrs; } |
Reid Spencer | fa3e912 | 2007-04-09 18:00:57 +0000 | [diff] [blame] | 2424 | |
Chris Lattner | 041221c | 2008-03-13 04:33:03 +0000 | [diff] [blame] | 2425 | /// setParamAttrs - Set the parameter attributes for this invoke. |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 2426 | /// |
| 2427 | void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; } |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 2428 | |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 2429 | /// @brief Determine whether the call or the callee has the given attribute. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2430 | bool paramHasAttr(unsigned i, ParameterAttributes attr) const; |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 2431 | |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 2432 | /// @brief Extract the alignment for a call or parameter (0=unknown). |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2433 | unsigned getParamAlignment(unsigned i) const { |
| 2434 | return ParamAttrs.getParamAlignment(i); |
| 2435 | } |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 2436 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2437 | /// @brief Determine if the call does not access memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2438 | bool doesNotAccessMemory() const { |
| 2439 | return paramHasAttr(0, ParamAttr::ReadNone); |
| 2440 | } |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2441 | |
| 2442 | /// @brief Determine if the call does not access or only reads memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2443 | bool onlyReadsMemory() const { |
| 2444 | return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly); |
| 2445 | } |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2446 | |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 2447 | /// @brief Determine if the call cannot return. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2448 | bool doesNotReturn() const { |
| 2449 | return paramHasAttr(0, ParamAttr::NoReturn); |
| 2450 | } |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 2451 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2452 | /// @brief Determine if the call cannot unwind. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2453 | bool doesNotThrow() const { |
| 2454 | return paramHasAttr(0, ParamAttr::NoUnwind); |
| 2455 | } |
Duncan Sands | f0c3354 | 2007-12-19 21:13:37 +0000 | [diff] [blame] | 2456 | void setDoesNotThrow(bool doesNotThrow = true); |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2457 | |
Devang Patel | 41e2397 | 2008-03-03 21:46:28 +0000 | [diff] [blame] | 2458 | /// @brief Determine if the call returns a structure through first |
| 2459 | /// pointer argument. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2460 | bool hasStructRetAttr() const { |
| 2461 | // Be friendly and also check the callee. |
| 2462 | return paramHasAttr(1, ParamAttr::StructRet); |
| 2463 | } |
Reid Spencer | fa3e912 | 2007-04-09 18:00:57 +0000 | [diff] [blame] | 2464 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2465 | /// getCalledFunction - Return the function called, or null if this is an |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 2466 | /// indirect function invocation. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2467 | /// |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 2468 | Function *getCalledFunction() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2469 | return dyn_cast<Function>(getOperand(0)); |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 2470 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2471 | |
| 2472 | // 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] | 2473 | Value *getCalledValue() const { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2474 | |
| 2475 | // get*Dest - Return the destination basic blocks... |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2476 | BasicBlock *getNormalDest() const { |
| 2477 | return cast<BasicBlock>(getOperand(1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2478 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2479 | BasicBlock *getUnwindDest() const { |
| 2480 | return cast<BasicBlock>(getOperand(2)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2481 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2482 | void setNormalDest(BasicBlock *B) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2483 | setOperand(1, B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2484 | } |
| 2485 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2486 | void setUnwindDest(BasicBlock *B) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2487 | setOperand(2, B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2488 | } |
| 2489 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2490 | BasicBlock *getSuccessor(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2491 | assert(i < 2 && "Successor # out of range for invoke!"); |
| 2492 | return i == 0 ? getNormalDest() : getUnwindDest(); |
| 2493 | } |
| 2494 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2495 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2496 | assert(idx < 2 && "Successor # out of range for invoke!"); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2497 | setOperand(idx+1, NewSucc); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2498 | } |
| 2499 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2500 | unsigned getNumSuccessors() const { return 2; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2501 | |
| 2502 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2503 | static inline bool classof(const InvokeInst *) { return true; } |
| 2504 | static inline bool classof(const Instruction *I) { |
| 2505 | return (I->getOpcode() == Instruction::Invoke); |
| 2506 | } |
| 2507 | static inline bool classof(const Value *V) { |
| 2508 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2509 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2510 | private: |
| 2511 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2512 | virtual unsigned getNumSuccessorsV() const; |
| 2513 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2514 | }; |
| 2515 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2516 | template <> |
| 2517 | struct OperandTraits<InvokeInst> : VariadicOperandTraits<3> { |
| 2518 | }; |
| 2519 | |
| 2520 | template<typename InputIterator> |
| 2521 | InvokeInst::InvokeInst(Value *Func, |
| 2522 | BasicBlock *IfNormal, BasicBlock *IfException, |
| 2523 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2524 | unsigned Values, |
| 2525 | const std::string &Name, Instruction *InsertBefore) |
| 2526 | : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 2527 | ->getElementType())->getReturnType(), |
| 2528 | Instruction::Invoke, |
| 2529 | OperandTraits<InvokeInst>::op_end(this) - Values, |
| 2530 | Values, InsertBefore) { |
| 2531 | init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, |
| 2532 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 2533 | } |
| 2534 | template<typename InputIterator> |
| 2535 | InvokeInst::InvokeInst(Value *Func, |
| 2536 | BasicBlock *IfNormal, BasicBlock *IfException, |
| 2537 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2538 | unsigned Values, |
| 2539 | const std::string &Name, BasicBlock *InsertAtEnd) |
| 2540 | : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 2541 | ->getElementType())->getReturnType(), |
| 2542 | Instruction::Invoke, |
| 2543 | OperandTraits<InvokeInst>::op_end(this) - Values, |
| 2544 | Values, InsertAtEnd) { |
| 2545 | init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, |
| 2546 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 2547 | } |
| 2548 | |
| 2549 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value) |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2550 | |
| 2551 | //===----------------------------------------------------------------------===// |
| 2552 | // UnwindInst Class |
| 2553 | //===----------------------------------------------------------------------===// |
| 2554 | |
| 2555 | //===--------------------------------------------------------------------------- |
| 2556 | /// UnwindInst - Immediately exit the current function, unwinding the stack |
| 2557 | /// until an invoke instruction is found. |
| 2558 | /// |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2559 | class UnwindInst : public TerminatorInst { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2560 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2561 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2562 | // allocate space for exactly zero operands |
| 2563 | void *operator new(size_t s) { |
| 2564 | return User::operator new(s, 0); |
| 2565 | } |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2566 | explicit UnwindInst(Instruction *InsertBefore = 0); |
| 2567 | explicit UnwindInst(BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2568 | |
Chris Lattner | f319e83 | 2004-10-15 23:52:05 +0000 | [diff] [blame] | 2569 | virtual UnwindInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2570 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2571 | unsigned getNumSuccessors() const { return 0; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2572 | |
| 2573 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2574 | static inline bool classof(const UnwindInst *) { return true; } |
| 2575 | static inline bool classof(const Instruction *I) { |
| 2576 | return I->getOpcode() == Instruction::Unwind; |
| 2577 | } |
| 2578 | static inline bool classof(const Value *V) { |
| 2579 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2580 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2581 | private: |
| 2582 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2583 | virtual unsigned getNumSuccessorsV() const; |
| 2584 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2585 | }; |
| 2586 | |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2587 | //===----------------------------------------------------------------------===// |
| 2588 | // UnreachableInst Class |
| 2589 | //===----------------------------------------------------------------------===// |
| 2590 | |
| 2591 | //===--------------------------------------------------------------------------- |
| 2592 | /// UnreachableInst - This function has undefined behavior. In particular, the |
| 2593 | /// presence of this instruction indicates some higher level knowledge that the |
| 2594 | /// end of the block cannot be reached. |
| 2595 | /// |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2596 | class UnreachableInst : public TerminatorInst { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2597 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2598 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2599 | // allocate space for exactly zero operands |
| 2600 | void *operator new(size_t s) { |
| 2601 | return User::operator new(s, 0); |
| 2602 | } |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2603 | explicit UnreachableInst(Instruction *InsertBefore = 0); |
| 2604 | explicit UnreachableInst(BasicBlock *InsertAtEnd); |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2605 | |
| 2606 | virtual UnreachableInst *clone() const; |
| 2607 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2608 | unsigned getNumSuccessors() const { return 0; } |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2609 | |
| 2610 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2611 | static inline bool classof(const UnreachableInst *) { return true; } |
| 2612 | static inline bool classof(const Instruction *I) { |
| 2613 | return I->getOpcode() == Instruction::Unreachable; |
| 2614 | } |
| 2615 | static inline bool classof(const Value *V) { |
| 2616 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2617 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2618 | private: |
| 2619 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2620 | virtual unsigned getNumSuccessorsV() const; |
| 2621 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2622 | }; |
| 2623 | |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2624 | //===----------------------------------------------------------------------===// |
| 2625 | // TruncInst Class |
| 2626 | //===----------------------------------------------------------------------===// |
| 2627 | |
| 2628 | /// @brief This class represents a truncation of integer types. |
| 2629 | class TruncInst : public CastInst { |
| 2630 | /// Private copy constructor |
| 2631 | TruncInst(const TruncInst &CI) |
| 2632 | : CastInst(CI.getType(), Trunc, CI.getOperand(0)) { |
| 2633 | } |
| 2634 | public: |
| 2635 | /// @brief Constructor with insert-before-instruction semantics |
| 2636 | TruncInst( |
| 2637 | Value *S, ///< The value to be truncated |
| 2638 | const Type *Ty, ///< The (smaller) type to truncate to |
| 2639 | const std::string &Name = "", ///< A name for the new instruction |
| 2640 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2641 | ); |
| 2642 | |
| 2643 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2644 | TruncInst( |
| 2645 | Value *S, ///< The value to be truncated |
| 2646 | const Type *Ty, ///< The (smaller) type to truncate to |
| 2647 | const std::string &Name, ///< A name for the new instruction |
| 2648 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2649 | ); |
| 2650 | |
| 2651 | /// @brief Clone an identical TruncInst |
| 2652 | virtual CastInst *clone() const; |
| 2653 | |
| 2654 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2655 | static inline bool classof(const TruncInst *) { return true; } |
| 2656 | static inline bool classof(const Instruction *I) { |
| 2657 | return I->getOpcode() == Trunc; |
| 2658 | } |
| 2659 | static inline bool classof(const Value *V) { |
| 2660 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2661 | } |
| 2662 | }; |
| 2663 | |
| 2664 | //===----------------------------------------------------------------------===// |
| 2665 | // ZExtInst Class |
| 2666 | //===----------------------------------------------------------------------===// |
| 2667 | |
| 2668 | /// @brief This class represents zero extension of integer types. |
| 2669 | class ZExtInst : public CastInst { |
| 2670 | /// @brief Private copy constructor |
| 2671 | ZExtInst(const ZExtInst &CI) |
| 2672 | : CastInst(CI.getType(), ZExt, CI.getOperand(0)) { |
| 2673 | } |
| 2674 | public: |
| 2675 | /// @brief Constructor with insert-before-instruction semantics |
| 2676 | ZExtInst( |
| 2677 | Value *S, ///< The value to be zero extended |
| 2678 | const Type *Ty, ///< The type to zero extend to |
| 2679 | const std::string &Name = "", ///< A name for the new instruction |
| 2680 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2681 | ); |
| 2682 | |
| 2683 | /// @brief Constructor with insert-at-end semantics. |
| 2684 | ZExtInst( |
| 2685 | Value *S, ///< The value to be zero extended |
| 2686 | const Type *Ty, ///< The type to zero extend to |
| 2687 | const std::string &Name, ///< A name for the new instruction |
| 2688 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2689 | ); |
| 2690 | |
| 2691 | /// @brief Clone an identical ZExtInst |
| 2692 | virtual CastInst *clone() const; |
| 2693 | |
| 2694 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2695 | static inline bool classof(const ZExtInst *) { return true; } |
| 2696 | static inline bool classof(const Instruction *I) { |
| 2697 | return I->getOpcode() == ZExt; |
| 2698 | } |
| 2699 | static inline bool classof(const Value *V) { |
| 2700 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2701 | } |
| 2702 | }; |
| 2703 | |
| 2704 | //===----------------------------------------------------------------------===// |
| 2705 | // SExtInst Class |
| 2706 | //===----------------------------------------------------------------------===// |
| 2707 | |
| 2708 | /// @brief This class represents a sign extension of integer types. |
| 2709 | class SExtInst : public CastInst { |
| 2710 | /// @brief Private copy constructor |
| 2711 | SExtInst(const SExtInst &CI) |
| 2712 | : CastInst(CI.getType(), SExt, CI.getOperand(0)) { |
| 2713 | } |
| 2714 | public: |
| 2715 | /// @brief Constructor with insert-before-instruction semantics |
| 2716 | SExtInst( |
| 2717 | Value *S, ///< The value to be sign extended |
| 2718 | const Type *Ty, ///< The type to sign extend to |
| 2719 | const std::string &Name = "", ///< A name for the new instruction |
| 2720 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2721 | ); |
| 2722 | |
| 2723 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2724 | SExtInst( |
| 2725 | Value *S, ///< The value to be sign extended |
| 2726 | const Type *Ty, ///< The type to sign extend to |
| 2727 | const std::string &Name, ///< A name for the new instruction |
| 2728 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2729 | ); |
| 2730 | |
| 2731 | /// @brief Clone an identical SExtInst |
| 2732 | virtual CastInst *clone() const; |
| 2733 | |
| 2734 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2735 | static inline bool classof(const SExtInst *) { return true; } |
| 2736 | static inline bool classof(const Instruction *I) { |
| 2737 | return I->getOpcode() == SExt; |
| 2738 | } |
| 2739 | static inline bool classof(const Value *V) { |
| 2740 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2741 | } |
| 2742 | }; |
| 2743 | |
| 2744 | //===----------------------------------------------------------------------===// |
| 2745 | // FPTruncInst Class |
| 2746 | //===----------------------------------------------------------------------===// |
| 2747 | |
| 2748 | /// @brief This class represents a truncation of floating point types. |
| 2749 | class FPTruncInst : public CastInst { |
| 2750 | FPTruncInst(const FPTruncInst &CI) |
| 2751 | : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) { |
| 2752 | } |
| 2753 | public: |
| 2754 | /// @brief Constructor with insert-before-instruction semantics |
| 2755 | FPTruncInst( |
| 2756 | Value *S, ///< The value to be truncated |
| 2757 | const Type *Ty, ///< The type to truncate to |
| 2758 | const std::string &Name = "", ///< A name for the new instruction |
| 2759 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2760 | ); |
| 2761 | |
| 2762 | /// @brief Constructor with insert-before-instruction semantics |
| 2763 | FPTruncInst( |
| 2764 | Value *S, ///< The value to be truncated |
| 2765 | const Type *Ty, ///< The type to truncate to |
| 2766 | const std::string &Name, ///< A name for the new instruction |
| 2767 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2768 | ); |
| 2769 | |
| 2770 | /// @brief Clone an identical FPTruncInst |
| 2771 | virtual CastInst *clone() const; |
| 2772 | |
| 2773 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2774 | static inline bool classof(const FPTruncInst *) { return true; } |
| 2775 | static inline bool classof(const Instruction *I) { |
| 2776 | return I->getOpcode() == FPTrunc; |
| 2777 | } |
| 2778 | static inline bool classof(const Value *V) { |
| 2779 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2780 | } |
| 2781 | }; |
| 2782 | |
| 2783 | //===----------------------------------------------------------------------===// |
| 2784 | // FPExtInst Class |
| 2785 | //===----------------------------------------------------------------------===// |
| 2786 | |
| 2787 | /// @brief This class represents an extension of floating point types. |
| 2788 | class FPExtInst : public CastInst { |
| 2789 | FPExtInst(const FPExtInst &CI) |
| 2790 | : CastInst(CI.getType(), FPExt, CI.getOperand(0)) { |
| 2791 | } |
| 2792 | public: |
| 2793 | /// @brief Constructor with insert-before-instruction semantics |
| 2794 | FPExtInst( |
| 2795 | Value *S, ///< The value to be extended |
| 2796 | const Type *Ty, ///< The type to extend to |
| 2797 | const std::string &Name = "", ///< A name for the new instruction |
| 2798 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2799 | ); |
| 2800 | |
| 2801 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2802 | FPExtInst( |
| 2803 | Value *S, ///< The value to be extended |
| 2804 | const Type *Ty, ///< The type to extend to |
| 2805 | const std::string &Name, ///< A name for the new instruction |
| 2806 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2807 | ); |
| 2808 | |
| 2809 | /// @brief Clone an identical FPExtInst |
| 2810 | virtual CastInst *clone() const; |
| 2811 | |
| 2812 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2813 | static inline bool classof(const FPExtInst *) { return true; } |
| 2814 | static inline bool classof(const Instruction *I) { |
| 2815 | return I->getOpcode() == FPExt; |
| 2816 | } |
| 2817 | static inline bool classof(const Value *V) { |
| 2818 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2819 | } |
| 2820 | }; |
| 2821 | |
| 2822 | //===----------------------------------------------------------------------===// |
| 2823 | // UIToFPInst Class |
| 2824 | //===----------------------------------------------------------------------===// |
| 2825 | |
| 2826 | /// @brief This class represents a cast unsigned integer to floating point. |
| 2827 | class UIToFPInst : public CastInst { |
| 2828 | UIToFPInst(const UIToFPInst &CI) |
| 2829 | : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) { |
| 2830 | } |
| 2831 | public: |
| 2832 | /// @brief Constructor with insert-before-instruction semantics |
| 2833 | UIToFPInst( |
| 2834 | Value *S, ///< The value to be converted |
| 2835 | const Type *Ty, ///< The type to convert to |
| 2836 | const std::string &Name = "", ///< A name for the new instruction |
| 2837 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2838 | ); |
| 2839 | |
| 2840 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2841 | UIToFPInst( |
| 2842 | Value *S, ///< The value to be converted |
| 2843 | const Type *Ty, ///< The type to convert to |
| 2844 | const std::string &Name, ///< A name for the new instruction |
| 2845 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2846 | ); |
| 2847 | |
| 2848 | /// @brief Clone an identical UIToFPInst |
| 2849 | virtual CastInst *clone() const; |
| 2850 | |
| 2851 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2852 | static inline bool classof(const UIToFPInst *) { return true; } |
| 2853 | static inline bool classof(const Instruction *I) { |
| 2854 | return I->getOpcode() == UIToFP; |
| 2855 | } |
| 2856 | static inline bool classof(const Value *V) { |
| 2857 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2858 | } |
| 2859 | }; |
| 2860 | |
| 2861 | //===----------------------------------------------------------------------===// |
| 2862 | // SIToFPInst Class |
| 2863 | //===----------------------------------------------------------------------===// |
| 2864 | |
| 2865 | /// @brief This class represents a cast from signed integer to floating point. |
| 2866 | class SIToFPInst : public CastInst { |
| 2867 | SIToFPInst(const SIToFPInst &CI) |
| 2868 | : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) { |
| 2869 | } |
| 2870 | public: |
| 2871 | /// @brief Constructor with insert-before-instruction semantics |
| 2872 | SIToFPInst( |
| 2873 | Value *S, ///< The value to be converted |
| 2874 | const Type *Ty, ///< The type to convert to |
| 2875 | const std::string &Name = "", ///< A name for the new instruction |
| 2876 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2877 | ); |
| 2878 | |
| 2879 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2880 | SIToFPInst( |
| 2881 | Value *S, ///< The value to be converted |
| 2882 | const Type *Ty, ///< The type to convert to |
| 2883 | const std::string &Name, ///< A name for the new instruction |
| 2884 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2885 | ); |
| 2886 | |
| 2887 | /// @brief Clone an identical SIToFPInst |
| 2888 | virtual CastInst *clone() const; |
| 2889 | |
| 2890 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2891 | static inline bool classof(const SIToFPInst *) { return true; } |
| 2892 | static inline bool classof(const Instruction *I) { |
| 2893 | return I->getOpcode() == SIToFP; |
| 2894 | } |
| 2895 | static inline bool classof(const Value *V) { |
| 2896 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2897 | } |
| 2898 | }; |
| 2899 | |
| 2900 | //===----------------------------------------------------------------------===// |
| 2901 | // FPToUIInst Class |
| 2902 | //===----------------------------------------------------------------------===// |
| 2903 | |
| 2904 | /// @brief This class represents a cast from floating point to unsigned integer |
| 2905 | class FPToUIInst : public CastInst { |
| 2906 | FPToUIInst(const FPToUIInst &CI) |
| 2907 | : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) { |
| 2908 | } |
| 2909 | public: |
| 2910 | /// @brief Constructor with insert-before-instruction semantics |
| 2911 | FPToUIInst( |
| 2912 | Value *S, ///< The value to be converted |
| 2913 | const Type *Ty, ///< The type to convert to |
| 2914 | const std::string &Name = "", ///< A name for the new instruction |
| 2915 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2916 | ); |
| 2917 | |
| 2918 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2919 | FPToUIInst( |
| 2920 | Value *S, ///< The value to be converted |
| 2921 | const Type *Ty, ///< The type to convert to |
| 2922 | const std::string &Name, ///< A name for the new instruction |
| 2923 | BasicBlock *InsertAtEnd ///< Where to insert the new instruction |
| 2924 | ); |
| 2925 | |
| 2926 | /// @brief Clone an identical FPToUIInst |
| 2927 | virtual CastInst *clone() const; |
| 2928 | |
| 2929 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2930 | static inline bool classof(const FPToUIInst *) { return true; } |
| 2931 | static inline bool classof(const Instruction *I) { |
| 2932 | return I->getOpcode() == FPToUI; |
| 2933 | } |
| 2934 | static inline bool classof(const Value *V) { |
| 2935 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2936 | } |
| 2937 | }; |
| 2938 | |
| 2939 | //===----------------------------------------------------------------------===// |
| 2940 | // FPToSIInst Class |
| 2941 | //===----------------------------------------------------------------------===// |
| 2942 | |
| 2943 | /// @brief This class represents a cast from floating point to signed integer. |
| 2944 | class FPToSIInst : public CastInst { |
| 2945 | FPToSIInst(const FPToSIInst &CI) |
| 2946 | : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) { |
| 2947 | } |
| 2948 | public: |
| 2949 | /// @brief Constructor with insert-before-instruction semantics |
| 2950 | FPToSIInst( |
| 2951 | Value *S, ///< The value to be converted |
| 2952 | const Type *Ty, ///< The type to convert to |
| 2953 | const std::string &Name = "", ///< A name for the new instruction |
| 2954 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2955 | ); |
| 2956 | |
| 2957 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2958 | FPToSIInst( |
| 2959 | Value *S, ///< The value to be converted |
| 2960 | const Type *Ty, ///< The type to convert to |
| 2961 | const std::string &Name, ///< A name for the new instruction |
| 2962 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2963 | ); |
| 2964 | |
| 2965 | /// @brief Clone an identical FPToSIInst |
| 2966 | virtual CastInst *clone() const; |
| 2967 | |
| 2968 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2969 | static inline bool classof(const FPToSIInst *) { return true; } |
| 2970 | static inline bool classof(const Instruction *I) { |
| 2971 | return I->getOpcode() == FPToSI; |
| 2972 | } |
| 2973 | static inline bool classof(const Value *V) { |
| 2974 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2975 | } |
| 2976 | }; |
| 2977 | |
| 2978 | //===----------------------------------------------------------------------===// |
| 2979 | // IntToPtrInst Class |
| 2980 | //===----------------------------------------------------------------------===// |
| 2981 | |
| 2982 | /// @brief This class represents a cast from an integer to a pointer. |
| 2983 | class IntToPtrInst : public CastInst { |
| 2984 | IntToPtrInst(const IntToPtrInst &CI) |
| 2985 | : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) { |
| 2986 | } |
| 2987 | public: |
| 2988 | /// @brief Constructor with insert-before-instruction semantics |
| 2989 | IntToPtrInst( |
| 2990 | Value *S, ///< The value to be converted |
| 2991 | const Type *Ty, ///< The type to convert to |
| 2992 | const std::string &Name = "", ///< A name for the new instruction |
| 2993 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2994 | ); |
| 2995 | |
| 2996 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2997 | IntToPtrInst( |
| 2998 | Value *S, ///< The value to be converted |
| 2999 | const Type *Ty, ///< The type to convert to |
| 3000 | const std::string &Name, ///< A name for the new instruction |
| 3001 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 3002 | ); |
| 3003 | |
| 3004 | /// @brief Clone an identical IntToPtrInst |
| 3005 | virtual CastInst *clone() const; |
| 3006 | |
| 3007 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 3008 | static inline bool classof(const IntToPtrInst *) { return true; } |
| 3009 | static inline bool classof(const Instruction *I) { |
| 3010 | return I->getOpcode() == IntToPtr; |
| 3011 | } |
| 3012 | static inline bool classof(const Value *V) { |
| 3013 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 3014 | } |
| 3015 | }; |
| 3016 | |
| 3017 | //===----------------------------------------------------------------------===// |
| 3018 | // PtrToIntInst Class |
| 3019 | //===----------------------------------------------------------------------===// |
| 3020 | |
| 3021 | /// @brief This class represents a cast from a pointer to an integer |
| 3022 | class PtrToIntInst : public CastInst { |
| 3023 | PtrToIntInst(const PtrToIntInst &CI) |
| 3024 | : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) { |
| 3025 | } |
| 3026 | public: |
| 3027 | /// @brief Constructor with insert-before-instruction semantics |
| 3028 | PtrToIntInst( |
| 3029 | Value *S, ///< The value to be converted |
| 3030 | const Type *Ty, ///< The type to convert to |
| 3031 | const std::string &Name = "", ///< A name for the new instruction |
| 3032 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 3033 | ); |
| 3034 | |
| 3035 | /// @brief Constructor with insert-at-end-of-block semantics |
| 3036 | PtrToIntInst( |
| 3037 | Value *S, ///< The value to be converted |
| 3038 | const Type *Ty, ///< The type to convert to |
| 3039 | const std::string &Name, ///< A name for the new instruction |
| 3040 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 3041 | ); |
| 3042 | |
| 3043 | /// @brief Clone an identical PtrToIntInst |
| 3044 | virtual CastInst *clone() const; |
| 3045 | |
| 3046 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 3047 | static inline bool classof(const PtrToIntInst *) { return true; } |
| 3048 | static inline bool classof(const Instruction *I) { |
| 3049 | return I->getOpcode() == PtrToInt; |
| 3050 | } |
| 3051 | static inline bool classof(const Value *V) { |
| 3052 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 3053 | } |
| 3054 | }; |
| 3055 | |
| 3056 | //===----------------------------------------------------------------------===// |
| 3057 | // BitCastInst Class |
| 3058 | //===----------------------------------------------------------------------===// |
| 3059 | |
| 3060 | /// @brief This class represents a no-op cast from one type to another. |
| 3061 | class BitCastInst : public CastInst { |
| 3062 | BitCastInst(const BitCastInst &CI) |
| 3063 | : CastInst(CI.getType(), BitCast, CI.getOperand(0)) { |
| 3064 | } |
| 3065 | public: |
| 3066 | /// @brief Constructor with insert-before-instruction semantics |
| 3067 | BitCastInst( |
| 3068 | Value *S, ///< The value to be casted |
| 3069 | const Type *Ty, ///< The type to casted to |
| 3070 | const std::string &Name = "", ///< A name for the new instruction |
| 3071 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 3072 | ); |
| 3073 | |
| 3074 | /// @brief Constructor with insert-at-end-of-block semantics |
| 3075 | BitCastInst( |
| 3076 | Value *S, ///< The value to be casted |
| 3077 | const Type *Ty, ///< The type to casted to |
| 3078 | const std::string &Name, ///< A name for the new instruction |
| 3079 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 3080 | ); |
| 3081 | |
| 3082 | /// @brief Clone an identical BitCastInst |
| 3083 | virtual CastInst *clone() const; |
| 3084 | |
| 3085 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 3086 | static inline bool classof(const BitCastInst *) { return true; } |
| 3087 | static inline bool classof(const Instruction *I) { |
| 3088 | return I->getOpcode() == BitCast; |
| 3089 | } |
| 3090 | static inline bool classof(const Value *V) { |
| 3091 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 3092 | } |
| 3093 | }; |
| 3094 | |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3095 | //===----------------------------------------------------------------------===// |
| 3096 | // GetResultInst Class |
| 3097 | //===----------------------------------------------------------------------===// |
| 3098 | |
| 3099 | /// GetResultInst - This instruction extracts individual result value from |
| 3100 | /// aggregate value, where aggregate value is returned by CallInst. |
| 3101 | /// |
Gabor Greif | d6a2218 | 2008-05-13 07:09:08 +0000 | [diff] [blame] | 3102 | class GetResultInst : public UnaryInstruction { |
Devang Patel | 23755d8 | 2008-02-20 19:10:47 +0000 | [diff] [blame] | 3103 | unsigned Idx; |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3104 | GetResultInst(const GetResultInst &GRI) : |
Gabor Greif | d6a2218 | 2008-05-13 07:09:08 +0000 | [diff] [blame] | 3105 | UnaryInstruction(GRI.getType(), Instruction::GetResult, GRI.getOperand(0)), |
| 3106 | Idx(GRI.Idx) { |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3107 | } |
| 3108 | |
| 3109 | public: |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 3110 | GetResultInst(Value *Aggr, unsigned index, |
| 3111 | const std::string &Name = "", |
| 3112 | Instruction *InsertBefore = 0); |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3113 | |
| 3114 | /// isValidOperands - Return true if an getresult instruction can be |
| 3115 | /// formed with the specified operands. |
Devang Patel | 23755d8 | 2008-02-20 19:10:47 +0000 | [diff] [blame] | 3116 | static bool isValidOperands(const Value *Aggr, unsigned index); |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3117 | |
| 3118 | virtual GetResultInst *clone() const; |
| 3119 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 3120 | Value *getAggregateValue() { |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3121 | return getOperand(0); |
| 3122 | } |
Devang Patel | 2d2ae34 | 2008-02-20 18:36:16 +0000 | [diff] [blame] | 3123 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 3124 | const Value *getAggregateValue() const { |
Devang Patel | 2d2ae34 | 2008-02-20 18:36:16 +0000 | [diff] [blame] | 3125 | return getOperand(0); |
| 3126 | } |
| 3127 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 3128 | unsigned getIndex() const { |
Devang Patel | 23755d8 | 2008-02-20 19:10:47 +0000 | [diff] [blame] | 3129 | return Idx; |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3130 | } |
| 3131 | |
Devang Patel | 40a0421 | 2008-02-19 22:15:16 +0000 | [diff] [blame] | 3132 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 3133 | static inline bool classof(const GetResultInst *) { return true; } |
| 3134 | static inline bool classof(const Instruction *I) { |
| 3135 | return (I->getOpcode() == Instruction::GetResult); |
| 3136 | } |
| 3137 | static inline bool classof(const Value *V) { |
| 3138 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 3139 | } |
| 3140 | }; |
| 3141 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 3142 | } // End llvm namespace |
Chris Lattner | a892a3a | 2003-01-27 22:08:52 +0000 | [diff] [blame] | 3143 | |
| 3144 | #endif |