Skip to content

Commit 80959a8

Browse files
committed
rebase
1 parent 998b28f commit 80959a8

File tree

14 files changed

+116
-1
lines changed

14 files changed

+116
-1
lines changed

mlir/include/mlir/Dialect/DLTI/DLTIAttrs.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def DLTI_DataLayoutSpecAttr :
7777
/// Returns the alloca memory space identifier.
7878
StringAttr getAllocaMemorySpaceIdentifier(MLIRContext *context) const;
7979

80+
/// Returns the mangling style identifier.
81+
StringAttr getManglingStyleIdentifier(MLIRContext *context) const;
82+
8083
/// Returns the program memory space identifier.
8184
StringAttr getProgramMemorySpaceIdentifier(MLIRContext *context) const;
8285

mlir/include/mlir/Dialect/DLTI/DLTIBase.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def DLTI_Dialect : Dialect {
4949
constexpr const static ::llvm::StringLiteral
5050
kDataLayoutEndiannessLittle = "little";
5151

52+
constexpr const static ::llvm::StringLiteral
53+
kDataLayoutManglingStyleKey = "dlti.mangling_style";
54+
5255
constexpr const static ::llvm::StringLiteral
5356
kDataLayoutAllocaMemorySpaceKey = "dlti.alloca_memory_space";
5457

mlir/include/mlir/Interfaces/DataLayoutInterfaces.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ Attribute getDefaultEndianness(DataLayoutEntryInterface entry);
7878
/// DataLayoutInterface if specified, otherwise returns the default.
7979
Attribute getDefaultAllocaMemorySpace(DataLayoutEntryInterface entry);
8080

81+
/// Default handler for mangling style request. Dispatches to the
82+
/// DataLayoutInterface if specified, otherwise returns the default.
83+
Attribute getDefaultManglingStyle(DataLayoutEntryInterface entry);
84+
8185
/// Default handler for program memory space request. Dispatches to the
8286
/// DataLayoutInterface if specified, otherwise returns the default.
8387
Attribute getDefaultProgramMemorySpace(DataLayoutEntryInterface entry);
@@ -230,6 +234,9 @@ class DataLayout {
230234
/// Returns the memory space used for AllocaOps.
231235
Attribute getAllocaMemorySpace() const;
232236

237+
/// Returns the mangling style.
238+
Attribute getManglingStyle() const;
239+
233240
/// Returns the memory space used for program memory operations.
234241
Attribute getProgramMemorySpace() const;
235242

@@ -276,6 +283,8 @@ class DataLayout {
276283

277284
/// Cache for the endianness.
278285
mutable std::optional<Attribute> endianness;
286+
/// Cache for the mangling style.
287+
mutable std::optional<Attribute> manglingStyle;
279288
/// Cache for alloca, global, and program memory spaces.
280289
mutable std::optional<Attribute> allocaMemorySpace;
281290
mutable std::optional<Attribute> programMemorySpace;

mlir/include/mlir/Interfaces/DataLayoutInterfaces.td

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ def DataLayoutSpecInterface : AttrInterface<"DataLayoutSpecInterface", [DLTIQuer
153153
/*methodName=*/"getGlobalMemorySpaceIdentifier",
154154
/*args=*/(ins "::mlir::MLIRContext *":$context)
155155
>,
156+
InterfaceMethod<
157+
/*description=*/"Returns the mangling style identifier.",
158+
/*retTy=*/"::mlir::StringAttr",
159+
/*methodName=*/"getManglingStyleIdentifier",
160+
/*args=*/(ins "::mlir::MLIRContext *":$context)
161+
>,
156162
InterfaceMethod<
157163
/*description=*/"Returns the stack alignment identifier.",
158164
/*retTy=*/"::mlir::StringAttr",
@@ -481,6 +487,18 @@ def DataLayoutOpInterface : OpInterface<"DataLayoutOpInterface"> {
481487
return ::mlir::detail::getDefaultAllocaMemorySpace(entry);
482488
}]
483489
>,
490+
StaticInterfaceMethod<
491+
/*description=*/"Returns the mangling style computed "
492+
"using the relevant entries. The data layout object "
493+
"can be used for recursive queries.",
494+
/*retTy=*/"::mlir::Attribute",
495+
/*methodName=*/"getManglingStyle",
496+
/*args=*/(ins "::mlir::DataLayoutEntryInterface":$entry),
497+
/*methodBody=*/"",
498+
/*defaultImplementation=*/[{
499+
return ::mlir::detail::getDefaultManglingStyle(entry);
500+
}]
501+
>,
484502
StaticInterfaceMethod<
485503
/*description=*/"Returns the memory space used by the ABI computed "
486504
"using the relevant entries. The data layout object "

mlir/lib/Dialect/DLTI/DLTI.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,12 @@ DataLayoutSpecAttr::getGlobalMemorySpaceIdentifier(MLIRContext *context) const {
397397
DLTIDialect::kDataLayoutGlobalMemorySpaceKey);
398398
}
399399

400+
StringAttr
401+
DataLayoutSpecAttr::getManglingStyleIdentifier(MLIRContext *context) const {
402+
return Builder(context).getStringAttr(
403+
DLTIDialect::kDataLayoutManglingStyleKey);
404+
}
405+
400406
StringAttr
401407
DataLayoutSpecAttr::getStackAlignmentIdentifier(MLIRContext *context) const {
402408
return Builder(context).getStringAttr(
@@ -606,7 +612,8 @@ class TargetDataLayoutInterface : public DataLayoutDialectInterface {
606612
if (entryName == DLTIDialect::kDataLayoutAllocaMemorySpaceKey ||
607613
entryName == DLTIDialect::kDataLayoutProgramMemorySpaceKey ||
608614
entryName == DLTIDialect::kDataLayoutGlobalMemorySpaceKey ||
609-
entryName == DLTIDialect::kDataLayoutStackAlignmentKey)
615+
entryName == DLTIDialect::kDataLayoutStackAlignmentKey ||
616+
entryName == DLTIDialect::kDataLayoutManglingStyleKey)
610617
return success();
611618
return emitError(loc) << "unknown data layout entry name: " << entryName;
612619
}

mlir/lib/Interfaces/DataLayoutInterfaces.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,17 @@ mlir::detail::getDefaultAllocaMemorySpace(DataLayoutEntryInterface entry) {
258258
return entry.getValue();
259259
}
260260

261+
// Returns the mangling style if specified in the given entry.
262+
// If the entry is empty, an empty attribute is returned.
263+
Attribute
264+
mlir::detail::getDefaultManglingStyle(DataLayoutEntryInterface entry) {
265+
if (entry == DataLayoutEntryInterface()) {
266+
return Attribute();
267+
}
268+
269+
return entry.getValue();
270+
}
271+
261272
// Returns the memory space used for the program memory space. if
262273
// specified in the given entry. If the entry is empty the default
263274
// memory space represented by an empty attribute is returned.
@@ -612,6 +623,22 @@ mlir::Attribute mlir::DataLayout::getAllocaMemorySpace() const {
612623
return *allocaMemorySpace;
613624
}
614625

626+
mlir::Attribute mlir::DataLayout::getManglingStyle() const {
627+
checkValid();
628+
if (manglingStyle)
629+
return *manglingStyle;
630+
DataLayoutEntryInterface entry;
631+
if (originalLayout)
632+
entry = originalLayout.getSpecForIdentifier(
633+
originalLayout.getManglingStyleIdentifier(originalLayout.getContext()));
634+
635+
if (auto iface = dyn_cast_or_null<DataLayoutOpInterface>(scope))
636+
manglingStyle = iface.getManglingStyle(entry);
637+
else
638+
manglingStyle = detail::getDefaultManglingStyle(entry);
639+
return *manglingStyle;
640+
}
641+
615642
mlir::Attribute mlir::DataLayout::getProgramMemorySpace() const {
616643
checkValid();
617644
if (programMemorySpace)

mlir/lib/Target/LLVMIR/DataLayoutImporter.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@ DataLayoutImporter::tryToEmplaceEndiannessEntry(StringRef endianness,
163163
return success();
164164
}
165165

166+
LogicalResult DataLayoutImporter::tryToEmplaceManglingStyleEntry(
167+
StringRef token, llvm::StringLiteral manglingKey) {
168+
auto key = StringAttr::get(context, manglingKey);
169+
if (keyEntries.count(key))
170+
return success();
171+
172+
token.consume_front(":");
173+
if (token.empty())
174+
return failure();
175+
176+
keyEntries.try_emplace(
177+
key, DataLayoutEntryAttr::get(key, StringAttr::get(context, token)));
178+
return success();
179+
}
180+
166181
LogicalResult
167182
DataLayoutImporter::tryToEmplaceAddrSpaceEntry(StringRef token,
168183
llvm::StringLiteral spaceKey) {
@@ -254,6 +269,13 @@ void DataLayoutImporter::translateDataLayout(
254269
return;
255270
continue;
256271
}
272+
// Parse the mangling style.
273+
if (*prefix == "m") {
274+
if (failed(tryToEmplaceManglingStyleEntry(
275+
token, DLTIDialect::kDataLayoutManglingStyleKey)))
276+
return;
277+
continue;
278+
}
257279
// Parse the global address space.
258280
if (*prefix == "G") {
259281
if (failed(tryToEmplaceAddrSpaceEntry(

mlir/lib/Target/LLVMIR/DataLayoutImporter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ class DataLayoutImporter {
100100
LogicalResult tryToEmplaceAddrSpaceEntry(StringRef token,
101101
llvm::StringLiteral spaceKey);
102102

103+
/// Adds an mangling style entry if there is none yet.
104+
LogicalResult tryToEmplaceManglingStyleEntry(StringRef token,
105+
llvm::StringLiteral manglingKey);
106+
103107
/// Adds a stack alignment entry if there is none yet.
104108
LogicalResult tryToEmplaceStackAlignmentEntry(StringRef token);
105109

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ translateDataLayout(DataLayoutSpecInterface attribute,
199199
layoutStream << "-" << (isLittleEndian ? "e" : "E");
200200
continue;
201201
}
202+
if (key.getValue() == DLTIDialect::kDataLayoutManglingStyleKey) {
203+
auto value = cast<StringAttr>(entry.getValue());
204+
layoutStream << "-m:" << value.getValue();
205+
continue;
206+
}
202207
if (key.getValue() == DLTIDialect::kDataLayoutProgramMemorySpaceKey) {
203208
auto value = cast<IntegerAttr>(entry.getValue());
204209
uint64_t space = value.getValue().getZExtValue();

mlir/test/Target/LLVMIR/Import/data-layout.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ target datalayout = ""
2929
; CHECK-DAG: !llvm.ptr<271> = dense<32> : vector<4xi64>
3030
; CHECK-DAG: !llvm.ptr<272> = dense<64> : vector<4xi64>
3131
; CHECK-DAG: "dlti.stack_alignment" = 128 : i64
32+
; CHECK-DAG: "dlti.mangling_style" = "e"
3233
target datalayout = "e-m:e-p270:32:64-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
3334

3435
; // -----

mlir/test/Target/LLVMIR/Import/import-failure.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ declare void @llvm.experimental.noalias.scope.decl(metadata)
354354
; CHECK-SAME: warning: unhandled data layout token: ni:42
355355
target datalayout = "e-ni:42-i64:64"
356356

357+
; // -----
358+
; CHECK: import-failure.ll
359+
; CHECK-SAME: malformed specification, must be of the form "m:<mangling>"
360+
target datalayout = "e-m-i64:64"
361+
357362
; // -----
358363

359364
; CHECK: <unknown>

mlir/test/Target/LLVMIR/data-layout.mlir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// CHECK: E-
55
// CHECK: A4-
66
// CHECK: S128-
7+
// CHECK: m:e-
78
// CHECK: i64:64:128
89
// CHECK: f80:128:256
910
// CHECK: p0:32:64:128:32
@@ -12,6 +13,7 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<
1213
#dlti.dl_entry<"dlti.endianness", "big">,
1314
#dlti.dl_entry<"dlti.alloca_memory_space", 4 : ui32>,
1415
#dlti.dl_entry<"dlti.stack_alignment", 128 : i32>,
16+
#dlti.dl_entry<"dlti.mangling_style", "e">,
1517
#dlti.dl_entry<index, 64>,
1618
#dlti.dl_entry<i64, dense<[64,128]> : vector<2xi64>>,
1719
#dlti.dl_entry<f80, dense<[128,256]> : vector<2xi64>>,

mlir/test/lib/Dialect/DLTI/TestDataLayoutQuery.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct TestDataLayoutQuery
4343
uint64_t index = layout.getTypeIndexBitwidth(op.getType()).value_or(0);
4444
Attribute endianness = layout.getEndianness();
4545
Attribute allocaMemorySpace = layout.getAllocaMemorySpace();
46+
Attribute manglingStyle = layout.getManglingStyle();
4647
Attribute programMemorySpace = layout.getProgramMemorySpace();
4748
Attribute globalMemorySpace = layout.getGlobalMemorySpace();
4849
uint64_t stackAlignment = layout.getStackAlignment();
@@ -72,6 +73,10 @@ struct TestDataLayoutQuery
7273
allocaMemorySpace == Attribute()
7374
? builder.getUI32IntegerAttr(0)
7475
: allocaMemorySpace),
76+
builder.getNamedAttr("mangling_style",
77+
manglingStyle == Attribute()
78+
? builder.getStringAttr("")
79+
: manglingStyle),
7580
builder.getNamedAttr("program_memory_space",
7681
programMemorySpace == Attribute()
7782
? builder.getUI32IntegerAttr(0)

mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ constexpr static llvm::StringLiteral kAttrName = "dltest.layout";
2525
constexpr static llvm::StringLiteral kEndiannesKeyName = "dltest.endianness";
2626
constexpr static llvm::StringLiteral kAllocaKeyName =
2727
"dltest.alloca_memory_space";
28+
constexpr static llvm::StringLiteral kManglingStyleKeyName = "dltest.mangling";
2829
constexpr static llvm::StringLiteral kProgramKeyName =
2930
"dltest.program_memory_space";
3031
constexpr static llvm::StringLiteral kGlobalKeyName =
@@ -83,6 +84,9 @@ struct CustomDataLayoutSpec
8384
StringAttr getAllocaMemorySpaceIdentifier(MLIRContext *context) const {
8485
return Builder(context).getStringAttr(kAllocaKeyName);
8586
}
87+
StringAttr getManglingStyleIdentifier(MLIRContext *context) const {
88+
return Builder(context).getStringAttr(kManglingStyleKeyName);
89+
}
8690
StringAttr getProgramMemorySpaceIdentifier(MLIRContext *context) const {
8791
return Builder(context).getStringAttr(kProgramKeyName);
8892
}

0 commit comments

Comments
 (0)