[flang-commits] [flang] [mlir] [acc][flang] Use SymbolRefAttr for func_name in ACC routine (PR #146951)
via flang-commits
flang-commits at lists.llvm.org
Thu Jul 3 12:36:51 PDT 2025
https://github.com/delaram-talaashrafi created https://github.com/llvm/llvm-project/pull/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.
>From 6a28e458f6c7aaf703a2f6d78df39f9b339039b1 Mon Sep 17 00:00:00 2001
From: Delaram Talaashrafi <dtalaashrafi at rome5.pgi.net>
Date: Thu, 3 Jul 2025 11:04:36 -0700
Subject: [PATCH] [acc][flang] Use SymbolRefAttr for func_name in ACC routine
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.
---
flang/lib/Lower/OpenACC.cpp | 7 +++++--
.../mlir/Dialect/OpenACC/OpenACCOps.td | 21 ++++++++-----------
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 3ef3330cba2d6..e56d7f7ed9b6f 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -4561,7 +4561,8 @@ void createOpenACCRoutineConstruct(
llvm::SmallVector<mlir::Attribute> &vectorDeviceTypes) {
for (auto routineOp : mod.getOps<mlir::acc::RoutineOp>()) {
- if (routineOp.getFuncName().str().compare(funcName) == 0) {
+ if (routineOp.getFuncName().getLeafReference().str().compare(funcName) ==
+ 0) {
// If the routine is already specified with the same clauses, just skip
// the operation creation.
if (compareDeviceTypeInfo(routineOp, bindNames, bindNameDeviceTypes,
@@ -4579,7 +4580,9 @@ void createOpenACCRoutineConstruct(
mlir::OpBuilder modBuilder(mod.getBodyRegion());
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
modBuilder.create<mlir::acc::RoutineOp>(
- loc, routineOpStr, funcName, getArrayAttrOrNull(builder, bindNames),
+ loc, routineOpStr,
+ mlir::SymbolRefAttr::get(builder.getContext(), funcName),
+ getArrayAttrOrNull(builder, bindNames),
getArrayAttrOrNull(builder, bindNameDeviceTypes),
getArrayAttrOrNull(builder, workerDeviceTypes),
getArrayAttrOrNull(builder, vectorDeviceTypes),
diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
index 276b74bd43772..66378f116784e 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
@@ -2771,18 +2771,15 @@ def OpenACC_RoutineOp : OpenACC_Op<"routine", [IsolatedFromAbove]> {
must be modified as well.
}];
- let arguments = (ins SymbolNameAttr:$sym_name,
- SymbolNameAttr:$func_name,
- OptionalAttr<StrArrayAttr>:$bindName,
- OptionalAttr<DeviceTypeArrayAttr>:$bindNameDeviceType,
- OptionalAttr<DeviceTypeArrayAttr>:$worker,
- OptionalAttr<DeviceTypeArrayAttr>:$vector,
- OptionalAttr<DeviceTypeArrayAttr>:$seq,
- UnitAttr:$nohost,
- UnitAttr:$implicit,
- OptionalAttr<DeviceTypeArrayAttr>:$gang,
- OptionalAttr<I64ArrayAttr>:$gangDim,
- OptionalAttr<DeviceTypeArrayAttr>:$gangDimDeviceType);
+ let arguments = (ins SymbolNameAttr:$sym_name, SymbolRefAttr:$func_name,
+ OptionalAttr<StrArrayAttr>:$bindName,
+ OptionalAttr<DeviceTypeArrayAttr>:$bindNameDeviceType,
+ OptionalAttr<DeviceTypeArrayAttr>:$worker,
+ OptionalAttr<DeviceTypeArrayAttr>:$vector,
+ OptionalAttr<DeviceTypeArrayAttr>:$seq, UnitAttr:$nohost,
+ UnitAttr:$implicit, OptionalAttr<DeviceTypeArrayAttr>:$gang,
+ OptionalAttr<I64ArrayAttr>:$gangDim,
+ OptionalAttr<DeviceTypeArrayAttr>:$gangDimDeviceType);
let extraClassDeclaration = [{
static StringRef getGangDimKeyword() { return "dim"; }
More information about the flang-commits
mailing list