[flang-commits] [flang] [OpenMP][Flang] Add "IsolatedFromAbove" trait to omp.target (PR #67164)

via flang-commits flang-commits at lists.llvm.org
Fri Oct 6 07:21:46 PDT 2023


================
@@ -2433,10 +2502,44 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
                  Fortran::parser::OmpClause::Defaultmap>(
       currentLocation, llvm::omp::Directive::OMPD_target);
 
-  return genOpWithBody<mlir::omp::TargetOp>(
-      converter, eval, currentLocation, outerCombined, &clauseList,
-      ifClauseOperand, deviceOperand, threadLimitOperand, nowaitAttr,
-      mapOperands);
+  auto captureImplicitMap = [&](const Fortran::semantics::Symbol &sym) {
+    if (llvm::find(mapSymbols, &sym) == mapSymbols.end()) {
+      mlir::Value baseOp = converter.getSymbolAddress(sym);
+      if (!baseOp)
+        if (const auto *details = sym.template detailsIf<
+                                  Fortran::semantics::HostAssocDetails>()) {
+          baseOp = converter.getSymbolAddress(details->symbol());
+          converter.copySymbolBinding(details->symbol(), sym);
+        }
+
----------------
jeanPerier wrote:

Hi @TIFitis, first of all you cannot map extents/lengths to symbols: specifications in Fortran can be many other things than named objects (something that has a semantics::Symbols). An extent may be, `2*n+1`, there is no symbol for that.

You do not need to care about PFT/Symbols IMHO. You should most likely start from the ExtendedValue SSA values instead of going back to the Symbol evaluate::Expr (this is non trivial and there would be quite some risk to miss some relevant specification value).

My advice:

Either 1.:
- Manage to make a single value for the whole entity being passed as a block argument (i.e, make it a fir.boxchar/fir.box when some extents/lengths are needed). This is easier to do with HLFIR, since symbols are mapped to single SSA value in HLFIR. Probably the cleanest, but may not lead to performant code right away (too much "opaque" fir.box).

Or 2.:
- make some fir::ExtendedValue visitor that visits all the SSA value.
- You call it a first time when creating your block argument types, for non constant SSA values (can checked with something like [this helper that you could expose in FIRBuilder.h](https://github.com/llvm/llvm-project/blob/22f81b4cf4cbf001a8a27877274eb157a12466c3/flang/include/flang/Optimizer/Dialect/FIROpsSupport.h#L136)), push a block arguments.
- You call it a second time when mapping the new symbol inside the block, to re-create the constant value and map the block arguments/new ones (assuming the visit is non const and you can modify the SSA values on the fly).

Or 3.:
- You lower "as usual" in some not isolated from above region, and run some MLIR based pass later to capture SSA values used from outside via IRMapping and cloning after the target region is lowered. You should most likely do it in a pass after lowering (advised for better testing/debugging). It may just be the easiest IMHO.

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


More information about the flang-commits mailing list