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