[Mlir-commits] [mlir] [WIP][flang][OpenMP] Translate OpenMP scopes when compiling for target device (PR #130078)

Sergio Afonso llvmlistbot at llvm.org
Thu Mar 6 07:20:50 PST 2025


================
@@ -5255,6 +5256,49 @@ convertTargetOpsInNest(Operation *op, llvm::IRBuilderBase &builder,
               return WalkResult::interrupt();
             return WalkResult::skip();
           }
+
+          // Non-target ops might nest target-related ops, therefore, we
+          // translate them as non-OpenMP scopes. Translating them is needed by
+          // nested target-related ops since they might LLVM values defined in
+          // their parent non-target ops.
+          if (isa<omp::OpenMPDialect>(oper->getDialect()) &&
+              oper->getParentOfType<LLVM::LLVMFuncOp>() &&
+              !oper->getRegions().empty()) {
+
+            // TODO Handle other ops with entry block args.
----------------
skatrak wrote:

It's an unfortunate limitation of the current implementation of the `BlockArgOpenMPOpInterface` that we can't also get the matching operation arguments associated to the block arguments. I think something like what's currently done for `numXyzBlockArgs()` methods should work. Then, here instead of checking for each type, we could do something like:
```c++
if (auto blockArgIface = dyn_cast<BlockArgOpenMPOpInterface>(oper)) {
  for (auto [arg, var] : llvm::zip_equal(llvm::concat(blockArgIface.getPrivateBlockArgs(), ...), blockArgIface.getPrivateVars(), ...))
    moduleTranslation.mapValue(arg, moduleTranslation.lookupValue(var));
}
```
I'll work on that, since it's been in my TODO list for some time, but no need to block this work waiting for it. We can simplify it later.

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


More information about the Mlir-commits mailing list