summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-07-10 00:28:11 +0000
committerChris Lattner <sabre@nondot.org>2008-07-10 00:28:11 +0000
commit2105d66c053763462c526f094f1bb578ded22afb (patch)
tree53d5e63a7dac9964e5b3bcd74e54d3e51a88bc59 /llvm/lib
parentb69689e18b07bea8e6b912655562f18bdca026f8 (diff)
downloadbcm5719-llvm-2105d66c053763462c526f094f1bb578ded22afb.tar.gz
bcm5719-llvm-2105d66c053763462c526f094f1bb578ded22afb.zip
add a helper method for code that wants to handle vector
constants by element without caring how they are formed. llvm-svn: 53381
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/VMCore/Constants.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index 9d898f0b4db..7908638fd67 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -155,6 +155,31 @@ ConstantVector *ConstantVector::getAllOnesValue(const VectorType *Ty) {
}
+/// getVectorElements - This method, which is only valid on constant of vector
+/// type, returns the elements of the vector in the specified smallvector.
+/// This handles breaking down a vector undef into undef elements, etc.
+void Constant::getVectorElements(SmallVectorImpl<Constant*> &Elts) const {
+ assert(isa<VectorType>(getType()) && "Not a vector constant!");
+
+ if (const ConstantVector *CV = dyn_cast<ConstantVector>(this)) {
+ for (unsigned i = 0, e = CV->getNumOperands(); i != e; ++i)
+ Elts.push_back(CV->getOperand(i));
+ return;
+ }
+
+ const VectorType *VT = cast<VectorType>(getType());
+ if (isa<ConstantAggregateZero>(this)) {
+ Elts.assign(VT->getNumElements(),
+ Constant::getNullValue(VT->getElementType()));
+ return;
+ }
+
+ assert(isa<UndefValue>(this) && "Unknown vector constant type!");
+ Elts.assign(VT->getNumElements(), UndefValue::get(VT->getElementType()));
+}
+
+
+
//===----------------------------------------------------------------------===//
// ConstantInt
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud