[flang] Define & implement a lowering support API IsContiguous() in runtime
Create a new flang/runtime/support.cpp module to hold miscellaneous
runtime APIs to support lowering, and define an API IsContiguous() to
wrap the member function predicate Descriptor::IsContiguous().
And do a little clean-up of other API headers that don't need to expose
Runtime/descriptor.h.
Differential Revision: https://reviews.llvm.org/D114752
diff --git a/flang/include/flang/Runtime/reduction.h b/flang/include/flang/Runtime/reduction.h
index d70bb0d..b4aeaad 100644
--- a/flang/include/flang/Runtime/reduction.h
+++ b/flang/include/flang/Runtime/reduction.h
@@ -12,12 +12,15 @@
#define FORTRAN_RUNTIME_REDUCTION_H_
#include "flang/Common/uint128.h"
-#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/entry-names.h"
+#include <cinttypes>
#include <complex>
#include <cstdint>
namespace Fortran::runtime {
+
+class Descriptor;
+
extern "C" {
// Reductions that are known to return scalars have per-type entry
diff --git a/flang/include/flang/Runtime/support.h b/flang/include/flang/Runtime/support.h
new file mode 100644
index 0000000..532fc53
--- /dev/null
+++ b/flang/include/flang/Runtime/support.h
@@ -0,0 +1,26 @@
+//===-- include/flang/Runtime/support.h -------------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Defines APIs for runtime support code for lowering.
+#ifndef FORTRAN_RUNTIME_SUPPORT_H_
+#define FORTRAN_RUNTIME_SUPPORT_H_
+
+#include "flang/Runtime/entry-names.h"
+
+namespace Fortran::runtime {
+
+class Descriptor;
+
+extern "C" {
+
+// Predicate: is the storage described by a Descriptor contiguous in memory?
+bool RTNAME(IsContiguous)(const Descriptor &);
+
+} // extern "C"
+} // namespace Fortran::runtime
+#endif // FORTRAN_RUNTIME_SUPPORT_H_
diff --git a/flang/include/flang/Runtime/transformational.h b/flang/include/flang/Runtime/transformational.h
index ad17d48..21a4418 100644
--- a/flang/include/flang/Runtime/transformational.h
+++ b/flang/include/flang/Runtime/transformational.h
@@ -17,12 +17,13 @@
#ifndef FORTRAN_RUNTIME_TRANSFORMATIONAL_H_
#define FORTRAN_RUNTIME_TRANSFORMATIONAL_H_
-#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/entry-names.h"
-#include "flang/Runtime/memory.h"
+#include <cinttypes>
namespace Fortran::runtime {
+class Descriptor;
+
extern "C" {
void RTNAME(Reshape)(Descriptor &result, const Descriptor &source,
diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index b3e96fa..8b3a7a9 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -70,6 +70,7 @@
stat.cpp
stop.cpp
sum.cpp
+ support.cpp
terminator.cpp
time-intrinsic.cpp
tools.cpp
diff --git a/flang/runtime/reduction.cpp b/flang/runtime/reduction.cpp
index 0f858c8..dea25cf 100644
--- a/flang/runtime/reduction.cpp
+++ b/flang/runtime/reduction.cpp
@@ -15,6 +15,7 @@
#include "flang/Runtime/reduction.h"
#include "reduction-templates.h"
+#include "flang/Runtime/descriptor.h"
#include <cinttypes>
namespace Fortran::runtime {
diff --git a/flang/runtime/support.cpp b/flang/runtime/support.cpp
new file mode 100644
index 0000000..88a3e79
--- /dev/null
+++ b/flang/runtime/support.cpp
@@ -0,0 +1,20 @@
+//===-- runtime/support.cpp -----------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Runtime/support.h"
+#include "flang/Runtime/descriptor.h"
+
+namespace Fortran::runtime {
+extern "C" {
+
+bool RTNAME(IsContiguous)(const Descriptor &descriptor) {
+ return descriptor.IsContiguous();
+}
+
+} // extern "C"
+} // namespace Fortran::runtime
diff --git a/flang/runtime/terminator.h b/flang/runtime/terminator.h
index dbf08fe..107bbc8 100644
--- a/flang/runtime/terminator.h
+++ b/flang/runtime/terminator.h
@@ -11,7 +11,6 @@
#ifndef FORTRAN_RUNTIME_TERMINATOR_H_
#define FORTRAN_RUNTIME_TERMINATOR_H_
-#include "flang/Runtime/entry-names.h"
#include <cstdarg>
namespace Fortran::runtime {
diff --git a/flang/runtime/transformational.cpp b/flang/runtime/transformational.cpp
index 0ac1d46..79d1373 100644
--- a/flang/runtime/transformational.cpp
+++ b/flang/runtime/transformational.cpp
@@ -20,6 +20,7 @@
#include "copy.h"
#include "terminator.h"
#include "tools.h"
+#include "flang/Runtime/descriptor.h"
#include <algorithm>
namespace Fortran::runtime {