Skip to content

Commit 1f7effc

Browse files
[mlir][acc][flang] Use SymbolRefAttr for func_name in ACC routine (#146951)
Changed the type of the `func_name` attribute from SymbolNameAttr to SymbolRefAttr. SymbolNameAttr is typically used when defining a symbol (e.g., `sym_name`), while SymbolRefAttr is appropriate for referencing existing operations. This change ensures that MLIR can correctly track the link to the referenced `func.func` operation.
1 parent 0ceb0c3 commit 1f7effc

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4561,7 +4561,8 @@ void createOpenACCRoutineConstruct(
45614561
llvm::SmallVector<mlir::Attribute> &vectorDeviceTypes) {
45624562

45634563
for (auto routineOp : mod.getOps<mlir::acc::RoutineOp>()) {
4564-
if (routineOp.getFuncName().str().compare(funcName) == 0) {
4564+
if (routineOp.getFuncName().getLeafReference().str().compare(funcName) ==
4565+
0) {
45654566
// If the routine is already specified with the same clauses, just skip
45664567
// the operation creation.
45674568
if (compareDeviceTypeInfo(routineOp, bindNames, bindNameDeviceTypes,
@@ -4579,7 +4580,9 @@ void createOpenACCRoutineConstruct(
45794580
mlir::OpBuilder modBuilder(mod.getBodyRegion());
45804581
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
45814582
modBuilder.create<mlir::acc::RoutineOp>(
4582-
loc, routineOpStr, funcName, getArrayAttrOrNull(builder, bindNames),
4583+
loc, routineOpStr,
4584+
mlir::SymbolRefAttr::get(builder.getContext(), funcName),
4585+
getArrayAttrOrNull(builder, bindNames),
45834586
getArrayAttrOrNull(builder, bindNameDeviceTypes),
45844587
getArrayAttrOrNull(builder, workerDeviceTypes),
45854588
getArrayAttrOrNull(builder, vectorDeviceTypes),

mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,18 +2771,15 @@ def OpenACC_RoutineOp : OpenACC_Op<"routine", [IsolatedFromAbove]> {
27712771
must be modified as well.
27722772
}];
27732773

2774-
let arguments = (ins SymbolNameAttr:$sym_name,
2775-
SymbolNameAttr:$func_name,
2776-
OptionalAttr<StrArrayAttr>:$bindName,
2777-
OptionalAttr<DeviceTypeArrayAttr>:$bindNameDeviceType,
2778-
OptionalAttr<DeviceTypeArrayAttr>:$worker,
2779-
OptionalAttr<DeviceTypeArrayAttr>:$vector,
2780-
OptionalAttr<DeviceTypeArrayAttr>:$seq,
2781-
UnitAttr:$nohost,
2782-
UnitAttr:$implicit,
2783-
OptionalAttr<DeviceTypeArrayAttr>:$gang,
2784-
OptionalAttr<I64ArrayAttr>:$gangDim,
2785-
OptionalAttr<DeviceTypeArrayAttr>:$gangDimDeviceType);
2774+
let arguments = (ins SymbolNameAttr:$sym_name, SymbolRefAttr:$func_name,
2775+
OptionalAttr<StrArrayAttr>:$bindName,
2776+
OptionalAttr<DeviceTypeArrayAttr>:$bindNameDeviceType,
2777+
OptionalAttr<DeviceTypeArrayAttr>:$worker,
2778+
OptionalAttr<DeviceTypeArrayAttr>:$vector,
2779+
OptionalAttr<DeviceTypeArrayAttr>:$seq, UnitAttr:$nohost,
2780+
UnitAttr:$implicit, OptionalAttr<DeviceTypeArrayAttr>:$gang,
2781+
OptionalAttr<I64ArrayAttr>:$gangDim,
2782+
OptionalAttr<DeviceTypeArrayAttr>:$gangDimDeviceType);
27862783

27872784
let extraClassDeclaration = [{
27882785
static StringRef getGangDimKeyword() { return "dim"; }

0 commit comments

Comments
 (0)