[flang-commits] [flang] [flang][OpenMP] Add alias analysis for omp private (PR #113566)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Thu Oct 24 09:09:27 PDT 2024


================
@@ -470,20 +481,56 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
           breakFromLoop = true;
         })
         .Case<hlfir::DeclareOp, fir::DeclareOp>([&](auto op) {
-          // If declare operation is inside omp target region,
-          // continue alias analysis outside the target region
-          if (auto targetOp =
-                  llvm::dyn_cast<omp::TargetOp>(op->getParentOp())) {
-            auto argIface = cast<omp::BlockArgOpenMPOpInterface>(*targetOp);
-            for (auto [opArg, blockArg] : llvm::zip_equal(
-                     targetOp.getMapVars(), argIface.getMapBlockArgs())) {
-              if (blockArg == op.getMemref()) {
-                omp::MapInfoOp mapInfo =
-                    llvm::cast<omp::MapInfoOp>(opArg.getDefiningOp());
-                v = mapInfo.getVarPtr();
-                defOp = v.getDefiningOp();
-                return;
-              }
+          auto argIface = getOpenMPBlockArgInterface(op->getParentOp());
+          if (argIface) {
+            Value ompValArg;
+            llvm::TypeSwitch<Operation *>(op->getParentOp())
+                .template Case<omp::TargetOp>([&](auto targetOp) {
+                  // If declare operation is inside omp target region,
+                  // continue alias analysis outside the target region
+                  for (auto [opArg, blockArg] :
+                       llvm::zip_equal(targetOp.getMapVars(),
+                                       (*argIface).getMapBlockArgs())) {
+                    if (blockArg == op.getMemref()) {
+                      omp::MapInfoOp mapInfo =
+                          llvm::cast<omp::MapInfoOp>(opArg.getDefiningOp());
+                      ompValArg = mapInfo.getVarPtr();
+                      break;
+                    }
+                  }
+                })
+                .template Case<omp::ParallelOp>([&](auto parallelOp) {
+                  // TODO private clause can be part of multiple
----------------
tblah wrote:

I imagine it should be possible to write this generically to work on any operation with an `OpenMPBlockArgInterface`. If the operation does not yet support delayed privatisation the private syms should be empty.

Reductions also work in the same way as delayed privatization (but don't feel that has to be done in this PR).

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


More information about the flang-commits mailing list