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_IR_INSTRUCTIONS_H 00017 #define LLVM_IR_INSTRUCTIONS_H 00018 00019 #include "llvm/ADT/ArrayRef.h" 00020 #include "llvm/ADT/iterator_range.h" 00021 #include "llvm/ADT/SmallVector.h" 00022 #include "llvm/IR/Attributes.h" 00023 #include "llvm/IR/CallingConv.h" 00024 #include "llvm/IR/DerivedTypes.h" 00025 #include "llvm/IR/InstrTypes.h" 00026 #include "llvm/Support/ErrorHandling.h" 00027 #include <iterator> 00028 00029 namespace llvm { 00030 00031 class APInt; 00032 class ConstantInt; 00033 class ConstantRange; 00034 class DataLayout; 00035 class LLVMContext; 00036 00037 enum AtomicOrdering { 00038 NotAtomic = 0, 00039 Unordered = 1, 00040 Monotonic = 2, 00041 // Consume = 3, // Not specified yet. 00042 Acquire = 4, 00043 Release = 5, 00044 AcquireRelease = 6, 00045 SequentiallyConsistent = 7 00046 }; 00047 00048 enum SynchronizationScope { 00049 SingleThread = 0, 00050 CrossThread = 1 00051 }; 00052 00053 /// Returns true if the ordering is at least as strong as acquire 00054 /// (i.e. acquire, acq_rel or seq_cst) 00055 inline bool isAtLeastAcquire(AtomicOrdering Ord) { 00056 return (Ord == Acquire || 00057 Ord == AcquireRelease || 00058 Ord == SequentiallyConsistent); 00059 } 00060 00061 /// Returns true if the ordering is at least as strong as release 00062 /// (i.e. release, acq_rel or seq_cst) 00063 inline bool isAtLeastRelease(AtomicOrdering Ord) { 00064 return (Ord == Release || 00065 Ord == AcquireRelease || 00066 Ord == SequentiallyConsistent); 00067 } 00068 00069 //===----------------------------------------------------------------------===// 00070 // AllocaInst Class 00071 //===----------------------------------------------------------------------===// 00072 00073 /// AllocaInst - an instruction to allocate memory on the stack 00074 /// 00075 class AllocaInst : public UnaryInstruction { 00076 protected: 00077 AllocaInst *clone_impl() const override; 00078 public: 00079 explicit AllocaInst(Type *Ty, Value *ArraySize = nullptr, 00080 const Twine &Name = "", 00081 Instruction *InsertBefore = nullptr); 00082 AllocaInst(Type *Ty, Value *ArraySize, 00083 const Twine &Name, BasicBlock *InsertAtEnd); 00084 00085 AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = nullptr); 00086 AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd); 00087 00088 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align, 00089 const Twine &Name = "", Instruction *InsertBefore = nullptr); 00090 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align, 00091 const Twine &Name, BasicBlock *InsertAtEnd); 00092 00093 // Out of line virtual method, so the vtable, etc. has a home. 00094 virtual ~AllocaInst(); 00095 00096 /// isArrayAllocation - Return true if there is an allocation size parameter 00097 /// to the allocation instruction that is not 1. 00098 /// 00099 bool isArrayAllocation() const; 00100 00101 /// getArraySize - Get the number of elements allocated. For a simple 00102 /// allocation of a single element, this will return a constant 1 value. 00103 /// 00104 const Value *getArraySize() const { return getOperand(0); } 00105 Value *getArraySize() { return getOperand(0); } 00106 00107 /// getType - Overload to return most specific pointer type 00108 /// 00109 PointerType *getType() const { 00110 return cast<PointerType>(Instruction::getType()); 00111 } 00112 00113 /// getAllocatedType - Return the type that is being allocated by the 00114 /// instruction. 00115 /// 00116 Type *getAllocatedType() const; 00117 00118 /// getAlignment - Return the alignment of the memory that is being allocated 00119 /// by the instruction. 00120 /// 00121 unsigned getAlignment() const { 00122 return (1u << (getSubclassDataFromInstruction() & 31)) >> 1; 00123 } 00124 void setAlignment(unsigned Align); 00125 00126 /// isStaticAlloca - Return true if this alloca is in the entry block of the 00127 /// function and is a constant size. If so, the code generator will fold it 00128 /// into the prolog/epilog code, so it is basically free. 00129 bool isStaticAlloca() const; 00130 00131 /// \brief Return true if this alloca is used as an inalloca argument to a 00132 /// call. Such allocas are never considered static even if they are in the 00133 /// entry block. 00134 bool isUsedWithInAlloca() const { 00135 return getSubclassDataFromInstruction() & 32; 00136 } 00137 00138 /// \brief Specify whether this alloca is used to represent the arguments to 00139 /// a call. 00140 void setUsedWithInAlloca(bool V) { 00141 setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) | 00142 (V ? 32 : 0)); 00143 } 00144 00145 // Methods for support type inquiry through isa, cast, and dyn_cast: 00146 static inline bool classof(const Instruction *I) { 00147 return (I->getOpcode() == Instruction::Alloca); 00148 } 00149 static inline bool classof(const Value *V) { 00150 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00151 } 00152 private: 00153 // Shadow Instruction::setInstructionSubclassData with a private forwarding 00154 // method so that subclasses cannot accidentally use it. 00155 void setInstructionSubclassData(unsigned short D) { 00156 Instruction::setInstructionSubclassData(D); 00157 } 00158 }; 00159 00160 00161 //===----------------------------------------------------------------------===// 00162 // LoadInst Class 00163 //===----------------------------------------------------------------------===// 00164 00165 /// LoadInst - an instruction for reading from memory. This uses the 00166 /// SubclassData field in Value to store whether or not the load is volatile. 00167 /// 00168 class LoadInst : public UnaryInstruction { 00169 void AssertOK(); 00170 protected: 00171 LoadInst *clone_impl() const override; 00172 public: 00173 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore); 00174 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd); 00175 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false, 00176 Instruction *InsertBefore = nullptr); 00177 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, 00178 BasicBlock *InsertAtEnd); 00179 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, 00180 unsigned Align, Instruction *InsertBefore = nullptr); 00181 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, 00182 unsigned Align, BasicBlock *InsertAtEnd); 00183 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, 00184 unsigned Align, AtomicOrdering Order, 00185 SynchronizationScope SynchScope = CrossThread, 00186 Instruction *InsertBefore = nullptr); 00187 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, 00188 unsigned Align, AtomicOrdering Order, 00189 SynchronizationScope SynchScope, 00190 BasicBlock *InsertAtEnd); 00191 00192 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore); 00193 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd); 00194 explicit LoadInst(Value *Ptr, const char *NameStr = nullptr, 00195 bool isVolatile = false, 00196 Instruction *InsertBefore = nullptr); 00197 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile, 00198 BasicBlock *InsertAtEnd); 00199 00200 /// isVolatile - Return true if this is a load from a volatile memory 00201 /// location. 00202 /// 00203 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; } 00204 00205 /// setVolatile - Specify whether this is a volatile load or not. 00206 /// 00207 void setVolatile(bool V) { 00208 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | 00209 (V ? 1 : 0)); 00210 } 00211 00212 /// getAlignment - Return the alignment of the access that is being performed 00213 /// 00214 unsigned getAlignment() const { 00215 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1; 00216 } 00217 00218 void setAlignment(unsigned Align); 00219 00220 /// Returns the ordering effect of this fence. 00221 AtomicOrdering getOrdering() const { 00222 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7); 00223 } 00224 00225 /// Set the ordering constraint on this load. May not be Release or 00226 /// AcquireRelease. 00227 void setOrdering(AtomicOrdering Ordering) { 00228 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) | 00229 (Ordering << 7)); 00230 } 00231 00232 SynchronizationScope getSynchScope() const { 00233 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1); 00234 } 00235 00236 /// Specify whether this load is ordered with respect to all 00237 /// concurrently executing threads, or only with respect to signal handlers 00238 /// executing in the same thread. 00239 void setSynchScope(SynchronizationScope xthread) { 00240 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) | 00241 (xthread << 6)); 00242 } 00243 00244 void setAtomic(AtomicOrdering Ordering, 00245 SynchronizationScope SynchScope = CrossThread) { 00246 setOrdering(Ordering); 00247 setSynchScope(SynchScope); 00248 } 00249 00250 bool isSimple() const { return !isAtomic() && !isVolatile(); } 00251 bool isUnordered() const { 00252 return getOrdering() <= Unordered && !isVolatile(); 00253 } 00254 00255 Value *getPointerOperand() { return getOperand(0); } 00256 const Value *getPointerOperand() const { return getOperand(0); } 00257 static unsigned getPointerOperandIndex() { return 0U; } 00258 00259 /// \brief Returns the address space of the pointer operand. 00260 unsigned getPointerAddressSpace() const { 00261 return getPointerOperand()->getType()->getPointerAddressSpace(); 00262 } 00263 00264 00265 // Methods for support type inquiry through isa, cast, and dyn_cast: 00266 static inline bool classof(const Instruction *I) { 00267 return I->getOpcode() == Instruction::Load; 00268 } 00269 static inline bool classof(const Value *V) { 00270 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00271 } 00272 private: 00273 // Shadow Instruction::setInstructionSubclassData with a private forwarding 00274 // method so that subclasses cannot accidentally use it. 00275 void setInstructionSubclassData(unsigned short D) { 00276 Instruction::setInstructionSubclassData(D); 00277 } 00278 }; 00279 00280 00281 //===----------------------------------------------------------------------===// 00282 // StoreInst Class 00283 //===----------------------------------------------------------------------===// 00284 00285 /// StoreInst - an instruction for storing to memory 00286 /// 00287 class StoreInst : public Instruction { 00288 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 00289 void AssertOK(); 00290 protected: 00291 StoreInst *clone_impl() const override; 00292 public: 00293 // allocate space for exactly two operands 00294 void *operator new(size_t s) { 00295 return User::operator new(s, 2); 00296 } 00297 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore); 00298 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd); 00299 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false, 00300 Instruction *InsertBefore = nullptr); 00301 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd); 00302 StoreInst(Value *Val, Value *Ptr, bool isVolatile, 00303 unsigned Align, Instruction *InsertBefore = nullptr); 00304 StoreInst(Value *Val, Value *Ptr, bool isVolatile, 00305 unsigned Align, BasicBlock *InsertAtEnd); 00306 StoreInst(Value *Val, Value *Ptr, bool isVolatile, 00307 unsigned Align, AtomicOrdering Order, 00308 SynchronizationScope SynchScope = CrossThread, 00309 Instruction *InsertBefore = nullptr); 00310 StoreInst(Value *Val, Value *Ptr, bool isVolatile, 00311 unsigned Align, AtomicOrdering Order, 00312 SynchronizationScope SynchScope, 00313 BasicBlock *InsertAtEnd); 00314 00315 00316 /// isVolatile - Return true if this is a store to a volatile memory 00317 /// location. 00318 /// 00319 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; } 00320 00321 /// setVolatile - Specify whether this is a volatile store or not. 00322 /// 00323 void setVolatile(bool V) { 00324 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | 00325 (V ? 1 : 0)); 00326 } 00327 00328 /// Transparently provide more efficient getOperand methods. 00329 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 00330 00331 /// getAlignment - Return the alignment of the access that is being performed 00332 /// 00333 unsigned getAlignment() const { 00334 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1; 00335 } 00336 00337 void setAlignment(unsigned Align); 00338 00339 /// Returns the ordering effect of this store. 00340 AtomicOrdering getOrdering() const { 00341 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7); 00342 } 00343 00344 /// Set the ordering constraint on this store. May not be Acquire or 00345 /// AcquireRelease. 00346 void setOrdering(AtomicOrdering Ordering) { 00347 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) | 00348 (Ordering << 7)); 00349 } 00350 00351 SynchronizationScope getSynchScope() const { 00352 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1); 00353 } 00354 00355 /// Specify whether this store instruction is ordered with respect to all 00356 /// concurrently executing threads, or only with respect to signal handlers 00357 /// executing in the same thread. 00358 void setSynchScope(SynchronizationScope xthread) { 00359 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) | 00360 (xthread << 6)); 00361 } 00362 00363 void setAtomic(AtomicOrdering Ordering, 00364 SynchronizationScope SynchScope = CrossThread) { 00365 setOrdering(Ordering); 00366 setSynchScope(SynchScope); 00367 } 00368 00369 bool isSimple() const { return !isAtomic() && !isVolatile(); } 00370 bool isUnordered() const { 00371 return getOrdering() <= Unordered && !isVolatile(); 00372 } 00373 00374 Value *getValueOperand() { return getOperand(0); } 00375 const Value *getValueOperand() const { return getOperand(0); } 00376 00377 Value *getPointerOperand() { return getOperand(1); } 00378 const Value *getPointerOperand() const { return getOperand(1); } 00379 static unsigned getPointerOperandIndex() { return 1U; } 00380 00381 /// \brief Returns the address space of the pointer operand. 00382 unsigned getPointerAddressSpace() const { 00383 return getPointerOperand()->getType()->getPointerAddressSpace(); 00384 } 00385 00386 // Methods for support type inquiry through isa, cast, and dyn_cast: 00387 static inline bool classof(const Instruction *I) { 00388 return I->getOpcode() == Instruction::Store; 00389 } 00390 static inline bool classof(const Value *V) { 00391 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00392 } 00393 private: 00394 // Shadow Instruction::setInstructionSubclassData with a private forwarding 00395 // method so that subclasses cannot accidentally use it. 00396 void setInstructionSubclassData(unsigned short D) { 00397 Instruction::setInstructionSubclassData(D); 00398 } 00399 }; 00400 00401 template <> 00402 struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> { 00403 }; 00404 00405 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value) 00406 00407 //===----------------------------------------------------------------------===// 00408 // FenceInst Class 00409 //===----------------------------------------------------------------------===// 00410 00411 /// FenceInst - an instruction for ordering other memory operations 00412 /// 00413 class FenceInst : public Instruction { 00414 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 00415 void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope); 00416 protected: 00417 FenceInst *clone_impl() const override; 00418 public: 00419 // allocate space for exactly zero operands 00420 void *operator new(size_t s) { 00421 return User::operator new(s, 0); 00422 } 00423 00424 // Ordering may only be Acquire, Release, AcquireRelease, or 00425 // SequentiallyConsistent. 00426 FenceInst(LLVMContext &C, AtomicOrdering Ordering, 00427 SynchronizationScope SynchScope = CrossThread, 00428 Instruction *InsertBefore = nullptr); 00429 FenceInst(LLVMContext &C, AtomicOrdering Ordering, 00430 SynchronizationScope SynchScope, 00431 BasicBlock *InsertAtEnd); 00432 00433 /// Returns the ordering effect of this fence. 00434 AtomicOrdering getOrdering() const { 00435 return AtomicOrdering(getSubclassDataFromInstruction() >> 1); 00436 } 00437 00438 /// Set the ordering constraint on this fence. May only be Acquire, Release, 00439 /// AcquireRelease, or SequentiallyConsistent. 00440 void setOrdering(AtomicOrdering Ordering) { 00441 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) | 00442 (Ordering << 1)); 00443 } 00444 00445 SynchronizationScope getSynchScope() const { 00446 return SynchronizationScope(getSubclassDataFromInstruction() & 1); 00447 } 00448 00449 /// Specify whether this fence orders other operations with respect to all 00450 /// concurrently executing threads, or only with respect to signal handlers 00451 /// executing in the same thread. 00452 void setSynchScope(SynchronizationScope xthread) { 00453 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | 00454 xthread); 00455 } 00456 00457 // Methods for support type inquiry through isa, cast, and dyn_cast: 00458 static inline bool classof(const Instruction *I) { 00459 return I->getOpcode() == Instruction::Fence; 00460 } 00461 static inline bool classof(const Value *V) { 00462 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00463 } 00464 private: 00465 // Shadow Instruction::setInstructionSubclassData with a private forwarding 00466 // method so that subclasses cannot accidentally use it. 00467 void setInstructionSubclassData(unsigned short D) { 00468 Instruction::setInstructionSubclassData(D); 00469 } 00470 }; 00471 00472 //===----------------------------------------------------------------------===// 00473 // AtomicCmpXchgInst Class 00474 //===----------------------------------------------------------------------===// 00475 00476 /// AtomicCmpXchgInst - an instruction that atomically checks whether a 00477 /// specified value is in a memory location, and, if it is, stores a new value 00478 /// there. Returns the value that was loaded. 00479 /// 00480 class AtomicCmpXchgInst : public Instruction { 00481 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 00482 void Init(Value *Ptr, Value *Cmp, Value *NewVal, 00483 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, 00484 SynchronizationScope SynchScope); 00485 protected: 00486 AtomicCmpXchgInst *clone_impl() const override; 00487 public: 00488 // allocate space for exactly three operands 00489 void *operator new(size_t s) { 00490 return User::operator new(s, 3); 00491 } 00492 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, 00493 AtomicOrdering SuccessOrdering, 00494 AtomicOrdering FailureOrdering, 00495 SynchronizationScope SynchScope, 00496 Instruction *InsertBefore = nullptr); 00497 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, 00498 AtomicOrdering SuccessOrdering, 00499 AtomicOrdering FailureOrdering, 00500 SynchronizationScope SynchScope, 00501 BasicBlock *InsertAtEnd); 00502 00503 /// isVolatile - Return true if this is a cmpxchg from a volatile memory 00504 /// location. 00505 /// 00506 bool isVolatile() const { 00507 return getSubclassDataFromInstruction() & 1; 00508 } 00509 00510 /// setVolatile - Specify whether this is a volatile cmpxchg. 00511 /// 00512 void setVolatile(bool V) { 00513 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | 00514 (unsigned)V); 00515 } 00516 00517 /// Return true if this cmpxchg may spuriously fail. 00518 bool isWeak() const { 00519 return getSubclassDataFromInstruction() & 0x100; 00520 } 00521 00522 void setWeak(bool IsWeak) { 00523 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x100) | 00524 (IsWeak << 8)); 00525 } 00526 00527 /// Transparently provide more efficient getOperand methods. 00528 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 00529 00530 /// Set the ordering constraint on this cmpxchg. 00531 void setSuccessOrdering(AtomicOrdering Ordering) { 00532 assert(Ordering != NotAtomic && 00533 "CmpXchg instructions can only be atomic."); 00534 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) | 00535 (Ordering << 2)); 00536 } 00537 00538 void setFailureOrdering(AtomicOrdering Ordering) { 00539 assert(Ordering != NotAtomic && 00540 "CmpXchg instructions can only be atomic."); 00541 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) | 00542 (Ordering << 5)); 00543 } 00544 00545 /// Specify whether this cmpxchg is atomic and orders other operations with 00546 /// respect to all concurrently executing threads, or only with respect to 00547 /// signal handlers executing in the same thread. 00548 void setSynchScope(SynchronizationScope SynchScope) { 00549 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) | 00550 (SynchScope << 1)); 00551 } 00552 00553 /// Returns the ordering constraint on this cmpxchg. 00554 AtomicOrdering getSuccessOrdering() const { 00555 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7); 00556 } 00557 00558 /// Returns the ordering constraint on this cmpxchg. 00559 AtomicOrdering getFailureOrdering() const { 00560 return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7); 00561 } 00562 00563 /// Returns whether this cmpxchg is atomic between threads or only within a 00564 /// single thread. 00565 SynchronizationScope getSynchScope() const { 00566 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1); 00567 } 00568 00569 Value *getPointerOperand() { return getOperand(0); } 00570 const Value *getPointerOperand() const { return getOperand(0); } 00571 static unsigned getPointerOperandIndex() { return 0U; } 00572 00573 Value *getCompareOperand() { return getOperand(1); } 00574 const Value *getCompareOperand() const { return getOperand(1); } 00575 00576 Value *getNewValOperand() { return getOperand(2); } 00577 const Value *getNewValOperand() const { return getOperand(2); } 00578 00579 /// \brief Returns the address space of the pointer operand. 00580 unsigned getPointerAddressSpace() const { 00581 return getPointerOperand()->getType()->getPointerAddressSpace(); 00582 } 00583 00584 /// \brief Returns the strongest permitted ordering on failure, given the 00585 /// desired ordering on success. 00586 /// 00587 /// If the comparison in a cmpxchg operation fails, there is no atomic store 00588 /// so release semantics cannot be provided. So this function drops explicit 00589 /// Release requests from the AtomicOrdering. A SequentiallyConsistent 00590 /// operation would remain SequentiallyConsistent. 00591 static AtomicOrdering 00592 getStrongestFailureOrdering(AtomicOrdering SuccessOrdering) { 00593 switch (SuccessOrdering) { 00594 default: llvm_unreachable("invalid cmpxchg success ordering"); 00595 case Release: 00596 case Monotonic: 00597 return Monotonic; 00598 case AcquireRelease: 00599 case Acquire: 00600 return Acquire; 00601 case SequentiallyConsistent: 00602 return SequentiallyConsistent; 00603 } 00604 } 00605 00606 // Methods for support type inquiry through isa, cast, and dyn_cast: 00607 static inline bool classof(const Instruction *I) { 00608 return I->getOpcode() == Instruction::AtomicCmpXchg; 00609 } 00610 static inline bool classof(const Value *V) { 00611 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00612 } 00613 private: 00614 // Shadow Instruction::setInstructionSubclassData with a private forwarding 00615 // method so that subclasses cannot accidentally use it. 00616 void setInstructionSubclassData(unsigned short D) { 00617 Instruction::setInstructionSubclassData(D); 00618 } 00619 }; 00620 00621 template <> 00622 struct OperandTraits<AtomicCmpXchgInst> : 00623 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> { 00624 }; 00625 00626 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value) 00627 00628 //===----------------------------------------------------------------------===// 00629 // AtomicRMWInst Class 00630 //===----------------------------------------------------------------------===// 00631 00632 /// AtomicRMWInst - an instruction that atomically reads a memory location, 00633 /// combines it with another value, and then stores the result back. Returns 00634 /// the old value. 00635 /// 00636 class AtomicRMWInst : public Instruction { 00637 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 00638 protected: 00639 AtomicRMWInst *clone_impl() const override; 00640 public: 00641 /// This enumeration lists the possible modifications atomicrmw can make. In 00642 /// the descriptions, 'p' is the pointer to the instruction's memory location, 00643 /// 'old' is the initial value of *p, and 'v' is the other value passed to the 00644 /// instruction. These instructions always return 'old'. 00645 enum BinOp { 00646 /// *p = v 00647 Xchg, 00648 /// *p = old + v 00649 Add, 00650 /// *p = old - v 00651 Sub, 00652 /// *p = old & v 00653 And, 00654 /// *p = ~old & v 00655 Nand, 00656 /// *p = old | v 00657 Or, 00658 /// *p = old ^ v 00659 Xor, 00660 /// *p = old >signed v ? old : v 00661 Max, 00662 /// *p = old <signed v ? old : v 00663 Min, 00664 /// *p = old >unsigned v ? old : v 00665 UMax, 00666 /// *p = old <unsigned v ? old : v 00667 UMin, 00668 00669 FIRST_BINOP = Xchg, 00670 LAST_BINOP = UMin, 00671 BAD_BINOP 00672 }; 00673 00674 // allocate space for exactly two operands 00675 void *operator new(size_t s) { 00676 return User::operator new(s, 2); 00677 } 00678 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, 00679 AtomicOrdering Ordering, SynchronizationScope SynchScope, 00680 Instruction *InsertBefore = nullptr); 00681 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, 00682 AtomicOrdering Ordering, SynchronizationScope SynchScope, 00683 BasicBlock *InsertAtEnd); 00684 00685 BinOp getOperation() const { 00686 return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5); 00687 } 00688 00689 void setOperation(BinOp Operation) { 00690 unsigned short SubclassData = getSubclassDataFromInstruction(); 00691 setInstructionSubclassData((SubclassData & 31) | 00692 (Operation << 5)); 00693 } 00694 00695 /// isVolatile - Return true if this is a RMW on a volatile memory location. 00696 /// 00697 bool isVolatile() const { 00698 return getSubclassDataFromInstruction() & 1; 00699 } 00700 00701 /// setVolatile - Specify whether this is a volatile RMW or not. 00702 /// 00703 void setVolatile(bool V) { 00704 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | 00705 (unsigned)V); 00706 } 00707 00708 /// Transparently provide more efficient getOperand methods. 00709 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 00710 00711 /// Set the ordering constraint on this RMW. 00712 void setOrdering(AtomicOrdering Ordering) { 00713 assert(Ordering != NotAtomic && 00714 "atomicrmw instructions can only be atomic."); 00715 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) | 00716 (Ordering << 2)); 00717 } 00718 00719 /// Specify whether this RMW orders other operations with respect to all 00720 /// concurrently executing threads, or only with respect to signal handlers 00721 /// executing in the same thread. 00722 void setSynchScope(SynchronizationScope SynchScope) { 00723 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) | 00724 (SynchScope << 1)); 00725 } 00726 00727 /// Returns the ordering constraint on this RMW. 00728 AtomicOrdering getOrdering() const { 00729 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7); 00730 } 00731 00732 /// Returns whether this RMW is atomic between threads or only within a 00733 /// single thread. 00734 SynchronizationScope getSynchScope() const { 00735 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1); 00736 } 00737 00738 Value *getPointerOperand() { return getOperand(0); } 00739 const Value *getPointerOperand() const { return getOperand(0); } 00740 static unsigned getPointerOperandIndex() { return 0U; } 00741 00742 Value *getValOperand() { return getOperand(1); } 00743 const Value *getValOperand() const { return getOperand(1); } 00744 00745 /// \brief Returns the address space of the pointer operand. 00746 unsigned getPointerAddressSpace() const { 00747 return getPointerOperand()->getType()->getPointerAddressSpace(); 00748 } 00749 00750 // Methods for support type inquiry through isa, cast, and dyn_cast: 00751 static inline bool classof(const Instruction *I) { 00752 return I->getOpcode() == Instruction::AtomicRMW; 00753 } 00754 static inline bool classof(const Value *V) { 00755 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00756 } 00757 private: 00758 void Init(BinOp Operation, Value *Ptr, Value *Val, 00759 AtomicOrdering Ordering, SynchronizationScope SynchScope); 00760 // Shadow Instruction::setInstructionSubclassData with a private forwarding 00761 // method so that subclasses cannot accidentally use it. 00762 void setInstructionSubclassData(unsigned short D) { 00763 Instruction::setInstructionSubclassData(D); 00764 } 00765 }; 00766 00767 template <> 00768 struct OperandTraits<AtomicRMWInst> 00769 : public FixedNumOperandTraits<AtomicRMWInst,2> { 00770 }; 00771 00772 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value) 00773 00774 //===----------------------------------------------------------------------===// 00775 // GetElementPtrInst Class 00776 //===----------------------------------------------------------------------===// 00777 00778 // checkGEPType - Simple wrapper function to give a better assertion failure 00779 // message on bad indexes for a gep instruction. 00780 // 00781 inline Type *checkGEPType(Type *Ty) { 00782 assert(Ty && "Invalid GetElementPtrInst indices for type!"); 00783 return Ty; 00784 } 00785 00786 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to 00787 /// access elements of arrays and structs 00788 /// 00789 class GetElementPtrInst : public Instruction { 00790 GetElementPtrInst(const GetElementPtrInst &GEPI); 00791 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr); 00792 00793 /// Constructors - Create a getelementptr instruction with a base pointer an 00794 /// list of indices. The first ctor can optionally insert before an existing 00795 /// instruction, the second appends the new instruction to the specified 00796 /// BasicBlock. 00797 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList, 00798 unsigned Values, const Twine &NameStr, 00799 Instruction *InsertBefore); 00800 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList, 00801 unsigned Values, const Twine &NameStr, 00802 BasicBlock *InsertAtEnd); 00803 protected: 00804 GetElementPtrInst *clone_impl() const override; 00805 public: 00806 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList, 00807 const Twine &NameStr = "", 00808 Instruction *InsertBefore = nullptr) { 00809 unsigned Values = 1 + unsigned(IdxList.size()); 00810 return new(Values) 00811 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore); 00812 } 00813 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList, 00814 const Twine &NameStr, 00815 BasicBlock *InsertAtEnd) { 00816 unsigned Values = 1 + unsigned(IdxList.size()); 00817 return new(Values) 00818 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd); 00819 } 00820 00821 /// Create an "inbounds" getelementptr. See the documentation for the 00822 /// "inbounds" flag in LangRef.html for details. 00823 static GetElementPtrInst *CreateInBounds(Value *Ptr, 00824 ArrayRef<Value *> IdxList, 00825 const Twine &NameStr = "", 00826 Instruction *InsertBefore = nullptr){ 00827 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore); 00828 GEP->setIsInBounds(true); 00829 return GEP; 00830 } 00831 static GetElementPtrInst *CreateInBounds(Value *Ptr, 00832 ArrayRef<Value *> IdxList, 00833 const Twine &NameStr, 00834 BasicBlock *InsertAtEnd) { 00835 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd); 00836 GEP->setIsInBounds(true); 00837 return GEP; 00838 } 00839 00840 /// Transparently provide more efficient getOperand methods. 00841 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 00842 00843 // getType - Overload to return most specific sequential type. 00844 SequentialType *getType() const { 00845 return cast<SequentialType>(Instruction::getType()); 00846 } 00847 00848 /// \brief Returns the address space of this instruction's pointer type. 00849 unsigned getAddressSpace() const { 00850 // Note that this is always the same as the pointer operand's address space 00851 // and that is cheaper to compute, so cheat here. 00852 return getPointerAddressSpace(); 00853 } 00854 00855 /// getIndexedType - Returns the type of the element that would be loaded with 00856 /// a load instruction with the specified parameters. 00857 /// 00858 /// Null is returned if the indices are invalid for the specified 00859 /// pointer type. 00860 /// 00861 static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList); 00862 static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList); 00863 static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList); 00864 00865 inline op_iterator idx_begin() { return op_begin()+1; } 00866 inline const_op_iterator idx_begin() const { return op_begin()+1; } 00867 inline op_iterator idx_end() { return op_end(); } 00868 inline const_op_iterator idx_end() const { return op_end(); } 00869 00870 Value *getPointerOperand() { 00871 return getOperand(0); 00872 } 00873 const Value *getPointerOperand() const { 00874 return getOperand(0); 00875 } 00876 static unsigned getPointerOperandIndex() { 00877 return 0U; // get index for modifying correct operand. 00878 } 00879 00880 /// getPointerOperandType - Method to return the pointer operand as a 00881 /// PointerType. 00882 Type *getPointerOperandType() const { 00883 return getPointerOperand()->getType(); 00884 } 00885 00886 /// \brief Returns the address space of the pointer operand. 00887 unsigned getPointerAddressSpace() const { 00888 return getPointerOperandType()->getPointerAddressSpace(); 00889 } 00890 00891 /// GetGEPReturnType - Returns the pointer type returned by the GEP 00892 /// instruction, which may be a vector of pointers. 00893 static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) { 00894 Type *PtrTy = PointerType::get(checkGEPType( 00895 getIndexedType(Ptr->getType(), IdxList)), 00896 Ptr->getType()->getPointerAddressSpace()); 00897 // Vector GEP 00898 if (Ptr->getType()->isVectorTy()) { 00899 unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements(); 00900 return VectorType::get(PtrTy, NumElem); 00901 } 00902 00903 // Scalar GEP 00904 return PtrTy; 00905 } 00906 00907 unsigned getNumIndices() const { // Note: always non-negative 00908 return getNumOperands() - 1; 00909 } 00910 00911 bool hasIndices() const { 00912 return getNumOperands() > 1; 00913 } 00914 00915 /// hasAllZeroIndices - Return true if all of the indices of this GEP are 00916 /// zeros. If so, the result pointer and the first operand have the same 00917 /// value, just potentially different types. 00918 bool hasAllZeroIndices() const; 00919 00920 /// hasAllConstantIndices - Return true if all of the indices of this GEP are 00921 /// constant integers. If so, the result pointer and the first operand have 00922 /// a constant offset between them. 00923 bool hasAllConstantIndices() const; 00924 00925 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction. 00926 /// See LangRef.html for the meaning of inbounds on a getelementptr. 00927 void setIsInBounds(bool b = true); 00928 00929 /// isInBounds - Determine whether the GEP has the inbounds flag. 00930 bool isInBounds() const; 00931 00932 /// \brief Accumulate the constant address offset of this GEP if possible. 00933 /// 00934 /// This routine accepts an APInt into which it will accumulate the constant 00935 /// offset of this GEP if the GEP is in fact constant. If the GEP is not 00936 /// all-constant, it returns false and the value of the offset APInt is 00937 /// undefined (it is *not* preserved!). The APInt passed into this routine 00938 /// must be at least as wide as the IntPtr type for the address space of 00939 /// the base GEP pointer. 00940 bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const; 00941 00942 // Methods for support type inquiry through isa, cast, and dyn_cast: 00943 static inline bool classof(const Instruction *I) { 00944 return (I->getOpcode() == Instruction::GetElementPtr); 00945 } 00946 static inline bool classof(const Value *V) { 00947 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 00948 } 00949 }; 00950 00951 template <> 00952 struct OperandTraits<GetElementPtrInst> : 00953 public VariadicOperandTraits<GetElementPtrInst, 1> { 00954 }; 00955 00956 GetElementPtrInst::GetElementPtrInst(Value *Ptr, 00957 ArrayRef<Value *> IdxList, 00958 unsigned Values, 00959 const Twine &NameStr, 00960 Instruction *InsertBefore) 00961 : Instruction(getGEPReturnType(Ptr, IdxList), 00962 GetElementPtr, 00963 OperandTraits<GetElementPtrInst>::op_end(this) - Values, 00964 Values, InsertBefore) { 00965 init(Ptr, IdxList, NameStr); 00966 } 00967 GetElementPtrInst::GetElementPtrInst(Value *Ptr, 00968 ArrayRef<Value *> IdxList, 00969 unsigned Values, 00970 const Twine &NameStr, 00971 BasicBlock *InsertAtEnd) 00972 : Instruction(getGEPReturnType(Ptr, IdxList), 00973 GetElementPtr, 00974 OperandTraits<GetElementPtrInst>::op_end(this) - Values, 00975 Values, InsertAtEnd) { 00976 init(Ptr, IdxList, NameStr); 00977 } 00978 00979 00980 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value) 00981 00982 00983 //===----------------------------------------------------------------------===// 00984 // ICmpInst Class 00985 //===----------------------------------------------------------------------===// 00986 00987 /// This instruction compares its operands according to the predicate given 00988 /// to the constructor. It only operates on integers or pointers. The operands 00989 /// must be identical types. 00990 /// \brief Represent an integer comparison operator. 00991 class ICmpInst: public CmpInst { 00992 void AssertOK() { 00993 assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE && 00994 getPredicate() <= CmpInst::LAST_ICMP_PREDICATE && 00995 "Invalid ICmp predicate value"); 00996 assert(getOperand(0)->getType() == getOperand(1)->getType() && 00997 "Both operands to ICmp instruction are not of the same type!"); 00998 // Check that the operands are the right type 00999 assert((getOperand(0)->getType()->isIntOrIntVectorTy() || 01000 getOperand(0)->getType()->isPtrOrPtrVectorTy()) && 01001 "Invalid operand types for ICmp instruction"); 01002 } 01003 01004 protected: 01005 /// \brief Clone an identical ICmpInst 01006 ICmpInst *clone_impl() const override; 01007 public: 01008 /// \brief Constructor with insert-before-instruction semantics. 01009 ICmpInst( 01010 Instruction *InsertBefore, ///< Where to insert 01011 Predicate pred, ///< The predicate to use for the comparison 01012 Value *LHS, ///< The left-hand-side of the expression 01013 Value *RHS, ///< The right-hand-side of the expression 01014 const Twine &NameStr = "" ///< Name of the instruction 01015 ) : CmpInst(makeCmpResultType(LHS->getType()), 01016 Instruction::ICmp, pred, LHS, RHS, NameStr, 01017 InsertBefore) { 01018 #ifndef NDEBUG 01019 AssertOK(); 01020 #endif 01021 } 01022 01023 /// \brief Constructor with insert-at-end semantics. 01024 ICmpInst( 01025 BasicBlock &InsertAtEnd, ///< Block to insert into. 01026 Predicate pred, ///< The predicate to use for the comparison 01027 Value *LHS, ///< The left-hand-side of the expression 01028 Value *RHS, ///< The right-hand-side of the expression 01029 const Twine &NameStr = "" ///< Name of the instruction 01030 ) : CmpInst(makeCmpResultType(LHS->getType()), 01031 Instruction::ICmp, pred, LHS, RHS, NameStr, 01032 &InsertAtEnd) { 01033 #ifndef NDEBUG 01034 AssertOK(); 01035 #endif 01036 } 01037 01038 /// \brief Constructor with no-insertion semantics 01039 ICmpInst( 01040 Predicate pred, ///< The predicate to use for the comparison 01041 Value *LHS, ///< The left-hand-side of the expression 01042 Value *RHS, ///< The right-hand-side of the expression 01043 const Twine &NameStr = "" ///< Name of the instruction 01044 ) : CmpInst(makeCmpResultType(LHS->getType()), 01045 Instruction::ICmp, pred, LHS, RHS, NameStr) { 01046 #ifndef NDEBUG 01047 AssertOK(); 01048 #endif 01049 } 01050 01051 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc. 01052 /// @returns the predicate that would be the result if the operand were 01053 /// regarded as signed. 01054 /// \brief Return the signed version of the predicate 01055 Predicate getSignedPredicate() const { 01056 return getSignedPredicate(getPredicate()); 01057 } 01058 01059 /// This is a static version that you can use without an instruction. 01060 /// \brief Return the signed version of the predicate. 01061 static Predicate getSignedPredicate(Predicate pred); 01062 01063 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc. 01064 /// @returns the predicate that would be the result if the operand were 01065 /// regarded as unsigned. 01066 /// \brief Return the unsigned version of the predicate 01067 Predicate getUnsignedPredicate() const { 01068 return getUnsignedPredicate(getPredicate()); 01069 } 01070 01071 /// This is a static version that you can use without an instruction. 01072 /// \brief Return the unsigned version of the predicate. 01073 static Predicate getUnsignedPredicate(Predicate pred); 01074 01075 /// isEquality - Return true if this predicate is either EQ or NE. This also 01076 /// tests for commutativity. 01077 static bool isEquality(Predicate P) { 01078 return P == ICMP_EQ || P == ICMP_NE; 01079 } 01080 01081 /// isEquality - Return true if this predicate is either EQ or NE. This also 01082 /// tests for commutativity. 01083 bool isEquality() const { 01084 return isEquality(getPredicate()); 01085 } 01086 01087 /// @returns true if the predicate of this ICmpInst is commutative 01088 /// \brief Determine if this relation is commutative. 01089 bool isCommutative() const { return isEquality(); } 01090 01091 /// isRelational - Return true if the predicate is relational (not EQ or NE). 01092 /// 01093 bool isRelational() const { 01094 return !isEquality(); 01095 } 01096 01097 /// isRelational - Return true if the predicate is relational (not EQ or NE). 01098 /// 01099 static bool isRelational(Predicate P) { 01100 return !isEquality(P); 01101 } 01102 01103 /// Initialize a set of values that all satisfy the predicate with C. 01104 /// \brief Make a ConstantRange for a relation with a constant value. 01105 static ConstantRange makeConstantRange(Predicate pred, const APInt &C); 01106 01107 /// Exchange the two operands to this instruction in such a way that it does 01108 /// not modify the semantics of the instruction. The predicate value may be 01109 /// changed to retain the same result if the predicate is order dependent 01110 /// (e.g. ult). 01111 /// \brief Swap operands and adjust predicate. 01112 void swapOperands() { 01113 setPredicate(getSwappedPredicate()); 01114 Op<0>().swap(Op<1>()); 01115 } 01116 01117 // Methods for support type inquiry through isa, cast, and dyn_cast: 01118 static inline bool classof(const Instruction *I) { 01119 return I->getOpcode() == Instruction::ICmp; 01120 } 01121 static inline bool classof(const Value *V) { 01122 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01123 } 01124 01125 }; 01126 01127 //===----------------------------------------------------------------------===// 01128 // FCmpInst Class 01129 //===----------------------------------------------------------------------===// 01130 01131 /// This instruction compares its operands according to the predicate given 01132 /// to the constructor. It only operates on floating point values or packed 01133 /// vectors of floating point values. The operands must be identical types. 01134 /// \brief Represents a floating point comparison operator. 01135 class FCmpInst: public CmpInst { 01136 protected: 01137 /// \brief Clone an identical FCmpInst 01138 FCmpInst *clone_impl() const override; 01139 public: 01140 /// \brief Constructor with insert-before-instruction semantics. 01141 FCmpInst( 01142 Instruction *InsertBefore, ///< Where to insert 01143 Predicate pred, ///< The predicate to use for the comparison 01144 Value *LHS, ///< The left-hand-side of the expression 01145 Value *RHS, ///< The right-hand-side of the expression 01146 const Twine &NameStr = "" ///< Name of the instruction 01147 ) : CmpInst(makeCmpResultType(LHS->getType()), 01148 Instruction::FCmp, pred, LHS, RHS, NameStr, 01149 InsertBefore) { 01150 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && 01151 "Invalid FCmp predicate value"); 01152 assert(getOperand(0)->getType() == getOperand(1)->getType() && 01153 "Both operands to FCmp instruction are not of the same type!"); 01154 // Check that the operands are the right type 01155 assert(getOperand(0)->getType()->isFPOrFPVectorTy() && 01156 "Invalid operand types for FCmp instruction"); 01157 } 01158 01159 /// \brief Constructor with insert-at-end semantics. 01160 FCmpInst( 01161 BasicBlock &InsertAtEnd, ///< Block to insert into. 01162 Predicate pred, ///< The predicate to use for the comparison 01163 Value *LHS, ///< The left-hand-side of the expression 01164 Value *RHS, ///< The right-hand-side of the expression 01165 const Twine &NameStr = "" ///< Name of the instruction 01166 ) : CmpInst(makeCmpResultType(LHS->getType()), 01167 Instruction::FCmp, pred, LHS, RHS, NameStr, 01168 &InsertAtEnd) { 01169 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && 01170 "Invalid FCmp predicate value"); 01171 assert(getOperand(0)->getType() == getOperand(1)->getType() && 01172 "Both operands to FCmp instruction are not of the same type!"); 01173 // Check that the operands are the right type 01174 assert(getOperand(0)->getType()->isFPOrFPVectorTy() && 01175 "Invalid operand types for FCmp instruction"); 01176 } 01177 01178 /// \brief Constructor with no-insertion semantics 01179 FCmpInst( 01180 Predicate pred, ///< The predicate to use for the comparison 01181 Value *LHS, ///< The left-hand-side of the expression 01182 Value *RHS, ///< The right-hand-side of the expression 01183 const Twine &NameStr = "" ///< Name of the instruction 01184 ) : CmpInst(makeCmpResultType(LHS->getType()), 01185 Instruction::FCmp, pred, LHS, RHS, NameStr) { 01186 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && 01187 "Invalid FCmp predicate value"); 01188 assert(getOperand(0)->getType() == getOperand(1)->getType() && 01189 "Both operands to FCmp instruction are not of the same type!"); 01190 // Check that the operands are the right type 01191 assert(getOperand(0)->getType()->isFPOrFPVectorTy() && 01192 "Invalid operand types for FCmp instruction"); 01193 } 01194 01195 /// @returns true if the predicate of this instruction is EQ or NE. 01196 /// \brief Determine if this is an equality predicate. 01197 bool isEquality() const { 01198 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE || 01199 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE; 01200 } 01201 01202 /// @returns true if the predicate of this instruction is commutative. 01203 /// \brief Determine if this is a commutative predicate. 01204 bool isCommutative() const { 01205 return isEquality() || 01206 getPredicate() == FCMP_FALSE || 01207 getPredicate() == FCMP_TRUE || 01208 getPredicate() == FCMP_ORD || 01209 getPredicate() == FCMP_UNO; 01210 } 01211 01212 /// @returns true if the predicate is relational (not EQ or NE). 01213 /// \brief Determine if this a relational predicate. 01214 bool isRelational() const { return !isEquality(); } 01215 01216 /// Exchange the two operands to this instruction in such a way that it does 01217 /// not modify the semantics of the instruction. The predicate value may be 01218 /// changed to retain the same result if the predicate is order dependent 01219 /// (e.g. ult). 01220 /// \brief Swap operands and adjust predicate. 01221 void swapOperands() { 01222 setPredicate(getSwappedPredicate()); 01223 Op<0>().swap(Op<1>()); 01224 } 01225 01226 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 01227 static inline bool classof(const Instruction *I) { 01228 return I->getOpcode() == Instruction::FCmp; 01229 } 01230 static inline bool classof(const Value *V) { 01231 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01232 } 01233 }; 01234 01235 //===----------------------------------------------------------------------===// 01236 /// CallInst - This class represents a function call, abstracting a target 01237 /// machine's calling convention. This class uses low bit of the SubClassData 01238 /// field to indicate whether or not this is a tail call. The rest of the bits 01239 /// hold the calling convention of the call. 01240 /// 01241 class CallInst : public Instruction { 01242 AttributeSet AttributeList; ///< parameter attributes for call 01243 CallInst(const CallInst &CI); 01244 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr); 01245 void init(Value *Func, const Twine &NameStr); 01246 01247 /// Construct a CallInst given a range of arguments. 01248 /// \brief Construct a CallInst from a range of arguments 01249 inline CallInst(Value *Func, ArrayRef<Value *> Args, 01250 const Twine &NameStr, Instruction *InsertBefore); 01251 01252 /// Construct a CallInst given a range of arguments. 01253 /// \brief Construct a CallInst from a range of arguments 01254 inline CallInst(Value *Func, ArrayRef<Value *> Args, 01255 const Twine &NameStr, BasicBlock *InsertAtEnd); 01256 01257 explicit CallInst(Value *F, const Twine &NameStr, 01258 Instruction *InsertBefore); 01259 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd); 01260 protected: 01261 CallInst *clone_impl() const override; 01262 public: 01263 static CallInst *Create(Value *Func, 01264 ArrayRef<Value *> Args, 01265 const Twine &NameStr = "", 01266 Instruction *InsertBefore = nullptr) { 01267 return new(unsigned(Args.size() + 1)) 01268 CallInst(Func, Args, NameStr, InsertBefore); 01269 } 01270 static CallInst *Create(Value *Func, 01271 ArrayRef<Value *> Args, 01272 const Twine &NameStr, BasicBlock *InsertAtEnd) { 01273 return new(unsigned(Args.size() + 1)) 01274 CallInst(Func, Args, NameStr, InsertAtEnd); 01275 } 01276 static CallInst *Create(Value *F, const Twine &NameStr = "", 01277 Instruction *InsertBefore = nullptr) { 01278 return new(1) CallInst(F, NameStr, InsertBefore); 01279 } 01280 static CallInst *Create(Value *F, const Twine &NameStr, 01281 BasicBlock *InsertAtEnd) { 01282 return new(1) CallInst(F, NameStr, InsertAtEnd); 01283 } 01284 /// CreateMalloc - Generate the IR for a call to malloc: 01285 /// 1. Compute the malloc call's argument as the specified type's size, 01286 /// possibly multiplied by the array size if the array size is not 01287 /// constant 1. 01288 /// 2. Call malloc with that argument. 01289 /// 3. Bitcast the result of the malloc call to the specified type. 01290 static Instruction *CreateMalloc(Instruction *InsertBefore, 01291 Type *IntPtrTy, Type *AllocTy, 01292 Value *AllocSize, Value *ArraySize = nullptr, 01293 Function* MallocF = nullptr, 01294 const Twine &Name = ""); 01295 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd, 01296 Type *IntPtrTy, Type *AllocTy, 01297 Value *AllocSize, Value *ArraySize = nullptr, 01298 Function* MallocF = nullptr, 01299 const Twine &Name = ""); 01300 /// CreateFree - Generate the IR for a call to the builtin free function. 01301 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore); 01302 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd); 01303 01304 ~CallInst(); 01305 01306 // Note that 'musttail' implies 'tail'. 01307 enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2 }; 01308 TailCallKind getTailCallKind() const { 01309 return TailCallKind(getSubclassDataFromInstruction() & 3); 01310 } 01311 bool isTailCall() const { 01312 return (getSubclassDataFromInstruction() & 3) != TCK_None; 01313 } 01314 bool isMustTailCall() const { 01315 return (getSubclassDataFromInstruction() & 3) == TCK_MustTail; 01316 } 01317 void setTailCall(bool isTC = true) { 01318 setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) | 01319 unsigned(isTC ? TCK_Tail : TCK_None)); 01320 } 01321 void setTailCallKind(TailCallKind TCK) { 01322 setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) | 01323 unsigned(TCK)); 01324 } 01325 01326 /// Provide fast operand accessors 01327 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 01328 01329 /// getNumArgOperands - Return the number of call arguments. 01330 /// 01331 unsigned getNumArgOperands() const { return getNumOperands() - 1; } 01332 01333 /// getArgOperand/setArgOperand - Return/set the i-th call argument. 01334 /// 01335 Value *getArgOperand(unsigned i) const { return getOperand(i); } 01336 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); } 01337 01338 /// arg_operands - iteration adapter for range-for loops. 01339 iterator_range<op_iterator> arg_operands() { 01340 // The last operand in the op list is the callee - it's not one of the args 01341 // so we don't want to iterate over it. 01342 return iterator_range<op_iterator>(op_begin(), op_end() - 1); 01343 } 01344 01345 /// arg_operands - iteration adapter for range-for loops. 01346 iterator_range<const_op_iterator> arg_operands() const { 01347 return iterator_range<const_op_iterator>(op_begin(), op_end() - 1); 01348 } 01349 01350 /// \brief Wrappers for getting the \c Use of a call argument. 01351 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); } 01352 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); } 01353 01354 /// getCallingConv/setCallingConv - Get or set the calling convention of this 01355 /// function call. 01356 CallingConv::ID getCallingConv() const { 01357 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2); 01358 } 01359 void setCallingConv(CallingConv::ID CC) { 01360 setInstructionSubclassData((getSubclassDataFromInstruction() & 3) | 01361 (static_cast<unsigned>(CC) << 2)); 01362 } 01363 01364 /// getAttributes - Return the parameter attributes for this call. 01365 /// 01366 const AttributeSet &getAttributes() const { return AttributeList; } 01367 01368 /// setAttributes - Set the parameter attributes for this call. 01369 /// 01370 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; } 01371 01372 /// addAttribute - adds the attribute to the list of attributes. 01373 void addAttribute(unsigned i, Attribute::AttrKind attr); 01374 01375 /// removeAttribute - removes the attribute from the list of attributes. 01376 void removeAttribute(unsigned i, Attribute attr); 01377 01378 /// \brief Determine whether this call has the given attribute. 01379 bool hasFnAttr(Attribute::AttrKind A) const { 01380 assert(A != Attribute::NoBuiltin && 01381 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin"); 01382 return hasFnAttrImpl(A); 01383 } 01384 01385 /// \brief Determine whether the call or the callee has the given attributes. 01386 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const; 01387 01388 /// \brief Extract the alignment for a call or parameter (0=unknown). 01389 unsigned getParamAlignment(unsigned i) const { 01390 return AttributeList.getParamAlignment(i); 01391 } 01392 01393 /// \brief Extract the number of dereferenceable bytes for a call or 01394 /// parameter (0=unknown). 01395 uint64_t getDereferenceableBytes(unsigned i) const { 01396 return AttributeList.getDereferenceableBytes(i); 01397 } 01398 01399 /// \brief Return true if the call should not be treated as a call to a 01400 /// builtin. 01401 bool isNoBuiltin() const { 01402 return hasFnAttrImpl(Attribute::NoBuiltin) && 01403 !hasFnAttrImpl(Attribute::Builtin); 01404 } 01405 01406 /// \brief Return true if the call should not be inlined. 01407 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); } 01408 void setIsNoInline() { 01409 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline); 01410 } 01411 01412 /// \brief Return true if the call can return twice 01413 bool canReturnTwice() const { 01414 return hasFnAttr(Attribute::ReturnsTwice); 01415 } 01416 void setCanReturnTwice() { 01417 addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice); 01418 } 01419 01420 /// \brief Determine if the call does not access memory. 01421 bool doesNotAccessMemory() const { 01422 return hasFnAttr(Attribute::ReadNone); 01423 } 01424 void setDoesNotAccessMemory() { 01425 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone); 01426 } 01427 01428 /// \brief Determine if the call does not access or only reads memory. 01429 bool onlyReadsMemory() const { 01430 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly); 01431 } 01432 void setOnlyReadsMemory() { 01433 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly); 01434 } 01435 01436 /// \brief Determine if the call cannot return. 01437 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); } 01438 void setDoesNotReturn() { 01439 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn); 01440 } 01441 01442 /// \brief Determine if the call cannot unwind. 01443 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); } 01444 void setDoesNotThrow() { 01445 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind); 01446 } 01447 01448 /// \brief Determine if the call cannot be duplicated. 01449 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); } 01450 void setCannotDuplicate() { 01451 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate); 01452 } 01453 01454 /// \brief Determine if the call returns a structure through first 01455 /// pointer argument. 01456 bool hasStructRetAttr() const { 01457 // Be friendly and also check the callee. 01458 return paramHasAttr(1, Attribute::StructRet); 01459 } 01460 01461 /// \brief Determine if any call argument is an aggregate passed by value. 01462 bool hasByValArgument() const { 01463 return AttributeList.hasAttrSomewhere(Attribute::ByVal); 01464 } 01465 01466 /// getCalledFunction - Return the function called, or null if this is an 01467 /// indirect function invocation. 01468 /// 01469 Function *getCalledFunction() const { 01470 return dyn_cast<Function>(Op<-1>()); 01471 } 01472 01473 /// getCalledValue - Get a pointer to the function that is invoked by this 01474 /// instruction. 01475 const Value *getCalledValue() const { return Op<-1>(); } 01476 Value *getCalledValue() { return Op<-1>(); } 01477 01478 /// setCalledFunction - Set the function called. 01479 void setCalledFunction(Value* Fn) { 01480 Op<-1>() = Fn; 01481 } 01482 01483 /// isInlineAsm - Check if this call is an inline asm statement. 01484 bool isInlineAsm() const { 01485 return isa<InlineAsm>(Op<-1>()); 01486 } 01487 01488 // Methods for support type inquiry through isa, cast, and dyn_cast: 01489 static inline bool classof(const Instruction *I) { 01490 return I->getOpcode() == Instruction::Call; 01491 } 01492 static inline bool classof(const Value *V) { 01493 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01494 } 01495 private: 01496 01497 bool hasFnAttrImpl(Attribute::AttrKind A) const; 01498 01499 // Shadow Instruction::setInstructionSubclassData with a private forwarding 01500 // method so that subclasses cannot accidentally use it. 01501 void setInstructionSubclassData(unsigned short D) { 01502 Instruction::setInstructionSubclassData(D); 01503 } 01504 }; 01505 01506 template <> 01507 struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> { 01508 }; 01509 01510 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args, 01511 const Twine &NameStr, BasicBlock *InsertAtEnd) 01512 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) 01513 ->getElementType())->getReturnType(), 01514 Instruction::Call, 01515 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1), 01516 unsigned(Args.size() + 1), InsertAtEnd) { 01517 init(Func, Args, NameStr); 01518 } 01519 01520 CallInst::CallInst(Value *Func, ArrayRef<Value *> Args, 01521 const Twine &NameStr, Instruction *InsertBefore) 01522 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) 01523 ->getElementType())->getReturnType(), 01524 Instruction::Call, 01525 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1), 01526 unsigned(Args.size() + 1), InsertBefore) { 01527 init(Func, Args, NameStr); 01528 } 01529 01530 01531 // Note: if you get compile errors about private methods then 01532 // please update your code to use the high-level operand 01533 // interfaces. See line 943 above. 01534 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value) 01535 01536 //===----------------------------------------------------------------------===// 01537 // SelectInst Class 01538 //===----------------------------------------------------------------------===// 01539 01540 /// SelectInst - This class represents the LLVM 'select' instruction. 01541 /// 01542 class SelectInst : public Instruction { 01543 void init(Value *C, Value *S1, Value *S2) { 01544 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select"); 01545 Op<0>() = C; 01546 Op<1>() = S1; 01547 Op<2>() = S2; 01548 } 01549 01550 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr, 01551 Instruction *InsertBefore) 01552 : Instruction(S1->getType(), Instruction::Select, 01553 &Op<0>(), 3, InsertBefore) { 01554 init(C, S1, S2); 01555 setName(NameStr); 01556 } 01557 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr, 01558 BasicBlock *InsertAtEnd) 01559 : Instruction(S1->getType(), Instruction::Select, 01560 &Op<0>(), 3, InsertAtEnd) { 01561 init(C, S1, S2); 01562 setName(NameStr); 01563 } 01564 protected: 01565 SelectInst *clone_impl() const override; 01566 public: 01567 static SelectInst *Create(Value *C, Value *S1, Value *S2, 01568 const Twine &NameStr = "", 01569 Instruction *InsertBefore = nullptr) { 01570 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore); 01571 } 01572 static SelectInst *Create(Value *C, Value *S1, Value *S2, 01573 const Twine &NameStr, 01574 BasicBlock *InsertAtEnd) { 01575 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd); 01576 } 01577 01578 const Value *getCondition() const { return Op<0>(); } 01579 const Value *getTrueValue() const { return Op<1>(); } 01580 const Value *getFalseValue() const { return Op<2>(); } 01581 Value *getCondition() { return Op<0>(); } 01582 Value *getTrueValue() { return Op<1>(); } 01583 Value *getFalseValue() { return Op<2>(); } 01584 01585 /// areInvalidOperands - Return a string if the specified operands are invalid 01586 /// for a select operation, otherwise return null. 01587 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False); 01588 01589 /// Transparently provide more efficient getOperand methods. 01590 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 01591 01592 OtherOps getOpcode() const { 01593 return static_cast<OtherOps>(Instruction::getOpcode()); 01594 } 01595 01596 // Methods for support type inquiry through isa, cast, and dyn_cast: 01597 static inline bool classof(const Instruction *I) { 01598 return I->getOpcode() == Instruction::Select; 01599 } 01600 static inline bool classof(const Value *V) { 01601 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01602 } 01603 }; 01604 01605 template <> 01606 struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> { 01607 }; 01608 01609 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value) 01610 01611 //===----------------------------------------------------------------------===// 01612 // VAArgInst Class 01613 //===----------------------------------------------------------------------===// 01614 01615 /// VAArgInst - This class represents the va_arg llvm instruction, which returns 01616 /// an argument of the specified type given a va_list and increments that list 01617 /// 01618 class VAArgInst : public UnaryInstruction { 01619 protected: 01620 VAArgInst *clone_impl() const override; 01621 01622 public: 01623 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "", 01624 Instruction *InsertBefore = nullptr) 01625 : UnaryInstruction(Ty, VAArg, List, InsertBefore) { 01626 setName(NameStr); 01627 } 01628 VAArgInst(Value *List, Type *Ty, const Twine &NameStr, 01629 BasicBlock *InsertAtEnd) 01630 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) { 01631 setName(NameStr); 01632 } 01633 01634 Value *getPointerOperand() { return getOperand(0); } 01635 const Value *getPointerOperand() const { return getOperand(0); } 01636 static unsigned getPointerOperandIndex() { return 0U; } 01637 01638 // Methods for support type inquiry through isa, cast, and dyn_cast: 01639 static inline bool classof(const Instruction *I) { 01640 return I->getOpcode() == VAArg; 01641 } 01642 static inline bool classof(const Value *V) { 01643 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01644 } 01645 }; 01646 01647 //===----------------------------------------------------------------------===// 01648 // ExtractElementInst Class 01649 //===----------------------------------------------------------------------===// 01650 01651 /// ExtractElementInst - This instruction extracts a single (scalar) 01652 /// element from a VectorType value 01653 /// 01654 class ExtractElementInst : public Instruction { 01655 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "", 01656 Instruction *InsertBefore = nullptr); 01657 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr, 01658 BasicBlock *InsertAtEnd); 01659 protected: 01660 ExtractElementInst *clone_impl() const override; 01661 01662 public: 01663 static ExtractElementInst *Create(Value *Vec, Value *Idx, 01664 const Twine &NameStr = "", 01665 Instruction *InsertBefore = nullptr) { 01666 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore); 01667 } 01668 static ExtractElementInst *Create(Value *Vec, Value *Idx, 01669 const Twine &NameStr, 01670 BasicBlock *InsertAtEnd) { 01671 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd); 01672 } 01673 01674 /// isValidOperands - Return true if an extractelement instruction can be 01675 /// formed with the specified operands. 01676 static bool isValidOperands(const Value *Vec, const Value *Idx); 01677 01678 Value *getVectorOperand() { return Op<0>(); } 01679 Value *getIndexOperand() { return Op<1>(); } 01680 const Value *getVectorOperand() const { return Op<0>(); } 01681 const Value *getIndexOperand() const { return Op<1>(); } 01682 01683 VectorType *getVectorOperandType() const { 01684 return cast<VectorType>(getVectorOperand()->getType()); 01685 } 01686 01687 01688 /// Transparently provide more efficient getOperand methods. 01689 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 01690 01691 // Methods for support type inquiry through isa, cast, and dyn_cast: 01692 static inline bool classof(const Instruction *I) { 01693 return I->getOpcode() == Instruction::ExtractElement; 01694 } 01695 static inline bool classof(const Value *V) { 01696 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01697 } 01698 }; 01699 01700 template <> 01701 struct OperandTraits<ExtractElementInst> : 01702 public FixedNumOperandTraits<ExtractElementInst, 2> { 01703 }; 01704 01705 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value) 01706 01707 //===----------------------------------------------------------------------===// 01708 // InsertElementInst Class 01709 //===----------------------------------------------------------------------===// 01710 01711 /// InsertElementInst - This instruction inserts a single (scalar) 01712 /// element into a VectorType value 01713 /// 01714 class InsertElementInst : public Instruction { 01715 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, 01716 const Twine &NameStr = "", 01717 Instruction *InsertBefore = nullptr); 01718 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, 01719 const Twine &NameStr, BasicBlock *InsertAtEnd); 01720 protected: 01721 InsertElementInst *clone_impl() const override; 01722 01723 public: 01724 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, 01725 const Twine &NameStr = "", 01726 Instruction *InsertBefore = nullptr) { 01727 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore); 01728 } 01729 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, 01730 const Twine &NameStr, 01731 BasicBlock *InsertAtEnd) { 01732 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd); 01733 } 01734 01735 /// isValidOperands - Return true if an insertelement instruction can be 01736 /// formed with the specified operands. 01737 static bool isValidOperands(const Value *Vec, const Value *NewElt, 01738 const Value *Idx); 01739 01740 /// getType - Overload to return most specific vector type. 01741 /// 01742 VectorType *getType() const { 01743 return cast<VectorType>(Instruction::getType()); 01744 } 01745 01746 /// Transparently provide more efficient getOperand methods. 01747 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 01748 01749 // Methods for support type inquiry through isa, cast, and dyn_cast: 01750 static inline bool classof(const Instruction *I) { 01751 return I->getOpcode() == Instruction::InsertElement; 01752 } 01753 static inline bool classof(const Value *V) { 01754 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01755 } 01756 }; 01757 01758 template <> 01759 struct OperandTraits<InsertElementInst> : 01760 public FixedNumOperandTraits<InsertElementInst, 3> { 01761 }; 01762 01763 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value) 01764 01765 //===----------------------------------------------------------------------===// 01766 // ShuffleVectorInst Class 01767 //===----------------------------------------------------------------------===// 01768 01769 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two 01770 /// input vectors. 01771 /// 01772 class ShuffleVectorInst : public Instruction { 01773 protected: 01774 ShuffleVectorInst *clone_impl() const override; 01775 01776 public: 01777 // allocate space for exactly three operands 01778 void *operator new(size_t s) { 01779 return User::operator new(s, 3); 01780 } 01781 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, 01782 const Twine &NameStr = "", 01783 Instruction *InsertBefor = nullptr); 01784 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, 01785 const Twine &NameStr, BasicBlock *InsertAtEnd); 01786 01787 /// isValidOperands - Return true if a shufflevector instruction can be 01788 /// formed with the specified operands. 01789 static bool isValidOperands(const Value *V1, const Value *V2, 01790 const Value *Mask); 01791 01792 /// getType - Overload to return most specific vector type. 01793 /// 01794 VectorType *getType() const { 01795 return cast<VectorType>(Instruction::getType()); 01796 } 01797 01798 /// Transparently provide more efficient getOperand methods. 01799 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 01800 01801 Constant *getMask() const { 01802 return cast<Constant>(getOperand(2)); 01803 } 01804 01805 /// getMaskValue - Return the index from the shuffle mask for the specified 01806 /// output result. This is either -1 if the element is undef or a number less 01807 /// than 2*numelements. 01808 static int getMaskValue(Constant *Mask, unsigned i); 01809 01810 int getMaskValue(unsigned i) const { 01811 return getMaskValue(getMask(), i); 01812 } 01813 01814 /// getShuffleMask - Return the full mask for this instruction, where each 01815 /// element is the element number and undef's are returned as -1. 01816 static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result); 01817 01818 void getShuffleMask(SmallVectorImpl<int> &Result) const { 01819 return getShuffleMask(getMask(), Result); 01820 } 01821 01822 SmallVector<int, 16> getShuffleMask() const { 01823 SmallVector<int, 16> Mask; 01824 getShuffleMask(Mask); 01825 return Mask; 01826 } 01827 01828 01829 // Methods for support type inquiry through isa, cast, and dyn_cast: 01830 static inline bool classof(const Instruction *I) { 01831 return I->getOpcode() == Instruction::ShuffleVector; 01832 } 01833 static inline bool classof(const Value *V) { 01834 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01835 } 01836 }; 01837 01838 template <> 01839 struct OperandTraits<ShuffleVectorInst> : 01840 public FixedNumOperandTraits<ShuffleVectorInst, 3> { 01841 }; 01842 01843 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value) 01844 01845 //===----------------------------------------------------------------------===// 01846 // ExtractValueInst Class 01847 //===----------------------------------------------------------------------===// 01848 01849 /// ExtractValueInst - This instruction extracts a struct member or array 01850 /// element value from an aggregate value. 01851 /// 01852 class ExtractValueInst : public UnaryInstruction { 01853 SmallVector<unsigned, 4> Indices; 01854 01855 ExtractValueInst(const ExtractValueInst &EVI); 01856 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr); 01857 01858 /// Constructors - Create a extractvalue instruction with a base aggregate 01859 /// value and a list of indices. The first ctor can optionally insert before 01860 /// an existing instruction, the second appends the new instruction to the 01861 /// specified BasicBlock. 01862 inline ExtractValueInst(Value *Agg, 01863 ArrayRef<unsigned> Idxs, 01864 const Twine &NameStr, 01865 Instruction *InsertBefore); 01866 inline ExtractValueInst(Value *Agg, 01867 ArrayRef<unsigned> Idxs, 01868 const Twine &NameStr, BasicBlock *InsertAtEnd); 01869 01870 // allocate space for exactly one operand 01871 void *operator new(size_t s) { 01872 return User::operator new(s, 1); 01873 } 01874 protected: 01875 ExtractValueInst *clone_impl() const override; 01876 01877 public: 01878 static ExtractValueInst *Create(Value *Agg, 01879 ArrayRef<unsigned> Idxs, 01880 const Twine &NameStr = "", 01881 Instruction *InsertBefore = nullptr) { 01882 return new 01883 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore); 01884 } 01885 static ExtractValueInst *Create(Value *Agg, 01886 ArrayRef<unsigned> Idxs, 01887 const Twine &NameStr, 01888 BasicBlock *InsertAtEnd) { 01889 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd); 01890 } 01891 01892 /// getIndexedType - Returns the type of the element that would be extracted 01893 /// with an extractvalue instruction with the specified parameters. 01894 /// 01895 /// Null is returned if the indices are invalid for the specified type. 01896 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs); 01897 01898 typedef const unsigned* idx_iterator; 01899 inline idx_iterator idx_begin() const { return Indices.begin(); } 01900 inline idx_iterator idx_end() const { return Indices.end(); } 01901 01902 Value *getAggregateOperand() { 01903 return getOperand(0); 01904 } 01905 const Value *getAggregateOperand() const { 01906 return getOperand(0); 01907 } 01908 static unsigned getAggregateOperandIndex() { 01909 return 0U; // get index for modifying correct operand 01910 } 01911 01912 ArrayRef<unsigned> getIndices() const { 01913 return Indices; 01914 } 01915 01916 unsigned getNumIndices() const { 01917 return (unsigned)Indices.size(); 01918 } 01919 01920 bool hasIndices() const { 01921 return true; 01922 } 01923 01924 // Methods for support type inquiry through isa, cast, and dyn_cast: 01925 static inline bool classof(const Instruction *I) { 01926 return I->getOpcode() == Instruction::ExtractValue; 01927 } 01928 static inline bool classof(const Value *V) { 01929 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 01930 } 01931 }; 01932 01933 ExtractValueInst::ExtractValueInst(Value *Agg, 01934 ArrayRef<unsigned> Idxs, 01935 const Twine &NameStr, 01936 Instruction *InsertBefore) 01937 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)), 01938 ExtractValue, Agg, InsertBefore) { 01939 init(Idxs, NameStr); 01940 } 01941 ExtractValueInst::ExtractValueInst(Value *Agg, 01942 ArrayRef<unsigned> Idxs, 01943 const Twine &NameStr, 01944 BasicBlock *InsertAtEnd) 01945 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)), 01946 ExtractValue, Agg, InsertAtEnd) { 01947 init(Idxs, NameStr); 01948 } 01949 01950 01951 //===----------------------------------------------------------------------===// 01952 // InsertValueInst Class 01953 //===----------------------------------------------------------------------===// 01954 01955 /// InsertValueInst - This instruction inserts a struct field of array element 01956 /// value into an aggregate value. 01957 /// 01958 class InsertValueInst : public Instruction { 01959 SmallVector<unsigned, 4> Indices; 01960 01961 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 01962 InsertValueInst(const InsertValueInst &IVI); 01963 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs, 01964 const Twine &NameStr); 01965 01966 /// Constructors - Create a insertvalue instruction with a base aggregate 01967 /// value, a value to insert, and a list of indices. The first ctor can 01968 /// optionally insert before an existing instruction, the second appends 01969 /// the new instruction to the specified BasicBlock. 01970 inline InsertValueInst(Value *Agg, Value *Val, 01971 ArrayRef<unsigned> Idxs, 01972 const Twine &NameStr, 01973 Instruction *InsertBefore); 01974 inline InsertValueInst(Value *Agg, Value *Val, 01975 ArrayRef<unsigned> Idxs, 01976 const Twine &NameStr, BasicBlock *InsertAtEnd); 01977 01978 /// Constructors - These two constructors are convenience methods because one 01979 /// and two index insertvalue instructions are so common. 01980 InsertValueInst(Value *Agg, Value *Val, 01981 unsigned Idx, const Twine &NameStr = "", 01982 Instruction *InsertBefore = nullptr); 01983 InsertValueInst(Value *Agg, Value *Val, unsigned Idx, 01984 const Twine &NameStr, BasicBlock *InsertAtEnd); 01985 protected: 01986 InsertValueInst *clone_impl() const override; 01987 public: 01988 // allocate space for exactly two operands 01989 void *operator new(size_t s) { 01990 return User::operator new(s, 2); 01991 } 01992 01993 static InsertValueInst *Create(Value *Agg, Value *Val, 01994 ArrayRef<unsigned> Idxs, 01995 const Twine &NameStr = "", 01996 Instruction *InsertBefore = nullptr) { 01997 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore); 01998 } 01999 static InsertValueInst *Create(Value *Agg, Value *Val, 02000 ArrayRef<unsigned> Idxs, 02001 const Twine &NameStr, 02002 BasicBlock *InsertAtEnd) { 02003 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd); 02004 } 02005 02006 /// Transparently provide more efficient getOperand methods. 02007 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 02008 02009 typedef const unsigned* idx_iterator; 02010 inline idx_iterator idx_begin() const { return Indices.begin(); } 02011 inline idx_iterator idx_end() const { return Indices.end(); } 02012 02013 Value *getAggregateOperand() { 02014 return getOperand(0); 02015 } 02016 const Value *getAggregateOperand() const { 02017 return getOperand(0); 02018 } 02019 static unsigned getAggregateOperandIndex() { 02020 return 0U; // get index for modifying correct operand 02021 } 02022 02023 Value *getInsertedValueOperand() { 02024 return getOperand(1); 02025 } 02026 const Value *getInsertedValueOperand() const { 02027 return getOperand(1); 02028 } 02029 static unsigned getInsertedValueOperandIndex() { 02030 return 1U; // get index for modifying correct operand 02031 } 02032 02033 ArrayRef<unsigned> getIndices() const { 02034 return Indices; 02035 } 02036 02037 unsigned getNumIndices() const { 02038 return (unsigned)Indices.size(); 02039 } 02040 02041 bool hasIndices() const { 02042 return true; 02043 } 02044 02045 // Methods for support type inquiry through isa, cast, and dyn_cast: 02046 static inline bool classof(const Instruction *I) { 02047 return I->getOpcode() == Instruction::InsertValue; 02048 } 02049 static inline bool classof(const Value *V) { 02050 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02051 } 02052 }; 02053 02054 template <> 02055 struct OperandTraits<InsertValueInst> : 02056 public FixedNumOperandTraits<InsertValueInst, 2> { 02057 }; 02058 02059 InsertValueInst::InsertValueInst(Value *Agg, 02060 Value *Val, 02061 ArrayRef<unsigned> Idxs, 02062 const Twine &NameStr, 02063 Instruction *InsertBefore) 02064 : Instruction(Agg->getType(), InsertValue, 02065 OperandTraits<InsertValueInst>::op_begin(this), 02066 2, InsertBefore) { 02067 init(Agg, Val, Idxs, NameStr); 02068 } 02069 InsertValueInst::InsertValueInst(Value *Agg, 02070 Value *Val, 02071 ArrayRef<unsigned> Idxs, 02072 const Twine &NameStr, 02073 BasicBlock *InsertAtEnd) 02074 : Instruction(Agg->getType(), InsertValue, 02075 OperandTraits<InsertValueInst>::op_begin(this), 02076 2, InsertAtEnd) { 02077 init(Agg, Val, Idxs, NameStr); 02078 } 02079 02080 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value) 02081 02082 //===----------------------------------------------------------------------===// 02083 // PHINode Class 02084 //===----------------------------------------------------------------------===// 02085 02086 // PHINode - The PHINode class is used to represent the magical mystical PHI 02087 // node, that can not exist in nature, but can be synthesized in a computer 02088 // scientist's overactive imagination. 02089 // 02090 class PHINode : public Instruction { 02091 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 02092 /// ReservedSpace - The number of operands actually allocated. NumOperands is 02093 /// the number actually in use. 02094 unsigned ReservedSpace; 02095 PHINode(const PHINode &PN); 02096 // allocate space for exactly zero operands 02097 void *operator new(size_t s) { 02098 return User::operator new(s, 0); 02099 } 02100 explicit PHINode(Type *Ty, unsigned NumReservedValues, 02101 const Twine &NameStr = "", 02102 Instruction *InsertBefore = nullptr) 02103 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore), 02104 ReservedSpace(NumReservedValues) { 02105 setName(NameStr); 02106 OperandList = allocHungoffUses(ReservedSpace); 02107 } 02108 02109 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr, 02110 BasicBlock *InsertAtEnd) 02111 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd), 02112 ReservedSpace(NumReservedValues) { 02113 setName(NameStr); 02114 OperandList = allocHungoffUses(ReservedSpace); 02115 } 02116 protected: 02117 // allocHungoffUses - this is more complicated than the generic 02118 // User::allocHungoffUses, because we have to allocate Uses for the incoming 02119 // values and pointers to the incoming blocks, all in one allocation. 02120 Use *allocHungoffUses(unsigned) const; 02121 02122 PHINode *clone_impl() const override; 02123 public: 02124 /// Constructors - NumReservedValues is a hint for the number of incoming 02125 /// edges that this phi node will have (use 0 if you really have no idea). 02126 static PHINode *Create(Type *Ty, unsigned NumReservedValues, 02127 const Twine &NameStr = "", 02128 Instruction *InsertBefore = nullptr) { 02129 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore); 02130 } 02131 static PHINode *Create(Type *Ty, unsigned NumReservedValues, 02132 const Twine &NameStr, BasicBlock *InsertAtEnd) { 02133 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd); 02134 } 02135 ~PHINode(); 02136 02137 /// Provide fast operand accessors 02138 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 02139 02140 // Block iterator interface. This provides access to the list of incoming 02141 // basic blocks, which parallels the list of incoming values. 02142 02143 typedef BasicBlock **block_iterator; 02144 typedef BasicBlock * const *const_block_iterator; 02145 02146 block_iterator block_begin() { 02147 Use::UserRef *ref = 02148 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace); 02149 return reinterpret_cast<block_iterator>(ref + 1); 02150 } 02151 02152 const_block_iterator block_begin() const { 02153 const Use::UserRef *ref = 02154 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace); 02155 return reinterpret_cast<const_block_iterator>(ref + 1); 02156 } 02157 02158 block_iterator block_end() { 02159 return block_begin() + getNumOperands(); 02160 } 02161 02162 const_block_iterator block_end() const { 02163 return block_begin() + getNumOperands(); 02164 } 02165 02166 /// getNumIncomingValues - Return the number of incoming edges 02167 /// 02168 unsigned getNumIncomingValues() const { return getNumOperands(); } 02169 02170 /// getIncomingValue - Return incoming value number x 02171 /// 02172 Value *getIncomingValue(unsigned i) const { 02173 return getOperand(i); 02174 } 02175 void setIncomingValue(unsigned i, Value *V) { 02176 setOperand(i, V); 02177 } 02178 static unsigned getOperandNumForIncomingValue(unsigned i) { 02179 return i; 02180 } 02181 static unsigned getIncomingValueNumForOperand(unsigned i) { 02182 return i; 02183 } 02184 02185 /// getIncomingBlock - Return incoming basic block number @p i. 02186 /// 02187 BasicBlock *getIncomingBlock(unsigned i) const { 02188 return block_begin()[i]; 02189 } 02190 02191 /// getIncomingBlock - Return incoming basic block corresponding 02192 /// to an operand of the PHI. 02193 /// 02194 BasicBlock *getIncomingBlock(const Use &U) const { 02195 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?"); 02196 return getIncomingBlock(unsigned(&U - op_begin())); 02197 } 02198 02199 /// getIncomingBlock - Return incoming basic block corresponding 02200 /// to value use iterator. 02201 /// 02202 BasicBlock *getIncomingBlock(Value::const_user_iterator I) const { 02203 return getIncomingBlock(I.getUse()); 02204 } 02205 02206 void setIncomingBlock(unsigned i, BasicBlock *BB) { 02207 block_begin()[i] = BB; 02208 } 02209 02210 /// addIncoming - Add an incoming value to the end of the PHI list 02211 /// 02212 void addIncoming(Value *V, BasicBlock *BB) { 02213 assert(V && "PHI node got a null value!"); 02214 assert(BB && "PHI node got a null basic block!"); 02215 assert(getType() == V->getType() && 02216 "All operands to PHI node must be the same type as the PHI node!"); 02217 if (NumOperands == ReservedSpace) 02218 growOperands(); // Get more space! 02219 // Initialize some new operands. 02220 ++NumOperands; 02221 setIncomingValue(NumOperands - 1, V); 02222 setIncomingBlock(NumOperands - 1, BB); 02223 } 02224 02225 /// removeIncomingValue - Remove an incoming value. This is useful if a 02226 /// predecessor basic block is deleted. The value removed is returned. 02227 /// 02228 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty 02229 /// is true), the PHI node is destroyed and any uses of it are replaced with 02230 /// dummy values. The only time there should be zero incoming values to a PHI 02231 /// node is when the block is dead, so this strategy is sound. 02232 /// 02233 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true); 02234 02235 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) { 02236 int Idx = getBasicBlockIndex(BB); 02237 assert(Idx >= 0 && "Invalid basic block argument to remove!"); 02238 return removeIncomingValue(Idx, DeletePHIIfEmpty); 02239 } 02240 02241 /// getBasicBlockIndex - Return the first index of the specified basic 02242 /// block in the value list for this PHI. Returns -1 if no instance. 02243 /// 02244 int getBasicBlockIndex(const BasicBlock *BB) const { 02245 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) 02246 if (block_begin()[i] == BB) 02247 return i; 02248 return -1; 02249 } 02250 02251 Value *getIncomingValueForBlock(const BasicBlock *BB) const { 02252 int Idx = getBasicBlockIndex(BB); 02253 assert(Idx >= 0 && "Invalid basic block argument!"); 02254 return getIncomingValue(Idx); 02255 } 02256 02257 /// hasConstantValue - If the specified PHI node always merges together the 02258 /// same value, return the value, otherwise return null. 02259 Value *hasConstantValue() const; 02260 02261 /// Methods for support type inquiry through isa, cast, and dyn_cast: 02262 static inline bool classof(const Instruction *I) { 02263 return I->getOpcode() == Instruction::PHI; 02264 } 02265 static inline bool classof(const Value *V) { 02266 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02267 } 02268 private: 02269 void growOperands(); 02270 }; 02271 02272 template <> 02273 struct OperandTraits<PHINode> : public HungoffOperandTraits<2> { 02274 }; 02275 02276 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value) 02277 02278 //===----------------------------------------------------------------------===// 02279 // LandingPadInst Class 02280 //===----------------------------------------------------------------------===// 02281 02282 //===--------------------------------------------------------------------------- 02283 /// LandingPadInst - The landingpad instruction holds all of the information 02284 /// necessary to generate correct exception handling. The landingpad instruction 02285 /// cannot be moved from the top of a landing pad block, which itself is 02286 /// accessible only from the 'unwind' edge of an invoke. This uses the 02287 /// SubclassData field in Value to store whether or not the landingpad is a 02288 /// cleanup. 02289 /// 02290 class LandingPadInst : public Instruction { 02291 /// ReservedSpace - The number of operands actually allocated. NumOperands is 02292 /// the number actually in use. 02293 unsigned ReservedSpace; 02294 LandingPadInst(const LandingPadInst &LP); 02295 public: 02296 enum ClauseType { Catch, Filter }; 02297 private: 02298 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 02299 // Allocate space for exactly zero operands. 02300 void *operator new(size_t s) { 02301 return User::operator new(s, 0); 02302 } 02303 void growOperands(unsigned Size); 02304 void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr); 02305 02306 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn, 02307 unsigned NumReservedValues, const Twine &NameStr, 02308 Instruction *InsertBefore); 02309 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn, 02310 unsigned NumReservedValues, const Twine &NameStr, 02311 BasicBlock *InsertAtEnd); 02312 protected: 02313 LandingPadInst *clone_impl() const override; 02314 public: 02315 /// Constructors - NumReservedClauses is a hint for the number of incoming 02316 /// clauses that this landingpad will have (use 0 if you really have no idea). 02317 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn, 02318 unsigned NumReservedClauses, 02319 const Twine &NameStr = "", 02320 Instruction *InsertBefore = nullptr); 02321 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn, 02322 unsigned NumReservedClauses, 02323 const Twine &NameStr, BasicBlock *InsertAtEnd); 02324 ~LandingPadInst(); 02325 02326 /// Provide fast operand accessors 02327 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 02328 02329 /// getPersonalityFn - Get the personality function associated with this 02330 /// landing pad. 02331 Value *getPersonalityFn() const { return getOperand(0); } 02332 02333 /// isCleanup - Return 'true' if this landingpad instruction is a 02334 /// cleanup. I.e., it should be run when unwinding even if its landing pad 02335 /// doesn't catch the exception. 02336 bool isCleanup() const { return getSubclassDataFromInstruction() & 1; } 02337 02338 /// setCleanup - Indicate that this landingpad instruction is a cleanup. 02339 void setCleanup(bool V) { 02340 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | 02341 (V ? 1 : 0)); 02342 } 02343 02344 /// Add a catch or filter clause to the landing pad. 02345 void addClause(Constant *ClauseVal); 02346 02347 /// Get the value of the clause at index Idx. Use isCatch/isFilter to 02348 /// determine what type of clause this is. 02349 Constant *getClause(unsigned Idx) const { 02350 return cast<Constant>(OperandList[Idx + 1]); 02351 } 02352 02353 /// isCatch - Return 'true' if the clause and index Idx is a catch clause. 02354 bool isCatch(unsigned Idx) const { 02355 return !isa<ArrayType>(OperandList[Idx + 1]->getType()); 02356 } 02357 02358 /// isFilter - Return 'true' if the clause and index Idx is a filter clause. 02359 bool isFilter(unsigned Idx) const { 02360 return isa<ArrayType>(OperandList[Idx + 1]->getType()); 02361 } 02362 02363 /// getNumClauses - Get the number of clauses for this landing pad. 02364 unsigned getNumClauses() const { return getNumOperands() - 1; } 02365 02366 /// reserveClauses - Grow the size of the operand list to accommodate the new 02367 /// number of clauses. 02368 void reserveClauses(unsigned Size) { growOperands(Size); } 02369 02370 // Methods for support type inquiry through isa, cast, and dyn_cast: 02371 static inline bool classof(const Instruction *I) { 02372 return I->getOpcode() == Instruction::LandingPad; 02373 } 02374 static inline bool classof(const Value *V) { 02375 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02376 } 02377 }; 02378 02379 template <> 02380 struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> { 02381 }; 02382 02383 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value) 02384 02385 //===----------------------------------------------------------------------===// 02386 // ReturnInst Class 02387 //===----------------------------------------------------------------------===// 02388 02389 //===--------------------------------------------------------------------------- 02390 /// ReturnInst - Return a value (possibly void), from a function. Execution 02391 /// does not continue in this function any longer. 02392 /// 02393 class ReturnInst : public TerminatorInst { 02394 ReturnInst(const ReturnInst &RI); 02395 02396 private: 02397 // ReturnInst constructors: 02398 // ReturnInst() - 'ret void' instruction 02399 // ReturnInst( null) - 'ret void' instruction 02400 // ReturnInst(Value* X) - 'ret X' instruction 02401 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I 02402 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I 02403 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B 02404 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B 02405 // 02406 // NOTE: If the Value* passed is of type void then the constructor behaves as 02407 // if it was passed NULL. 02408 explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr, 02409 Instruction *InsertBefore = nullptr); 02410 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd); 02411 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd); 02412 protected: 02413 ReturnInst *clone_impl() const override; 02414 public: 02415 static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr, 02416 Instruction *InsertBefore = nullptr) { 02417 return new(!!retVal) ReturnInst(C, retVal, InsertBefore); 02418 } 02419 static ReturnInst* Create(LLVMContext &C, Value *retVal, 02420 BasicBlock *InsertAtEnd) { 02421 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd); 02422 } 02423 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) { 02424 return new(0) ReturnInst(C, InsertAtEnd); 02425 } 02426 virtual ~ReturnInst(); 02427 02428 /// Provide fast operand accessors 02429 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 02430 02431 /// Convenience accessor. Returns null if there is no return value. 02432 Value *getReturnValue() const { 02433 return getNumOperands() != 0 ? getOperand(0) : nullptr; 02434 } 02435 02436 unsigned getNumSuccessors() const { return 0; } 02437 02438 // Methods for support type inquiry through isa, cast, and dyn_cast: 02439 static inline bool classof(const Instruction *I) { 02440 return (I->getOpcode() == Instruction::Ret); 02441 } 02442 static inline bool classof(const Value *V) { 02443 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02444 } 02445 private: 02446 BasicBlock *getSuccessorV(unsigned idx) const override; 02447 unsigned getNumSuccessorsV() const override; 02448 void setSuccessorV(unsigned idx, BasicBlock *B) override; 02449 }; 02450 02451 template <> 02452 struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> { 02453 }; 02454 02455 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value) 02456 02457 //===----------------------------------------------------------------------===// 02458 // BranchInst Class 02459 //===----------------------------------------------------------------------===// 02460 02461 //===--------------------------------------------------------------------------- 02462 /// BranchInst - Conditional or Unconditional Branch instruction. 02463 /// 02464 class BranchInst : public TerminatorInst { 02465 /// Ops list - Branches are strange. The operands are ordered: 02466 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because 02467 /// they don't have to check for cond/uncond branchness. These are mostly 02468 /// accessed relative from op_end(). 02469 BranchInst(const BranchInst &BI); 02470 void AssertOK(); 02471 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition): 02472 // BranchInst(BB *B) - 'br B' 02473 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F' 02474 // BranchInst(BB* B, Inst *I) - 'br B' insert before I 02475 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I 02476 // BranchInst(BB* B, BB *I) - 'br B' insert at end 02477 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end 02478 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr); 02479 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, 02480 Instruction *InsertBefore = nullptr); 02481 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd); 02482 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, 02483 BasicBlock *InsertAtEnd); 02484 protected: 02485 BranchInst *clone_impl() const override; 02486 public: 02487 static BranchInst *Create(BasicBlock *IfTrue, 02488 Instruction *InsertBefore = nullptr) { 02489 return new(1) BranchInst(IfTrue, InsertBefore); 02490 } 02491 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, 02492 Value *Cond, Instruction *InsertBefore = nullptr) { 02493 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore); 02494 } 02495 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) { 02496 return new(1) BranchInst(IfTrue, InsertAtEnd); 02497 } 02498 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, 02499 Value *Cond, BasicBlock *InsertAtEnd) { 02500 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd); 02501 } 02502 02503 /// Transparently provide more efficient getOperand methods. 02504 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 02505 02506 bool isUnconditional() const { return getNumOperands() == 1; } 02507 bool isConditional() const { return getNumOperands() == 3; } 02508 02509 Value *getCondition() const { 02510 assert(isConditional() && "Cannot get condition of an uncond branch!"); 02511 return Op<-3>(); 02512 } 02513 02514 void setCondition(Value *V) { 02515 assert(isConditional() && "Cannot set condition of unconditional branch!"); 02516 Op<-3>() = V; 02517 } 02518 02519 unsigned getNumSuccessors() const { return 1+isConditional(); } 02520 02521 BasicBlock *getSuccessor(unsigned i) const { 02522 assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); 02523 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get()); 02524 } 02525 02526 void setSuccessor(unsigned idx, BasicBlock *NewSucc) { 02527 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!"); 02528 *(&Op<-1>() - idx) = (Value*)NewSucc; 02529 } 02530 02531 /// \brief Swap the successors of this branch instruction. 02532 /// 02533 /// Swaps the successors of the branch instruction. This also swaps any 02534 /// branch weight metadata associated with the instruction so that it 02535 /// continues to map correctly to each operand. 02536 void swapSuccessors(); 02537 02538 // Methods for support type inquiry through isa, cast, and dyn_cast: 02539 static inline bool classof(const Instruction *I) { 02540 return (I->getOpcode() == Instruction::Br); 02541 } 02542 static inline bool classof(const Value *V) { 02543 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02544 } 02545 private: 02546 BasicBlock *getSuccessorV(unsigned idx) const override; 02547 unsigned getNumSuccessorsV() const override; 02548 void setSuccessorV(unsigned idx, BasicBlock *B) override; 02549 }; 02550 02551 template <> 02552 struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> { 02553 }; 02554 02555 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value) 02556 02557 //===----------------------------------------------------------------------===// 02558 // SwitchInst Class 02559 //===----------------------------------------------------------------------===// 02560 02561 //===--------------------------------------------------------------------------- 02562 /// SwitchInst - Multiway switch 02563 /// 02564 class SwitchInst : public TerminatorInst { 02565 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 02566 unsigned ReservedSpace; 02567 // Operand[0] = Value to switch on 02568 // Operand[1] = Default basic block destination 02569 // Operand[2n ] = Value to match 02570 // Operand[2n+1] = BasicBlock to go to on match 02571 SwitchInst(const SwitchInst &SI); 02572 void init(Value *Value, BasicBlock *Default, unsigned NumReserved); 02573 void growOperands(); 02574 // allocate space for exactly zero operands 02575 void *operator new(size_t s) { 02576 return User::operator new(s, 0); 02577 } 02578 /// SwitchInst ctor - Create a new switch instruction, specifying a value to 02579 /// switch on and a default destination. The number of additional cases can 02580 /// be specified here to make memory allocation more efficient. This 02581 /// constructor can also autoinsert before another instruction. 02582 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, 02583 Instruction *InsertBefore); 02584 02585 /// SwitchInst ctor - Create a new switch instruction, specifying a value to 02586 /// switch on and a default destination. The number of additional cases can 02587 /// be specified here to make memory allocation more efficient. This 02588 /// constructor also autoinserts at the end of the specified BasicBlock. 02589 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, 02590 BasicBlock *InsertAtEnd); 02591 protected: 02592 SwitchInst *clone_impl() const override; 02593 public: 02594 02595 // -2 02596 static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1); 02597 02598 template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy> 02599 class CaseIteratorT { 02600 protected: 02601 02602 SwitchInstTy *SI; 02603 unsigned Index; 02604 02605 public: 02606 02607 typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self; 02608 02609 /// Initializes case iterator for given SwitchInst and for given 02610 /// case number. 02611 CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) { 02612 this->SI = SI; 02613 Index = CaseNum; 02614 } 02615 02616 /// Initializes case iterator for given SwitchInst and for given 02617 /// TerminatorInst's successor index. 02618 static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) { 02619 assert(SuccessorIndex < SI->getNumSuccessors() && 02620 "Successor index # out of range!"); 02621 return SuccessorIndex != 0 ? 02622 Self(SI, SuccessorIndex - 1) : 02623 Self(SI, DefaultPseudoIndex); 02624 } 02625 02626 /// Resolves case value for current case. 02627 ConstantIntTy *getCaseValue() { 02628 assert(Index < SI->getNumCases() && "Index out the number of cases."); 02629 return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2)); 02630 } 02631 02632 /// Resolves successor for current case. 02633 BasicBlockTy *getCaseSuccessor() { 02634 assert((Index < SI->getNumCases() || 02635 Index == DefaultPseudoIndex) && 02636 "Index out the number of cases."); 02637 return SI->getSuccessor(getSuccessorIndex()); 02638 } 02639 02640 /// Returns number of current case. 02641 unsigned getCaseIndex() const { return Index; } 02642 02643 /// Returns TerminatorInst's successor index for current case successor. 02644 unsigned getSuccessorIndex() const { 02645 assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) && 02646 "Index out the number of cases."); 02647 return Index != DefaultPseudoIndex ? Index + 1 : 0; 02648 } 02649 02650 Self operator++() { 02651 // Check index correctness after increment. 02652 // Note: Index == getNumCases() means end(). 02653 assert(Index+1 <= SI->getNumCases() && "Index out the number of cases."); 02654 ++Index; 02655 return *this; 02656 } 02657 Self operator++(int) { 02658 Self tmp = *this; 02659 ++(*this); 02660 return tmp; 02661 } 02662 Self operator--() { 02663 // Check index correctness after decrement. 02664 // Note: Index == getNumCases() means end(). 02665 // Also allow "-1" iterator here. That will became valid after ++. 02666 assert((Index == 0 || Index-1 <= SI->getNumCases()) && 02667 "Index out the number of cases."); 02668 --Index; 02669 return *this; 02670 } 02671 Self operator--(int) { 02672 Self tmp = *this; 02673 --(*this); 02674 return tmp; 02675 } 02676 bool operator==(const Self& RHS) const { 02677 assert(RHS.SI == SI && "Incompatible operators."); 02678 return RHS.Index == Index; 02679 } 02680 bool operator!=(const Self& RHS) const { 02681 assert(RHS.SI == SI && "Incompatible operators."); 02682 return RHS.Index != Index; 02683 } 02684 Self &operator*() { 02685 return *this; 02686 } 02687 }; 02688 02689 typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock> 02690 ConstCaseIt; 02691 02692 class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> { 02693 02694 typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy; 02695 02696 public: 02697 02698 CaseIt(const ParentTy& Src) : ParentTy(Src) {} 02699 CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {} 02700 02701 /// Sets the new value for current case. 02702 void setValue(ConstantInt *V) { 02703 assert(Index < SI->getNumCases() && "Index out the number of cases."); 02704 SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V)); 02705 } 02706 02707 /// Sets the new successor for current case. 02708 void setSuccessor(BasicBlock *S) { 02709 SI->setSuccessor(getSuccessorIndex(), S); 02710 } 02711 }; 02712 02713 static SwitchInst *Create(Value *Value, BasicBlock *Default, 02714 unsigned NumCases, 02715 Instruction *InsertBefore = nullptr) { 02716 return new SwitchInst(Value, Default, NumCases, InsertBefore); 02717 } 02718 static SwitchInst *Create(Value *Value, BasicBlock *Default, 02719 unsigned NumCases, BasicBlock *InsertAtEnd) { 02720 return new SwitchInst(Value, Default, NumCases, InsertAtEnd); 02721 } 02722 02723 ~SwitchInst(); 02724 02725 /// Provide fast operand accessors 02726 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 02727 02728 // Accessor Methods for Switch stmt 02729 Value *getCondition() const { return getOperand(0); } 02730 void setCondition(Value *V) { setOperand(0, V); } 02731 02732 BasicBlock *getDefaultDest() const { 02733 return cast<BasicBlock>(getOperand(1)); 02734 } 02735 02736 void setDefaultDest(BasicBlock *DefaultCase) { 02737 setOperand(1, reinterpret_cast<Value*>(DefaultCase)); 02738 } 02739 02740 /// getNumCases - return the number of 'cases' in this switch instruction, 02741 /// except the default case 02742 unsigned getNumCases() const { 02743 return getNumOperands()/2 - 1; 02744 } 02745 02746 /// Returns a read/write iterator that points to the first 02747 /// case in SwitchInst. 02748 CaseIt case_begin() { 02749 return CaseIt(this, 0); 02750 } 02751 /// Returns a read-only iterator that points to the first 02752 /// case in the SwitchInst. 02753 ConstCaseIt case_begin() const { 02754 return ConstCaseIt(this, 0); 02755 } 02756 02757 /// Returns a read/write iterator that points one past the last 02758 /// in the SwitchInst. 02759 CaseIt case_end() { 02760 return CaseIt(this, getNumCases()); 02761 } 02762 /// Returns a read-only iterator that points one past the last 02763 /// in the SwitchInst. 02764 ConstCaseIt case_end() const { 02765 return ConstCaseIt(this, getNumCases()); 02766 } 02767 02768 /// cases - iteration adapter for range-for loops. 02769 iterator_range<CaseIt> cases() { 02770 return iterator_range<CaseIt>(case_begin(), case_end()); 02771 } 02772 02773 /// cases - iteration adapter for range-for loops. 02774 iterator_range<ConstCaseIt> cases() const { 02775 return iterator_range<ConstCaseIt>(case_begin(), case_end()); 02776 } 02777 02778 /// Returns an iterator that points to the default case. 02779 /// Note: this iterator allows to resolve successor only. Attempt 02780 /// to resolve case value causes an assertion. 02781 /// Also note, that increment and decrement also causes an assertion and 02782 /// makes iterator invalid. 02783 CaseIt case_default() { 02784 return CaseIt(this, DefaultPseudoIndex); 02785 } 02786 ConstCaseIt case_default() const { 02787 return ConstCaseIt(this, DefaultPseudoIndex); 02788 } 02789 02790 /// findCaseValue - Search all of the case values for the specified constant. 02791 /// If it is explicitly handled, return the case iterator of it, otherwise 02792 /// return default case iterator to indicate 02793 /// that it is handled by the default handler. 02794 CaseIt findCaseValue(const ConstantInt *C) { 02795 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) 02796 if (i.getCaseValue() == C) 02797 return i; 02798 return case_default(); 02799 } 02800 ConstCaseIt findCaseValue(const ConstantInt *C) const { 02801 for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i) 02802 if (i.getCaseValue() == C) 02803 return i; 02804 return case_default(); 02805 } 02806 02807 /// findCaseDest - Finds the unique case value for a given successor. Returns 02808 /// null if the successor is not found, not unique, or is the default case. 02809 ConstantInt *findCaseDest(BasicBlock *BB) { 02810 if (BB == getDefaultDest()) return nullptr; 02811 02812 ConstantInt *CI = nullptr; 02813 for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) { 02814 if (i.getCaseSuccessor() == BB) { 02815 if (CI) return nullptr; // Multiple cases lead to BB. 02816 else CI = i.getCaseValue(); 02817 } 02818 } 02819 return CI; 02820 } 02821 02822 /// addCase - Add an entry to the switch instruction... 02823 /// Note: 02824 /// This action invalidates case_end(). Old case_end() iterator will 02825 /// point to the added case. 02826 void addCase(ConstantInt *OnVal, BasicBlock *Dest); 02827 02828 /// removeCase - This method removes the specified case and its successor 02829 /// from the switch instruction. Note that this operation may reorder the 02830 /// remaining cases at index idx and above. 02831 /// Note: 02832 /// This action invalidates iterators for all cases following the one removed, 02833 /// including the case_end() iterator. 02834 void removeCase(CaseIt i); 02835 02836 unsigned getNumSuccessors() const { return getNumOperands()/2; } 02837 BasicBlock *getSuccessor(unsigned idx) const { 02838 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!"); 02839 return cast<BasicBlock>(getOperand(idx*2+1)); 02840 } 02841 void setSuccessor(unsigned idx, BasicBlock *NewSucc) { 02842 assert(idx < getNumSuccessors() && "Successor # out of range for switch!"); 02843 setOperand(idx*2+1, (Value*)NewSucc); 02844 } 02845 02846 // Methods for support type inquiry through isa, cast, and dyn_cast: 02847 static inline bool classof(const Instruction *I) { 02848 return I->getOpcode() == Instruction::Switch; 02849 } 02850 static inline bool classof(const Value *V) { 02851 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02852 } 02853 private: 02854 BasicBlock *getSuccessorV(unsigned idx) const override; 02855 unsigned getNumSuccessorsV() const override; 02856 void setSuccessorV(unsigned idx, BasicBlock *B) override; 02857 }; 02858 02859 template <> 02860 struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> { 02861 }; 02862 02863 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value) 02864 02865 02866 //===----------------------------------------------------------------------===// 02867 // IndirectBrInst Class 02868 //===----------------------------------------------------------------------===// 02869 02870 //===--------------------------------------------------------------------------- 02871 /// IndirectBrInst - Indirect Branch Instruction. 02872 /// 02873 class IndirectBrInst : public TerminatorInst { 02874 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 02875 unsigned ReservedSpace; 02876 // Operand[0] = Value to switch on 02877 // Operand[1] = Default basic block destination 02878 // Operand[2n ] = Value to match 02879 // Operand[2n+1] = BasicBlock to go to on match 02880 IndirectBrInst(const IndirectBrInst &IBI); 02881 void init(Value *Address, unsigned NumDests); 02882 void growOperands(); 02883 // allocate space for exactly zero operands 02884 void *operator new(size_t s) { 02885 return User::operator new(s, 0); 02886 } 02887 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an 02888 /// Address to jump to. The number of expected destinations can be specified 02889 /// here to make memory allocation more efficient. This constructor can also 02890 /// autoinsert before another instruction. 02891 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore); 02892 02893 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an 02894 /// Address to jump to. The number of expected destinations can be specified 02895 /// here to make memory allocation more efficient. This constructor also 02896 /// autoinserts at the end of the specified BasicBlock. 02897 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd); 02898 protected: 02899 IndirectBrInst *clone_impl() const override; 02900 public: 02901 static IndirectBrInst *Create(Value *Address, unsigned NumDests, 02902 Instruction *InsertBefore = nullptr) { 02903 return new IndirectBrInst(Address, NumDests, InsertBefore); 02904 } 02905 static IndirectBrInst *Create(Value *Address, unsigned NumDests, 02906 BasicBlock *InsertAtEnd) { 02907 return new IndirectBrInst(Address, NumDests, InsertAtEnd); 02908 } 02909 ~IndirectBrInst(); 02910 02911 /// Provide fast operand accessors. 02912 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 02913 02914 // Accessor Methods for IndirectBrInst instruction. 02915 Value *getAddress() { return getOperand(0); } 02916 const Value *getAddress() const { return getOperand(0); } 02917 void setAddress(Value *V) { setOperand(0, V); } 02918 02919 02920 /// getNumDestinations - return the number of possible destinations in this 02921 /// indirectbr instruction. 02922 unsigned getNumDestinations() const { return getNumOperands()-1; } 02923 02924 /// getDestination - Return the specified destination. 02925 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); } 02926 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); } 02927 02928 /// addDestination - Add a destination. 02929 /// 02930 void addDestination(BasicBlock *Dest); 02931 02932 /// removeDestination - This method removes the specified successor from the 02933 /// indirectbr instruction. 02934 void removeDestination(unsigned i); 02935 02936 unsigned getNumSuccessors() const { return getNumOperands()-1; } 02937 BasicBlock *getSuccessor(unsigned i) const { 02938 return cast<BasicBlock>(getOperand(i+1)); 02939 } 02940 void setSuccessor(unsigned i, BasicBlock *NewSucc) { 02941 setOperand(i+1, (Value*)NewSucc); 02942 } 02943 02944 // Methods for support type inquiry through isa, cast, and dyn_cast: 02945 static inline bool classof(const Instruction *I) { 02946 return I->getOpcode() == Instruction::IndirectBr; 02947 } 02948 static inline bool classof(const Value *V) { 02949 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 02950 } 02951 private: 02952 BasicBlock *getSuccessorV(unsigned idx) const override; 02953 unsigned getNumSuccessorsV() const override; 02954 void setSuccessorV(unsigned idx, BasicBlock *B) override; 02955 }; 02956 02957 template <> 02958 struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> { 02959 }; 02960 02961 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value) 02962 02963 02964 //===----------------------------------------------------------------------===// 02965 // InvokeInst Class 02966 //===----------------------------------------------------------------------===// 02967 02968 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the 02969 /// calling convention of the call. 02970 /// 02971 class InvokeInst : public TerminatorInst { 02972 AttributeSet AttributeList; 02973 InvokeInst(const InvokeInst &BI); 02974 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, 02975 ArrayRef<Value *> Args, const Twine &NameStr); 02976 02977 /// Construct an InvokeInst given a range of arguments. 02978 /// 02979 /// \brief Construct an InvokeInst from a range of arguments 02980 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, 02981 ArrayRef<Value *> Args, unsigned Values, 02982 const Twine &NameStr, Instruction *InsertBefore); 02983 02984 /// Construct an InvokeInst given a range of arguments. 02985 /// 02986 /// \brief Construct an InvokeInst from a range of arguments 02987 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, 02988 ArrayRef<Value *> Args, unsigned Values, 02989 const Twine &NameStr, BasicBlock *InsertAtEnd); 02990 protected: 02991 InvokeInst *clone_impl() const override; 02992 public: 02993 static InvokeInst *Create(Value *Func, 02994 BasicBlock *IfNormal, BasicBlock *IfException, 02995 ArrayRef<Value *> Args, const Twine &NameStr = "", 02996 Instruction *InsertBefore = nullptr) { 02997 unsigned Values = unsigned(Args.size()) + 3; 02998 return new(Values) InvokeInst(Func, IfNormal, IfException, Args, 02999 Values, NameStr, InsertBefore); 03000 } 03001 static InvokeInst *Create(Value *Func, 03002 BasicBlock *IfNormal, BasicBlock *IfException, 03003 ArrayRef<Value *> Args, const Twine &NameStr, 03004 BasicBlock *InsertAtEnd) { 03005 unsigned Values = unsigned(Args.size()) + 3; 03006 return new(Values) InvokeInst(Func, IfNormal, IfException, Args, 03007 Values, NameStr, InsertAtEnd); 03008 } 03009 03010 /// Provide fast operand accessors 03011 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 03012 03013 /// getNumArgOperands - Return the number of invoke arguments. 03014 /// 03015 unsigned getNumArgOperands() const { return getNumOperands() - 3; } 03016 03017 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument. 03018 /// 03019 Value *getArgOperand(unsigned i) const { return getOperand(i); } 03020 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); } 03021 03022 /// arg_operands - iteration adapter for range-for loops. 03023 iterator_range<op_iterator> arg_operands() { 03024 return iterator_range<op_iterator>(op_begin(), op_end() - 3); 03025 } 03026 03027 /// arg_operands - iteration adapter for range-for loops. 03028 iterator_range<const_op_iterator> arg_operands() const { 03029 return iterator_range<const_op_iterator>(op_begin(), op_end() - 3); 03030 } 03031 03032 /// \brief Wrappers for getting the \c Use of a invoke argument. 03033 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); } 03034 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); } 03035 03036 /// getCallingConv/setCallingConv - Get or set the calling convention of this 03037 /// function call. 03038 CallingConv::ID getCallingConv() const { 03039 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction()); 03040 } 03041 void setCallingConv(CallingConv::ID CC) { 03042 setInstructionSubclassData(static_cast<unsigned>(CC)); 03043 } 03044 03045 /// getAttributes - Return the parameter attributes for this invoke. 03046 /// 03047 const AttributeSet &getAttributes() const { return AttributeList; } 03048 03049 /// setAttributes - Set the parameter attributes for this invoke. 03050 /// 03051 void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; } 03052 03053 /// addAttribute - adds the attribute to the list of attributes. 03054 void addAttribute(unsigned i, Attribute::AttrKind attr); 03055 03056 /// removeAttribute - removes the attribute from the list of attributes. 03057 void removeAttribute(unsigned i, Attribute attr); 03058 03059 /// \brief Determine whether this call has the given attribute. 03060 bool hasFnAttr(Attribute::AttrKind A) const { 03061 assert(A != Attribute::NoBuiltin && 03062 "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin"); 03063 return hasFnAttrImpl(A); 03064 } 03065 03066 /// \brief Determine whether the call or the callee has the given attributes. 03067 bool paramHasAttr(unsigned i, Attribute::AttrKind A) const; 03068 03069 /// \brief Extract the alignment for a call or parameter (0=unknown). 03070 unsigned getParamAlignment(unsigned i) const { 03071 return AttributeList.getParamAlignment(i); 03072 } 03073 03074 /// \brief Extract the number of dereferenceable bytes for a call or 03075 /// parameter (0=unknown). 03076 uint64_t getDereferenceableBytes(unsigned i) const { 03077 return AttributeList.getDereferenceableBytes(i); 03078 } 03079 03080 /// \brief Return true if the call should not be treated as a call to a 03081 /// builtin. 03082 bool isNoBuiltin() const { 03083 // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have 03084 // to check it by hand. 03085 return hasFnAttrImpl(Attribute::NoBuiltin) && 03086 !hasFnAttrImpl(Attribute::Builtin); 03087 } 03088 03089 /// \brief Return true if the call should not be inlined. 03090 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); } 03091 void setIsNoInline() { 03092 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline); 03093 } 03094 03095 /// \brief Determine if the call does not access memory. 03096 bool doesNotAccessMemory() const { 03097 return hasFnAttr(Attribute::ReadNone); 03098 } 03099 void setDoesNotAccessMemory() { 03100 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone); 03101 } 03102 03103 /// \brief Determine if the call does not access or only reads memory. 03104 bool onlyReadsMemory() const { 03105 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly); 03106 } 03107 void setOnlyReadsMemory() { 03108 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly); 03109 } 03110 03111 /// \brief Determine if the call cannot return. 03112 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); } 03113 void setDoesNotReturn() { 03114 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn); 03115 } 03116 03117 /// \brief Determine if the call cannot unwind. 03118 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); } 03119 void setDoesNotThrow() { 03120 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind); 03121 } 03122 03123 /// \brief Determine if the invoke cannot be duplicated. 03124 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); } 03125 void setCannotDuplicate() { 03126 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate); 03127 } 03128 03129 /// \brief Determine if the call returns a structure through first 03130 /// pointer argument. 03131 bool hasStructRetAttr() const { 03132 // Be friendly and also check the callee. 03133 return paramHasAttr(1, Attribute::StructRet); 03134 } 03135 03136 /// \brief Determine if any call argument is an aggregate passed by value. 03137 bool hasByValArgument() const { 03138 return AttributeList.hasAttrSomewhere(Attribute::ByVal); 03139 } 03140 03141 /// getCalledFunction - Return the function called, or null if this is an 03142 /// indirect function invocation. 03143 /// 03144 Function *getCalledFunction() const { 03145 return dyn_cast<Function>(Op<-3>()); 03146 } 03147 03148 /// getCalledValue - Get a pointer to the function that is invoked by this 03149 /// instruction 03150 const Value *getCalledValue() const { return Op<-3>(); } 03151 Value *getCalledValue() { return Op<-3>(); } 03152 03153 /// setCalledFunction - Set the function called. 03154 void setCalledFunction(Value* Fn) { 03155 Op<-3>() = Fn; 03156 } 03157 03158 // get*Dest - Return the destination basic blocks... 03159 BasicBlock *getNormalDest() const { 03160 return cast<BasicBlock>(Op<-2>()); 03161 } 03162 BasicBlock *getUnwindDest() const { 03163 return cast<BasicBlock>(Op<-1>()); 03164 } 03165 void setNormalDest(BasicBlock *B) { 03166 Op<-2>() = reinterpret_cast<Value*>(B); 03167 } 03168 void setUnwindDest(BasicBlock *B) { 03169 Op<-1>() = reinterpret_cast<Value*>(B); 03170 } 03171 03172 /// getLandingPadInst - Get the landingpad instruction from the landing pad 03173 /// block (the unwind destination). 03174 LandingPadInst *getLandingPadInst() const; 03175 03176 BasicBlock *getSuccessor(unsigned i) const { 03177 assert(i < 2 && "Successor # out of range for invoke!"); 03178 return i == 0 ? getNormalDest() : getUnwindDest(); 03179 } 03180 03181 void setSuccessor(unsigned idx, BasicBlock *NewSucc) { 03182 assert(idx < 2 && "Successor # out of range for invoke!"); 03183 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc); 03184 } 03185 03186 unsigned getNumSuccessors() const { return 2; } 03187 03188 // Methods for support type inquiry through isa, cast, and dyn_cast: 03189 static inline bool classof(const Instruction *I) { 03190 return (I->getOpcode() == Instruction::Invoke); 03191 } 03192 static inline bool classof(const Value *V) { 03193 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03194 } 03195 03196 private: 03197 BasicBlock *getSuccessorV(unsigned idx) const override; 03198 unsigned getNumSuccessorsV() const override; 03199 void setSuccessorV(unsigned idx, BasicBlock *B) override; 03200 03201 bool hasFnAttrImpl(Attribute::AttrKind A) const; 03202 03203 // Shadow Instruction::setInstructionSubclassData with a private forwarding 03204 // method so that subclasses cannot accidentally use it. 03205 void setInstructionSubclassData(unsigned short D) { 03206 Instruction::setInstructionSubclassData(D); 03207 } 03208 }; 03209 03210 template <> 03211 struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> { 03212 }; 03213 03214 InvokeInst::InvokeInst(Value *Func, 03215 BasicBlock *IfNormal, BasicBlock *IfException, 03216 ArrayRef<Value *> Args, unsigned Values, 03217 const Twine &NameStr, Instruction *InsertBefore) 03218 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) 03219 ->getElementType())->getReturnType(), 03220 Instruction::Invoke, 03221 OperandTraits<InvokeInst>::op_end(this) - Values, 03222 Values, InsertBefore) { 03223 init(Func, IfNormal, IfException, Args, NameStr); 03224 } 03225 InvokeInst::InvokeInst(Value *Func, 03226 BasicBlock *IfNormal, BasicBlock *IfException, 03227 ArrayRef<Value *> Args, unsigned Values, 03228 const Twine &NameStr, BasicBlock *InsertAtEnd) 03229 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) 03230 ->getElementType())->getReturnType(), 03231 Instruction::Invoke, 03232 OperandTraits<InvokeInst>::op_end(this) - Values, 03233 Values, InsertAtEnd) { 03234 init(Func, IfNormal, IfException, Args, NameStr); 03235 } 03236 03237 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value) 03238 03239 //===----------------------------------------------------------------------===// 03240 // ResumeInst Class 03241 //===----------------------------------------------------------------------===// 03242 03243 //===--------------------------------------------------------------------------- 03244 /// ResumeInst - Resume the propagation of an exception. 03245 /// 03246 class ResumeInst : public TerminatorInst { 03247 ResumeInst(const ResumeInst &RI); 03248 03249 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr); 03250 ResumeInst(Value *Exn, BasicBlock *InsertAtEnd); 03251 protected: 03252 ResumeInst *clone_impl() const override; 03253 public: 03254 static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) { 03255 return new(1) ResumeInst(Exn, InsertBefore); 03256 } 03257 static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) { 03258 return new(1) ResumeInst(Exn, InsertAtEnd); 03259 } 03260 03261 /// Provide fast operand accessors 03262 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 03263 03264 /// Convenience accessor. 03265 Value *getValue() const { return Op<0>(); } 03266 03267 unsigned getNumSuccessors() const { return 0; } 03268 03269 // Methods for support type inquiry through isa, cast, and dyn_cast: 03270 static inline bool classof(const Instruction *I) { 03271 return I->getOpcode() == Instruction::Resume; 03272 } 03273 static inline bool classof(const Value *V) { 03274 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03275 } 03276 private: 03277 BasicBlock *getSuccessorV(unsigned idx) const override; 03278 unsigned getNumSuccessorsV() const override; 03279 void setSuccessorV(unsigned idx, BasicBlock *B) override; 03280 }; 03281 03282 template <> 03283 struct OperandTraits<ResumeInst> : 03284 public FixedNumOperandTraits<ResumeInst, 1> { 03285 }; 03286 03287 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value) 03288 03289 //===----------------------------------------------------------------------===// 03290 // UnreachableInst Class 03291 //===----------------------------------------------------------------------===// 03292 03293 //===--------------------------------------------------------------------------- 03294 /// UnreachableInst - This function has undefined behavior. In particular, the 03295 /// presence of this instruction indicates some higher level knowledge that the 03296 /// end of the block cannot be reached. 03297 /// 03298 class UnreachableInst : public TerminatorInst { 03299 void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 03300 protected: 03301 UnreachableInst *clone_impl() const override; 03302 03303 public: 03304 // allocate space for exactly zero operands 03305 void *operator new(size_t s) { 03306 return User::operator new(s, 0); 03307 } 03308 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr); 03309 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd); 03310 03311 unsigned getNumSuccessors() const { return 0; } 03312 03313 // Methods for support type inquiry through isa, cast, and dyn_cast: 03314 static inline bool classof(const Instruction *I) { 03315 return I->getOpcode() == Instruction::Unreachable; 03316 } 03317 static inline bool classof(const Value *V) { 03318 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03319 } 03320 private: 03321 BasicBlock *getSuccessorV(unsigned idx) const override; 03322 unsigned getNumSuccessorsV() const override; 03323 void setSuccessorV(unsigned idx, BasicBlock *B) override; 03324 }; 03325 03326 //===----------------------------------------------------------------------===// 03327 // TruncInst Class 03328 //===----------------------------------------------------------------------===// 03329 03330 /// \brief This class represents a truncation of integer types. 03331 class TruncInst : public CastInst { 03332 protected: 03333 /// \brief Clone an identical TruncInst 03334 TruncInst *clone_impl() const override; 03335 03336 public: 03337 /// \brief Constructor with insert-before-instruction semantics 03338 TruncInst( 03339 Value *S, ///< The value to be truncated 03340 Type *Ty, ///< The (smaller) type to truncate to 03341 const Twine &NameStr = "", ///< A name for the new instruction 03342 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction 03343 ); 03344 03345 /// \brief Constructor with insert-at-end-of-block semantics 03346 TruncInst( 03347 Value *S, ///< The value to be truncated 03348 Type *Ty, ///< The (smaller) type to truncate to 03349 const Twine &NameStr, ///< A name for the new instruction 03350 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 03351 ); 03352 03353 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 03354 static inline bool classof(const Instruction *I) { 03355 return I->getOpcode() == Trunc; 03356 } 03357 static inline bool classof(const Value *V) { 03358 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03359 } 03360 }; 03361 03362 //===----------------------------------------------------------------------===// 03363 // ZExtInst Class 03364 //===----------------------------------------------------------------------===// 03365 03366 /// \brief This class represents zero extension of integer types. 03367 class ZExtInst : public CastInst { 03368 protected: 03369 /// \brief Clone an identical ZExtInst 03370 ZExtInst *clone_impl() const override; 03371 03372 public: 03373 /// \brief Constructor with insert-before-instruction semantics 03374 ZExtInst( 03375 Value *S, ///< The value to be zero extended 03376 Type *Ty, ///< The type to zero extend to 03377 const Twine &NameStr = "", ///< A name for the new instruction 03378 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction 03379 ); 03380 03381 /// \brief Constructor with insert-at-end semantics. 03382 ZExtInst( 03383 Value *S, ///< The value to be zero extended 03384 Type *Ty, ///< The type to zero extend to 03385 const Twine &NameStr, ///< A name for the new instruction 03386 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 03387 ); 03388 03389 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 03390 static inline bool classof(const Instruction *I) { 03391 return I->getOpcode() == ZExt; 03392 } 03393 static inline bool classof(const Value *V) { 03394 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03395 } 03396 }; 03397 03398 //===----------------------------------------------------------------------===// 03399 // SExtInst Class 03400 //===----------------------------------------------------------------------===// 03401 03402 /// \brief This class represents a sign extension of integer types. 03403 class SExtInst : public CastInst { 03404 protected: 03405 /// \brief Clone an identical SExtInst 03406 SExtInst *clone_impl() const override; 03407 03408 public: 03409 /// \brief Constructor with insert-before-instruction semantics 03410 SExtInst( 03411 Value *S, ///< The value to be sign extended 03412 Type *Ty, ///< The type to sign extend to 03413 const Twine &NameStr = "", ///< A name for the new instruction 03414 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction 03415 ); 03416 03417 /// \brief Constructor with insert-at-end-of-block semantics 03418 SExtInst( 03419 Value *S, ///< The value to be sign extended 03420 Type *Ty, ///< The type to sign extend to 03421 const Twine &NameStr, ///< A name for the new instruction 03422 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 03423 ); 03424 03425 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 03426 static inline bool classof(const Instruction *I) { 03427 return I->getOpcode() == SExt; 03428 } 03429 static inline bool classof(const Value *V) { 03430 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03431 } 03432 }; 03433 03434 //===----------------------------------------------------------------------===// 03435 // FPTruncInst Class 03436 //===----------------------------------------------------------------------===// 03437 03438 /// \brief This class represents a truncation of floating point types. 03439 class FPTruncInst : public CastInst { 03440 protected: 03441 /// \brief Clone an identical FPTruncInst 03442 FPTruncInst *clone_impl() const override; 03443 03444 public: 03445 /// \brief Constructor with insert-before-instruction semantics 03446 FPTruncInst( 03447 Value *S, ///< The value to be truncated 03448 Type *Ty, ///< The type to truncate to 03449 const Twine &NameStr = "", ///< A name for the new instruction 03450 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction 03451 ); 03452 03453 /// \brief Constructor with insert-before-instruction semantics 03454 FPTruncInst( 03455 Value *S, ///< The value to be truncated 03456 Type *Ty, ///< The type to truncate to 03457 const Twine &NameStr, ///< A name for the new instruction 03458 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 03459 ); 03460 03461 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 03462 static inline bool classof(const Instruction *I) { 03463 return I->getOpcode() == FPTrunc; 03464 } 03465 static inline bool classof(const Value *V) { 03466 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03467 } 03468 }; 03469 03470 //===----------------------------------------------------------------------===// 03471 // FPExtInst Class 03472 //===----------------------------------------------------------------------===// 03473 03474 /// \brief This class represents an extension of floating point types. 03475 class FPExtInst : public CastInst { 03476 protected: 03477 /// \brief Clone an identical FPExtInst 03478 FPExtInst *clone_impl() const override; 03479 03480 public: 03481 /// \brief Constructor with insert-before-instruction semantics 03482 FPExtInst( 03483 Value *S, ///< The value to be extended 03484 Type *Ty, ///< The type to extend to 03485 const Twine &NameStr = "", ///< A name for the new instruction 03486 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction 03487 ); 03488 03489 /// \brief Constructor with insert-at-end-of-block semantics 03490 FPExtInst( 03491 Value *S, ///< The value to be extended 03492 Type *Ty, ///< The type to extend to 03493 const Twine &NameStr, ///< A name for the new instruction 03494 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 03495 ); 03496 03497 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 03498 static inline bool classof(const Instruction *I) { 03499 return I->getOpcode() == FPExt; 03500 } 03501 static inline bool classof(const Value *V) { 03502 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03503 } 03504 }; 03505 03506 //===----------------------------------------------------------------------===// 03507 // UIToFPInst Class 03508 //===----------------------------------------------------------------------===// 03509 03510 /// \brief This class represents a cast unsigned integer to floating point. 03511 class UIToFPInst : public CastInst { 03512 protected: 03513 /// \brief Clone an identical UIToFPInst 03514 UIToFPInst *clone_impl() const override; 03515 03516 public: 03517 /// \brief Constructor with insert-before-instruction semantics 03518 UIToFPInst( 03519 Value *S, ///< The value to be converted 03520 Type *Ty, ///< The type to convert to 03521 const Twine &NameStr = "", ///< A name for the new instruction 03522 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction 03523 ); 03524 03525 /// \brief Constructor with insert-at-end-of-block semantics 03526 UIToFPInst( 03527 Value *S, ///< The value to be converted 03528 Type *Ty, ///< The type to convert to 03529 const Twine &NameStr, ///< A name for the new instruction 03530 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 03531 ); 03532 03533 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 03534 static inline bool classof(const Instruction *I) { 03535 return I->getOpcode() == UIToFP; 03536 } 03537 static inline bool classof(const Value *V) { 03538 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03539 } 03540 }; 03541 03542 //===----------------------------------------------------------------------===// 03543 // SIToFPInst Class 03544 //===----------------------------------------------------------------------===// 03545 03546 /// \brief This class represents a cast from signed integer to floating point. 03547 class SIToFPInst : public CastInst { 03548 protected: 03549 /// \brief Clone an identical SIToFPInst 03550 SIToFPInst *clone_impl() const override; 03551 03552 public: 03553 /// \brief Constructor with insert-before-instruction semantics 03554 SIToFPInst( 03555 Value *S, ///< The value to be converted 03556 Type *Ty, ///< The type to convert to 03557 const Twine &NameStr = "", ///< A name for the new instruction 03558 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction 03559 ); 03560 03561 /// \brief Constructor with insert-at-end-of-block semantics 03562 SIToFPInst( 03563 Value *S, ///< The value to be converted 03564 Type *Ty, ///< The type to convert to 03565 const Twine &NameStr, ///< A name for the new instruction 03566 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 03567 ); 03568 03569 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 03570 static inline bool classof(const Instruction *I) { 03571 return I->getOpcode() == SIToFP; 03572 } 03573 static inline bool classof(const Value *V) { 03574 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03575 } 03576 }; 03577 03578 //===----------------------------------------------------------------------===// 03579 // FPToUIInst Class 03580 //===----------------------------------------------------------------------===// 03581 03582 /// \brief This class represents a cast from floating point to unsigned integer 03583 class FPToUIInst : public CastInst { 03584 protected: 03585 /// \brief Clone an identical FPToUIInst 03586 FPToUIInst *clone_impl() const override; 03587 03588 public: 03589 /// \brief Constructor with insert-before-instruction semantics 03590 FPToUIInst( 03591 Value *S, ///< The value to be converted 03592 Type *Ty, ///< The type to convert to 03593 const Twine &NameStr = "", ///< A name for the new instruction 03594 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction 03595 ); 03596 03597 /// \brief Constructor with insert-at-end-of-block semantics 03598 FPToUIInst( 03599 Value *S, ///< The value to be converted 03600 Type *Ty, ///< The type to convert to 03601 const Twine &NameStr, ///< A name for the new instruction 03602 BasicBlock *InsertAtEnd ///< Where to insert the new instruction 03603 ); 03604 03605 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 03606 static inline bool classof(const Instruction *I) { 03607 return I->getOpcode() == FPToUI; 03608 } 03609 static inline bool classof(const Value *V) { 03610 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03611 } 03612 }; 03613 03614 //===----------------------------------------------------------------------===// 03615 // FPToSIInst Class 03616 //===----------------------------------------------------------------------===// 03617 03618 /// \brief This class represents a cast from floating point to signed integer. 03619 class FPToSIInst : public CastInst { 03620 protected: 03621 /// \brief Clone an identical FPToSIInst 03622 FPToSIInst *clone_impl() const override; 03623 03624 public: 03625 /// \brief Constructor with insert-before-instruction semantics 03626 FPToSIInst( 03627 Value *S, ///< The value to be converted 03628 Type *Ty, ///< The type to convert to 03629 const Twine &NameStr = "", ///< A name for the new instruction 03630 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction 03631 ); 03632 03633 /// \brief Constructor with insert-at-end-of-block semantics 03634 FPToSIInst( 03635 Value *S, ///< The value to be converted 03636 Type *Ty, ///< The type to convert to 03637 const Twine &NameStr, ///< A name for the new instruction 03638 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 03639 ); 03640 03641 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 03642 static inline bool classof(const Instruction *I) { 03643 return I->getOpcode() == FPToSI; 03644 } 03645 static inline bool classof(const Value *V) { 03646 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03647 } 03648 }; 03649 03650 //===----------------------------------------------------------------------===// 03651 // IntToPtrInst Class 03652 //===----------------------------------------------------------------------===// 03653 03654 /// \brief This class represents a cast from an integer to a pointer. 03655 class IntToPtrInst : public CastInst { 03656 public: 03657 /// \brief Constructor with insert-before-instruction semantics 03658 IntToPtrInst( 03659 Value *S, ///< The value to be converted 03660 Type *Ty, ///< The type to convert to 03661 const Twine &NameStr = "", ///< A name for the new instruction 03662 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction 03663 ); 03664 03665 /// \brief Constructor with insert-at-end-of-block semantics 03666 IntToPtrInst( 03667 Value *S, ///< The value to be converted 03668 Type *Ty, ///< The type to convert to 03669 const Twine &NameStr, ///< A name for the new instruction 03670 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 03671 ); 03672 03673 /// \brief Clone an identical IntToPtrInst 03674 IntToPtrInst *clone_impl() const override; 03675 03676 /// \brief Returns the address space of this instruction's pointer type. 03677 unsigned getAddressSpace() const { 03678 return getType()->getPointerAddressSpace(); 03679 } 03680 03681 // Methods for support type inquiry through isa, cast, and dyn_cast: 03682 static inline bool classof(const Instruction *I) { 03683 return I->getOpcode() == IntToPtr; 03684 } 03685 static inline bool classof(const Value *V) { 03686 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03687 } 03688 }; 03689 03690 //===----------------------------------------------------------------------===// 03691 // PtrToIntInst Class 03692 //===----------------------------------------------------------------------===// 03693 03694 /// \brief This class represents a cast from a pointer to an integer 03695 class PtrToIntInst : public CastInst { 03696 protected: 03697 /// \brief Clone an identical PtrToIntInst 03698 PtrToIntInst *clone_impl() const override; 03699 03700 public: 03701 /// \brief Constructor with insert-before-instruction semantics 03702 PtrToIntInst( 03703 Value *S, ///< The value to be converted 03704 Type *Ty, ///< The type to convert to 03705 const Twine &NameStr = "", ///< A name for the new instruction 03706 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction 03707 ); 03708 03709 /// \brief Constructor with insert-at-end-of-block semantics 03710 PtrToIntInst( 03711 Value *S, ///< The value to be converted 03712 Type *Ty, ///< The type to convert to 03713 const Twine &NameStr, ///< A name for the new instruction 03714 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 03715 ); 03716 03717 /// \brief Gets the pointer operand. 03718 Value *getPointerOperand() { return getOperand(0); } 03719 /// \brief Gets the pointer operand. 03720 const Value *getPointerOperand() const { return getOperand(0); } 03721 /// \brief Gets the operand index of the pointer operand. 03722 static unsigned getPointerOperandIndex() { return 0U; } 03723 03724 /// \brief Returns the address space of the pointer operand. 03725 unsigned getPointerAddressSpace() const { 03726 return getPointerOperand()->getType()->getPointerAddressSpace(); 03727 } 03728 03729 // Methods for support type inquiry through isa, cast, and dyn_cast: 03730 static inline bool classof(const Instruction *I) { 03731 return I->getOpcode() == PtrToInt; 03732 } 03733 static inline bool classof(const Value *V) { 03734 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03735 } 03736 }; 03737 03738 //===----------------------------------------------------------------------===// 03739 // BitCastInst Class 03740 //===----------------------------------------------------------------------===// 03741 03742 /// \brief This class represents a no-op cast from one type to another. 03743 class BitCastInst : public CastInst { 03744 protected: 03745 /// \brief Clone an identical BitCastInst 03746 BitCastInst *clone_impl() const override; 03747 03748 public: 03749 /// \brief Constructor with insert-before-instruction semantics 03750 BitCastInst( 03751 Value *S, ///< The value to be casted 03752 Type *Ty, ///< The type to casted to 03753 const Twine &NameStr = "", ///< A name for the new instruction 03754 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction 03755 ); 03756 03757 /// \brief Constructor with insert-at-end-of-block semantics 03758 BitCastInst( 03759 Value *S, ///< The value to be casted 03760 Type *Ty, ///< The type to casted to 03761 const Twine &NameStr, ///< A name for the new instruction 03762 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 03763 ); 03764 03765 // Methods for support type inquiry through isa, cast, and dyn_cast: 03766 static inline bool classof(const Instruction *I) { 03767 return I->getOpcode() == BitCast; 03768 } 03769 static inline bool classof(const Value *V) { 03770 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03771 } 03772 }; 03773 03774 //===----------------------------------------------------------------------===// 03775 // AddrSpaceCastInst Class 03776 //===----------------------------------------------------------------------===// 03777 03778 /// \brief This class represents a conversion between pointers from 03779 /// one address space to another. 03780 class AddrSpaceCastInst : public CastInst { 03781 protected: 03782 /// \brief Clone an identical AddrSpaceCastInst 03783 AddrSpaceCastInst *clone_impl() const override; 03784 03785 public: 03786 /// \brief Constructor with insert-before-instruction semantics 03787 AddrSpaceCastInst( 03788 Value *S, ///< The value to be casted 03789 Type *Ty, ///< The type to casted to 03790 const Twine &NameStr = "", ///< A name for the new instruction 03791 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction 03792 ); 03793 03794 /// \brief Constructor with insert-at-end-of-block semantics 03795 AddrSpaceCastInst( 03796 Value *S, ///< The value to be casted 03797 Type *Ty, ///< The type to casted to 03798 const Twine &NameStr, ///< A name for the new instruction 03799 BasicBlock *InsertAtEnd ///< The block to insert the instruction into 03800 ); 03801 03802 // Methods for support type inquiry through isa, cast, and dyn_cast: 03803 static inline bool classof(const Instruction *I) { 03804 return I->getOpcode() == AddrSpaceCast; 03805 } 03806 static inline bool classof(const Value *V) { 03807 return isa<Instruction>(V) && classof(cast<Instruction>(V)); 03808 } 03809 }; 03810 03811 } // End llvm namespace 03812 03813 #endif