diff options
author | Owen Anderson <resistor@mac.com> | 2009-07-09 23:48:35 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-07-09 23:48:35 +0000 |
commit | 6601fcdc38a21a39ac124f2bd8794846519b6455 (patch) | |
tree | bc6f5f739c43dec91104275aec30e16f30a7610e /include | |
parent | 1e3fe6c538ba7beac73bb4e1a6337da203a6f0f7 (diff) | |
download | external_llvm-6601fcdc38a21a39ac124f2bd8794846519b6455.zip external_llvm-6601fcdc38a21a39ac124f2bd8794846519b6455.tar.gz external_llvm-6601fcdc38a21a39ac124f2bd8794846519b6455.tar.bz2 |
This started as a small change, I swear. Unfortunately, lots of things call the [I|F]CmpInst constructors. Who knew!?
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75200 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/InstrTypes.h | 16 | ||||
-rw-r--r-- | include/llvm/Instruction.h | 4 | ||||
-rw-r--r-- | include/llvm/Instructions.h | 149 | ||||
-rw-r--r-- | include/llvm/LLVMContext.h | 4 | ||||
-rw-r--r-- | include/llvm/Support/IRBuilder.h | 4 |
5 files changed, 110 insertions, 67 deletions
diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index 0a018de..7682719 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -22,6 +22,8 @@ namespace llvm { +class LLVMContext; + //===----------------------------------------------------------------------===// // TerminatorInst Class //===----------------------------------------------------------------------===// @@ -50,7 +52,7 @@ protected: virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0; public: - virtual Instruction *clone() const = 0; + virtual Instruction *clone(LLVMContext &Context) const = 0; /// getNumSuccessors - Return the number of successors that this terminator /// has. @@ -235,7 +237,7 @@ public: return static_cast<BinaryOps>(Instruction::getOpcode()); } - virtual BinaryOperator *clone() const; + virtual BinaryOperator *clone(LLVMContext &Context) const; /// swapOperands - Exchange the two operands to this instruction. /// This instruction is safe to use on any binary instruction and @@ -569,7 +571,8 @@ public: /// instruction into a BasicBlock right before the specified instruction. /// The specified Instruction is allowed to be a dereferenced end iterator. /// @brief Create a CmpInst - static CmpInst *Create(OtherOps Op, unsigned short predicate, Value *S1, + static CmpInst *Create(LLVMContext &Context, OtherOps Op, + unsigned short predicate, Value *S1, Value *S2, const std::string &Name = "", Instruction *InsertBefore = 0); @@ -660,13 +663,6 @@ public: static inline bool classof(const Value *V) { return isa<Instruction>(V) && classof(cast<Instruction>(V)); } - /// @brief Create a result type for fcmp/icmp - static const Type* makeCmpResultType(const Type* opnd_type) { - if (const VectorType* vt = dyn_cast<const VectorType>(opnd_type)) { - return VectorType::get(Type::Int1Ty, vt->getNumElements()); - } - return Type::Int1Ty; - } }; diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h index 7d946e8..e06ae2d 100644 --- a/include/llvm/Instruction.h +++ b/include/llvm/Instruction.h @@ -20,6 +20,8 @@ namespace llvm { +class LLVMContext; + template<typename ValueSubClass, typename ItemParentClass> class SymbolTableListTraits; @@ -45,7 +47,7 @@ public: /// * The instruction has no parent /// * The instruction has no name /// - virtual Instruction *clone() const = 0; + virtual Instruction *clone(LLVMContext &Context) const = 0; /// isIdenticalTo - Return true if the specified instruction is exactly /// identical to the current one. This means that all operands match and any diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index aef77f0..5bd3066 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -20,6 +20,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/Attributes.h" #include "llvm/BasicBlock.h" +#include "llvm/LLVMContext.h" #include "llvm/ADT/SmallVector.h" #include <iterator> @@ -74,7 +75,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; } @@ -120,7 +121,7 @@ public: 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; } @@ -164,7 +165,7 @@ public: const std::string &NameStr, BasicBlock *InsertAtEnd) : AllocationInst(Ty, ArraySize, Alloca, Align, NameStr, InsertAtEnd) {} - virtual AllocaInst *clone() const; + virtual AllocaInst *clone(LLVMContext &Context) const; /// isStaticAlloca - Return true if this alloca is in the entry block of the /// function and is a constant size. If so, the code generator will fold it @@ -194,7 +195,7 @@ 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); } @@ -260,7 +261,7 @@ public: 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 /// @@ -344,7 +345,7 @@ public: 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); } @@ -485,7 +486,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); @@ -626,12 +627,13 @@ 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->getParent()->getContext()-> + makeCmpResultType(LHS->getType()), Instruction::ICmp, pred, LHS, RHS, NameStr, InsertBefore) { assert(pred >= CmpInst::FIRST_ICMP_PREDICATE && @@ -645,16 +647,36 @@ public: "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"); @@ -756,7 +778,7 @@ public: 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; } @@ -781,12 +803,13 @@ 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 && @@ -797,17 +820,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() && @@ -848,7 +889,7 @@ public: 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; } @@ -959,7 +1000,7 @@ public: SubclassData = (SubclassData & ~1) | unsigned(isTC); } - virtual CallInst *clone() const; + virtual CallInst *clone(LLVMContext &Context) const; /// Provide fast operand accessors DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); @@ -1152,7 +1193,7 @@ public: 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; } @@ -1192,7 +1233,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; } @@ -1236,7 +1277,7 @@ public: /// 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); @@ -1306,7 +1347,7 @@ public: 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. /// @@ -1358,7 +1399,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. /// @@ -1502,7 +1543,7 @@ public: return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd); } - virtual ExtractValueInst *clone() const; + 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. @@ -1672,7 +1713,7 @@ 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); @@ -1801,7 +1842,7 @@ public: resizeOperands(NumValues*2); } - virtual PHINode *clone() const; + virtual PHINode *clone(LLVMContext &Context) const; /// Provide fast operand accessors DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); @@ -1960,7 +2001,7 @@ public: } virtual ~ReturnInst(); - virtual ReturnInst *clone() const; + virtual ReturnInst *clone(LLVMContext &Context) const; /// Provide fast operand accessors DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); @@ -2042,7 +2083,7 @@ public: /// 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; } @@ -2212,7 +2253,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 { @@ -2326,7 +2367,7 @@ public: Values, NameStr, InsertAtEnd); } - virtual InvokeInst *clone() const; + virtual InvokeInst *clone(LLVMContext &Context) const; /// Provide fast operand accessors DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); @@ -2514,7 +2555,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; } @@ -2551,7 +2592,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; } @@ -2597,7 +2638,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; } @@ -2637,7 +2678,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; } @@ -2677,7 +2718,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; } @@ -2716,7 +2757,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; } @@ -2755,7 +2796,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; } @@ -2794,7 +2835,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; } @@ -2833,7 +2874,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; } @@ -2872,7 +2913,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; } @@ -2911,7 +2952,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; } @@ -2950,7 +2991,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; } @@ -2989,7 +3030,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; } @@ -3028,7 +3069,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; } diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h index 60da89e..75b7e59 100644 --- a/include/llvm/LLVMContext.h +++ b/include/llvm/LLVMContext.h @@ -213,6 +213,10 @@ public: VectorType* getVectorTypeInteger(const VectorType* VTy); VectorType* getVectorTypeExtendedElement(const VectorType* VTy); VectorType* getVectorTypeTruncatedElement(const VectorType* VTy); + + // Other helpers + /// @brief Create a result type for fcmp/icmp + const Type* makeCmpResultType(const Type* opnd_type); }; /// FOR BACKWARDS COMPATIBILITY - Returns a global context. diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index 0fe0c3c..fe794c6 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -565,14 +565,14 @@ public: if (Constant *LC = dyn_cast<Constant>(LHS)) if (Constant *RC = dyn_cast<Constant>(RHS)) return Folder.CreateICmp(P, LC, RC); - return Insert(new ICmpInst(P, LHS, RHS), Name); + return Insert(new ICmpInst(Context, P, LHS, RHS), Name); } Value *CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const char *Name = "") { if (Constant *LC = dyn_cast<Constant>(LHS)) if (Constant *RC = dyn_cast<Constant>(RHS)) return Folder.CreateFCmp(P, LC, RC); - return Insert(new FCmpInst(P, LHS, RHS), Name); + return Insert(new FCmpInst(Context, P, LHS, RHS), Name); } //===--------------------------------------------------------------------===// |