aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/IR/DataLayout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/IR/DataLayout.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/IR/DataLayout.cpp36
1 files changed, 20 insertions, 16 deletions
diff --git a/contrib/llvm-project/llvm/lib/IR/DataLayout.cpp b/contrib/llvm-project/llvm/lib/IR/DataLayout.cpp
index 96f55cf14de8..379c6d577b4e 100644
--- a/contrib/llvm-project/llvm/lib/IR/DataLayout.cpp
+++ b/contrib/llvm-project/llvm/lib/IR/DataLayout.cpp
@@ -406,6 +406,9 @@ Error DataLayout::parseSpecifier(StringRef Desc) {
return reportError("Invalid ABI alignment, must be a 16bit integer");
if (ABIAlign != 0 && !isPowerOf2_64(ABIAlign))
return reportError("Invalid ABI alignment, must be a power of 2");
+ if (AlignType == INTEGER_ALIGN && Size == 8 && ABIAlign != 1)
+ return reportError(
+ "Invalid ABI alignment, i8 must be naturally aligned");
// Preferred alignment.
unsigned PrefAlign = ABIAlign;
@@ -783,7 +786,7 @@ Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
case Type::PPC_FP128TyID:
case Type::FP128TyID:
case Type::X86_FP80TyID: {
- unsigned BitWidth = getTypeSizeInBits(Ty).getFixedSize();
+ unsigned BitWidth = getTypeSizeInBits(Ty).getFixedValue();
auto I = findAlignmentLowerBound(FLOAT_ALIGN, BitWidth);
if (I != Alignments.end() && I->AlignType == FLOAT_ALIGN &&
I->TypeBitWidth == BitWidth)
@@ -800,7 +803,7 @@ Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
case Type::X86_MMXTyID:
case Type::FixedVectorTyID:
case Type::ScalableVectorTyID: {
- unsigned BitWidth = getTypeSizeInBits(Ty).getKnownMinSize();
+ unsigned BitWidth = getTypeSizeInBits(Ty).getKnownMinValue();
auto I = findAlignmentLowerBound(VECTOR_ALIGN, BitWidth);
if (I != Alignments.end() && I->AlignType == VECTOR_ALIGN &&
I->TypeBitWidth == BitWidth)
@@ -812,10 +815,14 @@ Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
// We're only calculating a natural alignment, so it doesn't have to be
// based on the full size for scalable vectors. Using the minimum element
// count should be enough here.
- return Align(PowerOf2Ceil(getTypeStoreSize(Ty).getKnownMinSize()));
+ return Align(PowerOf2Ceil(getTypeStoreSize(Ty).getKnownMinValue()));
}
case Type::X86_AMXTyID:
return Align(64);
+ case Type::TargetExtTyID: {
+ Type *LayoutTy = cast<TargetExtType>(Ty)->getLayoutType();
+ return getAlignment(LayoutTy, abi_or_pref);
+ }
default:
llvm_unreachable("Bad type for getAlignment!!!");
}
@@ -925,28 +932,25 @@ static APInt getElementIndex(TypeSize ElemSize, APInt &Offset) {
return Index;
}
-Optional<APInt> DataLayout::getGEPIndexForOffset(Type *&ElemTy,
- APInt &Offset) const {
+std::optional<APInt> DataLayout::getGEPIndexForOffset(Type *&ElemTy,
+ APInt &Offset) const {
if (auto *ArrTy = dyn_cast<ArrayType>(ElemTy)) {
ElemTy = ArrTy->getElementType();
return getElementIndex(getTypeAllocSize(ElemTy), Offset);
}
- if (auto *VecTy = dyn_cast<VectorType>(ElemTy)) {
- ElemTy = VecTy->getElementType();
- unsigned ElemSizeInBits = getTypeSizeInBits(ElemTy).getFixedSize();
- // GEPs over non-multiple of 8 size vector elements are invalid.
- if (ElemSizeInBits % 8 != 0)
- return None;
-
- return getElementIndex(TypeSize::Fixed(ElemSizeInBits / 8), Offset);
+ if (isa<VectorType>(ElemTy)) {
+ // Vector GEPs are partially broken (e.g. for overaligned element types),
+ // and may be forbidden in the future, so avoid generating GEPs into
+ // vectors. See https://discourse.llvm.org/t/67497
+ return std::nullopt;
}
if (auto *STy = dyn_cast<StructType>(ElemTy)) {
const StructLayout *SL = getStructLayout(STy);
uint64_t IntOffset = Offset.getZExtValue();
if (IntOffset >= SL->getSizeInBytes())
- return None;
+ return std::nullopt;
unsigned Index = SL->getElementContainingOffset(IntOffset);
Offset -= SL->getElementOffset(Index);
@@ -955,7 +959,7 @@ Optional<APInt> DataLayout::getGEPIndexForOffset(Type *&ElemTy,
}
// Non-aggregate type.
- return None;
+ return std::nullopt;
}
SmallVector<APInt> DataLayout::getGEPIndicesForOffset(Type *&ElemTy,
@@ -964,7 +968,7 @@ SmallVector<APInt> DataLayout::getGEPIndicesForOffset(Type *&ElemTy,
SmallVector<APInt> Indices;
Indices.push_back(getElementIndex(getTypeAllocSize(ElemTy), Offset));
while (Offset != 0) {
- Optional<APInt> Index = getGEPIndexForOffset(ElemTy, Offset);
+ std::optional<APInt> Index = getGEPIndexForOffset(ElemTy, Offset);
if (!Index)
break;
Indices.push_back(*Index);