1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[IR] Add getExtendedType() to IntegerType and Type (dispatching to IntegerType or VectorType)

llvm-svn: 372638
This commit is contained in:
Roman Lebedev 2019-09-23 18:21:33 +00:00
parent 6cba8c3172
commit 058f214422
3 changed files with 24 additions and 13 deletions

View File

@ -62,6 +62,11 @@ public:
/// Get or create an IntegerType instance.
static IntegerType *get(LLVMContext &C, unsigned NumBits);
/// Returns type twice as wide the input type.
IntegerType *getExtendedType() const {
return Type::getIntNTy(getContext(), 2 * getScalarSizeInBits());
}
/// Get the number of bits in this IntegerType
unsigned getBitWidth() const { return getSubclassData(); }
@ -470,9 +475,9 @@ public:
/// This static method is like getInteger except that the element types are
/// twice as wide as the elements in the input type.
static VectorType *getExtendedElementVectorType(VectorType *VTy) {
unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
Type *EltTy = IntegerType::get(VTy->getContext(), EltBits * 2);
return VectorType::get(EltTy, VTy->getElementCount());
assert(VTy->isIntOrIntVectorTy() && "VTy expected to be a vector of ints.");
auto *EltTy = cast<IntegerType>(VTy->getElementType());
return VectorType::get(EltTy->getExtendedType(), VTy->getElementCount());
}
// This static method gets a VectorType with the same number of elements as
@ -603,6 +608,16 @@ public:
}
};
Type *Type::getExtendedType() const {
assert(
isIntOrIntVectorTy() &&
"Original type expected to be a vector of integers or a scalar integer.");
if (auto *VTy = dyn_cast<VectorType>(this))
return VectorType::getExtendedElementVectorType(
const_cast<VectorType *>(VTy));
return cast<IntegerType>(this)->getExtendedType();
}
unsigned Type::getPointerAddressSpace() const {
return cast<PointerType>(getScalarType())->getAddressSpace();
}

View File

@ -378,6 +378,10 @@ public:
return ContainedTys[0];
}
/// Given scalar/vector integer type, returns a type with elements twice as
/// wide as in the original type. For vectors, preserves element count.
inline Type *getExtendedType() const;
/// Get the address space of this pointer or pointer vector type.
inline unsigned getPointerAddressSpace() const;

View File

@ -173,11 +173,7 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
return nullptr; // Else we can't perform the fold.
// The mask must be computed in a type twice as wide to ensure
// that no bits are lost if the sum-of-shifts is wider than the base type.
Type *ExtendedScalarTy = Type::getIntNTy(Ty->getContext(), 2 * BitWidth);
Type *ExtendedTy =
Ty->isVectorTy()
? VectorType::get(ExtendedScalarTy, Ty->getVectorNumElements())
: ExtendedScalarTy;
Type *ExtendedTy = Ty->getExtendedType();
auto *ExtendedSumOfShAmts =
ConstantExpr::getZExt(SumOfShAmts, ExtendedTy);
// And compute the mask as usual: ~(-1 << (SumOfShAmts))
@ -213,11 +209,7 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
unsigned BitWidth = Ty->getScalarSizeInBits();
// The mask must be computed in a type twice as wide to ensure
// that no bits are lost if the sum-of-shifts is wider than the base type.
Type *ExtendedScalarTy = Type::getIntNTy(Ty->getContext(), 2 * BitWidth);
Type *ExtendedTy =
Ty->isVectorTy()
? VectorType::get(ExtendedScalarTy, Ty->getVectorNumElements())
: ExtendedScalarTy;
Type *ExtendedTy = Ty->getExtendedType();
auto *ExtendedNumHighBitsToClear = ConstantExpr::getZExt(
ConstantExpr::getAdd(
ConstantExpr::getNeg(ShAmtsDiff),