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