From: Chris Lattner Date: Thu, 10 Jul 2008 00:28:11 +0000 (+0000) Subject: add a helper method for code that wants to handle vector X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=8638144825f43fe59b0e1b78d65d93f0a7b737a7;p=oota-llvm.git add a helper method for code that wants to handle vector constants by element without caring how they are formed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53381 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 9d898f0b4db..7908638fd67 100644 --- a/lib/VMCore/Constants.cpp +++ b/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 &Elts) const { + assert(isa(getType()) && "Not a vector constant!"); + + if (const ConstantVector *CV = dyn_cast(this)) { + for (unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) + Elts.push_back(CV->getOperand(i)); + return; + } + + const VectorType *VT = cast(getType()); + if (isa(this)) { + Elts.assign(VT->getNumElements(), + Constant::getNullValue(VT->getElementType())); + return; + } + + assert(isa(this) && "Unknown vector constant type!"); + Elts.assign(VT->getNumElements(), UndefValue::get(VT->getElementType())); +} + + + //===----------------------------------------------------------------------===// // ConstantInt //===----------------------------------------------------------------------===//