#ifndef LLVM_IR_INSTRUCTIONS_H
#define LLVM_IR_INSTRUCTIONS_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/IntegersSubset.h"
#include "llvm/Support/IntegersSubsetMapping.h"
#include <iterator>
namespace llvm {
class APInt;
class ConstantInt;
class ConstantRange;
class DataLayout;
class LLVMContext;
enum AtomicOrdering {
NotAtomic = 0,
Unordered = 1,
Monotonic = 2,
Acquire = 4,
Release = 5,
AcquireRelease = 6,
SequentiallyConsistent = 7
};
enum SynchronizationScope {
SingleThread = 0,
CrossThread = 1
};
class AllocaInst : public UnaryInstruction {
protected:
virtual AllocaInst *clone_impl() const;
public:
explicit AllocaInst(Type *Ty, Value *ArraySize = 0,
const Twine &Name = "", Instruction *InsertBefore = 0);
AllocaInst(Type *Ty, Value *ArraySize,
const Twine &Name, BasicBlock *InsertAtEnd);
AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
const Twine &Name = "", Instruction *InsertBefore = 0);
AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
const Twine &Name, BasicBlock *InsertAtEnd);
virtual ~AllocaInst();
bool isArrayAllocation() const;
const Value *getArraySize() const { return getOperand(0); }
Value *getArraySize() { return getOperand(0); }
PointerType *getType() const {
return reinterpret_cast<PointerType*>(Instruction::getType());
}
Type *getAllocatedType() const;
unsigned getAlignment() const {
return (1u << getSubclassDataFromInstruction()) >> 1;
}
void setAlignment(unsigned Align);
bool isStaticAlloca() const;
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::Alloca);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
void setInstructionSubclassData(unsigned short D) {
Instruction::setInstructionSubclassData(D);
}
};
class LoadInst : public UnaryInstruction {
void AssertOK();
protected:
virtual LoadInst *clone_impl() const;
public:
LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
Instruction *InsertBefore = 0);
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
BasicBlock *InsertAtEnd);
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
unsigned Align, Instruction *InsertBefore = 0);
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
unsigned Align, BasicBlock *InsertAtEnd);
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
unsigned Align, AtomicOrdering Order,
SynchronizationScope SynchScope = CrossThread,
Instruction *InsertBefore = 0);
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
unsigned Align, AtomicOrdering Order,
SynchronizationScope SynchScope,
BasicBlock *InsertAtEnd);
LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
explicit LoadInst(Value *Ptr, const char *NameStr = 0,
bool isVolatile = false, Instruction *InsertBefore = 0);
LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
BasicBlock *InsertAtEnd);
bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
void setVolatile(bool V) {
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
(V ? 1 : 0));
}
unsigned getAlignment() const {
return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
}
void setAlignment(unsigned Align);
AtomicOrdering getOrdering() const {
return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
}
void setOrdering(AtomicOrdering Ordering) {
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
(Ordering << 7));
}
SynchronizationScope getSynchScope() const {
return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
}
void setSynchScope(SynchronizationScope xthread) {
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
(xthread << 6));
}
bool isAtomic() const { return getOrdering() != NotAtomic; }
void setAtomic(AtomicOrdering Ordering,
SynchronizationScope SynchScope = CrossThread) {
setOrdering(Ordering);
setSynchScope(SynchScope);
}
bool isSimple() const { return !isAtomic() && !isVolatile(); }
bool isUnordered() const {
return getOrdering() <= Unordered && !isVolatile();
}
Value *getPointerOperand() { return getOperand(0); }
const Value *getPointerOperand() const { return getOperand(0); }
static unsigned getPointerOperandIndex() { return 0U; }
unsigned getPointerAddressSpace() const {
return getPointerOperand()->getType()->getPointerAddressSpace();
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::Load;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
void setInstructionSubclassData(unsigned short D) {
Instruction::setInstructionSubclassData(D);
}
};
class StoreInst : public Instruction {
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
void AssertOK();
protected:
virtual StoreInst *clone_impl() const;
public:
void *operator new(size_t s) {
return User::operator new(s, 2);
}
StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
Instruction *InsertBefore = 0);
StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
unsigned Align, Instruction *InsertBefore = 0);
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
unsigned Align, BasicBlock *InsertAtEnd);
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
unsigned Align, AtomicOrdering Order,
SynchronizationScope SynchScope = CrossThread,
Instruction *InsertBefore = 0);
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
unsigned Align, AtomicOrdering Order,
SynchronizationScope SynchScope,
BasicBlock *InsertAtEnd);
bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
void setVolatile(bool V) {
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
(V ? 1 : 0));
}
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
unsigned getAlignment() const {
return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
}
void setAlignment(unsigned Align);
AtomicOrdering getOrdering() const {
return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
}
void setOrdering(AtomicOrdering Ordering) {
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
(Ordering << 7));
}
SynchronizationScope getSynchScope() const {
return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
}
void setSynchScope(SynchronizationScope xthread) {
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
(xthread << 6));
}
bool isAtomic() const { return getOrdering() != NotAtomic; }
void setAtomic(AtomicOrdering Ordering,
SynchronizationScope SynchScope = CrossThread) {
setOrdering(Ordering);
setSynchScope(SynchScope);
}
bool isSimple() const { return !isAtomic() && !isVolatile(); }
bool isUnordered() const {
return getOrdering() <= Unordered && !isVolatile();
}
Value *getValueOperand() { return getOperand(0); }
const Value *getValueOperand() const { return getOperand(0); }
Value *getPointerOperand() { return getOperand(1); }
const Value *getPointerOperand() const { return getOperand(1); }
static unsigned getPointerOperandIndex() { return 1U; }
unsigned getPointerAddressSpace() const {
return getPointerOperand()->getType()->getPointerAddressSpace();
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::Store;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
void setInstructionSubclassData(unsigned short D) {
Instruction::setInstructionSubclassData(D);
}
};
template <>
struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
class FenceInst : public Instruction {
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
protected:
virtual FenceInst *clone_impl() const;
public:
void *operator new(size_t s) {
return User::operator new(s, 0);
}
FenceInst(LLVMContext &C, AtomicOrdering Ordering,
SynchronizationScope SynchScope = CrossThread,
Instruction *InsertBefore = 0);
FenceInst(LLVMContext &C, AtomicOrdering Ordering,
SynchronizationScope SynchScope,
BasicBlock *InsertAtEnd);
AtomicOrdering getOrdering() const {
return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
}
void setOrdering(AtomicOrdering Ordering) {
setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
(Ordering << 1));
}
SynchronizationScope getSynchScope() const {
return SynchronizationScope(getSubclassDataFromInstruction() & 1);
}
void setSynchScope(SynchronizationScope xthread) {
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
xthread);
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::Fence;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
void setInstructionSubclassData(unsigned short D) {
Instruction::setInstructionSubclassData(D);
}
};
class AtomicCmpXchgInst : public Instruction {
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
void Init(Value *Ptr, Value *Cmp, Value *NewVal,
AtomicOrdering Ordering, SynchronizationScope SynchScope);
protected:
virtual AtomicCmpXchgInst *clone_impl() const;
public:
void *operator new(size_t s) {
return User::operator new(s, 3);
}
AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
AtomicOrdering Ordering, SynchronizationScope SynchScope,
Instruction *InsertBefore = 0);
AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
AtomicOrdering Ordering, SynchronizationScope SynchScope,
BasicBlock *InsertAtEnd);
bool isVolatile() const {
return getSubclassDataFromInstruction() & 1;
}
void setVolatile(bool V) {
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
(unsigned)V);
}
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
void setOrdering(AtomicOrdering Ordering) {
assert(Ordering != NotAtomic &&
"CmpXchg instructions can only be atomic.");
setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
(Ordering << 2));
}
void setSynchScope(SynchronizationScope SynchScope) {
setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
(SynchScope << 1));
}
AtomicOrdering getOrdering() const {
return AtomicOrdering(getSubclassDataFromInstruction() >> 2);
}
SynchronizationScope getSynchScope() const {
return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
}
Value *getPointerOperand() { return getOperand(0); }
const Value *getPointerOperand() const { return getOperand(0); }
static unsigned getPointerOperandIndex() { return 0U; }
Value *getCompareOperand() { return getOperand(1); }
const Value *getCompareOperand() const { return getOperand(1); }
Value *getNewValOperand() { return getOperand(2); }
const Value *getNewValOperand() const { return getOperand(2); }
unsigned getPointerAddressSpace() const {
return getPointerOperand()->getType()->getPointerAddressSpace();
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::AtomicCmpXchg;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
void setInstructionSubclassData(unsigned short D) {
Instruction::setInstructionSubclassData(D);
}
};
template <>
struct OperandTraits<AtomicCmpXchgInst> :
public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
class AtomicRMWInst : public Instruction {
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
protected:
virtual AtomicRMWInst *clone_impl() const;
public:
enum BinOp {
Xchg,
Add,
Sub,
And,
Nand,
Or,
Xor,
Max,
Min,
UMax,
UMin,
FIRST_BINOP = Xchg,
LAST_BINOP = UMin,
BAD_BINOP
};
void *operator new(size_t s) {
return User::operator new(s, 2);
}
AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
AtomicOrdering Ordering, SynchronizationScope SynchScope,
Instruction *InsertBefore = 0);
AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
AtomicOrdering Ordering, SynchronizationScope SynchScope,
BasicBlock *InsertAtEnd);
BinOp getOperation() const {
return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
}
void setOperation(BinOp Operation) {
unsigned short SubclassData = getSubclassDataFromInstruction();
setInstructionSubclassData((SubclassData & 31) |
(Operation << 5));
}
bool isVolatile() const {
return getSubclassDataFromInstruction() & 1;
}
void setVolatile(bool V) {
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
(unsigned)V);
}
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
void setOrdering(AtomicOrdering Ordering) {
assert(Ordering != NotAtomic &&
"atomicrmw instructions can only be atomic.");
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
(Ordering << 2));
}
void setSynchScope(SynchronizationScope SynchScope) {
setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
(SynchScope << 1));
}
AtomicOrdering getOrdering() const {
return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
}
SynchronizationScope getSynchScope() const {
return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
}
Value *getPointerOperand() { return getOperand(0); }
const Value *getPointerOperand() const { return getOperand(0); }
static unsigned getPointerOperandIndex() { return 0U; }
Value *getValOperand() { return getOperand(1); }
const Value *getValOperand() const { return getOperand(1); }
unsigned getPointerAddressSpace() const {
return getPointerOperand()->getType()->getPointerAddressSpace();
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::AtomicRMW;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
void Init(BinOp Operation, Value *Ptr, Value *Val,
AtomicOrdering Ordering, SynchronizationScope SynchScope);
void setInstructionSubclassData(unsigned short D) {
Instruction::setInstructionSubclassData(D);
}
};
template <>
struct OperandTraits<AtomicRMWInst>
: public FixedNumOperandTraits<AtomicRMWInst,2> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
inline Type *checkGEPType(Type *Ty) {
assert(Ty && "Invalid GetElementPtrInst indices for type!");
return Ty;
}
class GetElementPtrInst : public Instruction {
GetElementPtrInst(const GetElementPtrInst &GEPI);
void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
unsigned Values, const Twine &NameStr,
Instruction *InsertBefore);
inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
unsigned Values, const Twine &NameStr,
BasicBlock *InsertAtEnd);
protected:
virtual GetElementPtrInst *clone_impl() const;
public:
static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
unsigned Values = 1 + unsigned(IdxList.size());
return new(Values)
GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
}
static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
unsigned Values = 1 + unsigned(IdxList.size());
return new(Values)
GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
}
static GetElementPtrInst *CreateInBounds(Value *Ptr,
ArrayRef<Value *> IdxList,
const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
GEP->setIsInBounds(true);
return GEP;
}
static GetElementPtrInst *CreateInBounds(Value *Ptr,
ArrayRef<Value *> IdxList,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
GEP->setIsInBounds(true);
return GEP;
}
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
PointerType *getType() const {
return reinterpret_cast<PointerType*>(Instruction::getType());
}
unsigned getAddressSpace() const {
return getPointerAddressSpace();
}
static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
inline op_iterator idx_begin() { return op_begin()+1; }
inline const_op_iterator idx_begin() const { return op_begin()+1; }
inline op_iterator idx_end() { return op_end(); }
inline const_op_iterator idx_end() const { return op_end(); }
Value *getPointerOperand() {
return getOperand(0);
}
const Value *getPointerOperand() const {
return getOperand(0);
}
static unsigned getPointerOperandIndex() {
return 0U; }
Type *getPointerOperandType() const {
return getPointerOperand()->getType();
}
unsigned getPointerAddressSpace() const {
return getPointerOperandType()->getPointerAddressSpace();
}
static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
Type *PtrTy = PointerType::get(checkGEPType(
getIndexedType(Ptr->getType(), IdxList)),
Ptr->getType()->getPointerAddressSpace());
if (Ptr->getType()->isVectorTy()) {
unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements();
return VectorType::get(PtrTy, NumElem);
}
return PtrTy;
}
unsigned getNumIndices() const { return getNumOperands() - 1;
}
bool hasIndices() const {
return getNumOperands() > 1;
}
bool hasAllZeroIndices() const;
bool hasAllConstantIndices() const;
void setIsInBounds(bool b = true);
bool isInBounds() const;
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::GetElementPtr);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
template <>
struct OperandTraits<GetElementPtrInst> :
public VariadicOperandTraits<GetElementPtrInst, 1> {
};
GetElementPtrInst::GetElementPtrInst(Value *Ptr,
ArrayRef<Value *> IdxList,
unsigned Values,
const Twine &NameStr,
Instruction *InsertBefore)
: Instruction(getGEPReturnType(Ptr, IdxList),
GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
Values, InsertBefore) {
init(Ptr, IdxList, NameStr);
}
GetElementPtrInst::GetElementPtrInst(Value *Ptr,
ArrayRef<Value *> IdxList,
unsigned Values,
const Twine &NameStr,
BasicBlock *InsertAtEnd)
: Instruction(getGEPReturnType(Ptr, IdxList),
GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
Values, InsertAtEnd) {
init(Ptr, IdxList, NameStr);
}
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
class ICmpInst: public CmpInst {
protected:
virtual ICmpInst *clone_impl() const;
public:
ICmpInst(
Instruction *InsertBefore, Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr = "" ) : CmpInst(makeCmpResultType(LHS->getType()),
Instruction::ICmp, pred, LHS, RHS, NameStr,
InsertBefore) {
assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
pred <= CmpInst::LAST_ICMP_PREDICATE &&
"Invalid ICmp predicate value");
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
"Both operands to ICmp instruction are not of the same type!");
assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
"Invalid operand types for ICmp instruction");
}
ICmpInst(
BasicBlock &InsertAtEnd, Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr = "" ) : CmpInst(makeCmpResultType(LHS->getType()),
Instruction::ICmp, pred, LHS, RHS, NameStr,
&InsertAtEnd) {
assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
pred <= CmpInst::LAST_ICMP_PREDICATE &&
"Invalid ICmp predicate value");
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
"Both operands to ICmp instruction are not of the same type!");
assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
"Invalid operand types for ICmp instruction");
}
ICmpInst(
Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr = "" ) : CmpInst(makeCmpResultType(LHS->getType()),
Instruction::ICmp, pred, LHS, RHS, NameStr) {
assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
pred <= CmpInst::LAST_ICMP_PREDICATE &&
"Invalid ICmp predicate value");
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
"Both operands to ICmp instruction are not of the same type!");
assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
getOperand(0)->getType()->getScalarType()->isPointerTy()) &&
"Invalid operand types for ICmp instruction");
}
Predicate getSignedPredicate() const {
return getSignedPredicate(getPredicate());
}
static Predicate getSignedPredicate(Predicate pred);
Predicate getUnsignedPredicate() const {
return getUnsignedPredicate(getPredicate());
}
static Predicate getUnsignedPredicate(Predicate pred);
static bool isEquality(Predicate P) {
return P == ICMP_EQ || P == ICMP_NE;
}
bool isEquality() const {
return isEquality(getPredicate());
}
bool isCommutative() const { return isEquality(); }
bool isRelational() const {
return !isEquality();
}
static bool isRelational(Predicate P) {
return !isEquality(P);
}
static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
void swapOperands() {
setPredicate(getSwappedPredicate());
Op<0>().swap(Op<1>());
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::ICmp;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class FCmpInst: public CmpInst {
protected:
virtual FCmpInst *clone_impl() const;
public:
FCmpInst(
Instruction *InsertBefore, Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr = "" ) : CmpInst(makeCmpResultType(LHS->getType()),
Instruction::FCmp, pred, LHS, RHS, NameStr,
InsertBefore) {
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
"Invalid FCmp predicate value");
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
"Both operands to FCmp instruction are not of the same type!");
assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
"Invalid operand types for FCmp instruction");
}
FCmpInst(
BasicBlock &InsertAtEnd, Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr = "" ) : CmpInst(makeCmpResultType(LHS->getType()),
Instruction::FCmp, pred, LHS, RHS, NameStr,
&InsertAtEnd) {
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
"Invalid FCmp predicate value");
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
"Both operands to FCmp instruction are not of the same type!");
assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
"Invalid operand types for FCmp instruction");
}
FCmpInst(
Predicate pred, Value *LHS, Value *RHS, const Twine &NameStr = "" ) : CmpInst(makeCmpResultType(LHS->getType()),
Instruction::FCmp, pred, LHS, RHS, NameStr) {
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
"Invalid FCmp predicate value");
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
"Both operands to FCmp instruction are not of the same type!");
assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
"Invalid operand types for FCmp instruction");
}
bool isEquality() const {
return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
}
bool isCommutative() const {
return isEquality() ||
getPredicate() == FCMP_FALSE ||
getPredicate() == FCMP_TRUE ||
getPredicate() == FCMP_ORD ||
getPredicate() == FCMP_UNO;
}
bool isRelational() const { return !isEquality(); }
void swapOperands() {
setPredicate(getSwappedPredicate());
Op<0>().swap(Op<1>());
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::FCmp;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class CallInst : public Instruction {
AttributeSet AttributeList; CallInst(const CallInst &CI);
void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
void init(Value *Func, const Twine &NameStr);
inline CallInst(Value *Func, ArrayRef<Value *> Args,
const Twine &NameStr, Instruction *InsertBefore);
inline CallInst(Value *Func, ArrayRef<Value *> Args,
const Twine &NameStr, BasicBlock *InsertAtEnd);
CallInst(Value *F, Value *Actual, const Twine &NameStr,
Instruction *InsertBefore);
CallInst(Value *F, Value *Actual, const Twine &NameStr,
BasicBlock *InsertAtEnd);
explicit CallInst(Value *F, const Twine &NameStr,
Instruction *InsertBefore);
CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
protected:
virtual CallInst *clone_impl() const;
public:
static CallInst *Create(Value *Func,
ArrayRef<Value *> Args,
const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
return new(unsigned(Args.size() + 1))
CallInst(Func, Args, NameStr, InsertBefore);
}
static CallInst *Create(Value *Func,
ArrayRef<Value *> Args,
const Twine &NameStr, BasicBlock *InsertAtEnd) {
return new(unsigned(Args.size() + 1))
CallInst(Func, Args, NameStr, InsertAtEnd);
}
static CallInst *Create(Value *F, const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
return new(1) CallInst(F, NameStr, InsertBefore);
}
static CallInst *Create(Value *F, const Twine &NameStr,
BasicBlock *InsertAtEnd) {
return new(1) CallInst(F, NameStr, InsertAtEnd);
}
static Instruction *CreateMalloc(Instruction *InsertBefore,
Type *IntPtrTy, Type *AllocTy,
Value *AllocSize, Value *ArraySize = 0,
Function* MallocF = 0,
const Twine &Name = "");
static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
Type *IntPtrTy, Type *AllocTy,
Value *AllocSize, Value *ArraySize = 0,
Function* MallocF = 0,
const Twine &Name = "");
static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
~CallInst();
bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
void setTailCall(bool isTC = true) {
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
unsigned(isTC));
}
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
unsigned getNumArgOperands() const { return getNumOperands() - 1; }
Value *getArgOperand(unsigned i) const { return getOperand(i); }
void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
CallingConv::ID getCallingConv() const {
return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
}
void setCallingConv(CallingConv::ID CC) {
setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
(static_cast<unsigned>(CC) << 1));
}
const AttributeSet &getAttributes() const { return AttributeList; }
void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
void addAttribute(unsigned i, Attribute attr);
void removeAttribute(unsigned i, Attribute attr);
bool hasFnAttr(Attribute::AttrKind A) const;
bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
unsigned getParamAlignment(unsigned i) const {
return AttributeList.getParamAlignment(i);
}
bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
void setIsNoInline() {
addAttribute(AttributeSet::FunctionIndex,
Attribute::get(getContext(), Attribute::NoInline));
}
bool canReturnTwice() const {
return hasFnAttr(Attribute::ReturnsTwice);
}
void setCanReturnTwice() {
addAttribute(AttributeSet::FunctionIndex,
Attribute::get(getContext(), Attribute::ReturnsTwice));
}
bool doesNotAccessMemory() const {
return hasFnAttr(Attribute::ReadNone);
}
void setDoesNotAccessMemory() {
addAttribute(AttributeSet::FunctionIndex,
Attribute::get(getContext(), Attribute::ReadNone));
}
bool onlyReadsMemory() const {
return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
}
void setOnlyReadsMemory() {
addAttribute(AttributeSet::FunctionIndex,
Attribute::get(getContext(), Attribute::ReadOnly));
}
bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
void setDoesNotReturn() {
addAttribute(AttributeSet::FunctionIndex,
Attribute::get(getContext(), Attribute::NoReturn));
}
bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
void setDoesNotThrow() {
addAttribute(AttributeSet::FunctionIndex,
Attribute::get(getContext(), Attribute::NoUnwind));
}
bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
void setCannotDuplicate() {
addAttribute(AttributeSet::FunctionIndex,
Attribute::get(getContext(), Attribute::NoDuplicate));
}
bool hasStructRetAttr() const {
return paramHasAttr(1, Attribute::StructRet);
}
bool hasByValArgument() const {
return AttributeList.hasAttrSomewhere(Attribute::ByVal);
}
Function *getCalledFunction() const {
return dyn_cast<Function>(Op<-1>());
}
const Value *getCalledValue() const { return Op<-1>(); }
Value *getCalledValue() { return Op<-1>(); }
void setCalledFunction(Value* Fn) {
Op<-1>() = Fn;
}
bool isInlineAsm() const {
return isa<InlineAsm>(Op<-1>());
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::Call;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
void setInstructionSubclassData(unsigned short D) {
Instruction::setInstructionSubclassData(D);
}
};
template <>
struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
};
CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
const Twine &NameStr, BasicBlock *InsertAtEnd)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
Instruction::Call,
OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
unsigned(Args.size() + 1), InsertAtEnd) {
init(Func, Args, NameStr);
}
CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
const Twine &NameStr, Instruction *InsertBefore)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
Instruction::Call,
OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
unsigned(Args.size() + 1), InsertBefore) {
init(Func, Args, NameStr);
}
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
class SelectInst : public Instruction {
void init(Value *C, Value *S1, Value *S2) {
assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
Op<0>() = C;
Op<1>() = S1;
Op<2>() = S2;
}
SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
Instruction *InsertBefore)
: Instruction(S1->getType(), Instruction::Select,
&Op<0>(), 3, InsertBefore) {
init(C, S1, S2);
setName(NameStr);
}
SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
BasicBlock *InsertAtEnd)
: Instruction(S1->getType(), Instruction::Select,
&Op<0>(), 3, InsertAtEnd) {
init(C, S1, S2);
setName(NameStr);
}
protected:
virtual SelectInst *clone_impl() const;
public:
static SelectInst *Create(Value *C, Value *S1, Value *S2,
const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
}
static SelectInst *Create(Value *C, Value *S1, Value *S2,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
}
const Value *getCondition() const { return Op<0>(); }
const Value *getTrueValue() const { return Op<1>(); }
const Value *getFalseValue() const { return Op<2>(); }
Value *getCondition() { return Op<0>(); }
Value *getTrueValue() { return Op<1>(); }
Value *getFalseValue() { return Op<2>(); }
static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
OtherOps getOpcode() const {
return static_cast<OtherOps>(Instruction::getOpcode());
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::Select;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
template <>
struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
class VAArgInst : public UnaryInstruction {
protected:
virtual VAArgInst *clone_impl() const;
public:
VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
Instruction *InsertBefore = 0)
: UnaryInstruction(Ty, VAArg, List, InsertBefore) {
setName(NameStr);
}
VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
BasicBlock *InsertAtEnd)
: UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
setName(NameStr);
}
Value *getPointerOperand() { return getOperand(0); }
const Value *getPointerOperand() const { return getOperand(0); }
static unsigned getPointerOperandIndex() { return 0U; }
static inline bool classof(const Instruction *I) {
return I->getOpcode() == VAArg;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class ExtractElementInst : public Instruction {
ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
Instruction *InsertBefore = 0);
ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
BasicBlock *InsertAtEnd);
protected:
virtual ExtractElementInst *clone_impl() const;
public:
static ExtractElementInst *Create(Value *Vec, Value *Idx,
const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
}
static ExtractElementInst *Create(Value *Vec, Value *Idx,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
}
static bool isValidOperands(const Value *Vec, const Value *Idx);
Value *getVectorOperand() { return Op<0>(); }
Value *getIndexOperand() { return Op<1>(); }
const Value *getVectorOperand() const { return Op<0>(); }
const Value *getIndexOperand() const { return Op<1>(); }
VectorType *getVectorOperandType() const {
return reinterpret_cast<VectorType*>(getVectorOperand()->getType());
}
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::ExtractElement;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
template <>
struct OperandTraits<ExtractElementInst> :
public FixedNumOperandTraits<ExtractElementInst, 2> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
class InsertElementInst : public Instruction {
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
const Twine &NameStr = "",
Instruction *InsertBefore = 0);
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
const Twine &NameStr, BasicBlock *InsertAtEnd);
protected:
virtual InsertElementInst *clone_impl() const;
public:
static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
}
static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
}
static bool isValidOperands(const Value *Vec, const Value *NewElt,
const Value *Idx);
VectorType *getType() const {
return reinterpret_cast<VectorType*>(Instruction::getType());
}
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::InsertElement;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
template <>
struct OperandTraits<InsertElementInst> :
public FixedNumOperandTraits<InsertElementInst, 3> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
class ShuffleVectorInst : public Instruction {
protected:
virtual ShuffleVectorInst *clone_impl() const;
public:
void *operator new(size_t s) {
return User::operator new(s, 3);
}
ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
const Twine &NameStr = "",
Instruction *InsertBefor = 0);
ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
const Twine &NameStr, BasicBlock *InsertAtEnd);
static bool isValidOperands(const Value *V1, const Value *V2,
const Value *Mask);
VectorType *getType() const {
return reinterpret_cast<VectorType*>(Instruction::getType());
}
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Constant *getMask() const {
return reinterpret_cast<Constant*>(getOperand(2));
}
static int getMaskValue(Constant *Mask, unsigned i);
int getMaskValue(unsigned i) const {
return getMaskValue(getMask(), i);
}
static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
void getShuffleMask(SmallVectorImpl<int> &Result) const {
return getShuffleMask(getMask(), Result);
}
SmallVector<int, 16> getShuffleMask() const {
SmallVector<int, 16> Mask;
getShuffleMask(Mask);
return Mask;
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::ShuffleVector;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
template <>
struct OperandTraits<ShuffleVectorInst> :
public FixedNumOperandTraits<ShuffleVectorInst, 3> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
class ExtractValueInst : public UnaryInstruction {
SmallVector<unsigned, 4> Indices;
ExtractValueInst(const ExtractValueInst &EVI);
void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
inline ExtractValueInst(Value *Agg,
ArrayRef<unsigned> Idxs,
const Twine &NameStr,
Instruction *InsertBefore);
inline ExtractValueInst(Value *Agg,
ArrayRef<unsigned> Idxs,
const Twine &NameStr, BasicBlock *InsertAtEnd);
void *operator new(size_t s) {
return User::operator new(s, 1);
}
protected:
virtual ExtractValueInst *clone_impl() const;
public:
static ExtractValueInst *Create(Value *Agg,
ArrayRef<unsigned> Idxs,
const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
return new
ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
}
static ExtractValueInst *Create(Value *Agg,
ArrayRef<unsigned> Idxs,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
}
static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
typedef const unsigned* idx_iterator;
inline idx_iterator idx_begin() const { return Indices.begin(); }
inline idx_iterator idx_end() const { return Indices.end(); }
Value *getAggregateOperand() {
return getOperand(0);
}
const Value *getAggregateOperand() const {
return getOperand(0);
}
static unsigned getAggregateOperandIndex() {
return 0U; }
ArrayRef<unsigned> getIndices() const {
return Indices;
}
unsigned getNumIndices() const {
return (unsigned)Indices.size();
}
bool hasIndices() const {
return true;
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::ExtractValue;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
ExtractValueInst::ExtractValueInst(Value *Agg,
ArrayRef<unsigned> Idxs,
const Twine &NameStr,
Instruction *InsertBefore)
: UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
ExtractValue, Agg, InsertBefore) {
init(Idxs, NameStr);
}
ExtractValueInst::ExtractValueInst(Value *Agg,
ArrayRef<unsigned> Idxs,
const Twine &NameStr,
BasicBlock *InsertAtEnd)
: UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
ExtractValue, Agg, InsertAtEnd) {
init(Idxs, NameStr);
}
class InsertValueInst : public Instruction {
SmallVector<unsigned, 4> Indices;
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
InsertValueInst(const InsertValueInst &IVI);
void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
const Twine &NameStr);
inline InsertValueInst(Value *Agg, Value *Val,
ArrayRef<unsigned> Idxs,
const Twine &NameStr,
Instruction *InsertBefore);
inline InsertValueInst(Value *Agg, Value *Val,
ArrayRef<unsigned> Idxs,
const Twine &NameStr, BasicBlock *InsertAtEnd);
InsertValueInst(Value *Agg, Value *Val,
unsigned Idx, const Twine &NameStr = "",
Instruction *InsertBefore = 0);
InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
const Twine &NameStr, BasicBlock *InsertAtEnd);
protected:
virtual InsertValueInst *clone_impl() const;
public:
void *operator new(size_t s) {
return User::operator new(s, 2);
}
static InsertValueInst *Create(Value *Agg, Value *Val,
ArrayRef<unsigned> Idxs,
const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
}
static InsertValueInst *Create(Value *Agg, Value *Val,
ArrayRef<unsigned> Idxs,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
}
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
typedef const unsigned* idx_iterator;
inline idx_iterator idx_begin() const { return Indices.begin(); }
inline idx_iterator idx_end() const { return Indices.end(); }
Value *getAggregateOperand() {
return getOperand(0);
}
const Value *getAggregateOperand() const {
return getOperand(0);
}
static unsigned getAggregateOperandIndex() {
return 0U; }
Value *getInsertedValueOperand() {
return getOperand(1);
}
const Value *getInsertedValueOperand() const {
return getOperand(1);
}
static unsigned getInsertedValueOperandIndex() {
return 1U; }
ArrayRef<unsigned> getIndices() const {
return Indices;
}
unsigned getNumIndices() const {
return (unsigned)Indices.size();
}
bool hasIndices() const {
return true;
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::InsertValue;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
template <>
struct OperandTraits<InsertValueInst> :
public FixedNumOperandTraits<InsertValueInst, 2> {
};
InsertValueInst::InsertValueInst(Value *Agg,
Value *Val,
ArrayRef<unsigned> Idxs,
const Twine &NameStr,
Instruction *InsertBefore)
: Instruction(Agg->getType(), InsertValue,
OperandTraits<InsertValueInst>::op_begin(this),
2, InsertBefore) {
init(Agg, Val, Idxs, NameStr);
}
InsertValueInst::InsertValueInst(Value *Agg,
Value *Val,
ArrayRef<unsigned> Idxs,
const Twine &NameStr,
BasicBlock *InsertAtEnd)
: Instruction(Agg->getType(), InsertValue,
OperandTraits<InsertValueInst>::op_begin(this),
2, InsertAtEnd) {
init(Agg, Val, Idxs, NameStr);
}
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
class PHINode : public Instruction {
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
unsigned ReservedSpace;
PHINode(const PHINode &PN);
void *operator new(size_t s) {
return User::operator new(s, 0);
}
explicit PHINode(Type *Ty, unsigned NumReservedValues,
const Twine &NameStr = "", Instruction *InsertBefore = 0)
: Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
ReservedSpace(NumReservedValues) {
setName(NameStr);
OperandList = allocHungoffUses(ReservedSpace);
}
PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
BasicBlock *InsertAtEnd)
: Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
ReservedSpace(NumReservedValues) {
setName(NameStr);
OperandList = allocHungoffUses(ReservedSpace);
}
protected:
Use *allocHungoffUses(unsigned) const;
virtual PHINode *clone_impl() const;
public:
static PHINode *Create(Type *Ty, unsigned NumReservedValues,
const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
}
static PHINode *Create(Type *Ty, unsigned NumReservedValues,
const Twine &NameStr, BasicBlock *InsertAtEnd) {
return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
}
~PHINode();
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
typedef BasicBlock **block_iterator;
typedef BasicBlock * const *const_block_iterator;
block_iterator block_begin() {
Use::UserRef *ref =
reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
return reinterpret_cast<block_iterator>(ref + 1);
}
const_block_iterator block_begin() const {
const Use::UserRef *ref =
reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
return reinterpret_cast<const_block_iterator>(ref + 1);
}
block_iterator block_end() {
return block_begin() + getNumOperands();
}
const_block_iterator block_end() const {
return block_begin() + getNumOperands();
}
unsigned getNumIncomingValues() const { return getNumOperands(); }
Value *getIncomingValue(unsigned i) const {
return getOperand(i);
}
void setIncomingValue(unsigned i, Value *V) {
setOperand(i, V);
}
static unsigned getOperandNumForIncomingValue(unsigned i) {
return i;
}
static unsigned getIncomingValueNumForOperand(unsigned i) {
return i;
}
BasicBlock *getIncomingBlock(unsigned i) const {
return block_begin()[i];
}
BasicBlock *getIncomingBlock(const Use &U) const {
assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
return getIncomingBlock(unsigned(&U - op_begin()));
}
template <typename U>
BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
return getIncomingBlock(I.getUse());
}
void setIncomingBlock(unsigned i, BasicBlock *BB) {
block_begin()[i] = BB;
}
void addIncoming(Value *V, BasicBlock *BB) {
assert(V && "PHI node got a null value!");
assert(BB && "PHI node got a null basic block!");
assert(getType() == V->getType() &&
"All operands to PHI node must be the same type as the PHI node!");
if (NumOperands == ReservedSpace)
growOperands(); ++NumOperands;
setIncomingValue(NumOperands - 1, V);
setIncomingBlock(NumOperands - 1, BB);
}
Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
int Idx = getBasicBlockIndex(BB);
assert(Idx >= 0 && "Invalid basic block argument to remove!");
return removeIncomingValue(Idx, DeletePHIIfEmpty);
}
int getBasicBlockIndex(const BasicBlock *BB) const {
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
if (block_begin()[i] == BB)
return i;
return -1;
}
Value *getIncomingValueForBlock(const BasicBlock *BB) const {
int Idx = getBasicBlockIndex(BB);
assert(Idx >= 0 && "Invalid basic block argument!");
return getIncomingValue(Idx);
}
Value *hasConstantValue() const;
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::PHI;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
void growOperands();
};
template <>
struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
class LandingPadInst : public Instruction {
unsigned ReservedSpace;
LandingPadInst(const LandingPadInst &LP);
public:
enum ClauseType { Catch, Filter };
private:
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
void *operator new(size_t s) {
return User::operator new(s, 0);
}
void growOperands(unsigned Size);
void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
unsigned NumReservedValues, const Twine &NameStr,
Instruction *InsertBefore);
explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
unsigned NumReservedValues, const Twine &NameStr,
BasicBlock *InsertAtEnd);
protected:
virtual LandingPadInst *clone_impl() const;
public:
static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
unsigned NumReservedClauses,
const Twine &NameStr = "",
Instruction *InsertBefore = 0);
static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
unsigned NumReservedClauses,
const Twine &NameStr, BasicBlock *InsertAtEnd);
~LandingPadInst();
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Value *getPersonalityFn() const { return getOperand(0); }
bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
void setCleanup(bool V) {
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
(V ? 1 : 0));
}
void addClause(Value *ClauseVal);
Value *getClause(unsigned Idx) const { return OperandList[Idx + 1]; }
bool isCatch(unsigned Idx) const {
return !isa<ArrayType>(OperandList[Idx + 1]->getType());
}
bool isFilter(unsigned Idx) const {
return isa<ArrayType>(OperandList[Idx + 1]->getType());
}
unsigned getNumClauses() const { return getNumOperands() - 1; }
void reserveClauses(unsigned Size) { growOperands(Size); }
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::LandingPad;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
template <>
struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
class ReturnInst : public TerminatorInst {
ReturnInst(const ReturnInst &RI);
private:
explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
Instruction *InsertBefore = 0);
ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
protected:
virtual ReturnInst *clone_impl() const;
public:
static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
Instruction *InsertBefore = 0) {
return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
}
static ReturnInst* Create(LLVMContext &C, Value *retVal,
BasicBlock *InsertAtEnd) {
return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
}
static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
return new(0) ReturnInst(C, InsertAtEnd);
}
virtual ~ReturnInst();
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Value *getReturnValue() const {
return getNumOperands() != 0 ? getOperand(0) : 0;
}
unsigned getNumSuccessors() const { return 0; }
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::Ret);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
virtual BasicBlock *getSuccessorV(unsigned idx) const;
virtual unsigned getNumSuccessorsV() const;
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
};
template <>
struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
class BranchInst : public TerminatorInst {
BranchInst(const BranchInst &BI);
void AssertOK();
explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Instruction *InsertBefore = 0);
BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
BasicBlock *InsertAtEnd);
protected:
virtual BranchInst *clone_impl() const;
public:
static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
return new(1) BranchInst(IfTrue, InsertBefore);
}
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
Value *Cond, Instruction *InsertBefore = 0) {
return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
}
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
return new(1) BranchInst(IfTrue, InsertAtEnd);
}
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
Value *Cond, BasicBlock *InsertAtEnd) {
return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
}
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
bool isUnconditional() const { return getNumOperands() == 1; }
bool isConditional() const { return getNumOperands() == 3; }
Value *getCondition() const {
assert(isConditional() && "Cannot get condition of an uncond branch!");
return Op<-3>();
}
void setCondition(Value *V) {
assert(isConditional() && "Cannot set condition of unconditional branch!");
Op<-3>() = V;
}
unsigned getNumSuccessors() const { return 1+isConditional(); }
BasicBlock *getSuccessor(unsigned i) const {
assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
}
void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
*(&Op<-1>() - idx) = (Value*)NewSucc;
}
void swapSuccessors();
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::Br);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
virtual BasicBlock *getSuccessorV(unsigned idx) const;
virtual unsigned getNumSuccessorsV() const;
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
};
template <>
struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
class SwitchInst : public TerminatorInst {
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
unsigned ReservedSpace;
typedef std::list<IntegersSubset> Subsets;
typedef Subsets::iterator SubsetsIt;
typedef Subsets::const_iterator SubsetsConstIt;
Subsets TheSubsets;
SwitchInst(const SwitchInst &SI);
void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
void growOperands();
void *operator new(size_t s) {
return User::operator new(s, 0);
}
SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Instruction *InsertBefore);
SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
BasicBlock *InsertAtEnd);
protected:
virtual SwitchInst *clone_impl() const;
public:
template <class SwitchInstTy, class ConstantIntTy,
class SubsetsItTy, class BasicBlockTy>
class CaseIteratorT;
typedef CaseIteratorT<const SwitchInst, const ConstantInt,
SubsetsConstIt, const BasicBlock> ConstCaseIt;
class CaseIt;
static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
static SwitchInst *Create(Value *Value, BasicBlock *Default,
unsigned NumCases, Instruction *InsertBefore = 0) {
return new SwitchInst(Value, Default, NumCases, InsertBefore);
}
static SwitchInst *Create(Value *Value, BasicBlock *Default,
unsigned NumCases, BasicBlock *InsertAtEnd) {
return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
}
~SwitchInst();
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Value *getCondition() const { return getOperand(0); }
void setCondition(Value *V) { setOperand(0, V); }
BasicBlock *getDefaultDest() const {
return cast<BasicBlock>(getOperand(1));
}
void setDefaultDest(BasicBlock *DefaultCase) {
setOperand(1, reinterpret_cast<Value*>(DefaultCase));
}
unsigned getNumCases() const {
return getNumOperands()/2 - 1;
}
CaseIt case_begin() {
return CaseIt(this, 0, TheSubsets.begin());
}
ConstCaseIt case_begin() const {
return ConstCaseIt(this, 0, TheSubsets.begin());
}
CaseIt case_end() {
return CaseIt(this, getNumCases(), TheSubsets.end());
}
ConstCaseIt case_end() const {
return ConstCaseIt(this, getNumCases(), TheSubsets.end());
}
CaseIt case_default() {
return CaseIt(this, DefaultPseudoIndex, TheSubsets.end());
}
ConstCaseIt case_default() const {
return ConstCaseIt(this, DefaultPseudoIndex, TheSubsets.end());
}
CaseIt findCaseValue(const ConstantInt *C) {
for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
if (i.getCaseValueEx().isSatisfies(IntItem::fromConstantInt(C)))
return i;
return case_default();
}
ConstCaseIt findCaseValue(const ConstantInt *C) const {
for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
if (i.getCaseValueEx().isSatisfies(IntItem::fromConstantInt(C)))
return i;
return case_default();
}
ConstantInt *findCaseDest(BasicBlock *BB) {
if (BB == getDefaultDest()) return NULL;
ConstantInt *CI = NULL;
for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
if (i.getCaseSuccessor() == BB) {
if (CI) return NULL; else CI = i.getCaseValue();
}
}
return CI;
}
void addCase(ConstantInt *OnVal, BasicBlock *Dest);
void addCase(IntegersSubset& OnVal, BasicBlock *Dest);
void removeCase(CaseIt& i);
unsigned getNumSuccessors() const { return getNumOperands()/2; }
BasicBlock *getSuccessor(unsigned idx) const {
assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
return cast<BasicBlock>(getOperand(idx*2+1));
}
void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
setOperand(idx*2+1, (Value*)NewSucc);
}
uint16_t hash() const {
uint32_t NumberOfCases = (uint32_t)getNumCases();
uint16_t Hash = (0xFFFF & NumberOfCases) ^ (NumberOfCases >> 16);
for (ConstCaseIt i = case_begin(), e = case_end();
i != e; ++i) {
uint32_t NumItems = (uint32_t)i.getCaseValueEx().getNumItems();
Hash = (Hash << 1) ^ (0xFFFF & NumItems) ^ (NumItems >> 16);
}
return Hash;
}
template <class SwitchInstTy, class ConstantIntTy,
class SubsetsItTy, class BasicBlockTy>
class CaseIteratorT {
protected:
SwitchInstTy *SI;
unsigned long Index;
SubsetsItTy SubsetIt;
friend class SwitchInst;
CaseIteratorT(SwitchInstTy *SI, unsigned SuccessorIndex,
SubsetsItTy CaseValueIt) {
this->SI = SI;
Index = SuccessorIndex;
this->SubsetIt = CaseValueIt;
}
public:
typedef typename SubsetsItTy::reference IntegersSubsetRef;
typedef CaseIteratorT<SwitchInstTy, ConstantIntTy,
SubsetsItTy, BasicBlockTy> Self;
CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
this->SI = SI;
Index = CaseNum;
SubsetIt = SI->TheSubsets.begin();
std::advance(SubsetIt, CaseNum);
}
static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
assert(SuccessorIndex < SI->getNumSuccessors() &&
"Successor index # out of range!");
return SuccessorIndex != 0 ?
Self(SI, SuccessorIndex - 1) :
Self(SI, DefaultPseudoIndex);
}
ConstantIntTy *getCaseValue() {
assert(Index < SI->getNumCases() && "Index out the number of cases.");
IntegersSubsetRef CaseRanges = *SubsetIt;
return CaseRanges.getSingleNumber(0).toConstantInt();
}
IntegersSubsetRef getCaseValueEx() {
assert(Index < SI->getNumCases() && "Index out the number of cases.");
return *SubsetIt;
}
BasicBlockTy *getCaseSuccessor() {
assert((Index < SI->getNumCases() ||
Index == DefaultPseudoIndex) &&
"Index out the number of cases.");
return SI->getSuccessor(getSuccessorIndex());
}
unsigned getCaseIndex() const { return Index; }
unsigned getSuccessorIndex() const {
assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
"Index out the number of cases.");
return Index != DefaultPseudoIndex ? Index + 1 : 0;
}
Self operator++() {
assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
++Index;
if (Index == 0)
SubsetIt = SI->TheSubsets.begin();
else
++SubsetIt;
return *this;
}
Self operator++(int) {
Self tmp = *this;
++(*this);
return tmp;
}
Self operator--() {
unsigned NumCases = SI->getNumCases();
assert((Index == 0 || Index-1 <= NumCases) &&
"Index out the number of cases.");
--Index;
if (Index == NumCases) {
SubsetIt = SI->TheSubsets.end();
return *this;
}
if (Index != -1UL)
--SubsetIt;
return *this;
}
Self operator--(int) {
Self tmp = *this;
--(*this);
return tmp;
}
bool operator==(const Self& RHS) const {
assert(RHS.SI == SI && "Incompatible operators.");
return RHS.Index == Index;
}
bool operator!=(const Self& RHS) const {
assert(RHS.SI == SI && "Incompatible operators.");
return RHS.Index != Index;
}
};
class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt,
SubsetsIt, BasicBlock> {
typedef CaseIteratorT<SwitchInst, ConstantInt, SubsetsIt, BasicBlock>
ParentTy;
protected:
friend class SwitchInst;
CaseIt(SwitchInst *SI, unsigned CaseNum, SubsetsIt SubsetIt) :
ParentTy(SI, CaseNum, SubsetIt) {}
void updateCaseValueOperand(IntegersSubset& V) {
SI->setOperand(2 + Index*2, reinterpret_cast<Value*>((Constant*)V));
}
public:
CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
CaseIt(const ParentTy& Src) : ParentTy(Src) {}
void setValue(ConstantInt *V) {
assert(Index < SI->getNumCases() && "Index out the number of cases.");
IntegersSubsetToBB Mapping;
Mapping.add(IntItem::fromConstantInt(V));
*SubsetIt = Mapping.getCase();
updateCaseValueOperand(*SubsetIt);
}
void setValueEx(IntegersSubset& V) {
assert(Index < SI->getNumCases() && "Index out the number of cases.");
*SubsetIt = V;
updateCaseValueOperand(*SubsetIt);
}
void setSuccessor(BasicBlock *S) {
SI->setSuccessor(getSuccessorIndex(), S);
}
};
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::Switch;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
virtual BasicBlock *getSuccessorV(unsigned idx) const;
virtual unsigned getNumSuccessorsV() const;
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
};
template <>
struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
class IndirectBrInst : public TerminatorInst {
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
unsigned ReservedSpace;
IndirectBrInst(const IndirectBrInst &IBI);
void init(Value *Address, unsigned NumDests);
void growOperands();
void *operator new(size_t s) {
return User::operator new(s, 0);
}
IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
protected:
virtual IndirectBrInst *clone_impl() const;
public:
static IndirectBrInst *Create(Value *Address, unsigned NumDests,
Instruction *InsertBefore = 0) {
return new IndirectBrInst(Address, NumDests, InsertBefore);
}
static IndirectBrInst *Create(Value *Address, unsigned NumDests,
BasicBlock *InsertAtEnd) {
return new IndirectBrInst(Address, NumDests, InsertAtEnd);
}
~IndirectBrInst();
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Value *getAddress() { return getOperand(0); }
const Value *getAddress() const { return getOperand(0); }
void setAddress(Value *V) { setOperand(0, V); }
unsigned getNumDestinations() const { return getNumOperands()-1; }
BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
void addDestination(BasicBlock *Dest);
void removeDestination(unsigned i);
unsigned getNumSuccessors() const { return getNumOperands()-1; }
BasicBlock *getSuccessor(unsigned i) const {
return cast<BasicBlock>(getOperand(i+1));
}
void setSuccessor(unsigned i, BasicBlock *NewSucc) {
setOperand(i+1, (Value*)NewSucc);
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::IndirectBr;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
virtual BasicBlock *getSuccessorV(unsigned idx) const;
virtual unsigned getNumSuccessorsV() const;
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
};
template <>
struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
class InvokeInst : public TerminatorInst {
AttributeSet AttributeList;
InvokeInst(const InvokeInst &BI);
void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
ArrayRef<Value *> Args, const Twine &NameStr);
inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
ArrayRef<Value *> Args, unsigned Values,
const Twine &NameStr, Instruction *InsertBefore);
inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
ArrayRef<Value *> Args, unsigned Values,
const Twine &NameStr, BasicBlock *InsertAtEnd);
protected:
virtual InvokeInst *clone_impl() const;
public:
static InvokeInst *Create(Value *Func,
BasicBlock *IfNormal, BasicBlock *IfException,
ArrayRef<Value *> Args, const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
unsigned Values = unsigned(Args.size()) + 3;
return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
Values, NameStr, InsertBefore);
}
static InvokeInst *Create(Value *Func,
BasicBlock *IfNormal, BasicBlock *IfException,
ArrayRef<Value *> Args, const Twine &NameStr,
BasicBlock *InsertAtEnd) {
unsigned Values = unsigned(Args.size()) + 3;
return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
Values, NameStr, InsertAtEnd);
}
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
unsigned getNumArgOperands() const { return getNumOperands() - 3; }
Value *getArgOperand(unsigned i) const { return getOperand(i); }
void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
CallingConv::ID getCallingConv() const {
return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
}
void setCallingConv(CallingConv::ID CC) {
setInstructionSubclassData(static_cast<unsigned>(CC));
}
const AttributeSet &getAttributes() const { return AttributeList; }
void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
void addAttribute(unsigned i, Attribute attr);
void removeAttribute(unsigned i, Attribute attr);
bool hasFnAttr(Attribute::AttrKind A) const;
bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
unsigned getParamAlignment(unsigned i) const {
return AttributeList.getParamAlignment(i);
}
bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
void setIsNoInline() {
addAttribute(AttributeSet::FunctionIndex,
Attribute::get(getContext(), Attribute::NoInline));
}
bool doesNotAccessMemory() const {
return hasFnAttr(Attribute::ReadNone);
}
void setDoesNotAccessMemory() {
addAttribute(AttributeSet::FunctionIndex,
Attribute::get(getContext(), Attribute::ReadNone));
}
bool onlyReadsMemory() const {
return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
}
void setOnlyReadsMemory() {
addAttribute(AttributeSet::FunctionIndex,
Attribute::get(getContext(), Attribute::ReadOnly));
}
bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
void setDoesNotReturn() {
addAttribute(AttributeSet::FunctionIndex,
Attribute::get(getContext(), Attribute::NoReturn));
}
bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
void setDoesNotThrow() {
addAttribute(AttributeSet::FunctionIndex,
Attribute::get(getContext(), Attribute::NoUnwind));
}
bool hasStructRetAttr() const {
return paramHasAttr(1, Attribute::StructRet);
}
bool hasByValArgument() const {
return AttributeList.hasAttrSomewhere(Attribute::ByVal);
}
Function *getCalledFunction() const {
return dyn_cast<Function>(Op<-3>());
}
const Value *getCalledValue() const { return Op<-3>(); }
Value *getCalledValue() { return Op<-3>(); }
void setCalledFunction(Value* Fn) {
Op<-3>() = Fn;
}
BasicBlock *getNormalDest() const {
return cast<BasicBlock>(Op<-2>());
}
BasicBlock *getUnwindDest() const {
return cast<BasicBlock>(Op<-1>());
}
void setNormalDest(BasicBlock *B) {
Op<-2>() = reinterpret_cast<Value*>(B);
}
void setUnwindDest(BasicBlock *B) {
Op<-1>() = reinterpret_cast<Value*>(B);
}
LandingPadInst *getLandingPadInst() const;
BasicBlock *getSuccessor(unsigned i) const {
assert(i < 2 && "Successor # out of range for invoke!");
return i == 0 ? getNormalDest() : getUnwindDest();
}
void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
assert(idx < 2 && "Successor # out of range for invoke!");
*(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
}
unsigned getNumSuccessors() const { return 2; }
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::Invoke);
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
virtual BasicBlock *getSuccessorV(unsigned idx) const;
virtual unsigned getNumSuccessorsV() const;
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
void setInstructionSubclassData(unsigned short D) {
Instruction::setInstructionSubclassData(D);
}
};
template <>
struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
};
InvokeInst::InvokeInst(Value *Func,
BasicBlock *IfNormal, BasicBlock *IfException,
ArrayRef<Value *> Args, unsigned Values,
const Twine &NameStr, Instruction *InsertBefore)
: TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
Instruction::Invoke,
OperandTraits<InvokeInst>::op_end(this) - Values,
Values, InsertBefore) {
init(Func, IfNormal, IfException, Args, NameStr);
}
InvokeInst::InvokeInst(Value *Func,
BasicBlock *IfNormal, BasicBlock *IfException,
ArrayRef<Value *> Args, unsigned Values,
const Twine &NameStr, BasicBlock *InsertAtEnd)
: TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
->getElementType())->getReturnType(),
Instruction::Invoke,
OperandTraits<InvokeInst>::op_end(this) - Values,
Values, InsertAtEnd) {
init(Func, IfNormal, IfException, Args, NameStr);
}
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
class ResumeInst : public TerminatorInst {
ResumeInst(const ResumeInst &RI);
explicit ResumeInst(Value *Exn, Instruction *InsertBefore=0);
ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
protected:
virtual ResumeInst *clone_impl() const;
public:
static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = 0) {
return new(1) ResumeInst(Exn, InsertBefore);
}
static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
return new(1) ResumeInst(Exn, InsertAtEnd);
}
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Value *getValue() const { return Op<0>(); }
unsigned getNumSuccessors() const { return 0; }
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::Resume;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
virtual BasicBlock *getSuccessorV(unsigned idx) const;
virtual unsigned getNumSuccessorsV() const;
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
};
template <>
struct OperandTraits<ResumeInst> :
public FixedNumOperandTraits<ResumeInst, 1> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
class UnreachableInst : public TerminatorInst {
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
protected:
virtual UnreachableInst *clone_impl() const;
public:
void *operator new(size_t s) {
return User::operator new(s, 0);
}
explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
unsigned getNumSuccessors() const { return 0; }
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::Unreachable;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
private:
virtual BasicBlock *getSuccessorV(unsigned idx) const;
virtual unsigned getNumSuccessorsV() const;
virtual void setSuccessorV(unsigned idx, BasicBlock *B);
};
class TruncInst : public CastInst {
protected:
virtual TruncInst *clone_impl() const;
public:
TruncInst(
Value *S, Type *Ty, const Twine &NameStr = "", Instruction *InsertBefore = 0 );
TruncInst(
Value *S, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd );
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Trunc;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class ZExtInst : public CastInst {
protected:
virtual ZExtInst *clone_impl() const;
public:
ZExtInst(
Value *S, Type *Ty, const Twine &NameStr = "", Instruction *InsertBefore = 0 );
ZExtInst(
Value *S, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd );
static inline bool classof(const Instruction *I) {
return I->getOpcode() == ZExt;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class SExtInst : public CastInst {
protected:
virtual SExtInst *clone_impl() const;
public:
SExtInst(
Value *S, Type *Ty, const Twine &NameStr = "", Instruction *InsertBefore = 0 );
SExtInst(
Value *S, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd );
static inline bool classof(const Instruction *I) {
return I->getOpcode() == SExt;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class FPTruncInst : public CastInst {
protected:
virtual FPTruncInst *clone_impl() const;
public:
FPTruncInst(
Value *S, Type *Ty, const Twine &NameStr = "", Instruction *InsertBefore = 0 );
FPTruncInst(
Value *S, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd );
static inline bool classof(const Instruction *I) {
return I->getOpcode() == FPTrunc;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class FPExtInst : public CastInst {
protected:
virtual FPExtInst *clone_impl() const;
public:
FPExtInst(
Value *S, Type *Ty, const Twine &NameStr = "", Instruction *InsertBefore = 0 );
FPExtInst(
Value *S, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd );
static inline bool classof(const Instruction *I) {
return I->getOpcode() == FPExt;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class UIToFPInst : public CastInst {
protected:
virtual UIToFPInst *clone_impl() const;
public:
UIToFPInst(
Value *S, Type *Ty, const Twine &NameStr = "", Instruction *InsertBefore = 0 );
UIToFPInst(
Value *S, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd );
static inline bool classof(const Instruction *I) {
return I->getOpcode() == UIToFP;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class SIToFPInst : public CastInst {
protected:
virtual SIToFPInst *clone_impl() const;
public:
SIToFPInst(
Value *S, Type *Ty, const Twine &NameStr = "", Instruction *InsertBefore = 0 );
SIToFPInst(
Value *S, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd );
static inline bool classof(const Instruction *I) {
return I->getOpcode() == SIToFP;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class FPToUIInst : public CastInst {
protected:
virtual FPToUIInst *clone_impl() const;
public:
FPToUIInst(
Value *S, Type *Ty, const Twine &NameStr = "", Instruction *InsertBefore = 0 );
FPToUIInst(
Value *S, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd );
static inline bool classof(const Instruction *I) {
return I->getOpcode() == FPToUI;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class FPToSIInst : public CastInst {
protected:
virtual FPToSIInst *clone_impl() const;
public:
FPToSIInst(
Value *S, Type *Ty, const Twine &NameStr = "", Instruction *InsertBefore = 0 );
FPToSIInst(
Value *S, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd );
static inline bool classof(const Instruction *I) {
return I->getOpcode() == FPToSI;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class IntToPtrInst : public CastInst {
public:
IntToPtrInst(
Value *S, Type *Ty, const Twine &NameStr = "", Instruction *InsertBefore = 0 );
IntToPtrInst(
Value *S, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd );
virtual IntToPtrInst *clone_impl() const;
unsigned getAddressSpace() const {
return getType()->getPointerAddressSpace();
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == IntToPtr;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class PtrToIntInst : public CastInst {
protected:
virtual PtrToIntInst *clone_impl() const;
public:
PtrToIntInst(
Value *S, Type *Ty, const Twine &NameStr = "", Instruction *InsertBefore = 0 );
PtrToIntInst(
Value *S, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd );
Value *getPointerOperand() { return getOperand(0); }
const Value *getPointerOperand() const { return getOperand(0); }
static unsigned getPointerOperandIndex() { return 0U; }
unsigned getPointerAddressSpace() const {
return getPointerOperand()->getType()->getPointerAddressSpace();
}
static inline bool classof(const Instruction *I) {
return I->getOpcode() == PtrToInt;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
class BitCastInst : public CastInst {
protected:
virtual BitCastInst *clone_impl() const;
public:
BitCastInst(
Value *S, Type *Ty, const Twine &NameStr = "", Instruction *InsertBefore = 0 );
BitCastInst(
Value *S, Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd );
static inline bool classof(const Instruction *I) {
return I->getOpcode() == BitCast;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
}
#endif