#ifndef LLVM_INSTRUCTIONS_H
#define LLVM_INSTRUCTIONS_H
-#include <iterator>
-
#include "llvm/InstrTypes.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Attributes.h"
#include "llvm/BasicBlock.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/SmallVector.h"
+#include <iterator>
namespace llvm {
class ConstantInt;
-class PointerType;
-class VectorType;
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(LLVMContext &Context) const;
- virtual AllocaInst *clone() 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
+ /// into the prolog/epilog code, so it is basically free.
+ bool isStaticAlloca() const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const AllocaInst *) { return true; }
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); }
const Value *getPointerOperand() const { return getOperand(0); }
public:
LoadInst(Value *Ptr, const std::string &NameStr, Instruction *InsertBefore);
LoadInst(Value *Ptr, const std::string &NameStr, BasicBlock *InsertAtEnd);
- LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile = false,
+ LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile = false,
Instruction *InsertBefore = 0);
LoadInst(Value *Ptr, const std::string &NameStr, bool isVolatile,
unsigned Align, Instruction *InsertBefore = 0);
bool isVolatile = false, Instruction *InsertBefore = 0);
LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
BasicBlock *InsertAtEnd);
-
+
/// isVolatile - Return true if this is a load from a volatile memory
/// location.
///
/// setVolatile - Specify whether this is a volatile load or not.
///
- void setVolatile(bool V) {
- SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
+ void setVolatile(bool V) {
+ 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
///
unsigned getAlignment() const {
return (1 << (SubclassData>>1)) >> 1;
}
-
+
void setAlignment(unsigned Align);
Value *getPointerOperand() { return getOperand(0); }
///
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
/// setVolatile - Specify whether this is a volatile load or not.
///
- void setVolatile(bool V) {
- SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
+ void setVolatile(bool V) {
+ SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
}
/// Transparently provide more efficient getOperand methods.
unsigned getAlignment() const {
return (1 << (SubclassData>>1)) >> 1;
}
-
+
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); }
// do arithmetic on in constant time
std::random_access_iterator_tag) {
unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
-
+
if (NumIdx > 0) {
// This requires that the iterator points to contiguous memory.
init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
///
template<typename InputIterator>
static const Type *getIndexedType(const Type *Ptr,
- InputIterator IdxBegin,
+ InputIterator IdxBegin,
InputIterator IdxEnd,
// This argument ensures that we
// have an iterator we can do
if (NumIdx > 0)
// This requires that the iterator points to contiguous memory.
- return getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx);
+ return getIndexedType(Ptr, &*IdxBegin, NumIdx);
else
return getIndexedType(Ptr, (Value *const*)0, NumIdx);
}
/// instruction, the second appends the new instruction to the specified
/// BasicBlock.
template<typename InputIterator>
- inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
+ inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
InputIterator IdxEnd,
unsigned Values,
const std::string &NameStr,
const std::string &NameStr, BasicBlock *InsertAtEnd);
public:
template<typename InputIterator>
- static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
+ static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
InputIterator IdxEnd,
const std::string &NameStr = "",
Instruction *InsertBefore = 0) {
- typename std::iterator_traits<InputIterator>::difference_type Values =
+ typename std::iterator_traits<InputIterator>::difference_type Values =
1 + std::distance(IdxBegin, IdxEnd);
return new(Values)
GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore);
InputIterator IdxBegin, InputIterator IdxEnd,
const std::string &NameStr,
BasicBlock *InsertAtEnd) {
- typename std::iterator_traits<InputIterator>::difference_type Values =
+ typename std::iterator_traits<InputIterator>::difference_type Values =
1 + std::distance(IdxBegin, IdxEnd);
return new(Values)
GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd);
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);
return getIndexedType(Ptr, IdxBegin, IdxEnd,
typename std::iterator_traits<InputIterator>::
iterator_category());
- }
+ }
static const Type *getIndexedType(const Type *Ptr,
Value* const *Idx, unsigned NumIdx);
return 0U; // get index for modifying correct operand
}
+ /// getPointerOperandType - Method to return the pointer operand as a
+ /// PointerType.
+ const PointerType *getPointerOperandType() const {
+ return reinterpret_cast<const PointerType*>(getPointerOperand()->getType());
+ }
+
+
unsigned getNumIndices() const { // Note: always non-negative
return getNumOperands() - 1;
}
bool hasIndices() const {
return getNumOperands() > 1;
}
-
+
/// hasAllZeroIndices - Return true if all of the indices of this GEP are
/// zeros. If so, the result pointer and the first operand have the same
/// value, just potentially different types.
bool hasAllZeroIndices() const;
-
+
/// hasAllConstantIndices - Return true if all of the indices of this GEP are
/// constant integers. If so, the result pointer and the first operand have
/// a constant offset between them.
bool hasAllConstantIndices() const;
-
+
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const GetElementPtrInst *) { return true; }
template<typename InputIterator>
GetElementPtrInst::GetElementPtrInst(Value *Ptr,
- InputIterator IdxBegin,
+ InputIterator IdxBegin,
InputIterator IdxEnd,
unsigned Values,
const std::string &NameStr,
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 &&
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() ||
+ assert((getOperand(0)->getType()->isIntOrIntVector() ||
isa<PointerType>(getOperand(0)->getType())) &&
"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");
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() ||
+ assert((getOperand(0)->getType()->isIntOrIntVector() ||
isa<PointerType>(getOperand(0)->getType())) &&
"Invalid operand types for ICmp instruction");
}
static bool isEquality(Predicate P) {
return P == ICMP_EQ || P == ICMP_NE;
}
-
+
/// isEquality - Return true if this predicate is either EQ or NE. This also
/// tests for commutativity.
bool isEquality() const {
/// @brief Determine if this relation is commutative.
bool isCommutative() const { return isEquality(); }
- /// isRelational - Return true if the predicate is relational (not EQ or NE).
+ /// isRelational - Return true if the predicate is relational (not EQ or NE).
///
bool isRelational() const {
return !isEquality();
}
- /// isRelational - Return true if the predicate is relational (not EQ or NE).
+ /// isRelational - Return true if the predicate is relational (not EQ or NE).
///
static bool isRelational(Predicate P) {
return !isEquality(P);
}
-
+
/// @returns true if the predicate of this ICmpInst is signed, false otherwise
/// @brief Determine if this instruction's predicate is signed.
bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
return isTrueWhenEqual(getPredicate());
}
- /// Initialize a set of values that all satisfy the predicate with C.
+ /// Initialize a set of values that all satisfy the predicate with C.
/// @brief Make a ConstantRange for a relation with a constant value.
static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
/// Exchange the two operands to this instruction in such a way that it does
/// not modify the semantics of the instruction. The predicate value may be
/// changed to retain the same result if the predicate is order dependent
- /// (e.g. ult).
+ /// (e.g. ult).
/// @brief Swap operands and adjust predicate.
void swapOperands() {
SubclassData = getSwappedPredicate();
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; }
//===----------------------------------------------------------------------===//
/// This instruction compares its operands according to the predicate given
-/// to the constructor. It only operates on floating point values or packed
+/// to the constructor. It only operates on floating point values or packed
/// vectors of floating point values. The operands must be identical types.
/// @brief Represents a floating point comparison operator.
class FCmpInst: public CmpInst {
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() &&
SubclassData == FCMP_UNO;
}
- /// @returns true if the predicate is relational (not EQ or NE).
+ /// @returns true if the predicate is relational (not EQ or NE).
/// @brief Determine if this a relational predicate.
bool isRelational() const { return !isEquality(); }
/// Exchange the two operands to this instruction in such a way that it does
/// not modify the semantics of the instruction. The predicate value may be
/// changed to retain the same result if the predicate is order dependent
- /// (e.g. ult).
+ /// (e.g. ult).
/// @brief Swap operands and adjust predicate.
void swapOperands() {
SubclassData = getSwappedPredicate();
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; }
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
-
-};
-//===----------------------------------------------------------------------===//
-// 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));
- }
};
//===----------------------------------------------------------------------===//
// do arithmetic on in constant time
std::random_access_iterator_tag) {
unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
-
+
// This requires that the iterator points to contiguous memory.
init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
setName(NameStr);
~CallInst();
- virtual CallInst *clone() const;
-
- /// Provide fast operand accessors
- DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
-
bool isTailCall() const { return SubclassData & 1; }
void setTailCall(bool isTC = true) {
SubclassData = (SubclassData & ~1) | unsigned(isTC);
}
+ virtual CallInst *clone(LLVMContext &Context) const;
+
+ /// Provide fast operand accessors
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
/// getCallingConv/setCallingConv - Get or set the calling convention of this
/// function call.
unsigned getCallingConv() const { return SubclassData >> 1; }
///
const AttrListPtr &getAttributes() const { return AttributeList; }
- /// setAttributes - Sets the parameter attributes for this call.
+ /// setAttributes - Set the parameter attributes for this call.
+ ///
void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
-
+
/// addAttribute - adds the attribute to the list of attributes.
void addAttribute(unsigned i, Attributes attr);
void removeAttribute(unsigned i, Attributes attr);
/// @brief Determine whether the call or the callee has the given attribute.
- bool paramHasAttr(unsigned i, unsigned attr) const;
+ bool paramHasAttr(unsigned i, Attributes attr) const;
/// @brief Extract the alignment for a call or parameter (0=unknown).
unsigned getParamAlignment(unsigned i) const {
/// @brief Determine if the call does not access memory.
bool doesNotAccessMemory() const {
- return paramHasAttr(0, Attribute::ReadNone);
+ return paramHasAttr(~0, Attribute::ReadNone);
}
void setDoesNotAccessMemory(bool NotAccessMemory = true) {
- if (NotAccessMemory) addAttribute(0, Attribute::ReadNone);
- else removeAttribute(0, Attribute::ReadNone);
+ if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
+ else removeAttribute(~0, Attribute::ReadNone);
}
/// @brief Determine if the call does not access or only reads memory.
bool onlyReadsMemory() const {
- return doesNotAccessMemory() || paramHasAttr(0, Attribute::ReadOnly);
+ return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
}
void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
- if (OnlyReadsMemory) addAttribute(0, Attribute::ReadOnly);
- else removeAttribute(0, Attribute::ReadOnly | Attribute::ReadNone);
+ if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
+ else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
}
/// @brief Determine if the call cannot return.
bool doesNotReturn() const {
- return paramHasAttr(0, Attribute::NoReturn);
+ return paramHasAttr(~0, Attribute::NoReturn);
}
void setDoesNotReturn(bool DoesNotReturn = true) {
- if (DoesNotReturn) addAttribute(0, Attribute::NoReturn);
- else removeAttribute(0, Attribute::NoReturn);
+ if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
+ else removeAttribute(~0, Attribute::NoReturn);
}
/// @brief Determine if the call cannot unwind.
bool doesNotThrow() const {
- return paramHasAttr(0, Attribute::NoUnwind);
+ return paramHasAttr(~0, Attribute::NoUnwind);
}
void setDoesNotThrow(bool DoesNotThrow = true) {
- if (DoesNotThrow) addAttribute(0, Attribute::NoUnwind);
- else removeAttribute(0, Attribute::NoUnwind);
+ if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
+ else removeAttribute(~0, Attribute::NoUnwind);
}
- /// @brief Determine if the call returns a structure through first
+ /// @brief Determine if the call returns a structure through first
/// pointer argument.
bool hasStructRetAttr() const {
// Be friendly and also check the callee.
return AttributeList.hasAttrSomewhere(Attribute::ByVal);
}
- /// getCalledFunction - Return the function being called by this instruction
- /// if it is a direct call. If it is a call through a function pointer,
- /// return null.
+ /// getCalledFunction - Return the function called, or null if this is an
+ /// 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
+ /// 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; }
Instruction::Call,
OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
(unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) {
- init(Func, ArgBegin, ArgEnd, NameStr,
+ init(Func, ArgBegin, ArgEnd, NameStr,
typename std::iterator_traits<InputIterator>::iterator_category());
}
///
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;
Value *getTrueValue() const { return Op<1>(); }
Value *getFalseValue() const { return Op<2>(); }
+ /// areInvalidOperands - Return a string if the specified operands are invalid
+ /// for a select operation, otherwise return null.
+ static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
+
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
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);
class InsertElementInst : public Instruction {
InsertElementInst(const InsertElementInst &IE);
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);
+ 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.
///
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
-
+
/// getMaskValue - Return the index from the shuffle mask for the specified
/// output result. This is either -1 if the element is undef or a number less
/// than 2*numelements.
// do arithmetic on in constant time
std::random_access_iterator_tag) {
unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
-
+
// There's no fundamental reason why we require at least one index
// (other than weirdness with &*IdxBegin being invalid; see
// getelementptr's init routine for example). But there's no
template<typename InputIterator>
static const Type *getIndexedType(const Type *Ptr,
- InputIterator IdxBegin,
+ InputIterator IdxBegin,
InputIterator IdxEnd,
// This argument ensures that we
// have an iterator we can do
/// an existing instruction, the second appends the new instruction to the
/// specified BasicBlock.
template<typename InputIterator>
- inline ExtractValueInst(Value *Agg, InputIterator IdxBegin,
+ inline ExtractValueInst(Value *Agg, InputIterator IdxBegin,
InputIterator IdxEnd,
const std::string &NameStr,
Instruction *InsertBefore);
public:
template<typename InputIterator>
- static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin,
+ static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin,
InputIterator IdxEnd,
const std::string &NameStr = "",
Instruction *InsertBefore = 0) {
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 getIndexedType(Ptr, IdxBegin, IdxEnd,
typename std::iterator_traits<InputIterator>::
iterator_category());
- }
+ }
static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
typedef const unsigned* idx_iterator;
bool hasIndices() const {
return true;
}
-
+
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ExtractValueInst *) { return true; }
static inline bool classof(const Instruction *I) {
template<typename InputIterator>
ExtractValueInst::ExtractValueInst(Value *Agg,
- InputIterator IdxBegin,
+ InputIterator IdxBegin,
InputIterator IdxEnd,
const std::string &NameStr,
Instruction *InsertBefore)
// do arithmetic on in constant time
std::random_access_iterator_tag) {
unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
-
+
// There's no fundamental reason why we require at least one index
// (other than weirdness with &*IdxBegin being invalid; see
// getelementptr's init routine for example). But there's no
/// optionally insert before an existing instruction, the second appends
/// the new instruction to the specified BasicBlock.
template<typename InputIterator>
- inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin,
+ inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin,
InputIterator IdxEnd,
const std::string &NameStr,
Instruction *InsertBefore);
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(); }
bool hasIndices() const {
return true;
}
-
+
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const InsertValueInst *) { return true; }
static inline bool classof(const Instruction *I) {
template<typename InputIterator>
InsertValueInst::InsertValueInst(Value *Agg,
Value *Val,
- InputIterator IdxBegin,
+ InputIterator IdxBegin,
InputIterator IdxEnd,
const std::string &NameStr,
Instruction *InsertBefore)
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
+ ///
+ template <typename U>
+ BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
+ assert(this == *I && "Iterator doesn't point to PHI's Uses?");
+ return static_cast<BasicBlock*>((&I.getUse() + 1)->get());
+ }
/// getIncomingBlock - Return incoming basic block number x
///
BasicBlock *getIncomingBlock(unsigned i) const {
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
///
struct OperandTraits<PHINode> : HungoffOperandTraits<2> {
};
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
//===----------------------------------------------------------------------===//
}
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!");
- return cast<BasicBlock>(getOperand(i));
+ 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)
/// constructor can also autoinsert before another instruction.
SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Instruction *InsertBefore = 0);
-
+
/// SwitchInst ctor - Create a new switch instruction, specifying a value to
/// switch on and a default destination. The number of additional cases can
/// be specified here to make memory allocation more efficient. This
///
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 {
struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> {
};
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
//===----------------------------------------------------------------------===//
// do arithmetic on in constant time
std::random_access_iterator_tag) {
unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
-
+
// This requires that the iterator points to contiguous memory.
init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
setName(NameStr);
Values, NameStr, InsertAtEnd);
}
- virtual InvokeInst *clone() const;
+ virtual InvokeInst *clone(LLVMContext &Context) const;
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
-
+
/// getCallingConv/setCallingConv - Get or set the calling convention of this
/// function call.
unsigned getCallingConv() const { return SubclassData; }
///
void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
- /// @brief Determine whether the call or the callee has the given attribute.
- bool paramHasAttr(unsigned i, Attributes attr) const;
-
/// addAttribute - adds the attribute to the list of attributes.
void addAttribute(unsigned i, Attributes attr);
/// removeAttribute - removes the attribute from the list of attributes.
void removeAttribute(unsigned i, Attributes attr);
+ /// @brief Determine whether the call or the callee has the given attribute.
+ bool paramHasAttr(unsigned i, Attributes attr) const;
+
/// @brief Extract the alignment for a call or parameter (0=unknown).
unsigned getParamAlignment(unsigned i) const {
return AttributeList.getParamAlignment(i);
return paramHasAttr(0, Attribute::ReadNone);
}
void setDoesNotAccessMemory(bool NotAccessMemory = true) {
- if (NotAccessMemory) addAttribute(0, Attribute::ReadNone);
- else removeAttribute(0, Attribute::ReadNone);
+ if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
+ else removeAttribute(~0, Attribute::ReadNone);
}
/// @brief Determine if the call does not access or only reads memory.
bool onlyReadsMemory() const {
- return doesNotAccessMemory() || paramHasAttr(0, Attribute::ReadOnly);
+ return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
}
void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
- if (OnlyReadsMemory) addAttribute(0, Attribute::ReadOnly);
- else removeAttribute(0, Attribute::ReadOnly | Attribute::ReadNone);
+ if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
+ else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
}
/// @brief Determine if the call cannot return.
bool doesNotReturn() const {
- return paramHasAttr(0, Attribute::NoReturn);
+ return paramHasAttr(~0, Attribute::NoReturn);
}
void setDoesNotReturn(bool DoesNotReturn = true) {
- if (DoesNotReturn) addAttribute(0, Attribute::NoReturn);
- else removeAttribute(0, Attribute::NoReturn);
+ if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
+ else removeAttribute(~0, Attribute::NoReturn);
}
/// @brief Determine if the call cannot unwind.
bool doesNotThrow() const {
- return paramHasAttr(0, Attribute::NoUnwind);
+ return paramHasAttr(~0, Attribute::NoUnwind);
}
void setDoesNotThrow(bool DoesNotThrow = true) {
- if (DoesNotThrow) addAttribute(0, Attribute::NoUnwind);
- else removeAttribute(0, Attribute::NoUnwind);
+ if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
+ else removeAttribute(~0, Attribute::NoUnwind);
}
- /// @brief Determine if the call returns a structure through first
+ /// @brief Determine if the call returns a structure through first
/// pointer argument.
bool hasStructRetAttr() const {
// Be friendly and also check the callee.
return paramHasAttr(1, Attribute::StructRet);
}
+ /// @brief Determine if any call argument is an aggregate passed by value.
+ bool hasByValArgument() const {
+ return AttributeList.hasAttrSomewhere(Attribute::ByVal);
+ }
+
/// getCalledFunction - Return the function called, or null if this is an
/// indirect function invocation.
///
return dyn_cast<Function>(getOperand(0));
}
- // getCalledValue - Get a pointer to a function that is invoked by this inst.
- Value *getCalledValue() const { return getOperand(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); }
// get*Dest - Return the destination basic blocks...
BasicBlock *getNormalDest() const {
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; }