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