summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-07-28 21:19:26 +0000
committerOwen Anderson <resistor@mac.com>2009-07-28 21:19:26 +0000
commitaf7ec975870f92245f1f1484ac80a1e2db6a0afa (patch)
treeb00e71c30dafeea2c63c1b512c0d858e621870fa
parente7c329bf4b48ba3a4539183dc2d0804db6f4042a (diff)
downloadllvm-af7ec975870f92245f1f1484ac80a1e2db6a0afa.tar.gz
llvm-af7ec975870f92245f1f1484ac80a1e2db6a0afa.tar.bz2
llvm-af7ec975870f92245f1f1484ac80a1e2db6a0afa.tar.xz
Return ConstantVector to 2.5 API.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77366 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Constants.h5
-rw-r--r--include/llvm/LLVMContext.h8
-rw-r--r--lib/Analysis/ConstantFolding.cpp2
-rw-r--r--lib/AsmParser/LLParser.cpp2
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp4
-rw-r--r--lib/CodeGen/SelectionDAG/LegalizeDAG.cpp2
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp2
-rw-r--r--lib/Linker/LinkModules.cpp2
-rw-r--r--lib/Target/CellSPU/SPUISelDAGToDAG.cpp2
-rw-r--r--lib/Target/X86/X86ISelLowering.cpp12
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp18
-rw-r--r--lib/Transforms/Scalar/ScalarReplAggregates.cpp2
-rw-r--r--lib/Transforms/Utils/ValueMapper.cpp2
-rw-r--r--lib/VMCore/AutoUpgrade.cpp10
-rw-r--r--lib/VMCore/ConstantFold.cpp52
-rw-r--r--lib/VMCore/Constants.cpp61
-rw-r--r--lib/VMCore/Core.cpp2
-rw-r--r--lib/VMCore/Instructions.cpp4
-rw-r--r--lib/VMCore/LLVMContext.cpp23
-rw-r--r--lib/VMCore/LLVMContextImpl.cpp39
-rw-r--r--lib/VMCore/LLVMContextImpl.h6
21 files changed, 122 insertions, 138 deletions
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index 442472acb3..a3bd551790 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -448,6 +448,11 @@ class ConstantVector : public Constant {
protected:
ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
public:
+ // ConstantVector accessors
+ static Constant* get(const VectorType* T, const std::vector<Constant*>& V);
+ static Constant* get(const std::vector<Constant*>& V);
+ static Constant* get(Constant* const* Vals, unsigned NumVals);
+
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h
index 03de906c14..de118aae64 100644
--- a/include/llvm/LLVMContext.h
+++ b/include/llvm/LLVMContext.h
@@ -59,6 +59,7 @@ class LLVMContext {
friend class ConstantFP;
friend class ConstantStruct;
friend class ConstantArray;
+ friend class ConstantVector;
public:
LLVMContext();
~LLVMContext();
@@ -160,12 +161,6 @@ public:
///
Constant* getConstantExprSizeOf(const Type* Ty);
- // ConstantVector accessors
- Constant* getConstantVector(const VectorType* T,
- const std::vector<Constant*>& V);
- Constant* getConstantVector(const std::vector<Constant*>& V);
- Constant* getConstantVector(Constant* const* Vals, unsigned NumVals);
-
// MDNode accessors
MDNode* getMDNode(Value* const* Vals, unsigned NumVals);
@@ -211,7 +206,6 @@ public:
void erase(MDString *M);
void erase(MDNode *M);
void erase(ConstantAggregateZero *Z);
- void erase(ConstantVector *V);
};
/// FOR BACKWARDS COMPATIBILITY - Returns a global context.
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index 31d4f8230b..b3c8a771b3 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/lib/Analysis/ConstantFolding.cpp
@@ -264,7 +264,7 @@ static Constant *FoldBitCast(Constant *C, const Type *DestTy,
}
}
- return Context.getConstantVector(Result.data(), Result.size());
+ return ConstantVector::get(Result.data(), Result.size());
}
}
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index fc58dbccc6..430253746e 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -1777,7 +1777,7 @@ bool LLParser::ParseValID(ValID &ID) {
"vector element #" + utostr(i) +
" is not of type '" + Elts[0]->getType()->getDescription());
- ID.ConstantVal = Context.getConstantVector(Elts.data(), Elts.size());
+ ID.ConstantVal = ConstantVector::get(Elts.data(), Elts.size());
ID.Kind = ValID::t_Constant;
return false;
}
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index 117a8758d0..ed2e303870 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -294,7 +294,7 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() {
NewC = ConstantStruct::get(&NewOps[0], NewOps.size(),
UserCS->getType()->isPacked());
} else if (isa<ConstantVector>(UserC)) {
- NewC = Context.getConstantVector(&NewOps[0], NewOps.size());
+ NewC = ConstantVector::get(&NewOps[0], NewOps.size());
} else {
assert(isa<ConstantExpr>(UserC) && "Must be a ConstantExpr.");
NewC = cast<ConstantExpr>(UserC)->getWithOperands(&NewOps[0],
@@ -935,7 +935,7 @@ bool BitcodeReader::ParseConstants() {
const Type *EltTy = VTy->getElementType();
for (unsigned i = 0; i != Size; ++i)
Elts.push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
- V = Context.getConstantVector(Elts);
+ V = ConstantVector::get(Elts);
} else {
V = Context.getUndef(CurTy);
}
diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index 4f4c255b08..32f70a74ca 100644
--- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -1849,7 +1849,7 @@ SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) {
CV.push_back(Context->getUndef(OpNTy));
}
}
- Constant *CP = Context->getConstantVector(CV);
+ Constant *CP = ConstantVector::get(CV);
SDValue CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy());
unsigned Alignment = cast<ConstantPoolSDNode>(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 3a8b782564..7134938060 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
@@ -2149,7 +2149,7 @@ void SelectionDAGLowering::visitFSub(User &I) {
const Type *ElTy = DestTy->getElementType();
unsigned VL = DestTy->getNumElements();
std::vector<Constant*> NZ(VL, ConstantFP::getNegativeZero(ElTy));
- Constant *CNZ = DAG.getContext()->getConstantVector(&NZ[0], NZ.size());
+ Constant *CNZ = ConstantVector::get(&NZ[0], NZ.size());
if (CV == CNZ) {
SDValue Op2 = getValue(I.getOperand(1));
setValue(&I, DAG.getNode(ISD::FNEG, getCurDebugLoc(),
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index 0e9976f1ca..858b8d18f1 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -384,7 +384,7 @@ static Value *RemapOperand(const Value *In,
for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
Operands[i] = cast<Constant>(RemapOperand(CP->getOperand(i), ValueMap,
Context));
- Result = Context.getConstantVector(Operands);
+ Result = ConstantVector::get(Operands);
} else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CPV)) {
std::vector<Constant*> Ops;
for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i)
diff --git a/lib/Target/CellSPU/SPUISelDAGToDAG.cpp b/lib/Target/CellSPU/SPUISelDAGToDAG.cpp
index 97b16dd608..d29ddaac4b 100644
--- a/lib/Target/CellSPU/SPUISelDAGToDAG.cpp
+++ b/lib/Target/CellSPU/SPUISelDAGToDAG.cpp
@@ -306,7 +306,7 @@ namespace {
CV.push_back(const_cast<ConstantInt *> (V->getConstantIntValue()));
}
- Constant *CP = CurDAG->getContext()->getConstantVector(CV);
+ Constant *CP = ConstantVector::get(CV);
SDValue CPIdx = CurDAG->getConstantPool(CP, SPUtli.getPointerTy());
unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
SDValue CGPoolOffset =
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp
index f34deb1f46..2322814b92 100644
--- a/lib/Target/X86/X86ISelLowering.cpp
+++ b/lib/Target/X86/X86ISelLowering.cpp
@@ -4909,7 +4909,7 @@ SDValue X86TargetLowering::LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG) {
CV0.push_back(ConstantInt::get(*Context, APInt(32, 0x43300000)));
CV0.push_back(ConstantInt::get(*Context, APInt(32, 0)));
CV0.push_back(ConstantInt::get(*Context, APInt(32, 0)));
- Constant *C0 = Context->getConstantVector(CV0);
+ Constant *C0 = ConstantVector::get(CV0);
SDValue CPIdx0 = DAG.getConstantPool(C0, getPointerTy(), 16);
std::vector<Constant*> CV1;
@@ -4917,7 +4917,7 @@ SDValue X86TargetLowering::LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG) {
ConstantFP::get(*Context, APFloat(APInt(64, 0x4530000000000000ULL))));
CV1.push_back(
ConstantFP::get(*Context, APFloat(APInt(64, 0x4330000000000000ULL))));
- Constant *C1 = Context->getConstantVector(CV1);
+ Constant *C1 = ConstantVector::get(CV1);
SDValue CPIdx1 = DAG.getConstantPool(C1, getPointerTy(), 16);
SDValue XR1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v4i32,
@@ -5139,7 +5139,7 @@ SDValue X86TargetLowering::LowerFABS(SDValue Op, SelectionDAG &DAG) {
CV.push_back(C);
CV.push_back(C);
}
- Constant *C = Context->getConstantVector(CV);
+ Constant *C = ConstantVector::get(CV);
SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
SDValue Mask = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,
PseudoSourceValue::getConstantPool(), 0,
@@ -5169,7 +5169,7 @@ SDValue X86TargetLowering::LowerFNEG(SDValue Op, SelectionDAG &DAG) {
CV.push_back(C);
CV.push_back(C);
}
- Constant *C = Context->getConstantVector(CV);
+ Constant *C = ConstantVector::get(CV);
SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
SDValue Mask = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,
PseudoSourceValue::getConstantPool(), 0,
@@ -5218,7 +5218,7 @@ SDValue X86TargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) {
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
}
- Constant *C = Context->getConstantVector(CV);
+ Constant *C = ConstantVector::get(CV);
SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
SDValue Mask1 = DAG.getLoad(SrcVT, dl, DAG.getEntryNode(), CPIdx,
PseudoSourceValue::getConstantPool(), 0,
@@ -5247,7 +5247,7 @@ SDValue X86TargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) {
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
}
- C = Context->getConstantVector(CV);
+ C = ConstantVector::get(CV);
CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
SDValue Mask2 = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,
PseudoSourceValue::getConstantPool(), 0,
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index be43c55d6b..28a226ccc9 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -1458,7 +1458,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
}
// If we changed the constant, return it.
- Constant *NewCP = Context->getConstantVector(Elts);
+ Constant *NewCP = ConstantVector::get(Elts);
return NewCP != CP ? NewCP : 0;
} else if (isa<ConstantAggregateZero>(V)) {
// Simplify the CAZ to a ConstantVector where the non-demanded elements are
@@ -1478,7 +1478,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
Elts.push_back(Elt);
}
UndefElts = DemandedElts ^ EltMask;
- return Context->getConstantVector(Elts);
+ return ConstantVector::get(Elts);
}
// Limit search depth.
@@ -1597,7 +1597,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
Elts.push_back(ConstantInt::get(Type::Int32Ty,
Shuffle->getMaskValue(i)));
}
- I->setOperand(2, Context->getConstantVector(Elts));
+ I->setOperand(2, ConstantVector::get(Elts));
MadeChange = true;
}
break;
@@ -2926,7 +2926,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
if (const VectorType *Ty = dyn_cast<VectorType>(I.getType())) {
Constant *CI = ConstantInt::get(Ty->getElementType(), 1);
std::vector<Constant*> Elts(Ty->getNumElements(), CI);
- return ReplaceInstUsesWith(I, Context->getConstantVector(Elts));
+ return ReplaceInstUsesWith(I, ConstantVector::get(Elts));
}
Constant *CI = ConstantInt::get(I.getType(), 1);
@@ -3259,7 +3259,7 @@ Instruction *InstCombiner::visitSRem(BinaryOperator &I) {
}
}
- Constant *NewRHSV = Context->getConstantVector(Elts);
+ Constant *NewRHSV = ConstantVector::get(Elts);
if (NewRHSV != RHSV) {
AddUsesToWorkList(I);
I.setOperand(1, NewRHSV);
@@ -12689,7 +12689,7 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
Mask[InsertedIdx] =
ConstantInt::get(Type::Int32Ty, ExtractedIdx);
return new ShuffleVectorInst(EI->getOperand(0), VecOp,
- Context->getConstantVector(Mask));
+ ConstantVector::get(Mask));
}
// If this insertelement isn't used by some other insertelement, turn it
@@ -12701,7 +12701,7 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
if (RHS == 0) RHS = Context->getUndef(LHS->getType());
// We now have a shuffle of LHS, RHS, Mask.
return new ShuffleVectorInst(LHS, RHS,
- Context->getConstantVector(Mask));
+ ConstantVector::get(Mask));
}
}
}
@@ -12766,7 +12766,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
}
SVI.setOperand(0, SVI.getOperand(1));
SVI.setOperand(1, Context->getUndef(RHS->getType()));
- SVI.setOperand(2, Context->getConstantVector(Elts));
+ SVI.setOperand(2, ConstantVector::get(Elts));
LHS = SVI.getOperand(0);
RHS = SVI.getOperand(1);
MadeChange = true;
@@ -12823,7 +12823,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
}
return new ShuffleVectorInst(LHSSVI->getOperand(0),
LHSSVI->getOperand(1),
- Context->getConstantVector(Elts));
+ ConstantVector::get(Elts));
}
}
}
diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
index a182943c78..5fdc497727 100644
--- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp
+++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
@@ -850,7 +850,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst,
if (EltTy != ValTy) {
unsigned NumElts = cast<VectorType>(ValTy)->getNumElements();
SmallVector<Constant*, 16> Elts(NumElts, StoreVal);
- StoreVal = Context.getConstantVector(&Elts[0], NumElts);
+ StoreVal = ConstantVector::get(&Elts[0], NumElts);
}
}
new StoreInst(StoreVal, EltPtr, MI);
diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp
index 673bb0b58e..3bef8124e1 100644
--- a/lib/Transforms/Utils/ValueMapper.cpp
+++ b/lib/Transforms/Utils/ValueMapper.cpp
@@ -101,7 +101,7 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext &Context) {
Values.push_back(cast<Constant>(MV));
for (++i; i != e; ++i)
Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
- return VM[V] = Context.getConstantVector(Values);
+ return VM[V] = ConstantVector::get(Values);
}
}
return VM[V] = C;
diff --git a/lib/VMCore/AutoUpgrade.cpp b/lib/VMCore/AutoUpgrade.cpp
index c771500d91..fc86e54682 100644
--- a/lib/VMCore/AutoUpgrade.cpp
+++ b/lib/VMCore/AutoUpgrade.cpp
@@ -281,7 +281,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1));
}
- Value *Mask = Context.getConstantVector(Idxs);
+ Value *Mask = ConstantVector::get(Idxs);
SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
} else if (isMovL) {
Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
@@ -289,14 +289,14 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
Idxs.push_back(Zero);
Idxs.push_back(Zero);
Idxs.push_back(Zero);
- Value *ZeroV = Context.getConstantVector(Idxs);
+ Value *ZeroV = ConstantVector::get(Idxs);
Idxs.clear();
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 4));
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 5));
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 3));
- Value *Mask = Context.getConstantVector(Idxs);
+ Value *Mask = ConstantVector::get(Idxs);
SI = new ShuffleVectorInst(ZeroV, Op0, Mask, "upgraded.", CI);
} else if (isMovSD ||
isUnpckhPD || isUnpcklPD || isPunpckhQPD || isPunpcklQPD) {
@@ -311,7 +311,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 0));
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
}
- Value *Mask = Context.getConstantVector(Idxs);
+ Value *Mask = ConstantVector::get(Idxs);
SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
} else if (isShufPD) {
Value *Op1 = CI->getOperand(2);
@@ -319,7 +319,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
Idxs.push_back(ConstantInt::get(Type::Int32Ty, MaskVal & 1));
Idxs.push_back(ConstantInt::get(Type::Int32Ty,
((MaskVal >> 1) & 1)+2));
- Value *Mask = Context.getConstantVector(Idxs);
+ Value *Mask = ConstantVector::get(Idxs);
SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
}
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 3c0d94e4e3..2fdf08d394 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -63,7 +63,7 @@ static Constant *BitCastConstantVector(LLVMContext &Context, ConstantVector *CV,
for (unsigned i = 0; i != NumElts; ++i)
Result.push_back(Context.getConstantExprBitCast(CV->getOperand(i),
DstEltTy));
- return Context.getConstantVector(Result);
+ return ConstantVector::get(Result);
}
/// This function determines which opcode to use to fold two constant cast
@@ -145,7 +145,7 @@ static Constant *FoldBitCast(LLVMContext &Context,
// can only be handled by Analysis/ConstantFolding.cpp).
if (isa<ConstantInt>(V) || isa<ConstantFP>(V))
return Context.getConstantExprBitCast(
- Context.getConstantVector(&V, 1), DestPTy);
+ ConstantVector::get(&V, 1), DestPTy);
}
// Finally, implement bitcast folding now. The code below doesn't handle
@@ -228,7 +228,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i)
res.push_back(Context.getConstantExprCast(opc,
CV->getOperand(i), DstEltTy));
- return Context.getConstantVector(DestVecTy, res);
+ return ConstantVector::get(DestVecTy, res);
}
// We actually have to do a cast now. Perform the cast according to the
@@ -374,7 +374,7 @@ Constant *llvm::ConstantFoldInsertElementInstruction(LLVMContext &Context,
(idxVal == i) ? Elt : Context.getUndef(Elt->getType());
Ops.push_back(const_cast<Constant*>(Op));
}
- return Context.getConstantVector(Ops);
+ return ConstantVector::get(Ops);
}
if (isa<ConstantAggregateZero>(Val)) {
// Insertion of scalar constant into vector aggregate zero
@@ -392,7 +392,7 @@ Constant *llvm::ConstantFoldInsertElementInstruction(LLVMContext &Context,
(idxVal == i) ? Elt : Context.getNullValue(Elt->getType());
Ops.push_back(const_cast<Constant*>(Op));
}
- return Context.getConstantVector(Ops);
+ return ConstantVector::get(Ops);
}
if (const ConstantVector *CVal = dyn_cast<ConstantVector>(Val)) {
// Insertion of scalar constant into vector constant
@@ -403,7 +403,7 @@ Constant *llvm::ConstantFoldInsertElementInstruction(LLVMContext &Context,
(idxVal == i) ? Elt : cast<Constant>(CVal->getOperand(i));
Ops.push_back(const_cast<Constant*>(Op));
}
- return Context.getConstantVector(Ops);
+ return ConstantVector::get(Ops);
}
return 0;
@@ -459,7 +459,7 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(LLVMContext &Context,
Result.push_back(InElt);
}
- return Context.getConstantVector(&Result[0], Result.size());
+ return ConstantVector::get(&Result[0], Result.size());
}
Constant *llvm::ConstantFoldExtractValueInstruction(LLVMContext &Context,
@@ -829,7 +829,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprAdd(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::FAdd:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -837,7 +837,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprFAdd(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::Sub:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -845,7 +845,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprSub(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::FSub:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -853,7 +853,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprFSub(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::Mul:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -861,7 +861,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprMul(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::FMul:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -869,7 +869,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprFMul(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::UDiv:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -877,7 +877,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprUDiv(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::SDiv:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -885,7 +885,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprSDiv(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::FDiv:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -893,7 +893,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprFDiv(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::URem:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -901,7 +901,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprURem(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::SRem:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -909,7 +909,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprSRem(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::FRem:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -917,7 +917,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprFRem(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::And:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -925,7 +925,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprAnd(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::Or:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -933,7 +933,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprOr(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::Xor:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -941,7 +941,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprXor(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::LShr:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -949,7 +949,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprLShr(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::AShr:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -957,7 +957,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprAShr(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
case Instruction::Shl:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -965,7 +965,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
Res.push_back(Context.getConstantExprShl(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
- return Context.getConstantVector(Res);
+ return ConstantVector::get(Res);
}
}
}
@@ -1496,7 +1496,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
ResElts.push_back(
Context.getConstantExprCompare(pred, C1Elts[i], C2Elts[i]));
}
- return Context.getConstantVector(&ResElts[0], ResElts.size());
+ return ConstantVector::get(&ResElts[0], ResElts.size());
}
if (C1->getType()->isFloatingPoint()) {
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index ec1bf13e5d..31a82e59f2 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -206,7 +206,7 @@ Constant* ConstantInt::get(const Type* Ty, uint64_t V, bool isSigned) {
// For vectors, broadcast the value.
if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
- return Ty->getContext().getConstantVector(
+ return ConstantVector::get(
std::vector<Constant *>(VTy->getNumElements(), C));
return C;
@@ -232,7 +232,7 @@ Constant* ConstantInt::get(const Type* Ty, const APInt& V) {
// For vectors, broadcast the value.
if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
- return Ty->getContext().getConstantVector(
+ return ConstantVector::get(
std::vector<Constant *>(VTy->getNumElements(), C));
return C;
@@ -270,7 +270,7 @@ Constant* ConstantFP::get(const Type* Ty, double V) {
// For vectors, broadcast the value.
if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
- return Context.getConstantVector(
+ return ConstantVector::get(
std::vector<Constant *>(VTy->getNumElements(), C));
return C;
@@ -290,7 +290,7 @@ Constant* ConstantFP::getZeroValueForNegation(const Type* Ty) {
if (PTy->getElementType()->isFloatingPoint()) {
std::vector<Constant*> zeros(PTy->getNumElements(),
getNegativeZero(PTy->getElementType()));
- return Context.getConstantVector(PTy, zeros);
+ return ConstantVector::get(PTy, zeros);
}
if (Ty->isFloatingPoint())
@@ -490,6 +490,46 @@ ConstantVector::ConstantVector(const VectorType *T,
}
}
+// ConstantVector accessors.
+Constant* ConstantVector::get(const VectorType* T,
+ const std::vector<Constant*>& V) {
+ assert(!V.empty() && "Vectors can't be empty");
+ LLVMContext &Context = T->getContext();
+ LLVMContextImpl *pImpl = Context.pImpl;
+
+ // If this is an all-undef or alll-zero vector, return a
+ // ConstantAggregateZero or UndefValue.
+ Constant *C = V[0];
+ bool isZero = C->isNullValue();
+ bool isUndef = isa<UndefValue>(C);
+
+ if (isZero || isUndef) {
+ for (unsigned i = 1, e = V.size(); i != e; ++i)
+ if (V[i] != C) {
+ isZero = isUndef = false;
+ break;
+ }
+ }
+
+ if (isZero)
+ return Context.getConstantAggregateZero(T);
+ if (isUndef)
+ return Context.getUndef(T);
+
+ // Implicitly locked.
+ return pImpl->VectorConstants.getOrCreate(T, 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);
+}
+
+Constant* ConstantVector::get(Constant* const* Vals, unsigned NumVals) {
+ // FIXME: make this the primary ctor method.
+ return get(std::vector<Constant*>(Vals, Vals+NumVals));
+}
+
namespace llvm {
// We declare several classes private to this file, so use an anonymous
@@ -1064,7 +1104,7 @@ void ConstantStruct::destroyConstant() {
//
void ConstantVector::destroyConstant() {
// Implicitly locked.
- getType()->getContext().erase(this);
+ getType()->getContext().pImpl->VectorConstants.remove(this);
destroyConstantImpl();
}
@@ -2127,6 +2167,14 @@ void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
destroyConstant();
}
+static std::vector<Constant*> getValType(ConstantVector *CP) {
+ std::vector<Constant*> Elements;
+ Elements.reserve(CP->getNumOperands());
+ for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
+ Elements.push_back(CP->getOperand(i));
+ return Elements;
+}
+
void ConstantVector::replaceUsesOfWithOnConstant(Value *From, Value *To,
Use *U) {
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
@@ -2139,8 +2187,7 @@ void ConstantVector::replaceUsesOfWithOnConstant(Value *From, Value *To,
Values.push_back(Val);
}
- Constant *Replacement =
- getType()->getContext().getConstantVector(getType(), Values);
+ Constant *Replacement = get(getType(), Values);
assert(Replacement != this && "I didn't contain From!");
// Everyone using this now uses the replacement.
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp
index a262f40c49..d1e6fb26f6 100644
--- a/lib/VMCore/Core.cpp
+++ b/lib/VMCore/Core.cpp
@@ -421,7 +421,7 @@ LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
}
LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
- return wrap(getGlobalContext().getConstantVector(
+ return wrap(ConstantVector::get(
unwrap<Constant>(ScalarConstantVals, Size), Size));
}
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index a90bb4afcb..0b24241505 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -1616,7 +1616,7 @@ BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context,
Constant *C;
if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
C = Context.getAllOnesValue(PTy->getElementType());
- C = Context.getConstantVector(
+ C = ConstantVector::get(
std::vector<Constant*>(PTy->getNumElements(), C));
} else {
C = Context.getAllOnesValue(Op->getType());
@@ -1633,7 +1633,7 @@ 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 = Context.getConstantVector(
+ AllOnes = ConstantVector::get(
std::vector<Constant*>(PTy->getNumElements(), Elt));
} else {
AllOnes = Context.getAllOnesValue(Op->getType());
diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp
index 97857c5dda..14a891fb90 100644
--- a/lib/VMCore/LLVMContext.cpp
+++ b/lib/VMCore/LLVMContext.cpp
@@ -72,7 +72,7 @@ Constant* LLVMContext::getAllOnesValue(const Type* Ty) {
const VectorType* VTy = cast<VectorType>(Ty);
Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType()));
assert(Elts[0] && "Not a vector integer type!");
- return cast<ConstantVector>(getConstantVector(Elts));
+ return cast<ConstantVector>(ConstantVector::get(Elts));
}
// UndefValue accessors.
@@ -367,23 +367,6 @@ Constant* LLVMContext::getConstantExprSizeOf(const Type* Ty) {
return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int64Ty);
}
-// ConstantVector accessors.
-Constant* LLVMContext::getConstantVector(const VectorType* T,
- const std::vector<Constant*>& V) {
- return pImpl->getConstantVector(T, V);
-}
-
-Constant* LLVMContext::getConstantVector(const std::vector<Constant*>& 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) {
- // FIXME: make this the primary ctor method.
- return getConstantVector(std::vector<Constant*>(Vals, Vals+NumVals));
-}
-
// MDNode accessors
MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
return pImpl->getMDNode(Vals, NumVals);
@@ -488,7 +471,3 @@ void LLVMContext::erase(MDNode *M) {
void LLVMContext::erase(ConstantAggregateZero *Z) {
pImpl->erase(Z);
}
-
-void LLVMContext::erase(ConstantVector *V) {
- pImpl->erase(V);
-}
diff --git a/lib/VMCore/LLVMContextImpl.cpp b/lib/VMCore/LLVMContextImpl.cpp
index 72e415cd66..5efc1ebe5e 100644
--- a/lib/VMCore/LLVMContextImpl.cpp
+++ b/lib/VMCore/LLVMContextImpl.cpp
@@ -21,15 +21,6 @@ using namespace llvm;
static char getValType(ConstantAggregateZero *CPZ) { return 0; }
-static std::vector<Constant*> getValType(ConstantVector *CP) {
- std::vector<Constant*> Elements;
- Elements.reserve(CP->getNumOperands());
- for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
- Elements.push_back(CP->getOperand(i));
- return Elements;
-}
-
-
LLVMContextImpl::LLVMContextImpl(LLVMContext &C) :
Context(C), TheTrueVal(0), TheFalseVal(0) { }
@@ -77,32 +68,6 @@ LLVMContextImpl::getConstantAggregateZero(const Type *Ty) {
return AggZeroConstants.getOrCreate(Ty, 0);
}
-Constant *LLVMContextImpl::getConstantVector(const VectorType *Ty,
- const std::vector<Constant*> &V) {
- assert(!V.empty() && "Vectors can't be empty");
- // If this is an all-undef or alll-zero vector, return a
- // ConstantAggregateZero or UndefValue.
- Constant *C = V[0];
- bool isZero = C->isNullValue();
- bool isUndef = isa<UndefValue>(C);
-
- if (isZero || isUndef) {
- for (unsigned i = 1, e = V.size(); i != e; ++i)
- if (V[i] != C) {
- isZero = isUndef = false;
- break;
- }
- }
-
- if (isZero)
- return Context.getConstantAggregateZero(Ty);
- if (isUndef)
- return Context.getUndef(Ty);
-
- // Implicitly locked.
- return VectorConstants.getOrCreate(Ty, V);
-}
-
// *** erase methods ***
void LLVMContextImpl::erase(MDString *M) {
@@ -118,7 +83,3 @@ void LLVMContextImpl::erase(MDNode *M) {
void LLVMContextImpl::erase(ConstantAggregateZero *Z) {
AggZeroConstants.remove(Z);
}
-
-void LLVMContextImpl::erase(ConstantVector *V) {
- VectorConstants.remove(V);
-}
diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h
index eea495d1db..ebcb8a44f1 100644
--- a/lib/VMCore/LLVMContextImpl.h
+++ b/lib/VMCore/LLVMContextImpl.h
@@ -117,7 +117,7 @@ struct ConvertConstantType<ConstantVector, VectorType> {
std::vector<Constant*> C;
for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
C.push_back(cast<Constant>(OldC->getOperand(i)));
- Constant *New = OldC->getContext().getConstantVector(NewTy, C);
+ Constant *New = ConstantVector::get(NewTy, C);
assert(New != OldC && "Didn't replace constant??");
OldC->uncheckedReplaceAllUsesWith(New);
OldC->destroyConstant(); // This constant is now dead, destroy it.
@@ -460,6 +460,7 @@ class LLVMContextImpl {
friend class ConstantFP;
friend class ConstantStruct;
friend class ConstantArray;
+ friend class ConstantVector;
public:
LLVMContextImpl(LLVMContext &C);
@@ -469,9 +470,6 @@ public:
ConstantAggregateZero *getConstantAggregateZero(const Type *Ty);
- Constant *getConstantVector(const VectorType *Ty,
- const std::vector<Constant*> &V);
-
ConstantInt *getTrue() {
if (TheTrueVal)
return TheTrueVal;