forked from OSchip/llvm-project
eliminate the Constant::getVectorElements method. There are better (and
more robust) ways to do what it was doing now. Also, add static methods for decoding a ShuffleVector mask. llvm-svn: 149028
This commit is contained in:
parent
24e9afff43
commit
cf12970bd0
|
@ -91,12 +91,6 @@ public:
|
||||||
/// FIXME: This really should not be in VMCore.
|
/// FIXME: This really should not be in VMCore.
|
||||||
PossibleRelocationsTy getRelocationInfo() const;
|
PossibleRelocationsTy getRelocationInfo() const;
|
||||||
|
|
||||||
/// 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. For
|
|
||||||
/// constant exprs and other cases we can't handle, we return an empty vector.
|
|
||||||
void getVectorElements(SmallVectorImpl<Constant*> &Elts) const;
|
|
||||||
|
|
||||||
/// getAggregateElement - For aggregates (struct/array/vector) return the
|
/// getAggregateElement - For aggregates (struct/array/vector) return the
|
||||||
/// constant that corresponds to the specified element if possible, or null if
|
/// constant that corresponds to the specified element if possible, or null if
|
||||||
/// not. This can return null if the element index is a ConstantExpr, or if
|
/// not. This can return null if the element index is a ConstantExpr, or if
|
||||||
|
|
|
@ -1677,11 +1677,19 @@ public:
|
||||||
/// getMaskValue - Return the index from the shuffle mask for the specified
|
/// getMaskValue - Return the index from the shuffle mask for the specified
|
||||||
/// output result. This is either -1 if the element is undef or a number less
|
/// output result. This is either -1 if the element is undef or a number less
|
||||||
/// than 2*numelements.
|
/// than 2*numelements.
|
||||||
int getMaskValue(unsigned i) const;
|
static int getMaskValue(Constant *Mask, unsigned i);
|
||||||
|
|
||||||
|
int getMaskValue(unsigned i) const {
|
||||||
|
return getMaskValue(getMask(), i);
|
||||||
|
}
|
||||||
|
|
||||||
/// getShuffleMask - Return the full mask for this instruction, where each
|
/// getShuffleMask - Return the full mask for this instruction, where each
|
||||||
/// element is the element number and undef's are returned as -1.
|
/// element is the element number and undef's are returned as -1.
|
||||||
void getShuffleMask(SmallVectorImpl<int> &Mask) const;
|
static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
|
||||||
|
|
||||||
|
void getShuffleMask(SmallVectorImpl<int> &Result) const {
|
||||||
|
return getShuffleMask(getMask(), Result);
|
||||||
|
}
|
||||||
|
|
||||||
SmallVector<int, 16> getShuffleMask() const {
|
SmallVector<int, 16> getShuffleMask() const {
|
||||||
SmallVector<int, 16> Mask;
|
SmallVector<int, 16> Mask;
|
||||||
|
|
|
@ -2806,22 +2806,13 @@ static bool isSequentialInRange(const SmallVectorImpl<int> &Mask,
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionDAGBuilder::visitShuffleVector(const User &I) {
|
void SelectionDAGBuilder::visitShuffleVector(const User &I) {
|
||||||
SmallVector<int, 8> Mask;
|
|
||||||
SDValue Src1 = getValue(I.getOperand(0));
|
SDValue Src1 = getValue(I.getOperand(0));
|
||||||
SDValue Src2 = getValue(I.getOperand(1));
|
SDValue Src2 = getValue(I.getOperand(1));
|
||||||
|
|
||||||
// Convert the ConstantVector mask operand into an array of ints, with -1
|
SmallVector<int, 8> Mask;
|
||||||
// representing undef values.
|
ShuffleVectorInst::getShuffleMask(cast<Constant>(I.getOperand(2)), Mask);
|
||||||
SmallVector<Constant*, 8> MaskElts;
|
unsigned MaskNumElts = Mask.size();
|
||||||
cast<Constant>(I.getOperand(2))->getVectorElements(MaskElts);
|
|
||||||
unsigned MaskNumElts = MaskElts.size();
|
|
||||||
for (unsigned i = 0; i != MaskNumElts; ++i) {
|
|
||||||
if (isa<UndefValue>(MaskElts[i]))
|
|
||||||
Mask.push_back(-1);
|
|
||||||
else
|
|
||||||
Mask.push_back(cast<ConstantInt>(MaskElts[i])->getSExtValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
EVT VT = TLI.getValueType(I.getType());
|
EVT VT = TLI.getValueType(I.getType());
|
||||||
EVT SrcVT = Src1.getValueType();
|
EVT SrcVT = Src1.getValueType();
|
||||||
unsigned SrcNumElts = SrcVT.getVectorNumElements();
|
unsigned SrcNumElts = SrcVT.getVectorNumElements();
|
||||||
|
|
|
@ -1697,20 +1697,20 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
|
||||||
R==APFloat::cmpEqual);
|
R==APFloat::cmpEqual);
|
||||||
}
|
}
|
||||||
} else if (C1->getType()->isVectorTy()) {
|
} else if (C1->getType()->isVectorTy()) {
|
||||||
SmallVector<Constant*, 16> C1Elts, C2Elts;
|
|
||||||
C1->getVectorElements(C1Elts);
|
|
||||||
C2->getVectorElements(C2Elts);
|
|
||||||
if (C1Elts.empty() || C2Elts.empty())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// If we can constant fold the comparison of each element, constant fold
|
// If we can constant fold the comparison of each element, constant fold
|
||||||
// the whole vector comparison.
|
// the whole vector comparison.
|
||||||
SmallVector<Constant*, 4> ResElts;
|
SmallVector<Constant*, 4> ResElts;
|
||||||
// Compare the elements, producing an i1 result or constant expr.
|
// Compare the elements, producing an i1 result or constant expr.
|
||||||
for (unsigned i = 0, e = C1Elts.size(); i != e; ++i)
|
for (unsigned i = 0, e = C1->getType()->getVectorNumElements(); i != e;++i){
|
||||||
ResElts.push_back(ConstantExpr::getCompare(pred, C1Elts[i], C2Elts[i]));
|
Constant *C1E = C1->getAggregateElement(i);
|
||||||
|
Constant *C2E = C2->getAggregateElement(i);
|
||||||
return ConstantVector::get(ResElts);
|
if (C1E == 0 || C2E == 0) break;
|
||||||
|
|
||||||
|
ResElts.push_back(ConstantExpr::getCompare(pred, C1E, C2E));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ResElts.size() == C1->getType()->getVectorNumElements())
|
||||||
|
return ConstantVector::get(ResElts);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (C1->getType()->isFloatingPointTy()) {
|
if (C1->getType()->isFloatingPointTy()) {
|
||||||
|
|
|
@ -312,36 +312,6 @@ Constant::PossibleRelocationsTy Constant::getRelocationInfo() const {
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// 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. For
|
|
||||||
/// constant exprs and other cases we can't handle, we return an empty vector.
|
|
||||||
void Constant::getVectorElements(SmallVectorImpl<Constant*> &Elts) const {
|
|
||||||
assert(getType()->isVectorTy() && "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;
|
|
||||||
}
|
|
||||||
|
|
||||||
VectorType *VT = cast<VectorType>(getType());
|
|
||||||
if (isa<ConstantAggregateZero>(this)) {
|
|
||||||
Elts.assign(VT->getNumElements(),
|
|
||||||
Constant::getNullValue(VT->getElementType()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isa<UndefValue>(this)) {
|
|
||||||
Elts.assign(VT->getNumElements(), UndefValue::get(VT->getElementType()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unknown type, must be constant expr etc.
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// removeDeadUsersOfConstant - If the specified constantexpr is dead, remove
|
/// removeDeadUsersOfConstant - If the specified constantexpr is dead, remove
|
||||||
/// it. This involves recursively eliminating any dead users of the
|
/// it. This involves recursively eliminating any dead users of the
|
||||||
/// constantexpr.
|
/// constantexpr.
|
||||||
|
|
|
@ -1625,11 +1625,11 @@ bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2,
|
||||||
/// getMaskValue - Return the index from the shuffle mask for the specified
|
/// getMaskValue - Return the index from the shuffle mask for the specified
|
||||||
/// output result. This is either -1 if the element is undef or a number less
|
/// output result. This is either -1 if the element is undef or a number less
|
||||||
/// than 2*numelements.
|
/// than 2*numelements.
|
||||||
int ShuffleVectorInst::getMaskValue(unsigned i) const {
|
int ShuffleVectorInst::getMaskValue(Constant *Mask, unsigned i) {
|
||||||
assert(i < getType()->getNumElements() && "Index out of range");
|
assert(i < Mask->getType()->getVectorNumElements() && "Index out of range");
|
||||||
if (ConstantDataSequential *CDS =dyn_cast<ConstantDataSequential>(getMask()))
|
if (ConstantDataSequential *CDS =dyn_cast<ConstantDataSequential>(Mask))
|
||||||
return CDS->getElementAsInteger(i);
|
return CDS->getElementAsInteger(i);
|
||||||
Constant *C = getMask()->getAggregateElement(i);
|
Constant *C = Mask->getAggregateElement(i);
|
||||||
if (isa<UndefValue>(C))
|
if (isa<UndefValue>(C))
|
||||||
return -1;
|
return -1;
|
||||||
return cast<ConstantInt>(C)->getZExtValue();
|
return cast<ConstantInt>(C)->getZExtValue();
|
||||||
|
@ -1637,15 +1637,15 @@ int ShuffleVectorInst::getMaskValue(unsigned i) const {
|
||||||
|
|
||||||
/// getShuffleMask - Return the full mask for this instruction, where each
|
/// getShuffleMask - Return the full mask for this instruction, where each
|
||||||
/// element is the element number and undef's are returned as -1.
|
/// element is the element number and undef's are returned as -1.
|
||||||
void ShuffleVectorInst::getShuffleMask(SmallVectorImpl<int> &Result) const {
|
void ShuffleVectorInst::getShuffleMask(Constant *Mask,
|
||||||
unsigned NumElts = getType()->getNumElements();
|
SmallVectorImpl<int> &Result) {
|
||||||
|
unsigned NumElts = Mask->getType()->getVectorNumElements();
|
||||||
|
|
||||||
if (ConstantDataSequential *CDS=dyn_cast<ConstantDataSequential>(getMask())) {
|
if (ConstantDataSequential *CDS=dyn_cast<ConstantDataSequential>(Mask)) {
|
||||||
for (unsigned i = 0; i != NumElts; ++i)
|
for (unsigned i = 0; i != NumElts; ++i)
|
||||||
Result.push_back(CDS->getElementAsInteger(i));
|
Result.push_back(CDS->getElementAsInteger(i));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Constant *Mask = getMask();
|
|
||||||
for (unsigned i = 0; i != NumElts; ++i) {
|
for (unsigned i = 0; i != NumElts; ++i) {
|
||||||
Constant *C = Mask->getAggregateElement(i);
|
Constant *C = Mask->getAggregateElement(i);
|
||||||
Result.push_back(isa<UndefValue>(C) ? -1 :
|
Result.push_back(isa<UndefValue>(C) ? -1 :
|
||||||
|
|
Loading…
Reference in New Issue