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