LLVM API Documentation
00001 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file exposes the class definitions of all of the subclasses of the 00011 // Instruction class. This is meant to be an easy way to get access to all 00012 // instruction subclasses. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_INSTRUCTIONS_H 00017 #define LLVM_INSTRUCTIONS_H 00018 00019 #include "llvm/InstrTypes.h" 00020 #include "llvm/DerivedTypes.h" 00021 #include "llvm/Attributes.h" 00022 #include "llvm/BasicBlock.h" 00023 #include "llvm/LLVMContext.h" 00024 #include "llvm/ADT/SmallVector.h" 00025 #include <iterator> 00026 00027 namespace llvm { 00028 00029 class ConstantInt; 00030 class ConstantRange; 00031 class APInt; 00032 class LLVMContext; 00033 00034 //===----------------------------------------------------------------------===// 00035 // AllocationInst Class 00036 //===----------------------------------------------------------------------===// 00037 00038 /// AllocationInst - This class is the common base class of MallocInst and 00039 /// AllocaInst. 00040 /// 00041 class AllocationInst : public UnaryInstruction { 00042 protected: 00043 AllocationInst(const Type *Ty, Value *ArraySize, 00044 unsigned iTy, unsigned Align, const Twine &Name = "", 00045 Instruction *InsertBefore = 0); 00046 AllocationInst(const Type *Ty, Value *ArraySize, 00047 unsigned iTy, unsigned Align, const Twine &Name, 00048 BasicBlock *InsertAtEnd); 00049 public: 00050 // Out of line virtual method, so the vtable, etc. has a home. 00051 virtual ~AllocationInst(); 00052 00053 /// isArrayAllocation - Return true if there is an allocation size parameter 00054 /// to the allocation instruction that is not 1. 00055 /// 00056 bool isArrayAllocation() const; 00057 00058 /// getArraySize - Get the number of elements allocated. For a simple 00059 /// allocation of a single element, this will return a constant 1 value. 00060 /// 00061 const Value *getArraySize() const { return getOperand(0); } 00062 Value *getArraySize() { return getOperand(0); } 00063 00064 /// getType - Overload to return most specific pointer type 00065 /// 00066 const PointerType *getType() const { 00067 return reinterpret_cast<const PointerType*>(Instruction::getType()); 00068 } 00069 00070 /// getAllocatedType - Return the type that is being allocated by the 00071 /// instruction. 00072 /// 00073 const Type *getAllocatedType() const; 00074 00075 /// getAlignment - Return the alignment of the memory that is being allocated 00076 /// by the instruction. 00077 /// 00078 unsigned getAlignment() const { return (1u << SubclassData) >> 1; } 00079 void setAlignment(unsigned Align); 00080 00081 virtual Instruction *clone(LLVMContext &Context) const = 0; 00082 00083 // Methods for support type inquiry through isa, cast, and dyn_cast: 00084 static inline bool classof(const AllocationInst *) { return true; } 00085 static inline bool classof(const Instruction *I) { 00086 return I->getOpcode() == Instruction::Alloca || 00087 I->getOpcode() == Instruction::Malloc; 00088 } 00089 static inline bool classof(const Value *V) { 00090 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00091 } 00092 }; 00093 00094 00095 //===----------------------------------------------------------------------===// 00096 // MallocInst Class 00097 //===----------------------------------------------------------------------===// 00098 00099 /// MallocInst - an instruction to allocated memory on the heap 00100 /// 00101 class MallocInst : public AllocationInst { 00102 public: 00103 explicit MallocInst(const Type *Ty, Value *ArraySize = 0, 00104 const Twine &NameStr = "", 00105 Instruction *InsertBefore = 0) 00106 : AllocationInst(Ty, ArraySize, Malloc, 00107 0, NameStr, InsertBefore) {} 00108 MallocInst(const Type *Ty, Value *ArraySize, 00109 const Twine &NameStr, BasicBlock *InsertAtEnd) 00110 : AllocationInst(Ty, ArraySize, Malloc, 0, NameStr, InsertAtEnd) {} 00111 00112 MallocInst(const Type *Ty, const Twine &NameStr, 00113 Instruction *InsertBefore = 0) 00114 : AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertBefore) {} 00115 MallocInst(const Type *Ty, const Twine &NameStr, 00116 BasicBlock *InsertAtEnd) 00117 : AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertAtEnd) {} 00118 00119 MallocInst(const Type *Ty, Value *ArraySize, 00120 unsigned Align, const Twine &NameStr, 00121 BasicBlock *InsertAtEnd) 00122 : AllocationInst(Ty, ArraySize, Malloc, 00123 Align, NameStr, InsertAtEnd) {} 00124 MallocInst(const Type *Ty, Value *ArraySize, 00125 unsigned Align, const Twine &NameStr = "", 00126 Instruction *InsertBefore = 0) 00127 : AllocationInst(Ty, ArraySize, 00128 Malloc, Align, NameStr, InsertBefore) {} 00129 00130 virtual MallocInst *clone(LLVMContext &Context) const; 00131 00132 // Methods for support type inquiry through isa, cast, and dyn_cast: 00133 static inline bool classof(const MallocInst *) { return true; } 00134 static inline bool classof(const Instruction *I) { 00135 return (I->getOpcode() == Instruction::Malloc); 00136 } 00137 static inline bool classof(const Value *V) { 00138 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00139 } 00140 }; 00141 00142 00143 //===----------------------------------------------------------------------===// 00144 // AllocaInst Class 00145 //===----------------------------------------------------------------------===// 00146 00147 /// AllocaInst - an instruction to allocate memory on the stack 00148 /// 00149 class AllocaInst : public AllocationInst { 00150 public: 00151 explicit AllocaInst(const Type *Ty, 00152 Value *ArraySize = 0, 00153 const Twine &NameStr = "", 00154 Instruction *InsertBefore = 0) 00155 : AllocationInst(Ty, ArraySize, Alloca, 00156 0, NameStr, InsertBefore) {} 00157 AllocaInst(const Type *Ty, 00158 Value *ArraySize, const Twine &NameStr, 00159 BasicBlock *InsertAtEnd) 00160 : AllocationInst(Ty, ArraySize, Alloca, 0, NameStr, InsertAtEnd) {} 00161 00162 AllocaInst(const Type *Ty, const Twine &NameStr, 00163 Instruction *InsertBefore = 0) 00164 : AllocationInst(Ty, 0, Alloca, 0, NameStr, InsertBefore) {} 00165 AllocaInst(const Type *Ty, const Twine &NameStr, 00166 BasicBlock *InsertAtEnd) 00167 : AllocationInst(Ty, 0, Alloca, 0, NameStr, InsertAtEnd) {} 00168 00169 AllocaInst(const Type *Ty, Value *ArraySize, 00170 unsigned Align, const Twine &NameStr = "", 00171 Instruction *InsertBefore = 0) 00172 : AllocationInst(Ty, ArraySize, Alloca, 00173 Align, NameStr, InsertBefore) {} 00174 AllocaInst(const Type *Ty, Value *ArraySize, 00175 unsigned Align, const Twine &NameStr, 00176 BasicBlock *InsertAtEnd) 00177 : AllocationInst(Ty, ArraySize, Alloca, 00178 Align, NameStr, InsertAtEnd) {} 00179 00180 virtual AllocaInst *clone(LLVMContext &Context) const; 00181 00182 /// isStaticAlloca - Return true if this alloca is in the entry block of the 00183 /// function and is a constant size. If so, the code generator will fold it 00184 /// into the prolog/epilog code, so it is basically free. 00185 bool isStaticAlloca() const; 00186 00187 // Methods for support type inquiry through isa, cast, and dyn_cast: 00188 static inline bool classof(const AllocaInst *) { return true; } 00189 static inline bool classof(const Instruction *I) { 00190 return (I->getOpcode() == Instruction::Alloca); 00191 } 00192 static inline bool classof(const Value *V) { 00193 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00194 } 00195 }; 00196 00197 00198 //===----------------------------------------------------------------------===// 00199 // FreeInst Class 00200 //===----------------------------------------------------------------------===// 00201 00202 /// FreeInst - an instruction to deallocate memory 00203 /// 00204 class FreeInst : public UnaryInstruction { 00205 void AssertOK(); 00206 public: 00207 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0); 00208 FreeInst(Value *Ptr, BasicBlock *InsertAfter); 00209 00210 virtual FreeInst *clone(LLVMContext &Context) const; 00211 00212 // Accessor methods for consistency with other memory operations 00213 Value *getPointerOperand() { return getOperand(0); } 00214 const Value *getPointerOperand() const { return getOperand(0); } 00215 00216 // Methods for support type inquiry through isa, cast, and dyn_cast: 00217 static inline bool classof(const FreeInst *) { return true; } 00218 static inline bool classof(const Instruction *I) { 00219 return (I->getOpcode() == Instruction::Free); 00220 } 00221 static inline bool classof(const Value *V) { 00222 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00223 } 00224 }; 00225 00226 00227 //===----------------------------------------------------------------------===// 00228 // LoadInst Class 00229 //===----------------------------------------------------------------------===// 00230 00231 /// LoadInst - an instruction for reading from memory. This uses the 00232 /// SubclassData field in Value to store whether or not the load is volatile. 00233 /// 00234 class LoadInst : public UnaryInstruction { 00235 void AssertOK(); 00236 public: 00237 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore); 00238 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd); 00239 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false, 00240 Instruction *InsertBefore = 0); 00241 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, 00242 unsigned Align, Instruction *InsertBefore = 0); 00243 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, 00244 BasicBlock *InsertAtEnd); 00245 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, 00246 unsigned Align, BasicBlock *InsertAtEnd); 00247 00248 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore); 00249 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd); 00250 explicit LoadInst(Value *Ptr, const char *NameStr = 0, 00251 bool isVolatile = false, Instruction *InsertBefore = 0); 00252 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile, 00253 BasicBlock *InsertAtEnd); 00254 00255 /// isVolatile - Return true if this is a load from a volatile memory 00256 /// location. 00257 /// 00258 bool isVolatile() const { return SubclassData & 1; } 00259 00260 /// setVolatile - Specify whether this is a volatile load or not. 00261 /// 00262 void setVolatile(bool V) { 00263 SubclassData = (SubclassData & ~1) | (V ? 1 : 0); 00264 } 00265 00266 virtual LoadInst *clone(LLVMContext &Context) const; 00267 00268 /// getAlignment - Return the alignment of the access that is being performed 00269 /// 00270 unsigned getAlignment() const { 00271 return (1 << (SubclassData>>1)) >> 1; 00272 } 00273 00274 void setAlignment(unsigned Align); 00275 00276 Value *getPointerOperand() { return getOperand(0); } 00277 const Value *getPointerOperand() const { return getOperand(0); } 00278 static unsigned getPointerOperandIndex() { return 0U; } 00279 00280 // Methods for support type inquiry through isa, cast, and dyn_cast: 00281 static inline bool classof(const LoadInst *) { return true; } 00282 static inline bool classof(const Instruction *I) { 00283 return I->getOpcode() == Instruction::Load; 00284 } 00285 static inline bool classof(const Value *V) { 00286 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00287 } 00288 }; 00289 00290 00291 //===----------------------------------------------------------------------===// 00292 // StoreInst Class 00293 //===----------------------------------------------------------------------===// 00294 00295 /// StoreInst - an instruction for storing to memory 00296 /// 00297 class StoreInst : public Instruction { 00298 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 00299 void AssertOK(); 00300 public: 00301 // allocate space for exactly two operands 00302 void *operator new(size_t s) { 00303 return User::operator new(s, 2); 00304 } 00305 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore); 00306 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd); 00307 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false, 00308 Instruction *InsertBefore = 0); 00309 StoreInst(Value *Val, Value *Ptr, bool isVolatile, 00310 unsigned Align, Instruction *InsertBefore = 0); 00311 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd); 00312 StoreInst(Value *Val, Value *Ptr, bool isVolatile, 00313 unsigned Align, BasicBlock *InsertAtEnd); 00314 00315 00316 /// isVolatile - Return true if this is a load from a volatile memory 00317 /// location. 00318 /// 00319 bool isVolatile() const { return SubclassData & 1; } 00320 00321 /// setVolatile - Specify whether this is a volatile load or not. 00322 /// 00323 void setVolatile(bool V) { 00324 SubclassData = (SubclassData & ~1) | (V ? 1 : 0); 00325 } 00326 00327 /// Transparently provide more efficient getOperand methods. 00328 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 00329 00330 /// getAlignment - Return the alignment of the access that is being performed 00331 /// 00332 unsigned getAlignment() const { 00333 return (1 << (SubclassData>>1)) >> 1; 00334 } 00335 00336 void setAlignment(unsigned Align); 00337 00338 virtual StoreInst *clone(LLVMContext &Context) const; 00339 00340 Value *getPointerOperand() { return getOperand(1); } 00341 const Value *getPointerOperand() const { return getOperand(1); } 00342 static unsigned getPointerOperandIndex() { return 1U; } 00343 00344 // Methods for support type inquiry through isa, cast, and dyn_cast: 00345 static inline bool classof(const StoreInst *) { return true; } 00346 static inline bool classof(const Instruction *I) { 00347 return I->getOpcode() == Instruction::Store; 00348 } 00349 static inline bool classof(const Value *V) { 00350 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00351 } 00352 }; 00353 00354 template <> 00355 struct OperandTraits<StoreInst> : FixedNumOperandTraits<2> { 00356 }; 00357 00358 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value) 00359 00360 //===----------------------------------------------------------------------===// 00361 // GetElementPtrInst Class 00362 //===----------------------------------------------------------------------===// 00363 00364 // checkType - Simple wrapper function to give a better assertion failure 00365 // message on bad indexes for a gep instruction. 00366 // 00367 static inline const Type *checkType(const Type *Ty) { 00368 assert(Ty && "Invalid GetElementPtrInst indices for type!"); 00369 return Ty; 00370 } 00371 00372 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to 00373 /// access elements of arrays and structs 00374 /// 00375 class GetElementPtrInst : public Instruction { 00376 GetElementPtrInst(const GetElementPtrInst &GEPI); 00377 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx, 00378 const Twine &NameStr); 00379 void init(Value *Ptr, Value *Idx, const Twine &NameStr); 00380 00381 template<typename InputIterator> 00382 void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd, 00383 const Twine &NameStr, 00384 // This argument ensures that we have an iterator we can 00385 // do arithmetic on in constant time 00386 std::random_access_iterator_tag) { 00387 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); 00388 00389 if (NumIdx > 0) { 00390 // This requires that the iterator points to contiguous memory. 00391 init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case 00392 // we have to build an array here 00393 } 00394 else { 00395 init(Ptr, 0, NumIdx, NameStr); 00396 } 00397 } 00398 00399 /// getIndexedType - Returns the type of the element that would be loaded with 00400 /// a load instruction with the specified parameters. 00401 /// 00402 /// Null is returned if the indices are invalid for the specified 00403 /// pointer type. 00404 /// 00405 template<typename InputIterator> 00406 static const Type *getIndexedType(const Type *Ptr, 00407 InputIterator IdxBegin, 00408 InputIterator IdxEnd, 00409 // This argument ensures that we 00410 // have an iterator we can do 00411 // arithmetic on in constant time 00412 std::random_access_iterator_tag) { 00413 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); 00414 00415 if (NumIdx > 0) 00416 // This requires that the iterator points to contiguous memory. 00417 return getIndexedType(Ptr, &*IdxBegin, NumIdx); 00418 else 00419 return getIndexedType(Ptr, (Value *const*)0, NumIdx); 00420 } 00421 00422 /// Constructors - Create a getelementptr instruction with a base pointer an 00423 /// list of indices. The first ctor can optionally insert before an existing 00424 /// instruction, the second appends the new instruction to the specified 00425 /// BasicBlock. 00426 template<typename InputIterator> 00427 inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, 00428 InputIterator IdxEnd, 00429 unsigned Values, 00430 const Twine &NameStr, 00431 Instruction *InsertBefore); 00432 template<typename InputIterator> 00433 inline GetElementPtrInst(Value *Ptr, 00434 InputIterator IdxBegin, InputIterator IdxEnd, 00435 unsigned Values, 00436 const Twine &NameStr, BasicBlock *InsertAtEnd); 00437 00438 /// Constructors - These two constructors are convenience methods because one 00439 /// and two index getelementptr instructions are so common. 00440 GetElementPtrInst(Value *Ptr, Value *Idx, const Twine &NameStr = "", 00441 Instruction *InsertBefore = 0); 00442 GetElementPtrInst(Value *Ptr, Value *Idx, 00443 const Twine &NameStr, BasicBlock *InsertAtEnd); 00444 public: 00445 template<typename InputIterator> 00446 static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin, 00447 InputIterator IdxEnd, 00448 const Twine &NameStr = "", 00449 Instruction *InsertBefore = 0) { 00450 typename std::iterator_traits<InputIterator>::difference_type Values = 00451 1 + std::distance(IdxBegin, IdxEnd); 00452 return new(Values) 00453 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore); 00454 } 00455 template<typename InputIterator> 00456 static GetElementPtrInst *Create(Value *Ptr, 00457 InputIterator IdxBegin, InputIterator IdxEnd, 00458 const Twine &NameStr, 00459 BasicBlock *InsertAtEnd) { 00460 typename std::iterator_traits<InputIterator>::difference_type Values = 00461 1 + std::distance(IdxBegin, IdxEnd); 00462 return new(Values) 00463 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd); 00464 } 00465 00466 /// Constructors - These two creators are convenience methods because one 00467 /// index getelementptr instructions are so common. 00468 static GetElementPtrInst *Create(Value *Ptr, Value *Idx, 00469 const Twine &NameStr = "", 00470 Instruction *InsertBefore = 0) { 00471 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertBefore); 00472 } 00473 static GetElementPtrInst *Create(Value *Ptr, Value *Idx, 00474 const Twine &NameStr, 00475 BasicBlock *InsertAtEnd) { 00476 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd); 00477 } 00478 00479 /// Create an "inbounds" getelementptr. See the documentation for the 00480 /// "inbounds" flag in LangRef.html for details. 00481 template<typename InputIterator> 00482 static GetElementPtrInst *CreateInBounds(Value *Ptr, InputIterator IdxBegin, 00483 InputIterator IdxEnd, 00484 const Twine &NameStr = "", 00485 Instruction *InsertBefore = 0) { 00486 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd, 00487 NameStr, InsertBefore); 00488 cast<GEPOperator>(GEP)->setIsInBounds(true); 00489 return GEP; 00490 } 00491 template<typename InputIterator> 00492 static GetElementPtrInst *CreateInBounds(Value *Ptr, 00493 InputIterator IdxBegin, 00494 InputIterator IdxEnd, 00495 const Twine &NameStr, 00496 BasicBlock *InsertAtEnd) { 00497 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd, 00498 NameStr, InsertAtEnd); 00499 cast<GEPOperator>(GEP)->setIsInBounds(true); 00500 return GEP; 00501 } 00502 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx, 00503 const Twine &NameStr = "", 00504 Instruction *InsertBefore = 0) { 00505 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore); 00506 cast<GEPOperator>(GEP)->setIsInBounds(true); 00507 return GEP; 00508 } 00509 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx, 00510 const Twine &NameStr, 00511 BasicBlock *InsertAtEnd) { 00512 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd); 00513 cast<GEPOperator>(GEP)->setIsInBounds(true); 00514 return GEP; 00515 } 00516 00517 virtual GetElementPtrInst *clone(LLVMContext &Context) const; 00518 00519 /// Transparently provide more efficient getOperand methods. 00520 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 00521 00522 // getType - Overload to return most specific pointer type... 00523 const PointerType *getType() const { 00524 return reinterpret_cast<const PointerType*>(Instruction::getType()); 00525 } 00526 00527 /// getIndexedType - Returns the type of the element that would be loaded with 00528 /// a load instruction with the specified parameters. 00529 /// 00530 /// Null is returned if the indices are invalid for the specified 00531 /// pointer type. 00532 /// 00533 template<typename InputIterator> 00534 static const Type *getIndexedType(const Type *Ptr, 00535 InputIterator IdxBegin, 00536 InputIterator IdxEnd) { 00537 return getIndexedType(Ptr, IdxBegin, IdxEnd, 00538 typename std::iterator_traits<InputIterator>:: 00539 iterator_category()); 00540 } 00541 00542 static const Type *getIndexedType(const Type *Ptr, 00543 Value* const *Idx, unsigned NumIdx); 00544 00545 static const Type *getIndexedType(const Type *Ptr, 00546 uint64_t const *Idx, unsigned NumIdx); 00547 00548 static const Type *getIndexedType(const Type *Ptr, Value *Idx); 00549 00550 inline op_iterator idx_begin() { return op_begin()+1; } 00551 inline const_op_iterator idx_begin() const { return op_begin()+1; } 00552 inline op_iterator idx_end() { return op_end(); } 00553 inline const_op_iterator idx_end() const { return op_end(); } 00554 00555 Value *getPointerOperand() { 00556 return getOperand(0); 00557 } 00558 const Value *getPointerOperand() const { 00559 return getOperand(0); 00560 } 00561 static unsigned getPointerOperandIndex() { 00562 return 0U; // get index for modifying correct operand 00563 } 00564 00565 /// getPointerOperandType - Method to return the pointer operand as a 00566 /// PointerType. 00567 const PointerType *getPointerOperandType() const { 00568 return reinterpret_cast<const PointerType*>(getPointerOperand()->getType()); 00569 } 00570 00571 00572 unsigned getNumIndices() const { // Note: always non-negative 00573 return getNumOperands() - 1; 00574 } 00575 00576 bool hasIndices() const { 00577 return getNumOperands() > 1; 00578 } 00579 00580 /// hasAllZeroIndices - Return true if all of the indices of this GEP are 00581 /// zeros. If so, the result pointer and the first operand have the same 00582 /// value, just potentially different types. 00583 bool hasAllZeroIndices() const; 00584 00585 /// hasAllConstantIndices - Return true if all of the indices of this GEP are 00586 /// constant integers. If so, the result pointer and the first operand have 00587 /// a constant offset between them. 00588 bool hasAllConstantIndices() const; 00589 00590 // Methods for support type inquiry through isa, cast, and dyn_cast: 00591 static inline bool classof(const GetElementPtrInst *) { return true; } 00592 static inline bool classof(const Instruction *I) { 00593 return (I->getOpcode() == Instruction::GetElementPtr); 00594 } 00595 static inline bool classof(const Value *V) { 00596 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00597 } 00598 }; 00599 00600 template <> 00601 struct OperandTraits<GetElementPtrInst> : VariadicOperandTraits<1> { 00602 }; 00603 00604 template<typename InputIterator> 00605 GetElementPtrInst::GetElementPtrInst(Value *Ptr, 00606 InputIterator IdxBegin, 00607 InputIterator IdxEnd, 00608 unsigned Values, 00609 const Twine &NameStr, 00610 Instruction *InsertBefore) 00611 : Instruction(PointerType::get(checkType( 00612 getIndexedType(Ptr->getType(), 00613 IdxBegin, IdxEnd)), 00614 cast<PointerType>(Ptr->getType()) 00615 ->getAddressSpace()), 00616 GetElementPtr, 00617 OperandTraits<GetElementPtrInst>::op_end(this) - Values, 00618 Values, InsertBefore) { 00619 init(Ptr, IdxBegin, IdxEnd, NameStr, 00620 typename std::iterator_traits<InputIterator>::iterator_category()); 00621 } 00622 template<typename InputIterator> 00623 GetElementPtrInst::GetElementPtrInst(Value *Ptr, 00624 InputIterator IdxBegin, 00625 InputIterator IdxEnd, 00626 unsigned Values, 00627 const Twine &NameStr, 00628 BasicBlock *InsertAtEnd) 00629 : Instruction(PointerType::get(checkType( 00630 getIndexedType(Ptr->getType(), 00631 IdxBegin, IdxEnd)), 00632 cast<PointerType>(Ptr->getType()) 00633 ->getAddressSpace()), 00634 GetElementPtr, 00635 OperandTraits<GetElementPtrInst>::op_end(this) - Values, 00636 Values, InsertAtEnd) { 00637 init(Ptr, IdxBegin, IdxEnd, NameStr, 00638 typename std::iterator_traits<InputIterator>::iterator_category()); 00639 } 00640 00641 00642 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value) 00643 00644 00645 //===----------------------------------------------------------------------===// 00646 // ICmpInst Class 00647 //===----------------------------------------------------------------------===// 00648 00649 /// This instruction compares its operands according to the predicate given 00650 /// to the constructor. It only operates on integers or pointers. The operands 00651 /// must be identical types. 00652 /// @brief Represent an integer comparison operator. 00653 class ICmpInst: public CmpInst { 00654 public: 00655 /// @brief Constructor with insert-before-instruction semantics. 00656 ICmpInst( 00657 Instruction *InsertBefore, ///< Where to insert 00658 Predicate pred, ///< The predicate to use for the comparison 00659 Value *LHS, ///< The left-hand-side of the expression 00660 Value *RHS, ///< The right-hand-side of the expression 00661 const Twine &NameStr = "" ///< Name of the instruction 00662 ) : CmpInst(makeCmpResultType(LHS->getType()), 00663 Instruction::ICmp, pred, LHS, RHS, NameStr, 00664 InsertBefore) { 00665 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE && 00666 pred <= CmpInst::LAST_ICMP_PREDICATE && 00667 "Invalid ICmp predicate value"); 00668 assert(getOperand(0)->getType() == getOperand(1)->getType() && 00669 "Both operands to ICmp instruction are not of the same type!"); 00670 // Check that the operands are the right type 00671 assert((getOperand(0)->getType()->isIntOrIntVector() || 00672 isa<PointerType>(getOperand(0)->getType())) && 00673 "Invalid operand types for ICmp instruction"); 00674 } 00675 00676 /// @brief Constructor with insert-at-end semantics. 00677 ICmpInst( 00678 BasicBlock &InsertAtEnd, ///< Block to insert into. 00679 Predicate pred, ///< The predicate to use for the comparison 00680 Value *LHS, ///< The left-hand-side of the expression 00681 Value *RHS, ///< The right-hand-side of the expression 00682 const Twine &NameStr = "" ///< Name of the instruction 00683 ) : CmpInst(makeCmpResultType(LHS->getType()), 00684 Instruction::ICmp, pred, LHS, RHS, NameStr, 00685 &InsertAtEnd) { 00686 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE && 00687 pred <= CmpInst::LAST_ICMP_PREDICATE && 00688 "Invalid ICmp predicate value"); 00689 assert(getOperand(0)->getType() == getOperand(1)->getType() && 00690 "Both operands to ICmp instruction are not of the same type!"); 00691 // Check that the operands are the right type 00692 assert((getOperand(0)->getType()->isIntOrIntVector() || 00693 isa<PointerType>(getOperand(0)->getType())) && 00694 "Invalid operand types for ICmp instruction"); 00695 } 00696 00697 /// @brief Constructor with no-insertion semantics 00698 ICmpInst( 00699 LLVMContext &Context, ///< Context to construct within 00700 Predicate pred, ///< The predicate to use for the comparison 00701 Value *LHS, ///< The left-hand-side of the expression 00702 Value *RHS, ///< The right-hand-side of the expression 00703 const Twine &NameStr = "" ///< Name of the instruction 00704 ) : CmpInst(makeCmpResultType(LHS->getType()), 00705 Instruction::ICmp, pred, LHS, RHS, NameStr) { 00706 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE && 00707 pred <= CmpInst::LAST_ICMP_PREDICATE && 00708 "Invalid ICmp predicate value"); 00709 assert(getOperand(0)->getType() == getOperand(1)->getType() && 00710 "Both operands to ICmp instruction are not of the same type!"); 00711 // Check that the operands are the right type 00712 assert((getOperand(0)->getType()->isIntOrIntVector() || 00713 isa<PointerType>(getOperand(0)->getType())) && 00714 "Invalid operand types for ICmp instruction"); 00715 } 00716 00717 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc. 00718 /// @returns the predicate that would be the result if the operand were 00719 /// regarded as signed. 00720 /// @brief Return the signed version of the predicate 00721 Predicate getSignedPredicate() const { 00722 return getSignedPredicate(getPredicate()); 00723 } 00724 00725 /// This is a static version that you can use without an instruction. 00726 /// @brief Return the signed version of the predicate. 00727 static Predicate getSignedPredicate(Predicate pred); 00728 00729 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc. 00730 /// @returns the predicate that would be the result if the operand were 00731 /// regarded as unsigned. 00732 /// @brief Return the unsigned version of the predicate 00733 Predicate getUnsignedPredicate() const { 00734 return getUnsignedPredicate(getPredicate()); 00735 } 00736 00737 /// This is a static version that you can use without an instruction. 00738 /// @brief Return the unsigned version of the predicate. 00739 static Predicate getUnsignedPredicate(Predicate pred); 00740 00741 /// isEquality - Return true if this predicate is either EQ or NE. This also 00742 /// tests for commutativity. 00743 static bool isEquality(Predicate P) { 00744 return P == ICMP_EQ || P == ICMP_NE; 00745 } 00746 00747 /// isEquality - Return true if this predicate is either EQ or NE. This also 00748 /// tests for commutativity. 00749 bool isEquality() const { 00750 return isEquality(getPredicate()); 00751 } 00752 00753 /// @returns true if the predicate of this ICmpInst is commutative 00754 /// @brief Determine if this relation is commutative. 00755 bool isCommutative() const { return isEquality(); } 00756 00757 /// isRelational - Return true if the predicate is relational (not EQ or NE). 00758 /// 00759 bool isRelational() const { 00760 return !isEquality(); 00761 } 00762 00763 /// isRelational - Return true if the predicate is relational (not EQ or NE). 00764 /// 00765 static bool isRelational(Predicate P) { 00766 return !isEquality(P); 00767 } 00768 00769 /// @returns true if the predicate of this ICmpInst is signed, false otherwise 00770 /// @brief Determine if this instruction's predicate is signed. 00771 bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); } 00772 00773 /// @returns true if the predicate provided is signed, false otherwise 00774 /// @brief Determine if the predicate is signed. 00775 static bool isSignedPredicate(Predicate pred); 00776 00777 /// @returns true if the specified compare predicate is 00778 /// true when both operands are equal... 00779 /// @brief Determine if the icmp is true when both operands are equal 00780 static bool isTrueWhenEqual(ICmpInst::Predicate pred) { 00781 return pred == ICmpInst::ICMP_EQ || pred == ICmpInst::ICMP_UGE || 00782 pred == ICmpInst::ICMP_SGE || pred == ICmpInst::ICMP_ULE || 00783 pred == ICmpInst::ICMP_SLE; 00784 } 00785 00786 /// @returns true if the specified compare instruction is 00787 /// true when both operands are equal... 00788 /// @brief Determine if the ICmpInst returns true when both operands are equal 00789 bool isTrueWhenEqual() { 00790 return isTrueWhenEqual(getPredicate()); 00791 } 00792 00793 /// Initialize a set of values that all satisfy the predicate with C. 00794 /// @brief Make a ConstantRange for a relation with a constant value. 00795 static ConstantRange makeConstantRange(Predicate pred, const APInt &C); 00796 00797 /// Exchange the two operands to this instruction in such a way that it does 00798 /// not modify the semantics of the instruction. The predicate value may be 00799 /// changed to retain the same result if the predicate is order dependent 00800 /// (e.g. ult). 00801 /// @brief Swap operands and adjust predicate. 00802 void swapOperands() { 00803 SubclassData = getSwappedPredicate(); 00804 Op<0>().swap(Op<1>()); 00805 } 00806 00807 virtual ICmpInst *clone(LLVMContext &Context) const; 00808 00809 // Methods for support type inquiry through isa, cast, and dyn_cast: 00810 static inline bool classof(const ICmpInst *) { return true; } 00811 static inline bool classof(const Instruction *I) { 00812 return I->getOpcode() == Instruction::ICmp; 00813 } 00814 static inline bool classof(const Value *V) { 00815 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00816 } 00817 00818 }; 00819 00820 //===----------------------------------------------------------------------===// 00821 // FCmpInst Class 00822 //===----------------------------------------------------------------------===// 00823 00824 /// This instruction compares its operands according to the predicate given 00825 /// to the constructor. It only operates on floating point values or packed 00826 /// vectors of floating point values. The operands must be identical types. 00827 /// @brief Represents a floating point comparison operator. 00828 class FCmpInst: public CmpInst { 00829 public: 00830 /// @brief Constructor with insert-before-instruction semantics. 00831 FCmpInst( 00832 Instruction *InsertBefore, ///< Where to insert 00833 Predicate pred, ///< The predicate to use for the comparison 00834 Value *LHS, ///< The left-hand-side of the expression 00835 Value *RHS, ///< The right-hand-side of the expression 00836 const Twine &NameStr = "" ///< Name of the instruction 00837 ) : CmpInst(makeCmpResultType(LHS->getType()), 00838 Instruction::FCmp, pred, LHS, RHS, NameStr, 00839 InsertBefore) { 00840 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && 00841 "Invalid FCmp predicate value"); 00842 assert(getOperand(0)->getType() == getOperand(1)->getType() && 00843 "Both operands to FCmp instruction are not of the same type!"); 00844 // Check that the operands are the right type 00845 assert(getOperand(0)->getType()->isFPOrFPVector() && 00846 "Invalid operand types for FCmp instruction"); 00847 } 00848 00849 /// @brief Constructor with insert-at-end semantics. 00850 FCmpInst( 00851 BasicBlock &InsertAtEnd, ///< Block to insert into. 00852 Predicate pred, ///< The predicate to use for the comparison 00853 Value *LHS, ///< The left-hand-side of the expression 00854 Value *RHS, ///< The right-hand-side of the expression 00855 const Twine &NameStr = "" ///< Name of the instruction 00856 ) : CmpInst(makeCmpResultType(LHS->getType()), 00857 Instruction::FCmp, pred, LHS, RHS, NameStr, 00858 &InsertAtEnd) { 00859 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && 00860 "Invalid FCmp predicate value"); 00861 assert(getOperand(0)->getType() == getOperand(1)->getType() && 00862 "Both operands to FCmp instruction are not of the same type!"); 00863 // Check that the operands are the right type 00864 assert(getOperand(0)->getType()->isFPOrFPVector() && 00865 "Invalid operand types for FCmp instruction"); 00866 } 00867 00868 /// @brief Constructor with no-insertion semantics 00869 FCmpInst( 00870 LLVMContext &Context, ///< Context to build in 00871 Predicate pred, ///< The predicate to use for the comparison 00872 Value *LHS, ///< The left-hand-side of the expression 00873 Value *RHS, ///< The right-hand-side of the expression 00874 const Twine &NameStr = "" ///< Name of the instruction 00875 ) : CmpInst(makeCmpResultType(LHS->getType()), 00876 Instruction::FCmp, pred, LHS, RHS, NameStr) { 00877 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && 00878 "Invalid FCmp predicate value"); 00879 assert(getOperand(0)->getType() == getOperand(1)->getType() && 00880 "Both operands to FCmp instruction are not of the same type!"); 00881 // Check that the operands are the right type 00882 assert(getOperand(0)->getType()->isFPOrFPVector() && 00883 "Invalid operand types for FCmp instruction"); 00884 } 00885 00886 /// @returns true if the predicate of this instruction is EQ or NE. 00887 /// @brief Determine if this is an equality predicate. 00888 bool isEquality() const { 00889 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE || 00890 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE; 00891 } 00892 00893 /// @returns true if the predicate of this instruction is commutative. 00894 /// @brief Determine if this is a commutative predicate. 00895 bool isCommutative() const { 00896 return isEquality() || 00897 SubclassData == FCMP_FALSE || 00898 SubclassData == FCMP_TRUE || 00899 SubclassData == FCMP_ORD || 00900 SubclassData == FCMP_UNO; 00901 } 00902 00903 /// @returns true if the predicate is relational (not EQ or NE). 00904 /// @brief Determine if this a relational predicate. 00905 bool isRelational() const { return !isEquality(); } 00906 00907 /// Exchange the two operands to this instruction in such a way that it does 00908 /// not modify the semantics of the instruction. The predicate value may be 00909 /// changed to retain the same result if the predicate is order dependent 00910 /// (e.g. ult). 00911 /// @brief Swap operands and adjust predicate. 00912 void swapOperands() { 00913 SubclassData = getSwappedPredicate(); 00914 Op<0>().swap(Op<1>()); 00915 } 00916 00917 virtual FCmpInst *clone(LLVMContext &Context) const; 00918 00919 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: 00920 static inline bool classof(const FCmpInst *) { return true; } 00921 static inline bool classof(const Instruction *I) { 00922 return I->getOpcode() == Instruction::FCmp; 00923 } 00924 static inline bool classof(const Value *V) { 00925 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00926 } 00927 }; 00928 00929 //===----------------------------------------------------------------------===// 00930 // CallInst Class 00931 //===----------------------------------------------------------------------===// 00932 /// CallInst - This class represents a function call, abstracting a target 00933 /// machine's calling convention. This class uses low bit of the SubClassData 00934 /// field to indicate whether or not this is a tail call. The rest of the bits 00935 /// hold the calling convention of the call. 00936 /// 00937 00938 class CallInst : public Instruction { 00939 AttrListPtr AttributeList; ///< parameter attributes for call 00940 CallInst(const CallInst &CI); 00941 void init(Value *Func, Value* const *Params, unsigned NumParams); 00942 void init(Value *Func, Value *Actual1, Value *Actual2); 00943 void init(Value *Func, Value *Actual); 00944 void init(Value *Func); 00945 00946 template<typename InputIterator> 00947 void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, 00948 const Twine &NameStr, 00949 // This argument ensures that we have an iterator we can 00950 // do arithmetic on in constant time 00951 std::random_access_iterator_tag) { 00952 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd); 00953 00954 // This requires that the iterator points to contiguous memory. 00955 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs); 00956 setName(NameStr); 00957 } 00958 00959 /// Construct a CallInst given a range of arguments. InputIterator 00960 /// must be a random-access iterator pointing to contiguous storage 00961 /// (e.g. a std::vector<>::iterator). Checks are made for 00962 /// random-accessness but not for contiguous storage as that would 00963 /// incur runtime overhead. 00964 /// @brief Construct a CallInst from a range of arguments 00965 template<typename InputIterator> 00966 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, 00967 const Twine &NameStr, Instruction *InsertBefore); 00968 00969 /// Construct a CallInst given a range of arguments. InputIterator 00970 /// must be a random-access iterator pointing to contiguous storage 00971 /// (e.g. a std::vector<>::iterator). Checks are made for 00972 /// random-accessness but not for contiguous storage as that would 00973 /// incur runtime overhead. 00974 /// @brief Construct a CallInst from a range of arguments 00975 template<typename InputIterator> 00976 inline CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, 00977 const Twine &NameStr, BasicBlock *InsertAtEnd); 00978 00979 CallInst(Value *F, Value *Actual, const Twine &NameStr, 00980 Instruction *InsertBefore); 00981 CallInst(Value *F, Value *Actual, const Twine &NameStr, 00982 BasicBlock *InsertAtEnd); 00983 explicit CallInst(Value *F, const Twine &NameStr, 00984 Instruction *InsertBefore); 00985 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd); 00986 public: 00987 template<typename InputIterator> 00988 static CallInst *Create(Value *Func, 00989 InputIterator ArgBegin, InputIterator ArgEnd, 00990 const Twine &NameStr = "", 00991 Instruction *InsertBefore = 0) { 00992 return new((unsigned)(ArgEnd - ArgBegin + 1)) 00993 CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertBefore); 00994 } 00995 template<typename InputIterator> 00996 static CallInst *Create(Value *Func, 00997 InputIterator ArgBegin, InputIterator ArgEnd, 00998 const Twine &NameStr, BasicBlock *InsertAtEnd) { 00999 return new((unsigned)(ArgEnd - ArgBegin + 1)) 01000 CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertAtEnd); 01001 } 01002 static CallInst *Create(Value *F, Value *Actual, 01003 const Twine &NameStr = "", 01004 Instruction *InsertBefore = 0) { 01005 return new(2) CallInst(F, Actual, NameStr, InsertBefore); 01006 } 01007 static CallInst *Create(Value *F, Value *Actual, const Twine &NameStr, 01008 BasicBlock *InsertAtEnd) { 01009 return new(2) CallInst(F, Actual, NameStr, InsertAtEnd); 01010 } 01011 static CallInst *Create(Value *F, const Twine &NameStr = "", 01012 Instruction *InsertBefore = 0) { 01013 return new(1) CallInst(F, NameStr, InsertBefore); 01014 } 01015 static CallInst *Create(Value *F, const Twine &NameStr, 01016 BasicBlock *InsertAtEnd) { 01017 return new(1) CallInst(F, NameStr, InsertAtEnd); 01018 } 01019 01020 ~CallInst(); 01021 01022 bool isTailCall() const { return SubclassData & 1; } 01023 void setTailCall(bool isTC = true) { 01024 SubclassData = (SubclassData & ~1) | unsigned(isTC); 01025 } 01026 01027 virtual CallInst *clone(LLVMContext &Context) const; 01028 01029 /// Provide fast operand accessors 01030 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 01031 01032 /// getCallingConv/setCallingConv - Get or set the calling convention of this 01033 /// function call. 01034 unsigned getCallingConv() const { return SubclassData >> 1; } 01035 void setCallingConv(unsigned CC) { 01036 SubclassData = (SubclassData & 1) | (CC << 1); 01037 } 01038 01039 /// getAttributes - Return the parameter attributes for this call. 01040 /// 01041 const AttrListPtr &getAttributes() const { return AttributeList; } 01042 01043 /// setAttributes - Set the parameter attributes for this call. 01044 /// 01045 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; } 01046 01047 /// addAttribute - adds the attribute to the list of attributes. 01048 void addAttribute(unsigned i, Attributes attr); 01049 01050 /// removeAttribute - removes the attribute from the list of attributes. 01051 void removeAttribute(unsigned i, Attributes attr); 01052 01053 /// @brief Determine whether the call or the callee has the given attribute. 01054 bool paramHasAttr(unsigned i, Attributes attr) const; 01055 01056 /// @brief Extract the alignment for a call or parameter (0=unknown). 01057 unsigned getParamAlignment(unsigned i) const { 01058 return AttributeList.getParamAlignment(i); 01059 } 01060 01061 /// @brief Determine if the call does not access memory. 01062 bool doesNotAccessMemory() const { 01063 return paramHasAttr(~0, Attribute::ReadNone); 01064 } 01065 void setDoesNotAccessMemory(bool NotAccessMemory = true) { 01066 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone); 01067 else removeAttribute(~0, Attribute::ReadNone); 01068 } 01069 01070 /// @brief Determine if the call does not access or only reads memory. 01071 bool onlyReadsMemory() const { 01072 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly); 01073 } 01074 void setOnlyReadsMemory(bool OnlyReadsMemory = true) { 01075 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly); 01076 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone); 01077 } 01078 01079 /// @brief Determine if the call cannot return. 01080 bool doesNotReturn() const { 01081 return paramHasAttr(~0, Attribute::NoReturn); 01082 } 01083 void setDoesNotReturn(bool DoesNotReturn = true) { 01084 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn); 01085 else removeAttribute(~0, Attribute::NoReturn); 01086 } 01087 01088 /// @brief Determine if the call cannot unwind. 01089 bool doesNotThrow() const { 01090 return paramHasAttr(~0, Attribute::NoUnwind); 01091 } 01092 void setDoesNotThrow(bool DoesNotThrow = true) { 01093 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind); 01094 else removeAttribute(~0, Attribute::NoUnwind); 01095 } 01096 01097 /// @brief Determine if the call returns a structure through first 01098 /// pointer argument. 01099 bool hasStructRetAttr() const { 01100 // Be friendly and also check the callee. 01101 return paramHasAttr(1, Attribute::StructRet); 01102 } 01103 01104 /// @brief Determine if any call argument is an aggregate passed by value. 01105 bool hasByValArgument() const { 01106 return AttributeList.hasAttrSomewhere(Attribute::ByVal); 01107 } 01108 01109 /// getCalledFunction - Return the function called, or null if this is an 01110 /// indirect function invocation. 01111 /// 01112 Function *getCalledFunction() const { 01113 return dyn_cast<Function>(Op<0>()); 01114 } 01115 01116 /// getCalledValue - Get a pointer to the function that is invoked by this 01117 /// instruction 01118 const Value *getCalledValue() const { return Op<0>(); } 01119 Value *getCalledValue() { return Op<0>(); } 01120 01121 // Methods for support type inquiry through isa, cast, and dyn_cast: 01122 static inline bool classof(const CallInst *) { return true; } 01123 static inline bool classof(const Instruction *I) { 01124 return I->getOpcode() == Instruction::Call; 01125 } 01126 static inline bool classof(const Value *V) { 01127 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01128 } 01129 }; 01130 01131 template <> 01132 struct OperandTraits<CallInst> : VariadicOperandTraits<1> { 01133 }; 01134 01135 template<typename InputIterator> 01136 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, 01137 const Twine &NameStr, BasicBlock *InsertAtEnd) 01138 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) 01139 ->getElementType())->getReturnType(), 01140 Instruction::Call, 01141 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1), 01142 (unsigned)(ArgEnd - ArgBegin + 1), InsertAtEnd) { 01143 init(Func, ArgBegin, ArgEnd, NameStr, 01144 typename std::iterator_traits<InputIterator>::iterator_category()); 01145 } 01146 01147 template<typename InputIterator> 01148 CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, 01149 const Twine &NameStr, Instruction *InsertBefore) 01150 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) 01151 ->getElementType())->getReturnType(), 01152 Instruction::Call, 01153 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1), 01154 (unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) { 01155 init(Func, ArgBegin, ArgEnd, NameStr, 01156 typename std::iterator_traits<InputIterator>::iterator_category()); 01157 } 01158 01159 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value) 01160 01161 //===----------------------------------------------------------------------===// 01162 // SelectInst Class 01163 //===----------------------------------------------------------------------===// 01164 01165 /// SelectInst - This class represents the LLVM 'select' instruction. 01166 /// 01167 class SelectInst : public Instruction { 01168 void init(Value *C, Value *S1, Value *S2) { 01169 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select"); 01170 Op<0>() = C; 01171 Op<1>() = S1; 01172 Op<2>() = S2; 01173 } 01174 01175 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr, 01176 Instruction *InsertBefore) 01177 : Instruction(S1->getType(), Instruction::Select, 01178 &Op<0>(), 3, InsertBefore) { 01179 init(C, S1, S2); 01180 setName(NameStr); 01181 } 01182 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr, 01183 BasicBlock *InsertAtEnd) 01184 : Instruction(S1->getType(), Instruction::Select, 01185 &Op<0>(), 3, InsertAtEnd) { 01186 init(C, S1, S2); 01187 setName(NameStr); 01188 } 01189 public: 01190 static SelectInst *Create(Value *C, Value *S1, Value *S2, 01191 const Twine &NameStr = "", 01192 Instruction *InsertBefore = 0) { 01193 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore); 01194 } 01195 static SelectInst *Create(Value *C, Value *S1, Value *S2, 01196 const Twine &NameStr, 01197 BasicBlock *InsertAtEnd) { 01198 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd); 01199 } 01200 01201 Value *getCondition() const { return Op<0>(); } 01202 Value *getTrueValue() const { return Op<1>(); } 01203 Value *getFalseValue() const { return Op<2>(); } 01204 01205 /// areInvalidOperands - Return a string if the specified operands are invalid 01206 /// for a select operation, otherwise return null. 01207 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False); 01208 01209 /// Transparently provide more efficient getOperand methods. 01210 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 01211 01212 OtherOps getOpcode() const { 01213 return static_cast<OtherOps>(Instruction::getOpcode()); 01214 } 01215 01216 virtual SelectInst *clone(LLVMContext &Context) const; 01217 01218 // Methods for support type inquiry through isa, cast, and dyn_cast: 01219 static inline bool classof(const SelectInst *) { return true; } 01220 static inline bool classof(const Instruction *I) { 01221 return I->getOpcode() == Instruction::Select; 01222 } 01223 static inline bool classof(const Value *V) { 01224 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01225 } 01226 }; 01227 01228 template <> 01229 struct OperandTraits<SelectInst> : FixedNumOperandTraits<3> { 01230 }; 01231 01232 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value) 01233 01234 //===----------------------------------------------------------------------===// 01235 // VAArgInst Class 01236 //===----------------------------------------------------------------------===// 01237 01238 /// VAArgInst - This class represents the va_arg llvm instruction, which returns 01239 /// an argument of the specified type given a va_list and increments that list 01240 /// 01241 class VAArgInst : public UnaryInstruction { 01242 public: 01243 VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "", 01244 Instruction *InsertBefore = 0) 01245 : UnaryInstruction(Ty, VAArg, List, InsertBefore) { 01246 setName(NameStr); 01247 } 01248 VAArgInst(Value *List, const Type *Ty, const Twine &NameStr, 01249 BasicBlock *InsertAtEnd) 01250 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) { 01251 setName(NameStr); 01252 } 01253 01254 virtual VAArgInst *clone(LLVMContext &Context) const; 01255 01256 // Methods for support type inquiry through isa, cast, and dyn_cast: 01257 static inline bool classof(const VAArgInst *) { return true; } 01258 static inline bool classof(const Instruction *I) { 01259 return I->getOpcode() == VAArg; 01260 } 01261 static inline bool classof(const Value *V) { 01262 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01263 } 01264 }; 01265 01266 //===----------------------------------------------------------------------===// 01267 // ExtractElementInst Class 01268 //===----------------------------------------------------------------------===// 01269 01270 /// ExtractElementInst - This instruction extracts a single (scalar) 01271 /// element from a VectorType value 01272 /// 01273 class ExtractElementInst : public Instruction { 01274 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "", 01275 Instruction *InsertBefore = 0); 01276 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr, 01277 BasicBlock *InsertAtEnd); 01278 public: 01279 static ExtractElementInst *Create(const ExtractElementInst &EE) { 01280 return Create(EE.getOperand(0), EE.getOperand(1)); 01281 } 01282 01283 static ExtractElementInst *Create(Value *Vec, Value *Idx, 01284 const Twine &NameStr = "", 01285 Instruction *InsertBefore = 0) { 01286 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore); 01287 } 01288 static ExtractElementInst *Create(Value *Vec, Value *Idx, 01289 const Twine &NameStr, 01290 BasicBlock *InsertAtEnd) { 01291 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd); 01292 } 01293 01294 /// isValidOperands - Return true if an extractelement instruction can be 01295 /// formed with the specified operands. 01296 static bool isValidOperands(const Value *Vec, const Value *Idx); 01297 01298 virtual ExtractElementInst *clone(LLVMContext &Context) const; 01299 01300 /// Transparently provide more efficient getOperand methods. 01301 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 01302 01303 // Methods for support type inquiry through isa, cast, and dyn_cast: 01304 static inline bool classof(const ExtractElementInst *) { return true; } 01305 static inline bool classof(const Instruction *I) { 01306 return I->getOpcode() == Instruction::ExtractElement; 01307 } 01308 static inline bool classof(const Value *V) { 01309 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01310 } 01311 }; 01312 01313 template <> 01314 struct OperandTraits<ExtractElementInst> : FixedNumOperandTraits<2> { 01315 }; 01316 01317 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value) 01318 01319 //===----------------------------------------------------------------------===// 01320 // InsertElementInst Class 01321 //===----------------------------------------------------------------------===// 01322 01323 /// InsertElementInst - This instruction inserts a single (scalar) 01324 /// element into a VectorType value 01325 /// 01326 class InsertElementInst : public Instruction { 01327 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, 01328 const Twine &NameStr = "", 01329 Instruction *InsertBefore = 0); 01330 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, 01331 const Twine &NameStr, BasicBlock *InsertAtEnd); 01332 public: 01333 static InsertElementInst *Create(const InsertElementInst &IE) { 01334 return Create(IE.getOperand(0), IE.getOperand(1), IE.getOperand(2)); 01335 } 01336 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, 01337 const Twine &NameStr = "", 01338 Instruction *InsertBefore = 0) { 01339 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore); 01340 } 01341 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, 01342 const Twine &NameStr, 01343 BasicBlock *InsertAtEnd) { 01344 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd); 01345 } 01346 01347 /// isValidOperands - Return true if an insertelement instruction can be 01348 /// formed with the specified operands. 01349 static bool isValidOperands(const Value *Vec, const Value *NewElt, 01350 const Value *Idx); 01351 01352 virtual InsertElementInst *clone(LLVMContext &Context) const; 01353 01354 /// getType - Overload to return most specific vector type. 01355 /// 01356 const VectorType *getType() const { 01357 return reinterpret_cast<const VectorType*>(Instruction::getType()); 01358 } 01359 01360 /// Transparently provide more efficient getOperand methods. 01361 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 01362 01363 // Methods for support type inquiry through isa, cast, and dyn_cast: 01364 static inline bool classof(const InsertElementInst *) { return true; } 01365 static inline bool classof(const Instruction *I) { 01366 return I->getOpcode() == Instruction::InsertElement; 01367 } 01368 static inline bool classof(const Value *V) { 01369 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01370 } 01371 }; 01372 01373 template <> 01374 struct OperandTraits<InsertElementInst> : FixedNumOperandTraits<3> { 01375 }; 01376 01377 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value) 01378 01379 //===----------------------------------------------------------------------===// 01380 // ShuffleVectorInst Class 01381 //===----------------------------------------------------------------------===// 01382 01383 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two 01384 /// input vectors. 01385 /// 01386 class ShuffleVectorInst : public Instruction { 01387 public: 01388 // allocate space for exactly three operands 01389 void *operator new(size_t s) { 01390 return User::operator new(s, 3); 01391 } 01392 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, 01393 const Twine &NameStr = "", 01394 Instruction *InsertBefor = 0); 01395 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, 01396 const Twine &NameStr, BasicBlock *InsertAtEnd); 01397 01398 /// isValidOperands - Return true if a shufflevector instruction can be 01399 /// formed with the specified operands. 01400 static bool isValidOperands(const Value *V1, const Value *V2, 01401 const Value *Mask); 01402 01403 virtual ShuffleVectorInst *clone(LLVMContext &Context) const; 01404 01405 /// getType - Overload to return most specific vector type. 01406 /// 01407 const VectorType *getType() const { 01408 return reinterpret_cast<const VectorType*>(Instruction::getType()); 01409 } 01410 01411 /// Transparently provide more efficient getOperand methods. 01412 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 01413 01414 /// getMaskValue - Return the index from the shuffle mask for the specified 01415 /// output result. This is either -1 if the element is undef or a number less 01416 /// than 2*numelements. 01417 int getMaskValue(unsigned i) const; 01418 01419 // Methods for support type inquiry through isa, cast, and dyn_cast: 01420 static inline bool classof(const ShuffleVectorInst *) { return true; } 01421 static inline bool classof(const Instruction *I) { 01422 return I->getOpcode() == Instruction::ShuffleVector; 01423 } 01424 static inline bool classof(const Value *V) { 01425 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01426 } 01427 }; 01428 01429 template <> 01430 struct OperandTraits<ShuffleVectorInst> : FixedNumOperandTraits<3> { 01431 }; 01432 01433 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value) 01434 01435 //===----------------------------------------------------------------------===// 01436 // ExtractValueInst Class 01437 //===----------------------------------------------------------------------===// 01438 01439 /// ExtractValueInst - This instruction extracts a struct member or array 01440 /// element value from an aggregate value. 01441 /// 01442 class ExtractValueInst : public UnaryInstruction { 01443 SmallVector<unsigned, 4> Indices; 01444 01445 ExtractValueInst(const ExtractValueInst &EVI); 01446 void init(const unsigned *Idx, unsigned NumIdx, 01447 const Twine &NameStr); 01448 void init(unsigned Idx, const Twine &NameStr); 01449 01450 template<typename InputIterator> 01451 void init(InputIterator IdxBegin, InputIterator IdxEnd, 01452 const Twine &NameStr, 01453 // This argument ensures that we have an iterator we can 01454 // do arithmetic on in constant time 01455 std::random_access_iterator_tag) { 01456 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); 01457 01458 // There's no fundamental reason why we require at least one index 01459 // (other than weirdness with &*IdxBegin being invalid; see 01460 // getelementptr's init routine for example). But there's no 01461 // present need to support it. 01462 assert(NumIdx > 0 && "ExtractValueInst must have at least one index"); 01463 01464 // This requires that the iterator points to contiguous memory. 01465 init(&*IdxBegin, NumIdx, NameStr); // FIXME: for the general case 01466 // we have to build an array here 01467 } 01468 01469 /// getIndexedType - Returns the type of the element that would be extracted 01470 /// with an extractvalue instruction with the specified parameters. 01471 /// 01472 /// Null is returned if the indices are invalid for the specified 01473 /// pointer type. 01474 /// 01475 static const Type *getIndexedType(const Type *Agg, 01476 const unsigned *Idx, unsigned NumIdx); 01477 01478 template<typename InputIterator> 01479 static const Type *getIndexedType(const Type *Ptr, 01480 InputIterator IdxBegin, 01481 InputIterator IdxEnd, 01482 // This argument ensures that we 01483 // have an iterator we can do 01484 // arithmetic on in constant time 01485 std::random_access_iterator_tag) { 01486 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); 01487 01488 if (NumIdx > 0) 01489 // This requires that the iterator points to contiguous memory. 01490 return getIndexedType(Ptr, &*IdxBegin, NumIdx); 01491 else 01492 return getIndexedType(Ptr, (const unsigned *)0, NumIdx); 01493 } 01494 01495 /// Constructors - Create a extractvalue instruction with a base aggregate 01496 /// value and a list of indices. The first ctor can optionally insert before 01497 /// an existing instruction, the second appends the new instruction to the 01498 /// specified BasicBlock. 01499 template<typename InputIterator> 01500 inline ExtractValueInst(Value *Agg, InputIterator IdxBegin, 01501 InputIterator IdxEnd, 01502 const Twine &NameStr, 01503 Instruction *InsertBefore); 01504 template<typename InputIterator> 01505 inline ExtractValueInst(Value *Agg, 01506 InputIterator IdxBegin, InputIterator IdxEnd, 01507 const Twine &NameStr, BasicBlock *InsertAtEnd); 01508 01509 // allocate space for exactly one operand 01510 void *operator new(size_t s) { 01511 return User::operator new(s, 1); 01512 } 01513 01514 public: 01515 template<typename InputIterator> 01516 static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin, 01517 InputIterator IdxEnd, 01518 const Twine &NameStr = "", 01519 Instruction *InsertBefore = 0) { 01520 return new 01521 ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertBefore); 01522 } 01523 template<typename InputIterator> 01524 static ExtractValueInst *Create(Value *Agg, 01525 InputIterator IdxBegin, InputIterator IdxEnd, 01526 const Twine &NameStr, 01527 BasicBlock *InsertAtEnd) { 01528 return new ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertAtEnd); 01529 } 01530 01531 /// Constructors - These two creators are convenience methods because one 01532 /// index extractvalue instructions are much more common than those with 01533 /// more than one. 01534 static ExtractValueInst *Create(Value *Agg, unsigned Idx, 01535 const Twine &NameStr = "", 01536 Instruction *InsertBefore = 0) { 01537 unsigned Idxs[1] = { Idx }; 01538 return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertBefore); 01539 } 01540 static ExtractValueInst *Create(Value *Agg, unsigned Idx, 01541 const Twine &NameStr, 01542 BasicBlock *InsertAtEnd) { 01543 unsigned Idxs[1] = { Idx }; 01544 return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd); 01545 } 01546 01547 virtual ExtractValueInst *clone(LLVMContext &Context) const; 01548 01549 /// getIndexedType - Returns the type of the element that would be extracted 01550 /// with an extractvalue instruction with the specified parameters. 01551 /// 01552 /// Null is returned if the indices are invalid for the specified 01553 /// pointer type. 01554 /// 01555 template<typename InputIterator> 01556 static const Type *getIndexedType(const Type *Ptr, 01557 InputIterator IdxBegin, 01558 InputIterator IdxEnd) { 01559 return getIndexedType(Ptr, IdxBegin, IdxEnd, 01560 typename std::iterator_traits<InputIterator>:: 01561 iterator_category()); 01562 } 01563 static const Type *getIndexedType(const Type *Ptr, unsigned Idx); 01564 01565 typedef const unsigned* idx_iterator; 01566 inline idx_iterator idx_begin() const { return Indices.begin(); } 01567 inline idx_iterator idx_end() const { return Indices.end(); } 01568 01569 Value *getAggregateOperand() { 01570 return getOperand(0); 01571 } 01572 const Value *getAggregateOperand() const { 01573 return getOperand(0); 01574 } 01575 static unsigned getAggregateOperandIndex() { 01576 return 0U; // get index for modifying correct operand 01577 } 01578 01579 unsigned getNumIndices() const { // Note: always non-negative 01580 return (unsigned)Indices.size(); 01581 } 01582 01583 bool hasIndices() const { 01584 return true; 01585 } 01586 01587 // Methods for support type inquiry through isa, cast, and dyn_cast: 01588 static inline bool classof(const ExtractValueInst *) { return true; } 01589 static inline bool classof(const Instruction *I) { 01590 return I->getOpcode() == Instruction::ExtractValue; 01591 } 01592 static inline bool classof(const Value *V) { 01593 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01594 } 01595 }; 01596 01597 template<typename InputIterator> 01598 ExtractValueInst::ExtractValueInst(Value *Agg, 01599 InputIterator IdxBegin, 01600 InputIterator IdxEnd, 01601 const Twine &NameStr, 01602 Instruction *InsertBefore) 01603 : UnaryInstruction(checkType(getIndexedType(Agg->getType(), 01604 IdxBegin, IdxEnd)), 01605 ExtractValue, Agg, InsertBefore) { 01606 init(IdxBegin, IdxEnd, NameStr, 01607 typename std::iterator_traits<InputIterator>::iterator_category()); 01608 } 01609 template<typename InputIterator> 01610 ExtractValueInst::ExtractValueInst(Value *Agg, 01611 InputIterator IdxBegin, 01612 InputIterator IdxEnd, 01613 const Twine &NameStr, 01614 BasicBlock *InsertAtEnd) 01615 : UnaryInstruction(checkType(getIndexedType(Agg->getType(), 01616 IdxBegin, IdxEnd)), 01617 ExtractValue, Agg, InsertAtEnd) { 01618 init(IdxBegin, IdxEnd, NameStr, 01619 typename std::iterator_traits<InputIterator>::iterator_category()); 01620 } 01621 01622 01623 //===----------------------------------------------------------------------===// 01624 // InsertValueInst Class 01625 //===----------------------------------------------------------------------===// 01626 01627 /// InsertValueInst - This instruction inserts a struct field of array element 01628 /// value into an aggregate value. 01629 /// 01630 class InsertValueInst : public Instruction { 01631 SmallVector<unsigned, 4> Indices; 01632 01633 void *operator new(size_t, unsigned); // Do not implement 01634 InsertValueInst(const InsertValueInst &IVI); 01635 void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx, 01636 const Twine &NameStr); 01637 void init(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr); 01638 01639 template<typename InputIterator> 01640 void init(Value *Agg, Value *Val, 01641 InputIterator IdxBegin, InputIterator IdxEnd, 01642 const Twine &NameStr, 01643 // This argument ensures that we have an iterator we can 01644 // do arithmetic on in constant time 01645 std::random_access_iterator_tag) { 01646 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); 01647 01648 // There's no fundamental reason why we require at least one index 01649 // (other than weirdness with &*IdxBegin being invalid; see 01650 // getelementptr's init routine for example). But there's no 01651 // present need to support it. 01652 assert(NumIdx > 0 && "InsertValueInst must have at least one index"); 01653 01654 // This requires that the iterator points to contiguous memory. 01655 init(Agg, Val, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case 01656 // we have to build an array here 01657 } 01658 01659 /// Constructors - Create a insertvalue instruction with a base aggregate 01660 /// value, a value to insert, and a list of indices. The first ctor can 01661 /// optionally insert before an existing instruction, the second appends 01662 /// the new instruction to the specified BasicBlock. 01663 template<typename InputIterator> 01664 inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin, 01665 InputIterator IdxEnd, 01666 const Twine &NameStr, 01667 Instruction *InsertBefore); 01668 template<typename InputIterator> 01669 inline InsertValueInst(Value *Agg, Value *Val, 01670 InputIterator IdxBegin, InputIterator IdxEnd, 01671 const Twine &NameStr, BasicBlock *InsertAtEnd); 01672 01673 /// Constructors - These two constructors are convenience methods because one 01674 /// and two index insertvalue instructions are so common. 01675 InsertValueInst(Value *Agg, Value *Val, 01676 unsigned Idx, const Twine &NameStr = "", 01677 Instruction *InsertBefore = 0); 01678 InsertValueInst(Value *Agg, Value *Val, unsigned Idx, 01679 const Twine &NameStr, BasicBlock *InsertAtEnd); 01680 public: 01681 // allocate space for exactly two operands 01682 void *operator new(size_t s) { 01683 return User::operator new(s, 2); 01684 } 01685 01686 template<typename InputIterator> 01687 static InsertValueInst *Create(Value *Agg, Value *Val, InputIterator IdxBegin, 01688 InputIterator IdxEnd, 01689 const Twine &NameStr = "", 01690 Instruction *InsertBefore = 0) { 01691 return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd, 01692 NameStr, InsertBefore); 01693 } 01694 template<typename InputIterator> 01695 static InsertValueInst *Create(Value *Agg, Value *Val, 01696 InputIterator IdxBegin, InputIterator IdxEnd, 01697 const Twine &NameStr, 01698 BasicBlock *InsertAtEnd) { 01699 return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd, 01700 NameStr, InsertAtEnd); 01701 } 01702 01703 /// Constructors - These two creators are convenience methods because one 01704 /// index insertvalue instructions are much more common than those with 01705 /// more than one. 01706 static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx, 01707 const Twine &NameStr = "", 01708 Instruction *InsertBefore = 0) { 01709 return new InsertValueInst(Agg, Val, Idx, NameStr, InsertBefore); 01710 } 01711 static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx, 01712 const Twine &NameStr, 01713 BasicBlock *InsertAtEnd) { 01714 return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd); 01715 } 01716 01717 virtual InsertValueInst *clone(LLVMContext &Context) const; 01718 01719 /// Transparently provide more efficient getOperand methods. 01720 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 01721 01722 typedef const unsigned* idx_iterator; 01723 inline idx_iterator idx_begin() const { return Indices.begin(); } 01724 inline idx_iterator idx_end() const { return Indices.end(); } 01725 01726 Value *getAggregateOperand() { 01727 return getOperand(0); 01728 } 01729 const Value *getAggregateOperand() const { 01730 return getOperand(0); 01731 } 01732 static unsigned getAggregateOperandIndex() { 01733 return 0U; // get index for modifying correct operand 01734 } 01735 01736 Value *getInsertedValueOperand() { 01737 return getOperand(1); 01738 } 01739 const Value *getInsertedValueOperand() const { 01740 return getOperand(1); 01741 } 01742 static unsigned getInsertedValueOperandIndex() { 01743 return 1U; // get index for modifying correct operand 01744 } 01745 01746 unsigned getNumIndices() const { // Note: always non-negative 01747 return (unsigned)Indices.size(); 01748 } 01749 01750 bool hasIndices() const { 01751 return true; 01752 } 01753 01754 // Methods for support type inquiry through isa, cast, and dyn_cast: 01755 static inline bool classof(const InsertValueInst *) { return true; } 01756 static inline bool classof(const Instruction *I) { 01757 return I->getOpcode() == Instruction::InsertValue; 01758 } 01759 static inline bool classof(const Value *V) { 01760 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01761 } 01762 }; 01763 01764 template <> 01765 struct OperandTraits<InsertValueInst> : FixedNumOperandTraits<2> { 01766 }; 01767 01768 template<typename InputIterator> 01769 InsertValueInst::InsertValueInst(Value *Agg, 01770 Value *Val, 01771 InputIterator IdxBegin, 01772 InputIterator IdxEnd, 01773 const Twine &NameStr, 01774 Instruction *InsertBefore) 01775 : Instruction(Agg->getType(), InsertValue, 01776 OperandTraits<InsertValueInst>::op_begin(this), 01777 2, InsertBefore) { 01778 init(Agg, Val, IdxBegin, IdxEnd, NameStr, 01779 typename std::iterator_traits<InputIterator>::iterator_category()); 01780 } 01781 template<typename InputIterator> 01782 InsertValueInst::InsertValueInst(Value *Agg, 01783 Value *Val, 01784 InputIterator IdxBegin, 01785 InputIterator IdxEnd, 01786 const Twine &NameStr, 01787 BasicBlock *InsertAtEnd) 01788 : Instruction(Agg->getType(), InsertValue, 01789 OperandTraits<InsertValueInst>::op_begin(this), 01790 2, InsertAtEnd) { 01791 init(Agg, Val, IdxBegin, IdxEnd, NameStr, 01792 typename std::iterator_traits<InputIterator>::iterator_category()); 01793 } 01794 01795 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value) 01796 01797 //===----------------------------------------------------------------------===// 01798 // PHINode Class 01799 //===----------------------------------------------------------------------===// 01800 01801 // PHINode - The PHINode class is used to represent the magical mystical PHI 01802 // node, that can not exist in nature, but can be synthesized in a computer 01803 // scientist's overactive imagination. 01804 // 01805 class PHINode : public Instruction { 01806 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 01807 /// ReservedSpace - The number of operands actually allocated. NumOperands is 01808 /// the number actually in use. 01809 unsigned ReservedSpace; 01810 PHINode(const PHINode &PN); 01811 // allocate space for exactly zero operands 01812 void *operator new(size_t s) { 01813 return User::operator new(s, 0); 01814 } 01815 explicit PHINode(const Type *Ty, const Twine &NameStr = "", 01816 Instruction *InsertBefore = 0) 01817 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore), 01818 ReservedSpace(0) { 01819 setName(NameStr); 01820 } 01821 01822 PHINode(const Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd) 01823 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd), 01824 ReservedSpace(0) { 01825 setName(NameStr); 01826 } 01827 public: 01828 static PHINode *Create(const Type *Ty, const Twine &NameStr = "", 01829 Instruction *InsertBefore = 0) { 01830 return new PHINode(Ty, NameStr, InsertBefore); 01831 } 01832 static PHINode *Create(const Type *Ty, const Twine &NameStr, 01833 BasicBlock *InsertAtEnd) { 01834 return new PHINode(Ty, NameStr, InsertAtEnd); 01835 } 01836 ~PHINode(); 01837 01838 /// reserveOperandSpace - This method can be used to avoid repeated 01839 /// reallocation of PHI operand lists by reserving space for the correct 01840 /// number of operands before adding them. Unlike normal vector reserves, 01841 /// this method can also be used to trim the operand space. 01842 void reserveOperandSpace(unsigned NumValues) { 01843 resizeOperands(NumValues*2); 01844 } 01845 01846 virtual PHINode *clone(LLVMContext &Context) const; 01847 01848 /// Provide fast operand accessors 01849 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 01850 01851 /// getNumIncomingValues - Return the number of incoming edges 01852 /// 01853 unsigned getNumIncomingValues() const { return getNumOperands()/2; } 01854 01855 /// getIncomingValue - Return incoming value number x 01856 /// 01857 Value *getIncomingValue(unsigned i) const { 01858 assert(i*2 < getNumOperands() && "Invalid value number!"); 01859 return getOperand(i*2); 01860 } 01861 void setIncomingValue(unsigned i, Value *V) { 01862 assert(i*2 < getNumOperands() && "Invalid value number!"); 01863 setOperand(i*2, V); 01864 } 01865 static unsigned getOperandNumForIncomingValue(unsigned i) { 01866 return i*2; 01867 } 01868 static unsigned getIncomingValueNumForOperand(unsigned i) { 01869 assert(i % 2 == 0 && "Invalid incoming-value operand index!"); 01870 return i/2; 01871 } 01872 01873 /// getIncomingBlock - Return incoming basic block corresponding 01874 /// to value use iterator 01875 /// 01876 template <typename U> 01877 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const { 01878 assert(this == *I && "Iterator doesn't point to PHI's Uses?"); 01879 return static_cast<BasicBlock*>((&I.getUse() + 1)->get()); 01880 } 01881 /// getIncomingBlock - Return incoming basic block number x 01882 /// 01883 BasicBlock *getIncomingBlock(unsigned i) const { 01884 return static_cast<BasicBlock*>(getOperand(i*2+1)); 01885 } 01886 void setIncomingBlock(unsigned i, BasicBlock *BB) { 01887 setOperand(i*2+1, BB); 01888 } 01889 static unsigned getOperandNumForIncomingBlock(unsigned i) { 01890 return i*2+1; 01891 } 01892 static unsigned getIncomingBlockNumForOperand(unsigned i) { 01893 assert(i % 2 == 1 && "Invalid incoming-block operand index!"); 01894 return i/2; 01895 } 01896 01897 /// addIncoming - Add an incoming value to the end of the PHI list 01898 /// 01899 void addIncoming(Value *V, BasicBlock *BB) { 01900 assert(V && "PHI node got a null value!"); 01901 assert(BB && "PHI node got a null basic block!"); 01902 assert(getType() == V->getType() && 01903 "All operands to PHI node must be the same type as the PHI node!"); 01904 unsigned OpNo = NumOperands; 01905 if (OpNo+2 > ReservedSpace) 01906 resizeOperands(0); // Get more space! 01907 // Initialize some new operands. 01908 NumOperands = OpNo+2; 01909 OperandList[OpNo] = V; 01910 OperandList[OpNo+1] = BB; 01911 } 01912 01913 /// removeIncomingValue - Remove an incoming value. This is useful if a 01914 /// predecessor basic block is deleted. The value removed is returned. 01915 /// 01916 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty 01917 /// is true), the PHI node is destroyed and any uses of it are replaced with 01918 /// dummy values. The only time there should be zero incoming values to a PHI 01919 /// node is when the block is dead, so this strategy is sound. 01920 /// 01921 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true); 01922 01923 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) { 01924 int Idx = getBasicBlockIndex(BB); 01925 assert(Idx >= 0 && "Invalid basic block argument to remove!"); 01926 return removeIncomingValue(Idx, DeletePHIIfEmpty); 01927 } 01928 01929 /// getBasicBlockIndex - Return the first index of the specified basic 01930 /// block in the value list for this PHI. Returns -1 if no instance. 01931 /// 01932 int getBasicBlockIndex(const BasicBlock *BB) const { 01933 Use *OL = OperandList; 01934 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2) 01935 if (OL[i+1].get() == BB) return i/2; 01936 return -1; 01937 } 01938 01939 Value *getIncomingValueForBlock(const BasicBlock *BB) const { 01940 return getIncomingValue(getBasicBlockIndex(BB)); 01941 } 01942 01943 /// hasConstantValue - If the specified PHI node always merges together the 01944 /// same value, return the value, otherwise return null. 01945 /// 01946 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const; 01947 01948 /// Methods for support type inquiry through isa, cast, and dyn_cast: 01949 static inline bool classof(const PHINode *) { return true; } 01950 static inline bool classof(const Instruction *I) { 01951 return I->getOpcode() == Instruction::PHI; 01952 } 01953 static inline bool classof(const Value *V) { 01954 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01955 } 01956 private: 01957 void resizeOperands(unsigned NumOperands); 01958 }; 01959 01960 template <> 01961 struct OperandTraits<PHINode> : HungoffOperandTraits<2> { 01962 }; 01963 01964 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value) 01965 01966 01967 //===----------------------------------------------------------------------===// 01968 // ReturnInst Class 01969 //===----------------------------------------------------------------------===// 01970 01971 //===--------------------------------------------------------------------------- 01972 /// ReturnInst - Return a value (possibly void), from a function. Execution 01973 /// does not continue in this function any longer. 01974 /// 01975 class ReturnInst : public TerminatorInst { 01976 ReturnInst(const ReturnInst &RI); 01977 01978 private: 01979 // ReturnInst constructors: 01980 // ReturnInst() - 'ret void' instruction 01981 // ReturnInst( null) - 'ret void' instruction 01982 // ReturnInst(Value* X) - 'ret X' instruction 01983 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I 01984 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I 01985 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B 01986 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B 01987 // 01988 // NOTE: If the Value* passed is of type void then the constructor behaves as 01989 // if it was passed NULL. 01990 explicit ReturnInst(LLVMContext &C, Value *retVal = 0, 01991 Instruction *InsertBefore = 0); 01992 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd); 01993 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd); 01994 public: 01995 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0, 01996 Instruction *InsertBefore = 0) { 01997 return new(!!retVal) ReturnInst(C, retVal, InsertBefore); 01998 } 01999 static ReturnInst* Create(LLVMContext &C, Value *retVal, 02000 BasicBlock *InsertAtEnd) { 02001 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd); 02002 } 02003 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) { 02004 return new(0) ReturnInst(C, InsertAtEnd); 02005 } 02006 virtual ~ReturnInst(); 02007 02008 virtual ReturnInst *clone(LLVMContext &Context) const; 02009 02010 /// Provide fast operand accessors 02011 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 02012 02013 /// Convenience accessor 02014 Value *getReturnValue(unsigned n = 0) const { 02015 return n < getNumOperands() 02016 ? getOperand(n) 02017 : 0; 02018 } 02019 02020 unsigned getNumSuccessors() const { return 0; } 02021 02022 // Methods for support type inquiry through isa, cast, and dyn_cast: 02023 static inline bool classof(const ReturnInst *) { return true; } 02024 static inline bool classof(const Instruction *I) { 02025 return (I->getOpcode() == Instruction::Ret); 02026 } 02027 static inline bool classof(const Value *V) { 02028 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02029 } 02030 private: 02031 virtual BasicBlock *getSuccessorV(unsigned idx) const; 02032 virtual unsigned getNumSuccessorsV() const; 02033 virtual void setSuccessorV(unsigned idx, BasicBlock *B); 02034 }; 02035 02036 template <> 02037 struct OperandTraits<ReturnInst> : OptionalOperandTraits<> { 02038 }; 02039 02040 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value) 02041 02042 //===----------------------------------------------------------------------===// 02043 // BranchInst Class 02044 //===----------------------------------------------------------------------===// 02045 02046 //===--------------------------------------------------------------------------- 02047 /// BranchInst - Conditional or Unconditional Branch instruction. 02048 /// 02049 class BranchInst : public TerminatorInst { 02050 /// Ops list - Branches are strange. The operands are ordered: 02051 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because 02052 /// they don't have to check for cond/uncond branchness. These are mostly 02053 /// accessed relative from op_end(). 02054 BranchInst(const BranchInst &BI); 02055 void AssertOK(); 02056 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition): 02057 // BranchInst(BB *B) - 'br B' 02058 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F' 02059 // BranchInst(BB* B, Inst *I) - 'br B' insert before I 02060 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I 02061 // BranchInst(BB* B, BB *I) - 'br B' insert at end 02062 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end 02063 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0); 02064 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, 02065 Instruction *InsertBefore = 0); 02066 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd); 02067 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, 02068 BasicBlock *InsertAtEnd); 02069 public: 02070 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) { 02071 return new(1, true) BranchInst(IfTrue, InsertBefore); 02072 } 02073 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, 02074 Value *Cond, Instruction *InsertBefore = 0) { 02075 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore); 02076 } 02077 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) { 02078 return new(1, true) BranchInst(IfTrue, InsertAtEnd); 02079 } 02080 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, 02081 Value *Cond, BasicBlock *InsertAtEnd) { 02082 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd); 02083 } 02084 02085 ~BranchInst(); 02086 02087 /// Transparently provide more efficient getOperand methods. 02088 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 02089 02090 virtual BranchInst *clone(LLVMContext &Context) const; 02091 02092 bool isUnconditional() const { return getNumOperands() == 1; } 02093 bool isConditional() const { return getNumOperands() == 3; } 02094 02095 Value *getCondition() const { 02096 assert(isConditional() && "Cannot get condition of an uncond branch!"); 02097 return Op<-3>(); 02098 } 02099 02100 void setCondition(Value *V) { 02101 assert(isConditional() && "Cannot set condition of unconditional branch!"); 02102 Op<-3>() = V; 02103 } 02104 02105 // setUnconditionalDest - Change the current branch to an unconditional branch 02106 // targeting the specified block. 02107 // FIXME: Eliminate this ugly method. 02108 void setUnconditionalDest(BasicBlock *Dest) { 02109 Op<-1>() = Dest; 02110 if (isConditional()) { // Convert this to an uncond branch. 02111 Op<-2>() = 0; 02112 Op<-3>() = 0; 02113 NumOperands = 1; 02114 OperandList = op_begin(); 02115 } 02116 } 02117 02118 unsigned getNumSuccessors() const { return 1+isConditional(); } 02119 02120 BasicBlock *getSuccessor(unsigned i) const { 02121 assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); 02122 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get()); 02123 } 02124 02125 void setSuccessor(unsigned idx, BasicBlock *NewSucc) { 02126 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!"); 02127 *(&Op<-1>() - idx) = NewSucc; 02128 } 02129 02130 // Methods for support type inquiry through isa, cast, and dyn_cast: 02131 static inline bool classof(const BranchInst *) { return true; } 02132 static inline bool classof(const Instruction *I) { 02133 return (I->getOpcode() == Instruction::Br); 02134 } 02135 static inline bool classof(const Value *V) { 02136 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02137 } 02138 private: 02139 virtual BasicBlock *getSuccessorV(unsigned idx) const; 02140 virtual unsigned getNumSuccessorsV() const; 02141 virtual void setSuccessorV(unsigned idx, BasicBlock *B); 02142 }; 02143 02144 template <> 02145 struct OperandTraits<BranchInst> : VariadicOperandTraits<1> {}; 02146 02147 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value) 02148 02149 //===----------------------------------------------------------------------===// 02150 // SwitchInst Class 02151 //===----------------------------------------------------------------------===// 02152 02153 //===--------------------------------------------------------------------------- 02154 /// SwitchInst - Multiway switch 02155 /// 02156 class SwitchInst : public TerminatorInst { 02157 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 02158 unsigned ReservedSpace; 02159 // Operand[0] = Value to switch on 02160 // Operand[1] = Default basic block destination 02161 // Operand[2n ] = Value to match 02162 // Operand[2n+1] = BasicBlock to go to on match 02163 SwitchInst(const SwitchInst &RI); 02164 void init(Value *Value, BasicBlock *Default, unsigned NumCases); 02165 void resizeOperands(unsigned No); 02166 // allocate space for exactly zero operands 02167 void *operator new(size_t s) { 02168 return User::operator new(s, 0); 02169 } 02170 /// SwitchInst ctor - Create a new switch instruction, specifying a value to 02171 /// switch on and a default destination. The number of additional cases can 02172 /// be specified here to make memory allocation more efficient. This 02173 /// constructor can also autoinsert before another instruction. 02174 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, 02175 Instruction *InsertBefore = 0); 02176 02177 /// SwitchInst ctor - Create a new switch instruction, specifying a value to 02178 /// switch on and a default destination. The number of additional cases can 02179 /// be specified here to make memory allocation more efficient. This 02180 /// constructor also autoinserts at the end of the specified BasicBlock. 02181 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, 02182 BasicBlock *InsertAtEnd); 02183 public: 02184 static SwitchInst *Create(Value *Value, BasicBlock *Default, 02185 unsigned NumCases, Instruction *InsertBefore = 0) { 02186 return new SwitchInst(Value, Default, NumCases, InsertBefore); 02187 } 02188 static SwitchInst *Create(Value *Value, BasicBlock *Default, 02189 unsigned NumCases, BasicBlock *InsertAtEnd) { 02190 return new SwitchInst(Value, Default, NumCases, InsertAtEnd); 02191 } 02192 ~SwitchInst(); 02193 02194 /// Provide fast operand accessors 02195 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 02196 02197 // Accessor Methods for Switch stmt 02198 Value *getCondition() const { return getOperand(0); } 02199 void setCondition(Value *V) { setOperand(0, V); } 02200 02201 BasicBlock *getDefaultDest() const { 02202 return cast<BasicBlock>(getOperand(1)); 02203 } 02204 02205 /// getNumCases - return the number of 'cases' in this switch instruction. 02206 /// Note that case #0 is always the default case. 02207 unsigned getNumCases() const { 02208 return getNumOperands()/2; 02209 } 02210 02211 /// getCaseValue - Return the specified case value. Note that case #0, the 02212 /// default destination, does not have a case value. 02213 ConstantInt *getCaseValue(unsigned i) { 02214 assert(i && i < getNumCases() && "Illegal case value to get!"); 02215 return getSuccessorValue(i); 02216 } 02217 02218 /// getCaseValue - Return the specified case value. Note that case #0, the 02219 /// default destination, does not have a case value. 02220 const ConstantInt *getCaseValue(unsigned i) const { 02221 assert(i && i < getNumCases() && "Illegal case value to get!"); 02222 return getSuccessorValue(i); 02223 } 02224 02225 /// findCaseValue - Search all of the case values for the specified constant. 02226 /// If it is explicitly handled, return the case number of it, otherwise 02227 /// return 0 to indicate that it is handled by the default handler. 02228 unsigned findCaseValue(const ConstantInt *C) const { 02229 for (unsigned i = 1, e = getNumCases(); i != e; ++i) 02230 if (getCaseValue(i) == C) 02231 return i; 02232 return 0; 02233 } 02234 02235 /// findCaseDest - Finds the unique case value for a given successor. Returns 02236 /// null if the successor is not found, not unique, or is the default case. 02237 ConstantInt *findCaseDest(BasicBlock *BB) { 02238 if (BB == getDefaultDest()) return NULL; 02239 02240 ConstantInt *CI = NULL; 02241 for (unsigned i = 1, e = getNumCases(); i != e; ++i) { 02242 if (getSuccessor(i) == BB) { 02243 if (CI) return NULL; // Multiple cases lead to BB. 02244 else CI = getCaseValue(i); 02245 } 02246 } 02247 return CI; 02248 } 02249 02250 /// addCase - Add an entry to the switch instruction... 02251 /// 02252 void addCase(ConstantInt *OnVal, BasicBlock *Dest); 02253 02254 /// removeCase - This method removes the specified successor from the switch 02255 /// instruction. Note that this cannot be used to remove the default 02256 /// destination (successor #0). 02257 /// 02258 void removeCase(unsigned idx); 02259 02260 virtual SwitchInst *clone(LLVMContext &Context) const; 02261 02262 unsigned getNumSuccessors() const { return getNumOperands()/2; } 02263 BasicBlock *getSuccessor(unsigned idx) const { 02264 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!"); 02265 return cast<BasicBlock>(getOperand(idx*2+1)); 02266 } 02267 void setSuccessor(unsigned idx, BasicBlock *NewSucc) { 02268 assert(idx < getNumSuccessors() && "Successor # out of range for switch!"); 02269 setOperand(idx*2+1, NewSucc); 02270 } 02271 02272 // getSuccessorValue - Return the value associated with the specified 02273 // successor. 02274 ConstantInt *getSuccessorValue(unsigned idx) const { 02275 assert(idx < getNumSuccessors() && "Successor # out of range!"); 02276 return reinterpret_cast<ConstantInt*>(getOperand(idx*2)); 02277 } 02278 02279 // Methods for support type inquiry through isa, cast, and dyn_cast: 02280 static inline bool classof(const SwitchInst *) { return true; } 02281 static inline bool classof(const Instruction *I) { 02282 return I->getOpcode() == Instruction::Switch; 02283 } 02284 static inline bool classof(const Value *V) { 02285 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02286 } 02287 private: 02288 virtual BasicBlock *getSuccessorV(unsigned idx) const; 02289 virtual unsigned getNumSuccessorsV() const; 02290 virtual void setSuccessorV(unsigned idx, BasicBlock *B); 02291 }; 02292 02293 template <> 02294 struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> { 02295 }; 02296 02297 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value) 02298 02299 02300 //===----------------------------------------------------------------------===// 02301 // InvokeInst Class 02302 //===----------------------------------------------------------------------===// 02303 02304 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the 02305 /// calling convention of the call. 02306 /// 02307 class InvokeInst : public TerminatorInst { 02308 AttrListPtr AttributeList; 02309 InvokeInst(const InvokeInst &BI); 02310 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, 02311 Value* const *Args, unsigned NumArgs); 02312 02313 template<typename InputIterator> 02314 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, 02315 InputIterator ArgBegin, InputIterator ArgEnd, 02316 const Twine &NameStr, 02317 // This argument ensures that we have an iterator we can 02318 // do arithmetic on in constant time 02319 std::random_access_iterator_tag) { 02320 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd); 02321 02322 // This requires that the iterator points to contiguous memory. 02323 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs); 02324 setName(NameStr); 02325 } 02326 02327 /// Construct an InvokeInst given a range of arguments. 02328 /// InputIterator must be a random-access iterator pointing to 02329 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are 02330 /// made for random-accessness but not for contiguous storage as 02331 /// that would incur runtime overhead. 02332 /// 02333 /// @brief Construct an InvokeInst from a range of arguments 02334 template<typename InputIterator> 02335 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, 02336 InputIterator ArgBegin, InputIterator ArgEnd, 02337 unsigned Values, 02338 const Twine &NameStr, Instruction *InsertBefore); 02339 02340 /// Construct an InvokeInst given a range of arguments. 02341 /// InputIterator must be a random-access iterator pointing to 02342 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are 02343 /// made for random-accessness but not for contiguous storage as 02344 /// that would incur runtime overhead. 02345 /// 02346 /// @brief Construct an InvokeInst from a range of arguments 02347 template<typename InputIterator> 02348 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, 02349 InputIterator ArgBegin, InputIterator ArgEnd, 02350 unsigned Values, 02351 const Twine &NameStr, BasicBlock *InsertAtEnd); 02352 public: 02353 template<typename InputIterator> 02354 static InvokeInst *Create(Value *Func, 02355 BasicBlock *IfNormal, BasicBlock *IfException, 02356 InputIterator ArgBegin, InputIterator ArgEnd, 02357 const Twine &NameStr = "", 02358 Instruction *InsertBefore = 0) { 02359 unsigned Values(ArgEnd - ArgBegin + 3); 02360 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, 02361 Values, NameStr, InsertBefore); 02362 } 02363 template<typename InputIterator> 02364 static InvokeInst *Create(Value *Func, 02365 BasicBlock *IfNormal, BasicBlock *IfException, 02366 InputIterator ArgBegin, InputIterator ArgEnd, 02367 const Twine &NameStr, 02368 BasicBlock *InsertAtEnd) { 02369 unsigned Values(ArgEnd - ArgBegin + 3); 02370 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, 02371 Values, NameStr, InsertAtEnd); 02372 } 02373 02374 virtual InvokeInst *clone(LLVMContext &Context) const; 02375 02376 /// Provide fast operand accessors 02377 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 02378 02379 /// getCallingConv/setCallingConv - Get or set the calling convention of this 02380 /// function call. 02381 unsigned getCallingConv() const { return SubclassData; } 02382 void setCallingConv(unsigned CC) { 02383 SubclassData = CC; 02384 } 02385 02386 /// getAttributes - Return the parameter attributes for this invoke. 02387 /// 02388 const AttrListPtr &getAttributes() const { return AttributeList; } 02389 02390 /// setAttributes - Set the parameter attributes for this invoke. 02391 /// 02392 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; } 02393 02394 /// addAttribute - adds the attribute to the list of attributes. 02395 void addAttribute(unsigned i, Attributes attr); 02396 02397 /// removeAttribute - removes the attribute from the list of attributes. 02398 void removeAttribute(unsigned i, Attributes attr); 02399 02400 /// @brief Determine whether the call or the callee has the given attribute. 02401 bool paramHasAttr(unsigned i, Attributes attr) const; 02402 02403 /// @brief Extract the alignment for a call or parameter (0=unknown). 02404 unsigned getParamAlignment(unsigned i) const { 02405 return AttributeList.getParamAlignment(i); 02406 } 02407 02408 /// @brief Determine if the call does not access memory. 02409 bool doesNotAccessMemory() const { 02410 return paramHasAttr(~0, Attribute::ReadNone); 02411 } 02412 void setDoesNotAccessMemory(bool NotAccessMemory = true) { 02413 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone); 02414 else removeAttribute(~0, Attribute::ReadNone); 02415 } 02416 02417 /// @brief Determine if the call does not access or only reads memory. 02418 bool onlyReadsMemory() const { 02419 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly); 02420 } 02421 void setOnlyReadsMemory(bool OnlyReadsMemory = true) { 02422 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly); 02423 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone); 02424 } 02425 02426 /// @brief Determine if the call cannot return. 02427 bool doesNotReturn() const { 02428 return paramHasAttr(~0, Attribute::NoReturn); 02429 } 02430 void setDoesNotReturn(bool DoesNotReturn = true) { 02431 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn); 02432 else removeAttribute(~0, Attribute::NoReturn); 02433 } 02434 02435 /// @brief Determine if the call cannot unwind. 02436 bool doesNotThrow() const { 02437 return paramHasAttr(~0, Attribute::NoUnwind); 02438 } 02439 void setDoesNotThrow(bool DoesNotThrow = true) { 02440 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind); 02441 else removeAttribute(~0, Attribute::NoUnwind); 02442 } 02443 02444 /// @brief Determine if the call returns a structure through first 02445 /// pointer argument. 02446 bool hasStructRetAttr() const { 02447 // Be friendly and also check the callee. 02448 return paramHasAttr(1, Attribute::StructRet); 02449 } 02450 02451 /// @brief Determine if any call argument is an aggregate passed by value. 02452 bool hasByValArgument() const { 02453 return AttributeList.hasAttrSomewhere(Attribute::ByVal); 02454 } 02455 02456 /// getCalledFunction - Return the function called, or null if this is an 02457 /// indirect function invocation. 02458 /// 02459 Function *getCalledFunction() const { 02460 return dyn_cast<Function>(getOperand(0)); 02461 } 02462 02463 /// getCalledValue - Get a pointer to the function that is invoked by this 02464 /// instruction 02465 const Value *getCalledValue() const { return getOperand(0); } 02466 Value *getCalledValue() { return getOperand(0); } 02467 02468 // get*Dest - Return the destination basic blocks... 02469 BasicBlock *getNormalDest() const { 02470 return cast<BasicBlock>(getOperand(1)); 02471 } 02472 BasicBlock *getUnwindDest() const { 02473 return cast<BasicBlock>(getOperand(2)); 02474 } 02475 void setNormalDest(BasicBlock *B) { 02476 setOperand(1, B); 02477 } 02478 02479 void setUnwindDest(BasicBlock *B) { 02480 setOperand(2, B); 02481 } 02482 02483 BasicBlock *getSuccessor(unsigned i) const { 02484 assert(i < 2 && "Successor # out of range for invoke!"); 02485 return i == 0 ? getNormalDest() : getUnwindDest(); 02486 } 02487 02488 void setSuccessor(unsigned idx, BasicBlock *NewSucc) { 02489 assert(idx < 2 && "Successor # out of range for invoke!"); 02490 setOperand(idx+1, NewSucc); 02491 } 02492 02493 unsigned getNumSuccessors() const { return 2; } 02494 02495 // Methods for support type inquiry through isa, cast, and dyn_cast: 02496 static inline bool classof(const InvokeInst *) { return true; } 02497 static inline bool classof(const Instruction *I) { 02498 return (I->getOpcode() == Instruction::Invoke); 02499 } 02500 static inline bool classof(const Value *V) { 02501 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02502 } 02503 private: 02504 virtual BasicBlock *getSuccessorV(unsigned idx) const; 02505 virtual unsigned getNumSuccessorsV() const; 02506 virtual void setSuccessorV(unsigned idx, BasicBlock *B); 02507 }; 02508 02509 template <> 02510 struct OperandTraits<InvokeInst> : VariadicOperandTraits<3> { 02511 }; 02512 02513 template<typename InputIterator> 02514 InvokeInst::InvokeInst(Value *Func, 02515 BasicBlock *IfNormal, BasicBlock *IfException, 02516 InputIterator ArgBegin, InputIterator ArgEnd, 02517 unsigned Values, 02518 const Twine &NameStr, Instruction *InsertBefore) 02519 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) 02520 ->getElementType())->getReturnType(), 02521 Instruction::Invoke, 02522 OperandTraits<InvokeInst>::op_end(this) - Values, 02523 Values, InsertBefore) { 02524 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr, 02525 typename std::iterator_traits<InputIterator>::iterator_category()); 02526 } 02527 template<typename InputIterator> 02528 InvokeInst::InvokeInst(Value *Func, 02529 BasicBlock *IfNormal, BasicBlock *IfException, 02530 InputIterator ArgBegin, InputIterator ArgEnd, 02531 unsigned Values, 02532 const Twine &NameStr, BasicBlock *InsertAtEnd) 02533 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) 02534 ->getElementType())->getReturnType(), 02535 Instruction::Invoke, 02536 OperandTraits<InvokeInst>::op_end(this) - Values, 02537 Values, InsertAtEnd) { 02538 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr, 02539 typename std::iterator_traits<InputIterator>::iterator_category()); 02540 } 02541 02542 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value) 02543 02544 //===----------------------------------------------------------------------===// 02545 // UnwindInst Class 02546 //===----------------------------------------------------------------------===// 02547 02548 //===--------------------------------------------------------------------------- 02549 /// UnwindInst - Immediately exit the current function, unwinding the stack 02550 /// until an invoke instruction is found. 02551 /// 02552 class UnwindInst : public TerminatorInst { 02553 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 02554 public: 02555 // allocate space for exactly zero operands 02556 void *operator new(size_t s) { 02557 return User::operator new(s, 0); 02558 } 02559 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0); 02560 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd); 02561 02562 virtual UnwindInst *clone(LLVMContext &Context) const; 02563 02564 unsigned getNumSuccessors() const { return 0; } 02565 02566 // Methods for support type inquiry through isa, cast, and dyn_cast: 02567 static inline bool classof(const UnwindInst *) { return true; } 02568 static inline bool classof(const Instruction *I) { 02569 return I->getOpcode() == Instruction::Unwind; 02570 } 02571 static inline bool classof(const Value *V) { 02572 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02573 } 02574 private: 02575 virtual BasicBlock *getSuccessorV(unsigned idx) const; 02576 virtual unsigned getNumSuccessorsV() const; 02577 virtual void setSuccessorV(unsigned idx, BasicBlock *B); 02578 }; 02579 02580 //===----------------------------------------------------------------------===// 02581 // UnreachableInst Class 02582 //===----------------------------------------------------------------------===// 02583 02584 //===--------------------------------------------------------------------------- 02585 /// UnreachableInst - This function has undefined behavior. In particular, the 02586 /// presence of this instruction indicates some higher level knowledge that the 02587 /// end of the block cannot be reached. 02588 /// 02589 class UnreachableInst : public TerminatorInst { 02590 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 02591 public: 02592 // allocate space for exactly zero operands 02593 void *operator new(size_t s) { 02594 return User::operator new(s, 0); 02595 } 02596 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0); 02597 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd); 02598 02599 virtual UnreachableInst *clone(LLVMContext &Context) const; 02600 02601 unsigned getNumSuccessors() const { return 0; } 02602 02603 // Methods for support type inquiry through isa, cast, and dyn_cast: 02604 static inline bool classof(const UnreachableInst *) { return true; } 02605 static inline bool classof(const Instruction *I) { 02606 return I->getOpcode() == Instruction::Unreachable; 02607 } 02608 static inline bool classof(const Value *V) { 02609 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02610 } 02611 private: 02612 virtual BasicBlock *getSuccessorV(unsigned idx) const; 02613 virtual unsigned getNumSuccessorsV() const; 02614 virtual void setSuccessorV(unsigned idx, BasicBlock *B); 02615 }; 02616 02617 //===----------------------------------------------------------------------===// 02618 // TruncInst Class 02619 //===----------------------------------------------------------------------===// 02620 02621 /// @brief This class represents a truncation of integer types. 02622 class TruncInst : public CastInst { 02623 public: 02624 /// @brief Constructor with insert-before-instruction semantics 02625 TruncInst( 02626 Value *S, ///< The value to be truncated 02627 const Type *Ty, ///< The (smaller) type to truncate to 02628 const Twine &NameStr = "", ///< A name for the new instruction 02629 Instruction *InsertBefore = 0 ///< Where to insert the new instruction 02630 ); 02631 02632 /// @brief Constructor with insert-at-end-of-block semantics 02633 TruncInst( 02634 Value *S, ///< The value to be truncated 02635 const Type *Ty, ///< The (smaller) type to truncate to 02636 const Twine &NameStr, ///< A name for the new instruction 02637 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 02638 ); 02639 02640 /// @brief Clone an identical TruncInst 02641 virtual CastInst *clone(LLVMContext &Context) const; 02642 02643 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: 02644 static inline bool classof(const TruncInst *) { return true; } 02645 static inline bool classof(const Instruction *I) { 02646 return I->getOpcode() == Trunc; 02647 } 02648 static inline bool classof(const Value *V) { 02649 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02650 } 02651 }; 02652 02653 //===----------------------------------------------------------------------===// 02654 // ZExtInst Class 02655 //===----------------------------------------------------------------------===// 02656 02657 /// @brief This class represents zero extension of integer types. 02658 class ZExtInst : public CastInst { 02659 public: 02660 /// @brief Constructor with insert-before-instruction semantics 02661 ZExtInst( 02662 Value *S, ///< The value to be zero extended 02663 const Type *Ty, ///< The type to zero extend to 02664 const Twine &NameStr = "", ///< A name for the new instruction 02665 Instruction *InsertBefore = 0 ///< Where to insert the new instruction 02666 ); 02667 02668 /// @brief Constructor with insert-at-end semantics. 02669 ZExtInst( 02670 Value *S, ///< The value to be zero extended 02671 const Type *Ty, ///< The type to zero extend to 02672 const Twine &NameStr, ///< A name for the new instruction 02673 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 02674 ); 02675 02676 /// @brief Clone an identical ZExtInst 02677 virtual CastInst *clone(LLVMContext &Context) const; 02678 02679 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: 02680 static inline bool classof(const ZExtInst *) { return true; } 02681 static inline bool classof(const Instruction *I) { 02682 return I->getOpcode() == ZExt; 02683 } 02684 static inline bool classof(const Value *V) { 02685 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02686 } 02687 }; 02688 02689 //===----------------------------------------------------------------------===// 02690 // SExtInst Class 02691 //===----------------------------------------------------------------------===// 02692 02693 /// @brief This class represents a sign extension of integer types. 02694 class SExtInst : public CastInst { 02695 public: 02696 /// @brief Constructor with insert-before-instruction semantics 02697 SExtInst( 02698 Value *S, ///< The value to be sign extended 02699 const Type *Ty, ///< The type to sign extend to 02700 const Twine &NameStr = "", ///< A name for the new instruction 02701 Instruction *InsertBefore = 0 ///< Where to insert the new instruction 02702 ); 02703 02704 /// @brief Constructor with insert-at-end-of-block semantics 02705 SExtInst( 02706 Value *S, ///< The value to be sign extended 02707 const Type *Ty, ///< The type to sign extend to 02708 const Twine &NameStr, ///< A name for the new instruction 02709 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 02710 ); 02711 02712 /// @brief Clone an identical SExtInst 02713 virtual CastInst *clone(LLVMContext &Context) const; 02714 02715 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: 02716 static inline bool classof(const SExtInst *) { return true; } 02717 static inline bool classof(const Instruction *I) { 02718 return I->getOpcode() == SExt; 02719 } 02720 static inline bool classof(const Value *V) { 02721 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02722 } 02723 }; 02724 02725 //===----------------------------------------------------------------------===// 02726 // FPTruncInst Class 02727 //===----------------------------------------------------------------------===// 02728 02729 /// @brief This class represents a truncation of floating point types. 02730 class FPTruncInst : public CastInst { 02731 public: 02732 /// @brief Constructor with insert-before-instruction semantics 02733 FPTruncInst( 02734 Value *S, ///< The value to be truncated 02735 const Type *Ty, ///< The type to truncate to 02736 const Twine &NameStr = "", ///< A name for the new instruction 02737 Instruction *InsertBefore = 0 ///< Where to insert the new instruction 02738 ); 02739 02740 /// @brief Constructor with insert-before-instruction semantics 02741 FPTruncInst( 02742 Value *S, ///< The value to be truncated 02743 const Type *Ty, ///< The type to truncate to 02744 const Twine &NameStr, ///< A name for the new instruction 02745 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 02746 ); 02747 02748 /// @brief Clone an identical FPTruncInst 02749 virtual CastInst *clone(LLVMContext &Context) const; 02750 02751 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: 02752 static inline bool classof(const FPTruncInst *) { return true; } 02753 static inline bool classof(const Instruction *I) { 02754 return I->getOpcode() == FPTrunc; 02755 } 02756 static inline bool classof(const Value *V) { 02757 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02758 } 02759 }; 02760 02761 //===----------------------------------------------------------------------===// 02762 // FPExtInst Class 02763 //===----------------------------------------------------------------------===// 02764 02765 /// @brief This class represents an extension of floating point types. 02766 class FPExtInst : public CastInst { 02767 public: 02768 /// @brief Constructor with insert-before-instruction semantics 02769 FPExtInst( 02770 Value *S, ///< The value to be extended 02771 const Type *Ty, ///< The type to extend to 02772 const Twine &NameStr = "", ///< A name for the new instruction 02773 Instruction *InsertBefore = 0 ///< Where to insert the new instruction 02774 ); 02775 02776 /// @brief Constructor with insert-at-end-of-block semantics 02777 FPExtInst( 02778 Value *S, ///< The value to be extended 02779 const Type *Ty, ///< The type to extend to 02780 const Twine &NameStr, ///< A name for the new instruction 02781 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 02782 ); 02783 02784 /// @brief Clone an identical FPExtInst 02785 virtual CastInst *clone(LLVMContext &Context) const; 02786 02787 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: 02788 static inline bool classof(const FPExtInst *) { return true; } 02789 static inline bool classof(const Instruction *I) { 02790 return I->getOpcode() == FPExt; 02791 } 02792 static inline bool classof(const Value *V) { 02793 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02794 } 02795 }; 02796 02797 //===----------------------------------------------------------------------===// 02798 // UIToFPInst Class 02799 //===----------------------------------------------------------------------===// 02800 02801 /// @brief This class represents a cast unsigned integer to floating point. 02802 class UIToFPInst : public CastInst { 02803 public: 02804 /// @brief Constructor with insert-before-instruction semantics 02805 UIToFPInst( 02806 Value *S, ///< The value to be converted 02807 const Type *Ty, ///< The type to convert to 02808 const Twine &NameStr = "", ///< A name for the new instruction 02809 Instruction *InsertBefore = 0 ///< Where to insert the new instruction 02810 ); 02811 02812 /// @brief Constructor with insert-at-end-of-block semantics 02813 UIToFPInst( 02814 Value *S, ///< The value to be converted 02815 const Type *Ty, ///< The type to convert to 02816 const Twine &NameStr, ///< A name for the new instruction 02817 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 02818 ); 02819 02820 /// @brief Clone an identical UIToFPInst 02821 virtual CastInst *clone(LLVMContext &Context) const; 02822 02823 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: 02824 static inline bool classof(const UIToFPInst *) { return true; } 02825 static inline bool classof(const Instruction *I) { 02826 return I->getOpcode() == UIToFP; 02827 } 02828 static inline bool classof(const Value *V) { 02829 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02830 } 02831 }; 02832 02833 //===----------------------------------------------------------------------===// 02834 // SIToFPInst Class 02835 //===----------------------------------------------------------------------===// 02836 02837 /// @brief This class represents a cast from signed integer to floating point. 02838 class SIToFPInst : public CastInst { 02839 public: 02840 /// @brief Constructor with insert-before-instruction semantics 02841 SIToFPInst( 02842 Value *S, ///< The value to be converted 02843 const Type *Ty, ///< The type to convert to 02844 const Twine &NameStr = "", ///< A name for the new instruction 02845 Instruction *InsertBefore = 0 ///< Where to insert the new instruction 02846 ); 02847 02848 /// @brief Constructor with insert-at-end-of-block semantics 02849 SIToFPInst( 02850 Value *S, ///< The value to be converted 02851 const Type *Ty, ///< The type to convert to 02852 const Twine &NameStr, ///< A name for the new instruction 02853 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 02854 ); 02855 02856 /// @brief Clone an identical SIToFPInst 02857 virtual CastInst *clone(LLVMContext &Context) const; 02858 02859 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: 02860 static inline bool classof(const SIToFPInst *) { return true; } 02861 static inline bool classof(const Instruction *I) { 02862 return I->getOpcode() == SIToFP; 02863 } 02864 static inline bool classof(const Value *V) { 02865 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02866 } 02867 }; 02868 02869 //===----------------------------------------------------------------------===// 02870 // FPToUIInst Class 02871 //===----------------------------------------------------------------------===// 02872 02873 /// @brief This class represents a cast from floating point to unsigned integer 02874 class FPToUIInst : public CastInst { 02875 public: 02876 /// @brief Constructor with insert-before-instruction semantics 02877 FPToUIInst( 02878 Value *S, ///< The value to be converted 02879 const Type *Ty, ///< The type to convert to 02880 const Twine &NameStr = "", ///< A name for the new instruction 02881 Instruction *InsertBefore = 0 ///< Where to insert the new instruction 02882 ); 02883 02884 /// @brief Constructor with insert-at-end-of-block semantics 02885 FPToUIInst( 02886 Value *S, ///< The value to be converted 02887 const Type *Ty, ///< The type to convert to 02888 const Twine &NameStr, ///< A name for the new instruction 02889 BasicBlock *InsertAtEnd ///< Where to insert the new instruction 02890 ); 02891 02892 /// @brief Clone an identical FPToUIInst 02893 virtual CastInst *clone(LLVMContext &Context) const; 02894 02895 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: 02896 static inline bool classof(const FPToUIInst *) { return true; } 02897 static inline bool classof(const Instruction *I) { 02898 return I->getOpcode() == FPToUI; 02899 } 02900 static inline bool classof(const Value *V) { 02901 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02902 } 02903 }; 02904 02905 //===----------------------------------------------------------------------===// 02906 // FPToSIInst Class 02907 //===----------------------------------------------------------------------===// 02908 02909 /// @brief This class represents a cast from floating point to signed integer. 02910 class FPToSIInst : public CastInst { 02911 public: 02912 /// @brief Constructor with insert-before-instruction semantics 02913 FPToSIInst( 02914 Value *S, ///< The value to be converted 02915 const Type *Ty, ///< The type to convert to 02916 const Twine &NameStr = "", ///< A name for the new instruction 02917 Instruction *InsertBefore = 0 ///< Where to insert the new instruction 02918 ); 02919 02920 /// @brief Constructor with insert-at-end-of-block semantics 02921 FPToSIInst( 02922 Value *S, ///< The value to be converted 02923 const Type *Ty, ///< The type to convert to 02924 const Twine &NameStr, ///< A name for the new instruction 02925 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 02926 ); 02927 02928 /// @brief Clone an identical FPToSIInst 02929 virtual CastInst *clone(LLVMContext &Context) const; 02930 02931 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: 02932 static inline bool classof(const FPToSIInst *) { return true; } 02933 static inline bool classof(const Instruction *I) { 02934 return I->getOpcode() == FPToSI; 02935 } 02936 static inline bool classof(const Value *V) { 02937 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02938 } 02939 }; 02940 02941 //===----------------------------------------------------------------------===// 02942 // IntToPtrInst Class 02943 //===----------------------------------------------------------------------===// 02944 02945 /// @brief This class represents a cast from an integer to a pointer. 02946 class IntToPtrInst : public CastInst { 02947 public: 02948 /// @brief Constructor with insert-before-instruction semantics 02949 IntToPtrInst( 02950 Value *S, ///< The value to be converted 02951 const Type *Ty, ///< The type to convert to 02952 const Twine &NameStr = "", ///< A name for the new instruction 02953 Instruction *InsertBefore = 0 ///< Where to insert the new instruction 02954 ); 02955 02956 /// @brief Constructor with insert-at-end-of-block semantics 02957 IntToPtrInst( 02958 Value *S, ///< The value to be converted 02959 const Type *Ty, ///< The type to convert to 02960 const Twine &NameStr, ///< A name for the new instruction 02961 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 02962 ); 02963 02964 /// @brief Clone an identical IntToPtrInst 02965 virtual CastInst *clone(LLVMContext &Context) const; 02966 02967 // Methods for support type inquiry through isa, cast, and dyn_cast: 02968 static inline bool classof(const IntToPtrInst *) { return true; } 02969 static inline bool classof(const Instruction *I) { 02970 return I->getOpcode() == IntToPtr; 02971 } 02972 static inline bool classof(const Value *V) { 02973 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02974 } 02975 }; 02976 02977 //===----------------------------------------------------------------------===// 02978 // PtrToIntInst Class 02979 //===----------------------------------------------------------------------===// 02980 02981 /// @brief This class represents a cast from a pointer to an integer 02982 class PtrToIntInst : public CastInst { 02983 public: 02984 /// @brief Constructor with insert-before-instruction semantics 02985 PtrToIntInst( 02986 Value *S, ///< The value to be converted 02987 const Type *Ty, ///< The type to convert to 02988 const Twine &NameStr = "", ///< A name for the new instruction 02989 Instruction *InsertBefore = 0 ///< Where to insert the new instruction 02990 ); 02991 02992 /// @brief Constructor with insert-at-end-of-block semantics 02993 PtrToIntInst( 02994 Value *S, ///< The value to be converted 02995 const Type *Ty, ///< The type to convert to 02996 const Twine &NameStr, ///< A name for the new instruction 02997 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 02998 ); 02999 03000 /// @brief Clone an identical PtrToIntInst 03001 virtual CastInst *clone(LLVMContext &Context) const; 03002 03003 // Methods for support type inquiry through isa, cast, and dyn_cast: 03004 static inline bool classof(const PtrToIntInst *) { return true; } 03005 static inline bool classof(const Instruction *I) { 03006 return I->getOpcode() == PtrToInt; 03007 } 03008 static inline bool classof(const Value *V) { 03009 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03010 } 03011 }; 03012 03013 //===----------------------------------------------------------------------===// 03014 // BitCastInst Class 03015 //===----------------------------------------------------------------------===// 03016 03017 /// @brief This class represents a no-op cast from one type to another. 03018 class BitCastInst : public CastInst { 03019 public: 03020 /// @brief Constructor with insert-before-instruction semantics 03021 BitCastInst( 03022 Value *S, ///< The value to be casted 03023 const Type *Ty, ///< The type to casted to 03024 const Twine &NameStr = "", ///< A name for the new instruction 03025 Instruction *InsertBefore = 0 ///< Where to insert the new instruction 03026 ); 03027 03028 /// @brief Constructor with insert-at-end-of-block semantics 03029 BitCastInst( 03030 Value *S, ///< The value to be casted 03031 const Type *Ty, ///< The type to casted to 03032 const Twine &NameStr, ///< A name for the new instruction 03033 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 03034 ); 03035 03036 /// @brief Clone an identical BitCastInst 03037 virtual CastInst *clone(LLVMContext &Context) const; 03038 03039 // Methods for support type inquiry through isa, cast, and dyn_cast: 03040 static inline bool classof(const BitCastInst *) { return true; } 03041 static inline bool classof(const Instruction *I) { 03042 return I->getOpcode() == BitCast; 03043 } 03044 static inline bool classof(const Value *V) { 03045 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03046 } 03047 }; 03048 03049 } // End llvm namespace 03050 03051 #endif