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

Akash Banerjee via flang-commits flang-commits at lists.llvm.org
Wed Nov 1 12:39:59 PDT 2023


================
@@ -2430,6 +2448,89 @@ genEnterExitDataOp(Fortran::lower::AbstractConverter &converter,
                                    deviceOperand, nowaitAttr, mapOperands);
 }
 
+// This functions creates a block for the body of the targetOp's region. It adds
+// all the symbols present in mapSymbols as block arguments to this block.
+static void genBodyOfTargetOp(
+    Fortran::lower::AbstractConverter &converter,
+    Fortran::lower::pft::Evaluation &eval, mlir::omp::TargetOp &targetOp,
+    const llvm::SmallVector<mlir::Type> &mapSymTypes,
+    const llvm::SmallVector<mlir::Location> &mapSymLocs,
+    const llvm::SmallVector<const Fortran::semantics::Symbol *> &mapSymbols,
+    const mlir::Location &currentLocation, bool outerCombined) {
+  assert(mapSymTypes.size() == mapSymLocs.size());
+
+  fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+  mlir::Region &region = targetOp.getRegion();
+
+  firOpBuilder.createBlock(&region, {}, mapSymTypes, mapSymLocs);
+  firOpBuilder.create<mlir::omp::TerminatorOp>(currentLocation);
+  firOpBuilder.setInsertionPointToStart(&region.front());
+
+  // If it is an unstructured region and is not the outer region of a combined
+  // construct, create empty blocks for all evaluations.
+  if (eval.lowerAsUnstructured() && !outerCombined)
+    Fortran::lower::createEmptyRegionBlocks<mlir::omp::TerminatorOp,
+                                            mlir::omp::YieldOp>(
+        firOpBuilder, eval.getNestedEvaluations());
----------------
TIFitis wrote:

> I am assuming this happens only when there is unstructured code (code with jumps, do while etc) in the body of the operation. There is some special handling for unstructured code, have a look at
> 
> https://github.com/llvm/llvm-project/blob/6c320b434d249c0d5692cbecc0e67ec22d659b7e/flang/lib/Lower/OpenMP.cpp#L2132
> 

Just adding these lines didn't make any difference. Sorry, but couldn't find anything else that was directly related to it that I could add. Any idea what else needs to be done?

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


More information about the flang-commits mailing list