[flang-commits] [flang] [flang] Avoid recursion in runtime derived type initialization (PR #102394)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Fri Aug 9 12:38:46 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};
----------------
klausler wrote:
the suffix is for private data members
https://github.com/llvm/llvm-project/pull/102394
More information about the flang-commits
mailing list