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