[llvm-branch-commits] [flang] [flang][CodeGen] Run PreCGRewrite on omp reduction declare ops (PR #84954)

Tom Eccles via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Mar 14 07:04:21 PDT 2024


https://github.com/tblah updated https://github.com/llvm/llvm-project/pull/84954

>From f951d16cf6cb1ab221f47ca2e712020b9af0af87 Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles at arm.com>
Date: Fri, 1 Mar 2024 16:59:09 +0000
Subject: [PATCH 1/4] [flang][CodeGen] Run PreCGRewrite on omp reduction
 declare ops

OpenMP reduction declare operations can contain FIR code which needs to
be lowered to LLVM. With array reductions, these regions can contain
more complicated operations which need PreCGRewriting. A similar extra
case was already needed for fir::GlobalOp.
---
 flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
index 0170b56367cf3c..dd935e71762355 100644
--- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
@@ -22,6 +22,7 @@
 #include "mlir/Transforms/RegionUtils.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Debug.h"
+#include <mlir/Dialect/OpenMP/OpenMPDialect.h>
 
 namespace fir {
 #define GEN_PASS_DEF_CODEGENREWRITE
@@ -319,6 +320,10 @@ class CodeGenRewrite : public fir::impl::CodeGenRewriteBase<CodeGenRewrite> {
       runOn(func, func.getBody());
     for (auto global : mod.getOps<fir::GlobalOp>())
       runOn(global, global.getRegion());
+    for (auto omp : mod.getOps<mlir::omp::ReductionDeclareOp>()) {
+      runOn(omp, omp.getInitializerRegion());
+      runOn(omp, omp.getReductionRegion());
+    }
   }
 };
 

>From b909193418789d1bcb572b69070fdca9c2d35a7c Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles at arm.com>
Date: Thu, 14 Mar 2024 07:54:12 +0000
Subject: [PATCH 2/4] Fix include

---
 flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
index dd935e71762355..097845e447842b 100644
--- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
@@ -18,11 +18,11 @@
 #include "flang/Optimizer/Dialect/FIROps.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Dialect/Support/FIRContext.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/Transforms/DialectConversion.h"
 #include "mlir/Transforms/RegionUtils.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Debug.h"
-#include <mlir/Dialect/OpenMP/OpenMPDialect.h>
 
 namespace fir {
 #define GEN_PASS_DEF_CODEGENREWRITE

>From 9d5026a16f4de4037d1fefa77d5c913085183150 Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles at arm.com>
Date: Thu, 14 Mar 2024 08:02:40 +0000
Subject: [PATCH 3/4] Run PreCGRewrite on all regions in the module

---
 flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
index 097845e447842b..410e6400c9be14 100644
--- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
@@ -284,7 +284,7 @@ class DeclareOpConversion : public mlir::OpRewritePattern<fir::DeclareOp> {
 
 class CodeGenRewrite : public fir::impl::CodeGenRewriteBase<CodeGenRewrite> {
 public:
-  void runOn(mlir::Operation *op, mlir::Region &region) {
+  void runOn(mlir::Operation *op) {
     auto &context = getContext();
     mlir::ConversionTarget target(context);
     target.addLegalDialect<mlir::arith::ArithDialect, fir::FIROpsDialect,
@@ -315,15 +315,8 @@ class CodeGenRewrite : public fir::impl::CodeGenRewriteBase<CodeGenRewrite> {
 
   void runOnOperation() override final {
     // Call runOn on all top level regions that may contain emboxOp/arrayCoorOp.
-    auto mod = getOperation();
-    for (auto func : mod.getOps<mlir::func::FuncOp>())
-      runOn(func, func.getBody());
-    for (auto global : mod.getOps<fir::GlobalOp>())
-      runOn(global, global.getRegion());
-    for (auto omp : mod.getOps<mlir::omp::ReductionDeclareOp>()) {
-      runOn(omp, omp.getInitializerRegion());
-      runOn(omp, omp.getReductionRegion());
-    }
+    mlir::ModuleOp mod = getOperation();
+    runOn(mod);
   }
 };
 

>From c7ffde450f0d3480be4532c4b21ed5a036fb8424 Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles at arm.com>
Date: Thu, 14 Mar 2024 14:03:13 +0000
Subject: [PATCH 4/4] Remove unessecary include

---
 flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
index 410e6400c9be14..4a05ad717f02f2 100644
--- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
@@ -18,7 +18,6 @@
 #include "flang/Optimizer/Dialect/FIROps.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Dialect/Support/FIRContext.h"
-#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/Transforms/DialectConversion.h"
 #include "mlir/Transforms/RegionUtils.h"
 #include "llvm/ADT/STLExtras.h"



More information about the llvm-branch-commits mailing list