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