X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=include%2Fllvm%2FInstructions.h;h=63a3dc0212bb5b251d97da0682e832aa5b41662e;hb=104cf9e02b0ed94d4173869a598af6c6972a8660;hp=1406b93357f5e7ace615023a2cc4f59cbdac1cda;hpb=0598866c052147c31b808391f58434ce3dbfb838;p=oota-llvm.git diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 1406b93357f..63a3dc0212b 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -16,21 +16,20 @@ #ifndef LLVM_INSTRUCTIONS_H #define LLVM_INSTRUCTIONS_H -#include - #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 namespace llvm { class ConstantInt; -class PointerType; -class VectorType; class ConstantRange; class APInt; +class LLVMContext; //===----------------------------------------------------------------------===// // AllocationInst Class @@ -41,10 +40,12 @@ class APInt; /// 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(); @@ -54,7 +55,7 @@ public: /// 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); } @@ -77,7 +78,7 @@ public: 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; } @@ -103,26 +104,31 @@ public: 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; } @@ -144,11 +150,14 @@ public: 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) {} @@ -159,14 +168,23 @@ public: 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; } @@ -191,8 +209,8 @@ public: 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); } @@ -230,7 +248,7 @@ class LoadInst : public UnaryInstruction { 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); @@ -245,7 +263,7 @@ public: 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. /// @@ -253,18 +271,18 @@ public: /// 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); } @@ -290,14 +308,14 @@ public: /// 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 @@ -326,8 +344,8 @@ public: /// 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. @@ -338,10 +356,10 @@ public: 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); } @@ -391,7 +409,7 @@ class GetElementPtrInst : public Instruction { // do arithmetic on in constant time std::random_access_iterator_tag) { unsigned NumIdx = static_cast(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 @@ -410,7 +428,7 @@ class GetElementPtrInst : public Instruction { /// template static const Type *getIndexedType(const Type *Ptr, - InputIterator IdxBegin, + InputIterator IdxBegin, InputIterator IdxEnd, // This argument ensures that we // have an iterator we can do @@ -420,7 +438,7 @@ class GetElementPtrInst : public Instruction { 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); } @@ -430,7 +448,7 @@ class GetElementPtrInst : public Instruction { /// instruction, the second appends the new instruction to the specified /// BasicBlock. template - inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, + inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd, unsigned Values, const std::string &NameStr, @@ -449,11 +467,11 @@ class GetElementPtrInst : public Instruction { const std::string &NameStr, BasicBlock *InsertAtEnd); public: template - 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::difference_type Values = + typename std::iterator_traits::difference_type Values = 1 + std::distance(IdxBegin, IdxEnd); return new(Values) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore); @@ -463,7 +481,7 @@ public: InputIterator IdxBegin, InputIterator IdxEnd, const std::string &NameStr, BasicBlock *InsertAtEnd) { - typename std::iterator_traits::difference_type Values = + typename std::iterator_traits::difference_type Values = 1 + std::distance(IdxBegin, IdxEnd); return new(Values) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd); @@ -482,7 +500,7 @@ public: 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); @@ -505,7 +523,7 @@ public: return getIndexedType(Ptr, IdxBegin, IdxEnd, typename std::iterator_traits:: iterator_category()); - } + } static const Type *getIndexedType(const Type *Ptr, Value* const *Idx, unsigned NumIdx); @@ -530,6 +548,13 @@ public: 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(getPointerOperand()->getType()); + } + + unsigned getNumIndices() const { // Note: always non-negative return getNumOperands() - 1; } @@ -537,17 +562,16 @@ public: 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; } @@ -565,7 +589,7 @@ struct OperandTraits : VariadicOperandTraits<1> { template GetElementPtrInst::GetElementPtrInst(Value *Ptr, - InputIterator IdxBegin, + InputIterator IdxBegin, InputIterator IdxEnd, unsigned Values, const std::string &NameStr, @@ -616,12 +640,12 @@ class ICmpInst: public CmpInst { 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->getContext().makeCmpResultType(LHS->getType()), Instruction::ICmp, pred, LHS, RHS, NameStr, InsertBefore) { assert(pred >= CmpInst::FIRST_ICMP_PREDICATE && @@ -630,28 +654,48 @@ public: 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(getOperand(0)->getType())) && + "Invalid operand types for ICmp instruction"); + } + + /// @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(getOperand(0)->getType())) && "Invalid operand types for ICmp instruction"); } - /// @brief Constructor with insert-at-block-end semantics. + /// @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(getOperand(0)->getType())) && "Invalid operand types for ICmp instruction"); } @@ -685,7 +729,7 @@ public: 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 { @@ -696,18 +740,18 @@ public: /// @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()); } @@ -732,21 +776,21 @@ public: 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; } @@ -764,19 +808,19 @@ public: //===----------------------------------------------------------------------===// /// 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->getContext().makeCmpResultType(LHS->getType()), Instruction::FCmp, pred, LHS, RHS, NameStr, InsertBefore) { assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && @@ -787,17 +831,35 @@ public: 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() && @@ -824,21 +886,21 @@ public: 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; } @@ -848,119 +910,7 @@ public: static inline bool classof(const Value *V) { return isa(V) && classof(cast(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(V) && classof(cast(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(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(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(V) && classof(cast(V)); - } }; //===----------------------------------------------------------------------===// @@ -987,7 +937,7 @@ class CallInst : public Instruction { // 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); @@ -1056,16 +1006,16 @@ public: ~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; } @@ -1077,9 +1027,10 @@ public: /// 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); @@ -1087,7 +1038,7 @@ public: 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 { @@ -1096,41 +1047,41 @@ public: /// @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. @@ -1142,17 +1093,17 @@ public: 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(getOperand(0)); + return dyn_cast(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; } @@ -1188,7 +1139,7 @@ CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, Instruction::Call, OperandTraits::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::iterator_category()); } @@ -1202,6 +1153,7 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value) /// class SelectInst : public Instruction { void init(Value *C, Value *S1, Value *S2) { + assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select"); Op<0>() = C; Op<1>() = S1; Op<2>() = S2; @@ -1241,6 +1193,10 @@ public: 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); @@ -1248,7 +1204,7 @@ public: return static_cast(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; } @@ -1288,7 +1244,7 @@ public: 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; } @@ -1321,18 +1277,14 @@ public: } 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); @@ -1363,13 +1315,10 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, 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); @@ -1379,28 +1328,18 @@ public: 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. /// @@ -1452,7 +1391,7 @@ public: 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. /// @@ -1462,7 +1401,7 @@ public: /// 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. @@ -1506,7 +1445,7 @@ class ExtractValueInst : public UnaryInstruction { // do arithmetic on in constant time std::random_access_iterator_tag) { unsigned NumIdx = static_cast(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 @@ -1529,7 +1468,7 @@ class ExtractValueInst : public UnaryInstruction { template static const Type *getIndexedType(const Type *Ptr, - InputIterator IdxBegin, + InputIterator IdxBegin, InputIterator IdxEnd, // This argument ensures that we // have an iterator we can do @@ -1549,7 +1488,7 @@ class ExtractValueInst : public UnaryInstruction { /// an existing instruction, the second appends the new instruction to the /// specified BasicBlock. template - inline ExtractValueInst(Value *Agg, InputIterator IdxBegin, + inline ExtractValueInst(Value *Agg, InputIterator IdxBegin, InputIterator IdxEnd, const std::string &NameStr, Instruction *InsertBefore); @@ -1565,7 +1504,7 @@ class ExtractValueInst : public UnaryInstruction { public: template - static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin, + static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin, InputIterator IdxEnd, const std::string &NameStr = "", Instruction *InsertBefore = 0) { @@ -1596,12 +1535,7 @@ public: 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(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. @@ -1616,7 +1550,7 @@ public: return getIndexedType(Ptr, IdxBegin, IdxEnd, typename std::iterator_traits:: iterator_category()); - } + } static const Type *getIndexedType(const Type *Ptr, unsigned Idx); typedef const unsigned* idx_iterator; @@ -1640,7 +1574,7 @@ public: 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) { @@ -1653,7 +1587,7 @@ public: template ExtractValueInst::ExtractValueInst(Value *Agg, - InputIterator IdxBegin, + InputIterator IdxBegin, InputIterator IdxEnd, const std::string &NameStr, Instruction *InsertBefore) @@ -1701,7 +1635,7 @@ class InsertValueInst : public Instruction { // do arithmetic on in constant time std::random_access_iterator_tag) { unsigned NumIdx = static_cast(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 @@ -1718,7 +1652,7 @@ class InsertValueInst : public Instruction { /// optionally insert before an existing instruction, the second appends /// the new instruction to the specified BasicBlock. template - inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin, + inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin, InputIterator IdxEnd, const std::string &NameStr, Instruction *InsertBefore); @@ -1771,16 +1705,11 @@ public: 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(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(); } @@ -1812,7 +1741,7 @@ public: 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) { @@ -1830,7 +1759,7 @@ struct OperandTraits : FixedNumOperandTraits<2> { template InsertValueInst::InsertValueInst(Value *Agg, Value *Val, - InputIterator IdxBegin, + InputIterator IdxBegin, InputIterator IdxEnd, const std::string &NameStr, Instruction *InsertBefore) @@ -1905,7 +1834,7 @@ public: resizeOperands(NumValues*2); } - virtual PHINode *clone() const; + virtual PHINode *clone(LLVMContext &Context) const; /// Provide fast operand accessors DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); @@ -1924,10 +1853,22 @@ public: 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 + BasicBlock *getIncomingBlock(value_use_iterator I) const { + assert(this == *I && "Iterator doesn't point to PHI's Uses?"); + return static_cast((&I.getUse() + 1)->get()); + } /// getIncomingBlock - Return incoming basic block number x /// BasicBlock *getIncomingBlock(unsigned i) const { @@ -1936,9 +1877,13 @@ public: 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 /// @@ -2007,7 +1952,7 @@ template <> struct OperandTraits : HungoffOperandTraits<2> { }; -DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value) +DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value) //===----------------------------------------------------------------------===// @@ -2048,7 +1993,7 @@ public: } virtual ~ReturnInst(); - virtual ReturnInst *clone() const; + virtual ReturnInst *clone(LLVMContext &Context) const; /// Provide fast operand accessors DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); @@ -2091,8 +2036,9 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, 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): @@ -2110,52 +2056,50 @@ class BranchInst : public TerminatorInst { 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(); } } @@ -2163,12 +2107,12 @@ public: BasicBlock *getSuccessor(unsigned i) const { assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); - return cast(getOperand(i)); + return cast_or_null((&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: @@ -2186,11 +2130,7 @@ private: }; template <> -struct OperandTraits : 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 : VariadicOperandTraits<1> {}; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value) @@ -2221,7 +2161,7 @@ class SwitchInst : public TerminatorInst { /// 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 @@ -2305,7 +2245,7 @@ public: /// 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 { @@ -2342,7 +2282,7 @@ template <> struct OperandTraits : HungoffOperandTraits<2> { }; -DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value) +DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value) //===----------------------------------------------------------------------===// @@ -2366,7 +2306,7 @@ class InvokeInst : public TerminatorInst { // 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); @@ -2419,11 +2359,11 @@ public: 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; } @@ -2439,15 +2379,15 @@ public: /// 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); @@ -2455,47 +2395,52 @@ public: /// @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 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. /// @@ -2503,8 +2448,10 @@ public: return dyn_cast(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 { @@ -2600,7 +2547,7 @@ public: explicit UnwindInst(Instruction *InsertBefore = 0); explicit UnwindInst(BasicBlock *InsertAtEnd); - virtual UnwindInst *clone() const; + virtual UnwindInst *clone(LLVMContext &Context) const; unsigned getNumSuccessors() const { return 0; } @@ -2637,7 +2584,7 @@ public: explicit UnreachableInst(Instruction *InsertBefore = 0); explicit UnreachableInst(BasicBlock *InsertAtEnd); - virtual UnreachableInst *clone() const; + virtual UnreachableInst *clone(LLVMContext &Context) const; unsigned getNumSuccessors() const { return 0; } @@ -2683,7 +2630,7 @@ public: ); /// @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; } @@ -2723,7 +2670,7 @@ public: ); /// @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; } @@ -2763,7 +2710,7 @@ public: ); /// @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; } @@ -2802,7 +2749,7 @@ public: ); /// @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; } @@ -2841,7 +2788,7 @@ public: ); /// @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; } @@ -2880,7 +2827,7 @@ public: ); /// @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; } @@ -2919,7 +2866,7 @@ public: ); /// @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; } @@ -2958,7 +2905,7 @@ public: ); /// @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; } @@ -2997,7 +2944,7 @@ public: ); /// @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; } @@ -3036,7 +2983,7 @@ public: ); /// @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; } @@ -3075,7 +3022,7 @@ public: ); /// @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; } @@ -3114,7 +3061,7 @@ public: ); /// @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; }