Remove some dead code and tidy things up now that vectors use ConstantDataVector

instead of always using ConstantVector.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149912 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2012-02-06 21:56:39 +00:00
parent 705f4813af
commit 7302d80490
9 changed files with 40 additions and 129 deletions

View File

@@ -54,37 +54,35 @@ static Constant *FoldBitCast(Constant *C, Type *DestTy,
// Handle a vector->integer cast.
if (IntegerType *IT = dyn_cast<IntegerType>(DestTy)) {
// FIXME: Remove ConstantVector support.
if ((!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C)) ||
// TODO: Handle big endian someday.
!TD.isLittleEndian())
ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(C);
if (CDV == 0)
return ConstantExpr::getBitCast(C, DestTy);
unsigned NumSrcElts = C->getType()->getVectorNumElements();
unsigned NumSrcElts = CDV->getType()->getNumElements();
Type *SrcEltTy = CDV->getType()->getElementType();
// If the vector is a vector of floating point, convert it to vector of int
// to simplify things.
if (C->getType()->getVectorElementType()->isFloatingPointTy()) {
unsigned FPWidth =
C->getType()->getVectorElementType()->getPrimitiveSizeInBits();
if (SrcEltTy->isFloatingPointTy()) {
unsigned FPWidth = SrcEltTy->getPrimitiveSizeInBits();
Type *SrcIVTy =
VectorType::get(IntegerType::get(C->getContext(), FPWidth), NumSrcElts);
// Ask VMCore to do the conversion now that #elts line up.
C = ConstantExpr::getBitCast(C, SrcIVTy);
CDV = cast<ConstantDataVector>(C);
}
// Now that we know that the input value is a vector of integers, just shift
// and insert them into our result.
unsigned BitShift =
TD.getTypeAllocSizeInBits(C->getType()->getVectorElementType());
unsigned BitShift = TD.getTypeAllocSizeInBits(SrcEltTy);
APInt Result(IT->getBitWidth(), 0);
for (unsigned i = 0; i != NumSrcElts; ++i) {
// FIXME: Rework when we have ConstantDataVector.
ConstantInt *Elt=dyn_cast_or_null<ConstantInt>(C->getAggregateElement(i));
if (Elt == 0) // Elt must be a constant expr or something.
return ConstantExpr::getBitCast(C, DestTy);
Result |= Elt->getValue().zextOrSelf(IT->getBitWidth()) << i*BitShift;
Result <<= BitShift;
if (TD.isLittleEndian())
Result |= CDV->getElementAsInteger(NumSrcElts-i-1);
else
Result |= CDV->getElementAsInteger(i);
}
return ConstantInt::get(IT, Result);
@@ -103,7 +101,6 @@ static Constant *FoldBitCast(Constant *C, Type *DestTy,
}
// If this is a bitcast from constant vector -> vector, fold it.
// FIXME: Remove ConstantVector support.
if (!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C))
return ConstantExpr::getBitCast(C, DestTy);
@@ -350,7 +347,6 @@ static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset,
// not reached.
}
// FIXME: Remove ConstantVector
if (isa<ConstantArray>(C) || isa<ConstantVector>(C) ||
isa<ConstantDataSequential>(C)) {
Type *EltTy = cast<SequentialType>(C->getType())->getElementType();