[llvm-commits] [llvm] r53381 - /llvm/trunk/lib/VMCore/Constants.cpp

Chris Lattner sabre at nondot.org
Wed Jul 9 17:28:11 PDT 2008


Author: lattner
Date: Wed Jul  9 19:28:11 2008
New Revision: 53381

URL: http://llvm.org/viewvc/llvm-project?rev=53381&view=rev
Log:
add a helper method for code that wants to handle vector
constants by element without caring how they are formed.

Modified:
    llvm/trunk/lib/VMCore/Constants.cpp

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=53381&r1=53380&r2=53381&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Wed Jul  9 19:28:11 2008
@@ -155,6 +155,31 @@
 }
 
 
+/// 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
 //===----------------------------------------------------------------------===//





More information about the llvm-commits mailing list