[Mlir-commits] [flang] [mlir] [Flang][OpenACC] add loop annotations to acc.loop (PR #216769)

Scott Manley llvmlistbot at llvm.org
Tue Aug 18 05:52:39 PDT 2026


================
@@ -2503,12 +2530,15 @@ static mlir::acc::LoopOp createLoopOp(
     loopOp.setCombinedAttr(mlir::acc::CombinedConstructsTypeAttr::get(
         builder.getContext(), *combinedConstructs));
 
-  // TODO: retrieve directives from NonLabelDoStmt pft::Evaluation, and add them
-  // as attribute to the acc.loop as an extra attribute. It is not quite clear
-  // how useful these $dir are in acc contexts, but they could still provide
-  // more information about the loop acc codegen. They can be obtained by
-  // looking for the first lexicalSuccessor of eval that is a NonLabelDoStmt,
-  // and using the related `dirs` member.
+  // Apply `!dir$` loop directives associated with the DO statement as a
+  // discardable LLVM loop annotation attribute on the acc.loop.
+  if (Fortran::lower::pft::Evaluation *doStmtEval =
+          getAccLoopDoStmtEval(eval)) {
+    if (mlir::LLVM::LoopAnnotationAttr la =
+            Fortran::lower::genLoopAnnotationAttr(builder.getContext(),
+                                                  doStmtEval->dirs))
+      loopOp->setDiscardableAttr("loopAnnotation", la);
----------------
rscottmanley wrote:

this should have used the loop annotation name, will fix

https://github.com/llvm/llvm-project/pull/216769


More information about the Mlir-commits mailing list