[flang-commits] [clang] [flang] [lld] [Flang] Rename libFortranRuntime.a to libflang_rt.runtime.a (PR #122341)

Michael Kruse via flang-commits flang-commits at lists.llvm.org
Sat Feb 8 08:25:16 PST 2025


https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/122341

>From 72e3c5dedb2f76ae0500befe5963d032bc9c48c8 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 24 Jan 2025 16:24:02 +0100
Subject: [PATCH 01/18] [Flang] Introduce FortranSupport

---
 .../ISO_Fortran_binding_wrapper.h             | 15 +++---
 flang/include/flang/Common/fast-int-set.h     |  6 +--
 flang/include/flang/Evaluate/call.h           |  6 +--
 .../include/flang/Evaluate/characteristics.h  |  6 +--
 flang/include/flang/Evaluate/common.h         |  8 +--
 flang/include/flang/Evaluate/constant.h       |  4 +-
 flang/include/flang/Evaluate/expression.h     |  6 +--
 flang/include/flang/Evaluate/formatting.h     |  2 +-
 flang/include/flang/Evaluate/intrinsics.h     |  2 +-
 flang/include/flang/Evaluate/shape.h          |  2 +-
 flang/include/flang/Evaluate/target.h         |  2 +-
 flang/include/flang/Evaluate/tools.h          |  4 +-
 flang/include/flang/Evaluate/traverse.h       |  2 +-
 flang/include/flang/Evaluate/type.h           |  6 +--
 flang/include/flang/Evaluate/variable.h       |  4 +-
 .../flang/Frontend/CompilerInvocation.h       |  2 +-
 .../include/flang/Frontend/FrontendOptions.h  |  2 +-
 flang/include/flang/ISO_Fortran_binding.h     |  2 +-
 flang/include/flang/Lower/AbstractConverter.h |  2 +-
 flang/include/flang/Lower/Bridge.h            |  2 +-
 flang/include/flang/Lower/CallInterface.h     |  2 +-
 flang/include/flang/Lower/ConvertType.h       |  2 +-
 flang/include/flang/Lower/LoweringOptions.h   |  2 +-
 flang/include/flang/Lower/PFTBuilder.h        |  4 +-
 flang/include/flang/Lower/Support/Utils.h     |  2 +-
 flang/include/flang/Lower/SymbolMap.h         |  2 +-
 .../flang/Optimizer/Builder/FIRBuilder.h      |  2 +-
 .../Optimizer/Builder/PPCIntrinsicCall.h      |  2 +-
 .../Optimizer/Builder/Runtime/RTBuilder.h     |  2 +-
 .../flang/Optimizer/CodeGen/DescriptorModel.h |  2 +-
 .../Dialect/CUF/Attributes/CUFAttr.h          |  2 +-
 .../flang/Optimizer/Support/TypeCode.h        |  2 +-
 flang/include/flang/Optimizer/Support/Utils.h |  2 +-
 flang/include/flang/Parser/char-block.h       |  2 +-
 flang/include/flang/Parser/dump-parse-tree.h  |  4 +-
 flang/include/flang/Parser/message.h          |  4 +-
 flang/include/flang/Parser/parse-state.h      |  2 +-
 flang/include/flang/Parser/parse-tree.h       |  4 +-
 flang/include/flang/Parser/parsing.h          |  2 +-
 flang/include/flang/Parser/provenance.h       |  2 +-
 flang/include/flang/Parser/source.h           |  2 +-
 flang/include/flang/Parser/user-state.h       |  2 +-
 .../include/flang/Runtime/descriptor-consts.h |  2 +-
 flang/include/flang/Runtime/descriptor.h      |  2 +-
 flang/include/flang/Runtime/random.h          |  5 ++
 flang/include/flang/Runtime/support.h         |  2 +-
 flang/include/flang/Runtime/type-code.h       |  2 +-
 flang/include/flang/Semantics/expression.h    |  4 +-
 .../flang/Semantics/runtime-type-info.h       |  2 +-
 flang/include/flang/Semantics/scope.h         |  4 +-
 flang/include/flang/Semantics/semantics.h     |  4 +-
 flang/include/flang/Semantics/symbol.h        |  4 +-
 flang/include/flang/Semantics/tools.h         |  2 +-
 flang/include/flang/Semantics/type.h          |  2 +-
 .../{Common => Support}/Fortran-features.h    | 10 ++--
 .../flang/{Common => Support}/Fortran.h       | 12 ++---
 .../flang/{Common => Support}/LangOptions.def |  0
 .../flang/{Common => Support}/LangOptions.h   | 14 ++---
 .../{Common => Support}/MathOptionsBase.def   |  0
 .../{Common => Support}/MathOptionsBase.h     | 14 ++---
 .../{Common => Support}/OpenMP-features.h     |  8 +--
 flang/include/flang/Support/Timing.h          |  8 +--
 .../flang/{Common => Support}/Version.h       |  8 +--
 .../flang/{Common => Support}/default-kinds.h | 10 ++--
 .../flang/{Common => Support}/indirection.h   | 10 ++--
 .../flang/{Common => Support}/interval.h      | 10 ++--
 .../{Common => Support}/reference-counted.h   |  8 +--
 .../flang/{Common => Support}/reference.h     |  8 +--
 .../static-multimap-view.h                    |  8 +--
 .../flang/{Common => Support}/template.h      | 10 ++--
 .../flang/{Common => Support}/unwrap.h        | 12 ++---
 flang/include/flang/Tools/CrossToolHelpers.h  |  4 +-
 flang/lib/CMakeLists.txt                      |  1 -
 flang/lib/Common/CMakeLists.txt               | 52 ------------------
 flang/lib/Evaluate/CMakeLists.txt             |  2 +-
 flang/lib/Evaluate/call.cpp                   |  2 +-
 flang/lib/Evaluate/characteristics.cpp        |  2 +-
 flang/lib/Evaluate/fold-implementation.h      |  6 +--
 flang/lib/Evaluate/formatting.cpp             |  2 +-
 flang/lib/Evaluate/intrinsics-library.cpp     |  2 +-
 flang/lib/Evaluate/intrinsics.cpp             |  2 +-
 flang/lib/Evaluate/shape.cpp                  |  2 +-
 flang/lib/Evaluate/target.cpp                 |  2 +-
 flang/lib/Frontend/CMakeLists.txt             |  2 +-
 flang/lib/Frontend/CompilerInstance.cpp       |  2 +-
 flang/lib/Frontend/CompilerInvocation.cpp     |  6 +--
 flang/lib/Frontend/FrontendActions.cpp        |  2 +-
 flang/lib/Lower/Bridge.cpp                    |  2 +-
 flang/lib/Lower/CMakeLists.txt                |  2 +-
 flang/lib/Lower/CallInterface.cpp             |  2 +-
 flang/lib/Lower/ConvertExpr.cpp               |  4 +-
 flang/lib/Lower/Mangler.cpp                   |  2 +-
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp |  2 +-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  2 +-
 flang/lib/Optimizer/Dialect/FIRType.cpp       |  2 +-
 flang/lib/Optimizer/OpenMP/CMakeLists.txt     |  2 +-
 flang/lib/Optimizer/Passes/CMakeLists.txt     |  5 +-
 .../lib/Optimizer/Transforms/AddDebugInfo.cpp |  2 +-
 .../Transforms/AssumedRankOpConversion.cpp    |  2 +-
 flang/lib/Optimizer/Transforms/CMakeLists.txt |  2 +-
 .../Optimizer/Transforms/CUFDeviceGlobal.cpp  |  2 +-
 .../Transforms/CUFGPUToLLVMConversion.cpp     |  2 +-
 .../Optimizer/Transforms/CUFOpConversion.cpp  |  2 +-
 .../Transforms/ExternalNameConversion.cpp     |  2 +-
 .../Optimizer/Transforms/LoopVersioning.cpp   |  2 +-
 .../Transforms/SimplifyIntrinsics.cpp         |  2 +-
 .../lib/Optimizer/Transforms/StackReclaim.cpp |  2 +-
 flang/lib/Optimizer/Transforms/VScaleAttr.cpp |  2 +-
 flang/lib/Parser/CMakeLists.txt               |  2 +-
 flang/lib/Parser/basic-parsers.h              |  4 +-
 flang/lib/Parser/parse-tree.cpp               |  2 +-
 flang/lib/Parser/prescan.h                    |  2 +-
 flang/lib/Parser/unparse.cpp                  |  4 +-
 flang/lib/Semantics/CMakeLists.txt            |  2 +-
 flang/lib/Semantics/assignment.h              |  2 +-
 flang/lib/Semantics/check-case.cpp            |  4 +-
 flang/lib/Semantics/check-coarray.cpp         |  2 +-
 flang/lib/Semantics/check-cuda.cpp            |  2 +-
 flang/lib/Semantics/check-data.h              |  2 +-
 flang/lib/Semantics/check-do-forall.cpp       |  2 +-
 flang/lib/Semantics/check-return.cpp          |  2 +-
 flang/lib/Semantics/check-select-rank.cpp     |  2 +-
 flang/lib/Semantics/check-select-type.cpp     |  2 +-
 flang/lib/Semantics/check-stop.cpp            |  2 +-
 flang/lib/Semantics/data-to-inits.h           |  4 +-
 flang/lib/Semantics/expression.cpp            |  2 +-
 flang/lib/Semantics/pointer-assignment.cpp    |  2 +-
 flang/lib/Semantics/resolve-labels.cpp        |  2 +-
 flang/lib/Semantics/resolve-names-utils.cpp   |  6 +--
 flang/lib/Semantics/resolve-names.cpp         |  6 +--
 flang/lib/Semantics/rewrite-parse-tree.cpp    |  2 +-
 flang/lib/Semantics/semantics.cpp             |  2 +-
 flang/lib/Semantics/tools.cpp                 |  4 +-
 flang/lib/Support/CMakeLists.txt              | 53 +++++++++++++++++++
 .../{Common => Support}/Fortran-features.cpp  |  6 +--
 flang/lib/{Common => Support}/Fortran.cpp     |  6 +--
 flang/lib/{Common => Support}/LangOptions.cpp |  6 +--
 .../lib/{Common => Support}/OpenMP-utils.cpp  |  2 +-
 flang/lib/Support/Timing.cpp                  |  2 +-
 flang/lib/{Common => Support}/Version.cpp     |  4 +-
 .../lib/{Common => Support}/default-kinds.cpp |  4 +-
 flang/lib/{Common => Support}/idioms.cpp      |  2 +-
 flang/runtime/CUDA/allocator.cpp              |  4 +-
 flang/runtime/ISO_Fortran_binding.cpp         |  2 +-
 flang/runtime/ISO_Fortran_util.h              |  2 +-
 flang/runtime/allocatable.cpp                 |  2 +-
 flang/runtime/stat.h                          |  2 +-
 flang/runtime/temporary-stack.cpp             |  2 +-
 flang/tools/bbc/CMakeLists.txt                |  2 +-
 flang/tools/bbc/bbc.cpp                       | 10 ++--
 flang/tools/f18-parse-demo/CMakeLists.txt     |  2 +-
 flang/tools/f18-parse-demo/f18-parse-demo.cpp |  4 +-
 flang/tools/tco/CMakeLists.txt                |  2 +-
 flang/unittests/Evaluate/CMakeLists.txt       |  6 +--
 .../Evaluate/ISO-Fortran-binding.cpp          |  2 +-
 flang/unittests/Frontend/CMakeLists.txt       |  2 +-
 flang/unittests/Runtime/CUDA/Allocatable.cpp  |  2 +-
 flang/unittests/Runtime/CUDA/AllocatorCUF.cpp |  2 +-
 flang/unittests/Runtime/CUDA/Memory.cpp       |  2 +-
 flang/unittests/Runtime/TemporaryStack.cpp    |  2 +-
 160 files changed, 333 insertions(+), 332 deletions(-)
 rename flang/include/flang/{ => Common}/ISO_Fortran_binding_wrapper.h (70%)
 rename flang/include/flang/{Common => Support}/Fortran-features.h (96%)
 rename flang/include/flang/{Common => Support}/Fortran.h (94%)
 rename flang/include/flang/{Common => Support}/LangOptions.def (100%)
 rename flang/include/flang/{Common => Support}/LangOptions.h (87%)
 rename flang/include/flang/{Common => Support}/MathOptionsBase.def (100%)
 rename flang/include/flang/{Common => Support}/MathOptionsBase.h (77%)
 rename flang/include/flang/{Common => Support}/OpenMP-features.h (85%)
 rename flang/include/flang/{Common => Support}/Version.h (90%)
 rename flang/include/flang/{Common => Support}/default-kinds.h (91%)
 rename flang/include/flang/{Common => Support}/indirection.h (95%)
 rename flang/include/flang/{Common => Support}/interval.h (94%)
 rename flang/include/flang/{Common => Support}/reference-counted.h (90%)
 rename flang/include/flang/{Common => Support}/reference.h (91%)
 rename flang/include/flang/{Common => Support}/static-multimap-view.h (91%)
 rename flang/include/flang/{Common => Support}/template.h (98%)
 rename flang/include/flang/{Common => Support}/unwrap.h (94%)
 delete mode 100644 flang/lib/Common/CMakeLists.txt
 rename flang/lib/{Common => Support}/Fortran-features.cpp (97%)
 rename flang/lib/{Common => Support}/Fortran.cpp (96%)
 rename flang/lib/{Common => Support}/LangOptions.cpp (80%)
 rename flang/lib/{Common => Support}/OpenMP-utils.cpp (95%)
 rename flang/lib/{Common => Support}/Version.cpp (95%)
 rename flang/lib/{Common => Support}/default-kinds.cpp (94%)
 rename flang/lib/{Common => Support}/idioms.cpp (89%)

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 37289bdbabd03c5..7a8a8a9787bd036 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 d1c9c756a44a652..1214bac75a4bf16 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 63277438128ebb3..4d8ca28cf329a12 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 357fc3e5952436b..ccd584b5ee6aa4f 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 915e95169c7f816..91d38748f5a5753 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 61a814446bbfd3d..63e8ed4119cdf52 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 04f4406fc8a2c09..ec71550d2a50c9d 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 aa82f56107fdd37..ae9351139b19330 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 15afb772ae767b8..dbe1ba7fe7ec1b8 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 3e42ec691158bcf..18dca71379e0dac 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 e07f916b875e06b..f4595dfe4e4333a 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 669efb41b034423..fbe905168d25386 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 dd38d64bff63f70..58f188a40924930 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 1f9296ac4fea75d..ab7e4723152d7e5 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 9b597d29813da12..bb4150613c81dd4 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 7d3f0bdf2e510e2..b3b7297f6f7f1f4 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 a4cb021e309d4a4..0bd2e621813ca54 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 945f8fef89f0b43..f5b8d0d2ea610a7 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 c24f43737df50aa..3d2b805da6f477f 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 6404a16f7785ae9..a8c2bcfda31c1fa 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 72bc9dd890a94b0..c15edf62df388eb 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 7a3f92649a4e4af..179a6825840464e 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 8105ccd7ef6b15d..171510393b81683 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 42d6546b77553bc..05da17faf2dd7d6 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 1cc74521e22d888..08a872b228691d0 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 c03f9afd40801cd..fb64db407708ade 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 ea658fb16a36c3a..805667bfe502b1d 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 5ae32f70a11a7f3..8374b18b8a17d82 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 eaa1de76154d933..be07e8d2a9390a7 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 9cccf8db87270ec..b9a8a670d07938f 100644
--- a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
+++ b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
@@ -22,7 +22,7 @@
 #ifndef OPTIMIZER_DESCRIPTOR_MODEL_H
 #define OPTIMIZER_DESCRIPTOR_MODEL_H
 
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/descriptor-consts.h"
 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
 #include "mlir/IR/BuiltinTypes.h"
diff --git a/flang/include/flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h b/flang/include/flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h
index f32e39b543e3f74..85615a4d69157d2 100644
--- a/flang/include/flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h
+++ b/flang/include/flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h
@@ -13,7 +13,7 @@
 #ifndef FORTRAN_OPTIMIZER_DIALECT_CUF_CUFATTR_H
 #define FORTRAN_OPTIMIZER_DIALECT_CUF_CUFATTR_H
 
-#include "flang/Common/Fortran.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinAttributes.h"
 
 namespace llvm {
diff --git a/flang/include/flang/Optimizer/Support/TypeCode.h b/flang/include/flang/Optimizer/Support/TypeCode.h
index 308c82118d50209..ec21d672287e62a 100644
--- a/flang/include/flang/Optimizer/Support/TypeCode.h
+++ b/flang/include/flang/Optimizer/Support/TypeCode.h
@@ -13,7 +13,7 @@
 #ifndef FORTRAN_OPTIMIZER_SUPPORT_TYPECODE_H
 #define FORTRAN_OPTIMIZER_SUPPORT_TYPECODE_H
 
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "llvm/Support/ErrorHandling.h"
 
 namespace fir {
diff --git a/flang/include/flang/Optimizer/Support/Utils.h b/flang/include/flang/Optimizer/Support/Utils.h
index d507f4116efb701..ec73af6ec72e90f 100644
--- a/flang/include/flang/Optimizer/Support/Utils.h
+++ b/flang/include/flang/Optimizer/Support/Utils.h
@@ -13,13 +13,13 @@
 #ifndef FORTRAN_OPTIMIZER_SUPPORT_UTILS_H
 #define FORTRAN_OPTIMIZER_SUPPORT_UTILS_H
 
-#include "flang/Common/default-kinds.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Builder/Todo.h"
 #include "flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h"
 #include "flang/Optimizer/Dialect/FIROps.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Support/FatalError.h"
+#include "flang/Support/default-kinds.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/Parser/char-block.h b/flang/include/flang/Parser/char-block.h
index 38f4f7b82e1eae3..4541b31e566f95b 100644
--- a/flang/include/flang/Parser/char-block.h
+++ b/flang/include/flang/Parser/char-block.h
@@ -11,7 +11,7 @@
 
 // Describes a contiguous block of characters; does not own their storage.
 
-#include "flang/Common/interval.h"
+#include "flang/Support/interval.h"
 #include <algorithm>
 #include <cstddef>
 #include <cstring>
diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index 11725991e9c9a96..13e367e725a54e5 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -14,9 +14,9 @@
 #include "parse-tree.h"
 #include "tools.h"
 #include "unparse.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <string>
 #include <type_traits>
diff --git a/flang/include/flang/Parser/message.h b/flang/include/flang/Parser/message.h
index bc38f571ca3df42..bfbc985b8b91aae 100644
--- a/flang/include/flang/Parser/message.h
+++ b/flang/include/flang/Parser/message.h
@@ -15,10 +15,10 @@
 #include "char-block.h"
 #include "char-set.h"
 #include "provenance.h"
-#include "flang/Common/Fortran-features.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/reference-counted.h"
 #include "flang/Common/restorer.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/reference-counted.h"
 #include <cstddef>
 #include <cstring>
 #include <forward_list>
diff --git a/flang/include/flang/Parser/parse-state.h b/flang/include/flang/Parser/parse-state.h
index 76cbb3470dc08d6..36d70b81b792363 100644
--- a/flang/include/flang/Parser/parse-state.h
+++ b/flang/include/flang/Parser/parse-state.h
@@ -16,11 +16,11 @@
 // and recovery during parsing!
 
 #include "user-state.h"
-#include "flang/Common/Fortran-features.h"
 #include "flang/Common/idioms.h"
 #include "flang/Parser/characters.h"
 #include "flang/Parser/message.h"
 #include "flang/Parser/provenance.h"
+#include "flang/Support/Fortran-features.h"
 #include <cstddef>
 #include <cstring>
 #include <list>
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index 00d85aa05fb3a52..217328b79284414 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -22,9 +22,9 @@
 #include "format-specification.h"
 #include "message.h"
 #include "provenance.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
 #include "llvm/Frontend/OpenACC/ACC.h.inc"
 #include "llvm/Frontend/OpenMP/OMP.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
diff --git a/flang/include/flang/Parser/parsing.h b/flang/include/flang/Parser/parsing.h
index 0c774decb16d313..116b6bd6f191f59 100644
--- a/flang/include/flang/Parser/parsing.h
+++ b/flang/include/flang/Parser/parsing.h
@@ -14,8 +14,8 @@
 #include "message.h"
 #include "parse-tree.h"
 #include "provenance.h"
-#include "flang/Common/Fortran-features.h"
 #include "flang/Parser/preprocessor.h"
+#include "flang/Support/Fortran-features.h"
 #include "llvm/Support/raw_ostream.h"
 #include <optional>
 #include <string>
diff --git a/flang/include/flang/Parser/provenance.h b/flang/include/flang/Parser/provenance.h
index a9224b727fd0548..7f29fb272c94214 100644
--- a/flang/include/flang/Parser/provenance.h
+++ b/flang/include/flang/Parser/provenance.h
@@ -14,7 +14,7 @@
 #include "characters.h"
 #include "source.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/interval.h"
+#include "flang/Support/interval.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstddef>
 #include <list>
diff --git a/flang/include/flang/Parser/source.h b/flang/include/flang/Parser/source.h
index a6efdf9546c7f31..a67fd66045a3de9 100644
--- a/flang/include/flang/Parser/source.h
+++ b/flang/include/flang/Parser/source.h
@@ -15,7 +15,7 @@
 //  - A Unicode byte order mark is recognized if present.
 
 #include "characters.h"
-#include "flang/Common/reference.h"
+#include "flang/Support/reference.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstddef>
diff --git a/flang/include/flang/Parser/user-state.h b/flang/include/flang/Parser/user-state.h
index 61745a833c715c8..129f9fb8fee058b 100644
--- a/flang/include/flang/Parser/user-state.h
+++ b/flang/include/flang/Parser/user-state.h
@@ -14,10 +14,10 @@
 // parse tree construction so as to avoid any need for representing
 // state in static data.
 
-#include "flang/Common/Fortran-features.h"
 #include "flang/Common/idioms.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Parser/parse-tree.h"
+#include "flang/Support/Fortran-features.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cinttypes>
 #include <optional>
diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h
index 3b2537579d58645..abcdbc4a12002ca 100644
--- a/flang/include/flang/Runtime/descriptor-consts.h
+++ b/flang/include/flang/Runtime/descriptor-consts.h
@@ -9,8 +9,8 @@
 #ifndef FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_
 #define FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_
 
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Common/api-attrs.h"
-#include "flang/ISO_Fortran_binding_wrapper.h"
 #include <cstddef>
 #include <cstdint>
 
diff --git a/flang/include/flang/Runtime/descriptor.h b/flang/include/flang/Runtime/descriptor.h
index dd36fba157ca92b..628ac8c927a51e6 100644
--- a/flang/include/flang/Runtime/descriptor.h
+++ b/flang/include/flang/Runtime/descriptor.h
@@ -18,7 +18,7 @@
 // User C code is welcome to depend on that ISO_Fortran_binding.h file,
 // but should never reference this internal header.
 
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/memory.h"
 #include "flang/Runtime/type-code.h"
diff --git a/flang/include/flang/Runtime/random.h b/flang/include/flang/Runtime/random.h
index 269297dff47dbaf..bb6dcb3873f21d2 100644
--- a/flang/include/flang/Runtime/random.h
+++ b/flang/include/flang/Runtime/random.h
@@ -8,6 +8,9 @@
 
 // Intrinsic subroutines RANDOM_INIT, RANDOM_NUMBER, and RANDOM_SEED.
 
+#ifndef FORTRAN_RUNTIME_RANDOM_H_
+#define FORTRAN_RUNTIME_RANDOM_H_
+
 #include "flang/Runtime/entry-names.h"
 #include <cstdint>
 
@@ -35,3 +38,5 @@ void RTNAME(RandomSeed)(const Descriptor *size, const Descriptor *put,
 
 } // extern "C"
 } // namespace Fortran::runtime
+
+#endif /* FORTRAN_RUNTIME_RANDOM_H_ */
diff --git a/flang/include/flang/Runtime/support.h b/flang/include/flang/Runtime/support.h
index ba9c2598bb0ddd5..4a6d4357e871039 100644
--- a/flang/include/flang/Runtime/support.h
+++ b/flang/include/flang/Runtime/support.h
@@ -10,7 +10,7 @@
 #ifndef FORTRAN_RUNTIME_SUPPORT_H_
 #define FORTRAN_RUNTIME_SUPPORT_H_
 
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/entry-names.h"
 #include <cstddef>
 #include <cstdint>
diff --git a/flang/include/flang/Runtime/type-code.h b/flang/include/flang/Runtime/type-code.h
index dd3a9f2690ee74e..ae854ed2145e468 100644
--- a/flang/include/flang/Runtime/type-code.h
+++ b/flang/include/flang/Runtime/type-code.h
@@ -10,8 +10,8 @@
 #define FORTRAN_RUNTIME_TYPE_CODE_H_
 
 #include "flang/Common/Fortran-consts.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Common/optional.h"
-#include "flang/ISO_Fortran_binding_wrapper.h"
 #include <utility>
 
 namespace Fortran::runtime {
diff --git a/flang/include/flang/Semantics/expression.h b/flang/include/flang/Semantics/expression.h
index bb1674a9f88778f..8ea33902bd21375 100644
--- a/flang/include/flang/Semantics/expression.h
+++ b/flang/include/flang/Semantics/expression.h
@@ -10,8 +10,6 @@
 #define FORTRAN_SEMANTICS_EXPRESSION_H_
 
 #include "semantics.h"
-#include "flang/Common/Fortran.h"
-#include "flang/Common/indirection.h"
 #include "flang/Common/restorer.h"
 #include "flang/Common/visit.h"
 #include "flang/Evaluate/characteristics.h"
@@ -24,6 +22,8 @@
 #include "flang/Parser/parse-tree-visitor.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Parser/tools.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
 #include <map>
 #include <optional>
 #include <type_traits>
diff --git a/flang/include/flang/Semantics/runtime-type-info.h b/flang/include/flang/Semantics/runtime-type-info.h
index e90d3ae8baf1eba..94c50aab696816e 100644
--- a/flang/include/flang/Semantics/runtime-type-info.h
+++ b/flang/include/flang/Semantics/runtime-type-info.h
@@ -14,8 +14,8 @@
 #ifndef FORTRAN_SEMANTICS_RUNTIME_TYPE_INFO_H_
 #define FORTRAN_SEMANTICS_RUNTIME_TYPE_INFO_H_
 
-#include "flang/Common/reference.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/reference.h"
 #include <map>
 #include <set>
 #include <string>
diff --git a/flang/include/flang/Semantics/scope.h b/flang/include/flang/Semantics/scope.h
index b3b033a5a3ae3c7..b7d115ec2bca4e6 100644
--- a/flang/include/flang/Semantics/scope.h
+++ b/flang/include/flang/Semantics/scope.h
@@ -11,11 +11,11 @@
 
 #include "attr.h"
 #include "symbol.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/reference.h"
 #include "flang/Parser/message.h"
 #include "flang/Parser/provenance.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/reference.h"
 #include <list>
 #include <map>
 #include <optional>
diff --git a/flang/include/flang/Semantics/semantics.h b/flang/include/flang/Semantics/semantics.h
index c981d86fbd94cb0..c03a0bad24a6e9a 100644
--- a/flang/include/flang/Semantics/semantics.h
+++ b/flang/include/flang/Semantics/semantics.h
@@ -13,12 +13,12 @@
 #include "program-tree.h"
 #include "scope.h"
 #include "symbol.h"
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/LangOptions.h"
 #include "flang/Evaluate/common.h"
 #include "flang/Evaluate/intrinsics.h"
 #include "flang/Evaluate/target.h"
 #include "flang/Parser/message.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/LangOptions.h"
 #include <iosfwd>
 #include <set>
 #include <string>
diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h
index bc6abccac1bb85a..dfe323acbd49011 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -10,11 +10,11 @@
 #define FORTRAN_SEMANTICS_SYMBOL_H_
 
 #include "type.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/enum-set.h"
-#include "flang/Common/reference.h"
 #include "flang/Common/visit.h"
 #include "flang/Semantics/module-dependences.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/reference.h"
 #include "llvm/ADT/DenseMapInfo.h"
 
 #include <array>
diff --git a/flang/include/flang/Semantics/tools.h b/flang/include/flang/Semantics/tools.h
index 07103f98ff04129..012223ef9a0989e 100644
--- a/flang/include/flang/Semantics/tools.h
+++ b/flang/include/flang/Semantics/tools.h
@@ -12,7 +12,6 @@
 // Simple predicates and look-up functions that are best defined
 // canonically for use in semantic checking.
 
-#include "flang/Common/Fortran.h"
 #include "flang/Common/visit.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Evaluate/shape.h"
@@ -23,6 +22,7 @@
 #include "flang/Semantics/attr.h"
 #include "flang/Semantics/expression.h"
 #include "flang/Semantics/semantics.h"
+#include "flang/Support/Fortran.h"
 #include <functional>
 
 namespace Fortran::semantics {
diff --git a/flang/include/flang/Semantics/type.h b/flang/include/flang/Semantics/type.h
index 352219150205958..5d96f1e89bf52ce 100644
--- a/flang/include/flang/Semantics/type.h
+++ b/flang/include/flang/Semantics/type.h
@@ -9,10 +9,10 @@
 #ifndef FORTRAN_SEMANTICS_TYPE_H_
 #define FORTRAN_SEMANTICS_TYPE_H_
 
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Parser/char-block.h"
+#include "flang/Support/Fortran.h"
 #include <algorithm>
 #include <iosfwd>
 #include <map>
diff --git a/flang/include/flang/Common/Fortran-features.h b/flang/include/flang/Support/Fortran-features.h
similarity index 96%
rename from flang/include/flang/Common/Fortran-features.h
rename to flang/include/flang/Support/Fortran-features.h
index 44f88009f8f2c2d..690329411dc50d1 100644
--- a/flang/include/flang/Common/Fortran-features.h
+++ b/flang/include/flang/Support/Fortran-features.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/Fortran-features.h -----------------*- C++ -*-===//
+//===-- include/flang/Support/Fortran-features.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.
@@ -6,12 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_FORTRAN_FEATURES_H_
-#define FORTRAN_COMMON_FORTRAN_FEATURES_H_
+#ifndef FORTRAN_SUPPORT_FORTRAN_FEATURES_H_
+#define FORTRAN_SUPPORT_FORTRAN_FEATURES_H_
 
-#include "flang/Common/Fortran.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/idioms.h"
+#include "flang/Support/Fortran.h"
 #include <optional>
 #include <vector>
 
@@ -125,4 +125,4 @@ class LanguageFeatureControl {
   bool warnAllUsage_{false};
 };
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_FORTRAN_FEATURES_H_
+#endif /* FORTRAN_SUPPORT_FORTRAN_FEATURES_H_ */
diff --git a/flang/include/flang/Common/Fortran.h b/flang/include/flang/Support/Fortran.h
similarity index 94%
rename from flang/include/flang/Common/Fortran.h
rename to flang/include/flang/Support/Fortran.h
index e1922f7654bb1ac..4e6bdbb67f5f355 100644
--- a/flang/include/flang/Common/Fortran.h
+++ b/flang/include/flang/Support/Fortran.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/Fortran.h --------------------------*- C++ -*-===//
+//===-- include/flang/Support/Fortran.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.
@@ -6,15 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_FORTRAN_H_
-#define FORTRAN_COMMON_FORTRAN_H_
+#ifndef FORTRAN_SUPPORT_FORTRAN_H_
+#define FORTRAN_SUPPORT_FORTRAN_H_
 
 // Fortran language concepts that are used in many phases are defined
 // once here to avoid redundancy and needless translation.
 
-#include "enum-set.h"
-#include "idioms.h"
 #include "flang/Common/Fortran-consts.h"
+#include "flang/Common/enum-set.h"
+#include "flang/Common/idioms.h"
 #include <cinttypes>
 #include <optional>
 #include <string>
@@ -109,4 +109,4 @@ inline std::string GetExternalAssemblyName(
 }
 
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_FORTRAN_H_
+#endif /* FORTRAN_SUPPORT_FORTRAN_H_ */
diff --git a/flang/include/flang/Common/LangOptions.def b/flang/include/flang/Support/LangOptions.def
similarity index 100%
rename from flang/include/flang/Common/LangOptions.def
rename to flang/include/flang/Support/LangOptions.def
diff --git a/flang/include/flang/Common/LangOptions.h b/flang/include/flang/Support/LangOptions.h
similarity index 87%
rename from flang/include/flang/Common/LangOptions.h
rename to flang/include/flang/Support/LangOptions.h
index 83f25cfbe26142f..3c6094c9a9c87f3 100644
--- a/flang/include/flang/Common/LangOptions.h
+++ b/flang/include/flang/Support/LangOptions.h
@@ -1,4 +1,4 @@
-//===------ LangOptions.h ---------------------------------------*- C++ -*-===//
+//===-- include/flang/Support/LangOptions.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.
@@ -12,8 +12,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_LANGOPTIONS_H
-#define FORTRAN_COMMON_LANGOPTIONS_H
+#ifndef FORTRAN_SUPPORT_LANGOPTIONS_H_
+#define FORTRAN_SUPPORT_LANGOPTIONS_H_
 
 #include <string>
 #include <vector>
@@ -45,12 +45,12 @@ class LangOptionsBase {
 
 #define LANGOPT(Name, Bits, Default) unsigned Name : Bits;
 #define ENUM_LANGOPT(Name, Type, Bits, Default)
-#include "flang/Common/LangOptions.def"
+#include "flang/Support/LangOptions.def"
 
 protected:
 #define LANGOPT(Name, Bits, Default)
 #define ENUM_LANGOPT(Name, Type, Bits, Default) unsigned Name : Bits;
-#include "flang/Common/LangOptions.def"
+#include "flang/Support/LangOptions.def"
 };
 
 /// Tracks various options which control the dialect of Fortran that is
@@ -63,7 +63,7 @@ class LangOptions : public LangOptionsBase {
 #define ENUM_LANGOPT(Name, Type, Bits, Default) \
   Type get##Name() const { return static_cast<Type>(Name); } \
   void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
-#include "flang/Common/LangOptions.def"
+#include "flang/Support/LangOptions.def"
 
   /// Name of the IR file that contains the result of the OpenMP target
   /// host code generation.
@@ -77,4 +77,4 @@ class LangOptions : public LangOptionsBase {
 
 } // end namespace Fortran::common
 
-#endif // FORTRAN_COMMON_LANGOPTIONS_H
+#endif /* FORTRAN_SUPPORT_LANGOPTIONS_H_ */
diff --git a/flang/include/flang/Common/MathOptionsBase.def b/flang/include/flang/Support/MathOptionsBase.def
similarity index 100%
rename from flang/include/flang/Common/MathOptionsBase.def
rename to flang/include/flang/Support/MathOptionsBase.def
diff --git a/flang/include/flang/Common/MathOptionsBase.h b/flang/include/flang/Support/MathOptionsBase.h
similarity index 77%
rename from flang/include/flang/Common/MathOptionsBase.h
rename to flang/include/flang/Support/MathOptionsBase.h
index 7f8ebdbee198784..072aed20da4708e 100644
--- a/flang/include/flang/Common/MathOptionsBase.h
+++ b/flang/include/flang/Support/MathOptionsBase.h
@@ -1,4 +1,4 @@
-//===- MathOptionsBase.h - Math options config ------------------*- C++ -*-===//
+//===-- include/flang/Support/MathOptionsBase.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.
@@ -14,8 +14,8 @@
 ///
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_MATHOPTIONSBASE_H
-#define FORTRAN_COMMON_MATHOPTIONSBASE_H
+#ifndef FORTRAN_SUPPORT_MATHOPTIONSBASE_H_
+#define FORTRAN_SUPPORT_MATHOPTIONSBASE_H_
 
 namespace Fortran::common {
 
@@ -27,18 +27,18 @@ class MathOptionsBase {
     Name = static_cast<unsigned>(Value); \
     return *this; \
   }
-#include "flang/Common/MathOptionsBase.def"
+#include "flang/Support/MathOptionsBase.def"
 
   MathOptionsBase() {
 #define ENUM_MATHOPT(Name, Type, Bits, Default) set##Name(Default);
-#include "flang/Common/MathOptionsBase.def"
+#include "flang/Support/MathOptionsBase.def"
   }
 
 private:
 #define ENUM_MATHOPT(Name, Type, Bits, Default) unsigned Name : Bits;
-#include "flang/Common/MathOptionsBase.def"
+#include "flang/Support/MathOptionsBase.def"
 };
 
 } // namespace Fortran::common
 
-#endif // FORTRAN_COMMON_MATHOPTIONSBASE_H
+#endif /* FORTRAN_SUPPORT_MATHOPTIONSBASE_H_ */
diff --git a/flang/include/flang/Common/OpenMP-features.h b/flang/include/flang/Support/OpenMP-features.h
similarity index 85%
rename from flang/include/flang/Common/OpenMP-features.h
rename to flang/include/flang/Support/OpenMP-features.h
index 480c8b4c1013fe9..85c901e7fdb82fa 100644
--- a/flang/include/flang/Common/OpenMP-features.h
+++ b/flang/include/flang/Support/OpenMP-features.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/OpenMP-features.h -----------------*- C++ -*-====//
+//===-- include/flang/Support/OpenMP-features.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.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_OPENMP_FEATURES_H_
-#define FORTRAN_COMMON_OPENMP_FEATURES_H_
+#ifndef FORTRAN_SUPPORT_OPENMP_FEATURES_H_
+#define FORTRAN_SUPPORT_OPENMP_FEATURES_H_
 
 namespace Fortran::common {
 
@@ -49,4 +49,4 @@ void setOpenMPMacro(int version, FortranPredefinitions &predefinitions) {
   }
 }
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_OPENMP_FEATURES_H_
+#endif /* FORTRAN_SUPPORT_OPENMP_FEATURES_H_ */
diff --git a/flang/include/flang/Support/Timing.h b/flang/include/flang/Support/Timing.h
index 75ba2a8d85f39fe..5d66831d6c1c283 100644
--- a/flang/include/flang/Support/Timing.h
+++ b/flang/include/flang/Support/Timing.h
@@ -1,4 +1,4 @@
-//===- Timing.h - Execution time measurement facilities ---------*- C++ -*-===//
+//===-- include/flang/Support/Timing.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.
@@ -10,8 +10,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_SUPPORT_TIMING_H
-#define FORTRAN_SUPPORT_TIMING_H
+#ifndef FORTRAN_SUPPORT_TIMING_H_
+#define FORTRAN_SUPPORT_TIMING_H_
 
 #include "mlir/Support/Timing.h"
 
@@ -24,4 +24,4 @@ std::unique_ptr<mlir::OutputStrategy> createTimingFormatterText(
 
 } // namespace Fortran::support
 
-#endif // FORTRAN_SUPPORT_TIMING_H
+#endif /* FORTRAN_SUPPORT_TIMING_H_ */
diff --git a/flang/include/flang/Common/Version.h b/flang/include/flang/Support/Version.h
similarity index 90%
rename from flang/include/flang/Common/Version.h
rename to flang/include/flang/Support/Version.h
index 3257d4a4f645939..4ceb19e7f4d714a 100644
--- a/flang/include/flang/Common/Version.h
+++ b/flang/include/flang/Support/Version.h
@@ -1,4 +1,4 @@
-//===- Version.h - Flang Version Number ---------------------*- Fortran -*-===//
+//===-- include/flang/Support/Version.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.
@@ -12,8 +12,8 @@
 ///
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_VERSION_H
-#define FORTRAN_COMMON_VERSION_H
+#ifndef FORTRAN_SUPPORT_VERSION_H_
+#define FORTRAN_SUPPORT_VERSION_H_
 
 #include "flang/Version.inc"
 #include "llvm/ADT/StringRef.h"
@@ -53,4 +53,4 @@ std::string getFlangFullVersion();
 std::string getFlangToolFullVersion(llvm::StringRef ToolName);
 } // namespace Fortran::common
 
-#endif // FORTRAN_COMMON_VERSION_H
+#endif /* FORTRAN_SUPPORT_VERSION_H_ */
diff --git a/flang/include/flang/Common/default-kinds.h b/flang/include/flang/Support/default-kinds.h
similarity index 91%
rename from flang/include/flang/Common/default-kinds.h
rename to flang/include/flang/Support/default-kinds.h
index 6c66b98e98a05b3..92f06e6fe2d272a 100644
--- a/flang/include/flang/Common/default-kinds.h
+++ b/flang/include/flang/Support/default-kinds.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/default-kinds.h --------------------*- C++ -*-===//
+//===-- include/flang/Support/default-kinds.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.
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_DEFAULT_KINDS_H_
-#define FORTRAN_COMMON_DEFAULT_KINDS_H_
+#ifndef FORTRAN_SUPPORT_DEFAULT_KINDS_H_
+#define FORTRAN_SUPPORT_DEFAULT_KINDS_H_
 
-#include "flang/Common/Fortran.h"
+#include "flang/Support/Fortran.h"
 #include <cstdint>
 
 namespace Fortran::common {
@@ -58,4 +58,4 @@ class IntrinsicTypeDefaultKinds {
   int defaultLogicalKind_{defaultIntegerKind_};
 };
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_DEFAULT_KINDS_H_
+#endif /* FORTRAN_SUPPORT_DEFAULT_KINDS_H_ */
diff --git a/flang/include/flang/Common/indirection.h b/flang/include/flang/Support/indirection.h
similarity index 95%
rename from flang/include/flang/Common/indirection.h
rename to flang/include/flang/Support/indirection.h
index 7348eb0473f072c..aeb1698516bae92 100644
--- a/flang/include/flang/Common/indirection.h
+++ b/flang/include/flang/Support/indirection.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/indirection.h ----------------------*- C++ -*-===//
+//===-- include/flang/Support/indirection.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.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_INDIRECTION_H_
-#define FORTRAN_COMMON_INDIRECTION_H_
+#ifndef FORTRAN_SUPPORT_INDIRECTION_H_
+#define FORTRAN_SUPPORT_INDIRECTION_H_
 
 // Define a smart pointer class template that is rather like
 // non-nullable std::unique_ptr<>.  Indirection<> is, like a C++ reference
@@ -20,7 +20,7 @@
 //    template class Fortran::common::Indirection<FORWARD_TYPE>;
 // in one C++ source file later where a definition of the type is visible.
 
-#include "idioms.h"
+#include "flang/Common/idioms.h"
 #include <memory>
 #include <type_traits>
 #include <utility>
@@ -171,4 +171,4 @@ template <typename A> class ForwardOwningPointer {
   void (*deleter_)(A *){nullptr};
 };
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_INDIRECTION_H_
+#endif /* FORTRAN_SUPPORT_INDIRECTION_H_ */
diff --git a/flang/include/flang/Common/interval.h b/flang/include/flang/Support/interval.h
similarity index 94%
rename from flang/include/flang/Common/interval.h
rename to flang/include/flang/Support/interval.h
index c4cab0ccf1130b6..99c0784f006a80b 100644
--- a/flang/include/flang/Common/interval.h
+++ b/flang/include/flang/Support/interval.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/interval.h -------------------------*- C++ -*-===//
+//===-- include/flang/Support/interval.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.
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_INTERVAL_H_
-#define FORTRAN_COMMON_INTERVAL_H_
+#ifndef FORTRAN_SUPPORT_INTERVAL_H_
+#define FORTRAN_SUPPORT_INTERVAL_H_
 
 // Defines a generalized template class Interval<A> to represent
 // the half-open interval [x .. x+n).
 
-#include "idioms.h"
+#include "flang/Common/idioms.h"
 #include <algorithm>
 #include <cstddef>
 #include <utility>
@@ -126,4 +126,4 @@ template <typename A> class Interval {
   std::size_t size_{0};
 };
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_INTERVAL_H_
+#endif /* FORTRAN_SUPPORT_INTERVAL_H_ */
diff --git a/flang/include/flang/Common/reference-counted.h b/flang/include/flang/Support/reference-counted.h
similarity index 90%
rename from flang/include/flang/Common/reference-counted.h
rename to flang/include/flang/Support/reference-counted.h
index de91d4fb6ee8b70..636613d93d80cc0 100644
--- a/flang/include/flang/Common/reference-counted.h
+++ b/flang/include/flang/Support/reference-counted.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/reference-counted.h ----------------*- C++ -*-===//
+//===-- include/flang/Support/reference-counted.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.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_REFERENCE_COUNTED_H_
-#define FORTRAN_COMMON_REFERENCE_COUNTED_H_
+#ifndef FORTRAN_SUPPORT_REFERENCE_COUNTED_H_
+#define FORTRAN_SUPPORT_REFERENCE_COUNTED_H_
 
 // A class template of smart pointers to objects with their own
 // reference counting object lifetimes that's lighter weight
@@ -74,4 +74,4 @@ template <typename A> class CountedReference {
   type *p_{nullptr};
 };
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_REFERENCE_COUNTED_H_
+#endif /* FORTRAN_SUPPORT_REFERENCE_COUNTED_H_ */
diff --git a/flang/include/flang/Common/reference.h b/flang/include/flang/Support/reference.h
similarity index 91%
rename from flang/include/flang/Common/reference.h
rename to flang/include/flang/Support/reference.h
index 0c579de44bd7fa2..c0b0e048ae04a79 100644
--- a/flang/include/flang/Common/reference.h
+++ b/flang/include/flang/Support/reference.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/reference.h ------------------------*- C++ -*-===//
+//===-- include/flang/Support/reference.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.
@@ -11,8 +11,8 @@
 // Use Reference<A> in place of a real A& reference when assignability is
 // required; safer than a bare pointer because it's guaranteed to not be null.
 
-#ifndef FORTRAN_COMMON_REFERENCE_H_
-#define FORTRAN_COMMON_REFERENCE_H_
+#ifndef FORTRAN_SUPPORT_REFERENCE_H_
+#define FORTRAN_SUPPORT_REFERENCE_H_
 #include <type_traits>
 namespace Fortran::common {
 template <typename A> class Reference {
@@ -60,4 +60,4 @@ template <typename A> class Reference {
 };
 template <typename A> Reference(A &) -> Reference<A>;
 } // namespace Fortran::common
-#endif
+#endif /* FORTRAN_SUPPORT_REFERENCE_H_ */
diff --git a/flang/include/flang/Common/static-multimap-view.h b/flang/include/flang/Support/static-multimap-view.h
similarity index 91%
rename from flang/include/flang/Common/static-multimap-view.h
rename to flang/include/flang/Support/static-multimap-view.h
index 27d2ba89c8009cf..8928fab6bfb6f5a 100644
--- a/flang/include/flang/Common/static-multimap-view.h
+++ b/flang/include/flang/Support/static-multimap-view.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/static-multimap-view.h -------------*- C++ -*-===//
+//===-- include/flang/Support/static-multimap-view.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.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_STATIC_MULTIMAP_VIEW_H_
-#define FORTRAN_COMMON_STATIC_MULTIMAP_VIEW_H_
+#ifndef FORTRAN_SUPPORT_STATIC_MULTIMAP_VIEW_H_
+#define FORTRAN_SUPPORT_STATIC_MULTIMAP_VIEW_H_
 #include <algorithm>
 #include <utility>
 
@@ -59,4 +59,4 @@ template <typename V> class StaticMultimapView {
   const_iterator end_{nullptr};
 };
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_STATIC_MULTIMAP_VIEW_H_
+#endif /* FORTRAN_SUPPORT_STATIC_MULTIMAP_VIEW_H_ */
diff --git a/flang/include/flang/Common/template.h b/flang/include/flang/Support/template.h
similarity index 98%
rename from flang/include/flang/Common/template.h
rename to flang/include/flang/Support/template.h
index 51d09fb42ce3684..36fa6f7072b40cb 100644
--- a/flang/include/flang/Common/template.h
+++ b/flang/include/flang/Support/template.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/template.h -------------------------*- C++ -*-===//
+//===-- include/flang/Support/template.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.
@@ -6,11 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_TEMPLATE_H_
-#define FORTRAN_COMMON_TEMPLATE_H_
+#ifndef FORTRAN_SUPPORT_TEMPLATE_H_
+#define FORTRAN_SUPPORT_TEMPLATE_H_
 
-#include "variant.h"
 #include "flang/Common/idioms.h"
+#include "flang/Common/variant.h"
 #include <functional>
 #include <optional>
 #include <tuple>
@@ -322,4 +322,4 @@ common::IfNoLvalue<typename VISITOR::Result, VISITOR> SearchTypes(
       std::move(visitor), std::move(defaultResult));
 }
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_TEMPLATE_H_
+#endif /* FORTRAN_SUPPORT_TEMPLATE_H_ */
diff --git a/flang/include/flang/Common/unwrap.h b/flang/include/flang/Support/unwrap.h
similarity index 94%
rename from flang/include/flang/Common/unwrap.h
rename to flang/include/flang/Support/unwrap.h
index 84582174e4b3006..e890753499d1a16 100644
--- a/flang/include/flang/Common/unwrap.h
+++ b/flang/include/flang/Support/unwrap.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/unwrap.h ---------------------------*- C++ -*-===//
+//===-- include/flang/Support/unwrap.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.
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_UNWRAP_H_
-#define FORTRAN_COMMON_UNWRAP_H_
+#ifndef FORTRAN_SUPPORT_UNWRAP_H_
+#define FORTRAN_SUPPORT_UNWRAP_H_
 
 #include "indirection.h"
 #include "reference-counted.h"
 #include "reference.h"
-#include "variant.h"
-#include "visit.h"
+#include "flang/Common/variant.h"
+#include "flang/Common/visit.h"
 #include <memory>
 #include <optional>
 #include <type_traits>
@@ -155,4 +155,4 @@ template <typename A, typename B> std::optional<A> UnwrapCopy(const B &x) {
   }
 }
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_UNWRAP_H_
+#endif /* FORTRAN_SUPPORT_UNWRAP_H_ */
diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h
index 0286f2aa1451928..d9401e753fb7966 100644
--- a/flang/include/flang/Tools/CrossToolHelpers.h
+++ b/flang/include/flang/Tools/CrossToolHelpers.h
@@ -13,9 +13,9 @@
 #ifndef FORTRAN_TOOLS_CROSS_TOOL_HELPERS_H
 #define FORTRAN_TOOLS_CROSS_TOOL_HELPERS_H
 
-#include "flang/Common/LangOptions.h"
-#include "flang/Common/MathOptionsBase.h"
 #include "flang/Frontend/CodeGenOptions.h"
+#include "flang/Support/LangOptions.h"
+#include "flang/Support/MathOptionsBase.h"
 #include <cstdint>
 
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
diff --git a/flang/lib/CMakeLists.txt b/flang/lib/CMakeLists.txt
index 2182e845b6a7934..05c3535b09b3d38 100644
--- a/flang/lib/CMakeLists.txt
+++ b/flang/lib/CMakeLists.txt
@@ -1,4 +1,3 @@
-add_subdirectory(Common)
 add_subdirectory(Evaluate)
 add_subdirectory(Decimal)
 add_subdirectory(Lower)
diff --git a/flang/lib/Common/CMakeLists.txt b/flang/lib/Common/CMakeLists.txt
deleted file mode 100644
index 4b5df0a49f40312..000000000000000
--- a/flang/lib/Common/CMakeLists.txt
+++ /dev/null
@@ -1,52 +0,0 @@
-find_first_existing_vc_file("${LLVM_MAIN_SRC_DIR}" llvm_vc)
-find_first_existing_vc_file("${FLANG_SOURCE_DIR}" flang_vc)
-
-# The VC revision include that we want to generate.
-set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
-
-set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake")
-
-if(llvm_vc AND LLVM_APPEND_VC_REV)
-  set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
-endif()
-if(flang_vc AND LLVM_APPEND_VC_REV)
-  set(flang_source_dir ${FLANG_SOURCE_DIR})
-endif()
-
-# Create custom target to generate the VC revision include.
-add_custom_command(OUTPUT "${version_inc}"
-  DEPENDS "${llvm_vc}" "${flang_vc}" "${generate_vcs_version_script}"
-  COMMAND ${CMAKE_COMMAND} "-DNAMES=\"LLVM;FLANG\""
-                           "-DLLVM_SOURCE_DIR=${llvm_source_dir}"
-                           "-DFLANG_SOURCE_DIR=${flang_source_dir}"
-                           "-DHEADER_FILE=${version_inc}"
-                           "-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
-                           "-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
-                           -P "${generate_vcs_version_script}")
-
-# Mark the generated header as being generated.
-set_source_files_properties("${version_inc}"
-  PROPERTIES GENERATED TRUE
-             HEADER_FILE_ONLY TRUE)
-
-if(FLANG_VENDOR)
-  set_source_files_properties(Version.cpp
-    PROPERTIES COMPILE_DEFINITIONS "FLANG_VENDOR=\"${FLANG_VENDOR} \"")
-endif()
-
-add_flang_library(FortranCommon
-  Fortran.cpp
-  Fortran-features.cpp
-  default-kinds.cpp
-  idioms.cpp
-  LangOptions.cpp
-  OpenMP-utils.cpp
-  Version.cpp
-  ${version_inc}
-
-  LINK_COMPONENTS
-  Support
-
-  MLIR_LIBS
-  MLIRIR
-)
diff --git a/flang/lib/Evaluate/CMakeLists.txt b/flang/lib/Evaluate/CMakeLists.txt
index b38f450d746ea78..e0bdb6b2d24d823 100644
--- a/flang/lib/Evaluate/CMakeLists.txt
+++ b/flang/lib/Evaluate/CMakeLists.txt
@@ -60,7 +60,7 @@ add_flang_library(FortranEvaluate
   variable.cpp
 
   LINK_LIBS
-  FortranCommon
+  FortranSupport
   FortranDecimal
   FortranParser
   ${LIBPGMATH}
diff --git a/flang/lib/Evaluate/call.cpp b/flang/lib/Evaluate/call.cpp
index c5b50e806d2497d..f77df92a7597ab9 100644
--- a/flang/lib/Evaluate/call.cpp
+++ b/flang/lib/Evaluate/call.cpp
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Evaluate/call.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
 #include "flang/Evaluate/characteristics.h"
 #include "flang/Evaluate/check-expression.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Evaluate/tools.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/Fortran.h"
 
 namespace Fortran::evaluate {
 
diff --git a/flang/lib/Evaluate/characteristics.cpp b/flang/lib/Evaluate/characteristics.cpp
index 3912d1c4b477152..49d11f41ea4caa9 100644
--- a/flang/lib/Evaluate/characteristics.cpp
+++ b/flang/lib/Evaluate/characteristics.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Evaluate/characteristics.h"
-#include "flang/Common/indirection.h"
 #include "flang/Evaluate/check-expression.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/intrinsics.h"
@@ -17,6 +16,7 @@
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <initializer_list>
 
diff --git a/flang/lib/Evaluate/fold-implementation.h b/flang/lib/Evaluate/fold-implementation.h
index 31d043f490fd85c..723bb8d97f68e29 100644
--- a/flang/lib/Evaluate/fold-implementation.h
+++ b/flang/lib/Evaluate/fold-implementation.h
@@ -12,9 +12,6 @@
 #include "character.h"
 #include "host.h"
 #include "int-power.h"
-#include "flang/Common/indirection.h"
-#include "flang/Common/template.h"
-#include "flang/Common/unwrap.h"
 #include "flang/Evaluate/characteristics.h"
 #include "flang/Evaluate/common.h"
 #include "flang/Evaluate/constant.h"
@@ -31,6 +28,9 @@
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/indirection.h"
+#include "flang/Support/template.h"
+#include "flang/Support/unwrap.h"
 #include <algorithm>
 #include <cmath>
 #include <complex>
diff --git a/flang/lib/Evaluate/formatting.cpp b/flang/lib/Evaluate/formatting.cpp
index f3a53c1f983dfa2..c4c399825783019 100644
--- a/flang/lib/Evaluate/formatting.cpp
+++ b/flang/lib/Evaluate/formatting.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Evaluate/formatting.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Evaluate/call.h"
 #include "flang/Evaluate/constant.h"
 #include "flang/Evaluate/expression.h"
@@ -16,6 +15,7 @@
 #include "flang/Parser/characters.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/Fortran.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace Fortran::evaluate {
diff --git a/flang/lib/Evaluate/intrinsics-library.cpp b/flang/lib/Evaluate/intrinsics-library.cpp
index c1b270f518c0e0a..fa2c931b21f0aa3 100644
--- a/flang/lib/Evaluate/intrinsics-library.cpp
+++ b/flang/lib/Evaluate/intrinsics-library.cpp
@@ -16,8 +16,8 @@
 #include "host.h"
 #include "flang/Common/erfc-scaled.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/static-multimap-view.h"
 #include "flang/Evaluate/expression.h"
+#include "flang/Support/static-multimap-view.h"
 #include <cfloat>
 #include <cmath>
 #include <complex>
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index f234241cfe14a6a..2881d9942af7e42 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Evaluate/intrinsics.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/idioms.h"
 #include "flang/Evaluate/check-expression.h"
@@ -19,6 +18,7 @@
 #include "flang/Evaluate/type.h"
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/Fortran.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <cmath>
diff --git a/flang/lib/Evaluate/shape.cpp b/flang/lib/Evaluate/shape.cpp
index 58b824d9b8e6441..ab7c357fa78a8ae 100644
--- a/flang/lib/Evaluate/shape.cpp
+++ b/flang/lib/Evaluate/shape.cpp
@@ -8,7 +8,6 @@
 
 #include "flang/Evaluate/shape.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/template.h"
 #include "flang/Evaluate/characteristics.h"
 #include "flang/Evaluate/check-expression.h"
 #include "flang/Evaluate/fold.h"
@@ -17,6 +16,7 @@
 #include "flang/Evaluate/type.h"
 #include "flang/Parser/message.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/template.h"
 #include <functional>
 
 using namespace std::placeholders; // _1, _2, &c. for std::bind()
diff --git a/flang/lib/Evaluate/target.cpp b/flang/lib/Evaluate/target.cpp
index 94dc35ecd5900a2..f87cce8b3200519 100644
--- a/flang/lib/Evaluate/target.cpp
+++ b/flang/lib/Evaluate/target.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Evaluate/target.h"
-#include "flang/Common/template.h"
 #include "flang/Evaluate/common.h"
 #include "flang/Evaluate/type.h"
+#include "flang/Support/template.h"
 
 namespace Fortran::evaluate {
 
diff --git a/flang/lib/Frontend/CMakeLists.txt b/flang/lib/Frontend/CMakeLists.txt
index d063ed36d00b451..81eef2d468d8c63 100644
--- a/flang/lib/Frontend/CMakeLists.txt
+++ b/flang/lib/Frontend/CMakeLists.txt
@@ -27,7 +27,7 @@ add_flang_library(flangFrontend
   FortranParser
   FortranSemantics
   FortranEvaluate
-  FortranCommon
+  FortranSupport
   FortranLower
   FortranSupport
   FIRDialect
diff --git a/flang/lib/Frontend/CompilerInstance.cpp b/flang/lib/Frontend/CompilerInstance.cpp
index 298790bae665586..7888bab5ffb4267 100644
--- a/flang/lib/Frontend/CompilerInstance.cpp
+++ b/flang/lib/Frontend/CompilerInstance.cpp
@@ -11,12 +11,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Frontend/CompilerInstance.h"
-#include "flang/Common/Fortran-features.h"
 #include "flang/Frontend/CompilerInvocation.h"
 #include "flang/Frontend/TextDiagnosticPrinter.h"
 #include "flang/Parser/parsing.h"
 #include "flang/Parser/provenance.h"
 #include "flang/Semantics/semantics.h"
+#include "flang/Support/Fortran-features.h"
 #include "flang/Support/Timing.h"
 #include "mlir/Support/RawOstreamExtras.h"
 #include "clang/Basic/DiagnosticFrontend.h"
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 15b1e1e0a24881c..e89c7f3daaf42b6 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -11,13 +11,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Frontend/CompilerInvocation.h"
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/OpenMP-features.h"
-#include "flang/Common/Version.h"
 #include "flang/Frontend/CodeGenOptions.h"
 #include "flang/Frontend/PreprocessorOptions.h"
 #include "flang/Frontend/TargetOptions.h"
 #include "flang/Semantics/semantics.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/OpenMP-features.h"
+#include "flang/Support/Version.h"
 #include "flang/Tools/TargetSetup.h"
 #include "flang/Version.inc"
 #include "clang/Basic/AllDiagnostics.h"
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index b0545a7ac2f99a7..b7674bd093f688f 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -11,7 +11,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Frontend/FrontendActions.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Frontend/CompilerInstance.h"
 #include "flang/Frontend/CompilerInvocation.h"
 #include "flang/Frontend/FrontendOptions.h"
@@ -34,6 +33,7 @@
 #include "flang/Semantics/runtime-type-info.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/unparse-with-symbols.h"
+#include "flang/Support/default-kinds.h"
 #include "flang/Tools/CrossToolHelpers.h"
 
 #include "mlir/IR/Dialect.h"
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 700ca56141a3246..708b6e7be5d8a21 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -12,7 +12,6 @@
 
 #include "flang/Lower/Bridge.h"
 
-#include "flang/Common/Version.h"
 #include "flang/Lower/Allocatable.h"
 #include "flang/Lower/CallInterface.h"
 #include "flang/Lower/Coarray.h"
@@ -62,6 +61,7 @@
 #include "flang/Semantics/runtime-type-info.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/Version.h"
 #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
 #include "mlir/IR/Matchers.h"
 #include "mlir/IR/PatternMatch.h"
diff --git a/flang/lib/Lower/CMakeLists.txt b/flang/lib/Lower/CMakeLists.txt
index f611010765cb505..0bc708a1636382b 100644
--- a/flang/lib/Lower/CMakeLists.txt
+++ b/flang/lib/Lower/CMakeLists.txt
@@ -55,7 +55,7 @@ add_flang_library(FortranLower
   FIRSupport
   FIRTransforms
   HLFIRDialect
-  FortranCommon
+  FortranSupport
   FortranParser
   FortranEvaluate
   FortranSemantics
diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp
index e20b90b2ff1bcb0..c8314fac9054c42 100644
--- a/flang/lib/Lower/CallInterface.cpp
+++ b/flang/lib/Lower/CallInterface.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Lower/CallInterface.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Lower/Bridge.h"
 #include "flang/Lower/Mangler.h"
@@ -23,6 +22,7 @@
 #include "flang/Optimizer/Support/Utils.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/Fortran.h"
 #include <optional>
 
 static mlir::FunctionType
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index d9ae502edbafaa2..04df137ce566ff2 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -11,8 +11,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Lower/ConvertExpr.h"
-#include "flang/Common/default-kinds.h"
-#include "flang/Common/unwrap.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/real.h"
 #include "flang/Evaluate/traverse.h"
@@ -52,6 +50,8 @@
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
 #include "flang/Semantics/type.h"
+#include "flang/Support/default-kinds.h"
+#include "flang/Support/unwrap.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "llvm/ADT/TypeSwitch.h"
 #include "llvm/Support/CommandLine.h"
diff --git a/flang/lib/Lower/Mangler.cpp b/flang/lib/Lower/Mangler.cpp
index 1165417ef89a282..aa40b1219652022 100644
--- a/flang/lib/Lower/Mangler.cpp
+++ b/flang/lib/Lower/Mangler.cpp
@@ -7,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Lower/Mangler.h"
-#include "flang/Common/reference.h"
 #include "flang/Lower/Support/Utils.h"
 #include "flang/Optimizer/Builder/Todo.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Support/InternalNames.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/reference.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 6a343645ab87869..77256a51fa7f718 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -14,7 +14,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Optimizer/Builder/IntrinsicCall.h"
-#include "flang/Common/static-multimap-view.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Builder/Character.h"
 #include "flang/Optimizer/Builder/Complex.h"
@@ -42,6 +41,7 @@
 #include "flang/Optimizer/Support/Utils.h"
 #include "flang/Runtime/entry-names.h"
 #include "flang/Runtime/iostat-consts.h"
+#include "flang/Support/static-multimap-view.h"
 #include "mlir/Dialect/Complex/IR/Complex.h"
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/Dialect/Math/IR/Math.h"
diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.cpp b/flang/lib/Optimizer/CodeGen/TypeConverter.cpp
index 0eace903720f038..89f498433806e8a 100644
--- a/flang/lib/Optimizer/CodeGen/TypeConverter.cpp
+++ b/flang/lib/Optimizer/CodeGen/TypeConverter.cpp
@@ -13,7 +13,6 @@
 #define DEBUG_TYPE "flang-type-conversion"
 
 #include "flang/Optimizer/CodeGen/TypeConverter.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Optimizer/Builder/Todo.h" // remove when TODO's are done
 #include "flang/Optimizer/CodeGen/DescriptorModel.h"
 #include "flang/Optimizer/CodeGen/TBAABuilder.h"
@@ -22,6 +21,7 @@
 #include "flang/Optimizer/Dialect/Support/FIRContext.h"
 #include "flang/Optimizer/Dialect/Support/KindMapping.h"
 #include "flang/Optimizer/Support/InternalNames.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/Conversion/LLVMCommon/TypeConverter.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/Debug.h"
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 0b57a10a6c49334..67d918cc0f41c47 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -11,7 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Optimizer/Dialect/FIRType.h"
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Optimizer/Builder/Todo.h"
 #include "flang/Optimizer/Dialect/FIRDialect.h"
 #include "flang/Optimizer/Dialect/Support/KindMapping.h"
diff --git a/flang/lib/Optimizer/OpenMP/CMakeLists.txt b/flang/lib/Optimizer/OpenMP/CMakeLists.txt
index 9fe2d3947c26dd6..f3412e32326de06 100644
--- a/flang/lib/Optimizer/OpenMP/CMakeLists.txt
+++ b/flang/lib/Optimizer/OpenMP/CMakeLists.txt
@@ -21,7 +21,7 @@ add_flang_library(FlangOpenMPTransforms
   FIRDialect
   FIRDialectSupport
   FIRSupport
-  FortranCommon
+  FortranSupport
   FortranEvaluate
   HLFIRDialect
 
diff --git a/flang/lib/Optimizer/Passes/CMakeLists.txt b/flang/lib/Optimizer/Passes/CMakeLists.txt
index eb25beba309bf67..1c19a5765aff155 100644
--- a/flang/lib/Optimizer/Passes/CMakeLists.txt
+++ b/flang/lib/Optimizer/Passes/CMakeLists.txt
@@ -5,14 +5,11 @@ add_flang_library(flangPasses
   CommandLineOpts.cpp
   Pipelines.cpp
 
-  DEPENDS
-  FortranCommon
-
   LINK_LIBS
   FIRCodeGen
   FIRTransforms
   FlangOpenMPTransforms
-  FortranCommon
+  FortranSupport
   HLFIRTransforms
 
   LINK_COMPONENTS
diff --git a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
index a8e9d198ccb97c2..79e2b360018c158 100644
--- a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
+++ b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
@@ -12,7 +12,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "DebugTypeGenerator.h"
-#include "flang/Common/Version.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Builder/Todo.h"
 #include "flang/Optimizer/CodeGen/CGOps.h"
@@ -23,6 +22,7 @@
 #include "flang/Optimizer/Dialect/Support/FIRContext.h"
 #include "flang/Optimizer/Support/InternalNames.h"
 #include "flang/Optimizer/Transforms/Passes.h"
+#include "flang/Support/Version.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/IR/Matchers.h"
diff --git a/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp b/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp
index eb59045a5fde7f8..d0bd67a23641985 100644
--- a/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp
@@ -6,7 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/Fortran.h"
 #include "flang/Lower/BuiltinModules.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Builder/Runtime/Support.h"
@@ -17,6 +16,7 @@
 #include "flang/Optimizer/Support/Utils.h"
 #include "flang/Optimizer/Transforms/Passes.h"
 #include "flang/Runtime/support.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/Pass/Pass.h"
 #include "mlir/Transforms/DialectConversion.h"
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index 9c550f983434a99..50994fbb2170002 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -46,7 +46,7 @@ add_flang_library(FIRTransforms
   FIRDialect
   FIRDialectSupport
   FIRSupport
-  FortranCommon
+  FortranSupport
   HLFIRDialect
 
   MLIR_LIBS
diff --git a/flang/lib/Optimizer/Transforms/CUFDeviceGlobal.cpp b/flang/lib/Optimizer/Transforms/CUFDeviceGlobal.cpp
index 5ce39f99bbb126c..1aeb59b1d669e2e 100644
--- a/flang/lib/Optimizer/Transforms/CUFDeviceGlobal.cpp
+++ b/flang/lib/Optimizer/Transforms/CUFDeviceGlobal.cpp
@@ -6,7 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/Fortran.h"
 #include "flang/Optimizer/Builder/CUFCommon.h"
 #include "flang/Optimizer/Dialect/CUF/CUFOps.h"
 #include "flang/Optimizer/Dialect/FIRDialect.h"
@@ -15,6 +14,7 @@
 #include "flang/Optimizer/Support/InternalNames.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/allocatable.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/Dialect/LLVMIR/NVVMDialect.h"
 #include "mlir/IR/SymbolTable.h"
 #include "mlir/Pass/Pass.h"
diff --git a/flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp b/flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp
index 60aa401e1cc8cc5..5a3d38722ecd31b 100644
--- a/flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp
@@ -7,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Optimizer/Transforms/CUFGPUToLLVMConversion.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Optimizer/CodeGen/TypeConverter.h"
 #include "flang/Optimizer/Support/DataLayout.h"
 #include "flang/Runtime/CUDA/common.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/Conversion/LLVMCommon/Pattern.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/Pass/Pass.h"
diff --git a/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp b/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp
index 8b8c00fa7ecfcb1..88b23b92336b53a 100644
--- a/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Optimizer/Transforms/CUFOpConversion.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Optimizer/Builder/CUFCommon.h"
 #include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
 #include "flang/Optimizer/CodeGen/TypeConverter.h"
@@ -21,6 +20,7 @@
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/CUDA/memory.h"
 #include "flang/Runtime/allocatable.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/Conversion/LLVMCommon/Pattern.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/IR/Matchers.h"
diff --git a/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp b/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
index 4f6974ee526955b..3d84eaa4c1595ae 100644
--- a/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
@@ -6,12 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/Fortran.h"
 #include "flang/Optimizer/Dialect/FIRDialect.h"
 #include "flang/Optimizer/Dialect/FIROps.h"
 #include "flang/Optimizer/Dialect/FIROpsSupport.h"
 #include "flang/Optimizer/Support/InternalNames.h"
 #include "flang/Optimizer/Transforms/Passes.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/SymbolTable.h"
diff --git a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp
index b534ec160ce2151..343cc6ff2895003 100644
--- a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp
+++ b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp
@@ -40,7 +40,7 @@
 ///       could be part of the cost analysis above.
 //===----------------------------------------------------------------------===//
 
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Builder/Runtime/Inquiry.h"
diff --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
index fa6a7b23624e846..df2887ff1422e70 100644
--- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
+++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
@@ -22,7 +22,6 @@
 /// and small in size.
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/Fortran.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Builder/CUFCommon.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
@@ -35,6 +34,7 @@
 #include "flang/Optimizer/Transforms/Passes.h"
 #include "flang/Optimizer/Transforms/Utils.h"
 #include "flang/Runtime/entry-names.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/IR/Matchers.h"
 #include "mlir/IR/Operation.h"
diff --git a/flang/lib/Optimizer/Transforms/StackReclaim.cpp b/flang/lib/Optimizer/Transforms/StackReclaim.cpp
index bd3e49a47bc399d..acb685850d173c8 100644
--- a/flang/lib/Optimizer/Transforms/StackReclaim.cpp
+++ b/flang/lib/Optimizer/Transforms/StackReclaim.cpp
@@ -6,11 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/Fortran.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Dialect/FIRDialect.h"
 #include "flang/Optimizer/Dialect/FIROps.h"
 #include "flang/Optimizer/Transforms/Passes.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/IR/Matchers.h"
 #include "mlir/Pass/Pass.h"
diff --git a/flang/lib/Optimizer/Transforms/VScaleAttr.cpp b/flang/lib/Optimizer/Transforms/VScaleAttr.cpp
index d311167c58b4d63..54a2456e77366c6 100644
--- a/flang/lib/Optimizer/Transforms/VScaleAttr.cpp
+++ b/flang/lib/Optimizer/Transforms/VScaleAttr.cpp
@@ -14,7 +14,7 @@
 /// likely harmless to run it on something else, but it is also not valuable].
 //===----------------------------------------------------------------------===//
 
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Builder/Runtime/Inquiry.h"
diff --git a/flang/lib/Parser/CMakeLists.txt b/flang/lib/Parser/CMakeLists.txt
index d364671d7a32296..76fe3d7ce6ba483 100644
--- a/flang/lib/Parser/CMakeLists.txt
+++ b/flang/lib/Parser/CMakeLists.txt
@@ -25,7 +25,7 @@ add_flang_library(FortranParser
   user-state.cpp
 
   LINK_LIBS
-  FortranCommon
+  FortranSupport
 
   LINK_COMPONENTS
   Support
diff --git a/flang/lib/Parser/basic-parsers.h b/flang/lib/Parser/basic-parsers.h
index 1a8c14e7048f646..d739102b8464fe3 100644
--- a/flang/lib/Parser/basic-parsers.h
+++ b/flang/lib/Parser/basic-parsers.h
@@ -22,14 +22,14 @@
 // This header defines the fundamental parser class templates and helper
 // template functions.  See parser-combinators.txt for documentation.
 
-#include "flang/Common/Fortran-features.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Parser/message.h"
 #include "flang/Parser/parse-state.h"
 #include "flang/Parser/provenance.h"
 #include "flang/Parser/user-state.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/indirection.h"
 #include <cstring>
 #include <functional>
 #include <list>
diff --git a/flang/lib/Parser/parse-tree.cpp b/flang/lib/Parser/parse-tree.cpp
index a414f226058e3ed..89491fd2fa2a710 100644
--- a/flang/lib/Parser/parse-tree.cpp
+++ b/flang/lib/Parser/parse-tree.cpp
@@ -8,9 +8,9 @@
 
 #include "flang/Parser/parse-tree.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Parser/tools.h"
 #include "flang/Parser/user-state.h"
+#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 
diff --git a/flang/lib/Parser/prescan.h b/flang/lib/Parser/prescan.h
index 08041f93b14b6c7..e2440ad6fbc4271 100644
--- a/flang/lib/Parser/prescan.h
+++ b/flang/lib/Parser/prescan.h
@@ -16,11 +16,11 @@
 // fixed form character literals on truncated card images, file
 // inclusion, and driving the Fortran source preprocessor.
 
-#include "flang/Common/Fortran-features.h"
 #include "flang/Parser/characters.h"
 #include "flang/Parser/message.h"
 #include "flang/Parser/provenance.h"
 #include "flang/Parser/token-sequence.h"
+#include "flang/Support/Fortran-features.h"
 #include <bitset>
 #include <optional>
 #include <string>
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 7bf404bba2c3e43..6cd18abbdff0c52 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -10,13 +10,13 @@
 // traversal templates in parse-tree-visitor.h.
 
 #include "flang/Parser/unparse.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Parser/characters.h"
 #include "flang/Parser/parse-tree-visitor.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Parser/tools.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <cinttypes>
diff --git a/flang/lib/Semantics/CMakeLists.txt b/flang/lib/Semantics/CMakeLists.txt
index 7855ae7eed13870..00108dde49dbdc2 100644
--- a/flang/lib/Semantics/CMakeLists.txt
+++ b/flang/lib/Semantics/CMakeLists.txt
@@ -53,7 +53,7 @@ add_flang_library(FortranSemantics
   omp_gen
 
   LINK_LIBS
-  FortranCommon
+  FortranSupport
   FortranParser
   FortranEvaluate
 
diff --git a/flang/lib/Semantics/assignment.h b/flang/lib/Semantics/assignment.h
index 95d7b3cf91b17a5..ba0c70f7d224cb5 100644
--- a/flang/lib/Semantics/assignment.h
+++ b/flang/lib/Semantics/assignment.h
@@ -9,9 +9,9 @@
 #ifndef FORTRAN_SEMANTICS_ASSIGNMENT_H_
 #define FORTRAN_SEMANTICS_ASSIGNMENT_H_
 
-#include "flang/Common/indirection.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Semantics/semantics.h"
+#include "flang/Support/indirection.h"
 
 namespace Fortran::parser {
 class ContextualMessages;
diff --git a/flang/lib/Semantics/check-case.cpp b/flang/lib/Semantics/check-case.cpp
index 5ce143c9aec91a4..c81d3b16ab313ca 100644
--- a/flang/lib/Semantics/check-case.cpp
+++ b/flang/lib/Semantics/check-case.cpp
@@ -8,13 +8,13 @@
 
 #include "check-case.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/reference.h"
-#include "flang/Common/template.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/type.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/reference.h"
+#include "flang/Support/template.h"
 #include <tuple>
 
 namespace Fortran::semantics {
diff --git a/flang/lib/Semantics/check-coarray.cpp b/flang/lib/Semantics/check-coarray.cpp
index 6cf61a6b923db35..ac1f38801cee72c 100644
--- a/flang/lib/Semantics/check-coarray.cpp
+++ b/flang/lib/Semantics/check-coarray.cpp
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "check-coarray.h"
-#include "flang/Common/indirection.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Parser/message.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Parser/tools.h"
 #include "flang/Semantics/expression.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/indirection.h"
 
 namespace Fortran::semantics {
 
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index d8a5639227648f8..d079f5b6aa53017 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "check-cuda.h"
-#include "flang/Common/template.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/tools.h"
 #include "flang/Evaluate/traverse.h"
@@ -17,6 +16,7 @@
 #include "flang/Semantics/expression.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/template.h"
 
 // Once labeled DO constructs have been canonicalized and their parse subtrees
 // transformed into parser::DoConstructs, scan the parser::Blocks of the program
diff --git a/flang/lib/Semantics/check-data.h b/flang/lib/Semantics/check-data.h
index 479d32568fa66a2..6da316cccc4a7b8 100644
--- a/flang/lib/Semantics/check-data.h
+++ b/flang/lib/Semantics/check-data.h
@@ -10,11 +10,11 @@
 #define FORTRAN_SEMANTICS_CHECK_DATA_H_
 
 #include "data-to-inits.h"
-#include "flang/Common/interval.h"
 #include "flang/Evaluate/fold-designator.h"
 #include "flang/Evaluate/initial-image.h"
 #include "flang/Semantics/expression.h"
 #include "flang/Semantics/semantics.h"
+#include "flang/Support/interval.h"
 #include <list>
 #include <map>
 #include <vector>
diff --git a/flang/lib/Semantics/check-do-forall.cpp b/flang/lib/Semantics/check-do-forall.cpp
index 84e6b6455cc6122..ddba4c04b1ee3fa 100644
--- a/flang/lib/Semantics/check-do-forall.cpp
+++ b/flang/lib/Semantics/check-do-forall.cpp
@@ -8,7 +8,6 @@
 
 #include "check-do-forall.h"
 #include "definable.h"
-#include "flang/Common/template.h"
 #include "flang/Evaluate/call.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Evaluate/tools.h"
@@ -22,6 +21,7 @@
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
 #include "flang/Semantics/type.h"
+#include "flang/Support/template.h"
 
 namespace Fortran::evaluate {
 using ActualArgumentRef = common::Reference<const ActualArgument>;
diff --git a/flang/lib/Semantics/check-return.cpp b/flang/lib/Semantics/check-return.cpp
index 22729f659ed5bef..52220a566bbdcc0 100644
--- a/flang/lib/Semantics/check-return.cpp
+++ b/flang/lib/Semantics/check-return.cpp
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "check-return.h"
-#include "flang/Common/Fortran-features.h"
 #include "flang/Parser/message.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/Fortran-features.h"
 
 namespace Fortran::semantics {
 
diff --git a/flang/lib/Semantics/check-select-rank.cpp b/flang/lib/Semantics/check-select-rank.cpp
index 2e602d307013c1e..b227bbaaef4ba48 100644
--- a/flang/lib/Semantics/check-select-rank.cpp
+++ b/flang/lib/Semantics/check-select-rank.cpp
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "check-select-rank.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
 #include "flang/Parser/message.h"
 #include "flang/Parser/tools.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/Fortran.h"
 #include <list>
 #include <optional>
 #include <set>
diff --git a/flang/lib/Semantics/check-select-type.cpp b/flang/lib/Semantics/check-select-type.cpp
index 94d16a719277af6..b86a95492b21c15 100644
--- a/flang/lib/Semantics/check-select-type.cpp
+++ b/flang/lib/Semantics/check-select-type.cpp
@@ -8,12 +8,12 @@
 
 #include "check-select-type.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/reference.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/type.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/reference.h"
 #include <optional>
 
 namespace Fortran::semantics {
diff --git a/flang/lib/Semantics/check-stop.cpp b/flang/lib/Semantics/check-stop.cpp
index 43535b07f029e94..aabd52098e63bb8 100644
--- a/flang/lib/Semantics/check-stop.cpp
+++ b/flang/lib/Semantics/check-stop.cpp
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "check-stop.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/Fortran.h"
 #include <optional>
 
 namespace Fortran::semantics {
diff --git a/flang/lib/Semantics/data-to-inits.h b/flang/lib/Semantics/data-to-inits.h
index d8cc4601de26fa9..e99a02cc79db15c 100644
--- a/flang/lib/Semantics/data-to-inits.h
+++ b/flang/lib/Semantics/data-to-inits.h
@@ -9,10 +9,10 @@
 #ifndef FORTRAN_SEMANTICS_DATA_TO_INITS_H_
 #define FORTRAN_SEMANTICS_DATA_TO_INITS_H_
 
-#include "flang/Common/default-kinds.h"
-#include "flang/Common/interval.h"
 #include "flang/Evaluate/fold-designator.h"
 #include "flang/Evaluate/initial-image.h"
+#include "flang/Support/default-kinds.h"
+#include "flang/Support/interval.h"
 #include <list>
 #include <map>
 
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 3ec6f385ceb86e0..1dd603412f42d74 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -11,7 +11,6 @@
 #include "pointer-assignment.h"
 #include "resolve-names-utils.h"
 #include "resolve-names.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
 #include "flang/Evaluate/common.h"
 #include "flang/Evaluate/fold.h"
@@ -24,6 +23,7 @@
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/Fortran.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <functional>
diff --git a/flang/lib/Semantics/pointer-assignment.cpp b/flang/lib/Semantics/pointer-assignment.cpp
index 7f4548c7327e3b8..49684ffd5f80424 100644
--- a/flang/lib/Semantics/pointer-assignment.cpp
+++ b/flang/lib/Semantics/pointer-assignment.cpp
@@ -10,7 +10,6 @@
 #include "definable.h"
 #include "flang/Common/idioms.h"
 #include "flang/Common/restorer.h"
-#include "flang/Common/template.h"
 #include "flang/Evaluate/characteristics.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Evaluate/fold.h"
@@ -21,6 +20,7 @@
 #include "flang/Semantics/expression.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/template.h"
 #include "llvm/Support/raw_ostream.h"
 #include <optional>
 #include <set>
diff --git a/flang/lib/Semantics/resolve-labels.cpp b/flang/lib/Semantics/resolve-labels.cpp
index 04e4b142efedf85..584319b8abdf630 100644
--- a/flang/lib/Semantics/resolve-labels.cpp
+++ b/flang/lib/Semantics/resolve-labels.cpp
@@ -8,9 +8,9 @@
 
 #include "resolve-labels.h"
 #include "flang/Common/enum-set.h"
-#include "flang/Common/template.h"
 #include "flang/Parser/parse-tree-visitor.h"
 #include "flang/Semantics/semantics.h"
+#include "flang/Support/template.h"
 #include <cstdarg>
 #include <type_traits>
 
diff --git a/flang/lib/Semantics/resolve-names-utils.cpp b/flang/lib/Semantics/resolve-names-utils.cpp
index a838d49c06104d4..065090ed03b6a66 100644
--- a/flang/lib/Semantics/resolve-names-utils.cpp
+++ b/flang/lib/Semantics/resolve-names-utils.cpp
@@ -7,10 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "resolve-names-utils.h"
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/tools.h"
 #include "flang/Evaluate/traverse.h"
@@ -20,6 +17,9 @@
 #include "flang/Semantics/expression.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
 #include <initializer_list>
 #include <variant>
 
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index f3c2a5bf094d04b..2175d5edea0c006 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -13,9 +13,6 @@
 #include "resolve-directives.h"
 #include "resolve-names-utils.h"
 #include "rewrite-parse-tree.h"
-#include "flang/Common/Fortran.h"
-#include "flang/Common/default-kinds.h"
-#include "flang/Common/indirection.h"
 #include "flang/Common/restorer.h"
 #include "flang/Common/visit.h"
 #include "flang/Evaluate/characteristics.h"
@@ -38,6 +35,9 @@
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
 #include "flang/Semantics/type.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/default-kinds.h"
+#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <list>
 #include <map>
diff --git a/flang/lib/Semantics/rewrite-parse-tree.cpp b/flang/lib/Semantics/rewrite-parse-tree.cpp
index 577558e7e33b261..171c0021fba08c2 100644
--- a/flang/lib/Semantics/rewrite-parse-tree.cpp
+++ b/flang/lib/Semantics/rewrite-parse-tree.cpp
@@ -8,7 +8,6 @@
 
 #include "rewrite-parse-tree.h"
 #include "rewrite-directives.h"
-#include "flang/Common/indirection.h"
 #include "flang/Parser/parse-tree-visitor.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Parser/tools.h"
@@ -16,6 +15,7 @@
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/indirection.h"
 #include <list>
 
 namespace Fortran::semantics {
diff --git a/flang/lib/Semantics/semantics.cpp b/flang/lib/Semantics/semantics.cpp
index 58dc1f218b56f41..10a01039ea0ae71 100644
--- a/flang/lib/Semantics/semantics.cpp
+++ b/flang/lib/Semantics/semantics.cpp
@@ -37,12 +37,12 @@
 #include "resolve-labels.h"
 #include "resolve-names.h"
 #include "rewrite-parse-tree.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Parser/parse-tree-visitor.h"
 #include "flang/Parser/tools.h"
 #include "flang/Semantics/expression.h"
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/default-kinds.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
 #include "llvm/TargetParser/Triple.h"
diff --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp
index 052d71be4347201..64e4c9d7e194dba 100644
--- a/flang/lib/Semantics/tools.cpp
+++ b/flang/lib/Semantics/tools.cpp
@@ -7,8 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Parser/tools.h"
-#include "flang/Common/Fortran.h"
-#include "flang/Common/indirection.h"
 #include "flang/Parser/dump-parse-tree.h"
 #include "flang/Parser/message.h"
 #include "flang/Parser/parse-tree.h"
@@ -17,6 +15,8 @@
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
 #include "flang/Semantics/type.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <set>
diff --git a/flang/lib/Support/CMakeLists.txt b/flang/lib/Support/CMakeLists.txt
index 12183f590316d92..809266960a02d4e 100644
--- a/flang/lib/Support/CMakeLists.txt
+++ b/flang/lib/Support/CMakeLists.txt
@@ -1,9 +1,62 @@
+#===-- lib/Support/CMakeLists.txt ------------------------------------------===#
+#
+# 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
+#
+#===------------------------------------------------------------------------===#
+
+find_first_existing_vc_file("${LLVM_MAIN_SRC_DIR}" llvm_vc)
+find_first_existing_vc_file("${FLANG_SOURCE_DIR}" flang_vc)
+
+# The VC revision include that we want to generate.
+set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
+
+set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake")
+
+if(llvm_vc AND LLVM_APPEND_VC_REV)
+  set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
+endif()
+if(flang_vc AND LLVM_APPEND_VC_REV)
+  set(flang_source_dir ${FLANG_SOURCE_DIR})
+endif()
+
+# Create custom target to generate the VC revision include.
+add_custom_command(OUTPUT "${version_inc}"
+  DEPENDS "${llvm_vc}" "${flang_vc}" "${generate_vcs_version_script}"
+  COMMAND ${CMAKE_COMMAND} "-DNAMES=\"LLVM;FLANG\""
+                           "-DLLVM_SOURCE_DIR=${llvm_source_dir}"
+                           "-DFLANG_SOURCE_DIR=${flang_source_dir}"
+                           "-DHEADER_FILE=${version_inc}"
+                           "-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
+                           "-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
+                           -P "${generate_vcs_version_script}")
+
+# Mark the generated header as being generated.
+set_source_files_properties("${version_inc}"
+  PROPERTIES GENERATED TRUE
+             HEADER_FILE_ONLY TRUE)
+
+if(FLANG_VENDOR)
+  set_source_files_properties(Version.cpp
+    PROPERTIES COMPILE_DEFINITIONS "FLANG_VENDOR=\"${FLANG_VENDOR} \"")
+endif()
+
 add_flang_library(FortranSupport
+  Fortran.cpp
+  Fortran-features.cpp
+  default-kinds.cpp
+  idioms.cpp
+  LangOptions.cpp
+  OpenMP-utils.cpp
+  Version.cpp
   Timing.cpp
+  ${version_inc}
 
   LINK_COMPONENTS
   Support
 
   MLIR_LIBS
+  MLIRIR
   MLIRSupport
 )
diff --git a/flang/lib/Common/Fortran-features.cpp b/flang/lib/Support/Fortran-features.cpp
similarity index 97%
rename from flang/lib/Common/Fortran-features.cpp
rename to flang/lib/Support/Fortran-features.cpp
index 3565275915a3120..be84072ae6a5b18 100644
--- a/flang/lib/Common/Fortran-features.cpp
+++ b/flang/lib/Support/Fortran-features.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Common/Fortran-features.cpp -----------------------------------===//
+//===-- lib/Support/Fortran-features.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
+#include "flang/Support/Fortran-features.h"
 #include "flang/Common/idioms.h"
+#include "flang/Support/Fortran.h"
 
 namespace Fortran::common {
 
diff --git a/flang/lib/Common/Fortran.cpp b/flang/lib/Support/Fortran.cpp
similarity index 96%
rename from flang/lib/Common/Fortran.cpp
rename to flang/lib/Support/Fortran.cpp
index eec83419f9eb2ba..746b7c974072891 100644
--- a/flang/lib/Common/Fortran.cpp
+++ b/flang/lib/Support/Fortran.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Common/Fortran.cpp --------------------------------------------===//
+//===-- lib/Support/Fortran.cpp ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/Fortran.h"
-#include "flang/Common/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/Fortran-features.h"
 
 namespace Fortran::common {
 
diff --git a/flang/lib/Common/LangOptions.cpp b/flang/lib/Support/LangOptions.cpp
similarity index 80%
rename from flang/lib/Common/LangOptions.cpp
rename to flang/lib/Support/LangOptions.cpp
index 415c715156e7bf4..273274fc07215d8 100644
--- a/flang/lib/Common/LangOptions.cpp
+++ b/flang/lib/Support/LangOptions.cpp
@@ -1,4 +1,4 @@
-//===------ LangOptions.cpp -----------------------------------------------===//
+//===-- lib/Support/LangOptions.cpp -----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,7 +10,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/LangOptions.h"
+#include "flang/Support/LangOptions.h"
 #include <string.h>
 
 namespace Fortran::common {
@@ -18,7 +18,7 @@ namespace Fortran::common {
 LangOptions::LangOptions() {
 #define LANGOPT(Name, Bits, Default) Name = Default;
 #define ENUM_LANGOPT(Name, Type, Bits, Default) set##Name(Default);
-#include "flang/Common/LangOptions.def"
+#include "flang/Support/LangOptions.def"
 }
 
 } // end namespace Fortran::common
diff --git a/flang/lib/Common/OpenMP-utils.cpp b/flang/lib/Support/OpenMP-utils.cpp
similarity index 95%
rename from flang/lib/Common/OpenMP-utils.cpp
rename to flang/lib/Support/OpenMP-utils.cpp
index 47e89fe6dd1ee99..b3cab763aca3035 100644
--- a/flang/lib/Common/OpenMP-utils.cpp
+++ b/flang/lib/Support/OpenMP-utils.cpp
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/OpenMP-utils.cpp ------------------*- C++ -*-====//
+//===-- lib/Support/OpenMP-utils.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/lib/Support/Timing.cpp b/flang/lib/Support/Timing.cpp
index ee8309a950eec86..41cb2be8269070b 100644
--- a/flang/lib/Support/Timing.cpp
+++ b/flang/lib/Support/Timing.cpp
@@ -1,4 +1,4 @@
-//===- Timing.cpp - Execution time measurement facilities -----------------===//
+//===-- lib/Support/Timing.cpp ----------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/lib/Common/Version.cpp b/flang/lib/Support/Version.cpp
similarity index 95%
rename from flang/lib/Common/Version.cpp
rename to flang/lib/Support/Version.cpp
index d67255f353dfd77..8ee4908f28f6219 100644
--- a/flang/lib/Common/Version.cpp
+++ b/flang/lib/Support/Version.cpp
@@ -1,4 +1,4 @@
-//===- Version.cpp - Flang Version Number -------------------*- Fortran -*-===//
+//===-- lib/Support/Version.cpp ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,7 +10,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/Version.h"
+#include "flang/Support/Version.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstdlib>
 #include <cstring>
diff --git a/flang/lib/Common/default-kinds.cpp b/flang/lib/Support/default-kinds.cpp
similarity index 94%
rename from flang/lib/Common/default-kinds.cpp
rename to flang/lib/Support/default-kinds.cpp
index fbafd827ff0d0b4..c6d7759097be171 100644
--- a/flang/lib/Common/default-kinds.cpp
+++ b/flang/lib/Support/default-kinds.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Common/default-kinds.cpp --------------------------------------===//
+//===-- lib/Support/default-kinds.cpp ---------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/default-kinds.h"
+#include "flang/Support/default-kinds.h"
 #include "flang/Common/idioms.h"
 
 namespace Fortran::common {
diff --git a/flang/lib/Common/idioms.cpp b/flang/lib/Support/idioms.cpp
similarity index 89%
rename from flang/lib/Common/idioms.cpp
rename to flang/lib/Support/idioms.cpp
index 536a5c2e5479df9..906a4c1bcd9b0a4 100644
--- a/flang/lib/Common/idioms.cpp
+++ b/flang/lib/Support/idioms.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Common/idioms.cpp ---------------------------------------------===//
+//===-- lib/Support/idioms.cpp ----------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/CUDA/allocator.cpp b/flang/runtime/CUDA/allocator.cpp
index 85b3daf65a8ba4f..368c1124ef70a51 100644
--- a/flang/runtime/CUDA/allocator.cpp
+++ b/flang/runtime/CUDA/allocator.cpp
@@ -11,10 +11,10 @@
 #include "../stat.h"
 #include "../terminator.h"
 #include "../type-info.h"
-#include "flang/Common/Fortran.h"
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/allocator-registry.h"
+#include "flang/Support/Fortran.h"
 
 #include "cuda_runtime.h"
 
diff --git a/flang/runtime/ISO_Fortran_binding.cpp b/flang/runtime/ISO_Fortran_binding.cpp
index fe22026f31f55f6..64e239f498230cb 100644
--- a/flang/runtime/ISO_Fortran_binding.cpp
+++ b/flang/runtime/ISO_Fortran_binding.cpp
@@ -11,7 +11,7 @@
 
 #include "ISO_Fortran_util.h"
 #include "terminator.h"
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/pointer.h"
 #include "flang/Runtime/type-code.h"
diff --git a/flang/runtime/ISO_Fortran_util.h b/flang/runtime/ISO_Fortran_util.h
index dd0eeef80bb896f..aca9aee8c5718e1 100644
--- a/flang/runtime/ISO_Fortran_util.h
+++ b/flang/runtime/ISO_Fortran_util.h
@@ -12,7 +12,7 @@
 // Internal utils for establishing CFI_cdesc_t descriptors.
 
 #include "terminator.h"
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/type-code.h"
 #include <cstdlib>
diff --git a/flang/runtime/allocatable.cpp b/flang/runtime/allocatable.cpp
index 5e065f47636a899..686114bf86eafa2 100644
--- a/flang/runtime/allocatable.cpp
+++ b/flang/runtime/allocatable.cpp
@@ -12,7 +12,7 @@
 #include "stat.h"
 #include "terminator.h"
 #include "type-info.h"
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/assign.h"
 #include "flang/Runtime/descriptor.h"
 
diff --git a/flang/runtime/stat.h b/flang/runtime/stat.h
index 71faeb027d9085f..572cb6d10b4893a 100644
--- a/flang/runtime/stat.h
+++ b/flang/runtime/stat.h
@@ -11,8 +11,8 @@
 
 #ifndef FORTRAN_RUNTIME_STAT_H_
 #define FORTRAN_RUNTIME_STAT_H_
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Common/api-attrs.h"
-#include "flang/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/magic-numbers.h"
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/temporary-stack.cpp b/flang/runtime/temporary-stack.cpp
index 667b10e04dbd293..93340266b1b44d4 100644
--- a/flang/runtime/temporary-stack.cpp
+++ b/flang/runtime/temporary-stack.cpp
@@ -11,7 +11,7 @@
 
 #include "flang/Runtime/temporary-stack.h"
 #include "terminator.h"
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/assign.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/memory.h"
diff --git a/flang/tools/bbc/CMakeLists.txt b/flang/tools/bbc/CMakeLists.txt
index 85aeb85e0c53093..f950f03920d3fe3 100644
--- a/flang/tools/bbc/CMakeLists.txt
+++ b/flang/tools/bbc/CMakeLists.txt
@@ -36,7 +36,7 @@ mlir_target_link_libraries(bbc PRIVATE
   ${extension_libs}
   MLIRAffineToStandard
   MLIRSCFToControlFlow
-  FortranCommon
+  FortranSupport
   FortranParser
   FortranEvaluate
   FortranSemantics
diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index 7efc460be86795c..4499e44711bd359 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -14,11 +14,6 @@
 ///
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/LangOptions.h"
-#include "flang/Common/OpenMP-features.h"
-#include "flang/Common/Version.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Frontend/CodeGenOptions.h"
 #include "flang/Frontend/TargetOptions.h"
 #include "flang/Lower/Bridge.h"
@@ -42,6 +37,11 @@
 #include "flang/Semantics/runtime-type-info.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/unparse-with-symbols.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/LangOptions.h"
+#include "flang/Support/OpenMP-features.h"
+#include "flang/Support/Version.h"
+#include "flang/Support/default-kinds.h"
 #include "flang/Tools/CrossToolHelpers.h"
 #include "flang/Tools/TargetSetup.h"
 #include "flang/Version.inc"
diff --git a/flang/tools/f18-parse-demo/CMakeLists.txt b/flang/tools/f18-parse-demo/CMakeLists.txt
index df1f1d24a55e511..743a44017e8a5a2 100644
--- a/flang/tools/f18-parse-demo/CMakeLists.txt
+++ b/flang/tools/f18-parse-demo/CMakeLists.txt
@@ -11,6 +11,6 @@ add_flang_tool(f18-parse-demo
 
 target_link_libraries(f18-parse-demo
   PRIVATE
-  FortranCommon
+  FortranSupport
   FortranParser
   )
diff --git a/flang/tools/f18-parse-demo/f18-parse-demo.cpp b/flang/tools/f18-parse-demo/f18-parse-demo.cpp
index 3025dbd4dca4ab5..a50c88dc8406432 100644
--- a/flang/tools/f18-parse-demo/f18-parse-demo.cpp
+++ b/flang/tools/f18-parse-demo/f18-parse-demo.cpp
@@ -21,8 +21,6 @@
 // scaffolding compiler driver that can test some semantic passes of the
 // F18 compiler under development.
 
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Parser/characters.h"
 #include "flang/Parser/dump-parse-tree.h"
 #include "flang/Parser/message.h"
@@ -31,6 +29,8 @@
 #include "flang/Parser/parsing.h"
 #include "flang/Parser/provenance.h"
 #include "flang/Parser/unparse.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/default-kinds.h"
 #include "llvm/Support/Errno.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Program.h"
diff --git a/flang/tools/tco/CMakeLists.txt b/flang/tools/tco/CMakeLists.txt
index 220f908d2f1085f..c277cdbf167b65a 100644
--- a/flang/tools/tco/CMakeLists.txt
+++ b/flang/tools/tco/CMakeLists.txt
@@ -20,7 +20,7 @@ target_link_libraries(tco PRIVATE
   flangPasses
   FIROpenACCSupport
   FlangOpenMPTransforms
-  FortranCommon
+  FortranSupport
 )
 
 mlir_target_link_libraries(tco PRIVATE
diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt
index 52eb385f4763fbc..0ea02ad7f71156e 100644
--- a/flang/unittests/Evaluate/CMakeLists.txt
+++ b/flang/unittests/Evaluate/CMakeLists.txt
@@ -26,7 +26,7 @@ add_flang_nongtest_unittest(uint128
 )
 
 add_flang_nongtest_unittest(expression
-  FortranCommon
+  FortranSupport
   FortranEvaluateTesting
   FortranEvaluate
   FortranSemantics
@@ -40,7 +40,7 @@ add_flang_nongtest_unittest(integer
 )
 
 add_flang_nongtest_unittest(intrinsics
-  FortranCommon
+  FortranSupport
   FortranEvaluateTesting
   FortranEvaluate
   FortranDecimal
@@ -84,7 +84,7 @@ add_flang_nongtest_unittest(ISO-Fortran-binding
 )
 
 add_flang_nongtest_unittest(folding
-  FortranCommon
+  FortranSupport
   FortranEvaluateTesting
   FortranEvaluate
   FortranSemantics
diff --git a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp b/flang/unittests/Evaluate/ISO-Fortran-binding.cpp
index 3c98363f9004664..38688b404876ff2 100644
--- a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp
+++ b/flang/unittests/Evaluate/ISO-Fortran-binding.cpp
@@ -1,5 +1,5 @@
 #include "testing.h"
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/descriptor.h"
 #include "llvm/Support/raw_ostream.h"
 #include <type_traits>
diff --git a/flang/unittests/Frontend/CMakeLists.txt b/flang/unittests/Frontend/CMakeLists.txt
index 9177997f41f53ac..3cbc2cf148511df 100644
--- a/flang/unittests/Frontend/CMakeLists.txt
+++ b/flang/unittests/Frontend/CMakeLists.txt
@@ -18,7 +18,7 @@ target_link_libraries(FlangFrontendTests
   FortranLower
   FortranParser
   FortranSemantics
-  FortranCommon
+  FortranSupport
   FortranEvaluate
 )
 
diff --git a/flang/unittests/Runtime/CUDA/Allocatable.cpp b/flang/unittests/Runtime/CUDA/Allocatable.cpp
index 0f7eb27789316cb..bdfa8f5cc3213c7 100644
--- a/flang/unittests/Runtime/CUDA/Allocatable.cpp
+++ b/flang/unittests/Runtime/CUDA/Allocatable.cpp
@@ -9,11 +9,11 @@
 #include "flang/Runtime/allocatable.h"
 #include "gtest/gtest.h"
 #include "../../../runtime/terminator.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Runtime/CUDA/allocator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/allocator-registry.h"
+#include "flang/Support/Fortran.h"
 
 #include "cuda_runtime.h"
 
diff --git a/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp b/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp
index 7cb25787e7797ba..5ec122e4c5777fe 100644
--- a/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp
+++ b/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp
@@ -8,11 +8,11 @@
 
 #include "gtest/gtest.h"
 #include "../../../runtime/terminator.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Runtime/CUDA/allocator.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/allocator-registry.h"
+#include "flang/Support/Fortran.h"
 
 #include "cuda_runtime.h"
 
diff --git a/flang/unittests/Runtime/CUDA/Memory.cpp b/flang/unittests/Runtime/CUDA/Memory.cpp
index 7c8b7aa5a4d78b4..61c9d1131ee5679 100644
--- a/flang/unittests/Runtime/CUDA/Memory.cpp
+++ b/flang/unittests/Runtime/CUDA/Memory.cpp
@@ -10,12 +10,12 @@
 #include "gtest/gtest.h"
 #include "../../../runtime/terminator.h"
 #include "../tools.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Runtime/CUDA/allocator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/allocator-registry.h"
+#include "flang/Support/Fortran.h"
 
 #include "cuda_runtime.h"
 
diff --git a/flang/unittests/Runtime/TemporaryStack.cpp b/flang/unittests/Runtime/TemporaryStack.cpp
index 0a9344969ca6bae..4f701e09b294525 100644
--- a/flang/unittests/Runtime/TemporaryStack.cpp
+++ b/flang/unittests/Runtime/TemporaryStack.cpp
@@ -8,7 +8,7 @@
 
 #include "gtest/gtest.h"
 #include "tools.h"
-#include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
 #include "flang/Runtime/descriptor.h"

>From 71015c8f9ab17431d052472aec99dc67929a166e Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 24 Jan 2025 16:30:47 +0100
Subject: [PATCH 02/18] [Flang] Promote FortranEvaluateTesting library

---
 .../flang/Testing}/fp-testing.h               | 14 ++++++--
 .../flang/Testing}/testing.h                  | 14 ++++++--
 flang/lib/CMakeLists.txt                      |  4 +++
 flang/lib/Testing/CMakeLists.txt              | 20 +++++++++++
 .../Evaluate => lib/Testing}/fp-testing.cpp   | 10 +++++-
 .../Evaluate => lib/Testing}/testing.cpp      | 10 +++++-
 flang/unittests/Evaluate/CMakeLists.txt       | 35 ++++++-------------
 .../Evaluate/ISO-Fortran-binding.cpp          |  2 +-
 .../Evaluate/bit-population-count.cpp         |  2 +-
 flang/unittests/Evaluate/expression.cpp       |  2 +-
 flang/unittests/Evaluate/folding.cpp          |  2 +-
 flang/unittests/Evaluate/integer.cpp          |  2 +-
 flang/unittests/Evaluate/intrinsics.cpp       |  2 +-
 .../Evaluate/leading-zero-bit-count.cpp       |  2 +-
 flang/unittests/Evaluate/logical.cpp          |  2 +-
 flang/unittests/Evaluate/real.cpp             |  4 +--
 flang/unittests/Evaluate/reshape.cpp          |  2 +-
 flang/unittests/Evaluate/uint128.cpp          |  2 +-
 18 files changed, 87 insertions(+), 44 deletions(-)
 rename flang/{unittests/Evaluate => include/flang/Testing}/fp-testing.h (54%)
 rename flang/{unittests/Evaluate => include/flang/Testing}/testing.h (74%)
 create mode 100644 flang/lib/Testing/CMakeLists.txt
 rename flang/{unittests/Evaluate => lib/Testing}/fp-testing.cpp (87%)
 rename flang/{unittests/Evaluate => lib/Testing}/testing.cpp (88%)

diff --git a/flang/unittests/Evaluate/fp-testing.h b/flang/include/flang/Testing/fp-testing.h
similarity index 54%
rename from flang/unittests/Evaluate/fp-testing.h
rename to flang/include/flang/Testing/fp-testing.h
index 9091963a99b32d7..e223d2ef7d1b8b9 100644
--- a/flang/unittests/Evaluate/fp-testing.h
+++ b/flang/include/flang/Testing/fp-testing.h
@@ -1,5 +1,13 @@
-#ifndef FORTRAN_TEST_EVALUATE_FP_TESTING_H_
-#define FORTRAN_TEST_EVALUATE_FP_TESTING_H_
+//===-- include/flang/Testing/fp-testing.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_TESTING_FP_TESTING_H_
+#define FORTRAN_TESTING_FP_TESTING_H_
 
 #include "flang/Common/target-rounding.h"
 #include <fenv.h>
@@ -24,4 +32,4 @@ class ScopedHostFloatingPointEnvironment {
 #endif
 };
 
-#endif // FORTRAN_TEST_EVALUATE_FP_TESTING_H_
+#endif /* FORTRAN_TESTING_FP_TESTING_H_ */
diff --git a/flang/unittests/Evaluate/testing.h b/flang/include/flang/Testing/testing.h
similarity index 74%
rename from flang/unittests/Evaluate/testing.h
rename to flang/include/flang/Testing/testing.h
index 422e2853c05bc66..404650c9a89f2c5 100644
--- a/flang/unittests/Evaluate/testing.h
+++ b/flang/include/flang/Testing/testing.h
@@ -1,5 +1,13 @@
-#ifndef FORTRAN_EVALUATE_TESTING_H_
-#define FORTRAN_EVALUATE_TESTING_H_
+//===-- include/flang/Testing/testing.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_TESTING_TESTING_H_
+#define FORTRAN_TESTING_TESTING_H_
 
 #include <cinttypes>
 #include <string>
@@ -33,4 +41,4 @@ FailureDetailPrinter Match(const char *file, int line, const std::string &want,
 FailureDetailPrinter Compare(const char *file, int line, const char *xs,
     const char *rel, const char *ys, std::uint64_t x, std::uint64_t y);
 } // namespace testing
-#endif // FORTRAN_EVALUATE_TESTING_H_
+#endif /* FORTRAN_TESTING_TESTING_H_ */
diff --git a/flang/lib/CMakeLists.txt b/flang/lib/CMakeLists.txt
index 05c3535b09b3d38..8b201d9a758a80c 100644
--- a/flang/lib/CMakeLists.txt
+++ b/flang/lib/CMakeLists.txt
@@ -8,3 +8,7 @@ add_subdirectory(Frontend)
 add_subdirectory(FrontendTool)
 
 add_subdirectory(Optimizer)
+
+if (FLANG_INCLUDE_TESTS)
+  add_subdirectory(Testing)
+endif ()
diff --git a/flang/lib/Testing/CMakeLists.txt b/flang/lib/Testing/CMakeLists.txt
new file mode 100644
index 000000000000000..8051bc09736d163
--- /dev/null
+++ b/flang/lib/Testing/CMakeLists.txt
@@ -0,0 +1,20 @@
+#===-- lib/Testing/CMakeLists.txt ------------------------------------------===#
+#
+# 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
+#
+#===------------------------------------------------------------------------===#
+
+add_library(NonGTestTesting EXCLUDE_FROM_ALL
+    testing.cpp
+    fp-testing.cpp
+)
+set_target_properties(NonGTestTesting PROPERTIES FOLDER "Flang/Tests")
+
+if (LLVM_LINK_LLVM_DYLIB)
+  set(llvm_libs LLVM)
+else()
+  llvm_map_components_to_libnames(llvm_libs Support)
+endif()
+target_link_libraries(NonGTestTesting ${llvm_libs})
diff --git a/flang/unittests/Evaluate/fp-testing.cpp b/flang/lib/Testing/fp-testing.cpp
similarity index 87%
rename from flang/unittests/Evaluate/fp-testing.cpp
rename to flang/lib/Testing/fp-testing.cpp
index 1a1d7425d58249b..5e1728e8df5e4bd 100644
--- a/flang/unittests/Evaluate/fp-testing.cpp
+++ b/flang/lib/Testing/fp-testing.cpp
@@ -1,4 +1,12 @@
-#include "fp-testing.h"
+//===-- lib/Testing/fp-testing.cpp ------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Testing/fp-testing.h"
 #include "llvm/Support/Errno.h"
 #include <cstdio>
 #include <cstdlib>
diff --git a/flang/unittests/Evaluate/testing.cpp b/flang/lib/Testing/testing.cpp
similarity index 88%
rename from flang/unittests/Evaluate/testing.cpp
rename to flang/lib/Testing/testing.cpp
index b2f73bf1b265a77..37f9d88f4886b4c 100644
--- a/flang/unittests/Evaluate/testing.cpp
+++ b/flang/lib/Testing/testing.cpp
@@ -1,4 +1,12 @@
-#include "testing.h"
+//===-- lib/Testing/testing.cpp ---------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Testing/testing.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstdarg>
 #include <cstdio>
diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt
index 0ea02ad7f71156e..8111ecd72cfc7d6 100644
--- a/flang/unittests/Evaluate/CMakeLists.txt
+++ b/flang/unittests/Evaluate/CMakeLists.txt
@@ -1,47 +1,34 @@
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-add_library(FortranEvaluateTesting
-  testing.cpp
-  fp-testing.cpp
-)
-set_target_properties(FortranEvaluateTesting PROPERTIES FOLDER "Flang/Tests")
-if (LLVM_LINK_LLVM_DYLIB)
-  set(llvm_libs LLVM)
-else()
-  llvm_map_components_to_libnames(llvm_libs Support)
-endif()
-
-target_link_libraries(FortranEvaluateTesting
-  ${llvm_libs})
 
 add_flang_nongtest_unittest(leading-zero-bit-count
-  FortranEvaluateTesting
+  NonGTestTesting
 )
 
 add_flang_nongtest_unittest(bit-population-count
-  FortranEvaluateTesting
+  NonGTestTesting
 )
 
 add_flang_nongtest_unittest(uint128
-  FortranEvaluateTesting
+  NonGTestTesting
 )
 
 add_flang_nongtest_unittest(expression
   FortranSupport
-  FortranEvaluateTesting
+  NonGTestTesting
   FortranEvaluate
   FortranSemantics
   FortranParser
 )
 
 add_flang_nongtest_unittest(integer
-  FortranEvaluateTesting
+  NonGTestTesting
   FortranEvaluate
   FortranSemantics
 )
 
 add_flang_nongtest_unittest(intrinsics
   FortranSupport
-  FortranEvaluateTesting
+  NonGTestTesting
   FortranEvaluate
   FortranDecimal
   FortranSemantics
@@ -50,7 +37,7 @@ add_flang_nongtest_unittest(intrinsics
 )
 
 add_flang_nongtest_unittest(logical
-  FortranEvaluateTesting
+  NonGTestTesting
   FortranEvaluate
   FortranSemantics
 )
@@ -62,7 +49,7 @@ add_flang_nongtest_unittest(logical
 set(LLVM_REQUIRES_EH ON)
 set(LLVM_REQUIRES_RTTI ON)
 add_flang_nongtest_unittest(real
-  FortranEvaluateTesting
+  NonGTestTesting
   FortranEvaluate
   FortranDecimal
   FortranSemantics
@@ -70,14 +57,14 @@ add_flang_nongtest_unittest(real
 llvm_update_compile_flags(real.test)
 
 add_flang_nongtest_unittest(reshape
-  FortranEvaluateTesting
+  NonGTestTesting
   FortranSemantics
   FortranEvaluate
   FortranRuntime
 )
 
 add_flang_nongtest_unittest(ISO-Fortran-binding
-  FortranEvaluateTesting
+  NonGTestTesting
   FortranEvaluate
   FortranSemantics
   FortranRuntime
@@ -85,7 +72,7 @@ add_flang_nongtest_unittest(ISO-Fortran-binding
 
 add_flang_nongtest_unittest(folding
   FortranSupport
-  FortranEvaluateTesting
+  NonGTestTesting
   FortranEvaluate
   FortranSemantics
 )
diff --git a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp b/flang/unittests/Evaluate/ISO-Fortran-binding.cpp
index 38688b404876ff2..2884686b3f26efe 100644
--- a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp
+++ b/flang/unittests/Evaluate/ISO-Fortran-binding.cpp
@@ -1,6 +1,6 @@
-#include "testing.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/descriptor.h"
+#include "flang/Testing/testing.h"
 #include "llvm/Support/raw_ostream.h"
 #include <type_traits>
 
diff --git a/flang/unittests/Evaluate/bit-population-count.cpp b/flang/unittests/Evaluate/bit-population-count.cpp
index 24e721c14f94a79..0c9529a92e5724b 100644
--- a/flang/unittests/Evaluate/bit-population-count.cpp
+++ b/flang/unittests/Evaluate/bit-population-count.cpp
@@ -1,5 +1,5 @@
 #include "flang/Common/bit-population-count.h"
-#include "testing.h"
+#include "flang/Testing/testing.h"
 
 using Fortran::common::BitPopulationCount;
 using Fortran::common::Parity;
diff --git a/flang/unittests/Evaluate/expression.cpp b/flang/unittests/Evaluate/expression.cpp
index f03a6bc2a4e23c9..d575f36def287ed 100644
--- a/flang/unittests/Evaluate/expression.cpp
+++ b/flang/unittests/Evaluate/expression.cpp
@@ -1,10 +1,10 @@
 #include "flang/Evaluate/expression.h"
-#include "testing.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/intrinsics.h"
 #include "flang/Evaluate/target.h"
 #include "flang/Evaluate/tools.h"
 #include "flang/Parser/message.h"
+#include "flang/Testing/testing.h"
 #include <cstdio>
 #include <cstdlib>
 #include <string>
diff --git a/flang/unittests/Evaluate/folding.cpp b/flang/unittests/Evaluate/folding.cpp
index 4e8ff9754e4ccb8..832e55d44316da8 100644
--- a/flang/unittests/Evaluate/folding.cpp
+++ b/flang/unittests/Evaluate/folding.cpp
@@ -1,4 +1,3 @@
-#include "testing.h"
 #include "../../lib/Evaluate/host.h"
 #include "flang/Evaluate/call.h"
 #include "flang/Evaluate/expression.h"
@@ -7,6 +6,7 @@
 #include "flang/Evaluate/intrinsics.h"
 #include "flang/Evaluate/target.h"
 #include "flang/Evaluate/tools.h"
+#include "flang/Testing/testing.h"
 #include <tuple>
 
 using namespace Fortran::evaluate;
diff --git a/flang/unittests/Evaluate/integer.cpp b/flang/unittests/Evaluate/integer.cpp
index 3eabb2434cce607..5ab22cc6443a7b0 100644
--- a/flang/unittests/Evaluate/integer.cpp
+++ b/flang/unittests/Evaluate/integer.cpp
@@ -1,5 +1,5 @@
 #include "flang/Evaluate/integer.h"
-#include "testing.h"
+#include "flang/Testing/testing.h"
 #include <cstdio>
 #include <string>
 
diff --git a/flang/unittests/Evaluate/intrinsics.cpp b/flang/unittests/Evaluate/intrinsics.cpp
index 86c471d2c629505..cca2f8c30247e00 100644
--- a/flang/unittests/Evaluate/intrinsics.cpp
+++ b/flang/unittests/Evaluate/intrinsics.cpp
@@ -1,10 +1,10 @@
 #include "flang/Evaluate/intrinsics.h"
-#include "testing.h"
 #include "flang/Evaluate/common.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Evaluate/target.h"
 #include "flang/Evaluate/tools.h"
 #include "flang/Parser/provenance.h"
+#include "flang/Testing/testing.h"
 #include "llvm/Support/raw_ostream.h"
 #include <initializer_list>
 #include <map>
diff --git a/flang/unittests/Evaluate/leading-zero-bit-count.cpp b/flang/unittests/Evaluate/leading-zero-bit-count.cpp
index 968946b69f27ead..25e2664e76df04e 100644
--- a/flang/unittests/Evaluate/leading-zero-bit-count.cpp
+++ b/flang/unittests/Evaluate/leading-zero-bit-count.cpp
@@ -1,5 +1,5 @@
 #include "flang/Common/leading-zero-bit-count.h"
-#include "testing.h"
+#include "flang/Testing/testing.h"
 
 using Fortran::common::LeadingZeroBitCount;
 
diff --git a/flang/unittests/Evaluate/logical.cpp b/flang/unittests/Evaluate/logical.cpp
index d79aff844871235..ba7d0d8d0c0e3a2 100644
--- a/flang/unittests/Evaluate/logical.cpp
+++ b/flang/unittests/Evaluate/logical.cpp
@@ -1,5 +1,5 @@
-#include "testing.h"
 #include "flang/Evaluate/type.h"
+#include "flang/Testing/testing.h"
 #include <cstdio>
 
 template <int KIND> void testKind() {
diff --git a/flang/unittests/Evaluate/real.cpp b/flang/unittests/Evaluate/real.cpp
index 1bf7fa1016a9e93..a28da5c3273ceb9 100644
--- a/flang/unittests/Evaluate/real.cpp
+++ b/flang/unittests/Evaluate/real.cpp
@@ -1,6 +1,6 @@
-#include "fp-testing.h"
-#include "testing.h"
 #include "flang/Evaluate/type.h"
+#include "flang/Testing/fp-testing.h"
+#include "flang/Testing/testing.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cmath>
 #include <cstdio>
diff --git a/flang/unittests/Evaluate/reshape.cpp b/flang/unittests/Evaluate/reshape.cpp
index 5d138cd3d88d98b..16cba15dcef6084 100644
--- a/flang/unittests/Evaluate/reshape.cpp
+++ b/flang/unittests/Evaluate/reshape.cpp
@@ -1,6 +1,6 @@
-#include "testing.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/transformational.h"
+#include "flang/Testing/testing.h"
 #include <cinttypes>
 
 using namespace Fortran::common;
diff --git a/flang/unittests/Evaluate/uint128.cpp b/flang/unittests/Evaluate/uint128.cpp
index f05c1c96a7e8b02..0b749abe1c080a5 100644
--- a/flang/unittests/Evaluate/uint128.cpp
+++ b/flang/unittests/Evaluate/uint128.cpp
@@ -1,6 +1,6 @@
 #define AVOID_NATIVE_UINT128_T 1
 #include "flang/Common/uint128.h"
-#include "testing.h"
+#include "flang/Testing/testing.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cinttypes>
 

>From 2e50a1f563dcfec3dae1a5770ed4c90189cf7ba8 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 24 Jan 2025 16:28:55 +0100
Subject: [PATCH 03/18] [Flang] Don't use FortranDecimal for runtime

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp    |  3 +-
 clang/lib/Driver/ToolChains/Flang.cpp         |  4 -
 flang/docs/FlangDriver.md                     |  7 +-
 flang/lib/Decimal/CMakeLists.txt              | 92 ++-----------------
 flang/runtime/CMakeLists.txt                  | 14 +--
 flang/test/Driver/linker-flags.f90            |  6 +-
 .../test/Driver/msvc-dependent-lib-flags.f90  |  4 -
 flang/test/Driver/nostdlib.f90                |  1 -
 flang/test/Runtime/no-cpp-dep.c               |  2 +-
 flang/test/lit.cfg.py                         |  3 -
 lld/COFF/MinGW.cpp                            |  1 -
 11 files changed, 18 insertions(+), 119 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index f8967890f722cf8..b5273dd8cf1e3a5 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1321,7 +1321,7 @@ void tools::addOpenMPHostOffloadingArgs(const Compilation &C,
 /// Add Fortran runtime libs
 void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
                                   llvm::opt::ArgStringList &CmdArgs) {
-  // Link FortranRuntime and FortranDecimal
+  // Link FortranRuntime
   // These are handled earlier on Windows by telling the frontend driver to
   // add the correct libraries to link against as dependents in the object
   // file.
@@ -1338,7 +1338,6 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
         addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
     }
     CmdArgs.push_back("-lFortranRuntime");
-    CmdArgs.push_back("-lFortranDecimal");
     addArchSpecificRPath(TC, Args, CmdArgs);
   }
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 86ed25badfa2b71..f1bf32b32382704 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -361,21 +361,18 @@ static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args,
     CmdArgs.push_back("-D_MT");
     CmdArgs.push_back("--dependent-lib=libcmt");
     CmdArgs.push_back("--dependent-lib=FortranRuntime.static.lib");
-    CmdArgs.push_back("--dependent-lib=FortranDecimal.static.lib");
     break;
   case options::OPT__SLASH_MTd:
     CmdArgs.push_back("-D_MT");
     CmdArgs.push_back("-D_DEBUG");
     CmdArgs.push_back("--dependent-lib=libcmtd");
     CmdArgs.push_back("--dependent-lib=FortranRuntime.static_dbg.lib");
-    CmdArgs.push_back("--dependent-lib=FortranDecimal.static_dbg.lib");
     break;
   case options::OPT__SLASH_MD:
     CmdArgs.push_back("-D_MT");
     CmdArgs.push_back("-D_DLL");
     CmdArgs.push_back("--dependent-lib=msvcrt");
     CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic.lib");
-    CmdArgs.push_back("--dependent-lib=FortranDecimal.dynamic.lib");
     break;
   case options::OPT__SLASH_MDd:
     CmdArgs.push_back("-D_MT");
@@ -383,7 +380,6 @@ static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args,
     CmdArgs.push_back("-D_DLL");
     CmdArgs.push_back("--dependent-lib=msvcrtd");
     CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic_dbg.lib");
-    CmdArgs.push_back("--dependent-lib=FortranDecimal.dynamic_dbg.lib");
     break;
   }
 }
diff --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index 23cbab30ee903e5..be5633529f50cda 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -175,19 +175,18 @@ like this:
 
 ```
 $ flang -v -o example example.o
-"/usr/bin/ld" [...] example.o [...] "-lFortranRuntime" "-lFortranDecimal" [...]
+"/usr/bin/ld" [...] example.o [...] "-lFortranRuntime" [...]
 ```
 
 The automatically added libraries are:
 
 * `FortranRuntime`: Provides most of the Flang runtime library.
-* `FortranDecimal`: Provides operations for decimal numbers.
 
 If the code is C/C++ based and invokes Fortran routines, one can either use Clang
 or Flang as the linker driver.  If Clang is used, it will automatically all
 required runtime libraries needed by C++ (e.g., for STL) to the linker invocation.
-In this case, one has to explicitly provide the Fortran runtime libraries
-`FortranRuntime` and/or `FortranDecimal`.  An alternative is to use Flang to link.
+In this case, one has to explicitly provide the Fortran runtime library
+`FortranRuntime`.  An alternative is to use Flang to link.
 In this case, it may be required to explicitly supply C++ runtime libraries.
 
 On Darwin, the logical root where the system libraries are located (sysroot)
diff --git a/flang/lib/Decimal/CMakeLists.txt b/flang/lib/Decimal/CMakeLists.txt
index 880b190f1c5815a..477d44e0565ebe0 100644
--- a/flang/lib/Decimal/CMakeLists.txt
+++ b/flang/lib/Decimal/CMakeLists.txt
@@ -1,86 +1,12 @@
-if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
-  cmake_minimum_required(VERSION 3.20.0)
-
-  project(FortranDecimal C CXX)
-
-  set(CMAKE_CXX_STANDARD 17)
-  set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
-  set(CMAKE_CXX_EXTENSIONS OFF)
-
-  set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")
-
-  set(LLVM_COMMON_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../cmake")
-  set(LLVM_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../llvm/cmake")
-  set(CLANG_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../clang/cmake")
-
-  # Add path for custom modules
-  list(INSERT CMAKE_MODULE_PATH 0
-    "${FLANG_SOURCE_DIR}/cmake"
-    "${FLANG_SOURCE_DIR}/cmake/modules"
-    "${LLVM_COMMON_CMAKE_UTILS}"
-    "${LLVM_COMMON_CMAKE_UTILS}/Modules"
-    "${LLVM_CMAKE_UTILS}"
-    "${LLVM_CMAKE_UTILS}/modules"
-    "${CLANG_CMAKE_UTILS}/modules"
-    )
-
-  include(AddClang)
-  include(AddLLVM)
-  include(AddFlang)
-  include(HandleLLVMOptions)
-
-  include(TestBigEndian)
-  test_big_endian(IS_BIGENDIAN)
-  if (IS_BIGENDIAN)
-    add_compile_definitions(FLANG_BIG_ENDIAN=1)
-  else ()
-    add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
-  endif ()
-  include_directories(BEFORE
-    ${FLANG_SOURCE_DIR}/include)
-endif()
-
-check_cxx_compiler_flag(-fno-lto FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
-if (FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
-  append("-fno-lto" CMAKE_CXX_FLAGS)
-endif()
-
-# Disable libstdc++ assertions, even in an LLVM_ENABLE_ASSERTIONS build, to
-# avoid an unwanted dependency on libstdc++.so.
-add_definitions(-U_GLIBCXX_ASSERTIONS)
-
-set(sources
+#===-- lib/Decimal/CMakeLists.txt ------------------------------------------===#
+#
+# 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
+#
+#===------------------------------------------------------------------------===#
+
+add_flang_library(FortranDecimal
   binary-to-decimal.cpp
   decimal-to-binary.cpp
 )
-
-include(AddFlangOffloadRuntime)
-enable_cuda_compilation(FortranDecimal "${sources}")
-enable_omp_offload_compilation("${sources}")
-
-add_flang_library(FortranDecimal INSTALL_WITH_TOOLCHAIN ${sources})
-
-if (DEFINED MSVC)
-  set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
-  add_flang_library(FortranDecimal.static INSTALL_WITH_TOOLCHAIN
-          binary-to-decimal.cpp
-          decimal-to-binary.cpp
-  )
-  set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
-  add_flang_library(FortranDecimal.dynamic INSTALL_WITH_TOOLCHAIN
-    binary-to-decimal.cpp
-    decimal-to-binary.cpp
-  )
-  set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
-  add_flang_library(FortranDecimal.static_dbg INSTALL_WITH_TOOLCHAIN
-          binary-to-decimal.cpp
-          decimal-to-binary.cpp
-  )
-  set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL)
-  add_flang_library(FortranDecimal.dynamic_dbg INSTALL_WITH_TOOLCHAIN
-    binary-to-decimal.cpp
-    decimal-to-binary.cpp
-  )
-  add_dependencies(FortranDecimal FortranDecimal.static FortranDecimal.dynamic
-    FortranDecimal.static_dbg FortranDecimal.dynamic_dbg)
-endif()
diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index fbfaae9a8806486..6343c4276f0e3e1 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -111,6 +111,8 @@ add_definitions(-U_LIBCPP_ENABLE_ASSERTIONS)
 add_subdirectory(Float128Math)
 
 set(sources
+  ${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp
+  ${FLANG_SOURCE_DIR}/lib/Decimal/decimal-to-binary.cpp
   ISO_Fortran_binding.cpp
   allocator-registry.cpp
   allocatable.cpp
@@ -270,39 +272,27 @@ endif()
 if (NOT DEFINED MSVC)
   add_flang_library(FortranRuntime
     ${sources}
-    LINK_LIBS
-    FortranDecimal
 
     INSTALL_WITH_TOOLCHAIN
   )
 else()
   add_flang_library(FortranRuntime
     ${sources}
-    LINK_LIBS
-    FortranDecimal
   )
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
   add_flang_library(FortranRuntime.static ${sources}
-    LINK_LIBS
-    FortranDecimal.static
     INSTALL_WITH_TOOLCHAIN)
   set_target_properties(FortranRuntime.static PROPERTIES FOLDER "Flang/Runtime Libraries")
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
   add_flang_library(FortranRuntime.dynamic ${sources}
-    LINK_LIBS
-    FortranDecimal.dynamic
     INSTALL_WITH_TOOLCHAIN)
   set_target_properties(FortranRuntime.dynamic PROPERTIES FOLDER "Flang/Runtime Libraries")
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
   add_flang_library(FortranRuntime.static_dbg ${sources}
-    LINK_LIBS
-    FortranDecimal.static_dbg
     INSTALL_WITH_TOOLCHAIN)
   set_target_properties(FortranRuntime.static_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL)
   add_flang_library(FortranRuntime.dynamic_dbg ${sources}
-    LINK_LIBS
-    FortranDecimal.dynamic_dbg
     INSTALL_WITH_TOOLCHAIN)
   set_target_properties(FortranRuntime.dynamic_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
   add_dependencies(FortranRuntime FortranRuntime.static FortranRuntime.dynamic
diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90
index ac9500d7c45cecd..fdeb95e4dd97c63 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -33,7 +33,7 @@
 ! SOLARIS-F128NONE-NOT: FortranFloat128Math
 ! UNIX-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
 ! SOLARIS-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "-z" "ignore" "-lquadmath" "-z" "record"
-! UNIX-SAME: "-lFortranRuntime" "-lFortranDecimal" "-lm"
+! UNIX-SAME: "-lFortranRuntime" "-lm"
 ! COMPILER-RT: "{{.*}}{{\\|/}}libclang_rt.builtins.a"
 
 ! DARWIN-LABEL:  "{{.*}}ld{{(\.exe)?}}"
@@ -41,20 +41,18 @@
 ! DARWIN-F128NONE-NOT: FortranFloat128Math
 ! DARWIN-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
 ! DARWIN-SAME: -lFortranRuntime
-! DARWIN-SAME: -lFortranDecimal
 
 ! HAIKU-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! HAIKU-SAME: "[[object_file]]"
 ! HAIKU-F128NONE-NOT: FortranFloat128Math
 ! HAIKU-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
-! HAIKU-SAME: "-lFortranRuntime" "-lFortranDecimal"
+! HAIKU-SAME: "-lFortranRuntime"
 
 ! MINGW-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! MINGW-SAME: "[[object_file]]"
 ! MINGW-F128NONE-NOT: FortranFloat128Math
 ! MINGW-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
 ! MINGW-SAME: -lFortranRuntime
-! MINGW-SAME: -lFortranDecimal
 
 ! NOTE: This also matches lld-link (when CLANG_DEFAULT_LINKER=lld) and
 !       any .exe suffix that is added when resolving to the full path of
diff --git a/flang/test/Driver/msvc-dependent-lib-flags.f90 b/flang/test/Driver/msvc-dependent-lib-flags.f90
index 765917f07d8e723..befe61fdadcd141 100644
--- a/flang/test/Driver/msvc-dependent-lib-flags.f90
+++ b/flang/test/Driver/msvc-dependent-lib-flags.f90
@@ -8,7 +8,6 @@
 ! MSVC-SAME: -D_MT
 ! MSVC-SAME: --dependent-lib=libcmt
 ! MSVC-SAME: --dependent-lib=FortranRuntime.static.lib
-! MSVC-SAME: --dependent-lib=FortranDecimal.static.lib
 
 ! MSVC-DEBUG: -fc1
 ! MSVC-DEBUG-SAME: --dependent-lib=clang_rt.builtins.lib
@@ -16,7 +15,6 @@
 ! MSVC-DEBUG-SAME: -D_DEBUG
 ! MSVC-DEBUG-SAME: --dependent-lib=libcmtd
 ! MSVC-DEBUG-SAME: --dependent-lib=FortranRuntime.static_dbg.lib
-! MSVC-DEBUG-SAME: --dependent-lib=FortranDecimal.static_dbg.lib
 
 ! MSVC-DLL: -fc1
 ! MSVC-DLL-SAME: --dependent-lib=clang_rt.builtins.lib
@@ -24,7 +22,6 @@
 ! MSVC-DLL-SAME: -D_DLL
 ! MSVC-DLL-SAME: --dependent-lib=msvcrt
 ! MSVC-DLL-SAME: --dependent-lib=FortranRuntime.dynamic.lib
-! MSVC-DLL-SAME: --dependent-lib=FortranDecimal.dynamic.lib
 
 ! MSVC-DLL-DEBUG: -fc1
 ! MSVC-DLL-DEBUG-SAME: --dependent-lib=clang_rt.builtins.lib
@@ -33,4 +30,3 @@
 ! MSVC-DLL-DEBUG-SAME: -D_DLL
 ! MSVC-DLL-DEBUG-SAME: --dependent-lib=msvcrtd
 ! MSVC-DLL-DEBUG-SAME: --dependent-lib=FortranRuntime.dynamic_dbg.lib
-! MSVC-DLL-DEBUG-SAME: --dependent-lib=FortranDecimal.dynamic_dbg.lib
diff --git a/flang/test/Driver/nostdlib.f90 b/flang/test/Driver/nostdlib.f90
index cd707e632a45ff0..ab7c675fe7b77d5 100644
--- a/flang/test/Driver/nostdlib.f90
+++ b/flang/test/Driver/nostdlib.f90
@@ -25,5 +25,4 @@
 ! platform individually.
 
 ! CHECK-NOT: "-lFortranRuntime"
-! CHECK-NOT: "-lFortranDecimal"
 ! CHECK-NOT: "-lgcc"
diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang/test/Runtime/no-cpp-dep.c
index 606a5d189f71996..b1a5fa004014cc8 100644
--- a/flang/test/Runtime/no-cpp-dep.c
+++ b/flang/test/Runtime/no-cpp-dep.c
@@ -6,7 +6,7 @@ a C compiler.
 REQUIRES: c-compiler
 
 RUN: %if system-aix %{ export OBJECT_MODE=64 %}
-RUN: %cc -std=c99 %s -I%include %libruntime %libdecimal -lm  \
+RUN: %cc -std=c99 %s -I%include %libruntime -lm  \
 RUN: %if system-aix %{-lpthread %}
 RUN: rm a.out
 */
diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py
index f43234fb125b7e7..c452b6d231c89f0 100644
--- a/flang/test/lit.cfg.py
+++ b/flang/test/lit.cfg.py
@@ -168,12 +168,10 @@
 # we don't have one, we can just disable the test.
 if config.cc:
     libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a")
-    libdecimal = os.path.join(config.flang_lib_dir, "libFortranDecimal.a")
     include = os.path.join(config.flang_src_dir, "include")
 
     if (
         os.path.isfile(libruntime)
-        and os.path.isfile(libdecimal)
         and os.path.isdir(include)
     ):
         config.available_features.add("c-compiler")
@@ -183,7 +181,6 @@
             )
         )
         tools.append(ToolSubst("%libruntime", command=libruntime, unresolved="fatal"))
-        tools.append(ToolSubst("%libdecimal", command=libdecimal, unresolved="fatal"))
         tools.append(ToolSubst("%include", command=include, unresolved="fatal"))
 
 # Add all the tools and their substitutions (if applicable). Use the search paths provided for
diff --git a/lld/COFF/MinGW.cpp b/lld/COFF/MinGW.cpp
index 76f5a0a7500b9db..797ab37f0698108 100644
--- a/lld/COFF/MinGW.cpp
+++ b/lld/COFF/MinGW.cpp
@@ -51,7 +51,6 @@ AutoExporter::AutoExporter(
       "libc++",
       "libc++abi",
       "libFortranRuntime",
-      "libFortranDecimal",
       "libunwind",
       "libmsvcrt",
       "libucrtbase",

>From 4c676f468ba344ac0c388583a4ed28035d05ae89 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 24 Jan 2025 15:00:16 +0100
Subject: [PATCH 04/18] users/meinersbur/flang_runtime_FLANG_INCLUDE_RUNTIME

---
 flang/CMakeLists.txt                    |  6 +++++-
 flang/test/CMakeLists.txt               |  6 +++++-
 flang/test/Driver/ctofortran.f90        |  1 +
 flang/test/Driver/exec.f90              |  1 +
 flang/test/Runtime/no-cpp-dep.c         |  2 +-
 flang/test/lit.cfg.py                   |  5 ++++-
 flang/test/lit.site.cfg.py.in           |  2 ++
 flang/tools/f18/CMakeLists.txt          |  2 +-
 flang/unittests/CMakeLists.txt          | 11 +++++++++-
 flang/unittests/Evaluate/CMakeLists.txt | 27 +++++++++++++------------
 10 files changed, 44 insertions(+), 19 deletions(-)

diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index b619553ef830218..7d6dcb5c184a52d 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -247,6 +247,8 @@ else()
   include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR})
 endif()
 
+option(FLANG_INCLUDE_RUNTIME "Build the runtime in-tree (deprecated; to be replaced with LLVM_ENABLE_RUNTIMES=flang-rt)" ON)
+
 set(FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
     "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")
 mark_as_advanced(FLANG_TOOLS_INSTALL_DIR)
@@ -487,7 +489,9 @@ if (FLANG_CUF_RUNTIME)
   find_package(CUDAToolkit REQUIRED)
 endif()
 
-add_subdirectory(runtime)
+if (FLANG_INCLUDE_RUNTIME)
+  add_subdirectory(runtime)
+endif ()
 
 if (LLVM_INCLUDE_EXAMPLES)
   add_subdirectory(examples)
diff --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt
index cab214c2ef4c8c1..e398e0786147aa7 100644
--- a/flang/test/CMakeLists.txt
+++ b/flang/test/CMakeLists.txt
@@ -71,9 +71,13 @@ set(FLANG_TEST_DEPENDS
   llvm-objdump
   llvm-readobj
   split-file
-  FortranRuntime
   FortranDecimal
 )
+
+if (FLANG_INCLUDE_RUNTIME)
+  list(APPEND FLANG_TEST_DEPENDS FortranRuntime)
+endif ()
+
 if (LLVM_ENABLE_PLUGINS AND NOT WIN32)
   list(APPEND FLANG_TEST_DEPENDS Bye)
 endif()
diff --git a/flang/test/Driver/ctofortran.f90 b/flang/test/Driver/ctofortran.f90
index 78eac32133b18e1..10c7adaccc9588b 100644
--- a/flang/test/Driver/ctofortran.f90
+++ b/flang/test/Driver/ctofortran.f90
@@ -1,4 +1,5 @@
 ! UNSUPPORTED: system-windows
+! REQUIRES: flang-rt
 ! RUN: split-file %s %t
 ! RUN: chmod +x %t/runtest.sh
 ! RUN: %t/runtest.sh %t %t/ffile.f90 %t/cfile.c %flang | FileCheck %s
diff --git a/flang/test/Driver/exec.f90 b/flang/test/Driver/exec.f90
index fd174005ddf62ac..9ca91ee24011c9f 100644
--- a/flang/test/Driver/exec.f90
+++ b/flang/test/Driver/exec.f90
@@ -1,4 +1,5 @@
 ! UNSUPPORTED: system-windows
+! REQUIRES: flang-rt
 ! Verify that flang can correctly build executables.
 
 ! RUN: %flang %s -o %t
diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang/test/Runtime/no-cpp-dep.c
index b1a5fa004014cc8..7303ce63fdec410 100644
--- a/flang/test/Runtime/no-cpp-dep.c
+++ b/flang/test/Runtime/no-cpp-dep.c
@@ -3,7 +3,7 @@ This test makes sure that flang's runtime does not depend on the C++ runtime
 library. It tries to link this simple file against libFortranRuntime.a with
 a C compiler.
 
-REQUIRES: c-compiler
+REQUIRES: c-compiler, flang-rt
 
 RUN: %if system-aix %{ export OBJECT_MODE=64 %}
 RUN: %cc -std=c99 %s -I%include %libruntime -lm  \
diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py
index c452b6d231c89f0..f4580afc8c47b12 100644
--- a/flang/test/lit.cfg.py
+++ b/flang/test/lit.cfg.py
@@ -163,10 +163,13 @@
         ToolSubst("%not_todo_abort_cmd", command=FindTool("not"), unresolved="fatal")
     )
 
+if config.flang_include_runtime:
+    config.available_features.add("flang-rt")
+
 # Define some variables to help us test that the flang runtime doesn't depend on
 # the C++ runtime libraries. For this we need a C compiler. If for some reason
 # we don't have one, we can just disable the test.
-if config.cc:
+if config.flang_include_runtime and config.cc:
     libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a")
     include = os.path.join(config.flang_src_dir, "include")
 
diff --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in
index d1a0ac763cf8a06..697ba3fa797633d 100644
--- a/flang/test/lit.site.cfg.py.in
+++ b/flang/test/lit.site.cfg.py.in
@@ -1,6 +1,7 @@
 @LIT_SITE_CFG_IN_HEADER@
 
 import sys
+import lit.util
 
 config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
 config.llvm_shlib_dir = lit_config.substitute(path(r"@SHLIBDIR@"))
@@ -32,6 +33,7 @@ else:
     config.openmp_module_dir = None
 config.flang_runtime_f128_math_lib = "@FLANG_RUNTIME_F128_MATH_LIB@"
 config.have_ldbl_mant_dig_113 = "@HAVE_LDBL_MANT_DIG_113@"
+config.flang_include_runtime = lit.util.pythonize_bool("@FLANG_INCLUDE_RUNTIME@")
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)
diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index cc2bc5b8eb5ce23..85ba2c74cdeb5c4 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -109,7 +109,7 @@ if (NOT CMAKE_CROSSCOMPILING)
     set(compile_with "-fsyntax-only")
     set(object_output "")
     set(include_in_link FALSE)
-    if(${filename} IN_LIST MODULES_WITH_IMPLEMENTATION)
+    if(${filename} IN_LIST MODULES_WITH_IMPLEMENTATION AND FLANG_INCLUDE_RUNTIME)
       set(object_output "${CMAKE_CURRENT_BINARY_DIR}/${filename}${CMAKE_CXX_OUTPUT_EXTENSION}")
       set(compile_with -c -o ${object_output})
       set(include_in_link TRUE)
diff --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt
index 945067fed4f82d0..ecb7d68d8f72966 100644
--- a/flang/unittests/CMakeLists.txt
+++ b/flang/unittests/CMakeLists.txt
@@ -1,3 +1,5 @@
+include(AddFlangOffloadRuntime)
+
 if (FLANG_EXPERIMENTAL_CUDA_RUNTIME)
   # If Fortran runtime is built as CUDA library, the linking
   # of targets that link FortranRuntime must be done
@@ -11,6 +13,11 @@ add_custom_target(FlangUnitTests)
 set_target_properties(FlangUnitTests PROPERTIES FOLDER "Flang/Tests")
 
 function(add_flang_unittest_offload_properties target)
+  # Do not apply runtime properties if not even compiling the runtime.
+  if (NOT FLANG_INCLUDE_RUNTIME)
+    return ()
+  endif ()
+
   # Set CUDA_RESOLVE_DEVICE_SYMBOLS.
   if (FLANG_EXPERIMENTAL_CUDA_RUNTIME)
     set_target_properties(${target}
@@ -75,5 +82,7 @@ add_subdirectory(Optimizer)
 add_subdirectory(Common)
 add_subdirectory(Decimal)
 add_subdirectory(Evaluate)
-add_subdirectory(Runtime)
+if (FLANG_INCLUDE_RUNTIME)
+  add_subdirectory(Runtime)
+endif ()
 add_subdirectory(Frontend)
diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt
index 8111ecd72cfc7d6..1c3fac29cd2982e 100644
--- a/flang/unittests/Evaluate/CMakeLists.txt
+++ b/flang/unittests/Evaluate/CMakeLists.txt
@@ -33,7 +33,6 @@ add_flang_nongtest_unittest(intrinsics
   FortranDecimal
   FortranSemantics
   FortranParser
-  FortranRuntime
 )
 
 add_flang_nongtest_unittest(logical
@@ -56,19 +55,21 @@ add_flang_nongtest_unittest(real
 )
 llvm_update_compile_flags(real.test)
 
-add_flang_nongtest_unittest(reshape
-  NonGTestTesting
-  FortranSemantics
-  FortranEvaluate
-  FortranRuntime
-)
+if (FLANG_INCLUDE_RUNTIME)
+  add_flang_nongtest_unittest(reshape
+    NonGTestTesting
+    FortranSemantics
+    FortranEvaluate
+    FortranRuntime
+  )
 
-add_flang_nongtest_unittest(ISO-Fortran-binding
-  NonGTestTesting
-  FortranEvaluate
-  FortranSemantics
-  FortranRuntime
-)
+  add_flang_nongtest_unittest(ISO-Fortran-binding
+    NonGTestTesting
+    FortranEvaluate
+    FortranSemantics
+    FortranRuntime
+  )
+endif ()
 
 add_flang_nongtest_unittest(folding
   FortranSupport

>From 875607fdecfada90a80ec732637ea9595fe72ba3 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 24 Jan 2025 16:42:24 +0100
Subject: [PATCH 05/18] [Flang] Rename libFortranRuntime.a to libflang_rt.a

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp    |  4 +-
 clang/lib/Driver/ToolChains/Flang.cpp         |  8 ++--
 flang/CMakeLists.txt                          |  2 +-
 flang/docs/FlangDriver.md                     |  6 +--
 flang/docs/GettingStarted.md                  |  6 +--
 flang/docs/OpenACC-descriptor-management.md   |  2 +-
 flang/docs/ReleaseNotes.md                    |  2 +
 .../ExternalHelloWorld/CMakeLists.txt         |  2 +-
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp |  2 +-
 flang/runtime/CMakeLists.txt                  | 40 +++++++++++--------
 flang/runtime/CUDA/CMakeLists.txt             |  2 +-
 flang/runtime/Float128Math/CMakeLists.txt     |  2 +-
 flang/runtime/time-intrinsic.cpp              |  2 +-
 flang/test/CMakeLists.txt                     |  8 +++-
 .../test/Driver/gcc-toolchain-install-dir.f90 |  2 +-
 flang/test/Driver/linker-flags.f90            |  8 ++--
 .../test/Driver/msvc-dependent-lib-flags.f90  |  8 ++--
 flang/test/Driver/nostdlib.f90                |  2 +-
 flang/test/Runtime/no-cpp-dep.c               |  2 +-
 flang/test/lit.cfg.py                         |  2 +-
 flang/tools/f18/CMakeLists.txt                |  8 ++--
 flang/unittests/CMakeLists.txt                |  2 +-
 flang/unittests/Evaluate/CMakeLists.txt       |  4 +-
 flang/unittests/Runtime/CMakeLists.txt        |  2 +-
 flang/unittests/Runtime/CUDA/CMakeLists.txt   |  2 +-
 lld/COFF/MinGW.cpp                            |  2 +-
 26 files changed, 73 insertions(+), 59 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index b5273dd8cf1e3a5..c7b0a660ee021fc 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1321,7 +1321,7 @@ void tools::addOpenMPHostOffloadingArgs(const Compilation &C,
 /// Add Fortran runtime libs
 void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
                                   llvm::opt::ArgStringList &CmdArgs) {
-  // Link FortranRuntime
+  // Link flang_rt
   // These are handled earlier on Windows by telling the frontend driver to
   // add the correct libraries to link against as dependents in the object
   // file.
@@ -1337,7 +1337,7 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
       if (AsNeeded)
         addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
     }
-    CmdArgs.push_back("-lFortranRuntime");
+    CmdArgs.push_back("-lflang_rt");
     addArchSpecificRPath(TC, Args, CmdArgs);
   }
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index f1bf32b32382704..68a17edf8ca341f 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -360,26 +360,26 @@ static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args,
   case options::OPT__SLASH_MT:
     CmdArgs.push_back("-D_MT");
     CmdArgs.push_back("--dependent-lib=libcmt");
-    CmdArgs.push_back("--dependent-lib=FortranRuntime.static.lib");
+    CmdArgs.push_back("--dependent-lib=flang_rt.static.lib");
     break;
   case options::OPT__SLASH_MTd:
     CmdArgs.push_back("-D_MT");
     CmdArgs.push_back("-D_DEBUG");
     CmdArgs.push_back("--dependent-lib=libcmtd");
-    CmdArgs.push_back("--dependent-lib=FortranRuntime.static_dbg.lib");
+    CmdArgs.push_back("--dependent-lib=flang_rt.static_dbg.lib");
     break;
   case options::OPT__SLASH_MD:
     CmdArgs.push_back("-D_MT");
     CmdArgs.push_back("-D_DLL");
     CmdArgs.push_back("--dependent-lib=msvcrt");
-    CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic.lib");
+    CmdArgs.push_back("--dependent-lib=flang_rt.dynamic.lib");
     break;
   case options::OPT__SLASH_MDd:
     CmdArgs.push_back("-D_MT");
     CmdArgs.push_back("-D_DEBUG");
     CmdArgs.push_back("-D_DLL");
     CmdArgs.push_back("--dependent-lib=msvcrtd");
-    CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic_dbg.lib");
+    CmdArgs.push_back("--dependent-lib=flang_rt.dynamic_dbg.lib");
     break;
   }
 }
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 7d6dcb5c184a52d..8a8b8bfa73b0077 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -301,7 +301,7 @@ set(FLANG_DEFAULT_LINKER "" CACHE STRING
   "Default linker to use (linker name or absolute path, empty for platform default)")
 
 set(FLANG_DEFAULT_RTLIB "" CACHE STRING
-   "Default Fortran runtime library to use (\"libFortranRuntime\"), leave empty for platform default.")
+   "Default Fortran runtime library to use (\"libflang_rt\"), leave empty for platform default.")
 
 if (NOT(FLANG_DEFAULT_RTLIB STREQUAL ""))
   message(WARNING "Resetting Flang's default runtime library to use platform default.")
diff --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index be5633529f50cda..f3a732b03989003 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -175,18 +175,18 @@ like this:
 
 ```
 $ flang -v -o example example.o
-"/usr/bin/ld" [...] example.o [...] "-lFortranRuntime" [...]
+"/usr/bin/ld" [...] example.o [...] "-lflang_rt" [...]
 ```
 
 The automatically added libraries are:
 
-* `FortranRuntime`: Provides most of the Flang runtime library.
+* `flang_rt`: Provides most of the Flang runtime library.
 
 If the code is C/C++ based and invokes Fortran routines, one can either use Clang
 or Flang as the linker driver.  If Clang is used, it will automatically all
 required runtime libraries needed by C++ (e.g., for STL) to the linker invocation.
 In this case, one has to explicitly provide the Fortran runtime library
-`FortranRuntime`.  An alternative is to use Flang to link.
+`flang_rt`.  An alternative is to use Flang to link.
 In this case, it may be required to explicitly supply C++ runtime libraries.
 
 On Darwin, the logical root where the system libraries are located (sysroot)
diff --git a/flang/docs/GettingStarted.md b/flang/docs/GettingStarted.md
index 1c85a6754b155b9..ffde50b6f481e88 100644
--- a/flang/docs/GettingStarted.md
+++ b/flang/docs/GettingStarted.md
@@ -216,7 +216,7 @@ cmake \
   -DCMAKE_CUDA_COMPILER=clang \
   -DCMAKE_CUDA_HOST_COMPILER=clang++ \
   ../runtime/
-make -j FortranRuntime
+make -j flang-rt
 ```
 
 Note that the used version of `clang` must [support](https://releases.llvm.org/16.0.0/tools/clang/docs/ReleaseNotes.html#cuda-support)
@@ -239,7 +239,7 @@ cmake \
   -DCMAKE_CUDA_HOST_COMPILER=clang++ \
   ../runtime/
 
-make -j FortranRuntime
+make -j flang-rt
 ```
 
 Note that `nvcc` might limit support to certain
@@ -294,7 +294,7 @@ cmake \
   -DFLANG_OMP_DEVICE_ARCHITECTURES="all" \
   ../runtime/
 
-make -j FortranRuntime
+make -j flang-rt
 ```
 
 The result of the build is a "device-only" library, i.e. the host
diff --git a/flang/docs/OpenACC-descriptor-management.md b/flang/docs/OpenACC-descriptor-management.md
index 52d00ae4daef88c..6c147a56894c8f5 100644
--- a/flang/docs/OpenACC-descriptor-management.md
+++ b/flang/docs/OpenACC-descriptor-management.md
@@ -427,7 +427,7 @@ The implementation's behavior may be described as (OpenACC 2.7.2):
 
 All the "is-present" checks and the data actions for the auxiliary pointers must be performed atomically with regards to the present counters bookkeeping.
 
-The API relies on the primitives provided by `liboffload`, so it is provided by a new F18 runtime library, e.g. `FortranOffloadRuntime`, that depends on `FortranRuntime` and `liboffload`.  The F18 driver adds `FortranOffloadRuntime` for linking under `-fopenacc`/`-fopenmp` (and maybe additional switches like `-fopenmp-targets`).
+The API relies on the primitives provided by `liboffload`, so it is provided by a new F18 runtime library, e.g. `FortranOffloadRuntime`, that depends on `flang_rt` and `liboffload`.  The F18 driver adds `FortranOffloadRuntime` for linking under `-fopenacc`/`-fopenmp` (and maybe additional switches like `-fopenmp-targets`).
 
 ## TODOs:
 
diff --git a/flang/docs/ReleaseNotes.md b/flang/docs/ReleaseNotes.md
index f0c956281915f4d..a163b4f4ed67dee 100644
--- a/flang/docs/ReleaseNotes.md
+++ b/flang/docs/ReleaseNotes.md
@@ -36,6 +36,8 @@ page](https://llvm.org/releases/).
 
 ## Build System Changes
 
+ * FortranRuntime has been renamed to `flang_rt`.
+
 ## New Issues Found
 
 
diff --git a/flang/examples/ExternalHelloWorld/CMakeLists.txt b/flang/examples/ExternalHelloWorld/CMakeLists.txt
index 042d4b6238ba45c..213fc462ac2b1a0 100644
--- a/flang/examples/ExternalHelloWorld/CMakeLists.txt
+++ b/flang/examples/ExternalHelloWorld/CMakeLists.txt
@@ -5,5 +5,5 @@ add_llvm_example(external-hello-world
 
 target_link_libraries(external-hello-world
   PRIVATE
-  FortranRuntime
+  flang_rt
   )
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 77256a51fa7f718..29ab0ab9a75f3f6 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -784,7 +784,7 @@ prettyPrintIntrinsicName(fir::FirOpBuilder &builder, mlir::Location loc,
 // Generate a call to the Fortran runtime library providing
 // support for 128-bit float math.
 // On 'HAS_LDBL128' targets the implementation
-// is provided by FortranRuntime, otherwise, it is done via
+// is provided by flang_rt, otherwise, it is done via
 // FortranFloat128Math library. In the latter case the compiler
 // has to be built with FLANG_RUNTIME_F128_MATH_LIB to guarantee
 // proper linking actions in the driver.
diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index 6343c4276f0e3e1..3e32daba52a818b 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -236,13 +236,13 @@ set(supported_files
   utf.cpp
   )
 
-enable_cuda_compilation(FortranRuntime "${supported_files}")
+enable_cuda_compilation(flang_rt "${supported_files}")
 enable_omp_offload_compilation("${supported_files}")
 
 if (NOT TARGET FortranFloat128Math)
   # If FortranFloat128Math is not defined, then we are not building
   # standalone FortranFloat128Math library. Instead, include
-  # the relevant sources into FortranRuntime itself.
+  # the relevant sources into flang_rt itself.
   # The information is provided via FortranFloat128MathILib
   # interface library.
   get_target_property(f128_sources
@@ -270,37 +270,37 @@ if (NOT TARGET FortranFloat128Math)
 endif()
 
 if (NOT DEFINED MSVC)
-  add_flang_library(FortranRuntime
+  add_flang_library(flang_rt
     ${sources}
 
     INSTALL_WITH_TOOLCHAIN
   )
 else()
-  add_flang_library(FortranRuntime
+  add_flang_library(flang_rt
     ${sources}
   )
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
-  add_flang_library(FortranRuntime.static ${sources}
+  add_flang_library(flang_rt.static ${sources}
     INSTALL_WITH_TOOLCHAIN)
-  set_target_properties(FortranRuntime.static PROPERTIES FOLDER "Flang/Runtime Libraries")
+  set_target_properties(flang_rt.static PROPERTIES FOLDER "Flang/Runtime Libraries")
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
-  add_flang_library(FortranRuntime.dynamic ${sources}
+  add_flang_library(flang_rt.dynamic ${sources}
     INSTALL_WITH_TOOLCHAIN)
-  set_target_properties(FortranRuntime.dynamic PROPERTIES FOLDER "Flang/Runtime Libraries")
+  set_target_properties(flang_rt.dynamic PROPERTIES FOLDER "Flang/Runtime Libraries")
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
-  add_flang_library(FortranRuntime.static_dbg ${sources}
+  add_flang_library(flang_rt.static_dbg ${sources}
     INSTALL_WITH_TOOLCHAIN)
-  set_target_properties(FortranRuntime.static_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
+  set_target_properties(flang_rt.static_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL)
-  add_flang_library(FortranRuntime.dynamic_dbg ${sources}
+  add_flang_library(flang_rt.dynamic_dbg ${sources}
     INSTALL_WITH_TOOLCHAIN)
-  set_target_properties(FortranRuntime.dynamic_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
-  add_dependencies(FortranRuntime FortranRuntime.static FortranRuntime.dynamic
-    FortranRuntime.static_dbg FortranRuntime.dynamic_dbg)
+  set_target_properties(flang_rt.dynamic_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
+  add_dependencies(flang_rt flang_rt.static flang_rt.dynamic
+    flang_rt.static_dbg flang_rt.dynamic_dbg)
 endif()
-set_target_properties(FortranRuntime PROPERTIES FOLDER "Flang/Runtime Libraries")
+set_target_properties(flang_rt PROPERTIES FOLDER "Flang/Runtime Libraries")
 
-# If FortranRuntime is part of a Flang build (and not a separate build) then
+# If flang_rt is part of a Flang build (and not a separate build) then
 # add dependency to make sure that Fortran runtime library is being built after
 # we have the Flang compiler available.  This also includes the MODULE files
 # that compile when the 'flang' target is built.
@@ -308,9 +308,15 @@ set_target_properties(FortranRuntime PROPERTIES FOLDER "Flang/Runtime Libraries"
 # TODO: This is a workaround and should be updated when runtime build procedure
 # is changed to a regular runtime build.  See discussion in PR #95388.
 if (TARGET flang AND TARGET module_files)
-  add_dependencies(FortranRuntime flang module_files)
+  add_dependencies(flang_rt flang module_files)
 endif()
 
 if (FLANG_CUF_RUNTIME)
   add_subdirectory(CUDA)
 endif()
+
+# Compatibility targets.
+add_custom_target(flang-rt)
+add_dependencies(flang-rt flang_rt)
+add_custom_target(FortranRuntime)
+add_dependencies(FortranRuntime flang_rt)
diff --git a/flang/runtime/CUDA/CMakeLists.txt b/flang/runtime/CUDA/CMakeLists.txt
index 3a88824826de311..744df95267e6fc8 100644
--- a/flang/runtime/CUDA/CMakeLists.txt
+++ b/flang/runtime/CUDA/CMakeLists.txt
@@ -31,6 +31,6 @@ endif()
 
 target_link_libraries(${CUFRT_LIBNAME}
   PRIVATE
-  FortranRuntime
+  flang_rt
   ${CUDA_RT_TARGET}
 )
diff --git a/flang/runtime/Float128Math/CMakeLists.txt b/flang/runtime/Float128Math/CMakeLists.txt
index 703f85fcaf8dacb..d65193be05ab5c1 100644
--- a/flang/runtime/Float128Math/CMakeLists.txt
+++ b/flang/runtime/Float128Math/CMakeLists.txt
@@ -118,7 +118,7 @@ elseif (HAVE_LDBL_MANT_DIG_113)
       )
     target_sources(FortranFloat128MathILib INTERFACE ${sources})
   else()
-    message(FATAL_ERROR "FortranRuntime cannot build without libm")
+    message(FATAL_ERROR "flang_rt cannot build without libm")
   endif()
 else()
   # We can use '__float128' version from libc, if it has them.
diff --git a/flang/runtime/time-intrinsic.cpp b/flang/runtime/time-intrinsic.cpp
index e6f6e81c7b50cca..942604a92aaad79 100644
--- a/flang/runtime/time-intrinsic.cpp
+++ b/flang/runtime/time-intrinsic.cpp
@@ -62,7 +62,7 @@ template <typename Unused = void> double GetCpuTime(fallback_implementation) {
 
 #if defined __MINGW32__
 // clock_gettime is implemented in the pthread library for MinGW.
-// Using it here would mean that all programs that link libFortranRuntime are
+// Using it here would mean that all programs that link libflang_rt are
 // required to also link to pthread. Instead, don't use the function.
 #undef CLOCKID_CPU_TIME
 #undef CLOCKID_ELAPSED_TIME
diff --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt
index e398e0786147aa7..e8e8099d4eaf7bc 100644
--- a/flang/test/CMakeLists.txt
+++ b/flang/test/CMakeLists.txt
@@ -75,7 +75,7 @@ set(FLANG_TEST_DEPENDS
 )
 
 if (FLANG_INCLUDE_RUNTIME)
-  list(APPEND FLANG_TEST_DEPENDS FortranRuntime)
+  list(APPEND FLANG_TEST_DEPENDS flang_rt)
 endif ()
 
 if (LLVM_ENABLE_PLUGINS AND NOT WIN32)
@@ -124,3 +124,9 @@ if (DEFINED FLANG_TEST_TARGET_TRIPLE)
                         "to use FLANG_TEST_TARGET_TRIPLE.")
   endif()
 endif()
+
+# Compatibility targets.
+if (FLANG_INCLUDE_RUNTIME)
+  add_custom_target(check-flang-rt)
+  add_dependencies(check-flang-rt check-flang)
+endif ()
diff --git a/flang/test/Driver/gcc-toolchain-install-dir.f90 b/flang/test/Driver/gcc-toolchain-install-dir.f90
index 5a073b0c517122a..d9160e1971250fe 100644
--- a/flang/test/Driver/gcc-toolchain-install-dir.f90
+++ b/flang/test/Driver/gcc-toolchain-install-dir.f90
@@ -1,5 +1,5 @@
 !! Test that --gcc-toolchain and --gcc-install-dir options are working as expected.
-!! It does not test cross-compiling (--sysroot), so crtbegin.o, libgcc/compiler-rt, libc, libFortranRuntime, etc. are not supposed to be affected.
+!! It does not test cross-compiling (--sysroot), so crtbegin.o, libgcc/compiler-rt, libc, libflang_rt, etc. are not supposed to be affected.
 !! PREFIX is captured twice because the driver escapes backslashes (occuring in Windows paths) in the -### output, but not on the "Selected GCC installation:" line.
 
 ! RUN: %flang 2>&1 -### -v -o %t %s -no-integrated-as -fuse-ld=ld --target=i386-unknown-linux-gnu --gcc-install-dir=%S/Inputs/basic_cross_linux_tree/usr/lib/gcc/i386-unknown-linux-gnu/10.2.0 | FileCheck %s --check-prefix=CHECK-I386
diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90
index fdeb95e4dd97c63..5dc89fe45c8cc0d 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -33,26 +33,26 @@
 ! SOLARIS-F128NONE-NOT: FortranFloat128Math
 ! UNIX-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
 ! SOLARIS-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "-z" "ignore" "-lquadmath" "-z" "record"
-! UNIX-SAME: "-lFortranRuntime" "-lm"
+! UNIX-SAME: "-lflang_rt" "-lm"
 ! COMPILER-RT: "{{.*}}{{\\|/}}libclang_rt.builtins.a"
 
 ! DARWIN-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! DARWIN-SAME: "[[object_file]]"
 ! DARWIN-F128NONE-NOT: FortranFloat128Math
 ! DARWIN-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
-! DARWIN-SAME: -lFortranRuntime
+! DARWIN-SAME: -lflang_rt
 
 ! HAIKU-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! HAIKU-SAME: "[[object_file]]"
 ! HAIKU-F128NONE-NOT: FortranFloat128Math
 ! HAIKU-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
-! HAIKU-SAME: "-lFortranRuntime"
+! HAIKU-SAME: "-lflang_rt"
 
 ! MINGW-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! MINGW-SAME: "[[object_file]]"
 ! MINGW-F128NONE-NOT: FortranFloat128Math
 ! MINGW-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
-! MINGW-SAME: -lFortranRuntime
+! MINGW-SAME: -lflang_rt
 
 ! NOTE: This also matches lld-link (when CLANG_DEFAULT_LINKER=lld) and
 !       any .exe suffix that is added when resolving to the full path of
diff --git a/flang/test/Driver/msvc-dependent-lib-flags.f90 b/flang/test/Driver/msvc-dependent-lib-flags.f90
index befe61fdadcd141..dabac56d602d1e1 100644
--- a/flang/test/Driver/msvc-dependent-lib-flags.f90
+++ b/flang/test/Driver/msvc-dependent-lib-flags.f90
@@ -7,21 +7,21 @@
 ! MSVC-SAME: --dependent-lib=clang_rt.builtins.lib
 ! MSVC-SAME: -D_MT
 ! MSVC-SAME: --dependent-lib=libcmt
-! MSVC-SAME: --dependent-lib=FortranRuntime.static.lib
+! MSVC-SAME: --dependent-lib=flang_rt.static.lib
 
 ! MSVC-DEBUG: -fc1
 ! MSVC-DEBUG-SAME: --dependent-lib=clang_rt.builtins.lib
 ! MSVC-DEBUG-SAME: -D_MT
 ! MSVC-DEBUG-SAME: -D_DEBUG
 ! MSVC-DEBUG-SAME: --dependent-lib=libcmtd
-! MSVC-DEBUG-SAME: --dependent-lib=FortranRuntime.static_dbg.lib
+! MSVC-DEBUG-SAME: --dependent-lib=flang_rt.static_dbg.lib
 
 ! MSVC-DLL: -fc1
 ! MSVC-DLL-SAME: --dependent-lib=clang_rt.builtins.lib
 ! MSVC-DLL-SAME: -D_MT
 ! MSVC-DLL-SAME: -D_DLL
 ! MSVC-DLL-SAME: --dependent-lib=msvcrt
-! MSVC-DLL-SAME: --dependent-lib=FortranRuntime.dynamic.lib
+! MSVC-DLL-SAME: --dependent-lib=flang_rt.dynamic.lib
 
 ! MSVC-DLL-DEBUG: -fc1
 ! MSVC-DLL-DEBUG-SAME: --dependent-lib=clang_rt.builtins.lib
@@ -29,4 +29,4 @@
 ! MSVC-DLL-DEBUG-SAME: -D_DEBUG
 ! MSVC-DLL-DEBUG-SAME: -D_DLL
 ! MSVC-DLL-DEBUG-SAME: --dependent-lib=msvcrtd
-! MSVC-DLL-DEBUG-SAME: --dependent-lib=FortranRuntime.dynamic_dbg.lib
+! MSVC-DLL-DEBUG-SAME: --dependent-lib=flang_rt.dynamic_dbg.lib
diff --git a/flang/test/Driver/nostdlib.f90 b/flang/test/Driver/nostdlib.f90
index ab7c675fe7b77d5..17ed10fa0615d58 100644
--- a/flang/test/Driver/nostdlib.f90
+++ b/flang/test/Driver/nostdlib.f90
@@ -24,5 +24,5 @@
 ! in certain cases. But it is not clear that it is worth checking for each
 ! platform individually.
 
-! CHECK-NOT: "-lFortranRuntime"
+! CHECK-NOT: "-lflang_rt"
 ! CHECK-NOT: "-lgcc"
diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang/test/Runtime/no-cpp-dep.c
index 7303ce63fdec410..c03029f0f3c26db 100644
--- a/flang/test/Runtime/no-cpp-dep.c
+++ b/flang/test/Runtime/no-cpp-dep.c
@@ -1,6 +1,6 @@
 /*
 This test makes sure that flang's runtime does not depend on the C++ runtime
-library. It tries to link this simple file against libFortranRuntime.a with
+library. It tries to link this simple file against libflang_rt.a with
 a C compiler.
 
 REQUIRES: c-compiler, flang-rt
diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py
index f4580afc8c47b12..08ba586e1226d3c 100644
--- a/flang/test/lit.cfg.py
+++ b/flang/test/lit.cfg.py
@@ -170,7 +170,7 @@
 # the C++ runtime libraries. For this we need a C compiler. If for some reason
 # we don't have one, we can just disable the test.
 if config.flang_include_runtime and config.cc:
-    libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a")
+    libruntime = os.path.join(config.flang_lib_dir, "libflang_rt.a")
     include = os.path.join(config.flang_src_dir, "include")
 
     if (
diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index 85ba2c74cdeb5c4..a849e95df31c17b 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -5,7 +5,7 @@ set(LLVM_LINK_COMPONENTS
   )
 
 # Define the list of Fortran module files that need to be compiled
-# to produce an object file for inclusion into the FortranRuntime
+# to produce an object file for inclusion into the flang_rt
 # library.
 set(MODULES_WITH_IMPLEMENTATION
   "iso_fortran_env_impl"
@@ -105,7 +105,7 @@ if (NOT CMAKE_CROSSCOMPILING)
     endif()
 
     # Some modules have an implementation part that needs to be added to the
-    # FortranRuntime library.
+    # flang_rt library.
     set(compile_with "-fsyntax-only")
     set(object_output "")
     set(include_in_link FALSE)
@@ -127,14 +127,14 @@ if (NOT CMAKE_CROSSCOMPILING)
     install(FILES ${base}.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
 
     # If a module has been compiled into an object file, add the file to
-    # the link line for the FortranRuntime library.
+    # the link line for the flang_rt library.
     if(include_in_link)
       list(APPEND module_objects ${object_output})
     endif()
   endforeach()
 
   # Set a CACHE variable that is visible to the CMakeLists.txt in runtime/, so that
-  # the compiled Fortran modules can be added to the link line of the FortranRuntime
+  # the compiled Fortran modules can be added to the link line of the flang_rt
   # library.
   set(FORTRAN_MODULE_OBJECTS ${module_objects} CACHE INTERNAL "" FORCE)
 
diff --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt
index ecb7d68d8f72966..7b0f85638f14e48 100644
--- a/flang/unittests/CMakeLists.txt
+++ b/flang/unittests/CMakeLists.txt
@@ -2,7 +2,7 @@ include(AddFlangOffloadRuntime)
 
 if (FLANG_EXPERIMENTAL_CUDA_RUNTIME)
   # If Fortran runtime is built as CUDA library, the linking
-  # of targets that link FortranRuntime must be done
+  # of targets that link flang_rt must be done
   # with CUDA_RESOLVE_DEVICE_SYMBOLS.
   # CUDA language must be enabled for CUDA_RESOLVE_DEVICE_SYMBOLS
   # to take effect.
diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt
index 1c3fac29cd2982e..9e19b2cdfbb90c4 100644
--- a/flang/unittests/Evaluate/CMakeLists.txt
+++ b/flang/unittests/Evaluate/CMakeLists.txt
@@ -60,14 +60,14 @@ if (FLANG_INCLUDE_RUNTIME)
     NonGTestTesting
     FortranSemantics
     FortranEvaluate
-    FortranRuntime
+    flang_rt
   )
 
   add_flang_nongtest_unittest(ISO-Fortran-binding
     NonGTestTesting
     FortranEvaluate
     FortranSemantics
-    FortranRuntime
+    flang_rt
   )
 endif ()
 
diff --git a/flang/unittests/Runtime/CMakeLists.txt b/flang/unittests/Runtime/CMakeLists.txt
index 179e439917ff237..a60b43d422878d2 100644
--- a/flang/unittests/Runtime/CMakeLists.txt
+++ b/flang/unittests/Runtime/CMakeLists.txt
@@ -33,7 +33,7 @@ add_flang_unittest(FlangRuntimeTests
 
 target_link_libraries(FlangRuntimeTests
   PRIVATE
-  FortranRuntime
+  flang_rt
 )
 
 target_compile_definitions(FlangRuntimeTests PRIVATE NOT_EXE="$<TARGET_FILE:not>")
diff --git a/flang/unittests/Runtime/CUDA/CMakeLists.txt b/flang/unittests/Runtime/CUDA/CMakeLists.txt
index a7fe604d687bdd8..38888e32e6ed8ac 100644
--- a/flang/unittests/Runtime/CUDA/CMakeLists.txt
+++ b/flang/unittests/Runtime/CUDA/CMakeLists.txt
@@ -16,7 +16,7 @@ target_link_libraries(FlangCufRuntimeTests
   PRIVATE
   ${CUDA_RT_TARGET}
   CufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR}
-  FortranRuntime
+  flang_rt
 )
 
 target_include_directories(FlangCufRuntimeTests PRIVATE ${CUDAToolkit_INCLUDE_DIRS})
diff --git a/lld/COFF/MinGW.cpp b/lld/COFF/MinGW.cpp
index 797ab37f0698108..e188dfb503c1aa5 100644
--- a/lld/COFF/MinGW.cpp
+++ b/lld/COFF/MinGW.cpp
@@ -50,7 +50,7 @@ AutoExporter::AutoExporter(
       "libclang_rt.profile-x86_64",
       "libc++",
       "libc++abi",
-      "libFortranRuntime",
+      "libflang_rt",
       "libunwind",
       "libmsvcrt",
       "libucrtbase",

>From 24fb7606827ba33397aad5220f423ae5daa87de5 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 27 Jan 2025 11:23:39 +0100
Subject: [PATCH 06/18] Sort files alphabetically

---
 flang/lib/Support/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Support/CMakeLists.txt b/flang/lib/Support/CMakeLists.txt
index 809266960a02d4e..4ee381589a2087c 100644
--- a/flang/lib/Support/CMakeLists.txt
+++ b/flang/lib/Support/CMakeLists.txt
@@ -43,14 +43,14 @@ if(FLANG_VENDOR)
 endif()
 
 add_flang_library(FortranSupport
+  default-kinds.cpp
   Fortran.cpp
   Fortran-features.cpp
-  default-kinds.cpp
   idioms.cpp
   LangOptions.cpp
   OpenMP-utils.cpp
-  Version.cpp
   Timing.cpp
+  Version.cpp
   ${version_inc}
 
   LINK_COMPONENTS

>From b9ab00df5906d473196be6be819d9739bc7d3e63 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Wed, 29 Jan 2025 10:43:18 +0100
Subject: [PATCH 07/18] Move files back to Common

---
 .../flang/Common/ISO_Fortran_binding_wrapper.h       |  2 +-
 flang/include/flang/Common/format.h                  |  2 +-
 .../include/flang/{Support => Common}/indirection.h  | 10 +++++-----
 flang/include/flang/{Support => Common}/interval.h   | 10 +++++-----
 flang/include/flang/Common/optional.h                |  2 +-
 flang/include/flang/Common/real.h                    |  2 +-
 .../flang/{Support => Common}/reference-counted.h    |  8 ++++----
 flang/include/flang/Common/reference-wrapper.h       |  2 +-
 flang/include/flang/{Support => Common}/reference.h  |  8 ++++----
 flang/include/flang/Common/restorer.h                |  2 +-
 .../flang/{Support => Common}/static-multimap-view.h |  8 ++++----
 flang/include/flang/Common/target-rounding.h         |  4 ++--
 flang/include/flang/{Support => Common}/template.h   | 12 ++++++------
 flang/include/flang/Common/uint128.h                 |  2 +-
 flang/include/flang/{Support => Common}/unwrap.h     | 12 ++++++------
 flang/include/flang/Common/visit.h                   |  2 +-
 flang/include/flang/Evaluate/call.h                  |  4 ++--
 flang/include/flang/Evaluate/characteristics.h       |  2 +-
 flang/include/flang/Evaluate/common.h                |  2 +-
 flang/include/flang/Evaluate/constant.h              |  2 +-
 flang/include/flang/Evaluate/expression.h            |  4 ++--
 flang/include/flang/Evaluate/formatting.h            |  2 +-
 flang/include/flang/Evaluate/shape.h                 |  2 +-
 flang/include/flang/Evaluate/tools.h                 |  4 ++--
 flang/include/flang/Evaluate/traverse.h              |  2 +-
 flang/include/flang/Evaluate/type.h                  |  2 +-
 flang/include/flang/Evaluate/variable.h              |  4 ++--
 flang/include/flang/Lower/CallInterface.h            |  2 +-
 flang/include/flang/Lower/PFTBuilder.h               |  4 ++--
 flang/include/flang/Lower/Support/Utils.h            |  2 +-
 flang/include/flang/Lower/SymbolMap.h                |  2 +-
 .../flang/Optimizer/Builder/PPCIntrinsicCall.h       |  2 +-
 flang/include/flang/Parser/char-block.h              |  2 +-
 flang/include/flang/Parser/dump-parse-tree.h         |  2 +-
 flang/include/flang/Parser/message.h                 |  2 +-
 flang/include/flang/Parser/parse-tree.h              |  2 +-
 flang/include/flang/Parser/provenance.h              |  2 +-
 flang/include/flang/Parser/source.h                  |  2 +-
 flang/include/flang/Semantics/expression.h           |  2 +-
 flang/include/flang/Semantics/runtime-type-info.h    |  2 +-
 flang/include/flang/Semantics/scope.h                |  2 +-
 flang/include/flang/Semantics/symbol.h               |  2 +-
 flang/include/flang/Support/Fortran-features.h       |  2 +-
 flang/include/flang/Support/LangOptions.h            |  6 +++---
 flang/include/flang/Support/MathOptionsBase.h        |  6 +++---
 .../include/flang/{Common => Support}/OpenMP-utils.h |  8 ++++----
 flang/include/flang/Support/default-kinds.h          |  2 +-
 flang/lib/Decimal/CMakeLists.txt                     |  8 ++++++++
 flang/lib/Evaluate/characteristics.cpp               |  2 +-
 flang/lib/Evaluate/fold-implementation.h             |  6 +++---
 flang/lib/Evaluate/intrinsics-library.cpp            |  2 +-
 flang/lib/Evaluate/shape.cpp                         |  2 +-
 flang/lib/Evaluate/target.cpp                        |  2 +-
 flang/lib/Lower/ConvertExpr.cpp                      |  2 +-
 flang/lib/Lower/Mangler.cpp                          |  2 +-
 flang/lib/Lower/OpenMP/OpenMP.cpp                    |  2 +-
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp        |  2 +-
 flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp |  2 +-
 flang/lib/Parser/basic-parsers.h                     |  2 +-
 flang/lib/Parser/parse-tree.cpp                      |  2 +-
 flang/lib/Parser/unparse.cpp                         |  2 +-
 flang/lib/Semantics/assignment.h                     |  2 +-
 flang/lib/Semantics/check-case.cpp                   |  4 ++--
 flang/lib/Semantics/check-coarray.cpp                |  2 +-
 flang/lib/Semantics/check-cuda.cpp                   |  2 +-
 flang/lib/Semantics/check-data.h                     |  2 +-
 flang/lib/Semantics/check-do-forall.cpp              |  2 +-
 flang/lib/Semantics/check-select-type.cpp            |  2 +-
 flang/lib/Semantics/data-to-inits.h                  |  2 +-
 flang/lib/Semantics/pointer-assignment.cpp           |  2 +-
 flang/lib/Semantics/resolve-labels.cpp               |  2 +-
 flang/lib/Semantics/resolve-names-utils.cpp          |  2 +-
 flang/lib/Semantics/resolve-names.cpp                |  2 +-
 flang/lib/Semantics/rewrite-parse-tree.cpp           |  2 +-
 flang/lib/Semantics/tools.cpp                        |  2 +-
 flang/lib/Support/OpenMP-utils.cpp                   |  2 +-
 76 files changed, 126 insertions(+), 118 deletions(-)
 rename flang/include/flang/{Support => Common}/indirection.h (95%)
 rename flang/include/flang/{Support => Common}/interval.h (94%)
 rename flang/include/flang/{Support => Common}/reference-counted.h (90%)
 rename flang/include/flang/{Support => Common}/reference.h (91%)
 rename flang/include/flang/{Support => Common}/static-multimap-view.h (91%)
 rename flang/include/flang/{Support => Common}/template.h (98%)
 rename flang/include/flang/{Support => Common}/unwrap.h (94%)
 rename flang/include/flang/{Common => Support}/OpenMP-utils.h (92%)

diff --git a/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
index 7a8a8a9787bd036..5d9c66f47b48e62 100644
--- a/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
+++ b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
@@ -22,7 +22,7 @@
 
 /* clang-format off */
 #include <stddef.h>
-#include "flang/Common/api-attrs.h"
+#include "api-attrs.h"
 #ifdef __cplusplus
 namespace Fortran {
 namespace ISO {
diff --git a/flang/include/flang/Common/format.h b/flang/include/flang/Common/format.h
index c5e9fb06e260f12..da416506ffb5d08 100644
--- a/flang/include/flang/Common/format.h
+++ b/flang/include/flang/Common/format.h
@@ -9,8 +9,8 @@
 #ifndef FORTRAN_COMMON_FORMAT_H_
 #define FORTRAN_COMMON_FORMAT_H_
 
+#include "Fortran-consts.h"
 #include "enum-set.h"
-#include "flang/Common/Fortran-consts.h"
 #include <cstring>
 
 // Define a FormatValidator class template to validate a format expression
diff --git a/flang/include/flang/Support/indirection.h b/flang/include/flang/Common/indirection.h
similarity index 95%
rename from flang/include/flang/Support/indirection.h
rename to flang/include/flang/Common/indirection.h
index aeb1698516bae92..7348eb0473f072c 100644
--- a/flang/include/flang/Support/indirection.h
+++ b/flang/include/flang/Common/indirection.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Support/indirection.h ---------------------*- C++ -*-===//
+//===-- include/flang/Common/indirection.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.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_SUPPORT_INDIRECTION_H_
-#define FORTRAN_SUPPORT_INDIRECTION_H_
+#ifndef FORTRAN_COMMON_INDIRECTION_H_
+#define FORTRAN_COMMON_INDIRECTION_H_
 
 // Define a smart pointer class template that is rather like
 // non-nullable std::unique_ptr<>.  Indirection<> is, like a C++ reference
@@ -20,7 +20,7 @@
 //    template class Fortran::common::Indirection<FORWARD_TYPE>;
 // in one C++ source file later where a definition of the type is visible.
 
-#include "flang/Common/idioms.h"
+#include "idioms.h"
 #include <memory>
 #include <type_traits>
 #include <utility>
@@ -171,4 +171,4 @@ template <typename A> class ForwardOwningPointer {
   void (*deleter_)(A *){nullptr};
 };
 } // namespace Fortran::common
-#endif /* FORTRAN_SUPPORT_INDIRECTION_H_ */
+#endif // FORTRAN_COMMON_INDIRECTION_H_
diff --git a/flang/include/flang/Support/interval.h b/flang/include/flang/Common/interval.h
similarity index 94%
rename from flang/include/flang/Support/interval.h
rename to flang/include/flang/Common/interval.h
index 99c0784f006a80b..c4cab0ccf1130b6 100644
--- a/flang/include/flang/Support/interval.h
+++ b/flang/include/flang/Common/interval.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Support/interval.h ------------------------*- C++ -*-===//
+//===-- include/flang/Common/interval.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.
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_SUPPORT_INTERVAL_H_
-#define FORTRAN_SUPPORT_INTERVAL_H_
+#ifndef FORTRAN_COMMON_INTERVAL_H_
+#define FORTRAN_COMMON_INTERVAL_H_
 
 // Defines a generalized template class Interval<A> to represent
 // the half-open interval [x .. x+n).
 
-#include "flang/Common/idioms.h"
+#include "idioms.h"
 #include <algorithm>
 #include <cstddef>
 #include <utility>
@@ -126,4 +126,4 @@ template <typename A> class Interval {
   std::size_t size_{0};
 };
 } // namespace Fortran::common
-#endif /* FORTRAN_SUPPORT_INTERVAL_H_ */
+#endif // FORTRAN_COMMON_INTERVAL_H_
diff --git a/flang/include/flang/Common/optional.h b/flang/include/flang/Common/optional.h
index c0f4278009f40a8..c7c81f40cc8c8f3 100644
--- a/flang/include/flang/Common/optional.h
+++ b/flang/include/flang/Common/optional.h
@@ -26,7 +26,7 @@
 #ifndef FORTRAN_COMMON_OPTIONAL_H
 #define FORTRAN_COMMON_OPTIONAL_H
 
-#include "flang/Common/api-attrs.h"
+#include "api-attrs.h"
 #include <optional>
 #include <type_traits>
 
diff --git a/flang/include/flang/Common/real.h b/flang/include/flang/Common/real.h
index b527deda0e3b4f8..b47ba46581db666 100644
--- a/flang/include/flang/Common/real.h
+++ b/flang/include/flang/Common/real.h
@@ -13,7 +13,7 @@
 // The various representations are distinguished by their binary precisions
 // (number of explicit significand bits and any implicit MSB in the fraction).
 
-#include "flang/Common/api-attrs.h"
+#include "api-attrs.h"
 #include <cinttypes>
 
 namespace Fortran::common {
diff --git a/flang/include/flang/Support/reference-counted.h b/flang/include/flang/Common/reference-counted.h
similarity index 90%
rename from flang/include/flang/Support/reference-counted.h
rename to flang/include/flang/Common/reference-counted.h
index 636613d93d80cc0..de91d4fb6ee8b70 100644
--- a/flang/include/flang/Support/reference-counted.h
+++ b/flang/include/flang/Common/reference-counted.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Support/reference-counted.h ---------------*- C++ -*-===//
+//===-- include/flang/Common/reference-counted.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.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_SUPPORT_REFERENCE_COUNTED_H_
-#define FORTRAN_SUPPORT_REFERENCE_COUNTED_H_
+#ifndef FORTRAN_COMMON_REFERENCE_COUNTED_H_
+#define FORTRAN_COMMON_REFERENCE_COUNTED_H_
 
 // A class template of smart pointers to objects with their own
 // reference counting object lifetimes that's lighter weight
@@ -74,4 +74,4 @@ template <typename A> class CountedReference {
   type *p_{nullptr};
 };
 } // namespace Fortran::common
-#endif /* FORTRAN_SUPPORT_REFERENCE_COUNTED_H_ */
+#endif // FORTRAN_COMMON_REFERENCE_COUNTED_H_
diff --git a/flang/include/flang/Common/reference-wrapper.h b/flang/include/flang/Common/reference-wrapper.h
index 2983754108f95a7..85b2c6d5abce398 100644
--- a/flang/include/flang/Common/reference-wrapper.h
+++ b/flang/include/flang/Common/reference-wrapper.h
@@ -25,7 +25,7 @@
 #ifndef FORTRAN_COMMON_REFERENCE_WRAPPER_H
 #define FORTRAN_COMMON_REFERENCE_WRAPPER_H
 
-#include "flang/Common/api-attrs.h"
+#include "api-attrs.h"
 #include <functional>
 #include <type_traits>
 
diff --git a/flang/include/flang/Support/reference.h b/flang/include/flang/Common/reference.h
similarity index 91%
rename from flang/include/flang/Support/reference.h
rename to flang/include/flang/Common/reference.h
index c0b0e048ae04a79..0c579de44bd7fa2 100644
--- a/flang/include/flang/Support/reference.h
+++ b/flang/include/flang/Common/reference.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Support/reference.h -----------------------*- C++ -*-===//
+//===-- include/flang/Common/reference.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.
@@ -11,8 +11,8 @@
 // Use Reference<A> in place of a real A& reference when assignability is
 // required; safer than a bare pointer because it's guaranteed to not be null.
 
-#ifndef FORTRAN_SUPPORT_REFERENCE_H_
-#define FORTRAN_SUPPORT_REFERENCE_H_
+#ifndef FORTRAN_COMMON_REFERENCE_H_
+#define FORTRAN_COMMON_REFERENCE_H_
 #include <type_traits>
 namespace Fortran::common {
 template <typename A> class Reference {
@@ -60,4 +60,4 @@ template <typename A> class Reference {
 };
 template <typename A> Reference(A &) -> Reference<A>;
 } // namespace Fortran::common
-#endif /* FORTRAN_SUPPORT_REFERENCE_H_ */
+#endif
diff --git a/flang/include/flang/Common/restorer.h b/flang/include/flang/Common/restorer.h
index 0f1bc48620d37e8..c18c13e351c768d 100644
--- a/flang/include/flang/Common/restorer.h
+++ b/flang/include/flang/Common/restorer.h
@@ -18,8 +18,8 @@
 
 #ifndef FORTRAN_COMMON_RESTORER_H_
 #define FORTRAN_COMMON_RESTORER_H_
+#include "api-attrs.h"
 #include "idioms.h"
-#include "flang/Common/api-attrs.h"
 namespace Fortran::common {
 template <typename A> class Restorer {
 public:
diff --git a/flang/include/flang/Support/static-multimap-view.h b/flang/include/flang/Common/static-multimap-view.h
similarity index 91%
rename from flang/include/flang/Support/static-multimap-view.h
rename to flang/include/flang/Common/static-multimap-view.h
index 8928fab6bfb6f5a..27d2ba89c8009cf 100644
--- a/flang/include/flang/Support/static-multimap-view.h
+++ b/flang/include/flang/Common/static-multimap-view.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Support/static-multimap-view.h ------------*- C++ -*-===//
+//===-- include/flang/Common/static-multimap-view.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.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_SUPPORT_STATIC_MULTIMAP_VIEW_H_
-#define FORTRAN_SUPPORT_STATIC_MULTIMAP_VIEW_H_
+#ifndef FORTRAN_COMMON_STATIC_MULTIMAP_VIEW_H_
+#define FORTRAN_COMMON_STATIC_MULTIMAP_VIEW_H_
 #include <algorithm>
 #include <utility>
 
@@ -59,4 +59,4 @@ template <typename V> class StaticMultimapView {
   const_iterator end_{nullptr};
 };
 } // namespace Fortran::common
-#endif /* FORTRAN_SUPPORT_STATIC_MULTIMAP_VIEW_H_ */
+#endif // FORTRAN_COMMON_STATIC_MULTIMAP_VIEW_H_
diff --git a/flang/include/flang/Common/target-rounding.h b/flang/include/flang/Common/target-rounding.h
index c0c9f6c49b26a2a..f503b22930ed496 100644
--- a/flang/include/flang/Common/target-rounding.h
+++ b/flang/include/flang/Common/target-rounding.h
@@ -9,8 +9,8 @@
 #ifndef FORTRAN_COMMON_TARGET_ROUNDING_H_
 #define FORTRAN_COMMON_TARGET_ROUNDING_H_
 
-#include "flang/Common/Fortran-consts.h"
-#include "flang/Common/enum-set.h"
+#include "Fortran-consts.h"
+#include "enum-set.h"
 
 namespace Fortran::common {
 
diff --git a/flang/include/flang/Support/template.h b/flang/include/flang/Common/template.h
similarity index 98%
rename from flang/include/flang/Support/template.h
rename to flang/include/flang/Common/template.h
index 36fa6f7072b40cb..6501994133759cd 100644
--- a/flang/include/flang/Support/template.h
+++ b/flang/include/flang/Common/template.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Support/template.h ------------------------*- C++ -*-===//
+//===-- include/flang/Common/template.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.
@@ -6,11 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_SUPPORT_TEMPLATE_H_
-#define FORTRAN_SUPPORT_TEMPLATE_H_
+#ifndef FORTRAN_COMMON_TEMPLATE_H_
+#define FORTRAN_COMMON_TEMPLATE_H_
 
-#include "flang/Common/idioms.h"
-#include "flang/Common/variant.h"
+#include "idioms.h"
+#include "variant.h"
 #include <functional>
 #include <optional>
 #include <tuple>
@@ -322,4 +322,4 @@ common::IfNoLvalue<typename VISITOR::Result, VISITOR> SearchTypes(
       std::move(visitor), std::move(defaultResult));
 }
 } // namespace Fortran::common
-#endif /* FORTRAN_SUPPORT_TEMPLATE_H_ */
+#endif // FORTRAN_COMMON_TEMPLATE_H_
diff --git a/flang/include/flang/Common/uint128.h b/flang/include/flang/Common/uint128.h
index 821c8c3b08a52fb..faecb88737a0b24 100644
--- a/flang/include/flang/Common/uint128.h
+++ b/flang/include/flang/Common/uint128.h
@@ -19,8 +19,8 @@
 #define AVOID_NATIVE_UINT128_T 0
 #endif
 
+#include "api-attrs.h"
 #include "leading-zero-bit-count.h"
-#include "flang/Common/api-attrs.h"
 #include <cstdint>
 #include <type_traits>
 
diff --git a/flang/include/flang/Support/unwrap.h b/flang/include/flang/Common/unwrap.h
similarity index 94%
rename from flang/include/flang/Support/unwrap.h
rename to flang/include/flang/Common/unwrap.h
index e890753499d1a16..84582174e4b3006 100644
--- a/flang/include/flang/Support/unwrap.h
+++ b/flang/include/flang/Common/unwrap.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Support/unwrap.h --------------------------*- C++ -*-===//
+//===-- include/flang/Common/unwrap.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.
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_SUPPORT_UNWRAP_H_
-#define FORTRAN_SUPPORT_UNWRAP_H_
+#ifndef FORTRAN_COMMON_UNWRAP_H_
+#define FORTRAN_COMMON_UNWRAP_H_
 
 #include "indirection.h"
 #include "reference-counted.h"
 #include "reference.h"
-#include "flang/Common/variant.h"
-#include "flang/Common/visit.h"
+#include "variant.h"
+#include "visit.h"
 #include <memory>
 #include <optional>
 #include <type_traits>
@@ -155,4 +155,4 @@ template <typename A, typename B> std::optional<A> UnwrapCopy(const B &x) {
   }
 }
 } // namespace Fortran::common
-#endif /* FORTRAN_SUPPORT_UNWRAP_H_ */
+#endif // FORTRAN_COMMON_UNWRAP_H_
diff --git a/flang/include/flang/Common/visit.h b/flang/include/flang/Common/visit.h
index ad66297650b093a..1a84102b5664279 100644
--- a/flang/include/flang/Common/visit.h
+++ b/flang/include/flang/Common/visit.h
@@ -21,8 +21,8 @@
 #ifndef FORTRAN_COMMON_VISIT_H_
 #define FORTRAN_COMMON_VISIT_H_
 
+#include "api-attrs.h"
 #include "variant.h"
-#include "flang/Common/api-attrs.h"
 #include <type_traits>
 
 namespace Fortran::common {
diff --git a/flang/include/flang/Evaluate/call.h b/flang/include/flang/Evaluate/call.h
index 4d8ca28cf329a12..2a5929b873d7420 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/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 ccd584b5ee6aa4f..b4e14cd299fb610 100644
--- a/flang/include/flang/Evaluate/characteristics.h
+++ b/flang/include/flang/Evaluate/characteristics.h
@@ -20,11 +20,11 @@
 #include "type.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 91d38748f5a5753..993540aebca5733 100644
--- a/flang/include/flang/Evaluate/common.h
+++ b/flang/include/flang/Evaluate/common.h
@@ -11,6 +11,7 @@
 
 #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"
@@ -18,7 +19,6 @@
 #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 63e8ed4119cdf52..6fc22e3b86aa2fd 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/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 ec71550d2a50c9d..1203fca8640a62b 100644
--- a/flang/include/flang/Evaluate/expression.h
+++ b/flang/include/flang/Evaluate/expression.h
@@ -22,10 +22,10 @@
 #include "type.h"
 #include "variable.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 ae9351139b19330..aa82f56107fdd37 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/Support/indirection.h"
+#include "flang/Common/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <optional>
 #include <type_traits>
diff --git a/flang/include/flang/Evaluate/shape.h b/flang/include/flang/Evaluate/shape.h
index 18dca71379e0dac..3e42ec691158bcf 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/tools.h b/flang/include/flang/Evaluate/tools.h
index fbe905168d25386..669efb41b034423 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -11,6 +11,8 @@
 
 #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"
@@ -19,8 +21,6 @@
 #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 58f188a40924930..dd38d64bff63f70 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 ab7e4723152d7e5..98cc9b8cbba2126 100644
--- a/flang/include/flang/Evaluate/type.h
+++ b/flang/include/flang/Evaluate/type.h
@@ -24,9 +24,9 @@
 #include "real.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 bb4150613c81dd4..9b597d29813da12 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/Lower/CallInterface.h b/flang/include/flang/Lower/CallInterface.h
index c15edf62df388eb..72bc9dd890a94b0 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/PFTBuilder.h b/flang/include/flang/Lower/PFTBuilder.h
index 05da17faf2dd7d6..42d6546b77553bc 100644
--- a/flang/include/flang/Lower/PFTBuilder.h
+++ b/flang/include/flang/Lower/PFTBuilder.h
@@ -17,6 +17,8 @@
 #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"
@@ -24,8 +26,6 @@
 #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 08a872b228691d0..1cc74521e22d888 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 fb64db407708ade..c03f9afd40801cd 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/PPCIntrinsicCall.h b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
index 8374b18b8a17d82..5ae32f70a11a7f3 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/Parser/char-block.h b/flang/include/flang/Parser/char-block.h
index 4541b31e566f95b..38f4f7b82e1eae3 100644
--- a/flang/include/flang/Parser/char-block.h
+++ b/flang/include/flang/Parser/char-block.h
@@ -11,7 +11,7 @@
 
 // Describes a contiguous block of characters; does not own their storage.
 
-#include "flang/Support/interval.h"
+#include "flang/Common/interval.h"
 #include <algorithm>
 #include <cstddef>
 #include <cstring>
diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index 42d622c4d497bba..8114cb3c7d04965 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -15,8 +15,8 @@
 #include "tools.h"
 #include "unparse.h"
 #include "flang/Common/idioms.h"
+#include "flang/Common/indirection.h"
 #include "flang/Support/Fortran.h"
-#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <string>
 #include <type_traits>
diff --git a/flang/include/flang/Parser/message.h b/flang/include/flang/Parser/message.h
index bfbc985b8b91aae..e19b16c23b82ba8 100644
--- a/flang/include/flang/Parser/message.h
+++ b/flang/include/flang/Parser/message.h
@@ -16,9 +16,9 @@
 #include "char-set.h"
 #include "provenance.h"
 #include "flang/Common/idioms.h"
+#include "flang/Common/reference-counted.h"
 #include "flang/Common/restorer.h"
 #include "flang/Support/Fortran-features.h"
-#include "flang/Support/reference-counted.h"
 #include <cstddef>
 #include <cstring>
 #include <forward_list>
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index 158c27a8be2f9f1..69deff2a3be6400 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -23,8 +23,8 @@
 #include "message.h"
 #include "provenance.h"
 #include "flang/Common/idioms.h"
+#include "flang/Common/indirection.h"
 #include "flang/Support/Fortran.h"
-#include "flang/Support/indirection.h"
 #include "llvm/Frontend/OpenACC/ACC.h.inc"
 #include "llvm/Frontend/OpenMP/OMP.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
diff --git a/flang/include/flang/Parser/provenance.h b/flang/include/flang/Parser/provenance.h
index 7f29fb272c94214..a9224b727fd0548 100644
--- a/flang/include/flang/Parser/provenance.h
+++ b/flang/include/flang/Parser/provenance.h
@@ -14,7 +14,7 @@
 #include "characters.h"
 #include "source.h"
 #include "flang/Common/idioms.h"
-#include "flang/Support/interval.h"
+#include "flang/Common/interval.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstddef>
 #include <list>
diff --git a/flang/include/flang/Parser/source.h b/flang/include/flang/Parser/source.h
index a67fd66045a3de9..a6efdf9546c7f31 100644
--- a/flang/include/flang/Parser/source.h
+++ b/flang/include/flang/Parser/source.h
@@ -15,7 +15,7 @@
 //  - A Unicode byte order mark is recognized if present.
 
 #include "characters.h"
-#include "flang/Support/reference.h"
+#include "flang/Common/reference.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstddef>
diff --git a/flang/include/flang/Semantics/expression.h b/flang/include/flang/Semantics/expression.h
index 8ea33902bd21375..7b68ea728cbd5b2 100644
--- a/flang/include/flang/Semantics/expression.h
+++ b/flang/include/flang/Semantics/expression.h
@@ -10,6 +10,7 @@
 #define FORTRAN_SEMANTICS_EXPRESSION_H_
 
 #include "semantics.h"
+#include "flang/Common/indirection.h"
 #include "flang/Common/restorer.h"
 #include "flang/Common/visit.h"
 #include "flang/Evaluate/characteristics.h"
@@ -23,7 +24,6 @@
 #include "flang/Parser/parse-tree.h"
 #include "flang/Parser/tools.h"
 #include "flang/Support/Fortran.h"
-#include "flang/Support/indirection.h"
 #include <map>
 #include <optional>
 #include <type_traits>
diff --git a/flang/include/flang/Semantics/runtime-type-info.h b/flang/include/flang/Semantics/runtime-type-info.h
index 94c50aab696816e..e90d3ae8baf1eba 100644
--- a/flang/include/flang/Semantics/runtime-type-info.h
+++ b/flang/include/flang/Semantics/runtime-type-info.h
@@ -14,8 +14,8 @@
 #ifndef FORTRAN_SEMANTICS_RUNTIME_TYPE_INFO_H_
 #define FORTRAN_SEMANTICS_RUNTIME_TYPE_INFO_H_
 
+#include "flang/Common/reference.h"
 #include "flang/Semantics/symbol.h"
-#include "flang/Support/reference.h"
 #include <map>
 #include <set>
 #include <string>
diff --git a/flang/include/flang/Semantics/scope.h b/flang/include/flang/Semantics/scope.h
index b7d115ec2bca4e6..b4046830522b887 100644
--- a/flang/include/flang/Semantics/scope.h
+++ b/flang/include/flang/Semantics/scope.h
@@ -12,10 +12,10 @@
 #include "attr.h"
 #include "symbol.h"
 #include "flang/Common/idioms.h"
+#include "flang/Common/reference.h"
 #include "flang/Parser/message.h"
 #include "flang/Parser/provenance.h"
 #include "flang/Support/Fortran.h"
-#include "flang/Support/reference.h"
 #include <list>
 #include <map>
 #include <optional>
diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h
index dfe323acbd49011..974add6cc5de37b 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -11,10 +11,10 @@
 
 #include "type.h"
 #include "flang/Common/enum-set.h"
+#include "flang/Common/reference.h"
 #include "flang/Common/visit.h"
 #include "flang/Semantics/module-dependences.h"
 #include "flang/Support/Fortran.h"
-#include "flang/Support/reference.h"
 #include "llvm/ADT/DenseMapInfo.h"
 
 #include <array>
diff --git a/flang/include/flang/Support/Fortran-features.h b/flang/include/flang/Support/Fortran-features.h
index 690329411dc50d1..58f84e94136762d 100644
--- a/flang/include/flang/Support/Fortran-features.h
+++ b/flang/include/flang/Support/Fortran-features.h
@@ -9,9 +9,9 @@
 #ifndef FORTRAN_SUPPORT_FORTRAN_FEATURES_H_
 #define FORTRAN_SUPPORT_FORTRAN_FEATURES_H_
 
+#include "Fortran.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/idioms.h"
-#include "flang/Support/Fortran.h"
 #include <optional>
 #include <vector>
 
diff --git a/flang/include/flang/Support/LangOptions.h b/flang/include/flang/Support/LangOptions.h
index 3c6094c9a9c87f3..f4f197dd87ca37e 100644
--- a/flang/include/flang/Support/LangOptions.h
+++ b/flang/include/flang/Support/LangOptions.h
@@ -45,12 +45,12 @@ class LangOptionsBase {
 
 #define LANGOPT(Name, Bits, Default) unsigned Name : Bits;
 #define ENUM_LANGOPT(Name, Type, Bits, Default)
-#include "flang/Support/LangOptions.def"
+#include "LangOptions.def"
 
 protected:
 #define LANGOPT(Name, Bits, Default)
 #define ENUM_LANGOPT(Name, Type, Bits, Default) unsigned Name : Bits;
-#include "flang/Support/LangOptions.def"
+#include "LangOptions.def"
 };
 
 /// Tracks various options which control the dialect of Fortran that is
@@ -63,7 +63,7 @@ class LangOptions : public LangOptionsBase {
 #define ENUM_LANGOPT(Name, Type, Bits, Default) \
   Type get##Name() const { return static_cast<Type>(Name); } \
   void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
-#include "flang/Support/LangOptions.def"
+#include "LangOptions.def"
 
   /// Name of the IR file that contains the result of the OpenMP target
   /// host code generation.
diff --git a/flang/include/flang/Support/MathOptionsBase.h b/flang/include/flang/Support/MathOptionsBase.h
index 072aed20da4708e..b4838c63d4ef897 100644
--- a/flang/include/flang/Support/MathOptionsBase.h
+++ b/flang/include/flang/Support/MathOptionsBase.h
@@ -27,16 +27,16 @@ class MathOptionsBase {
     Name = static_cast<unsigned>(Value); \
     return *this; \
   }
-#include "flang/Support/MathOptionsBase.def"
+#include "MathOptionsBase.def"
 
   MathOptionsBase() {
 #define ENUM_MATHOPT(Name, Type, Bits, Default) set##Name(Default);
-#include "flang/Support/MathOptionsBase.def"
+#include "MathOptionsBase.def"
   }
 
 private:
 #define ENUM_MATHOPT(Name, Type, Bits, Default) unsigned Name : Bits;
-#include "flang/Support/MathOptionsBase.def"
+#include "MathOptionsBase.def"
 };
 
 } // namespace Fortran::common
diff --git a/flang/include/flang/Common/OpenMP-utils.h b/flang/include/flang/Support/OpenMP-utils.h
similarity index 92%
rename from flang/include/flang/Common/OpenMP-utils.h
rename to flang/include/flang/Support/OpenMP-utils.h
index 827f13bc4758e2e..ad3da16008319e6 100644
--- a/flang/include/flang/Common/OpenMP-utils.h
+++ b/flang/include/flang/Support/OpenMP-utils.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/OpenMP-utils.h --------------------*- C++ -*-====//
+//===-- include/flang/Support/OpenMP-utils.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.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_OPENMP_UTILS_H_
-#define FORTRAN_COMMON_OPENMP_UTILS_H_
+#ifndef FORTRAN_SUPPORT_OPENMP_UTILS_H_
+#define FORTRAN_SUPPORT_OPENMP_UTILS_H_
 
 #include "flang/Semantics/symbol.h"
 
@@ -73,4 +73,4 @@ mlir::Block *genEntryBlock(
     mlir::OpBuilder &builder, const EntryBlockArgs &args, mlir::Region &region);
 } // namespace Fortran::common::openmp
 
-#endif // FORTRAN_COMMON_OPENMP_UTILS_H_
+#endif /* FORTRAN_SUPPORT_OPENMP_UTILS_H_ */
diff --git a/flang/include/flang/Support/default-kinds.h b/flang/include/flang/Support/default-kinds.h
index 92f06e6fe2d272a..5553366aa409d46 100644
--- a/flang/include/flang/Support/default-kinds.h
+++ b/flang/include/flang/Support/default-kinds.h
@@ -9,7 +9,7 @@
 #ifndef FORTRAN_SUPPORT_DEFAULT_KINDS_H_
 #define FORTRAN_SUPPORT_DEFAULT_KINDS_H_
 
-#include "flang/Support/Fortran.h"
+#include "Fortran.h"
 #include <cstdint>
 
 namespace Fortran::common {
diff --git a/flang/lib/Decimal/CMakeLists.txt b/flang/lib/Decimal/CMakeLists.txt
index 880b190f1c5815a..2fd2a429d7c22b1 100644
--- a/flang/lib/Decimal/CMakeLists.txt
+++ b/flang/lib/Decimal/CMakeLists.txt
@@ -1,3 +1,11 @@
+#===-- lib/Decimal/CMakeLists.txt ------------------------------------------===#
+#
+# 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
+#
+#===------------------------------------------------------------------------===#
+
 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   cmake_minimum_required(VERSION 3.20.0)
 
diff --git a/flang/lib/Evaluate/characteristics.cpp b/flang/lib/Evaluate/characteristics.cpp
index 49d11f41ea4caa9..3912d1c4b477152 100644
--- a/flang/lib/Evaluate/characteristics.cpp
+++ b/flang/lib/Evaluate/characteristics.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Evaluate/characteristics.h"
+#include "flang/Common/indirection.h"
 #include "flang/Evaluate/check-expression.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/intrinsics.h"
@@ -16,7 +17,6 @@
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
-#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <initializer_list>
 
diff --git a/flang/lib/Evaluate/fold-implementation.h b/flang/lib/Evaluate/fold-implementation.h
index 723bb8d97f68e29..31d043f490fd85c 100644
--- a/flang/lib/Evaluate/fold-implementation.h
+++ b/flang/lib/Evaluate/fold-implementation.h
@@ -12,6 +12,9 @@
 #include "character.h"
 #include "host.h"
 #include "int-power.h"
+#include "flang/Common/indirection.h"
+#include "flang/Common/template.h"
+#include "flang/Common/unwrap.h"
 #include "flang/Evaluate/characteristics.h"
 #include "flang/Evaluate/common.h"
 #include "flang/Evaluate/constant.h"
@@ -28,9 +31,6 @@
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
-#include "flang/Support/indirection.h"
-#include "flang/Support/template.h"
-#include "flang/Support/unwrap.h"
 #include <algorithm>
 #include <cmath>
 #include <complex>
diff --git a/flang/lib/Evaluate/intrinsics-library.cpp b/flang/lib/Evaluate/intrinsics-library.cpp
index fa2c931b21f0aa3..c1b270f518c0e0a 100644
--- a/flang/lib/Evaluate/intrinsics-library.cpp
+++ b/flang/lib/Evaluate/intrinsics-library.cpp
@@ -16,8 +16,8 @@
 #include "host.h"
 #include "flang/Common/erfc-scaled.h"
 #include "flang/Common/idioms.h"
+#include "flang/Common/static-multimap-view.h"
 #include "flang/Evaluate/expression.h"
-#include "flang/Support/static-multimap-view.h"
 #include <cfloat>
 #include <cmath>
 #include <complex>
diff --git a/flang/lib/Evaluate/shape.cpp b/flang/lib/Evaluate/shape.cpp
index ab7c357fa78a8ae..58b824d9b8e6441 100644
--- a/flang/lib/Evaluate/shape.cpp
+++ b/flang/lib/Evaluate/shape.cpp
@@ -8,6 +8,7 @@
 
 #include "flang/Evaluate/shape.h"
 #include "flang/Common/idioms.h"
+#include "flang/Common/template.h"
 #include "flang/Evaluate/characteristics.h"
 #include "flang/Evaluate/check-expression.h"
 #include "flang/Evaluate/fold.h"
@@ -16,7 +17,6 @@
 #include "flang/Evaluate/type.h"
 #include "flang/Parser/message.h"
 #include "flang/Semantics/symbol.h"
-#include "flang/Support/template.h"
 #include <functional>
 
 using namespace std::placeholders; // _1, _2, &c. for std::bind()
diff --git a/flang/lib/Evaluate/target.cpp b/flang/lib/Evaluate/target.cpp
index f87cce8b3200519..94dc35ecd5900a2 100644
--- a/flang/lib/Evaluate/target.cpp
+++ b/flang/lib/Evaluate/target.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Evaluate/target.h"
+#include "flang/Common/template.h"
 #include "flang/Evaluate/common.h"
 #include "flang/Evaluate/type.h"
-#include "flang/Support/template.h"
 
 namespace Fortran::evaluate {
 
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index 04df137ce566ff2..b33baf90582b850 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -11,6 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Lower/ConvertExpr.h"
+#include "flang/Common/unwrap.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/real.h"
 #include "flang/Evaluate/traverse.h"
@@ -51,7 +52,6 @@
 #include "flang/Semantics/tools.h"
 #include "flang/Semantics/type.h"
 #include "flang/Support/default-kinds.h"
-#include "flang/Support/unwrap.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "llvm/ADT/TypeSwitch.h"
 #include "llvm/Support/CommandLine.h"
diff --git a/flang/lib/Lower/Mangler.cpp b/flang/lib/Lower/Mangler.cpp
index aa40b1219652022..1165417ef89a282 100644
--- a/flang/lib/Lower/Mangler.cpp
+++ b/flang/lib/Lower/Mangler.cpp
@@ -7,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Lower/Mangler.h"
+#include "flang/Common/reference.h"
 #include "flang/Lower/Support/Utils.h"
 #include "flang/Optimizer/Builder/Todo.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Support/InternalNames.h"
 #include "flang/Semantics/tools.h"
-#include "flang/Support/reference.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 7c8d292e90f0113..3789babd6c2c807 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -18,7 +18,6 @@
 #include "Decomposer.h"
 #include "ReductionProcessor.h"
 #include "Utils.h"
-#include "flang/Common/OpenMP-utils.h"
 #include "flang/Common/idioms.h"
 #include "flang/Lower/Bridge.h"
 #include "flang/Lower/ConvertExpr.h"
@@ -35,6 +34,7 @@
 #include "flang/Parser/parse-tree.h"
 #include "flang/Semantics/openmp-directive-sets.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/OpenMP-utils.h"
 #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/Transforms/RegionUtils.h"
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 803fa8bff90dc0c..db9918c265164de 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -14,6 +14,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Optimizer/Builder/IntrinsicCall.h"
+#include "flang/Common/static-multimap-view.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Builder/Character.h"
 #include "flang/Optimizer/Builder/Complex.h"
@@ -41,7 +42,6 @@
 #include "flang/Optimizer/Support/Utils.h"
 #include "flang/Runtime/entry-names.h"
 #include "flang/Runtime/iostat-consts.h"
-#include "flang/Support/static-multimap-view.h"
 #include "mlir/Dialect/Complex/IR/Complex.h"
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
diff --git a/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp b/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
index 555601c5e92df6c..696e80105f80f1d 100644
--- a/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
+++ b/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/OpenMP-utils.h"
+#include "flang/Support/OpenMP-utils.h"
 
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
diff --git a/flang/lib/Parser/basic-parsers.h b/flang/lib/Parser/basic-parsers.h
index d739102b8464fe3..7e69d41debfcd2b 100644
--- a/flang/lib/Parser/basic-parsers.h
+++ b/flang/lib/Parser/basic-parsers.h
@@ -23,13 +23,13 @@
 // template functions.  See parser-combinators.txt for documentation.
 
 #include "flang/Common/idioms.h"
+#include "flang/Common/indirection.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Parser/message.h"
 #include "flang/Parser/parse-state.h"
 #include "flang/Parser/provenance.h"
 #include "flang/Parser/user-state.h"
 #include "flang/Support/Fortran-features.h"
-#include "flang/Support/indirection.h"
 #include <cstring>
 #include <functional>
 #include <list>
diff --git a/flang/lib/Parser/parse-tree.cpp b/flang/lib/Parser/parse-tree.cpp
index 89491fd2fa2a710..a414f226058e3ed 100644
--- a/flang/lib/Parser/parse-tree.cpp
+++ b/flang/lib/Parser/parse-tree.cpp
@@ -8,9 +8,9 @@
 
 #include "flang/Parser/parse-tree.h"
 #include "flang/Common/idioms.h"
+#include "flang/Common/indirection.h"
 #include "flang/Parser/tools.h"
 #include "flang/Parser/user-state.h"
-#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index d5d9252cf4c7321..993a38749bf50cc 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -11,12 +11,12 @@
 
 #include "flang/Parser/unparse.h"
 #include "flang/Common/idioms.h"
+#include "flang/Common/indirection.h"
 #include "flang/Parser/characters.h"
 #include "flang/Parser/parse-tree-visitor.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Parser/tools.h"
 #include "flang/Support/Fortran.h"
-#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <cinttypes>
diff --git a/flang/lib/Semantics/assignment.h b/flang/lib/Semantics/assignment.h
index ba0c70f7d224cb5..95d7b3cf91b17a5 100644
--- a/flang/lib/Semantics/assignment.h
+++ b/flang/lib/Semantics/assignment.h
@@ -9,9 +9,9 @@
 #ifndef FORTRAN_SEMANTICS_ASSIGNMENT_H_
 #define FORTRAN_SEMANTICS_ASSIGNMENT_H_
 
+#include "flang/Common/indirection.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Semantics/semantics.h"
-#include "flang/Support/indirection.h"
 
 namespace Fortran::parser {
 class ContextualMessages;
diff --git a/flang/lib/Semantics/check-case.cpp b/flang/lib/Semantics/check-case.cpp
index c81d3b16ab313ca..5ce143c9aec91a4 100644
--- a/flang/lib/Semantics/check-case.cpp
+++ b/flang/lib/Semantics/check-case.cpp
@@ -8,13 +8,13 @@
 
 #include "check-case.h"
 #include "flang/Common/idioms.h"
+#include "flang/Common/reference.h"
+#include "flang/Common/template.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/type.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/tools.h"
-#include "flang/Support/reference.h"
-#include "flang/Support/template.h"
 #include <tuple>
 
 namespace Fortran::semantics {
diff --git a/flang/lib/Semantics/check-coarray.cpp b/flang/lib/Semantics/check-coarray.cpp
index ac1f38801cee72c..6cf61a6b923db35 100644
--- a/flang/lib/Semantics/check-coarray.cpp
+++ b/flang/lib/Semantics/check-coarray.cpp
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "check-coarray.h"
+#include "flang/Common/indirection.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Parser/message.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Parser/tools.h"
 #include "flang/Semantics/expression.h"
 #include "flang/Semantics/tools.h"
-#include "flang/Support/indirection.h"
 
 namespace Fortran::semantics {
 
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 32dcaad52e33a3f..c85a84ea5527f05 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "check-cuda.h"
+#include "flang/Common/template.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/tools.h"
 #include "flang/Evaluate/traverse.h"
@@ -16,7 +17,6 @@
 #include "flang/Semantics/expression.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
-#include "flang/Support/template.h"
 
 // Once labeled DO constructs have been canonicalized and their parse subtrees
 // transformed into parser::DoConstructs, scan the parser::Blocks of the program
diff --git a/flang/lib/Semantics/check-data.h b/flang/lib/Semantics/check-data.h
index 6da316cccc4a7b8..479d32568fa66a2 100644
--- a/flang/lib/Semantics/check-data.h
+++ b/flang/lib/Semantics/check-data.h
@@ -10,11 +10,11 @@
 #define FORTRAN_SEMANTICS_CHECK_DATA_H_
 
 #include "data-to-inits.h"
+#include "flang/Common/interval.h"
 #include "flang/Evaluate/fold-designator.h"
 #include "flang/Evaluate/initial-image.h"
 #include "flang/Semantics/expression.h"
 #include "flang/Semantics/semantics.h"
-#include "flang/Support/interval.h"
 #include <list>
 #include <map>
 #include <vector>
diff --git a/flang/lib/Semantics/check-do-forall.cpp b/flang/lib/Semantics/check-do-forall.cpp
index ddba4c04b1ee3fa..84e6b6455cc6122 100644
--- a/flang/lib/Semantics/check-do-forall.cpp
+++ b/flang/lib/Semantics/check-do-forall.cpp
@@ -8,6 +8,7 @@
 
 #include "check-do-forall.h"
 #include "definable.h"
+#include "flang/Common/template.h"
 #include "flang/Evaluate/call.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Evaluate/tools.h"
@@ -21,7 +22,6 @@
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
 #include "flang/Semantics/type.h"
-#include "flang/Support/template.h"
 
 namespace Fortran::evaluate {
 using ActualArgumentRef = common::Reference<const ActualArgument>;
diff --git a/flang/lib/Semantics/check-select-type.cpp b/flang/lib/Semantics/check-select-type.cpp
index b86a95492b21c15..94d16a719277af6 100644
--- a/flang/lib/Semantics/check-select-type.cpp
+++ b/flang/lib/Semantics/check-select-type.cpp
@@ -8,12 +8,12 @@
 
 #include "check-select-type.h"
 #include "flang/Common/idioms.h"
+#include "flang/Common/reference.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/type.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/tools.h"
-#include "flang/Support/reference.h"
 #include <optional>
 
 namespace Fortran::semantics {
diff --git a/flang/lib/Semantics/data-to-inits.h b/flang/lib/Semantics/data-to-inits.h
index e99a02cc79db15c..7486ac8113e9030 100644
--- a/flang/lib/Semantics/data-to-inits.h
+++ b/flang/lib/Semantics/data-to-inits.h
@@ -9,10 +9,10 @@
 #ifndef FORTRAN_SEMANTICS_DATA_TO_INITS_H_
 #define FORTRAN_SEMANTICS_DATA_TO_INITS_H_
 
+#include "flang/Common/interval.h"
 #include "flang/Evaluate/fold-designator.h"
 #include "flang/Evaluate/initial-image.h"
 #include "flang/Support/default-kinds.h"
-#include "flang/Support/interval.h"
 #include <list>
 #include <map>
 
diff --git a/flang/lib/Semantics/pointer-assignment.cpp b/flang/lib/Semantics/pointer-assignment.cpp
index 49684ffd5f80424..7f4548c7327e3b8 100644
--- a/flang/lib/Semantics/pointer-assignment.cpp
+++ b/flang/lib/Semantics/pointer-assignment.cpp
@@ -10,6 +10,7 @@
 #include "definable.h"
 #include "flang/Common/idioms.h"
 #include "flang/Common/restorer.h"
+#include "flang/Common/template.h"
 #include "flang/Evaluate/characteristics.h"
 #include "flang/Evaluate/expression.h"
 #include "flang/Evaluate/fold.h"
@@ -20,7 +21,6 @@
 #include "flang/Semantics/expression.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
-#include "flang/Support/template.h"
 #include "llvm/Support/raw_ostream.h"
 #include <optional>
 #include <set>
diff --git a/flang/lib/Semantics/resolve-labels.cpp b/flang/lib/Semantics/resolve-labels.cpp
index 584319b8abdf630..04e4b142efedf85 100644
--- a/flang/lib/Semantics/resolve-labels.cpp
+++ b/flang/lib/Semantics/resolve-labels.cpp
@@ -8,9 +8,9 @@
 
 #include "resolve-labels.h"
 #include "flang/Common/enum-set.h"
+#include "flang/Common/template.h"
 #include "flang/Parser/parse-tree-visitor.h"
 #include "flang/Semantics/semantics.h"
-#include "flang/Support/template.h"
 #include <cstdarg>
 #include <type_traits>
 
diff --git a/flang/lib/Semantics/resolve-names-utils.cpp b/flang/lib/Semantics/resolve-names-utils.cpp
index 065090ed03b6a66..c91c522b7c73ea3 100644
--- a/flang/lib/Semantics/resolve-names-utils.cpp
+++ b/flang/lib/Semantics/resolve-names-utils.cpp
@@ -8,6 +8,7 @@
 
 #include "resolve-names-utils.h"
 #include "flang/Common/idioms.h"
+#include "flang/Common/indirection.h"
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/tools.h"
 #include "flang/Evaluate/traverse.h"
@@ -19,7 +20,6 @@
 #include "flang/Semantics/tools.h"
 #include "flang/Support/Fortran-features.h"
 #include "flang/Support/Fortran.h"
-#include "flang/Support/indirection.h"
 #include <initializer_list>
 #include <variant>
 
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index d0e0a3784f2afbe..d6d05a41f691765 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -13,6 +13,7 @@
 #include "resolve-directives.h"
 #include "resolve-names-utils.h"
 #include "rewrite-parse-tree.h"
+#include "flang/Common/indirection.h"
 #include "flang/Common/restorer.h"
 #include "flang/Common/visit.h"
 #include "flang/Evaluate/characteristics.h"
@@ -37,7 +38,6 @@
 #include "flang/Semantics/type.h"
 #include "flang/Support/Fortran.h"
 #include "flang/Support/default-kinds.h"
-#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <list>
 #include <map>
diff --git a/flang/lib/Semantics/rewrite-parse-tree.cpp b/flang/lib/Semantics/rewrite-parse-tree.cpp
index 171c0021fba08c2..577558e7e33b261 100644
--- a/flang/lib/Semantics/rewrite-parse-tree.cpp
+++ b/flang/lib/Semantics/rewrite-parse-tree.cpp
@@ -8,6 +8,7 @@
 
 #include "rewrite-parse-tree.h"
 #include "rewrite-directives.h"
+#include "flang/Common/indirection.h"
 #include "flang/Parser/parse-tree-visitor.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Parser/tools.h"
@@ -15,7 +16,6 @@
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
-#include "flang/Support/indirection.h"
 #include <list>
 
 namespace Fortran::semantics {
diff --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp
index 64e4c9d7e194dba..1166ec9a58f86c7 100644
--- a/flang/lib/Semantics/tools.cpp
+++ b/flang/lib/Semantics/tools.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Parser/tools.h"
+#include "flang/Common/indirection.h"
 #include "flang/Parser/dump-parse-tree.h"
 #include "flang/Parser/message.h"
 #include "flang/Parser/parse-tree.h"
@@ -16,7 +17,6 @@
 #include "flang/Semantics/tools.h"
 #include "flang/Semantics/type.h"
 #include "flang/Support/Fortran.h"
-#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <set>
diff --git a/flang/lib/Support/OpenMP-utils.cpp b/flang/lib/Support/OpenMP-utils.cpp
index b3cab763aca3035..178a6e38dc0f2ff 100644
--- a/flang/lib/Support/OpenMP-utils.cpp
+++ b/flang/lib/Support/OpenMP-utils.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/OpenMP-utils.h"
+#include "flang/Support/OpenMP-utils.h"
 
 #include "mlir/IR/OpDefinition.h"
 

>From f3e9c1533d550b89c476c4f12123d5fb074e387b Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Wed, 29 Jan 2025 11:39:41 +0100
Subject: [PATCH 08/18] add missing includes

---
 flang/include/flang/Common/erfc-scaled.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/flang/include/flang/Common/erfc-scaled.h b/flang/include/flang/Common/erfc-scaled.h
index a1bf3ea0f09251d..88e2183c15d035c 100644
--- a/flang/include/flang/Common/erfc-scaled.h
+++ b/flang/include/flang/Common/erfc-scaled.h
@@ -9,6 +9,9 @@
 #ifndef FORTRAN_COMMON_ERFC_SCALED_H_
 #define FORTRAN_COMMON_ERFC_SCALED_H_
 
+#include <cmath>
+#include <limits>
+
 namespace Fortran::common {
 template <typename T> inline T ErfcScaled(T arg) {
   // Coefficients for approximation to erfc in the first interval.

>From 6a7bd039888c71fe037c451223fd602ccc046b09 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Wed, 29 Jan 2025 13:53:45 +0100
Subject: [PATCH 09/18] Use C++style comments for header guards

---
 flang/include/flang/Runtime/random.h           | 2 +-
 flang/include/flang/Support/Fortran-features.h | 2 +-
 flang/include/flang/Support/Fortran.h          | 2 +-
 flang/include/flang/Support/LangOptions.h      | 2 +-
 flang/include/flang/Support/MathOptionsBase.h  | 2 +-
 flang/include/flang/Support/OpenMP-utils.h     | 2 +-
 flang/include/flang/Support/Timing.h           | 8 ++++----
 flang/include/flang/Support/Version.h          | 2 +-
 flang/include/flang/Support/default-kinds.h    | 2 +-
 flang/lib/Support/Timing.cpp                   | 2 +-
 10 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/flang/include/flang/Runtime/random.h b/flang/include/flang/Runtime/random.h
index bb6dcb3873f21d2..1f01be1aa9ffa08 100644
--- a/flang/include/flang/Runtime/random.h
+++ b/flang/include/flang/Runtime/random.h
@@ -39,4 +39,4 @@ void RTNAME(RandomSeed)(const Descriptor *size, const Descriptor *put,
 } // extern "C"
 } // namespace Fortran::runtime
 
-#endif /* FORTRAN_RUNTIME_RANDOM_H_ */
+#endif // FORTRAN_RUNTIME_RANDOM_H_
diff --git a/flang/include/flang/Support/Fortran-features.h b/flang/include/flang/Support/Fortran-features.h
index 58f84e94136762d..826b65e8d3c3c78 100644
--- a/flang/include/flang/Support/Fortran-features.h
+++ b/flang/include/flang/Support/Fortran-features.h
@@ -125,4 +125,4 @@ class LanguageFeatureControl {
   bool warnAllUsage_{false};
 };
 } // namespace Fortran::common
-#endif /* FORTRAN_SUPPORT_FORTRAN_FEATURES_H_ */
+#endif // FORTRAN_SUPPORT_FORTRAN_FEATURES_H_
diff --git a/flang/include/flang/Support/Fortran.h b/flang/include/flang/Support/Fortran.h
index 4e6bdbb67f5f355..6e6e37ba594bed9 100644
--- a/flang/include/flang/Support/Fortran.h
+++ b/flang/include/flang/Support/Fortran.h
@@ -109,4 +109,4 @@ inline std::string GetExternalAssemblyName(
 }
 
 } // namespace Fortran::common
-#endif /* FORTRAN_SUPPORT_FORTRAN_H_ */
+#endif // FORTRAN_SUPPORT_FORTRAN_H_
diff --git a/flang/include/flang/Support/LangOptions.h b/flang/include/flang/Support/LangOptions.h
index f4f197dd87ca37e..fac6fb92df85a25 100644
--- a/flang/include/flang/Support/LangOptions.h
+++ b/flang/include/flang/Support/LangOptions.h
@@ -77,4 +77,4 @@ class LangOptions : public LangOptionsBase {
 
 } // end namespace Fortran::common
 
-#endif /* FORTRAN_SUPPORT_LANGOPTIONS_H_ */
+#endif // FORTRAN_SUPPORT_LANGOPTIONS_H_
diff --git a/flang/include/flang/Support/MathOptionsBase.h b/flang/include/flang/Support/MathOptionsBase.h
index b4838c63d4ef897..a2bea3c598a8c09 100644
--- a/flang/include/flang/Support/MathOptionsBase.h
+++ b/flang/include/flang/Support/MathOptionsBase.h
@@ -41,4 +41,4 @@ class MathOptionsBase {
 
 } // namespace Fortran::common
 
-#endif /* FORTRAN_SUPPORT_MATHOPTIONSBASE_H_ */
+#endif // FORTRAN_SUPPORT_MATHOPTIONSBASE_H_
diff --git a/flang/include/flang/Support/OpenMP-utils.h b/flang/include/flang/Support/OpenMP-utils.h
index ad3da16008319e6..d8f82e1cf94f1c7 100644
--- a/flang/include/flang/Support/OpenMP-utils.h
+++ b/flang/include/flang/Support/OpenMP-utils.h
@@ -73,4 +73,4 @@ mlir::Block *genEntryBlock(
     mlir::OpBuilder &builder, const EntryBlockArgs &args, mlir::Region &region);
 } // namespace Fortran::common::openmp
 
-#endif /* FORTRAN_SUPPORT_OPENMP_UTILS_H_ */
+#endif // FORTRAN_SUPPORT_OPENMP_UTILS_H_
diff --git a/flang/include/flang/Support/Timing.h b/flang/include/flang/Support/Timing.h
index 5d66831d6c1c283..75ba2a8d85f39fe 100644
--- a/flang/include/flang/Support/Timing.h
+++ b/flang/include/flang/Support/Timing.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Support/Timing.h --------------------------*- C++ -*-===//
+//===- Timing.h - Execution time measurement facilities ---------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,8 +10,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_SUPPORT_TIMING_H_
-#define FORTRAN_SUPPORT_TIMING_H_
+#ifndef FORTRAN_SUPPORT_TIMING_H
+#define FORTRAN_SUPPORT_TIMING_H
 
 #include "mlir/Support/Timing.h"
 
@@ -24,4 +24,4 @@ std::unique_ptr<mlir::OutputStrategy> createTimingFormatterText(
 
 } // namespace Fortran::support
 
-#endif /* FORTRAN_SUPPORT_TIMING_H_ */
+#endif // FORTRAN_SUPPORT_TIMING_H
diff --git a/flang/include/flang/Support/Version.h b/flang/include/flang/Support/Version.h
index 4ceb19e7f4d714a..fe7f7395e1ebaa7 100644
--- a/flang/include/flang/Support/Version.h
+++ b/flang/include/flang/Support/Version.h
@@ -53,4 +53,4 @@ std::string getFlangFullVersion();
 std::string getFlangToolFullVersion(llvm::StringRef ToolName);
 } // namespace Fortran::common
 
-#endif /* FORTRAN_SUPPORT_VERSION_H_ */
+#endif // FORTRAN_SUPPORT_VERSION_H_
diff --git a/flang/include/flang/Support/default-kinds.h b/flang/include/flang/Support/default-kinds.h
index 5553366aa409d46..ab1422d63af3003 100644
--- a/flang/include/flang/Support/default-kinds.h
+++ b/flang/include/flang/Support/default-kinds.h
@@ -58,4 +58,4 @@ class IntrinsicTypeDefaultKinds {
   int defaultLogicalKind_{defaultIntegerKind_};
 };
 } // namespace Fortran::common
-#endif /* FORTRAN_SUPPORT_DEFAULT_KINDS_H_ */
+#endif // FORTRAN_SUPPORT_DEFAULT_KINDS_H_
diff --git a/flang/lib/Support/Timing.cpp b/flang/lib/Support/Timing.cpp
index 41cb2be8269070b..ee8309a950eec86 100644
--- a/flang/lib/Support/Timing.cpp
+++ b/flang/lib/Support/Timing.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Support/Timing.cpp ----------------------------------*- C++ -*-===//
+//===- Timing.cpp - Execution time measurement facilities -----------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

>From db749b9e8d8490486cd45cf0b9e0ccf9ada77f44 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Wed, 29 Jan 2025 14:15:02 +0100
Subject: [PATCH 10/18] Use C++style comments for header guards II

---
 flang/include/flang/Support/OpenMP-features.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/include/flang/Support/OpenMP-features.h b/flang/include/flang/Support/OpenMP-features.h
index 85c901e7fdb82fa..1dd7ea560cc963c 100644
--- a/flang/include/flang/Support/OpenMP-features.h
+++ b/flang/include/flang/Support/OpenMP-features.h
@@ -49,4 +49,4 @@ void setOpenMPMacro(int version, FortranPredefinitions &predefinitions) {
   }
 }
 } // namespace Fortran::common
-#endif /* FORTRAN_SUPPORT_OPENMP_FEATURES_H_ */
+#endif // FORTRAN_SUPPORT_OPENMP_FEATURES_H_

>From f4729e6a2fce9b20bb259f877618099d841cf037 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 3 Feb 2025 13:03:25 +0100
Subject: [PATCH 11/18] Conditionalize runtime example

---
 flang/examples/CMakeLists.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/flang/examples/CMakeLists.txt b/flang/examples/CMakeLists.txt
index 8cc66ddbbbb0ef4..23c6e790791fba2 100644
--- a/flang/examples/CMakeLists.txt
+++ b/flang/examples/CMakeLists.txt
@@ -1,4 +1,6 @@
-add_subdirectory(ExternalHelloWorld)
+if (FLANG_INCLUDE_RUNTIME)
+  add_subdirectory(ExternalHelloWorld)
+endif ()
 add_subdirectory(PrintFlangFunctionNames)
 add_subdirectory(FlangOmpReport)
 add_subdirectory(FeatureList)

>From 4303d5ac59c4ed62acff104501a11ee89f4a549a Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 3 Feb 2025 21:09:45 +0100
Subject: [PATCH 12/18] Rename to libflang_rt.<component>.(a|so)

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp    |  6 +--
 clang/lib/Driver/ToolChains/Flang.cpp         | 22 +++++----
 flang/cmake/modules/AddFlang.cmake            |  2 +-
 flang/docs/FlangDriver.md                     |  6 +--
 flang/docs/GettingStarted.md                  |  2 +-
 flang/docs/OpenACC-descriptor-management.md   |  2 +-
 flang/docs/Real16MathSupport.md               |  4 +-
 flang/docs/ReleaseNotes.md                    |  7 ++-
 .../ExternalHelloWorld/CMakeLists.txt         |  2 +-
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp |  4 +-
 flang/runtime/CMakeLists.txt                  | 47 +++++++++++--------
 flang/runtime/CUDA/CMakeLists.txt             |  6 +--
 flang/runtime/Float128Math/CMakeLists.txt     | 14 +++---
 flang/runtime/tools.h                         |  2 +-
 flang/test/CMakeLists.txt                     |  2 +-
 .../test/Driver/gcc-toolchain-install-dir.f90 |  2 +-
 flang/test/Driver/linker-flags.f90            | 28 +++++------
 .../test/Driver/msvc-dependent-lib-flags.f90  |  8 ++--
 flang/test/Driver/nostdlib.f90                |  2 +-
 flang/test/lit.cfg.py                         |  2 +-
 flang/unittests/Evaluate/CMakeLists.txt       |  4 +-
 flang/unittests/Runtime/CMakeLists.txt        |  2 +-
 flang/unittests/Runtime/CUDA/CMakeLists.txt   |  4 +-
 lld/COFF/MinGW.cpp                            |  2 +-
 24 files changed, 100 insertions(+), 82 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 361cf41544b0642..a213a055956cecc 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1321,7 +1321,7 @@ void tools::addOpenMPHostOffloadingArgs(const Compilation &C,
 /// Add Fortran runtime libs
 void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
                                   llvm::opt::ArgStringList &CmdArgs) {
-  // Link flang_rt
+  // Link flang_rt.runtime
   // These are handled earlier on Windows by telling the frontend driver to
   // add the correct libraries to link against as dependents in the object
   // file.
@@ -1330,14 +1330,14 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
     F128LibName.consume_front_insensitive("lib");
     if (!F128LibName.empty()) {
       bool AsNeeded = !TC.getTriple().isOSAIX();
-      CmdArgs.push_back("-lFortranFloat128Math");
+      CmdArgs.push_back("-lflang_rt.quadmath");
       if (AsNeeded)
         addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/true);
       CmdArgs.push_back(Args.MakeArgString("-l" + F128LibName));
       if (AsNeeded)
         addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
     }
-    CmdArgs.push_back("-lflang_rt");
+    CmdArgs.push_back("-lflang_rt.runtime");
     addArchSpecificRPath(TC, Args, CmdArgs);
   }
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 87111e18114f5c8..f6ff58d07e822ea 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -345,11 +345,15 @@ static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args,
                                     ArgStringList &CmdArgs) {
   assert(TC.getTriple().isKnownWindowsMSVCEnvironment() &&
          "can only add VS runtime library on Windows!");
-  // if -fno-fortran-main has been passed, skip linking Fortran_main.a
-  if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
-    CmdArgs.push_back(Args.MakeArgString(
-        "--dependent-lib=" + TC.getCompilerRTBasename(Args, "builtins")));
-  }
+
+  // Flang/Clang (including clang-cl) -compiled programs targeting the MSVC ABI
+  // should only depend on msv(u)crt. LLVM still emits libgcc/compiler-rt
+  // functions in some cases like 128-bit integer math (__udivti3, __modti3,
+  // __fixsfti, __floattidf, ...) that msvc does not support. We are injecting a
+  // dependency to Compiler-RT's builtin library where these are implemented.
+  CmdArgs.push_back(Args.MakeArgString(
+      "--dependent-lib=" + TC.getCompilerRTBasename(Args, "builtins")));
+
   unsigned RTOptionID = options::OPT__SLASH_MT;
   if (auto *rtl = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
     RTOptionID = llvm::StringSwitch<unsigned>(rtl->getValue())
@@ -363,26 +367,26 @@ static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args,
   case options::OPT__SLASH_MT:
     CmdArgs.push_back("-D_MT");
     CmdArgs.push_back("--dependent-lib=libcmt");
-    CmdArgs.push_back("--dependent-lib=flang_rt.static.lib");
+    CmdArgs.push_back("--dependent-lib=flang_rt.runtime.static.lib");
     break;
   case options::OPT__SLASH_MTd:
     CmdArgs.push_back("-D_MT");
     CmdArgs.push_back("-D_DEBUG");
     CmdArgs.push_back("--dependent-lib=libcmtd");
-    CmdArgs.push_back("--dependent-lib=flang_rt.static_dbg.lib");
+    CmdArgs.push_back("--dependent-lib=flang_rt.runtime.static_dbg.lib");
     break;
   case options::OPT__SLASH_MD:
     CmdArgs.push_back("-D_MT");
     CmdArgs.push_back("-D_DLL");
     CmdArgs.push_back("--dependent-lib=msvcrt");
-    CmdArgs.push_back("--dependent-lib=flang_rt.dynamic.lib");
+    CmdArgs.push_back("--dependent-lib=flang_rt.runtime.dynamic.lib");
     break;
   case options::OPT__SLASH_MDd:
     CmdArgs.push_back("-D_MT");
     CmdArgs.push_back("-D_DEBUG");
     CmdArgs.push_back("-D_DLL");
     CmdArgs.push_back("--dependent-lib=msvcrtd");
-    CmdArgs.push_back("--dependent-lib=flang_rt.dynamic_dbg.lib");
+    CmdArgs.push_back("--dependent-lib=flang_rt.runtime.dynamic_dbg.lib");
     break;
   }
 }
diff --git a/flang/cmake/modules/AddFlang.cmake b/flang/cmake/modules/AddFlang.cmake
index 1f178772067edc7..c9f65eb73fef00a 100644
--- a/flang/cmake/modules/AddFlang.cmake
+++ b/flang/cmake/modules/AddFlang.cmake
@@ -57,7 +57,7 @@ function(add_flang_library name)
     set(LIBTYPE SHARED)
   elseif(ARG_STATIC)
     # If BUILD_SHARED_LIBS and ARG_STATIC are both set, llvm_add_library prioritizes STATIC.
-    # This is required behavior for libFortranFloat128Math.
+    # This is required behavior for libflang_rt.quadmath.
     set(LIBTYPE STATIC)
   else()
     # Let llvm_add_library decide, taking BUILD_SHARED_LIBS into account.
diff --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index e8dc3de3577db2c..97744f0bee069b1 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -175,18 +175,18 @@ like this:
 
 ```
 $ flang -v -o example example.o
-"/usr/bin/ld" [...] example.o [...] "-lflang_rt" [...]
+"/usr/bin/ld" [...] example.o [...] "-lflang_rt.runtime" [...]
 ```
 
 The automatically added libraries are:
 
-* `flang_rt`: Provides most of the Flang runtime library.
+* `flang_rt.runtime`: Provides most of the Flang runtime library.
 
 If the code is C/C++ based and invokes Fortran routines, one can either use Clang
 or Flang as the linker driver.  If Clang is used, it will automatically all
 required runtime libraries needed by C++ (e.g., for STL) to the linker invocation.
 In this case, one has to explicitly provide the Fortran runtime library
-`flang_rt`.  An alternative is to use Flang to link.
+`flang_rt.runtime`.  An alternative is to use Flang to link.
 In this case, it may be required to explicitly supply C++ runtime libraries.
 
 On Darwin, the logical root where the system libraries are located (sysroot)
diff --git a/flang/docs/GettingStarted.md b/flang/docs/GettingStarted.md
index ffde50b6f481e88..e422a31a0b40210 100644
--- a/flang/docs/GettingStarted.md
+++ b/flang/docs/GettingStarted.md
@@ -309,7 +309,7 @@ The same set of CMake variables works for Flang in-tree build.
 One may provide optional CMake variables to customize the build. Available options:
 
 * `-DFLANG_RUNTIME_F128_MATH_LIB=libquadmath`: enables build of
-  `FortranFloat128Math` library that provides `REAL(16)` math APIs
+  `flang_rt.quadmath` library that provides `REAL(16)` math APIs
   for intrinsics such as `SIN`, `COS`, etc. GCC `libquadmath`'s header file
   `quadmath.h` must be available to the build compiler.
   [More details](Real16MathSupport.md).
diff --git a/flang/docs/OpenACC-descriptor-management.md b/flang/docs/OpenACC-descriptor-management.md
index 6c147a56894c8f5..008c57937e23b89 100644
--- a/flang/docs/OpenACC-descriptor-management.md
+++ b/flang/docs/OpenACC-descriptor-management.md
@@ -427,7 +427,7 @@ The implementation's behavior may be described as (OpenACC 2.7.2):
 
 All the "is-present" checks and the data actions for the auxiliary pointers must be performed atomically with regards to the present counters bookkeeping.
 
-The API relies on the primitives provided by `liboffload`, so it is provided by a new F18 runtime library, e.g. `FortranOffloadRuntime`, that depends on `flang_rt` and `liboffload`.  The F18 driver adds `FortranOffloadRuntime` for linking under `-fopenacc`/`-fopenmp` (and maybe additional switches like `-fopenmp-targets`).
+The API relies on the primitives provided by `liboffload`, so it is provided by a new F18 runtime library, e.g. `FortranOffloadRuntime`, that depends on `flang_rt.runtime` and `liboffload`.  The F18 driver adds `FortranOffloadRuntime` for linking under `-fopenacc`/`-fopenmp` (and maybe additional switches like `-fopenmp-targets`).
 
 ## TODOs:
 
diff --git a/flang/docs/Real16MathSupport.md b/flang/docs/Real16MathSupport.md
index 21482c7be21af6d..93492c8b767c394 100644
--- a/flang/docs/Real16MathSupport.md
+++ b/flang/docs/Real16MathSupport.md
@@ -12,9 +12,9 @@ To support most `REAL(16)` (i.e. 128-bit float) math intrinsics Flang relies
 on third-party libraries providing the implementation.
 
 `-DFLANG_RUNTIME_F128_MATH_LIB=libquadmath` CMake option can be used
-to build `FortranFloat128Math` library that has unresolved references
+to build `libflang_rt.quadmath` library that has unresolved references
 to GCC `libquadmath` library. A Flang driver built with this option
-will automatically link `FortranFloat128Math` and `libquadmath` libraries
+will automatically link `libflang_rt.quadmath` and `libquadmath` libraries
 to any Fortran program. This implies that `libquadmath` library
 has to be available in the standard library paths, so that linker
 can find it. The `libquadmath` library installation into Flang project
diff --git a/flang/docs/ReleaseNotes.md b/flang/docs/ReleaseNotes.md
index a163b4f4ed67dee..387d4b2e62e0fee 100644
--- a/flang/docs/ReleaseNotes.md
+++ b/flang/docs/ReleaseNotes.md
@@ -36,7 +36,12 @@ page](https://llvm.org/releases/).
 
 ## Build System Changes
 
- * FortranRuntime has been renamed to `flang_rt`.
+ * The FortranRuntime library has been renamed to `flang_rt.runtime`.
+
+ * The FortranFloat128Math library has been renamed to `flang_rt.quadmath`.
+
+ * The CufRuntime_cuda_${version} library has been renamed to
+   `flang_rt.cuda_${version}`.
 
 ## New Issues Found
 
diff --git a/flang/examples/ExternalHelloWorld/CMakeLists.txt b/flang/examples/ExternalHelloWorld/CMakeLists.txt
index 213fc462ac2b1a0..b61948718a5e3de 100644
--- a/flang/examples/ExternalHelloWorld/CMakeLists.txt
+++ b/flang/examples/ExternalHelloWorld/CMakeLists.txt
@@ -5,5 +5,5 @@ add_llvm_example(external-hello-world
 
 target_link_libraries(external-hello-world
   PRIVATE
-  flang_rt
+  flang_rt.runtime
   )
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index ea78103d78239d9..d7d1471535db8d9 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -808,8 +808,8 @@ prettyPrintIntrinsicName(fir::FirOpBuilder &builder, mlir::Location loc,
 // Generate a call to the Fortran runtime library providing
 // support for 128-bit float math.
 // On 'HAS_LDBL128' targets the implementation
-// is provided by flang_rt, otherwise, it is done via
-// FortranFloat128Math library. In the latter case the compiler
+// is provided by flang_rt, otherwise, it is done via the
+// libflang_rt.quadmath library. In the latter case the compiler
 // has to be built with FLANG_RUNTIME_F128_MATH_LIB to guarantee
 // proper linking actions in the driver.
 static mlir::Value genLibF128Call(fir::FirOpBuilder &builder,
diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index 3e32daba52a818b..1186d4b429de4f1 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -239,9 +239,9 @@ set(supported_files
 enable_cuda_compilation(flang_rt "${supported_files}")
 enable_omp_offload_compilation("${supported_files}")
 
-if (NOT TARGET FortranFloat128Math)
-  # If FortranFloat128Math is not defined, then we are not building
-  # standalone FortranFloat128Math library. Instead, include
+if (NOT TARGET flang_rt.quadmath)
+  # If flang_rt.quadmath is not defined, then we are not building
+  # standalone flang_rt.quadmath library. Instead, include
   # the relevant sources into flang_rt itself.
   # The information is provided via FortranFloat128MathILib
   # interface library.
@@ -270,35 +270,38 @@ if (NOT TARGET FortranFloat128Math)
 endif()
 
 if (NOT DEFINED MSVC)
-  add_flang_library(flang_rt
+  add_flang_library(flang_rt.runtime
     ${sources}
 
     INSTALL_WITH_TOOLCHAIN
   )
 else()
-  add_flang_library(flang_rt
+  add_flang_library(flang_rt.runtime
     ${sources}
   )
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
-  add_flang_library(flang_rt.static ${sources}
+  add_flang_library(flang_rt.runtime.static ${sources}
     INSTALL_WITH_TOOLCHAIN)
-  set_target_properties(flang_rt.static PROPERTIES FOLDER "Flang/Runtime Libraries")
+  set_target_properties(flang_rt.runtime.static PROPERTIES FOLDER "Flang/Runtime Libraries")
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
-  add_flang_library(flang_rt.dynamic ${sources}
+  add_flang_library(flang_rt.runtime.dynamic ${sources}
     INSTALL_WITH_TOOLCHAIN)
-  set_target_properties(flang_rt.dynamic PROPERTIES FOLDER "Flang/Runtime Libraries")
+  set_target_properties(flang_rt.runtime.dynamic PROPERTIES FOLDER "Flang/Runtime Libraries")
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
-  add_flang_library(flang_rt.static_dbg ${sources}
+  add_flang_library(flang_rt.runtime.static_dbg ${sources}
     INSTALL_WITH_TOOLCHAIN)
-  set_target_properties(flang_rt.static_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
+  set_target_properties(flang_rt.runtime.static_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL)
-  add_flang_library(flang_rt.dynamic_dbg ${sources}
+  add_flang_library(flang_rt.runtime.dynamic_dbg ${sources}
     INSTALL_WITH_TOOLCHAIN)
-  set_target_properties(flang_rt.dynamic_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
-  add_dependencies(flang_rt flang_rt.static flang_rt.dynamic
-    flang_rt.static_dbg flang_rt.dynamic_dbg)
+  set_target_properties(flang_rt.runtime.dynamic_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
+  add_dependencies(flang_rt.runtime
+    flang_rt.runtime.static
+    flang_rt.runtime.dynamic
+    flang_rt.runtime.static_dbg
+    flang_rt.runtime.dynamic_dbg)
 endif()
-set_target_properties(flang_rt PROPERTIES FOLDER "Flang/Runtime Libraries")
+set_target_properties(flang_rt.runtime PROPERTIES FOLDER "Flang/Runtime Libraries")
 
 # If flang_rt is part of a Flang build (and not a separate build) then
 # add dependency to make sure that Fortran runtime library is being built after
@@ -308,7 +311,7 @@ set_target_properties(flang_rt PROPERTIES FOLDER "Flang/Runtime Libraries")
 # TODO: This is a workaround and should be updated when runtime build procedure
 # is changed to a regular runtime build.  See discussion in PR #95388.
 if (TARGET flang AND TARGET module_files)
-  add_dependencies(flang_rt flang module_files)
+  add_dependencies(flang_rt.runtime flang module_files)
 endif()
 
 if (FLANG_CUF_RUNTIME)
@@ -317,6 +320,12 @@ endif()
 
 # Compatibility targets.
 add_custom_target(flang-rt)
-add_dependencies(flang-rt flang_rt)
+add_dependencies(flang-rt flang_rt.runtime)
+if (TARGET flang_rt.quadmath)
+  add_dependencies(flang-rt flang_rt.quadmath)
+endif ()
+if (TARGET flang_rt.cuda_${CUDAToolkit_VERSION_MAJOR})
+  add_dependencies(flang-rt flang_rt.cuda_${CUDAToolkit_VERSION_MAJOR})
+endif ()
 add_custom_target(FortranRuntime)
-add_dependencies(FortranRuntime flang_rt)
+add_dependencies(FortranRuntime flang_rt.runtime)
diff --git a/flang/runtime/CUDA/CMakeLists.txt b/flang/runtime/CUDA/CMakeLists.txt
index a20f77e427ce623..1fd3bf22a83cf81 100644
--- a/flang/runtime/CUDA/CMakeLists.txt
+++ b/flang/runtime/CUDA/CMakeLists.txt
@@ -8,10 +8,10 @@
 
 include_directories(${CUDAToolkit_INCLUDE_DIRS})
 
-# libCufRuntime depends on a certain version of CUDA. To be able to have
+# libflang_rt.cuda depends on a certain version of CUDA. To be able to have
 # multiple build of this library with different CUDA version, the version is
 # added to the library name.
-set(CUFRT_LIBNAME CufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR})
+set(CUFRT_LIBNAME flang_rt.cuda_${CUDAToolkit_VERSION_MAJOR})
 
 add_flang_library(${CUFRT_LIBNAME}
   allocator.cpp
@@ -33,6 +33,6 @@ endif()
 
 target_link_libraries(${CUFRT_LIBNAME}
   PRIVATE
-  flang_rt
+  flang_rt.runtime
   ${CUDA_RT_TARGET}
 )
diff --git a/flang/runtime/Float128Math/CMakeLists.txt b/flang/runtime/Float128Math/CMakeLists.txt
index d65193be05ab5c1..3c382d16a21cdaf 100644
--- a/flang/runtime/Float128Math/CMakeLists.txt
+++ b/flang/runtime/Float128Math/CMakeLists.txt
@@ -12,7 +12,7 @@
 # It is distributed as a static library only.
 # Fortran programs/libraries that end up linking any of the provided
 # will have a dependency on the third-party library that is being
-# used for building this FortranFloat128Math library.
+# used for building this flang_rt.quadmath library.
 
 include(CheckLibraryExists)
 
@@ -93,20 +93,20 @@ if (FLANG_RUNTIME_F128_MATH_LIB)
       )
   endif()
 
-  add_flang_library(FortranFloat128Math STATIC INSTALL_WITH_TOOLCHAIN
+  add_flang_library(flang_rt.quadmath STATIC INSTALL_WITH_TOOLCHAIN
     ${sources})
 
   if (DEFINED MSVC)
     set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
-    add_flang_library(FortranFloat128Math.static STATIC INSTALL_WITH_TOOLCHAIN
+    add_flang_library(flang_rt.quadmath.static STATIC INSTALL_WITH_TOOLCHAIN
       ${sources}
       )
     set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
-    add_flang_library(FortranFloat128Math.static_dbg STATIC INSTALL_WITH_TOOLCHAIN
+    add_flang_library(flang_rt.quadmath.static_dbg STATIC INSTALL_WITH_TOOLCHAIN
       ${sources}
       )
-    add_dependencies(FortranFloat128Math FortranFloat128Math.static
-      FortranFloat128Math.static_dbg
+    add_dependencies(flang_rt.quadmath flang_rt.quadmath.static
+      flang_rt.quadmath.static_dbg
       )
   endif()
 elseif (HAVE_LDBL_MANT_DIG_113)
@@ -118,7 +118,7 @@ elseif (HAVE_LDBL_MANT_DIG_113)
       )
     target_sources(FortranFloat128MathILib INTERFACE ${sources})
   else()
-    message(FATAL_ERROR "flang_rt cannot build without libm")
+    message(FATAL_ERROR "flang_rt.quadmath cannot build without libm")
   endif()
 else()
   # We can use '__float128' version from libc, if it has them.
diff --git a/flang/runtime/tools.h b/flang/runtime/tools.h
index facbd2316105700..75544098d47ab27 100644
--- a/flang/runtime/tools.h
+++ b/flang/runtime/tools.h
@@ -348,7 +348,7 @@ inline RT_API_ATTRS RESULT ApplyFloatingPointKind(
     if constexpr (HasCppTypeFor<TypeCategory::Real, 16>) {
       // If FUNC implemenation relies on FP math functions,
       // then we should not be here. The compiler should have
-      // generated a call to an entry in FortranFloat128Math
+      // generated a call to an entry in flang_rt.quadmath
       // library.
       if constexpr (!NEEDSMATH) {
         return FUNC<16>{}(std::forward<A>(x)...);
diff --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt
index e8e8099d4eaf7bc..3fac8717e9bd9da 100644
--- a/flang/test/CMakeLists.txt
+++ b/flang/test/CMakeLists.txt
@@ -75,7 +75,7 @@ set(FLANG_TEST_DEPENDS
 )
 
 if (FLANG_INCLUDE_RUNTIME)
-  list(APPEND FLANG_TEST_DEPENDS flang_rt)
+  list(APPEND FLANG_TEST_DEPENDS flang_rt.runtime)
 endif ()
 
 if (LLVM_ENABLE_PLUGINS AND NOT WIN32)
diff --git a/flang/test/Driver/gcc-toolchain-install-dir.f90 b/flang/test/Driver/gcc-toolchain-install-dir.f90
index d9160e1971250fe..e195bdde6d2c93a 100644
--- a/flang/test/Driver/gcc-toolchain-install-dir.f90
+++ b/flang/test/Driver/gcc-toolchain-install-dir.f90
@@ -1,5 +1,5 @@
 !! Test that --gcc-toolchain and --gcc-install-dir options are working as expected.
-!! It does not test cross-compiling (--sysroot), so crtbegin.o, libgcc/compiler-rt, libc, libflang_rt, etc. are not supposed to be affected.
+!! It does not test cross-compiling (--sysroot), so crtbegin.o, libgcc/compiler-rt, libc, libflang_rt.runtime, etc. are not supposed to be affected.
 !! PREFIX is captured twice because the driver escapes backslashes (occuring in Windows paths) in the -### output, but not on the "Selected GCC installation:" line.
 
 ! RUN: %flang 2>&1 -### -v -o %t %s -no-integrated-as -fuse-ld=ld --target=i386-unknown-linux-gnu --gcc-install-dir=%S/Inputs/basic_cross_linux_tree/usr/lib/gcc/i386-unknown-linux-gnu/10.2.0 | FileCheck %s --check-prefix=CHECK-I386
diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90
index 5dc89fe45c8cc0d..0b6eff80432476d 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -29,30 +29,30 @@
 !       executable and may find the GNU linker from MinGW or Cygwin.
 ! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! UNIX-SAME: "[[object_file]]"
-! UNIX-F128NONE-NOT: FortranFloat128Math
-! SOLARIS-F128NONE-NOT: FortranFloat128Math
-! UNIX-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
-! SOLARIS-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "-z" "ignore" "-lquadmath" "-z" "record"
-! UNIX-SAME: "-lflang_rt" "-lm"
+! UNIX-F128NONE-NOT: libflang_rt.quadmath
+! SOLARIS-F128NONE-NOT: libflang_rt.quadmath
+! UNIX-F128LIBQUADMATH-SAME: "-lflang_rt.quadmath" "--as-needed" "-lquadmath" "--no-as-needed"
+! SOLARIS-F128LIBQUADMATH-SAME: "-lflang_rt.quadmath" "-z" "ignore" "-lquadmath" "-z" "record"
+! UNIX-SAME: "-lflang_rt.runtime" "-lm"
 ! COMPILER-RT: "{{.*}}{{\\|/}}libclang_rt.builtins.a"
 
 ! DARWIN-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! DARWIN-SAME: "[[object_file]]"
-! DARWIN-F128NONE-NOT: FortranFloat128Math
-! DARWIN-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
-! DARWIN-SAME: -lflang_rt
+! DARWIN-F128NONE-NOT: libflang_rt.quadmath
+! DARWIN-F128LIBQUADMATH-SAME: "-lflang_rt.quadmath" "--as-needed" "-lquadmath" "--no-as-needed"
+! DARWIN-SAME: -lflang_rt.runtime
 
 ! HAIKU-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! HAIKU-SAME: "[[object_file]]"
-! HAIKU-F128NONE-NOT: FortranFloat128Math
-! HAIKU-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
-! HAIKU-SAME: "-lflang_rt"
+! HAIKU-F128NONE-NOT: libflang_rt.quadmath
+! HAIKU-F128LIBQUADMATH-SAME: "-lflang_rt.quadmath" "--as-needed" "-lquadmath" "--no-as-needed"
+! HAIKU-SAME: "-lflang_rt.runtime"
 
 ! MINGW-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! MINGW-SAME: "[[object_file]]"
-! MINGW-F128NONE-NOT: FortranFloat128Math
-! MINGW-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
-! MINGW-SAME: -lflang_rt
+! MINGW-F128NONE-NOT: libflang_rt.quadmath
+! MINGW-F128LIBQUADMATH-SAME: "-lflang_rt.quadmath" "--as-needed" "-lquadmath" "--no-as-needed"
+! MINGW-SAME: -lflang_rt.runtime
 
 ! NOTE: This also matches lld-link (when CLANG_DEFAULT_LINKER=lld) and
 !       any .exe suffix that is added when resolving to the full path of
diff --git a/flang/test/Driver/msvc-dependent-lib-flags.f90 b/flang/test/Driver/msvc-dependent-lib-flags.f90
index dabac56d602d1e1..641c73912c4d1e5 100644
--- a/flang/test/Driver/msvc-dependent-lib-flags.f90
+++ b/flang/test/Driver/msvc-dependent-lib-flags.f90
@@ -7,21 +7,21 @@
 ! MSVC-SAME: --dependent-lib=clang_rt.builtins.lib
 ! MSVC-SAME: -D_MT
 ! MSVC-SAME: --dependent-lib=libcmt
-! MSVC-SAME: --dependent-lib=flang_rt.static.lib
+! MSVC-SAME: --dependent-lib=flang_rt.runtime.static.lib
 
 ! MSVC-DEBUG: -fc1
 ! MSVC-DEBUG-SAME: --dependent-lib=clang_rt.builtins.lib
 ! MSVC-DEBUG-SAME: -D_MT
 ! MSVC-DEBUG-SAME: -D_DEBUG
 ! MSVC-DEBUG-SAME: --dependent-lib=libcmtd
-! MSVC-DEBUG-SAME: --dependent-lib=flang_rt.static_dbg.lib
+! MSVC-DEBUG-SAME: --dependent-lib=flang_rt.runtime.static_dbg.lib
 
 ! MSVC-DLL: -fc1
 ! MSVC-DLL-SAME: --dependent-lib=clang_rt.builtins.lib
 ! MSVC-DLL-SAME: -D_MT
 ! MSVC-DLL-SAME: -D_DLL
 ! MSVC-DLL-SAME: --dependent-lib=msvcrt
-! MSVC-DLL-SAME: --dependent-lib=flang_rt.dynamic.lib
+! MSVC-DLL-SAME: --dependent-lib=flang_rt.runtime.dynamic.lib
 
 ! MSVC-DLL-DEBUG: -fc1
 ! MSVC-DLL-DEBUG-SAME: --dependent-lib=clang_rt.builtins.lib
@@ -29,4 +29,4 @@
 ! MSVC-DLL-DEBUG-SAME: -D_DEBUG
 ! MSVC-DLL-DEBUG-SAME: -D_DLL
 ! MSVC-DLL-DEBUG-SAME: --dependent-lib=msvcrtd
-! MSVC-DLL-DEBUG-SAME: --dependent-lib=flang_rt.dynamic_dbg.lib
+! MSVC-DLL-DEBUG-SAME: --dependent-lib=flang_rt.runtime.dynamic_dbg.lib
diff --git a/flang/test/Driver/nostdlib.f90 b/flang/test/Driver/nostdlib.f90
index 17ed10fa0615d58..dc23be646237697 100644
--- a/flang/test/Driver/nostdlib.f90
+++ b/flang/test/Driver/nostdlib.f90
@@ -24,5 +24,5 @@
 ! in certain cases. But it is not clear that it is worth checking for each
 ! platform individually.
 
-! CHECK-NOT: "-lflang_rt"
+! CHECK-NOT: "-lflang_rt.runtime"
 ! CHECK-NOT: "-lgcc"
diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py
index 08ba586e1226d3c..c6266f3976f7c56 100644
--- a/flang/test/lit.cfg.py
+++ b/flang/test/lit.cfg.py
@@ -170,7 +170,7 @@
 # the C++ runtime libraries. For this we need a C compiler. If for some reason
 # we don't have one, we can just disable the test.
 if config.flang_include_runtime and config.cc:
-    libruntime = os.path.join(config.flang_lib_dir, "libflang_rt.a")
+    libruntime = os.path.join(config.flang_lib_dir, "libflang_rt.runtime.a")
     include = os.path.join(config.flang_src_dir, "include")
 
     if (
diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt
index 9e19b2cdfbb90c4..2278d61febcb11d 100644
--- a/flang/unittests/Evaluate/CMakeLists.txt
+++ b/flang/unittests/Evaluate/CMakeLists.txt
@@ -60,14 +60,14 @@ if (FLANG_INCLUDE_RUNTIME)
     NonGTestTesting
     FortranSemantics
     FortranEvaluate
-    flang_rt
+    flang_rt.runtime
   )
 
   add_flang_nongtest_unittest(ISO-Fortran-binding
     NonGTestTesting
     FortranEvaluate
     FortranSemantics
-    flang_rt
+    flang_rt.runtime
   )
 endif ()
 
diff --git a/flang/unittests/Runtime/CMakeLists.txt b/flang/unittests/Runtime/CMakeLists.txt
index a60b43d422878d2..f3743be49b01549 100644
--- a/flang/unittests/Runtime/CMakeLists.txt
+++ b/flang/unittests/Runtime/CMakeLists.txt
@@ -33,7 +33,7 @@ add_flang_unittest(FlangRuntimeTests
 
 target_link_libraries(FlangRuntimeTests
   PRIVATE
-  flang_rt
+  flang_rt.runtime
 )
 
 target_compile_definitions(FlangRuntimeTests PRIVATE NOT_EXE="$<TARGET_FILE:not>")
diff --git a/flang/unittests/Runtime/CUDA/CMakeLists.txt b/flang/unittests/Runtime/CUDA/CMakeLists.txt
index 38888e32e6ed8ac..860b2664d623b99 100644
--- a/flang/unittests/Runtime/CUDA/CMakeLists.txt
+++ b/flang/unittests/Runtime/CUDA/CMakeLists.txt
@@ -15,8 +15,8 @@ endif()
 target_link_libraries(FlangCufRuntimeTests
   PRIVATE
   ${CUDA_RT_TARGET}
-  CufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR}
-  flang_rt
+  flang_rt.cuda_${CUDAToolkit_VERSION_MAJOR}
+  flang_rt.runtime
 )
 
 target_include_directories(FlangCufRuntimeTests PRIVATE ${CUDAToolkit_INCLUDE_DIRS})
diff --git a/lld/COFF/MinGW.cpp b/lld/COFF/MinGW.cpp
index e188dfb503c1aa5..baaf06fa021a2c2 100644
--- a/lld/COFF/MinGW.cpp
+++ b/lld/COFF/MinGW.cpp
@@ -50,7 +50,7 @@ AutoExporter::AutoExporter(
       "libclang_rt.profile-x86_64",
       "libc++",
       "libc++abi",
-      "libflang_rt",
+      "libflang_rt.runtime",
       "libunwind",
       "libmsvcrt",
       "libucrtbase",

>From 8fae56556fd8dd69b39af96098b16bd8fd9626e1 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 3 Feb 2025 23:33:40 +0100
Subject: [PATCH 13/18] forgotten change

---
 flang/test/Runtime/no-cpp-dep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang/test/Runtime/no-cpp-dep.c
index c03029f0f3c26db..4fcf8f9d478d8c1 100644
--- a/flang/test/Runtime/no-cpp-dep.c
+++ b/flang/test/Runtime/no-cpp-dep.c
@@ -1,6 +1,6 @@
 /*
 This test makes sure that flang's runtime does not depend on the C++ runtime
-library. It tries to link this simple file against libflang_rt.a with
+library. It tries to link this simple file against libflang_rt.runtime.a with
 a C compiler.
 
 REQUIRES: c-compiler, flang-rt

>From b286a88b23b0ac977222c8b7d7289f8c9f292eb5 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Thu, 6 Feb 2025 10:58:03 +0100
Subject: [PATCH 14/18] clang-format includes

---
 flang/include/flang/Common/ISO_Fortran_binding_wrapper.h | 2 +-
 flang/include/flang/Frontend/CompilerInvocation.h        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
index 5d9c66f47b48e62..890522953efe09b 100644
--- a/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
+++ b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
@@ -1,4 +1,4 @@
-/*===-- include/flang/Common/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.
diff --git a/flang/include/flang/Frontend/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h
index b3b7297f6f7f1f4..9e6724be3303359 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -20,8 +20,8 @@
 #include "flang/Lower/LoweringOptions.h"
 #include "flang/Parser/parsing.h"
 #include "flang/Semantics/semantics.h"
-#include "mlir/Support/Timing.h"
 #include "flang/Support/LangOptions.h"
+#include "mlir/Support/Timing.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "llvm/Option/ArgList.h"

>From 778f51608331ac1267353b1c1225357f5e7a9106 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Thu, 6 Feb 2025 19:02:37 +0100
Subject: [PATCH 15/18] Adapt BSD test

---
 flang/test/Driver/linker-flags.f90 | 1 -
 1 file changed, 1 deletion(-)

diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90
index 4b4b6d52f132725..16bd4c3ba837113 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -41,7 +41,6 @@
 ! BSD-F128NONE-NOT: FortranFloat128Math
 ! BSD-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
 ! BSD-SAME: -lFortranRuntime
-! BSD-SAME: -lFortranDecimal
 ! BSD-SAME: -lexecinfo
 
 ! DARWIN-LABEL:  "{{.*}}ld{{(\.exe)?}}"

>From 8ce70e56d8f3bf838503d619b1a4dafa8df29a71 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Thu, 6 Feb 2025 19:06:58 +0100
Subject: [PATCH 16/18] Adapt BSD test for rename

---
 flang/test/Driver/linker-flags.f90 | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90
index 2c6c3beef478315..4e62a8c32d36083 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -29,8 +29,8 @@
 !       executable and may find the GNU linker from MinGW or Cygwin.
 ! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! UNIX-SAME: "[[object_file]]"
-! UNIX-F128NONE-NOT: libflang_rt.quadmath
-! SOLARIS-F128NONE-NOT: libflang_rt.quadmath
+! UNIX-F128NONE-NOT: lang_rt.quadmath
+! SOLARIS-F128NONE-NOT: flang_rt.quadmath
 ! UNIX-F128LIBQUADMATH-SAME: "-lflang_rt.quadmath" "--as-needed" "-lquadmath" "--no-as-needed"
 ! SOLARIS-F128LIBQUADMATH-SAME: "-lflang_rt.quadmath" "-z" "ignore" "-lquadmath" "-z" "record"
 ! UNIX-SAME: "-lflang_rt.runtime" "-lm"
@@ -38,9 +38,9 @@
 
 ! BSD-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! BSD-SAME: "[[object_file]]"
-! BSD-F128NONE-NOT: FortranFloat128Math
-! BSD-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
-! BSD-SAME: -lFortranRuntime
+! BSD-F128NONE-NOT: flang_rt.quadmath
+! BSD-F128LIBQUADMATH-SAME: "-lflang_rt.quadmath" "--as-needed" "-lquadmath" "--no-as-needed"
+! BSD-SAME: -lflang_rt.runtime
 ! BSD-SAME: -lexecinfo
 
 ! DARWIN-LABEL:  "{{.*}}ld{{(\.exe)?}}"

>From f258e0e71651b63847aed875a46db116a5265b78 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Thu, 6 Feb 2025 19:43:34 +0100
Subject: [PATCH 17/18] Use C++ header guards III

---
 flang/include/flang/Testing/fp-testing.h | 2 +-
 flang/include/flang/Testing/testing.h    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/include/flang/Testing/fp-testing.h b/flang/include/flang/Testing/fp-testing.h
index e223d2ef7d1b8b9..c65766b8b47e882 100644
--- a/flang/include/flang/Testing/fp-testing.h
+++ b/flang/include/flang/Testing/fp-testing.h
@@ -32,4 +32,4 @@ class ScopedHostFloatingPointEnvironment {
 #endif
 };
 
-#endif /* FORTRAN_TESTING_FP_TESTING_H_ */
+#endif // FORTRAN_TESTING_FP_TESTING_H_
diff --git a/flang/include/flang/Testing/testing.h b/flang/include/flang/Testing/testing.h
index 404650c9a89f2c5..03b589924518d8b 100644
--- a/flang/include/flang/Testing/testing.h
+++ b/flang/include/flang/Testing/testing.h
@@ -41,4 +41,4 @@ FailureDetailPrinter Match(const char *file, int line, const std::string &want,
 FailureDetailPrinter Compare(const char *file, int line, const char *xs,
     const char *rel, const char *ys, std::uint64_t x, std::uint64_t y);
 } // namespace testing
-#endif /* FORTRAN_TESTING_TESTING_H_ */
+#endif // FORTRAN_TESTING_TESTING_H_

>From 6b4621029a667e0b3cbfbefd28e09282f7e023fd Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Sat, 8 Feb 2025 17:24:45 +0100
Subject: [PATCH 18/18] Specifically refer to flang_rt.runtime in comments

---
 flang/CMakeLists.txt           | 2 +-
 flang/runtime/CMakeLists.txt   | 2 +-
 flang/tools/f18/CMakeLists.txt | 8 ++++----
 flang/unittests/CMakeLists.txt | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 7c598e02bd09b1a..c6271f1856eb93c 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -301,7 +301,7 @@ set(FLANG_DEFAULT_LINKER "" CACHE STRING
   "Default linker to use (linker name or absolute path, empty for platform default)")
 
 set(FLANG_DEFAULT_RTLIB "" CACHE STRING
-   "Default Fortran runtime library to use (\"libflang_rt\"), leave empty for platform default.")
+   "Default Fortran runtime library to use (\"libflang_rt.runtime\"), leave empty for platform default.")
 
 if (NOT(FLANG_DEFAULT_RTLIB STREQUAL ""))
   message(WARNING "Resetting Flang's default runtime library to use platform default.")
diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index 65c6b0d37401366..7cc720e2df9af8c 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -247,7 +247,7 @@ enable_omp_offload_compilation("${supported_files}")
 if (NOT TARGET flang_rt.quadmath)
   # If flang_rt.quadmath is not defined, then we are not building
   # standalone flang_rt.quadmath library. Instead, include
-  # the relevant sources into flang_rt itself.
+  # the relevant sources into flang_rt.runtime itself.
   # The information is provided via FortranFloat128MathILib
   # interface library.
   get_target_property(f128_sources
diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index a849e95df31c17b..5b5f23b5dc73c2e 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -5,7 +5,7 @@ set(LLVM_LINK_COMPONENTS
   )
 
 # Define the list of Fortran module files that need to be compiled
-# to produce an object file for inclusion into the flang_rt
+# to produce an object file for inclusion into the flang_rt.runtime
 # library.
 set(MODULES_WITH_IMPLEMENTATION
   "iso_fortran_env_impl"
@@ -105,7 +105,7 @@ if (NOT CMAKE_CROSSCOMPILING)
     endif()
 
     # Some modules have an implementation part that needs to be added to the
-    # flang_rt library.
+    # flang_rt.runtime library.
     set(compile_with "-fsyntax-only")
     set(object_output "")
     set(include_in_link FALSE)
@@ -127,14 +127,14 @@ if (NOT CMAKE_CROSSCOMPILING)
     install(FILES ${base}.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
 
     # If a module has been compiled into an object file, add the file to
-    # the link line for the flang_rt library.
+    # the link line for the flang_rt.runtime library.
     if(include_in_link)
       list(APPEND module_objects ${object_output})
     endif()
   endforeach()
 
   # Set a CACHE variable that is visible to the CMakeLists.txt in runtime/, so that
-  # the compiled Fortran modules can be added to the link line of the flang_rt
+  # the compiled Fortran modules can be added to the link line of the flang_rt.runtime
   # library.
   set(FORTRAN_MODULE_OBJECTS ${module_objects} CACHE INTERNAL "" FORCE)
 
diff --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt
index 7b0f85638f14e48..c54ceb3332abf80 100644
--- a/flang/unittests/CMakeLists.txt
+++ b/flang/unittests/CMakeLists.txt
@@ -2,7 +2,7 @@ include(AddFlangOffloadRuntime)
 
 if (FLANG_EXPERIMENTAL_CUDA_RUNTIME)
   # If Fortran runtime is built as CUDA library, the linking
-  # of targets that link flang_rt must be done
+  # of targets that link flang_rt.runtime must be done
   # with CUDA_RESOLVE_DEVICE_SYMBOLS.
   # CUDA language must be enabled for CUDA_RESOLVE_DEVICE_SYMBOLS
   # to take effect.



More information about the flang-commits mailing list