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
This commit is contained in:
Owen Anderson 2009-07-15 21:51:10 +00:00
parent 7add5ff1d1
commit a90b3dc2f1
9 changed files with 57 additions and 56 deletions

View File

@ -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<Constant*> &);
static Constant *get(const ArrayType *T,
Constant*const*Vals, unsigned NumVals) {
// FIXME: make this the primary ctor method.
return get(T, std::vector<Constant*>(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<Constant*> &);
static Constant *get(const std::vector<Constant*> &V);
static Constant *get(Constant*const* Vals, unsigned NumVals) {
// FIXME: make this the primary ctor method.
return get(std::vector<Constant*>(Vals, Vals+NumVals));
}
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);

View File

@ -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<ConstantPoolSDNode>(CPIdx)->getAlignment();

View File

@ -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<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC, SType));
LLVMC = cast<ConstantFP>(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<ConstantPoolSDNode>(CPIdx)->getAlignment();
return DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,

View File

@ -2140,7 +2140,7 @@ void SelectionDAGLowering::visitFSub(User &I) {
const Type *ElTy = DestTy->getElementType();
unsigned VL = DestTy->getNumElements();
std::vector<Constant*> 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(),

View File

@ -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<ConstantInt *> (V->getConstantIntValue()));
}
Constant *CP = ConstantVector::get(CV);
Constant *CP = CurDAG->getContext()->getConstantVector(CV);
SDValue CPIdx = CurDAG->getConstantPool(CP, SPUtli.getPointerTy());
unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
SDValue CGPoolOffset =

View File

@ -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<Constant*> 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<Constant*> 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<Constant*> 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<Constant*> 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<Constant*> 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,

View File

@ -1434,11 +1434,6 @@ Constant *ConstantVector::get(const VectorType *Ty,
return VectorConstants->getOrCreate(Ty, V);
}
Constant *ConstantVector::get(const std::vector<Constant*> &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() {

View File

@ -1617,7 +1617,8 @@ BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context,
Constant *C;
if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
C = Context.getAllOnesValue(PTy->getElementType());
C = ConstantVector::get(std::vector<Constant*>(PTy->getNumElements(), C));
C = Context.getConstantVector(
std::vector<Constant*>(PTy->getNumElements(), C));
} else {
C = Context.getAllOnesValue(Op->getType());
}
@ -1633,8 +1634,8 @@ BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context,
if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
// Create a vector of all ones values.
Constant *Elt = Context.getAllOnesValue(PTy->getElementType());
AllOnes =
ConstantVector::get(std::vector<Constant*>(PTy->getNumElements(), Elt));
AllOnes = Context.getConstantVector(
std::vector<Constant*>(PTy->getNumElements(), Elt));
} else {
AllOnes = Context.getAllOnesValue(Op->getType());
}

View File

@ -128,7 +128,7 @@ Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) {
// For vectors, broadcast the value.
if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
return
ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C));
getConstantVector(std::vector<Constant *>(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<Constant*>(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<Constant*>& 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<Constant*>(Vals, Vals+NumVals));
}
// MDNode accessors