aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Constants.cpp
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 /lib/VMCore/Constants.cpp
parente7c329bf4b48ba3a4539183dc2d0804db6f4042a (diff)
downloadexternal_llvm-af7ec975870f92245f1f1484ac80a1e2db6a0afa.zip
external_llvm-af7ec975870f92245f1f1484ac80a1e2db6a0afa.tar.gz
external_llvm-af7ec975870f92245f1f1484ac80a1e2db6a0afa.tar.bz2
Return ConstantVector to 2.5 API.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77366 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Constants.cpp')
-rw-r--r--lib/VMCore/Constants.cpp61
1 files changed, 54 insertions, 7 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index ec1bf13..31a82e5 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.