#include "llvm/DerivedTypes.h"
#include "llvm/Attributes.h"
#include "llvm/BasicBlock.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/SmallVector.h"
#include <iterator>
class ConstantInt;
class ConstantRange;
class APInt;
+class LLVMContext;
//===----------------------------------------------------------------------===//
// AllocationInst Class
///
class AllocationInst : public UnaryInstruction {
protected:
- AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
- const std::string &Name = "", Instruction *InsertBefore = 0);
- AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
- const std::string &Name, BasicBlock *InsertAtEnd);
+ AllocationInst(const Type *Ty, Value *ArraySize,
+ unsigned iTy, unsigned Align, const std::string &Name = "",
+ Instruction *InsertBefore = 0);
+ AllocationInst(const Type *Ty, Value *ArraySize,
+ unsigned iTy, unsigned Align, const std::string &Name,
+ BasicBlock *InsertAtEnd);
public:
// Out of line virtual method, so the vtable, etc. has a home.
virtual ~AllocationInst();
///
bool isArrayAllocation() const;
- /// getArraySize - Get the number of element allocated, for a simple
+ /// getArraySize - Get the number of elements allocated. For a simple
/// allocation of a single element, this will return a constant 1 value.
///
const Value *getArraySize() const { return getOperand(0); }
unsigned getAlignment() const { return (1u << SubclassData) >> 1; }
void setAlignment(unsigned Align);
- virtual Instruction *clone() const = 0;
+ virtual Instruction *clone(LLVMContext &Context) const = 0;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const AllocationInst *) { return true; }
explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
const std::string &NameStr = "",
Instruction *InsertBefore = 0)
- : AllocationInst(Ty, ArraySize, Malloc, 0, NameStr, InsertBefore) {}
- MallocInst(const Type *Ty, Value *ArraySize, const std::string &NameStr,
- BasicBlock *InsertAtEnd)
+ : AllocationInst(Ty, ArraySize, Malloc,
+ 0, NameStr, InsertBefore) {}
+ MallocInst(const Type *Ty, Value *ArraySize,
+ const std::string &NameStr, BasicBlock *InsertAtEnd)
: AllocationInst(Ty, ArraySize, Malloc, 0, NameStr, InsertAtEnd) {}
MallocInst(const Type *Ty, const std::string &NameStr,
Instruction *InsertBefore = 0)
: AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertBefore) {}
- MallocInst(const Type *Ty, const std::string &NameStr, BasicBlock *InsertAtEnd)
+ MallocInst(const Type *Ty, const std::string &NameStr,
+ BasicBlock *InsertAtEnd)
: AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertAtEnd) {}
- MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
- const std::string &NameStr, BasicBlock *InsertAtEnd)
- : AllocationInst(Ty, ArraySize, Malloc, Align, NameStr, InsertAtEnd) {}
- MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
- const std::string &NameStr = "",
- Instruction *InsertBefore = 0)
- : AllocationInst(Ty, ArraySize, Malloc, Align, NameStr, InsertBefore) {}
+ MallocInst(const Type *Ty, Value *ArraySize,
+ unsigned Align, const std::string &NameStr,
+ BasicBlock *InsertAtEnd)
+ : AllocationInst(Ty, ArraySize, Malloc,
+ Align, NameStr, InsertAtEnd) {}
+ MallocInst(const Type *Ty, Value *ArraySize,
+ unsigned Align, const std::string &NameStr = "",
+ Instruction *InsertBefore = 0)
+ : AllocationInst(Ty, ArraySize,
+ Malloc, Align, NameStr, InsertBefore) {}
- virtual MallocInst *clone() const;
+ virtual MallocInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MallocInst *) { return true; }
class AllocaInst : public AllocationInst {
AllocaInst(const AllocaInst &);
public:
- explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
+ explicit AllocaInst(const Type *Ty,
+ Value *ArraySize = 0,
const std::string &NameStr = "",
Instruction *InsertBefore = 0)
- : AllocationInst(Ty, ArraySize, Alloca, 0, NameStr, InsertBefore) {}
- AllocaInst(const Type *Ty, Value *ArraySize, const std::string &NameStr,
+ : AllocationInst(Ty, ArraySize, Alloca,
+ 0, NameStr, InsertBefore) {}
+ AllocaInst(const Type *Ty,
+ Value *ArraySize, const std::string &NameStr,
BasicBlock *InsertAtEnd)
: AllocationInst(Ty, ArraySize, Alloca, 0, NameStr, InsertAtEnd) {}
BasicBlock *InsertAtEnd)
: AllocationInst(Ty, 0, Alloca, 0, NameStr, InsertAtEnd) {}
- AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
- const std::string &NameStr = "", Instruction *InsertBefore = 0)
- : AllocationInst(Ty, ArraySize, Alloca, Align, NameStr, InsertBefore) {}
- AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
- const std::string &NameStr, BasicBlock *InsertAtEnd)
- : AllocationInst(Ty, ArraySize, Alloca, Align, NameStr, InsertAtEnd) {}
+ AllocaInst(const Type *Ty, Value *ArraySize,
+ unsigned Align, const std::string &NameStr = "",
+ Instruction *InsertBefore = 0)
+ : AllocationInst(Ty, ArraySize, Alloca,
+ Align, NameStr, InsertBefore) {}
+ AllocaInst(const Type *Ty, Value *ArraySize,
+ unsigned Align, const std::string &NameStr,
+ BasicBlock *InsertAtEnd)
+ : AllocationInst(Ty, ArraySize, Alloca,
+ Align, NameStr, InsertAtEnd) {}
- virtual AllocaInst *clone() const;
+ virtual AllocaInst *clone(LLVMContext &Context) const;
/// isStaticAlloca - Return true if this alloca is in the entry block of the
/// function and is a constant size. If so, the code generator will fold it
explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
FreeInst(Value *Ptr, BasicBlock *InsertAfter);
- virtual FreeInst *clone() const;
+ virtual FreeInst *clone(LLVMContext &Context) const;
// Accessor methods for consistency with other memory operations
Value *getPointerOperand() { return getOperand(0); }
SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
}
- virtual LoadInst *clone() const;
+ virtual LoadInst *clone(LLVMContext &Context) const;
/// getAlignment - Return the alignment of the access that is being performed
///
void setAlignment(unsigned Align);
- virtual StoreInst *clone() const;
+ virtual StoreInst *clone(LLVMContext &Context) const;
Value *getPointerOperand() { return getOperand(1); }
const Value *getPointerOperand() const { return getOperand(1); }
return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
}
- virtual GetElementPtrInst *clone() const;
+ virtual GetElementPtrInst *clone(LLVMContext &Context) const;
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
public:
/// @brief Constructor with insert-before-instruction semantics.
ICmpInst(
+ Instruction *InsertBefore, ///< Where to insert
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
- const std::string &NameStr = "", ///< Name of the instruction
- Instruction *InsertBefore = 0 ///< Where to insert
- ) : CmpInst(makeCmpResultType(LHS->getType()),
+ const std::string &NameStr = "" ///< Name of the instruction
+ ) : CmpInst(InsertBefore->getParent()->getContext()->
+ makeCmpResultType(LHS->getType()),
Instruction::ICmp, pred, LHS, RHS, NameStr,
InsertBefore) {
assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
"Invalid operand types for ICmp instruction");
}
- /// @brief Constructor with insert-at-block-end semantics.
+ /// @brief Constructor with insert-at-end semantics.
+ ICmpInst(
+ BasicBlock &InsertAtEnd, ///< Block to insert into.
+ 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
+ const std::string &NameStr = "" ///< Name of the instruction
+ ) : CmpInst(InsertAtEnd.getContext()->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!");
+ // Check that the operands are the right type
+ assert((getOperand(0)->getType()->isIntOrIntVector() ||
+ isa<PointerType>(getOperand(0)->getType())) &&
+ "Invalid operand types for ICmp instruction");
+ }
+
+ /// @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
- const std::string &NameStr, ///< Name of the instruction
- BasicBlock *InsertAtEnd ///< Block to insert into.
- ) : CmpInst(makeCmpResultType(LHS->getType()),
- Instruction::ICmp, pred, LHS, RHS, NameStr,
- InsertAtEnd) {
+ const std::string &NameStr = "" ///< Name of the instruction
+ ) : CmpInst(Context.makeCmpResultType(LHS->getType()),
+ Instruction::ICmp, pred, LHS, RHS, NameStr) {
assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
pred <= CmpInst::LAST_ICMP_PREDICATE &&
"Invalid ICmp predicate value");
Op<0>().swap(Op<1>());
}
- virtual ICmpInst *clone() const;
+ virtual ICmpInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ICmpInst *) { return true; }
public:
/// @brief Constructor with insert-before-instruction semantics.
FCmpInst(
+ Instruction *InsertBefore, ///< Where to insert
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
- const std::string &NameStr = "", ///< Name of the instruction
- Instruction *InsertBefore = 0 ///< Where to insert
- ) : CmpInst(makeCmpResultType(LHS->getType()),
+ const std::string &NameStr = "" ///< Name of the instruction
+ ) : CmpInst(InsertBefore->getParent()->getContext()->
+ makeCmpResultType(LHS->getType()),
Instruction::FCmp, pred, LHS, RHS, NameStr,
InsertBefore) {
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
assert(getOperand(0)->getType()->isFPOrFPVector() &&
"Invalid operand types for FCmp instruction");
}
+
+ /// @brief Constructor with insert-at-end semantics.
+ FCmpInst(
+ BasicBlock &InsertAtEnd, ///< Block to insert into.
+ 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
+ const std::string &NameStr = "" ///< Name of the instruction
+ ) : CmpInst(InsertAtEnd.getContext()->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!");
+ // Check that the operands are the right type
+ assert(getOperand(0)->getType()->isFPOrFPVector() &&
+ "Invalid operand types for FCmp instruction");
+ }
- /// @brief Constructor with insert-at-block-end semantics.
+ /// @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
- const std::string &NameStr, ///< Name of the instruction
- BasicBlock *InsertAtEnd ///< Block to insert into.
- ) : CmpInst(makeCmpResultType(LHS->getType()),
- Instruction::FCmp, pred, LHS, RHS, NameStr,
- InsertAtEnd) {
+ const std::string &NameStr = "" ///< Name of the instruction
+ ) : CmpInst(Context.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() &&
Op<0>().swap(Op<1>());
}
- virtual FCmpInst *clone() const;
+ virtual FCmpInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FCmpInst *) { return true; }
};
-//===----------------------------------------------------------------------===//
-// VICmpInst Class
-//===----------------------------------------------------------------------===//
-
-/// This instruction compares its operands according to the predicate given
-/// to the constructor. It only operates on vectors of integers.
-/// The operands must be identical types.
-/// @brief Represents a vector integer comparison operator.
-class VICmpInst: public CmpInst {
-public:
- /// @brief Constructor with insert-before-instruction semantics.
- VICmpInst(
- 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
- const std::string &NameStr = "", ///< Name of the instruction
- Instruction *InsertBefore = 0 ///< Where to insert
- ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, NameStr,
- InsertBefore) {
- assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
- pred <= CmpInst::LAST_ICMP_PREDICATE &&
- "Invalid VICmp predicate value");
- assert(getOperand(0)->getType() == getOperand(1)->getType() &&
- "Both operands to VICmp instruction are not of the same type!");
- }
-
- /// @brief Constructor with insert-at-block-end semantics.
- VICmpInst(
- 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
- const std::string &NameStr, ///< Name of the instruction
- BasicBlock *InsertAtEnd ///< Block to insert into.
- ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, NameStr,
- InsertAtEnd) {
- assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
- pred <= CmpInst::LAST_ICMP_PREDICATE &&
- "Invalid VICmp predicate value");
- assert(getOperand(0)->getType() == getOperand(1)->getType() &&
- "Both operands to VICmp instruction are not of the same type!");
- }
-
- /// @brief Return the predicate for this instruction.
- Predicate getPredicate() const { return Predicate(SubclassData); }
-
- virtual VICmpInst *clone() const;
-
- // Methods for support type inquiry through isa, cast, and dyn_cast:
- static inline bool classof(const VICmpInst *) { return true; }
- static inline bool classof(const Instruction *I) {
- return I->getOpcode() == Instruction::VICmp;
- }
- static inline bool classof(const Value *V) {
- return isa<Instruction>(V) && classof(cast<Instruction>(V));
- }
-};
-
-//===----------------------------------------------------------------------===//
-// VFCmpInst Class
-//===----------------------------------------------------------------------===//
-
-/// This instruction compares its operands according to the predicate given
-/// to the constructor. It only operates on vectors of floating point values.
-/// The operands must be identical types.
-/// @brief Represents a vector floating point comparison operator.
-class VFCmpInst: public CmpInst {
-public:
- /// @brief Constructor with insert-before-instruction semantics.
- VFCmpInst(
- 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
- const std::string &NameStr = "", ///< Name of the instruction
- Instruction *InsertBefore = 0 ///< Where to insert
- ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
- Instruction::VFCmp, pred, LHS, RHS, NameStr, InsertBefore) {
- assert(pred <= CmpInst::LAST_FCMP_PREDICATE &&
- "Invalid VFCmp predicate value");
- assert(getOperand(0)->getType() == getOperand(1)->getType() &&
- "Both operands to VFCmp instruction are not of the same type!");
- }
-
- /// @brief Constructor with insert-at-block-end semantics.
- VFCmpInst(
- 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
- const std::string &NameStr, ///< Name of the instruction
- BasicBlock *InsertAtEnd ///< Block to insert into.
- ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
- Instruction::VFCmp, pred, LHS, RHS, NameStr, InsertAtEnd) {
- assert(pred <= CmpInst::LAST_FCMP_PREDICATE &&
- "Invalid VFCmp predicate value");
- assert(getOperand(0)->getType() == getOperand(1)->getType() &&
- "Both operands to VFCmp instruction are not of the same type!");
- }
-
- /// @brief Return the predicate for this instruction.
- Predicate getPredicate() const { return Predicate(SubclassData); }
-
- virtual VFCmpInst *clone() const;
-
- /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
- static inline bool classof(const VFCmpInst *) { return true; }
- static inline bool classof(const Instruction *I) {
- return I->getOpcode() == Instruction::VFCmp;
- }
- static inline bool classof(const Value *V) {
- return isa<Instruction>(V) && classof(cast<Instruction>(V));
- }
-};
-
//===----------------------------------------------------------------------===//
// CallInst Class
//===----------------------------------------------------------------------===//
SubclassData = (SubclassData & ~1) | unsigned(isTC);
}
- virtual CallInst *clone() const;
+ virtual CallInst *clone(LLVMContext &Context) const;
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
/// indirect function invocation.
///
Function *getCalledFunction() const {
- return dyn_cast<Function>(getOperand(0));
+ return dyn_cast<Function>(Op<0>());
}
/// getCalledValue - Get a pointer to the function that is invoked by this
/// instruction
- const Value *getCalledValue() const { return getOperand(0); }
- Value *getCalledValue() { return getOperand(0); }
+ const Value *getCalledValue() const { return Op<0>(); }
+ Value *getCalledValue() { return Op<0>(); }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const CallInst *) { return true; }
return static_cast<OtherOps>(Instruction::getOpcode());
}
- virtual SelectInst *clone() const;
+ virtual SelectInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const SelectInst *) { return true; }
setName(NameStr);
}
- virtual VAArgInst *clone() const;
+ virtual VAArgInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const VAArgInst *) { return true; }
}
ExtractElementInst(Value *Vec, Value *Idx, const std::string &NameStr = "",
Instruction *InsertBefore = 0);
- ExtractElementInst(Value *Vec, unsigned Idx, const std::string &NameStr = "",
- Instruction *InsertBefore = 0);
ExtractElementInst(Value *Vec, Value *Idx, const std::string &NameStr,
BasicBlock *InsertAtEnd);
- ExtractElementInst(Value *Vec, unsigned Idx, const std::string &NameStr,
- BasicBlock *InsertAtEnd);
/// isValidOperands - Return true if an extractelement instruction can be
/// formed with the specified operands.
static bool isValidOperands(const Value *Vec, const Value *Idx);
- virtual ExtractElementInst *clone() const;
+ virtual ExtractElementInst *clone(LLVMContext &Context) const;
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
const std::string &NameStr = "",
Instruction *InsertBefore = 0);
- InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
- const std::string &NameStr = "",
- Instruction *InsertBefore = 0);
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
const std::string &NameStr, BasicBlock *InsertAtEnd);
- InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
- const std::string &NameStr, BasicBlock *InsertAtEnd);
public:
static InsertElementInst *Create(const InsertElementInst &IE) {
return new(IE.getNumOperands()) InsertElementInst(IE);
Instruction *InsertBefore = 0) {
return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
}
- static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
- const std::string &NameStr = "",
- Instruction *InsertBefore = 0) {
- return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
- }
static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
const std::string &NameStr,
BasicBlock *InsertAtEnd) {
return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
}
- static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
- const std::string &NameStr,
- BasicBlock *InsertAtEnd) {
- return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
- }
/// isValidOperands - Return true if an insertelement instruction can be
/// formed with the specified operands.
static bool isValidOperands(const Value *Vec, const Value *NewElt,
const Value *Idx);
- virtual InsertElementInst *clone() const;
+ virtual InsertElementInst *clone(LLVMContext &Context) const;
/// getType - Overload to return most specific vector type.
///
static bool isValidOperands(const Value *V1, const Value *V2,
const Value *Mask);
- virtual ShuffleVectorInst *clone() const;
+ virtual ShuffleVectorInst *clone(LLVMContext &Context) const;
/// getType - Overload to return most specific vector type.
///
return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
}
- virtual ExtractValueInst *clone() const;
-
- // getType - Overload to return most specific pointer type...
- const PointerType *getType() const {
- return reinterpret_cast<const PointerType*>(Instruction::getType());
- }
+ virtual ExtractValueInst *clone(LLVMContext &Context) const;
/// getIndexedType - Returns the type of the element that would be extracted
/// with an extractvalue instruction with the specified parameters.
return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
}
- virtual InsertValueInst *clone() const;
+ virtual InsertValueInst *clone(LLVMContext &Context) const;
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
- // getType - Overload to return most specific pointer type...
- const PointerType *getType() const {
- return reinterpret_cast<const PointerType*>(Instruction::getType());
- }
-
typedef const unsigned* idx_iterator;
inline idx_iterator idx_begin() const { return Indices.begin(); }
inline idx_iterator idx_end() const { return Indices.end(); }
resizeOperands(NumValues*2);
}
- virtual PHINode *clone() const;
+ virtual PHINode *clone(LLVMContext &Context) const;
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
assert(i*2 < getNumOperands() && "Invalid value number!");
setOperand(i*2, V);
}
- unsigned getOperandNumForIncomingValue(unsigned i) {
+ static unsigned getOperandNumForIncomingValue(unsigned i) {
return i*2;
}
+ static unsigned getIncomingValueNumForOperand(unsigned i) {
+ assert(i % 2 == 0 && "Invalid incoming-value operand index!");
+ return i/2;
+ }
/// getIncomingBlock - Return incoming basic block corresponding
/// to value use iterator
void setIncomingBlock(unsigned i, BasicBlock *BB) {
setOperand(i*2+1, BB);
}
- unsigned getOperandNumForIncomingBlock(unsigned i) {
+ static unsigned getOperandNumForIncomingBlock(unsigned i) {
return i*2+1;
}
+ static unsigned getIncomingBlockNumForOperand(unsigned i) {
+ assert(i % 2 == 1 && "Invalid incoming-block operand index!");
+ return i/2;
+ }
/// addIncoming - Add an incoming value to the end of the PHI list
///
}
virtual ~ReturnInst();
- virtual ReturnInst *clone() const;
+ virtual ReturnInst *clone(LLVMContext &Context) const;
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
///
class BranchInst : public TerminatorInst {
/// Ops list - Branches are strange. The operands are ordered:
- /// TrueDest, FalseDest, Cond. This makes some accessors faster because
- /// they don't have to check for cond/uncond branchness.
+ /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
+ /// they don't have to check for cond/uncond branchness. These are mostly
+ /// accessed relative from op_end().
BranchInst(const BranchInst &BI);
void AssertOK();
// BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
BasicBlock *InsertAtEnd);
public:
static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
- return new(1) BranchInst(IfTrue, InsertBefore);
+ return new(1, true) 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);
+ return new(1, true) BranchInst(IfTrue, InsertAtEnd);
}
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
Value *Cond, BasicBlock *InsertAtEnd) {
return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
}
- ~BranchInst() {
- if (NumOperands == 1)
- NumOperands = (unsigned)((Use*)this - OperandList);
- }
+ ~BranchInst();
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
- virtual BranchInst *clone() const;
+ virtual BranchInst *clone(LLVMContext &Context) const;
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 getOperand(2);
+ return Op<-3>();
}
void setCondition(Value *V) {
assert(isConditional() && "Cannot set condition of unconditional branch!");
- setOperand(2, V);
+ Op<-3>() = V;
}
// setUnconditionalDest - Change the current branch to an unconditional branch
// targeting the specified block.
// FIXME: Eliminate this ugly method.
void setUnconditionalDest(BasicBlock *Dest) {
- Op<0>() = Dest;
+ Op<-1>() = Dest;
if (isConditional()) { // Convert this to an uncond branch.
- Op<1>().set(0);
- Op<2>().set(0);
+ Op<-2>() = 0;
+ Op<-3>() = 0;
NumOperands = 1;
+ OperandList = op_begin();
}
}
BasicBlock *getSuccessor(unsigned i) const {
assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
- if (Value *V = getOperand(i))
- return cast<BasicBlock>(V);
- return 0;
+ return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
}
void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
- setOperand(idx, NewSucc);
+ *(&Op<-1>() - idx) = NewSucc;
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
};
template <>
-struct OperandTraits<BranchInst> : HungoffOperandTraits<> {
- // we need to access operands via OperandList, since
- // the NumOperands may change from 3 to 1
- static inline void *allocate(unsigned); // FIXME
-};
+struct OperandTraits<BranchInst> : VariadicOperandTraits<1> {};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
///
void removeCase(unsigned idx);
- virtual SwitchInst *clone() const;
+ virtual SwitchInst *clone(LLVMContext &Context) const;
unsigned getNumSuccessors() const { return getNumOperands()/2; }
BasicBlock *getSuccessor(unsigned idx) const {
Values, NameStr, InsertAtEnd);
}
- virtual InvokeInst *clone() const;
+ virtual InvokeInst *clone(LLVMContext &Context) const;
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
explicit UnwindInst(Instruction *InsertBefore = 0);
explicit UnwindInst(BasicBlock *InsertAtEnd);
- virtual UnwindInst *clone() const;
+ virtual UnwindInst *clone(LLVMContext &Context) const;
unsigned getNumSuccessors() const { return 0; }
explicit UnreachableInst(Instruction *InsertBefore = 0);
explicit UnreachableInst(BasicBlock *InsertAtEnd);
- virtual UnreachableInst *clone() const;
+ virtual UnreachableInst *clone(LLVMContext &Context) const;
unsigned getNumSuccessors() const { return 0; }
);
/// @brief Clone an identical TruncInst
- virtual CastInst *clone() const;
+ virtual CastInst *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 Clone an identical ZExtInst
- virtual CastInst *clone() const;
+ virtual CastInst *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 Clone an identical SExtInst
- virtual CastInst *clone() const;
+ virtual CastInst *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 Clone an identical FPTruncInst
- virtual CastInst *clone() const;
+ virtual CastInst *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 Clone an identical FPExtInst
- virtual CastInst *clone() const;
+ virtual CastInst *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 Clone an identical UIToFPInst
- virtual CastInst *clone() const;
+ virtual CastInst *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 Clone an identical SIToFPInst
- virtual CastInst *clone() const;
+ virtual CastInst *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 Clone an identical FPToUIInst
- virtual CastInst *clone() const;
+ virtual CastInst *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 Clone an identical FPToSIInst
- virtual CastInst *clone() const;
+ virtual CastInst *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 Clone an identical IntToPtrInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const IntToPtrInst *) { return true; }
);
/// @brief Clone an identical PtrToIntInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const PtrToIntInst *) { return true; }
);
/// @brief Clone an identical BitCastInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const BitCastInst *) { return true; }