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