Skip to content

[Flang] Move non-Common headers to FortranSupport #124416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 6, 2025

Conversation

Meinersbur
Copy link
Member

@Meinersbur Meinersbur commented Jan 25, 2025

Move non-common files from FortranCommon to FortranSupport (analogous to LLVMSupport) such that

  • declarations and definitions that are only used by the Flang compiler, but not by the runtime, are moved to FortranSupport

  • declarations and definitions that are used by both ("common"), the compiler and the runtime, remain in FortranCommon

  • Generic STL-like/ADT/utility classes and algorithms remain in FortranCommon

This allows a for cleaner separation between compiler and runtime components, which are compiled differently. For instance, runtime sources must not use STL's <optional> which causes problems with CUDA support. Instead, the surrogate header flang/Common/optional.h must be used. This PR fixes this for fast-int-sel.h.

Declarations in include/Runtime are also used by both, but are header-only. ISO_Fortran_binding_wrapper.h, a header used by compiler and runtime, is also moved into FortranCommon.

The PR is split off from #110298 and #110217.

@Meinersbur Meinersbur changed the title [Flang] Introduce FortranSupport [Flang] Move non-Common headers to FortranSupport Jan 25, 2025
@Meinersbur Meinersbur marked this pull request as ready for review January 27, 2025 10:16
@Meinersbur Meinersbur requested review from jhuber6 and jplehr January 27, 2025 10:16
@llvmbot
Copy link
Member

llvmbot commented Jan 27, 2025

@llvm/pr-subscribers-flang-parser
@llvm/pr-subscribers-flang-runtime

@llvm/pr-subscribers-flang-driver

Author: Michael Kruse (Meinersbur)

Changes

Split off FortranSupport (analogous to LLVMSupport) from FortranCommon such that

  • declarations and definitions that are only used by the Flang compiler, but not by the runtime, are moved to FortranSupport

  • declarations and definitions that are used by both ("common"), the compiler and the runtime, remain in FortranCommon

This allows a for cleaner separation between compiler and runtime components, which are compiled differently. For instance, runtime sources must not use STL's &lt;optional&gt; which causes problems with CUDA support. Instead, the surrogate header flang/Common/optional.h must be used. This PR fixes this for fast-int-sel.h.

Declarations in include/Runtime are also used by both, but are header-only. ISO_Fortran_binding_wrapper.h, a header used by compiler and runtime, is also moved into FortranCommon.

The PR is split off from #110298 and #110217.


Patch is 117.01 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/124416.diff

160 Files Affected:

  • (renamed) flang/include/flang/Common/ISO_Fortran_binding_wrapper.h (+7-8)
  • (modified) flang/include/flang/Common/fast-int-set.h (+3-3)
  • (modified) flang/include/flang/Evaluate/call.h (+3-3)
  • (modified) flang/include/flang/Evaluate/characteristics.h (+3-3)
  • (modified) flang/include/flang/Evaluate/common.h (+4-4)
  • (modified) flang/include/flang/Evaluate/constant.h (+2-2)
  • (modified) flang/include/flang/Evaluate/expression.h (+3-3)
  • (modified) flang/include/flang/Evaluate/formatting.h (+1-1)
  • (modified) flang/include/flang/Evaluate/intrinsics.h (+1-1)
  • (modified) flang/include/flang/Evaluate/shape.h (+1-1)
  • (modified) flang/include/flang/Evaluate/target.h (+1-1)
  • (modified) flang/include/flang/Evaluate/tools.h (+2-2)
  • (modified) flang/include/flang/Evaluate/traverse.h (+1-1)
  • (modified) flang/include/flang/Evaluate/type.h (+3-3)
  • (modified) flang/include/flang/Evaluate/variable.h (+2-2)
  • (modified) flang/include/flang/Frontend/CompilerInvocation.h (+1-1)
  • (modified) flang/include/flang/Frontend/FrontendOptions.h (+1-1)
  • (modified) flang/include/flang/ISO_Fortran_binding.h (+1-1)
  • (modified) flang/include/flang/Lower/AbstractConverter.h (+1-1)
  • (modified) flang/include/flang/Lower/Bridge.h (+1-1)
  • (modified) flang/include/flang/Lower/CallInterface.h (+1-1)
  • (modified) flang/include/flang/Lower/ConvertType.h (+1-1)
  • (modified) flang/include/flang/Lower/LoweringOptions.h (+1-1)
  • (modified) flang/include/flang/Lower/PFTBuilder.h (+2-2)
  • (modified) flang/include/flang/Lower/Support/Utils.h (+1-1)
  • (modified) flang/include/flang/Lower/SymbolMap.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Builder/FIRBuilder.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h (+1-1)
  • (modified) flang/include/flang/Optimizer/CodeGen/DescriptorModel.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Support/TypeCode.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Support/Utils.h (+1-1)
  • (modified) flang/include/flang/Parser/char-block.h (+1-1)
  • (modified) flang/include/flang/Parser/dump-parse-tree.h (+2-2)
  • (modified) flang/include/flang/Parser/message.h (+2-2)
  • (modified) flang/include/flang/Parser/parse-state.h (+1-1)
  • (modified) flang/include/flang/Parser/parse-tree.h (+2-2)
  • (modified) flang/include/flang/Parser/parsing.h (+1-1)
  • (modified) flang/include/flang/Parser/provenance.h (+1-1)
  • (modified) flang/include/flang/Parser/source.h (+1-1)
  • (modified) flang/include/flang/Parser/user-state.h (+1-1)
  • (modified) flang/include/flang/Runtime/descriptor-consts.h (+1-1)
  • (modified) flang/include/flang/Runtime/descriptor.h (+1-1)
  • (modified) flang/include/flang/Runtime/random.h (+5)
  • (modified) flang/include/flang/Runtime/support.h (+1-1)
  • (modified) flang/include/flang/Runtime/type-code.h (+1-1)
  • (modified) flang/include/flang/Semantics/expression.h (+2-2)
  • (modified) flang/include/flang/Semantics/runtime-type-info.h (+1-1)
  • (modified) flang/include/flang/Semantics/scope.h (+2-2)
  • (modified) flang/include/flang/Semantics/semantics.h (+2-2)
  • (modified) flang/include/flang/Semantics/symbol.h (+2-2)
  • (modified) flang/include/flang/Semantics/tools.h (+1-1)
  • (modified) flang/include/flang/Semantics/type.h (+1-1)
  • (renamed) flang/include/flang/Support/Fortran-features.h (+5-5)
  • (renamed) flang/include/flang/Support/Fortran.h (+6-6)
  • (renamed) flang/include/flang/Support/LangOptions.def ()
  • (renamed) flang/include/flang/Support/LangOptions.h (+7-7)
  • (renamed) flang/include/flang/Support/MathOptionsBase.def ()
  • (renamed) flang/include/flang/Support/MathOptionsBase.h (+7-7)
  • (renamed) flang/include/flang/Support/OpenMP-features.h (+4-4)
  • (modified) flang/include/flang/Support/Timing.h (+4-4)
  • (renamed) flang/include/flang/Support/Version.h (+4-4)
  • (renamed) flang/include/flang/Support/default-kinds.h (+5-5)
  • (renamed) flang/include/flang/Support/indirection.h (+5-5)
  • (renamed) flang/include/flang/Support/interval.h (+5-5)
  • (renamed) flang/include/flang/Support/reference-counted.h (+4-4)
  • (renamed) flang/include/flang/Support/reference.h (+4-4)
  • (renamed) flang/include/flang/Support/static-multimap-view.h (+4-4)
  • (renamed) flang/include/flang/Support/template.h (+5-5)
  • (renamed) flang/include/flang/Support/unwrap.h (+6-6)
  • (modified) flang/include/flang/Tools/CrossToolHelpers.h (+2-2)
  • (modified) flang/lib/CMakeLists.txt (-1)
  • (removed) flang/lib/Common/CMakeLists.txt (-52)
  • (modified) flang/lib/Evaluate/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Evaluate/call.cpp (+1-1)
  • (modified) flang/lib/Evaluate/characteristics.cpp (+1-1)
  • (modified) flang/lib/Evaluate/fold-implementation.h (+3-3)
  • (modified) flang/lib/Evaluate/formatting.cpp (+1-1)
  • (modified) flang/lib/Evaluate/intrinsics-library.cpp (+1-1)
  • (modified) flang/lib/Evaluate/intrinsics.cpp (+1-1)
  • (modified) flang/lib/Evaluate/shape.cpp (+1-1)
  • (modified) flang/lib/Evaluate/target.cpp (+1-1)
  • (modified) flang/lib/Frontend/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Frontend/CompilerInstance.cpp (+1-1)
  • (modified) flang/lib/Frontend/CompilerInvocation.cpp (+3-3)
  • (modified) flang/lib/Frontend/FrontendActions.cpp (+1-1)
  • (modified) flang/lib/Lower/Bridge.cpp (+1-1)
  • (modified) flang/lib/Lower/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Lower/CallInterface.cpp (+1-1)
  • (modified) flang/lib/Lower/ConvertExpr.cpp (+2-2)
  • (modified) flang/lib/Lower/Mangler.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Builder/IntrinsicCall.cpp (+1-1)
  • (modified) flang/lib/Optimizer/CodeGen/TypeConverter.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Dialect/FIRType.cpp (+1-1)
  • (modified) flang/lib/Optimizer/OpenMP/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Optimizer/Passes/CMakeLists.txt (+1-4)
  • (modified) flang/lib/Optimizer/Transforms/AddDebugInfo.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CUFDeviceGlobal.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CUFOpConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/LoopVersioning.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/StackReclaim.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/VScaleAttr.cpp (+1-1)
  • (modified) flang/lib/Parser/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Parser/basic-parsers.h (+2-2)
  • (modified) flang/lib/Parser/parse-tree.cpp (+1-1)
  • (modified) flang/lib/Parser/prescan.h (+1-1)
  • (modified) flang/lib/Parser/unparse.cpp (+2-2)
  • (modified) flang/lib/Semantics/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Semantics/assignment.h (+1-1)
  • (modified) flang/lib/Semantics/check-case.cpp (+2-2)
  • (modified) flang/lib/Semantics/check-coarray.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-cuda.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-data.h (+1-1)
  • (modified) flang/lib/Semantics/check-do-forall.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-return.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-select-rank.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-select-type.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-stop.cpp (+1-1)
  • (modified) flang/lib/Semantics/data-to-inits.h (+2-2)
  • (modified) flang/lib/Semantics/expression.cpp (+1-1)
  • (modified) flang/lib/Semantics/pointer-assignment.cpp (+1-1)
  • (modified) flang/lib/Semantics/resolve-labels.cpp (+1-1)
  • (modified) flang/lib/Semantics/resolve-names-utils.cpp (+3-3)
  • (modified) flang/lib/Semantics/resolve-names.cpp (+3-3)
  • (modified) flang/lib/Semantics/rewrite-parse-tree.cpp (+1-1)
  • (modified) flang/lib/Semantics/semantics.cpp (+1-1)
  • (modified) flang/lib/Semantics/tools.cpp (+2-2)
  • (modified) flang/lib/Support/CMakeLists.txt (+53)
  • (renamed) flang/lib/Support/Fortran-features.cpp (+3-3)
  • (renamed) flang/lib/Support/Fortran.cpp (+3-3)
  • (renamed) flang/lib/Support/LangOptions.cpp (+3-3)
  • (renamed) flang/lib/Support/OpenMP-utils.cpp (+1-1)
  • (modified) flang/lib/Support/Timing.cpp (+1-1)
  • (renamed) flang/lib/Support/Version.cpp (+2-2)
  • (renamed) flang/lib/Support/default-kinds.cpp (+2-2)
  • (renamed) flang/lib/Support/idioms.cpp (+1-1)
  • (modified) flang/runtime/CUDA/allocator.cpp (+2-2)
  • (modified) flang/runtime/ISO_Fortran_binding.cpp (+1-1)
  • (modified) flang/runtime/ISO_Fortran_util.h (+1-1)
  • (modified) flang/runtime/allocatable.cpp (+1-1)
  • (modified) flang/runtime/stat.h (+1-1)
  • (modified) flang/runtime/temporary-stack.cpp (+1-1)
  • (modified) flang/tools/bbc/CMakeLists.txt (+1-1)
  • (modified) flang/tools/bbc/bbc.cpp (+5-5)
  • (modified) flang/tools/f18-parse-demo/CMakeLists.txt (+1-1)
  • (modified) flang/tools/f18-parse-demo/f18-parse-demo.cpp (+2-2)
  • (modified) flang/tools/tco/CMakeLists.txt (+1-1)
  • (modified) flang/unittests/Evaluate/CMakeLists.txt (+3-3)
  • (modified) flang/unittests/Evaluate/ISO-Fortran-binding.cpp (+1-1)
  • (modified) flang/unittests/Frontend/CMakeLists.txt (+1-1)
  • (modified) flang/unittests/Runtime/CUDA/Allocatable.cpp (+1-1)
  • (modified) flang/unittests/Runtime/CUDA/AllocatorCUF.cpp (+1-1)
  • (modified) flang/unittests/Runtime/CUDA/Memory.cpp (+1-1)
  • (modified) flang/unittests/Runtime/TemporaryStack.cpp (+1-1)
diff --git a/flang/include/flang/ISO_Fortran_binding_wrapper.h b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
similarity index 70%
rename from flang/include/flang/ISO_Fortran_binding_wrapper.h
rename to flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
index 37289bdbabd03c..7a8a8a9787bd03 100644
--- a/flang/include/flang/ISO_Fortran_binding_wrapper.h
+++ b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
@@ -1,14 +1,13 @@
-/*===-- include/flang/ISO_Fortran_binding_wrapper.h ---------------*- C++ -*-===
+/*===-- include/flang/Common/ISO_Fortran_binding_wrapper.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
  *
- * ===-----------------------------------------------------------------------===
- */
+ *===----------------------------------------------------------------------===*/
 
-#ifndef FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
-#define FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
+#ifndef FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
+#define FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
 
 /* A thin wrapper around flang/include/ISO_Fortran_binding.h
  * This header file must be included when ISO_Fortran_binding.h
@@ -23,17 +22,17 @@
 
 /* clang-format off */
 #include <stddef.h>
-#include "Common/api-attrs.h"
+#include "flang/Common/api-attrs.h"
 #ifdef __cplusplus
 namespace Fortran {
 namespace ISO {
 #define FORTRAN_ISO_NAMESPACE_ ::Fortran::ISO
 #endif /* __cplusplus */
-#include "ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding.h"
 #ifdef __cplusplus
 } // namespace ISO
 } // namespace Fortran
 #endif /* __cplusplus */
 /* clang-format on */
 
-#endif /* FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_ */
+#endif /* FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_ */
diff --git a/flang/include/flang/Common/fast-int-set.h b/flang/include/flang/Common/fast-int-set.h
index d1c9c756a44a65..1214bac75a4bf1 100644
--- a/flang/include/flang/Common/fast-int-set.h
+++ b/flang/include/flang/Common/fast-int-set.h
@@ -24,7 +24,7 @@
 #ifndef FORTRAN_COMMON_FAST_INT_SET_H_
 #define FORTRAN_COMMON_FAST_INT_SET_H_
 
-#include <optional>
+#include "optional.h"
 
 namespace Fortran::common {
 
@@ -83,9 +83,9 @@ template <int N> class FastIntSet {
     }
   }
 
