[clang] [flang] [lld] [llvm] [Flang][NFC] Move runtime library files to flang-rt. (PR #110298)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 14 00:26:28 PST 2025


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

>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/24] [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 37289bdbabd03..7a8a8a9787bd0 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 d1c9c756a44a6..1214bac75a4bf 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 63277438128eb..4d8ca28cf329a 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 357fc3e595243..ccd584b5ee6aa 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 915e95169c7f8..91d38748f5a57 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 61a814446bbfd..63e8ed4119cdf 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 04f4406fc8a2c..ec71550d2a50c 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 aa82f56107fdd..ae9351139b193 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 15afb772ae767..dbe1ba7fe7ec1 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 3e42ec691158b..18dca71379e0d 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 e07f916b875e0..f4595dfe4e433 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 669efb41b0344..fbe905168d253 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 dd38d64bff63f..58f188a409249 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 1f9296ac4fea7..ab7e4723152d7 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 9b597d29813da..bb4150613c81d 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 7d3f0bdf2e510..b3b7297f6f7f1 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 a4cb021e309d4..0bd2e621813ca 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 945f8fef89f0b..f5b8d0d2ea610 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 c24f43737df50..3d2b805da6f47 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 6404a16f7785a..a8c2bcfda31c1 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 72bc9dd890a94..c15edf62df388 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 7a3f92649a4e4..179a682584046 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 8105ccd7ef6b1..171510393b816 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 42d6546b77553..05da17faf2dd7 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 1cc74521e22d8..08a872b228691 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 c03f9afd40801..fb64db407708a 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 ea658fb16a36c..805667bfe502b 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 5ae32f70a11a7..8374b18b8a17d 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 eaa1de76154d9..be07e8d2a9390 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 9cccf8db87270..b9a8a670d0793 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 f32e39b543e3f..85615a4d69157 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 308c82118d502..ec21d672287e6 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 d507f4116efb7..ec73af6ec72e9 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 38f4f7b82e1ea..4541b31e566f9 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 11725991e9c9a..13e367e725a54 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 bc38f571ca3df..bfbc985b8b91a 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 76cbb3470dc08..36d70b81b7923 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 00d85aa05fb3a..217328b792844 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 0c774decb16d3..116b6bd6f191f 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 a9224b727fd05..7f29fb272c942 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 a6efdf9546c7f..a67fd66045a3d 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 61745a833c715..129f9fb8fee05 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 3b2537579d586..abcdbc4a12002 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 dd36fba157ca9..628ac8c927a51 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 269297dff47db..bb6dcb3873f21 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 ba9c2598bb0dd..4a6d4357e8710 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 dd3a9f2690ee7..ae854ed2145e4 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 bb1674a9f8877..8ea33902bd213 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 e90d3ae8baf1e..94c50aab69681 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 b3b033a5a3ae3..b7d115ec2bca4 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 c981d86fbd94c..c03a0bad24a6e 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 bc6abccac1bb8..dfe323acbd490 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 07103f98ff041..012223ef9a098 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 3522191502059..5d96f1e89bf52 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 44f88009f8f2c..690329411dc50 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 e1922f7654bb1..4e6bdbb67f5f3 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 83f25cfbe2614..3c6094c9a9c87 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 7f8ebdbee1987..072aed20da470 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 480c8b4c1013f..85c901e7fdb82 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 75ba2a8d85f39..5d66831d6c1c2 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 3257d4a4f6459..4ceb19e7f4d71 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 6c66b98e98a05..92f06e6fe2d27 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 7348eb0473f07..aeb1698516bae 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 c4cab0ccf1130..99c0784f006a8 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 de91d4fb6ee8b..636613d93d80c 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 0c579de44bd7f..c0b0e048ae04a 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 27d2ba89c8009..8928fab6bfb6f 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 51d09fb42ce36..36fa6f7072b40 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 84582174e4b30..e890753499d1a 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 0286f2aa14519..d9401e753fb79 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 2182e845b6a79..05c3535b09b3d 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 4b5df0a49f403..0000000000000
--- 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 b38f450d746ea..e0bdb6b2d24d8 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 c5b50e806d249..f77df92a7597a 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 3912d1c4b4771..49d11f41ea4ca 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 31d043f490fd8..723bb8d97f68e 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 f3a53c1f983df..c4c3998257830 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 c1b270f518c0e..fa2c931b21f0a 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 f234241cfe14a..2881d9942af7e 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 58b824d9b8e64..ab7c357fa78a8 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 94dc35ecd5900..f87cce8b32005 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 d063ed36d00b4..81eef2d468d8c 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 298790bae6655..7888bab5ffb42 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 15b1e1e0a2488..e89c7f3daaf42 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 b0545a7ac2f99..b7674bd093f68 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 700ca56141a32..708b6e7be5d8a 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 f611010765cb5..0bc708a163638 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 e20b90b2ff1bc..c8314fac9054c 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 d9ae502edbafa..04df137ce566f 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 1165417ef89a2..aa40b12196520 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 6a343645ab878..77256a51fa7f7 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 0eace903720f0..89f498433806e 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 0b57a10a6c493..67d918cc0f41c 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 9fe2d3947c26d..f3412e32326de 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 eb25beba309bf..1c19a5765aff1 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 a8e9d198ccb97..79e2b360018c1 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 eb59045a5fde7..d0bd67a236419 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 9c550f983434a..50994fbb21700 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 5ce39f99bbb12..1aeb59b1d669e 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 60aa401e1cc8c..5a3d38722ecd3 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 8b8c00fa7ecfc..88b23b92336b5 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 4f6974ee52695..3d84eaa4c1595 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 b534ec160ce21..343cc6ff28950 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 fa6a7b23624e8..df2887ff1422e 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 bd3e49a47bc39..acb685850d173 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 d311167c58b4d..54a2456e77366 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 d364671d7a322..76fe3d7ce6ba4 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 1a8c14e7048f6..d739102b8464f 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 a414f226058e3..89491fd2fa2a7 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 08041f93b14b6..e2440ad6fbc42 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 7bf404bba2c3e..6cd18abbdff0c 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 7855ae7eed138..00108dde49dbd 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 95d7b3cf91b17..ba0c70f7d224c 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 5ce143c9aec91..c81d3b16ab313 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 6cf61a6b923db..ac1f38801cee7 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 d8a5639227648..d079f5b6aa530 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 479d32568fa66..6da316cccc4a7 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 84e6b6455cc61..ddba4c04b1ee3 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 22729f659ed5b..52220a566bbdc 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 2e602d307013c..b227bbaaef4ba 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 94d16a719277a..b86a95492b21c 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 43535b07f029e..aabd52098e63b 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 d8cc4601de26f..e99a02cc79db1 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 3ec6f385ceb86..1dd603412f42d 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 7f4548c7327e3..49684ffd5f804 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 04e4b142efedf..584319b8abdf6 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 a838d49c06104..065090ed03b6a 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 f3c2a5bf094d0..2175d5edea0c0 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 577558e7e33b2..171c0021fba08 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 58dc1f218b56f..10a01039ea0ae 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 052d71be43472..64e4c9d7e194d 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 12183f590316d..809266960a02d 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 3565275915a31..be84072ae6a5b 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 eec83419f9eb2..746b7c9740728 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 415c715156e7b..273274fc07215 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 47e89fe6dd1ee..b3cab763aca30 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 ee8309a950eec..41cb2be826907 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 d67255f353dfd..8ee4908f28f62 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 fbafd827ff0d0..c6d7759097be1 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 536a5c2e5479d..906a4c1bcd9b0 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 85b3daf65a8ba..368c1124ef70a 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 fe22026f31f55..64e239f498230 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 dd0eeef80bb89..aca9aee8c5718 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 5e065f47636a8..686114bf86eaf 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 71faeb027d908..572cb6d10b489 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 667b10e04dbd2..93340266b1b44 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 85aeb85e0c530..f950f03920d3f 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 7efc460be8679..4499e44711bd3 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 df1f1d24a55e5..743a44017e8a5 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 3025dbd4dca4a..a50c88dc84064 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 220f908d2f108..c277cdbf167b6 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 52eb385f4763f..0ea02ad7f7115 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 3c98363f90046..38688b404876f 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 9177997f41f53..3cbc2cf148511 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 0f7eb27789316..bdfa8f5cc3213 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 7cb25787e7797..5ec122e4c5777 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 7c8b7aa5a4d78..61c9d1131ee56 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 0a9344969ca6b..4f701e09b2945 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/24] [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 9091963a99b32..e223d2ef7d1b8 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 422e2853c05bc..404650c9a89f2 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 05c3535b09b3d..8b201d9a758a8 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 0000000000000..8051bc09736d1
--- /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 1a1d7425d5824..5e1728e8df5e4 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 b2f73bf1b265a..37f9d88f4886b 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 0ea02ad7f7115..8111ecd72cfc7 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 38688b404876f..2884686b3f26e 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 24e721c14f94a..0c9529a92e572 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 f03a6bc2a4e23..d575f36def287 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 4e8ff9754e4cc..832e55d44316d 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 3eabb2434cce6..5ab22cc6443a7 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 86c471d2c6295..cca2f8c30247e 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 968946b69f27e..25e2664e76df0 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 d79aff8448712..ba7d0d8d0c0e3 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 1bf7fa1016a9e..a28da5c3273ce 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 5d138cd3d88d9..16cba15dcef60 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 f05c1c96a7e8b..0b749abe1c080 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/24] [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 f8967890f722c..b5273dd8cf1e3 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 86ed25badfa2b..f1bf32b323827 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 23cbab30ee903..be5633529f50c 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 880b190f1c581..477d44e0565eb 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 fbfaae9a88064..6343c4276f0e3 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 ac9500d7c45ce..fdeb95e4dd97c 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 765917f07d8e7..befe61fdadcd1 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 cd707e632a45f..ab7c675fe7b77 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 606a5d189f719..b1a5fa004014c 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 f43234fb125b7..c452b6d231c89 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 76f5a0a7500b9..797ab37f06981 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/24] 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 b619553ef8302..7d6dcb5c184a5 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 cab214c2ef4c8..e398e0786147a 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 78eac32133b18..10c7adaccc958 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 fd174005ddf62..9ca91ee24011c 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 b1a5fa004014c..7303ce63fdec4 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 c452b6d231c89..f4580afc8c47b 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 d1a0ac763cf8a..697ba3fa79763 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 cc2bc5b8eb5ce..85ba2c74cdeb5 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 945067fed4f82..ecb7d68d8f729 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 8111ecd72cfc7..1c3fac29cd298 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/24] [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 b5273dd8cf1e3..c7b0a660ee021 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 f1bf32b323827..68a17edf8ca34 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 7d6dcb5c184a5..8a8b8bfa73b00 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 be5633529f50c..f3a732b039890 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 1c85a6754b155..ffde50b6f481e 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 52d00ae4daef8..6c147a56894c8 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 f0c956281915f..a163b4f4ed67d 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 042d4b6238ba4..213fc462ac2b1 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 77256a51fa7f7..29ab0ab9a75f3 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 6343c4276f0e3..3e32daba52a81 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 3a88824826de3..744df95267e6f 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 703f85fcaf8da..d65193be05ab5 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 e6f6e81c7b50c..942604a92aaad 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 e398e0786147a..e8e8099d4eaf7 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 5a073b0c51712..d9160e1971250 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 fdeb95e4dd97c..5dc89fe45c8cc 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 befe61fdadcd1..dabac56d602d1 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 ab7c675fe7b77..17ed10fa0615d 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 7303ce63fdec4..c03029f0f3c26 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 f4580afc8c47b..08ba586e1226d 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 85ba2c74cdeb5..a849e95df31c1 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 ecb7d68d8f729..7b0f85638f14e 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 1c3fac29cd298..9e19b2cdfbb90 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 179e439917ff2..a60b43d422878 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 a7fe604d687bd..38888e32e6ed8 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 797ab37f06981..e188dfb503c1a 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 7e369b5626b6de43de394212efe5024a4fdebf48 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 24 Jan 2025 16:47:29 +0100
Subject: [PATCH 06/24] [Flang][NFC] Move runtime library files to flang-rt

---
 flang-rt/.clang-format                        |  25 +++++
 flang-rt/cmake/config.h.cmake.in              |  19 ++++
 .../include/flang-rt}/CUDA/allocator.h        |  10 +-
 .../include/flang-rt}/allocator-registry.h    |   8 +-
 .../include/flang-rt}/array-constructor.h     |  10 +-
 .../include/flang-rt}/assign-impl.h           |   8 +-
 .../include/flang-rt}/buffer.h                |  10 +-
 .../include/flang-rt}/connection.h            |   8 +-
 .../include/flang-rt}/derived.h               |   8 +-
 .../include/flang-rt}/descriptor.h            |  12 +--
 .../include/flang-rt}/emit-encoded.h          |   8 +-
 .../include/flang-rt}/environment.h           |   8 +-
 .../include/flang-rt}/file.h                  |  10 +-
 .../include/flang-rt}/format-implementation.h |   8 +-
 .../include/flang-rt}/format.h                |   8 +-
 .../include/flang-rt}/internal-unit.h         |  10 +-
 .../include/flang-rt}/io-error.h              |  10 +-
 .../include/flang-rt}/io-stmt.h               |  10 +-
 .../include/flang-rt}/lock.h                  |   8 +-
 .../include/flang-rt}/memory.h                |   8 +-
 .../include/flang-rt}/namelist.h              |   8 +-
 .../include/flang-rt}/non-tbp-dio.h           |   8 +-
 .../include/flang-rt}/numeric-templates.h     |   8 +-
 .../include/flang-rt}/random-templates.h      |  10 +-
 .../include/flang-rt}/reduction-templates.h   |  10 +-
 .../include/flang-rt}/stat.h                  |   8 +-
 .../include/flang-rt}/terminator.h            |   8 +-
 .../include/flang-rt}/tools.h                 |  12 +--
 .../include/flang-rt}/type-code.h             |   8 +-
 .../include/flang-rt}/type-info.h             |  10 +-
 .../include/flang-rt}/utf.h                   |   8 +-
 .../lib/FortranFloat128Math}/acos.cpp         |   2 +-
 .../lib/FortranFloat128Math}/acosh.cpp        |   2 +-
 .../lib/FortranFloat128Math}/asin.cpp         |   2 +-
 .../lib/FortranFloat128Math}/asinh.cpp        |   2 +-
 .../lib/FortranFloat128Math}/atan.cpp         |   2 +-
 .../lib/FortranFloat128Math}/atan2.cpp        |   2 +-
 .../lib/FortranFloat128Math}/atanh.cpp        |   2 +-
 .../lib/FortranFloat128Math}/ceil.cpp         |   2 +-
 .../lib/FortranFloat128Math}/complex-math.c   |   5 +-
 .../lib/FortranFloat128Math}/complex-math.h   |   8 +-
 .../lib/FortranFloat128Math}/cos.cpp          |   2 +-
 .../lib/FortranFloat128Math}/cosh.cpp         |   2 +-
 .../lib/FortranFloat128Math}/erf.cpp          |   2 +-
 .../lib/FortranFloat128Math}/erfc.cpp         |   2 +-
 .../lib/FortranFloat128Math}/exp.cpp          |   2 +-
 .../lib/FortranFloat128Math}/exponent.cpp     |   2 +-
 .../lib/FortranFloat128Math}/floor.cpp        |   2 +-
 .../lib/FortranFloat128Math}/fma.cpp          |   2 +-
 .../lib/FortranFloat128Math}/fraction.cpp     |   2 +-
 .../lib/FortranFloat128Math}/hypot.cpp        |   2 +-
 .../lib/FortranFloat128Math}/j0.cpp           |   2 +-
 .../lib/FortranFloat128Math}/j1.cpp           |   2 +-
 .../lib/FortranFloat128Math}/jn.cpp           |   2 +-
 .../lib/FortranFloat128Math}/lgamma.cpp       |   2 +-
 .../lib/FortranFloat128Math}/llround.cpp      |   2 +-
 .../lib/FortranFloat128Math}/log.cpp          |   2 +-
 .../lib/FortranFloat128Math}/log10.cpp        |   2 +-
 .../lib/FortranFloat128Math}/lround.cpp       |   2 +-
 .../lib/FortranFloat128Math}/math-entries.h   |  13 +--
 .../lib/FortranFloat128Math}/mod-real.cpp     |   2 +-
 .../lib/FortranFloat128Math}/modulo-real.cpp  |   2 +-
 .../lib/FortranFloat128Math}/nearbyint.cpp    |   2 +-
 .../lib/FortranFloat128Math}/nearest.cpp      |   2 +-
 .../lib/FortranFloat128Math}/norm2.cpp        |   4 +-
 .../numeric-template-specs.h                  |  10 +-
 .../lib/FortranFloat128Math}/pow.cpp          |   2 +-
 .../lib/FortranFloat128Math}/random.cpp       |   4 +-
 .../lib/FortranFloat128Math}/remainder.cpp    |   2 +-
 .../lib/FortranFloat128Math}/round.cpp        |   2 +-
 .../lib/FortranFloat128Math}/rrspacing.cpp    |   2 +-
 .../lib/FortranFloat128Math}/scale.cpp        |   2 +-
 .../lib/FortranFloat128Math}/set-exponent.cpp |   2 +-
 .../lib/FortranFloat128Math}/sin.cpp          |   2 +-
 .../lib/FortranFloat128Math}/sinh.cpp         |   2 +-
 .../lib/FortranFloat128Math}/spacing.cpp      |   2 +-
 .../lib/FortranFloat128Math}/sqrt.cpp         |   2 +-
 .../lib/FortranFloat128Math}/tan.cpp          |   2 +-
 .../lib/FortranFloat128Math}/tanh.cpp         |   2 +-
 .../lib/FortranFloat128Math}/tgamma.cpp       |   2 +-
 .../lib/FortranFloat128Math}/trunc.cpp        |   2 +-
 .../lib/FortranFloat128Math}/y0.cpp           |   2 +-
 .../lib/FortranFloat128Math}/y1.cpp           |   2 +-
 .../lib/FortranFloat128Math}/yn.cpp           |   2 +-
 .../lib/flang_rt}/CUDA/allocatable.cpp        |   9 +-
 .../lib/flang_rt}/CUDA/allocator.cpp          |  14 +--
 .../lib/flang_rt}/CUDA/descriptor.cpp         |   8 +-
 .../lib/flang_rt}/CUDA/kernel.cpp             |   4 +-
 .../lib/flang_rt}/CUDA/memmove-function.cpp   |   4 +-
 .../lib/flang_rt}/CUDA/memory.cpp             |   6 +-
 .../lib/flang_rt}/CUDA/registration.cpp       |   4 +-
 .../lib/flang_rt}/ISO_Fortran_binding.cpp     |   8 +-
 .../lib/flang_rt}/ISO_Fortran_util.h          |  14 +--
 .../lib/flang_rt}/allocatable.cpp             |  14 +--
 .../lib/flang_rt}/allocator-registry.cpp      |   6 +-
 .../lib/flang_rt}/array-constructor.cpp       |  14 +--
 .../lib/flang_rt}/assign.cpp                  |  16 +--
 .../lib/flang_rt}/buffer.cpp                  |   4 +-
 .../lib/flang_rt}/character.cpp               |   8 +-
 .../lib/flang_rt}/command.cpp                 |  12 +--
 .../lib/flang_rt}/complex-powi.cpp            |  16 +--
 .../lib/flang_rt}/complex-reduction.c         |   5 +-
 .../lib/flang_rt}/complex-reduction.h         |  11 +-
 .../lib/flang_rt}/connection.cpp              |   8 +-
 .../lib/flang_rt}/copy.cpp                    |   8 +-
 .../runtime => flang-rt/lib/flang_rt}/copy.h  |  10 +-
 .../lib/flang_rt}/derived-api.cpp             |  13 ++-
 .../lib/flang_rt}/derived.cpp                 |  14 +--
 .../lib/flang_rt}/descriptor-io.cpp           |   2 +-
 .../lib/flang_rt}/descriptor-io.h             |  18 ++--
 .../lib/flang_rt}/descriptor.cpp              |  22 ++--
 .../lib/flang_rt}/dot-product.cpp             |   8 +-
 .../lib/flang_rt}/edit-input.cpp              |   6 +-
 .../lib/flang_rt}/edit-input.h                |  12 +--
 .../lib/flang_rt}/edit-output.cpp             |   6 +-
 .../lib/flang_rt}/edit-output.h               |  12 +--
 .../lib/flang_rt}/environment-default-list.h  |  11 +-
 .../lib/flang_rt}/environment.cpp             |   6 +-
 .../lib/flang_rt}/exceptions.cpp              |   4 +-
 .../lib/flang_rt}/execute.cpp                 |  12 +--
 .../lib/flang_rt}/extensions.cpp              |   8 +-
 .../lib/flang_rt}/external-unit.cpp           |   8 +-
 .../lib/flang_rt}/extrema.cpp                 |   4 +-
 .../lib/flang_rt}/file.cpp                    |   8 +-
 .../lib/flang_rt}/findloc.cpp                 |   4 +-
 .../lib/flang_rt}/format.cpp                  |   4 +-
 .../lib/flang_rt}/inquiry.cpp                 |   8 +-
 .../lib/flang_rt}/internal-unit.cpp           |   8 +-
 .../lib/flang_rt}/io-api-common.h             |  12 +--
 .../lib/flang_rt}/io-api-minimal.cpp          |  10 +-
 .../lib/flang_rt}/io-api.cpp                  |  16 +--
 .../lib/flang_rt}/io-error.cpp                |   6 +-
 .../lib/flang_rt}/io-stmt.cpp                 |  16 +--
 .../lib/flang_rt}/iostat.cpp                  |   2 +-
 .../lib/flang_rt}/main.cpp                    |   6 +-
 .../lib/flang_rt}/matmul-transpose.cpp        |   8 +-
 .../lib/flang_rt}/matmul.cpp                  |   8 +-
 .../lib/flang_rt}/memory.cpp                  |   8 +-
 .../lib/flang_rt}/misc-intrinsic.cpp          |   8 +-
 .../lib/flang_rt}/namelist.cpp                |   8 +-
 .../lib/flang_rt}/non-tbp-dio.cpp             |   6 +-
 .../lib/flang_rt}/numeric.cpp                 |   8 +-
 .../lib/flang_rt}/pointer.cpp                 |  16 +--
 .../lib/flang_rt}/product.cpp                 |   4 +-
 .../lib/flang_rt}/pseudo-unit.cpp             |   6 +-
 .../lib/flang_rt}/ragged.cpp                  |   4 +-
 .../lib/flang_rt}/random.cpp                  |  10 +-
 .../lib/flang_rt}/reduce.cpp                  |  10 +-
 .../lib/flang_rt}/reduction.cpp               |   6 +-
 .../runtime => flang-rt/lib/flang_rt}/stack.h |  12 +--
 .../lib/flang_rt}/stat.cpp                    |  10 +-
 .../lib/flang_rt}/stop.cpp                    |  10 +-
 .../runtime => flang-rt/lib/flang_rt}/sum.cpp |   4 +-
 .../lib/flang_rt}/support.cpp                 |   6 +-
 .../lib/flang_rt}/temporary-stack.cpp         |   8 +-
 .../lib/flang_rt}/terminator.cpp              |   4 +-
 .../lib/flang_rt}/time-intrinsic.cpp          |   8 +-
 .../lib/flang_rt}/tools.cpp                   |   6 +-
 .../lib/flang_rt}/transformational.cpp        |   8 +-
 .../lib/flang_rt}/type-code.cpp               |   4 +-
 .../lib/flang_rt}/type-info.cpp               |  10 +-
 .../lib/flang_rt}/unit-map.cpp                |   2 +-
 .../lib/flang_rt}/unit-map.h                  |  12 +--
 .../lib/flang_rt}/unit.cpp                    |   8 +-
 .../runtime => flang-rt/lib/flang_rt}/unit.h  |  30 +++---
 .../runtime => flang-rt/lib/flang_rt}/utf.cpp |   4 +-
 .../test/Driver/ctofortran.f90                |   0
 {flang => flang-rt}/test/Driver/exec.f90      |   0
 {flang => flang-rt}/test/Runtime/no-cpp-dep.c |   0
 .../Evaluate/ISO-Fortran-binding.cpp          |  10 +-
 .../unittests/Evaluate/reshape.cpp            |  10 +-
 .../unittests/Runtime/AccessTest.cpp          |   2 +-
 .../unittests/Runtime/Allocatable.cpp         |   4 +-
 .../unittests/Runtime/ArrayConstructor.cpp    |  10 +-
 .../unittests/Runtime/BufferTest.cpp          |   4 +-
 .../unittests/Runtime/CUDA/Allocatable.cpp    |  12 +--
 .../unittests/Runtime/CUDA/AllocatorCUF.cpp   |  12 +--
 .../unittests/Runtime/CUDA/Memory.cpp         |  13 ++-
 .../unittests/Runtime/CharacterTest.cpp       |   4 +-
 .../unittests/Runtime/CommandTest.cpp         |   4 +-
 .../unittests/Runtime/Complex.cpp             |   3 +-
 .../unittests/Runtime/CrashHandlerFixture.cpp |   5 +-
 .../unittests/Runtime/CrashHandlerFixture.h   |   9 +-
 .../unittests/Runtime/Derived.cpp             |   6 +-
 .../unittests/Runtime/ExternalIOTest.cpp      |   4 +-
 .../unittests/Runtime/Format.cpp              |   8 +-
 .../unittests/Runtime/Inquiry.cpp             |   6 +-
 .../unittests/Runtime/ListInputTest.cpp       |   6 +-
 .../unittests/Runtime/LogicalFormatTest.cpp   |   4 +-
 .../unittests/Runtime/Matmul.cpp              |   8 +-
 .../unittests/Runtime/MatmulTranspose.cpp     |   8 +-
 .../unittests/Runtime/MiscIntrinsic.cpp       |   8 +-
 .../unittests/Runtime/Namelist.cpp            |   6 +-
 .../unittests/Runtime/Numeric.cpp             |   2 +-
 .../unittests/Runtime/NumericalFormatTest.cpp |   4 +-
 .../unittests/Runtime/Pointer.cpp             |   6 +-
 .../unittests/Runtime/Ragged.cpp              |   2 +-
 .../unittests/Runtime/Random.cpp              |   8 +-
 .../unittests/Runtime/Reduction.cpp           |   8 +-
 .../unittests/Runtime/RuntimeCrashTest.cpp    |   4 +-
 .../unittests/Runtime/Stop.cpp                |   5 +-
 .../unittests/Runtime/Support.cpp             |   6 +-
 .../unittests/Runtime/TemporaryStack.cpp      |   8 +-
 .../unittests/Runtime/Time.cpp                |   2 +-
 .../unittests/Runtime/Transformational.cpp    |   6 +-
 {flang => flang-rt}/unittests/Runtime/tools.h |  12 +--
 flang/CMakeLists.txt                          |   1 +
 flang/include/flang/Runtime/allocatable.h     |   2 +-
 .../include/flang/Runtime/descriptor-consts.h |   2 +
 flang/include/flang/Runtime/pointer.h         |   2 +-
 flang/runtime/CMakeLists.txt                  |  30 +++++-
 flang/runtime/CUDA/CMakeLists.txt             |   7 +-
 flang/runtime/Float128Math/CMakeLists.txt     | 100 +++++++++---------
 flang/runtime/config.h.cmake                  |  16 ---
 flang/unittests/CMakeLists.txt                |  10 +-
 flang/unittests/Runtime/CMakeLists.txt        |  60 +++++------
 flang/unittests/Runtime/CUDA/CMakeLists.txt   |   6 +-
 217 files changed, 866 insertions(+), 776 deletions(-)
 create mode 100644 flang-rt/.clang-format
 create mode 100644 flang-rt/cmake/config.h.cmake.in
 rename {flang/include/flang/Runtime => flang-rt/include/flang-rt}/CUDA/allocator.h (78%)
 rename {flang/include/flang/Runtime => flang-rt/include/flang-rt}/allocator-registry.h (88%)
 rename {flang/include/flang/Runtime => flang-rt/include/flang-rt}/array-constructor.h (89%)
 rename {flang/runtime => flang-rt/include/flang-rt}/assign-impl.h (85%)
 rename {flang/runtime => flang-rt/include/flang-rt}/buffer.h (97%)
 rename {flang/runtime => flang-rt/include/flang-rt}/connection.h (96%)
 rename {flang/runtime => flang-rt/include/flang-rt}/derived.h (90%)
 rename {flang/include/flang/Runtime => flang-rt/include/flang-rt}/descriptor.h (98%)
 rename {flang/runtime => flang-rt/include/flang-rt}/emit-encoded.h (94%)
 rename {flang/runtime => flang-rt/include/flang-rt}/environment.h (91%)
 rename {flang/runtime => flang-rt/include/flang-rt}/file.h (95%)
 rename {flang/runtime => flang-rt/include/flang-rt}/format-implementation.h (98%)
 rename {flang/runtime => flang-rt/include/flang-rt}/format.h (97%)
 rename {flang/runtime => flang-rt/include/flang-rt}/internal-unit.h (89%)
 rename {flang/runtime => flang-rt/include/flang-rt}/io-error.h (92%)
 rename {flang/runtime => flang-rt/include/flang-rt}/io-stmt.h (99%)
 rename {flang/runtime => flang-rt/include/flang-rt}/lock.h (94%)
 rename {flang/include/flang/Runtime => flang-rt/include/flang-rt}/memory.h (96%)
 rename {flang/runtime => flang-rt/include/flang-rt}/namelist.h (91%)
 rename {flang/runtime => flang-rt/include/flang-rt}/non-tbp-dio.h (91%)
 rename {flang/runtime => flang-rt/include/flang-rt}/numeric-templates.h (98%)
 rename {flang/runtime => flang-rt/include/flang-rt}/random-templates.h (93%)
 rename {flang/runtime => flang-rt/include/flang-rt}/reduction-templates.h (98%)
 rename {flang/runtime => flang-rt/include/flang-rt}/stat.h (93%)
 rename {flang/runtime => flang-rt/include/flang-rt}/terminator.h (95%)
 rename {flang/runtime => flang-rt/include/flang-rt}/tools.h (98%)
 rename {flang/include/flang/Runtime => flang-rt/include/flang-rt}/type-code.h (93%)
 rename {flang/runtime => flang-rt/include/flang-rt}/type-info.h (98%)
 rename {flang/runtime => flang-rt/include/flang-rt}/utf.h (94%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/acos.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/acosh.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/asin.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/asinh.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/atan.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/atan2.cpp (88%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/atanh.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/ceil.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/complex-math.c (92%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/complex-math.h (88%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/cos.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/cosh.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/erf.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/erfc.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/exp.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/exponent.cpp (90%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/floor.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/fma.cpp (89%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/fraction.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/hypot.cpp (88%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/j0.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/j1.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/jn.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/lgamma.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/llround.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/log.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/log10.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/lround.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/math-entries.h (96%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/mod-real.cpp (88%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/modulo-real.cpp (89%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/nearbyint.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/nearest.cpp (88%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/norm2.cpp (90%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/numeric-template-specs.h (82%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/pow.cpp (88%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/random.cpp (84%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/remainder.cpp (88%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/round.cpp (89%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/rrspacing.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/scale.cpp (90%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/set-exponent.cpp (88%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/sin.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/sinh.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/spacing.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/sqrt.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/tan.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/tanh.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/tgamma.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/trunc.cpp (89%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/y0.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/y1.cpp (87%)
 rename {flang/runtime/Float128Math => flang-rt/lib/FortranFloat128Math}/yn.cpp (87%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/CUDA/allocatable.cpp (94%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/CUDA/allocator.cpp (86%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/CUDA/descriptor.cpp (90%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/CUDA/kernel.cpp (97%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/CUDA/memmove-function.cpp (91%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/CUDA/memory.cpp (97%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/CUDA/registration.cpp (93%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/ISO_Fortran_binding.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/ISO_Fortran_util.h (91%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/allocatable.cpp (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/allocator-registry.cpp (88%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/array-constructor.cpp (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/assign.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/buffer.cpp (89%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/character.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/command.cpp (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/complex-powi.cpp (92%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/complex-reduction.c (97%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/complex-reduction.h (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/connection.cpp (91%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/copy.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/copy.h (79%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/derived-api.cpp (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/derived.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/descriptor-io.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/descriptor-io.h (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/descriptor.cpp (95%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/dot-product.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/edit-input.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/edit-input.h (89%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/edit-output.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/edit-output.h (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/environment-default-list.h (70%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/environment.cpp (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/exceptions.cpp (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/execute.cpp (97%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/extensions.cpp (97%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/external-unit.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/extrema.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/file.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/findloc.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/format.cpp (88%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/inquiry.cpp (94%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/internal-unit.cpp (97%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/io-api-common.h (93%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/io-api-minimal.cpp (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/io-api.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/io-error.cpp (97%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/io-stmt.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/iostat.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/main.cpp (90%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/matmul-transpose.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/matmul.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/memory.cpp (87%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/misc-intrinsic.cpp (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/namelist.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/non-tbp-dio.cpp (87%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/numeric.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/pointer.cpp (97%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/product.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/pseudo-unit.cpp (97%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/ragged.cpp (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/random.cpp (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/reduce.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/reduction.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/stack.h (94%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/stat.cpp (93%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/stop.cpp (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/sum.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/support.cpp (90%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/temporary-stack.cpp (97%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/terminator.cpp (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/time-intrinsic.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/tools.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/transformational.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/type-code.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/type-info.cpp (98%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/unit-map.cpp (97%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/unit-map.h (92%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/unit.cpp (99%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/unit.h (96%)
 rename {flang/runtime => flang-rt/lib/flang_rt}/utf.cpp (97%)
 rename {flang => flang-rt}/test/Driver/ctofortran.f90 (100%)
 rename {flang => flang-rt}/test/Driver/exec.f90 (100%)
 rename {flang => flang-rt}/test/Runtime/no-cpp-dep.c (100%)
 rename {flang => flang-rt}/unittests/Evaluate/ISO-Fortran-binding.cpp (98%)
 rename {flang => flang-rt}/unittests/Evaluate/reshape.cpp (88%)
 rename {flang => flang-rt}/unittests/Runtime/AccessTest.cpp (99%)
 rename {flang => flang-rt}/unittests/Runtime/Allocatable.cpp (97%)
 rename {flang => flang-rt}/unittests/Runtime/ArrayConstructor.cpp (97%)
 rename {flang => flang-rt}/unittests/Runtime/BufferTest.cpp (97%)
 rename {flang => flang-rt}/unittests/Runtime/CUDA/Allocatable.cpp (89%)
 rename {flang => flang-rt}/unittests/Runtime/CUDA/AllocatorCUF.cpp (91%)
 rename {flang => flang-rt}/unittests/Runtime/CUDA/Memory.cpp (92%)
 rename {flang => flang-rt}/unittests/Runtime/CharacterTest.cpp (99%)
 rename {flang => flang-rt}/unittests/Runtime/CommandTest.cpp (99%)
 rename {flang => flang-rt}/unittests/Runtime/Complex.cpp (98%)
 rename {flang => flang-rt}/unittests/Runtime/CrashHandlerFixture.cpp (92%)
 rename {flang => flang-rt}/unittests/Runtime/CrashHandlerFixture.h (70%)
 rename {flang => flang-rt}/unittests/Runtime/Derived.cpp (94%)
 rename {flang => flang-rt}/unittests/Runtime/ExternalIOTest.cpp (99%)
 rename {flang => flang-rt}/unittests/Runtime/Format.cpp (96%)
 rename {flang => flang-rt}/unittests/Runtime/Inquiry.cpp (98%)
 rename {flang => flang-rt}/unittests/Runtime/ListInputTest.cpp (98%)
 rename {flang => flang-rt}/unittests/Runtime/LogicalFormatTest.cpp (95%)
 rename {flang => flang-rt}/unittests/Runtime/Matmul.cpp (98%)
 rename {flang => flang-rt}/unittests/Runtime/MatmulTranspose.cpp (98%)
 rename {flang => flang-rt}/unittests/Runtime/MiscIntrinsic.cpp (96%)
 rename {flang => flang-rt}/unittests/Runtime/Namelist.cpp (99%)
 rename {flang => flang-rt}/unittests/Runtime/Numeric.cpp (99%)
 rename {flang => flang-rt}/unittests/Runtime/NumericalFormatTest.cpp (99%)
 rename {flang => flang-rt}/unittests/Runtime/Pointer.cpp (96%)
 rename {flang => flang-rt}/unittests/Runtime/Ragged.cpp (94%)
 rename {flang => flang-rt}/unittests/Runtime/Random.cpp (92%)
 rename {flang => flang-rt}/unittests/Runtime/Reduction.cpp (99%)
 rename {flang => flang-rt}/unittests/Runtime/RuntimeCrashTest.cpp (98%)
 rename {flang => flang-rt}/unittests/Runtime/Stop.cpp (96%)
 rename {flang => flang-rt}/unittests/Runtime/Support.cpp (96%)
 rename {flang => flang-rt}/unittests/Runtime/TemporaryStack.cpp (98%)
 rename {flang => flang-rt}/unittests/Runtime/Time.cpp (98%)
 rename {flang => flang-rt}/unittests/Runtime/Transformational.cpp (99%)
 rename {flang => flang-rt}/unittests/Runtime/tools.h (85%)
 delete mode 100644 flang/runtime/config.h.cmake

diff --git a/flang-rt/.clang-format b/flang-rt/.clang-format
new file mode 100644
index 0000000000000..23f4c5ae2dcf2
--- /dev/null
+++ b/flang-rt/.clang-format
@@ -0,0 +1,25 @@
+---
+# See: https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+BasedOnStyle: LLVM
+AlignAfterOpenBracket: DontAlign
+AlignEscapedNewlines: DontAlign
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignOperands: false
+AlignTrailingComments: false
+IncludeCategories:
+  - Regex:           '^<'
+    Priority:        6
+  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
+    Priority:        5
+  - Regex:           '^"flang/'     # Headers shared with Flang
+    Priority:        4
+  - Regex:           '^"flang-rt/'  # Public Flang-RT headers
+    Priority:        3
+  - Regex:           '^[^/]*$'      # Private headers from same library
+    Priority:        1
+  - Regex:           '.*'           # Private headers from sibling libraries
+    Priority:        2
+...
+
+# vim:set filetype=yaml:
diff --git a/flang-rt/cmake/config.h.cmake.in b/flang-rt/cmake/config.h.cmake.in
new file mode 100644
index 0000000000000..8a4668b90addd
--- /dev/null
+++ b/flang-rt/cmake/config.h.cmake.in
@@ -0,0 +1,19 @@
+/*===-- cmake/config.cmake.in ---------------------------------------*- 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_RUNTIME_CONFIG_H
+#define FORTRAN_RUNTIME_CONFIG_H
+
+/* Define to 1 if you have the `strerror_r' function. */
+#cmakedefine01 HAVE_STRERROR_R
+
+/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you
+   don't. */
+#cmakedefine01 HAVE_DECL_STRERROR_S
+
+#endif
diff --git a/flang/include/flang/Runtime/CUDA/allocator.h b/flang-rt/include/flang-rt/CUDA/allocator.h
similarity index 78%
rename from flang/include/flang/Runtime/CUDA/allocator.h
rename to flang-rt/include/flang-rt/CUDA/allocator.h
index 4fb4c94c5e9b0..fb09b5ff2402a 100644
--- a/flang/include/flang/Runtime/CUDA/allocator.h
+++ b/flang-rt/include/flang-rt/CUDA/allocator.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/CUDA/allocator.h ------------------*- C++ -*-===//
+//===-- include/flang-rt/CUDA/allocator.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_RUNTIME_CUDA_ALLOCATOR_H_
-#define FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
+#ifndef FLANG_RT_CUDA_ALLOCATOR_H_
+#define FLANG_RT_CUDA_ALLOCATOR_H_
 
-#include "common.h"
+#include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
 
@@ -33,4 +33,4 @@ void *CUFAllocUnified(std::size_t);
 void CUFFreeUnified(void *);
 
 } // namespace Fortran::runtime::cuda
-#endif // FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
+#endif /* FLANG_RT_CUDA_ALLOCATOR_H_ */
diff --git a/flang/include/flang/Runtime/allocator-registry.h b/flang-rt/include/flang-rt/allocator-registry.h
similarity index 88%
rename from flang/include/flang/Runtime/allocator-registry.h
rename to flang-rt/include/flang-rt/allocator-registry.h
index 29302c5d825bc..1f004462ca624 100644
--- a/flang/include/flang/Runtime/allocator-registry.h
+++ b/flang-rt/include/flang-rt/allocator-registry.h
@@ -1,4 +1,4 @@
-//===-- runtime/allocator-registry.h ----------------------------*- C++ -*-===//
+//===-- include/flang-rt/allocator-registry.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_RUNTIME_ALLOCATOR_REGISTRY_H_
-#define FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_
+#ifndef FLANG_RT_ALLOCATOR_REGISTRY_H_
+#define FLANG_RT_ALLOCATOR_REGISTRY_H_
 
 #include "flang/Common/api-attrs.h"
 #include "flang/Runtime/allocator-registry-consts.h"
@@ -55,4 +55,4 @@ RT_OFFLOAD_VAR_GROUP_END
 
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_
+#endif /* FLANG_RT_ALLOCATOR_REGISTRY_H_ */
diff --git a/flang/include/flang/Runtime/array-constructor.h b/flang-rt/include/flang-rt/array-constructor.h
similarity index 89%
rename from flang/include/flang/Runtime/array-constructor.h
rename to flang-rt/include/flang-rt/array-constructor.h
index 2f6aaae17c650..7ff0779e46c6a 100644
--- a/flang/include/flang/Runtime/array-constructor.h
+++ b/flang-rt/include/flang-rt/array-constructor.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/array-constructor.h ---------------*- C++ -*-===//
+//===-- include/flang-rt/array-constructor.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.
@@ -9,11 +9,11 @@
 // External APIs to create temporary storage for array constructors when their
 // final extents or length parameters cannot be pre-computed.
 
-#ifndef FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
-#define FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
+#ifndef FLANG_RT_ARRAY_CONSTRUCTOR_H_
+#define FLANG_RT_ARRAY_CONSTRUCTOR_H_
 
+#include "descriptor.h"
 #include "flang/Runtime/array-constructor-consts.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/entry-names.h"
 #include <cstdint>
 
@@ -54,4 +54,4 @@ static_assert(alignof(Fortran::runtime::ArrayConstructorVector) <=
     "MaxArrayConstructorVectorAlignInBytes");
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
+#endif /* FLANG_RT_ARRAY_CONSTRUCTOR_H_ */
diff --git a/flang/runtime/assign-impl.h b/flang-rt/include/flang-rt/assign-impl.h
similarity index 85%
rename from flang/runtime/assign-impl.h
rename to flang-rt/include/flang-rt/assign-impl.h
index aaa320ef7f959..7e2cef9df753b 100644
--- a/flang/runtime/assign-impl.h
+++ b/flang-rt/include/flang-rt/assign-impl.h
@@ -1,4 +1,4 @@
-//===-- runtime/assign-impl.h -----------------------------------*- C++ -*-===//
+//===-- include/flang-rt/assign-impl.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_RUNTIME_ASSIGN_IMPL_H_
-#define FORTRAN_RUNTIME_ASSIGN_IMPL_H_
+#ifndef FLANG_RT_ASSIGN_IMPL_H_
+#define FLANG_RT_ASSIGN_IMPL_H_
 
 #include "flang/Runtime/freestanding-tools.h"
 
@@ -28,4 +28,4 @@ RT_API_ATTRS void DoFromSourceAssign(Descriptor &, const Descriptor &,
 #endif
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_ASSIGN_IMPL_H_
+#endif /* FLANG_RT_ASSIGN_IMPL_H_ */
diff --git a/flang/runtime/buffer.h b/flang-rt/include/flang-rt/buffer.h
similarity index 97%
rename from flang/runtime/buffer.h
rename to flang-rt/include/flang-rt/buffer.h
index 41a1abb1b2d90..ba172448a93a5 100644
--- a/flang/runtime/buffer.h
+++ b/flang-rt/include/flang-rt/buffer.h
@@ -1,4 +1,4 @@
-//===-- runtime/buffer.h ----------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/buffer.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.
@@ -8,12 +8,12 @@
 
 // External file buffering
 
-#ifndef FORTRAN_RUNTIME_BUFFER_H_
-#define FORTRAN_RUNTIME_BUFFER_H_
+#ifndef FLANG_RT_BUFFER_H_
+#define FLANG_RT_BUFFER_H_
 
 #include "io-error.h"
+#include "memory.h"
 #include "flang/Runtime/freestanding-tools.h"
-#include "flang/Runtime/memory.h"
 #include <algorithm>
 #include <cinttypes>
 #include <cstring>
@@ -221,4 +221,4 @@ template <typename STORE, std::size_t minBuffer = 65536> class FileFrame {
   bool dirty_{false};
 };
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_BUFFER_H_
+#endif /* FLANG_RT_BUFFER_H_ */
diff --git a/flang/runtime/connection.h b/flang-rt/include/flang-rt/connection.h
similarity index 96%
rename from flang/runtime/connection.h
rename to flang-rt/include/flang-rt/connection.h
index 6f1ea90a160e5..7f594deee69c6 100644
--- a/flang/runtime/connection.h
+++ b/flang-rt/include/flang-rt/connection.h
@@ -1,4 +1,4 @@
-//===-- runtime/connection.h ------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/connection.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.
@@ -8,8 +8,8 @@
 
 // Fortran I/O connection state (abstracted over internal & external units)
 
-#ifndef FORTRAN_RUNTIME_IO_CONNECTION_H_
-#define FORTRAN_RUNTIME_IO_CONNECTION_H_
+#ifndef FLANG_RT_CONNECTION_H_
+#define FLANG_RT_CONNECTION_H_
 
 #include "format.h"
 #include "flang/Common/optional.h"
@@ -124,4 +124,4 @@ class SavedPosition {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IO_CONNECTION_H_
+#endif /* FLANG_RT_CONNECTION_H_ */
diff --git a/flang/runtime/derived.h b/flang-rt/include/flang-rt/derived.h
similarity index 90%
rename from flang/runtime/derived.h
rename to flang-rt/include/flang-rt/derived.h
index f5a1e219b848c..797a089e767c4 100644
--- a/flang/runtime/derived.h
+++ b/flang-rt/include/flang-rt/derived.h
@@ -1,4 +1,4 @@
-//===-- runtime/derived.h -------------------------------------------------===//
+//===-- include/flang-rt/derived.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.
@@ -8,8 +8,8 @@
 
 // Internal runtime utilities for derived type operations.
 
-#ifndef FORTRAN_RUNTIME_DERIVED_H_
-#define FORTRAN_RUNTIME_DERIVED_H_
+#ifndef FLANG_RT_DERIVED_H_
+#define FLANG_RT_DERIVED_H_
 
 #include "flang/Common/api-attrs.h"
 
@@ -48,4 +48,4 @@ RT_API_ATTRS void Destroy(const Descriptor &, bool finalize,
 RT_API_ATTRS bool HasDynamicComponent(const Descriptor &);
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_DERIVED_H_
+#endif /* FLANG_RT_DERIVED_H_ */
diff --git a/flang/include/flang/Runtime/descriptor.h b/flang-rt/include/flang-rt/descriptor.h
similarity index 98%
rename from flang/include/flang/Runtime/descriptor.h
rename to flang-rt/include/flang-rt/descriptor.h
index 628ac8c927a51..27f80bec4ba93 100644
--- a/flang/include/flang/Runtime/descriptor.h
+++ b/flang-rt/include/flang-rt/descriptor.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/descriptor.h ----------------------*- C++ -*-===//
+//===-- include/flang-rt/descriptor.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_RUNTIME_DESCRIPTOR_H_
-#define FORTRAN_RUNTIME_DESCRIPTOR_H_
+#ifndef FLANG_RT_DESCRIPTOR_H_
+#define FLANG_RT_DESCRIPTOR_H_
 
 // Defines data structures used during execution of a Fortran program
 // to implement nontrivial dummy arguments, pointers, allocatables,
@@ -18,10 +18,10 @@
 // User C code is welcome to depend on that ISO_Fortran_binding.h file,
 // but should never reference this internal header.
 
+#include "memory.h"
+#include "type-code.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"
 #include <algorithm>
 #include <cassert>
 #include <cinttypes>
@@ -482,4 +482,4 @@ class alignas(Descriptor) StaticDescriptor {
 };
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_DESCRIPTOR_H_
+#endif /* FLANG_RT_DESCRIPTOR_H_ */
diff --git a/flang/runtime/emit-encoded.h b/flang-rt/include/flang-rt/emit-encoded.h
similarity index 94%
rename from flang/runtime/emit-encoded.h
rename to flang-rt/include/flang-rt/emit-encoded.h
index 4b5e390078835..f3cb7a9f790e4 100644
--- a/flang/runtime/emit-encoded.h
+++ b/flang-rt/include/flang-rt/emit-encoded.h
@@ -1,4 +1,4 @@
-//===-- runtime/emit-encoded.h ----------------------------------*- C++ -*-===//
+//===-- include/flang-rt/emit-encoded.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.
@@ -8,8 +8,8 @@
 
 // Templates for emitting CHARACTER values with conversion
 
-#ifndef FORTRAN_RUNTIME_EMIT_ENCODED_H_
-#define FORTRAN_RUNTIME_EMIT_ENCODED_H_
+#ifndef FLANG_RT_EMIT_ENCODED_H_
+#define FLANG_RT_EMIT_ENCODED_H_
 
 #include "connection.h"
 #include "environment.h"
@@ -114,4 +114,4 @@ RT_API_ATTRS bool EmitRepeated(CONTEXT &to, char ch, std::size_t n) {
 }
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_EMIT_ENCODED_H_
+#endif /* FLANG_RT_EMIT_ENCODED_H_ */
diff --git a/flang/runtime/environment.h b/flang-rt/include/flang-rt/environment.h
similarity index 91%
rename from flang/runtime/environment.h
rename to flang-rt/include/flang-rt/environment.h
index b8b9f10e4e57f..55e896b0e0861 100644
--- a/flang/runtime/environment.h
+++ b/flang-rt/include/flang-rt/environment.h
@@ -1,4 +1,4 @@
-//===-- runtime/environment.h -----------------------------------*- C++ -*-===//
+//===-- include/flang-rt/environment.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_RUNTIME_ENVIRONMENT_H_
-#define FORTRAN_RUNTIME_ENVIRONMENT_H_
+#ifndef FLANG_RT_ENVIRONMENT_H_
+#define FLANG_RT_ENVIRONMENT_H_
 
 #include "flang/Common/optional.h"
 #include "flang/Decimal/decimal.h"
@@ -64,4 +64,4 @@ RT_OFFLOAD_VAR_GROUP_END
 
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_ENVIRONMENT_H_
+#endif /* FLANG_RT_ENVIRONMENT_H_ */
diff --git a/flang/runtime/file.h b/flang-rt/include/flang-rt/file.h
similarity index 95%
rename from flang/runtime/file.h
rename to flang-rt/include/flang-rt/file.h
index c06acbb9904cc..ca95156e1fba4 100644
--- a/flang/runtime/file.h
+++ b/flang-rt/include/flang-rt/file.h
@@ -1,4 +1,4 @@
-//===-- runtime/file.h ------------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/file.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.
@@ -8,12 +8,12 @@
 
 // Raw system I/O wrappers
 
-#ifndef FORTRAN_RUNTIME_FILE_H_
-#define FORTRAN_RUNTIME_FILE_H_
+#ifndef FLANG_RT_FILE_H_
+#define FLANG_RT_FILE_H_
 
 #include "io-error.h"
+#include "memory.h"
 #include "flang/Common/optional.h"
-#include "flang/Runtime/memory.h"
 #include <cinttypes>
 
 namespace Fortran::runtime::io {
@@ -113,4 +113,4 @@ RT_API_ATTRS bool MayWrite(const char *path);
 RT_API_ATTRS bool MayReadAndWrite(const char *path);
 RT_API_ATTRS std::int64_t SizeInBytes(const char *path);
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_FILE_H_
+#endif /* FLANG_RT_FILE_H_ */
diff --git a/flang/runtime/format-implementation.h b/flang-rt/include/flang-rt/format-implementation.h
similarity index 98%
rename from flang/runtime/format-implementation.h
rename to flang-rt/include/flang-rt/format-implementation.h
index 46204ca927c13..52f265d06f9bf 100644
--- a/flang/runtime/format-implementation.h
+++ b/flang-rt/include/flang-rt/format-implementation.h
@@ -1,4 +1,4 @@
-//===-- runtime/format-implementation.h -------------------------*- C++ -*-===//
+//===-- include/flang-rt/format-implementation.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.
@@ -8,8 +8,8 @@
 
 // Implements out-of-line member functions of template class FormatControl
 
-#ifndef FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_
-#define FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_
+#ifndef FLANG_RT_FORMAT_IMPLEMENTATION_H_
+#define FLANG_RT_FORMAT_IMPLEMENTATION_H_
 
 #include "emit-encoded.h"
 #include "format.h"
@@ -601,4 +601,4 @@ RT_API_ATTRS void FormatControl<CONTEXT>::Finish(Context &context) {
   }
 }
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_
+#endif /* FLANG_RT_FORMAT_IMPLEMENTATION_H_ */
diff --git a/flang/runtime/format.h b/flang-rt/include/flang-rt/format.h
similarity index 97%
rename from flang/runtime/format.h
rename to flang-rt/include/flang-rt/format.h
index 815bf70685e64..d81241e41877c 100644
--- a/flang/runtime/format.h
+++ b/flang-rt/include/flang-rt/format.h
@@ -1,4 +1,4 @@
-//===-- runtime/format.h ----------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/format.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.
@@ -8,8 +8,8 @@
 
 // FORMAT string processing
 
-#ifndef FORTRAN_RUNTIME_FORMAT_H_
-#define FORTRAN_RUNTIME_FORMAT_H_
+#ifndef FLANG_RT_FORMAT_H_
+#define FLANG_RT_FORMAT_H_
 
 #include "environment.h"
 #include "io-error.h"
@@ -201,4 +201,4 @@ template <typename CONTEXT> class FormatControl {
   Iteration stack_[maxMaxHeight];
 };
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_FORMAT_H_
+#endif /* FLANG_RT_FORMAT_H_ */
diff --git a/flang/runtime/internal-unit.h b/flang-rt/include/flang-rt/internal-unit.h
similarity index 89%
rename from flang/runtime/internal-unit.h
rename to flang-rt/include/flang-rt/internal-unit.h
index a0ee6353eeda3..21e64b5624196 100644
--- a/flang/runtime/internal-unit.h
+++ b/flang-rt/include/flang-rt/internal-unit.h
@@ -1,4 +1,4 @@
-//===-- runtime/internal-unit.h ---------------------------------*- C++ -*-===//
+//===-- include/flang-rt/internal-unit.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.
@@ -8,11 +8,11 @@
 
 // Fortran internal I/O "units"
 
-#ifndef FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
-#define FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
+#ifndef FLANG_RT_INTERNAL_UNIT_H_
+#define FLANG_RT_INTERNAL_UNIT_H_
 
 #include "connection.h"
-#include "flang/Runtime/descriptor.h"
+#include "descriptor.h"
 #include <cinttypes>
 #include <type_traits>
 
@@ -56,4 +56,4 @@ template <Direction DIR> class InternalDescriptorUnit : public ConnectionState {
 extern template class InternalDescriptorUnit<Direction::Output>;
 extern template class InternalDescriptorUnit<Direction::Input>;
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
+#endif /* FLANG_RT_INTERNAL_UNIT_H_ */
diff --git a/flang/runtime/io-error.h b/flang-rt/include/flang-rt/io-error.h
similarity index 92%
rename from flang/runtime/io-error.h
rename to flang-rt/include/flang-rt/io-error.h
index 39a343c8e0a51..c74c08970f94a 100644
--- a/flang/runtime/io-error.h
+++ b/flang-rt/include/flang-rt/io-error.h
@@ -1,4 +1,4 @@
-//===-- runtime/io-error.h --------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/io-error.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,12 +12,12 @@
 // IOSTAT error codes are raw errno values augmented with values for
 // Fortran-specific errors.
 
-#ifndef FORTRAN_RUNTIME_IO_ERROR_H_
-#define FORTRAN_RUNTIME_IO_ERROR_H_
+#ifndef FLANG_RT_IO_ERROR_H_
+#define FLANG_RT_IO_ERROR_H_
 
+#include "memory.h"
 #include "terminator.h"
 #include "flang/Runtime/iostat.h"
-#include "flang/Runtime/memory.h"
 #include <cinttypes>
 
 namespace Fortran::runtime::io {
@@ -80,4 +80,4 @@ class IoErrorHandler : public Terminator {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IO_ERROR_H_
+#endif /* FLANG_RT_IO_ERROR_H_ */
diff --git a/flang/runtime/io-stmt.h b/flang-rt/include/flang-rt/io-stmt.h
similarity index 99%
rename from flang/runtime/io-stmt.h
rename to flang-rt/include/flang-rt/io-stmt.h
index 1f1419b249e5e..87fd93c353d76 100644
--- a/flang/runtime/io-stmt.h
+++ b/flang-rt/include/flang-rt/io-stmt.h
@@ -1,4 +1,4 @@
-//===-- runtime/io-stmt.h ---------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/io-stmt.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.
@@ -8,10 +8,11 @@
 
 // Representations of the state of an I/O statement in progress
 
-#ifndef FORTRAN_RUNTIME_IO_STMT_H_
-#define FORTRAN_RUNTIME_IO_STMT_H_
+#ifndef FLANG_RT_IO_STMT_H_
+#define FLANG_RT_IO_STMT_H_
 
 #include "connection.h"
+#include "descriptor.h"
 #include "file.h"
 #include "format.h"
 #include "internal-unit.h"
@@ -19,7 +20,6 @@
 #include "flang/Common/optional.h"
 #include "flang/Common/reference-wrapper.h"
 #include "flang/Common/visit.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/io-api.h"
 #include <flang/Common/variant.h>
 #include <functional>
@@ -791,4 +791,4 @@ class ErroneousIoStatementState : public IoStatementBase {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IO_STMT_H_
+#endif /* FLANG_RT_IO_STMT_H_ */
diff --git a/flang/runtime/lock.h b/flang-rt/include/flang-rt/lock.h
similarity index 94%
rename from flang/runtime/lock.h
rename to flang-rt/include/flang-rt/lock.h
index 46ca28703a45b..f57e97184edd5 100644
--- a/flang/runtime/lock.h
+++ b/flang-rt/include/flang-rt/lock.h
@@ -1,4 +1,4 @@
-//===-- runtime/lock.h ------------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/lock.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.
@@ -8,8 +8,8 @@
 
 // Wraps a mutex
 
-#ifndef FORTRAN_RUNTIME_LOCK_H_
-#define FORTRAN_RUNTIME_LOCK_H_
+#ifndef FLANG_RT_LOCK_H_
+#define FLANG_RT_LOCK_H_
 
 #include "terminator.h"
 #include "tools.h"
@@ -113,4 +113,4 @@ class CriticalSection {
 };
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_LOCK_H_
+#endif /* FLANG_RT_LOCK_H_ */
diff --git a/flang/include/flang/Runtime/memory.h b/flang-rt/include/flang-rt/memory.h
similarity index 96%
rename from flang/include/flang/Runtime/memory.h
rename to flang-rt/include/flang-rt/memory.h
index 98412a989f890..afbb1b34c1d2c 100644
--- a/flang/include/flang/Runtime/memory.h
+++ b/flang-rt/include/flang-rt/memory.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/memory.h --------------------------*- C++ -*-===//
+//===-- include/flang-rt/memory.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.
@@ -9,8 +9,8 @@
 // Thin wrapper around malloc()/free() to isolate the dependency,
 // ease porting, and provide an owning pointer.
 
-#ifndef FORTRAN_RUNTIME_MEMORY_H_
-#define FORTRAN_RUNTIME_MEMORY_H_
+#ifndef FLANG_RT_MEMORY_H_
+#define FLANG_RT_MEMORY_H_
 
 #include "flang/Common/api-attrs.h"
 #include <cassert>
@@ -170,4 +170,4 @@ template <typename A> struct Allocator {
 };
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_MEMORY_H_
+#endif /* FLANG_RT_MEMORY_H_ */
diff --git a/flang/runtime/namelist.h b/flang-rt/include/flang-rt/namelist.h
similarity index 91%
rename from flang/runtime/namelist.h
rename to flang-rt/include/flang-rt/namelist.h
index 25216a75e9367..5757bfb3b7109 100644
--- a/flang/runtime/namelist.h
+++ b/flang-rt/include/flang-rt/namelist.h
@@ -1,4 +1,4 @@
-//===-- runtime/namelist.h --------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/namelist.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.
@@ -8,8 +8,8 @@
 
 // Defines the data structure used for NAMELIST I/O
 
-#ifndef FORTRAN_RUNTIME_NAMELIST_H_
-#define FORTRAN_RUNTIME_NAMELIST_H_
+#ifndef FLANG_RT_NAMELIST_H_
+#define FLANG_RT_NAMELIST_H_
 
 #include "non-tbp-dio.h"
 #include "flang/Common/api-attrs.h"
@@ -51,4 +51,4 @@ class NamelistGroup {
 RT_API_ATTRS bool IsNamelistNameOrSlash(IoStatementState &);
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_NAMELIST_H_
+#endif /* FLANG_RT_NAMELIST_H_ */
diff --git a/flang/runtime/non-tbp-dio.h b/flang-rt/include/flang-rt/non-tbp-dio.h
similarity index 91%
rename from flang/runtime/non-tbp-dio.h
rename to flang-rt/include/flang-rt/non-tbp-dio.h
index 8429d790fea57..58ed29ba7a102 100644
--- a/flang/runtime/non-tbp-dio.h
+++ b/flang-rt/include/flang-rt/non-tbp-dio.h
@@ -1,4 +1,4 @@
-//===-- flang/runtime/non-tbp-dio.h -----------------------------*- C++ -*-===//
+//===-- include/flang-rt/non-tbp-dio.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.
@@ -19,8 +19,8 @@
 // a containing scope has become inaccessible in a nested scope due
 // to the use of "IMPORT, NONE" or "IMPORT, ONLY:".
 
-#ifndef FORTRAN_RUNTIME_NON_TBP_DIO_H_
-#define FORTRAN_RUNTIME_NON_TBP_DIO_H_
+#ifndef FLANG_RT_NON_TBP_DIO_H_
+#define FLANG_RT_NON_TBP_DIO_H_
 
 #include "flang/Common/Fortran-consts.h"
 #include "flang/Common/api-attrs.h"
@@ -53,4 +53,4 @@ struct NonTbpDefinedIoTable {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_NON_TBP_DIO_H_
+#endif /* FLANG_RT_NON_TBP_DIO_H_ */
diff --git a/flang/runtime/numeric-templates.h b/flang-rt/include/flang-rt/numeric-templates.h
similarity index 98%
rename from flang/runtime/numeric-templates.h
rename to flang-rt/include/flang-rt/numeric-templates.h
index fbb371bffc27a..7019151c3a207 100644
--- a/flang/runtime/numeric-templates.h
+++ b/flang-rt/include/flang-rt/numeric-templates.h
@@ -1,4 +1,4 @@
-//===-- runtime/numeric-templates.h -----------------------------*- C++ -*-===//
+//===-- include/flang-rt/numeric-templates.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.
@@ -15,8 +15,8 @@
 // for the data type corresponding to CppTypeFor<TypeCategory::Real, 16>
 // on the target.
 
-#ifndef FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_
-#define FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_
+#ifndef FLANG_RT_NUMERIC_TEMPLATES_H_
+#define FLANG_RT_NUMERIC_TEMPLATES_H_
 
 #include "terminator.h"
 #include "tools.h"
@@ -368,4 +368,4 @@ template <typename T> inline RT_API_ATTRS T ErfcScaled(T arg) {
 
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_
+#endif /* FLANG_RT_NUMERIC_TEMPLATES_H_ */
diff --git a/flang/runtime/random-templates.h b/flang-rt/include/flang-rt/random-templates.h
similarity index 93%
rename from flang/runtime/random-templates.h
rename to flang-rt/include/flang-rt/random-templates.h
index 3885941704d4a..f320f2cd328f5 100644
--- a/flang/runtime/random-templates.h
+++ b/flang-rt/include/flang-rt/random-templates.h
@@ -1,4 +1,4 @@
-//===-- runtime/random-templates.h ------------------------------*- C++ -*-===//
+//===-- include/flang-rt/random-templates.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_RUNTIME_RANDOM_TEMPLATES_H_
-#define FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_
+#ifndef FLANG_RT_RANDOM_TEMPLATES_H_
+#define FLANG_RT_RANDOM_TEMPLATES_H_
 
+#include "descriptor.h"
 #include "lock.h"
 #include "numeric-templates.h"
 #include "flang/Common/optional.h"
-#include "flang/Runtime/descriptor.h"
 #include <algorithm>
 #include <random>
 
@@ -108,4 +108,4 @@ inline void GenerateUnsigned(const Descriptor &harvest) {
 
 } // namespace Fortran::runtime::random
 
-#endif // FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_
+#endif /* FLANG_RT_RANDOM_TEMPLATES_H_ */
diff --git a/flang/runtime/reduction-templates.h b/flang-rt/include/flang-rt/reduction-templates.h
similarity index 98%
rename from flang/runtime/reduction-templates.h
rename to flang-rt/include/flang-rt/reduction-templates.h
index b20b03655c3d0..513b3e4478498 100644
--- a/flang/runtime/reduction-templates.h
+++ b/flang-rt/include/flang-rt/reduction-templates.h
@@ -1,4 +1,4 @@
-//===-- runtime/reduction-templates.h ---------------------------*- C++ -*-===//
+//===-- include/flang-rt/reduction-templates.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.
@@ -18,14 +18,14 @@
 // * Character-valued reductions (MAXVAL & MINVAL) return arbitrary
 //   length results, dynamically allocated in a caller-supplied descriptor
 
-#ifndef FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_
-#define FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_
+#ifndef FLANG_RT_REDUCTION_TEMPLATES_H_
+#define FLANG_RT_REDUCTION_TEMPLATES_H_
 
+#include "descriptor.h"
 #include "numeric-templates.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include <algorithm>
 
 namespace Fortran::runtime {
@@ -416,4 +416,4 @@ template <int KIND> struct Norm2Helper {
 };
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_
+#endif /* FLANG_RT_REDUCTION_TEMPLATES_H_ */
diff --git a/flang/runtime/stat.h b/flang-rt/include/flang-rt/stat.h
similarity index 93%
rename from flang/runtime/stat.h
rename to flang-rt/include/flang-rt/stat.h
index 572cb6d10b489..95ae286a03b49 100644
--- a/flang/runtime/stat.h
+++ b/flang-rt/include/flang-rt/stat.h
@@ -1,4 +1,4 @@
-//===-- runtime/stat.h ------------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/stat.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.
@@ -9,8 +9,8 @@
 // Defines the values returned by the runtime for STAT= specifiers
 // on executable statements.
 
-#ifndef FORTRAN_RUNTIME_STAT_H_
-#define FORTRAN_RUNTIME_STAT_H_
+#ifndef FLANG_RT_STAT_H_
+#define FLANG_RT_STAT_H_
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Common/api-attrs.h"
 #include "flang/Runtime/magic-numbers.h"
@@ -60,4 +60,4 @@ RT_API_ATTRS int ToErrmsg(const Descriptor *errmsg, int stat); // returns stat
 RT_API_ATTRS int ReturnError(Terminator &, int stat,
     const Descriptor *errmsg = nullptr, bool hasStat = false);
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_STAT_H
+#endif /* FLANG_RT_STAT_H_ */
diff --git a/flang/runtime/terminator.h b/flang-rt/include/flang-rt/terminator.h
similarity index 95%
rename from flang/runtime/terminator.h
rename to flang-rt/include/flang-rt/terminator.h
index 609f059d6e092..800ed6f3755b7 100644
--- a/flang/runtime/terminator.h
+++ b/flang-rt/include/flang-rt/terminator.h
@@ -1,4 +1,4 @@
-//===-- runtime/terminator.h ------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/terminator.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.
@@ -8,8 +8,8 @@
 
 // Termination of the image
 
-#ifndef FORTRAN_RUNTIME_TERMINATOR_H_
-#define FORTRAN_RUNTIME_TERMINATOR_H_
+#ifndef FLANG_RT_TERMINATOR_H_
+#define FLANG_RT_TERMINATOR_H_
 
 #include "flang/Common/api-attrs.h"
 #include <cstdarg>
@@ -121,4 +121,4 @@ namespace Fortran::runtime::io {
 RT_API_ATTRS void FlushOutputOnCrash(const Terminator &);
 }
 
-#endif // FORTRAN_RUNTIME_TERMINATOR_H_
+#endif /* FLANG_RT_TERMINATOR_H_ */
diff --git a/flang/runtime/tools.h b/flang-rt/include/flang-rt/tools.h
similarity index 98%
rename from flang/runtime/tools.h
rename to flang-rt/include/flang-rt/tools.h
index facbd23161057..38804a1f40991 100644
--- a/flang/runtime/tools.h
+++ b/flang-rt/include/flang-rt/tools.h
@@ -1,4 +1,4 @@
-//===-- runtime/tools.h -----------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/tools.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,16 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_TOOLS_H_
-#define FORTRAN_RUNTIME_TOOLS_H_
+#ifndef FLANG_RT_TOOLS_H_
+#define FLANG_RT_TOOLS_H_
 
+#include "descriptor.h"
+#include "memory.h"
 #include "stat.h"
 #include "terminator.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/freestanding-tools.h"
-#include "flang/Runtime/memory.h"
 #include <cstring>
 #include <functional>
 #include <map>
@@ -570,4 +570,4 @@ RT_API_ATTRS void CreatePartialReductionResult(Descriptor &result,
     const char *intrinsic, TypeCode);
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_TOOLS_H_
+#endif /* FLANG_RT_TOOLS_H_ */
diff --git a/flang/include/flang/Runtime/type-code.h b/flang-rt/include/flang-rt/type-code.h
similarity index 93%
rename from flang/include/flang/Runtime/type-code.h
rename to flang-rt/include/flang-rt/type-code.h
index ae854ed2145e4..1d057481261a1 100644
--- a/flang/include/flang/Runtime/type-code.h
+++ b/flang-rt/include/flang-rt/type-code.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/type-code.h -----------------------*- C++ -*-===//
+//===-- include/flang-rt/type-code.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_RUNTIME_TYPE_CODE_H_
-#define FORTRAN_RUNTIME_TYPE_CODE_H_
+#ifndef FLANG_RT_TYPE_CODE_H_
+#define FLANG_RT_TYPE_CODE_H_
 
 #include "flang/Common/Fortran-consts.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
@@ -75,4 +75,4 @@ class TypeCode {
   ISO::CFI_type_t raw_{CFI_type_other};
 };
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_TYPE_CODE_H_
+#endif /* FLANG_RT_TYPE_CODE_H_ */
diff --git a/flang/runtime/type-info.h b/flang-rt/include/flang-rt/type-info.h
similarity index 98%
rename from flang/runtime/type-info.h
rename to flang-rt/include/flang-rt/type-info.h
index 32403b1db5169..52e208c93fe25 100644
--- a/flang/runtime/type-info.h
+++ b/flang-rt/include/flang-rt/type-info.h
@@ -1,4 +1,4 @@
-//===-- runtime/type-info.h -------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/type-info.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,17 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_TYPE_INFO_H_
-#define FORTRAN_RUNTIME_TYPE_INFO_H_
+#ifndef FLANG_RT_TYPE_INFO_H_
+#define FLANG_RT_TYPE_INFO_H_
 
 // A C++ perspective of the derived type description schemata in
 // flang/module/__fortran_type_info.f90.
 
+#include "descriptor.h"
 #include "terminator.h"
 #include "flang/Common/Fortran-consts.h"
 #include "flang/Common/bit-population-count.h"
 #include "flang/Common/optional.h"
-#include "flang/Runtime/descriptor.h"
 #include <cinttypes>
 #include <memory>
 
@@ -321,4 +321,4 @@ class DerivedType {
 };
 
 } // namespace Fortran::runtime::typeInfo
-#endif // FORTRAN_RUNTIME_TYPE_INFO_H_
+#endif /* FLANG_RT_TYPE_INFO_H_ */
diff --git a/flang/runtime/utf.h b/flang-rt/include/flang-rt/utf.h
similarity index 94%
rename from flang/runtime/utf.h
rename to flang-rt/include/flang-rt/utf.h
index 10c2d61484217..4d1e23b9ccb94 100644
--- a/flang/runtime/utf.h
+++ b/flang-rt/include/flang-rt/utf.h
@@ -1,4 +1,4 @@
-//===-- runtime/utf.h -----------------------------------------------------===//
+//===-- include/flang-rt/utf.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.
@@ -38,8 +38,8 @@
 // standard maximum.  However, we support extended forms up to 32 bits so that
 // CHARACTER(KIND=4) can be abused to hold arbitrary 32-bit data.
 
-#ifndef FORTRAN_RUNTIME_UTF_H_
-#define FORTRAN_RUNTIME_UTF_H_
+#ifndef FLANG_RT_UTF_H_
+#define FLANG_RT_UTF_H_
 
 #include "flang/Common/optional.h"
 #include <cstddef>
@@ -70,4 +70,4 @@ RT_API_ATTRS Fortran::common::optional<char32_t> DecodeUTF8(const char *);
 RT_API_ATTRS std::size_t EncodeUTF8(char *, char32_t);
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_UTF_H_
+#endif /* FLANG_RT_UTF_H_ */
diff --git a/flang/runtime/Float128Math/acos.cpp b/flang-rt/lib/FortranFloat128Math/acos.cpp
similarity index 87%
rename from flang/runtime/Float128Math/acos.cpp
rename to flang-rt/lib/FortranFloat128Math/acos.cpp
index d9b4950aa1e35..7f20654752754 100644
--- a/flang/runtime/Float128Math/acos.cpp
+++ b/flang-rt/lib/FortranFloat128Math/acos.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/acos.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/acos.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/Float128Math/acosh.cpp b/flang-rt/lib/FortranFloat128Math/acosh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/acosh.cpp
rename to flang-rt/lib/FortranFloat128Math/acosh.cpp
index c572673ef55e6..73b64230f08c7 100644
--- a/flang/runtime/Float128Math/acosh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/acosh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/acosh.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/acosh.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/Float128Math/asin.cpp b/flang-rt/lib/FortranFloat128Math/asin.cpp
similarity index 87%
rename from flang/runtime/Float128Math/asin.cpp
rename to flang-rt/lib/FortranFloat128Math/asin.cpp
index 57b6ffd967360..b51ecb6b674d3 100644
--- a/flang/runtime/Float128Math/asin.cpp
+++ b/flang-rt/lib/FortranFloat128Math/asin.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/asin.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/asin.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/Float128Math/asinh.cpp b/flang-rt/lib/FortranFloat128Math/asinh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/asinh.cpp
rename to flang-rt/lib/FortranFloat128Math/asinh.cpp
index 03dded722b254..2fc181d075aec 100644
--- a/flang/runtime/Float128Math/asinh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/asinh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/asinh.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/asinh.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/Float128Math/atan.cpp b/flang-rt/lib/FortranFloat128Math/atan.cpp
similarity index 87%
rename from flang/runtime/Float128Math/atan.cpp
rename to flang-rt/lib/FortranFloat128Math/atan.cpp
index 19c86cae8867b..ff1ec39bfdebd 100644
--- a/flang/runtime/Float128Math/atan.cpp
+++ b/flang-rt/lib/FortranFloat128Math/atan.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/atan.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/atan.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/Float128Math/atan2.cpp b/flang-rt/lib/FortranFloat128Math/atan2.cpp
similarity index 88%
rename from flang/runtime/Float128Math/atan2.cpp
rename to flang-rt/lib/FortranFloat128Math/atan2.cpp
index 09d666ae14304..4e809cb547a1b 100644
--- a/flang/runtime/Float128Math/atan2.cpp
+++ b/flang-rt/lib/FortranFloat128Math/atan2.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/atan2.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/atan2.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/Float128Math/atanh.cpp b/flang-rt/lib/FortranFloat128Math/atanh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/atanh.cpp
rename to flang-rt/lib/FortranFloat128Math/atanh.cpp
index 442d9beafae47..d4e3e7426b16d 100644
--- a/flang/runtime/Float128Math/atanh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/atanh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/atanh.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/atanh.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/Float128Math/ceil.cpp b/flang-rt/lib/FortranFloat128Math/ceil.cpp
similarity index 87%
rename from flang/runtime/Float128Math/ceil.cpp
rename to flang-rt/lib/FortranFloat128Math/ceil.cpp
index 48e20b2b41577..f439f22c0565a 100644
--- a/flang/runtime/Float128Math/ceil.cpp
+++ b/flang-rt/lib/FortranFloat128Math/ceil.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/ceil.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/ceil.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/Float128Math/complex-math.c b/flang-rt/lib/FortranFloat128Math/complex-math.c
similarity index 92%
rename from flang/runtime/Float128Math/complex-math.c
rename to flang-rt/lib/FortranFloat128Math/complex-math.c
index a7e32f3ef755b..fed37dfce6332 100644
--- a/flang/runtime/Float128Math/complex-math.c
+++ b/flang-rt/lib/FortranFloat128Math/complex-math.c
@@ -1,11 +1,10 @@
-/*===-- runtime/Float128Math/complex-math.c -------------------------*- C -*-===
+/*===-- lib/FortranFloat128Math/complex-math.c ----------------------*- 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 "complex-math.h"
 
diff --git a/flang/runtime/Float128Math/complex-math.h b/flang-rt/lib/FortranFloat128Math/complex-math.h
similarity index 88%
rename from flang/runtime/Float128Math/complex-math.h
rename to flang-rt/lib/FortranFloat128Math/complex-math.h
index cf5e980a39b6b..24ccc794fd144 100644
--- a/flang/runtime/Float128Math/complex-math.h
+++ b/flang-rt/lib/FortranFloat128Math/complex-math.h
@@ -1,4 +1,4 @@
-/*===-- runtime/Float128Math/complex-math.h -------------------------*- C -*-===
+/*===-- lib/FortranFloat128Math/complex-math.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_RUNTIME_FLOAT128MATH_COMPLEX_MATH_H_
-#define FORTRAN_RUNTIME_FLOAT128MATH_COMPLEX_MATH_H_
+#ifndef FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_
+#define FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_
 
 #include "flang/Common/float128.h"
 #include "flang/Runtime/entry-names.h"
@@ -59,4 +59,4 @@
 #error "Float128Math build with glibc>=2.26 is unsupported yet"
 #endif
 
-#endif /* FORTRAN_RUNTIME_FLOAT128MATH_COMPLEX_MATH_H_ */
+#endif /* FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_ */
diff --git a/flang/runtime/Float128Math/cos.cpp b/flang-rt/lib/FortranFloat128Math/cos.cpp
similarity index 87%
rename from flang/runtime/Float128Math/cos.cpp
rename to flang-rt/lib/FortranFloat128Math/cos.cpp
index d1b3e0e736ca3..aed337c325836 100644
--- a/flang/runtime/Float128Math/cos.cpp
+++ b/flang-rt/lib/FortranFloat128Math/cos.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/cos.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/cos.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/Float128Math/cosh.cpp b/flang-rt/lib/FortranFloat128Math/cosh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/cosh.cpp
rename to flang-rt/lib/FortranFloat128Math/cosh.cpp
index 9fe5b61d8f95f..bddbff766b575 100644
--- a/flang/runtime/Float128Math/cosh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/cosh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/cosh.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/cosh.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/Float128Math/erf.cpp b/flang-rt/lib/FortranFloat128Math/erf.cpp
similarity index 87%
rename from flang/runtime/Float128Math/erf.cpp
rename to flang-rt/lib/FortranFloat128Math/erf.cpp
index 2a553bd395e88..a56430040248d 100644
--- a/flang/runtime/Float128Math/erf.cpp
+++ b/flang-rt/lib/FortranFloat128Math/erf.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/erf.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/erf.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/Float128Math/erfc.cpp b/flang-rt/lib/FortranFloat128Math/erfc.cpp
similarity index 87%
rename from flang/runtime/Float128Math/erfc.cpp
rename to flang-rt/lib/FortranFloat128Math/erfc.cpp
index 2435ed2786cb3..255a2a7b4edac 100644
--- a/flang/runtime/Float128Math/erfc.cpp
+++ b/flang-rt/lib/FortranFloat128Math/erfc.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/erfc.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/erfc.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/Float128Math/exp.cpp b/flang-rt/lib/FortranFloat128Math/exp.cpp
similarity index 87%
rename from flang/runtime/Float128Math/exp.cpp
rename to flang-rt/lib/FortranFloat128Math/exp.cpp
index 5ca87d9dd25d2..9bc87d959cf69 100644
--- a/flang/runtime/Float128Math/exp.cpp
+++ b/flang-rt/lib/FortranFloat128Math/exp.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/exp.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/exp.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/Float128Math/exponent.cpp b/flang-rt/lib/FortranFloat128Math/exponent.cpp
similarity index 90%
rename from flang/runtime/Float128Math/exponent.cpp
rename to flang-rt/lib/FortranFloat128Math/exponent.cpp
index 237cde34e8691..bf27a26a73427 100644
--- a/flang/runtime/Float128Math/exponent.cpp
+++ b/flang-rt/lib/FortranFloat128Math/exponent.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/exponent.cpp ---------------------------------===//
+//===-- lib/FortranFloat128Math/exponent.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/Float128Math/floor.cpp b/flang-rt/lib/FortranFloat128Math/floor.cpp
similarity index 87%
rename from flang/runtime/Float128Math/floor.cpp
rename to flang-rt/lib/FortranFloat128Math/floor.cpp
index 28f9c7b55dd51..abda5fadfd296 100644
--- a/flang/runtime/Float128Math/floor.cpp
+++ b/flang-rt/lib/FortranFloat128Math/floor.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/floor.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/floor.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/Float128Math/fma.cpp b/flang-rt/lib/FortranFloat128Math/fma.cpp
similarity index 89%
rename from flang/runtime/Float128Math/fma.cpp
rename to flang-rt/lib/FortranFloat128Math/fma.cpp
index 87176c25dd604..2e7aabedf1e8c 100644
--- a/flang/runtime/Float128Math/fma.cpp
+++ b/flang-rt/lib/FortranFloat128Math/fma.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/fma.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/fma.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/Float128Math/fraction.cpp b/flang-rt/lib/FortranFloat128Math/fraction.cpp
similarity index 87%
rename from flang/runtime/Float128Math/fraction.cpp
rename to flang-rt/lib/FortranFloat128Math/fraction.cpp
index 45ec12cd77518..bf1da6f63e5ce 100644
--- a/flang/runtime/Float128Math/fraction.cpp
+++ b/flang-rt/lib/FortranFloat128Math/fraction.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/fraction.cpp ---------------------------------===//
+//===-- lib/FortranFloat128Math/fraction.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/Float128Math/hypot.cpp b/flang-rt/lib/FortranFloat128Math/hypot.cpp
similarity index 88%
rename from flang/runtime/Float128Math/hypot.cpp
rename to flang-rt/lib/FortranFloat128Math/hypot.cpp
index 03049b06d3a24..910bda798c1a0 100644
--- a/flang/runtime/Float128Math/hypot.cpp
+++ b/flang-rt/lib/FortranFloat128Math/hypot.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/hypot.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/hypot.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/Float128Math/j0.cpp b/flang-rt/lib/FortranFloat128Math/j0.cpp
similarity index 87%
rename from flang/runtime/Float128Math/j0.cpp
rename to flang-rt/lib/FortranFloat128Math/j0.cpp
index 7207cbe1a92e7..d2fac98c3ec69 100644
--- a/flang/runtime/Float128Math/j0.cpp
+++ b/flang-rt/lib/FortranFloat128Math/j0.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/j0.cpp ---------------------------------------===//
+//===-- lib/FortranFloat128Math/j0.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/Float128Math/j1.cpp b/flang-rt/lib/FortranFloat128Math/j1.cpp
similarity index 87%
rename from flang/runtime/Float128Math/j1.cpp
rename to flang-rt/lib/FortranFloat128Math/j1.cpp
index 9e49bcbc32ca4..60401030124c8 100644
--- a/flang/runtime/Float128Math/j1.cpp
+++ b/flang-rt/lib/FortranFloat128Math/j1.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/j1.cpp ---------------------------------------===//
+//===-- lib/FortranFloat128Math/j1.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/Float128Math/jn.cpp b/flang-rt/lib/FortranFloat128Math/jn.cpp
similarity index 87%
rename from flang/runtime/Float128Math/jn.cpp
rename to flang-rt/lib/FortranFloat128Math/jn.cpp
index 37e5f428e5e26..71e11335d0830 100644
--- a/flang/runtime/Float128Math/jn.cpp
+++ b/flang-rt/lib/FortranFloat128Math/jn.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/jn.cpp ---------------------------------------===//
+//===-- lib/FortranFloat128Math/jn.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/Float128Math/lgamma.cpp b/flang-rt/lib/FortranFloat128Math/lgamma.cpp
similarity index 87%
rename from flang/runtime/Float128Math/lgamma.cpp
rename to flang-rt/lib/FortranFloat128Math/lgamma.cpp
index 54d0dd8083868..1ae4cc4d95d61 100644
--- a/flang/runtime/Float128Math/lgamma.cpp
+++ b/flang-rt/lib/FortranFloat128Math/lgamma.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/lgamma.cpp -----------------------------------===//
+//===-- lib/FortranFloat128Math/lgamma.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/Float128Math/llround.cpp b/flang-rt/lib/FortranFloat128Math/llround.cpp
similarity index 87%
rename from flang/runtime/Float128Math/llround.cpp
rename to flang-rt/lib/FortranFloat128Math/llround.cpp
index f0c53ccdf66fd..5bd4cc26dd497 100644
--- a/flang/runtime/Float128Math/llround.cpp
+++ b/flang-rt/lib/FortranFloat128Math/llround.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/llround.cpp ----------------------------------===//
+//===-- lib/FortranFloat128Math/llround.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/Float128Math/log.cpp b/flang-rt/lib/FortranFloat128Math/log.cpp
similarity index 87%
rename from flang/runtime/Float128Math/log.cpp
rename to flang-rt/lib/FortranFloat128Math/log.cpp
index 28fec1958f10b..414e41ae0ce29 100644
--- a/flang/runtime/Float128Math/log.cpp
+++ b/flang-rt/lib/FortranFloat128Math/log.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/log.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/log.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/Float128Math/log10.cpp b/flang-rt/lib/FortranFloat128Math/log10.cpp
similarity index 87%
rename from flang/runtime/Float128Math/log10.cpp
rename to flang-rt/lib/FortranFloat128Math/log10.cpp
index f844d508f8d3b..55db1b1a2dc1f 100644
--- a/flang/runtime/Float128Math/log10.cpp
+++ b/flang-rt/lib/FortranFloat128Math/log10.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/log10.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/log10.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/Float128Math/lround.cpp b/flang-rt/lib/FortranFloat128Math/lround.cpp
similarity index 87%
rename from flang/runtime/Float128Math/lround.cpp
rename to flang-rt/lib/FortranFloat128Math/lround.cpp
index 8c2d3315c62a7..a0bea49243681 100644
--- a/flang/runtime/Float128Math/lround.cpp
+++ b/flang-rt/lib/FortranFloat128Math/lround.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/lround.cpp -----------------------------------===//
+//===-- lib/FortranFloat128Math/lround.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/Float128Math/math-entries.h b/flang-rt/lib/FortranFloat128Math/math-entries.h
similarity index 96%
rename from flang/runtime/Float128Math/math-entries.h
rename to flang-rt/lib/FortranFloat128Math/math-entries.h
index a94503fe8e67a..b9821163d94fb 100644
--- a/flang/runtime/Float128Math/math-entries.h
+++ b/flang-rt/lib/FortranFloat128Math/math-entries.h
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/math-entries.h ---------------------*- C++ -*-===//
+//===-- lib/FortranFloat128Math/math-entries.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,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
-#define FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
-#include "terminator.h"
-#include "tools.h"
+#ifndef FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_
+#define FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_
+
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/entry-names.h"
 #include <cfloat>
@@ -231,4 +232,4 @@ DEFINE_SIMPLE_ALIAS(Yn, ynl)
 
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
+#endif /* FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_ */
diff --git a/flang/runtime/Float128Math/mod-real.cpp b/flang-rt/lib/FortranFloat128Math/mod-real.cpp
similarity index 88%
rename from flang/runtime/Float128Math/mod-real.cpp
rename to flang-rt/lib/FortranFloat128Math/mod-real.cpp
index e831c2df4abc1..beb412f719c52 100644
--- a/flang/runtime/Float128Math/mod-real.cpp
+++ b/flang-rt/lib/FortranFloat128Math/mod-real.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/mod-real.cpp ---------------------------------===//
+//===-- lib/FortranFloat128Math/mod-real.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/Float128Math/modulo-real.cpp b/flang-rt/lib/FortranFloat128Math/modulo-real.cpp
similarity index 89%
rename from flang/runtime/Float128Math/modulo-real.cpp
rename to flang-rt/lib/FortranFloat128Math/modulo-real.cpp
index 88729da7e3987..c8160b1d27451 100644
--- a/flang/runtime/Float128Math/modulo-real.cpp
+++ b/flang-rt/lib/FortranFloat128Math/modulo-real.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/modulo-real.cpp ------------------------------===//
+//===-- lib/FortranFloat128Math/modulo-real.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/Float128Math/nearbyint.cpp b/flang-rt/lib/FortranFloat128Math/nearbyint.cpp
similarity index 87%
rename from flang/runtime/Float128Math/nearbyint.cpp
rename to flang-rt/lib/FortranFloat128Math/nearbyint.cpp
index 9eecb0c5f3e2f..d572641e2b0d4 100644
--- a/flang/runtime/Float128Math/nearbyint.cpp
+++ b/flang-rt/lib/FortranFloat128Math/nearbyint.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/nearbyint.cpp --------------------------------===//
+//===-- lib/FortranFloat128Math/nearbyint.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/Float128Math/nearest.cpp b/flang-rt/lib/FortranFloat128Math/nearest.cpp
similarity index 88%
rename from flang/runtime/Float128Math/nearest.cpp
rename to flang-rt/lib/FortranFloat128Math/nearest.cpp
index 50f6e7ea75a60..3e32de7ea9d0a 100644
--- a/flang/runtime/Float128Math/nearest.cpp
+++ b/flang-rt/lib/FortranFloat128Math/nearest.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/nearest.cpp ----------------------------------===//
+//===-- lib/FortranFloat128Math/nearest.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/Float128Math/norm2.cpp b/flang-rt/lib/FortranFloat128Math/norm2.cpp
similarity index 90%
rename from flang/runtime/Float128Math/norm2.cpp
rename to flang-rt/lib/FortranFloat128Math/norm2.cpp
index 18e9c8cc8a2b9..8f6b2c87eec32 100644
--- a/flang/runtime/Float128Math/norm2.cpp
+++ b/flang-rt/lib/FortranFloat128Math/norm2.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/norm2.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/norm2.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.
@@ -8,7 +8,7 @@
 
 #include "math-entries.h"
 #include "numeric-template-specs.h"
-#include "reduction-templates.h"
+#include "flang-rt/reduction-templates.h"
 
 namespace Fortran::runtime {
 extern "C" {
diff --git a/flang/runtime/Float128Math/numeric-template-specs.h b/flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
similarity index 82%
rename from flang/runtime/Float128Math/numeric-template-specs.h
rename to flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
index a0a77230c3e9e..fc912f75075a7 100644
--- a/flang/runtime/Float128Math/numeric-template-specs.h
+++ b/flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/numeric-template-specs.h -----------*- C++ -*-===//
+//===-- lib/FortranFloat128Math/numeric-template-specs.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_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
-#define FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
+#ifndef FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
+#define FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
 
 #include "math-entries.h"
-#include "numeric-templates.h"
+#include "flang-rt/numeric-templates.h"
 
 namespace Fortran::runtime {
 using F128Type = CppTypeFor<TypeCategory::Real, 16>;
@@ -52,4 +52,4 @@ template <> struct SQRTTy<F128Type> {
 };
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
+#endif /* FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_ */
diff --git a/flang/runtime/Float128Math/pow.cpp b/flang-rt/lib/FortranFloat128Math/pow.cpp
similarity index 88%
rename from flang/runtime/Float128Math/pow.cpp
rename to flang-rt/lib/FortranFloat128Math/pow.cpp
index 99aae04c65ecb..bbdda217c5108 100644
--- a/flang/runtime/Float128Math/pow.cpp
+++ b/flang-rt/lib/FortranFloat128Math/pow.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/pow.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/pow.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/Float128Math/random.cpp b/flang-rt/lib/FortranFloat128Math/random.cpp
similarity index 84%
rename from flang/runtime/Float128Math/random.cpp
rename to flang-rt/lib/FortranFloat128Math/random.cpp
index 93c5c14cee37d..701f9429fcb6c 100644
--- a/flang/runtime/Float128Math/random.cpp
+++ b/flang-rt/lib/FortranFloat128Math/random.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/random.cpp -----------------------------------===//
+//===-- lib/FortranFloat128Math/random.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.
@@ -8,7 +8,7 @@
 
 #include "math-entries.h"
 #include "numeric-template-specs.h"
-#include "random-templates.h"
+#include "flang-rt/random-templates.h"
 
 using namespace Fortran::runtime::random;
 extern "C" {
diff --git a/flang/runtime/Float128Math/remainder.cpp b/flang-rt/lib/FortranFloat128Math/remainder.cpp
similarity index 88%
rename from flang/runtime/Float128Math/remainder.cpp
rename to flang-rt/lib/FortranFloat128Math/remainder.cpp
index e5c2793dab71a..ca4165a357eda 100644
--- a/flang/runtime/Float128Math/remainder.cpp
+++ b/flang-rt/lib/FortranFloat128Math/remainder.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/remainder.cpp --------------------------------===//
+//===-- lib/FortranFloat128Math/remainder.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/Float128Math/round.cpp b/flang-rt/lib/FortranFloat128Math/round.cpp
similarity index 89%
rename from flang/runtime/Float128Math/round.cpp
rename to flang-rt/lib/FortranFloat128Math/round.cpp
index e79ce30536b3b..348f7ff8a6771 100644
--- a/flang/runtime/Float128Math/round.cpp
+++ b/flang-rt/lib/FortranFloat128Math/round.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/round.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/round.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/Float128Math/rrspacing.cpp b/flang-rt/lib/FortranFloat128Math/rrspacing.cpp
similarity index 87%
rename from flang/runtime/Float128Math/rrspacing.cpp
rename to flang-rt/lib/FortranFloat128Math/rrspacing.cpp
index 04cefc049bbee..0a87a5c572652 100644
--- a/flang/runtime/Float128Math/rrspacing.cpp
+++ b/flang-rt/lib/FortranFloat128Math/rrspacing.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/rrspacing.cpp --------------------------------===//
+//===-- lib/FortranFloat128Math/rrspacing.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/Float128Math/scale.cpp b/flang-rt/lib/FortranFloat128Math/scale.cpp
similarity index 90%
rename from flang/runtime/Float128Math/scale.cpp
rename to flang-rt/lib/FortranFloat128Math/scale.cpp
index 6b083afbdf4d1..a316a2a0cd706 100644
--- a/flang/runtime/Float128Math/scale.cpp
+++ b/flang-rt/lib/FortranFloat128Math/scale.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/scale.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/scale.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/Float128Math/set-exponent.cpp b/flang-rt/lib/FortranFloat128Math/set-exponent.cpp
similarity index 88%
rename from flang/runtime/Float128Math/set-exponent.cpp
rename to flang-rt/lib/FortranFloat128Math/set-exponent.cpp
index 63c5b325085fb..335c68f632f18 100644
--- a/flang/runtime/Float128Math/set-exponent.cpp
+++ b/flang-rt/lib/FortranFloat128Math/set-exponent.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/set-exponent.cpp -----------------------------===//
+//===-- lib/FortranFloat128Math/set-exponent.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/Float128Math/sin.cpp b/flang-rt/lib/FortranFloat128Math/sin.cpp
similarity index 87%
rename from flang/runtime/Float128Math/sin.cpp
rename to flang-rt/lib/FortranFloat128Math/sin.cpp
index 99fa3e493e694..bd5f62808fc31 100644
--- a/flang/runtime/Float128Math/sin.cpp
+++ b/flang-rt/lib/FortranFloat128Math/sin.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/sin.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/sin.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/Float128Math/sinh.cpp b/flang-rt/lib/FortranFloat128Math/sinh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/sinh.cpp
rename to flang-rt/lib/FortranFloat128Math/sinh.cpp
index b6cd96963612e..07f12d437ed56 100644
--- a/flang/runtime/Float128Math/sinh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/sinh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/sinh.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/sinh.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/Float128Math/spacing.cpp b/flang-rt/lib/FortranFloat128Math/spacing.cpp
similarity index 87%
rename from flang/runtime/Float128Math/spacing.cpp
rename to flang-rt/lib/FortranFloat128Math/spacing.cpp
index fc6aa2c4ec2d8..b10351ab95555 100644
--- a/flang/runtime/Float128Math/spacing.cpp
+++ b/flang-rt/lib/FortranFloat128Math/spacing.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/spacing.cpp ----------------------------------===//
+//===-- lib/FortranFloat128Math/spacing.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/Float128Math/sqrt.cpp b/flang-rt/lib/FortranFloat128Math/sqrt.cpp
similarity index 87%
rename from flang/runtime/Float128Math/sqrt.cpp
rename to flang-rt/lib/FortranFloat128Math/sqrt.cpp
index 871c66e007984..b6fd6eabc267b 100644
--- a/flang/runtime/Float128Math/sqrt.cpp
+++ b/flang-rt/lib/FortranFloat128Math/sqrt.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/sqrt.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/sqrt.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/Float128Math/tan.cpp b/flang-rt/lib/FortranFloat128Math/tan.cpp
similarity index 87%
rename from flang/runtime/Float128Math/tan.cpp
rename to flang-rt/lib/FortranFloat128Math/tan.cpp
index 2d6f448ba8955..437c0692191e8 100644
--- a/flang/runtime/Float128Math/tan.cpp
+++ b/flang-rt/lib/FortranFloat128Math/tan.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/tan.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/tan.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/Float128Math/tanh.cpp b/flang-rt/lib/FortranFloat128Math/tanh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/tanh.cpp
rename to flang-rt/lib/FortranFloat128Math/tanh.cpp
index f6321f4819191..48544d4bb75f4 100644
--- a/flang/runtime/Float128Math/tanh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/tanh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/tanh.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/tanh.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/Float128Math/tgamma.cpp b/flang-rt/lib/FortranFloat128Math/tgamma.cpp
similarity index 87%
rename from flang/runtime/Float128Math/tgamma.cpp
rename to flang-rt/lib/FortranFloat128Math/tgamma.cpp
index 98fd792a63330..8d7963caa61c5 100644
--- a/flang/runtime/Float128Math/tgamma.cpp
+++ b/flang-rt/lib/FortranFloat128Math/tgamma.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/tgamma.cpp -----------------------------------===//
+//===-- lib/FortranFloat128Math/tgamma.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/Float128Math/trunc.cpp b/flang-rt/lib/FortranFloat128Math/trunc.cpp
similarity index 89%
rename from flang/runtime/Float128Math/trunc.cpp
rename to flang-rt/lib/FortranFloat128Math/trunc.cpp
index 54fa33176813c..4a3dddeb1326c 100644
--- a/flang/runtime/Float128Math/trunc.cpp
+++ b/flang-rt/lib/FortranFloat128Math/trunc.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/trunc.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/trunc.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/Float128Math/y0.cpp b/flang-rt/lib/FortranFloat128Math/y0.cpp
similarity index 87%
rename from flang/runtime/Float128Math/y0.cpp
rename to flang-rt/lib/FortranFloat128Math/y0.cpp
index 0b3059b4cfe25..c5b266b5cec03 100644
--- a/flang/runtime/Float128Math/y0.cpp
+++ b/flang-rt/lib/FortranFloat128Math/y0.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/y0.cpp ---------------------------------------===//
+//===-- lib/FortranFloat128Math/y0.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/Float128Math/y1.cpp b/flang-rt/lib/FortranFloat128Math/y1.cpp
similarity index 87%
rename from flang/runtime/Float128Math/y1.cpp
rename to flang-rt/lib/FortranFloat128Math/y1.cpp
index cb39d87034dc7..8b492c69e3741 100644
--- a/flang/runtime/Float128Math/y1.cpp
+++ b/flang-rt/lib/FortranFloat128Math/y1.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/y1.cpp ---------------------------------------===//
+//===-- lib/FortranFloat128Math/y1.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/Float128Math/yn.cpp b/flang-rt/lib/FortranFloat128Math/yn.cpp
similarity index 87%
rename from flang/runtime/Float128Math/yn.cpp
rename to flang-rt/lib/FortranFloat128Math/yn.cpp
index bef8f9457df2f..cb212b400f6e0 100644
--- a/flang/runtime/Float128Math/yn.cpp
+++ b/flang-rt/lib/FortranFloat128Math/yn.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/yn.cpp ---------------------------------------===//
+//===-- lib/FortranFloat128Math/yn.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/allocatable.cpp b/flang-rt/lib/flang_rt/CUDA/allocatable.cpp
similarity index 94%
rename from flang/runtime/CUDA/allocatable.cpp
rename to flang-rt/lib/flang_rt/CUDA/allocatable.cpp
index 9be54e8906903..2281e2148d4ae 100644
--- a/flang/runtime/CUDA/allocatable.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/allocatable.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/allocatable.cpp --------------------------------------===//
+//===-- lib/flang_rt/CUDA/allocatable.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.
@@ -7,9 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/allocatable.h"
-#include "../assign-impl.h"
-#include "../stat.h"
-#include "../terminator.h"
+#include "flang-rt/assign-impl.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/CUDA/memmove-function.h"
diff --git a/flang/runtime/CUDA/allocator.cpp b/flang-rt/lib/flang_rt/CUDA/allocator.cpp
similarity index 86%
rename from flang/runtime/CUDA/allocator.cpp
rename to flang-rt/lib/flang_rt/CUDA/allocator.cpp
index 368c1124ef70a..dc1ce5920e222 100644
--- a/flang/runtime/CUDA/allocator.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/allocator.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/allocator.cpp ----------------------------------------===//
+//===-- lib/flang_rt/CUDA/allocator.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,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/CUDA/allocator.h"
-#include "../derived.h"
-#include "../stat.h"
-#include "../terminator.h"
-#include "../type-info.h"
+#include "flang-rt/CUDA/allocator.h"
+#include "flang-rt/allocator-registry.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/type-info.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/CUDA/descriptor.cpp b/flang-rt/lib/flang_rt/CUDA/descriptor.cpp
similarity index 90%
rename from flang/runtime/CUDA/descriptor.cpp
rename to flang-rt/lib/flang_rt/CUDA/descriptor.cpp
index 947eeb66aa3d6..9ec79ccea22c3 100644
--- a/flang/runtime/CUDA/descriptor.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/descriptor.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/descriptor.cpp ---------------------------------------===//
+//===-- lib/flang_rt/CUDA/descriptor.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.
@@ -7,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/descriptor.h"
-#include "../terminator.h"
-#include "flang/Runtime/CUDA/allocator.h"
+#include "flang-rt/CUDA/allocator.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
-#include "flang/Runtime/descriptor.h"
 
 #include "cuda_runtime.h"
 
diff --git a/flang/runtime/CUDA/kernel.cpp b/flang-rt/lib/flang_rt/CUDA/kernel.cpp
similarity index 97%
rename from flang/runtime/CUDA/kernel.cpp
rename to flang-rt/lib/flang_rt/CUDA/kernel.cpp
index bdc04ccb17672..fce6e24ae0f12 100644
--- a/flang/runtime/CUDA/kernel.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/kernel.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/kernel.cpp -------------------------------------------===//
+//===-- lib/flang_rt/CUDA/kernel.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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/kernel.h"
-#include "../terminator.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 
 #include "cuda_runtime.h"
diff --git a/flang/runtime/CUDA/memmove-function.cpp b/flang-rt/lib/flang_rt/CUDA/memmove-function.cpp
similarity index 91%
rename from flang/runtime/CUDA/memmove-function.cpp
rename to flang-rt/lib/flang_rt/CUDA/memmove-function.cpp
index 3ba9fa7e0f7f7..ca04e20379d03 100644
--- a/flang/runtime/CUDA/memmove-function.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/memmove-function.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/memmove-function.cpp ---------------------------------===//
+//===-- lib/flang_rt/CUDA/memmove-function.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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/memmove-function.h"
-#include "../terminator.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 
 #include "cuda_runtime.h"
diff --git a/flang/runtime/CUDA/memory.cpp b/flang-rt/lib/flang_rt/CUDA/memory.cpp
similarity index 97%
rename from flang/runtime/CUDA/memory.cpp
rename to flang-rt/lib/flang_rt/CUDA/memory.cpp
index 0bbb493d2db91..3d4a74f5f9e52 100644
--- a/flang/runtime/CUDA/memory.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/memory.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/memory.cpp -------------------------------------------===//
+//===-- lib/flang_rt/CUDA/memory.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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/memory.h"
-#include "../assign-impl.h"
-#include "../terminator.h"
+#include "flang-rt/assign-impl.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/CUDA/memmove-function.h"
diff --git a/flang/runtime/CUDA/registration.cpp b/flang-rt/lib/flang_rt/CUDA/registration.cpp
similarity index 93%
rename from flang/runtime/CUDA/registration.cpp
rename to flang-rt/lib/flang_rt/CUDA/registration.cpp
index b7b6ef389bffb..f8a7b197bed3b 100644
--- a/flang/runtime/CUDA/registration.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/registration.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/registration.cpp -------------------------------------===//
+//===-- lib/flang_rt/CUDA/registration.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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/registration.h"
-#include "../terminator.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 
 #include "cuda_runtime.h"
diff --git a/flang/runtime/ISO_Fortran_binding.cpp b/flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
similarity index 98%
rename from flang/runtime/ISO_Fortran_binding.cpp
rename to flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
index 64e239f498230..d9b0bfe9aeb6b 100644
--- a/flang/runtime/ISO_Fortran_binding.cpp
+++ b/flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/ISO_Fortran_binding.cpp -----------------------------------===//
+//===-- lib/flang_rt/ISO_Fortran_binding.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,11 +10,11 @@
 // as specified in section 18.5.5 of Fortran 2018.
 
 #include "ISO_Fortran_util.h"
-#include "terminator.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/type-code.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"
 #include <cstdlib>
 
 namespace Fortran::ISO {
diff --git a/flang/runtime/ISO_Fortran_util.h b/flang-rt/lib/flang_rt/ISO_Fortran_util.h
similarity index 91%
rename from flang/runtime/ISO_Fortran_util.h
rename to flang-rt/lib/flang_rt/ISO_Fortran_util.h
index aca9aee8c5718..6128faba5bcea 100644
--- a/flang/runtime/ISO_Fortran_util.h
+++ b/flang-rt/lib/flang_rt/ISO_Fortran_util.h
@@ -1,4 +1,4 @@
-//===-- runtime/ISO_Fortran_util.h ------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/ISO_Fortran_util.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_RUNTIME_ISO_FORTRAN_UTIL_H_
-#define FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_
+#ifndef FLANG_RT_ISO_FORTRAN_UTIL_H_
+#define FLANG_RT_ISO_FORTRAN_UTIL_H_
 
 // Internal utils for establishing CFI_cdesc_t descriptors.
 
-#include "terminator.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/type-code.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
 #include <cstdlib>
 
 namespace Fortran::ISO {
@@ -99,4 +99,4 @@ static inline RT_API_ATTRS void EstablishDescriptor(CFI_cdesc_t *descriptor,
   }
 }
 } // namespace Fortran::ISO
-#endif // FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_
+#endif /* FLANG_RT_ISO_FORTRAN_UTIL_H_ */
diff --git a/flang/runtime/allocatable.cpp b/flang-rt/lib/flang_rt/allocatable.cpp
similarity index 96%
rename from flang/runtime/allocatable.cpp
rename to flang-rt/lib/flang_rt/allocatable.cpp
index 686114bf86eaf..63ef99b8a72d1 100644
--- a/flang/runtime/allocatable.cpp
+++ b/flang-rt/lib/flang_rt/allocatable.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/allocatable.cpp -------------------------------------------===//
+//===-- lib/flang_rt/allocatable.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.
@@ -7,14 +7,14 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/allocatable.h"
-#include "assign-impl.h"
-#include "derived.h"
-#include "stat.h"
-#include "terminator.h"
-#include "type-info.h"
+#include "flang-rt/assign-impl.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/type-info.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/assign.h"
-#include "flang/Runtime/descriptor.h"
 
 namespace Fortran::runtime {
 extern "C" {
diff --git a/flang/runtime/allocator-registry.cpp b/flang-rt/lib/flang_rt/allocator-registry.cpp
similarity index 88%
rename from flang/runtime/allocator-registry.cpp
rename to flang-rt/lib/flang_rt/allocator-registry.cpp
index f5670331d6dbe..11847de68724d 100644
--- a/flang/runtime/allocator-registry.cpp
+++ b/flang-rt/lib/flang_rt/allocator-registry.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/allocator-registry.cpp ------------------------------------===//
+//===-- lib/flang_rt/allocator-registry.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/Runtime/allocator-registry.h"
-#include "terminator.h"
+#include "flang-rt/allocator-registry.h"
+#include "flang-rt/terminator.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/array-constructor.cpp b/flang-rt/lib/flang_rt/array-constructor.cpp
similarity index 96%
rename from flang/runtime/array-constructor.cpp
rename to flang-rt/lib/flang_rt/array-constructor.cpp
index c6953167f5fb2..d2765c9439b75 100644
--- a/flang/runtime/array-constructor.cpp
+++ b/flang-rt/lib/flang_rt/array-constructor.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/array-constructor.cpp -------------------------------------===//
+//===-- lib/flang_rt/array-constructor.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,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/array-constructor.h"
-#include "derived.h"
-#include "terminator.h"
-#include "tools.h"
-#include "type-info.h"
+#include "flang-rt/array-constructor.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-info.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/assign.h"
-#include "flang/Runtime/descriptor.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/assign.cpp b/flang-rt/lib/flang_rt/assign.cpp
similarity index 98%
rename from flang/runtime/assign.cpp
rename to flang-rt/lib/flang_rt/assign.cpp
index 8f0efaa376c19..0d6045eac503a 100644
--- a/flang/runtime/assign.cpp
+++ b/flang-rt/lib/flang_rt/assign.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/assign.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/assign.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.
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/assign.h"
-#include "assign-impl.h"
-#include "derived.h"
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "type-info.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/assign-impl.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-info.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/buffer.cpp b/flang-rt/lib/flang_rt/buffer.cpp
similarity index 89%
rename from flang/runtime/buffer.cpp
rename to flang-rt/lib/flang_rt/buffer.cpp
index 7b4869d69c2e5..e084155068bc5 100644
--- a/flang/runtime/buffer.cpp
+++ b/flang-rt/lib/flang_rt/buffer.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/buffer.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/buffer.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 "buffer.h"
+#include "flang-rt/buffer.h"
 #include <algorithm>
 
 namespace Fortran::runtime::io {
diff --git a/flang/runtime/character.cpp b/flang-rt/lib/flang_rt/character.cpp
similarity index 99%
rename from flang/runtime/character.cpp
rename to flang-rt/lib/flang_rt/character.cpp
index 5049247397eb3..79d4ebdb0afbf 100644
--- a/flang/runtime/character.cpp
+++ b/flang-rt/lib/flang_rt/character.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/character.cpp ---------------------------------------------===//
+//===-- lib/flang_rt/character.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.
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/character.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/bit-population-count.h"
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/character.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include <algorithm>
 #include <cstring>
 
diff --git a/flang/runtime/command.cpp b/flang-rt/lib/flang_rt/command.cpp
similarity index 96%
rename from flang/runtime/command.cpp
rename to flang-rt/lib/flang_rt/command.cpp
index a555e26f96a66..498ae8db17224 100644
--- a/flang/runtime/command.cpp
+++ b/flang-rt/lib/flang_rt/command.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/command.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/command.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.
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/command.h"
-#include "environment.h"
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include <cstdlib>
 #include <limits>
 
diff --git a/flang/runtime/complex-powi.cpp b/flang-rt/lib/flang_rt/complex-powi.cpp
similarity index 92%
rename from flang/runtime/complex-powi.cpp
rename to flang-rt/lib/flang_rt/complex-powi.cpp
index 62f73e037b76f..287bafc422057 100644
--- a/flang/runtime/complex-powi.cpp
+++ b/flang-rt/lib/flang_rt/complex-powi.cpp
@@ -1,11 +1,11 @@
-/*===-- flang/runtime/complex-powi.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
- *
- * ===-----------------------------------------------------------------------===
- */
+//===-- lib/flang_rt/complex-powi.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/Common/float128.h"
 #include "flang/Runtime/cpp-type.h"
 #include "flang/Runtime/entry-names.h"
diff --git a/flang/runtime/complex-reduction.c b/flang-rt/lib/flang_rt/complex-reduction.c
similarity index 97%
rename from flang/runtime/complex-reduction.c
rename to flang-rt/lib/flang_rt/complex-reduction.c
index de1ff3d683084..967f26c05e702 100644
--- a/flang/runtime/complex-reduction.c
+++ b/flang-rt/lib/flang_rt/complex-reduction.c
@@ -1,11 +1,10 @@
-/*===-- flang/runtime/complex-reduction.c ---------------------------*- C -*-===
+/*===-- lib/flang_rt/complex-reduction.c ----------------------------*- 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 "complex-reduction.h"
 #include <float.h>
diff --git a/flang/runtime/complex-reduction.h b/flang-rt/lib/flang_rt/complex-reduction.h
similarity index 96%
rename from flang/runtime/complex-reduction.h
rename to flang-rt/lib/flang_rt/complex-reduction.h
index 5ff2a828fb3ec..2678dbf4e6472 100644
--- a/flang/runtime/complex-reduction.h
+++ b/flang-rt/lib/flang_rt/complex-reduction.h
@@ -1,19 +1,18 @@
-/*===-- flang/runtime/complex-reduction.h ---------------------------*- C -*-===
+/*===-- lib/flang_rt/complex-reduction.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
  *
- * ===-----------------------------------------------------------------------===
- */
+ *===----------------------------------------------------------------------===*/
 
 /* Wraps the C++-coded complex-valued SUM and PRODUCT reductions with
  * C-coded wrapper functions returning _Complex values, to avoid problems
  * with C++ build compilers that don't support C's _Complex.
  */
 
-#ifndef FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
-#define FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
+#ifndef FLANG_RT_COMPLEX_REDUCTION_H_
+#define FLANG_RT_COMPLEX_REDUCTION_H_
 
 #include "flang/Common/float128.h"
 #include "flang/Runtime/entry-names.h"
@@ -156,4 +155,4 @@ void RTNAME(ReduceComplex16DimValue)(
     REDUCE_DIM_ARGS(CFloat128ComplexType, CFloat128ComplexType_value_op));
 #endif
 
-#endif // FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
+#endif /* FLANG_RT_COMPLEX_REDUCTION_H_ */
diff --git a/flang/runtime/connection.cpp b/flang-rt/lib/flang_rt/connection.cpp
similarity index 91%
rename from flang/runtime/connection.cpp
rename to flang-rt/lib/flang_rt/connection.cpp
index f24f0e832eb48..1c454b81389ac 100644
--- a/flang/runtime/connection.cpp
+++ b/flang-rt/lib/flang_rt/connection.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/connection.cpp --------------------------------------------===//
+//===-- lib/flang_rt/connection.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 "connection.h"
-#include "environment.h"
-#include "io-stmt.h"
+#include "flang-rt/connection.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/io-stmt.h"
 #include <algorithm>
 
 namespace Fortran::runtime::io {
diff --git a/flang/runtime/copy.cpp b/flang-rt/lib/flang_rt/copy.cpp
similarity index 98%
rename from flang/runtime/copy.cpp
rename to flang-rt/lib/flang_rt/copy.cpp
index b20f68f019498..0ad6946d3161a 100644
--- a/flang/runtime/copy.cpp
+++ b/flang-rt/lib/flang_rt/copy.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/copy.cpp -------------------------------------------------===//
+//===-- lib/flang_rt/copy.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.
@@ -8,10 +8,10 @@
 
 #include "copy.h"
 #include "stack.h"
-#include "terminator.h"
-#include "type-info.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/type-info.h"
 #include "flang/Runtime/allocatable.h"
-#include "flang/Runtime/descriptor.h"
 #include <cstring>
 
 namespace Fortran::runtime {
diff --git a/flang/runtime/copy.h b/flang-rt/lib/flang_rt/copy.h
similarity index 79%
rename from flang/runtime/copy.h
rename to flang-rt/lib/flang_rt/copy.h
index 542660530bfb6..468c2439baf61 100644
--- a/flang/runtime/copy.h
+++ b/flang-rt/lib/flang_rt/copy.h
@@ -1,4 +1,4 @@
-//===-- runtime/copy.h ------------------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/copy.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.
@@ -9,10 +9,10 @@
 // Utilities that copy data in a type-aware fashion, allocating & duplicating
 // allocatable/automatic components of derived types along the way.
 
-#ifndef FORTRAN_RUNTIME_COPY_H_
-#define FORTRAN_RUNTIME_COPY_H_
+#ifndef FLANG_RT_COPY_H_
+#define FLANG_RT_COPY_H_
 
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 
 namespace Fortran::runtime {
 
@@ -22,4 +22,4 @@ RT_API_ATTRS void CopyElement(const Descriptor &to, const SubscriptValue toAt[],
     const Descriptor &from, const SubscriptValue fromAt[], Terminator &);
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_COPY_H_
+#endif /* FLANG_RT_COPY_H_ */
diff --git a/flang/runtime/derived-api.cpp b/flang-rt/lib/flang_rt/derived-api.cpp
similarity index 96%
rename from flang/runtime/derived-api.cpp
rename to flang-rt/lib/flang_rt/derived-api.cpp
index c8ffd8e3bb67c..353bc4a83ebd9 100644
--- a/flang/runtime/derived-api.cpp
+++ b/flang-rt/lib/flang_rt/derived-api.cpp
@@ -1,5 +1,4 @@
-//===-- runtime/derived-api.cpp
-//-----------------------------------------------===//
+//===-- lib/flang_rt/derived-api.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.
@@ -8,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/derived-api.h"
-#include "derived.h"
-#include "terminator.h"
-#include "tools.h"
-#include "type-info.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-info.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/derived.cpp b/flang-rt/lib/flang_rt/derived.cpp
similarity index 98%
rename from flang/runtime/derived.cpp
rename to flang-rt/lib/flang_rt/derived.cpp
index 10813c62e5da1..cace9e1074e65 100644
--- a/flang/runtime/derived.cpp
+++ b/flang-rt/lib/flang_rt/derived.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/derived.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/derived.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,12 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "derived.h"
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "type-info.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-info.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/descriptor-io.cpp b/flang-rt/lib/flang_rt/descriptor-io.cpp
similarity index 98%
rename from flang/runtime/descriptor-io.cpp
rename to flang-rt/lib/flang_rt/descriptor-io.cpp
index 380ad425d925f..c5cfa4d7fc597 100644
--- a/flang/runtime/descriptor-io.cpp
+++ b/flang-rt/lib/flang_rt/descriptor-io.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/descriptor-io.cpp -----------------------------------------===//
+//===-- lib/flang_rt/descriptor-io.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/descriptor-io.h b/flang-rt/lib/flang_rt/descriptor-io.h
similarity index 98%
rename from flang/runtime/descriptor-io.h
rename to flang-rt/lib/flang_rt/descriptor-io.h
index 1034958bf654a..763ebb1735752 100644
--- a/flang/runtime/descriptor-io.h
+++ b/flang-rt/lib/flang_rt/descriptor-io.h
@@ -1,4 +1,4 @@
-//===-- runtime/descriptor-io.h ---------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/descriptor-io.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_RUNTIME_DESCRIPTOR_IO_H_
-#define FORTRAN_RUNTIME_DESCRIPTOR_IO_H_
+#ifndef FLANG_RT_DESCRIPTOR_IO_H_
+#define FLANG_RT_DESCRIPTOR_IO_H_
 
 // Implementation of I/O data list item transfers based on descriptors.
 // (All I/O items come through here so that the code is exercised for test;
@@ -16,15 +16,15 @@
 
 #include "edit-input.h"
 #include "edit-output.h"
-#include "io-stmt.h"
-#include "namelist.h"
-#include "terminator.h"
-#include "type-info.h"
 #include "unit.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-stmt.h"
+#include "flang-rt/namelist.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/type-info.h"
 #include "flang/Common/optional.h"
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 
 namespace Fortran::runtime::io::descr {
 template <typename A>
@@ -626,4 +626,4 @@ static RT_API_ATTRS bool DescriptorIO(IoStatementState &io,
   return false;
 }
 } // namespace Fortran::runtime::io::descr
-#endif // FORTRAN_RUNTIME_DESCRIPTOR_IO_H_
+#endif /* FLANG_RT_DESCRIPTOR_IO_H_ */
diff --git a/flang/runtime/descriptor.cpp b/flang-rt/lib/flang_rt/descriptor.cpp
similarity index 95%
rename from flang/runtime/descriptor.cpp
rename to flang-rt/lib/flang_rt/descriptor.cpp
index 32f43e89dc7a3..cdf01f12e7134 100644
--- a/flang/runtime/descriptor.cpp
+++ b/flang-rt/lib/flang_rt/descriptor.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/descriptor.cpp --------------------------------------------===//
+//===-- lib/flang_rt/descriptor.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,15 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "ISO_Fortran_util.h"
-#include "derived.h"
 #include "memory.h"
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "type-info.h"
-#include "flang/Runtime/allocator-registry.h"
+#include "flang-rt/allocator-registry.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-info.h"
 #include <cassert>
 #include <cstdlib>
 #include <cstring>
@@ -141,8 +141,10 @@ RT_API_ATTRS OwningPtr<Descriptor> Descriptor::Create(
 
 RT_API_ATTRS std::size_t Descriptor::SizeInBytes() const {
   const DescriptorAddendum *addendum{Addendum()};
-  return sizeof *this - sizeof(Dimension) + raw_.rank * sizeof(Dimension) +
-      (addendum ? addendum->SizeInBytes() : 0);
+  std::size_t bytes{ sizeof *this - sizeof(Dimension) + raw_.rank * sizeof(Dimension) +
+      (addendum ? addendum->SizeInBytes() : 0)};
+  assert (bytes <= MaxDescriptorSizeInBytes(raw_.rank,addendum) && "Descriptor must fit compiler-allocated space");
+  return bytes;
 }
 
 RT_API_ATTRS std::size_t Descriptor::Elements() const {
diff --git a/flang/runtime/dot-product.cpp b/flang-rt/lib/flang_rt/dot-product.cpp
similarity index 98%
rename from flang/runtime/dot-product.cpp
rename to flang-rt/lib/flang_rt/dot-product.cpp
index 712497a3a50ac..ad600a4228463 100644
--- a/flang/runtime/dot-product.cpp
+++ b/flang-rt/lib/flang_rt/dot-product.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/dot-product.cpp -------------------------------------------===//
+//===-- lib/flang_rt/dot-product.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.
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "float.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/reduction.h"
 #include <cfloat>
 #include <cinttypes>
diff --git a/flang/runtime/edit-input.cpp b/flang-rt/lib/flang_rt/edit-input.cpp
similarity index 99%
rename from flang/runtime/edit-input.cpp
rename to flang-rt/lib/flang_rt/edit-input.cpp
index 317f0b676bd21..7121f6e42dea6 100644
--- a/flang/runtime/edit-input.cpp
+++ b/flang-rt/lib/flang_rt/edit-input.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/edit-input.cpp --------------------------------------------===//
+//===-- lib/flang_rt/edit-input.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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "edit-input.h"
-#include "namelist.h"
-#include "utf.h"
+#include "flang-rt/namelist.h"
+#include "flang-rt/utf.h"
 #include "flang/Common/optional.h"
 #include "flang/Common/real.h"
 #include "flang/Common/uint128.h"
diff --git a/flang/runtime/edit-input.h b/flang-rt/lib/flang_rt/edit-input.h
similarity index 89%
rename from flang/runtime/edit-input.h
rename to flang-rt/lib/flang_rt/edit-input.h
index 55a7a45578171..2d6a3f241a005 100644
--- a/flang/runtime/edit-input.h
+++ b/flang-rt/lib/flang_rt/edit-input.h
@@ -1,4 +1,4 @@
-//===-- runtime/edit-input.h ------------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/edit-input.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_RUNTIME_EDIT_INPUT_H_
-#define FORTRAN_RUNTIME_EDIT_INPUT_H_
+#ifndef FLANG_RT_EDIT_INPUT_H_
+#define FLANG_RT_EDIT_INPUT_H_
 
-#include "format.h"
-#include "io-stmt.h"
+#include "flang-rt/format.h"
+#include "flang-rt/io-stmt.h"
 #include "flang/Decimal/decimal.h"
 
 namespace Fortran::runtime::io {
@@ -50,4 +50,4 @@ extern template RT_API_ATTRS bool EditCharacterInput(
     IoStatementState &, const DataEdit &, char32_t *, std::size_t);
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_EDIT_INPUT_H_
+#endif /* FLANG_RT_EDIT_INPUT_H_ */
diff --git a/flang/runtime/edit-output.cpp b/flang-rt/lib/flang_rt/edit-output.cpp
similarity index 99%
rename from flang/runtime/edit-output.cpp
rename to flang-rt/lib/flang_rt/edit-output.cpp
index 9db9a3d4a511b..096bd4567a42a 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang-rt/lib/flang_rt/edit-output.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/edit-output.cpp -------------------------------------------===//
+//===-- lib/flang_rt/edit-output.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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "edit-output.h"
-#include "emit-encoded.h"
-#include "utf.h"
+#include "flang-rt/emit-encoded.h"
+#include "flang-rt/utf.h"
 #include "flang/Common/real.h"
 #include "flang/Common/uint128.h"
 #include <algorithm>
diff --git a/flang/runtime/edit-output.h b/flang-rt/lib/flang_rt/edit-output.h
similarity index 96%
rename from flang/runtime/edit-output.h
rename to flang-rt/lib/flang_rt/edit-output.h
index 42cc993f98cc1..59f5d820c4ad5 100644
--- a/flang/runtime/edit-output.h
+++ b/flang-rt/lib/flang_rt/edit-output.h
@@ -1,4 +1,4 @@
-//===-- runtime/edit-output.h -----------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/edit-output.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_RUNTIME_EDIT_OUTPUT_H_
-#define FORTRAN_RUNTIME_EDIT_OUTPUT_H_
+#ifndef FLANG_RT_EDIT_OUTPUT_H_
+#define FLANG_RT_EDIT_OUTPUT_H_
 
 // Output data editing templates implementing the FORMAT data editing
 // descriptors E, EN, ES, EX, D, F, and G for REAL data (and COMPLEX
@@ -18,8 +18,8 @@
 // Drives the same fast binary-to-decimal formatting templates used
 // in the f18 front-end.
 
-#include "format.h"
-#include "io-stmt.h"
+#include "flang-rt/format.h"
+#include "flang-rt/io-stmt.h"
 #include "flang/Common/uint128.h"
 #include "flang/Decimal/decimal.h"
 
@@ -138,4 +138,4 @@ extern template class RealOutputEditing<10>;
 extern template class RealOutputEditing<16>;
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_EDIT_OUTPUT_H_
+#endif /* FLANG_RT_EDIT_OUTPUT_H_ */
diff --git a/flang/runtime/environment-default-list.h b/flang-rt/lib/flang_rt/environment-default-list.h
similarity index 70%
rename from flang/runtime/environment-default-list.h
rename to flang-rt/lib/flang_rt/environment-default-list.h
index 4da261b10b9a8..76c0955bcce6d 100644
--- a/flang/runtime/environment-default-list.h
+++ b/flang-rt/lib/flang_rt/environment-default-list.h
@@ -1,14 +1,13 @@
-/*===-- runtime/environment-default-list.h --------------------------*- C -*-===
+/*===-- lib/flang_rt/environment-default-list.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_RUNTIME_ENVIRONMENT_DEFAULT_LIST_H_
-#define FORTRAN_RUNTIME_ENVIRONMENT_DEFAULT_LIST_H_
+#ifndef FLANG_RT_ENVIRONMENT_DEFAULT_LIST_H_
+#define FLANG_RT_ENVIRONMENT_DEFAULT_LIST_H_
 
 /* Try to maintain C compatibility to make it easier to both define environment
  * defaults in non-Fortran main programs as well as pass through the environment
@@ -28,4 +27,4 @@ struct EnvironmentDefaultList {
   const struct EnvironmentDefaultItem *item;
 };
 
-#endif /* FORTRAN_RUNTIME_ENVIRONMENT_DEFAULT_LIST_H_ */
+#endif /* FLANG_RT_ENVIRONMENT_DEFAULT_LIST_H_ */
diff --git a/flang/runtime/environment.cpp b/flang-rt/lib/flang_rt/environment.cpp
similarity index 96%
rename from flang/runtime/environment.cpp
rename to flang-rt/lib/flang_rt/environment.cpp
index 52b1d99ba536e..b8d96b933f5b6 100644
--- a/flang/runtime/environment.cpp
+++ b/flang-rt/lib/flang_rt/environment.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/environment.cpp -------------------------------------------===//
+//===-- lib/flang_rt/environment.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,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "environment.h"
+#include "flang-rt/environment.h"
 #include "environment-default-list.h"
 #include "memory.h"
-#include "tools.h"
+#include "flang-rt/tools.h"
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
diff --git a/flang/runtime/exceptions.cpp b/flang-rt/lib/flang_rt/exceptions.cpp
similarity index 96%
rename from flang/runtime/exceptions.cpp
rename to flang-rt/lib/flang_rt/exceptions.cpp
index f541b8e844ade..c6ddc5d05ccf3 100644
--- a/flang/runtime/exceptions.cpp
+++ b/flang-rt/lib/flang_rt/exceptions.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/exceptions.cpp --------------------------------------===//
+//===-- lib/flang_rt/exceptions.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.
@@ -9,7 +9,7 @@
 // Runtime exception support.
 
 #include "flang/Runtime/exceptions.h"
-#include "terminator.h"
+#include "flang-rt/terminator.h"
 #include <cfenv>
 #if __x86_64__
 #include <xmmintrin.h>
diff --git a/flang/runtime/execute.cpp b/flang-rt/lib/flang_rt/execute.cpp
similarity index 97%
rename from flang/runtime/execute.cpp
rename to flang-rt/lib/flang_rt/execute.cpp
index c7f8f386d81f4..8d56581c12a49 100644
--- a/flang/runtime/execute.cpp
+++ b/flang-rt/lib/flang_rt/execute.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/execute.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/execute.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.
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/execute.h"
-#include "environment.h"
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include <cstdlib>
 #include <errno.h>
 #include <future>
diff --git a/flang/runtime/extensions.cpp b/flang-rt/lib/flang_rt/extensions.cpp
similarity index 97%
rename from flang/runtime/extensions.cpp
rename to flang-rt/lib/flang_rt/extensions.cpp
index 50d3c72fe650d..aee71164575a2 100644
--- a/flang/runtime/extensions.cpp
+++ b/flang-rt/lib/flang_rt/extensions.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/extensions.cpp --------------------------------------------===//
+//===-- lib/flang_rt/extensions.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,10 +10,10 @@
 // extensions that will eventually be implemented in Fortran.
 
 #include "flang/Runtime/extensions.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/command.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/entry-names.h"
 #include "flang/Runtime/io-api.h"
 #include <chrono>
diff --git a/flang/runtime/external-unit.cpp b/flang-rt/lib/flang_rt/external-unit.cpp
similarity index 98%
rename from flang/runtime/external-unit.cpp
rename to flang-rt/lib/flang_rt/external-unit.cpp
index d17a92622f844..4be90cbbcc4c8 100644
--- a/flang/runtime/external-unit.cpp
+++ b/flang-rt/lib/flang_rt/external-unit.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/external-unit.cpp -----------------------------------------===//
+//===-- lib/flang_rt/external-unit.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,11 +10,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "io-error.h"
-#include "lock.h"
-#include "tools.h"
 #include "unit-map.h"
 #include "unit.h"
+#include "flang-rt/io-error.h"
+#include "flang-rt/lock.h"
+#include "flang-rt/tools.h"
 
 // NOTE: the header files above may define OpenMP declare target
 // variables, so they have to be included unconditionally
diff --git a/flang/runtime/extrema.cpp b/flang-rt/lib/flang_rt/extrema.cpp
similarity index 99%
rename from flang/runtime/extrema.cpp
rename to flang-rt/lib/flang_rt/extrema.cpp
index 7ecdf4b91702e..8ecd7fbe91d77 100644
--- a/flang/runtime/extrema.cpp
+++ b/flang-rt/lib/flang_rt/extrema.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/extrema.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/extrema.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 @@
 // and shapes and (for MAXLOC & MINLOC) result integer kinds.  Also implements
 // NORM2 using common infrastructure.
 
-#include "reduction-templates.h"
+#include "flang-rt/reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/character.h"
 #include "flang/Runtime/reduction.h"
diff --git a/flang/runtime/file.cpp b/flang-rt/lib/flang_rt/file.cpp
similarity index 98%
rename from flang/runtime/file.cpp
rename to flang-rt/lib/flang_rt/file.cpp
index 9e077b8cea44b..c9fcf0f97b718 100644
--- a/flang/runtime/file.cpp
+++ b/flang-rt/lib/flang_rt/file.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/file.cpp --------------------------------------------------===//
+//===-- lib/flang_rt/file.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,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "file.h"
-#include "tools.h"
+#include "flang-rt/file.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/magic-numbers.h"
-#include "flang/Runtime/memory.h"
 #include <algorithm>
 #include <cerrno>
 #include <cstring>
diff --git a/flang/runtime/findloc.cpp b/flang-rt/lib/flang_rt/findloc.cpp
similarity index 99%
rename from flang/runtime/findloc.cpp
rename to flang-rt/lib/flang_rt/findloc.cpp
index b9b1d7f7ab689..ac432676f5efc 100644
--- a/flang/runtime/findloc.cpp
+++ b/flang-rt/lib/flang_rt/findloc.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/findloc.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/findloc.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.
@@ -9,7 +9,7 @@
 // Implements FINDLOC for all required operand types and shapes and result
 // integer kinds.
 
-#include "reduction-templates.h"
+#include "flang-rt/reduction-templates.h"
 #include "flang/Runtime/character.h"
 #include "flang/Runtime/reduction.h"
 #include <cinttypes>
diff --git a/flang/runtime/format.cpp b/flang-rt/lib/flang_rt/format.cpp
similarity index 88%
rename from flang/runtime/format.cpp
rename to flang-rt/lib/flang_rt/format.cpp
index 433acce4b7373..abd01b56919a4 100644
--- a/flang/runtime/format.cpp
+++ b/flang-rt/lib/flang_rt/format.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/format.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/format.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 "format-implementation.h"
+#include "flang-rt/format-implementation.h"
 
 namespace Fortran::runtime::io {
 RT_OFFLOAD_API_GROUP_BEGIN
diff --git a/flang/runtime/inquiry.cpp b/flang-rt/lib/flang_rt/inquiry.cpp
similarity index 94%
rename from flang/runtime/inquiry.cpp
rename to flang-rt/lib/flang_rt/inquiry.cpp
index 9fbcaa96fa3c4..e98d3900987dc 100644
--- a/flang/runtime/inquiry.cpp
+++ b/flang-rt/lib/flang_rt/inquiry.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/inquiry.cpp --------------------------------------===//
+//===-- lib/flang_rt/inquiry.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.
@@ -11,9 +11,9 @@
 
 #include "flang/Runtime/inquiry.h"
 #include "copy.h"
-#include "terminator.h"
-#include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include <algorithm>
 
 namespace Fortran::runtime {
diff --git a/flang/runtime/internal-unit.cpp b/flang-rt/lib/flang_rt/internal-unit.cpp
similarity index 97%
rename from flang/runtime/internal-unit.cpp
rename to flang-rt/lib/flang_rt/internal-unit.cpp
index f8f3877efb20e..12d702de4c598 100644
--- a/flang/runtime/internal-unit.cpp
+++ b/flang-rt/lib/flang_rt/internal-unit.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/internal-unit.cpp -----------------------------------------===//
+//===-- lib/flang_rt/internal-unit.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 "internal-unit.h"
-#include "io-error.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/internal-unit.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-error.h"
 #include "flang/Runtime/freestanding-tools.h"
 #include <algorithm>
 #include <type_traits>
diff --git a/flang/runtime/io-api-common.h b/flang-rt/lib/flang_rt/io-api-common.h
similarity index 93%
rename from flang/runtime/io-api-common.h
rename to flang-rt/lib/flang_rt/io-api-common.h
index c7b86cab73a52..ba8c7177c2811 100644
--- a/flang/runtime/io-api-common.h
+++ b/flang-rt/lib/flang_rt/io-api-common.h
@@ -1,4 +1,4 @@
-//===-- runtime/io-api-common.h ---------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/io-api-common.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 FLANG_RUNTIME_IO_API_COMMON_H_
-#define FLANG_RUNTIME_IO_API_COMMON_H_
+#ifndef FLANG_RT_IO_API_COMMON_H_
+#define FLANG_RT_IO_API_COMMON_H_
 
-#include "io-stmt.h"
-#include "terminator.h"
 #include "unit.h"
+#include "flang-rt/io-stmt.h"
+#include "flang-rt/terminator.h"
 #include "flang/Common/api-attrs.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/io-api.h"
@@ -94,4 +94,4 @@ RT_API_ATTRS Cookie BeginExternalListIO(
 }
 
 } // namespace Fortran::runtime::io
-#endif // FLANG_RUNTIME_IO_API_COMMON_H_
+#endif /* FLANG_RT_IO_API_COMMON_H_ */
diff --git a/flang/runtime/io-api-minimal.cpp b/flang-rt/lib/flang_rt/io-api-minimal.cpp
similarity index 96%
rename from flang/runtime/io-api-minimal.cpp
rename to flang-rt/lib/flang_rt/io-api-minimal.cpp
index 68768427be0c2..c3234c78c10c8 100644
--- a/flang/runtime/io-api-minimal.cpp
+++ b/flang-rt/lib/flang_rt/io-api-minimal.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/io-api-minimal.cpp ----------------------------------------===//
+//===-- lib/flang_rt/io-api-minimal.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,12 +10,12 @@
 // list-directed output (PRINT *) of intrinsic types.
 
 #include "edit-output.h"
-#include "format.h"
 #include "io-api-common.h"
-#include "io-stmt.h"
-#include "terminator.h"
-#include "tools.h"
 #include "unit.h"
+#include "flang-rt/format.h"
+#include "flang-rt/io-stmt.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/io-api.h"
 
 namespace Fortran::runtime::io {
diff --git a/flang/runtime/io-api.cpp b/flang-rt/lib/flang_rt/io-api.cpp
similarity index 99%
rename from flang/runtime/io-api.cpp
rename to flang-rt/lib/flang_rt/io-api.cpp
index 7023f61ba34de..ce1330ff323d4 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang-rt/lib/flang_rt/io-api.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/io-api.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/io-api.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.
@@ -17,16 +17,16 @@
 #include "descriptor-io.h"
 #include "edit-input.h"
 #include "edit-output.h"
-#include "environment.h"
-#include "format.h"
 #include "io-api-common.h"
-#include "io-stmt.h"
-#include "terminator.h"
-#include "tools.h"
 #include "unit.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/format.h"
+#include "flang-rt/io-stmt.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/optional.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/memory.h"
 #include <cstdlib>
 #include <memory>
 
diff --git a/flang/runtime/io-error.cpp b/flang-rt/lib/flang_rt/io-error.cpp
similarity index 97%
rename from flang/runtime/io-error.cpp
rename to flang-rt/lib/flang_rt/io-error.cpp
index 37909e8e6dad2..b356642c95f85 100644
--- a/flang/runtime/io-error.cpp
+++ b/flang-rt/lib/flang_rt/io-error.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/io-error.cpp ----------------------------------------------===//
+//===-- lib/flang_rt/io-error.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 "io-error.h"
+#include "flang-rt/io-error.h"
 #include "config.h"
-#include "tools.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/magic-numbers.h"
 #include <cerrno>
 #include <cstdarg>
diff --git a/flang/runtime/io-stmt.cpp b/flang-rt/lib/flang_rt/io-stmt.cpp
similarity index 99%
rename from flang/runtime/io-stmt.cpp
rename to flang-rt/lib/flang_rt/io-stmt.cpp
index f24eb929ce748..a07bf70a6593e 100644
--- a/flang/runtime/io-stmt.cpp
+++ b/flang-rt/lib/flang_rt/io-stmt.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/io-stmt.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/io-stmt.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,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "io-stmt.h"
-#include "connection.h"
-#include "emit-encoded.h"
-#include "format.h"
-#include "tools.h"
+#include "flang-rt/io-stmt.h"
 #include "unit.h"
-#include "utf.h"
-#include "flang/Runtime/memory.h"
+#include "flang-rt/connection.h"
+#include "flang-rt/emit-encoded.h"
+#include "flang-rt/format.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/utf.h"
 #include <algorithm>
 #include <cstdio>
 #include <cstring>
diff --git a/flang/runtime/iostat.cpp b/flang-rt/lib/flang_rt/iostat.cpp
similarity index 98%
rename from flang/runtime/iostat.cpp
rename to flang-rt/lib/flang_rt/iostat.cpp
index 39e224cb01286..ab2fc63cf7b21 100644
--- a/flang/runtime/iostat.cpp
+++ b/flang-rt/lib/flang_rt/iostat.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/iostat.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/iostat.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/main.cpp b/flang-rt/lib/flang_rt/main.cpp
similarity index 90%
rename from flang/runtime/main.cpp
rename to flang-rt/lib/flang_rt/main.cpp
index 96454989581b7..dac7268f82b16 100644
--- a/flang/runtime/main.cpp
+++ b/flang-rt/lib/flang_rt/main.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/main.cpp --------------------------------------------------===//
+//===-- lib/flang_rt/main.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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/main.h"
-#include "environment.h"
-#include "terminator.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/terminator.h"
 #include <cfenv>
 #include <cstdio>
 #include <cstdlib>
diff --git a/flang/runtime/matmul-transpose.cpp b/flang-rt/lib/flang_rt/matmul-transpose.cpp
similarity index 98%
rename from flang/runtime/matmul-transpose.cpp
rename to flang-rt/lib/flang_rt/matmul-transpose.cpp
index bafa05056bebc..307995bb8ab1e 100644
--- a/flang/runtime/matmul-transpose.cpp
+++ b/flang-rt/lib/flang_rt/matmul-transpose.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/matmul-transpose.cpp --------------------------------------===//
+//===-- lib/flang_rt/matmul-transpose.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.
@@ -21,12 +21,12 @@
 // to use the faster BLAS routines.
 
 #include "flang/Runtime/matmul-transpose.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/c-or-cpp.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include <cstring>
 
 namespace {
diff --git a/flang/runtime/matmul.cpp b/flang-rt/lib/flang_rt/matmul.cpp
similarity index 99%
rename from flang/runtime/matmul.cpp
rename to flang-rt/lib/flang_rt/matmul.cpp
index f72601073a600..c5036e24f86f4 100644
--- a/flang/runtime/matmul.cpp
+++ b/flang-rt/lib/flang_rt/matmul.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/matmul.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/matmul.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.
@@ -20,12 +20,12 @@
 // Places where BLAS routines could be called are marked as TODO items.
 
 #include "flang/Runtime/matmul.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/c-or-cpp.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include <cstring>
 
 namespace {
diff --git a/flang/runtime/memory.cpp b/flang-rt/lib/flang_rt/memory.cpp
similarity index 87%
rename from flang/runtime/memory.cpp
rename to flang-rt/lib/flang_rt/memory.cpp
index c7068ad6479a1..e09e45898da8e 100644
--- a/flang/runtime/memory.cpp
+++ b/flang-rt/lib/flang_rt/memory.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/memory.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/memory.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/Runtime/memory.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/freestanding-tools.h"
 #include <cstdlib>
 
diff --git a/flang/runtime/misc-intrinsic.cpp b/flang-rt/lib/flang_rt/misc-intrinsic.cpp
similarity index 96%
rename from flang/runtime/misc-intrinsic.cpp
rename to flang-rt/lib/flang_rt/misc-intrinsic.cpp
index f7d893829fc0d..1a5bc8114e8ae 100644
--- a/flang/runtime/misc-intrinsic.cpp
+++ b/flang-rt/lib/flang_rt/misc-intrinsic.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/misc-intrinsic.cpp ----------------------------------------===//
+//===-- lib/flang_rt/misc-intrinsic.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.
@@ -7,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/misc-intrinsic.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/optional.h"
-#include "flang/Runtime/descriptor.h"
 #include <algorithm>
 #include <cstdio>
 #include <cstring>
diff --git a/flang/runtime/namelist.cpp b/flang-rt/lib/flang_rt/namelist.cpp
similarity index 99%
rename from flang/runtime/namelist.cpp
rename to flang-rt/lib/flang_rt/namelist.cpp
index af092de70f781..4cf1cd2062ac5 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang-rt/lib/flang_rt/namelist.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/namelist.cpp ----------------------------------------------===//
+//===-- lib/flang_rt/namelist.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,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "namelist.h"
+#include "flang-rt/namelist.h"
 #include "descriptor-io.h"
-#include "emit-encoded.h"
-#include "io-stmt.h"
+#include "flang-rt/emit-encoded.h"
+#include "flang-rt/io-stmt.h"
 #include "flang/Runtime/io-api.h"
 #include <algorithm>
 #include <cstring>
diff --git a/flang/runtime/non-tbp-dio.cpp b/flang-rt/lib/flang_rt/non-tbp-dio.cpp
similarity index 87%
rename from flang/runtime/non-tbp-dio.cpp
rename to flang-rt/lib/flang_rt/non-tbp-dio.cpp
index 9419adb7631cc..5663c2ee338d7 100644
--- a/flang/runtime/non-tbp-dio.cpp
+++ b/flang-rt/lib/flang_rt/non-tbp-dio.cpp
@@ -1,4 +1,4 @@
-//===-- flang/runtime/non-tbp-dio.cpp ---------------------------*- C++ -*-===//
+//===-- lib/flang_rt/non-tbp-dio.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 "non-tbp-dio.h"
-#include "type-info.h"
+#include "flang-rt/non-tbp-dio.h"
+#include "flang-rt/type-info.h"
 
 namespace Fortran::runtime::io {
 
diff --git a/flang/runtime/numeric.cpp b/flang-rt/lib/flang_rt/numeric.cpp
similarity index 99%
rename from flang/runtime/numeric.cpp
rename to flang-rt/lib/flang_rt/numeric.cpp
index 45fb56348fd44..b63c604cadcfb 100644
--- a/flang/runtime/numeric.cpp
+++ b/flang-rt/lib/flang_rt/numeric.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/numeric.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/numeric.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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/numeric.h"
-#include "numeric-templates.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/numeric-templates.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/float128.h"
 #include <cfloat>
 #include <climits>
diff --git a/flang/runtime/pointer.cpp b/flang-rt/lib/flang_rt/pointer.cpp
similarity index 97%
rename from flang/runtime/pointer.cpp
rename to flang-rt/lib/flang_rt/pointer.cpp
index 2979181ddd61b..3138a54f1d122 100644
--- a/flang/runtime/pointer.cpp
+++ b/flang-rt/lib/flang_rt/pointer.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/pointer.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/pointer.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.
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/pointer.h"
-#include "assign-impl.h"
-#include "derived.h"
-#include "environment.h"
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "type-info.h"
+#include "flang-rt/assign-impl.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-info.h"
 
 namespace Fortran::runtime {
 extern "C" {
diff --git a/flang/runtime/product.cpp b/flang-rt/lib/flang_rt/product.cpp
similarity index 98%
rename from flang/runtime/product.cpp
rename to flang-rt/lib/flang_rt/product.cpp
index 293ffd301ba2e..c7b6d23d3014e 100644
--- a/flang/runtime/product.cpp
+++ b/flang-rt/lib/flang_rt/product.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/product.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/product.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.
@@ -8,7 +8,7 @@
 
 // Implements PRODUCT for all required operand types and shapes.
 
-#include "reduction-templates.h"
+#include "flang-rt/reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/reduction.h"
 #include <cfloat>
diff --git a/flang/runtime/pseudo-unit.cpp b/flang-rt/lib/flang_rt/pseudo-unit.cpp
similarity index 97%
rename from flang/runtime/pseudo-unit.cpp
rename to flang-rt/lib/flang_rt/pseudo-unit.cpp
index 526afd11d916e..f4d204890581e 100644
--- a/flang/runtime/pseudo-unit.cpp
+++ b/flang-rt/lib/flang_rt/pseudo-unit.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/pseudo-unit.cpp -------------------------------------------===//
+//===-- lib/flang_rt/pseudo-unit.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.
@@ -11,9 +11,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "io-error.h"
-#include "tools.h"
 #include "unit.h"
+#include "flang-rt/io-error.h"
+#include "flang-rt/tools.h"
 
 // NOTE: the header files above may define OpenMP declare target
 // variables, so they have to be included unconditionally
diff --git a/flang/runtime/ragged.cpp b/flang-rt/lib/flang_rt/ragged.cpp
similarity index 96%
rename from flang/runtime/ragged.cpp
rename to flang-rt/lib/flang_rt/ragged.cpp
index a4d9e541ba531..798b3464e7bca 100644
--- a/flang/runtime/ragged.cpp
+++ b/flang-rt/lib/flang_rt/ragged.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/ragged.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/ragged.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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/ragged.h"
-#include "tools.h"
+#include "flang-rt/tools.h"
 #include <cstdlib>
 
 namespace Fortran::runtime {
diff --git a/flang/runtime/random.cpp b/flang-rt/lib/flang_rt/random.cpp
similarity index 96%
rename from flang/runtime/random.cpp
rename to flang-rt/lib/flang_rt/random.cpp
index 8f158007a5a65..76971cf3fc888 100644
--- a/flang/runtime/random.cpp
+++ b/flang-rt/lib/flang_rt/random.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/random.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/random.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,14 +10,14 @@
 // RANDOM_SEED.
 
 #include "flang/Runtime/random.h"
-#include "lock.h"
-#include "random-templates.h"
-#include "terminator.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/lock.h"
+#include "flang-rt/random-templates.h"
+#include "flang-rt/terminator.h"
 #include "flang/Common/float128.h"
 #include "flang/Common/leading-zero-bit-count.h"
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include <cmath>
 #include <cstdint>
 #include <limits>
diff --git a/flang/runtime/reduce.cpp b/flang-rt/lib/flang_rt/reduce.cpp
similarity index 99%
rename from flang/runtime/reduce.cpp
rename to flang-rt/lib/flang_rt/reduce.cpp
index 6c42c5ef50e4f..4bb6dc10ea9da 100644
--- a/flang/runtime/reduce.cpp
+++ b/flang-rt/lib/flang_rt/reduce.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/reduce.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/reduce.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.
@@ -9,10 +9,10 @@
 // REDUCE() implementation
 
 #include "flang/Runtime/reduce.h"
-#include "reduction-templates.h"
-#include "terminator.h"
-#include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/reduction-templates.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/reduction.cpp b/flang-rt/lib/flang_rt/reduction.cpp
similarity index 99%
rename from flang/runtime/reduction.cpp
rename to flang-rt/lib/flang_rt/reduction.cpp
index a8fcde7b3a166..9ceaeffc6541a 100644
--- a/flang/runtime/reduction.cpp
+++ b/flang-rt/lib/flang_rt/reduction.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/reduction.cpp ---------------------------------------------===//
+//===-- lib/flang_rt/reduction.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.
@@ -14,8 +14,8 @@
 // NORM2, MAXLOC, MINLOC, MAXVAL, and MINVAL are in extrema.cpp.
 
 #include "flang/Runtime/reduction.h"
-#include "reduction-templates.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/reduction-templates.h"
 #include <cinttypes>
 
 namespace Fortran::runtime {
diff --git a/flang/runtime/stack.h b/flang-rt/lib/flang_rt/stack.h
similarity index 94%
rename from flang/runtime/stack.h
rename to flang-rt/lib/flang_rt/stack.h
index b6e6edb595e9a..88cd276456fbc 100644
--- a/flang/runtime/stack.h
+++ b/flang-rt/lib/flang_rt/stack.h
@@ -1,4 +1,4 @@
-//===-- runtime/stack.h -----------------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/stack.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,11 +10,11 @@
 // It is a list based stack with dynamic allocation/deallocation
 // of the list nodes.
 
-#ifndef FORTRAN_RUNTIME_STACK_H
-#define FORTRAN_RUNTIME_STACK_H
+#ifndef FLANG_RT_STACK_H_
+#define FLANG_RT_STACK_H_
 
-#include "terminator.h"
-#include "flang/Runtime/memory.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/terminator.h"
 
 namespace Fortran::runtime {
 // Storage for the Stack elements of type T.
@@ -133,4 +133,4 @@ template <typename T, unsigned N = 0> class Stack : public StackStorage<T, N> {
   Terminator &terminator_;
 };
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_STACK_H
+#endif /* FLANG_RT_STACK_H_ */
diff --git a/flang/runtime/stat.cpp b/flang-rt/lib/flang_rt/stat.cpp
similarity index 93%
rename from flang/runtime/stat.cpp
rename to flang-rt/lib/flang_rt/stat.cpp
index 525a4e36cdc77..883e85d0fbf2f 100644
--- a/flang/runtime/stat.cpp
+++ b/flang-rt/lib/flang_rt/stat.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/stat.cpp --------------------------------------------------===//
+//===-- lib/flang_rt/stat.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,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 
 namespace Fortran::runtime {
 RT_OFFLOAD_API_GROUP_BEGIN
diff --git a/flang/runtime/stop.cpp b/flang-rt/lib/flang_rt/stop.cpp
similarity index 96%
rename from flang/runtime/stop.cpp
rename to flang-rt/lib/flang_rt/stop.cpp
index a7be8a082e026..68141383246c3 100644
--- a/flang/runtime/stop.cpp
+++ b/flang-rt/lib/flang_rt/stop.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/stop.cpp --------------------------------------------------===//
+//===-- lib/flang_rt/stop.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.
@@ -8,11 +8,11 @@
 
 #include "flang/Runtime/stop.h"
 #include "config.h"
-#include "environment.h"
-#include "file.h"
-#include "io-error.h"
-#include "terminator.h"
 #include "unit.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/file.h"
+#include "flang-rt/io-error.h"
+#include "flang-rt/terminator.h"
 #include <cfenv>
 #include <cstdio>
 #include <cstdlib>
diff --git a/flang/runtime/sum.cpp b/flang-rt/lib/flang_rt/sum.cpp
similarity index 98%
rename from flang/runtime/sum.cpp
rename to flang-rt/lib/flang_rt/sum.cpp
index 3cb7a2b285779..fd98525b8c9b2 100644
--- a/flang/runtime/sum.cpp
+++ b/flang-rt/lib/flang_rt/sum.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/sum.cpp ---------------------------------------------------===//
+//===-- lib/flang_rt/sum.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.
@@ -12,7 +12,7 @@
 // cancellation on intermediate results by using "Kahan summation"
 // (basically the same as manual "double-double").
 
-#include "reduction-templates.h"
+#include "flang-rt/reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/reduction.h"
 #include <cfloat>
diff --git a/flang/runtime/support.cpp b/flang-rt/lib/flang_rt/support.cpp
similarity index 90%
rename from flang/runtime/support.cpp
rename to flang-rt/lib/flang_rt/support.cpp
index a607120256d9d..2673176bd8185 100644
--- a/flang/runtime/support.cpp
+++ b/flang-rt/lib/flang_rt/support.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/support.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/support.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.
@@ -8,8 +8,8 @@
 
 #include "flang/Runtime/support.h"
 #include "ISO_Fortran_util.h"
-#include "type-info.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-info.h"
 
 namespace Fortran::runtime {
 extern "C" {
diff --git a/flang/runtime/temporary-stack.cpp b/flang-rt/lib/flang_rt/temporary-stack.cpp
similarity index 97%
rename from flang/runtime/temporary-stack.cpp
rename to flang-rt/lib/flang_rt/temporary-stack.cpp
index 93340266b1b44..32ec4dacc872d 100644
--- a/flang/runtime/temporary-stack.cpp
+++ b/flang-rt/lib/flang_rt/temporary-stack.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/temporary-stack.cpp ---------------------------------------===//
+//===-- lib/flang_rt/temporary-stack.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,11 +10,11 @@
 // temporaries. For use in HLFIR lowering.
 
 #include "flang/Runtime/temporary-stack.h"
-#include "terminator.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/terminator.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/assign.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/memory.h"
 
 namespace {
 
diff --git a/flang/runtime/terminator.cpp b/flang-rt/lib/flang_rt/terminator.cpp
similarity index 96%
rename from flang/runtime/terminator.cpp
rename to flang-rt/lib/flang_rt/terminator.cpp
index bab9edc64fa35..0dfc08eb70370 100644
--- a/flang/runtime/terminator.cpp
+++ b/flang-rt/lib/flang_rt/terminator.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/terminate.cpp ---------------------------------------------===//
+//===-- lib/flang_rt/terminator.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 "terminator.h"
+#include "flang-rt/terminator.h"
 #include <cstdio>
 #include <cstdlib>
 
diff --git a/flang/runtime/time-intrinsic.cpp b/flang-rt/lib/flang_rt/time-intrinsic.cpp
similarity index 99%
rename from flang/runtime/time-intrinsic.cpp
rename to flang-rt/lib/flang_rt/time-intrinsic.cpp
index 942604a92aaad..1929fccbd4cf3 100644
--- a/flang/runtime/time-intrinsic.cpp
+++ b/flang-rt/lib/flang_rt/time-intrinsic.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/time-intrinsic.cpp ----------------------------------------===//
+//===-- lib/flang_rt/time-intrinsic.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.
@@ -9,10 +9,10 @@
 // Implements time-related intrinsic subroutines.
 
 #include "flang/Runtime/time-intrinsic.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include <algorithm>
 #include <cstdint>
 #include <cstdio>
diff --git a/flang/runtime/tools.cpp b/flang-rt/lib/flang_rt/tools.cpp
similarity index 98%
rename from flang/runtime/tools.cpp
rename to flang-rt/lib/flang_rt/tools.cpp
index 73d6c2cf7e1d2..9b460f81ad5c2 100644
--- a/flang/runtime/tools.cpp
+++ b/flang-rt/lib/flang_rt/tools.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/tools.cpp -------------------------------------------------===//
+//===-- lib/flang_rt/tools.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 "tools.h"
-#include "terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/terminator.h"
 #include <algorithm>
 #include <cstdint>
 #include <cstdlib>
diff --git a/flang/runtime/transformational.cpp b/flang-rt/lib/flang_rt/transformational.cpp
similarity index 99%
rename from flang/runtime/transformational.cpp
rename to flang-rt/lib/flang_rt/transformational.cpp
index ab303bdef9b1d..7453bf18323e9 100644
--- a/flang/runtime/transformational.cpp
+++ b/flang-rt/lib/flang_rt/transformational.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/transformational.cpp --------------------------------------===//
+//===-- lib/flang_rt/transformational.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.
@@ -18,10 +18,10 @@
 
 #include "flang/Runtime/transformational.h"
 #include "copy.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/float128.h"
-#include "flang/Runtime/descriptor.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/type-code.cpp b/flang-rt/lib/flang_rt/type-code.cpp
similarity index 98%
rename from flang/runtime/type-code.cpp
rename to flang-rt/lib/flang_rt/type-code.cpp
index d6948983bfe9f..432c7591520cb 100644
--- a/flang/runtime/type-code.cpp
+++ b/flang-rt/lib/flang_rt/type-code.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/type-code.cpp ---------------------------------------------===//
+//===-- lib/flang_rt/type-code.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/Runtime/type-code.h"
+#include "flang-rt/type-code.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/type-info.cpp b/flang-rt/lib/flang_rt/type-info.cpp
similarity index 98%
rename from flang/runtime/type-info.cpp
rename to flang-rt/lib/flang_rt/type-info.cpp
index d4daa72aee6a1..e1859e4864ca1 100644
--- a/flang/runtime/type-info.cpp
+++ b/flang-rt/lib/flang_rt/type-info.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/type-info.cpp ---------------------------------------------===//
+//===-- lib/flang_rt/type-info.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 "type-info.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/type-info.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include <cstdio>
 
 namespace Fortran::runtime::typeInfo {
@@ -86,7 +86,7 @@ RT_API_ATTRS std::size_t Component::SizeInBytes(
   } else if (category() == TypeCategory::Derived) {
     const DerivedType *type{derivedType()};
     return Descriptor::SizeInBytes(
-        rank_, true, type ? type->LenParameters() : 0);
+         rank_, true, type ? type->LenParameters() : 0);
   } else {
     return Descriptor::SizeInBytes(rank_);
   }
diff --git a/flang/runtime/unit-map.cpp b/flang-rt/lib/flang_rt/unit-map.cpp
similarity index 97%
rename from flang/runtime/unit-map.cpp
rename to flang-rt/lib/flang_rt/unit-map.cpp
index 684a9b9e20b97..0fda53ac071b2 100644
--- a/flang/runtime/unit-map.cpp
+++ b/flang-rt/lib/flang_rt/unit-map.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/unit-map.cpp ----------------------------------------------===//
+//===-- lib/flang_rt/unit-map.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/unit-map.h b/flang-rt/lib/flang_rt/unit-map.h
similarity index 92%
rename from flang/runtime/unit-map.h
rename to flang-rt/lib/flang_rt/unit-map.h
index 6f1e01bb1e64a..6f7eb692b970a 100644
--- a/flang/runtime/unit-map.h
+++ b/flang-rt/lib/flang_rt/unit-map.h
@@ -1,4 +1,4 @@
-//===-- runtime/unit-map.h --------------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/unit-map.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.
@@ -9,13 +9,13 @@
 // Maps Fortran unit numbers to their ExternalFileUnit instances.
 // A simple hash table with forward-linked chains per bucket.
 
-#ifndef FORTRAN_RUNTIME_UNIT_MAP_H_
-#define FORTRAN_RUNTIME_UNIT_MAP_H_
+#ifndef FLANG_RT_UNIT_MAP_H_
+#define FLANG_RT_UNIT_MAP_H_
 
-#include "lock.h"
 #include "unit.h"
+#include "flang-rt/lock.h"
+#include "flang-rt/memory.h"
 #include "flang/Common/fast-int-set.h"
-#include "flang/Runtime/memory.h"
 #include <cstdint>
 #include <cstdlib>
 
@@ -100,4 +100,4 @@ class UnitMap {
   int emergencyNewUnit_{maxNewUnits_}; // not recycled
 };
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_UNIT_MAP_H_
+#endif /* FLANG_RT_UNIT_MAP_H_ */
diff --git a/flang/runtime/unit.cpp b/flang-rt/lib/flang_rt/unit.cpp
similarity index 99%
rename from flang/runtime/unit.cpp
rename to flang-rt/lib/flang_rt/unit.cpp
index 4aee8397d477e..f05c4b5236dd5 100644
--- a/flang/runtime/unit.cpp
+++ b/flang-rt/lib/flang_rt/unit.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/unit.cpp --------------------------------------------------===//
+//===-- lib/flang_rt/unit.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.
@@ -11,9 +11,9 @@
 //
 //===----------------------------------------------------------------------===//
 #include "unit.h"
-#include "io-error.h"
-#include "lock.h"
-#include "tools.h"
+#include "flang-rt/io-error.h"
+#include "flang-rt/lock.h"
+#include "flang-rt/tools.h"
 #include <limits>
 #include <utility>
 
diff --git a/flang/runtime/unit.h b/flang-rt/lib/flang_rt/unit.h
similarity index 96%
rename from flang/runtime/unit.h
rename to flang-rt/lib/flang_rt/unit.h
index a3ea268681680..3b20c9870897a 100644
--- a/flang/runtime/unit.h
+++ b/flang-rt/lib/flang_rt/unit.h
@@ -1,4 +1,4 @@
-//===-- runtime/unit.h ------------------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/unit.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.
@@ -8,21 +8,21 @@
 
 // Fortran external I/O units
 
-#ifndef FORTRAN_RUNTIME_IO_UNIT_H_
-#define FORTRAN_RUNTIME_IO_UNIT_H_
-
-#include "buffer.h"
-#include "connection.h"
-#include "environment.h"
-#include "file.h"
-#include "format.h"
-#include "io-error.h"
-#include "io-stmt.h"
-#include "lock.h"
-#include "terminator.h"
+#ifndef FLANG_RT_UNIT_H_
+#define FLANG_RT_UNIT_H_
+
+#include "flang-rt/buffer.h"
+#include "flang-rt/connection.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/file.h"
+#include "flang-rt/format.h"
+#include "flang-rt/io-error.h"
+#include "flang-rt/io-stmt.h"
+#include "flang-rt/lock.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/terminator.h"
 #include "flang/Common/constexpr-bitset.h"
 #include "flang/Common/optional.h"
-#include "flang/Runtime/memory.h"
 #include <cstdlib>
 #include <cstring>
 #include <flang/Common/variant.h>
@@ -291,4 +291,4 @@ class ChildIo {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IO_UNIT_H_
+#endif /* FLANG_RT_UNIT_H_ */
diff --git a/flang/runtime/utf.cpp b/flang-rt/lib/flang_rt/utf.cpp
similarity index 97%
rename from flang/runtime/utf.cpp
rename to flang-rt/lib/flang_rt/utf.cpp
index b09819cb2f736..dd74889c025c5 100644
--- a/flang/runtime/utf.cpp
+++ b/flang-rt/lib/flang_rt/utf.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/utf.cpp ---------------------------------------------------===//
+//===-- lib/flang_rt/utf.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 "utf.h"
+#include "flang-rt/utf.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/test/Driver/ctofortran.f90 b/flang-rt/test/Driver/ctofortran.f90
similarity index 100%
rename from flang/test/Driver/ctofortran.f90
rename to flang-rt/test/Driver/ctofortran.f90
diff --git a/flang/test/Driver/exec.f90 b/flang-rt/test/Driver/exec.f90
similarity index 100%
rename from flang/test/Driver/exec.f90
rename to flang-rt/test/Driver/exec.f90
diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang-rt/test/Runtime/no-cpp-dep.c
similarity index 100%
rename from flang/test/Runtime/no-cpp-dep.c
rename to flang-rt/test/Runtime/no-cpp-dep.c
diff --git a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp b/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp
similarity index 98%
rename from flang/unittests/Evaluate/ISO-Fortran-binding.cpp
rename to flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp
index 2884686b3f26e..d1417b715e959 100644
--- a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp
+++ b/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp
@@ -1,5 +1,13 @@
+//===-- unittests/Evaluate/ISO-Fortran-binding.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-rt/descriptor.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/reshape.cpp b/flang-rt/unittests/Evaluate/reshape.cpp
similarity index 88%
rename from flang/unittests/Evaluate/reshape.cpp
rename to flang-rt/unittests/Evaluate/reshape.cpp
index 16cba15dcef60..a45e06ad0f69d 100644
--- a/flang/unittests/Evaluate/reshape.cpp
+++ b/flang-rt/unittests/Evaluate/reshape.cpp
@@ -1,4 +1,12 @@
-#include "flang/Runtime/descriptor.h"
+//===-- unittests/Evaluate/reshape.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-rt/descriptor.h"
 #include "flang/Runtime/transformational.h"
 #include "flang/Testing/testing.h"
 #include <cinttypes>
diff --git a/flang/unittests/Runtime/AccessTest.cpp b/flang-rt/unittests/Runtime/AccessTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/AccessTest.cpp
rename to flang-rt/unittests/Runtime/AccessTest.cpp
index c2a2d7d398220..d431d0d19bd61 100644
--- a/flang/unittests/Runtime/AccessTest.cpp
+++ b/flang-rt/unittests/Runtime/AccessTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/AccessTest.cpp ----------------------------===//
+//===-- unittests/Runtime/AccessTest.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/unittests/Runtime/Allocatable.cpp b/flang-rt/unittests/Runtime/Allocatable.cpp
similarity index 97%
rename from flang/unittests/Runtime/Allocatable.cpp
rename to flang-rt/unittests/Runtime/Allocatable.cpp
index f15f26bfd9c57..b03003a93fe09 100644
--- a/flang/unittests/Runtime/Allocatable.cpp
+++ b/flang-rt/unittests/Runtime/Allocatable.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Allocatable.cpp--------- ---------*- C++-*-===//
+//===-- unittests/Runtime/Allocatable.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.
@@ -8,7 +8,7 @@
 
 #include "flang/Runtime/allocatable.h"
 #include "gtest/gtest.h"
-#include "tools.h"
+#include "flang-rt/tools.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang/unittests/Runtime/ArrayConstructor.cpp b/flang-rt/unittests/Runtime/ArrayConstructor.cpp
similarity index 97%
rename from flang/unittests/Runtime/ArrayConstructor.cpp
rename to flang-rt/unittests/Runtime/ArrayConstructor.cpp
index 53774a0eea07d..5c84cd162a293 100644
--- a/flang/unittests/Runtime/ArrayConstructor.cpp
+++ b/flang-rt/unittests/Runtime/ArrayConstructor.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/ArrayConstructor.cpp-------------*- C++ -*-===//
+//===-- unittests/Runtime/ArrayConstructor.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,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "gtest/gtest.h"
 #include "tools.h"
+#include "gtest/gtest.h"
+#include "flang-rt/array-constructor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "flang/Runtime/allocatable.h"
-#include "flang/Runtime/array-constructor.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
 
 #include <memory>
 
diff --git a/flang/unittests/Runtime/BufferTest.cpp b/flang-rt/unittests/Runtime/BufferTest.cpp
similarity index 97%
rename from flang/unittests/Runtime/BufferTest.cpp
rename to flang-rt/unittests/Runtime/BufferTest.cpp
index 0632324b25d22..7795a79593eb2 100644
--- a/flang/unittests/Runtime/BufferTest.cpp
+++ b/flang-rt/unittests/Runtime/BufferTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/BufferTest.cpp ------------------*- C++ -*-===//
+//===-- unittests/Runtime/BufferTest.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 "../../runtime/buffer.h"
+#include "flang-rt/buffer.h"
 #include "CrashHandlerFixture.h"
 #include "gtest/gtest.h"
 #include <algorithm>
diff --git a/flang/unittests/Runtime/CUDA/Allocatable.cpp b/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp
similarity index 89%
rename from flang/unittests/Runtime/CUDA/Allocatable.cpp
rename to flang-rt/unittests/Runtime/CUDA/Allocatable.cpp
index bdfa8f5cc3213..db6589990be18 100644
--- a/flang/unittests/Runtime/CUDA/Allocatable.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Allocatable.cpp ------------------*- C++-*-===//
+//===-- unittests/Runtime/CUDA/Allocatable.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.
@@ -7,16 +7,16 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/allocatable.h"
+#include "cuda_runtime.h"
 #include "gtest/gtest.h"
-#include "../../../runtime/terminator.h"
-#include "flang/Runtime/CUDA/allocator.h"
+#include "flang-rt/CUDA/allocator.h"
+#include "flang-rt/allocator-registry.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.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"
-
 using namespace Fortran::runtime;
 using namespace Fortran::runtime::cuda;
 
diff --git a/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
similarity index 91%
rename from flang/unittests/Runtime/CUDA/AllocatorCUF.cpp
rename to flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
index 5ec122e4c5777..86c13d0dd290c 100644
--- a/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/AllocatableCUF.cpp ---------------*- C++-*-===//
+//===-- unittests/Runtime/CUDA/AllocatorCUF.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,16 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "cuda_runtime.h"
 #include "gtest/gtest.h"
-#include "../../../runtime/terminator.h"
-#include "flang/Runtime/CUDA/allocator.h"
+#include "flang-rt/CUDA/allocator.h"
+#include "flang-rt/allocator-registry.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.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"
-
 using namespace Fortran::runtime;
 using namespace Fortran::runtime::cuda;
 
diff --git a/flang/unittests/Runtime/CUDA/Memory.cpp b/flang-rt/unittests/Runtime/CUDA/Memory.cpp
similarity index 92%
rename from flang/unittests/Runtime/CUDA/Memory.cpp
rename to flang-rt/unittests/Runtime/CUDA/Memory.cpp
index 61c9d1131ee56..32609795c0169 100644
--- a/flang/unittests/Runtime/CUDA/Memory.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/Memory.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Memory.cpp -----------------------*- C++-*-===//
+//===-- unittests/Runtime/CUDA/Memory.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.
@@ -7,18 +7,17 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/memory.h"
-#include "gtest/gtest.h"
-#include "../../../runtime/terminator.h"
+#include "cuda_runtime.h"
 #include "../tools.h"
-#include "flang/Runtime/CUDA/allocator.h"
+#include "gtest/gtest.h"
+#include "flang-rt/CUDA/allocator.h"
+#include "flang-rt/allocator-registry.h"
+#include "flang-rt/terminator.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"
-
 using namespace Fortran::runtime;
 using namespace Fortran::runtime::cuda;
 
diff --git a/flang/unittests/Runtime/CharacterTest.cpp b/flang-rt/unittests/Runtime/CharacterTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/CharacterTest.cpp
rename to flang-rt/unittests/Runtime/CharacterTest.cpp
index d462c9120fd8c..696ab6b06e9e7 100644
--- a/flang/unittests/Runtime/CharacterTest.cpp
+++ b/flang-rt/unittests/Runtime/CharacterTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/CharacterTest.cpp ---------------*- C++ -*-===//
+//===-- unittests/Runtime/CharacterTest.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.
@@ -11,7 +11,7 @@
 
 #include "flang/Runtime/character.h"
 #include "gtest/gtest.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include <cstring>
 #include <functional>
 #include <tuple>
diff --git a/flang/unittests/Runtime/CommandTest.cpp b/flang-rt/unittests/Runtime/CommandTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/CommandTest.cpp
rename to flang-rt/unittests/Runtime/CommandTest.cpp
index ecb325330f1ad..a34c329750f39 100644
--- a/flang/unittests/Runtime/CommandTest.cpp
+++ b/flang-rt/unittests/Runtime/CommandTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/CommandTest.cpp ---------------------------===//
+//===-- unittests/Runtime/CommandTest.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.
@@ -9,7 +9,7 @@
 #include "flang/Runtime/command.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/execute.h"
 #include "flang/Runtime/extensions.h"
 #include "flang/Runtime/main.h"
diff --git a/flang/unittests/Runtime/Complex.cpp b/flang-rt/unittests/Runtime/Complex.cpp
similarity index 98%
rename from flang/unittests/Runtime/Complex.cpp
rename to flang-rt/unittests/Runtime/Complex.cpp
index d714da24dc4e5..d7e5f55414fe2 100644
--- a/flang/unittests/Runtime/Complex.cpp
+++ b/flang-rt/unittests/Runtime/Complex.cpp
@@ -1,10 +1,11 @@
-//===-- flang/unittests/Runtime/Complex.cpp ---------------------*- C++ -*-===//
+//===-- unittests/Runtime/Complex.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 "gmock/gmock.h"
 #include "gtest/gtest-matchers.h"
 #include <limits>
diff --git a/flang/unittests/Runtime/CrashHandlerFixture.cpp b/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp
similarity index 92%
rename from flang/unittests/Runtime/CrashHandlerFixture.cpp
rename to flang-rt/unittests/Runtime/CrashHandlerFixture.cpp
index 811603337e660..939cc62c433f0 100644
--- a/flang/unittests/Runtime/CrashHandlerFixture.cpp
+++ b/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp
@@ -1,12 +1,13 @@
-//===-- flang/unittests/Runtime/CrashHandlerFixture.cpp ---------*- C++ -*-===//
+//===-- unittests/Runtime/CrashHandlerFixture.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 "CrashHandlerFixture.h"
-#include "../../runtime/terminator.h"
+#include "flang-rt/terminator.h"
 #include <cstdarg>
 #include <cstdlib>
 
diff --git a/flang/unittests/Runtime/CrashHandlerFixture.h b/flang-rt/unittests/Runtime/CrashHandlerFixture.h
similarity index 70%
rename from flang/unittests/Runtime/CrashHandlerFixture.h
rename to flang-rt/unittests/Runtime/CrashHandlerFixture.h
index fe0ee0da5204e..74531d1e728f4 100644
--- a/flang/unittests/Runtime/CrashHandlerFixture.h
+++ b/flang-rt/unittests/Runtime/CrashHandlerFixture.h
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/CrashHandlerFixture.h -----------*- C++ -*-===//
+//===-- unittests/Runtime/CrashHandlerFixture.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,12 +10,13 @@
 /// with expected message.
 //
 //===----------------------------------------------------------------------===//
-#ifndef LLVM_FLANG_UNITTESTS_RUNTIMEGTEST_CRASHHANDLERFIXTURE_H
-#define LLVM_FLANG_UNITTESTS_RUNTIMEGTEST_CRASHHANDLERFIXTURE_H
+
+#ifndef FLANG_RT_UNITTESTS_RUNTIME_CRASHHANDLERFIXTURE_H_
+#define FLANG_RT_UNITTESTS_RUNTIME_CRASHHANDLERFIXTURE_H_
 #include <gtest/gtest.h>
 
 struct CrashHandlerFixture : testing::Test {
   void SetUp();
 };
 
-#endif
+#endif /* FLANG_RT_UNITTESTS_RUNTIME_CRASHHANDLERFIXTURE_H_ */
diff --git a/flang/unittests/Runtime/Derived.cpp b/flang-rt/unittests/Runtime/Derived.cpp
similarity index 94%
rename from flang/unittests/Runtime/Derived.cpp
rename to flang-rt/unittests/Runtime/Derived.cpp
index 019d5e8309e4a..2f45dfb80f7fd 100644
--- a/flang/unittests/Runtime/Derived.cpp
+++ b/flang-rt/unittests/Runtime/Derived.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Pointer.cpp--------- -------------*- C++-*-===//
+//===-- unittests/Runtime/Derived.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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "gtest/gtest.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/derived-api.h"
-#include "flang/Runtime/descriptor.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang/unittests/Runtime/ExternalIOTest.cpp b/flang-rt/unittests/Runtime/ExternalIOTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/ExternalIOTest.cpp
rename to flang-rt/unittests/Runtime/ExternalIOTest.cpp
index b9407b5e7a591..a5481e071916d 100644
--- a/flang/unittests/Runtime/ExternalIOTest.cpp
+++ b/flang-rt/unittests/Runtime/ExternalIOTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/RuntimeGTest/ExternalIOTest.cpp ---------*- C++ -*-===//
+//===-- unittests/Runtime/ExternalIOTest.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.
@@ -12,7 +12,7 @@
 
 #include "CrashHandlerFixture.h"
 #include "gtest/gtest.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/io-api-consts.h"
 #include "flang/Runtime/main.h"
 #include "flang/Runtime/stop.h"
diff --git a/flang/unittests/Runtime/Format.cpp b/flang-rt/unittests/Runtime/Format.cpp
similarity index 96%
rename from flang/unittests/Runtime/Format.cpp
rename to flang-rt/unittests/Runtime/Format.cpp
index 01803c628de26..83650e0f999ac 100644
--- a/flang/unittests/Runtime/Format.cpp
+++ b/flang-rt/unittests/Runtime/Format.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Format.cpp ----------------------*- C++ -*-===//
+//===-- unittests/Runtime/Format.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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "../runtime/connection.h"
-#include "../runtime/format-implementation.h"
-#include "../runtime/io-error.h"
+#include "flang-rt/connection.h"
+#include "flang-rt/format-implementation.h"
+#include "flang-rt/io-error.h"
 #include <optional>
 #include <string>
 #include <tuple>
diff --git a/flang/unittests/Runtime/Inquiry.cpp b/flang-rt/unittests/Runtime/Inquiry.cpp
similarity index 98%
rename from flang/unittests/Runtime/Inquiry.cpp
rename to flang-rt/unittests/Runtime/Inquiry.cpp
index 3b523e992a317..f6097484bd481 100644
--- a/flang/unittests/Runtime/Inquiry.cpp
+++ b/flang-rt/unittests/Runtime/Inquiry.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Inquiry.cpp -------------------------------===//
+//===-- unittests/Runtime/Inquiry.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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/inquiry.h"
-#include "gtest/gtest.h"
 #include "tools.h"
-#include "flang/Runtime/type-code.h"
+#include "gtest/gtest.h"
+#include "flang-rt/type-code.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang/unittests/Runtime/ListInputTest.cpp b/flang-rt/unittests/Runtime/ListInputTest.cpp
similarity index 98%
rename from flang/unittests/Runtime/ListInputTest.cpp
rename to flang-rt/unittests/Runtime/ListInputTest.cpp
index 38c758b7ef966..0c6c59d6a325e 100644
--- a/flang/unittests/Runtime/ListInputTest.cpp
+++ b/flang-rt/unittests/Runtime/ListInputTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/ListInputTest.cpp ---------------*- C++ -*-===//
+//===-- unittests/Runtime/ListInputTest.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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "../../runtime/io-error.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-error.h"
 #include "flang/Runtime/io-api-consts.h"
 
 using namespace Fortran::runtime;
diff --git a/flang/unittests/Runtime/LogicalFormatTest.cpp b/flang-rt/unittests/Runtime/LogicalFormatTest.cpp
similarity index 95%
rename from flang/unittests/Runtime/LogicalFormatTest.cpp
rename to flang-rt/unittests/Runtime/LogicalFormatTest.cpp
index 26c9374be1338..07f62ee02fc66 100644
--- a/flang/unittests/Runtime/LogicalFormatTest.cpp
+++ b/flang-rt/unittests/Runtime/LogicalFormatTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/LogicalFormatTest.cpp -----------*- C++ -*-===//
+//===-- unittests/Runtime/LogicalFormatTest.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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/io-api-consts.h"
 #include <algorithm>
 #include <array>
diff --git a/flang/unittests/Runtime/Matmul.cpp b/flang-rt/unittests/Runtime/Matmul.cpp
similarity index 98%
rename from flang/unittests/Runtime/Matmul.cpp
rename to flang-rt/unittests/Runtime/Matmul.cpp
index c3fed9b972df2..28bf2327da949 100644
--- a/flang/unittests/Runtime/Matmul.cpp
+++ b/flang-rt/unittests/Runtime/Matmul.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Matmul.cpp--------- -------------*- C++ -*-===//
+//===-- unittests/Runtime/Matmul.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.
@@ -7,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/matmul.h"
-#include "gtest/gtest.h"
 #include "tools.h"
+#include "gtest/gtest.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang/unittests/Runtime/MatmulTranspose.cpp b/flang-rt/unittests/Runtime/MatmulTranspose.cpp
similarity index 98%
rename from flang/unittests/Runtime/MatmulTranspose.cpp
rename to flang-rt/unittests/Runtime/MatmulTranspose.cpp
index c582e945dc7c9..b06afa29ce28e 100644
--- a/flang/unittests/Runtime/MatmulTranspose.cpp
+++ b/flang-rt/unittests/Runtime/MatmulTranspose.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/MatmulTranspose.cpp -------------*- C++ -*-===//
+//===-- unittests/Runtime/MatmulTranspose.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,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "gtest/gtest.h"
 #include "tools.h"
+#include "gtest/gtest.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/matmul-transpose.h"
-#include "flang/Runtime/type-code.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang/unittests/Runtime/MiscIntrinsic.cpp b/flang-rt/unittests/Runtime/MiscIntrinsic.cpp
similarity index 96%
rename from flang/unittests/Runtime/MiscIntrinsic.cpp
rename to flang-rt/unittests/Runtime/MiscIntrinsic.cpp
index 7e19ed250bdc0..61b05b31f45a9 100644
--- a/flang/unittests/Runtime/MiscIntrinsic.cpp
+++ b/flang-rt/unittests/Runtime/MiscIntrinsic.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/MiscIntrinsic.cpp ---------------*- C++ -*-===//
+//===-- unittests/Runtime/MiscIntrinsic.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,12 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "gtest/gtest.h"
 #include "tools.h"
-#include "flang/Runtime//misc-intrinsic.h"
+#include "gtest/gtest.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/misc-intrinsic.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang/unittests/Runtime/Namelist.cpp b/flang-rt/unittests/Runtime/Namelist.cpp
similarity index 99%
rename from flang/unittests/Runtime/Namelist.cpp
rename to flang-rt/unittests/Runtime/Namelist.cpp
index 0a28f3590b86e..d48a0273bf556 100644
--- a/flang/unittests/Runtime/Namelist.cpp
+++ b/flang-rt/unittests/Runtime/Namelist.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Namelist.cpp --------------------*- C++ -*-===//
+//===-- unittests/Runtime/Namelist.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,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "../../runtime/namelist.h"
+#include "flang-rt/namelist.h"
 #include "CrashHandlerFixture.h"
 #include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/io-api-consts.h"
 #include <algorithm>
 #include <cinttypes>
diff --git a/flang/unittests/Runtime/Numeric.cpp b/flang-rt/unittests/Runtime/Numeric.cpp
similarity index 99%
rename from flang/unittests/Runtime/Numeric.cpp
rename to flang-rt/unittests/Runtime/Numeric.cpp
index 29ebbc8ad7aa7..4baad3fc9ad0e 100644
--- a/flang/unittests/Runtime/Numeric.cpp
+++ b/flang-rt/unittests/Runtime/Numeric.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Numeric.cpp ---------------------*- C++ -*-===//
+//===-- unittests/Runtime/Numeric.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/unittests/Runtime/NumericalFormatTest.cpp b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/NumericalFormatTest.cpp
rename to flang-rt/unittests/Runtime/NumericalFormatTest.cpp
index 274498b8e8695..a86e6b807fc53 100644
--- a/flang/unittests/Runtime/NumericalFormatTest.cpp
+++ b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/NumericalFormatTest.cpp ---------*- C++ -*-===//
+//===-- unittests/Runtime/NumericalFormatTest.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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/io-api-consts.h"
 #include <algorithm>
 #include <array>
diff --git a/flang/unittests/Runtime/Pointer.cpp b/flang-rt/unittests/Runtime/Pointer.cpp
similarity index 96%
rename from flang/unittests/Runtime/Pointer.cpp
rename to flang-rt/unittests/Runtime/Pointer.cpp
index 4ce13ebc50a56..13f1922e6c5c3 100644
--- a/flang/unittests/Runtime/Pointer.cpp
+++ b/flang-rt/unittests/Runtime/Pointer.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Pointer.cpp--------- -------------*- C++-*-===//
+//===-- unittests/Runtime/Pointer.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.
@@ -8,8 +8,8 @@
 
 #include "flang/Runtime/pointer.h"
 #include "gtest/gtest.h"
-#include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/tools.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang/unittests/Runtime/Ragged.cpp b/flang-rt/unittests/Runtime/Ragged.cpp
similarity index 94%
rename from flang/unittests/Runtime/Ragged.cpp
rename to flang-rt/unittests/Runtime/Ragged.cpp
index 5049bc83405f1..feadd032f59bd 100644
--- a/flang/unittests/Runtime/Ragged.cpp
+++ b/flang-rt/unittests/Runtime/Ragged.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Ragged.cpp ----------------------*- C++ -*-===//
+//===-- unittests/Runtime/Ragged.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/unittests/Runtime/Random.cpp b/flang-rt/unittests/Runtime/Random.cpp
similarity index 92%
rename from flang/unittests/Runtime/Random.cpp
rename to flang-rt/unittests/Runtime/Random.cpp
index cb739b9451429..dba480cffa9c9 100644
--- a/flang/unittests/Runtime/Random.cpp
+++ b/flang-rt/unittests/Runtime/Random.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Random.cpp ----------------------*- C++ -*-===//
+//===-- unittests/Runtime/Random.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,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime//random.h"
+#include "flang/Runtime/random.h"
 #include "gtest/gtest.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include <cmath>
 
 using namespace Fortran::runtime;
diff --git a/flang/unittests/Runtime/Reduction.cpp b/flang-rt/unittests/Runtime/Reduction.cpp
similarity index 99%
rename from flang/unittests/Runtime/Reduction.cpp
rename to flang-rt/unittests/Runtime/Reduction.cpp
index 29675399abf5c..cb84512639933 100644
--- a/flang/unittests/Runtime/Reduction.cpp
+++ b/flang-rt/unittests/Runtime/Reduction.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Reductions.cpp ----------------------------===//
+//===-- unittests/Runtime/Reduction.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.
@@ -7,14 +7,14 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/reduction.h"
-#include "gtest/gtest.h"
 #include "tools.h"
+#include "gtest/gtest.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/reduce.h"
-#include "flang/Runtime/type-code.h"
 #include <cstdint>
 #include <cstring>
 #include <string>
diff --git a/flang/unittests/Runtime/RuntimeCrashTest.cpp b/flang-rt/unittests/Runtime/RuntimeCrashTest.cpp
similarity index 98%
rename from flang/unittests/Runtime/RuntimeCrashTest.cpp
rename to flang-rt/unittests/Runtime/RuntimeCrashTest.cpp
index 72a0b290cf864..23a60d98bf6ad 100644
--- a/flang/unittests/Runtime/RuntimeCrashTest.cpp
+++ b/flang-rt/unittests/Runtime/RuntimeCrashTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/CrashHandlerFixture.cpp ---------*- C++ -*-===//
+//===-- unittests/Runtime/RuntimeCrashTest.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.
@@ -12,7 +12,7 @@
 //===----------------------------------------------------------------------===//
 #include "CrashHandlerFixture.h"
 #include "tools.h"
-#include "../../runtime/terminator.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/io-api-consts.h"
 #include "flang/Runtime/transformational.h"
 #include <gtest/gtest.h>
diff --git a/flang/unittests/Runtime/Stop.cpp b/flang-rt/unittests/Runtime/Stop.cpp
similarity index 96%
rename from flang/unittests/Runtime/Stop.cpp
rename to flang-rt/unittests/Runtime/Stop.cpp
index b13602eaee5ea..102fecd1afb22 100644
--- a/flang/unittests/Runtime/Stop.cpp
+++ b/flang-rt/unittests/Runtime/Stop.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Stop.cpp ----------------------------------===//
+//===-- unittests/Runtime/Stop.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.
@@ -9,9 +9,10 @@
 /// Test runtime API for STOP statement and runtime API to kill the program.
 //
 //===----------------------------------------------------------------------===//
+
 #include "flang/Runtime/stop.h"
 #include "CrashHandlerFixture.h"
-#include "../../runtime/environment.h"
+#include "flang-rt/environment.h"
 #include <cstdlib>
 #include <gtest/gtest.h>
 
diff --git a/flang/unittests/Runtime/Support.cpp b/flang-rt/unittests/Runtime/Support.cpp
similarity index 96%
rename from flang/unittests/Runtime/Support.cpp
rename to flang-rt/unittests/Runtime/Support.cpp
index 8c8de73b5b979..0159bd74aa60c 100644
--- a/flang/unittests/Runtime/Support.cpp
+++ b/flang-rt/unittests/Runtime/Support.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Support.cpp ----------------------*- C++-*-===//
+//===-- unittests/Runtime/Support.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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/support.h"
-#include "gtest/gtest.h"
 #include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "gtest/gtest.h"
+#include "flang-rt/descriptor.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang/unittests/Runtime/TemporaryStack.cpp b/flang-rt/unittests/Runtime/TemporaryStack.cpp
similarity index 98%
rename from flang/unittests/Runtime/TemporaryStack.cpp
rename to flang-rt/unittests/Runtime/TemporaryStack.cpp
index 4f701e09b2945..d5cb9e5bfb9da 100644
--- a/flang/unittests/Runtime/TemporaryStack.cpp
+++ b/flang-rt/unittests/Runtime/TemporaryStack.cpp
@@ -1,4 +1,4 @@
-//===--- flang/unittests/Runtime/TemporaryStack.cpp -------------*- C++ -*-===//
+//===-- unittests/Runtime/TemporaryStack.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.
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "gtest/gtest.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-code.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"
 #include "flang/Runtime/temporary-stack.h"
-#include "flang/Runtime/type-code.h"
 #include <vector>
 
 using namespace Fortran::runtime;
diff --git a/flang/unittests/Runtime/Time.cpp b/flang-rt/unittests/Runtime/Time.cpp
similarity index 98%
rename from flang/unittests/Runtime/Time.cpp
rename to flang-rt/unittests/Runtime/Time.cpp
index 9309d7b1ceffa..548c0834e34a3 100644
--- a/flang/unittests/Runtime/Time.cpp
+++ b/flang-rt/unittests/Runtime/Time.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Time.cpp ----------------------------===//
+//===-- unittests/Runtime/Time.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/unittests/Runtime/Transformational.cpp b/flang-rt/unittests/Runtime/Transformational.cpp
similarity index 99%
rename from flang/unittests/Runtime/Transformational.cpp
rename to flang-rt/unittests/Runtime/Transformational.cpp
index 1d84b7e23779a..8805613738a60 100644
--- a/flang/unittests/Runtime/Transformational.cpp
+++ b/flang-rt/unittests/Runtime/Transformational.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Transformational.cpp ----------------------===//
+//===-- unittests/Runtime/Transformational.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.
@@ -7,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/transformational.h"
-#include "gtest/gtest.h"
 #include "tools.h"
+#include "gtest/gtest.h"
+#include "flang-rt/type-code.h"
 #include "flang/Common/float128.h"
-#include "flang/Runtime/type-code.h"
 #include <vector>
 
 using namespace Fortran::runtime;
diff --git a/flang/unittests/Runtime/tools.h b/flang-rt/unittests/Runtime/tools.h
similarity index 85%
rename from flang/unittests/Runtime/tools.h
rename to flang-rt/unittests/Runtime/tools.h
index 0347edace5c05..ff39d7ccb2a24 100644
--- a/flang/unittests/Runtime/tools.h
+++ b/flang-rt/unittests/Runtime/tools.h
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/tools.h -------------------------*- C++ -*-===//
+//===-- unittests/Runtime/tools.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_UNITTESTS_RUNTIME_TOOLS_H_
-#define FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
+#ifndef FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_
+#define FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_
 
 #include "gtest/gtest.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
 #include <cstdint>
 #include <cstring>
 #include <vector>
@@ -54,4 +54,4 @@ static OwningPtr<Descriptor> MakeArray(const std::vector<int> &shape,
 }
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
+#endif /* FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_ */
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 8a8b8bfa73b00..0044779da011d 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -23,6 +23,7 @@ if (LLVM_ENABLE_EH)
 endif()
 
 set(FLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(FLANG_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../flang-rt")
 
 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE)
   message(FATAL_ERROR "In-source builds are not allowed. \
diff --git a/flang/include/flang/Runtime/allocatable.h b/flang/include/flang/Runtime/allocatable.h
index 58061d9862095..714d85ec073c6 100644
--- a/flang/include/flang/Runtime/allocatable.h
+++ b/flang/include/flang/Runtime/allocatable.h
@@ -11,7 +11,7 @@
 #ifndef FORTRAN_RUNTIME_ALLOCATABLE_H_
 #define FORTRAN_RUNTIME_ALLOCATABLE_H_
 
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
 
 namespace Fortran::runtime {
diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h
index abcdbc4a12002..acd7bc5ddbdef 100644
--- a/flang/include/flang/Runtime/descriptor-consts.h
+++ b/flang/include/flang/Runtime/descriptor-consts.h
@@ -9,6 +9,7 @@
 #ifndef FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_
 #define FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_
 
+#include "flang/Common/Fortran-consts.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Common/api-attrs.h"
 #include <cstddef>
@@ -29,6 +30,7 @@ class DerivedType;
 namespace Fortran::runtime {
 class Descriptor;
 using SubscriptValue = ISO::CFI_index_t;
+using common::TypeCategory;
 
 /// Returns size in bytes of the descriptor (not the data)
 /// This must be at least as large as the largest descriptor of any target
diff --git a/flang/include/flang/Runtime/pointer.h b/flang/include/flang/Runtime/pointer.h
index 704144f08114f..67c4fe266f55c 100644
--- a/flang/include/flang/Runtime/pointer.h
+++ b/flang/include/flang/Runtime/pointer.h
@@ -12,7 +12,7 @@
 #ifndef FORTRAN_RUNTIME_POINTER_H_
 #define FORTRAN_RUNTIME_POINTER_H_
 
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
 
 namespace Fortran::runtime {
diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index 3e32daba52a81..2bdcfca4cba85 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -16,6 +16,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   set(CMAKE_CXX_EXTENSIONS OFF)
 
   set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
+  set(FLANG_RT_SOURCE_DIR "${FLANG_SOURCE_DIR}/../flang-rt")
 
   set(LLVM_COMMON_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../cmake")
   set(LLVM_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../llvm/cmake")
@@ -57,8 +58,31 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
     REAL(16) is mapped to __float128, or libm for targets where REAL(16) \
     is mapped to long double, etc."
     )
+
+  option(FLANG_CUF_RUNTIME
+    "Compile CUDA Fortran runtime sources" OFF)
+  if (FLANG_CUF_RUNTIME)
+    find_package(CUDAToolkit REQUIRED)
+  endif()
 endif()
 
+# Runtime files are in Flang-RT's source dir.
+function (runtime_source_files outvar)
+  cmake_parse_arguments(ARG "" "SUBDIR" "" ${ARGN})
+
+  set(new_sources "")
+  foreach (source IN LISTS "${outvar}")
+    set(new_source "${FLANG_RT_SOURCE_DIR}/lib/flang_rt")
+    cmake_path(APPEND new_source "${ARG_SUBDIR}")
+    cmake_path(APPEND new_source "${source}")
+    list(APPEND new_sources "${new_source}")
+  endforeach ()
+  set("${outvar}" ${new_sources} PARENT_SCOPE)
+endfunction ()
+
+# Runtime includes are in Flang-RT's source dir.
+include_directories(BEFORE "${FLANG_RT_SOURCE_DIR}/include")
+
 # function checks
 find_package(Backtrace)
 set(HAVE_BACKTRACE ${Backtrace_FOUND})
@@ -94,7 +118,7 @@ else()
   set(NO_LTO_FLAGS "")
 endif()
 
-configure_file(config.h.cmake config.h)
+configure_file("${FLANG_RT_SOURCE_DIR}/cmake/config.h.cmake.in" config.h)
 # include_directories is used here instead of target_include_directories
 # because add_flang_library creates multiple objects (STATIC/SHARED, OBJECT)
 # with different names
@@ -236,6 +260,7 @@ set(supported_files
   utf.cpp
   )
 
+runtime_source_files(supported_files)
 enable_cuda_compilation(flang_rt "${supported_files}")
 enable_omp_offload_compilation("${supported_files}")
 
@@ -269,6 +294,9 @@ if (NOT TARGET FortranFloat128Math)
   endif()
 endif()
 
+runtime_source_files(sources)
+
+
 if (NOT DEFINED MSVC)
   add_flang_library(flang_rt
     ${sources}
diff --git a/flang/runtime/CUDA/CMakeLists.txt b/flang/runtime/CUDA/CMakeLists.txt
index 744df95267e6f..86a76658042eb 100644
--- a/flang/runtime/CUDA/CMakeLists.txt
+++ b/flang/runtime/CUDA/CMakeLists.txt
@@ -13,7 +13,7 @@ include_directories(${CUDAToolkit_INCLUDE_DIRS})
 # added to the library name.
 set(CUFRT_LIBNAME CufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR})
 
-add_flang_library(${CUFRT_LIBNAME}
+set(sources
   allocator.cpp
   allocatable.cpp
   descriptor.cpp
@@ -22,6 +22,11 @@ add_flang_library(${CUFRT_LIBNAME}
   memory.cpp
   registration.cpp
 )
+runtime_source_files(sources SUBDIR "CUDA")
+
+add_flang_library(${CUFRT_LIBNAME}
+  ${sources}
+)
 
 if (BUILD_SHARED_LIBS)
   set(CUDA_RT_TARGET CUDA::cudart)
diff --git a/flang/runtime/Float128Math/CMakeLists.txt b/flang/runtime/Float128Math/CMakeLists.txt
index d65193be05ab5..2cd7e46c80407 100644
--- a/flang/runtime/Float128Math/CMakeLists.txt
+++ b/flang/runtime/Float128Math/CMakeLists.txt
@@ -17,56 +17,56 @@
 include(CheckLibraryExists)
 
 set(sources
-  acos.cpp
-  acosh.cpp
-  asin.cpp
-  asinh.cpp
-  atan.cpp
-  atan2.cpp
-  atanh.cpp
-  ceil.cpp
-  complex-math.c
-  cos.cpp
-  cosh.cpp
-  erf.cpp
-  erfc.cpp
-  exp.cpp
-  exponent.cpp
-  floor.cpp
-  fma.cpp
-  fraction.cpp
-  hypot.cpp
-  j0.cpp
-  j1.cpp
-  jn.cpp
-  lgamma.cpp
-  llround.cpp
-  log.cpp
-  log10.cpp
-  lround.cpp
-  mod-real.cpp
-  modulo-real.cpp
-  nearest.cpp
-  nearbyint.cpp
-  norm2.cpp
-  pow.cpp
-  random.cpp
-  remainder.cpp
-  round.cpp
-  rrspacing.cpp
-  scale.cpp
-  set-exponent.cpp
-  sin.cpp
-  sinh.cpp
-  spacing.cpp
-  sqrt.cpp
-  tan.cpp
-  tanh.cpp
-  tgamma.cpp
-  trunc.cpp
-  y0.cpp
-  y1.cpp
-  yn.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/acos.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/acosh.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/asin.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/asinh.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/atan.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/atan2.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/atanh.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/ceil.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/complex-math.c
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/cos.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/cosh.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/erf.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/erfc.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/exp.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/exponent.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/floor.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/fma.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/fraction.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/hypot.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/j0.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/j1.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/jn.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/lgamma.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/llround.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/log.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/log10.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/lround.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/mod-real.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/modulo-real.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/nearest.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/nearbyint.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/norm2.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/pow.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/random.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/remainder.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/round.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/rrspacing.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/scale.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/set-exponent.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/sin.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/sinh.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/spacing.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/sqrt.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/tan.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/tanh.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/tgamma.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/trunc.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/y0.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/y1.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/yn.cpp
   )
 
 include_directories(AFTER "${CMAKE_CURRENT_SOURCE_DIR}/..")
diff --git a/flang/runtime/config.h.cmake b/flang/runtime/config.h.cmake
deleted file mode 100644
index a2271be77b8c6..0000000000000
--- a/flang/runtime/config.h.cmake
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef FORTRAN_RUNTIME_CONFIG_H
-#define FORTRAN_RUNTIME_CONFIG_H
-
-/* Define to 1 if you have the `strerror_r' function. */
-#cmakedefine01 HAVE_STRERROR_R
-
-/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you
-   don't. */
-#cmakedefine01 HAVE_DECL_STRERROR_S
-
-/* Define to 1 if you have the `backtrace' function. */
-#cmakedefine HAVE_BACKTRACE ${HAVE_BACKTRACE}
-
-#define BACKTRACE_HEADER <${BACKTRACE_HEADER}>
-
-#endif
diff --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt
index 7b0f85638f14e..b946d39fad54b 100644
--- a/flang/unittests/CMakeLists.txt
+++ b/flang/unittests/CMakeLists.txt
@@ -12,6 +12,8 @@ endif()
 add_custom_target(FlangUnitTests)
 set_target_properties(FlangUnitTests PROPERTIES FOLDER "Flang/Tests")
 
+include_directories("${FLANG_RT_SOURCE_DIR}/include")
+
 function(add_flang_unittest_offload_properties target)
   # Do not apply runtime properties if not even compiling the runtime.
   if (NOT FLANG_INCLUDE_RUNTIME)
@@ -61,7 +63,13 @@ function(add_flang_nongtest_unittest test_name)
       set(suffix .test)
   endif()
 
-  add_executable(${test_name}${suffix} ${test_name}.cpp)
+  # Sources for runtime tests are in Flang-RT.
+  set(test_filepath "${FLANG_RT_SOURCE_DIR}/unittests/Evaluate/${test_name}.cpp")
+  if (NOT EXISTS "${test_filepath}")
+    set(test_filepath "${test_name}.cpp")
+  endif ()
+
+  add_executable(${test_name}${suffix} "${test_filepath}")
   set_target_properties(${test_name}${suffix} PROPERTIES FOLDER "Flang/Tests/Unit")
 
   if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
diff --git a/flang/unittests/Runtime/CMakeLists.txt b/flang/unittests/Runtime/CMakeLists.txt
index a60b43d422878..2e87391402744 100644
--- a/flang/unittests/Runtime/CMakeLists.txt
+++ b/flang/unittests/Runtime/CMakeLists.txt
@@ -1,34 +1,34 @@
 add_flang_unittest(FlangRuntimeTests
-  AccessTest.cpp
-  Allocatable.cpp
-  ArrayConstructor.cpp
-  BufferTest.cpp
-  CharacterTest.cpp
-  CommandTest.cpp
-  Complex.cpp
-  CrashHandlerFixture.cpp
-  Derived.cpp
-  ExternalIOTest.cpp
-  Format.cpp
-  Inquiry.cpp
-  ListInputTest.cpp
-  LogicalFormatTest.cpp
-  Matmul.cpp
-  MatmulTranspose.cpp
-  MiscIntrinsic.cpp
-  Namelist.cpp
-  Numeric.cpp
-  NumericalFormatTest.cpp
-  Pointer.cpp
-  Ragged.cpp
-  Random.cpp
-  Reduction.cpp
-  RuntimeCrashTest.cpp
-  Stop.cpp
-  Support.cpp
-  Time.cpp
-  TemporaryStack.cpp
-  Transformational.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/AccessTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Allocatable.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/ArrayConstructor.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/BufferTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CharacterTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CommandTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Complex.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CrashHandlerFixture.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Derived.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/ExternalIOTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Format.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Inquiry.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/ListInputTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/LogicalFormatTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Matmul.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/MatmulTranspose.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/MiscIntrinsic.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Namelist.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Numeric.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/NumericalFormatTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Pointer.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Ragged.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Random.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Reduction.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/RuntimeCrashTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Stop.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Support.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Time.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/TemporaryStack.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Transformational.cpp
 )
 
 target_link_libraries(FlangRuntimeTests
diff --git a/flang/unittests/Runtime/CUDA/CMakeLists.txt b/flang/unittests/Runtime/CUDA/CMakeLists.txt
index 38888e32e6ed8..762df4b460107 100644
--- a/flang/unittests/Runtime/CUDA/CMakeLists.txt
+++ b/flang/unittests/Runtime/CUDA/CMakeLists.txt
@@ -1,9 +1,9 @@
 if (FLANG_CUF_RUNTIME)
 
 add_flang_unittest(FlangCufRuntimeTests
-  Allocatable.cpp
-  AllocatorCUF.cpp
-  Memory.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CUDA/Allocatable.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CUDA/AllocatorCUF.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CUDA/Memory.cpp
 )
 
 if (BUILD_SHARED_LIBS)

>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 07/24] 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 809266960a02d..4ee381589a208 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 f2e15355b4c7e2a302299dbac2d9119bce1a0e0f Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 27 Jan 2025 15:00:37 +0100
Subject: [PATCH 08/24] Move new file pointer.cpp

---
 .../runtime => flang-rt/lib/flang_rt}/CUDA/pointer.cpp   | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
 rename {flang/runtime => flang-rt/lib/flang_rt}/CUDA/pointer.cpp (93%)

diff --git a/flang/runtime/CUDA/pointer.cpp b/flang-rt/lib/flang_rt/CUDA/pointer.cpp
similarity index 93%
rename from flang/runtime/CUDA/pointer.cpp
rename to flang-rt/lib/flang_rt/CUDA/pointer.cpp
index 3252410bd8d2c..b6e8033933834 100644
--- a/flang/runtime/CUDA/pointer.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/pointer.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/pointer.cpp ------------------------------------------===//
+//===-- lib/flang_rt/CUDA/pointer.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.
@@ -7,9 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/pointer.h"
-#include "../assign-impl.h"
-#include "../stat.h"
-#include "../terminator.h"
+#include "flang-rt/assign-impl.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/CUDA/memmove-function.h"
 #include "flang/Runtime/pointer.h"

>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 09/24] 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 7a8a8a9787bd0..5d9c66f47b48e 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 c5e9fb06e260f..da416506ffb5d 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 aeb1698516bae..7348eb0473f07 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 99c0784f006a8..c4cab0ccf1130 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 c0f4278009f40..c7c81f40cc8c8 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 b527deda0e3b4..b47ba46581db6 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 636613d93d80c..de91d4fb6ee8b 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 2983754108f95..85b2c6d5abce3 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 c0b0e048ae04a..0c579de44bd7f 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 0f1bc48620d37..c18c13e351c76 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 8928fab6bfb6f..27d2ba89c8009 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 c0c9f6c49b26a..f503b22930ed4 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 36fa6f7072b40..6501994133759 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 821c8c3b08a52..faecb88737a0b 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 e890753499d1a..84582174e4b30 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 ad66297650b09..1a84102b56642 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 4d8ca28cf329a..2a5929b873d74 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 ccd584b5ee6aa..b4e14cd299fb6 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 91d38748f5a57..993540aebca57 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 63e8ed4119cdf..6fc22e3b86aa2 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 ec71550d2a50c..1203fca8640a6 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 ae9351139b193..aa82f56107fdd 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 18dca71379e0d..3e42ec691158b 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 fbe905168d253..669efb41b0344 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 58f188a409249..dd38d64bff63f 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 ab7e4723152d7..98cc9b8cbba21 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 bb4150613c81d..9b597d29813da 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 c15edf62df388..72bc9dd890a94 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 05da17faf2dd7..42d6546b77553 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 08a872b228691..1cc74521e22d8 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 fb64db407708a..c03f9afd40801 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 8374b18b8a17d..5ae32f70a11a7 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 4541b31e566f9..38f4f7b82e1ea 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 42d622c4d497b..8114cb3c7d049 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 bfbc985b8b91a..e19b16c23b82b 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 158c27a8be2f9..69deff2a3be64 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 7f29fb272c942..a9224b727fd05 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 a67fd66045a3d..a6efdf9546c7f 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 8ea33902bd213..7b68ea728cbd5 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 94c50aab69681..e90d3ae8baf1e 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 b7d115ec2bca4..b4046830522b8 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 dfe323acbd490..974add6cc5de3 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 690329411dc50..58f84e9413676 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 3c6094c9a9c87..f4f197dd87ca3 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 072aed20da470..b4838c63d4ef8 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 827f13bc4758e..ad3da16008319 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 92f06e6fe2d27..5553366aa409d 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 880b190f1c581..2fd2a429d7c22 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 49d11f41ea4ca..3912d1c4b4771 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 723bb8d97f68e..31d043f490fd8 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 fa2c931b21f0a..c1b270f518c0e 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 ab7c357fa78a8..58b824d9b8e64 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 f87cce8b32005..94dc35ecd5900 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 04df137ce566f..b33baf90582b8 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 aa40b12196520..1165417ef89a2 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 7c8d292e90f01..3789babd6c2c8 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 803fa8bff90dc..db9918c265164 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 555601c5e92df..696e80105f80f 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 d739102b8464f..7e69d41debfcd 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 89491fd2fa2a7..a414f226058e3 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 d5d9252cf4c73..993a38749bf50 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 ba0c70f7d224c..95d7b3cf91b17 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 c81d3b16ab313..5ce143c9aec91 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 ac1f38801cee7..6cf61a6b923db 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 32dcaad52e33a..c85a84ea5527f 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 6da316cccc4a7..479d32568fa66 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 ddba4c04b1ee3..84e6b6455cc61 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 b86a95492b21c..94d16a719277a 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 e99a02cc79db1..7486ac8113e90 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 49684ffd5f804..7f4548c7327e3 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 584319b8abdf6..04e4b142efedf 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 065090ed03b6a..c91c522b7c73e 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 d0e0a3784f2af..d6d05a41f6917 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 171c0021fba08..577558e7e33b2 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 64e4c9d7e194d..1166ec9a58f86 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 b3cab763aca30..178a6e38dc0f2 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 10/24] 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 a1bf3ea0f0925..88e2183c15d03 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 11/24] 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 bb6dcb3873f21..1f01be1aa9ffa 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 58f84e9413676..826b65e8d3c3c 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 4e6bdbb67f5f3..6e6e37ba594be 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 f4f197dd87ca3..fac6fb92df85a 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 b4838c63d4ef8..a2bea3c598a8c 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 ad3da16008319..d8f82e1cf94f1 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 5d66831d6c1c2..75ba2a8d85f39 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 4ceb19e7f4d71..fe7f7395e1eba 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 5553366aa409d..ab1422d63af30 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 41cb2be826907..ee8309a950eec 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 12/24] 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 85c901e7fdb82..1dd7ea560cc96 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 9fce9efff9b7bbd3f1bc095f24760c77ca238f33 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Thu, 30 Jan 2025 13:33:57 +0100
Subject: [PATCH 13/24] Post-merge fixes

---
 flang-rt/include/flang-rt/CUDA/allocator.h                | 2 +-
 flang-rt/include/flang-rt/allocator-registry.h            | 2 +-
 flang-rt/include/flang-rt/array-constructor.h             | 2 +-
 flang-rt/include/flang-rt/assign-impl.h                   | 2 +-
 flang-rt/include/flang-rt/buffer.h                        | 2 +-
 flang-rt/include/flang-rt/connection.h                    | 2 +-
 flang-rt/include/flang-rt/derived.h                       | 2 +-
 flang-rt/include/flang-rt/descriptor.h                    | 2 +-
 flang-rt/include/flang-rt/emit-encoded.h                  | 2 +-
 flang-rt/include/flang-rt/environment.h                   | 2 +-
 flang-rt/include/flang-rt/file.h                          | 2 +-
 flang-rt/include/flang-rt/format-implementation.h         | 2 +-
 flang-rt/include/flang-rt/format.h                        | 2 +-
 flang-rt/include/flang-rt/internal-unit.h                 | 2 +-
 flang-rt/include/flang-rt/io-error.h                      | 2 +-
 flang-rt/include/flang-rt/io-stmt.h                       | 2 +-
 flang-rt/include/flang-rt/lock.h                          | 2 +-
 flang-rt/include/flang-rt/memory.h                        | 2 +-
 flang-rt/include/flang-rt/namelist.h                      | 2 +-
 flang-rt/include/flang-rt/non-tbp-dio.h                   | 2 +-
 flang-rt/include/flang-rt/numeric-templates.h             | 2 +-
 flang-rt/include/flang-rt/random-templates.h              | 2 +-
 flang-rt/include/flang-rt/reduction-templates.h           | 2 +-
 flang-rt/include/flang-rt/stat.h                          | 2 +-
 flang-rt/include/flang-rt/terminator.h                    | 2 +-
 flang-rt/include/flang-rt/tools.h                         | 2 +-
 flang-rt/include/flang-rt/type-code.h                     | 2 +-
 flang-rt/include/flang-rt/type-info.h                     | 2 +-
 flang-rt/include/flang-rt/utf.h                           | 2 +-
 flang-rt/lib/FortranFloat128Math/complex-math.h           | 2 +-
 flang-rt/lib/FortranFloat128Math/math-entries.h           | 2 +-
 flang-rt/lib/FortranFloat128Math/numeric-template-specs.h | 2 +-
 {flang/runtime => flang-rt/lib/flang_rt}/CUDA/init.cpp    | 6 +++---
 flang-rt/lib/flang_rt/ISO_Fortran_util.h                  | 2 +-
 flang-rt/lib/flang_rt/complex-reduction.h                 | 2 +-
 flang-rt/lib/flang_rt/copy.h                              | 2 +-
 flang-rt/lib/flang_rt/descriptor-io.h                     | 2 +-
 flang-rt/lib/flang_rt/edit-input.h                        | 2 +-
 flang-rt/lib/flang_rt/edit-output.h                       | 2 +-
 flang-rt/lib/flang_rt/io-api-common.h                     | 2 +-
 flang-rt/lib/flang_rt/stack.h                             | 2 +-
 flang-rt/lib/flang_rt/unit-map.h                          | 2 +-
 flang-rt/lib/flang_rt/unit.h                              | 2 +-
 flang-rt/unittests/Runtime/tools.h                        | 2 +-
 44 files changed, 46 insertions(+), 46 deletions(-)
 rename {flang/runtime => flang-rt/lib/flang_rt}/CUDA/init.cpp (82%)

diff --git a/flang-rt/include/flang-rt/CUDA/allocator.h b/flang-rt/include/flang-rt/CUDA/allocator.h
index fb09b5ff2402a..68bb0736dd5ee 100644
--- a/flang-rt/include/flang-rt/CUDA/allocator.h
+++ b/flang-rt/include/flang-rt/CUDA/allocator.h
@@ -33,4 +33,4 @@ void *CUFAllocUnified(std::size_t);
 void CUFFreeUnified(void *);
 
 } // namespace Fortran::runtime::cuda
-#endif /* FLANG_RT_CUDA_ALLOCATOR_H_ */
+#endif // FLANG_RT_CUDA_ALLOCATOR_H_
diff --git a/flang-rt/include/flang-rt/allocator-registry.h b/flang-rt/include/flang-rt/allocator-registry.h
index 1f004462ca624..ea905afc045ce 100644
--- a/flang-rt/include/flang-rt/allocator-registry.h
+++ b/flang-rt/include/flang-rt/allocator-registry.h
@@ -55,4 +55,4 @@ RT_OFFLOAD_VAR_GROUP_END
 
 } // namespace Fortran::runtime
 
-#endif /* FLANG_RT_ALLOCATOR_REGISTRY_H_ */
+#endif // FLANG_RT_ALLOCATOR_REGISTRY_H_
diff --git a/flang-rt/include/flang-rt/array-constructor.h b/flang-rt/include/flang-rt/array-constructor.h
index 7ff0779e46c6a..738050f80ef65 100644
--- a/flang-rt/include/flang-rt/array-constructor.h
+++ b/flang-rt/include/flang-rt/array-constructor.h
@@ -54,4 +54,4 @@ static_assert(alignof(Fortran::runtime::ArrayConstructorVector) <=
     "MaxArrayConstructorVectorAlignInBytes");
 
 } // namespace Fortran::runtime
-#endif /* FLANG_RT_ARRAY_CONSTRUCTOR_H_ */
+#endif // FLANG_RT_ARRAY_CONSTRUCTOR_H_
diff --git a/flang-rt/include/flang-rt/assign-impl.h b/flang-rt/include/flang-rt/assign-impl.h
index 7e2cef9df753b..2e85a451d5b52 100644
--- a/flang-rt/include/flang-rt/assign-impl.h
+++ b/flang-rt/include/flang-rt/assign-impl.h
@@ -28,4 +28,4 @@ RT_API_ATTRS void DoFromSourceAssign(Descriptor &, const Descriptor &,
 #endif
 
 } // namespace Fortran::runtime
-#endif /* FLANG_RT_ASSIGN_IMPL_H_ */
+#endif // FLANG_RT_ASSIGN_IMPL_H_
diff --git a/flang-rt/include/flang-rt/buffer.h b/flang-rt/include/flang-rt/buffer.h
index ba172448a93a5..bd2e8c47c6e30 100644
--- a/flang-rt/include/flang-rt/buffer.h
+++ b/flang-rt/include/flang-rt/buffer.h
@@ -221,4 +221,4 @@ template <typename STORE, std::size_t minBuffer = 65536> class FileFrame {
   bool dirty_{false};
 };
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_BUFFER_H_ */
+#endif // FLANG_RT_BUFFER_H_
diff --git a/flang-rt/include/flang-rt/connection.h b/flang-rt/include/flang-rt/connection.h
index 7f594deee69c6..550ddb15c7236 100644
--- a/flang-rt/include/flang-rt/connection.h
+++ b/flang-rt/include/flang-rt/connection.h
@@ -124,4 +124,4 @@ class SavedPosition {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_CONNECTION_H_ */
+#endif // FLANG_RT_CONNECTION_H_
diff --git a/flang-rt/include/flang-rt/derived.h b/flang-rt/include/flang-rt/derived.h
index 797a089e767c4..d65fb75172495 100644
--- a/flang-rt/include/flang-rt/derived.h
+++ b/flang-rt/include/flang-rt/derived.h
@@ -48,4 +48,4 @@ RT_API_ATTRS void Destroy(const Descriptor &, bool finalize,
 RT_API_ATTRS bool HasDynamicComponent(const Descriptor &);
 
 } // namespace Fortran::runtime
-#endif /* FLANG_RT_DERIVED_H_ */
+#endif // FLANG_RT_DERIVED_H_
diff --git a/flang-rt/include/flang-rt/descriptor.h b/flang-rt/include/flang-rt/descriptor.h
index 27f80bec4ba93..f97b8443425dc 100644
--- a/flang-rt/include/flang-rt/descriptor.h
+++ b/flang-rt/include/flang-rt/descriptor.h
@@ -482,4 +482,4 @@ class alignas(Descriptor) StaticDescriptor {
 };
 
 } // namespace Fortran::runtime
-#endif /* FLANG_RT_DESCRIPTOR_H_ */
+#endif // FLANG_RT_DESCRIPTOR_H_
diff --git a/flang-rt/include/flang-rt/emit-encoded.h b/flang-rt/include/flang-rt/emit-encoded.h
index f3cb7a9f790e4..279f751daff2c 100644
--- a/flang-rt/include/flang-rt/emit-encoded.h
+++ b/flang-rt/include/flang-rt/emit-encoded.h
@@ -114,4 +114,4 @@ RT_API_ATTRS bool EmitRepeated(CONTEXT &to, char ch, std::size_t n) {
 }
 
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_EMIT_ENCODED_H_ */
+#endif // FLANG_RT_EMIT_ENCODED_H_
diff --git a/flang-rt/include/flang-rt/environment.h b/flang-rt/include/flang-rt/environment.h
index b7597ad88af62..7fa3060768502 100644
--- a/flang-rt/include/flang-rt/environment.h
+++ b/flang-rt/include/flang-rt/environment.h
@@ -67,4 +67,4 @@ RT_OFFLOAD_VAR_GROUP_END
 
 } // namespace Fortran::runtime
 
-#endif /* FLANG_RT_ENVIRONMENT_H_ */
+#endif // FLANG_RT_ENVIRONMENT_H_
diff --git a/flang-rt/include/flang-rt/file.h b/flang-rt/include/flang-rt/file.h
index ca95156e1fba4..3ab21c655a38f 100644
--- a/flang-rt/include/flang-rt/file.h
+++ b/flang-rt/include/flang-rt/file.h
@@ -113,4 +113,4 @@ RT_API_ATTRS bool MayWrite(const char *path);
 RT_API_ATTRS bool MayReadAndWrite(const char *path);
 RT_API_ATTRS std::int64_t SizeInBytes(const char *path);
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_FILE_H_ */
+#endif // FLANG_RT_FILE_H_
diff --git a/flang-rt/include/flang-rt/format-implementation.h b/flang-rt/include/flang-rt/format-implementation.h
index 52f265d06f9bf..6a2e1078ab350 100644
--- a/flang-rt/include/flang-rt/format-implementation.h
+++ b/flang-rt/include/flang-rt/format-implementation.h
@@ -601,4 +601,4 @@ RT_API_ATTRS void FormatControl<CONTEXT>::Finish(Context &context) {
   }
 }
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_FORMAT_IMPLEMENTATION_H_ */
+#endif // FLANG_RT_FORMAT_IMPLEMENTATION_H_
diff --git a/flang-rt/include/flang-rt/format.h b/flang-rt/include/flang-rt/format.h
index d81241e41877c..09e151a2e98ca 100644
--- a/flang-rt/include/flang-rt/format.h
+++ b/flang-rt/include/flang-rt/format.h
@@ -201,4 +201,4 @@ template <typename CONTEXT> class FormatControl {
   Iteration stack_[maxMaxHeight];
 };
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_FORMAT_H_ */
+#endif // FLANG_RT_FORMAT_H_
diff --git a/flang-rt/include/flang-rt/internal-unit.h b/flang-rt/include/flang-rt/internal-unit.h
index 21e64b5624196..946d69080e611 100644
--- a/flang-rt/include/flang-rt/internal-unit.h
+++ b/flang-rt/include/flang-rt/internal-unit.h
@@ -56,4 +56,4 @@ template <Direction DIR> class InternalDescriptorUnit : public ConnectionState {
 extern template class InternalDescriptorUnit<Direction::Output>;
 extern template class InternalDescriptorUnit<Direction::Input>;
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_INTERNAL_UNIT_H_ */
+#endif // FLANG_RT_INTERNAL_UNIT_H_
diff --git a/flang-rt/include/flang-rt/io-error.h b/flang-rt/include/flang-rt/io-error.h
index c74c08970f94a..6b5c0f9f39019 100644
--- a/flang-rt/include/flang-rt/io-error.h
+++ b/flang-rt/include/flang-rt/io-error.h
@@ -80,4 +80,4 @@ class IoErrorHandler : public Terminator {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_IO_ERROR_H_ */
+#endif // FLANG_RT_IO_ERROR_H_
diff --git a/flang-rt/include/flang-rt/io-stmt.h b/flang-rt/include/flang-rt/io-stmt.h
index 87fd93c353d76..7efab320e5e1a 100644
--- a/flang-rt/include/flang-rt/io-stmt.h
+++ b/flang-rt/include/flang-rt/io-stmt.h
@@ -791,4 +791,4 @@ class ErroneousIoStatementState : public IoStatementBase {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_IO_STMT_H_ */
+#endif // FLANG_RT_IO_STMT_H_
diff --git a/flang-rt/include/flang-rt/lock.h b/flang-rt/include/flang-rt/lock.h
index f57e97184edd5..1b09434d26f4f 100644
--- a/flang-rt/include/flang-rt/lock.h
+++ b/flang-rt/include/flang-rt/lock.h
@@ -113,4 +113,4 @@ class CriticalSection {
 };
 } // namespace Fortran::runtime
 
-#endif /* FLANG_RT_LOCK_H_ */
+#endif // FLANG_RT_LOCK_H_
diff --git a/flang-rt/include/flang-rt/memory.h b/flang-rt/include/flang-rt/memory.h
index afbb1b34c1d2c..64db30baf2806 100644
--- a/flang-rt/include/flang-rt/memory.h
+++ b/flang-rt/include/flang-rt/memory.h
@@ -170,4 +170,4 @@ template <typename A> struct Allocator {
 };
 } // namespace Fortran::runtime
 
-#endif /* FLANG_RT_MEMORY_H_ */
+#endif // FLANG_RT_MEMORY_H_
diff --git a/flang-rt/include/flang-rt/namelist.h b/flang-rt/include/flang-rt/namelist.h
index 5757bfb3b7109..2ae93ca9c2050 100644
--- a/flang-rt/include/flang-rt/namelist.h
+++ b/flang-rt/include/flang-rt/namelist.h
@@ -51,4 +51,4 @@ class NamelistGroup {
 RT_API_ATTRS bool IsNamelistNameOrSlash(IoStatementState &);
 
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_NAMELIST_H_ */
+#endif // FLANG_RT_NAMELIST_H_
diff --git a/flang-rt/include/flang-rt/non-tbp-dio.h b/flang-rt/include/flang-rt/non-tbp-dio.h
index 58ed29ba7a102..1088257b72f59 100644
--- a/flang-rt/include/flang-rt/non-tbp-dio.h
+++ b/flang-rt/include/flang-rt/non-tbp-dio.h
@@ -53,4 +53,4 @@ struct NonTbpDefinedIoTable {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_NON_TBP_DIO_H_ */
+#endif // FLANG_RT_NON_TBP_DIO_H_
diff --git a/flang-rt/include/flang-rt/numeric-templates.h b/flang-rt/include/flang-rt/numeric-templates.h
index 7019151c3a207..a1475923ff3b1 100644
--- a/flang-rt/include/flang-rt/numeric-templates.h
+++ b/flang-rt/include/flang-rt/numeric-templates.h
@@ -368,4 +368,4 @@ template <typename T> inline RT_API_ATTRS T ErfcScaled(T arg) {
 
 } // namespace Fortran::runtime
 
-#endif /* FLANG_RT_NUMERIC_TEMPLATES_H_ */
+#endif // FLANG_RT_NUMERIC_TEMPLATES_H_
diff --git a/flang-rt/include/flang-rt/random-templates.h b/flang-rt/include/flang-rt/random-templates.h
index f320f2cd328f5..00542bd5b2553 100644
--- a/flang-rt/include/flang-rt/random-templates.h
+++ b/flang-rt/include/flang-rt/random-templates.h
@@ -108,4 +108,4 @@ inline void GenerateUnsigned(const Descriptor &harvest) {
 
 } // namespace Fortran::runtime::random
 
-#endif /* FLANG_RT_RANDOM_TEMPLATES_H_ */
+#endif // FLANG_RT_RANDOM_TEMPLATES_H_
diff --git a/flang-rt/include/flang-rt/reduction-templates.h b/flang-rt/include/flang-rt/reduction-templates.h
index 513b3e4478498..d6b3c24920cf9 100644
--- a/flang-rt/include/flang-rt/reduction-templates.h
+++ b/flang-rt/include/flang-rt/reduction-templates.h
@@ -416,4 +416,4 @@ template <int KIND> struct Norm2Helper {
 };
 
 } // namespace Fortran::runtime
-#endif /* FLANG_RT_REDUCTION_TEMPLATES_H_ */
+#endif // FLANG_RT_REDUCTION_TEMPLATES_H_
diff --git a/flang-rt/include/flang-rt/stat.h b/flang-rt/include/flang-rt/stat.h
index 95ae286a03b49..a6824f4803561 100644
--- a/flang-rt/include/flang-rt/stat.h
+++ b/flang-rt/include/flang-rt/stat.h
@@ -60,4 +60,4 @@ RT_API_ATTRS int ToErrmsg(const Descriptor *errmsg, int stat); // returns stat
 RT_API_ATTRS int ReturnError(Terminator &, int stat,
     const Descriptor *errmsg = nullptr, bool hasStat = false);
 } // namespace Fortran::runtime
-#endif /* FLANG_RT_STAT_H_ */
+#endif // FLANG_RT_STAT_H_
diff --git a/flang-rt/include/flang-rt/terminator.h b/flang-rt/include/flang-rt/terminator.h
index 800ed6f3755b7..c2a4e1f64eb66 100644
--- a/flang-rt/include/flang-rt/terminator.h
+++ b/flang-rt/include/flang-rt/terminator.h
@@ -121,4 +121,4 @@ namespace Fortran::runtime::io {
 RT_API_ATTRS void FlushOutputOnCrash(const Terminator &);
 }
 
-#endif /* FLANG_RT_TERMINATOR_H_ */
+#endif // FLANG_RT_TERMINATOR_H_
diff --git a/flang-rt/include/flang-rt/tools.h b/flang-rt/include/flang-rt/tools.h
index 38804a1f40991..3503c49308e4d 100644
--- a/flang-rt/include/flang-rt/tools.h
+++ b/flang-rt/include/flang-rt/tools.h
@@ -570,4 +570,4 @@ RT_API_ATTRS void CreatePartialReductionResult(Descriptor &result,
     const char *intrinsic, TypeCode);
 
 } // namespace Fortran::runtime
-#endif /* FLANG_RT_TOOLS_H_ */
+#endif // FLANG_RT_TOOLS_H_
diff --git a/flang-rt/include/flang-rt/type-code.h b/flang-rt/include/flang-rt/type-code.h
index 1d057481261a1..a3b79462887c1 100644
--- a/flang-rt/include/flang-rt/type-code.h
+++ b/flang-rt/include/flang-rt/type-code.h
@@ -75,4 +75,4 @@ class TypeCode {
   ISO::CFI_type_t raw_{CFI_type_other};
 };
 } // namespace Fortran::runtime
-#endif /* FLANG_RT_TYPE_CODE_H_ */
+#endif // FLANG_RT_TYPE_CODE_H_
diff --git a/flang-rt/include/flang-rt/type-info.h b/flang-rt/include/flang-rt/type-info.h
index 52e208c93fe25..dc5cd98d7523f 100644
--- a/flang-rt/include/flang-rt/type-info.h
+++ b/flang-rt/include/flang-rt/type-info.h
@@ -321,4 +321,4 @@ class DerivedType {
 };
 
 } // namespace Fortran::runtime::typeInfo
-#endif /* FLANG_RT_TYPE_INFO_H_ */
+#endif // FLANG_RT_TYPE_INFO_H_
diff --git a/flang-rt/include/flang-rt/utf.h b/flang-rt/include/flang-rt/utf.h
index 4d1e23b9ccb94..648937ca14f16 100644
--- a/flang-rt/include/flang-rt/utf.h
+++ b/flang-rt/include/flang-rt/utf.h
@@ -70,4 +70,4 @@ RT_API_ATTRS Fortran::common::optional<char32_t> DecodeUTF8(const char *);
 RT_API_ATTRS std::size_t EncodeUTF8(char *, char32_t);
 
 } // namespace Fortran::runtime
-#endif /* FLANG_RT_UTF_H_ */
+#endif // FLANG_RT_UTF_H_
diff --git a/flang-rt/lib/FortranFloat128Math/complex-math.h b/flang-rt/lib/FortranFloat128Math/complex-math.h
index 24ccc794fd144..d22598d52e832 100644
--- a/flang-rt/lib/FortranFloat128Math/complex-math.h
+++ b/flang-rt/lib/FortranFloat128Math/complex-math.h
@@ -59,4 +59,4 @@
 #error "Float128Math build with glibc>=2.26 is unsupported yet"
 #endif
 
-#endif /* FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_ */
+#endif // FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_
diff --git a/flang-rt/lib/FortranFloat128Math/math-entries.h b/flang-rt/lib/FortranFloat128Math/math-entries.h
index b9821163d94fb..72b12a1645c7d 100644
--- a/flang-rt/lib/FortranFloat128Math/math-entries.h
+++ b/flang-rt/lib/FortranFloat128Math/math-entries.h
@@ -232,4 +232,4 @@ DEFINE_SIMPLE_ALIAS(Yn, ynl)
 
 } // namespace Fortran::runtime
 
-#endif /* FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_ */
+#endif // FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_
diff --git a/flang-rt/lib/FortranFloat128Math/numeric-template-specs.h b/flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
index fc912f75075a7..e618902b03adc 100644
--- a/flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
+++ b/flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
@@ -52,4 +52,4 @@ template <> struct SQRTTy<F128Type> {
 };
 
 } // namespace Fortran::runtime
-#endif /* FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_ */
+#endif // FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
diff --git a/flang/runtime/CUDA/init.cpp b/flang-rt/lib/flang_rt/CUDA/init.cpp
similarity index 82%
rename from flang/runtime/CUDA/init.cpp
rename to flang-rt/lib/flang_rt/CUDA/init.cpp
index 2bffce842b952..f2d47d258519e 100644
--- a/flang/runtime/CUDA/init.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/init.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/init.cpp ---------------------------------------------===//
+//===-- lib/flang_rt/CUDA/init.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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/init.h"
-#include "../environment.h"
-#include "../terminator.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 
 #include "cuda_runtime.h"
diff --git a/flang-rt/lib/flang_rt/ISO_Fortran_util.h b/flang-rt/lib/flang_rt/ISO_Fortran_util.h
index 6128faba5bcea..9d4a907e1adde 100644
--- a/flang-rt/lib/flang_rt/ISO_Fortran_util.h
+++ b/flang-rt/lib/flang_rt/ISO_Fortran_util.h
@@ -99,4 +99,4 @@ static inline RT_API_ATTRS void EstablishDescriptor(CFI_cdesc_t *descriptor,
   }
 }
 } // namespace Fortran::ISO
-#endif /* FLANG_RT_ISO_FORTRAN_UTIL_H_ */
+#endif // FLANG_RT_ISO_FORTRAN_UTIL_H_
diff --git a/flang-rt/lib/flang_rt/complex-reduction.h b/flang-rt/lib/flang_rt/complex-reduction.h
index 2678dbf4e6472..45614ea660573 100644
--- a/flang-rt/lib/flang_rt/complex-reduction.h
+++ b/flang-rt/lib/flang_rt/complex-reduction.h
@@ -155,4 +155,4 @@ void RTNAME(ReduceComplex16DimValue)(
     REDUCE_DIM_ARGS(CFloat128ComplexType, CFloat128ComplexType_value_op));
 #endif
 
-#endif /* FLANG_RT_COMPLEX_REDUCTION_H_ */
+#endif // FLANG_RT_COMPLEX_REDUCTION_H_
diff --git a/flang-rt/lib/flang_rt/copy.h b/flang-rt/lib/flang_rt/copy.h
index 468c2439baf61..f4abac323196b 100644
--- a/flang-rt/lib/flang_rt/copy.h
+++ b/flang-rt/lib/flang_rt/copy.h
@@ -22,4 +22,4 @@ RT_API_ATTRS void CopyElement(const Descriptor &to, const SubscriptValue toAt[],
     const Descriptor &from, const SubscriptValue fromAt[], Terminator &);
 
 } // namespace Fortran::runtime
-#endif /* FLANG_RT_COPY_H_ */
+#endif // FLANG_RT_COPY_H_
diff --git a/flang-rt/lib/flang_rt/descriptor-io.h b/flang-rt/lib/flang_rt/descriptor-io.h
index 763ebb1735752..97bedce247d83 100644
--- a/flang-rt/lib/flang_rt/descriptor-io.h
+++ b/flang-rt/lib/flang_rt/descriptor-io.h
@@ -626,4 +626,4 @@ static RT_API_ATTRS bool DescriptorIO(IoStatementState &io,
   return false;
 }
 } // namespace Fortran::runtime::io::descr
-#endif /* FLANG_RT_DESCRIPTOR_IO_H_ */
+#endif // FLANG_RT_DESCRIPTOR_IO_H_
diff --git a/flang-rt/lib/flang_rt/edit-input.h b/flang-rt/lib/flang_rt/edit-input.h
index 2d6a3f241a005..fdee0f0e1131e 100644
--- a/flang-rt/lib/flang_rt/edit-input.h
+++ b/flang-rt/lib/flang_rt/edit-input.h
@@ -50,4 +50,4 @@ extern template RT_API_ATTRS bool EditCharacterInput(
     IoStatementState &, const DataEdit &, char32_t *, std::size_t);
 
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_EDIT_INPUT_H_ */
+#endif // FLANG_RT_EDIT_INPUT_H_
diff --git a/flang-rt/lib/flang_rt/edit-output.h b/flang-rt/lib/flang_rt/edit-output.h
index 59f5d820c4ad5..729f4400bd631 100644
--- a/flang-rt/lib/flang_rt/edit-output.h
+++ b/flang-rt/lib/flang_rt/edit-output.h
@@ -138,4 +138,4 @@ extern template class RealOutputEditing<10>;
 extern template class RealOutputEditing<16>;
 
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_EDIT_OUTPUT_H_ */
+#endif // FLANG_RT_EDIT_OUTPUT_H_
diff --git a/flang-rt/lib/flang_rt/io-api-common.h b/flang-rt/lib/flang_rt/io-api-common.h
index ba8c7177c2811..5e480fdef3483 100644
--- a/flang-rt/lib/flang_rt/io-api-common.h
+++ b/flang-rt/lib/flang_rt/io-api-common.h
@@ -94,4 +94,4 @@ RT_API_ATTRS Cookie BeginExternalListIO(
 }
 
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_IO_API_COMMON_H_ */
+#endif // FLANG_RT_IO_API_COMMON_H_
diff --git a/flang-rt/lib/flang_rt/stack.h b/flang-rt/lib/flang_rt/stack.h
index 88cd276456fbc..6f37282f00932 100644
--- a/flang-rt/lib/flang_rt/stack.h
+++ b/flang-rt/lib/flang_rt/stack.h
@@ -133,4 +133,4 @@ template <typename T, unsigned N = 0> class Stack : public StackStorage<T, N> {
   Terminator &terminator_;
 };
 } // namespace Fortran::runtime
-#endif /* FLANG_RT_STACK_H_ */
+#endif // FLANG_RT_STACK_H_
diff --git a/flang-rt/lib/flang_rt/unit-map.h b/flang-rt/lib/flang_rt/unit-map.h
index 6f7eb692b970a..64233008b6630 100644
--- a/flang-rt/lib/flang_rt/unit-map.h
+++ b/flang-rt/lib/flang_rt/unit-map.h
@@ -100,4 +100,4 @@ class UnitMap {
   int emergencyNewUnit_{maxNewUnits_}; // not recycled
 };
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_UNIT_MAP_H_ */
+#endif // FLANG_RT_UNIT_MAP_H_
diff --git a/flang-rt/lib/flang_rt/unit.h b/flang-rt/lib/flang_rt/unit.h
index 3b20c9870897a..a5fb7fb31691f 100644
--- a/flang-rt/lib/flang_rt/unit.h
+++ b/flang-rt/lib/flang_rt/unit.h
@@ -291,4 +291,4 @@ class ChildIo {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FLANG_RT_UNIT_H_ */
+#endif // FLANG_RT_UNIT_H_
diff --git a/flang-rt/unittests/Runtime/tools.h b/flang-rt/unittests/Runtime/tools.h
index ff39d7ccb2a24..146aae659c338 100644
--- a/flang-rt/unittests/Runtime/tools.h
+++ b/flang-rt/unittests/Runtime/tools.h
@@ -54,4 +54,4 @@ static OwningPtr<Descriptor> MakeArray(const std::vector<int> &shape,
 }
 
 } // namespace Fortran::runtime
-#endif /* FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_ */
+#endif // FLANG_RT_UNITTESTS_RUNTIME_TOOLS_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 14/24] 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 8cc66ddbbbb0e..23c6e790791fb 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 15/24] 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 361cf41544b06..a213a055956ce 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 87111e18114f5..f6ff58d07e822 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 1f178772067ed..c9f65eb73fef0 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 e8dc3de3577db..97744f0bee069 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 ffde50b6f481e..e422a31a0b402 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 6c147a56894c8..008c57937e23b 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 21482c7be21af..93492c8b767c3 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 a163b4f4ed67d..387d4b2e62e0f 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 213fc462ac2b1..b61948718a5e3 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 ea78103d78239..d7d1471535db8 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 3e32daba52a81..1186d4b429de4 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 a20f77e427ce6..1fd3bf22a83cf 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 d65193be05ab5..3c382d16a21cd 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 facbd23161057..75544098d47ab 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 e8e8099d4eaf7..3fac8717e9bd9 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 d9160e1971250..e195bdde6d2c9 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 5dc89fe45c8cc..0b6eff8043247 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 dabac56d602d1..641c73912c4d1 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 17ed10fa0615d..dc23be6462376 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 08ba586e1226d..c6266f3976f7c 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 9e19b2cdfbb90..2278d61febcb1 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 a60b43d422878..f3743be49b015 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 38888e32e6ed8..860b2664d623b 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 e188dfb503c1a..baaf06fa021a2 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 16/24] 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 c03029f0f3c26..4fcf8f9d478d8 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 8e8b33897eebd68fb5f4d7819eea25b573006120 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 3 Feb 2025 23:42:46 +0100
Subject: [PATCH 17/24] Rename to flang_rt.runtime, flang_rt.quadmath,
 flang_rt.cuda

---
 .../ExternalHelloWorld/external-hello.cpp     |   8 ++
 .../flang-rt/{CUDA => cuda}/allocator.h       |   2 +-
 .../{ => runtime}/allocator-registry.h        |   8 +-
 .../{ => runtime}/array-constructor.h         |   8 +-
 .../flang-rt/{ => runtime}/assign-impl.h      |   8 +-
 .../include/flang-rt/{ => runtime}/buffer.h   |   8 +-
 .../flang-rt/{ => runtime}/connection.h       |   8 +-
 .../include/flang-rt/{ => runtime}/derived.h  |   8 +-
 .../flang-rt/{ => runtime}/descriptor.h       |   8 +-
 .../flang-rt/{ => runtime}/emit-encoded.h     |   8 +-
 .../flang-rt/{ => runtime}/environment.h      |   8 +-
 .../include/flang-rt/{ => runtime}/file.h     |   8 +-
 .../{ => runtime}/format-implementation.h     |   8 +-
 .../include/flang-rt/{ => runtime}/format.h   |   8 +-
 .../flang-rt/{ => runtime}/internal-unit.h    |   8 +-
 .../include/flang-rt/{ => runtime}/io-error.h |   8 +-
 .../include/flang-rt/{ => runtime}/io-stmt.h  |   8 +-
 .../include/flang-rt/{ => runtime}/lock.h     |   8 +-
 .../include/flang-rt/{ => runtime}/memory.h   |   8 +-
 .../include/flang-rt/{ => runtime}/namelist.h |   8 +-
 .../flang-rt/{ => runtime}/non-tbp-dio.h      |   8 +-
 .../{ => runtime}/numeric-templates.h         |   8 +-
 .../flang-rt/{ => runtime}/random-templates.h |   8 +-
 .../{ => runtime}/reduction-templates.h       |   8 +-
 .../include/flang-rt/{ => runtime}/stat.h     |   8 +-
 .../flang-rt/{ => runtime}/terminator.h       |   8 +-
 .../include/flang-rt/{ => runtime}/tools.h    |  10 +-
 .../flang-rt/{ => runtime}/type-code.h        |   8 +-
 .../flang-rt/{ => runtime}/type-info.h        |   8 +-
 flang-rt/include/flang-rt/{ => runtime}/utf.h |   8 +-
 .../{flang_rt/CUDA => cuda}/allocatable.cpp   |  10 +-
 .../lib/{flang_rt/CUDA => cuda}/allocator.cpp |  14 +--
 .../{flang_rt/CUDA => cuda}/descriptor.cpp    |   8 +-
 flang-rt/lib/{flang_rt/CUDA => cuda}/init.cpp |   6 +-
 .../lib/{flang_rt/CUDA => cuda}/kernel.cpp    |   4 +-
 .../CUDA => cuda}/memmove-function.cpp        |   4 +-
 .../lib/{flang_rt/CUDA => cuda}/memory.cpp    |   6 +-
 .../lib/{flang_rt/CUDA => cuda}/pointer.cpp   |  10 +-
 .../{flang_rt/CUDA => cuda}/registration.cpp  |   4 +-
 .../acos.cpp                                  |   2 +-
 .../acosh.cpp                                 |   2 +-
 .../asin.cpp                                  |   2 +-
 .../asinh.cpp                                 |   2 +-
 .../atan.cpp                                  |   2 +-
 .../atan2.cpp                                 |   2 +-
 .../atanh.cpp                                 |   2 +-
 .../ceil.cpp                                  |   2 +-
 .../complex-math.c                            |   2 +-
 .../complex-math.h                            |   8 +-
 .../{FortranFloat128Math => quadmath}/cos.cpp |   2 +-
 .../cosh.cpp                                  |   2 +-
 .../{FortranFloat128Math => quadmath}/erf.cpp |   2 +-
 .../erfc.cpp                                  |   2 +-
 .../{FortranFloat128Math => quadmath}/exp.cpp |   2 +-
 .../exponent.cpp                              |   2 +-
 .../floor.cpp                                 |   2 +-
 .../{FortranFloat128Math => quadmath}/fma.cpp |   2 +-
 .../fraction.cpp                              |   2 +-
 .../hypot.cpp                                 |   2 +-
 .../{FortranFloat128Math => quadmath}/j0.cpp  |   2 +-
 .../{FortranFloat128Math => quadmath}/j1.cpp  |   2 +-
 .../{FortranFloat128Math => quadmath}/jn.cpp  |   2 +-
 .../lgamma.cpp                                |   2 +-
 .../llround.cpp                               |   2 +-
 .../{FortranFloat128Math => quadmath}/log.cpp |   2 +-
 .../log10.cpp                                 |   2 +-
 .../lround.cpp                                |   2 +-
 .../math-entries.h                            |  12 +--
 .../mod-real.cpp                              |   2 +-
 .../modulo-real.cpp                           |   2 +-
 .../nearbyint.cpp                             |   2 +-
 .../nearest.cpp                               |   2 +-
 .../norm2.cpp                                 |   4 +-
 .../numeric-template-specs.h                  |  10 +-
 .../{FortranFloat128Math => quadmath}/pow.cpp |   2 +-
 .../random.cpp                                |   4 +-
 .../remainder.cpp                             |   2 +-
 .../round.cpp                                 |   2 +-
 .../rrspacing.cpp                             |   2 +-
 .../scale.cpp                                 |   2 +-
 .../set-exponent.cpp                          |   2 +-
 .../{FortranFloat128Math => quadmath}/sin.cpp |   2 +-
 .../sinh.cpp                                  |   2 +-
 .../spacing.cpp                               |   2 +-
 .../sqrt.cpp                                  |   2 +-
 .../{FortranFloat128Math => quadmath}/tan.cpp |   2 +-
 .../tanh.cpp                                  |   2 +-
 .../tgamma.cpp                                |   2 +-
 .../trunc.cpp                                 |   2 +-
 .../{FortranFloat128Math => quadmath}/y0.cpp  |   2 +-
 .../{FortranFloat128Math => quadmath}/y1.cpp  |   2 +-
 .../{FortranFloat128Math => quadmath}/yn.cpp  |   2 +-
 .../ISO_Fortran_binding.cpp                   |   8 +-
 .../{flang_rt => runtime}/ISO_Fortran_util.h  |  14 +--
 .../lib/{flang_rt => runtime}/allocatable.cpp |  14 +--
 .../allocator-registry.cpp                    |   6 +-
 .../array-constructor.cpp                     |  14 +--
 flang-rt/lib/{flang_rt => runtime}/assign.cpp |  16 +--
 flang-rt/lib/{flang_rt => runtime}/buffer.cpp |   4 +-
 .../lib/{flang_rt => runtime}/character.cpp   |   8 +-
 .../lib/{flang_rt => runtime}/command.cpp     |  12 +--
 .../{flang_rt => runtime}/complex-powi.cpp    |   2 +-
 .../{flang_rt => runtime}/complex-reduction.c |   0
 .../{flang_rt => runtime}/complex-reduction.h |   8 +-
 .../lib/{flang_rt => runtime}/connection.cpp  |   8 +-
 flang-rt/lib/{flang_rt => runtime}/copy.cpp   |   8 +-
 flang-rt/lib/{flang_rt => runtime}/copy.h     |  10 +-
 .../lib/{flang_rt => runtime}/derived-api.cpp |  12 +--
 .../lib/{flang_rt => runtime}/derived.cpp     |  14 +--
 .../{flang_rt => runtime}/descriptor-io.cpp   |   2 +-
 .../lib/{flang_rt => runtime}/descriptor-io.h |  18 ++--
 .../lib/{flang_rt => runtime}/descriptor.cpp  |  16 +--
 .../lib/{flang_rt => runtime}/dot-product.cpp |   8 +-
 .../lib/{flang_rt => runtime}/edit-input.cpp  |   6 +-
 .../lib/{flang_rt => runtime}/edit-input.h    |  12 +--
 .../lib/{flang_rt => runtime}/edit-output.cpp |   6 +-
 .../lib/{flang_rt => runtime}/edit-output.h   |  12 +--
 .../environment-default-list.h                |   0
 .../lib/{flang_rt => runtime}/environment.cpp |   6 +-
 .../lib/{flang_rt => runtime}/exceptions.cpp  |   4 +-
 .../lib/{flang_rt => runtime}/execute.cpp     |  12 +--
 .../lib/{flang_rt => runtime}/extensions.cpp  |   8 +-
 .../{flang_rt => runtime}/external-unit.cpp   |   8 +-
 .../lib/{flang_rt => runtime}/extrema.cpp     |   4 +-
 flang-rt/lib/{flang_rt => runtime}/file.cpp   |   8 +-
 .../lib/{flang_rt => runtime}/findloc.cpp     |   4 +-
 flang-rt/lib/{flang_rt => runtime}/format.cpp |   4 +-
 .../lib/{flang_rt => runtime}/inquiry.cpp     |   8 +-
 .../{flang_rt => runtime}/internal-unit.cpp   |   8 +-
 .../lib/{flang_rt => runtime}/io-api-common.h |  12 +--
 .../{flang_rt => runtime}/io-api-minimal.cpp  |  12 +--
 flang-rt/lib/{flang_rt => runtime}/io-api.cpp |  16 +--
 .../lib/{flang_rt => runtime}/io-error.cpp    |   6 +-
 .../lib/{flang_rt => runtime}/io-stmt.cpp     |  16 +--
 flang-rt/lib/{flang_rt => runtime}/iostat.cpp |   2 +-
 flang-rt/lib/{flang_rt => runtime}/main.cpp   |   6 +-
 .../matmul-transpose.cpp                      |   8 +-
 flang-rt/lib/{flang_rt => runtime}/matmul.cpp |   8 +-
 flang-rt/lib/{flang_rt => runtime}/memory.cpp |   8 +-
 .../{flang_rt => runtime}/misc-intrinsic.cpp  |   8 +-
 .../lib/{flang_rt => runtime}/namelist.cpp    |   8 +-
 .../lib/{flang_rt => runtime}/non-tbp-dio.cpp |   6 +-
 .../lib/{flang_rt => runtime}/numeric.cpp     |   8 +-
 .../lib/{flang_rt => runtime}/pointer.cpp     |  16 +--
 .../lib/{flang_rt => runtime}/product.cpp     |   4 +-
 .../lib/{flang_rt => runtime}/pseudo-unit.cpp |   6 +-
 flang-rt/lib/{flang_rt => runtime}/ragged.cpp |   4 +-
 flang-rt/lib/{flang_rt => runtime}/random.cpp |  10 +-
 flang-rt/lib/{flang_rt => runtime}/reduce.cpp |  10 +-
 .../lib/{flang_rt => runtime}/reduction.cpp   |   6 +-
 flang-rt/lib/{flang_rt => runtime}/stack.h    |  12 +--
 flang-rt/lib/{flang_rt => runtime}/stat.cpp   |  10 +-
 flang-rt/lib/{flang_rt => runtime}/stop.cpp   |  10 +-
 flang-rt/lib/{flang_rt => runtime}/sum.cpp    |   4 +-
 .../lib/{flang_rt => runtime}/support.cpp     |   6 +-
 .../{flang_rt => runtime}/temporary-stack.cpp |   8 +-
 .../lib/{flang_rt => runtime}/terminator.cpp  |   4 +-
 .../{flang_rt => runtime}/time-intrinsic.cpp  |   8 +-
 flang-rt/lib/{flang_rt => runtime}/tools.cpp  |   6 +-
 .../transformational.cpp                      |   8 +-
 .../lib/{flang_rt => runtime}/type-code.cpp   |   4 +-
 .../lib/{flang_rt => runtime}/type-info.cpp   |   8 +-
 .../lib/{flang_rt => runtime}/unit-map.cpp    |   2 +-
 flang-rt/lib/{flang_rt => runtime}/unit-map.h |  12 +--
 flang-rt/lib/{flang_rt => runtime}/unit.cpp   |   8 +-
 flang-rt/lib/{flang_rt => runtime}/unit.h     |  30 +++---
 flang-rt/lib/{flang_rt => runtime}/utf.cpp    |   4 +-
 flang-rt/test/Runtime/no-cpp-dep.c            |   2 +-
 .../Evaluate/ISO-Fortran-binding.cpp          |   2 +-
 flang-rt/unittests/Evaluate/reshape.cpp       |   2 +-
 flang-rt/unittests/Runtime/Allocatable.cpp    |   2 +-
 .../unittests/Runtime/ArrayConstructor.cpp    |   6 +-
 flang-rt/unittests/Runtime/BufferTest.cpp     |   2 +-
 .../unittests/Runtime/CUDA/Allocatable.cpp    |   8 +-
 .../unittests/Runtime/CUDA/AllocatorCUF.cpp   |   8 +-
 flang-rt/unittests/Runtime/CUDA/Memory.cpp    |   6 +-
 flang-rt/unittests/Runtime/CharacterTest.cpp  |   2 +-
 flang-rt/unittests/Runtime/CommandTest.cpp    |   2 +-
 .../unittests/Runtime/CrashHandlerFixture.cpp |   2 +-
 flang-rt/unittests/Runtime/Derived.cpp        |   4 +-
 flang-rt/unittests/Runtime/ExternalIOTest.cpp |   2 +-
 flang-rt/unittests/Runtime/Format.cpp         |   6 +-
 flang-rt/unittests/Runtime/Inquiry.cpp        |   2 +-
 flang-rt/unittests/Runtime/ListInputTest.cpp  |   4 +-
 .../unittests/Runtime/LogicalFormatTest.cpp   |   2 +-
 flang-rt/unittests/Runtime/Matmul.cpp         |   4 +-
 .../unittests/Runtime/MatmulTranspose.cpp     |   4 +-
 flang-rt/unittests/Runtime/MiscIntrinsic.cpp  |   2 +-
 flang-rt/unittests/Runtime/Namelist.cpp       |   4 +-
 .../unittests/Runtime/NumericalFormatTest.cpp |   2 +-
 flang-rt/unittests/Runtime/Pointer.cpp        |   4 +-
 flang-rt/unittests/Runtime/Random.cpp         |   4 +-
 flang-rt/unittests/Runtime/Reduction.cpp      |   4 +-
 .../unittests/Runtime/RuntimeCrashTest.cpp    |   2 +-
 flang-rt/unittests/Runtime/Stop.cpp           |   2 +-
 flang-rt/unittests/Runtime/Support.cpp        |   2 +-
 flang-rt/unittests/Runtime/TemporaryStack.cpp |   6 +-
 .../unittests/Runtime/Transformational.cpp    |   2 +-
 flang-rt/unittests/Runtime/tools.h            |   4 +-
 .../ExternalHelloWorld/CMakeLists.txt         |   2 +-
 flang/runtime/CMakeLists.txt                  |   7 +-
 flang/runtime/CUDA/CMakeLists.txt             |   2 +-
 flang/runtime/Float128Math/CMakeLists.txt     | 101 +++++++++---------
 203 files changed, 651 insertions(+), 643 deletions(-)
 rename {flang => flang-rt}/examples/ExternalHelloWorld/external-hello.cpp (80%)
 rename flang-rt/include/flang-rt/{CUDA => cuda}/allocator.h (93%)
 rename flang-rt/include/flang-rt/{ => runtime}/allocator-registry.h (87%)
 rename flang-rt/include/flang-rt/{ => runtime}/array-constructor.h (90%)
 rename flang-rt/include/flang-rt/{ => runtime}/assign-impl.h (85%)
 rename flang-rt/include/flang-rt/{ => runtime}/buffer.h (97%)
 rename flang-rt/include/flang-rt/{ => runtime}/connection.h (96%)
 rename flang-rt/include/flang-rt/{ => runtime}/derived.h (91%)
 rename flang-rt/include/flang-rt/{ => runtime}/descriptor.h (98%)
 rename flang-rt/include/flang-rt/{ => runtime}/emit-encoded.h (94%)
 rename flang-rt/include/flang-rt/{ => runtime}/environment.h (91%)
 rename flang-rt/include/flang-rt/{ => runtime}/file.h (95%)
 rename flang-rt/include/flang-rt/{ => runtime}/format-implementation.h (98%)
 rename flang-rt/include/flang-rt/{ => runtime}/format.h (97%)
 rename flang-rt/include/flang-rt/{ => runtime}/internal-unit.h (91%)
 rename flang-rt/include/flang-rt/{ => runtime}/io-error.h (94%)
 rename flang-rt/include/flang-rt/{ => runtime}/io-stmt.h (99%)
 rename flang-rt/include/flang-rt/{ => runtime}/lock.h (94%)
 rename flang-rt/include/flang-rt/{ => runtime}/memory.h (96%)
 rename flang-rt/include/flang-rt/{ => runtime}/namelist.h (91%)
 rename flang-rt/include/flang-rt/{ => runtime}/non-tbp-dio.h (91%)
 rename flang-rt/include/flang-rt/{ => runtime}/numeric-templates.h (98%)
 rename flang-rt/include/flang-rt/{ => runtime}/random-templates.h (94%)
 rename flang-rt/include/flang-rt/{ => runtime}/reduction-templates.h (98%)
 rename flang-rt/include/flang-rt/{ => runtime}/stat.h (93%)
 rename flang-rt/include/flang-rt/{ => runtime}/terminator.h (95%)
 rename flang-rt/include/flang-rt/{ => runtime}/tools.h (98%)
 rename flang-rt/include/flang-rt/{ => runtime}/type-code.h (93%)
 rename flang-rt/include/flang-rt/{ => runtime}/type-info.h (98%)
 rename flang-rt/include/flang-rt/{ => runtime}/utf.h (94%)
 rename flang-rt/lib/{flang_rt/CUDA => cuda}/allocatable.cpp (94%)
 rename flang-rt/lib/{flang_rt/CUDA => cuda}/allocator.cpp (86%)
 rename flang-rt/lib/{flang_rt/CUDA => cuda}/descriptor.cpp (90%)
 rename flang-rt/lib/{flang_rt/CUDA => cuda}/init.cpp (83%)
 rename flang-rt/lib/{flang_rt/CUDA => cuda}/kernel.cpp (98%)
 rename flang-rt/lib/{flang_rt/CUDA => cuda}/memmove-function.cpp (91%)
 rename flang-rt/lib/{flang_rt/CUDA => cuda}/memory.cpp (97%)
 rename flang-rt/lib/{flang_rt/CUDA => cuda}/pointer.cpp (92%)
 rename flang-rt/lib/{flang_rt/CUDA => cuda}/registration.cpp (93%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/acos.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/acosh.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/asin.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/asinh.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/atan.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/atan2.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/atanh.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/ceil.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/complex-math.c (96%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/complex-math.h (88%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/cos.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/cosh.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/erf.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/erfc.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/exp.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/exponent.cpp (92%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/floor.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/fma.cpp (91%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/fraction.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/hypot.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/j0.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/j1.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/jn.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/lgamma.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/llround.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/log.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/log10.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/lround.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/math-entries.h (96%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/mod-real.cpp (91%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/modulo-real.cpp (91%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/nearbyint.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/nearest.cpp (91%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/norm2.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/numeric-template-specs.h (82%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/pow.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/random.cpp (85%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/remainder.cpp (91%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/round.cpp (91%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/rrspacing.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/scale.cpp (92%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/set-exponent.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/sin.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/sinh.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/spacing.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/sqrt.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/tan.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/tanh.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/tgamma.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/trunc.cpp (91%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/y0.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/y1.cpp (90%)
 rename flang-rt/lib/{FortranFloat128Math => quadmath}/yn.cpp (90%)
 rename flang-rt/lib/{flang_rt => runtime}/ISO_Fortran_binding.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/ISO_Fortran_util.h (90%)
 rename flang-rt/lib/{flang_rt => runtime}/allocatable.cpp (96%)
 rename flang-rt/lib/{flang_rt => runtime}/allocator-registry.cpp (89%)
 rename flang-rt/lib/{flang_rt => runtime}/array-constructor.cpp (96%)
 rename flang-rt/lib/{flang_rt => runtime}/assign.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/buffer.cpp (90%)
 rename flang-rt/lib/{flang_rt => runtime}/character.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/command.cpp (96%)
 rename flang-rt/lib/{flang_rt => runtime}/complex-powi.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/complex-reduction.c (100%)
 rename flang-rt/lib/{flang_rt => runtime}/complex-reduction.h (97%)
 rename flang-rt/lib/{flang_rt => runtime}/connection.cpp (91%)
 rename flang-rt/lib/{flang_rt => runtime}/copy.cpp (97%)
 rename flang-rt/lib/{flang_rt => runtime}/copy.h (78%)
 rename flang-rt/lib/{flang_rt => runtime}/derived-api.cpp (95%)
 rename flang-rt/lib/{flang_rt => runtime}/derived.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/descriptor-io.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/descriptor-io.h (98%)
 rename flang-rt/lib/{flang_rt => runtime}/descriptor.cpp (97%)
 rename flang-rt/lib/{flang_rt => runtime}/dot-product.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/edit-input.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/edit-input.h (87%)
 rename flang-rt/lib/{flang_rt => runtime}/edit-output.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/edit-output.h (95%)
 rename flang-rt/lib/{flang_rt => runtime}/environment-default-list.h (100%)
 rename flang-rt/lib/{flang_rt => runtime}/environment.cpp (97%)
 rename flang-rt/lib/{flang_rt => runtime}/exceptions.cpp (97%)
 rename flang-rt/lib/{flang_rt => runtime}/execute.cpp (97%)
 rename flang-rt/lib/{flang_rt => runtime}/extensions.cpp (97%)
 rename flang-rt/lib/{flang_rt => runtime}/external-unit.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/extrema.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/file.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/findloc.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/format.cpp (89%)
 rename flang-rt/lib/{flang_rt => runtime}/inquiry.cpp (94%)
 rename flang-rt/lib/{flang_rt => runtime}/internal-unit.cpp (96%)
 rename flang-rt/lib/{flang_rt => runtime}/io-api-common.h (92%)
 rename flang-rt/lib/{flang_rt => runtime}/io-api-minimal.cpp (94%)
 rename flang-rt/lib/{flang_rt => runtime}/io-api.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/io-error.cpp (97%)
 rename flang-rt/lib/{flang_rt => runtime}/io-stmt.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/iostat.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/main.cpp (90%)
 rename flang-rt/lib/{flang_rt => runtime}/matmul-transpose.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/matmul.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/memory.cpp (87%)
 rename flang-rt/lib/{flang_rt => runtime}/misc-intrinsic.cpp (95%)
 rename flang-rt/lib/{flang_rt => runtime}/namelist.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/non-tbp-dio.cpp (86%)
 rename flang-rt/lib/{flang_rt => runtime}/numeric.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/pointer.cpp (96%)
 rename flang-rt/lib/{flang_rt => runtime}/product.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/pseudo-unit.cpp (97%)
 rename flang-rt/lib/{flang_rt => runtime}/ragged.cpp (96%)
 rename flang-rt/lib/{flang_rt => runtime}/random.cpp (96%)
 rename flang-rt/lib/{flang_rt => runtime}/reduce.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/reduction.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/stack.h (93%)
 rename flang-rt/lib/{flang_rt => runtime}/stat.cpp (93%)
 rename flang-rt/lib/{flang_rt => runtime}/stop.cpp (95%)
 rename flang-rt/lib/{flang_rt => runtime}/sum.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/support.cpp (91%)
 rename flang-rt/lib/{flang_rt => runtime}/temporary-stack.cpp (97%)
 rename flang-rt/lib/{flang_rt => runtime}/terminator.cpp (96%)
 rename flang-rt/lib/{flang_rt => runtime}/time-intrinsic.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/tools.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/transformational.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/type-code.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/type-info.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/unit-map.cpp (98%)
 rename flang-rt/lib/{flang_rt => runtime}/unit-map.h (92%)
 rename flang-rt/lib/{flang_rt => runtime}/unit.cpp (99%)
 rename flang-rt/lib/{flang_rt => runtime}/unit.h (95%)
 rename flang-rt/lib/{flang_rt => runtime}/utf.cpp (97%)

diff --git a/flang/examples/ExternalHelloWorld/external-hello.cpp b/flang-rt/examples/ExternalHelloWorld/external-hello.cpp
similarity index 80%
rename from flang/examples/ExternalHelloWorld/external-hello.cpp
rename to flang-rt/examples/ExternalHelloWorld/external-hello.cpp
index 4991bf9eba999..7c8a12476295c 100644
--- a/flang/examples/ExternalHelloWorld/external-hello.cpp
+++ b/flang-rt/examples/ExternalHelloWorld/external-hello.cpp
@@ -1,3 +1,11 @@
+//===-- examples/ExternalHelloWorld/external-hello.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/Runtime/io-api.h"
 #include "flang/Runtime/main.h"
 #include "flang/Runtime/stop.h"
diff --git a/flang-rt/include/flang-rt/CUDA/allocator.h b/flang-rt/include/flang-rt/cuda/allocator.h
similarity index 93%
rename from flang-rt/include/flang-rt/CUDA/allocator.h
rename to flang-rt/include/flang-rt/cuda/allocator.h
index 68bb0736dd5ee..5bc61cd04ee26 100644
--- a/flang-rt/include/flang-rt/CUDA/allocator.h
+++ b/flang-rt/include/flang-rt/cuda/allocator.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/CUDA/allocator.h -----------------------*- C++ -*-===//
+//===-- include/flang-rt/cuda/allocator.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-rt/include/flang-rt/allocator-registry.h b/flang-rt/include/flang-rt/runtime/allocator-registry.h
similarity index 87%
rename from flang-rt/include/flang-rt/allocator-registry.h
rename to flang-rt/include/flang-rt/runtime/allocator-registry.h
index ea905afc045ce..1a59ec8b1ef5b 100644
--- a/flang-rt/include/flang-rt/allocator-registry.h
+++ b/flang-rt/include/flang-rt/runtime/allocator-registry.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/allocator-registry.h -------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/allocator-registry.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 FLANG_RT_ALLOCATOR_REGISTRY_H_
-#define FLANG_RT_ALLOCATOR_REGISTRY_H_
+#ifndef FLANG_RT_RUNTIME_ALLOCATOR_REGISTRY_H_
+#define FLANG_RT_RUNTIME_ALLOCATOR_REGISTRY_H_
 
 #include "flang/Common/api-attrs.h"
 #include "flang/Runtime/allocator-registry-consts.h"
@@ -55,4 +55,4 @@ RT_OFFLOAD_VAR_GROUP_END
 
 } // namespace Fortran::runtime
 
-#endif // FLANG_RT_ALLOCATOR_REGISTRY_H_
+#endif // FLANG_RT_RUNTIME_ALLOCATOR_REGISTRY_H_
diff --git a/flang-rt/include/flang-rt/array-constructor.h b/flang-rt/include/flang-rt/runtime/array-constructor.h
similarity index 90%
rename from flang-rt/include/flang-rt/array-constructor.h
rename to flang-rt/include/flang-rt/runtime/array-constructor.h
index 738050f80ef65..9c037177161c0 100644
--- a/flang-rt/include/flang-rt/array-constructor.h
+++ b/flang-rt/include/flang-rt/runtime/array-constructor.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/array-constructor.h --------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/array-constructor.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.
@@ -9,8 +9,8 @@
 // External APIs to create temporary storage for array constructors when their
 // final extents or length parameters cannot be pre-computed.
 
-#ifndef FLANG_RT_ARRAY_CONSTRUCTOR_H_
-#define FLANG_RT_ARRAY_CONSTRUCTOR_H_
+#ifndef FLANG_RT_RUNTIME_ARRAY_CONSTRUCTOR_H_
+#define FLANG_RT_RUNTIME_ARRAY_CONSTRUCTOR_H_
 
 #include "descriptor.h"
 #include "flang/Runtime/array-constructor-consts.h"
@@ -54,4 +54,4 @@ static_assert(alignof(Fortran::runtime::ArrayConstructorVector) <=
     "MaxArrayConstructorVectorAlignInBytes");
 
 } // namespace Fortran::runtime
-#endif // FLANG_RT_ARRAY_CONSTRUCTOR_H_
+#endif // FLANG_RT_RUNTIME_ARRAY_CONSTRUCTOR_H_
diff --git a/flang-rt/include/flang-rt/assign-impl.h b/flang-rt/include/flang-rt/runtime/assign-impl.h
similarity index 85%
rename from flang-rt/include/flang-rt/assign-impl.h
rename to flang-rt/include/flang-rt/runtime/assign-impl.h
index 2e85a451d5b52..cc931f6713cd8 100644
--- a/flang-rt/include/flang-rt/assign-impl.h
+++ b/flang-rt/include/flang-rt/runtime/assign-impl.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/assign-impl.h --------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/assign-impl.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 FLANG_RT_ASSIGN_IMPL_H_
-#define FLANG_RT_ASSIGN_IMPL_H_
+#ifndef FLANG_RT_RUNTIME_ASSIGN_IMPL_H_
+#define FLANG_RT_RUNTIME_ASSIGN_IMPL_H_
 
 #include "flang/Runtime/freestanding-tools.h"
 
@@ -28,4 +28,4 @@ RT_API_ATTRS void DoFromSourceAssign(Descriptor &, const Descriptor &,
 #endif
 
 } // namespace Fortran::runtime
-#endif // FLANG_RT_ASSIGN_IMPL_H_
+#endif // FLANG_RT_RUNTIME_ASSIGN_IMPL_H_
diff --git a/flang-rt/include/flang-rt/buffer.h b/flang-rt/include/flang-rt/runtime/buffer.h
similarity index 97%
rename from flang-rt/include/flang-rt/buffer.h
rename to flang-rt/include/flang-rt/runtime/buffer.h
index bd2e8c47c6e30..b5a9ce9e35e91 100644
--- a/flang-rt/include/flang-rt/buffer.h
+++ b/flang-rt/include/flang-rt/runtime/buffer.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/buffer.h -------------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/buffer.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.
@@ -8,8 +8,8 @@
 
 // External file buffering
 
-#ifndef FLANG_RT_BUFFER_H_
-#define FLANG_RT_BUFFER_H_
+#ifndef FLANG_RT_RUNTIME_BUFFER_H_
+#define FLANG_RT_RUNTIME_BUFFER_H_
 
 #include "io-error.h"
 #include "memory.h"
@@ -221,4 +221,4 @@ template <typename STORE, std::size_t minBuffer = 65536> class FileFrame {
   bool dirty_{false};
 };
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_BUFFER_H_
+#endif // FLANG_RT_RUNTIME_BUFFER_H_
diff --git a/flang-rt/include/flang-rt/connection.h b/flang-rt/include/flang-rt/runtime/connection.h
similarity index 96%
rename from flang-rt/include/flang-rt/connection.h
rename to flang-rt/include/flang-rt/runtime/connection.h
index 550ddb15c7236..03d9658e7067b 100644
--- a/flang-rt/include/flang-rt/connection.h
+++ b/flang-rt/include/flang-rt/runtime/connection.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/connection.h ---------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/connection.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.
@@ -8,8 +8,8 @@
 
 // Fortran I/O connection state (abstracted over internal & external units)
 
-#ifndef FLANG_RT_CONNECTION_H_
-#define FLANG_RT_CONNECTION_H_
+#ifndef FLANG_RT_RUNTIME_CONNECTION_H_
+#define FLANG_RT_RUNTIME_CONNECTION_H_
 
 #include "format.h"
 #include "flang/Common/optional.h"
@@ -124,4 +124,4 @@ class SavedPosition {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_CONNECTION_H_
+#endif // FLANG_RT_RUNTIME_CONNECTION_H_
diff --git a/flang-rt/include/flang-rt/derived.h b/flang-rt/include/flang-rt/runtime/derived.h
similarity index 91%
rename from flang-rt/include/flang-rt/derived.h
rename to flang-rt/include/flang-rt/runtime/derived.h
index d65fb75172495..ac6962c57168c 100644
--- a/flang-rt/include/flang-rt/derived.h
+++ b/flang-rt/include/flang-rt/runtime/derived.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/derived.h ------------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/derived.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.
@@ -8,8 +8,8 @@
 
 // Internal runtime utilities for derived type operations.
 
-#ifndef FLANG_RT_DERIVED_H_
-#define FLANG_RT_DERIVED_H_
+#ifndef FLANG_RT_RUNTIME_DERIVED_H_
+#define FLANG_RT_RUNTIME_DERIVED_H_
 
 #include "flang/Common/api-attrs.h"
 
@@ -48,4 +48,4 @@ RT_API_ATTRS void Destroy(const Descriptor &, bool finalize,
 RT_API_ATTRS bool HasDynamicComponent(const Descriptor &);
 
 } // namespace Fortran::runtime
-#endif // FLANG_RT_DERIVED_H_
+#endif // FLANG_RT_RUNTIME_DERIVED_H_
diff --git a/flang-rt/include/flang-rt/descriptor.h b/flang-rt/include/flang-rt/runtime/descriptor.h
similarity index 98%
rename from flang-rt/include/flang-rt/descriptor.h
rename to flang-rt/include/flang-rt/runtime/descriptor.h
index f97b8443425dc..19e1a0bf6a1dd 100644
--- a/flang-rt/include/flang-rt/descriptor.h
+++ b/flang-rt/include/flang-rt/runtime/descriptor.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/descriptor.h ---------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/descriptor.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 FLANG_RT_DESCRIPTOR_H_
-#define FLANG_RT_DESCRIPTOR_H_
+#ifndef FLANG_RT_RUNTIME_DESCRIPTOR_H_
+#define FLANG_RT_RUNTIME_DESCRIPTOR_H_
 
 // Defines data structures used during execution of a Fortran program
 // to implement nontrivial dummy arguments, pointers, allocatables,
@@ -482,4 +482,4 @@ class alignas(Descriptor) StaticDescriptor {
 };
 
 } // namespace Fortran::runtime
-#endif // FLANG_RT_DESCRIPTOR_H_
+#endif // FLANG_RT_RUNTIME_DESCRIPTOR_H_
diff --git a/flang-rt/include/flang-rt/emit-encoded.h b/flang-rt/include/flang-rt/runtime/emit-encoded.h
similarity index 94%
rename from flang-rt/include/flang-rt/emit-encoded.h
rename to flang-rt/include/flang-rt/runtime/emit-encoded.h
index 279f751daff2c..d99f56b29558e 100644
--- a/flang-rt/include/flang-rt/emit-encoded.h
+++ b/flang-rt/include/flang-rt/runtime/emit-encoded.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/emit-encoded.h -------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/emit-encoded.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.
@@ -8,8 +8,8 @@
 
 // Templates for emitting CHARACTER values with conversion
 
-#ifndef FLANG_RT_EMIT_ENCODED_H_
-#define FLANG_RT_EMIT_ENCODED_H_
+#ifndef FLANG_RT_RUNTIME_EMIT_ENCODED_H_
+#define FLANG_RT_RUNTIME_EMIT_ENCODED_H_
 
 #include "connection.h"
 #include "environment.h"
@@ -114,4 +114,4 @@ RT_API_ATTRS bool EmitRepeated(CONTEXT &to, char ch, std::size_t n) {
 }
 
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_EMIT_ENCODED_H_
+#endif // FLANG_RT_RUNTIME_EMIT_ENCODED_H_
diff --git a/flang-rt/include/flang-rt/environment.h b/flang-rt/include/flang-rt/runtime/environment.h
similarity index 91%
rename from flang-rt/include/flang-rt/environment.h
rename to flang-rt/include/flang-rt/runtime/environment.h
index 7fa3060768502..142add432b5f7 100644
--- a/flang-rt/include/flang-rt/environment.h
+++ b/flang-rt/include/flang-rt/runtime/environment.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/environment.h --------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/environment.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 FLANG_RT_ENVIRONMENT_H_
-#define FLANG_RT_ENVIRONMENT_H_
+#ifndef FLANG_RT_RUNTIME_ENVIRONMENT_H_
+#define FLANG_RT_RUNTIME_ENVIRONMENT_H_
 
 #include "flang/Common/optional.h"
 #include "flang/Decimal/decimal.h"
@@ -67,4 +67,4 @@ RT_OFFLOAD_VAR_GROUP_END
 
 } // namespace Fortran::runtime
 
-#endif // FLANG_RT_ENVIRONMENT_H_
+#endif // FLANG_RT_RUNTIME_ENVIRONMENT_H_
diff --git a/flang-rt/include/flang-rt/file.h b/flang-rt/include/flang-rt/runtime/file.h
similarity index 95%
rename from flang-rt/include/flang-rt/file.h
rename to flang-rt/include/flang-rt/runtime/file.h
index 3ab21c655a38f..3bba29722b3b8 100644
--- a/flang-rt/include/flang-rt/file.h
+++ b/flang-rt/include/flang-rt/runtime/file.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/file.h ---------------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/file.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.
@@ -8,8 +8,8 @@
 
 // Raw system I/O wrappers
 
-#ifndef FLANG_RT_FILE_H_
-#define FLANG_RT_FILE_H_
+#ifndef FLANG_RT_RUNTIME_FILE_H_
+#define FLANG_RT_RUNTIME_FILE_H_
 
 #include "io-error.h"
 #include "memory.h"
@@ -113,4 +113,4 @@ RT_API_ATTRS bool MayWrite(const char *path);
 RT_API_ATTRS bool MayReadAndWrite(const char *path);
 RT_API_ATTRS std::int64_t SizeInBytes(const char *path);
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_FILE_H_
+#endif // FLANG_RT_RUNTIME_FILE_H_
diff --git a/flang-rt/include/flang-rt/format-implementation.h b/flang-rt/include/flang-rt/runtime/format-implementation.h
similarity index 98%
rename from flang-rt/include/flang-rt/format-implementation.h
rename to flang-rt/include/flang-rt/runtime/format-implementation.h
index 6a2e1078ab350..8f4eb1161dd14 100644
--- a/flang-rt/include/flang-rt/format-implementation.h
+++ b/flang-rt/include/flang-rt/runtime/format-implementation.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/format-implementation.h ----------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/format-implementation.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.
@@ -8,8 +8,8 @@
 
 // Implements out-of-line member functions of template class FormatControl
 
-#ifndef FLANG_RT_FORMAT_IMPLEMENTATION_H_
-#define FLANG_RT_FORMAT_IMPLEMENTATION_H_
+#ifndef FLANG_RT_RUNTIME_FORMAT_IMPLEMENTATION_H_
+#define FLANG_RT_RUNTIME_FORMAT_IMPLEMENTATION_H_
 
 #include "emit-encoded.h"
 #include "format.h"
@@ -601,4 +601,4 @@ RT_API_ATTRS void FormatControl<CONTEXT>::Finish(Context &context) {
   }
 }
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_FORMAT_IMPLEMENTATION_H_
+#endif // FLANG_RT_RUNTIME_FORMAT_IMPLEMENTATION_H_
diff --git a/flang-rt/include/flang-rt/format.h b/flang-rt/include/flang-rt/runtime/format.h
similarity index 97%
rename from flang-rt/include/flang-rt/format.h
rename to flang-rt/include/flang-rt/runtime/format.h
index 09e151a2e98ca..b169d63fa4999 100644
--- a/flang-rt/include/flang-rt/format.h
+++ b/flang-rt/include/flang-rt/runtime/format.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/format.h -------------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/format.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.
@@ -8,8 +8,8 @@
 
 // FORMAT string processing
 
-#ifndef FLANG_RT_FORMAT_H_
-#define FLANG_RT_FORMAT_H_
+#ifndef FLANG_RT_RUNTIME_FORMAT_H_
+#define FLANG_RT_RUNTIME_FORMAT_H_
 
 #include "environment.h"
 #include "io-error.h"
@@ -201,4 +201,4 @@ template <typename CONTEXT> class FormatControl {
   Iteration stack_[maxMaxHeight];
 };
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_FORMAT_H_
+#endif // FLANG_RT_RUNTIME_FORMAT_H_
diff --git a/flang-rt/include/flang-rt/internal-unit.h b/flang-rt/include/flang-rt/runtime/internal-unit.h
similarity index 91%
rename from flang-rt/include/flang-rt/internal-unit.h
rename to flang-rt/include/flang-rt/runtime/internal-unit.h
index 946d69080e611..429d3489e0112 100644
--- a/flang-rt/include/flang-rt/internal-unit.h
+++ b/flang-rt/include/flang-rt/runtime/internal-unit.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/internal-unit.h ------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/internal-unit.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.
@@ -8,8 +8,8 @@
 
 // Fortran internal I/O "units"
 
-#ifndef FLANG_RT_INTERNAL_UNIT_H_
-#define FLANG_RT_INTERNAL_UNIT_H_
+#ifndef FLANG_RT_RUNTIME_INTERNAL_UNIT_H_
+#define FLANG_RT_RUNTIME_INTERNAL_UNIT_H_
 
 #include "connection.h"
 #include "descriptor.h"
@@ -56,4 +56,4 @@ template <Direction DIR> class InternalDescriptorUnit : public ConnectionState {
 extern template class InternalDescriptorUnit<Direction::Output>;
 extern template class InternalDescriptorUnit<Direction::Input>;
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_INTERNAL_UNIT_H_
+#endif // FLANG_RT_RUNTIME_INTERNAL_UNIT_H_
diff --git a/flang-rt/include/flang-rt/io-error.h b/flang-rt/include/flang-rt/runtime/io-error.h
similarity index 94%
rename from flang-rt/include/flang-rt/io-error.h
rename to flang-rt/include/flang-rt/runtime/io-error.h
index 6b5c0f9f39019..1cef6a208f374 100644
--- a/flang-rt/include/flang-rt/io-error.h
+++ b/flang-rt/include/flang-rt/runtime/io-error.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/io-error.h -----------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/io-error.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 @@
 // IOSTAT error codes are raw errno values augmented with values for
 // Fortran-specific errors.
 
-#ifndef FLANG_RT_IO_ERROR_H_
-#define FLANG_RT_IO_ERROR_H_
+#ifndef FLANG_RT_RUNTIME_IO_ERROR_H_
+#define FLANG_RT_RUNTIME_IO_ERROR_H_
 
 #include "memory.h"
 #include "terminator.h"
@@ -80,4 +80,4 @@ class IoErrorHandler : public Terminator {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_IO_ERROR_H_
+#endif // FLANG_RT_RUNTIME_IO_ERROR_H_
diff --git a/flang-rt/include/flang-rt/io-stmt.h b/flang-rt/include/flang-rt/runtime/io-stmt.h
similarity index 99%
rename from flang-rt/include/flang-rt/io-stmt.h
rename to flang-rt/include/flang-rt/runtime/io-stmt.h
index 7efab320e5e1a..a364ddfd9b3c7 100644
--- a/flang-rt/include/flang-rt/io-stmt.h
+++ b/flang-rt/include/flang-rt/runtime/io-stmt.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/io-stmt.h ------------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/io-stmt.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.
@@ -8,8 +8,8 @@
 
 // Representations of the state of an I/O statement in progress
 
-#ifndef FLANG_RT_IO_STMT_H_
-#define FLANG_RT_IO_STMT_H_
+#ifndef FLANG_RT_RUNTIME_IO_STMT_H_
+#define FLANG_RT_RUNTIME_IO_STMT_H_
 
 #include "connection.h"
 #include "descriptor.h"
@@ -791,4 +791,4 @@ class ErroneousIoStatementState : public IoStatementBase {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_IO_STMT_H_
+#endif // FLANG_RT_RUNTIME_IO_STMT_H_
diff --git a/flang-rt/include/flang-rt/lock.h b/flang-rt/include/flang-rt/runtime/lock.h
similarity index 94%
rename from flang-rt/include/flang-rt/lock.h
rename to flang-rt/include/flang-rt/runtime/lock.h
index 1b09434d26f4f..7c88534245733 100644
--- a/flang-rt/include/flang-rt/lock.h
+++ b/flang-rt/include/flang-rt/runtime/lock.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/lock.h ---------------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/lock.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.
@@ -8,8 +8,8 @@
 
 // Wraps a mutex
 
-#ifndef FLANG_RT_LOCK_H_
-#define FLANG_RT_LOCK_H_
+#ifndef FLANG_RT_RUNTIME_LOCK_H_
+#define FLANG_RT_RUNTIME_LOCK_H_
 
 #include "terminator.h"
 #include "tools.h"
@@ -113,4 +113,4 @@ class CriticalSection {
 };
 } // namespace Fortran::runtime
 
-#endif // FLANG_RT_LOCK_H_
+#endif // FLANG_RT_RUNTIME_LOCK_H_
diff --git a/flang-rt/include/flang-rt/memory.h b/flang-rt/include/flang-rt/runtime/memory.h
similarity index 96%
rename from flang-rt/include/flang-rt/memory.h
rename to flang-rt/include/flang-rt/runtime/memory.h
index 64db30baf2806..93b477afa9814 100644
--- a/flang-rt/include/flang-rt/memory.h
+++ b/flang-rt/include/flang-rt/runtime/memory.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/memory.h -------------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/memory.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.
@@ -9,8 +9,8 @@
 // Thin wrapper around malloc()/free() to isolate the dependency,
 // ease porting, and provide an owning pointer.
 
-#ifndef FLANG_RT_MEMORY_H_
-#define FLANG_RT_MEMORY_H_
+#ifndef FLANG_RT_RUNTIME_MEMORY_H_
+#define FLANG_RT_RUNTIME_MEMORY_H_
 
 #include "flang/Common/api-attrs.h"
 #include <cassert>
@@ -170,4 +170,4 @@ template <typename A> struct Allocator {
 };
 } // namespace Fortran::runtime
 
-#endif // FLANG_RT_MEMORY_H_
+#endif // FLANG_RT_RUNTIME_MEMORY_H_
diff --git a/flang-rt/include/flang-rt/namelist.h b/flang-rt/include/flang-rt/runtime/namelist.h
similarity index 91%
rename from flang-rt/include/flang-rt/namelist.h
rename to flang-rt/include/flang-rt/runtime/namelist.h
index 2ae93ca9c2050..17d7bf310cc96 100644
--- a/flang-rt/include/flang-rt/namelist.h
+++ b/flang-rt/include/flang-rt/runtime/namelist.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/namelist.h -----------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/namelist.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.
@@ -8,8 +8,8 @@
 
 // Defines the data structure used for NAMELIST I/O
 
-#ifndef FLANG_RT_NAMELIST_H_
-#define FLANG_RT_NAMELIST_H_
+#ifndef FLANG_RT_RUNTIME_NAMELIST_H_
+#define FLANG_RT_RUNTIME_NAMELIST_H_
 
 #include "non-tbp-dio.h"
 #include "flang/Common/api-attrs.h"
@@ -51,4 +51,4 @@ class NamelistGroup {
 RT_API_ATTRS bool IsNamelistNameOrSlash(IoStatementState &);
 
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_NAMELIST_H_
+#endif // FLANG_RT_RUNTIME_NAMELIST_H_
diff --git a/flang-rt/include/flang-rt/non-tbp-dio.h b/flang-rt/include/flang-rt/runtime/non-tbp-dio.h
similarity index 91%
rename from flang-rt/include/flang-rt/non-tbp-dio.h
rename to flang-rt/include/flang-rt/runtime/non-tbp-dio.h
index 1088257b72f59..2bbbfa7f97f79 100644
--- a/flang-rt/include/flang-rt/non-tbp-dio.h
+++ b/flang-rt/include/flang-rt/runtime/non-tbp-dio.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/non-tbp-dio.h --------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/non-tbp-dio.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.
@@ -19,8 +19,8 @@
 // a containing scope has become inaccessible in a nested scope due
 // to the use of "IMPORT, NONE" or "IMPORT, ONLY:".
 
-#ifndef FLANG_RT_NON_TBP_DIO_H_
-#define FLANG_RT_NON_TBP_DIO_H_
+#ifndef FLANG_RT_RUNTIME_NON_TBP_DIO_H_
+#define FLANG_RT_RUNTIME_NON_TBP_DIO_H_
 
 #include "flang/Common/Fortran-consts.h"
 #include "flang/Common/api-attrs.h"
@@ -53,4 +53,4 @@ struct NonTbpDefinedIoTable {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_NON_TBP_DIO_H_
+#endif // FLANG_RT_RUNTIME_NON_TBP_DIO_H_
diff --git a/flang-rt/include/flang-rt/numeric-templates.h b/flang-rt/include/flang-rt/runtime/numeric-templates.h
similarity index 98%
rename from flang-rt/include/flang-rt/numeric-templates.h
rename to flang-rt/include/flang-rt/runtime/numeric-templates.h
index a1475923ff3b1..1253d56f3c0fd 100644
--- a/flang-rt/include/flang-rt/numeric-templates.h
+++ b/flang-rt/include/flang-rt/runtime/numeric-templates.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/numeric-templates.h --------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/numeric-templates.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.
@@ -15,8 +15,8 @@
 // for the data type corresponding to CppTypeFor<TypeCategory::Real, 16>
 // on the target.
 
-#ifndef FLANG_RT_NUMERIC_TEMPLATES_H_
-#define FLANG_RT_NUMERIC_TEMPLATES_H_
+#ifndef FLANG_RT_RUNTIME_NUMERIC_TEMPLATES_H_
+#define FLANG_RT_RUNTIME_NUMERIC_TEMPLATES_H_
 
 #include "terminator.h"
 #include "tools.h"
@@ -368,4 +368,4 @@ template <typename T> inline RT_API_ATTRS T ErfcScaled(T arg) {
 
 } // namespace Fortran::runtime
 
-#endif // FLANG_RT_NUMERIC_TEMPLATES_H_
+#endif // FLANG_RT_RUNTIME_NUMERIC_TEMPLATES_H_
diff --git a/flang-rt/include/flang-rt/random-templates.h b/flang-rt/include/flang-rt/runtime/random-templates.h
similarity index 94%
rename from flang-rt/include/flang-rt/random-templates.h
rename to flang-rt/include/flang-rt/runtime/random-templates.h
index 00542bd5b2553..895c5ad4fc8bb 100644
--- a/flang-rt/include/flang-rt/random-templates.h
+++ b/flang-rt/include/flang-rt/runtime/random-templates.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/random-templates.h ---------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/random-templates.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 FLANG_RT_RANDOM_TEMPLATES_H_
-#define FLANG_RT_RANDOM_TEMPLATES_H_
+#ifndef FLANG_RT_RUNTIME_RANDOM_TEMPLATES_H_
+#define FLANG_RT_RUNTIME_RANDOM_TEMPLATES_H_
 
 #include "descriptor.h"
 #include "lock.h"
@@ -108,4 +108,4 @@ inline void GenerateUnsigned(const Descriptor &harvest) {
 
 } // namespace Fortran::runtime::random
 
-#endif // FLANG_RT_RANDOM_TEMPLATES_H_
+#endif // FLANG_RT_RUNTIME_RANDOM_TEMPLATES_H_
diff --git a/flang-rt/include/flang-rt/reduction-templates.h b/flang-rt/include/flang-rt/runtime/reduction-templates.h
similarity index 98%
rename from flang-rt/include/flang-rt/reduction-templates.h
rename to flang-rt/include/flang-rt/runtime/reduction-templates.h
index d6b3c24920cf9..8c6f838b8dadf 100644
--- a/flang-rt/include/flang-rt/reduction-templates.h
+++ b/flang-rt/include/flang-rt/runtime/reduction-templates.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/reduction-templates.h ------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/reduction-templates.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.
@@ -18,8 +18,8 @@
 // * Character-valued reductions (MAXVAL & MINVAL) return arbitrary
 //   length results, dynamically allocated in a caller-supplied descriptor
 
-#ifndef FLANG_RT_REDUCTION_TEMPLATES_H_
-#define FLANG_RT_REDUCTION_TEMPLATES_H_
+#ifndef FLANG_RT_RUNTIME_REDUCTION_TEMPLATES_H_
+#define FLANG_RT_RUNTIME_REDUCTION_TEMPLATES_H_
 
 #include "descriptor.h"
 #include "numeric-templates.h"
@@ -416,4 +416,4 @@ template <int KIND> struct Norm2Helper {
 };
 
 } // namespace Fortran::runtime
-#endif // FLANG_RT_REDUCTION_TEMPLATES_H_
+#endif // FLANG_RT_RUNTIME_REDUCTION_TEMPLATES_H_
diff --git a/flang-rt/include/flang-rt/stat.h b/flang-rt/include/flang-rt/runtime/stat.h
similarity index 93%
rename from flang-rt/include/flang-rt/stat.h
rename to flang-rt/include/flang-rt/runtime/stat.h
index a6824f4803561..070d0bf8673fb 100644
--- a/flang-rt/include/flang-rt/stat.h
+++ b/flang-rt/include/flang-rt/runtime/stat.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/stat.h ---------------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/stat.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.
@@ -9,8 +9,8 @@
 // Defines the values returned by the runtime for STAT= specifiers
 // on executable statements.
 
-#ifndef FLANG_RT_STAT_H_
-#define FLANG_RT_STAT_H_
+#ifndef FLANG_RT_RUNTIME_STAT_H_
+#define FLANG_RT_RUNTIME_STAT_H_
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Common/api-attrs.h"
 #include "flang/Runtime/magic-numbers.h"
@@ -60,4 +60,4 @@ RT_API_ATTRS int ToErrmsg(const Descriptor *errmsg, int stat); // returns stat
 RT_API_ATTRS int ReturnError(Terminator &, int stat,
     const Descriptor *errmsg = nullptr, bool hasStat = false);
 } // namespace Fortran::runtime
-#endif // FLANG_RT_STAT_H_
+#endif // FLANG_RT_RUNTIME_STAT_H_
diff --git a/flang-rt/include/flang-rt/terminator.h b/flang-rt/include/flang-rt/runtime/terminator.h
similarity index 95%
rename from flang-rt/include/flang-rt/terminator.h
rename to flang-rt/include/flang-rt/runtime/terminator.h
index c2a4e1f64eb66..4815f0674c849 100644
--- a/flang-rt/include/flang-rt/terminator.h
+++ b/flang-rt/include/flang-rt/runtime/terminator.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/terminator.h ---------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/terminator.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.
@@ -8,8 +8,8 @@
 
 // Termination of the image
 
-#ifndef FLANG_RT_TERMINATOR_H_
-#define FLANG_RT_TERMINATOR_H_
+#ifndef FLANG_RT_RUNTIME_TERMINATOR_H_
+#define FLANG_RT_RUNTIME_TERMINATOR_H_
 
 #include "flang/Common/api-attrs.h"
 #include <cstdarg>
@@ -121,4 +121,4 @@ namespace Fortran::runtime::io {
 RT_API_ATTRS void FlushOutputOnCrash(const Terminator &);
 }
 
-#endif // FLANG_RT_TERMINATOR_H_
+#endif // FLANG_RT_RUNTIME_TERMINATOR_H_
diff --git a/flang-rt/include/flang-rt/tools.h b/flang-rt/include/flang-rt/runtime/tools.h
similarity index 98%
rename from flang-rt/include/flang-rt/tools.h
rename to flang-rt/include/flang-rt/runtime/tools.h
index 6bb31cbcc9b93..91a026bf2ac14 100644
--- a/flang-rt/include/flang-rt/tools.h
+++ b/flang-rt/include/flang-rt/runtime/tools.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/tools.h --------------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/tools.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 FLANG_RT_TOOLS_H_
-#define FLANG_RT_TOOLS_H_
+#ifndef FLANG_RT_RUNTIME_TOOLS_H_
+#define FLANG_RT_RUNTIME_TOOLS_H_
 
 #include "descriptor.h"
 #include "memory.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 flang_rt.quadmath
+      // generated a call to an entry in the libflang_rt.quadmath
       // library.
       if constexpr (!NEEDSMATH) {
         return FUNC<16>{}(std::forward<A>(x)...);
@@ -570,4 +570,4 @@ RT_API_ATTRS void CreatePartialReductionResult(Descriptor &result,
     const char *intrinsic, TypeCode);
 
 } // namespace Fortran::runtime
-#endif // FLANG_RT_TOOLS_H_
+#endif // FLANG_RT_RUNTIME_TOOLS_H_
diff --git a/flang-rt/include/flang-rt/type-code.h b/flang-rt/include/flang-rt/runtime/type-code.h
similarity index 93%
rename from flang-rt/include/flang-rt/type-code.h
rename to flang-rt/include/flang-rt/runtime/type-code.h
index a3b79462887c1..9416a2816fd43 100644
--- a/flang-rt/include/flang-rt/type-code.h
+++ b/flang-rt/include/flang-rt/runtime/type-code.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/type-code.h ----------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/type-code.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 FLANG_RT_TYPE_CODE_H_
-#define FLANG_RT_TYPE_CODE_H_
+#ifndef FLANG_RT_RUNTIME_TYPE_CODE_H_
+#define FLANG_RT_RUNTIME_TYPE_CODE_H_
 
 #include "flang/Common/Fortran-consts.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
@@ -75,4 +75,4 @@ class TypeCode {
   ISO::CFI_type_t raw_{CFI_type_other};
 };
 } // namespace Fortran::runtime
-#endif // FLANG_RT_TYPE_CODE_H_
+#endif // FLANG_RT_RUNTIME_TYPE_CODE_H_
diff --git a/flang-rt/include/flang-rt/type-info.h b/flang-rt/include/flang-rt/runtime/type-info.h
similarity index 98%
rename from flang-rt/include/flang-rt/type-info.h
rename to flang-rt/include/flang-rt/runtime/type-info.h
index dc5cd98d7523f..9891fcecdcb25 100644
--- a/flang-rt/include/flang-rt/type-info.h
+++ b/flang-rt/include/flang-rt/runtime/type-info.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/type-info.h ----------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/type-info.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 FLANG_RT_TYPE_INFO_H_
-#define FLANG_RT_TYPE_INFO_H_
+#ifndef FLANG_RT_RUNTIME_TYPE_INFO_H_
+#define FLANG_RT_RUNTIME_TYPE_INFO_H_
 
 // A C++ perspective of the derived type description schemata in
 // flang/module/__fortran_type_info.f90.
@@ -321,4 +321,4 @@ class DerivedType {
 };
 
 } // namespace Fortran::runtime::typeInfo
-#endif // FLANG_RT_TYPE_INFO_H_
+#endif // FLANG_RT_RUNTIME_TYPE_INFO_H_
diff --git a/flang-rt/include/flang-rt/utf.h b/flang-rt/include/flang-rt/runtime/utf.h
similarity index 94%
rename from flang-rt/include/flang-rt/utf.h
rename to flang-rt/include/flang-rt/runtime/utf.h
index 648937ca14f16..b5add823124fc 100644
--- a/flang-rt/include/flang-rt/utf.h
+++ b/flang-rt/include/flang-rt/runtime/utf.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/utf.h ----------------------------------*- C++ -*-===//
+//===-- include/flang-rt/runtime/utf.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.
@@ -38,8 +38,8 @@
 // standard maximum.  However, we support extended forms up to 32 bits so that
 // CHARACTER(KIND=4) can be abused to hold arbitrary 32-bit data.
 
-#ifndef FLANG_RT_UTF_H_
-#define FLANG_RT_UTF_H_
+#ifndef FLANG_RT_RUNTIME_UTF_H_
+#define FLANG_RT_RUNTIME_UTF_H_
 
 #include "flang/Common/optional.h"
 #include <cstddef>
@@ -70,4 +70,4 @@ RT_API_ATTRS Fortran::common::optional<char32_t> DecodeUTF8(const char *);
 RT_API_ATTRS std::size_t EncodeUTF8(char *, char32_t);
 
 } // namespace Fortran::runtime
-#endif // FLANG_RT_UTF_H_
+#endif // FLANG_RT_RUNTIME_UTF_H_
diff --git a/flang-rt/lib/flang_rt/CUDA/allocatable.cpp b/flang-rt/lib/cuda/allocatable.cpp
similarity index 94%
rename from flang-rt/lib/flang_rt/CUDA/allocatable.cpp
rename to flang-rt/lib/cuda/allocatable.cpp
index 2281e2148d4ae..2f549b604fe58 100644
--- a/flang-rt/lib/flang_rt/CUDA/allocatable.cpp
+++ b/flang-rt/lib/cuda/allocatable.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/CUDA/allocatable.cpp -----------------------*- C++ -*-===//
+//===-- lib/cuda/allocatable.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.
@@ -7,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/allocatable.h"
-#include "flang-rt/assign-impl.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/stat.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/assign-impl.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/stat.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/CUDA/memmove-function.h"
diff --git a/flang-rt/lib/flang_rt/CUDA/allocator.cpp b/flang-rt/lib/cuda/allocator.cpp
similarity index 86%
rename from flang-rt/lib/flang_rt/CUDA/allocator.cpp
rename to flang-rt/lib/cuda/allocator.cpp
index dc1ce5920e222..511543f6a4863 100644
--- a/flang-rt/lib/flang_rt/CUDA/allocator.cpp
+++ b/flang-rt/lib/cuda/allocator.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/CUDA/allocator.cpp -------------------------*- C++ -*-===//
+//===-- lib/cuda/allocator.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,12 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/CUDA/allocator.h"
-#include "flang-rt/allocator-registry.h"
-#include "flang-rt/derived.h"
-#include "flang-rt/stat.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/type-info.h"
+#include "flang-rt/cuda/allocator.h"
+#include "flang-rt/runtime/allocator-registry.h"
+#include "flang-rt/runtime/derived.h"
+#include "flang-rt/runtime/stat.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/type-info.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Support/Fortran.h"
diff --git a/flang-rt/lib/flang_rt/CUDA/descriptor.cpp b/flang-rt/lib/cuda/descriptor.cpp
similarity index 90%
rename from flang-rt/lib/flang_rt/CUDA/descriptor.cpp
rename to flang-rt/lib/cuda/descriptor.cpp
index 9ec79ccea22c3..60e096acfde32 100644
--- a/flang-rt/lib/flang_rt/CUDA/descriptor.cpp
+++ b/flang-rt/lib/cuda/descriptor.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/CUDA/descriptor.cpp ------------------------*- C++ -*-===//
+//===-- lib/cuda/descriptor.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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/descriptor.h"
-#include "flang-rt/CUDA/allocator.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/cuda/allocator.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 
 #include "cuda_runtime.h"
diff --git a/flang-rt/lib/flang_rt/CUDA/init.cpp b/flang-rt/lib/cuda/init.cpp
similarity index 83%
rename from flang-rt/lib/flang_rt/CUDA/init.cpp
rename to flang-rt/lib/cuda/init.cpp
index f2d47d258519e..d79bffc32424d 100644
--- a/flang-rt/lib/flang_rt/CUDA/init.cpp
+++ b/flang-rt/lib/cuda/init.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/CUDA/init.cpp ------------------------------*- C++ -*-===//
+//===-- lib/cuda/init.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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/init.h"
-#include "flang-rt/environment.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/environment.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 
 #include "cuda_runtime.h"
diff --git a/flang-rt/lib/flang_rt/CUDA/kernel.cpp b/flang-rt/lib/cuda/kernel.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/CUDA/kernel.cpp
rename to flang-rt/lib/cuda/kernel.cpp
index 7f9786319d574..75eb639817b9a 100644
--- a/flang-rt/lib/flang_rt/CUDA/kernel.cpp
+++ b/flang-rt/lib/cuda/kernel.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/CUDA/kernel.cpp ----------------------------*- C++ -*-===//
+//===-- lib/cuda/kernel.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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/kernel.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 
 #include "cuda_runtime.h"
diff --git a/flang-rt/lib/flang_rt/CUDA/memmove-function.cpp b/flang-rt/lib/cuda/memmove-function.cpp
similarity index 91%
rename from flang-rt/lib/flang_rt/CUDA/memmove-function.cpp
rename to flang-rt/lib/cuda/memmove-function.cpp
index ca04e20379d03..a7eb0cf1a3e7a 100644
--- a/flang-rt/lib/flang_rt/CUDA/memmove-function.cpp
+++ b/flang-rt/lib/cuda/memmove-function.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/CUDA/memmove-function.cpp ------------------*- C++ -*-===//
+//===-- lib/cuda/memmove-function.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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/memmove-function.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 
 #include "cuda_runtime.h"
diff --git a/flang-rt/lib/flang_rt/CUDA/memory.cpp b/flang-rt/lib/cuda/memory.cpp
similarity index 97%
rename from flang-rt/lib/flang_rt/CUDA/memory.cpp
rename to flang-rt/lib/cuda/memory.cpp
index 3d4a74f5f9e52..7ead0dd35e1d9 100644
--- a/flang-rt/lib/flang_rt/CUDA/memory.cpp
+++ b/flang-rt/lib/cuda/memory.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/CUDA/memory.cpp ----------------------------*- C++ -*-===//
+//===-- lib/cuda/memory.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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/memory.h"
-#include "flang-rt/assign-impl.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/assign-impl.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/CUDA/memmove-function.h"
diff --git a/flang-rt/lib/flang_rt/CUDA/pointer.cpp b/flang-rt/lib/cuda/pointer.cpp
similarity index 92%
rename from flang-rt/lib/flang_rt/CUDA/pointer.cpp
rename to flang-rt/lib/cuda/pointer.cpp
index b6e8033933834..d94e3958b9153 100644
--- a/flang-rt/lib/flang_rt/CUDA/pointer.cpp
+++ b/flang-rt/lib/cuda/pointer.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/CUDA/pointer.cpp ---------------------------*- C++ -*-===//
+//===-- lib/cuda/pointer.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.
@@ -7,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/pointer.h"
-#include "flang-rt/assign-impl.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/stat.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/assign-impl.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/stat.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/CUDA/memmove-function.h"
 #include "flang/Runtime/pointer.h"
diff --git a/flang-rt/lib/flang_rt/CUDA/registration.cpp b/flang-rt/lib/cuda/registration.cpp
similarity index 93%
rename from flang-rt/lib/flang_rt/CUDA/registration.cpp
rename to flang-rt/lib/cuda/registration.cpp
index f8a7b197bed3b..60b0e491b6ffd 100644
--- a/flang-rt/lib/flang_rt/CUDA/registration.cpp
+++ b/flang-rt/lib/cuda/registration.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/CUDA/registration.cpp ----------------------*- C++ -*-===//
+//===-- lib/cuda/registration.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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/registration.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 
 #include "cuda_runtime.h"
diff --git a/flang-rt/lib/FortranFloat128Math/acos.cpp b/flang-rt/lib/quadmath/acos.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/acos.cpp
rename to flang-rt/lib/quadmath/acos.cpp
index 7f20654752754..d094121f0f678 100644
--- a/flang-rt/lib/FortranFloat128Math/acos.cpp
+++ b/flang-rt/lib/quadmath/acos.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/acos.cpp ------------------------*- C++ -*-===//
+//===-- lib/quadmath/acos.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-rt/lib/FortranFloat128Math/acosh.cpp b/flang-rt/lib/quadmath/acosh.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/acosh.cpp
rename to flang-rt/lib/quadmath/acosh.cpp
index 73b64230f08c7..968aa489d15a2 100644
--- a/flang-rt/lib/FortranFloat128Math/acosh.cpp
+++ b/flang-rt/lib/quadmath/acosh.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/acosh.cpp -----------------------*- C++ -*-===//
+//===-- lib/quadmath/acosh.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-rt/lib/FortranFloat128Math/asin.cpp b/flang-rt/lib/quadmath/asin.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/asin.cpp
rename to flang-rt/lib/quadmath/asin.cpp
index b51ecb6b674d3..c3345cd3d748a 100644
--- a/flang-rt/lib/FortranFloat128Math/asin.cpp
+++ b/flang-rt/lib/quadmath/asin.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/asin.cpp ------------------------*- C++ -*-===//
+//===-- lib/quadmath/asin.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-rt/lib/FortranFloat128Math/asinh.cpp b/flang-rt/lib/quadmath/asinh.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/asinh.cpp
rename to flang-rt/lib/quadmath/asinh.cpp
index 2fc181d075aec..1023b678b6131 100644
--- a/flang-rt/lib/FortranFloat128Math/asinh.cpp
+++ b/flang-rt/lib/quadmath/asinh.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/asinh.cpp -----------------------*- C++ -*-===//
+//===-- lib/quadmath/asinh.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-rt/lib/FortranFloat128Math/atan.cpp b/flang-rt/lib/quadmath/atan.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/atan.cpp
rename to flang-rt/lib/quadmath/atan.cpp
index ff1ec39bfdebd..6379df3275c03 100644
--- a/flang-rt/lib/FortranFloat128Math/atan.cpp
+++ b/flang-rt/lib/quadmath/atan.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/atan.cpp ------------------------*- C++ -*-===//
+//===-- lib/quadmath/atan.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-rt/lib/FortranFloat128Math/atan2.cpp b/flang-rt/lib/quadmath/atan2.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/atan2.cpp
rename to flang-rt/lib/quadmath/atan2.cpp
index 4e809cb547a1b..7527b224cb3a5 100644
--- a/flang-rt/lib/FortranFloat128Math/atan2.cpp
+++ b/flang-rt/lib/quadmath/atan2.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/atan2.cpp -----------------------*- C++ -*-===//
+//===-- lib/quadmath/atan2.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-rt/lib/FortranFloat128Math/atanh.cpp b/flang-rt/lib/quadmath/atanh.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/atanh.cpp
rename to flang-rt/lib/quadmath/atanh.cpp
index d4e3e7426b16d..c7455fcb7ca67 100644
--- a/flang-rt/lib/FortranFloat128Math/atanh.cpp
+++ b/flang-rt/lib/quadmath/atanh.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/atanh.cpp -----------------------*- C++ -*-===//
+//===-- lib/quadmath/atanh.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-rt/lib/FortranFloat128Math/ceil.cpp b/flang-rt/lib/quadmath/ceil.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/ceil.cpp
rename to flang-rt/lib/quadmath/ceil.cpp
index f439f22c0565a..03a98bedfdc03 100644
--- a/flang-rt/lib/FortranFloat128Math/ceil.cpp
+++ b/flang-rt/lib/quadmath/ceil.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/ceil.cpp ------------------------*- C++ -*-===//
+//===-- lib/quadmath/ceil.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-rt/lib/FortranFloat128Math/complex-math.c b/flang-rt/lib/quadmath/complex-math.c
similarity index 96%
rename from flang-rt/lib/FortranFloat128Math/complex-math.c
rename to flang-rt/lib/quadmath/complex-math.c
index fed37dfce6332..e485fd7eb5dbb 100644
--- a/flang-rt/lib/FortranFloat128Math/complex-math.c
+++ b/flang-rt/lib/quadmath/complex-math.c
@@ -1,4 +1,4 @@
-/*===-- lib/FortranFloat128Math/complex-math.c ----------------------*- C -*-===
+/*===-- lib/quadmath/complex-math.c ---------------------------------*- 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-rt/lib/FortranFloat128Math/complex-math.h b/flang-rt/lib/quadmath/complex-math.h
similarity index 88%
rename from flang-rt/lib/FortranFloat128Math/complex-math.h
rename to flang-rt/lib/quadmath/complex-math.h
index d22598d52e832..424ed84da4e01 100644
--- a/flang-rt/lib/FortranFloat128Math/complex-math.h
+++ b/flang-rt/lib/quadmath/complex-math.h
@@ -1,4 +1,4 @@
-/*===-- lib/FortranFloat128Math/complex-math.h ----------------------*- C -*-===
+/*===-- lib/quadmath/complex-math.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 FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_
-#define FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_
+#ifndef FLANG_RT_QUADMATH_COMPLEX_MATH_H_
+#define FLANG_RT_QUADMATH_COMPLEX_MATH_H_
 
 #include "flang/Common/float128.h"
 #include "flang/Runtime/entry-names.h"
@@ -59,4 +59,4 @@
 #error "Float128Math build with glibc>=2.26 is unsupported yet"
 #endif
 
-#endif // FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_
+#endif /* FLANG_RT_QUADMATH_COMPLEX_MATH_H_ */
diff --git a/flang-rt/lib/FortranFloat128Math/cos.cpp b/flang-rt/lib/quadmath/cos.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/cos.cpp
rename to flang-rt/lib/quadmath/cos.cpp
index aed337c325836..1116080c53d2a 100644
--- a/flang-rt/lib/FortranFloat128Math/cos.cpp
+++ b/flang-rt/lib/quadmath/cos.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/cos.cpp -------------------------*- C++ -*-===//
+//===-- lib/quadmath/cos.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-rt/lib/FortranFloat128Math/cosh.cpp b/flang-rt/lib/quadmath/cosh.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/cosh.cpp
rename to flang-rt/lib/quadmath/cosh.cpp
index bddbff766b575..dd5978e5e5f08 100644
--- a/flang-rt/lib/FortranFloat128Math/cosh.cpp
+++ b/flang-rt/lib/quadmath/cosh.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/cosh.cpp ------------------------*- C++ -*-===//
+//===-- lib/quadmath/cosh.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-rt/lib/FortranFloat128Math/erf.cpp b/flang-rt/lib/quadmath/erf.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/erf.cpp
rename to flang-rt/lib/quadmath/erf.cpp
index a56430040248d..0021b7900f6a1 100644
--- a/flang-rt/lib/FortranFloat128Math/erf.cpp
+++ b/flang-rt/lib/quadmath/erf.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/erf.cpp -------------------------*- C++ -*-===//
+//===-- lib/quadmath/erf.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-rt/lib/FortranFloat128Math/erfc.cpp b/flang-rt/lib/quadmath/erfc.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/erfc.cpp
rename to flang-rt/lib/quadmath/erfc.cpp
index 255a2a7b4edac..5b80fb475b3fc 100644
--- a/flang-rt/lib/FortranFloat128Math/erfc.cpp
+++ b/flang-rt/lib/quadmath/erfc.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/erfc.cpp ------------------------*- C++ -*-===//
+//===-- lib/quadmath/erfc.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-rt/lib/FortranFloat128Math/exp.cpp b/flang-rt/lib/quadmath/exp.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/exp.cpp
rename to flang-rt/lib/quadmath/exp.cpp
index 9bc87d959cf69..94e444c3b00c7 100644
--- a/flang-rt/lib/FortranFloat128Math/exp.cpp
+++ b/flang-rt/lib/quadmath/exp.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/exp.cpp -------------------------*- C++ -*-===//
+//===-- lib/quadmath/exp.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-rt/lib/FortranFloat128Math/exponent.cpp b/flang-rt/lib/quadmath/exponent.cpp
similarity index 92%
rename from flang-rt/lib/FortranFloat128Math/exponent.cpp
rename to flang-rt/lib/quadmath/exponent.cpp
index bf27a26a73427..0d2fa6478cca8 100644
--- a/flang-rt/lib/FortranFloat128Math/exponent.cpp
+++ b/flang-rt/lib/quadmath/exponent.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/exponent.cpp --------------------*- C++ -*-===//
+//===-- lib/quadmath/exponent.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-rt/lib/FortranFloat128Math/floor.cpp b/flang-rt/lib/quadmath/floor.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/floor.cpp
rename to flang-rt/lib/quadmath/floor.cpp
index abda5fadfd296..e5dfb33db82ce 100644
--- a/flang-rt/lib/FortranFloat128Math/floor.cpp
+++ b/flang-rt/lib/quadmath/floor.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/floor.cpp -----------------------*- C++ -*-===//
+//===-- lib/quadmath/floor.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-rt/lib/FortranFloat128Math/fma.cpp b/flang-rt/lib/quadmath/fma.cpp
similarity index 91%
rename from flang-rt/lib/FortranFloat128Math/fma.cpp
rename to flang-rt/lib/quadmath/fma.cpp
index 2e7aabedf1e8c..910303af32339 100644
--- a/flang-rt/lib/FortranFloat128Math/fma.cpp
+++ b/flang-rt/lib/quadmath/fma.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/fma.cpp -------------------------*- C++ -*-===//
+//===-- lib/quadmath/fma.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-rt/lib/FortranFloat128Math/fraction.cpp b/flang-rt/lib/quadmath/fraction.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/fraction.cpp
rename to flang-rt/lib/quadmath/fraction.cpp
index bf1da6f63e5ce..a9927666a7b00 100644
--- a/flang-rt/lib/FortranFloat128Math/fraction.cpp
+++ b/flang-rt/lib/quadmath/fraction.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/fraction.cpp --------------------*- C++ -*-===//
+//===-- lib/quadmath/fraction.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-rt/lib/FortranFloat128Math/hypot.cpp b/flang-rt/lib/quadmath/hypot.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/hypot.cpp
rename to flang-rt/lib/quadmath/hypot.cpp
index 910bda798c1a0..3090d0b2aff74 100644
--- a/flang-rt/lib/FortranFloat128Math/hypot.cpp
+++ b/flang-rt/lib/quadmath/hypot.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/hypot.cpp -----------------------*- C++ -*-===//
+//===-- lib/quadmath/hypot.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-rt/lib/FortranFloat128Math/j0.cpp b/flang-rt/lib/quadmath/j0.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/j0.cpp
rename to flang-rt/lib/quadmath/j0.cpp
index d2fac98c3ec69..06df1c2aca452 100644
--- a/flang-rt/lib/FortranFloat128Math/j0.cpp
+++ b/flang-rt/lib/quadmath/j0.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/j0.cpp --------------------------*- C++ -*-===//
+//===-- lib/quadmath/j0.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-rt/lib/FortranFloat128Math/j1.cpp b/flang-rt/lib/quadmath/j1.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/j1.cpp
rename to flang-rt/lib/quadmath/j1.cpp
index 60401030124c8..d8a1f123b95e6 100644
--- a/flang-rt/lib/FortranFloat128Math/j1.cpp
+++ b/flang-rt/lib/quadmath/j1.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/j1.cpp --------------------------*- C++ -*-===//
+//===-- lib/quadmath/j1.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-rt/lib/FortranFloat128Math/jn.cpp b/flang-rt/lib/quadmath/jn.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/jn.cpp
rename to flang-rt/lib/quadmath/jn.cpp
index 71e11335d0830..a53e305bb8746 100644
--- a/flang-rt/lib/FortranFloat128Math/jn.cpp
+++ b/flang-rt/lib/quadmath/jn.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/jn.cpp --------------------------*- C++ -*-===//
+//===-- lib/quadmath/jn.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-rt/lib/FortranFloat128Math/lgamma.cpp b/flang-rt/lib/quadmath/lgamma.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/lgamma.cpp
rename to flang-rt/lib/quadmath/lgamma.cpp
index 1ae4cc4d95d61..b96dff1d0d72a 100644
--- a/flang-rt/lib/FortranFloat128Math/lgamma.cpp
+++ b/flang-rt/lib/quadmath/lgamma.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/lgamma.cpp ----------------------*- C++ -*-===//
+//===-- lib/quadmath/lgamma.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-rt/lib/FortranFloat128Math/llround.cpp b/flang-rt/lib/quadmath/llround.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/llround.cpp
rename to flang-rt/lib/quadmath/llround.cpp
index 5bd4cc26dd497..8f2913d390431 100644
--- a/flang-rt/lib/FortranFloat128Math/llround.cpp
+++ b/flang-rt/lib/quadmath/llround.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/llround.cpp ---------------------*- C++ -*-===//
+//===-- lib/quadmath/llround.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-rt/lib/FortranFloat128Math/log.cpp b/flang-rt/lib/quadmath/log.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/log.cpp
rename to flang-rt/lib/quadmath/log.cpp
index 414e41ae0ce29..0c489c922a3fc 100644
--- a/flang-rt/lib/FortranFloat128Math/log.cpp
+++ b/flang-rt/lib/quadmath/log.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/log.cpp -------------------------*- C++ -*-===//
+//===-- lib/quadmath/log.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-rt/lib/FortranFloat128Math/log10.cpp b/flang-rt/lib/quadmath/log10.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/log10.cpp
rename to flang-rt/lib/quadmath/log10.cpp
index 55db1b1a2dc1f..a2f222e15a147 100644
--- a/flang-rt/lib/FortranFloat128Math/log10.cpp
+++ b/flang-rt/lib/quadmath/log10.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/log10.cpp -----------------------*- C++ -*-===//
+//===-- lib/quadmath/log10.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-rt/lib/FortranFloat128Math/lround.cpp b/flang-rt/lib/quadmath/lround.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/lround.cpp
rename to flang-rt/lib/quadmath/lround.cpp
index a0bea49243681..539ee107a3881 100644
--- a/flang-rt/lib/FortranFloat128Math/lround.cpp
+++ b/flang-rt/lib/quadmath/lround.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/lround.cpp ----------------------*- C++ -*-===//
+//===-- lib/quadmath/lround.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-rt/lib/FortranFloat128Math/math-entries.h b/flang-rt/lib/quadmath/math-entries.h
similarity index 96%
rename from flang-rt/lib/FortranFloat128Math/math-entries.h
rename to flang-rt/lib/quadmath/math-entries.h
index 72b12a1645c7d..6e47f32cc8a43 100644
--- a/flang-rt/lib/FortranFloat128Math/math-entries.h
+++ b/flang-rt/lib/quadmath/math-entries.h
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/math-entries.h ------------------*- C++ -*-===//
+//===-- lib/quadmath/math-entries.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 FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_
-#define FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_
+#ifndef FLANG_RT_QUADMATH_MATH_ENTRIES_H_
+#define FLANG_RT_QUADMATH_MATH_ENTRIES_H_
 
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/entry-names.h"
 #include <cfloat>
@@ -232,4 +232,4 @@ DEFINE_SIMPLE_ALIAS(Yn, ynl)
 
 } // namespace Fortran::runtime
 
-#endif // FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_
+#endif // FLANG_RT_QUADMATH_MATH_ENTRIES_H_
diff --git a/flang-rt/lib/FortranFloat128Math/mod-real.cpp b/flang-rt/lib/quadmath/mod-real.cpp
similarity index 91%
rename from flang-rt/lib/FortranFloat128Math/mod-real.cpp
rename to flang-rt/lib/quadmath/mod-real.cpp
index beb412f719c52..0230964e3ddc2 100644
--- a/flang-rt/lib/FortranFloat128Math/mod-real.cpp
+++ b/flang-rt/lib/quadmath/mod-real.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/mod-real.cpp --------------------*- C++ -*-===//
+//===-- lib/quadmath/mod-real.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-rt/lib/FortranFloat128Math/modulo-real.cpp b/flang-rt/lib/quadmath/modulo-real.cpp
similarity index 91%
rename from flang-rt/lib/FortranFloat128Math/modulo-real.cpp
rename to flang-rt/lib/quadmath/modulo-real.cpp
index c8160b1d27451..0f28747b86985 100644
--- a/flang-rt/lib/FortranFloat128Math/modulo-real.cpp
+++ b/flang-rt/lib/quadmath/modulo-real.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/modulo-real.cpp -----------------*- C++ -*-===//
+//===-- lib/quadmath/modulo-real.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-rt/lib/FortranFloat128Math/nearbyint.cpp b/flang-rt/lib/quadmath/nearbyint.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/nearbyint.cpp
rename to flang-rt/lib/quadmath/nearbyint.cpp
index d572641e2b0d4..3811fc53d1d82 100644
--- a/flang-rt/lib/FortranFloat128Math/nearbyint.cpp
+++ b/flang-rt/lib/quadmath/nearbyint.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/nearbyint.cpp -------------------*- C++ -*-===//
+//===-- lib/quadmath/nearbyint.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-rt/lib/FortranFloat128Math/nearest.cpp b/flang-rt/lib/quadmath/nearest.cpp
similarity index 91%
rename from flang-rt/lib/FortranFloat128Math/nearest.cpp
rename to flang-rt/lib/quadmath/nearest.cpp
index 3e32de7ea9d0a..8c1969a7b596c 100644
--- a/flang-rt/lib/FortranFloat128Math/nearest.cpp
+++ b/flang-rt/lib/quadmath/nearest.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/nearest.cpp ---------------------*- C++ -*-===//
+//===-- lib/quadmath/nearest.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-rt/lib/FortranFloat128Math/norm2.cpp b/flang-rt/lib/quadmath/norm2.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/norm2.cpp
rename to flang-rt/lib/quadmath/norm2.cpp
index 8f6b2c87eec32..e98f4007737d1 100644
--- a/flang-rt/lib/FortranFloat128Math/norm2.cpp
+++ b/flang-rt/lib/quadmath/norm2.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/norm2.cpp -----------------------*- C++ -*-===//
+//===-- lib/quadmath/norm2.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.
@@ -8,7 +8,7 @@
 
 #include "math-entries.h"
 #include "numeric-template-specs.h"
-#include "flang-rt/reduction-templates.h"
+#include "flang-rt/runtime/reduction-templates.h"
 
 namespace Fortran::runtime {
 extern "C" {
diff --git a/flang-rt/lib/FortranFloat128Math/numeric-template-specs.h b/flang-rt/lib/quadmath/numeric-template-specs.h
similarity index 82%
rename from flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
rename to flang-rt/lib/quadmath/numeric-template-specs.h
index e618902b03adc..e215ad70eca14 100644
--- a/flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
+++ b/flang-rt/lib/quadmath/numeric-template-specs.h
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/numeric-template-specs.h --------*- C++ -*-===//
+//===-- lib/quadmath/numeric-template-specs.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 FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
-#define FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
+#ifndef FLANG_RT_QUADMATH_NUMERIC_TEMPLATE_SPECS_H_
+#define FLANG_RT_QUADMATH_NUMERIC_TEMPLATE_SPECS_H_
 
 #include "math-entries.h"
-#include "flang-rt/numeric-templates.h"
+#include "flang-rt/runtime/numeric-templates.h"
 
 namespace Fortran::runtime {
 using F128Type = CppTypeFor<TypeCategory::Real, 16>;
@@ -52,4 +52,4 @@ template <> struct SQRTTy<F128Type> {
 };
 
 } // namespace Fortran::runtime
-#endif // FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
+#endif // FLANG_RT_QUADMATH_NUMERIC_TEMPLATE_SPECS_H_
diff --git a/flang-rt/lib/FortranFloat128Math/pow.cpp b/flang-rt/lib/quadmath/pow.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/pow.cpp
rename to flang-rt/lib/quadmath/pow.cpp
index bbdda217c5108..29c0536254658 100644
--- a/flang-rt/lib/FortranFloat128Math/pow.cpp
+++ b/flang-rt/lib/quadmath/pow.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/pow.cpp -------------------------*- C++ -*-===//
+//===-- lib/quadmath/pow.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-rt/lib/FortranFloat128Math/random.cpp b/flang-rt/lib/quadmath/random.cpp
similarity index 85%
rename from flang-rt/lib/FortranFloat128Math/random.cpp
rename to flang-rt/lib/quadmath/random.cpp
index 701f9429fcb6c..a6d22733ebce4 100644
--- a/flang-rt/lib/FortranFloat128Math/random.cpp
+++ b/flang-rt/lib/quadmath/random.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/random.cpp ----------------------*- C++ -*-===//
+//===-- lib/quadmath/random.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.
@@ -8,7 +8,7 @@
 
 #include "math-entries.h"
 #include "numeric-template-specs.h"
-#include "flang-rt/random-templates.h"
+#include "flang-rt/runtime/random-templates.h"
 
 using namespace Fortran::runtime::random;
 extern "C" {
diff --git a/flang-rt/lib/FortranFloat128Math/remainder.cpp b/flang-rt/lib/quadmath/remainder.cpp
similarity index 91%
rename from flang-rt/lib/FortranFloat128Math/remainder.cpp
rename to flang-rt/lib/quadmath/remainder.cpp
index ca4165a357eda..4b68cdd6ac9de 100644
--- a/flang-rt/lib/FortranFloat128Math/remainder.cpp
+++ b/flang-rt/lib/quadmath/remainder.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/remainder.cpp -------------------*- C++ -*-===//
+//===-- lib/quadmath/remainder.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-rt/lib/FortranFloat128Math/round.cpp b/flang-rt/lib/quadmath/round.cpp
similarity index 91%
rename from flang-rt/lib/FortranFloat128Math/round.cpp
rename to flang-rt/lib/quadmath/round.cpp
index 348f7ff8a6771..844338f5e6413 100644
--- a/flang-rt/lib/FortranFloat128Math/round.cpp
+++ b/flang-rt/lib/quadmath/round.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/round.cpp -----------------------*- C++ -*-===//
+//===-- lib/quadmath/round.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-rt/lib/FortranFloat128Math/rrspacing.cpp b/flang-rt/lib/quadmath/rrspacing.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/rrspacing.cpp
rename to flang-rt/lib/quadmath/rrspacing.cpp
index 0a87a5c572652..e8613f4d7d7e2 100644
--- a/flang-rt/lib/FortranFloat128Math/rrspacing.cpp
+++ b/flang-rt/lib/quadmath/rrspacing.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/rrspacing.cpp -------------------*- C++ -*-===//
+//===-- lib/quadmath/rrspacing.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-rt/lib/FortranFloat128Math/scale.cpp b/flang-rt/lib/quadmath/scale.cpp
similarity index 92%
rename from flang-rt/lib/FortranFloat128Math/scale.cpp
rename to flang-rt/lib/quadmath/scale.cpp
index a316a2a0cd706..3d919f85a4487 100644
--- a/flang-rt/lib/FortranFloat128Math/scale.cpp
+++ b/flang-rt/lib/quadmath/scale.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/scale.cpp -----------------------*- C++ -*-===//
+//===-- lib/quadmath/scale.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-rt/lib/FortranFloat128Math/set-exponent.cpp b/flang-rt/lib/quadmath/set-exponent.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/set-exponent.cpp
rename to flang-rt/lib/quadmath/set-exponent.cpp
index 335c68f632f18..d6b582e7c4f38 100644
--- a/flang-rt/lib/FortranFloat128Math/set-exponent.cpp
+++ b/flang-rt/lib/quadmath/set-exponent.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/set-exponent.cpp ----------------*- C++ -*-===//
+//===-- lib/quadmath/set-exponent.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-rt/lib/FortranFloat128Math/sin.cpp b/flang-rt/lib/quadmath/sin.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/sin.cpp
rename to flang-rt/lib/quadmath/sin.cpp
index bd5f62808fc31..dcff2f9ce02ca 100644
--- a/flang-rt/lib/FortranFloat128Math/sin.cpp
+++ b/flang-rt/lib/quadmath/sin.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/sin.cpp -------------------------*- C++ -*-===//
+//===-- lib/quadmath/sin.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-rt/lib/FortranFloat128Math/sinh.cpp b/flang-rt/lib/quadmath/sinh.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/sinh.cpp
rename to flang-rt/lib/quadmath/sinh.cpp
index 07f12d437ed56..3ab7280f705a6 100644
--- a/flang-rt/lib/FortranFloat128Math/sinh.cpp
+++ b/flang-rt/lib/quadmath/sinh.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/sinh.cpp ------------------------*- C++ -*-===//
+//===-- lib/quadmath/sinh.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-rt/lib/FortranFloat128Math/spacing.cpp b/flang-rt/lib/quadmath/spacing.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/spacing.cpp
rename to flang-rt/lib/quadmath/spacing.cpp
index b10351ab95555..1d7ecdb4852d2 100644
--- a/flang-rt/lib/FortranFloat128Math/spacing.cpp
+++ b/flang-rt/lib/quadmath/spacing.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/spacing.cpp ---------------------*- C++ -*-===//
+//===-- lib/quadmath/spacing.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-rt/lib/FortranFloat128Math/sqrt.cpp b/flang-rt/lib/quadmath/sqrt.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/sqrt.cpp
rename to flang-rt/lib/quadmath/sqrt.cpp
index b6fd6eabc267b..6e0d11a6697f0 100644
--- a/flang-rt/lib/FortranFloat128Math/sqrt.cpp
+++ b/flang-rt/lib/quadmath/sqrt.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/sqrt.cpp ------------------------*- C++ -*-===//
+//===-- lib/quadmath/sqrt.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-rt/lib/FortranFloat128Math/tan.cpp b/flang-rt/lib/quadmath/tan.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/tan.cpp
rename to flang-rt/lib/quadmath/tan.cpp
index 437c0692191e8..6f09b93060228 100644
--- a/flang-rt/lib/FortranFloat128Math/tan.cpp
+++ b/flang-rt/lib/quadmath/tan.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/tan.cpp -------------------------*- C++ -*-===//
+//===-- lib/quadmath/tan.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-rt/lib/FortranFloat128Math/tanh.cpp b/flang-rt/lib/quadmath/tanh.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/tanh.cpp
rename to flang-rt/lib/quadmath/tanh.cpp
index 48544d4bb75f4..214a18d5c3778 100644
--- a/flang-rt/lib/FortranFloat128Math/tanh.cpp
+++ b/flang-rt/lib/quadmath/tanh.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/tanh.cpp ------------------------*- C++ -*-===//
+//===-- lib/quadmath/tanh.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-rt/lib/FortranFloat128Math/tgamma.cpp b/flang-rt/lib/quadmath/tgamma.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/tgamma.cpp
rename to flang-rt/lib/quadmath/tgamma.cpp
index 8d7963caa61c5..2b05a60dcaabb 100644
--- a/flang-rt/lib/FortranFloat128Math/tgamma.cpp
+++ b/flang-rt/lib/quadmath/tgamma.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/tgamma.cpp ----------------------*- C++ -*-===//
+//===-- lib/quadmath/tgamma.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-rt/lib/FortranFloat128Math/trunc.cpp b/flang-rt/lib/quadmath/trunc.cpp
similarity index 91%
rename from flang-rt/lib/FortranFloat128Math/trunc.cpp
rename to flang-rt/lib/quadmath/trunc.cpp
index 4a3dddeb1326c..cd7c27b569fc3 100644
--- a/flang-rt/lib/FortranFloat128Math/trunc.cpp
+++ b/flang-rt/lib/quadmath/trunc.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/trunc.cpp -----------------------*- C++ -*-===//
+//===-- lib/quadmath/trunc.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-rt/lib/FortranFloat128Math/y0.cpp b/flang-rt/lib/quadmath/y0.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/y0.cpp
rename to flang-rt/lib/quadmath/y0.cpp
index c5b266b5cec03..9db04277660ad 100644
--- a/flang-rt/lib/FortranFloat128Math/y0.cpp
+++ b/flang-rt/lib/quadmath/y0.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/y0.cpp --------------------------*- C++ -*-===//
+//===-- lib/quadmath/y0.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-rt/lib/FortranFloat128Math/y1.cpp b/flang-rt/lib/quadmath/y1.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/y1.cpp
rename to flang-rt/lib/quadmath/y1.cpp
index 8b492c69e3741..92e658195f3d9 100644
--- a/flang-rt/lib/FortranFloat128Math/y1.cpp
+++ b/flang-rt/lib/quadmath/y1.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/y1.cpp --------------------------*- C++ -*-===//
+//===-- lib/quadmath/y1.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-rt/lib/FortranFloat128Math/yn.cpp b/flang-rt/lib/quadmath/yn.cpp
similarity index 90%
rename from flang-rt/lib/FortranFloat128Math/yn.cpp
rename to flang-rt/lib/quadmath/yn.cpp
index cb212b400f6e0..20c0bc9d5218e 100644
--- a/flang-rt/lib/FortranFloat128Math/yn.cpp
+++ b/flang-rt/lib/quadmath/yn.cpp
@@ -1,4 +1,4 @@
-//===-- lib/FortranFloat128Math/yn.cpp --------------------------*- C++ -*-===//
+//===-- lib/quadmath/yn.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-rt/lib/flang_rt/ISO_Fortran_binding.cpp b/flang-rt/lib/runtime/ISO_Fortran_binding.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
rename to flang-rt/lib/runtime/ISO_Fortran_binding.cpp
index d9b0bfe9aeb6b..a5f8b357ae0b8 100644
--- a/flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
+++ b/flang-rt/lib/runtime/ISO_Fortran_binding.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/ISO_Fortran_binding.cpp --------------------*- C++ -*-===//
+//===-- lib/runtime/ISO_Fortran_binding.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,9 +10,9 @@
 // as specified in section 18.5.5 of Fortran 2018.
 
 #include "ISO_Fortran_util.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/type-code.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/type-code.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/pointer.h"
 #include <cstdlib>
diff --git a/flang-rt/lib/flang_rt/ISO_Fortran_util.h b/flang-rt/lib/runtime/ISO_Fortran_util.h
similarity index 90%
rename from flang-rt/lib/flang_rt/ISO_Fortran_util.h
rename to flang-rt/lib/runtime/ISO_Fortran_util.h
index 9d4a907e1adde..9bbc03eefc490 100644
--- a/flang-rt/lib/flang_rt/ISO_Fortran_util.h
+++ b/flang-rt/lib/runtime/ISO_Fortran_util.h
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/ISO_Fortran_util.h -------------------------*- C++ -*-===//
+//===-- lib/runtime/ISO_Fortran_util.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 FLANG_RT_ISO_FORTRAN_UTIL_H_
-#define FLANG_RT_ISO_FORTRAN_UTIL_H_
+#ifndef FLANG_RT_RUNTIME_ISO_FORTRAN_UTIL_H_
+#define FLANG_RT_RUNTIME_ISO_FORTRAN_UTIL_H_
 
 // Internal utils for establishing CFI_cdesc_t descriptors.
 
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/type-code.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/type-code.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include <cstdlib>
 
@@ -99,4 +99,4 @@ static inline RT_API_ATTRS void EstablishDescriptor(CFI_cdesc_t *descriptor,
   }
 }
 } // namespace Fortran::ISO
-#endif // FLANG_RT_ISO_FORTRAN_UTIL_H_
+#endif // FLANG_RT_RUNTIME_ISO_FORTRAN_UTIL_H_
diff --git a/flang-rt/lib/flang_rt/allocatable.cpp b/flang-rt/lib/runtime/allocatable.cpp
similarity index 96%
rename from flang-rt/lib/flang_rt/allocatable.cpp
rename to flang-rt/lib/runtime/allocatable.cpp
index 63ef99b8a72d1..a51816129199a 100644
--- a/flang-rt/lib/flang_rt/allocatable.cpp
+++ b/flang-rt/lib/runtime/allocatable.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/allocatable.cpp ----------------------------*- C++ -*-===//
+//===-- lib/runtime/allocatable.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.
@@ -7,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/allocatable.h"
-#include "flang-rt/assign-impl.h"
-#include "flang-rt/derived.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/stat.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/type-info.h"
+#include "flang-rt/runtime/assign-impl.h"
+#include "flang-rt/runtime/derived.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/stat.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/type-info.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/assign.h"
 
diff --git a/flang-rt/lib/flang_rt/allocator-registry.cpp b/flang-rt/lib/runtime/allocator-registry.cpp
similarity index 89%
rename from flang-rt/lib/flang_rt/allocator-registry.cpp
rename to flang-rt/lib/runtime/allocator-registry.cpp
index 11847de68724d..f8a8daaf8e748 100644
--- a/flang-rt/lib/flang_rt/allocator-registry.cpp
+++ b/flang-rt/lib/runtime/allocator-registry.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/allocator-registry.cpp ---------------------*- C++ -*-===//
+//===-- lib/runtime/allocator-registry.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-rt/allocator-registry.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/allocator-registry.h"
+#include "flang-rt/runtime/terminator.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang-rt/lib/flang_rt/array-constructor.cpp b/flang-rt/lib/runtime/array-constructor.cpp
similarity index 96%
rename from flang-rt/lib/flang_rt/array-constructor.cpp
rename to flang-rt/lib/runtime/array-constructor.cpp
index d2765c9439b75..7e267e714927f 100644
--- a/flang-rt/lib/flang_rt/array-constructor.cpp
+++ b/flang-rt/lib/runtime/array-constructor.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/array-constructor.cpp ----------------------*- C++ -*-===//
+//===-- lib/runtime/array-constructor.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,12 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/array-constructor.h"
-#include "flang-rt/derived.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
-#include "flang-rt/type-info.h"
+#include "flang-rt/runtime/array-constructor.h"
+#include "flang-rt/runtime/derived.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
+#include "flang-rt/runtime/type-info.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/assign.h"
 
diff --git a/flang-rt/lib/flang_rt/assign.cpp b/flang-rt/lib/runtime/assign.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/assign.cpp
rename to flang-rt/lib/runtime/assign.cpp
index 0d6045eac503a..a1f3715f278c1 100644
--- a/flang-rt/lib/flang_rt/assign.cpp
+++ b/flang-rt/lib/runtime/assign.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/assign.cpp ---------------------------------*- C++ -*-===//
+//===-- lib/runtime/assign.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.
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/assign.h"
-#include "flang-rt/assign-impl.h"
-#include "flang-rt/derived.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/stat.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
-#include "flang-rt/type-info.h"
+#include "flang-rt/runtime/assign-impl.h"
+#include "flang-rt/runtime/derived.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/stat.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
+#include "flang-rt/runtime/type-info.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang-rt/lib/flang_rt/buffer.cpp b/flang-rt/lib/runtime/buffer.cpp
similarity index 90%
rename from flang-rt/lib/flang_rt/buffer.cpp
rename to flang-rt/lib/runtime/buffer.cpp
index e084155068bc5..4cf85e13b6d36 100644
--- a/flang-rt/lib/flang_rt/buffer.cpp
+++ b/flang-rt/lib/runtime/buffer.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/buffer.cpp ---------------------------------*- C++ -*-===//
+//===-- lib/runtime/buffer.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-rt/buffer.h"
+#include "flang-rt/runtime/buffer.h"
 #include <algorithm>
 
 namespace Fortran::runtime::io {
diff --git a/flang-rt/lib/flang_rt/character.cpp b/flang-rt/lib/runtime/character.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/character.cpp
rename to flang-rt/lib/runtime/character.cpp
index 79d4ebdb0afbf..10cf27c37c4d8 100644
--- a/flang-rt/lib/flang_rt/character.cpp
+++ b/flang-rt/lib/runtime/character.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/character.cpp ------------------------------*- C++ -*-===//
+//===-- lib/runtime/character.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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/character.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Common/bit-population-count.h"
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/character.h"
diff --git a/flang-rt/lib/flang_rt/command.cpp b/flang-rt/lib/runtime/command.cpp
similarity index 96%
rename from flang-rt/lib/flang_rt/command.cpp
rename to flang-rt/lib/runtime/command.cpp
index 498ae8db17224..8a5a61ac1ad44 100644
--- a/flang-rt/lib/flang_rt/command.cpp
+++ b/flang-rt/lib/runtime/command.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/command.cpp --------------------------------*- C++ -*-===//
+//===-- lib/runtime/command.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.
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/command.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/environment.h"
-#include "flang-rt/stat.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/environment.h"
+#include "flang-rt/runtime/stat.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include <cstdlib>
 #include <limits>
 
diff --git a/flang-rt/lib/flang_rt/complex-powi.cpp b/flang-rt/lib/runtime/complex-powi.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/complex-powi.cpp
rename to flang-rt/lib/runtime/complex-powi.cpp
index 287bafc422057..a561d114591cf 100644
--- a/flang-rt/lib/flang_rt/complex-powi.cpp
+++ b/flang-rt/lib/runtime/complex-powi.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/complex-powi.cpp ---------------------------*- C++ -*-===//
+//===-- lib/runtime/complex-powi.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-rt/lib/flang_rt/complex-reduction.c b/flang-rt/lib/runtime/complex-reduction.c
similarity index 100%
rename from flang-rt/lib/flang_rt/complex-reduction.c
rename to flang-rt/lib/runtime/complex-reduction.c
diff --git a/flang-rt/lib/flang_rt/complex-reduction.h b/flang-rt/lib/runtime/complex-reduction.h
similarity index 97%
rename from flang-rt/lib/flang_rt/complex-reduction.h
rename to flang-rt/lib/runtime/complex-reduction.h
index 45614ea660573..44c52fb02fa43 100644
--- a/flang-rt/lib/flang_rt/complex-reduction.h
+++ b/flang-rt/lib/runtime/complex-reduction.h
@@ -1,4 +1,4 @@
-/*===-- lib/flang_rt/complex-reduction.h ----------------------------*- C -*-===
+/*===-- lib/runtime/complex-reduction.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 @@
  * with C++ build compilers that don't support C's _Complex.
  */
 
-#ifndef FLANG_RT_COMPLEX_REDUCTION_H_
-#define FLANG_RT_COMPLEX_REDUCTION_H_
+#ifndef FLANG_RT_RUNTIME_COMPLEX_REDUCTION_H_
+#define FLANG_RT_RUNTIME_COMPLEX_REDUCTION_H_
 
 #include "flang/Common/float128.h"
 #include "flang/Runtime/entry-names.h"
@@ -155,4 +155,4 @@ void RTNAME(ReduceComplex16DimValue)(
     REDUCE_DIM_ARGS(CFloat128ComplexType, CFloat128ComplexType_value_op));
 #endif
 
-#endif // FLANG_RT_COMPLEX_REDUCTION_H_
+#endif // FLANG_RT_RUNTIME_COMPLEX_REDUCTION_H_
diff --git a/flang-rt/lib/flang_rt/connection.cpp b/flang-rt/lib/runtime/connection.cpp
similarity index 91%
rename from flang-rt/lib/flang_rt/connection.cpp
rename to flang-rt/lib/runtime/connection.cpp
index 1c454b81389ac..2f01dbbb95920 100644
--- a/flang-rt/lib/flang_rt/connection.cpp
+++ b/flang-rt/lib/runtime/connection.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/connection.cpp -----------------------------*- C++ -*-===//
+//===-- lib/runtime/connection.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-rt/connection.h"
-#include "flang-rt/environment.h"
-#include "flang-rt/io-stmt.h"
+#include "flang-rt/runtime/connection.h"
+#include "flang-rt/runtime/environment.h"
+#include "flang-rt/runtime/io-stmt.h"
 #include <algorithm>
 
 namespace Fortran::runtime::io {
diff --git a/flang-rt/lib/flang_rt/copy.cpp b/flang-rt/lib/runtime/copy.cpp
similarity index 97%
rename from flang-rt/lib/flang_rt/copy.cpp
rename to flang-rt/lib/runtime/copy.cpp
index 0ad6946d3161a..5956642dd7258 100644
--- a/flang-rt/lib/flang_rt/copy.cpp
+++ b/flang-rt/lib/runtime/copy.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/copy.cpp -----------------------------------*- C++ -*-===//
+//===-- lib/runtime/copy.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.
@@ -8,9 +8,9 @@
 
 #include "copy.h"
 #include "stack.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/type-info.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/type-info.h"
 #include "flang/Runtime/allocatable.h"
 #include <cstring>
 
diff --git a/flang-rt/lib/flang_rt/copy.h b/flang-rt/lib/runtime/copy.h
similarity index 78%
rename from flang-rt/lib/flang_rt/copy.h
rename to flang-rt/lib/runtime/copy.h
index f4abac323196b..836c9d4a1ef89 100644
--- a/flang-rt/lib/flang_rt/copy.h
+++ b/flang-rt/lib/runtime/copy.h
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/copy.h -------------------------------------*- C++ -*-===//
+//===-- lib/runtime/copy.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.
@@ -9,10 +9,10 @@
 // Utilities that copy data in a type-aware fashion, allocating & duplicating
 // allocatable/automatic components of derived types along the way.
 
-#ifndef FLANG_RT_COPY_H_
-#define FLANG_RT_COPY_H_
+#ifndef FLANG_RT_RUNTIME_COPY_H_
+#define FLANG_RT_RUNTIME_COPY_H_
 
-#include "flang-rt/descriptor.h"
+#include "flang-rt/runtime/descriptor.h"
 
 namespace Fortran::runtime {
 
@@ -22,4 +22,4 @@ RT_API_ATTRS void CopyElement(const Descriptor &to, const SubscriptValue toAt[],
     const Descriptor &from, const SubscriptValue fromAt[], Terminator &);
 
 } // namespace Fortran::runtime
-#endif // FLANG_RT_COPY_H_
+#endif // FLANG_RT_RUNTIME_COPY_H_
diff --git a/flang-rt/lib/flang_rt/derived-api.cpp b/flang-rt/lib/runtime/derived-api.cpp
similarity index 95%
rename from flang-rt/lib/flang_rt/derived-api.cpp
rename to flang-rt/lib/runtime/derived-api.cpp
index 353bc4a83ebd9..884fa8ee7d095 100644
--- a/flang-rt/lib/flang_rt/derived-api.cpp
+++ b/flang-rt/lib/runtime/derived-api.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/derived-api.cpp ----------------------------*- C++ -*-===//
+//===-- lib/runtime/derived-api.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.
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/derived-api.h"
-#include "flang-rt/derived.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
-#include "flang-rt/type-info.h"
+#include "flang-rt/runtime/derived.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
+#include "flang-rt/runtime/type-info.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang-rt/lib/flang_rt/derived.cpp b/flang-rt/lib/runtime/derived.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/derived.cpp
rename to flang-rt/lib/runtime/derived.cpp
index cace9e1074e65..87e4b29d08c28 100644
--- a/flang-rt/lib/flang_rt/derived.cpp
+++ b/flang-rt/lib/runtime/derived.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/derived.cpp --------------------------------*- C++ -*-===//
+//===-- lib/runtime/derived.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,12 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/derived.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/stat.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
-#include "flang-rt/type-info.h"
+#include "flang-rt/runtime/derived.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/stat.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
+#include "flang-rt/runtime/type-info.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang-rt/lib/flang_rt/descriptor-io.cpp b/flang-rt/lib/runtime/descriptor-io.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/descriptor-io.cpp
rename to flang-rt/lib/runtime/descriptor-io.cpp
index c5cfa4d7fc597..3db1455af52fe 100644
--- a/flang-rt/lib/flang_rt/descriptor-io.cpp
+++ b/flang-rt/lib/runtime/descriptor-io.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/descriptor-io.cpp --------------------------*- C++ -*-===//
+//===-- lib/runtime/descriptor-io.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-rt/lib/flang_rt/descriptor-io.h b/flang-rt/lib/runtime/descriptor-io.h
similarity index 98%
rename from flang-rt/lib/flang_rt/descriptor-io.h
rename to flang-rt/lib/runtime/descriptor-io.h
index 97bedce247d83..dd399164325cb 100644
--- a/flang-rt/lib/flang_rt/descriptor-io.h
+++ b/flang-rt/lib/runtime/descriptor-io.h
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/descriptor-io.h ----------------------------*- C++ -*-===//
+//===-- lib/runtime/descriptor-io.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 FLANG_RT_DESCRIPTOR_IO_H_
-#define FLANG_RT_DESCRIPTOR_IO_H_
+#ifndef FLANG_RT_RUNTIME_DESCRIPTOR_IO_H_
+#define FLANG_RT_RUNTIME_DESCRIPTOR_IO_H_
 
 // Implementation of I/O data list item transfers based on descriptors.
 // (All I/O items come through here so that the code is exercised for test;
@@ -17,11 +17,11 @@
 #include "edit-input.h"
 #include "edit-output.h"
 #include "unit.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/io-stmt.h"
-#include "flang-rt/namelist.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/type-info.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/io-stmt.h"
+#include "flang-rt/runtime/namelist.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/type-info.h"
 #include "flang/Common/optional.h"
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/cpp-type.h"
@@ -626,4 +626,4 @@ static RT_API_ATTRS bool DescriptorIO(IoStatementState &io,
   return false;
 }
 } // namespace Fortran::runtime::io::descr
-#endif // FLANG_RT_DESCRIPTOR_IO_H_
+#endif // FLANG_RT_RUNTIME_DESCRIPTOR_IO_H_
diff --git a/flang-rt/lib/flang_rt/descriptor.cpp b/flang-rt/lib/runtime/descriptor.cpp
similarity index 97%
rename from flang-rt/lib/flang_rt/descriptor.cpp
rename to flang-rt/lib/runtime/descriptor.cpp
index cdf01f12e7134..8241a34a4990c 100644
--- a/flang-rt/lib/flang_rt/descriptor.cpp
+++ b/flang-rt/lib/runtime/descriptor.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/descriptor.cpp -----------------------------*- C++ -*-===//
+//===-- lib/runtime/descriptor.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,15 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/descriptor.h"
+#include "flang-rt/runtime/descriptor.h"
 #include "ISO_Fortran_util.h"
 #include "memory.h"
-#include "flang-rt/allocator-registry.h"
-#include "flang-rt/derived.h"
-#include "flang-rt/stat.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
-#include "flang-rt/type-info.h"
+#include "flang-rt/runtime/allocator-registry.h"
+#include "flang-rt/runtime/derived.h"
+#include "flang-rt/runtime/stat.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
+#include "flang-rt/runtime/type-info.h"
 #include <cassert>
 #include <cstdlib>
 #include <cstring>
diff --git a/flang-rt/lib/flang_rt/dot-product.cpp b/flang-rt/lib/runtime/dot-product.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/dot-product.cpp
rename to flang-rt/lib/runtime/dot-product.cpp
index ad600a4228463..20612f1876c15 100644
--- a/flang-rt/lib/flang_rt/dot-product.cpp
+++ b/flang-rt/lib/runtime/dot-product.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/dot-product.cpp ----------------------------*- C++ -*-===//
+//===-- lib/runtime/dot-product.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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "float.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/cpp-type.h"
 #include "flang/Runtime/reduction.h"
diff --git a/flang-rt/lib/flang_rt/edit-input.cpp b/flang-rt/lib/runtime/edit-input.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/edit-input.cpp
rename to flang-rt/lib/runtime/edit-input.cpp
index 7121f6e42dea6..99a266648f95c 100644
--- a/flang-rt/lib/flang_rt/edit-input.cpp
+++ b/flang-rt/lib/runtime/edit-input.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/edit-input.cpp -----------------------------*- C++ -*-===//
+//===-- lib/runtime/edit-input.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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "edit-input.h"
-#include "flang-rt/namelist.h"
-#include "flang-rt/utf.h"
+#include "flang-rt/runtime/namelist.h"
+#include "flang-rt/runtime/utf.h"
 #include "flang/Common/optional.h"
 #include "flang/Common/real.h"
 #include "flang/Common/uint128.h"
diff --git a/flang-rt/lib/flang_rt/edit-input.h b/flang-rt/lib/runtime/edit-input.h
similarity index 87%
rename from flang-rt/lib/flang_rt/edit-input.h
rename to flang-rt/lib/runtime/edit-input.h
index fdee0f0e1131e..686cd461b3e34 100644
--- a/flang-rt/lib/flang_rt/edit-input.h
+++ b/flang-rt/lib/runtime/edit-input.h
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/edit-input.h -------------------------------*- C++ -*-===//
+//===-- lib/runtime/edit-input.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 FLANG_RT_EDIT_INPUT_H_
-#define FLANG_RT_EDIT_INPUT_H_
+#ifndef FLANG_RT_RUNTIME_EDIT_INPUT_H_
+#define FLANG_RT_RUNTIME_EDIT_INPUT_H_
 
-#include "flang-rt/format.h"
-#include "flang-rt/io-stmt.h"
+#include "flang-rt/runtime/format.h"
+#include "flang-rt/runtime/io-stmt.h"
 #include "flang/Decimal/decimal.h"
 
 namespace Fortran::runtime::io {
@@ -50,4 +50,4 @@ extern template RT_API_ATTRS bool EditCharacterInput(
     IoStatementState &, const DataEdit &, char32_t *, std::size_t);
 
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_EDIT_INPUT_H_
+#endif // FLANG_RT_RUNTIME_EDIT_INPUT_H_
diff --git a/flang-rt/lib/flang_rt/edit-output.cpp b/flang-rt/lib/runtime/edit-output.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/edit-output.cpp
rename to flang-rt/lib/runtime/edit-output.cpp
index 096bd4567a42a..36bbc638ff5fc 100644
--- a/flang-rt/lib/flang_rt/edit-output.cpp
+++ b/flang-rt/lib/runtime/edit-output.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/edit-output.cpp ----------------------------*- C++ -*-===//
+//===-- lib/runtime/edit-output.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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "edit-output.h"
-#include "flang-rt/emit-encoded.h"
-#include "flang-rt/utf.h"
+#include "flang-rt/runtime/emit-encoded.h"
+#include "flang-rt/runtime/utf.h"
 #include "flang/Common/real.h"
 #include "flang/Common/uint128.h"
 #include <algorithm>
diff --git a/flang-rt/lib/flang_rt/edit-output.h b/flang-rt/lib/runtime/edit-output.h
similarity index 95%
rename from flang-rt/lib/flang_rt/edit-output.h
rename to flang-rt/lib/runtime/edit-output.h
index 729f4400bd631..51a47405e49e4 100644
--- a/flang-rt/lib/flang_rt/edit-output.h
+++ b/flang-rt/lib/runtime/edit-output.h
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/edit-output.h ------------------------------*- C++ -*-===//
+//===-- lib/runtime/edit-output.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 FLANG_RT_EDIT_OUTPUT_H_
-#define FLANG_RT_EDIT_OUTPUT_H_
+#ifndef FLANG_RT_RUNTIME_EDIT_OUTPUT_H_
+#define FLANG_RT_RUNTIME_EDIT_OUTPUT_H_
 
 // Output data editing templates implementing the FORMAT data editing
 // descriptors E, EN, ES, EX, D, F, and G for REAL data (and COMPLEX
@@ -18,8 +18,8 @@
 // Drives the same fast binary-to-decimal formatting templates used
 // in the f18 front-end.
 
-#include "flang-rt/format.h"
-#include "flang-rt/io-stmt.h"
+#include "flang-rt/runtime/format.h"
+#include "flang-rt/runtime/io-stmt.h"
 #include "flang/Common/uint128.h"
 #include "flang/Decimal/decimal.h"
 
@@ -138,4 +138,4 @@ extern template class RealOutputEditing<10>;
 extern template class RealOutputEditing<16>;
 
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_EDIT_OUTPUT_H_
+#endif // FLANG_RT_RUNTIME_EDIT_OUTPUT_H_
diff --git a/flang-rt/lib/flang_rt/environment-default-list.h b/flang-rt/lib/runtime/environment-default-list.h
similarity index 100%
rename from flang-rt/lib/flang_rt/environment-default-list.h
rename to flang-rt/lib/runtime/environment-default-list.h
diff --git a/flang-rt/lib/flang_rt/environment.cpp b/flang-rt/lib/runtime/environment.cpp
similarity index 97%
rename from flang-rt/lib/flang_rt/environment.cpp
rename to flang-rt/lib/runtime/environment.cpp
index e3727398b898f..15380ba148df5 100644
--- a/flang-rt/lib/flang_rt/environment.cpp
+++ b/flang-rt/lib/runtime/environment.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/environment.cpp ----------------------------*- C++ -*-===//
+//===-- lib/runtime/environment.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,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/environment.h"
+#include "flang-rt/runtime/environment.h"
 #include "environment-default-list.h"
 #include "memory.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/tools.h"
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
diff --git a/flang-rt/lib/flang_rt/exceptions.cpp b/flang-rt/lib/runtime/exceptions.cpp
similarity index 97%
rename from flang-rt/lib/flang_rt/exceptions.cpp
rename to flang-rt/lib/runtime/exceptions.cpp
index f417aa8810f1c..d676a0ad53aa9 100644
--- a/flang-rt/lib/flang_rt/exceptions.cpp
+++ b/flang-rt/lib/runtime/exceptions.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/exceptions.cpp -----------------------------*- C++ -*-===//
+//===-- lib/runtime/exceptions.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.
@@ -9,7 +9,7 @@
 // Runtime exception support.
 
 #include "flang/Runtime/exceptions.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/terminator.h"
 #include <cfenv>
 #if defined(__aarch64__) && !defined(_WIN32)
 #include <fpu_control.h>
diff --git a/flang-rt/lib/flang_rt/execute.cpp b/flang-rt/lib/runtime/execute.cpp
similarity index 97%
rename from flang-rt/lib/flang_rt/execute.cpp
rename to flang-rt/lib/runtime/execute.cpp
index 8d56581c12a49..f180da846a32c 100644
--- a/flang-rt/lib/flang_rt/execute.cpp
+++ b/flang-rt/lib/runtime/execute.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/execute.cpp --------------------------------*- C++ -*-===//
+//===-- lib/runtime/execute.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.
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/execute.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/environment.h"
-#include "flang-rt/stat.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/environment.h"
+#include "flang-rt/runtime/stat.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include <cstdlib>
 #include <errno.h>
 #include <future>
diff --git a/flang-rt/lib/flang_rt/extensions.cpp b/flang-rt/lib/runtime/extensions.cpp
similarity index 97%
rename from flang-rt/lib/flang_rt/extensions.cpp
rename to flang-rt/lib/runtime/extensions.cpp
index ef205c5aed689..75195c33a6c21 100644
--- a/flang-rt/lib/flang_rt/extensions.cpp
+++ b/flang-rt/lib/runtime/extensions.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/extensions.cpp -----------------------------*- C++ -*-===//
+//===-- lib/runtime/extensions.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,9 +10,9 @@
 // extensions that will eventually be implemented in Fortran.
 
 #include "flang/Runtime/extensions.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Runtime/command.h"
 #include "flang/Runtime/entry-names.h"
 #include "flang/Runtime/io-api.h"
diff --git a/flang-rt/lib/flang_rt/external-unit.cpp b/flang-rt/lib/runtime/external-unit.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/external-unit.cpp
rename to flang-rt/lib/runtime/external-unit.cpp
index 4be90cbbcc4c8..b8004d6315994 100644
--- a/flang-rt/lib/flang_rt/external-unit.cpp
+++ b/flang-rt/lib/runtime/external-unit.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/external-unit.cpp --------------------------*- C++ -*-===//
+//===-- lib/runtime/external-unit.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.
@@ -12,9 +12,9 @@
 
 #include "unit-map.h"
 #include "unit.h"
-#include "flang-rt/io-error.h"
-#include "flang-rt/lock.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/io-error.h"
+#include "flang-rt/runtime/lock.h"
+#include "flang-rt/runtime/tools.h"
 
 // NOTE: the header files above may define OpenMP declare target
 // variables, so they have to be included unconditionally
diff --git a/flang-rt/lib/flang_rt/extrema.cpp b/flang-rt/lib/runtime/extrema.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/extrema.cpp
rename to flang-rt/lib/runtime/extrema.cpp
index 8ecd7fbe91d77..3d84daa380441 100644
--- a/flang-rt/lib/flang_rt/extrema.cpp
+++ b/flang-rt/lib/runtime/extrema.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/extrema.cpp --------------------------------*- C++ -*-===//
+//===-- lib/runtime/extrema.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 @@
 // and shapes and (for MAXLOC & MINLOC) result integer kinds.  Also implements
 // NORM2 using common infrastructure.
 
-#include "flang-rt/reduction-templates.h"
+#include "flang-rt/runtime/reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/character.h"
 #include "flang/Runtime/reduction.h"
diff --git a/flang-rt/lib/flang_rt/file.cpp b/flang-rt/lib/runtime/file.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/file.cpp
rename to flang-rt/lib/runtime/file.cpp
index c9fcf0f97b718..16e73db488727 100644
--- a/flang-rt/lib/flang_rt/file.cpp
+++ b/flang-rt/lib/runtime/file.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/file.cpp -----------------------------------*- C++ -*-===//
+//===-- lib/runtime/file.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-rt/file.h"
-#include "flang-rt/memory.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/file.h"
+#include "flang-rt/runtime/memory.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Runtime/magic-numbers.h"
 #include <algorithm>
 #include <cerrno>
diff --git a/flang-rt/lib/flang_rt/findloc.cpp b/flang-rt/lib/runtime/findloc.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/findloc.cpp
rename to flang-rt/lib/runtime/findloc.cpp
index ac432676f5efc..95986aefb86a4 100644
--- a/flang-rt/lib/flang_rt/findloc.cpp
+++ b/flang-rt/lib/runtime/findloc.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/findloc.cpp --------------------------------*- C++ -*-===//
+//===-- lib/runtime/findloc.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.
@@ -9,7 +9,7 @@
 // Implements FINDLOC for all required operand types and shapes and result
 // integer kinds.
 
-#include "flang-rt/reduction-templates.h"
+#include "flang-rt/runtime/reduction-templates.h"
 #include "flang/Runtime/character.h"
 #include "flang/Runtime/reduction.h"
 #include <cinttypes>
diff --git a/flang-rt/lib/flang_rt/format.cpp b/flang-rt/lib/runtime/format.cpp
similarity index 89%
rename from flang-rt/lib/flang_rt/format.cpp
rename to flang-rt/lib/runtime/format.cpp
index abd01b56919a4..ee0059f5f0729 100644
--- a/flang-rt/lib/flang_rt/format.cpp
+++ b/flang-rt/lib/runtime/format.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/format.cpp ---------------------------------*- C++ -*-===//
+//===-- lib/runtime/format.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-rt/format-implementation.h"
+#include "flang-rt/runtime/format-implementation.h"
 
 namespace Fortran::runtime::io {
 RT_OFFLOAD_API_GROUP_BEGIN
diff --git a/flang-rt/lib/flang_rt/inquiry.cpp b/flang-rt/lib/runtime/inquiry.cpp
similarity index 94%
rename from flang-rt/lib/flang_rt/inquiry.cpp
rename to flang-rt/lib/runtime/inquiry.cpp
index e98d3900987dc..b6a7fce7a1e78 100644
--- a/flang-rt/lib/flang_rt/inquiry.cpp
+++ b/flang-rt/lib/runtime/inquiry.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/inquiry.cpp --------------------------------*- C++ -*-===//
+//===-- lib/runtime/inquiry.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.
@@ -11,9 +11,9 @@
 
 #include "flang/Runtime/inquiry.h"
 #include "copy.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include <algorithm>
 
 namespace Fortran::runtime {
diff --git a/flang-rt/lib/flang_rt/internal-unit.cpp b/flang-rt/lib/runtime/internal-unit.cpp
similarity index 96%
rename from flang-rt/lib/flang_rt/internal-unit.cpp
rename to flang-rt/lib/runtime/internal-unit.cpp
index 12d702de4c598..e344b01e8b34e 100644
--- a/flang-rt/lib/flang_rt/internal-unit.cpp
+++ b/flang-rt/lib/runtime/internal-unit.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/internal-unit.cpp --------------------------*- C++ -*-===//
+//===-- lib/runtime/internal-unit.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-rt/internal-unit.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/io-error.h"
+#include "flang-rt/runtime/internal-unit.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/io-error.h"
 #include "flang/Runtime/freestanding-tools.h"
 #include <algorithm>
 #include <type_traits>
diff --git a/flang-rt/lib/flang_rt/io-api-common.h b/flang-rt/lib/runtime/io-api-common.h
similarity index 92%
rename from flang-rt/lib/flang_rt/io-api-common.h
rename to flang-rt/lib/runtime/io-api-common.h
index 5e480fdef3483..b91ff9ff16863 100644
--- a/flang-rt/lib/flang_rt/io-api-common.h
+++ b/flang-rt/lib/runtime/io-api-common.h
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/io-api-common.h ----------------------------*- C++ -*-===//
+//===-- lib/runtime/io-api-common.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 FLANG_RT_IO_API_COMMON_H_
-#define FLANG_RT_IO_API_COMMON_H_
+#ifndef FLANG_RT_RUNTIME_IO_API_COMMON_H_
+#define FLANG_RT_RUNTIME_IO_API_COMMON_H_
 
 #include "unit.h"
-#include "flang-rt/io-stmt.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/io-stmt.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Common/api-attrs.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/io-api.h"
@@ -94,4 +94,4 @@ RT_API_ATTRS Cookie BeginExternalListIO(
 }
 
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_IO_API_COMMON_H_
+#endif // FLANG_RT_RUNTIME_IO_API_COMMON_H_
diff --git a/flang-rt/lib/flang_rt/io-api-minimal.cpp b/flang-rt/lib/runtime/io-api-minimal.cpp
similarity index 94%
rename from flang-rt/lib/flang_rt/io-api-minimal.cpp
rename to flang-rt/lib/runtime/io-api-minimal.cpp
index c3234c78c10c8..c706a3aa239a5 100644
--- a/flang-rt/lib/flang_rt/io-api-minimal.cpp
+++ b/flang-rt/lib/runtime/io-api-minimal.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/io-api-minimal.cpp -------------------------*- C++ -*-===//
+//===-- lib/runtime/io-api-minimal.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.
@@ -12,10 +12,10 @@
 #include "edit-output.h"
 #include "io-api-common.h"
 #include "unit.h"
-#include "flang-rt/format.h"
-#include "flang-rt/io-stmt.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/format.h"
+#include "flang-rt/runtime/io-stmt.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Runtime/io-api.h"
 
 namespace Fortran::runtime::io {
@@ -150,7 +150,7 @@ bool IODEF(OutputLogical)(Cookie cookie, bool truth) {
 // Provide own definition for `std::__libcpp_verbose_abort` to avoid dependency
 // on the version provided by libc++.
 
-void std::__libcpp_verbose_abort(char const *format, ...) {
+void std::__libcpp_verbose_abort(char const *format, ...) noexcept {
   va_list list;
   va_start(list, format);
   std::vfprintf(stderr, format, list);
diff --git a/flang-rt/lib/flang_rt/io-api.cpp b/flang-rt/lib/runtime/io-api.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/io-api.cpp
rename to flang-rt/lib/runtime/io-api.cpp
index c904352cba7f5..72041ae429467 100644
--- a/flang-rt/lib/flang_rt/io-api.cpp
+++ b/flang-rt/lib/runtime/io-api.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/io-api.cpp ---------------------------------*- C++ -*-===//
+//===-- lib/runtime/io-api.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.
@@ -19,13 +19,13 @@
 #include "edit-output.h"
 #include "io-api-common.h"
 #include "unit.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/environment.h"
-#include "flang-rt/format.h"
-#include "flang-rt/io-stmt.h"
-#include "flang-rt/memory.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/environment.h"
+#include "flang-rt/runtime/format.h"
+#include "flang-rt/runtime/io-stmt.h"
+#include "flang-rt/runtime/memory.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Common/optional.h"
 #include <cstdlib>
 #include <memory>
diff --git a/flang-rt/lib/flang_rt/io-error.cpp b/flang-rt/lib/runtime/io-error.cpp
similarity index 97%
rename from flang-rt/lib/flang_rt/io-error.cpp
rename to flang-rt/lib/runtime/io-error.cpp
index b356642c95f85..b350fb66fc25b 100644
--- a/flang-rt/lib/flang_rt/io-error.cpp
+++ b/flang-rt/lib/runtime/io-error.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/io-error.cpp -------------------------------*- C++ -*-===//
+//===-- lib/runtime/io-error.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-rt/io-error.h"
+#include "flang-rt/runtime/io-error.h"
 #include "config.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Runtime/magic-numbers.h"
 #include <cerrno>
 #include <cstdarg>
diff --git a/flang-rt/lib/flang_rt/io-stmt.cpp b/flang-rt/lib/runtime/io-stmt.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/io-stmt.cpp
rename to flang-rt/lib/runtime/io-stmt.cpp
index a07bf70a6593e..b0823ffd9e703 100644
--- a/flang-rt/lib/flang_rt/io-stmt.cpp
+++ b/flang-rt/lib/runtime/io-stmt.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/io-stmt.cpp --------------------------------*- C++ -*-===//
+//===-- lib/runtime/io-stmt.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,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/io-stmt.h"
+#include "flang-rt/runtime/io-stmt.h"
 #include "unit.h"
-#include "flang-rt/connection.h"
-#include "flang-rt/emit-encoded.h"
-#include "flang-rt/format.h"
-#include "flang-rt/memory.h"
-#include "flang-rt/tools.h"
-#include "flang-rt/utf.h"
+#include "flang-rt/runtime/connection.h"
+#include "flang-rt/runtime/emit-encoded.h"
+#include "flang-rt/runtime/format.h"
+#include "flang-rt/runtime/memory.h"
+#include "flang-rt/runtime/tools.h"
+#include "flang-rt/runtime/utf.h"
 #include <algorithm>
 #include <cstdio>
 #include <cstring>
diff --git a/flang-rt/lib/flang_rt/iostat.cpp b/flang-rt/lib/runtime/iostat.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/iostat.cpp
rename to flang-rt/lib/runtime/iostat.cpp
index ab2fc63cf7b21..0f8bfb884e544 100644
--- a/flang-rt/lib/flang_rt/iostat.cpp
+++ b/flang-rt/lib/runtime/iostat.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/iostat.cpp ---------------------------------*- C++ -*-===//
+//===-- lib/runtime/iostat.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-rt/lib/flang_rt/main.cpp b/flang-rt/lib/runtime/main.cpp
similarity index 90%
rename from flang-rt/lib/flang_rt/main.cpp
rename to flang-rt/lib/runtime/main.cpp
index dac7268f82b16..b3f066cda3732 100644
--- a/flang-rt/lib/flang_rt/main.cpp
+++ b/flang-rt/lib/runtime/main.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/main.cpp -----------------------------------*- C++ -*-===//
+//===-- lib/runtime/main.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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/main.h"
-#include "flang-rt/environment.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/environment.h"
+#include "flang-rt/runtime/terminator.h"
 #include <cfenv>
 #include <cstdio>
 #include <cstdlib>
diff --git a/flang-rt/lib/flang_rt/matmul-transpose.cpp b/flang-rt/lib/runtime/matmul-transpose.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/matmul-transpose.cpp
rename to flang-rt/lib/runtime/matmul-transpose.cpp
index 307995bb8ab1e..e20abbdddcd30 100644
--- a/flang-rt/lib/flang_rt/matmul-transpose.cpp
+++ b/flang-rt/lib/runtime/matmul-transpose.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/matmul-transpose.cpp -----------------------*- C++ -*-===//
+//===-- lib/runtime/matmul-transpose.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.
@@ -21,9 +21,9 @@
 // to use the faster BLAS routines.
 
 #include "flang/Runtime/matmul-transpose.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/c-or-cpp.h"
 #include "flang/Runtime/cpp-type.h"
diff --git a/flang-rt/lib/flang_rt/matmul.cpp b/flang-rt/lib/runtime/matmul.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/matmul.cpp
rename to flang-rt/lib/runtime/matmul.cpp
index c5036e24f86f4..f14cea922d21e 100644
--- a/flang-rt/lib/flang_rt/matmul.cpp
+++ b/flang-rt/lib/runtime/matmul.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/matmul.cpp ---------------------------------*- C++ -*-===//
+//===-- lib/runtime/matmul.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.
@@ -20,9 +20,9 @@
 // Places where BLAS routines could be called are marked as TODO items.
 
 #include "flang/Runtime/matmul.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/c-or-cpp.h"
 #include "flang/Runtime/cpp-type.h"
diff --git a/flang-rt/lib/flang_rt/memory.cpp b/flang-rt/lib/runtime/memory.cpp
similarity index 87%
rename from flang-rt/lib/flang_rt/memory.cpp
rename to flang-rt/lib/runtime/memory.cpp
index e09e45898da8e..79c7e33777569 100644
--- a/flang-rt/lib/flang_rt/memory.cpp
+++ b/flang-rt/lib/runtime/memory.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/memory.cpp ---------------------------------*- C++ -*-===//
+//===-- lib/runtime/memory.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-rt/memory.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/memory.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Runtime/freestanding-tools.h"
 #include <cstdlib>
 
diff --git a/flang-rt/lib/flang_rt/misc-intrinsic.cpp b/flang-rt/lib/runtime/misc-intrinsic.cpp
similarity index 95%
rename from flang-rt/lib/flang_rt/misc-intrinsic.cpp
rename to flang-rt/lib/runtime/misc-intrinsic.cpp
index 1a5bc8114e8ae..b7335e9f6799e 100644
--- a/flang-rt/lib/flang_rt/misc-intrinsic.cpp
+++ b/flang-rt/lib/runtime/misc-intrinsic.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/misc-intrinsic.cpp -------------------------*- C++ -*-===//
+//===-- lib/runtime/misc-intrinsic.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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/misc-intrinsic.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Common/optional.h"
 #include <algorithm>
 #include <cstdio>
diff --git a/flang-rt/lib/flang_rt/namelist.cpp b/flang-rt/lib/runtime/namelist.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/namelist.cpp
rename to flang-rt/lib/runtime/namelist.cpp
index 4cf1cd2062ac5..b0cf2180fc6d4 100644
--- a/flang-rt/lib/flang_rt/namelist.cpp
+++ b/flang-rt/lib/runtime/namelist.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/namelist.cpp -------------------------------*- C++ -*-===//
+//===-- lib/runtime/namelist.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,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/namelist.h"
+#include "flang-rt/runtime/namelist.h"
 #include "descriptor-io.h"
-#include "flang-rt/emit-encoded.h"
-#include "flang-rt/io-stmt.h"
+#include "flang-rt/runtime/emit-encoded.h"
+#include "flang-rt/runtime/io-stmt.h"
 #include "flang/Runtime/io-api.h"
 #include <algorithm>
 #include <cstring>
diff --git a/flang-rt/lib/flang_rt/non-tbp-dio.cpp b/flang-rt/lib/runtime/non-tbp-dio.cpp
similarity index 86%
rename from flang-rt/lib/flang_rt/non-tbp-dio.cpp
rename to flang-rt/lib/runtime/non-tbp-dio.cpp
index 5663c2ee338d7..72101b06e0c6e 100644
--- a/flang-rt/lib/flang_rt/non-tbp-dio.cpp
+++ b/flang-rt/lib/runtime/non-tbp-dio.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/non-tbp-dio.cpp ----------------------------*- C++ -*-===//
+//===-- lib/runtime/non-tbp-dio.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-rt/non-tbp-dio.h"
-#include "flang-rt/type-info.h"
+#include "flang-rt/runtime/non-tbp-dio.h"
+#include "flang-rt/runtime/type-info.h"
 
 namespace Fortran::runtime::io {
 
diff --git a/flang-rt/lib/flang_rt/numeric.cpp b/flang-rt/lib/runtime/numeric.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/numeric.cpp
rename to flang-rt/lib/runtime/numeric.cpp
index b63c604cadcfb..37638765dc650 100644
--- a/flang-rt/lib/flang_rt/numeric.cpp
+++ b/flang-rt/lib/runtime/numeric.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/numeric.cpp --------------------------------*- C++ -*-===//
+//===-- lib/runtime/numeric.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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/numeric.h"
-#include "flang-rt/numeric-templates.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/numeric-templates.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Common/float128.h"
 #include <cfloat>
 #include <climits>
diff --git a/flang-rt/lib/flang_rt/pointer.cpp b/flang-rt/lib/runtime/pointer.cpp
similarity index 96%
rename from flang-rt/lib/flang_rt/pointer.cpp
rename to flang-rt/lib/runtime/pointer.cpp
index 3138a54f1d122..93ba82e0583c0 100644
--- a/flang-rt/lib/flang_rt/pointer.cpp
+++ b/flang-rt/lib/runtime/pointer.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/pointer.cpp --------------------------------*- C++ -*-===//
+//===-- lib/runtime/pointer.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.
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/pointer.h"
-#include "flang-rt/assign-impl.h"
-#include "flang-rt/derived.h"
-#include "flang-rt/environment.h"
-#include "flang-rt/stat.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
-#include "flang-rt/type-info.h"
+#include "flang-rt/runtime/assign-impl.h"
+#include "flang-rt/runtime/derived.h"
+#include "flang-rt/runtime/environment.h"
+#include "flang-rt/runtime/stat.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
+#include "flang-rt/runtime/type-info.h"
 
 namespace Fortran::runtime {
 extern "C" {
diff --git a/flang-rt/lib/flang_rt/product.cpp b/flang-rt/lib/runtime/product.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/product.cpp
rename to flang-rt/lib/runtime/product.cpp
index c7b6d23d3014e..02fdc2bfcd576 100644
--- a/flang-rt/lib/flang_rt/product.cpp
+++ b/flang-rt/lib/runtime/product.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/product.cpp --------------------------------*- C++ -*-===//
+//===-- lib/runtime/product.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.
@@ -8,7 +8,7 @@
 
 // Implements PRODUCT for all required operand types and shapes.
 
-#include "flang-rt/reduction-templates.h"
+#include "flang-rt/runtime/reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/reduction.h"
 #include <cfloat>
diff --git a/flang-rt/lib/flang_rt/pseudo-unit.cpp b/flang-rt/lib/runtime/pseudo-unit.cpp
similarity index 97%
rename from flang-rt/lib/flang_rt/pseudo-unit.cpp
rename to flang-rt/lib/runtime/pseudo-unit.cpp
index f4d204890581e..7e1f3bc86b294 100644
--- a/flang-rt/lib/flang_rt/pseudo-unit.cpp
+++ b/flang-rt/lib/runtime/pseudo-unit.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/pseudo-unit.cpp ----------------------------*- C++ -*-===//
+//===-- lib/runtime/pseudo-unit.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.
@@ -12,8 +12,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "unit.h"
-#include "flang-rt/io-error.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/io-error.h"
+#include "flang-rt/runtime/tools.h"
 
 // NOTE: the header files above may define OpenMP declare target
 // variables, so they have to be included unconditionally
diff --git a/flang-rt/lib/flang_rt/ragged.cpp b/flang-rt/lib/runtime/ragged.cpp
similarity index 96%
rename from flang-rt/lib/flang_rt/ragged.cpp
rename to flang-rt/lib/runtime/ragged.cpp
index 798b3464e7bca..dddc3ccdfd858 100644
--- a/flang-rt/lib/flang_rt/ragged.cpp
+++ b/flang-rt/lib/runtime/ragged.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/ragged.cpp ---------------------------------*- C++ -*-===//
+//===-- lib/runtime/ragged.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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/ragged.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/tools.h"
 #include <cstdlib>
 
 namespace Fortran::runtime {
diff --git a/flang-rt/lib/flang_rt/random.cpp b/flang-rt/lib/runtime/random.cpp
similarity index 96%
rename from flang-rt/lib/flang_rt/random.cpp
rename to flang-rt/lib/runtime/random.cpp
index 76971cf3fc888..dc74f2725ed51 100644
--- a/flang-rt/lib/flang_rt/random.cpp
+++ b/flang-rt/lib/runtime/random.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/random.cpp ---------------------------------*- C++ -*-===//
+//===-- lib/runtime/random.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,10 +10,10 @@
 // RANDOM_SEED.
 
 #include "flang/Runtime/random.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/lock.h"
-#include "flang-rt/random-templates.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/lock.h"
+#include "flang-rt/runtime/random-templates.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Common/float128.h"
 #include "flang/Common/leading-zero-bit-count.h"
 #include "flang/Common/uint128.h"
diff --git a/flang-rt/lib/flang_rt/reduce.cpp b/flang-rt/lib/runtime/reduce.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/reduce.cpp
rename to flang-rt/lib/runtime/reduce.cpp
index 4bb6dc10ea9da..3c5e815e32d2b 100644
--- a/flang-rt/lib/flang_rt/reduce.cpp
+++ b/flang-rt/lib/runtime/reduce.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/reduce.cpp ---------------------------------*- C++ -*-===//
+//===-- lib/runtime/reduce.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.
@@ -9,10 +9,10 @@
 // REDUCE() implementation
 
 #include "flang/Runtime/reduce.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/reduction-templates.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/reduction-templates.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang-rt/lib/flang_rt/reduction.cpp b/flang-rt/lib/runtime/reduction.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/reduction.cpp
rename to flang-rt/lib/runtime/reduction.cpp
index 9ceaeffc6541a..5e45870489479 100644
--- a/flang-rt/lib/flang_rt/reduction.cpp
+++ b/flang-rt/lib/runtime/reduction.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/reduction.cpp ------------------------------*- C++ -*-===//
+//===-- lib/runtime/reduction.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.
@@ -14,8 +14,8 @@
 // NORM2, MAXLOC, MINLOC, MAXVAL, and MINVAL are in extrema.cpp.
 
 #include "flang/Runtime/reduction.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/reduction-templates.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/reduction-templates.h"
 #include <cinttypes>
 
 namespace Fortran::runtime {
diff --git a/flang-rt/lib/flang_rt/stack.h b/flang-rt/lib/runtime/stack.h
similarity index 93%
rename from flang-rt/lib/flang_rt/stack.h
rename to flang-rt/lib/runtime/stack.h
index 6f37282f00932..38364ff541f16 100644
--- a/flang-rt/lib/flang_rt/stack.h
+++ b/flang-rt/lib/runtime/stack.h
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/stack.h ------------------------------------*- C++ -*-===//
+//===-- lib/runtime/stack.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,11 +10,11 @@
 // It is a list based stack with dynamic allocation/deallocation
 // of the list nodes.
 
-#ifndef FLANG_RT_STACK_H_
-#define FLANG_RT_STACK_H_
+#ifndef FLANG_RT_RUNTIME_STACK_H_
+#define FLANG_RT_RUNTIME_STACK_H_
 
-#include "flang-rt/memory.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/memory.h"
+#include "flang-rt/runtime/terminator.h"
 
 namespace Fortran::runtime {
 // Storage for the Stack elements of type T.
@@ -133,4 +133,4 @@ template <typename T, unsigned N = 0> class Stack : public StackStorage<T, N> {
   Terminator &terminator_;
 };
 } // namespace Fortran::runtime
-#endif // FLANG_RT_STACK_H_
+#endif // FLANG_RT_RUNTIME_STACK_H_
diff --git a/flang-rt/lib/flang_rt/stat.cpp b/flang-rt/lib/runtime/stat.cpp
similarity index 93%
rename from flang-rt/lib/flang_rt/stat.cpp
rename to flang-rt/lib/runtime/stat.cpp
index 883e85d0fbf2f..322b7282b7024 100644
--- a/flang-rt/lib/flang_rt/stat.cpp
+++ b/flang-rt/lib/runtime/stat.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/stat.cpp -----------------------------------*- C++ -*-===//
+//===-- lib/runtime/stat.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,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/stat.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/stat.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 
 namespace Fortran::runtime {
 RT_OFFLOAD_API_GROUP_BEGIN
diff --git a/flang-rt/lib/flang_rt/stop.cpp b/flang-rt/lib/runtime/stop.cpp
similarity index 95%
rename from flang-rt/lib/flang_rt/stop.cpp
rename to flang-rt/lib/runtime/stop.cpp
index 91f8e4a8f6bc1..1d70a137377aa 100644
--- a/flang-rt/lib/flang_rt/stop.cpp
+++ b/flang-rt/lib/runtime/stop.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/stop.cpp -----------------------------------*- C++ -*-===//
+//===-- lib/runtime/stop.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.
@@ -9,10 +9,10 @@
 #include "flang/Runtime/stop.h"
 #include "config.h"
 #include "unit.h"
-#include "flang-rt/environment.h"
-#include "flang-rt/file.h"
-#include "flang-rt/io-error.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/environment.h"
+#include "flang-rt/runtime/file.h"
+#include "flang-rt/runtime/io-error.h"
+#include "flang-rt/runtime/terminator.h"
 #include <cfenv>
 #include <cstdio>
 #include <cstdlib>
diff --git a/flang-rt/lib/flang_rt/sum.cpp b/flang-rt/lib/runtime/sum.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/sum.cpp
rename to flang-rt/lib/runtime/sum.cpp
index fd98525b8c9b2..a76e228f18a4e 100644
--- a/flang-rt/lib/flang_rt/sum.cpp
+++ b/flang-rt/lib/runtime/sum.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/sum.cpp ------------------------------------*- C++ -*-===//
+//===-- lib/runtime/sum.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.
@@ -12,7 +12,7 @@
 // cancellation on intermediate results by using "Kahan summation"
 // (basically the same as manual "double-double").
 
-#include "flang-rt/reduction-templates.h"
+#include "flang-rt/runtime/reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/reduction.h"
 #include <cfloat>
diff --git a/flang-rt/lib/flang_rt/support.cpp b/flang-rt/lib/runtime/support.cpp
similarity index 91%
rename from flang-rt/lib/flang_rt/support.cpp
rename to flang-rt/lib/runtime/support.cpp
index 2673176bd8185..5a2b0c920aa80 100644
--- a/flang-rt/lib/flang_rt/support.cpp
+++ b/flang-rt/lib/runtime/support.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/support.cpp --------------------------------*- C++ -*-===//
+//===-- lib/runtime/support.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.
@@ -8,8 +8,8 @@
 
 #include "flang/Runtime/support.h"
 #include "ISO_Fortran_util.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/type-info.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/type-info.h"
 
 namespace Fortran::runtime {
 extern "C" {
diff --git a/flang-rt/lib/flang_rt/temporary-stack.cpp b/flang-rt/lib/runtime/temporary-stack.cpp
similarity index 97%
rename from flang-rt/lib/flang_rt/temporary-stack.cpp
rename to flang-rt/lib/runtime/temporary-stack.cpp
index 32ec4dacc872d..ea89d0c17bb6b 100644
--- a/flang-rt/lib/flang_rt/temporary-stack.cpp
+++ b/flang-rt/lib/runtime/temporary-stack.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/temporary-stack.cpp ------------------------*- C++ -*-===//
+//===-- lib/runtime/temporary-stack.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,9 +10,9 @@
 // temporaries. For use in HLFIR lowering.
 
 #include "flang/Runtime/temporary-stack.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/memory.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/memory.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/assign.h"
 
diff --git a/flang-rt/lib/flang_rt/terminator.cpp b/flang-rt/lib/runtime/terminator.cpp
similarity index 96%
rename from flang-rt/lib/flang_rt/terminator.cpp
rename to flang-rt/lib/runtime/terminator.cpp
index 0dfc08eb70370..8a57ba06b1304 100644
--- a/flang-rt/lib/flang_rt/terminator.cpp
+++ b/flang-rt/lib/runtime/terminator.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/terminator.cpp -----------------------------*- C++ -*-===//
+//===-- lib/runtime/terminator.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-rt/terminator.h"
+#include "flang-rt/runtime/terminator.h"
 #include <cstdio>
 #include <cstdlib>
 
diff --git a/flang-rt/lib/flang_rt/time-intrinsic.cpp b/flang-rt/lib/runtime/time-intrinsic.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/time-intrinsic.cpp
rename to flang-rt/lib/runtime/time-intrinsic.cpp
index 1929fccbd4cf3..69c344f5d24bc 100644
--- a/flang-rt/lib/flang_rt/time-intrinsic.cpp
+++ b/flang-rt/lib/runtime/time-intrinsic.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/time-intrinsic.cpp -------------------------*- C++ -*-===//
+//===-- lib/runtime/time-intrinsic.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.
@@ -9,9 +9,9 @@
 // Implements time-related intrinsic subroutines.
 
 #include "flang/Runtime/time-intrinsic.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Runtime/cpp-type.h"
 #include <algorithm>
 #include <cstdint>
diff --git a/flang-rt/lib/flang_rt/tools.cpp b/flang-rt/lib/runtime/tools.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/tools.cpp
rename to flang-rt/lib/runtime/tools.cpp
index 9b460f81ad5c2..b9d9ca4fc378c 100644
--- a/flang-rt/lib/flang_rt/tools.cpp
+++ b/flang-rt/lib/runtime/tools.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/tools.cpp ----------------------------------*- C++ -*-===//
+//===-- lib/runtime/tools.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-rt/tools.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/tools.h"
+#include "flang-rt/runtime/terminator.h"
 #include <algorithm>
 #include <cstdint>
 #include <cstdlib>
diff --git a/flang-rt/lib/flang_rt/transformational.cpp b/flang-rt/lib/runtime/transformational.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/transformational.cpp
rename to flang-rt/lib/runtime/transformational.cpp
index 7453bf18323e9..eb694a9f2c833 100644
--- a/flang-rt/lib/flang_rt/transformational.cpp
+++ b/flang-rt/lib/runtime/transformational.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/transformational.cpp -----------------------*- C++ -*-===//
+//===-- lib/runtime/transformational.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.
@@ -18,9 +18,9 @@
 
 #include "flang/Runtime/transformational.h"
 #include "copy.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Common/float128.h"
 
 namespace Fortran::runtime {
diff --git a/flang-rt/lib/flang_rt/type-code.cpp b/flang-rt/lib/runtime/type-code.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/type-code.cpp
rename to flang-rt/lib/runtime/type-code.cpp
index 432c7591520cb..8cfec9a4ec2fb 100644
--- a/flang-rt/lib/flang_rt/type-code.cpp
+++ b/flang-rt/lib/runtime/type-code.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/type-code.cpp ------------------------------*- C++ -*-===//
+//===-- lib/runtime/type-code.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-rt/type-code.h"
+#include "flang-rt/runtime/type-code.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang-rt/lib/flang_rt/type-info.cpp b/flang-rt/lib/runtime/type-info.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/type-info.cpp
rename to flang-rt/lib/runtime/type-info.cpp
index e1859e4864ca1..82182696d70c6 100644
--- a/flang-rt/lib/flang_rt/type-info.cpp
+++ b/flang-rt/lib/runtime/type-info.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/type-info.cpp ------------------------------*- C++ -*-===//
+//===-- lib/runtime/type-info.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-rt/type-info.h"
-#include "flang-rt/terminator.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/type-info.h"
+#include "flang-rt/runtime/terminator.h"
+#include "flang-rt/runtime/tools.h"
 #include <cstdio>
 
 namespace Fortran::runtime::typeInfo {
diff --git a/flang-rt/lib/flang_rt/unit-map.cpp b/flang-rt/lib/runtime/unit-map.cpp
similarity index 98%
rename from flang-rt/lib/flang_rt/unit-map.cpp
rename to flang-rt/lib/runtime/unit-map.cpp
index 0fda53ac071b2..41a03f3319d64 100644
--- a/flang-rt/lib/flang_rt/unit-map.cpp
+++ b/flang-rt/lib/runtime/unit-map.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/unit-map.cpp -------------------------------*- C++ -*-===//
+//===-- lib/runtime/unit-map.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-rt/lib/flang_rt/unit-map.h b/flang-rt/lib/runtime/unit-map.h
similarity index 92%
rename from flang-rt/lib/flang_rt/unit-map.h
rename to flang-rt/lib/runtime/unit-map.h
index 64233008b6630..fa61288a1e18d 100644
--- a/flang-rt/lib/flang_rt/unit-map.h
+++ b/flang-rt/lib/runtime/unit-map.h
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/unit-map.h ---------------------------------*- C++ -*-===//
+//===-- lib/runtime/unit-map.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.
@@ -9,12 +9,12 @@
 // Maps Fortran unit numbers to their ExternalFileUnit instances.
 // A simple hash table with forward-linked chains per bucket.
 
-#ifndef FLANG_RT_UNIT_MAP_H_
-#define FLANG_RT_UNIT_MAP_H_
+#ifndef FLANG_RT_RUNTIME_UNIT_MAP_H_
+#define FLANG_RT_RUNTIME_UNIT_MAP_H_
 
 #include "unit.h"
-#include "flang-rt/lock.h"
-#include "flang-rt/memory.h"
+#include "flang-rt/runtime/lock.h"
+#include "flang-rt/runtime/memory.h"
 #include "flang/Common/fast-int-set.h"
 #include <cstdint>
 #include <cstdlib>
@@ -100,4 +100,4 @@ class UnitMap {
   int emergencyNewUnit_{maxNewUnits_}; // not recycled
 };
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_UNIT_MAP_H_
+#endif // FLANG_RT_RUNTIME_UNIT_MAP_H_
diff --git a/flang-rt/lib/flang_rt/unit.cpp b/flang-rt/lib/runtime/unit.cpp
similarity index 99%
rename from flang-rt/lib/flang_rt/unit.cpp
rename to flang-rt/lib/runtime/unit.cpp
index f05c4b5236dd5..1d4d54ae01956 100644
--- a/flang-rt/lib/flang_rt/unit.cpp
+++ b/flang-rt/lib/runtime/unit.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/unit.cpp -----------------------------------*- C++ -*-===//
+//===-- lib/runtime/unit.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.
@@ -11,9 +11,9 @@
 //
 //===----------------------------------------------------------------------===//
 #include "unit.h"
-#include "flang-rt/io-error.h"
-#include "flang-rt/lock.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/io-error.h"
+#include "flang-rt/runtime/lock.h"
+#include "flang-rt/runtime/tools.h"
 #include <limits>
 #include <utility>
 
diff --git a/flang-rt/lib/flang_rt/unit.h b/flang-rt/lib/runtime/unit.h
similarity index 95%
rename from flang-rt/lib/flang_rt/unit.h
rename to flang-rt/lib/runtime/unit.h
index a5fb7fb31691f..eb762a2d3b235 100644
--- a/flang-rt/lib/flang_rt/unit.h
+++ b/flang-rt/lib/runtime/unit.h
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/unit.h -------------------------------------*- C++ -*-===//
+//===-- lib/runtime/unit.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.
@@ -8,19 +8,19 @@
 
 // Fortran external I/O units
 
-#ifndef FLANG_RT_UNIT_H_
-#define FLANG_RT_UNIT_H_
-
-#include "flang-rt/buffer.h"
-#include "flang-rt/connection.h"
-#include "flang-rt/environment.h"
-#include "flang-rt/file.h"
-#include "flang-rt/format.h"
-#include "flang-rt/io-error.h"
-#include "flang-rt/io-stmt.h"
-#include "flang-rt/lock.h"
-#include "flang-rt/memory.h"
-#include "flang-rt/terminator.h"
+#ifndef FLANG_RT_RUNTIME_UNIT_H_
+#define FLANG_RT_RUNTIME_UNIT_H_
+
+#include "flang-rt/runtime/buffer.h"
+#include "flang-rt/runtime/connection.h"
+#include "flang-rt/runtime/environment.h"
+#include "flang-rt/runtime/file.h"
+#include "flang-rt/runtime/format.h"
+#include "flang-rt/runtime/io-error.h"
+#include "flang-rt/runtime/io-stmt.h"
+#include "flang-rt/runtime/lock.h"
+#include "flang-rt/runtime/memory.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Common/constexpr-bitset.h"
 #include "flang/Common/optional.h"
 #include <cstdlib>
@@ -291,4 +291,4 @@ class ChildIo {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FLANG_RT_UNIT_H_
+#endif // FLANG_RT_RUNTIME_UNIT_H_
diff --git a/flang-rt/lib/flang_rt/utf.cpp b/flang-rt/lib/runtime/utf.cpp
similarity index 97%
rename from flang-rt/lib/flang_rt/utf.cpp
rename to flang-rt/lib/runtime/utf.cpp
index dd74889c025c5..ef9df49f24f66 100644
--- a/flang-rt/lib/flang_rt/utf.cpp
+++ b/flang-rt/lib/runtime/utf.cpp
@@ -1,4 +1,4 @@
-//===-- lib/flang_rt/utf.cpp ------------------------------------*- C++ -*-===//
+//===-- lib/runtime/utf.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-rt/utf.h"
+#include "flang-rt/runtime/utf.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang-rt/test/Runtime/no-cpp-dep.c b/flang-rt/test/Runtime/no-cpp-dep.c
index c03029f0f3c26..4fcf8f9d478d8 100644
--- a/flang-rt/test/Runtime/no-cpp-dep.c
+++ b/flang-rt/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
diff --git a/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp b/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp
index d1417b715e959..8c0a6f29b6967 100644
--- a/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp
+++ b/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/descriptor.h"
+#include "flang-rt/runtime/descriptor.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Testing/testing.h"
 #include "llvm/Support/raw_ostream.h"
diff --git a/flang-rt/unittests/Evaluate/reshape.cpp b/flang-rt/unittests/Evaluate/reshape.cpp
index a45e06ad0f69d..2abe46c0969fb 100644
--- a/flang-rt/unittests/Evaluate/reshape.cpp
+++ b/flang-rt/unittests/Evaluate/reshape.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/descriptor.h"
+#include "flang-rt/runtime/descriptor.h"
 #include "flang/Runtime/transformational.h"
 #include "flang/Testing/testing.h"
 #include <cinttypes>
diff --git a/flang-rt/unittests/Runtime/Allocatable.cpp b/flang-rt/unittests/Runtime/Allocatable.cpp
index b03003a93fe09..4702f48e0f440 100644
--- a/flang-rt/unittests/Runtime/Allocatable.cpp
+++ b/flang-rt/unittests/Runtime/Allocatable.cpp
@@ -8,7 +8,7 @@
 
 #include "flang/Runtime/allocatable.h"
 #include "gtest/gtest.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/tools.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang-rt/unittests/Runtime/ArrayConstructor.cpp b/flang-rt/unittests/Runtime/ArrayConstructor.cpp
index 5c84cd162a293..5f791e7f4a7c3 100644
--- a/flang-rt/unittests/Runtime/ArrayConstructor.cpp
+++ b/flang-rt/unittests/Runtime/ArrayConstructor.cpp
@@ -8,9 +8,9 @@
 
 #include "tools.h"
 #include "gtest/gtest.h"
-#include "flang-rt/array-constructor.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/type-code.h"
+#include "flang-rt/runtime/array-constructor.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/type-code.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
 
diff --git a/flang-rt/unittests/Runtime/BufferTest.cpp b/flang-rt/unittests/Runtime/BufferTest.cpp
index 7795a79593eb2..f4b9e901d6fcb 100644
--- a/flang-rt/unittests/Runtime/BufferTest.cpp
+++ b/flang-rt/unittests/Runtime/BufferTest.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/buffer.h"
+#include "flang-rt/runtime/buffer.h"
 #include "CrashHandlerFixture.h"
 #include "gtest/gtest.h"
 #include <algorithm>
diff --git a/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp b/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp
index db6589990be18..90d4da849552a 100644
--- a/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp
@@ -9,10 +9,10 @@
 #include "flang/Runtime/allocatable.h"
 #include "cuda_runtime.h"
 #include "gtest/gtest.h"
-#include "flang-rt/CUDA/allocator.h"
-#include "flang-rt/allocator-registry.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/cuda/allocator.h"
+#include "flang-rt/runtime/allocator-registry.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Support/Fortran.h"
diff --git a/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
index 86c13d0dd290c..6e46a80aa8f3c 100644
--- a/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
@@ -8,10 +8,10 @@
 
 #include "cuda_runtime.h"
 #include "gtest/gtest.h"
-#include "flang-rt/CUDA/allocator.h"
-#include "flang-rt/allocator-registry.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/cuda/allocator.h"
+#include "flang-rt/runtime/allocator-registry.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Support/Fortran.h"
diff --git a/flang-rt/unittests/Runtime/CUDA/Memory.cpp b/flang-rt/unittests/Runtime/CUDA/Memory.cpp
index 32609795c0169..c43b165509a98 100644
--- a/flang-rt/unittests/Runtime/CUDA/Memory.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/Memory.cpp
@@ -10,9 +10,9 @@
 #include "cuda_runtime.h"
 #include "../tools.h"
 #include "gtest/gtest.h"
-#include "flang-rt/CUDA/allocator.h"
-#include "flang-rt/allocator-registry.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/cuda/allocator.h"
+#include "flang-rt/runtime/allocator-registry.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/allocatable.h"
diff --git a/flang-rt/unittests/Runtime/CharacterTest.cpp b/flang-rt/unittests/Runtime/CharacterTest.cpp
index 696ab6b06e9e7..83ec9b36d9b0c 100644
--- a/flang-rt/unittests/Runtime/CharacterTest.cpp
+++ b/flang-rt/unittests/Runtime/CharacterTest.cpp
@@ -11,7 +11,7 @@
 
 #include "flang/Runtime/character.h"
 #include "gtest/gtest.h"
-#include "flang-rt/descriptor.h"
+#include "flang-rt/runtime/descriptor.h"
 #include <cstring>
 #include <functional>
 #include <tuple>
diff --git a/flang-rt/unittests/Runtime/CommandTest.cpp b/flang-rt/unittests/Runtime/CommandTest.cpp
index a34c329750f39..72fe7629dbbb8 100644
--- a/flang-rt/unittests/Runtime/CommandTest.cpp
+++ b/flang-rt/unittests/Runtime/CommandTest.cpp
@@ -9,7 +9,7 @@
 #include "flang/Runtime/command.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
-#include "flang-rt/descriptor.h"
+#include "flang-rt/runtime/descriptor.h"
 #include "flang/Runtime/execute.h"
 #include "flang/Runtime/extensions.h"
 #include "flang/Runtime/main.h"
diff --git a/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp b/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp
index 939cc62c433f0..8213edd1f9225 100644
--- a/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp
+++ b/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/terminator.h"
 #include <cstdarg>
 #include <cstdlib>
 
diff --git a/flang-rt/unittests/Runtime/Derived.cpp b/flang-rt/unittests/Runtime/Derived.cpp
index 2f45dfb80f7fd..3196ba796ad19 100644
--- a/flang-rt/unittests/Runtime/Derived.cpp
+++ b/flang-rt/unittests/Runtime/Derived.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "gtest/gtest.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/tools.h"
 #include "flang/Runtime/derived-api.h"
 
 using namespace Fortran::runtime;
diff --git a/flang-rt/unittests/Runtime/ExternalIOTest.cpp b/flang-rt/unittests/Runtime/ExternalIOTest.cpp
index a5481e071916d..c83535ca82bd3 100644
--- a/flang-rt/unittests/Runtime/ExternalIOTest.cpp
+++ b/flang-rt/unittests/Runtime/ExternalIOTest.cpp
@@ -12,7 +12,7 @@
 
 #include "CrashHandlerFixture.h"
 #include "gtest/gtest.h"
-#include "flang-rt/descriptor.h"
+#include "flang-rt/runtime/descriptor.h"
 #include "flang/Runtime/io-api-consts.h"
 #include "flang/Runtime/main.h"
 #include "flang/Runtime/stop.h"
diff --git a/flang-rt/unittests/Runtime/Format.cpp b/flang-rt/unittests/Runtime/Format.cpp
index 83650e0f999ac..fe7403f26700b 100644
--- a/flang-rt/unittests/Runtime/Format.cpp
+++ b/flang-rt/unittests/Runtime/Format.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang-rt/connection.h"
-#include "flang-rt/format-implementation.h"
-#include "flang-rt/io-error.h"
+#include "flang-rt/runtime/connection.h"
+#include "flang-rt/runtime/format-implementation.h"
+#include "flang-rt/runtime/io-error.h"
 #include <optional>
 #include <string>
 #include <tuple>
diff --git a/flang-rt/unittests/Runtime/Inquiry.cpp b/flang-rt/unittests/Runtime/Inquiry.cpp
index f6097484bd481..e79c037864d9c 100644
--- a/flang-rt/unittests/Runtime/Inquiry.cpp
+++ b/flang-rt/unittests/Runtime/Inquiry.cpp
@@ -9,7 +9,7 @@
 #include "flang/Runtime/inquiry.h"
 #include "tools.h"
 #include "gtest/gtest.h"
-#include "flang-rt/type-code.h"
+#include "flang-rt/runtime/type-code.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang-rt/unittests/Runtime/ListInputTest.cpp b/flang-rt/unittests/Runtime/ListInputTest.cpp
index 0c6c59d6a325e..310c41a5c3fa5 100644
--- a/flang-rt/unittests/Runtime/ListInputTest.cpp
+++ b/flang-rt/unittests/Runtime/ListInputTest.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/io-error.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/io-error.h"
 #include "flang/Runtime/io-api-consts.h"
 
 using namespace Fortran::runtime;
diff --git a/flang-rt/unittests/Runtime/LogicalFormatTest.cpp b/flang-rt/unittests/Runtime/LogicalFormatTest.cpp
index 07f62ee02fc66..bc933292181c1 100644
--- a/flang-rt/unittests/Runtime/LogicalFormatTest.cpp
+++ b/flang-rt/unittests/Runtime/LogicalFormatTest.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang-rt/descriptor.h"
+#include "flang-rt/runtime/descriptor.h"
 #include "flang/Runtime/io-api-consts.h"
 #include <algorithm>
 #include <array>
diff --git a/flang-rt/unittests/Runtime/Matmul.cpp b/flang-rt/unittests/Runtime/Matmul.cpp
index 28bf2327da949..1b716fd01fd42 100644
--- a/flang-rt/unittests/Runtime/Matmul.cpp
+++ b/flang-rt/unittests/Runtime/Matmul.cpp
@@ -9,8 +9,8 @@
 #include "flang/Runtime/matmul.h"
 #include "tools.h"
 #include "gtest/gtest.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/type-code.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/type-code.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
 
diff --git a/flang-rt/unittests/Runtime/MatmulTranspose.cpp b/flang-rt/unittests/Runtime/MatmulTranspose.cpp
index b06afa29ce28e..cc14ab755505a 100644
--- a/flang-rt/unittests/Runtime/MatmulTranspose.cpp
+++ b/flang-rt/unittests/Runtime/MatmulTranspose.cpp
@@ -8,8 +8,8 @@
 
 #include "tools.h"
 #include "gtest/gtest.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/type-code.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/type-code.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
 #include "flang/Runtime/matmul-transpose.h"
diff --git a/flang-rt/unittests/Runtime/MiscIntrinsic.cpp b/flang-rt/unittests/Runtime/MiscIntrinsic.cpp
index 61b05b31f45a9..c6783381bfc35 100644
--- a/flang-rt/unittests/Runtime/MiscIntrinsic.cpp
+++ b/flang-rt/unittests/Runtime/MiscIntrinsic.cpp
@@ -8,7 +8,7 @@
 
 #include "tools.h"
 #include "gtest/gtest.h"
-#include "flang-rt/descriptor.h"
+#include "flang-rt/runtime/descriptor.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
 #include "flang/Runtime/misc-intrinsic.h"
diff --git a/flang-rt/unittests/Runtime/Namelist.cpp b/flang-rt/unittests/Runtime/Namelist.cpp
index d48a0273bf556..040dedb8cd47c 100644
--- a/flang-rt/unittests/Runtime/Namelist.cpp
+++ b/flang-rt/unittests/Runtime/Namelist.cpp
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/namelist.h"
+#include "flang-rt/runtime/namelist.h"
 #include "CrashHandlerFixture.h"
 #include "tools.h"
-#include "flang-rt/descriptor.h"
+#include "flang-rt/runtime/descriptor.h"
 #include "flang/Runtime/io-api-consts.h"
 #include <algorithm>
 #include <cinttypes>
diff --git a/flang-rt/unittests/Runtime/NumericalFormatTest.cpp b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
index a86e6b807fc53..5a8ead48dcef9 100644
--- a/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
+++ b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang-rt/descriptor.h"
+#include "flang-rt/runtime/descriptor.h"
 #include "flang/Runtime/io-api-consts.h"
 #include <algorithm>
 #include <array>
diff --git a/flang-rt/unittests/Runtime/Pointer.cpp b/flang-rt/unittests/Runtime/Pointer.cpp
index 13f1922e6c5c3..a4645f5b6bf98 100644
--- a/flang-rt/unittests/Runtime/Pointer.cpp
+++ b/flang-rt/unittests/Runtime/Pointer.cpp
@@ -8,8 +8,8 @@
 
 #include "flang/Runtime/pointer.h"
 #include "gtest/gtest.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/tools.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/tools.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang-rt/unittests/Runtime/Random.cpp b/flang-rt/unittests/Runtime/Random.cpp
index dba480cffa9c9..bf4b540e768fd 100644
--- a/flang-rt/unittests/Runtime/Random.cpp
+++ b/flang-rt/unittests/Runtime/Random.cpp
@@ -8,8 +8,8 @@
 
 #include "flang/Runtime/random.h"
 #include "gtest/gtest.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/type-code.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/type-code.h"
 #include <cmath>
 
 using namespace Fortran::runtime;
diff --git a/flang-rt/unittests/Runtime/Reduction.cpp b/flang-rt/unittests/Runtime/Reduction.cpp
index cb84512639933..3701a32042c58 100644
--- a/flang-rt/unittests/Runtime/Reduction.cpp
+++ b/flang-rt/unittests/Runtime/Reduction.cpp
@@ -9,8 +9,8 @@
 #include "flang/Runtime/reduction.h"
 #include "tools.h"
 #include "gtest/gtest.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/type-code.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/type-code.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
diff --git a/flang-rt/unittests/Runtime/RuntimeCrashTest.cpp b/flang-rt/unittests/Runtime/RuntimeCrashTest.cpp
index 23a60d98bf6ad..e716dac2d1203 100644
--- a/flang-rt/unittests/Runtime/RuntimeCrashTest.cpp
+++ b/flang-rt/unittests/Runtime/RuntimeCrashTest.cpp
@@ -12,7 +12,7 @@
 //===----------------------------------------------------------------------===//
 #include "CrashHandlerFixture.h"
 #include "tools.h"
-#include "flang-rt/terminator.h"
+#include "flang-rt/runtime/terminator.h"
 #include "flang/Runtime/io-api-consts.h"
 #include "flang/Runtime/transformational.h"
 #include <gtest/gtest.h>
diff --git a/flang-rt/unittests/Runtime/Stop.cpp b/flang-rt/unittests/Runtime/Stop.cpp
index 102fecd1afb22..5d1af20e77de7 100644
--- a/flang-rt/unittests/Runtime/Stop.cpp
+++ b/flang-rt/unittests/Runtime/Stop.cpp
@@ -12,7 +12,7 @@
 
 #include "flang/Runtime/stop.h"
 #include "CrashHandlerFixture.h"
-#include "flang-rt/environment.h"
+#include "flang-rt/runtime/environment.h"
 #include <cstdlib>
 #include <gtest/gtest.h>
 
diff --git a/flang-rt/unittests/Runtime/Support.cpp b/flang-rt/unittests/Runtime/Support.cpp
index 0159bd74aa60c..c97a6eae3a155 100644
--- a/flang-rt/unittests/Runtime/Support.cpp
+++ b/flang-rt/unittests/Runtime/Support.cpp
@@ -9,7 +9,7 @@
 #include "flang/Runtime/support.h"
 #include "tools.h"
 #include "gtest/gtest.h"
-#include "flang-rt/descriptor.h"
+#include "flang-rt/runtime/descriptor.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang-rt/unittests/Runtime/TemporaryStack.cpp b/flang-rt/unittests/Runtime/TemporaryStack.cpp
index d5cb9e5bfb9da..ff8efe123d7cc 100644
--- a/flang-rt/unittests/Runtime/TemporaryStack.cpp
+++ b/flang-rt/unittests/Runtime/TemporaryStack.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "gtest/gtest.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/tools.h"
-#include "flang-rt/type-code.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/tools.h"
+#include "flang-rt/runtime/type-code.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
diff --git a/flang-rt/unittests/Runtime/Transformational.cpp b/flang-rt/unittests/Runtime/Transformational.cpp
index 8805613738a60..06df96a3cc45a 100644
--- a/flang-rt/unittests/Runtime/Transformational.cpp
+++ b/flang-rt/unittests/Runtime/Transformational.cpp
@@ -9,7 +9,7 @@
 #include "flang/Runtime/transformational.h"
 #include "tools.h"
 #include "gtest/gtest.h"
-#include "flang-rt/type-code.h"
+#include "flang-rt/runtime/type-code.h"
 #include "flang/Common/float128.h"
 #include <vector>
 
diff --git a/flang-rt/unittests/Runtime/tools.h b/flang-rt/unittests/Runtime/tools.h
index 146aae659c338..36a4c2bd9c8b7 100644
--- a/flang-rt/unittests/Runtime/tools.h
+++ b/flang-rt/unittests/Runtime/tools.h
@@ -10,8 +10,8 @@
 #define FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_
 
 #include "gtest/gtest.h"
-#include "flang-rt/descriptor.h"
-#include "flang-rt/type-code.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/type-code.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
 #include <cstdint>
diff --git a/flang/examples/ExternalHelloWorld/CMakeLists.txt b/flang/examples/ExternalHelloWorld/CMakeLists.txt
index b61948718a5e3..dbb69475976dd 100644
--- a/flang/examples/ExternalHelloWorld/CMakeLists.txt
+++ b/flang/examples/ExternalHelloWorld/CMakeLists.txt
@@ -1,6 +1,6 @@
 # This test is not run by default as it requires input.
 add_llvm_example(external-hello-world
-  external-hello.cpp
+  ${FLANG_RT_SOURCE_DIR}/examples/ExternalHelloWorld/external-hello.cpp
 )
 
 target_link_libraries(external-hello-world
diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index 315947b962d22..04e120cc5d37a 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -72,7 +72,7 @@ function (runtime_source_files outvar)
 
   set(new_sources "")
   foreach (source IN LISTS "${outvar}")
-    set(new_source "${FLANG_RT_SOURCE_DIR}/lib/flang_rt")
+    set(new_source "${FLANG_RT_SOURCE_DIR}/lib")
     cmake_path(APPEND new_source "${ARG_SUBDIR}")
     cmake_path(APPEND new_source "${source}")
     list(APPEND new_sources "${new_source}")
@@ -259,8 +259,8 @@ set(supported_files
   unit.cpp
   utf.cpp
   )
+runtime_source_files(supported_files SUBDIR "runtime")
 
-runtime_source_files(supported_files)
 enable_cuda_compilation(flang_rt "${supported_files}")
 enable_omp_offload_compilation("${supported_files}")
 
@@ -293,8 +293,7 @@ if (NOT TARGET flang_rt.quadmath)
     list(APPEND sources ${f128_sources})
   endif()
 endif()
-
-runtime_source_files(sources)
+runtime_source_files(sources SUBDIR "runtime")
 
 
 if (NOT DEFINED MSVC)
diff --git a/flang/runtime/CUDA/CMakeLists.txt b/flang/runtime/CUDA/CMakeLists.txt
index 945cf60f00faa..aac1f62661810 100644
--- a/flang/runtime/CUDA/CMakeLists.txt
+++ b/flang/runtime/CUDA/CMakeLists.txt
@@ -24,7 +24,7 @@ set(sources
   pointer.cpp
   registration.cpp
 )
-runtime_source_files(sources SUBDIR "CUDA")
+runtime_source_files(sources SUBDIR "cuda")
 
 add_flang_library(${CUFRT_LIBNAME}
   ${sources}
diff --git a/flang/runtime/Float128Math/CMakeLists.txt b/flang/runtime/Float128Math/CMakeLists.txt
index a2266cf93237e..cdac5f893cf91 100644
--- a/flang/runtime/Float128Math/CMakeLists.txt
+++ b/flang/runtime/Float128Math/CMakeLists.txt
@@ -17,57 +17,58 @@
 include(CheckLibraryExists)
 
 set(sources
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/acos.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/acosh.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/asin.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/asinh.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/atan.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/atan2.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/atanh.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/ceil.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/complex-math.c
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/cos.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/cosh.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/erf.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/erfc.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/exp.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/exponent.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/floor.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/fma.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/fraction.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/hypot.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/j0.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/j1.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/jn.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/lgamma.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/llround.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/log.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/log10.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/lround.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/mod-real.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/modulo-real.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/nearest.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/nearbyint.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/norm2.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/pow.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/random.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/remainder.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/round.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/rrspacing.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/scale.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/set-exponent.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/sin.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/sinh.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/spacing.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/sqrt.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/tan.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/tanh.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/tgamma.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/trunc.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/y0.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/y1.cpp
-  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/yn.cpp
+  acos.cpp
+  acosh.cpp
+  asin.cpp
+  asinh.cpp
+  atan.cpp
+  atan2.cpp
+  atanh.cpp
+  ceil.cpp
+  complex-math.c
+  cos.cpp
+  cosh.cpp
+  erf.cpp
+  erfc.cpp
+  exp.cpp
+  exponent.cpp
+  floor.cpp
+  fma.cpp
+  fraction.cpp
+  hypot.cpp
+  j0.cpp
+  j1.cpp
+  jn.cpp
+  lgamma.cpp
+  llround.cpp
+  log.cpp
+  log10.cpp
+  lround.cpp
+  mod-real.cpp
+  modulo-real.cpp
+  nearest.cpp
+  nearbyint.cpp
+  norm2.cpp
+  pow.cpp
+  random.cpp
+  remainder.cpp
+  round.cpp
+  rrspacing.cpp
+  scale.cpp
+  set-exponent.cpp
+  sin.cpp
+  sinh.cpp
+  spacing.cpp
+  sqrt.cpp
+  tan.cpp
+  tanh.cpp
+  tgamma.cpp
+  trunc.cpp
+  y0.cpp
+  y1.cpp
+  yn.cpp
   )
+runtime_source_files(sources SUBDIR "quadmath")
 
 include_directories(AFTER "${CMAKE_CURRENT_SOURCE_DIR}/..")
 add_library(FortranFloat128MathILib INTERFACE)

>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 18/24] 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 5d9c66f47b48e..890522953efe0 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 b3b7297f6f7f1..9e6724be33033 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 19/24] 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 4b4b6d52f1327..16bd4c3ba8371 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 20/24] 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 2c6c3beef4783..4e62a8c32d360 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 21/24] 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 e223d2ef7d1b8..c65766b8b47e8 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 404650c9a89f2..03b589924518d 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 22/24] 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 7c598e02bd09b..c6271f1856eb9 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 65c6b0d374013..7cc720e2df9af 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 a849e95df31c1..5b5f23b5dc73c 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 7b0f85638f14e..c54ceb3332abf 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.

>From 8b91f2f2ca59653c140a6aeed84a57ca4566c898 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 10 Feb 2025 20:44:30 +0100
Subject: [PATCH 23/24] Undo move of CUDA/allocator.h

---
 flang-rt/lib/cuda/allocator.cpp                        |  2 +-
 flang-rt/lib/cuda/descriptor.cpp                       |  2 +-
 flang-rt/unittests/Runtime/CUDA/Allocatable.cpp        |  2 +-
 flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp       |  2 +-
 flang-rt/unittests/Runtime/CUDA/Memory.cpp             |  2 +-
 .../include/flang/Runtime/CUDA}/allocator.h            | 10 +++++-----
 6 files changed, 10 insertions(+), 10 deletions(-)
 rename {flang-rt/include/flang-rt/cuda => flang/include/flang/Runtime/CUDA}/allocator.h (78%)

diff --git a/flang-rt/lib/cuda/allocator.cpp b/flang-rt/lib/cuda/allocator.cpp
index 511543f6a4863..4199bf04b33f0 100644
--- a/flang-rt/lib/cuda/allocator.cpp
+++ b/flang-rt/lib/cuda/allocator.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/cuda/allocator.h"
+#include "flang/Runtime/CUDA/allocator.h"
 #include "flang-rt/runtime/allocator-registry.h"
 #include "flang-rt/runtime/derived.h"
 #include "flang-rt/runtime/stat.h"
diff --git a/flang-rt/lib/cuda/descriptor.cpp b/flang-rt/lib/cuda/descriptor.cpp
index 60e096acfde32..d44ab2e45d2a8 100644
--- a/flang-rt/lib/cuda/descriptor.cpp
+++ b/flang-rt/lib/cuda/descriptor.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/descriptor.h"
-#include "flang-rt/cuda/allocator.h"
 #include "flang-rt/runtime/descriptor.h"
 #include "flang-rt/runtime/terminator.h"
+#include "flang/Runtime/CUDA/allocator.h"
 #include "flang/Runtime/CUDA/common.h"
 
 #include "cuda_runtime.h"
diff --git a/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp b/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp
index 90d4da849552a..3f759a69c0388 100644
--- a/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp
@@ -9,10 +9,10 @@
 #include "flang/Runtime/allocatable.h"
 #include "cuda_runtime.h"
 #include "gtest/gtest.h"
-#include "flang-rt/cuda/allocator.h"
 #include "flang-rt/runtime/allocator-registry.h"
 #include "flang-rt/runtime/descriptor.h"
 #include "flang-rt/runtime/terminator.h"
+#include "flang/Runtime/CUDA/allocator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Support/Fortran.h"
diff --git a/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
index 6e46a80aa8f3c..9bda3270fe8a1 100644
--- a/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
@@ -8,10 +8,10 @@
 
 #include "cuda_runtime.h"
 #include "gtest/gtest.h"
-#include "flang-rt/cuda/allocator.h"
 #include "flang-rt/runtime/allocator-registry.h"
 #include "flang-rt/runtime/descriptor.h"
 #include "flang-rt/runtime/terminator.h"
+#include "flang/Runtime/CUDA/allocator.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Support/Fortran.h"
diff --git a/flang-rt/unittests/Runtime/CUDA/Memory.cpp b/flang-rt/unittests/Runtime/CUDA/Memory.cpp
index c43b165509a98..37ae59ec238c8 100644
--- a/flang-rt/unittests/Runtime/CUDA/Memory.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/Memory.cpp
@@ -10,9 +10,9 @@
 #include "cuda_runtime.h"
 #include "../tools.h"
 #include "gtest/gtest.h"
-#include "flang-rt/cuda/allocator.h"
 #include "flang-rt/runtime/allocator-registry.h"
 #include "flang-rt/runtime/terminator.h"
+#include "flang/Runtime/CUDA/allocator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/allocatable.h"
diff --git a/flang-rt/include/flang-rt/cuda/allocator.h b/flang/include/flang/Runtime/CUDA/allocator.h
similarity index 78%
rename from flang-rt/include/flang-rt/cuda/allocator.h
rename to flang/include/flang/Runtime/CUDA/allocator.h
index 5bc61cd04ee26..4fb4c94c5e9b0 100644
--- a/flang-rt/include/flang-rt/cuda/allocator.h
+++ b/flang/include/flang/Runtime/CUDA/allocator.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/cuda/allocator.h -----------------------*- C++ -*-===//
+//===-- include/flang/Runtime/CUDA/allocator.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 FLANG_RT_CUDA_ALLOCATOR_H_
-#define FLANG_RT_CUDA_ALLOCATOR_H_
+#ifndef FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
+#define FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
 
-#include "flang/Runtime/CUDA/common.h"
+#include "common.h"
 #include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
 
@@ -33,4 +33,4 @@ void *CUFAllocUnified(std::size_t);
 void CUFFreeUnified(void *);
 
 } // namespace Fortran::runtime::cuda
-#endif // FLANG_RT_CUDA_ALLOCATOR_H_
+#endif // FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_

>From 2f214660a5e6fe52f78d65e10744ff95e0f734e5 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Thu, 13 Feb 2025 23:36:50 +0100
Subject: [PATCH 24/24] Post-merge fixes

---
 flang-rt/unittests/Runtime/Pointer.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang-rt/unittests/Runtime/Pointer.cpp b/flang-rt/unittests/Runtime/Pointer.cpp
index b2515c9f981cd..6e8861d374889 100644
--- a/flang-rt/unittests/Runtime/Pointer.cpp
+++ b/flang-rt/unittests/Runtime/Pointer.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/pointer.h"
+#include "tools.h"
 #include "gtest/gtest.h"
 #include "flang-rt/runtime/descriptor.h"
-#include "flang-rt/runtime/tools.h"
 
 using namespace Fortran::runtime;
 



More information about the llvm-commits mailing list