@@ -23,13 +23,12 @@ using namespace mlir::ptr;
2323
2424constexpr const static unsigned kDefaultPointerSizeBits = 64 ;
2525constexpr const static unsigned kBitsInByte = 8 ;
26- constexpr const static unsigned kDefaultPointerAlignment = 8 ;
27-
28- static Attribute getDefaultMemorySpace (PtrType ptr) { return nullptr ; }
26+ constexpr const static unsigned kDefaultPointerAlignmentBits = 8 ;
2927
3028// / Searches the data layout for the pointer spec, returns nullptr if it is not
3129// / found.
32- static SpecAttr getPointerSpec (DataLayoutEntryListRef params, PtrType type) {
30+ static SpecAttr getPointerSpec (DataLayoutEntryListRef params, PtrType type,
31+ Attribute defaultMemorySpace) {
3332 for (DataLayoutEntryInterface entry : params) {
3433 if (!entry.isTypeEntry ())
3534 continue ;
@@ -41,20 +40,22 @@ static SpecAttr getPointerSpec(DataLayoutEntryListRef params, PtrType type) {
4140 }
4241 // If not found, and this is the pointer to the default memory space, assume
4342 // 64-bit pointers.
44- if (type.getMemorySpace () == getDefaultMemorySpace (type) )
43+ if (type.getMemorySpace () == defaultMemorySpace )
4544 return SpecAttr::get (type.getContext (), kDefaultPointerSizeBits ,
46- kDefaultPointerAlignment , kDefaultPointerAlignment ,
47- kDefaultPointerSizeBits );
45+ kDefaultPointerAlignmentBits ,
46+ kDefaultPointerAlignmentBits , kDefaultPointerSizeBits );
4847 return nullptr ;
4948}
5049
5150bool PtrType::areCompatible (DataLayoutEntryListRef oldLayout,
52- DataLayoutEntryListRef newLayout) const {
51+ DataLayoutEntryListRef newLayout,
52+ DataLayoutSpecInterface newSpec,
53+ const DataLayoutIdentifiedEntryMap &map) const {
5354 for (DataLayoutEntryInterface newEntry : newLayout) {
5455 if (!newEntry.isTypeEntry ())
5556 continue ;
5657 uint32_t size = kDefaultPointerSizeBits ;
57- uint32_t abi = kDefaultPointerAlignment ;
58+ uint32_t abi = kDefaultPointerAlignmentBits ;
5859 auto newType = llvm::cast<PtrType>(llvm::cast<Type>(newEntry.getKey ()));
5960 const auto *it =
6061 llvm::find_if (oldLayout, [&](DataLayoutEntryInterface entry) {
@@ -65,10 +66,12 @@ bool PtrType::areCompatible(DataLayoutEntryListRef oldLayout,
6566 return false ;
6667 });
6768 if (it == oldLayout.end ()) {
69+ Attribute defaultMemorySpace = mlir::detail::getDefaultMemorySpace (
70+ map.lookup (newSpec.getDefaultMemorySpaceIdentifier (getContext ())));
6871 it = llvm::find_if (oldLayout, [&](DataLayoutEntryInterface entry) {
6972 if (auto type = llvm::dyn_cast_if_present<Type>(entry.getKey ())) {
7073 auto ptrTy = llvm::cast<PtrType>(type);
71- return ptrTy.getMemorySpace () == getDefaultMemorySpace (ptrTy) ;
74+ return ptrTy.getMemorySpace () == defaultMemorySpace ;
7275 }
7376 return false ;
7477 });
@@ -90,43 +93,44 @@ bool PtrType::areCompatible(DataLayoutEntryListRef oldLayout,
9093
9194uint64_t PtrType::getABIAlignment (const DataLayout &dataLayout,
9295 DataLayoutEntryListRef params) const {
93- if (SpecAttr spec = getPointerSpec (params, *this ))
96+ Attribute defaultMemorySpace = dataLayout.getDefaultMemorySpace ();
97+ if (SpecAttr spec = getPointerSpec (params, *this , defaultMemorySpace))
9498 return spec.getAbi () / kBitsInByte ;
9599
96- return dataLayout.getTypeABIAlignment (
97- get (getContext (), getDefaultMemorySpace (*this )));
100+ return dataLayout.getTypeABIAlignment (get (getContext (), defaultMemorySpace));
98101}
99102
100103std::optional<uint64_t >
101104PtrType::getIndexBitwidth (const DataLayout &dataLayout,
102105 DataLayoutEntryListRef params) const {
103- if (SpecAttr spec = getPointerSpec (params, *this )) {
106+ Attribute defaultMemorySpace = dataLayout.getDefaultMemorySpace ();
107+ if (SpecAttr spec = getPointerSpec (params, *this , defaultMemorySpace)) {
104108 return spec.getIndex () == SpecAttr::kOptionalSpecValue ? spec.getSize ()
105109 : spec.getIndex ();
106110 }
107111
108- return dataLayout.getTypeIndexBitwidth (
109- get (getContext (), getDefaultMemorySpace (*this )));
112+ return dataLayout.getTypeIndexBitwidth (get (getContext (), defaultMemorySpace));
110113}
111114
112115llvm::TypeSize PtrType::getTypeSizeInBits (const DataLayout &dataLayout,
113116 DataLayoutEntryListRef params) const {
114- if (SpecAttr spec = getPointerSpec (params, *this ))
117+ Attribute defaultMemorySpace = dataLayout.getDefaultMemorySpace ();
118+ if (SpecAttr spec = getPointerSpec (params, *this , defaultMemorySpace))
115119 return llvm::TypeSize::getFixed (spec.getSize ());
116120
117121 // For other memory spaces, use the size of the pointer to the default memory
118122 // space.
119- return dataLayout.getTypeSizeInBits (
120- get (getContext (), getDefaultMemorySpace (*this )));
123+ return dataLayout.getTypeSizeInBits (get (getContext (), defaultMemorySpace));
121124}
122125
123126uint64_t PtrType::getPreferredAlignment (const DataLayout &dataLayout,
124127 DataLayoutEntryListRef params) const {
125- if (SpecAttr spec = getPointerSpec (params, *this ))
128+ Attribute defaultMemorySpace = dataLayout.getDefaultMemorySpace ();
129+ if (SpecAttr spec = getPointerSpec (params, *this , defaultMemorySpace))
126130 return spec.getPreferred () / kBitsInByte ;
127131
128132 return dataLayout.getTypePreferredAlignment (
129- get (getContext (), getDefaultMemorySpace (* this ) ));
133+ get (getContext (), defaultMemorySpace ));
130134}
131135
132136LogicalResult PtrType::verifyEntries (DataLayoutEntryListRef entries,
0 commit comments