1249259Sdim//===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===// 2249259Sdim// 3249259Sdim// The LLVM Compiler Infrastructure 4249259Sdim// 5249259Sdim// This file is distributed under the University of Illinois Open Source 6249259Sdim// License. See LICENSE.TXT for details. 7249259Sdim// 8249259Sdim//===----------------------------------------------------------------------===// 9249259Sdim// 10249259Sdim// This file exposes the class definitions of all of the subclasses of the 11249259Sdim// Instruction class. This is meant to be an easy way to get access to all 12249259Sdim// instruction subclasses. 13249259Sdim// 14249259Sdim//===----------------------------------------------------------------------===// 15249259Sdim 16249259Sdim#ifndef LLVM_IR_INSTRUCTIONS_H 17249259Sdim#define LLVM_IR_INSTRUCTIONS_H 18249259Sdim 19249259Sdim#include "llvm/ADT/ArrayRef.h" 20249259Sdim#include "llvm/ADT/SmallVector.h" 21249259Sdim#include "llvm/IR/Attributes.h" 22249259Sdim#include "llvm/IR/CallingConv.h" 23249259Sdim#include "llvm/IR/DerivedTypes.h" 24249259Sdim#include "llvm/IR/InstrTypes.h" 25249259Sdim#include "llvm/Support/ErrorHandling.h" 26249259Sdim#include <iterator> 27249259Sdim 28249259Sdimnamespace llvm { 29249259Sdim 30249259Sdimclass APInt; 31249259Sdimclass ConstantInt; 32249259Sdimclass ConstantRange; 33249259Sdimclass DataLayout; 34249259Sdimclass LLVMContext; 35249259Sdim 36249259Sdimenum AtomicOrdering { 37249259Sdim NotAtomic = 0, 38249259Sdim Unordered = 1, 39249259Sdim Monotonic = 2, 40249259Sdim // Consume = 3, // Not specified yet. 41249259Sdim Acquire = 4, 42249259Sdim Release = 5, 43249259Sdim AcquireRelease = 6, 44249259Sdim SequentiallyConsistent = 7 45249259Sdim}; 46249259Sdim 47249259Sdimenum SynchronizationScope { 48249259Sdim SingleThread = 0, 49249259Sdim CrossThread = 1 50249259Sdim}; 51249259Sdim 52249259Sdim//===----------------------------------------------------------------------===// 53249259Sdim// AllocaInst Class 54249259Sdim//===----------------------------------------------------------------------===// 55249259Sdim 56249259Sdim/// AllocaInst - an instruction to allocate memory on the stack 57249259Sdim/// 58249259Sdimclass AllocaInst : public UnaryInstruction { 59249259Sdimprotected: 60249259Sdim virtual AllocaInst *clone_impl() const; 61249259Sdimpublic: 62249259Sdim explicit AllocaInst(Type *Ty, Value *ArraySize = 0, 63249259Sdim const Twine &Name = "", Instruction *InsertBefore = 0); 64249259Sdim AllocaInst(Type *Ty, Value *ArraySize, 65249259Sdim const Twine &Name, BasicBlock *InsertAtEnd); 66249259Sdim 67249259Sdim AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = 0); 68249259Sdim AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd); 69249259Sdim 70249259Sdim AllocaInst(Type *Ty, Value *ArraySize, unsigned Align, 71249259Sdim const Twine &Name = "", Instruction *InsertBefore = 0); 72249259Sdim AllocaInst(Type *Ty, Value *ArraySize, unsigned Align, 73249259Sdim const Twine &Name, BasicBlock *InsertAtEnd); 74249259Sdim 75249259Sdim // Out of line virtual method, so the vtable, etc. has a home. 76249259Sdim virtual ~AllocaInst(); 77249259Sdim 78249259Sdim /// isArrayAllocation - Return true if there is an allocation size parameter 79249259Sdim /// to the allocation instruction that is not 1. 80249259Sdim /// 81249259Sdim bool isArrayAllocation() const; 82249259Sdim 83249259Sdim /// getArraySize - Get the number of elements allocated. For a simple 84249259Sdim /// allocation of a single element, this will return a constant 1 value. 85249259Sdim /// 86249259Sdim const Value *getArraySize() const { return getOperand(0); } 87249259Sdim Value *getArraySize() { return getOperand(0); } 88249259Sdim 89249259Sdim /// getType - Overload to return most specific pointer type 90249259Sdim /// 91249259Sdim PointerType *getType() const { 92249259Sdim return cast<PointerType>(Instruction::getType()); 93249259Sdim } 94249259Sdim 95249259Sdim /// getAllocatedType - Return the type that is being allocated by the 96249259Sdim /// instruction. 97249259Sdim /// 98249259Sdim Type *getAllocatedType() const; 99249259Sdim 100249259Sdim /// getAlignment - Return the alignment of the memory that is being allocated 101249259Sdim /// by the instruction. 102249259Sdim /// 103249259Sdim unsigned getAlignment() const { 104249259Sdim return (1u << getSubclassDataFromInstruction()) >> 1; 105249259Sdim } 106249259Sdim void setAlignment(unsigned Align); 107249259Sdim 108249259Sdim /// isStaticAlloca - Return true if this alloca is in the entry block of the 109249259Sdim /// function and is a constant size. If so, the code generator will fold it 110249259Sdim /// into the prolog/epilog code, so it is basically free. 111249259Sdim bool isStaticAlloca() const; 112249259Sdim 113249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 114249259Sdim static inline bool classof(const Instruction *I) { 115249259Sdim return (I->getOpcode() == Instruction::Alloca); 116249259Sdim } 117249259Sdim static inline bool classof(const Value *V) { 118249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 119249259Sdim } 120249259Sdimprivate: 121249259Sdim // Shadow Instruction::setInstructionSubclassData with a private forwarding 122249259Sdim // method so that subclasses cannot accidentally use it. 123249259Sdim void setInstructionSubclassData(unsigned short D) { 124249259Sdim Instruction::setInstructionSubclassData(D); 125249259Sdim } 126249259Sdim}; 127249259Sdim 128249259Sdim 129249259Sdim//===----------------------------------------------------------------------===// 130249259Sdim// LoadInst Class 131249259Sdim//===----------------------------------------------------------------------===// 132249259Sdim 133249259Sdim/// LoadInst - an instruction for reading from memory. This uses the 134249259Sdim/// SubclassData field in Value to store whether or not the load is volatile. 135249259Sdim/// 136249259Sdimclass LoadInst : public UnaryInstruction { 137249259Sdim void AssertOK(); 138249259Sdimprotected: 139249259Sdim virtual LoadInst *clone_impl() const; 140249259Sdimpublic: 141249259Sdim LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore); 142249259Sdim LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd); 143249259Sdim LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false, 144249259Sdim Instruction *InsertBefore = 0); 145249259Sdim LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, 146249259Sdim BasicBlock *InsertAtEnd); 147249259Sdim LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, 148249259Sdim unsigned Align, Instruction *InsertBefore = 0); 149249259Sdim LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, 150249259Sdim unsigned Align, BasicBlock *InsertAtEnd); 151249259Sdim LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, 152249259Sdim unsigned Align, AtomicOrdering Order, 153249259Sdim SynchronizationScope SynchScope = CrossThread, 154249259Sdim Instruction *InsertBefore = 0); 155249259Sdim LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, 156249259Sdim unsigned Align, AtomicOrdering Order, 157249259Sdim SynchronizationScope SynchScope, 158249259Sdim BasicBlock *InsertAtEnd); 159249259Sdim 160249259Sdim LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore); 161249259Sdim LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd); 162249259Sdim explicit LoadInst(Value *Ptr, const char *NameStr = 0, 163249259Sdim bool isVolatile = false, Instruction *InsertBefore = 0); 164249259Sdim LoadInst(Value *Ptr, const char *NameStr, bool isVolatile, 165249259Sdim BasicBlock *InsertAtEnd); 166249259Sdim 167249259Sdim /// isVolatile - Return true if this is a load from a volatile memory 168249259Sdim /// location. 169249259Sdim /// 170249259Sdim bool isVolatile() const { return getSubclassDataFromInstruction() & 1; } 171249259Sdim 172249259Sdim /// setVolatile - Specify whether this is a volatile load or not. 173249259Sdim /// 174249259Sdim void setVolatile(bool V) { 175249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | 176249259Sdim (V ? 1 : 0)); 177249259Sdim } 178249259Sdim 179249259Sdim /// getAlignment - Return the alignment of the access that is being performed 180249259Sdim /// 181249259Sdim unsigned getAlignment() const { 182249259Sdim return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1; 183249259Sdim } 184249259Sdim 185249259Sdim void setAlignment(unsigned Align); 186249259Sdim 187249259Sdim /// Returns the ordering effect of this fence. 188249259Sdim AtomicOrdering getOrdering() const { 189249259Sdim return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7); 190249259Sdim } 191249259Sdim 192249259Sdim /// Set the ordering constraint on this load. May not be Release or 193249259Sdim /// AcquireRelease. 194249259Sdim void setOrdering(AtomicOrdering Ordering) { 195249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) | 196249259Sdim (Ordering << 7)); 197249259Sdim } 198249259Sdim 199249259Sdim SynchronizationScope getSynchScope() const { 200249259Sdim return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1); 201249259Sdim } 202249259Sdim 203249259Sdim /// Specify whether this load is ordered with respect to all 204249259Sdim /// concurrently executing threads, or only with respect to signal handlers 205249259Sdim /// executing in the same thread. 206249259Sdim void setSynchScope(SynchronizationScope xthread) { 207249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) | 208249259Sdim (xthread << 6)); 209249259Sdim } 210249259Sdim 211249259Sdim bool isAtomic() const { return getOrdering() != NotAtomic; } 212249259Sdim void setAtomic(AtomicOrdering Ordering, 213249259Sdim SynchronizationScope SynchScope = CrossThread) { 214249259Sdim setOrdering(Ordering); 215249259Sdim setSynchScope(SynchScope); 216249259Sdim } 217249259Sdim 218249259Sdim bool isSimple() const { return !isAtomic() && !isVolatile(); } 219249259Sdim bool isUnordered() const { 220249259Sdim return getOrdering() <= Unordered && !isVolatile(); 221249259Sdim } 222249259Sdim 223249259Sdim Value *getPointerOperand() { return getOperand(0); } 224249259Sdim const Value *getPointerOperand() const { return getOperand(0); } 225249259Sdim static unsigned getPointerOperandIndex() { return 0U; } 226249259Sdim 227249259Sdim /// \brief Returns the address space of the pointer operand. 228249259Sdim unsigned getPointerAddressSpace() const { 229249259Sdim return getPointerOperand()->getType()->getPointerAddressSpace(); 230249259Sdim } 231249259Sdim 232249259Sdim 233249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 234249259Sdim static inline bool classof(const Instruction *I) { 235249259Sdim return I->getOpcode() == Instruction::Load; 236249259Sdim } 237249259Sdim static inline bool classof(const Value *V) { 238249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 239249259Sdim } 240249259Sdimprivate: 241249259Sdim // Shadow Instruction::setInstructionSubclassData with a private forwarding 242249259Sdim // method so that subclasses cannot accidentally use it. 243249259Sdim void setInstructionSubclassData(unsigned short D) { 244249259Sdim Instruction::setInstructionSubclassData(D); 245249259Sdim } 246249259Sdim}; 247249259Sdim 248249259Sdim 249249259Sdim//===----------------------------------------------------------------------===// 250249259Sdim// StoreInst Class 251249259Sdim//===----------------------------------------------------------------------===// 252249259Sdim 253249259Sdim/// StoreInst - an instruction for storing to memory 254249259Sdim/// 255249259Sdimclass StoreInst : public Instruction { 256249259Sdim void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 257249259Sdim void AssertOK(); 258249259Sdimprotected: 259249259Sdim virtual StoreInst *clone_impl() const; 260249259Sdimpublic: 261249259Sdim // allocate space for exactly two operands 262249259Sdim void *operator new(size_t s) { 263249259Sdim return User::operator new(s, 2); 264249259Sdim } 265249259Sdim StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore); 266249259Sdim StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd); 267249259Sdim StoreInst(Value *Val, Value *Ptr, bool isVolatile = false, 268249259Sdim Instruction *InsertBefore = 0); 269249259Sdim StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd); 270249259Sdim StoreInst(Value *Val, Value *Ptr, bool isVolatile, 271249259Sdim unsigned Align, Instruction *InsertBefore = 0); 272249259Sdim StoreInst(Value *Val, Value *Ptr, bool isVolatile, 273249259Sdim unsigned Align, BasicBlock *InsertAtEnd); 274249259Sdim StoreInst(Value *Val, Value *Ptr, bool isVolatile, 275249259Sdim unsigned Align, AtomicOrdering Order, 276249259Sdim SynchronizationScope SynchScope = CrossThread, 277249259Sdim Instruction *InsertBefore = 0); 278249259Sdim StoreInst(Value *Val, Value *Ptr, bool isVolatile, 279249259Sdim unsigned Align, AtomicOrdering Order, 280249259Sdim SynchronizationScope SynchScope, 281249259Sdim BasicBlock *InsertAtEnd); 282249259Sdim 283249259Sdim 284249259Sdim /// isVolatile - Return true if this is a store to a volatile memory 285249259Sdim /// location. 286249259Sdim /// 287249259Sdim bool isVolatile() const { return getSubclassDataFromInstruction() & 1; } 288249259Sdim 289249259Sdim /// setVolatile - Specify whether this is a volatile store or not. 290249259Sdim /// 291249259Sdim void setVolatile(bool V) { 292249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | 293249259Sdim (V ? 1 : 0)); 294249259Sdim } 295249259Sdim 296249259Sdim /// Transparently provide more efficient getOperand methods. 297249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 298249259Sdim 299249259Sdim /// getAlignment - Return the alignment of the access that is being performed 300249259Sdim /// 301249259Sdim unsigned getAlignment() const { 302249259Sdim return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1; 303249259Sdim } 304249259Sdim 305249259Sdim void setAlignment(unsigned Align); 306249259Sdim 307249259Sdim /// Returns the ordering effect of this store. 308249259Sdim AtomicOrdering getOrdering() const { 309249259Sdim return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7); 310249259Sdim } 311249259Sdim 312249259Sdim /// Set the ordering constraint on this store. May not be Acquire or 313249259Sdim /// AcquireRelease. 314249259Sdim void setOrdering(AtomicOrdering Ordering) { 315249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) | 316249259Sdim (Ordering << 7)); 317249259Sdim } 318249259Sdim 319249259Sdim SynchronizationScope getSynchScope() const { 320249259Sdim return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1); 321249259Sdim } 322249259Sdim 323249259Sdim /// Specify whether this store instruction is ordered with respect to all 324249259Sdim /// concurrently executing threads, or only with respect to signal handlers 325249259Sdim /// executing in the same thread. 326249259Sdim void setSynchScope(SynchronizationScope xthread) { 327249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) | 328249259Sdim (xthread << 6)); 329249259Sdim } 330249259Sdim 331249259Sdim bool isAtomic() const { return getOrdering() != NotAtomic; } 332249259Sdim void setAtomic(AtomicOrdering Ordering, 333249259Sdim SynchronizationScope SynchScope = CrossThread) { 334249259Sdim setOrdering(Ordering); 335249259Sdim setSynchScope(SynchScope); 336249259Sdim } 337249259Sdim 338249259Sdim bool isSimple() const { return !isAtomic() && !isVolatile(); } 339249259Sdim bool isUnordered() const { 340249259Sdim return getOrdering() <= Unordered && !isVolatile(); 341249259Sdim } 342249259Sdim 343249259Sdim Value *getValueOperand() { return getOperand(0); } 344249259Sdim const Value *getValueOperand() const { return getOperand(0); } 345249259Sdim 346249259Sdim Value *getPointerOperand() { return getOperand(1); } 347249259Sdim const Value *getPointerOperand() const { return getOperand(1); } 348249259Sdim static unsigned getPointerOperandIndex() { return 1U; } 349249259Sdim 350249259Sdim /// \brief Returns the address space of the pointer operand. 351249259Sdim unsigned getPointerAddressSpace() const { 352249259Sdim return getPointerOperand()->getType()->getPointerAddressSpace(); 353249259Sdim } 354249259Sdim 355249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 356249259Sdim static inline bool classof(const Instruction *I) { 357249259Sdim return I->getOpcode() == Instruction::Store; 358249259Sdim } 359249259Sdim static inline bool classof(const Value *V) { 360249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 361249259Sdim } 362249259Sdimprivate: 363249259Sdim // Shadow Instruction::setInstructionSubclassData with a private forwarding 364249259Sdim // method so that subclasses cannot accidentally use it. 365249259Sdim void setInstructionSubclassData(unsigned short D) { 366249259Sdim Instruction::setInstructionSubclassData(D); 367249259Sdim } 368249259Sdim}; 369249259Sdim 370249259Sdimtemplate <> 371249259Sdimstruct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> { 372249259Sdim}; 373249259Sdim 374249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value) 375249259Sdim 376249259Sdim//===----------------------------------------------------------------------===// 377249259Sdim// FenceInst Class 378249259Sdim//===----------------------------------------------------------------------===// 379249259Sdim 380249259Sdim/// FenceInst - an instruction for ordering other memory operations 381249259Sdim/// 382249259Sdimclass FenceInst : public Instruction { 383249259Sdim void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 384249259Sdim void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope); 385249259Sdimprotected: 386249259Sdim virtual FenceInst *clone_impl() const; 387249259Sdimpublic: 388249259Sdim // allocate space for exactly zero operands 389249259Sdim void *operator new(size_t s) { 390249259Sdim return User::operator new(s, 0); 391249259Sdim } 392249259Sdim 393249259Sdim // Ordering may only be Acquire, Release, AcquireRelease, or 394249259Sdim // SequentiallyConsistent. 395249259Sdim FenceInst(LLVMContext &C, AtomicOrdering Ordering, 396249259Sdim SynchronizationScope SynchScope = CrossThread, 397249259Sdim Instruction *InsertBefore = 0); 398249259Sdim FenceInst(LLVMContext &C, AtomicOrdering Ordering, 399249259Sdim SynchronizationScope SynchScope, 400249259Sdim BasicBlock *InsertAtEnd); 401249259Sdim 402249259Sdim /// Returns the ordering effect of this fence. 403249259Sdim AtomicOrdering getOrdering() const { 404249259Sdim return AtomicOrdering(getSubclassDataFromInstruction() >> 1); 405249259Sdim } 406249259Sdim 407249259Sdim /// Set the ordering constraint on this fence. May only be Acquire, Release, 408249259Sdim /// AcquireRelease, or SequentiallyConsistent. 409249259Sdim void setOrdering(AtomicOrdering Ordering) { 410249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & 1) | 411249259Sdim (Ordering << 1)); 412249259Sdim } 413249259Sdim 414249259Sdim SynchronizationScope getSynchScope() const { 415249259Sdim return SynchronizationScope(getSubclassDataFromInstruction() & 1); 416249259Sdim } 417249259Sdim 418249259Sdim /// Specify whether this fence orders other operations with respect to all 419249259Sdim /// concurrently executing threads, or only with respect to signal handlers 420249259Sdim /// executing in the same thread. 421249259Sdim void setSynchScope(SynchronizationScope xthread) { 422249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | 423249259Sdim xthread); 424249259Sdim } 425249259Sdim 426249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 427249259Sdim static inline bool classof(const Instruction *I) { 428249259Sdim return I->getOpcode() == Instruction::Fence; 429249259Sdim } 430249259Sdim static inline bool classof(const Value *V) { 431249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 432249259Sdim } 433249259Sdimprivate: 434249259Sdim // Shadow Instruction::setInstructionSubclassData with a private forwarding 435249259Sdim // method so that subclasses cannot accidentally use it. 436249259Sdim void setInstructionSubclassData(unsigned short D) { 437249259Sdim Instruction::setInstructionSubclassData(D); 438249259Sdim } 439249259Sdim}; 440249259Sdim 441249259Sdim//===----------------------------------------------------------------------===// 442249259Sdim// AtomicCmpXchgInst Class 443249259Sdim//===----------------------------------------------------------------------===// 444249259Sdim 445249259Sdim/// AtomicCmpXchgInst - an instruction that atomically checks whether a 446249259Sdim/// specified value is in a memory location, and, if it is, stores a new value 447249259Sdim/// there. Returns the value that was loaded. 448249259Sdim/// 449249259Sdimclass AtomicCmpXchgInst : public Instruction { 450249259Sdim void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 451249259Sdim void Init(Value *Ptr, Value *Cmp, Value *NewVal, 452249259Sdim AtomicOrdering Ordering, SynchronizationScope SynchScope); 453249259Sdimprotected: 454249259Sdim virtual AtomicCmpXchgInst *clone_impl() const; 455249259Sdimpublic: 456249259Sdim // allocate space for exactly three operands 457249259Sdim void *operator new(size_t s) { 458249259Sdim return User::operator new(s, 3); 459249259Sdim } 460249259Sdim AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, 461249259Sdim AtomicOrdering Ordering, SynchronizationScope SynchScope, 462249259Sdim Instruction *InsertBefore = 0); 463249259Sdim AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, 464249259Sdim AtomicOrdering Ordering, SynchronizationScope SynchScope, 465249259Sdim BasicBlock *InsertAtEnd); 466249259Sdim 467249259Sdim /// isVolatile - Return true if this is a cmpxchg from a volatile memory 468249259Sdim /// location. 469249259Sdim /// 470249259Sdim bool isVolatile() const { 471249259Sdim return getSubclassDataFromInstruction() & 1; 472249259Sdim } 473249259Sdim 474249259Sdim /// setVolatile - Specify whether this is a volatile cmpxchg. 475249259Sdim /// 476249259Sdim void setVolatile(bool V) { 477249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | 478249259Sdim (unsigned)V); 479249259Sdim } 480249259Sdim 481249259Sdim /// Transparently provide more efficient getOperand methods. 482249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 483249259Sdim 484249259Sdim /// Set the ordering constraint on this cmpxchg. 485249259Sdim void setOrdering(AtomicOrdering Ordering) { 486249259Sdim assert(Ordering != NotAtomic && 487249259Sdim "CmpXchg instructions can only be atomic."); 488249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & 3) | 489249259Sdim (Ordering << 2)); 490249259Sdim } 491249259Sdim 492249259Sdim /// Specify whether this cmpxchg is atomic and orders other operations with 493249259Sdim /// respect to all concurrently executing threads, or only with respect to 494249259Sdim /// signal handlers executing in the same thread. 495249259Sdim void setSynchScope(SynchronizationScope SynchScope) { 496249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) | 497249259Sdim (SynchScope << 1)); 498249259Sdim } 499249259Sdim 500249259Sdim /// Returns the ordering constraint on this cmpxchg. 501249259Sdim AtomicOrdering getOrdering() const { 502249259Sdim return AtomicOrdering(getSubclassDataFromInstruction() >> 2); 503249259Sdim } 504249259Sdim 505249259Sdim /// Returns whether this cmpxchg is atomic between threads or only within a 506249259Sdim /// single thread. 507249259Sdim SynchronizationScope getSynchScope() const { 508249259Sdim return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1); 509249259Sdim } 510249259Sdim 511249259Sdim Value *getPointerOperand() { return getOperand(0); } 512249259Sdim const Value *getPointerOperand() const { return getOperand(0); } 513249259Sdim static unsigned getPointerOperandIndex() { return 0U; } 514249259Sdim 515249259Sdim Value *getCompareOperand() { return getOperand(1); } 516249259Sdim const Value *getCompareOperand() const { return getOperand(1); } 517249259Sdim 518249259Sdim Value *getNewValOperand() { return getOperand(2); } 519249259Sdim const Value *getNewValOperand() const { return getOperand(2); } 520249259Sdim 521249259Sdim /// \brief Returns the address space of the pointer operand. 522249259Sdim unsigned getPointerAddressSpace() const { 523249259Sdim return getPointerOperand()->getType()->getPointerAddressSpace(); 524249259Sdim } 525249259Sdim 526249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 527249259Sdim static inline bool classof(const Instruction *I) { 528249259Sdim return I->getOpcode() == Instruction::AtomicCmpXchg; 529249259Sdim } 530249259Sdim static inline bool classof(const Value *V) { 531249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 532249259Sdim } 533249259Sdimprivate: 534249259Sdim // Shadow Instruction::setInstructionSubclassData with a private forwarding 535249259Sdim // method so that subclasses cannot accidentally use it. 536249259Sdim void setInstructionSubclassData(unsigned short D) { 537249259Sdim Instruction::setInstructionSubclassData(D); 538249259Sdim } 539249259Sdim}; 540249259Sdim 541249259Sdimtemplate <> 542249259Sdimstruct OperandTraits<AtomicCmpXchgInst> : 543249259Sdim public FixedNumOperandTraits<AtomicCmpXchgInst, 3> { 544249259Sdim}; 545249259Sdim 546249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value) 547249259Sdim 548249259Sdim//===----------------------------------------------------------------------===// 549249259Sdim// AtomicRMWInst Class 550249259Sdim//===----------------------------------------------------------------------===// 551249259Sdim 552249259Sdim/// AtomicRMWInst - an instruction that atomically reads a memory location, 553249259Sdim/// combines it with another value, and then stores the result back. Returns 554249259Sdim/// the old value. 555249259Sdim/// 556249259Sdimclass AtomicRMWInst : public Instruction { 557249259Sdim void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 558249259Sdimprotected: 559249259Sdim virtual AtomicRMWInst *clone_impl() const; 560249259Sdimpublic: 561249259Sdim /// This enumeration lists the possible modifications atomicrmw can make. In 562249259Sdim /// the descriptions, 'p' is the pointer to the instruction's memory location, 563249259Sdim /// 'old' is the initial value of *p, and 'v' is the other value passed to the 564249259Sdim /// instruction. These instructions always return 'old'. 565249259Sdim enum BinOp { 566249259Sdim /// *p = v 567249259Sdim Xchg, 568249259Sdim /// *p = old + v 569249259Sdim Add, 570249259Sdim /// *p = old - v 571249259Sdim Sub, 572249259Sdim /// *p = old & v 573249259Sdim And, 574249259Sdim /// *p = ~old & v 575249259Sdim Nand, 576249259Sdim /// *p = old | v 577249259Sdim Or, 578249259Sdim /// *p = old ^ v 579249259Sdim Xor, 580249259Sdim /// *p = old >signed v ? old : v 581249259Sdim Max, 582249259Sdim /// *p = old <signed v ? old : v 583249259Sdim Min, 584249259Sdim /// *p = old >unsigned v ? old : v 585249259Sdim UMax, 586249259Sdim /// *p = old <unsigned v ? old : v 587249259Sdim UMin, 588249259Sdim 589249259Sdim FIRST_BINOP = Xchg, 590249259Sdim LAST_BINOP = UMin, 591249259Sdim BAD_BINOP 592249259Sdim }; 593249259Sdim 594249259Sdim // allocate space for exactly two operands 595249259Sdim void *operator new(size_t s) { 596249259Sdim return User::operator new(s, 2); 597249259Sdim } 598249259Sdim AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, 599249259Sdim AtomicOrdering Ordering, SynchronizationScope SynchScope, 600249259Sdim Instruction *InsertBefore = 0); 601249259Sdim AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, 602249259Sdim AtomicOrdering Ordering, SynchronizationScope SynchScope, 603249259Sdim BasicBlock *InsertAtEnd); 604249259Sdim 605249259Sdim BinOp getOperation() const { 606249259Sdim return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5); 607249259Sdim } 608249259Sdim 609249259Sdim void setOperation(BinOp Operation) { 610249259Sdim unsigned short SubclassData = getSubclassDataFromInstruction(); 611249259Sdim setInstructionSubclassData((SubclassData & 31) | 612249259Sdim (Operation << 5)); 613249259Sdim } 614249259Sdim 615249259Sdim /// isVolatile - Return true if this is a RMW on a volatile memory location. 616249259Sdim /// 617249259Sdim bool isVolatile() const { 618249259Sdim return getSubclassDataFromInstruction() & 1; 619249259Sdim } 620249259Sdim 621249259Sdim /// setVolatile - Specify whether this is a volatile RMW or not. 622249259Sdim /// 623249259Sdim void setVolatile(bool V) { 624249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | 625249259Sdim (unsigned)V); 626249259Sdim } 627249259Sdim 628249259Sdim /// Transparently provide more efficient getOperand methods. 629249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 630249259Sdim 631249259Sdim /// Set the ordering constraint on this RMW. 632249259Sdim void setOrdering(AtomicOrdering Ordering) { 633249259Sdim assert(Ordering != NotAtomic && 634249259Sdim "atomicrmw instructions can only be atomic."); 635249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) | 636249259Sdim (Ordering << 2)); 637249259Sdim } 638249259Sdim 639249259Sdim /// Specify whether this RMW orders other operations with respect to all 640249259Sdim /// concurrently executing threads, or only with respect to signal handlers 641249259Sdim /// executing in the same thread. 642249259Sdim void setSynchScope(SynchronizationScope SynchScope) { 643249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) | 644249259Sdim (SynchScope << 1)); 645249259Sdim } 646249259Sdim 647249259Sdim /// Returns the ordering constraint on this RMW. 648249259Sdim AtomicOrdering getOrdering() const { 649249259Sdim return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7); 650249259Sdim } 651249259Sdim 652249259Sdim /// Returns whether this RMW is atomic between threads or only within a 653249259Sdim /// single thread. 654249259Sdim SynchronizationScope getSynchScope() const { 655249259Sdim return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1); 656249259Sdim } 657249259Sdim 658249259Sdim Value *getPointerOperand() { return getOperand(0); } 659249259Sdim const Value *getPointerOperand() const { return getOperand(0); } 660249259Sdim static unsigned getPointerOperandIndex() { return 0U; } 661249259Sdim 662249259Sdim Value *getValOperand() { return getOperand(1); } 663249259Sdim const Value *getValOperand() const { return getOperand(1); } 664249259Sdim 665249259Sdim /// \brief Returns the address space of the pointer operand. 666249259Sdim unsigned getPointerAddressSpace() const { 667249259Sdim return getPointerOperand()->getType()->getPointerAddressSpace(); 668249259Sdim } 669249259Sdim 670249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 671249259Sdim static inline bool classof(const Instruction *I) { 672249259Sdim return I->getOpcode() == Instruction::AtomicRMW; 673249259Sdim } 674249259Sdim static inline bool classof(const Value *V) { 675249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 676249259Sdim } 677249259Sdimprivate: 678249259Sdim void Init(BinOp Operation, Value *Ptr, Value *Val, 679249259Sdim AtomicOrdering Ordering, SynchronizationScope SynchScope); 680249259Sdim // Shadow Instruction::setInstructionSubclassData with a private forwarding 681249259Sdim // method so that subclasses cannot accidentally use it. 682249259Sdim void setInstructionSubclassData(unsigned short D) { 683249259Sdim Instruction::setInstructionSubclassData(D); 684249259Sdim } 685249259Sdim}; 686249259Sdim 687249259Sdimtemplate <> 688249259Sdimstruct OperandTraits<AtomicRMWInst> 689249259Sdim : public FixedNumOperandTraits<AtomicRMWInst,2> { 690249259Sdim}; 691249259Sdim 692249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value) 693249259Sdim 694249259Sdim//===----------------------------------------------------------------------===// 695249259Sdim// GetElementPtrInst Class 696249259Sdim//===----------------------------------------------------------------------===// 697249259Sdim 698249259Sdim// checkGEPType - Simple wrapper function to give a better assertion failure 699249259Sdim// message on bad indexes for a gep instruction. 700249259Sdim// 701249259Sdiminline Type *checkGEPType(Type *Ty) { 702249259Sdim assert(Ty && "Invalid GetElementPtrInst indices for type!"); 703249259Sdim return Ty; 704249259Sdim} 705249259Sdim 706249259Sdim/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to 707249259Sdim/// access elements of arrays and structs 708249259Sdim/// 709249259Sdimclass GetElementPtrInst : public Instruction { 710249259Sdim GetElementPtrInst(const GetElementPtrInst &GEPI); 711249259Sdim void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr); 712249259Sdim 713249259Sdim /// Constructors - Create a getelementptr instruction with a base pointer an 714249259Sdim /// list of indices. The first ctor can optionally insert before an existing 715249259Sdim /// instruction, the second appends the new instruction to the specified 716249259Sdim /// BasicBlock. 717249259Sdim inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList, 718249259Sdim unsigned Values, const Twine &NameStr, 719249259Sdim Instruction *InsertBefore); 720249259Sdim inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList, 721249259Sdim unsigned Values, const Twine &NameStr, 722249259Sdim BasicBlock *InsertAtEnd); 723249259Sdimprotected: 724249259Sdim virtual GetElementPtrInst *clone_impl() const; 725249259Sdimpublic: 726249259Sdim static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList, 727249259Sdim const Twine &NameStr = "", 728249259Sdim Instruction *InsertBefore = 0) { 729249259Sdim unsigned Values = 1 + unsigned(IdxList.size()); 730249259Sdim return new(Values) 731249259Sdim GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore); 732249259Sdim } 733249259Sdim static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList, 734249259Sdim const Twine &NameStr, 735249259Sdim BasicBlock *InsertAtEnd) { 736249259Sdim unsigned Values = 1 + unsigned(IdxList.size()); 737249259Sdim return new(Values) 738249259Sdim GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd); 739249259Sdim } 740249259Sdim 741249259Sdim /// Create an "inbounds" getelementptr. See the documentation for the 742249259Sdim /// "inbounds" flag in LangRef.html for details. 743249259Sdim static GetElementPtrInst *CreateInBounds(Value *Ptr, 744249259Sdim ArrayRef<Value *> IdxList, 745249259Sdim const Twine &NameStr = "", 746249259Sdim Instruction *InsertBefore = 0) { 747249259Sdim GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore); 748249259Sdim GEP->setIsInBounds(true); 749249259Sdim return GEP; 750249259Sdim } 751249259Sdim static GetElementPtrInst *CreateInBounds(Value *Ptr, 752249259Sdim ArrayRef<Value *> IdxList, 753249259Sdim const Twine &NameStr, 754249259Sdim BasicBlock *InsertAtEnd) { 755249259Sdim GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd); 756249259Sdim GEP->setIsInBounds(true); 757249259Sdim return GEP; 758249259Sdim } 759249259Sdim 760249259Sdim /// Transparently provide more efficient getOperand methods. 761249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 762249259Sdim 763249259Sdim // getType - Overload to return most specific sequential type. 764249259Sdim SequentialType *getType() const { 765249259Sdim return cast<SequentialType>(Instruction::getType()); 766249259Sdim } 767249259Sdim 768249259Sdim /// \brief Returns the address space of this instruction's pointer type. 769249259Sdim unsigned getAddressSpace() const { 770249259Sdim // Note that this is always the same as the pointer operand's address space 771249259Sdim // and that is cheaper to compute, so cheat here. 772249259Sdim return getPointerAddressSpace(); 773249259Sdim } 774249259Sdim 775249259Sdim /// getIndexedType - Returns the type of the element that would be loaded with 776249259Sdim /// a load instruction with the specified parameters. 777249259Sdim /// 778249259Sdim /// Null is returned if the indices are invalid for the specified 779249259Sdim /// pointer type. 780249259Sdim /// 781249259Sdim static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList); 782249259Sdim static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList); 783249259Sdim static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList); 784249259Sdim 785249259Sdim inline op_iterator idx_begin() { return op_begin()+1; } 786249259Sdim inline const_op_iterator idx_begin() const { return op_begin()+1; } 787249259Sdim inline op_iterator idx_end() { return op_end(); } 788249259Sdim inline const_op_iterator idx_end() const { return op_end(); } 789249259Sdim 790249259Sdim Value *getPointerOperand() { 791249259Sdim return getOperand(0); 792249259Sdim } 793249259Sdim const Value *getPointerOperand() const { 794249259Sdim return getOperand(0); 795249259Sdim } 796249259Sdim static unsigned getPointerOperandIndex() { 797249259Sdim return 0U; // get index for modifying correct operand. 798249259Sdim } 799249259Sdim 800249259Sdim /// getPointerOperandType - Method to return the pointer operand as a 801249259Sdim /// PointerType. 802249259Sdim Type *getPointerOperandType() const { 803249259Sdim return getPointerOperand()->getType(); 804249259Sdim } 805249259Sdim 806249259Sdim /// \brief Returns the address space of the pointer operand. 807249259Sdim unsigned getPointerAddressSpace() const { 808249259Sdim return getPointerOperandType()->getPointerAddressSpace(); 809249259Sdim } 810249259Sdim 811249259Sdim /// GetGEPReturnType - Returns the pointer type returned by the GEP 812249259Sdim /// instruction, which may be a vector of pointers. 813249259Sdim static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) { 814249259Sdim Type *PtrTy = PointerType::get(checkGEPType( 815249259Sdim getIndexedType(Ptr->getType(), IdxList)), 816249259Sdim Ptr->getType()->getPointerAddressSpace()); 817249259Sdim // Vector GEP 818249259Sdim if (Ptr->getType()->isVectorTy()) { 819249259Sdim unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements(); 820249259Sdim return VectorType::get(PtrTy, NumElem); 821249259Sdim } 822249259Sdim 823249259Sdim // Scalar GEP 824249259Sdim return PtrTy; 825249259Sdim } 826249259Sdim 827249259Sdim unsigned getNumIndices() const { // Note: always non-negative 828249259Sdim return getNumOperands() - 1; 829249259Sdim } 830249259Sdim 831249259Sdim bool hasIndices() const { 832249259Sdim return getNumOperands() > 1; 833249259Sdim } 834249259Sdim 835249259Sdim /// hasAllZeroIndices - Return true if all of the indices of this GEP are 836249259Sdim /// zeros. If so, the result pointer and the first operand have the same 837249259Sdim /// value, just potentially different types. 838249259Sdim bool hasAllZeroIndices() const; 839249259Sdim 840249259Sdim /// hasAllConstantIndices - Return true if all of the indices of this GEP are 841249259Sdim /// constant integers. If so, the result pointer and the first operand have 842249259Sdim /// a constant offset between them. 843249259Sdim bool hasAllConstantIndices() const; 844249259Sdim 845249259Sdim /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction. 846249259Sdim /// See LangRef.html for the meaning of inbounds on a getelementptr. 847249259Sdim void setIsInBounds(bool b = true); 848249259Sdim 849249259Sdim /// isInBounds - Determine whether the GEP has the inbounds flag. 850249259Sdim bool isInBounds() const; 851249259Sdim 852249259Sdim /// \brief Accumulate the constant address offset of this GEP if possible. 853249259Sdim /// 854249259Sdim /// This routine accepts an APInt into which it will accumulate the constant 855249259Sdim /// offset of this GEP if the GEP is in fact constant. If the GEP is not 856249259Sdim /// all-constant, it returns false and the value of the offset APInt is 857249259Sdim /// undefined (it is *not* preserved!). The APInt passed into this routine 858249259Sdim /// must be at least as wide as the IntPtr type for the address space of 859249259Sdim /// the base GEP pointer. 860249259Sdim bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const; 861249259Sdim 862249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 863249259Sdim static inline bool classof(const Instruction *I) { 864249259Sdim return (I->getOpcode() == Instruction::GetElementPtr); 865249259Sdim } 866249259Sdim static inline bool classof(const Value *V) { 867249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 868249259Sdim } 869249259Sdim}; 870249259Sdim 871249259Sdimtemplate <> 872249259Sdimstruct OperandTraits<GetElementPtrInst> : 873249259Sdim public VariadicOperandTraits<GetElementPtrInst, 1> { 874249259Sdim}; 875249259Sdim 876249259SdimGetElementPtrInst::GetElementPtrInst(Value *Ptr, 877249259Sdim ArrayRef<Value *> IdxList, 878249259Sdim unsigned Values, 879249259Sdim const Twine &NameStr, 880249259Sdim Instruction *InsertBefore) 881249259Sdim : Instruction(getGEPReturnType(Ptr, IdxList), 882249259Sdim GetElementPtr, 883249259Sdim OperandTraits<GetElementPtrInst>::op_end(this) - Values, 884249259Sdim Values, InsertBefore) { 885249259Sdim init(Ptr, IdxList, NameStr); 886249259Sdim} 887249259SdimGetElementPtrInst::GetElementPtrInst(Value *Ptr, 888249259Sdim ArrayRef<Value *> IdxList, 889249259Sdim unsigned Values, 890249259Sdim const Twine &NameStr, 891249259Sdim BasicBlock *InsertAtEnd) 892249259Sdim : Instruction(getGEPReturnType(Ptr, IdxList), 893249259Sdim GetElementPtr, 894249259Sdim OperandTraits<GetElementPtrInst>::op_end(this) - Values, 895249259Sdim Values, InsertAtEnd) { 896249259Sdim init(Ptr, IdxList, NameStr); 897249259Sdim} 898249259Sdim 899249259Sdim 900249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value) 901249259Sdim 902249259Sdim 903249259Sdim//===----------------------------------------------------------------------===// 904249259Sdim// ICmpInst Class 905249259Sdim//===----------------------------------------------------------------------===// 906249259Sdim 907249259Sdim/// This instruction compares its operands according to the predicate given 908249259Sdim/// to the constructor. It only operates on integers or pointers. The operands 909249259Sdim/// must be identical types. 910249259Sdim/// \brief Represent an integer comparison operator. 911249259Sdimclass ICmpInst: public CmpInst { 912263508Sdim void AssertOK() { 913263508Sdim assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE && 914263508Sdim getPredicate() <= CmpInst::LAST_ICMP_PREDICATE && 915263508Sdim "Invalid ICmp predicate value"); 916263508Sdim assert(getOperand(0)->getType() == getOperand(1)->getType() && 917263508Sdim "Both operands to ICmp instruction are not of the same type!"); 918263508Sdim // Check that the operands are the right type 919263508Sdim assert((getOperand(0)->getType()->isIntOrIntVectorTy() || 920263508Sdim getOperand(0)->getType()->isPtrOrPtrVectorTy()) && 921263508Sdim "Invalid operand types for ICmp instruction"); 922263508Sdim } 923263508Sdim 924249259Sdimprotected: 925249259Sdim /// \brief Clone an identical ICmpInst 926249259Sdim virtual ICmpInst *clone_impl() const; 927249259Sdimpublic: 928249259Sdim /// \brief Constructor with insert-before-instruction semantics. 929249259Sdim ICmpInst( 930249259Sdim Instruction *InsertBefore, ///< Where to insert 931249259Sdim Predicate pred, ///< The predicate to use for the comparison 932249259Sdim Value *LHS, ///< The left-hand-side of the expression 933249259Sdim Value *RHS, ///< The right-hand-side of the expression 934249259Sdim const Twine &NameStr = "" ///< Name of the instruction 935249259Sdim ) : CmpInst(makeCmpResultType(LHS->getType()), 936249259Sdim Instruction::ICmp, pred, LHS, RHS, NameStr, 937249259Sdim InsertBefore) { 938263508Sdim#ifndef NDEBUG 939263508Sdim AssertOK(); 940263508Sdim#endif 941249259Sdim } 942249259Sdim 943249259Sdim /// \brief Constructor with insert-at-end semantics. 944249259Sdim ICmpInst( 945249259Sdim BasicBlock &InsertAtEnd, ///< Block to insert into. 946249259Sdim Predicate pred, ///< The predicate to use for the comparison 947249259Sdim Value *LHS, ///< The left-hand-side of the expression 948249259Sdim Value *RHS, ///< The right-hand-side of the expression 949249259Sdim const Twine &NameStr = "" ///< Name of the instruction 950249259Sdim ) : CmpInst(makeCmpResultType(LHS->getType()), 951249259Sdim Instruction::ICmp, pred, LHS, RHS, NameStr, 952249259Sdim &InsertAtEnd) { 953263508Sdim#ifndef NDEBUG 954263508Sdim AssertOK(); 955263508Sdim#endif 956249259Sdim } 957249259Sdim 958249259Sdim /// \brief Constructor with no-insertion semantics 959249259Sdim ICmpInst( 960249259Sdim Predicate pred, ///< The predicate to use for the comparison 961249259Sdim Value *LHS, ///< The left-hand-side of the expression 962249259Sdim Value *RHS, ///< The right-hand-side of the expression 963249259Sdim const Twine &NameStr = "" ///< Name of the instruction 964249259Sdim ) : CmpInst(makeCmpResultType(LHS->getType()), 965249259Sdim Instruction::ICmp, pred, LHS, RHS, NameStr) { 966263508Sdim#ifndef NDEBUG 967263508Sdim AssertOK(); 968263508Sdim#endif 969249259Sdim } 970249259Sdim 971249259Sdim /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc. 972249259Sdim /// @returns the predicate that would be the result if the operand were 973249259Sdim /// regarded as signed. 974249259Sdim /// \brief Return the signed version of the predicate 975249259Sdim Predicate getSignedPredicate() const { 976249259Sdim return getSignedPredicate(getPredicate()); 977249259Sdim } 978249259Sdim 979249259Sdim /// This is a static version that you can use without an instruction. 980249259Sdim /// \brief Return the signed version of the predicate. 981249259Sdim static Predicate getSignedPredicate(Predicate pred); 982249259Sdim 983249259Sdim /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc. 984249259Sdim /// @returns the predicate that would be the result if the operand were 985249259Sdim /// regarded as unsigned. 986249259Sdim /// \brief Return the unsigned version of the predicate 987249259Sdim Predicate getUnsignedPredicate() const { 988249259Sdim return getUnsignedPredicate(getPredicate()); 989249259Sdim } 990249259Sdim 991249259Sdim /// This is a static version that you can use without an instruction. 992249259Sdim /// \brief Return the unsigned version of the predicate. 993249259Sdim static Predicate getUnsignedPredicate(Predicate pred); 994249259Sdim 995249259Sdim /// isEquality - Return true if this predicate is either EQ or NE. This also 996249259Sdim /// tests for commutativity. 997249259Sdim static bool isEquality(Predicate P) { 998249259Sdim return P == ICMP_EQ || P == ICMP_NE; 999249259Sdim } 1000249259Sdim 1001249259Sdim /// isEquality - Return true if this predicate is either EQ or NE. This also 1002249259Sdim /// tests for commutativity. 1003249259Sdim bool isEquality() const { 1004249259Sdim return isEquality(getPredicate()); 1005249259Sdim } 1006249259Sdim 1007249259Sdim /// @returns true if the predicate of this ICmpInst is commutative 1008249259Sdim /// \brief Determine if this relation is commutative. 1009249259Sdim bool isCommutative() const { return isEquality(); } 1010249259Sdim 1011249259Sdim /// isRelational - Return true if the predicate is relational (not EQ or NE). 1012249259Sdim /// 1013249259Sdim bool isRelational() const { 1014249259Sdim return !isEquality(); 1015249259Sdim } 1016249259Sdim 1017249259Sdim /// isRelational - Return true if the predicate is relational (not EQ or NE). 1018249259Sdim /// 1019249259Sdim static bool isRelational(Predicate P) { 1020249259Sdim return !isEquality(P); 1021249259Sdim } 1022249259Sdim 1023249259Sdim /// Initialize a set of values that all satisfy the predicate with C. 1024249259Sdim /// \brief Make a ConstantRange for a relation with a constant value. 1025249259Sdim static ConstantRange makeConstantRange(Predicate pred, const APInt &C); 1026249259Sdim 1027249259Sdim /// Exchange the two operands to this instruction in such a way that it does 1028249259Sdim /// not modify the semantics of the instruction. The predicate value may be 1029249259Sdim /// changed to retain the same result if the predicate is order dependent 1030249259Sdim /// (e.g. ult). 1031249259Sdim /// \brief Swap operands and adjust predicate. 1032249259Sdim void swapOperands() { 1033249259Sdim setPredicate(getSwappedPredicate()); 1034249259Sdim Op<0>().swap(Op<1>()); 1035249259Sdim } 1036249259Sdim 1037249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 1038249259Sdim static inline bool classof(const Instruction *I) { 1039249259Sdim return I->getOpcode() == Instruction::ICmp; 1040249259Sdim } 1041249259Sdim static inline bool classof(const Value *V) { 1042249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 1043249259Sdim } 1044249259Sdim 1045249259Sdim}; 1046249259Sdim 1047249259Sdim//===----------------------------------------------------------------------===// 1048249259Sdim// FCmpInst Class 1049249259Sdim//===----------------------------------------------------------------------===// 1050249259Sdim 1051249259Sdim/// This instruction compares its operands according to the predicate given 1052249259Sdim/// to the constructor. It only operates on floating point values or packed 1053249259Sdim/// vectors of floating point values. The operands must be identical types. 1054249259Sdim/// \brief Represents a floating point comparison operator. 1055249259Sdimclass FCmpInst: public CmpInst { 1056249259Sdimprotected: 1057249259Sdim /// \brief Clone an identical FCmpInst 1058249259Sdim virtual FCmpInst *clone_impl() const; 1059249259Sdimpublic: 1060249259Sdim /// \brief Constructor with insert-before-instruction semantics. 1061249259Sdim FCmpInst( 1062249259Sdim Instruction *InsertBefore, ///< Where to insert 1063249259Sdim Predicate pred, ///< The predicate to use for the comparison 1064249259Sdim Value *LHS, ///< The left-hand-side of the expression 1065249259Sdim Value *RHS, ///< The right-hand-side of the expression 1066249259Sdim const Twine &NameStr = "" ///< Name of the instruction 1067249259Sdim ) : CmpInst(makeCmpResultType(LHS->getType()), 1068249259Sdim Instruction::FCmp, pred, LHS, RHS, NameStr, 1069249259Sdim InsertBefore) { 1070249259Sdim assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && 1071249259Sdim "Invalid FCmp predicate value"); 1072249259Sdim assert(getOperand(0)->getType() == getOperand(1)->getType() && 1073249259Sdim "Both operands to FCmp instruction are not of the same type!"); 1074249259Sdim // Check that the operands are the right type 1075249259Sdim assert(getOperand(0)->getType()->isFPOrFPVectorTy() && 1076249259Sdim "Invalid operand types for FCmp instruction"); 1077249259Sdim } 1078249259Sdim 1079249259Sdim /// \brief Constructor with insert-at-end semantics. 1080249259Sdim FCmpInst( 1081249259Sdim BasicBlock &InsertAtEnd, ///< Block to insert into. 1082249259Sdim Predicate pred, ///< The predicate to use for the comparison 1083249259Sdim Value *LHS, ///< The left-hand-side of the expression 1084249259Sdim Value *RHS, ///< The right-hand-side of the expression 1085249259Sdim const Twine &NameStr = "" ///< Name of the instruction 1086249259Sdim ) : CmpInst(makeCmpResultType(LHS->getType()), 1087249259Sdim Instruction::FCmp, pred, LHS, RHS, NameStr, 1088249259Sdim &InsertAtEnd) { 1089249259Sdim assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && 1090249259Sdim "Invalid FCmp predicate value"); 1091249259Sdim assert(getOperand(0)->getType() == getOperand(1)->getType() && 1092249259Sdim "Both operands to FCmp instruction are not of the same type!"); 1093249259Sdim // Check that the operands are the right type 1094249259Sdim assert(getOperand(0)->getType()->isFPOrFPVectorTy() && 1095249259Sdim "Invalid operand types for FCmp instruction"); 1096249259Sdim } 1097249259Sdim 1098249259Sdim /// \brief Constructor with no-insertion semantics 1099249259Sdim FCmpInst( 1100249259Sdim Predicate pred, ///< The predicate to use for the comparison 1101249259Sdim Value *LHS, ///< The left-hand-side of the expression 1102249259Sdim Value *RHS, ///< The right-hand-side of the expression 1103249259Sdim const Twine &NameStr = "" ///< Name of the instruction 1104249259Sdim ) : CmpInst(makeCmpResultType(LHS->getType()), 1105249259Sdim Instruction::FCmp, pred, LHS, RHS, NameStr) { 1106249259Sdim assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && 1107249259Sdim "Invalid FCmp predicate value"); 1108249259Sdim assert(getOperand(0)->getType() == getOperand(1)->getType() && 1109249259Sdim "Both operands to FCmp instruction are not of the same type!"); 1110249259Sdim // Check that the operands are the right type 1111249259Sdim assert(getOperand(0)->getType()->isFPOrFPVectorTy() && 1112249259Sdim "Invalid operand types for FCmp instruction"); 1113249259Sdim } 1114249259Sdim 1115249259Sdim /// @returns true if the predicate of this instruction is EQ or NE. 1116249259Sdim /// \brief Determine if this is an equality predicate. 1117249259Sdim bool isEquality() const { 1118249259Sdim return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE || 1119249259Sdim getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE; 1120249259Sdim } 1121249259Sdim 1122249259Sdim /// @returns true if the predicate of this instruction is commutative. 1123249259Sdim /// \brief Determine if this is a commutative predicate. 1124249259Sdim bool isCommutative() const { 1125249259Sdim return isEquality() || 1126249259Sdim getPredicate() == FCMP_FALSE || 1127249259Sdim getPredicate() == FCMP_TRUE || 1128249259Sdim getPredicate() == FCMP_ORD || 1129249259Sdim getPredicate() == FCMP_UNO; 1130249259Sdim } 1131249259Sdim 1132249259Sdim /// @returns true if the predicate is relational (not EQ or NE). 1133249259Sdim /// \brief Determine if this a relational predicate. 1134249259Sdim bool isRelational() const { return !isEquality(); } 1135249259Sdim 1136249259Sdim /// Exchange the two operands to this instruction in such a way that it does 1137249259Sdim /// not modify the semantics of the instruction. The predicate value may be 1138249259Sdim /// changed to retain the same result if the predicate is order dependent 1139249259Sdim /// (e.g. ult). 1140249259Sdim /// \brief Swap operands and adjust predicate. 1141249259Sdim void swapOperands() { 1142249259Sdim setPredicate(getSwappedPredicate()); 1143249259Sdim Op<0>().swap(Op<1>()); 1144249259Sdim } 1145249259Sdim 1146249259Sdim /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 1147249259Sdim static inline bool classof(const Instruction *I) { 1148249259Sdim return I->getOpcode() == Instruction::FCmp; 1149249259Sdim } 1150249259Sdim static inline bool classof(const Value *V) { 1151249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 1152249259Sdim } 1153249259Sdim}; 1154249259Sdim 1155249259Sdim//===----------------------------------------------------------------------===// 1156249259Sdim/// CallInst - This class represents a function call, abstracting a target 1157249259Sdim/// machine's calling convention. This class uses low bit of the SubClassData 1158249259Sdim/// field to indicate whether or not this is a tail call. The rest of the bits 1159249259Sdim/// hold the calling convention of the call. 1160249259Sdim/// 1161249259Sdimclass CallInst : public Instruction { 1162249259Sdim AttributeSet AttributeList; ///< parameter attributes for call 1163249259Sdim CallInst(const CallInst &CI); 1164249259Sdim void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr); 1165249259Sdim void init(Value *Func, const Twine &NameStr); 1166249259Sdim 1167249259Sdim /// Construct a CallInst given a range of arguments. 1168249259Sdim /// \brief Construct a CallInst from a range of arguments 1169249259Sdim inline CallInst(Value *Func, ArrayRef<Value *> Args, 1170249259Sdim const Twine &NameStr, Instruction *InsertBefore); 1171249259Sdim 1172249259Sdim /// Construct a CallInst given a range of arguments. 1173249259Sdim /// \brief Construct a CallInst from a range of arguments 1174249259Sdim inline CallInst(Value *Func, ArrayRef<Value *> Args, 1175249259Sdim const Twine &NameStr, BasicBlock *InsertAtEnd); 1176249259Sdim 1177249259Sdim CallInst(Value *F, Value *Actual, const Twine &NameStr, 1178249259Sdim Instruction *InsertBefore); 1179249259Sdim CallInst(Value *F, Value *Actual, const Twine &NameStr, 1180249259Sdim BasicBlock *InsertAtEnd); 1181249259Sdim explicit CallInst(Value *F, const Twine &NameStr, 1182249259Sdim Instruction *InsertBefore); 1183249259Sdim CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd); 1184249259Sdimprotected: 1185249259Sdim virtual CallInst *clone_impl() const; 1186249259Sdimpublic: 1187249259Sdim static CallInst *Create(Value *Func, 1188249259Sdim ArrayRef<Value *> Args, 1189249259Sdim const Twine &NameStr = "", 1190249259Sdim Instruction *InsertBefore = 0) { 1191249259Sdim return new(unsigned(Args.size() + 1)) 1192249259Sdim CallInst(Func, Args, NameStr, InsertBefore); 1193249259Sdim } 1194249259Sdim static CallInst *Create(Value *Func, 1195249259Sdim ArrayRef<Value *> Args, 1196249259Sdim const Twine &NameStr, BasicBlock *InsertAtEnd) { 1197249259Sdim return new(unsigned(Args.size() + 1)) 1198249259Sdim CallInst(Func, Args, NameStr, InsertAtEnd); 1199249259Sdim } 1200249259Sdim static CallInst *Create(Value *F, const Twine &NameStr = "", 1201249259Sdim Instruction *InsertBefore = 0) { 1202249259Sdim return new(1) CallInst(F, NameStr, InsertBefore); 1203249259Sdim } 1204249259Sdim static CallInst *Create(Value *F, const Twine &NameStr, 1205249259Sdim BasicBlock *InsertAtEnd) { 1206249259Sdim return new(1) CallInst(F, NameStr, InsertAtEnd); 1207249259Sdim } 1208249259Sdim /// CreateMalloc - Generate the IR for a call to malloc: 1209249259Sdim /// 1. Compute the malloc call's argument as the specified type's size, 1210249259Sdim /// possibly multiplied by the array size if the array size is not 1211249259Sdim /// constant 1. 1212249259Sdim /// 2. Call malloc with that argument. 1213249259Sdim /// 3. Bitcast the result of the malloc call to the specified type. 1214249259Sdim static Instruction *CreateMalloc(Instruction *InsertBefore, 1215249259Sdim Type *IntPtrTy, Type *AllocTy, 1216249259Sdim Value *AllocSize, Value *ArraySize = 0, 1217249259Sdim Function* MallocF = 0, 1218249259Sdim const Twine &Name = ""); 1219249259Sdim static Instruction *CreateMalloc(BasicBlock *InsertAtEnd, 1220249259Sdim Type *IntPtrTy, Type *AllocTy, 1221249259Sdim Value *AllocSize, Value *ArraySize = 0, 1222249259Sdim Function* MallocF = 0, 1223249259Sdim const Twine &Name = ""); 1224249259Sdim /// CreateFree - Generate the IR for a call to the builtin free function. 1225249259Sdim static Instruction* CreateFree(Value* Source, Instruction *InsertBefore); 1226249259Sdim static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd); 1227249259Sdim 1228249259Sdim ~CallInst(); 1229249259Sdim 1230249259Sdim bool isTailCall() const { return getSubclassDataFromInstruction() & 1; } 1231249259Sdim void setTailCall(bool isTC = true) { 1232249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | 1233249259Sdim unsigned(isTC)); 1234249259Sdim } 1235249259Sdim 1236249259Sdim /// Provide fast operand accessors 1237249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 1238249259Sdim 1239249259Sdim /// getNumArgOperands - Return the number of call arguments. 1240249259Sdim /// 1241249259Sdim unsigned getNumArgOperands() const { return getNumOperands() - 1; } 1242249259Sdim 1243249259Sdim /// getArgOperand/setArgOperand - Return/set the i-th call argument. 1244249259Sdim /// 1245249259Sdim Value *getArgOperand(unsigned i) const { return getOperand(i); } 1246249259Sdim void setArgOperand(unsigned i, Value *v) { setOperand(i, v); } 1247249259Sdim 1248249259Sdim /// getCallingConv/setCallingConv - Get or set the calling convention of this 1249249259Sdim /// function call. 1250249259Sdim CallingConv::ID getCallingConv() const { 1251249259Sdim return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1); 1252249259Sdim } 1253249259Sdim void setCallingConv(CallingConv::ID CC) { 1254249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & 1) | 1255249259Sdim (static_cast<unsigned>(CC) << 1)); 1256249259Sdim } 1257249259Sdim 1258249259Sdim /// getAttributes - Return the parameter attributes for this call. 1259249259Sdim /// 1260249259Sdim const AttributeSet &getAttributes() const { return AttributeList; } 1261249259Sdim 1262249259Sdim /// setAttributes - Set the parameter attributes for this call. 1263249259Sdim /// 1264249259Sdim void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; } 1265249259Sdim 1266249259Sdim /// addAttribute - adds the attribute to the list of attributes. 1267249259Sdim void addAttribute(unsigned i, Attribute::AttrKind attr); 1268249259Sdim 1269249259Sdim /// removeAttribute - removes the attribute from the list of attributes. 1270249259Sdim void removeAttribute(unsigned i, Attribute attr); 1271249259Sdim 1272249259Sdim /// \brief Determine whether this call has the given attribute. 1273263508Sdim bool hasFnAttr(Attribute::AttrKind A) const { 1274263508Sdim assert(A != Attribute::NoBuiltin && 1275263508Sdim "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin"); 1276263508Sdim return hasFnAttrImpl(A); 1277263508Sdim } 1278249259Sdim 1279249259Sdim /// \brief Determine whether the call or the callee has the given attributes. 1280249259Sdim bool paramHasAttr(unsigned i, Attribute::AttrKind A) const; 1281249259Sdim 1282249259Sdim /// \brief Extract the alignment for a call or parameter (0=unknown). 1283249259Sdim unsigned getParamAlignment(unsigned i) const { 1284249259Sdim return AttributeList.getParamAlignment(i); 1285249259Sdim } 1286249259Sdim 1287263508Sdim /// \brief Return true if the call should not be treated as a call to a 1288263508Sdim /// builtin. 1289263508Sdim bool isNoBuiltin() const { 1290263508Sdim return hasFnAttrImpl(Attribute::NoBuiltin) && 1291263508Sdim !hasFnAttrImpl(Attribute::Builtin); 1292263508Sdim } 1293263508Sdim 1294249259Sdim /// \brief Return true if the call should not be inlined. 1295249259Sdim bool isNoInline() const { return hasFnAttr(Attribute::NoInline); } 1296249259Sdim void setIsNoInline() { 1297249259Sdim addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline); 1298249259Sdim } 1299249259Sdim 1300249259Sdim /// \brief Return true if the call can return twice 1301249259Sdim bool canReturnTwice() const { 1302249259Sdim return hasFnAttr(Attribute::ReturnsTwice); 1303249259Sdim } 1304249259Sdim void setCanReturnTwice() { 1305249259Sdim addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice); 1306249259Sdim } 1307249259Sdim 1308249259Sdim /// \brief Determine if the call does not access memory. 1309249259Sdim bool doesNotAccessMemory() const { 1310249259Sdim return hasFnAttr(Attribute::ReadNone); 1311249259Sdim } 1312249259Sdim void setDoesNotAccessMemory() { 1313249259Sdim addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone); 1314249259Sdim } 1315249259Sdim 1316249259Sdim /// \brief Determine if the call does not access or only reads memory. 1317249259Sdim bool onlyReadsMemory() const { 1318249259Sdim return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly); 1319249259Sdim } 1320249259Sdim void setOnlyReadsMemory() { 1321249259Sdim addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly); 1322249259Sdim } 1323249259Sdim 1324249259Sdim /// \brief Determine if the call cannot return. 1325249259Sdim bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); } 1326249259Sdim void setDoesNotReturn() { 1327249259Sdim addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn); 1328249259Sdim } 1329249259Sdim 1330249259Sdim /// \brief Determine if the call cannot unwind. 1331249259Sdim bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); } 1332249259Sdim void setDoesNotThrow() { 1333249259Sdim addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind); 1334249259Sdim } 1335249259Sdim 1336249259Sdim /// \brief Determine if the call cannot be duplicated. 1337249259Sdim bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); } 1338249259Sdim void setCannotDuplicate() { 1339249259Sdim addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate); 1340249259Sdim } 1341249259Sdim 1342249259Sdim /// \brief Determine if the call returns a structure through first 1343249259Sdim /// pointer argument. 1344249259Sdim bool hasStructRetAttr() const { 1345249259Sdim // Be friendly and also check the callee. 1346249259Sdim return paramHasAttr(1, Attribute::StructRet); 1347249259Sdim } 1348249259Sdim 1349249259Sdim /// \brief Determine if any call argument is an aggregate passed by value. 1350249259Sdim bool hasByValArgument() const { 1351249259Sdim return AttributeList.hasAttrSomewhere(Attribute::ByVal); 1352249259Sdim } 1353249259Sdim 1354249259Sdim /// getCalledFunction - Return the function called, or null if this is an 1355249259Sdim /// indirect function invocation. 1356249259Sdim /// 1357249259Sdim Function *getCalledFunction() const { 1358249259Sdim return dyn_cast<Function>(Op<-1>()); 1359249259Sdim } 1360249259Sdim 1361249259Sdim /// getCalledValue - Get a pointer to the function that is invoked by this 1362249259Sdim /// instruction. 1363249259Sdim const Value *getCalledValue() const { return Op<-1>(); } 1364249259Sdim Value *getCalledValue() { return Op<-1>(); } 1365249259Sdim 1366249259Sdim /// setCalledFunction - Set the function called. 1367249259Sdim void setCalledFunction(Value* Fn) { 1368249259Sdim Op<-1>() = Fn; 1369249259Sdim } 1370249259Sdim 1371249259Sdim /// isInlineAsm - Check if this call is an inline asm statement. 1372249259Sdim bool isInlineAsm() const { 1373249259Sdim return isa<InlineAsm>(Op<-1>()); 1374249259Sdim } 1375249259Sdim 1376249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 1377249259Sdim static inline bool classof(const Instruction *I) { 1378249259Sdim return I->getOpcode() == Instruction::Call; 1379249259Sdim } 1380249259Sdim static inline bool classof(const Value *V) { 1381249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 1382249259Sdim } 1383249259Sdimprivate: 1384263508Sdim 1385263508Sdim bool hasFnAttrImpl(Attribute::AttrKind A) const; 1386263508Sdim 1387249259Sdim // Shadow Instruction::setInstructionSubclassData with a private forwarding 1388249259Sdim // method so that subclasses cannot accidentally use it. 1389249259Sdim void setInstructionSubclassData(unsigned short D) { 1390249259Sdim Instruction::setInstructionSubclassData(D); 1391249259Sdim } 1392249259Sdim}; 1393249259Sdim 1394249259Sdimtemplate <> 1395249259Sdimstruct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> { 1396249259Sdim}; 1397249259Sdim 1398249259SdimCallInst::CallInst(Value *Func, ArrayRef<Value *> Args, 1399249259Sdim const Twine &NameStr, BasicBlock *InsertAtEnd) 1400249259Sdim : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) 1401249259Sdim ->getElementType())->getReturnType(), 1402249259Sdim Instruction::Call, 1403249259Sdim OperandTraits<CallInst>::op_end(this) - (Args.size() + 1), 1404249259Sdim unsigned(Args.size() + 1), InsertAtEnd) { 1405249259Sdim init(Func, Args, NameStr); 1406249259Sdim} 1407249259Sdim 1408249259SdimCallInst::CallInst(Value *Func, ArrayRef<Value *> Args, 1409249259Sdim const Twine &NameStr, Instruction *InsertBefore) 1410249259Sdim : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) 1411249259Sdim ->getElementType())->getReturnType(), 1412249259Sdim Instruction::Call, 1413249259Sdim OperandTraits<CallInst>::op_end(this) - (Args.size() + 1), 1414249259Sdim unsigned(Args.size() + 1), InsertBefore) { 1415249259Sdim init(Func, Args, NameStr); 1416249259Sdim} 1417249259Sdim 1418249259Sdim 1419249259Sdim// Note: if you get compile errors about private methods then 1420249259Sdim// please update your code to use the high-level operand 1421249259Sdim// interfaces. See line 943 above. 1422249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value) 1423249259Sdim 1424249259Sdim//===----------------------------------------------------------------------===// 1425249259Sdim// SelectInst Class 1426249259Sdim//===----------------------------------------------------------------------===// 1427249259Sdim 1428249259Sdim/// SelectInst - This class represents the LLVM 'select' instruction. 1429249259Sdim/// 1430249259Sdimclass SelectInst : public Instruction { 1431249259Sdim void init(Value *C, Value *S1, Value *S2) { 1432249259Sdim assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select"); 1433249259Sdim Op<0>() = C; 1434249259Sdim Op<1>() = S1; 1435249259Sdim Op<2>() = S2; 1436249259Sdim } 1437249259Sdim 1438249259Sdim SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr, 1439249259Sdim Instruction *InsertBefore) 1440249259Sdim : Instruction(S1->getType(), Instruction::Select, 1441249259Sdim &Op<0>(), 3, InsertBefore) { 1442249259Sdim init(C, S1, S2); 1443249259Sdim setName(NameStr); 1444249259Sdim } 1445249259Sdim SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr, 1446249259Sdim BasicBlock *InsertAtEnd) 1447249259Sdim : Instruction(S1->getType(), Instruction::Select, 1448249259Sdim &Op<0>(), 3, InsertAtEnd) { 1449249259Sdim init(C, S1, S2); 1450249259Sdim setName(NameStr); 1451249259Sdim } 1452249259Sdimprotected: 1453249259Sdim virtual SelectInst *clone_impl() const; 1454249259Sdimpublic: 1455249259Sdim static SelectInst *Create(Value *C, Value *S1, Value *S2, 1456249259Sdim const Twine &NameStr = "", 1457249259Sdim Instruction *InsertBefore = 0) { 1458249259Sdim return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore); 1459249259Sdim } 1460249259Sdim static SelectInst *Create(Value *C, Value *S1, Value *S2, 1461249259Sdim const Twine &NameStr, 1462249259Sdim BasicBlock *InsertAtEnd) { 1463249259Sdim return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd); 1464249259Sdim } 1465249259Sdim 1466249259Sdim const Value *getCondition() const { return Op<0>(); } 1467249259Sdim const Value *getTrueValue() const { return Op<1>(); } 1468249259Sdim const Value *getFalseValue() const { return Op<2>(); } 1469249259Sdim Value *getCondition() { return Op<0>(); } 1470249259Sdim Value *getTrueValue() { return Op<1>(); } 1471249259Sdim Value *getFalseValue() { return Op<2>(); } 1472249259Sdim 1473249259Sdim /// areInvalidOperands - Return a string if the specified operands are invalid 1474249259Sdim /// for a select operation, otherwise return null. 1475249259Sdim static const char *areInvalidOperands(Value *Cond, Value *True, Value *False); 1476249259Sdim 1477249259Sdim /// Transparently provide more efficient getOperand methods. 1478249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 1479249259Sdim 1480249259Sdim OtherOps getOpcode() const { 1481249259Sdim return static_cast<OtherOps>(Instruction::getOpcode()); 1482249259Sdim } 1483249259Sdim 1484249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 1485249259Sdim static inline bool classof(const Instruction *I) { 1486249259Sdim return I->getOpcode() == Instruction::Select; 1487249259Sdim } 1488249259Sdim static inline bool classof(const Value *V) { 1489249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 1490249259Sdim } 1491249259Sdim}; 1492249259Sdim 1493249259Sdimtemplate <> 1494249259Sdimstruct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> { 1495249259Sdim}; 1496249259Sdim 1497249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value) 1498249259Sdim 1499249259Sdim//===----------------------------------------------------------------------===// 1500249259Sdim// VAArgInst Class 1501249259Sdim//===----------------------------------------------------------------------===// 1502249259Sdim 1503249259Sdim/// VAArgInst - This class represents the va_arg llvm instruction, which returns 1504249259Sdim/// an argument of the specified type given a va_list and increments that list 1505249259Sdim/// 1506249259Sdimclass VAArgInst : public UnaryInstruction { 1507249259Sdimprotected: 1508249259Sdim virtual VAArgInst *clone_impl() const; 1509249259Sdim 1510249259Sdimpublic: 1511249259Sdim VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "", 1512249259Sdim Instruction *InsertBefore = 0) 1513249259Sdim : UnaryInstruction(Ty, VAArg, List, InsertBefore) { 1514249259Sdim setName(NameStr); 1515249259Sdim } 1516249259Sdim VAArgInst(Value *List, Type *Ty, const Twine &NameStr, 1517249259Sdim BasicBlock *InsertAtEnd) 1518249259Sdim : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) { 1519249259Sdim setName(NameStr); 1520249259Sdim } 1521249259Sdim 1522249259Sdim Value *getPointerOperand() { return getOperand(0); } 1523249259Sdim const Value *getPointerOperand() const { return getOperand(0); } 1524249259Sdim static unsigned getPointerOperandIndex() { return 0U; } 1525249259Sdim 1526249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 1527249259Sdim static inline bool classof(const Instruction *I) { 1528249259Sdim return I->getOpcode() == VAArg; 1529249259Sdim } 1530249259Sdim static inline bool classof(const Value *V) { 1531249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 1532249259Sdim } 1533249259Sdim}; 1534249259Sdim 1535249259Sdim//===----------------------------------------------------------------------===// 1536249259Sdim// ExtractElementInst Class 1537249259Sdim//===----------------------------------------------------------------------===// 1538249259Sdim 1539249259Sdim/// ExtractElementInst - This instruction extracts a single (scalar) 1540249259Sdim/// element from a VectorType value 1541249259Sdim/// 1542249259Sdimclass ExtractElementInst : public Instruction { 1543249259Sdim ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "", 1544249259Sdim Instruction *InsertBefore = 0); 1545249259Sdim ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr, 1546249259Sdim BasicBlock *InsertAtEnd); 1547249259Sdimprotected: 1548249259Sdim virtual ExtractElementInst *clone_impl() const; 1549249259Sdim 1550249259Sdimpublic: 1551249259Sdim static ExtractElementInst *Create(Value *Vec, Value *Idx, 1552249259Sdim const Twine &NameStr = "", 1553249259Sdim Instruction *InsertBefore = 0) { 1554249259Sdim return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore); 1555249259Sdim } 1556249259Sdim static ExtractElementInst *Create(Value *Vec, Value *Idx, 1557249259Sdim const Twine &NameStr, 1558249259Sdim BasicBlock *InsertAtEnd) { 1559249259Sdim return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd); 1560249259Sdim } 1561249259Sdim 1562249259Sdim /// isValidOperands - Return true if an extractelement instruction can be 1563249259Sdim /// formed with the specified operands. 1564249259Sdim static bool isValidOperands(const Value *Vec, const Value *Idx); 1565249259Sdim 1566249259Sdim Value *getVectorOperand() { return Op<0>(); } 1567249259Sdim Value *getIndexOperand() { return Op<1>(); } 1568249259Sdim const Value *getVectorOperand() const { return Op<0>(); } 1569249259Sdim const Value *getIndexOperand() const { return Op<1>(); } 1570249259Sdim 1571249259Sdim VectorType *getVectorOperandType() const { 1572249259Sdim return cast<VectorType>(getVectorOperand()->getType()); 1573249259Sdim } 1574249259Sdim 1575249259Sdim 1576249259Sdim /// Transparently provide more efficient getOperand methods. 1577249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 1578249259Sdim 1579249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 1580249259Sdim static inline bool classof(const Instruction *I) { 1581249259Sdim return I->getOpcode() == Instruction::ExtractElement; 1582249259Sdim } 1583249259Sdim static inline bool classof(const Value *V) { 1584249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 1585249259Sdim } 1586249259Sdim}; 1587249259Sdim 1588249259Sdimtemplate <> 1589249259Sdimstruct OperandTraits<ExtractElementInst> : 1590249259Sdim public FixedNumOperandTraits<ExtractElementInst, 2> { 1591249259Sdim}; 1592249259Sdim 1593249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value) 1594249259Sdim 1595249259Sdim//===----------------------------------------------------------------------===// 1596249259Sdim// InsertElementInst Class 1597249259Sdim//===----------------------------------------------------------------------===// 1598249259Sdim 1599249259Sdim/// InsertElementInst - This instruction inserts a single (scalar) 1600249259Sdim/// element into a VectorType value 1601249259Sdim/// 1602249259Sdimclass InsertElementInst : public Instruction { 1603249259Sdim InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, 1604249259Sdim const Twine &NameStr = "", 1605249259Sdim Instruction *InsertBefore = 0); 1606249259Sdim InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, 1607249259Sdim const Twine &NameStr, BasicBlock *InsertAtEnd); 1608249259Sdimprotected: 1609249259Sdim virtual InsertElementInst *clone_impl() const; 1610249259Sdim 1611249259Sdimpublic: 1612249259Sdim static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, 1613249259Sdim const Twine &NameStr = "", 1614249259Sdim Instruction *InsertBefore = 0) { 1615249259Sdim return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore); 1616249259Sdim } 1617249259Sdim static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, 1618249259Sdim const Twine &NameStr, 1619249259Sdim BasicBlock *InsertAtEnd) { 1620249259Sdim return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd); 1621249259Sdim } 1622249259Sdim 1623249259Sdim /// isValidOperands - Return true if an insertelement instruction can be 1624249259Sdim /// formed with the specified operands. 1625249259Sdim static bool isValidOperands(const Value *Vec, const Value *NewElt, 1626249259Sdim const Value *Idx); 1627249259Sdim 1628249259Sdim /// getType - Overload to return most specific vector type. 1629249259Sdim /// 1630249259Sdim VectorType *getType() const { 1631249259Sdim return cast<VectorType>(Instruction::getType()); 1632249259Sdim } 1633249259Sdim 1634249259Sdim /// Transparently provide more efficient getOperand methods. 1635249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 1636249259Sdim 1637249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 1638249259Sdim static inline bool classof(const Instruction *I) { 1639249259Sdim return I->getOpcode() == Instruction::InsertElement; 1640249259Sdim } 1641249259Sdim static inline bool classof(const Value *V) { 1642249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 1643249259Sdim } 1644249259Sdim}; 1645249259Sdim 1646249259Sdimtemplate <> 1647249259Sdimstruct OperandTraits<InsertElementInst> : 1648249259Sdim public FixedNumOperandTraits<InsertElementInst, 3> { 1649249259Sdim}; 1650249259Sdim 1651249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value) 1652249259Sdim 1653249259Sdim//===----------------------------------------------------------------------===// 1654249259Sdim// ShuffleVectorInst Class 1655249259Sdim//===----------------------------------------------------------------------===// 1656249259Sdim 1657249259Sdim/// ShuffleVectorInst - This instruction constructs a fixed permutation of two 1658249259Sdim/// input vectors. 1659249259Sdim/// 1660249259Sdimclass ShuffleVectorInst : public Instruction { 1661249259Sdimprotected: 1662249259Sdim virtual ShuffleVectorInst *clone_impl() const; 1663249259Sdim 1664249259Sdimpublic: 1665249259Sdim // allocate space for exactly three operands 1666249259Sdim void *operator new(size_t s) { 1667249259Sdim return User::operator new(s, 3); 1668249259Sdim } 1669249259Sdim ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, 1670249259Sdim const Twine &NameStr = "", 1671249259Sdim Instruction *InsertBefor = 0); 1672249259Sdim ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, 1673249259Sdim const Twine &NameStr, BasicBlock *InsertAtEnd); 1674249259Sdim 1675249259Sdim /// isValidOperands - Return true if a shufflevector instruction can be 1676249259Sdim /// formed with the specified operands. 1677249259Sdim static bool isValidOperands(const Value *V1, const Value *V2, 1678249259Sdim const Value *Mask); 1679249259Sdim 1680249259Sdim /// getType - Overload to return most specific vector type. 1681249259Sdim /// 1682249259Sdim VectorType *getType() const { 1683249259Sdim return cast<VectorType>(Instruction::getType()); 1684249259Sdim } 1685249259Sdim 1686249259Sdim /// Transparently provide more efficient getOperand methods. 1687249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 1688249259Sdim 1689249259Sdim Constant *getMask() const { 1690249259Sdim return cast<Constant>(getOperand(2)); 1691249259Sdim } 1692249259Sdim 1693249259Sdim /// getMaskValue - Return the index from the shuffle mask for the specified 1694249259Sdim /// output result. This is either -1 if the element is undef or a number less 1695249259Sdim /// than 2*numelements. 1696249259Sdim static int getMaskValue(Constant *Mask, unsigned i); 1697249259Sdim 1698249259Sdim int getMaskValue(unsigned i) const { 1699249259Sdim return getMaskValue(getMask(), i); 1700249259Sdim } 1701249259Sdim 1702249259Sdim /// getShuffleMask - Return the full mask for this instruction, where each 1703249259Sdim /// element is the element number and undef's are returned as -1. 1704249259Sdim static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result); 1705249259Sdim 1706249259Sdim void getShuffleMask(SmallVectorImpl<int> &Result) const { 1707249259Sdim return getShuffleMask(getMask(), Result); 1708249259Sdim } 1709249259Sdim 1710249259Sdim SmallVector<int, 16> getShuffleMask() const { 1711249259Sdim SmallVector<int, 16> Mask; 1712249259Sdim getShuffleMask(Mask); 1713249259Sdim return Mask; 1714249259Sdim } 1715249259Sdim 1716249259Sdim 1717249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 1718249259Sdim static inline bool classof(const Instruction *I) { 1719249259Sdim return I->getOpcode() == Instruction::ShuffleVector; 1720249259Sdim } 1721249259Sdim static inline bool classof(const Value *V) { 1722249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 1723249259Sdim } 1724249259Sdim}; 1725249259Sdim 1726249259Sdimtemplate <> 1727249259Sdimstruct OperandTraits<ShuffleVectorInst> : 1728249259Sdim public FixedNumOperandTraits<ShuffleVectorInst, 3> { 1729249259Sdim}; 1730249259Sdim 1731249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value) 1732249259Sdim 1733249259Sdim//===----------------------------------------------------------------------===// 1734249259Sdim// ExtractValueInst Class 1735249259Sdim//===----------------------------------------------------------------------===// 1736249259Sdim 1737249259Sdim/// ExtractValueInst - This instruction extracts a struct member or array 1738249259Sdim/// element value from an aggregate value. 1739249259Sdim/// 1740249259Sdimclass ExtractValueInst : public UnaryInstruction { 1741249259Sdim SmallVector<unsigned, 4> Indices; 1742249259Sdim 1743249259Sdim ExtractValueInst(const ExtractValueInst &EVI); 1744249259Sdim void init(ArrayRef<unsigned> Idxs, const Twine &NameStr); 1745249259Sdim 1746249259Sdim /// Constructors - Create a extractvalue instruction with a base aggregate 1747249259Sdim /// value and a list of indices. The first ctor can optionally insert before 1748249259Sdim /// an existing instruction, the second appends the new instruction to the 1749249259Sdim /// specified BasicBlock. 1750249259Sdim inline ExtractValueInst(Value *Agg, 1751249259Sdim ArrayRef<unsigned> Idxs, 1752249259Sdim const Twine &NameStr, 1753249259Sdim Instruction *InsertBefore); 1754249259Sdim inline ExtractValueInst(Value *Agg, 1755249259Sdim ArrayRef<unsigned> Idxs, 1756249259Sdim const Twine &NameStr, BasicBlock *InsertAtEnd); 1757249259Sdim 1758249259Sdim // allocate space for exactly one operand 1759249259Sdim void *operator new(size_t s) { 1760249259Sdim return User::operator new(s, 1); 1761249259Sdim } 1762249259Sdimprotected: 1763249259Sdim virtual ExtractValueInst *clone_impl() const; 1764249259Sdim 1765249259Sdimpublic: 1766249259Sdim static ExtractValueInst *Create(Value *Agg, 1767249259Sdim ArrayRef<unsigned> Idxs, 1768249259Sdim const Twine &NameStr = "", 1769249259Sdim Instruction *InsertBefore = 0) { 1770249259Sdim return new 1771249259Sdim ExtractValueInst(Agg, Idxs, NameStr, InsertBefore); 1772249259Sdim } 1773249259Sdim static ExtractValueInst *Create(Value *Agg, 1774249259Sdim ArrayRef<unsigned> Idxs, 1775249259Sdim const Twine &NameStr, 1776249259Sdim BasicBlock *InsertAtEnd) { 1777249259Sdim return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd); 1778249259Sdim } 1779249259Sdim 1780249259Sdim /// getIndexedType - Returns the type of the element that would be extracted 1781249259Sdim /// with an extractvalue instruction with the specified parameters. 1782249259Sdim /// 1783249259Sdim /// Null is returned if the indices are invalid for the specified type. 1784249259Sdim static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs); 1785249259Sdim 1786249259Sdim typedef const unsigned* idx_iterator; 1787249259Sdim inline idx_iterator idx_begin() const { return Indices.begin(); } 1788249259Sdim inline idx_iterator idx_end() const { return Indices.end(); } 1789249259Sdim 1790249259Sdim Value *getAggregateOperand() { 1791249259Sdim return getOperand(0); 1792249259Sdim } 1793249259Sdim const Value *getAggregateOperand() const { 1794249259Sdim return getOperand(0); 1795249259Sdim } 1796249259Sdim static unsigned getAggregateOperandIndex() { 1797249259Sdim return 0U; // get index for modifying correct operand 1798249259Sdim } 1799249259Sdim 1800249259Sdim ArrayRef<unsigned> getIndices() const { 1801249259Sdim return Indices; 1802249259Sdim } 1803249259Sdim 1804249259Sdim unsigned getNumIndices() const { 1805249259Sdim return (unsigned)Indices.size(); 1806249259Sdim } 1807249259Sdim 1808249259Sdim bool hasIndices() const { 1809249259Sdim return true; 1810249259Sdim } 1811249259Sdim 1812249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 1813249259Sdim static inline bool classof(const Instruction *I) { 1814249259Sdim return I->getOpcode() == Instruction::ExtractValue; 1815249259Sdim } 1816249259Sdim static inline bool classof(const Value *V) { 1817249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 1818249259Sdim } 1819249259Sdim}; 1820249259Sdim 1821249259SdimExtractValueInst::ExtractValueInst(Value *Agg, 1822249259Sdim ArrayRef<unsigned> Idxs, 1823249259Sdim const Twine &NameStr, 1824249259Sdim Instruction *InsertBefore) 1825249259Sdim : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)), 1826249259Sdim ExtractValue, Agg, InsertBefore) { 1827249259Sdim init(Idxs, NameStr); 1828249259Sdim} 1829249259SdimExtractValueInst::ExtractValueInst(Value *Agg, 1830249259Sdim ArrayRef<unsigned> Idxs, 1831249259Sdim const Twine &NameStr, 1832249259Sdim BasicBlock *InsertAtEnd) 1833249259Sdim : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)), 1834249259Sdim ExtractValue, Agg, InsertAtEnd) { 1835249259Sdim init(Idxs, NameStr); 1836249259Sdim} 1837249259Sdim 1838249259Sdim 1839249259Sdim//===----------------------------------------------------------------------===// 1840249259Sdim// InsertValueInst Class 1841249259Sdim//===----------------------------------------------------------------------===// 1842249259Sdim 1843249259Sdim/// InsertValueInst - This instruction inserts a struct field of array element 1844249259Sdim/// value into an aggregate value. 1845249259Sdim/// 1846249259Sdimclass InsertValueInst : public Instruction { 1847249259Sdim SmallVector<unsigned, 4> Indices; 1848249259Sdim 1849249259Sdim void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 1850249259Sdim InsertValueInst(const InsertValueInst &IVI); 1851249259Sdim void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs, 1852249259Sdim const Twine &NameStr); 1853249259Sdim 1854249259Sdim /// Constructors - Create a insertvalue instruction with a base aggregate 1855249259Sdim /// value, a value to insert, and a list of indices. The first ctor can 1856249259Sdim /// optionally insert before an existing instruction, the second appends 1857249259Sdim /// the new instruction to the specified BasicBlock. 1858249259Sdim inline InsertValueInst(Value *Agg, Value *Val, 1859249259Sdim ArrayRef<unsigned> Idxs, 1860249259Sdim const Twine &NameStr, 1861249259Sdim Instruction *InsertBefore); 1862249259Sdim inline InsertValueInst(Value *Agg, Value *Val, 1863249259Sdim ArrayRef<unsigned> Idxs, 1864249259Sdim const Twine &NameStr, BasicBlock *InsertAtEnd); 1865249259Sdim 1866249259Sdim /// Constructors - These two constructors are convenience methods because one 1867249259Sdim /// and two index insertvalue instructions are so common. 1868249259Sdim InsertValueInst(Value *Agg, Value *Val, 1869249259Sdim unsigned Idx, const Twine &NameStr = "", 1870249259Sdim Instruction *InsertBefore = 0); 1871249259Sdim InsertValueInst(Value *Agg, Value *Val, unsigned Idx, 1872249259Sdim const Twine &NameStr, BasicBlock *InsertAtEnd); 1873249259Sdimprotected: 1874249259Sdim virtual InsertValueInst *clone_impl() const; 1875249259Sdimpublic: 1876249259Sdim // allocate space for exactly two operands 1877249259Sdim void *operator new(size_t s) { 1878249259Sdim return User::operator new(s, 2); 1879249259Sdim } 1880249259Sdim 1881249259Sdim static InsertValueInst *Create(Value *Agg, Value *Val, 1882249259Sdim ArrayRef<unsigned> Idxs, 1883249259Sdim const Twine &NameStr = "", 1884249259Sdim Instruction *InsertBefore = 0) { 1885249259Sdim return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore); 1886249259Sdim } 1887249259Sdim static InsertValueInst *Create(Value *Agg, Value *Val, 1888249259Sdim ArrayRef<unsigned> Idxs, 1889249259Sdim const Twine &NameStr, 1890249259Sdim BasicBlock *InsertAtEnd) { 1891249259Sdim return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd); 1892249259Sdim } 1893249259Sdim 1894249259Sdim /// Transparently provide more efficient getOperand methods. 1895249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 1896249259Sdim 1897249259Sdim typedef const unsigned* idx_iterator; 1898249259Sdim inline idx_iterator idx_begin() const { return Indices.begin(); } 1899249259Sdim inline idx_iterator idx_end() const { return Indices.end(); } 1900249259Sdim 1901249259Sdim Value *getAggregateOperand() { 1902249259Sdim return getOperand(0); 1903249259Sdim } 1904249259Sdim const Value *getAggregateOperand() const { 1905249259Sdim return getOperand(0); 1906249259Sdim } 1907249259Sdim static unsigned getAggregateOperandIndex() { 1908249259Sdim return 0U; // get index for modifying correct operand 1909249259Sdim } 1910249259Sdim 1911249259Sdim Value *getInsertedValueOperand() { 1912249259Sdim return getOperand(1); 1913249259Sdim } 1914249259Sdim const Value *getInsertedValueOperand() const { 1915249259Sdim return getOperand(1); 1916249259Sdim } 1917249259Sdim static unsigned getInsertedValueOperandIndex() { 1918249259Sdim return 1U; // get index for modifying correct operand 1919249259Sdim } 1920249259Sdim 1921249259Sdim ArrayRef<unsigned> getIndices() const { 1922249259Sdim return Indices; 1923249259Sdim } 1924249259Sdim 1925249259Sdim unsigned getNumIndices() const { 1926249259Sdim return (unsigned)Indices.size(); 1927249259Sdim } 1928249259Sdim 1929249259Sdim bool hasIndices() const { 1930249259Sdim return true; 1931249259Sdim } 1932249259Sdim 1933249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 1934249259Sdim static inline bool classof(const Instruction *I) { 1935249259Sdim return I->getOpcode() == Instruction::InsertValue; 1936249259Sdim } 1937249259Sdim static inline bool classof(const Value *V) { 1938249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 1939249259Sdim } 1940249259Sdim}; 1941249259Sdim 1942249259Sdimtemplate <> 1943249259Sdimstruct OperandTraits<InsertValueInst> : 1944249259Sdim public FixedNumOperandTraits<InsertValueInst, 2> { 1945249259Sdim}; 1946249259Sdim 1947249259SdimInsertValueInst::InsertValueInst(Value *Agg, 1948249259Sdim Value *Val, 1949249259Sdim ArrayRef<unsigned> Idxs, 1950249259Sdim const Twine &NameStr, 1951249259Sdim Instruction *InsertBefore) 1952249259Sdim : Instruction(Agg->getType(), InsertValue, 1953249259Sdim OperandTraits<InsertValueInst>::op_begin(this), 1954249259Sdim 2, InsertBefore) { 1955249259Sdim init(Agg, Val, Idxs, NameStr); 1956249259Sdim} 1957249259SdimInsertValueInst::InsertValueInst(Value *Agg, 1958249259Sdim Value *Val, 1959249259Sdim ArrayRef<unsigned> Idxs, 1960249259Sdim const Twine &NameStr, 1961249259Sdim BasicBlock *InsertAtEnd) 1962249259Sdim : Instruction(Agg->getType(), InsertValue, 1963249259Sdim OperandTraits<InsertValueInst>::op_begin(this), 1964249259Sdim 2, InsertAtEnd) { 1965249259Sdim init(Agg, Val, Idxs, NameStr); 1966249259Sdim} 1967249259Sdim 1968249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value) 1969249259Sdim 1970249259Sdim//===----------------------------------------------------------------------===// 1971249259Sdim// PHINode Class 1972249259Sdim//===----------------------------------------------------------------------===// 1973249259Sdim 1974249259Sdim// PHINode - The PHINode class is used to represent the magical mystical PHI 1975249259Sdim// node, that can not exist in nature, but can be synthesized in a computer 1976249259Sdim// scientist's overactive imagination. 1977249259Sdim// 1978249259Sdimclass PHINode : public Instruction { 1979249259Sdim void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 1980249259Sdim /// ReservedSpace - The number of operands actually allocated. NumOperands is 1981249259Sdim /// the number actually in use. 1982249259Sdim unsigned ReservedSpace; 1983249259Sdim PHINode(const PHINode &PN); 1984249259Sdim // allocate space for exactly zero operands 1985249259Sdim void *operator new(size_t s) { 1986249259Sdim return User::operator new(s, 0); 1987249259Sdim } 1988249259Sdim explicit PHINode(Type *Ty, unsigned NumReservedValues, 1989249259Sdim const Twine &NameStr = "", Instruction *InsertBefore = 0) 1990249259Sdim : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore), 1991249259Sdim ReservedSpace(NumReservedValues) { 1992249259Sdim setName(NameStr); 1993249259Sdim OperandList = allocHungoffUses(ReservedSpace); 1994249259Sdim } 1995249259Sdim 1996249259Sdim PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr, 1997249259Sdim BasicBlock *InsertAtEnd) 1998249259Sdim : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd), 1999249259Sdim ReservedSpace(NumReservedValues) { 2000249259Sdim setName(NameStr); 2001249259Sdim OperandList = allocHungoffUses(ReservedSpace); 2002249259Sdim } 2003249259Sdimprotected: 2004249259Sdim // allocHungoffUses - this is more complicated than the generic 2005249259Sdim // User::allocHungoffUses, because we have to allocate Uses for the incoming 2006249259Sdim // values and pointers to the incoming blocks, all in one allocation. 2007249259Sdim Use *allocHungoffUses(unsigned) const; 2008249259Sdim 2009249259Sdim virtual PHINode *clone_impl() const; 2010249259Sdimpublic: 2011249259Sdim /// Constructors - NumReservedValues is a hint for the number of incoming 2012249259Sdim /// edges that this phi node will have (use 0 if you really have no idea). 2013249259Sdim static PHINode *Create(Type *Ty, unsigned NumReservedValues, 2014249259Sdim const Twine &NameStr = "", 2015249259Sdim Instruction *InsertBefore = 0) { 2016249259Sdim return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore); 2017249259Sdim } 2018249259Sdim static PHINode *Create(Type *Ty, unsigned NumReservedValues, 2019249259Sdim const Twine &NameStr, BasicBlock *InsertAtEnd) { 2020249259Sdim return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd); 2021249259Sdim } 2022249259Sdim ~PHINode(); 2023249259Sdim 2024249259Sdim /// Provide fast operand accessors 2025249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 2026249259Sdim 2027249259Sdim // Block iterator interface. This provides access to the list of incoming 2028249259Sdim // basic blocks, which parallels the list of incoming values. 2029249259Sdim 2030249259Sdim typedef BasicBlock **block_iterator; 2031249259Sdim typedef BasicBlock * const *const_block_iterator; 2032249259Sdim 2033249259Sdim block_iterator block_begin() { 2034249259Sdim Use::UserRef *ref = 2035249259Sdim reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace); 2036249259Sdim return reinterpret_cast<block_iterator>(ref + 1); 2037249259Sdim } 2038249259Sdim 2039249259Sdim const_block_iterator block_begin() const { 2040249259Sdim const Use::UserRef *ref = 2041249259Sdim reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace); 2042249259Sdim return reinterpret_cast<const_block_iterator>(ref + 1); 2043249259Sdim } 2044249259Sdim 2045249259Sdim block_iterator block_end() { 2046249259Sdim return block_begin() + getNumOperands(); 2047249259Sdim } 2048249259Sdim 2049249259Sdim const_block_iterator block_end() const { 2050249259Sdim return block_begin() + getNumOperands(); 2051249259Sdim } 2052249259Sdim 2053249259Sdim /// getNumIncomingValues - Return the number of incoming edges 2054249259Sdim /// 2055249259Sdim unsigned getNumIncomingValues() const { return getNumOperands(); } 2056249259Sdim 2057249259Sdim /// getIncomingValue - Return incoming value number x 2058249259Sdim /// 2059249259Sdim Value *getIncomingValue(unsigned i) const { 2060249259Sdim return getOperand(i); 2061249259Sdim } 2062249259Sdim void setIncomingValue(unsigned i, Value *V) { 2063249259Sdim setOperand(i, V); 2064249259Sdim } 2065249259Sdim static unsigned getOperandNumForIncomingValue(unsigned i) { 2066249259Sdim return i; 2067249259Sdim } 2068249259Sdim static unsigned getIncomingValueNumForOperand(unsigned i) { 2069249259Sdim return i; 2070249259Sdim } 2071249259Sdim 2072249259Sdim /// getIncomingBlock - Return incoming basic block number @p i. 2073249259Sdim /// 2074249259Sdim BasicBlock *getIncomingBlock(unsigned i) const { 2075249259Sdim return block_begin()[i]; 2076249259Sdim } 2077249259Sdim 2078249259Sdim /// getIncomingBlock - Return incoming basic block corresponding 2079249259Sdim /// to an operand of the PHI. 2080249259Sdim /// 2081249259Sdim BasicBlock *getIncomingBlock(const Use &U) const { 2082249259Sdim assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?"); 2083249259Sdim return getIncomingBlock(unsigned(&U - op_begin())); 2084249259Sdim } 2085249259Sdim 2086249259Sdim /// getIncomingBlock - Return incoming basic block corresponding 2087249259Sdim /// to value use iterator. 2088249259Sdim /// 2089249259Sdim template <typename U> 2090249259Sdim BasicBlock *getIncomingBlock(value_use_iterator<U> I) const { 2091249259Sdim return getIncomingBlock(I.getUse()); 2092249259Sdim } 2093249259Sdim 2094249259Sdim void setIncomingBlock(unsigned i, BasicBlock *BB) { 2095249259Sdim block_begin()[i] = BB; 2096249259Sdim } 2097249259Sdim 2098249259Sdim /// addIncoming - Add an incoming value to the end of the PHI list 2099249259Sdim /// 2100249259Sdim void addIncoming(Value *V, BasicBlock *BB) { 2101249259Sdim assert(V && "PHI node got a null value!"); 2102249259Sdim assert(BB && "PHI node got a null basic block!"); 2103249259Sdim assert(getType() == V->getType() && 2104249259Sdim "All operands to PHI node must be the same type as the PHI node!"); 2105249259Sdim if (NumOperands == ReservedSpace) 2106249259Sdim growOperands(); // Get more space! 2107249259Sdim // Initialize some new operands. 2108249259Sdim ++NumOperands; 2109249259Sdim setIncomingValue(NumOperands - 1, V); 2110249259Sdim setIncomingBlock(NumOperands - 1, BB); 2111249259Sdim } 2112249259Sdim 2113249259Sdim /// removeIncomingValue - Remove an incoming value. This is useful if a 2114249259Sdim /// predecessor basic block is deleted. The value removed is returned. 2115249259Sdim /// 2116249259Sdim /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty 2117249259Sdim /// is true), the PHI node is destroyed and any uses of it are replaced with 2118249259Sdim /// dummy values. The only time there should be zero incoming values to a PHI 2119249259Sdim /// node is when the block is dead, so this strategy is sound. 2120249259Sdim /// 2121249259Sdim Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true); 2122249259Sdim 2123249259Sdim Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) { 2124249259Sdim int Idx = getBasicBlockIndex(BB); 2125249259Sdim assert(Idx >= 0 && "Invalid basic block argument to remove!"); 2126249259Sdim return removeIncomingValue(Idx, DeletePHIIfEmpty); 2127249259Sdim } 2128249259Sdim 2129249259Sdim /// getBasicBlockIndex - Return the first index of the specified basic 2130249259Sdim /// block in the value list for this PHI. Returns -1 if no instance. 2131249259Sdim /// 2132249259Sdim int getBasicBlockIndex(const BasicBlock *BB) const { 2133249259Sdim for (unsigned i = 0, e = getNumOperands(); i != e; ++i) 2134249259Sdim if (block_begin()[i] == BB) 2135249259Sdim return i; 2136249259Sdim return -1; 2137249259Sdim } 2138249259Sdim 2139249259Sdim Value *getIncomingValueForBlock(const BasicBlock *BB) const { 2140249259Sdim int Idx = getBasicBlockIndex(BB); 2141249259Sdim assert(Idx >= 0 && "Invalid basic block argument!"); 2142249259Sdim return getIncomingValue(Idx); 2143249259Sdim } 2144249259Sdim 2145249259Sdim /// hasConstantValue - If the specified PHI node always merges together the 2146249259Sdim /// same value, return the value, otherwise return null. 2147249259Sdim Value *hasConstantValue() const; 2148249259Sdim 2149249259Sdim /// Methods for support type inquiry through isa, cast, and dyn_cast: 2150249259Sdim static inline bool classof(const Instruction *I) { 2151249259Sdim return I->getOpcode() == Instruction::PHI; 2152249259Sdim } 2153249259Sdim static inline bool classof(const Value *V) { 2154249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 2155249259Sdim } 2156249259Sdim private: 2157249259Sdim void growOperands(); 2158249259Sdim}; 2159249259Sdim 2160249259Sdimtemplate <> 2161249259Sdimstruct OperandTraits<PHINode> : public HungoffOperandTraits<2> { 2162249259Sdim}; 2163249259Sdim 2164249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value) 2165249259Sdim 2166249259Sdim//===----------------------------------------------------------------------===// 2167249259Sdim// LandingPadInst Class 2168249259Sdim//===----------------------------------------------------------------------===// 2169249259Sdim 2170249259Sdim//===--------------------------------------------------------------------------- 2171249259Sdim/// LandingPadInst - The landingpad instruction holds all of the information 2172249259Sdim/// necessary to generate correct exception handling. The landingpad instruction 2173249259Sdim/// cannot be moved from the top of a landing pad block, which itself is 2174249259Sdim/// accessible only from the 'unwind' edge of an invoke. This uses the 2175249259Sdim/// SubclassData field in Value to store whether or not the landingpad is a 2176249259Sdim/// cleanup. 2177249259Sdim/// 2178249259Sdimclass LandingPadInst : public Instruction { 2179249259Sdim /// ReservedSpace - The number of operands actually allocated. NumOperands is 2180249259Sdim /// the number actually in use. 2181249259Sdim unsigned ReservedSpace; 2182249259Sdim LandingPadInst(const LandingPadInst &LP); 2183249259Sdimpublic: 2184249259Sdim enum ClauseType { Catch, Filter }; 2185249259Sdimprivate: 2186249259Sdim void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 2187249259Sdim // Allocate space for exactly zero operands. 2188249259Sdim void *operator new(size_t s) { 2189249259Sdim return User::operator new(s, 0); 2190249259Sdim } 2191249259Sdim void growOperands(unsigned Size); 2192249259Sdim void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr); 2193249259Sdim 2194249259Sdim explicit LandingPadInst(Type *RetTy, Value *PersonalityFn, 2195249259Sdim unsigned NumReservedValues, const Twine &NameStr, 2196249259Sdim Instruction *InsertBefore); 2197249259Sdim explicit LandingPadInst(Type *RetTy, Value *PersonalityFn, 2198249259Sdim unsigned NumReservedValues, const Twine &NameStr, 2199249259Sdim BasicBlock *InsertAtEnd); 2200249259Sdimprotected: 2201249259Sdim virtual LandingPadInst *clone_impl() const; 2202249259Sdimpublic: 2203249259Sdim /// Constructors - NumReservedClauses is a hint for the number of incoming 2204249259Sdim /// clauses that this landingpad will have (use 0 if you really have no idea). 2205249259Sdim static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn, 2206249259Sdim unsigned NumReservedClauses, 2207249259Sdim const Twine &NameStr = "", 2208249259Sdim Instruction *InsertBefore = 0); 2209249259Sdim static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn, 2210249259Sdim unsigned NumReservedClauses, 2211249259Sdim const Twine &NameStr, BasicBlock *InsertAtEnd); 2212249259Sdim ~LandingPadInst(); 2213249259Sdim 2214249259Sdim /// Provide fast operand accessors 2215249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 2216249259Sdim 2217249259Sdim /// getPersonalityFn - Get the personality function associated with this 2218249259Sdim /// landing pad. 2219249259Sdim Value *getPersonalityFn() const { return getOperand(0); } 2220249259Sdim 2221249259Sdim /// isCleanup - Return 'true' if this landingpad instruction is a 2222249259Sdim /// cleanup. I.e., it should be run when unwinding even if its landing pad 2223249259Sdim /// doesn't catch the exception. 2224249259Sdim bool isCleanup() const { return getSubclassDataFromInstruction() & 1; } 2225249259Sdim 2226249259Sdim /// setCleanup - Indicate that this landingpad instruction is a cleanup. 2227249259Sdim void setCleanup(bool V) { 2228249259Sdim setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | 2229249259Sdim (V ? 1 : 0)); 2230249259Sdim } 2231249259Sdim 2232249259Sdim /// addClause - Add a catch or filter clause to the landing pad. 2233249259Sdim void addClause(Value *ClauseVal); 2234249259Sdim 2235249259Sdim /// getClause - Get the value of the clause at index Idx. Use isCatch/isFilter 2236249259Sdim /// to determine what type of clause this is. 2237249259Sdim Value *getClause(unsigned Idx) const { return OperandList[Idx + 1]; } 2238249259Sdim 2239249259Sdim /// isCatch - Return 'true' if the clause and index Idx is a catch clause. 2240249259Sdim bool isCatch(unsigned Idx) const { 2241249259Sdim return !isa<ArrayType>(OperandList[Idx + 1]->getType()); 2242249259Sdim } 2243249259Sdim 2244249259Sdim /// isFilter - Return 'true' if the clause and index Idx is a filter clause. 2245249259Sdim bool isFilter(unsigned Idx) const { 2246249259Sdim return isa<ArrayType>(OperandList[Idx + 1]->getType()); 2247249259Sdim } 2248249259Sdim 2249249259Sdim /// getNumClauses - Get the number of clauses for this landing pad. 2250249259Sdim unsigned getNumClauses() const { return getNumOperands() - 1; } 2251249259Sdim 2252249259Sdim /// reserveClauses - Grow the size of the operand list to accommodate the new 2253249259Sdim /// number of clauses. 2254249259Sdim void reserveClauses(unsigned Size) { growOperands(Size); } 2255249259Sdim 2256249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 2257249259Sdim static inline bool classof(const Instruction *I) { 2258249259Sdim return I->getOpcode() == Instruction::LandingPad; 2259249259Sdim } 2260249259Sdim static inline bool classof(const Value *V) { 2261249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 2262249259Sdim } 2263249259Sdim}; 2264249259Sdim 2265249259Sdimtemplate <> 2266249259Sdimstruct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> { 2267249259Sdim}; 2268249259Sdim 2269249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value) 2270249259Sdim 2271249259Sdim//===----------------------------------------------------------------------===// 2272249259Sdim// ReturnInst Class 2273249259Sdim//===----------------------------------------------------------------------===// 2274249259Sdim 2275249259Sdim//===--------------------------------------------------------------------------- 2276249259Sdim/// ReturnInst - Return a value (possibly void), from a function. Execution 2277249259Sdim/// does not continue in this function any longer. 2278249259Sdim/// 2279249259Sdimclass ReturnInst : public TerminatorInst { 2280249259Sdim ReturnInst(const ReturnInst &RI); 2281249259Sdim 2282249259Sdimprivate: 2283249259Sdim // ReturnInst constructors: 2284249259Sdim // ReturnInst() - 'ret void' instruction 2285249259Sdim // ReturnInst( null) - 'ret void' instruction 2286249259Sdim // ReturnInst(Value* X) - 'ret X' instruction 2287249259Sdim // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I 2288249259Sdim // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I 2289249259Sdim // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B 2290249259Sdim // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B 2291249259Sdim // 2292249259Sdim // NOTE: If the Value* passed is of type void then the constructor behaves as 2293249259Sdim // if it was passed NULL. 2294249259Sdim explicit ReturnInst(LLVMContext &C, Value *retVal = 0, 2295249259Sdim Instruction *InsertBefore = 0); 2296249259Sdim ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd); 2297249259Sdim explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd); 2298249259Sdimprotected: 2299249259Sdim virtual ReturnInst *clone_impl() const; 2300249259Sdimpublic: 2301249259Sdim static ReturnInst* Create(LLVMContext &C, Value *retVal = 0, 2302249259Sdim Instruction *InsertBefore = 0) { 2303249259Sdim return new(!!retVal) ReturnInst(C, retVal, InsertBefore); 2304249259Sdim } 2305249259Sdim static ReturnInst* Create(LLVMContext &C, Value *retVal, 2306249259Sdim BasicBlock *InsertAtEnd) { 2307249259Sdim return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd); 2308249259Sdim } 2309249259Sdim static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) { 2310249259Sdim return new(0) ReturnInst(C, InsertAtEnd); 2311249259Sdim } 2312249259Sdim virtual ~ReturnInst(); 2313249259Sdim 2314249259Sdim /// Provide fast operand accessors 2315249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 2316249259Sdim 2317249259Sdim /// Convenience accessor. Returns null if there is no return value. 2318249259Sdim Value *getReturnValue() const { 2319249259Sdim return getNumOperands() != 0 ? getOperand(0) : 0; 2320249259Sdim } 2321249259Sdim 2322249259Sdim unsigned getNumSuccessors() const { return 0; } 2323249259Sdim 2324249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 2325249259Sdim static inline bool classof(const Instruction *I) { 2326249259Sdim return (I->getOpcode() == Instruction::Ret); 2327249259Sdim } 2328249259Sdim static inline bool classof(const Value *V) { 2329249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 2330249259Sdim } 2331249259Sdim private: 2332249259Sdim virtual BasicBlock *getSuccessorV(unsigned idx) const; 2333249259Sdim virtual unsigned getNumSuccessorsV() const; 2334249259Sdim virtual void setSuccessorV(unsigned idx, BasicBlock *B); 2335249259Sdim}; 2336249259Sdim 2337249259Sdimtemplate <> 2338249259Sdimstruct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> { 2339249259Sdim}; 2340249259Sdim 2341249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value) 2342249259Sdim 2343249259Sdim//===----------------------------------------------------------------------===// 2344249259Sdim// BranchInst Class 2345249259Sdim//===----------------------------------------------------------------------===// 2346249259Sdim 2347249259Sdim//===--------------------------------------------------------------------------- 2348249259Sdim/// BranchInst - Conditional or Unconditional Branch instruction. 2349249259Sdim/// 2350249259Sdimclass BranchInst : public TerminatorInst { 2351249259Sdim /// Ops list - Branches are strange. The operands are ordered: 2352249259Sdim /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because 2353249259Sdim /// they don't have to check for cond/uncond branchness. These are mostly 2354249259Sdim /// accessed relative from op_end(). 2355249259Sdim BranchInst(const BranchInst &BI); 2356249259Sdim void AssertOK(); 2357249259Sdim // BranchInst constructors (where {B, T, F} are blocks, and C is a condition): 2358249259Sdim // BranchInst(BB *B) - 'br B' 2359249259Sdim // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F' 2360249259Sdim // BranchInst(BB* B, Inst *I) - 'br B' insert before I 2361249259Sdim // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I 2362249259Sdim // BranchInst(BB* B, BB *I) - 'br B' insert at end 2363249259Sdim // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end 2364249259Sdim explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0); 2365249259Sdim BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, 2366249259Sdim Instruction *InsertBefore = 0); 2367249259Sdim BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd); 2368249259Sdim BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, 2369249259Sdim BasicBlock *InsertAtEnd); 2370249259Sdimprotected: 2371249259Sdim virtual BranchInst *clone_impl() const; 2372249259Sdimpublic: 2373249259Sdim static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) { 2374249259Sdim return new(1) BranchInst(IfTrue, InsertBefore); 2375249259Sdim } 2376249259Sdim static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, 2377249259Sdim Value *Cond, Instruction *InsertBefore = 0) { 2378249259Sdim return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore); 2379249259Sdim } 2380249259Sdim static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) { 2381249259Sdim return new(1) BranchInst(IfTrue, InsertAtEnd); 2382249259Sdim } 2383249259Sdim static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, 2384249259Sdim Value *Cond, BasicBlock *InsertAtEnd) { 2385249259Sdim return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd); 2386249259Sdim } 2387249259Sdim 2388249259Sdim /// Transparently provide more efficient getOperand methods. 2389249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 2390249259Sdim 2391249259Sdim bool isUnconditional() const { return getNumOperands() == 1; } 2392249259Sdim bool isConditional() const { return getNumOperands() == 3; } 2393249259Sdim 2394249259Sdim Value *getCondition() const { 2395249259Sdim assert(isConditional() && "Cannot get condition of an uncond branch!"); 2396249259Sdim return Op<-3>(); 2397249259Sdim } 2398249259Sdim 2399249259Sdim void setCondition(Value *V) { 2400249259Sdim assert(isConditional() && "Cannot set condition of unconditional branch!"); 2401249259Sdim Op<-3>() = V; 2402249259Sdim } 2403249259Sdim 2404249259Sdim unsigned getNumSuccessors() const { return 1+isConditional(); } 2405249259Sdim 2406249259Sdim BasicBlock *getSuccessor(unsigned i) const { 2407249259Sdim assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); 2408249259Sdim return cast_or_null<BasicBlock>((&Op<-1>() - i)->get()); 2409249259Sdim } 2410249259Sdim 2411249259Sdim void setSuccessor(unsigned idx, BasicBlock *NewSucc) { 2412249259Sdim assert(idx < getNumSuccessors() && "Successor # out of range for Branch!"); 2413249259Sdim *(&Op<-1>() - idx) = (Value*)NewSucc; 2414249259Sdim } 2415249259Sdim 2416249259Sdim /// \brief Swap the successors of this branch instruction. 2417249259Sdim /// 2418249259Sdim /// Swaps the successors of the branch instruction. This also swaps any 2419249259Sdim /// branch weight metadata associated with the instruction so that it 2420249259Sdim /// continues to map correctly to each operand. 2421249259Sdim void swapSuccessors(); 2422249259Sdim 2423249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 2424249259Sdim static inline bool classof(const Instruction *I) { 2425249259Sdim return (I->getOpcode() == Instruction::Br); 2426249259Sdim } 2427249259Sdim static inline bool classof(const Value *V) { 2428249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 2429249259Sdim } 2430249259Sdimprivate: 2431249259Sdim virtual BasicBlock *getSuccessorV(unsigned idx) const; 2432249259Sdim virtual unsigned getNumSuccessorsV() const; 2433249259Sdim virtual void setSuccessorV(unsigned idx, BasicBlock *B); 2434249259Sdim}; 2435249259Sdim 2436249259Sdimtemplate <> 2437249259Sdimstruct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> { 2438249259Sdim}; 2439249259Sdim 2440249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value) 2441249259Sdim 2442249259Sdim//===----------------------------------------------------------------------===// 2443249259Sdim// SwitchInst Class 2444249259Sdim//===----------------------------------------------------------------------===// 2445249259Sdim 2446249259Sdim//===--------------------------------------------------------------------------- 2447249259Sdim/// SwitchInst - Multiway switch 2448249259Sdim/// 2449249259Sdimclass SwitchInst : public TerminatorInst { 2450249259Sdim void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 2451249259Sdim unsigned ReservedSpace; 2452249259Sdim // Operand[0] = Value to switch on 2453249259Sdim // Operand[1] = Default basic block destination 2454249259Sdim // Operand[2n ] = Value to match 2455249259Sdim // Operand[2n+1] = BasicBlock to go to on match 2456249259Sdim SwitchInst(const SwitchInst &SI); 2457249259Sdim void init(Value *Value, BasicBlock *Default, unsigned NumReserved); 2458249259Sdim void growOperands(); 2459249259Sdim // allocate space for exactly zero operands 2460249259Sdim void *operator new(size_t s) { 2461249259Sdim return User::operator new(s, 0); 2462249259Sdim } 2463249259Sdim /// SwitchInst ctor - Create a new switch instruction, specifying a value to 2464249259Sdim /// switch on and a default destination. The number of additional cases can 2465249259Sdim /// be specified here to make memory allocation more efficient. This 2466249259Sdim /// constructor can also autoinsert before another instruction. 2467249259Sdim SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, 2468249259Sdim Instruction *InsertBefore); 2469249259Sdim 2470249259Sdim /// SwitchInst ctor - Create a new switch instruction, specifying a value to 2471249259Sdim /// switch on and a default destination. The number of additional cases can 2472249259Sdim /// be specified here to make memory allocation more efficient. This 2473249259Sdim /// constructor also autoinserts at the end of the specified BasicBlock. 2474249259Sdim SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, 2475249259Sdim BasicBlock *InsertAtEnd); 2476249259Sdimprotected: 2477249259Sdim virtual SwitchInst *clone_impl() const; 2478249259Sdimpublic: 2479249259Sdim 2480249259Sdim // -2 2481249259Sdim static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1); 2482249259Sdim 2483263508Sdim template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy> 2484263508Sdim class CaseIteratorT { 2485263508Sdim protected: 2486263508Sdim 2487263508Sdim SwitchInstTy *SI; 2488263508Sdim unsigned Index; 2489263508Sdim 2490263508Sdim public: 2491263508Sdim 2492263508Sdim typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self; 2493263508Sdim 2494263508Sdim /// Initializes case iterator for given SwitchInst and for given 2495263508Sdim /// case number. 2496263508Sdim CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) { 2497263508Sdim this->SI = SI; 2498263508Sdim Index = CaseNum; 2499263508Sdim } 2500263508Sdim 2501263508Sdim /// Initializes case iterator for given SwitchInst and for given 2502263508Sdim /// TerminatorInst's successor index. 2503263508Sdim static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) { 2504263508Sdim assert(SuccessorIndex < SI->getNumSuccessors() && 2505263508Sdim "Successor index # out of range!"); 2506263508Sdim return SuccessorIndex != 0 ? 2507263508Sdim Self(SI, SuccessorIndex - 1) : 2508263508Sdim Self(SI, DefaultPseudoIndex); 2509263508Sdim } 2510263508Sdim 2511263508Sdim /// Resolves case value for current case. 2512263508Sdim ConstantIntTy *getCaseValue() { 2513263508Sdim assert(Index < SI->getNumCases() && "Index out the number of cases."); 2514263508Sdim return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2)); 2515263508Sdim } 2516263508Sdim 2517263508Sdim /// Resolves successor for current case. 2518263508Sdim BasicBlockTy *getCaseSuccessor() { 2519263508Sdim assert((Index < SI->getNumCases() || 2520263508Sdim Index == DefaultPseudoIndex) && 2521263508Sdim "Index out the number of cases."); 2522263508Sdim return SI->getSuccessor(getSuccessorIndex()); 2523263508Sdim } 2524263508Sdim 2525263508Sdim /// Returns number of current case. 2526263508Sdim unsigned getCaseIndex() const { return Index; } 2527263508Sdim 2528263508Sdim /// Returns TerminatorInst's successor index for current case successor. 2529263508Sdim unsigned getSuccessorIndex() const { 2530263508Sdim assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) && 2531263508Sdim "Index out the number of cases."); 2532263508Sdim return Index != DefaultPseudoIndex ? Index + 1 : 0; 2533263508Sdim } 2534263508Sdim 2535263508Sdim Self operator++() { 2536263508Sdim // Check index correctness after increment. 2537263508Sdim // Note: Index == getNumCases() means end(). 2538263508Sdim assert(Index+1 <= SI->getNumCases() && "Index out the number of cases."); 2539263508Sdim ++Index; 2540263508Sdim return *this; 2541263508Sdim } 2542263508Sdim Self operator++(int) { 2543263508Sdim Self tmp = *this; 2544263508Sdim ++(*this); 2545263508Sdim return tmp; 2546263508Sdim } 2547263508Sdim Self operator--() { 2548263508Sdim // Check index correctness after decrement. 2549263508Sdim // Note: Index == getNumCases() means end(). 2550263508Sdim // Also allow "-1" iterator here. That will became valid after ++. 2551263508Sdim assert((Index == 0 || Index-1 <= SI->getNumCases()) && 2552263508Sdim "Index out the number of cases."); 2553263508Sdim --Index; 2554263508Sdim return *this; 2555263508Sdim } 2556263508Sdim Self operator--(int) { 2557263508Sdim Self tmp = *this; 2558263508Sdim --(*this); 2559263508Sdim return tmp; 2560263508Sdim } 2561263508Sdim bool operator==(const Self& RHS) const { 2562263508Sdim assert(RHS.SI == SI && "Incompatible operators."); 2563263508Sdim return RHS.Index == Index; 2564263508Sdim } 2565263508Sdim bool operator!=(const Self& RHS) const { 2566263508Sdim assert(RHS.SI == SI && "Incompatible operators."); 2567263508Sdim return RHS.Index != Index; 2568263508Sdim } 2569263508Sdim }; 2570263508Sdim 2571263508Sdim typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock> 2572263508Sdim ConstCaseIt; 2573263508Sdim 2574263508Sdim class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> { 2575263508Sdim 2576263508Sdim typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy; 2577263508Sdim 2578263508Sdim public: 2579263508Sdim 2580263508Sdim CaseIt(const ParentTy& Src) : ParentTy(Src) {} 2581263508Sdim CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {} 2582263508Sdim 2583263508Sdim /// Sets the new value for current case. 2584263508Sdim void setValue(ConstantInt *V) { 2585263508Sdim assert(Index < SI->getNumCases() && "Index out the number of cases."); 2586263508Sdim SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V)); 2587263508Sdim } 2588263508Sdim 2589263508Sdim /// Sets the new successor for current case. 2590263508Sdim void setSuccessor(BasicBlock *S) { 2591263508Sdim SI->setSuccessor(getSuccessorIndex(), S); 2592263508Sdim } 2593263508Sdim }; 2594263508Sdim 2595249259Sdim static SwitchInst *Create(Value *Value, BasicBlock *Default, 2596249259Sdim unsigned NumCases, Instruction *InsertBefore = 0) { 2597249259Sdim return new SwitchInst(Value, Default, NumCases, InsertBefore); 2598249259Sdim } 2599249259Sdim static SwitchInst *Create(Value *Value, BasicBlock *Default, 2600249259Sdim unsigned NumCases, BasicBlock *InsertAtEnd) { 2601249259Sdim return new SwitchInst(Value, Default, NumCases, InsertAtEnd); 2602249259Sdim } 2603249259Sdim 2604249259Sdim ~SwitchInst(); 2605249259Sdim 2606249259Sdim /// Provide fast operand accessors 2607249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 2608249259Sdim 2609249259Sdim // Accessor Methods for Switch stmt 2610249259Sdim Value *getCondition() const { return getOperand(0); } 2611249259Sdim void setCondition(Value *V) { setOperand(0, V); } 2612249259Sdim 2613249259Sdim BasicBlock *getDefaultDest() const { 2614249259Sdim return cast<BasicBlock>(getOperand(1)); 2615249259Sdim } 2616249259Sdim 2617249259Sdim void setDefaultDest(BasicBlock *DefaultCase) { 2618249259Sdim setOperand(1, reinterpret_cast<Value*>(DefaultCase)); 2619249259Sdim } 2620249259Sdim 2621249259Sdim /// getNumCases - return the number of 'cases' in this switch instruction, 2622249259Sdim /// except the default case 2623249259Sdim unsigned getNumCases() const { 2624249259Sdim return getNumOperands()/2 - 1; 2625249259Sdim } 2626249259Sdim 2627249259Sdim /// Returns a read/write iterator that points to the first 2628249259Sdim /// case in SwitchInst. 2629249259Sdim CaseIt case_begin() { 2630263508Sdim return CaseIt(this, 0); 2631249259Sdim } 2632249259Sdim /// Returns a read-only iterator that points to the first 2633249259Sdim /// case in the SwitchInst. 2634249259Sdim ConstCaseIt case_begin() const { 2635263508Sdim return ConstCaseIt(this, 0); 2636249259Sdim } 2637249259Sdim 2638249259Sdim /// Returns a read/write iterator that points one past the last 2639249259Sdim /// in the SwitchInst. 2640249259Sdim CaseIt case_end() { 2641263508Sdim return CaseIt(this, getNumCases()); 2642249259Sdim } 2643249259Sdim /// Returns a read-only iterator that points one past the last 2644249259Sdim /// in the SwitchInst. 2645249259Sdim ConstCaseIt case_end() const { 2646263508Sdim return ConstCaseIt(this, getNumCases()); 2647249259Sdim } 2648249259Sdim /// Returns an iterator that points to the default case. 2649249259Sdim /// Note: this iterator allows to resolve successor only. Attempt 2650249259Sdim /// to resolve case value causes an assertion. 2651249259Sdim /// Also note, that increment and decrement also causes an assertion and 2652249259Sdim /// makes iterator invalid. 2653249259Sdim CaseIt case_default() { 2654263508Sdim return CaseIt(this, DefaultPseudoIndex); 2655249259Sdim } 2656249259Sdim ConstCaseIt case_default() const { 2657263508Sdim return ConstCaseIt(this, DefaultPseudoIndex); 2658249259Sdim } 2659249259Sdim 2660249259Sdim /// findCaseValue - Search all of the case values for the specified constant. 2661249259Sdim /// If it is explicitly handled, return the case iterator of it, otherwise 2662249259Sdim /// return default case iterator to indicate 2663249259Sdim /// that it is handled by the default handler. 2664249259Sdim CaseIt findCaseValue(const ConstantInt *C) { 2665249259Sdim for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) 2666263508Sdim if (i.getCaseValue() == C) 2667249259Sdim return i; 2668249259Sdim return case_default(); 2669249259Sdim } 2670249259Sdim ConstCaseIt findCaseValue(const ConstantInt *C) const { 2671249259Sdim for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i) 2672263508Sdim if (i.getCaseValue() == C) 2673249259Sdim return i; 2674249259Sdim return case_default(); 2675249259Sdim } 2676249259Sdim 2677249259Sdim /// findCaseDest - Finds the unique case value for a given successor. Returns 2678249259Sdim /// null if the successor is not found, not unique, or is the default case. 2679249259Sdim ConstantInt *findCaseDest(BasicBlock *BB) { 2680249259Sdim if (BB == getDefaultDest()) return NULL; 2681249259Sdim 2682249259Sdim ConstantInt *CI = NULL; 2683249259Sdim for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) { 2684249259Sdim if (i.getCaseSuccessor() == BB) { 2685249259Sdim if (CI) return NULL; // Multiple cases lead to BB. 2686249259Sdim else CI = i.getCaseValue(); 2687249259Sdim } 2688249259Sdim } 2689249259Sdim return CI; 2690249259Sdim } 2691249259Sdim 2692249259Sdim /// addCase - Add an entry to the switch instruction... 2693249259Sdim /// Note: 2694249259Sdim /// This action invalidates case_end(). Old case_end() iterator will 2695249259Sdim /// point to the added case. 2696249259Sdim void addCase(ConstantInt *OnVal, BasicBlock *Dest); 2697249259Sdim 2698249259Sdim /// removeCase - This method removes the specified case and its successor 2699249259Sdim /// from the switch instruction. Note that this operation may reorder the 2700249259Sdim /// remaining cases at index idx and above. 2701249259Sdim /// Note: 2702249259Sdim /// This action invalidates iterators for all cases following the one removed, 2703249259Sdim /// including the case_end() iterator. 2704263508Sdim void removeCase(CaseIt i); 2705249259Sdim 2706249259Sdim unsigned getNumSuccessors() const { return getNumOperands()/2; } 2707249259Sdim BasicBlock *getSuccessor(unsigned idx) const { 2708249259Sdim assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!"); 2709249259Sdim return cast<BasicBlock>(getOperand(idx*2+1)); 2710249259Sdim } 2711249259Sdim void setSuccessor(unsigned idx, BasicBlock *NewSucc) { 2712249259Sdim assert(idx < getNumSuccessors() && "Successor # out of range for switch!"); 2713249259Sdim setOperand(idx*2+1, (Value*)NewSucc); 2714249259Sdim } 2715249259Sdim 2716249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 2717249259Sdim static inline bool classof(const Instruction *I) { 2718249259Sdim return I->getOpcode() == Instruction::Switch; 2719249259Sdim } 2720249259Sdim static inline bool classof(const Value *V) { 2721249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 2722249259Sdim } 2723249259Sdimprivate: 2724249259Sdim virtual BasicBlock *getSuccessorV(unsigned idx) const; 2725249259Sdim virtual unsigned getNumSuccessorsV() const; 2726249259Sdim virtual void setSuccessorV(unsigned idx, BasicBlock *B); 2727249259Sdim}; 2728249259Sdim 2729249259Sdimtemplate <> 2730249259Sdimstruct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> { 2731249259Sdim}; 2732249259Sdim 2733249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value) 2734249259Sdim 2735249259Sdim 2736249259Sdim//===----------------------------------------------------------------------===// 2737249259Sdim// IndirectBrInst Class 2738249259Sdim//===----------------------------------------------------------------------===// 2739249259Sdim 2740249259Sdim//===--------------------------------------------------------------------------- 2741249259Sdim/// IndirectBrInst - Indirect Branch Instruction. 2742249259Sdim/// 2743249259Sdimclass IndirectBrInst : public TerminatorInst { 2744249259Sdim void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 2745249259Sdim unsigned ReservedSpace; 2746249259Sdim // Operand[0] = Value to switch on 2747249259Sdim // Operand[1] = Default basic block destination 2748249259Sdim // Operand[2n ] = Value to match 2749249259Sdim // Operand[2n+1] = BasicBlock to go to on match 2750249259Sdim IndirectBrInst(const IndirectBrInst &IBI); 2751249259Sdim void init(Value *Address, unsigned NumDests); 2752249259Sdim void growOperands(); 2753249259Sdim // allocate space for exactly zero operands 2754249259Sdim void *operator new(size_t s) { 2755249259Sdim return User::operator new(s, 0); 2756249259Sdim } 2757249259Sdim /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an 2758249259Sdim /// Address to jump to. The number of expected destinations can be specified 2759249259Sdim /// here to make memory allocation more efficient. This constructor can also 2760249259Sdim /// autoinsert before another instruction. 2761249259Sdim IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore); 2762249259Sdim 2763249259Sdim /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an 2764249259Sdim /// Address to jump to. The number of expected destinations can be specified 2765249259Sdim /// here to make memory allocation more efficient. This constructor also 2766249259Sdim /// autoinserts at the end of the specified BasicBlock. 2767249259Sdim IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd); 2768249259Sdimprotected: 2769249259Sdim virtual IndirectBrInst *clone_impl() const; 2770249259Sdimpublic: 2771249259Sdim static IndirectBrInst *Create(Value *Address, unsigned NumDests, 2772249259Sdim Instruction *InsertBefore = 0) { 2773249259Sdim return new IndirectBrInst(Address, NumDests, InsertBefore); 2774249259Sdim } 2775249259Sdim static IndirectBrInst *Create(Value *Address, unsigned NumDests, 2776249259Sdim BasicBlock *InsertAtEnd) { 2777249259Sdim return new IndirectBrInst(Address, NumDests, InsertAtEnd); 2778249259Sdim } 2779249259Sdim ~IndirectBrInst(); 2780249259Sdim 2781249259Sdim /// Provide fast operand accessors. 2782249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 2783249259Sdim 2784249259Sdim // Accessor Methods for IndirectBrInst instruction. 2785249259Sdim Value *getAddress() { return getOperand(0); } 2786249259Sdim const Value *getAddress() const { return getOperand(0); } 2787249259Sdim void setAddress(Value *V) { setOperand(0, V); } 2788249259Sdim 2789249259Sdim 2790249259Sdim /// getNumDestinations - return the number of possible destinations in this 2791249259Sdim /// indirectbr instruction. 2792249259Sdim unsigned getNumDestinations() const { return getNumOperands()-1; } 2793249259Sdim 2794249259Sdim /// getDestination - Return the specified destination. 2795249259Sdim BasicBlock *getDestination(unsigned i) { return getSuccessor(i); } 2796249259Sdim const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); } 2797249259Sdim 2798249259Sdim /// addDestination - Add a destination. 2799249259Sdim /// 2800249259Sdim void addDestination(BasicBlock *Dest); 2801249259Sdim 2802249259Sdim /// removeDestination - This method removes the specified successor from the 2803249259Sdim /// indirectbr instruction. 2804249259Sdim void removeDestination(unsigned i); 2805249259Sdim 2806249259Sdim unsigned getNumSuccessors() const { return getNumOperands()-1; } 2807249259Sdim BasicBlock *getSuccessor(unsigned i) const { 2808249259Sdim return cast<BasicBlock>(getOperand(i+1)); 2809249259Sdim } 2810249259Sdim void setSuccessor(unsigned i, BasicBlock *NewSucc) { 2811249259Sdim setOperand(i+1, (Value*)NewSucc); 2812249259Sdim } 2813249259Sdim 2814249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 2815249259Sdim static inline bool classof(const Instruction *I) { 2816249259Sdim return I->getOpcode() == Instruction::IndirectBr; 2817249259Sdim } 2818249259Sdim static inline bool classof(const Value *V) { 2819249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 2820249259Sdim } 2821249259Sdimprivate: 2822249259Sdim virtual BasicBlock *getSuccessorV(unsigned idx) const; 2823249259Sdim virtual unsigned getNumSuccessorsV() const; 2824249259Sdim virtual void setSuccessorV(unsigned idx, BasicBlock *B); 2825249259Sdim}; 2826249259Sdim 2827249259Sdimtemplate <> 2828249259Sdimstruct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> { 2829249259Sdim}; 2830249259Sdim 2831249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value) 2832249259Sdim 2833249259Sdim 2834249259Sdim//===----------------------------------------------------------------------===// 2835249259Sdim// InvokeInst Class 2836249259Sdim//===----------------------------------------------------------------------===// 2837249259Sdim 2838249259Sdim/// InvokeInst - Invoke instruction. The SubclassData field is used to hold the 2839249259Sdim/// calling convention of the call. 2840249259Sdim/// 2841249259Sdimclass InvokeInst : public TerminatorInst { 2842249259Sdim AttributeSet AttributeList; 2843249259Sdim InvokeInst(const InvokeInst &BI); 2844249259Sdim void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, 2845249259Sdim ArrayRef<Value *> Args, const Twine &NameStr); 2846249259Sdim 2847249259Sdim /// Construct an InvokeInst given a range of arguments. 2848249259Sdim /// 2849249259Sdim /// \brief Construct an InvokeInst from a range of arguments 2850249259Sdim inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, 2851249259Sdim ArrayRef<Value *> Args, unsigned Values, 2852249259Sdim const Twine &NameStr, Instruction *InsertBefore); 2853249259Sdim 2854249259Sdim /// Construct an InvokeInst given a range of arguments. 2855249259Sdim /// 2856249259Sdim /// \brief Construct an InvokeInst from a range of arguments 2857249259Sdim inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, 2858249259Sdim ArrayRef<Value *> Args, unsigned Values, 2859249259Sdim const Twine &NameStr, BasicBlock *InsertAtEnd); 2860249259Sdimprotected: 2861249259Sdim virtual InvokeInst *clone_impl() const; 2862249259Sdimpublic: 2863249259Sdim static InvokeInst *Create(Value *Func, 2864249259Sdim BasicBlock *IfNormal, BasicBlock *IfException, 2865249259Sdim ArrayRef<Value *> Args, const Twine &NameStr = "", 2866249259Sdim Instruction *InsertBefore = 0) { 2867249259Sdim unsigned Values = unsigned(Args.size()) + 3; 2868249259Sdim return new(Values) InvokeInst(Func, IfNormal, IfException, Args, 2869249259Sdim Values, NameStr, InsertBefore); 2870249259Sdim } 2871249259Sdim static InvokeInst *Create(Value *Func, 2872249259Sdim BasicBlock *IfNormal, BasicBlock *IfException, 2873249259Sdim ArrayRef<Value *> Args, const Twine &NameStr, 2874249259Sdim BasicBlock *InsertAtEnd) { 2875249259Sdim unsigned Values = unsigned(Args.size()) + 3; 2876249259Sdim return new(Values) InvokeInst(Func, IfNormal, IfException, Args, 2877249259Sdim Values, NameStr, InsertAtEnd); 2878249259Sdim } 2879249259Sdim 2880249259Sdim /// Provide fast operand accessors 2881249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 2882249259Sdim 2883249259Sdim /// getNumArgOperands - Return the number of invoke arguments. 2884249259Sdim /// 2885249259Sdim unsigned getNumArgOperands() const { return getNumOperands() - 3; } 2886249259Sdim 2887249259Sdim /// getArgOperand/setArgOperand - Return/set the i-th invoke argument. 2888249259Sdim /// 2889249259Sdim Value *getArgOperand(unsigned i) const { return getOperand(i); } 2890249259Sdim void setArgOperand(unsigned i, Value *v) { setOperand(i, v); } 2891249259Sdim 2892249259Sdim /// getCallingConv/setCallingConv - Get or set the calling convention of this 2893249259Sdim /// function call. 2894249259Sdim CallingConv::ID getCallingConv() const { 2895249259Sdim return static_cast<CallingConv::ID>(getSubclassDataFromInstruction()); 2896249259Sdim } 2897249259Sdim void setCallingConv(CallingConv::ID CC) { 2898249259Sdim setInstructionSubclassData(static_cast<unsigned>(CC)); 2899249259Sdim } 2900249259Sdim 2901249259Sdim /// getAttributes - Return the parameter attributes for this invoke. 2902249259Sdim /// 2903249259Sdim const AttributeSet &getAttributes() const { return AttributeList; } 2904249259Sdim 2905249259Sdim /// setAttributes - Set the parameter attributes for this invoke. 2906249259Sdim /// 2907249259Sdim void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; } 2908249259Sdim 2909249259Sdim /// addAttribute - adds the attribute to the list of attributes. 2910249259Sdim void addAttribute(unsigned i, Attribute::AttrKind attr); 2911249259Sdim 2912249259Sdim /// removeAttribute - removes the attribute from the list of attributes. 2913249259Sdim void removeAttribute(unsigned i, Attribute attr); 2914249259Sdim 2915263508Sdim /// \brief Determine whether this call has the given attribute. 2916263508Sdim bool hasFnAttr(Attribute::AttrKind A) const { 2917263508Sdim assert(A != Attribute::NoBuiltin && 2918263508Sdim "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin"); 2919263508Sdim return hasFnAttrImpl(A); 2920263508Sdim } 2921249259Sdim 2922249259Sdim /// \brief Determine whether the call or the callee has the given attributes. 2923249259Sdim bool paramHasAttr(unsigned i, Attribute::AttrKind A) const; 2924249259Sdim 2925249259Sdim /// \brief Extract the alignment for a call or parameter (0=unknown). 2926249259Sdim unsigned getParamAlignment(unsigned i) const { 2927249259Sdim return AttributeList.getParamAlignment(i); 2928249259Sdim } 2929249259Sdim 2930263508Sdim /// \brief Return true if the call should not be treated as a call to a 2931263508Sdim /// builtin. 2932263508Sdim bool isNoBuiltin() const { 2933263508Sdim // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have 2934263508Sdim // to check it by hand. 2935263508Sdim return hasFnAttrImpl(Attribute::NoBuiltin) && 2936263508Sdim !hasFnAttrImpl(Attribute::Builtin); 2937263508Sdim } 2938263508Sdim 2939249259Sdim /// \brief Return true if the call should not be inlined. 2940249259Sdim bool isNoInline() const { return hasFnAttr(Attribute::NoInline); } 2941249259Sdim void setIsNoInline() { 2942249259Sdim addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline); 2943249259Sdim } 2944249259Sdim 2945249259Sdim /// \brief Determine if the call does not access memory. 2946249259Sdim bool doesNotAccessMemory() const { 2947249259Sdim return hasFnAttr(Attribute::ReadNone); 2948249259Sdim } 2949249259Sdim void setDoesNotAccessMemory() { 2950249259Sdim addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone); 2951249259Sdim } 2952249259Sdim 2953249259Sdim /// \brief Determine if the call does not access or only reads memory. 2954249259Sdim bool onlyReadsMemory() const { 2955249259Sdim return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly); 2956249259Sdim } 2957249259Sdim void setOnlyReadsMemory() { 2958249259Sdim addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly); 2959249259Sdim } 2960249259Sdim 2961249259Sdim /// \brief Determine if the call cannot return. 2962249259Sdim bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); } 2963249259Sdim void setDoesNotReturn() { 2964249259Sdim addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn); 2965249259Sdim } 2966249259Sdim 2967249259Sdim /// \brief Determine if the call cannot unwind. 2968249259Sdim bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); } 2969249259Sdim void setDoesNotThrow() { 2970249259Sdim addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind); 2971249259Sdim } 2972249259Sdim 2973249259Sdim /// \brief Determine if the call returns a structure through first 2974249259Sdim /// pointer argument. 2975249259Sdim bool hasStructRetAttr() const { 2976249259Sdim // Be friendly and also check the callee. 2977249259Sdim return paramHasAttr(1, Attribute::StructRet); 2978249259Sdim } 2979249259Sdim 2980249259Sdim /// \brief Determine if any call argument is an aggregate passed by value. 2981249259Sdim bool hasByValArgument() const { 2982249259Sdim return AttributeList.hasAttrSomewhere(Attribute::ByVal); 2983249259Sdim } 2984249259Sdim 2985249259Sdim /// getCalledFunction - Return the function called, or null if this is an 2986249259Sdim /// indirect function invocation. 2987249259Sdim /// 2988249259Sdim Function *getCalledFunction() const { 2989249259Sdim return dyn_cast<Function>(Op<-3>()); 2990249259Sdim } 2991249259Sdim 2992249259Sdim /// getCalledValue - Get a pointer to the function that is invoked by this 2993249259Sdim /// instruction 2994249259Sdim const Value *getCalledValue() const { return Op<-3>(); } 2995249259Sdim Value *getCalledValue() { return Op<-3>(); } 2996249259Sdim 2997249259Sdim /// setCalledFunction - Set the function called. 2998249259Sdim void setCalledFunction(Value* Fn) { 2999249259Sdim Op<-3>() = Fn; 3000249259Sdim } 3001249259Sdim 3002249259Sdim // get*Dest - Return the destination basic blocks... 3003249259Sdim BasicBlock *getNormalDest() const { 3004249259Sdim return cast<BasicBlock>(Op<-2>()); 3005249259Sdim } 3006249259Sdim BasicBlock *getUnwindDest() const { 3007249259Sdim return cast<BasicBlock>(Op<-1>()); 3008249259Sdim } 3009249259Sdim void setNormalDest(BasicBlock *B) { 3010249259Sdim Op<-2>() = reinterpret_cast<Value*>(B); 3011249259Sdim } 3012249259Sdim void setUnwindDest(BasicBlock *B) { 3013249259Sdim Op<-1>() = reinterpret_cast<Value*>(B); 3014249259Sdim } 3015249259Sdim 3016249259Sdim /// getLandingPadInst - Get the landingpad instruction from the landing pad 3017249259Sdim /// block (the unwind destination). 3018249259Sdim LandingPadInst *getLandingPadInst() const; 3019249259Sdim 3020249259Sdim BasicBlock *getSuccessor(unsigned i) const { 3021249259Sdim assert(i < 2 && "Successor # out of range for invoke!"); 3022249259Sdim return i == 0 ? getNormalDest() : getUnwindDest(); 3023249259Sdim } 3024249259Sdim 3025249259Sdim void setSuccessor(unsigned idx, BasicBlock *NewSucc) { 3026249259Sdim assert(idx < 2 && "Successor # out of range for invoke!"); 3027249259Sdim *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc); 3028249259Sdim } 3029249259Sdim 3030249259Sdim unsigned getNumSuccessors() const { return 2; } 3031249259Sdim 3032249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 3033249259Sdim static inline bool classof(const Instruction *I) { 3034249259Sdim return (I->getOpcode() == Instruction::Invoke); 3035249259Sdim } 3036249259Sdim static inline bool classof(const Value *V) { 3037249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3038249259Sdim } 3039249259Sdim 3040249259Sdimprivate: 3041249259Sdim virtual BasicBlock *getSuccessorV(unsigned idx) const; 3042249259Sdim virtual unsigned getNumSuccessorsV() const; 3043249259Sdim virtual void setSuccessorV(unsigned idx, BasicBlock *B); 3044249259Sdim 3045263508Sdim bool hasFnAttrImpl(Attribute::AttrKind A) const; 3046263508Sdim 3047249259Sdim // Shadow Instruction::setInstructionSubclassData with a private forwarding 3048249259Sdim // method so that subclasses cannot accidentally use it. 3049249259Sdim void setInstructionSubclassData(unsigned short D) { 3050249259Sdim Instruction::setInstructionSubclassData(D); 3051249259Sdim } 3052249259Sdim}; 3053249259Sdim 3054249259Sdimtemplate <> 3055249259Sdimstruct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> { 3056249259Sdim}; 3057249259Sdim 3058249259SdimInvokeInst::InvokeInst(Value *Func, 3059249259Sdim BasicBlock *IfNormal, BasicBlock *IfException, 3060249259Sdim ArrayRef<Value *> Args, unsigned Values, 3061249259Sdim const Twine &NameStr, Instruction *InsertBefore) 3062249259Sdim : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) 3063249259Sdim ->getElementType())->getReturnType(), 3064249259Sdim Instruction::Invoke, 3065249259Sdim OperandTraits<InvokeInst>::op_end(this) - Values, 3066249259Sdim Values, InsertBefore) { 3067249259Sdim init(Func, IfNormal, IfException, Args, NameStr); 3068249259Sdim} 3069249259SdimInvokeInst::InvokeInst(Value *Func, 3070249259Sdim BasicBlock *IfNormal, BasicBlock *IfException, 3071249259Sdim ArrayRef<Value *> Args, unsigned Values, 3072249259Sdim const Twine &NameStr, BasicBlock *InsertAtEnd) 3073249259Sdim : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) 3074249259Sdim ->getElementType())->getReturnType(), 3075249259Sdim Instruction::Invoke, 3076249259Sdim OperandTraits<InvokeInst>::op_end(this) - Values, 3077249259Sdim Values, InsertAtEnd) { 3078249259Sdim init(Func, IfNormal, IfException, Args, NameStr); 3079249259Sdim} 3080249259Sdim 3081249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value) 3082249259Sdim 3083249259Sdim//===----------------------------------------------------------------------===// 3084249259Sdim// ResumeInst Class 3085249259Sdim//===----------------------------------------------------------------------===// 3086249259Sdim 3087249259Sdim//===--------------------------------------------------------------------------- 3088249259Sdim/// ResumeInst - Resume the propagation of an exception. 3089249259Sdim/// 3090249259Sdimclass ResumeInst : public TerminatorInst { 3091249259Sdim ResumeInst(const ResumeInst &RI); 3092249259Sdim 3093249259Sdim explicit ResumeInst(Value *Exn, Instruction *InsertBefore=0); 3094249259Sdim ResumeInst(Value *Exn, BasicBlock *InsertAtEnd); 3095249259Sdimprotected: 3096249259Sdim virtual ResumeInst *clone_impl() const; 3097249259Sdimpublic: 3098249259Sdim static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = 0) { 3099249259Sdim return new(1) ResumeInst(Exn, InsertBefore); 3100249259Sdim } 3101249259Sdim static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) { 3102249259Sdim return new(1) ResumeInst(Exn, InsertAtEnd); 3103249259Sdim } 3104249259Sdim 3105249259Sdim /// Provide fast operand accessors 3106249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 3107249259Sdim 3108249259Sdim /// Convenience accessor. 3109249259Sdim Value *getValue() const { return Op<0>(); } 3110249259Sdim 3111249259Sdim unsigned getNumSuccessors() const { return 0; } 3112249259Sdim 3113249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 3114249259Sdim static inline bool classof(const Instruction *I) { 3115249259Sdim return I->getOpcode() == Instruction::Resume; 3116249259Sdim } 3117249259Sdim static inline bool classof(const Value *V) { 3118249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3119249259Sdim } 3120249259Sdimprivate: 3121249259Sdim virtual BasicBlock *getSuccessorV(unsigned idx) const; 3122249259Sdim virtual unsigned getNumSuccessorsV() const; 3123249259Sdim virtual void setSuccessorV(unsigned idx, BasicBlock *B); 3124249259Sdim}; 3125249259Sdim 3126249259Sdimtemplate <> 3127249259Sdimstruct OperandTraits<ResumeInst> : 3128249259Sdim public FixedNumOperandTraits<ResumeInst, 1> { 3129249259Sdim}; 3130249259Sdim 3131249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value) 3132249259Sdim 3133249259Sdim//===----------------------------------------------------------------------===// 3134249259Sdim// UnreachableInst Class 3135249259Sdim//===----------------------------------------------------------------------===// 3136249259Sdim 3137249259Sdim//===--------------------------------------------------------------------------- 3138249259Sdim/// UnreachableInst - This function has undefined behavior. In particular, the 3139249259Sdim/// presence of this instruction indicates some higher level knowledge that the 3140249259Sdim/// end of the block cannot be reached. 3141249259Sdim/// 3142249259Sdimclass UnreachableInst : public TerminatorInst { 3143249259Sdim void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 3144249259Sdimprotected: 3145249259Sdim virtual UnreachableInst *clone_impl() const; 3146249259Sdim 3147249259Sdimpublic: 3148249259Sdim // allocate space for exactly zero operands 3149249259Sdim void *operator new(size_t s) { 3150249259Sdim return User::operator new(s, 0); 3151249259Sdim } 3152249259Sdim explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0); 3153249259Sdim explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd); 3154249259Sdim 3155249259Sdim unsigned getNumSuccessors() const { return 0; } 3156249259Sdim 3157249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 3158249259Sdim static inline bool classof(const Instruction *I) { 3159249259Sdim return I->getOpcode() == Instruction::Unreachable; 3160249259Sdim } 3161249259Sdim static inline bool classof(const Value *V) { 3162249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3163249259Sdim } 3164249259Sdimprivate: 3165249259Sdim virtual BasicBlock *getSuccessorV(unsigned idx) const; 3166249259Sdim virtual unsigned getNumSuccessorsV() const; 3167249259Sdim virtual void setSuccessorV(unsigned idx, BasicBlock *B); 3168249259Sdim}; 3169249259Sdim 3170249259Sdim//===----------------------------------------------------------------------===// 3171249259Sdim// TruncInst Class 3172249259Sdim//===----------------------------------------------------------------------===// 3173249259Sdim 3174249259Sdim/// \brief This class represents a truncation of integer types. 3175249259Sdimclass TruncInst : public CastInst { 3176249259Sdimprotected: 3177249259Sdim /// \brief Clone an identical TruncInst 3178249259Sdim virtual TruncInst *clone_impl() const; 3179249259Sdim 3180249259Sdimpublic: 3181249259Sdim /// \brief Constructor with insert-before-instruction semantics 3182249259Sdim TruncInst( 3183249259Sdim Value *S, ///< The value to be truncated 3184249259Sdim Type *Ty, ///< The (smaller) type to truncate to 3185249259Sdim const Twine &NameStr = "", ///< A name for the new instruction 3186249259Sdim Instruction *InsertBefore = 0 ///< Where to insert the new instruction 3187249259Sdim ); 3188249259Sdim 3189249259Sdim /// \brief Constructor with insert-at-end-of-block semantics 3190249259Sdim TruncInst( 3191249259Sdim Value *S, ///< The value to be truncated 3192249259Sdim Type *Ty, ///< The (smaller) type to truncate to 3193249259Sdim const Twine &NameStr, ///< A name for the new instruction 3194249259Sdim BasicBlock *InsertAtEnd ///< The block to insert the instruction into 3195249259Sdim ); 3196249259Sdim 3197249259Sdim /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 3198249259Sdim static inline bool classof(const Instruction *I) { 3199249259Sdim return I->getOpcode() == Trunc; 3200249259Sdim } 3201249259Sdim static inline bool classof(const Value *V) { 3202249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3203249259Sdim } 3204249259Sdim}; 3205249259Sdim 3206249259Sdim//===----------------------------------------------------------------------===// 3207249259Sdim// ZExtInst Class 3208249259Sdim//===----------------------------------------------------------------------===// 3209249259Sdim 3210249259Sdim/// \brief This class represents zero extension of integer types. 3211249259Sdimclass ZExtInst : public CastInst { 3212249259Sdimprotected: 3213249259Sdim /// \brief Clone an identical ZExtInst 3214249259Sdim virtual ZExtInst *clone_impl() const; 3215249259Sdim 3216249259Sdimpublic: 3217249259Sdim /// \brief Constructor with insert-before-instruction semantics 3218249259Sdim ZExtInst( 3219249259Sdim Value *S, ///< The value to be zero extended 3220249259Sdim Type *Ty, ///< The type to zero extend to 3221249259Sdim const Twine &NameStr = "", ///< A name for the new instruction 3222249259Sdim Instruction *InsertBefore = 0 ///< Where to insert the new instruction 3223249259Sdim ); 3224249259Sdim 3225249259Sdim /// \brief Constructor with insert-at-end semantics. 3226249259Sdim ZExtInst( 3227249259Sdim Value *S, ///< The value to be zero extended 3228249259Sdim Type *Ty, ///< The type to zero extend to 3229249259Sdim const Twine &NameStr, ///< A name for the new instruction 3230249259Sdim BasicBlock *InsertAtEnd ///< The block to insert the instruction into 3231249259Sdim ); 3232249259Sdim 3233249259Sdim /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 3234249259Sdim static inline bool classof(const Instruction *I) { 3235249259Sdim return I->getOpcode() == ZExt; 3236249259Sdim } 3237249259Sdim static inline bool classof(const Value *V) { 3238249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3239249259Sdim } 3240249259Sdim}; 3241249259Sdim 3242249259Sdim//===----------------------------------------------------------------------===// 3243249259Sdim// SExtInst Class 3244249259Sdim//===----------------------------------------------------------------------===// 3245249259Sdim 3246249259Sdim/// \brief This class represents a sign extension of integer types. 3247249259Sdimclass SExtInst : public CastInst { 3248249259Sdimprotected: 3249249259Sdim /// \brief Clone an identical SExtInst 3250249259Sdim virtual SExtInst *clone_impl() const; 3251249259Sdim 3252249259Sdimpublic: 3253249259Sdim /// \brief Constructor with insert-before-instruction semantics 3254249259Sdim SExtInst( 3255249259Sdim Value *S, ///< The value to be sign extended 3256249259Sdim Type *Ty, ///< The type to sign extend to 3257249259Sdim const Twine &NameStr = "", ///< A name for the new instruction 3258249259Sdim Instruction *InsertBefore = 0 ///< Where to insert the new instruction 3259249259Sdim ); 3260249259Sdim 3261249259Sdim /// \brief Constructor with insert-at-end-of-block semantics 3262249259Sdim SExtInst( 3263249259Sdim Value *S, ///< The value to be sign extended 3264249259Sdim Type *Ty, ///< The type to sign extend to 3265249259Sdim const Twine &NameStr, ///< A name for the new instruction 3266249259Sdim BasicBlock *InsertAtEnd ///< The block to insert the instruction into 3267249259Sdim ); 3268249259Sdim 3269249259Sdim /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 3270249259Sdim static inline bool classof(const Instruction *I) { 3271249259Sdim return I->getOpcode() == SExt; 3272249259Sdim } 3273249259Sdim static inline bool classof(const Value *V) { 3274249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3275249259Sdim } 3276249259Sdim}; 3277249259Sdim 3278249259Sdim//===----------------------------------------------------------------------===// 3279249259Sdim// FPTruncInst Class 3280249259Sdim//===----------------------------------------------------------------------===// 3281249259Sdim 3282249259Sdim/// \brief This class represents a truncation of floating point types. 3283249259Sdimclass FPTruncInst : public CastInst { 3284249259Sdimprotected: 3285249259Sdim /// \brief Clone an identical FPTruncInst 3286249259Sdim virtual FPTruncInst *clone_impl() const; 3287249259Sdim 3288249259Sdimpublic: 3289249259Sdim /// \brief Constructor with insert-before-instruction semantics 3290249259Sdim FPTruncInst( 3291249259Sdim Value *S, ///< The value to be truncated 3292249259Sdim Type *Ty, ///< The type to truncate to 3293249259Sdim const Twine &NameStr = "", ///< A name for the new instruction 3294249259Sdim Instruction *InsertBefore = 0 ///< Where to insert the new instruction 3295249259Sdim ); 3296249259Sdim 3297249259Sdim /// \brief Constructor with insert-before-instruction semantics 3298249259Sdim FPTruncInst( 3299249259Sdim Value *S, ///< The value to be truncated 3300249259Sdim Type *Ty, ///< The type to truncate to 3301249259Sdim const Twine &NameStr, ///< A name for the new instruction 3302249259Sdim BasicBlock *InsertAtEnd ///< The block to insert the instruction into 3303249259Sdim ); 3304249259Sdim 3305249259Sdim /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 3306249259Sdim static inline bool classof(const Instruction *I) { 3307249259Sdim return I->getOpcode() == FPTrunc; 3308249259Sdim } 3309249259Sdim static inline bool classof(const Value *V) { 3310249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3311249259Sdim } 3312249259Sdim}; 3313249259Sdim 3314249259Sdim//===----------------------------------------------------------------------===// 3315249259Sdim// FPExtInst Class 3316249259Sdim//===----------------------------------------------------------------------===// 3317249259Sdim 3318249259Sdim/// \brief This class represents an extension of floating point types. 3319249259Sdimclass FPExtInst : public CastInst { 3320249259Sdimprotected: 3321249259Sdim /// \brief Clone an identical FPExtInst 3322249259Sdim virtual FPExtInst *clone_impl() const; 3323249259Sdim 3324249259Sdimpublic: 3325249259Sdim /// \brief Constructor with insert-before-instruction semantics 3326249259Sdim FPExtInst( 3327249259Sdim Value *S, ///< The value to be extended 3328249259Sdim Type *Ty, ///< The type to extend to 3329249259Sdim const Twine &NameStr = "", ///< A name for the new instruction 3330249259Sdim Instruction *InsertBefore = 0 ///< Where to insert the new instruction 3331249259Sdim ); 3332249259Sdim 3333249259Sdim /// \brief Constructor with insert-at-end-of-block semantics 3334249259Sdim FPExtInst( 3335249259Sdim Value *S, ///< The value to be extended 3336249259Sdim Type *Ty, ///< The type to extend to 3337249259Sdim const Twine &NameStr, ///< A name for the new instruction 3338249259Sdim BasicBlock *InsertAtEnd ///< The block to insert the instruction into 3339249259Sdim ); 3340249259Sdim 3341249259Sdim /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 3342249259Sdim static inline bool classof(const Instruction *I) { 3343249259Sdim return I->getOpcode() == FPExt; 3344249259Sdim } 3345249259Sdim static inline bool classof(const Value *V) { 3346249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3347249259Sdim } 3348249259Sdim}; 3349249259Sdim 3350249259Sdim//===----------------------------------------------------------------------===// 3351249259Sdim// UIToFPInst Class 3352249259Sdim//===----------------------------------------------------------------------===// 3353249259Sdim 3354249259Sdim/// \brief This class represents a cast unsigned integer to floating point. 3355249259Sdimclass UIToFPInst : public CastInst { 3356249259Sdimprotected: 3357249259Sdim /// \brief Clone an identical UIToFPInst 3358249259Sdim virtual UIToFPInst *clone_impl() const; 3359249259Sdim 3360249259Sdimpublic: 3361249259Sdim /// \brief Constructor with insert-before-instruction semantics 3362249259Sdim UIToFPInst( 3363249259Sdim Value *S, ///< The value to be converted 3364249259Sdim Type *Ty, ///< The type to convert to 3365249259Sdim const Twine &NameStr = "", ///< A name for the new instruction 3366249259Sdim Instruction *InsertBefore = 0 ///< Where to insert the new instruction 3367249259Sdim ); 3368249259Sdim 3369249259Sdim /// \brief Constructor with insert-at-end-of-block semantics 3370249259Sdim UIToFPInst( 3371249259Sdim Value *S, ///< The value to be converted 3372249259Sdim Type *Ty, ///< The type to convert to 3373249259Sdim const Twine &NameStr, ///< A name for the new instruction 3374249259Sdim BasicBlock *InsertAtEnd ///< The block to insert the instruction into 3375249259Sdim ); 3376249259Sdim 3377249259Sdim /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 3378249259Sdim static inline bool classof(const Instruction *I) { 3379249259Sdim return I->getOpcode() == UIToFP; 3380249259Sdim } 3381249259Sdim static inline bool classof(const Value *V) { 3382249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3383249259Sdim } 3384249259Sdim}; 3385249259Sdim 3386249259Sdim//===----------------------------------------------------------------------===// 3387249259Sdim// SIToFPInst Class 3388249259Sdim//===----------------------------------------------------------------------===// 3389249259Sdim 3390249259Sdim/// \brief This class represents a cast from signed integer to floating point. 3391249259Sdimclass SIToFPInst : public CastInst { 3392249259Sdimprotected: 3393249259Sdim /// \brief Clone an identical SIToFPInst 3394249259Sdim virtual SIToFPInst *clone_impl() const; 3395249259Sdim 3396249259Sdimpublic: 3397249259Sdim /// \brief Constructor with insert-before-instruction semantics 3398249259Sdim SIToFPInst( 3399249259Sdim Value *S, ///< The value to be converted 3400249259Sdim Type *Ty, ///< The type to convert to 3401249259Sdim const Twine &NameStr = "", ///< A name for the new instruction 3402249259Sdim Instruction *InsertBefore = 0 ///< Where to insert the new instruction 3403249259Sdim ); 3404249259Sdim 3405249259Sdim /// \brief Constructor with insert-at-end-of-block semantics 3406249259Sdim SIToFPInst( 3407249259Sdim Value *S, ///< The value to be converted 3408249259Sdim Type *Ty, ///< The type to convert to 3409249259Sdim const Twine &NameStr, ///< A name for the new instruction 3410249259Sdim BasicBlock *InsertAtEnd ///< The block to insert the instruction into 3411249259Sdim ); 3412249259Sdim 3413249259Sdim /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 3414249259Sdim static inline bool classof(const Instruction *I) { 3415249259Sdim return I->getOpcode() == SIToFP; 3416249259Sdim } 3417249259Sdim static inline bool classof(const Value *V) { 3418249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3419249259Sdim } 3420249259Sdim}; 3421249259Sdim 3422249259Sdim//===----------------------------------------------------------------------===// 3423249259Sdim// FPToUIInst Class 3424249259Sdim//===----------------------------------------------------------------------===// 3425249259Sdim 3426249259Sdim/// \brief This class represents a cast from floating point to unsigned integer 3427249259Sdimclass FPToUIInst : public CastInst { 3428249259Sdimprotected: 3429249259Sdim /// \brief Clone an identical FPToUIInst 3430249259Sdim virtual FPToUIInst *clone_impl() const; 3431249259Sdim 3432249259Sdimpublic: 3433249259Sdim /// \brief Constructor with insert-before-instruction semantics 3434249259Sdim FPToUIInst( 3435249259Sdim Value *S, ///< The value to be converted 3436249259Sdim Type *Ty, ///< The type to convert to 3437249259Sdim const Twine &NameStr = "", ///< A name for the new instruction 3438249259Sdim Instruction *InsertBefore = 0 ///< Where to insert the new instruction 3439249259Sdim ); 3440249259Sdim 3441249259Sdim /// \brief Constructor with insert-at-end-of-block semantics 3442249259Sdim FPToUIInst( 3443249259Sdim Value *S, ///< The value to be converted 3444249259Sdim Type *Ty, ///< The type to convert to 3445249259Sdim const Twine &NameStr, ///< A name for the new instruction 3446249259Sdim BasicBlock *InsertAtEnd ///< Where to insert the new instruction 3447249259Sdim ); 3448249259Sdim 3449249259Sdim /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 3450249259Sdim static inline bool classof(const Instruction *I) { 3451249259Sdim return I->getOpcode() == FPToUI; 3452249259Sdim } 3453249259Sdim static inline bool classof(const Value *V) { 3454249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3455249259Sdim } 3456249259Sdim}; 3457249259Sdim 3458249259Sdim//===----------------------------------------------------------------------===// 3459249259Sdim// FPToSIInst Class 3460249259Sdim//===----------------------------------------------------------------------===// 3461249259Sdim 3462249259Sdim/// \brief This class represents a cast from floating point to signed integer. 3463249259Sdimclass FPToSIInst : public CastInst { 3464249259Sdimprotected: 3465249259Sdim /// \brief Clone an identical FPToSIInst 3466249259Sdim virtual FPToSIInst *clone_impl() const; 3467249259Sdim 3468249259Sdimpublic: 3469249259Sdim /// \brief Constructor with insert-before-instruction semantics 3470249259Sdim FPToSIInst( 3471249259Sdim Value *S, ///< The value to be converted 3472249259Sdim Type *Ty, ///< The type to convert to 3473249259Sdim const Twine &NameStr = "", ///< A name for the new instruction 3474249259Sdim Instruction *InsertBefore = 0 ///< Where to insert the new instruction 3475249259Sdim ); 3476249259Sdim 3477249259Sdim /// \brief Constructor with insert-at-end-of-block semantics 3478249259Sdim FPToSIInst( 3479249259Sdim Value *S, ///< The value to be converted 3480249259Sdim Type *Ty, ///< The type to convert to 3481249259Sdim const Twine &NameStr, ///< A name for the new instruction 3482249259Sdim BasicBlock *InsertAtEnd ///< The block to insert the instruction into 3483249259Sdim ); 3484249259Sdim 3485249259Sdim /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: 3486249259Sdim static inline bool classof(const Instruction *I) { 3487249259Sdim return I->getOpcode() == FPToSI; 3488249259Sdim } 3489249259Sdim static inline bool classof(const Value *V) { 3490249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3491249259Sdim } 3492249259Sdim}; 3493249259Sdim 3494249259Sdim//===----------------------------------------------------------------------===// 3495249259Sdim// IntToPtrInst Class 3496249259Sdim//===----------------------------------------------------------------------===// 3497249259Sdim 3498249259Sdim/// \brief This class represents a cast from an integer to a pointer. 3499249259Sdimclass IntToPtrInst : public CastInst { 3500249259Sdimpublic: 3501249259Sdim /// \brief Constructor with insert-before-instruction semantics 3502249259Sdim IntToPtrInst( 3503249259Sdim Value *S, ///< The value to be converted 3504249259Sdim Type *Ty, ///< The type to convert to 3505249259Sdim const Twine &NameStr = "", ///< A name for the new instruction 3506249259Sdim Instruction *InsertBefore = 0 ///< Where to insert the new instruction 3507249259Sdim ); 3508249259Sdim 3509249259Sdim /// \brief Constructor with insert-at-end-of-block semantics 3510249259Sdim IntToPtrInst( 3511249259Sdim Value *S, ///< The value to be converted 3512249259Sdim Type *Ty, ///< The type to convert to 3513249259Sdim const Twine &NameStr, ///< A name for the new instruction 3514249259Sdim BasicBlock *InsertAtEnd ///< The block to insert the instruction into 3515249259Sdim ); 3516249259Sdim 3517249259Sdim /// \brief Clone an identical IntToPtrInst 3518249259Sdim virtual IntToPtrInst *clone_impl() const; 3519249259Sdim 3520249259Sdim /// \brief Returns the address space of this instruction's pointer type. 3521249259Sdim unsigned getAddressSpace() const { 3522249259Sdim return getType()->getPointerAddressSpace(); 3523249259Sdim } 3524249259Sdim 3525249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 3526249259Sdim static inline bool classof(const Instruction *I) { 3527249259Sdim return I->getOpcode() == IntToPtr; 3528249259Sdim } 3529249259Sdim static inline bool classof(const Value *V) { 3530249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3531249259Sdim } 3532249259Sdim}; 3533249259Sdim 3534249259Sdim//===----------------------------------------------------------------------===// 3535249259Sdim// PtrToIntInst Class 3536249259Sdim//===----------------------------------------------------------------------===// 3537249259Sdim 3538249259Sdim/// \brief This class represents a cast from a pointer to an integer 3539249259Sdimclass PtrToIntInst : public CastInst { 3540249259Sdimprotected: 3541249259Sdim /// \brief Clone an identical PtrToIntInst 3542249259Sdim virtual PtrToIntInst *clone_impl() const; 3543249259Sdim 3544249259Sdimpublic: 3545249259Sdim /// \brief Constructor with insert-before-instruction semantics 3546249259Sdim PtrToIntInst( 3547249259Sdim Value *S, ///< The value to be converted 3548249259Sdim Type *Ty, ///< The type to convert to 3549249259Sdim const Twine &NameStr = "", ///< A name for the new instruction 3550249259Sdim Instruction *InsertBefore = 0 ///< Where to insert the new instruction 3551249259Sdim ); 3552249259Sdim 3553249259Sdim /// \brief Constructor with insert-at-end-of-block semantics 3554249259Sdim PtrToIntInst( 3555249259Sdim Value *S, ///< The value to be converted 3556249259Sdim Type *Ty, ///< The type to convert to 3557249259Sdim const Twine &NameStr, ///< A name for the new instruction 3558249259Sdim BasicBlock *InsertAtEnd ///< The block to insert the instruction into 3559249259Sdim ); 3560249259Sdim 3561249259Sdim /// \brief Gets the pointer operand. 3562249259Sdim Value *getPointerOperand() { return getOperand(0); } 3563249259Sdim /// \brief Gets the pointer operand. 3564249259Sdim const Value *getPointerOperand() const { return getOperand(0); } 3565249259Sdim /// \brief Gets the operand index of the pointer operand. 3566249259Sdim static unsigned getPointerOperandIndex() { return 0U; } 3567249259Sdim 3568249259Sdim /// \brief Returns the address space of the pointer operand. 3569249259Sdim unsigned getPointerAddressSpace() const { 3570249259Sdim return getPointerOperand()->getType()->getPointerAddressSpace(); 3571249259Sdim } 3572249259Sdim 3573249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 3574249259Sdim static inline bool classof(const Instruction *I) { 3575249259Sdim return I->getOpcode() == PtrToInt; 3576249259Sdim } 3577249259Sdim static inline bool classof(const Value *V) { 3578249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3579249259Sdim } 3580249259Sdim}; 3581249259Sdim 3582249259Sdim//===----------------------------------------------------------------------===// 3583249259Sdim// BitCastInst Class 3584249259Sdim//===----------------------------------------------------------------------===// 3585249259Sdim 3586249259Sdim/// \brief This class represents a no-op cast from one type to another. 3587249259Sdimclass BitCastInst : public CastInst { 3588249259Sdimprotected: 3589249259Sdim /// \brief Clone an identical BitCastInst 3590249259Sdim virtual BitCastInst *clone_impl() const; 3591249259Sdim 3592249259Sdimpublic: 3593249259Sdim /// \brief Constructor with insert-before-instruction semantics 3594249259Sdim BitCastInst( 3595249259Sdim Value *S, ///< The value to be casted 3596249259Sdim Type *Ty, ///< The type to casted to 3597249259Sdim const Twine &NameStr = "", ///< A name for the new instruction 3598249259Sdim Instruction *InsertBefore = 0 ///< Where to insert the new instruction 3599249259Sdim ); 3600249259Sdim 3601249259Sdim /// \brief Constructor with insert-at-end-of-block semantics 3602249259Sdim BitCastInst( 3603249259Sdim Value *S, ///< The value to be casted 3604249259Sdim Type *Ty, ///< The type to casted to 3605249259Sdim const Twine &NameStr, ///< A name for the new instruction 3606249259Sdim BasicBlock *InsertAtEnd ///< The block to insert the instruction into 3607249259Sdim ); 3608249259Sdim 3609249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 3610249259Sdim static inline bool classof(const Instruction *I) { 3611249259Sdim return I->getOpcode() == BitCast; 3612249259Sdim } 3613249259Sdim static inline bool classof(const Value *V) { 3614249259Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3615249259Sdim } 3616249259Sdim}; 3617249259Sdim 3618263508Sdim//===----------------------------------------------------------------------===// 3619263508Sdim// AddrSpaceCastInst Class 3620263508Sdim//===----------------------------------------------------------------------===// 3621263508Sdim 3622263508Sdim/// \brief This class represents a conversion between pointers from 3623263508Sdim/// one address space to another. 3624263508Sdimclass AddrSpaceCastInst : public CastInst { 3625263508Sdimprotected: 3626263508Sdim /// \brief Clone an identical AddrSpaceCastInst 3627263508Sdim virtual AddrSpaceCastInst *clone_impl() const; 3628263508Sdim 3629263508Sdimpublic: 3630263508Sdim /// \brief Constructor with insert-before-instruction semantics 3631263508Sdim AddrSpaceCastInst( 3632263508Sdim Value *S, ///< The value to be casted 3633263508Sdim Type *Ty, ///< The type to casted to 3634263508Sdim const Twine &NameStr = "", ///< A name for the new instruction 3635263508Sdim Instruction *InsertBefore = 0 ///< Where to insert the new instruction 3636263508Sdim ); 3637263508Sdim 3638263508Sdim /// \brief Constructor with insert-at-end-of-block semantics 3639263508Sdim AddrSpaceCastInst( 3640263508Sdim Value *S, ///< The value to be casted 3641263508Sdim Type *Ty, ///< The type to casted to 3642263508Sdim const Twine &NameStr, ///< A name for the new instruction 3643263508Sdim BasicBlock *InsertAtEnd ///< The block to insert the instruction into 3644263508Sdim ); 3645263508Sdim 3646263508Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 3647263508Sdim static inline bool classof(const Instruction *I) { 3648263508Sdim return I->getOpcode() == AddrSpaceCast; 3649263508Sdim } 3650263508Sdim static inline bool classof(const Value *V) { 3651263508Sdim return isa<Instruction>(V) && classof(cast<Instruction>(V)); 3652263508Sdim } 3653263508Sdim}; 3654263508Sdim 3655249259Sdim} // End llvm namespace 3656249259Sdim 3657249259Sdim#endif 3658