[flang] [clang] [clang-tools-extra] [llvm] [compiler-rt] [Flang][OpenMP] Restructure recursive lowering in `createBodyOfOp` (PR #77761)

Krzysztof Parzyszek via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 18 11:21:03 PST 2024


================
@@ -2186,11 +2178,43 @@ static void createBodyOfOp(
     const llvm::SmallVector<const Fortran::semantics::Symbol *> &args = {},
     bool outerCombined = false, DataSharingProcessor *dsp = nullptr) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+
+  auto insertMarker = [](fir::FirOpBuilder &builder) {
+    mlir::Value undef = builder.create<fir::UndefOp>(builder.getUnknownLoc(),
+                                                     builder.getIndexType());
+    return undef.getDefiningOp();
+  };
+
+  // Find the block where the OMP terminator should go. In simple cases
+  // it is the single block in the operation's region. When the region
+  // is more complicated, especially with unstructured control flow, there
+  // may be multiple blocks, and some of them may have non-OMP terminators
+  // resulting from lowering of the code contained within the operation.
+  // By OpenMP rules, there should be a single exit point from the region:
+  // here exit means transfering control to the code following the operation.
+  // STOP statement is allowed and does not count as exit for the purpose of
----------------
kparzysz wrote:

STOP is lowered as a function call, so we don't really see it as a control-flow construct in FIR.

Otherwise, you're right---it looks for blocks that haven't been terminated by any nested construct (i.e. after removing the temporary terminator at the end of the region), and asserts if there are more than 1.

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


More information about the cfe-commits mailing list