-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DataLayout] Refactor storage of non-integral address spaces #105734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,7 +151,8 @@ bool DataLayout::PrimitiveSpec::operator==(const PrimitiveSpec &Other) const { | |
bool DataLayout::PointerSpec::operator==(const PointerSpec &Other) const { | ||
return AddrSpace == Other.AddrSpace && BitWidth == Other.BitWidth && | ||
ABIAlign == Other.ABIAlign && PrefAlign == Other.PrefAlign && | ||
IndexBitWidth == Other.IndexBitWidth; | ||
IndexBitWidth == Other.IndexBitWidth && | ||
IsNonIntegral == Other.IsNonIntegral; | ||
} | ||
|
||
namespace { | ||
|
@@ -206,7 +207,8 @@ constexpr DataLayout::PrimitiveSpec DefaultVectorSpecs[] = { | |
|
||
// Default pointer type specifications. | ||
constexpr DataLayout::PointerSpec DefaultPointerSpecs[] = { | ||
{0, 64, Align::Constant<8>(), Align::Constant<8>(), 64} // p0:64:64:64:64 | ||
// p0:64:64:64:64 | ||
{0, 64, Align::Constant<8>(), Align::Constant<8>(), 64, false}, | ||
}; | ||
|
||
DataLayout::DataLayout() | ||
|
@@ -239,13 +241,11 @@ DataLayout &DataLayout::operator=(const DataLayout &Other) { | |
PointerSpecs = Other.PointerSpecs; | ||
StructABIAlignment = Other.StructABIAlignment; | ||
StructPrefAlignment = Other.StructPrefAlignment; | ||
NonIntegralAddressSpaces = Other.NonIntegralAddressSpaces; | ||
return *this; | ||
} | ||
|
||
bool DataLayout::operator==(const DataLayout &Other) const { | ||
// NOTE: StringRepresentation might differ, it is not canonicalized. | ||
// FIXME: NonIntegralAddressSpaces isn't compared. | ||
return BigEndian == Other.BigEndian && | ||
AllocaAddrSpace == Other.AllocaAddrSpace && | ||
ProgramAddrSpace == Other.ProgramAddrSpace && | ||
|
@@ -454,11 +454,13 @@ Error DataLayout::parsePointerSpec(StringRef Spec) { | |
return createStringError( | ||
"index size cannot be larger than the pointer size"); | ||
|
||
setPointerSpec(AddrSpace, BitWidth, ABIAlign, PrefAlign, IndexBitWidth); | ||
setPointerSpec(AddrSpace, BitWidth, ABIAlign, PrefAlign, IndexBitWidth, | ||
false); | ||
return Error::success(); | ||
} | ||
|
||
Error DataLayout::parseSpecification(StringRef Spec) { | ||
Error DataLayout::parseSpecification( | ||
StringRef Spec, SmallVectorImpl<unsigned> &NonIntegralAddressSpaces) { | ||
// The "ni" specifier is the only two-character specifier. Handle it first. | ||
if (Spec.starts_with("ni")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (optional) Since "ni" is special, may it make sense to extract this into a function and call it from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried this and it added more extra code so keeping as is. |
||
// ni:<address space>[:<address space>]... | ||
|
@@ -614,12 +616,23 @@ Error DataLayout::parseLayoutString(StringRef LayoutString) { | |
|
||
// Split the data layout string into specifications separated by '-' and | ||
// parse each specification individually, updating internal data structures. | ||
SmallVector<unsigned, 8> NonIntegralAddressSpaces; | ||
for (StringRef Spec : split(LayoutString, '-')) { | ||
if (Spec.empty()) | ||
return createStringError("empty specification is not allowed"); | ||
if (Error Err = parseSpecification(Spec)) | ||
if (Error Err = parseSpecification(Spec, NonIntegralAddressSpaces)) | ||
return Err; | ||
} | ||
// Mark all address spaces that were qualified as non-integral now. This has | ||
// to be done later since the non-integral property is not part of the data | ||
// layout pointer specification. | ||
for (unsigned AS : NonIntegralAddressSpaces) { | ||
// If there is no special spec for a given AS, getPointerSpec(AS) returns | ||
// the spec for AS0, and we then update that to mark it non-integral. | ||
const PointerSpec &PS = getPointerSpec(AS); | ||
setPointerSpec(AS, PS.BitWidth, PS.ABIAlign, PS.PrefAlign, PS.IndexBitWidth, | ||
true); | ||
arichardson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return Error::success(); | ||
} | ||
|
@@ -666,16 +679,17 @@ DataLayout::getPointerSpec(uint32_t AddrSpace) const { | |
|
||
void DataLayout::setPointerSpec(uint32_t AddrSpace, uint32_t BitWidth, | ||
Align ABIAlign, Align PrefAlign, | ||
uint32_t IndexBitWidth) { | ||
uint32_t IndexBitWidth, bool IsNonIntegral) { | ||
auto I = lower_bound(PointerSpecs, AddrSpace, LessPointerAddrSpace()); | ||
if (I == PointerSpecs.end() || I->AddrSpace != AddrSpace) { | ||
PointerSpecs.insert(I, PointerSpec{AddrSpace, BitWidth, ABIAlign, PrefAlign, | ||
IndexBitWidth}); | ||
IndexBitWidth, IsNonIntegral}); | ||
} else { | ||
I->BitWidth = BitWidth; | ||
I->ABIAlign = ABIAlign; | ||
I->PrefAlign = PrefAlign; | ||
I->IndexBitWidth = IndexBitWidth; | ||
I->IsNonIntegral = IsNonIntegral; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually used for anything now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is only used in tests - I could drop those if you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it might be useful somewhere I suppose