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