diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -2748,6 +2748,19 @@ loc, routineOpName.str(), func.getName(), mlir::StringAttr{}, mlir::UnitAttr{}, mlir::UnitAttr{}, mlir::UnitAttr{}, mlir::UnitAttr{}, mlir::UnitAttr{}, mlir::UnitAttr{}, mlir::IntegerAttr{}); + + llvm::SmallVector routines; + if (func.getOperation()->hasAttr(mlir::acc::getRoutineInfoAttrName())) { + auto routineInfo = + func.getOperation()->getAttrOfType( + mlir::acc::getRoutineInfoAttrName()); + routines.append(routineInfo.getAccRoutines().begin(), + routineInfo.getAccRoutines().end()); + } + routines.push_back(builder.getSymbolRefAttr(routineOpName.str())); + func.getOperation()->setAttr( + mlir::acc::getRoutineInfoAttrName(), + mlir::acc::RoutineInfoAttr::get(builder.getContext(), routines)); } void Fortran::lower::genOpenACCConstruct( diff --git a/flang/test/Lower/OpenACC/acc-routine.f90 b/flang/test/Lower/OpenACC/acc-routine.f90 --- a/flang/test/Lower/OpenACC/acc-routine.f90 +++ b/flang/test/Lower/OpenACC/acc-routine.f90 @@ -7,4 +7,4 @@ end subroutine ! CHECK: acc.routine @acc_routine_0 func(@_QPacc_routine1) -! CHECK-LABEL: func.func @_QPacc_routine1() +! CHECK-LABEL: func.func @_QPacc_routine1() attributes {acc.routine_info = #acc.routine_info<[@acc_routine_0]>} diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h --- a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h +++ b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h @@ -82,6 +82,10 @@ return StringLiteral("acc.declare_action"); } +static constexpr StringLiteral getRoutineInfoAttrName() { + return StringLiteral("acc.routine_info"); +} + } // namespace acc } // namespace mlir