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