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