[flang] Define & implement a lowering support API IsContiguous() in runtime
authorPeter Klausler <pklausler@nvidia.com>
Fri, 26 Nov 2021 19:39:31 +0000 (11:39 -0800)
committerPeter Klausler <pklausler@nvidia.com>
Tue, 30 Nov 2021 22:15:56 +0000 (14:15 -0800)
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

flang/include/flang/Runtime/reduction.h
flang/include/flang/Runtime/support.h [new file with mode: 0644]
flang/include/flang/Runtime/transformational.h
flang/runtime/CMakeLists.txt
flang/runtime/reduction.cpp
flang/runtime/support.cpp [new file with mode: 0644]
flang/runtime/terminator.h
flang/runtime/transformational.cpp

index d70bb0d..b4aeaad 100644 (file)
 #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 (file)
index 0000000..532fc53
--- /dev/null
@@ -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_
index ad17d48..21a4418 100644 (file)
 #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,
index b3e96fa..8b3a7a9 100644 (file)
@@ -70,6 +70,7 @@ add_flang_library(FortranRuntime
   stat.cpp
   stop.cpp
   sum.cpp
+  support.cpp
   terminator.cpp
   time-intrinsic.cpp
   tools.cpp
index 0f858c8..dea25cf 100644 (file)
@@ -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 (file)
index 0000000..88a3e79
--- /dev/null
@@ -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
index dbf08fe..107bbc8 100644 (file)
@@ -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 {
index 0ac1d46..79d1373 100644 (file)
@@ -20,6 +20,7 @@
 #include "copy.h"
 #include "terminator.h"
 #include "tools.h"
+#include "flang/Runtime/descriptor.h"
 #include <algorithm>
 
 namespace Fortran::runtime {