#include "llvm/DerivedTypes.h"
#include "llvm/Attributes.h"
#include "llvm/BasicBlock.h"
+#include "llvm/CallingConv.h"
#include "llvm/LLVMContext.h"
#include "llvm/ADT/SmallVector.h"
#include <iterator>
class ConstantRange;
class APInt;
class LLVMContext;
+class DominatorTree;
//===----------------------------------------------------------------------===//
// AllocationInst Class
unsigned getAlignment() const { return (1u << SubclassData) >> 1; }
void setAlignment(unsigned Align);
- virtual Instruction *clone(LLVMContext &Context) const = 0;
+ virtual AllocationInst *clone(LLVMContext &Context) const = 0;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const AllocationInst *) { return true; }
/// MallocInst - an instruction to allocated memory on the heap
///
class MallocInst : public AllocationInst {
- MallocInst(const MallocInst &MI);
public:
explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
const Twine &NameStr = "",
/// AllocaInst - an instruction to allocate memory on the stack
///
class AllocaInst : public AllocationInst {
- AllocaInst(const AllocaInst &);
public:
explicit AllocaInst(const Type *Ty,
Value *ArraySize = 0,
/// SubclassData field in Value to store whether or not the load is volatile.
///
class LoadInst : public UnaryInstruction {
-
- LoadInst(const LoadInst &LI)
- : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
- setVolatile(LI.isVolatile());
- setAlignment(LI.getAlignment());
-
-#ifndef NDEBUG
- AssertOK();
-#endif
- }
void AssertOK();
public:
LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
const Value *getPointerOperand() const { return getOperand(0); }
static unsigned getPointerOperandIndex() { return 0U; }
+ unsigned getPointerAddressSpace() const {
+ return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
+ }
+
+
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const LoadInst *) { return true; }
static inline bool classof(const Instruction *I) {
///
class StoreInst : public Instruction {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
-
- StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store,
- &Op<0>(), 2) {
- Op<0>() = SI.Op<0>();
- Op<1>() = SI.Op<1>();
- setVolatile(SI.isVolatile());
- setAlignment(SI.getAlignment());
-
-#ifndef NDEBUG
- AssertOK();
-#endif
- }
void AssertOK();
public:
// allocate space for exactly two operands
const Value *getPointerOperand() const { return getOperand(1); }
static unsigned getPointerOperandIndex() { return 1U; }
+ unsigned getPointerAddressSpace() const {
+ return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
+ }
+
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const StoreInst *) { return true; }
static inline bool classof(const Instruction *I) {
};
template <>
-struct OperandTraits<StoreInst> : FixedNumOperandTraits<2> {
+struct OperandTraits<StoreInst> : public FixedNumOperandTraits<2> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
Instruction *InsertBefore = 0) {
GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
NameStr, InsertBefore);
- cast<GEPOperator>(GEP)->setIsInBounds(true);
+ GEP->setIsInBounds(true);
return GEP;
}
template<typename InputIterator>
BasicBlock *InsertAtEnd) {
GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
NameStr, InsertAtEnd);
- cast<GEPOperator>(GEP)->setIsInBounds(true);
+ GEP->setIsInBounds(true);
return GEP;
}
static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore);
- cast<GEPOperator>(GEP)->setIsInBounds(true);
+ GEP->setIsInBounds(true);
return GEP;
}
static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd);
- cast<GEPOperator>(GEP)->setIsInBounds(true);
+ GEP->setIsInBounds(true);
return GEP;
}
static unsigned getPointerOperandIndex() {
return 0U; // get index for modifying correct operand
}
+
+ unsigned getPointerAddressSpace() const {
+ return cast<PointerType>(getType())->getAddressSpace();
+ }
/// getPointerOperandType - Method to return the pointer operand as a
/// PointerType.
/// a constant offset between them.
bool hasAllConstantIndices() const;
+ /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
+ /// See LangRef.html for the meaning of inbounds on a getelementptr.
+ void setIsInBounds(bool);
+
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const GetElementPtrInst *) { return true; }
static inline bool classof(const Instruction *I) {
};
template <>
-struct OperandTraits<GetElementPtrInst> : VariadicOperandTraits<1> {
+struct OperandTraits<GetElementPtrInst> : public VariadicOperandTraits<1> {
};
template<typename InputIterator>
/// @brief Constructor with no-insertion semantics
ICmpInst(
- LLVMContext &Context, ///< Context to construct within
Predicate pred, ///< The predicate to use for the comparison
Value *LHS, ///< The left-hand-side of the expression
Value *RHS, ///< The right-hand-side of the expression
/// @brief Constructor with no-insertion semantics
FCmpInst(
- LLVMContext &Context, ///< Context to build in
Predicate pred, ///< The predicate to use for the comparison
Value *LHS, ///< The left-hand-side of the expression
Value *RHS, ///< The right-hand-side of the expression
/// getCallingConv/setCallingConv - Get or set the calling convention of this
/// function call.
- unsigned getCallingConv() const { return SubclassData >> 1; }
- void setCallingConv(unsigned CC) {
- SubclassData = (SubclassData & 1) | (CC << 1);
+ CallingConv::ID getCallingConv() const {
+ return static_cast<CallingConv::ID>(SubclassData >> 1);
+ }
+ void setCallingConv(CallingConv::ID CC) {
+ SubclassData = (SubclassData & 1) | (static_cast<unsigned>(CC) << 1);
}
/// getAttributes - Return the parameter attributes for this call.
};
template <>
-struct OperandTraits<CallInst> : VariadicOperandTraits<1> {
+struct OperandTraits<CallInst> : public VariadicOperandTraits<1> {
};
template<typename InputIterator>
Op<2>() = S2;
}
- SelectInst(const SelectInst &SI)
- : Instruction(SI.getType(), SI.getOpcode(), &Op<0>(), 3) {
- init(SI.Op<0>(), SI.Op<1>(), SI.Op<2>());
- }
SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
Instruction *InsertBefore)
: Instruction(S1->getType(), Instruction::Select,
};
template <>
-struct OperandTraits<SelectInst> : FixedNumOperandTraits<3> {
+struct OperandTraits<SelectInst> : public FixedNumOperandTraits<3> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
/// an argument of the specified type given a va_list and increments that list
///
class VAArgInst : public UnaryInstruction {
- VAArgInst(const VAArgInst &VAA)
- : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
public:
VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "",
Instruction *InsertBefore = 0)
/// element from a VectorType value
///
class ExtractElementInst : public Instruction {
- ExtractElementInst(const ExtractElementInst &EE) :
- Instruction(EE.getType(), ExtractElement, &Op<0>(), 2) {
- Op<0>() = EE.Op<0>();
- Op<1>() = EE.Op<1>();
- }
-
ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
Instruction *InsertBefore = 0);
ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
BasicBlock *InsertAtEnd);
public:
- static ExtractElementInst *Create(const ExtractElementInst &EE) {
- return new(EE.getNumOperands()) ExtractElementInst(EE);
- }
-
static ExtractElementInst *Create(Value *Vec, Value *Idx,
const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
};
template <>
-struct OperandTraits<ExtractElementInst> : FixedNumOperandTraits<2> {
+struct OperandTraits<ExtractElementInst> : public FixedNumOperandTraits<2> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
/// element into a VectorType value
///
class InsertElementInst : public Instruction {
- InsertElementInst(const InsertElementInst &IE);
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);
public:
- static InsertElementInst *Create(const InsertElementInst &IE) {
- return new(IE.getNumOperands()) InsertElementInst(IE);
- }
static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
};
template <>
-struct OperandTraits<InsertElementInst> : FixedNumOperandTraits<3> {
+struct OperandTraits<InsertElementInst> : public FixedNumOperandTraits<3> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
/// input vectors.
///
class ShuffleVectorInst : public Instruction {
- ShuffleVectorInst(const ShuffleVectorInst &IE);
public:
// allocate space for exactly three operands
void *operator new(size_t s) {
};
template <>
-struct OperandTraits<ShuffleVectorInst> : FixedNumOperandTraits<3> {
+struct OperandTraits<ShuffleVectorInst> : public FixedNumOperandTraits<3> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
};
template <>
-struct OperandTraits<InsertValueInst> : FixedNumOperandTraits<2> {
+struct OperandTraits<InsertValueInst> : public FixedNumOperandTraits<2> {
};
template<typename InputIterator>
/// hasConstantValue - If the specified PHI node always merges together the
/// same value, return the value, otherwise return null.
///
- Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
+ /// If the PHI has undef operands, but all the rest of the operands are
+ /// some unique value, return that value if it can be proved that the
+ /// value dominates the PHI. If DT is null, use a conservative check,
+ /// otherwise use DT to test for dominance.
+ ///
+ Value *hasConstantValue(DominatorTree *DT = 0) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const PHINode *) { return true; }
};
template <>
-struct OperandTraits<PHINode> : HungoffOperandTraits<2> {
+struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
//
// NOTE: If the Value* passed is of type void then the constructor behaves as
// if it was passed NULL.
- explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
- ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
- explicit ReturnInst(BasicBlock *InsertAtEnd);
+ explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
+ Instruction *InsertBefore = 0);
+ ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
+ explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
public:
- static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) {
- return new(!!retVal) ReturnInst(retVal, InsertBefore);
+ static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
+ Instruction *InsertBefore = 0) {
+ return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
}
- static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) {
- return new(!!retVal) ReturnInst(retVal, InsertAtEnd);
+ static ReturnInst* Create(LLVMContext &C, Value *retVal,
+ BasicBlock *InsertAtEnd) {
+ return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
}
- static ReturnInst* Create(BasicBlock *InsertAtEnd) {
- return new(0) ReturnInst(InsertAtEnd);
+ static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
+ return new(0) ReturnInst(C, InsertAtEnd);
}
virtual ~ReturnInst();
};
template <>
-struct OperandTraits<ReturnInst> : OptionalOperandTraits<> {
+struct OperandTraits<ReturnInst> : public OptionalOperandTraits<> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
};
template <>
-struct OperandTraits<BranchInst> : VariadicOperandTraits<1> {};
+struct OperandTraits<BranchInst> : public VariadicOperandTraits<1> {};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
};
template <>
-struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> {
+struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
/// getCallingConv/setCallingConv - Get or set the calling convention of this
/// function call.
- unsigned getCallingConv() const { return SubclassData; }
- void setCallingConv(unsigned CC) {
- SubclassData = CC;
+ CallingConv::ID getCallingConv() const {
+ return static_cast<CallingConv::ID>(SubclassData);
+ }
+ void setCallingConv(CallingConv::ID CC) {
+ SubclassData = static_cast<unsigned>(CC);
}
/// getAttributes - Return the parameter attributes for this invoke.
};
template <>
-struct OperandTraits<InvokeInst> : VariadicOperandTraits<3> {
+struct OperandTraits<InvokeInst> : public VariadicOperandTraits<3> {
};
template<typename InputIterator>
void *operator new(size_t s) {
return User::operator new(s, 0);
}
- explicit UnwindInst(Instruction *InsertBefore = 0);
- explicit UnwindInst(BasicBlock *InsertAtEnd);
+ explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
+ explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
virtual UnwindInst *clone(LLVMContext &Context) const;
void *operator new(size_t s) {
return User::operator new(s, 0);
}
- explicit UnreachableInst(Instruction *InsertBefore = 0);
- explicit UnreachableInst(BasicBlock *InsertAtEnd);
+ explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
+ explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
virtual UnreachableInst *clone(LLVMContext &Context) const;
/// @brief This class represents a truncation of integer types.
class TruncInst : public CastInst {
- /// Private copy constructor
- TruncInst(const TruncInst &CI)
- : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
- }
public:
/// @brief Constructor with insert-before-instruction semantics
TruncInst(
);
/// @brief Clone an identical TruncInst
- virtual CastInst *clone(LLVMContext &Context) const;
+ virtual TruncInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const TruncInst *) { return true; }
/// @brief This class represents zero extension of integer types.
class ZExtInst : public CastInst {
- /// @brief Private copy constructor
- ZExtInst(const ZExtInst &CI)
- : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
- }
public:
/// @brief Constructor with insert-before-instruction semantics
ZExtInst(
);
/// @brief Clone an identical ZExtInst
- virtual CastInst *clone(LLVMContext &Context) const;
+ virtual ZExtInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ZExtInst *) { return true; }
/// @brief This class represents a sign extension of integer types.
class SExtInst : public CastInst {
- /// @brief Private copy constructor
- SExtInst(const SExtInst &CI)
- : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
- }
public:
/// @brief Constructor with insert-before-instruction semantics
SExtInst(
);
/// @brief Clone an identical SExtInst
- virtual CastInst *clone(LLVMContext &Context) const;
+ virtual SExtInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const SExtInst *) { return true; }
/// @brief This class represents a truncation of floating point types.
class FPTruncInst : public CastInst {
- FPTruncInst(const FPTruncInst &CI)
- : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
- }
public:
/// @brief Constructor with insert-before-instruction semantics
FPTruncInst(
);
/// @brief Clone an identical FPTruncInst
- virtual CastInst *clone(LLVMContext &Context) const;
+ virtual FPTruncInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FPTruncInst *) { return true; }
/// @brief This class represents an extension of floating point types.
class FPExtInst : public CastInst {
- FPExtInst(const FPExtInst &CI)
- : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
- }
public:
/// @brief Constructor with insert-before-instruction semantics
FPExtInst(
);
/// @brief Clone an identical FPExtInst
- virtual CastInst *clone(LLVMContext &Context) const;
+ virtual FPExtInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FPExtInst *) { return true; }
/// @brief This class represents a cast unsigned integer to floating point.
class UIToFPInst : public CastInst {
- UIToFPInst(const UIToFPInst &CI)
- : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
- }
public:
/// @brief Constructor with insert-before-instruction semantics
UIToFPInst(
);
/// @brief Clone an identical UIToFPInst
- virtual CastInst *clone(LLVMContext &Context) const;
+ virtual UIToFPInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const UIToFPInst *) { return true; }
/// @brief This class represents a cast from signed integer to floating point.
class SIToFPInst : public CastInst {
- SIToFPInst(const SIToFPInst &CI)
- : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
- }
public:
/// @brief Constructor with insert-before-instruction semantics
SIToFPInst(
);
/// @brief Clone an identical SIToFPInst
- virtual CastInst *clone(LLVMContext &Context) const;
+ virtual SIToFPInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const SIToFPInst *) { return true; }
/// @brief This class represents a cast from floating point to unsigned integer
class FPToUIInst : public CastInst {
- FPToUIInst(const FPToUIInst &CI)
- : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
- }
public:
/// @brief Constructor with insert-before-instruction semantics
FPToUIInst(
);
/// @brief Clone an identical FPToUIInst
- virtual CastInst *clone(LLVMContext &Context) const;
+ virtual FPToUIInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FPToUIInst *) { return true; }
/// @brief This class represents a cast from floating point to signed integer.
class FPToSIInst : public CastInst {
- FPToSIInst(const FPToSIInst &CI)
- : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
- }
public:
/// @brief Constructor with insert-before-instruction semantics
FPToSIInst(
);
/// @brief Clone an identical FPToSIInst
- virtual CastInst *clone(LLVMContext &Context) const;
+ virtual FPToSIInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FPToSIInst *) { return true; }
/// @brief This class represents a cast from an integer to a pointer.
class IntToPtrInst : public CastInst {
- IntToPtrInst(const IntToPtrInst &CI)
- : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
- }
public:
/// @brief Constructor with insert-before-instruction semantics
IntToPtrInst(
);
/// @brief Clone an identical IntToPtrInst
- virtual CastInst *clone(LLVMContext &Context) const;
+ virtual IntToPtrInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const IntToPtrInst *) { return true; }
/// @brief This class represents a cast from a pointer to an integer
class PtrToIntInst : public CastInst {
- PtrToIntInst(const PtrToIntInst &CI)
- : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
- }
public:
/// @brief Constructor with insert-before-instruction semantics
PtrToIntInst(
);
/// @brief Clone an identical PtrToIntInst
- virtual CastInst *clone(LLVMContext &Context) const;
+ virtual PtrToIntInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const PtrToIntInst *) { return true; }
/// @brief This class represents a no-op cast from one type to another.
class BitCastInst : public CastInst {
- BitCastInst(const BitCastInst &CI)
- : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
- }
public:
/// @brief Constructor with insert-before-instruction semantics
BitCastInst(
);
/// @brief Clone an identical BitCastInst
- virtual CastInst *clone(LLVMContext &Context) const;
+ virtual BitCastInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const BitCastInst *) { return true; }