From a90b3dc2f1f70ab7102ec3f1fc57f199fd56d7cc Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Wed, 15 Jul 2009 21:51:10 +0000 Subject: [PATCH] Move a few more convenience factory functions from Constant to LLVMContext. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75840 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Constants.h | 10 --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 4 +- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 8 ++- .../SelectionDAG/SelectionDAGBuild.cpp | 2 +- lib/Target/CellSPU/SPUISelDAGToDAG.cpp | 3 +- lib/Target/X86/X86ISelLowering.cpp | 63 ++++++++++--------- lib/VMCore/Constants.cpp | 5 -- lib/VMCore/Instructions.cpp | 7 ++- lib/VMCore/LLVMContext.cpp | 11 ++-- 9 files changed, 57 insertions(+), 56 deletions(-) diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index 12777025c6d..e06ce1f1b9e 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -313,11 +313,6 @@ protected: public: /// get() - Static factory methods - Return objects of the specified value static Constant *get(const ArrayType *T, const std::vector &); - static Constant *get(const ArrayType *T, - Constant*const*Vals, unsigned NumVals) { - // FIXME: make this the primary ctor method. - return get(T, std::vector(Vals, Vals+NumVals)); - } /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); @@ -424,11 +419,6 @@ protected: public: /// get() - Static factory methods - Return objects of the specified value static Constant *get(const VectorType *T, const std::vector &); - static Constant *get(const std::vector &V); - static Constant *get(Constant*const* Vals, unsigned NumVals) { - // FIXME: make this the primary ctor method. - return get(std::vector(Vals, Vals+NumVals)); - } /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 632c9fd09df..4ff2a3adedb 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -19,6 +19,7 @@ #define DEBUG_TYPE "dagcombine" #include "llvm/CodeGen/SelectionDAG.h" #include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/PseudoSourceValue.h" @@ -5808,7 +5809,8 @@ SDValue DAGCombiner::SimplifySelectCC(DebugLoc DL, SDValue N0, SDValue N1, const TargetData &TD = *TLI.getTargetData(); // Create a ConstantArray of the two constants. - Constant *CA = ConstantArray::get(ArrayType::get(FPTy, 2), Elts, 2); + Constant *CA = DAG.getContext()->getConstantArray( + DAG.getContext()->getArrayType(FPTy, 2), Elts, 2); SDValue CPIdx = DAG.getConstantPool(CA, TLI.getPointerTy(), TD.getPrefTypeAlignment(FPTy)); unsigned Alignment = cast(CPIdx)->getAlignment(); diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 9343b965c42..410447b1b46 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -337,6 +337,7 @@ static SDValue ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, SelectionDAG &DAG, const TargetLowering &TLI) { bool Extend = false; DebugLoc dl = CFP->getDebugLoc(); + LLVMContext *Context = DAG.getContext(); // If a FP immediate is precise when represented as a float and if the // target can do an extending load from float to double, we put it into @@ -362,7 +363,7 @@ static SDValue ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, TLI.isLoadExtLegal(ISD::EXTLOAD, SVT) && TLI.ShouldShrinkFPConstant(OrigVT)) { const Type *SType = SVT.getTypeForMVT(*DAG.getContext()); - LLVMC = cast(ConstantExpr::getFPTrunc(LLVMC, SType)); + LLVMC = cast(Context->getConstantExprFPTrunc(LLVMC, SType)); VT = SVT; Extend = true; } @@ -1794,6 +1795,7 @@ SDValue SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) { /// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't /// support the operation, but do support the resultant vector type. SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { + LLVMContext *Context = DAG.getContext(); unsigned NumElems = Node->getNumOperands(); SDValue Value1, Value2; DebugLoc dl = Node->getDebugLoc(); @@ -1844,10 +1846,10 @@ SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { } else { assert(Node->getOperand(i).getOpcode() == ISD::UNDEF); const Type *OpNTy = OpVT.getTypeForMVT(*DAG.getContext()); - CV.push_back(UndefValue::get(OpNTy)); + CV.push_back(Context->getUndef(OpNTy)); } } - Constant *CP = ConstantVector::get(CV); + Constant *CP = Context->getConstantVector(CV); SDValue CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); unsigned Alignment = cast(CPIdx)->getAlignment(); return DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx, diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index 499939beac2..4b2ee0e854f 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -2140,7 +2140,7 @@ void SelectionDAGLowering::visitFSub(User &I) { const Type *ElTy = DestTy->getElementType(); unsigned VL = DestTy->getNumElements(); std::vector NZ(VL, Context->getConstantFPNegativeZero(ElTy)); - Constant *CNZ = ConstantVector::get(&NZ[0], NZ.size()); + Constant *CNZ = DAG.getContext()->getConstantVector(&NZ[0], NZ.size()); if (CV == CNZ) { SDValue Op2 = getValue(I.getOperand(1)); setValue(&I, DAG.getNode(ISD::FNEG, getCurDebugLoc(), diff --git a/lib/Target/CellSPU/SPUISelDAGToDAG.cpp b/lib/Target/CellSPU/SPUISelDAGToDAG.cpp index 8f704ecaa5b..97b16dd608d 100644 --- a/lib/Target/CellSPU/SPUISelDAGToDAG.cpp +++ b/lib/Target/CellSPU/SPUISelDAGToDAG.cpp @@ -30,6 +30,7 @@ #include "llvm/Constants.h" #include "llvm/GlobalValue.h" #include "llvm/Intrinsics.h" +#include "llvm/LLVMContext.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" @@ -305,7 +306,7 @@ namespace { CV.push_back(const_cast (V->getConstantIntValue())); } - Constant *CP = ConstantVector::get(CV); + Constant *CP = CurDAG->getContext()->getConstantVector(CV); SDValue CPIdx = CurDAG->getConstantPool(CP, SPUtli.getPointerTy()); unsigned Alignment = cast(CPIdx)->getAlignment(); SDValue CGPoolOffset = diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index a2fedaf924a..097713f0780 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -23,6 +23,7 @@ #include "llvm/GlobalVariable.h" #include "llvm/Function.h" #include "llvm/Intrinsics.h" +#include "llvm/LLVMContext.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/VectorExtras.h" #include "llvm/CodeGen/MachineFrameInfo.h" @@ -4880,20 +4881,23 @@ SDValue X86TargetLowering::LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG) { */ DebugLoc dl = Op.getDebugLoc(); + LLVMContext *Context = DAG.getContext(); // Build some magic constants. std::vector CV0; - CV0.push_back(ConstantInt::get(APInt(32, 0x45300000))); - CV0.push_back(ConstantInt::get(APInt(32, 0x43300000))); - CV0.push_back(ConstantInt::get(APInt(32, 0))); - CV0.push_back(ConstantInt::get(APInt(32, 0))); - Constant *C0 = ConstantVector::get(CV0); + CV0.push_back(Context->getConstantInt(APInt(32, 0x45300000))); + CV0.push_back(Context->getConstantInt(APInt(32, 0x43300000))); + CV0.push_back(Context->getConstantInt(APInt(32, 0))); + CV0.push_back(Context->getConstantInt(APInt(32, 0))); + Constant *C0 = Context->getConstantVector(CV0); SDValue CPIdx0 = DAG.getConstantPool(C0, getPointerTy(), 16); std::vector CV1; - CV1.push_back(ConstantFP::get(APFloat(APInt(64, 0x4530000000000000ULL)))); - CV1.push_back(ConstantFP::get(APFloat(APInt(64, 0x4330000000000000ULL)))); - Constant *C1 = ConstantVector::get(CV1); + CV1.push_back( + Context->getConstantFP(APFloat(APInt(64, 0x4530000000000000ULL)))); + CV1.push_back( + Context->getConstantFP(APFloat(APInt(64, 0x4330000000000000ULL)))); + Constant *C1 = Context->getConstantVector(CV1); SDValue CPIdx1 = DAG.getConstantPool(C1, getPointerTy(), 16); SDValue XR1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v4i32, @@ -5097,6 +5101,7 @@ SDValue X86TargetLowering::LowerFP_TO_UINT(SDValue Op, SelectionDAG &DAG) { } SDValue X86TargetLowering::LowerFABS(SDValue Op, SelectionDAG &DAG) { + LLVMContext *Context = DAG.getContext(); DebugLoc dl = Op.getDebugLoc(); MVT VT = Op.getValueType(); MVT EltVT = VT; @@ -5104,17 +5109,17 @@ SDValue X86TargetLowering::LowerFABS(SDValue Op, SelectionDAG &DAG) { EltVT = VT.getVectorElementType(); std::vector CV; if (EltVT == MVT::f64) { - Constant *C = ConstantFP::get(APFloat(APInt(64, ~(1ULL << 63)))); + Constant *C = Context->getConstantFP(APFloat(APInt(64, ~(1ULL << 63)))); CV.push_back(C); CV.push_back(C); } else { - Constant *C = ConstantFP::get(APFloat(APInt(32, ~(1U << 31)))); + Constant *C = Context->getConstantFP(APFloat(APInt(32, ~(1U << 31)))); CV.push_back(C); CV.push_back(C); CV.push_back(C); CV.push_back(C); } - Constant *C = ConstantVector::get(CV); + Constant *C = Context->getConstantVector(CV); SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16); SDValue Mask = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx, PseudoSourceValue::getConstantPool(), 0, @@ -5123,6 +5128,7 @@ SDValue X86TargetLowering::LowerFABS(SDValue Op, SelectionDAG &DAG) { } SDValue X86TargetLowering::LowerFNEG(SDValue Op, SelectionDAG &DAG) { + LLVMContext *Context = DAG.getContext(); DebugLoc dl = Op.getDebugLoc(); MVT VT = Op.getValueType(); MVT EltVT = VT; @@ -5133,17 +5139,17 @@ SDValue X86TargetLowering::LowerFNEG(SDValue Op, SelectionDAG &DAG) { } std::vector CV; if (EltVT == MVT::f64) { - Constant *C = ConstantFP::get(APFloat(APInt(64, 1ULL << 63))); + Constant *C = Context->getConstantFP(APFloat(APInt(64, 1ULL << 63))); CV.push_back(C); CV.push_back(C); } else { - Constant *C = ConstantFP::get(APFloat(APInt(32, 1U << 31))); + Constant *C = Context->getConstantFP(APFloat(APInt(32, 1U << 31))); CV.push_back(C); CV.push_back(C); CV.push_back(C); CV.push_back(C); } - Constant *C = ConstantVector::get(CV); + Constant *C = Context->getConstantVector(CV); SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16); SDValue Mask = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx, PseudoSourceValue::getConstantPool(), 0, @@ -5160,6 +5166,7 @@ SDValue X86TargetLowering::LowerFNEG(SDValue Op, SelectionDAG &DAG) { } SDValue X86TargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) { + LLVMContext *Context = DAG.getContext(); SDValue Op0 = Op.getOperand(0); SDValue Op1 = Op.getOperand(1); DebugLoc dl = Op.getDebugLoc(); @@ -5183,15 +5190,15 @@ SDValue X86TargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) { // First get the sign bit of second operand. std::vector CV; if (SrcVT == MVT::f64) { - CV.push_back(ConstantFP::get(APFloat(APInt(64, 1ULL << 63)))); - CV.push_back(ConstantFP::get(APFloat(APInt(64, 0)))); + CV.push_back(Context->getConstantFP(APFloat(APInt(64, 1ULL << 63)))); + CV.push_back(Context->getConstantFP(APFloat(APInt(64, 0)))); } else { - CV.push_back(ConstantFP::get(APFloat(APInt(32, 1U << 31)))); - CV.push_back(ConstantFP::get(APFloat(APInt(32, 0)))); - CV.push_back(ConstantFP::get(APFloat(APInt(32, 0)))); - CV.push_back(ConstantFP::get(APFloat(APInt(32, 0)))); + CV.push_back(Context->getConstantFP(APFloat(APInt(32, 1U << 31)))); + CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0)))); + CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0)))); + CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0)))); } - Constant *C = ConstantVector::get(CV); + Constant *C = Context->getConstantVector(CV); SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16); SDValue Mask1 = DAG.getLoad(SrcVT, dl, DAG.getEntryNode(), CPIdx, PseudoSourceValue::getConstantPool(), 0, @@ -5212,15 +5219,15 @@ SDValue X86TargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) { // Clear first operand sign bit. CV.clear(); if (VT == MVT::f64) { - CV.push_back(ConstantFP::get(APFloat(APInt(64, ~(1ULL << 63))))); - CV.push_back(ConstantFP::get(APFloat(APInt(64, 0)))); + CV.push_back(Context->getConstantFP(APFloat(APInt(64, ~(1ULL << 63))))); + CV.push_back(Context->getConstantFP(APFloat(APInt(64, 0)))); } else { - CV.push_back(ConstantFP::get(APFloat(APInt(32, ~(1U << 31))))); - CV.push_back(ConstantFP::get(APFloat(APInt(32, 0)))); - CV.push_back(ConstantFP::get(APFloat(APInt(32, 0)))); - CV.push_back(ConstantFP::get(APFloat(APInt(32, 0)))); + CV.push_back(Context->getConstantFP(APFloat(APInt(32, ~(1U << 31))))); + CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0)))); + CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0)))); + CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0)))); } - C = ConstantVector::get(CV); + C = Context->getConstantVector(CV); CPIdx = DAG.getConstantPool(C, getPointerTy(), 16); SDValue Mask2 = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx, PseudoSourceValue::getConstantPool(), 0, diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index b123f85931b..49dd6a06d8a 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -1434,11 +1434,6 @@ Constant *ConstantVector::get(const VectorType *Ty, return VectorConstants->getOrCreate(Ty, V); } -Constant *ConstantVector::get(const std::vector &V) { - assert(!V.empty() && "Cannot infer type if V is empty"); - return get(VectorType::get(V.front()->getType(),V.size()), V); -} - // destroyConstant - Remove the constant from the constant table... // void ConstantVector::destroyConstant() { diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 6c3a36fe4f0..74bf42bc92f 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -1617,7 +1617,8 @@ BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context, Constant *C; if (const VectorType *PTy = dyn_cast(Op->getType())) { C = Context.getAllOnesValue(PTy->getElementType()); - C = ConstantVector::get(std::vector(PTy->getNumElements(), C)); + C = Context.getConstantVector( + std::vector(PTy->getNumElements(), C)); } else { C = Context.getAllOnesValue(Op->getType()); } @@ -1633,8 +1634,8 @@ BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context, if (const VectorType *PTy = dyn_cast(Op->getType())) { // Create a vector of all ones values. Constant *Elt = Context.getAllOnesValue(PTy->getElementType()); - AllOnes = - ConstantVector::get(std::vector(PTy->getNumElements(), Elt)); + AllOnes = Context.getConstantVector( + std::vector(PTy->getNumElements(), Elt)); } else { AllOnes = Context.getAllOnesValue(Op->getType()); } diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp index e359ae33df8..73c93a2d6e5 100644 --- a/lib/VMCore/LLVMContext.cpp +++ b/lib/VMCore/LLVMContext.cpp @@ -128,7 +128,7 @@ Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) { // For vectors, broadcast the value. if (const VectorType *VTy = dyn_cast(Ty)) return - ConstantVector::get(std::vector(VTy->getNumElements(), C)); + getConstantVector(std::vector(VTy->getNumElements(), C)); return C; } @@ -176,7 +176,8 @@ Constant* LLVMContext::getConstantArray(const ArrayType* T, Constant* LLVMContext::getConstantArray(const ArrayType* T, Constant* const* Vals, unsigned NumVals) { - return ConstantArray::get(T, Vals, NumVals); + // FIXME: make this the primary ctor method. + return getConstantArray(T, std::vector(Vals, Vals+NumVals)); } /// ConstantArray::get(const string&) - Return an array that is initialized to @@ -530,12 +531,14 @@ Constant* LLVMContext::getConstantVector(const VectorType* T, } Constant* LLVMContext::getConstantVector(const std::vector& V) { - return ConstantVector::get(V); + assert(!V.empty() && "Cannot infer type if V is empty"); + return getConstantVector(getVectorType(V.front()->getType(),V.size()), V); } Constant* LLVMContext::getConstantVector(Constant* const* Vals, unsigned NumVals) { - return ConstantVector::get(Vals, NumVals); + // FIXME: make this the primary ctor method. + return getConstantVector(std::vector(Vals, Vals+NumVals)); } // MDNode accessors