[flang-commits] [flang] [flang] Avoid recursion in runtime derived type initialization (PR #102394)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Fri Aug 9 12:34:24 PDT 2024


================
@@ -0,0 +1,144 @@
+//===-- runtime/engine.h --------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Implements a work engine for restartable tasks iterating over elements,
+// components, &c. of arrays and derived types.  Avoids recursion and
+// function pointers.
+
+#ifndef FORTRAN_RUNTIME_ENGINE_H_
+#define FORTRAN_RUNTIME_ENGINE_H_
+
+#include "derived.h"
+#include "stat.h"
+#include "terminator.h"
+#include "type-info.h"
+#include "flang/Runtime/descriptor.h"
+
+namespace Fortran::runtime::engine {
+
+class Engine;
+
+// Every task object derives from Task.
+struct Task {
+
+  enum class ResultType { ResultValue /*doesn't matter*/ };
+
+  struct Iteration {
+    RT_API_ATTRS bool Iterating(
+        std::size_t iters, const Descriptor *dtor = nullptr) {
+      if (!active) {
+        if (iters > 0) {
+          active = true;
+          at = 0;
+          n = iters;
+          descriptor = dtor;
+          if (descriptor) {
+            descriptor->GetLowerBounds(subscripts);
+          }
+        }
+      } else if (resuming) {
+        resuming = false;
+      } else if (++at < n) {
+        if (descriptor) {
+          descriptor->IncrementSubscripts(subscripts);
+        }
+      } else {
+        active = false;
+      }
+      return active;
+    }
+    // Call on all Iteration instances before calling Engine::Begin()
+    // when they should not advance when the job is resumed.
+    RT_API_ATTRS void ResumeAtSameIteration() { resuming = true; }
+
+    bool active{false}, resuming{false};
----------------
vzakhari wrote:

We seem to be using `_` suffix for all members in F18 RT. Or is there an exception for the nested classes?

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


More information about the flang-commits mailing list