-  std::optional<int> PopValue() {
+  optional<int> PopValue() {
     if (IsEmpty()) {
-      return std::nullopt;
+      return nullopt;
     } else {
       return value_[--size_];
     }
diff --git a/flang/include/flang/Evaluate/call.h b/flang/include/flang/Evaluate/call.h
index 63277438128ebb..4d8ca28cf329a1 100644
--- a/flang/include/flang/Evaluate/call.h
+++ b/flang/include/flang/Evaluate/call.h
@@ -13,11 +13,11 @@
 #include "constant.h"
 #include "formatting.h"
 #include "type.h"
-#include "flang/Common/Fortran.h"
-#include "flang/Common/indirection.h"
-#include "flang/Common/reference.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/attr.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
+#include "flang/Support/reference.h"
 #include <optional>
 #include <vector>
 
diff --git a/flang/include/flang/Evaluate/characteristics.h b/flang/include/flang/Evaluate/characteristics.h
index 357fc3e5952436..ccd584b5ee6aa4 100644
--- a/flang/include/flang/Evaluate/characteristics.h
+++ b/flang/include/flang/Evaluate/characteristics.h
@@ -18,13 +18,13 @@
 #include "shape.h"
 #include "tools.h"
 #include "type.h"
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
 #include <optional>
 #include <string>
 #include <variant>
diff --git a/flang/include/flang/Evaluate/common.h b/flang/include/flang/Evaluate/common.h
index 915e95169c7f81..91d38748f5a575 100644
--- a/flang/include/flang/Evaluate/common.h
+++ b/flang/include/flang/Evaluate/common.h
@@ -9,16 +9,16 @@
 #ifndef FORTRAN_EVALUATE_COMMON_H_
 #define FORTRAN_EVALUATE_COMMON_H_
 
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Common/restorer.h"
 #include "flang/Common/target-rounding.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Parser/message.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/default-kinds.h"
+#include "flang/Support/indirection.h"
 #include <cinttypes>
 #include <map>
 #include <set>
diff --git a/flang/include/flang/Evaluate/constant.h b/flang/include/flang/Evaluate/constant.h
index 61a814446bbfd3..63e8ed4119cdf5 100644
--- a/flang/include/flang/Evaluate/constant.h
+++ b/flang/include/flang/Evaluate/constant.h
@@ -11,8 +11,8 @@
 
 #include "formatting.h"
 #include "type.h"
-#include "flang/Common/default-kinds.h"
-#include "flang/Common/reference.h"
+#include "flang/Support/default-kinds.h"
+#include "flang/Support/reference.h"
 #include <map>
 #include <vector>
 
diff --git a/flang/include/flang/Evaluate/expression.h b/flang/include/flang/Evaluate/expression.h
index 04f4406fc8a2c0..ec71550d2a50c9 100644
--- a/flang/include/flang/Evaluate/expression.h
+++ b/flang/include/flang/Evaluate/expression.h
@@ -21,11 +21,11 @@
 #include "formatting.h"
 #include "type.h"
 #include "variable.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
-#include "flang/Common/template.h"
 #include "flang/Parser/char-block.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
+#include "flang/Support/template.h"
 #include <algorithm>
 #include <list>
 #include <tuple>
diff --git a/flang/include/flang/Evaluate/formatting.h b/flang/include/flang/Evaluate/formatting.h
index aa82f56107fdd3..ae9351139b1933 100644
--- a/flang/include/flang/Evaluate/formatting.h
+++ b/flang/include/flang/Evaluate/formatting.h
@@ -19,7 +19,7 @@
 // This header is meant to be included by the headers that define the several
 // representational class templates that need it, not by external clients.
 
-#include "flang/Common/indirection.h"
+#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <optional>
 #include <type_traits>
diff --git a/flang/include/flang/Evaluate/intrinsics.h b/flang/include/flang/Evaluate/intrinsics.h
index 15afb772ae767b..dbe1ba7fe7ec1b 100644
--- a/flang/include/flang/Evaluate/intrinsics.h
+++ b/flang/include/flang/Evaluate/intrinsics.h
@@ -12,9 +12,9 @@
 #include "call.h"
 #include "characteristics.h"
 #include "type.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Parser/message.h"
+#include "flang/Support/default-kinds.h"
 #include <memory>
 #include <optional>
 #include <string>
diff --git a/flang/include/flang/Evaluate/shape.h b/flang/include/flang/Evaluate/shape.h
index 3e42ec691158bc..18dca71379e0da 100644
--- a/flang/include/flang/Evaluate/shape.h
+++ b/flang/include/flang/Evaluate/shape.h
@@ -15,8 +15,8 @@
 #include "expression.h"
 #include "traverse.h"
 #include "variable.h"
-#include "flang/Common/indirection.h"
 #include "flang/Evaluate/type.h"
+#include "flang/Support/indirection.h"
 #include <optional>
 #include <variant>
 
diff --git a/flang/include/flang/Evaluate/target.h b/flang/include/flang/Evaluate/target.h
index e07f916b875e06..f4595dfe4e4333 100644
--- a/flang/include/flang/Evaluate/target.h
+++ b/flang/include/flang/Evaluate/target.h
@@ -12,11 +12,11 @@
 #ifndef FORTRAN_EVALUATE_TARGET_H_
 #define FORTRAN_EVALUATE_TARGET_H_
 
-#include "flang/Common/Fortran.h"
 #include "flang/Common/enum-class.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/target-rounding.h"
 #include "flang/Evaluate/common.h"
+#include "flang/Support/Fortran.h"
 #include <cstdint>
 
 namespace Fortran::evaluate {
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index 669efb41b03442..fbe905168d2538 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -11,8 +11,6 @@
 
 #include "traverse.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/template.h"
-#include "flang/Common/unwrap.h"
 #include "flang/Evaluate/constant.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Evaluate/shape.h"
@@ -21,6 +19,8 @@
 #include "flang/Semantics/attr.h"
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/template.h"
+#include "flang/Support/unwrap.h"
 #include <array>
 #include <optional>
 #include <set>
diff --git a/flang/include/flang/Evaluate/traverse.h b/flang/include/flang/Evaluate/traverse.h
index dd38d64bff63f7..58f188a4092493 100644
--- a/flang/include/flang/Evaluate/traverse.h
+++ b/flang/include/flang/Evaluate/traverse.h
@@ -38,9 +38,9 @@
 // expression of an ASSOCIATE (or related) construct entity.
 
 #include "expression.h"
-#include "flang/Common/indirection.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/type.h"
+#include "flang/Support/indirection.h"
 #include <set>
 #include <type_traits>
 
diff --git a/flang/include/flang/Evaluate/type.h b/flang/include/flang/Evaluate/type.h
index 1f9296ac4fea75..ab7e4723152d7e 100644
--- a/flang/include/flang/Evaluate/type.h
+++ b/flang/include/flang/Evaluate/type.h
@@ -22,11 +22,11 @@
 #include "integer.h"
 #include "logical.h"
 #include "real.h"
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
 #include "flang/Common/real.h"
-#include "flang/Common/template.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/template.h"
 #include <cinttypes>
 #include <optional>
 #include <string>
diff --git a/flang/include/flang/Evaluate/variable.h b/flang/include/flang/Evaluate/variable.h
index 9b597d29813da1..bb4150613c81dd 100644
--- a/flang/include/flang/Evaluate/variable.h
+++ b/flang/include/flang/Evaluate/variable.h
@@ -21,9 +21,9 @@
 #include "static-data.h"
 #include "type.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/reference.h"
-#include "flang/Common/template.h"
 #include "flang/Parser/char-block.h"
+#include "flang/Support/reference.h"
+#include "flang/Support/template.h"
 #include <optional>
 #include <variant>
 #include <vector>
diff --git a/flang/include/flang/Frontend/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h
index 7d3f0bdf2e510e..b3b7297f6f7f1f 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -13,7 +13,6 @@
 #ifndef FORTRAN_FRONTEND_COMPILERINVOCATION_H
 #define FORTRAN_FRONTEND_COMPILERINVOCATION_H
 
-#include "flang/Common/LangOptions.h"
 #include "flang/Frontend/CodeGenOptions.h"
 #include "flang/Frontend/FrontendOptions.h"
 #include "flang/Frontend/PreprocessorOptions.h"
@@ -22,6 +21,7 @@
 #include "flang/Parser/parsing.h"
 #include "flang/Semantics/semantics.h"
 #include "mlir/Support/Timing.h"
+#include "flang/Support/LangOptions.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "llvm/Option/ArgList.h"
diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index a4cb021e309d4a..0bd2e621813ca5 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -13,10 +13,10 @@
 #ifndef FORTRAN_FRONTEND_FRONTENDOPTIONS_H
 #define FORTRAN_FRONTEND_FRONTENDOPTIONS_H
 
-#include "flang/Common/Fortran-features.h"
 #include "flang/Lower/EnvironmentDefault.h"
 #include "flang/Parser/characters.h"
 #include "flang/Parser/unparse.h"
+#include "flang/Support/Fortran-features.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include <cstdint>
diff --git a/flang/include/flang/ISO_Fortran_binding.h b/flang/include/flang/ISO_Fortran_binding.h
index 945f8fef89f0b4..f5b8d0d2ea610a 100644
--- a/flang/include/flang/ISO_Fortran_binding.h
+++ b/flang/include/flang/ISO_Fortran_binding.h
@@ -14,7 +14,7 @@
  * it does so by means of a wrapper header that establishes namespaces and
  * a macro for extra function attributes (RT_API_ATTRS).
  */
-#ifndef FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
+#ifndef FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
 #include <stddef.h>
 #define FORTRAN_ISO_NAMESPACE_
 #endif
diff --git a/flang/include/flang/Lower/AbstractConverter.h b/flang/include/flang/Lower/AbstractConverter.h
index c24f43737df50a..3d2b805da6f477 100644
--- a/flang/include/flang/Lower/AbstractConverter.h
+++ b/flang/include/flang/Lower/AbstractConverter.h
@@ -13,12 +13,12 @@
 #ifndef FORTRAN_LOWER_ABSTRACTCONVERTER_H
 #define FORTRAN_LOWER_ABSTRACTCONVERTER_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Lower/LoweringOptions.h"
 #include "flang/Lower/PFTDefs.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Dialect/FIRAttr.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/Operation.h"
diff --git a/flang/include/flang/Lower/Bridge.h b/flang/include/flang/Lower/Bridge.h
index 6404a16f7785ae..a8c2bcfda31c1f 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -13,7 +13,6 @@
 #ifndef FORTRAN_LOWER_BRIDGE_H
 #define FORTRAN_LOWER_BRIDGE_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Frontend/CodeGenOptions.h"
 #include "flang/Frontend/TargetOptions.h"
 #include "flang/Lower/AbstractConverter.h"
@@ -22,6 +21,7 @@
 #include "flang/Lower/StatementContext.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/OwningOpRef.h"
 #include <set>
diff --git a/flang/include/flang/Lower/CallInterface.h b/flang/include/flang/Lower/CallInterface.h
index 72bc9dd890a94b..c15edf62df388e 100644
--- a/flang/include/flang/Lower/CallInterface.h
+++ b/flang/include/flang/Lower/CallInterface.h
@@ -27,8 +27,8 @@
 #ifndef FORTRAN_LOWER_CALLINTERFACE_H
 #define FORTRAN_LOWER_CALLINTERFACE_H
 
-#include "flang/Common/reference.h"
 #include "flang/Evaluate/characteristics.h"
+#include "flang/Support/reference.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/IR/BuiltinOps.h"
 #include <memory>
diff --git a/flang/include/flang/Lower/ConvertType.h b/flang/include/flang/Lower/ConvertType.h
index 7a3f92649a4e4a..179a6825840464 100644
--- a/flang/include/flang/Lower/ConvertType.h
+++ b/flang/include/flang/Lower/ConvertType.h
@@ -21,8 +21,8 @@
 #ifndef FORTRAN_LOWER_CONVERT_TYPE_H
 #define FORTRAN_LOWER_CONVERT_TYPE_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Evaluate/type.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinTypes.h"
 
 namespace mlir {
diff --git a/flang/include/flang/Lower/LoweringOptions.h b/flang/include/flang/Lower/LoweringOptions.h
index 8105ccd7ef6b15..171510393b8168 100644
--- a/flang/include/flang/Lower/LoweringOptions.h
+++ b/flang/include/flang/Lower/LoweringOptions.h
@@ -15,7 +15,7 @@
 #ifndef FLANG_LOWER_LOWERINGOPTIONS_H
 #define FLANG_LOWER_LOWERINGOPTIONS_H
 
-#include "flang/Common/MathOptionsBase.h"
+#include "flang/Support/MathOptionsBase.h"
 
 namespace Fortran::lower {
 
diff --git a/flang/include/flang/Lower/PFTBuilder.h b/flang/include/flang/Lower/PFTBuilder.h
index 42d6546b77553b..05da17faf2dd7d 100644
--- a/flang/include/flang/Lower/PFTBuilder.h
+++ b/flang/include/flang/Lower/PFTBuilder.h
@@ -17,8 +17,6 @@
 #ifndef FORTRAN_LOWER_PFTBUILDER_H
 #define FORTRAN_LOWER_PFTBUILDER_H
 
-#include "flang/Common/reference.h"
-#include "flang/Common/template.h"
 #include "flang/Lower/HostAssociations.h"
 #include "flang/Lower/PFTDefs.h"
 #include "flang/Parser/parse-tree.h"
@@ -26,6 +24,8 @@
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/reference.h"
+#include "flang/Support/template.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
diff --git a/flang/include/flang/Lower/Support/Utils.h b/flang/include/flang/Lower/Support/Utils.h
index 1cc74521e22d88..08a872b228691d 100644
--- a/flang/include/flang/Lower/Support/Utils.h
+++ b/flang/include/flang/Lower/Support/Utils.h
@@ -13,9 +13,9 @@
 #ifndef FORTRAN_LOWER_SUPPORT_UTILS_H
 #define FORTRAN_LOWER_SUPPORT_UTILS_H
 
-#include "flang/Common/indirection.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/indirection.h"
 #include "mlir/Dialect/Arith/IR/Arith.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/IR/BuiltinAttributes.h"
diff --git a/flang/include/flang/Lower/SymbolMap.h b/flang/include/flang/Lower/SymbolMap.h
index c03f9afd40801c..fb64db407708ad 100644
--- a/flang/include/flang/Lower/SymbolMap.h
+++ b/flang/include/flang/Lower/SymbolMap.h
@@ -13,12 +13,12 @@
 #ifndef FORTRAN_LOWER_SYMBOLMAP_H
 #define FORTRAN_LOWER_SYMBOLMAP_H
 
-#include "flang/Common/reference.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Dialect/FortranVariableInterface.h"
 #include "flang/Optimizer/Support/Matcher.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/reference.h"
 #include "mlir/IR/Value.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index ea658fb16a36c3..805667bfe502b1 100644
--- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
@@ -16,12 +16,12 @@
 #ifndef FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
 #define FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
 
-#include "flang/Common/MathOptionsBase.h"
 #include "flang/Optimizer/Dialect/FIROps.h"
 #include "flang/Optimizer/Dialect/FIROpsSupport.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Dialect/Support/FIRContext.h"
 #include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Support/MathOptionsBase.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "llvm/ADT/DenseMap.h"
diff --git a/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
index 5ae32f70a11a7f..8374b18b8a17d8 100644
--- a/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
@@ -9,8 +9,8 @@
 #ifndef FORTRAN_LOWER_PPCINTRINSICCALL_H
 #define FORTRAN_LOWER_PPCINTRINSICCALL_H
 
-#include "flang/Common/static-multimap-view.h"
 #include "flang/Optimizer/Builder/IntrinsicCall.h"
+#include "flang/Support/static-multimap-view.h"
 #include "mlir/Dialect/Math/IR/Math.h"
 
 namespace fir {
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index eaa1de76154d93..be07e8d2a9390a 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -17,12 +17,12 @@
 #ifndef FORTRAN_OPTIMIZER_BUILDER_RUNTIME_RTBUILDER_H
 #define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_RTBUILDER_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Common/uint128.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Dialect/FIRDialect.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Runtime/reduce.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinTypes.h"
 #include "mlir/IR/MLIRContext.h"
 #include "llvm/ADT/SmallVector.h"
diff --git a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
index 9cccf8db87270e..b9a8a670d07938 100644
--- a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
+++ b/flang/include/flang/Optimizer/...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Jan 27, 2025

@llvm/pr-subscribers-flang-fir-hlfir

Author: Michael Kruse (Meinersbur)

Changes

Split off FortranSupport (analogous to LLVMSupport) from FortranCommon such that

  • declarations and definitions that are only used by the Flang compiler, but not by the runtime, are moved to FortranSupport

  • declarations and definitions that are used by both ("common"), the compiler and the runtime, remain in FortranCommon

This allows a for cleaner separation between compiler and runtime components, which are compiled differently. For instance, runtime sources must not use STL's &lt;optional&gt; which causes problems with CUDA support. Instead, the surrogate header flang/Common/optional.h must be used. This PR fixes this for fast-int-sel.h.

Declarations in include/Runtime are also used by both, but are header-only. ISO_Fortran_binding_wrapper.h, a header used by compiler and runtime, is also moved into FortranCommon.

The PR is split off from #110298 and #110217.


Patch is 117.01 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/124416.diff

160 Files Affected:

  • (renamed) flang/include/flang/Common/ISO_Fortran_binding_wrapper.h (+7-8)
  • (modified) flang/include/flang/Common/fast-int-set.h (+3-3)
  • (modified) flang/include/flang/Evaluate/call.h (+3-3)
  • (modified) flang/include/flang/Evaluate/characteristics.h (+3-3)
  • (modified) flang/include/flang/Evaluate/common.h (+4-4)
  • (modified) flang/include/flang/Evaluate/constant.h (+2-2)
  • (modified) flang/include/flang/Evaluate/expression.h (+3-3)
  • (modified) flang/include/flang/Evaluate/formatting.h (+1-1)
  • (modified) flang/include/flang/Evaluate/intrinsics.h (+1-1)
  • (modified) flang/include/flang/Evaluate/shape.h (+1-1)
  • (modified) flang/include/flang/Evaluate/target.h (+1-1)
  • (modified) flang/include/flang/Evaluate/tools.h (+2-2)
  • (modified) flang/include/flang/Evaluate/traverse.h (+1-1)
  • (modified) flang/include/flang/Evaluate/type.h (+3-3)
  • (modified) flang/include/flang/Evaluate/variable.h (+2-2)
  • (modified) flang/include/flang/Frontend/CompilerInvocation.h (+1-1)
  • (modified) flang/include/flang/Frontend/FrontendOptions.h (+1-1)
  • (modified) flang/include/flang/ISO_Fortran_binding.h (+1-1)
  • (modified) flang/include/flang/Lower/AbstractConverter.h (+1-1)
  • (modified) flang/include/flang/Lower/Bridge.h (+1-1)
  • (modified) flang/include/flang/Lower/CallInterface.h (+1-1)
  • (modified) flang/include/flang/Lower/ConvertType.h (+1-1)
  • (modified) flang/include/flang/Lower/LoweringOptions.h (+1-1)
  • (modified) flang/include/flang/Lower/PFTBuilder.h (+2-2)
  • (modified) flang/include/flang/Lower/Support/Utils.h (+1-1)
  • (modified) flang/include/flang/Lower/SymbolMap.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Builder/FIRBuilder.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h (+1-1)
  • (modified) flang/include/flang/Optimizer/CodeGen/DescriptorModel.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Support/TypeCode.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Support/Utils.h (+1-1)
  • (modified) flang/include/flang/Parser/char-block.h (+1-1)
  • (modified) flang/include/flang/Parser/dump-parse-tree.h (+2-2)
  • (modified) flang/include/flang/Parser/message.h (+2-2)
  • (modified) flang/include/flang/Parser/parse-state.h (+1-1)
  • (modified) flang/include/flang/Parser/parse-tree.h (+2-2)
  • (modified) flang/include/flang/Parser/parsing.h (+1-1)
  • (modified) flang/include/flang/Parser/provenance.h (+1-1)
  • (modified) flang/include/flang/Parser/source.h (+1-1)
  • (modified) flang/include/flang/Parser/user-state.h (+1-1)
  • (modified) flang/include/flang/Runtime/descriptor-consts.h (+1-1)
  • (modified) flang/include/flang/Runtime/descriptor.h (+1-1)
  • (modified) flang/include/flang/Runtime/random.h (+5)
  • (modified) flang/include/flang/Runtime/support.h (+1-1)
  • (modified) flang/include/flang/Runtime/type-code.h (+1-1)
  • (modified) flang/include/flang/Semantics/expression.h (+2-2)
  • (modified) flang/include/flang/Semantics/runtime-type-info.h (+1-1)
  • (modified) flang/include/flang/Semantics/scope.h (+2-2)
  • (modified) flang/include/flang/Semantics/semantics.h (+2-2)
  • (modified) flang/include/flang/Semantics/symbol.h (+2-2)
  • (modified) flang/include/flang/Semantics/tools.h (+1-1)
  • (modified) flang/include/flang/Semantics/type.h (+1-1)
  • (renamed) flang/include/flang/Support/Fortran-features.h (+5-5)
  • (renamed) flang/include/flang/Support/Fortran.h (+6-6)
  • (renamed) flang/include/flang/Support/LangOptions.def ()
  • (renamed) flang/include/flang/Support/LangOptions.h (+7-7)
  • (renamed) flang/include/flang/Support/MathOptionsBase.def ()
  • (renamed) flang/include/flang/Support/MathOptionsBase.h (+7-7)
  • (renamed) flang/include/flang/Support/OpenMP-features.h (+4-4)
  • (modified) flang/include/flang/Support/Timing.h (+4-4)
  • (renamed) flang/include/flang/Support/Version.h (+4-4)
  • (renamed) flang/include/flang/Support/default-kinds.h (+5-5)
  • (renamed) flang/include/flang/Support/indirection.h (+5-5)
  • (renamed) flang/include/flang/Support/interval.h (+5-5)
  • (renamed) flang/include/flang/Support/reference-counted.h (+4-4)
  • (renamed) flang/include/flang/Support/reference.h (+4-4)
  • (renamed) flang/include/flang/Support/static-multimap-view.h (+4-4)
  • (renamed) flang/include/flang/Support/template.h (+5-5)
  • (renamed) flang/include/flang/Support/unwrap.h (+6-6)
  • (modified) flang/include/flang/Tools/CrossToolHelpers.h (+2-2)
  • (modified) flang/lib/CMakeLists.txt (-1)
  • (removed) flang/lib/Common/CMakeLists.txt (-52)
  • (modified) flang/lib/Evaluate/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Evaluate/call.cpp (+1-1)
  • (modified) flang/lib/Evaluate/characteristics.cpp (+1-1)
  • (modified) flang/lib/Evaluate/fold-implementation.h (+3-3)
  • (modified) flang/lib/Evaluate/formatting.cpp (+1-1)
  • (modified) flang/lib/Evaluate/intrinsics-library.cpp (+1-1)
  • (modified) flang/lib/Evaluate/intrinsics.cpp (+1-1)
  • (modified) flang/lib/Evaluate/shape.cpp (+1-1)
  • (modified) flang/lib/Evaluate/target.cpp (+1-1)
  • (modified) flang/lib/Frontend/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Frontend/CompilerInstance.cpp (+1-1)
  • (modified) flang/lib/Frontend/CompilerInvocation.cpp (+3-3)
  • (modified) flang/lib/Frontend/FrontendActions.cpp (+1-1)
  • (modified) flang/lib/Lower/Bridge.cpp (+1-1)
  • (modified) flang/lib/Lower/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Lower/CallInterface.cpp (+1-1)
  • (modified) flang/lib/Lower/ConvertExpr.cpp (+2-2)
  • (modified) flang/lib/Lower/Mangler.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Builder/IntrinsicCall.cpp (+1-1)
  • (modified) flang/lib/Optimizer/CodeGen/TypeConverter.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Dialect/FIRType.cpp (+1-1)
  • (modified) flang/lib/Optimizer/OpenMP/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Optimizer/Passes/CMakeLists.txt (+1-4)
  • (modified) flang/lib/Optimizer/Transforms/AddDebugInfo.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CUFDeviceGlobal.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CUFOpConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/LoopVersioning.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/StackReclaim.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/VScaleAttr.cpp (+1-1)
  • (modified) flang/lib/Parser/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Parser/basic-parsers.h (+2-2)
  • (modified) flang/lib/Parser/parse-tree.cpp (+1-1)
  • (modified) flang/lib/Parser/prescan.h (+1-1)
  • (modified) flang/lib/Parser/unparse.cpp (+2-2)
  • (modified) flang/lib/Semantics/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Semantics/assignment.h (+1-1)
  • (modified) flang/lib/Semantics/check-case.cpp (+2-2)
  • (modified) flang/lib/Semantics/check-coarray.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-cuda.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-data.h (+1-1)
  • (modified) flang/lib/Semantics/check-do-forall.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-return.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-select-rank.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-select-type.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-stop.cpp (+1-1)
  • (modified) flang/lib/Semantics/data-to-inits.h (+2-2)
  • (modified) flang/lib/Semantics/expression.cpp (+1-1)
  • (modified) flang/lib/Semantics/pointer-assignment.cpp (+1-1)
  • (modified) flang/lib/Semantics/resolve-labels.cpp (+1-1)
  • (modified) flang/lib/Semantics/resolve-names-utils.cpp (+3-3)
  • (modified) flang/lib/Semantics/resolve-names.cpp (+3-3)
  • (modified) flang/lib/Semantics/rewrite-parse-tree.cpp (+1-1)
  • (modified) flang/lib/Semantics/semantics.cpp (+1-1)
  • (modified) flang/lib/Semantics/tools.cpp (+2-2)
  • (modified) flang/lib/Support/CMakeLists.txt (+53)
  • (renamed) flang/lib/Support/Fortran-features.cpp (+3-3)
  • (renamed) flang/lib/Support/Fortran.cpp (+3-3)
  • (renamed) flang/lib/Support/LangOptions.cpp (+3-3)
  • (renamed) flang/lib/Support/OpenMP-utils.cpp (+1-1)
  • (modified) flang/lib/Support/Timing.cpp (+1-1)
  • (renamed) flang/lib/Support/Version.cpp (+2-2)
  • (renamed) flang/lib/Support/default-kinds.cpp (+2-2)
  • (renamed) flang/lib/Support/idioms.cpp (+1-1)
  • (modified) flang/runtime/CUDA/allocator.cpp (+2-2)
  • (modified) flang/runtime/ISO_Fortran_binding.cpp (+1-1)
  • (modified) flang/runtime/ISO_Fortran_util.h (+1-1)
  • (modified) flang/runtime/allocatable.cpp (+1-1)
  • (modified) flang/runtime/stat.h (+1-1)
  • (modified) flang/runtime/temporary-stack.cpp (+1-1)
  • (modified) flang/tools/bbc/CMakeLists.txt (+1-1)
  • (modified) flang/tools/bbc/bbc.cpp (+5-5)
  • (modified) flang/tools/f18-parse-demo/CMakeLists.txt (+1-1)
  • (modified) flang/tools/f18-parse-demo/f18-parse-demo.cpp (+2-2)
  • (modified) flang/tools/tco/CMakeLists.txt (+1-1)
  • (modified) flang/unittests/Evaluate/CMakeLists.txt (+3-3)
  • (modified) flang/unittests/Evaluate/ISO-Fortran-binding.cpp (+1-1)
  • (modified) flang/unittests/Frontend/CMakeLists.txt (+1-1)
  • (modified) flang/unittests/Runtime/CUDA/Allocatable.cpp (+1-1)
  • (modified) flang/unittests/Runtime/CUDA/AllocatorCUF.cpp (+1-1)
  • (modified) flang/unittests/Runtime/CUDA/Memory.cpp (+1-1)
  • (modified) flang/unittests/Runtime/TemporaryStack.cpp (+1-1)
diff --git a/flang/include/flang/ISO_Fortran_binding_wrapper.h b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
similarity index 70%
rename from flang/include/flang/ISO_Fortran_binding_wrapper.h
rename to flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
index 37289bdbabd03c..7a8a8a9787bd03 100644
--- a/flang/include/flang/ISO_Fortran_binding_wrapper.h
+++ b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
@@ -1,14 +1,13 @@
-/*===-- include/flang/ISO_Fortran_binding_wrapper.h ---------------*- C++ -*-===
+/*===-- include/flang/Common/ISO_Fortran_binding_wrapper.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
  *
- * ===-----------------------------------------------------------------------===
- */
+ *===----------------------------------------------------------------------===*/
 
-#ifndef FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
-#define FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
+#ifndef FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
+#define FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
 
 /* A thin wrapper around flang/include/ISO_Fortran_binding.h
  * This header file must be included when ISO_Fortran_binding.h
@@ -23,17 +22,17 @@
 
 /* clang-format off */
 #include <stddef.h>
-#include "Common/api-attrs.h"
+#include "flang/Common/api-attrs.h"
 #ifdef __cplusplus
 namespace Fortran {
 namespace ISO {
 #define FORTRAN_ISO_NAMESPACE_ ::Fortran::ISO
 #endif /* __cplusplus */
-#include "ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding.h"
 #ifdef __cplusplus
 } // namespace ISO
 } // namespace Fortran
 #endif /* __cplusplus */
 /* clang-format on */
 
-#endif /* FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_ */
+#endif /* FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_ */
diff --git a/flang/include/flang/Common/fast-int-set.h b/flang/include/flang/Common/fast-int-set.h
index d1c9c756a44a65..1214bac75a4bf1 100644
--- a/flang/include/flang/Common/fast-int-set.h
+++ b/flang/include/flang/Common/fast-int-set.h
@@ -24,7 +24,7 @@
 #ifndef FORTRAN_COMMON_FAST_INT_SET_H_
 #define FORTRAN_COMMON_FAST_INT_SET_H_
 
-#include <optional>
+#include "optional.h"
 
 namespace Fortran::common {
 
@@ -83,9 +83,9 @@ template <int N> class FastIntSet {
     }
   }
 
-  std::optional<int> PopValue() {
+  optional<int> PopValue() {
     if (IsEmpty()) {
-      return std::nullopt;
+      return nullopt;
     } else {
       return value_[--size_];
     }
diff --git a/flang/include/flang/Evaluate/call.h b/flang/include/flang/Evaluate/call.h
index 63277438128ebb..4d8ca28cf329a1 100644
--- a/flang/include/flang/Evaluate/call.h
+++ b/flang/include/flang/Evaluate/call.h
@@ -13,11 +13,11 @@
 #include "constant.h"
 #include "formatting.h"
 #include "type.h"
-#include "flang/Common/Fortran.h"
-#include "flang/Common/indirection.h"
-#include "flang/Common/reference.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/attr.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
+#include "flang/Support/reference.h"
 #include <optional>
 #include <vector>
 
diff --git a/flang/include/flang/Evaluate/characteristics.h b/flang/include/flang/Evaluate/characteristics.h
index 357fc3e5952436..ccd584b5ee6aa4 100644
--- a/flang/include/flang/Evaluate/characteristics.h
+++ b/flang/include/flang/Evaluate/characteristics.h
@@ -18,13 +18,13 @@
 #include "shape.h"
 #include "tools.h"
 #include "type.h"
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
 #include <optional>
 #include <string>
 #include <variant>
diff --git a/flang/include/flang/Evaluate/common.h b/flang/include/flang/Evaluate/common.h
index 915e95169c7f81..91d38748f5a575 100644
--- a/flang/include/flang/Evaluate/common.h
+++ b/flang/include/flang/Evaluate/common.h
@@ -9,16 +9,16 @@
 #ifndef FORTRAN_EVALUATE_COMMON_H_
 #define FORTRAN_EVALUATE_COMMON_H_
 
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Common/restorer.h"
 #include "flang/Common/target-rounding.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Parser/message.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/default-kinds.h"
+#include "flang/Support/indirection.h"
 #include <cinttypes>
 #include <map>
 #include <set>
diff --git a/flang/include/flang/Evaluate/constant.h b/flang/include/flang/Evaluate/constant.h
index 61a814446bbfd3..63e8ed4119cdf5 100644
--- a/flang/include/flang/Evaluate/constant.h
+++ b/flang/include/flang/Evaluate/constant.h
@@ -11,8 +11,8 @@
 
 #include "formatting.h"
 #include "type.h"
-#include "flang/Common/default-kinds.h"
-#include "flang/Common/reference.h"
+#include "flang/Support/default-kinds.h"
+#include "flang/Support/reference.h"
 #include <map>
 #include <vector>
 
diff --git a/flang/include/flang/Evaluate/expression.h b/flang/include/flang/Evaluate/expression.h
index 04f4406fc8a2c0..ec71550d2a50c9 100644
--- a/flang/include/flang/Evaluate/expression.h
+++ b/flang/include/flang/Evaluate/expression.h
@@ -21,11 +21,11 @@
 #include "formatting.h"
 #include "type.h"
 #include "variable.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
-#include "flang/Common/template.h"
 #include "flang/Parser/char-block.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
+#include "flang/Support/template.h"
 #include <algorithm>
 #include <list>
 #include <tuple>
diff --git a/flang/include/flang/Evaluate/formatting.h b/flang/include/flang/Evaluate/formatting.h
index aa82f56107fdd3..ae9351139b1933 100644
--- a/flang/include/flang/Evaluate/formatting.h
+++ b/flang/include/flang/Evaluate/formatting.h
@@ -19,7 +19,7 @@
 // This header is meant to be included by the headers that define the several
 // representational class templates that need it, not by external clients.
 
-#include "flang/Common/indirection.h"
+#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <optional>
 #include <type_traits>
diff --git a/flang/include/flang/Evaluate/intrinsics.h b/flang/include/flang/Evaluate/intrinsics.h
index 15afb772ae767b..dbe1ba7fe7ec1b 100644
--- a/flang/include/flang/Evaluate/intrinsics.h
+++ b/flang/include/flang/Evaluate/intrinsics.h
@@ -12,9 +12,9 @@
 #include "call.h"
 #include "characteristics.h"
 #include "type.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Parser/message.h"
+#include "flang/Support/default-kinds.h"
 #include <memory>
 #include <optional>
 #include <string>
diff --git a/flang/include/flang/Evaluate/shape.h b/flang/include/flang/Evaluate/shape.h
index 3e42ec691158bc..18dca71379e0da 100644
--- a/flang/include/flang/Evaluate/shape.h
+++ b/flang/include/flang/Evaluate/shape.h
@@ -15,8 +15,8 @@
 #include "expression.h"
 #include "traverse.h"
 #include "variable.h"
-#include "flang/Common/indirection.h"
 #include "flang/Evaluate/type.h"
+#include "flang/Support/indirection.h"
 #include <optional>
 #include <variant>
 
diff --git a/flang/include/flang/Evaluate/target.h b/flang/include/flang/Evaluate/target.h
index e07f916b875e06..f4595dfe4e4333 100644
--- a/flang/include/flang/Evaluate/target.h
+++ b/flang/include/flang/Evaluate/target.h
@@ -12,11 +12,11 @@
 #ifndef FORTRAN_EVALUATE_TARGET_H_
 #define FORTRAN_EVALUATE_TARGET_H_
 
-#include "flang/Common/Fortran.h"
 #include "flang/Common/enum-class.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/target-rounding.h"
 #include "flang/Evaluate/common.h"
+#include "flang/Support/Fortran.h"
 #include <cstdint>
 
 namespace Fortran::evaluate {
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index 669efb41b03442..fbe905168d2538 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -11,8 +11,6 @@
 
 #include "traverse.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/template.h"
-#include "flang/Common/unwrap.h"
 #include "flang/Evaluate/constant.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Evaluate/shape.h"
@@ -21,6 +19,8 @@
 #include "flang/Semantics/attr.h"
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/template.h"
+#include "flang/Support/unwrap.h"
 #include <array>
 #include <optional>
 #include <set>
diff --git a/flang/include/flang/Evaluate/traverse.h b/flang/include/flang/Evaluate/traverse.h
index dd38d64bff63f7..58f188a4092493 100644
--- a/flang/include/flang/Evaluate/traverse.h
+++ b/flang/include/flang/Evaluate/traverse.h
@@ -38,9 +38,9 @@
 // expression of an ASSOCIATE (or related) construct entity.
 
 #include "expression.h"
-#include "flang/Common/indirection.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/type.h"
+#include "flang/Support/indirection.h"
 #include <set>
 #include <type_traits>
 
diff --git a/flang/include/flang/Evaluate/type.h b/flang/include/flang/Evaluate/type.h
index 1f9296ac4fea75..ab7e4723152d7e 100644
--- a/flang/include/flang/Evaluate/type.h
+++ b/flang/include/flang/Evaluate/type.h
@@ -22,11 +22,11 @@
 #include "integer.h"
 #include "logical.h"
 #include "real.h"
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
 #include "flang/Common/real.h"
-#include "flang/Common/template.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/template.h"
 #include <cinttypes>
 #include <optional>
 #include <string>
diff --git a/flang/include/flang/Evaluate/variable.h b/flang/include/flang/Evaluate/variable.h
index 9b597d29813da1..bb4150613c81dd 100644
--- a/flang/include/flang/Evaluate/variable.h
+++ b/flang/include/flang/Evaluate/variable.h
@@ -21,9 +21,9 @@
 #include "static-data.h"
 #include "type.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/reference.h"
-#include "flang/Common/template.h"
 #include "flang/Parser/char-block.h"
+#include "flang/Support/reference.h"
+#include "flang/Support/template.h"
 #include <optional>
 #include <variant>
 #include <vector>
diff --git a/flang/include/flang/Frontend/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h
index 7d3f0bdf2e510e..b3b7297f6f7f1f 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -13,7 +13,6 @@
 #ifndef FORTRAN_FRONTEND_COMPILERINVOCATION_H
 #define FORTRAN_FRONTEND_COMPILERINVOCATION_H
 
-#include "flang/Common/LangOptions.h"
 #include "flang/Frontend/CodeGenOptions.h"
 #include "flang/Frontend/FrontendOptions.h"
 #include "flang/Frontend/PreprocessorOptions.h"
@@ -22,6 +21,7 @@
 #include "flang/Parser/parsing.h"
 #include "flang/Semantics/semantics.h"
 #include "mlir/Support/Timing.h"
+#include "flang/Support/LangOptions.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "llvm/Option/ArgList.h"
diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index a4cb021e309d4a..0bd2e621813ca5 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -13,10 +13,10 @@
 #ifndef FORTRAN_FRONTEND_FRONTENDOPTIONS_H
 #define FORTRAN_FRONTEND_FRONTENDOPTIONS_H
 
-#include "flang/Common/Fortran-features.h"
 #include "flang/Lower/EnvironmentDefault.h"
 #include "flang/Parser/characters.h"
 #include "flang/Parser/unparse.h"
+#include "flang/Support/Fortran-features.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include <cstdint>
diff --git a/flang/include/flang/ISO_Fortran_binding.h b/flang/include/flang/ISO_Fortran_binding.h
index 945f8fef89f0b4..f5b8d0d2ea610a 100644
--- a/flang/include/flang/ISO_Fortran_binding.h
+++ b/flang/include/flang/ISO_Fortran_binding.h
@@ -14,7 +14,7 @@
  * it does so by means of a wrapper header that establishes namespaces and
  * a macro for extra function attributes (RT_API_ATTRS).
  */
-#ifndef FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
+#ifndef FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
 #include <stddef.h>
 #define FORTRAN_ISO_NAMESPACE_
 #endif
diff --git a/flang/include/flang/Lower/AbstractConverter.h b/flang/include/flang/Lower/AbstractConverter.h
index c24f43737df50a..3d2b805da6f477 100644
--- a/flang/include/flang/Lower/AbstractConverter.h
+++ b/flang/include/flang/Lower/AbstractConverter.h
@@ -13,12 +13,12 @@
 #ifndef FORTRAN_LOWER_ABSTRACTCONVERTER_H
 #define FORTRAN_LOWER_ABSTRACTCONVERTER_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Lower/LoweringOptions.h"
 #include "flang/Lower/PFTDefs.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Dialect/FIRAttr.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/Operation.h"
diff --git a/flang/include/flang/Lower/Bridge.h b/flang/include/flang/Lower/Bridge.h
index 6404a16f7785ae..a8c2bcfda31c1f 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -13,7 +13,6 @@
 #ifndef FORTRAN_LOWER_BRIDGE_H
 #define FORTRAN_LOWER_BRIDGE_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Frontend/CodeGenOptions.h"
 #include "flang/Frontend/TargetOptions.h"
 #include "flang/Lower/AbstractConverter.h"
@@ -22,6 +21,7 @@
 #include "flang/Lower/StatementContext.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/OwningOpRef.h"
 #include <set>
diff --git a/flang/include/flang/Lower/CallInterface.h b/flang/include/flang/Lower/CallInterface.h
index 72bc9dd890a94b..c15edf62df388e 100644
--- a/flang/include/flang/Lower/CallInterface.h
+++ b/flang/include/flang/Lower/CallInterface.h
@@ -27,8 +27,8 @@
 #ifndef FORTRAN_LOWER_CALLINTERFACE_H
 #define FORTRAN_LOWER_CALLINTERFACE_H
 
-#include "flang/Common/reference.h"
 #include "flang/Evaluate/characteristics.h"
+#include "flang/Support/reference.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/IR/BuiltinOps.h"
 #include <memory>
diff --git a/flang/include/flang/Lower/ConvertType.h b/flang/include/flang/Lower/ConvertType.h
index 7a3f92649a4e4a..179a6825840464 100644
--- a/flang/include/flang/Lower/ConvertType.h
+++ b/flang/include/flang/Lower/ConvertType.h
@@ -21,8 +21,8 @@
 #ifndef FORTRAN_LOWER_CONVERT_TYPE_H
 #define FORTRAN_LOWER_CONVERT_TYPE_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Evaluate/type.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinTypes.h"
 
 namespace mlir {
diff --git a/flang/include/flang/Lower/LoweringOptions.h b/flang/include/flang/Lower/LoweringOptions.h
index 8105ccd7ef6b15..171510393b8168 100644
--- a/flang/include/flang/Lower/LoweringOptions.h
+++ b/flang/include/flang/Lower/LoweringOptions.h
@@ -15,7 +15,7 @@
 #ifndef FLANG_LOWER_LOWERINGOPTIONS_H
 #define FLANG_LOWER_LOWERINGOPTIONS_H
 
-#include "flang/Common/MathOptionsBase.h"
+#include "flang/Support/MathOptionsBase.h"
 
 namespace Fortran::lower {
 
diff --git a/flang/include/flang/Lower/PFTBuilder.h b/flang/include/flang/Lower/PFTBuilder.h
index 42d6546b77553b..05da17faf2dd7d 100644
--- a/flang/include/flang/Lower/PFTBuilder.h
+++ b/flang/include/flang/Lower/PFTBuilder.h
@@ -17,8 +17,6 @@
 #ifndef FORTRAN_LOWER_PFTBUILDER_H
 #define FORTRAN_LOWER_PFTBUILDER_H
 
-#include "flang/Common/reference.h"
-#include "flang/Common/template.h"
 #include "flang/Lower/HostAssociations.h"
 #include "flang/Lower/PFTDefs.h"
 #include "flang/Parser/parse-tree.h"
@@ -26,6 +24,8 @@
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/reference.h"
+#include "flang/Support/template.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
diff --git a/flang/include/flang/Lower/Support/Utils.h b/flang/include/flang/Lower/Support/Utils.h
index 1cc74521e22d88..08a872b228691d 100644
--- a/flang/include/flang/Lower/Support/Utils.h
+++ b/flang/include/flang/Lower/Support/Utils.h
@@ -13,9 +13,9 @@
 #ifndef FORTRAN_LOWER_SUPPORT_UTILS_H
 #define FORTRAN_LOWER_SUPPORT_UTILS_H
 
-#include "flang/Common/indirection.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/indirection.h"
 #include "mlir/Dialect/Arith/IR/Arith.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/IR/BuiltinAttributes.h"
diff --git a/flang/include/flang/Lower/SymbolMap.h b/flang/include/flang/Lower/SymbolMap.h
index c03f9afd40801c..fb64db407708ad 100644
--- a/flang/include/flang/Lower/SymbolMap.h
+++ b/flang/include/flang/Lower/SymbolMap.h
@@ -13,12 +13,12 @@
 #ifndef FORTRAN_LOWER_SYMBOLMAP_H
 #define FORTRAN_LOWER_SYMBOLMAP_H
 
-#include "flang/Common/reference.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Dialect/FortranVariableInterface.h"
 #include "flang/Optimizer/Support/Matcher.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/reference.h"
 #include "mlir/IR/Value.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index ea658fb16a36c3..805667bfe502b1 100644
--- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
@@ -16,12 +16,12 @@
 #ifndef FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
 #define FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
 
-#include "flang/Common/MathOptionsBase.h"
 #include "flang/Optimizer/Dialect/FIROps.h"
 #include "flang/Optimizer/Dialect/FIROpsSupport.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Dialect/Support/FIRContext.h"
 #include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Support/MathOptionsBase.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "llvm/ADT/DenseMap.h"
diff --git a/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
index 5ae32f70a11a7f..8374b18b8a17d8 100644
--- a/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
@@ -9,8 +9,8 @@
 #ifndef FORTRAN_LOWER_PPCINTRINSICCALL_H
 #define FORTRAN_LOWER_PPCINTRINSICCALL_H
 
-#include "flang/Common/static-multimap-view.h"
 #include "flang/Optimizer/Builder/IntrinsicCall.h"
+#include "flang/Support/static-multimap-view.h"
 #include "mlir/Dialect/Math/IR/Math.h"
 
 namespace fir {
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index eaa1de76154d93..be07e8d2a9390a 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -17,12 +17,12 @@
 #ifndef FORTRAN_OPTIMIZER_BUILDER_RUNTIME_RTBUILDER_H
 #define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_RTBUILDER_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Common/uint128.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Dialect/FIRDialect.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Runtime/reduce.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinTypes.h"
 #include "mlir/IR/MLIRContext.h"
 #include "llvm/ADT/SmallVector.h"
diff --git a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
index 9cccf8db87270e..b9a8a670d07938 100644
--- a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
+++ b/flang/include/flang/Optimizer/...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Jan 27, 2025

@llvm/pr-subscribers-flang-codegen

Author: Michael Kruse (Meinersbur)

Changes

Split off FortranSupport (analogous to LLVMSupport) from FortranCommon such that

  • declarations and definitions that are only used by the Flang compiler, but not by the runtime, are moved to FortranSupport

  • declarations and definitions that are used by both ("common"), the compiler and the runtime, remain in FortranCommon

This allows a for cleaner separation between compiler and runtime components, which are compiled differently. For instance, runtime sources must not use STL's &lt;optional&gt; which causes problems with CUDA support. Instead, the surrogate header flang/Common/optional.h must be used. This PR fixes this for fast-int-sel.h.

Declarations in include/Runtime are also used by both, but are header-only. ISO_Fortran_binding_wrapper.h, a header used by compiler and runtime, is also moved into FortranCommon.

The PR is split off from #110298 and #110217.


Patch is 117.01 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/124416.diff

160 Files Affected:

  • (renamed) flang/include/flang/Common/ISO_Fortran_binding_wrapper.h (+7-8)
  • (modified) flang/include/flang/Common/fast-int-set.h (+3-3)
  • (modified) flang/include/flang/Evaluate/call.h (+3-3)
  • (modified) flang/include/flang/Evaluate/characteristics.h (+3-3)
  • (modified) flang/include/flang/Evaluate/common.h (+4-4)
  • (modified) flang/include/flang/Evaluate/constant.h (+2-2)
  • (modified) flang/include/flang/Evaluate/expression.h (+3-3)
  • (modified) flang/include/flang/Evaluate/formatting.h (+1-1)
  • (modified) flang/include/flang/Evaluate/intrinsics.h (+1-1)
  • (modified) flang/include/flang/Evaluate/shape.h (+1-1)
  • (modified) flang/include/flang/Evaluate/target.h (+1-1)
  • (modified) flang/include/flang/Evaluate/tools.h (+2-2)
  • (modified) flang/include/flang/Evaluate/traverse.h (+1-1)
  • (modified) flang/include/flang/Evaluate/type.h (+3-3)
  • (modified) flang/include/flang/Evaluate/variable.h (+2-2)
  • (modified) flang/include/flang/Frontend/CompilerInvocation.h (+1-1)
  • (modified) flang/include/flang/Frontend/FrontendOptions.h (+1-1)
  • (modified) flang/include/flang/ISO_Fortran_binding.h (+1-1)
  • (modified) flang/include/flang/Lower/AbstractConverter.h (+1-1)
  • (modified) flang/include/flang/Lower/Bridge.h (+1-1)
  • (modified) flang/include/flang/Lower/CallInterface.h (+1-1)
  • (modified) flang/include/flang/Lower/ConvertType.h (+1-1)
  • (modified) flang/include/flang/Lower/LoweringOptions.h (+1-1)
  • (modified) flang/include/flang/Lower/PFTBuilder.h (+2-2)
  • (modified) flang/include/flang/Lower/Support/Utils.h (+1-1)
  • (modified) flang/include/flang/Lower/SymbolMap.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Builder/FIRBuilder.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h (+1-1)
  • (modified) flang/include/flang/Optimizer/CodeGen/DescriptorModel.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Support/TypeCode.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Support/Utils.h (+1-1)
  • (modified) flang/include/flang/Parser/char-block.h (+1-1)
  • (modified) flang/include/flang/Parser/dump-parse-tree.h (+2-2)
  • (modified) flang/include/flang/Parser/message.h (+2-2)
  • (modified) flang/include/flang/Parser/parse-state.h (+1-1)
  • (modified) flang/include/flang/Parser/parse-tree.h (+2-2)
  • (modified) flang/include/flang/Parser/parsing.h (+1-1)
  • (modified) flang/include/flang/Parser/provenance.h (+1-1)
  • (modified) flang/include/flang/Parser/source.h (+1-1)
  • (modified) flang/include/flang/Parser/user-state.h (+1-1)
  • (modified) flang/include/flang/Runtime/descriptor-consts.h (+1-1)
  • (modified) flang/include/flang/Runtime/descriptor.h (+1-1)
  • (modified) flang/include/flang/Runtime/random.h (+5)
  • (modified) flang/include/flang/Runtime/support.h (+1-1)
  • (modified) flang/include/flang/Runtime/type-code.h (+1-1)
  • (modified) flang/include/flang/Semantics/expression.h (+2-2)
  • (modified) flang/include/flang/Semantics/runtime-type-info.h (+1-1)
  • (modified) flang/include/flang/Semantics/scope.h (+2-2)
  • (modified) flang/include/flang/Semantics/semantics.h (+2-2)
  • (modified) flang/include/flang/Semantics/symbol.h (+2-2)
  • (modified) flang/include/flang/Semantics/tools.h (+1-1)
  • (modified) flang/include/flang/Semantics/type.h (+1-1)
  • (renamed) flang/include/flang/Support/Fortran-features.h (+5-5)
  • (renamed) flang/include/flang/Support/Fortran.h (+6-6)
  • (renamed) flang/include/flang/Support/LangOptions.def ()
  • (renamed) flang/include/flang/Support/LangOptions.h (+7-7)
  • (renamed) flang/include/flang/Support/MathOptionsBase.def ()
  • (renamed) flang/include/flang/Support/MathOptionsBase.h (+7-7)
  • (renamed) flang/include/flang/Support/OpenMP-features.h (+4-4)
  • (modified) flang/include/flang/Support/Timing.h (+4-4)
  • (renamed) flang/include/flang/Support/Version.h (+4-4)
  • (renamed) flang/include/flang/Support/default-kinds.h (+5-5)
  • (renamed) flang/include/flang/Support/indirection.h (+5-5)
  • (renamed) flang/include/flang/Support/interval.h (+5-5)
  • (renamed) flang/include/flang/Support/reference-counted.h (+4-4)
  • (renamed) flang/include/flang/Support/reference.h (+4-4)
  • (renamed) flang/include/flang/Support/static-multimap-view.h (+4-4)
  • (renamed) flang/include/flang/Support/template.h (+5-5)
  • (renamed) flang/include/flang/Support/unwrap.h (+6-6)
  • (modified) flang/include/flang/Tools/CrossToolHelpers.h (+2-2)
  • (modified) flang/lib/CMakeLists.txt (-1)
  • (removed) flang/lib/Common/CMakeLists.txt (-52)
  • (modified) flang/lib/Evaluate/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Evaluate/call.cpp (+1-1)
  • (modified) flang/lib/Evaluate/characteristics.cpp (+1-1)
  • (modified) flang/lib/Evaluate/fold-implementation.h (+3-3)
  • (modified) flang/lib/Evaluate/formatting.cpp (+1-1)
  • (modified) flang/lib/Evaluate/intrinsics-library.cpp (+1-1)
  • (modified) flang/lib/Evaluate/intrinsics.cpp (+1-1)
  • (modified) flang/lib/Evaluate/shape.cpp (+1-1)
  • (modified) flang/lib/Evaluate/target.cpp (+1-1)
  • (modified) flang/lib/Frontend/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Frontend/CompilerInstance.cpp (+1-1)
  • (modified) flang/lib/Frontend/CompilerInvocation.cpp (+3-3)
  • (modified) flang/lib/Frontend/FrontendActions.cpp (+1-1)
  • (modified) flang/lib/Lower/Bridge.cpp (+1-1)
  • (modified) flang/lib/Lower/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Lower/CallInterface.cpp (+1-1)
  • (modified) flang/lib/Lower/ConvertExpr.cpp (+2-2)
  • (modified) flang/lib/Lower/Mangler.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Builder/IntrinsicCall.cpp (+1-1)
  • (modified) flang/lib/Optimizer/CodeGen/TypeConverter.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Dialect/FIRType.cpp (+1-1)
  • (modified) flang/lib/Optimizer/OpenMP/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Optimizer/Passes/CMakeLists.txt (+1-4)
  • (modified) flang/lib/Optimizer/Transforms/AddDebugInfo.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CUFDeviceGlobal.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CUFOpConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/LoopVersioning.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/StackReclaim.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/VScaleAttr.cpp (+1-1)
  • (modified) flang/lib/Parser/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Parser/basic-parsers.h (+2-2)
  • (modified) flang/lib/Parser/parse-tree.cpp (+1-1)
  • (modified) flang/lib/Parser/prescan.h (+1-1)
  • (modified) flang/lib/Parser/unparse.cpp (+2-2)
  • (modified) flang/lib/Semantics/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Semantics/assignment.h (+1-1)
  • (modified) flang/lib/Semantics/check-case.cpp (+2-2)
  • (modified) flang/lib/Semantics/check-coarray.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-cuda.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-data.h (+1-1)
  • (modified) flang/lib/Semantics/check-do-forall.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-return.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-select-rank.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-select-type.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-stop.cpp (+1-1)
  • (modified) flang/lib/Semantics/data-to-inits.h (+2-2)
  • (modified) flang/lib/Semantics/expression.cpp (+1-1)
  • (modified) flang/lib/Semantics/pointer-assignment.cpp (+1-1)
  • (modified) flang/lib/Semantics/resolve-labels.cpp (+1-1)
  • (modified) flang/lib/Semantics/resolve-names-utils.cpp (+3-3)
  • (modified) flang/lib/Semantics/resolve-names.cpp (+3-3)
  • (modified) flang/lib/Semantics/rewrite-parse-tree.cpp (+1-1)
  • (modified) flang/lib/Semantics/semantics.cpp (+1-1)
  • (modified) flang/lib/Semantics/tools.cpp (+2-2)
  • (modified) flang/lib/Support/CMakeLists.txt (+53)
  • (renamed) flang/lib/Support/Fortran-features.cpp (+3-3)
  • (renamed) flang/lib/Support/Fortran.cpp (+3-3)
  • (renamed) flang/lib/Support/LangOptions.cpp (+3-3)
  • (renamed) flang/lib/Support/OpenMP-utils.cpp (+1-1)
  • (modified) flang/lib/Support/Timing.cpp (+1-1)
  • (renamed) flang/lib/Support/Version.cpp (+2-2)
  • (renamed) flang/lib/Support/default-kinds.cpp (+2-2)
  • (renamed) flang/lib/Support/idioms.cpp (+1-1)
  • (modified) flang/runtime/CUDA/allocator.cpp (+2-2)
  • (modified) flang/runtime/ISO_Fortran_binding.cpp (+1-1)
  • (modified) flang/runtime/ISO_Fortran_util.h (+1-1)
  • (modified) flang/runtime/allocatable.cpp (+1-1)
  • (modified) flang/runtime/stat.h (+1-1)
  • (modified) flang/runtime/temporary-stack.cpp (+1-1)
  • (modified) flang/tools/bbc/CMakeLists.txt (+1-1)
  • (modified) flang/tools/bbc/bbc.cpp (+5-5)
  • (modified) flang/tools/f18-parse-demo/CMakeLists.txt (+1-1)
  • (modified) flang/tools/f18-parse-demo/f18-parse-demo.cpp (+2-2)
  • (modified) flang/tools/tco/CMakeLists.txt (+1-1)
  • (modified) flang/unittests/Evaluate/CMakeLists.txt (+3-3)
  • (modified) flang/unittests/Evaluate/ISO-Fortran-binding.cpp (+1-1)
  • (modified) flang/unittests/Frontend/CMakeLists.txt (+1-1)
  • (modified) flang/unittests/Runtime/CUDA/Allocatable.cpp (+1-1)
  • (modified) flang/unittests/Runtime/CUDA/AllocatorCUF.cpp (+1-1)
  • (modified) flang/unittests/Runtime/CUDA/Memory.cpp (+1-1)
  • (modified) flang/unittests/Runtime/TemporaryStack.cpp (+1-1)
diff --git a/flang/include/flang/ISO_Fortran_binding_wrapper.h b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
similarity index 70%
rename from flang/include/flang/ISO_Fortran_binding_wrapper.h
rename to flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
index 37289bdbabd03c..7a8a8a9787bd03 100644
--- a/flang/include/flang/ISO_Fortran_binding_wrapper.h
+++ b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
@@ -1,14 +1,13 @@
-/*===-- include/flang/ISO_Fortran_binding_wrapper.h ---------------*- C++ -*-===
+/*===-- include/flang/Common/ISO_Fortran_binding_wrapper.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
  *
- * ===-----------------------------------------------------------------------===
- */
+ *===----------------------------------------------------------------------===*/
 
-#ifndef FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
-#define FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
+#ifndef FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
+#define FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
 
 /* A thin wrapper around flang/include/ISO_Fortran_binding.h
  * This header file must be included when ISO_Fortran_binding.h
@@ -23,17 +22,17 @@
 
 /* clang-format off */
 #include <stddef.h>
-#include "Common/api-attrs.h"
+#include "flang/Common/api-attrs.h"
 #ifdef __cplusplus
 namespace Fortran {
 namespace ISO {
 #define FORTRAN_ISO_NAMESPACE_ ::Fortran::ISO
 #endif /* __cplusplus */
-#include "ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding.h"
 #ifdef __cplusplus
 } // namespace ISO
 } // namespace Fortran
 #endif /* __cplusplus */
 /* clang-format on */
 
-#endif /* FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_ */
+#endif /* FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_ */
diff --git a/flang/include/flang/Common/fast-int-set.h b/flang/include/flang/Common/fast-int-set.h
index d1c9c756a44a65..1214bac75a4bf1 100644
--- a/flang/include/flang/Common/fast-int-set.h
+++ b/flang/include/flang/Common/fast-int-set.h
@@ -24,7 +24,7 @@
 #ifndef FORTRAN_COMMON_FAST_INT_SET_H_
 #define FORTRAN_COMMON_FAST_INT_SET_H_
 
-#include <optional>
+#include "optional.h"
 
 namespace Fortran::common {
 
@@ -83,9 +83,9 @@ template <int N> class FastIntSet {
     }
   }
 
-  std::optional<int> PopValue() {
+  optional<int> PopValue() {
     if (IsEmpty()) {
-      return std::nullopt;
+      return nullopt;
     } else {
       return value_[--size_];
     }
diff --git a/flang/include/flang/Evaluate/call.h b/flang/include/flang/Evaluate/call.h
index 63277438128ebb..4d8ca28cf329a1 100644
--- a/flang/include/flang/Evaluate/call.h
+++ b/flang/include/flang/Evaluate/call.h
@@ -13,11 +13,11 @@
 #include "constant.h"
 #include "formatting.h"
 #include "type.h"
-#include "flang/Common/Fortran.h"
-#include "flang/Common/indirection.h"
-#include "flang/Common/reference.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/attr.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
+#include "flang/Support/reference.h"
 #include <optional>
 #include <vector>
 
diff --git a/flang/include/flang/Evaluate/characteristics.h b/flang/include/flang/Evaluate/characteristics.h
index 357fc3e5952436..ccd584b5ee6aa4 100644
--- a/flang/include/flang/Evaluate/characteristics.h
+++ b/flang/include/flang/Evaluate/characteristics.h
@@ -18,13 +18,13 @@
 #include "shape.h"
 #include "tools.h"
 #include "type.h"
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
 #include <optional>
 #include <string>
 #include <variant>
diff --git a/flang/include/flang/Evaluate/common.h b/flang/include/flang/Evaluate/common.h
index 915e95169c7f81..91d38748f5a575 100644
--- a/flang/include/flang/Evaluate/common.h
+++ b/flang/include/flang/Evaluate/common.h
@@ -9,16 +9,16 @@
 #ifndef FORTRAN_EVALUATE_COMMON_H_
 #define FORTRAN_EVALUATE_COMMON_H_
 
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Common/restorer.h"
 #include "flang/Common/target-rounding.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Parser/message.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/default-kinds.h"
+#include "flang/Support/indirection.h"
 #include <cinttypes>
 #include <map>
 #include <set>
diff --git a/flang/include/flang/Evaluate/constant.h b/flang/include/flang/Evaluate/constant.h
index 61a814446bbfd3..63e8ed4119cdf5 100644
--- a/flang/include/flang/Evaluate/constant.h
+++ b/flang/include/flang/Evaluate/constant.h
@@ -11,8 +11,8 @@
 
 #include "formatting.h"
 #include "type.h"
-#include "flang/Common/default-kinds.h"
-#include "flang/Common/reference.h"
+#include "flang/Support/default-kinds.h"
+#include "flang/Support/reference.h"
 #include <map>
 #include <vector>
 
diff --git a/flang/include/flang/Evaluate/expression.h b/flang/include/flang/Evaluate/expression.h
index 04f4406fc8a2c0..ec71550d2a50c9 100644
--- a/flang/include/flang/Evaluate/expression.h
+++ b/flang/include/flang/Evaluate/expression.h
@@ -21,11 +21,11 @@
 #include "formatting.h"
 #include "type.h"
 #include "variable.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
-#include "flang/Common/template.h"
 #include "flang/Parser/char-block.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
+#include "flang/Support/template.h"
 #include <algorithm>
 #include <list>
 #include <tuple>
diff --git a/flang/include/flang/Evaluate/formatting.h b/flang/include/flang/Evaluate/formatting.h
index aa82f56107fdd3..ae9351139b1933 100644
--- a/flang/include/flang/Evaluate/formatting.h
+++ b/flang/include/flang/Evaluate/formatting.h
@@ -19,7 +19,7 @@
 // This header is meant to be included by the headers that define the several
 // representational class templates that need it, not by external clients.
 
-#include "flang/Common/indirection.h"
+#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <optional>
 #include <type_traits>
diff --git a/flang/include/flang/Evaluate/intrinsics.h b/flang/include/flang/Evaluate/intrinsics.h
index 15afb772ae767b..dbe1ba7fe7ec1b 100644
--- a/flang/include/flang/Evaluate/intrinsics.h
+++ b/flang/include/flang/Evaluate/intrinsics.h
@@ -12,9 +12,9 @@
 #include "call.h"
 #include "characteristics.h"
 #include "type.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Parser/message.h"
+#include "flang/Support/default-kinds.h"
 #include <memory>
 #include <optional>
 #include <string>
diff --git a/flang/include/flang/Evaluate/shape.h b/flang/include/flang/Evaluate/shape.h
index 3e42ec691158bc..18dca71379e0da 100644
--- a/flang/include/flang/Evaluate/shape.h
+++ b/flang/include/flang/Evaluate/shape.h
@@ -15,8 +15,8 @@
 #include "expression.h"
 #include "traverse.h"
 #include "variable.h"
-#include "flang/Common/indirection.h"
 #include "flang/Evaluate/type.h"
+#include "flang/Support/indirection.h"
 #include <optional>
 #include <variant>
 
diff --git a/flang/include/flang/Evaluate/target.h b/flang/include/flang/Evaluate/target.h
index e07f916b875e06..f4595dfe4e4333 100644
--- a/flang/include/flang/Evaluate/target.h
+++ b/flang/include/flang/Evaluate/target.h
@@ -12,11 +12,11 @@
 #ifndef FORTRAN_EVALUATE_TARGET_H_
 #define FORTRAN_EVALUATE_TARGET_H_
 
-#include "flang/Common/Fortran.h"
 #include "flang/Common/enum-class.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/target-rounding.h"
 #include "flang/Evaluate/common.h"
+#include "flang/Support/Fortran.h"
 #include <cstdint>
 
 namespace Fortran::evaluate {
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index 669efb41b03442..fbe905168d2538 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -11,8 +11,6 @@
 
 #include "traverse.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/template.h"
-#include "flang/Common/unwrap.h"
 #include "flang/Evaluate/constant.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Evaluate/shape.h"
@@ -21,6 +19,8 @@
 #include "flang/Semantics/attr.h"
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/template.h"
+#include "flang/Support/unwrap.h"
 #include <array>
 #include <optional>
 #include <set>
diff --git a/flang/include/flang/Evaluate/traverse.h b/flang/include/flang/Evaluate/traverse.h
index dd38d64bff63f7..58f188a4092493 100644
--- a/flang/include/flang/Evaluate/traverse.h
+++ b/flang/include/flang/Evaluate/traverse.h
@@ -38,9 +38,9 @@
 // expression of an ASSOCIATE (or related) construct entity.
 
 #include "expression.h"
-#include "flang/Common/indirection.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/type.h"
+#include "flang/Support/indirection.h"
 #include <set>
 #include <type_traits>
 
diff --git a/flang/include/flang/Evaluate/type.h b/flang/include/flang/Evaluate/type.h
index 1f9296ac4fea75..ab7e4723152d7e 100644
--- a/flang/include/flang/Evaluate/type.h
+++ b/flang/include/flang/Evaluate/type.h
@@ -22,11 +22,11 @@
 #include "integer.h"
 #include "logical.h"
 #include "real.h"
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
 #include "flang/Common/real.h"
-#include "flang/Common/template.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/template.h"
 #include <cinttypes>
 #include <optional>
 #include <string>
diff --git a/flang/include/flang/Evaluate/variable.h b/flang/include/flang/Evaluate/variable.h
index 9b597d29813da1..bb4150613c81dd 100644
--- a/flang/include/flang/Evaluate/variable.h
+++ b/flang/include/flang/Evaluate/variable.h
@@ -21,9 +21,9 @@
 #include "static-data.h"
 #include "type.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/reference.h"
-#include "flang/Common/template.h"
 #include "flang/Parser/char-block.h"
+#include "flang/Support/reference.h"
+#include "flang/Support/template.h"
 #include <optional>
 #include <variant>
 #include <vector>
diff --git a/flang/include/flang/Frontend/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h
index 7d3f0bdf2e510e..b3b7297f6f7f1f 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -13,7 +13,6 @@
 #ifndef FORTRAN_FRONTEND_COMPILERINVOCATION_H
 #define FORTRAN_FRONTEND_COMPILERINVOCATION_H
 
-#include "flang/Common/LangOptions.h"
 #include "flang/Frontend/CodeGenOptions.h"
 #include "flang/Frontend/FrontendOptions.h"
 #include "flang/Frontend/PreprocessorOptions.h"
@@ -22,6 +21,7 @@
 #include "flang/Parser/parsing.h"
 #include "flang/Semantics/semantics.h"
 #include "mlir/Support/Timing.h"
+#include "flang/Support/LangOptions.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "llvm/Option/ArgList.h"
diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index a4cb021e309d4a..0bd2e621813ca5 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -13,10 +13,10 @@
 #ifndef FORTRAN_FRONTEND_FRONTENDOPTIONS_H
 #define FORTRAN_FRONTEND_FRONTENDOPTIONS_H
 
-#include "flang/Common/Fortran-features.h"
 #include "flang/Lower/EnvironmentDefault.h"
 #include "flang/Parser/characters.h"
 #include "flang/Parser/unparse.h"
+#include "flang/Support/Fortran-features.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include <cstdint>
diff --git a/flang/include/flang/ISO_Fortran_binding.h b/flang/include/flang/ISO_Fortran_binding.h
index 945f8fef89f0b4..f5b8d0d2ea610a 100644
--- a/flang/include/flang/ISO_Fortran_binding.h
+++ b/flang/include/flang/ISO_Fortran_binding.h
@@ -14,7 +14,7 @@
  * it does so by means of a wrapper header that establishes namespaces and
  * a macro for extra function attributes (RT_API_ATTRS).
  */
-#ifndef FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
+#ifndef FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
 #include <stddef.h>
 #define FORTRAN_ISO_NAMESPACE_
 #endif
diff --git a/flang/include/flang/Lower/AbstractConverter.h b/flang/include/flang/Lower/AbstractConverter.h
index c24f43737df50a..3d2b805da6f477 100644
--- a/flang/include/flang/Lower/AbstractConverter.h
+++ b/flang/include/flang/Lower/AbstractConverter.h
@@ -13,12 +13,12 @@
 #ifndef FORTRAN_LOWER_ABSTRACTCONVERTER_H
 #define FORTRAN_LOWER_ABSTRACTCONVERTER_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Lower/LoweringOptions.h"
 #include "flang/Lower/PFTDefs.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Dialect/FIRAttr.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/Operation.h"
diff --git a/flang/include/flang/Lower/Bridge.h b/flang/include/flang/Lower/Bridge.h
index 6404a16f7785ae..a8c2bcfda31c1f 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -13,7 +13,6 @@
 #ifndef FORTRAN_LOWER_BRIDGE_H
 #define FORTRAN_LOWER_BRIDGE_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Frontend/CodeGenOptions.h"
 #include "flang/Frontend/TargetOptions.h"
 #include "flang/Lower/AbstractConverter.h"
@@ -22,6 +21,7 @@
 #include "flang/Lower/StatementContext.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/OwningOpRef.h"
 #include <set>
diff --git a/flang/include/flang/Lower/CallInterface.h b/flang/include/flang/Lower/CallInterface.h
index 72bc9dd890a94b..c15edf62df388e 100644
--- a/flang/include/flang/Lower/CallInterface.h
+++ b/flang/include/flang/Lower/CallInterface.h
@@ -27,8 +27,8 @@
 #ifndef FORTRAN_LOWER_CALLINTERFACE_H
 #define FORTRAN_LOWER_CALLINTERFACE_H
 
-#include "flang/Common/reference.h"
 #include "flang/Evaluate/characteristics.h"
+#include "flang/Support/reference.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/IR/BuiltinOps.h"
 #include <memory>
diff --git a/flang/include/flang/Lower/ConvertType.h b/flang/include/flang/Lower/ConvertType.h
index 7a3f92649a4e4a..179a6825840464 100644
--- a/flang/include/flang/Lower/ConvertType.h
+++ b/flang/include/flang/Lower/ConvertType.h
@@ -21,8 +21,8 @@
 #ifndef FORTRAN_LOWER_CONVERT_TYPE_H
 #define FORTRAN_LOWER_CONVERT_TYPE_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Evaluate/type.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinTypes.h"
 
 namespace mlir {
diff --git a/flang/include/flang/Lower/LoweringOptions.h b/flang/include/flang/Lower/LoweringOptions.h
index 8105ccd7ef6b15..171510393b8168 100644
--- a/flang/include/flang/Lower/LoweringOptions.h
+++ b/flang/include/flang/Lower/LoweringOptions.h
@@ -15,7 +15,7 @@
 #ifndef FLANG_LOWER_LOWERINGOPTIONS_H
 #define FLANG_LOWER_LOWERINGOPTIONS_H
 
-#include "flang/Common/MathOptionsBase.h"
+#include "flang/Support/MathOptionsBase.h"
 
 namespace Fortran::lower {
 
diff --git a/flang/include/flang/Lower/PFTBuilder.h b/flang/include/flang/Lower/PFTBuilder.h
index 42d6546b77553b..05da17faf2dd7d 100644
--- a/flang/include/flang/Lower/PFTBuilder.h
+++ b/flang/include/flang/Lower/PFTBuilder.h
@@ -17,8 +17,6 @@
 #ifndef FORTRAN_LOWER_PFTBUILDER_H
 #define FORTRAN_LOWER_PFTBUILDER_H
 
-#include "flang/Common/reference.h"
-#include "flang/Common/template.h"
 #include "flang/Lower/HostAssociations.h"
 #include "flang/Lower/PFTDefs.h"
 #include "flang/Parser/parse-tree.h"
@@ -26,6 +24,8 @@
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/reference.h"
+#include "flang/Support/template.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
diff --git a/flang/include/flang/Lower/Support/Utils.h b/flang/include/flang/Lower/Support/Utils.h
index 1cc74521e22d88..08a872b228691d 100644
--- a/flang/include/flang/Lower/Support/Utils.h
+++ b/flang/include/flang/Lower/Support/Utils.h
@@ -13,9 +13,9 @@
 #ifndef FORTRAN_LOWER_SUPPORT_UTILS_H
 #define FORTRAN_LOWER_SUPPORT_UTILS_H
 
-#include "flang/Common/indirection.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/indirection.h"
 #include "mlir/Dialect/Arith/IR/Arith.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/IR/BuiltinAttributes.h"
diff --git a/flang/include/flang/Lower/SymbolMap.h b/flang/include/flang/Lower/SymbolMap.h
index c03f9afd40801c..fb64db407708ad 100644
--- a/flang/include/flang/Lower/SymbolMap.h
+++ b/flang/include/flang/Lower/SymbolMap.h
@@ -13,12 +13,12 @@
 #ifndef FORTRAN_LOWER_SYMBOLMAP_H
 #define FORTRAN_LOWER_SYMBOLMAP_H
 
-#include "flang/Common/reference.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Dialect/FortranVariableInterface.h"
 #include "flang/Optimizer/Support/Matcher.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/reference.h"
 #include "mlir/IR/Value.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index ea658fb16a36c3..805667bfe502b1 100644
--- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
@@ -16,12 +16,12 @@
 #ifndef FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
 #define FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
 
-#include "flang/Common/MathOptionsBase.h"
 #include "flang/Optimizer/Dialect/FIROps.h"
 #include "flang/Optimizer/Dialect/FIROpsSupport.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Dialect/Support/FIRContext.h"
 #include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Support/MathOptionsBase.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "llvm/ADT/DenseMap.h"
diff --git a/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
index 5ae32f70a11a7f..8374b18b8a17d8 100644
--- a/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
@@ -9,8 +9,8 @@
 #ifndef FORTRAN_LOWER_PPCINTRINSICCALL_H
 #define FORTRAN_LOWER_PPCINTRINSICCALL_H
 
-#include "flang/Common/static-multimap-view.h"
 #include "flang/Optimizer/Builder/IntrinsicCall.h"
+#include "flang/Support/static-multimap-view.h"
 #include "mlir/Dialect/Math/IR/Math.h"
 
 namespace fir {
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index eaa1de76154d93..be07e8d2a9390a 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -17,12 +17,12 @@
 #ifndef FORTRAN_OPTIMIZER_BUILDER_RUNTIME_RTBUILDER_H
 #define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_RTBUILDER_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Common/uint128.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Dialect/FIRDialect.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Runtime/reduce.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinTypes.h"
 #include "mlir/IR/MLIRContext.h"
 #include "llvm/ADT/SmallVector.h"
diff --git a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
index 9cccf8db87270e..b9a8a670d07938 100644
--- a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
+++ b/flang/include/flang/Optimizer/...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Jan 27, 2025

@llvm/pr-subscribers-flang-semantics

Author: Michael Kruse (Meinersbur)

Changes

Split off FortranSupport (analogous to LLVMSupport) from FortranCommon such that

  • declarations and definitions that are only used by the Flang compiler, but not by the runtime, are moved to FortranSupport

  • declarations and definitions that are used by both ("common"), the compiler and the runtime, remain in FortranCommon

This allows a for cleaner separation between compiler and runtime components, which are compiled differently. For instance, runtime sources must not use STL's &lt;optional&gt; which causes problems with CUDA support. Instead, the surrogate header flang/Common/optional.h must be used. This PR fixes this for fast-int-sel.h.

Declarations in include/Runtime are also used by both, but are header-only. ISO_Fortran_binding_wrapper.h, a header used by compiler and runtime, is also moved into FortranCommon.

The PR is split off from #110298 and #110217.


Patch is 117.01 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/124416.diff

160 Files Affected:

  • (renamed) flang/include/flang/Common/ISO_Fortran_binding_wrapper.h (+7-8)
  • (modified) flang/include/flang/Common/fast-int-set.h (+3-3)
  • (modified) flang/include/flang/Evaluate/call.h (+3-3)
  • (modified) flang/include/flang/Evaluate/characteristics.h (+3-3)
  • (modified) flang/include/flang/Evaluate/common.h (+4-4)
  • (modified) flang/include/flang/Evaluate/constant.h (+2-2)
  • (modified) flang/include/flang/Evaluate/expression.h (+3-3)
  • (modified) flang/include/flang/Evaluate/formatting.h (+1-1)
  • (modified) flang/include/flang/Evaluate/intrinsics.h (+1-1)
  • (modified) flang/include/flang/Evaluate/shape.h (+1-1)
  • (modified) flang/include/flang/Evaluate/target.h (+1-1)
  • (modified) flang/include/flang/Evaluate/tools.h (+2-2)
  • (modified) flang/include/flang/Evaluate/traverse.h (+1-1)
  • (modified) flang/include/flang/Evaluate/type.h (+3-3)
  • (modified) flang/include/flang/Evaluate/variable.h (+2-2)
  • (modified) flang/include/flang/Frontend/CompilerInvocation.h (+1-1)
  • (modified) flang/include/flang/Frontend/FrontendOptions.h (+1-1)
  • (modified) flang/include/flang/ISO_Fortran_binding.h (+1-1)
  • (modified) flang/include/flang/Lower/AbstractConverter.h (+1-1)
  • (modified) flang/include/flang/Lower/Bridge.h (+1-1)
  • (modified) flang/include/flang/Lower/CallInterface.h (+1-1)
  • (modified) flang/include/flang/Lower/ConvertType.h (+1-1)
  • (modified) flang/include/flang/Lower/LoweringOptions.h (+1-1)
  • (modified) flang/include/flang/Lower/PFTBuilder.h (+2-2)
  • (modified) flang/include/flang/Lower/Support/Utils.h (+1-1)
  • (modified) flang/include/flang/Lower/SymbolMap.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Builder/FIRBuilder.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h (+1-1)
  • (modified) flang/include/flang/Optimizer/CodeGen/DescriptorModel.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Support/TypeCode.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Support/Utils.h (+1-1)
  • (modified) flang/include/flang/Parser/char-block.h (+1-1)
  • (modified) flang/include/flang/Parser/dump-parse-tree.h (+2-2)
  • (modified) flang/include/flang/Parser/message.h (+2-2)
  • (modified) flang/include/flang/Parser/parse-state.h (+1-1)
  • (modified) flang/include/flang/Parser/parse-tree.h (+2-2)
  • (modified) flang/include/flang/Parser/parsing.h (+1-1)
  • (modified) flang/include/flang/Parser/provenance.h (+1-1)
  • (modified) flang/include/flang/Parser/source.h (+1-1)
  • (modified) flang/include/flang/Parser/user-state.h (+1-1)
  • (modified) flang/include/flang/Runtime/descriptor-consts.h (+1-1)
  • (modified) flang/include/flang/Runtime/descriptor.h (+1-1)
  • (modified) flang/include/flang/Runtime/random.h (+5)
  • (modified) flang/include/flang/Runtime/support.h (+1-1)
  • (modified) flang/include/flang/Runtime/type-code.h (+1-1)
  • (modified) flang/include/flang/Semantics/expression.h (+2-2)
  • (modified) flang/include/flang/Semantics/runtime-type-info.h (+1-1)
  • (modified) flang/include/flang/Semantics/scope.h (+2-2)
  • (modified) flang/include/flang/Semantics/semantics.h (+2-2)
  • (modified) flang/include/flang/Semantics/symbol.h (+2-2)
  • (modified) flang/include/flang/Semantics/tools.h (+1-1)
  • (modified) flang/include/flang/Semantics/type.h (+1-1)
  • (renamed) flang/include/flang/Support/Fortran-features.h (+5-5)
  • (renamed) flang/include/flang/Support/Fortran.h (+6-6)
  • (renamed) flang/include/flang/Support/LangOptions.def ()
  • (renamed) flang/include/flang/Support/LangOptions.h (+7-7)
  • (renamed) flang/include/flang/Support/MathOptionsBase.def ()
  • (renamed) flang/include/flang/Support/MathOptionsBase.h (+7-7)
  • (renamed) flang/include/flang/Support/OpenMP-features.h (+4-4)
  • (modified) flang/include/flang/Support/Timing.h (+4-4)
  • (renamed) flang/include/flang/Support/Version.h (+4-4)
  • (renamed) flang/include/flang/Support/default-kinds.h (+5-5)
  • (renamed) flang/include/flang/Support/indirection.h (+5-5)
  • (renamed) flang/include/flang/Support/interval.h (+5-5)
  • (renamed) flang/include/flang/Support/reference-counted.h (+4-4)
  • (renamed) flang/include/flang/Support/reference.h (+4-4)
  • (renamed) flang/include/flang/Support/static-multimap-view.h (+4-4)
  • (renamed) flang/include/flang/Support/template.h (+5-5)
  • (renamed) flang/include/flang/Support/unwrap.h (+6-6)
  • (modified) flang/include/flang/Tools/CrossToolHelpers.h (+2-2)
  • (modified) flang/lib/CMakeLists.txt (-1)
  • (removed) flang/lib/Common/CMakeLists.txt (-52)
  • (modified) flang/lib/Evaluate/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Evaluate/call.cpp (+1-1)
  • (modified) flang/lib/Evaluate/characteristics.cpp (+1-1)
  • (modified) flang/lib/Evaluate/fold-implementation.h (+3-3)
  • (modified) flang/lib/Evaluate/formatting.cpp (+1-1)
  • (modified) flang/lib/Evaluate/intrinsics-library.cpp (+1-1)
  • (modified) flang/lib/Evaluate/intrinsics.cpp (+1-1)
  • (modified) flang/lib/Evaluate/shape.cpp (+1-1)
  • (modified) flang/lib/Evaluate/target.cpp (+1-1)
  • (modified) flang/lib/Frontend/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Frontend/CompilerInstance.cpp (+1-1)
  • (modified) flang/lib/Frontend/CompilerInvocation.cpp (+3-3)
  • (modified) flang/lib/Frontend/FrontendActions.cpp (+1-1)
  • (modified) flang/lib/Lower/Bridge.cpp (+1-1)
  • (modified) flang/lib/Lower/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Lower/CallInterface.cpp (+1-1)
  • (modified) flang/lib/Lower/ConvertExpr.cpp (+2-2)
  • (modified) flang/lib/Lower/Mangler.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Builder/IntrinsicCall.cpp (+1-1)
  • (modified) flang/lib/Optimizer/CodeGen/TypeConverter.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Dialect/FIRType.cpp (+1-1)
  • (modified) flang/lib/Optimizer/OpenMP/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Optimizer/Passes/CMakeLists.txt (+1-4)
  • (modified) flang/lib/Optimizer/Transforms/AddDebugInfo.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CUFDeviceGlobal.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/CUFOpConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/LoopVersioning.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/StackReclaim.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/VScaleAttr.cpp (+1-1)
  • (modified) flang/lib/Parser/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Parser/basic-parsers.h (+2-2)
  • (modified) flang/lib/Parser/parse-tree.cpp (+1-1)
  • (modified) flang/lib/Parser/prescan.h (+1-1)
  • (modified) flang/lib/Parser/unparse.cpp (+2-2)
  • (modified) flang/lib/Semantics/CMakeLists.txt (+1-1)
  • (modified) flang/lib/Semantics/assignment.h (+1-1)
  • (modified) flang/lib/Semantics/check-case.cpp (+2-2)
  • (modified) flang/lib/Semantics/check-coarray.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-cuda.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-data.h (+1-1)
  • (modified) flang/lib/Semantics/check-do-forall.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-return.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-select-rank.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-select-type.cpp (+1-1)
  • (modified) flang/lib/Semantics/check-stop.cpp (+1-1)
  • (modified) flang/lib/Semantics/data-to-inits.h (+2-2)
  • (modified) flang/lib/Semantics/expression.cpp (+1-1)
  • (modified) flang/lib/Semantics/pointer-assignment.cpp (+1-1)
  • (modified) flang/lib/Semantics/resolve-labels.cpp (+1-1)
  • (modified) flang/lib/Semantics/resolve-names-utils.cpp (+3-3)
  • (modified) flang/lib/Semantics/resolve-names.cpp (+3-3)
  • (modified) flang/lib/Semantics/rewrite-parse-tree.cpp (+1-1)
  • (modified) flang/lib/Semantics/semantics.cpp (+1-1)
  • (modified) flang/lib/Semantics/tools.cpp (+2-2)
  • (modified) flang/lib/Support/CMakeLists.txt (+53)
  • (renamed) flang/lib/Support/Fortran-features.cpp (+3-3)
  • (renamed) flang/lib/Support/Fortran.cpp (+3-3)
  • (renamed) flang/lib/Support/LangOptions.cpp (+3-3)
  • (renamed) flang/lib/Support/OpenMP-utils.cpp (+1-1)
  • (modified) flang/lib/Support/Timing.cpp (+1-1)
  • (renamed) flang/lib/Support/Version.cpp (+2-2)
  • (renamed) flang/lib/Support/default-kinds.cpp (+2-2)
  • (renamed) flang/lib/Support/idioms.cpp (+1-1)
  • (modified) flang/runtime/CUDA/allocator.cpp (+2-2)
  • (modified) flang/runtime/ISO_Fortran_binding.cpp (+1-1)
  • (modified) flang/runtime/ISO_Fortran_util.h (+1-1)
  • (modified) flang/runtime/allocatable.cpp (+1-1)
  • (modified) flang/runtime/stat.h (+1-1)
  • (modified) flang/runtime/temporary-stack.cpp (+1-1)
  • (modified) flang/tools/bbc/CMakeLists.txt (+1-1)
  • (modified) flang/tools/bbc/bbc.cpp (+5-5)
  • (modified) flang/tools/f18-parse-demo/CMakeLists.txt (+1-1)
  • (modified) flang/tools/f18-parse-demo/f18-parse-demo.cpp (+2-2)
  • (modified) flang/tools/tco/CMakeLists.txt (+1-1)
  • (modified) flang/unittests/Evaluate/CMakeLists.txt (+3-3)
  • (modified) flang/unittests/Evaluate/ISO-Fortran-binding.cpp (+1-1)
  • (modified) flang/unittests/Frontend/CMakeLists.txt (+1-1)
  • (modified) flang/unittests/Runtime/CUDA/Allocatable.cpp (+1-1)
  • (modified) flang/unittests/Runtime/CUDA/AllocatorCUF.cpp (+1-1)
  • (modified) flang/unittests/Runtime/CUDA/Memory.cpp (+1-1)
  • (modified) flang/unittests/Runtime/TemporaryStack.cpp (+1-1)
diff --git a/flang/include/flang/ISO_Fortran_binding_wrapper.h b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
similarity index 70%
rename from flang/include/flang/ISO_Fortran_binding_wrapper.h
rename to flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
index 37289bdbabd03c..7a8a8a9787bd03 100644
--- a/flang/include/flang/ISO_Fortran_binding_wrapper.h
+++ b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
@@ -1,14 +1,13 @@
-/*===-- include/flang/ISO_Fortran_binding_wrapper.h ---------------*- C++ -*-===
+/*===-- include/flang/Common/ISO_Fortran_binding_wrapper.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
  *
- * ===-----------------------------------------------------------------------===
- */
+ *===----------------------------------------------------------------------===*/
 
-#ifndef FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
-#define FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
+#ifndef FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
+#define FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
 
 /* A thin wrapper around flang/include/ISO_Fortran_binding.h
  * This header file must be included when ISO_Fortran_binding.h
@@ -23,17 +22,17 @@
 
 /* clang-format off */
 #include <stddef.h>
-#include "Common/api-attrs.h"
+#include "flang/Common/api-attrs.h"
 #ifdef __cplusplus
 namespace Fortran {
 namespace ISO {
 #define FORTRAN_ISO_NAMESPACE_ ::Fortran::ISO
 #endif /* __cplusplus */
-#include "ISO_Fortran_binding.h"
+#include "flang/ISO_Fortran_binding.h"
 #ifdef __cplusplus
 } // namespace ISO
 } // namespace Fortran
 #endif /* __cplusplus */
 /* clang-format on */
 
-#endif /* FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_ */
+#endif /* FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_ */
diff --git a/flang/include/flang/Common/fast-int-set.h b/flang/include/flang/Common/fast-int-set.h
index d1c9c756a44a65..1214bac75a4bf1 100644
--- a/flang/include/flang/Common/fast-int-set.h
+++ b/flang/include/flang/Common/fast-int-set.h
@@ -24,7 +24,7 @@
 #ifndef FORTRAN_COMMON_FAST_INT_SET_H_
 #define FORTRAN_COMMON_FAST_INT_SET_H_
 
-#include <optional>
+#include "optional.h"
 
 namespace Fortran::common {
 
@@ -83,9 +83,9 @@ template <int N> class FastIntSet {
     }
   }
 
-  std::optional<int> PopValue() {
+  optional<int> PopValue() {
     if (IsEmpty()) {
-      return std::nullopt;
+      return nullopt;
     } else {
       return value_[--size_];
     }
diff --git a/flang/include/flang/Evaluate/call.h b/flang/include/flang/Evaluate/call.h
index 63277438128ebb..4d8ca28cf329a1 100644
--- a/flang/include/flang/Evaluate/call.h
+++ b/flang/include/flang/Evaluate/call.h
@@ -13,11 +13,11 @@
 #include "constant.h"
 #include "formatting.h"
 #include "type.h"
-#include "flang/Common/Fortran.h"
-#include "flang/Common/indirection.h"
-#include "flang/Common/reference.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/attr.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
+#include "flang/Support/reference.h"
 #include <optional>
 #include <vector>
 
diff --git a/flang/include/flang/Evaluate/characteristics.h b/flang/include/flang/Evaluate/characteristics.h
index 357fc3e5952436..ccd584b5ee6aa4 100644
--- a/flang/include/flang/Evaluate/characteristics.h
+++ b/flang/include/flang/Evaluate/characteristics.h
@@ -18,13 +18,13 @@
 #include "shape.h"
 #include "tools.h"
 #include "type.h"
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
 #include <optional>
 #include <string>
 #include <variant>
diff --git a/flang/include/flang/Evaluate/common.h b/flang/include/flang/Evaluate/common.h
index 915e95169c7f81..91d38748f5a575 100644
--- a/flang/include/flang/Evaluate/common.h
+++ b/flang/include/flang/Evaluate/common.h
@@ -9,16 +9,16 @@
 #ifndef FORTRAN_EVALUATE_COMMON_H_
 #define FORTRAN_EVALUATE_COMMON_H_
 
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Common/restorer.h"
 #include "flang/Common/target-rounding.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Parser/message.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/default-kinds.h"
+#include "flang/Support/indirection.h"
 #include <cinttypes>
 #include <map>
 #include <set>
diff --git a/flang/include/flang/Evaluate/constant.h b/flang/include/flang/Evaluate/constant.h
index 61a814446bbfd3..63e8ed4119cdf5 100644
--- a/flang/include/flang/Evaluate/constant.h
+++ b/flang/include/flang/Evaluate/constant.h
@@ -11,8 +11,8 @@
 
 #include "formatting.h"
 #include "type.h"
-#include "flang/Common/default-kinds.h"
-#include "flang/Common/reference.h"
+#include "flang/Support/default-kinds.h"
+#include "flang/Support/reference.h"
 #include <map>
 #include <vector>
 
diff --git a/flang/include/flang/Evaluate/expression.h b/flang/include/flang/Evaluate/expression.h
index 04f4406fc8a2c0..ec71550d2a50c9 100644
--- a/flang/include/flang/Evaluate/expression.h
+++ b/flang/include/flang/Evaluate/expression.h
@@ -21,11 +21,11 @@
 #include "formatting.h"
 #include "type.h"
 #include "variable.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
-#include "flang/Common/template.h"
 #include "flang/Parser/char-block.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
+#include "flang/Support/template.h"
 #include <algorithm>
 #include <list>
 #include <tuple>
diff --git a/flang/include/flang/Evaluate/formatting.h b/flang/include/flang/Evaluate/formatting.h
index aa82f56107fdd3..ae9351139b1933 100644
--- a/flang/include/flang/Evaluate/formatting.h
+++ b/flang/include/flang/Evaluate/formatting.h
@@ -19,7 +19,7 @@
 // This header is meant to be included by the headers that define the several
 // representational class templates that need it, not by external clients.
 
-#include "flang/Common/indirection.h"
+#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <optional>
 #include <type_traits>
diff --git a/flang/include/flang/Evaluate/intrinsics.h b/flang/include/flang/Evaluate/intrinsics.h
index 15afb772ae767b..dbe1ba7fe7ec1b 100644
--- a/flang/include/flang/Evaluate/intrinsics.h
+++ b/flang/include/flang/Evaluate/intrinsics.h
@@ -12,9 +12,9 @@
 #include "call.h"
 #include "characteristics.h"
 #include "type.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Parser/message.h"
+#include "flang/Support/default-kinds.h"
 #include <memory>
 #include <optional>
 #include <string>
diff --git a/flang/include/flang/Evaluate/shape.h b/flang/include/flang/Evaluate/shape.h
index 3e42ec691158bc..18dca71379e0da 100644
--- a/flang/include/flang/Evaluate/shape.h
+++ b/flang/include/flang/Evaluate/shape.h
@@ -15,8 +15,8 @@
 #include "expression.h"
 #include "traverse.h"
 #include "variable.h"
-#include "flang/Common/indirection.h"
 #include "flang/Evaluate/type.h"
+#include "flang/Support/indirection.h"
 #include <optional>
 #include <variant>
 
diff --git a/flang/include/flang/Evaluate/target.h b/flang/include/flang/Evaluate/target.h
index e07f916b875e06..f4595dfe4e4333 100644
--- a/flang/include/flang/Evaluate/target.h
+++ b/flang/include/flang/Evaluate/target.h
@@ -12,11 +12,11 @@
 #ifndef FORTRAN_EVALUATE_TARGET_H_
 #define FORTRAN_EVALUATE_TARGET_H_
 
-#include "flang/Common/Fortran.h"
 #include "flang/Common/enum-class.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/target-rounding.h"
 #include "flang/Evaluate/common.h"
+#include "flang/Support/Fortran.h"
 #include <cstdint>
 
 namespace Fortran::evaluate {
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index 669efb41b03442..fbe905168d2538 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -11,8 +11,6 @@
 
 #include "traverse.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/template.h"
-#include "flang/Common/unwrap.h"
 #include "flang/Evaluate/constant.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Evaluate/shape.h"
@@ -21,6 +19,8 @@
 #include "flang/Semantics/attr.h"
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/template.h"
+#include "flang/Support/unwrap.h"
 #include <array>
 #include <optional>
 #include <set>
diff --git a/flang/include/flang/Evaluate/traverse.h b/flang/include/flang/Evaluate/traverse.h
index dd38d64bff63f7..58f188a4092493 100644
--- a/flang/include/flang/Evaluate/traverse.h
+++ b/flang/include/flang/Evaluate/traverse.h
@@ -38,9 +38,9 @@
 // expression of an ASSOCIATE (or related) construct entity.
 
 #include "expression.h"
-#include "flang/Common/indirection.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/type.h"
+#include "flang/Support/indirection.h"
 #include <set>
 #include <type_traits>
 
diff --git a/flang/include/flang/Evaluate/type.h b/flang/include/flang/Evaluate/type.h
index 1f9296ac4fea75..ab7e4723152d7e 100644
--- a/flang/include/flang/Evaluate/type.h
+++ b/flang/include/flang/Evaluate/type.h
@@ -22,11 +22,11 @@
 #include "integer.h"
 #include "logical.h"
 #include "real.h"
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
 #include "flang/Common/real.h"
-#include "flang/Common/template.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/template.h"
 #include <cinttypes>
 #include <optional>
 #include <string>
diff --git a/flang/include/flang/Evaluate/variable.h b/flang/include/flang/Evaluate/variable.h
index 9b597d29813da1..bb4150613c81dd 100644
--- a/flang/include/flang/Evaluate/variable.h
+++ b/flang/include/flang/Evaluate/variable.h
@@ -21,9 +21,9 @@
 #include "static-data.h"
 #include "type.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/reference.h"
-#include "flang/Common/template.h"
 #include "flang/Parser/char-block.h"
+#include "flang/Support/reference.h"
+#include "flang/Support/template.h"
 #include <optional>
 #include <variant>
 #include <vector>
diff --git a/flang/include/flang/Frontend/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h
index 7d3f0bdf2e510e..b3b7297f6f7f1f 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -13,7 +13,6 @@
 #ifndef FORTRAN_FRONTEND_COMPILERINVOCATION_H
 #define FORTRAN_FRONTEND_COMPILERINVOCATION_H
 
-#include "flang/Common/LangOptions.h"
 #include "flang/Frontend/CodeGenOptions.h"
 #include "flang/Frontend/FrontendOptions.h"
 #include "flang/Frontend/PreprocessorOptions.h"
@@ -22,6 +21,7 @@
 #include "flang/Parser/parsing.h"
 #include "flang/Semantics/semantics.h"
 #include "mlir/Support/Timing.h"
+#include "flang/Support/LangOptions.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "llvm/Option/ArgList.h"
diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index a4cb021e309d4a..0bd2e621813ca5 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -13,10 +13,10 @@
 #ifndef FORTRAN_FRONTEND_FRONTENDOPTIONS_H
 #define FORTRAN_FRONTEND_FRONTENDOPTIONS_H
 
-#include "flang/Common/Fortran-features.h"
 #include "flang/Lower/EnvironmentDefault.h"
 #include "flang/Parser/characters.h"
 #include "flang/Parser/unparse.h"
+#include "flang/Support/Fortran-features.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include <cstdint>
diff --git a/flang/include/flang/ISO_Fortran_binding.h b/flang/include/flang/ISO_Fortran_binding.h
index 945f8fef89f0b4..f5b8d0d2ea610a 100644
--- a/flang/include/flang/ISO_Fortran_binding.h
+++ b/flang/include/flang/ISO_Fortran_binding.h
@@ -14,7 +14,7 @@
  * it does so by means of a wrapper header that establishes namespaces and
  * a macro for extra function attributes (RT_API_ATTRS).
  */
-#ifndef FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
+#ifndef FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
 #include <stddef.h>
 #define FORTRAN_ISO_NAMESPACE_
 #endif
diff --git a/flang/include/flang/Lower/AbstractConverter.h b/flang/include/flang/Lower/AbstractConverter.h
index c24f43737df50a..3d2b805da6f477 100644
--- a/flang/include/flang/Lower/AbstractConverter.h
+++ b/flang/include/flang/Lower/AbstractConverter.h
@@ -13,12 +13,12 @@
 #ifndef FORTRAN_LOWER_ABSTRACTCONVERTER_H
 #define FORTRAN_LOWER_ABSTRACTCONVERTER_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Lower/LoweringOptions.h"
 #include "flang/Lower/PFTDefs.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Dialect/FIRAttr.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/Operation.h"
diff --git a/flang/include/flang/Lower/Bridge.h b/flang/include/flang/Lower/Bridge.h
index 6404a16f7785ae..a8c2bcfda31c1f 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -13,7 +13,6 @@
 #ifndef FORTRAN_LOWER_BRIDGE_H
 #define FORTRAN_LOWER_BRIDGE_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Frontend/CodeGenOptions.h"
 #include "flang/Frontend/TargetOptions.h"
 #include "flang/Lower/AbstractConverter.h"
@@ -22,6 +21,7 @@
 #include "flang/Lower/StatementContext.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/OwningOpRef.h"
 #include <set>
diff --git a/flang/include/flang/Lower/CallInterface.h b/flang/include/flang/Lower/CallInterface.h
index 72bc9dd890a94b..c15edf62df388e 100644
--- a/flang/include/flang/Lower/CallInterface.h
+++ b/flang/include/flang/Lower/CallInterface.h
@@ -27,8 +27,8 @@
 #ifndef FORTRAN_LOWER_CALLINTERFACE_H
 #define FORTRAN_LOWER_CALLINTERFACE_H
 
-#include "flang/Common/reference.h"
 #include "flang/Evaluate/characteristics.h"
+#include "flang/Support/reference.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/IR/BuiltinOps.h"
 #include <memory>
diff --git a/flang/include/flang/Lower/ConvertType.h b/flang/include/flang/Lower/ConvertType.h
index 7a3f92649a4e4a..179a6825840464 100644
--- a/flang/include/flang/Lower/ConvertType.h
+++ b/flang/include/flang/Lower/ConvertType.h
@@ -21,8 +21,8 @@
 #ifndef FORTRAN_LOWER_CONVERT_TYPE_H
 #define FORTRAN_LOWER_CONVERT_TYPE_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Evaluate/type.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinTypes.h"
 
 namespace mlir {
diff --git a/flang/include/flang/Lower/LoweringOptions.h b/flang/include/flang/Lower/LoweringOptions.h
index 8105ccd7ef6b15..171510393b8168 100644
--- a/flang/include/flang/Lower/LoweringOptions.h
+++ b/flang/include/flang/Lower/LoweringOptions.h
@@ -15,7 +15,7 @@
 #ifndef FLANG_LOWER_LOWERINGOPTIONS_H
 #define FLANG_LOWER_LOWERINGOPTIONS_H
 
-#include "flang/Common/MathOptionsBase.h"
+#include "flang/Support/MathOptionsBase.h"
 
 namespace Fortran::lower {
 
diff --git a/flang/include/flang/Lower/PFTBuilder.h b/flang/include/flang/Lower/PFTBuilder.h
index 42d6546b77553b..05da17faf2dd7d 100644
--- a/flang/include/flang/Lower/PFTBuilder.h
+++ b/flang/include/flang/Lower/PFTBuilder.h
@@ -17,8 +17,6 @@
 #ifndef FORTRAN_LOWER_PFTBUILDER_H
 #define FORTRAN_LOWER_PFTBUILDER_H
 
-#include "flang/Common/reference.h"
-#include "flang/Common/template.h"
 #include "flang/Lower/HostAssociations.h"
 #include "flang/Lower/PFTDefs.h"
 #include "flang/Parser/parse-tree.h"
@@ -26,6 +24,8 @@
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/reference.h"
+#include "flang/Support/template.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
diff --git a/flang/include/flang/Lower/Support/Utils.h b/flang/include/flang/Lower/Support/Utils.h
index 1cc74521e22d88..08a872b228691d 100644
--- a/flang/include/flang/Lower/Support/Utils.h
+++ b/flang/include/flang/Lower/Support/Utils.h
@@ -13,9 +13,9 @@
 #ifndef FORTRAN_LOWER_SUPPORT_UTILS_H
 #define FORTRAN_LOWER_SUPPORT_UTILS_H
 
-#include "flang/Common/indirection.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/indirection.h"
 #include "mlir/Dialect/Arith/IR/Arith.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/IR/BuiltinAttributes.h"
diff --git a/flang/include/flang/Lower/SymbolMap.h b/flang/include/flang/Lower/SymbolMap.h
index c03f9afd40801c..fb64db407708ad 100644
--- a/flang/include/flang/Lower/SymbolMap.h
+++ b/flang/include/flang/Lower/SymbolMap.h
@@ -13,12 +13,12 @@
 #ifndef FORTRAN_LOWER_SYMBOLMAP_H
 #define FORTRAN_LOWER_SYMBOLMAP_H
 
-#include "flang/Common/reference.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Dialect/FortranVariableInterface.h"
 #include "flang/Optimizer/Support/Matcher.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/reference.h"
 #include "mlir/IR/Value.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index ea658fb16a36c3..805667bfe502b1 100644
--- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
@@ -16,12 +16,12 @@
 #ifndef FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
 #define FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
 
-#include "flang/Common/MathOptionsBase.h"
 #include "flang/Optimizer/Dialect/FIROps.h"
 #include "flang/Optimizer/Dialect/FIROpsSupport.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Dialect/Support/FIRContext.h"
 #include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Support/MathOptionsBase.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "llvm/ADT/DenseMap.h"
diff --git a/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
index 5ae32f70a11a7f..8374b18b8a17d8 100644
--- a/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
@@ -9,8 +9,8 @@
 #ifndef FORTRAN_LOWER_PPCINTRINSICCALL_H
 #define FORTRAN_LOWER_PPCINTRINSICCALL_H
 
-#include "flang/Common/static-multimap-view.h"
 #include "flang/Optimizer/Builder/IntrinsicCall.h"
+#include "flang/Support/static-multimap-view.h"
 #include "mlir/Dialect/Math/IR/Math.h"
 
 namespace fir {
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index eaa1de76154d93..be07e8d2a9390a 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -17,12 +17,12 @@
 #ifndef FORTRAN_OPTIMIZER_BUILDER_RUNTIME_RTBUILDER_H
 #define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_RTBUILDER_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Common/uint128.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Dialect/FIRDialect.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Runtime/reduce.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinTypes.h"
 #include "mlir/IR/MLIRContext.h"
 #include "llvm/ADT/SmallVector.h"
diff --git a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
index 9cccf8db87270e..b9a8a670d07938 100644
--- a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
+++ b/flang/include/flang/Optimizer/...
[truncated]

Copy link
Contributor

@jhuber6 jhuber6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really straightforward. I don't think we need to bikeshed about which side requires utilities for now, we can easily amend that once we move over to the separate runtimes build.

Copy link

github-actions bot commented Jan 27, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@jeanPerier
Copy link
Contributor

Following up on PR122069 comments, We are OK going in your direction if that make things easier for you on the condition that the container like headers remain together to make the life of the developers easier (these are header only tools that could be use in the runtime too with small adjustments if needed, and having them separated from the other similar header makes them harder to find).

That is, please keep the following headers in Common even though they are not used in the runtime currently:

indirection.h
interval.h
reference-counted.h
reference.h
static-multimap-view.h
template.h
unwrap.h

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep STL like headers together (see comment above).

Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concur with Jean on keeping utility headers "shared". Otherwise it looks good to me with minor remarks inlined.

@Meinersbur
Copy link
Member Author

Moved files mentioned by @jeanPerier to FortranCommon

@Meinersbur Meinersbur requested a review from jeanPerier January 30, 2025 17:50
@Meinersbur
Copy link
Member Author

@jeanPerier If you are satisfied with the change, please adjust the "Requested changes" status.

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@Meinersbur Meinersbur merged commit b815a39 into main Feb 6, 2025
8 checks passed
@Meinersbur Meinersbur deleted the users/meinersbur/flang_runtime_FortranSupport branch February 6, 2025 14:29
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
Move non-common files from FortranCommon to FortranSupport (analogous to
LLVMSupport) such that

* declarations and definitions that are only used by the Flang compiler,
but not by the runtime, are moved to FortranSupport

* declarations and definitions that are used by both ("common"), the
compiler and the runtime, remain in FortranCommon

* generic STL-like/ADT/utility classes and algorithms remain in
FortranCommon

This allows a for cleaner separation between compiler and runtime
components, which are compiled differently. For instance, runtime
sources must not use STL's `<optional>` which causes problems with CUDA
support. Instead, the surrogate header `flang/Common/optional.h` must be
used. This PR fixes this for `fast-int-sel.h`.

Declarations in include/Runtime are also used by both, but are
header-only. `ISO_Fortran_binding_wrapper.h`, a header used by compiler
and runtime, is also moved into FortranCommon.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants