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

Michael Kruse via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Nov 11 08:17:10 PST 2024


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

>From 2216bfe4a07625d894accf5730a313a65d30a982 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 27 Sep 2024 17:20:13 +0200
Subject: [PATCH 01/12] Move files to FortranRuntime

---
 FortranRuntime/.clang-format                  | 21 +++++++++
 .../cmake/config.h.cmake.in                   |  0
 .../include/flang/Common/Fortran-consts.h     |  0
 .../flang/Common}/ISO_Fortran_binding.h       | 13 +++---
 .../Common}/ISO_Fortran_binding_wrapper.h     | 13 +++---
 .../include/flang/Common/api-attrs.h          | 11 +++--
 .../flang/Common}/binary-floating-point.h     |  8 ++--
 .../flang/Common/bit-population-count.h       |  2 +-
 .../include/flang/Common/constexpr-bitset.h   |  2 +-
 .../include/flang/Common}/decimal.h           | 11 +++--
 .../include/flang/Common/enum-class.h         |  2 +-
 .../include/flang/Common/enum-set.h           |  2 +-
 .../include/flang/Common/fast-int-set.h       |  4 +-
 .../include/flang/Common/float128.h           |  2 +-
 .../include/flang/Common/format.h             |  2 +-
 .../include/flang/Common/idioms.h             |  2 +-
 .../flang/Common/leading-zero-bit-count.h     |  2 +-
 .../include/flang/Common/optional.h           |  6 +--
 .../include/flang/Common/real.h               |  2 +-
 .../include/flang/Common/reference-wrapper.h  |  6 +--
 .../include/flang/Common/restorer.h           |  4 +-
 .../include/flang/Common/target-rounding.h    |  0
 .../include/flang/Common/uint128.h            |  4 +-
 .../include/flang/Common/variant.h            |  6 +--
 .../include/flang/Common/visit.h              |  4 +-
 .../include/flang/Common/windows-include.h    |  2 +-
 .../include/flang/Runtime/CUDA/allocator.h    |  2 +-
 .../include/flang/Runtime/CUDA/descriptor.h   |  2 +-
 .../include/flang/Runtime/allocatable.h       |  2 +-
 .../flang/Runtime/allocator-registry.h        |  8 ++--
 .../include/flang/Runtime/array-constructor.h |  6 +--
 .../include/flang/Runtime/assign.h            |  2 +-
 .../include/flang/Runtime/c-or-cpp.h          |  2 +-
 .../include/flang/Runtime/character.h         |  2 +-
 .../include/flang/Runtime/command.h           |  2 +-
 .../include/flang/Runtime/cpp-type.h          |  2 +-
 .../include/flang/Runtime/derived-api.h       |  2 +-
 .../include/flang/Runtime/descriptor.h        |  4 +-
 .../include/flang/Runtime/entry-names.h       | 11 +++--
 .../include/flang/Runtime/exceptions.h        |  4 +-
 .../include/flang/Runtime/execute.h           |  4 +-
 .../include/flang/Runtime/extensions.h        |  2 +-
 .../flang/Runtime/freestanding-tools.h        |  2 +-
 .../include/flang/Runtime/inquiry.h           |  4 +-
 .../include/flang/Runtime/io-api.h            |  2 +-
 .../include/flang/Runtime/iostat.h            |  2 +-
 .../include/flang/Runtime/magic-numbers.h     |  6 +--
 .../include/flang/Runtime/main.h              |  2 +-
 .../flang/Runtime/matmul-instances.inc        |  0
 .../include/flang/Runtime/matmul-transpose.h  |  2 +-
 .../include/flang/Runtime/matmul.h            |  2 +-
 .../include/flang/Runtime/memory.h            |  2 +-
 .../include/flang/Runtime/misc-intrinsic.h    |  2 +-
 .../include/flang/Runtime/numeric.h           |  2 +-
 .../include/flang/Runtime/pointer.h           |  2 +-
 .../include/flang/Runtime/ragged.h            |  4 +-
 .../include/flang/Runtime/random.h            |  5 +++
 .../include/flang/Runtime/reduce.h            |  2 +-
 .../include/flang/Runtime/reduction.h         |  2 +-
 .../include/flang/Runtime/stop.h              |  2 +-
 .../include/flang/Runtime/support.h           |  4 +-
 .../include/flang/Runtime/temporary-stack.h   |  2 +-
 .../include/flang/Runtime/time-intrinsic.h    |  2 +-
 .../include/flang/Runtime/transformational.h  |  2 +-
 .../include/flang/Runtime/type-code.h         |  4 +-
 .../include/flang/Testing}/fp-testing.h       | 14 ++++--
 .../include/flang/Testing}/testing.h          | 14 ++++--
 .../lib/Common}/big-radix-floating-point.h    | 12 +++---
 .../lib/Common}/binary-to-decimal.cpp         |  4 +-
 .../lib/Common}/decimal-to-binary.cpp         |  6 +--
 .../lib/Runtime}/CMakeLists.txt               |  5 ++-
 .../lib/Runtime}/CUDA/CMakeLists.txt          |  0
 .../lib/Runtime}/CUDA/allocator.cpp           |  4 +-
 .../lib/Runtime}/CUDA/descriptor.cpp          |  2 +-
 .../lib/Runtime}/Float128Math/CMakeLists.txt  |  0
 .../lib/Runtime}/Float128Math/acos.cpp        |  2 +-
 .../lib/Runtime}/Float128Math/acosh.cpp       |  2 +-
 .../lib/Runtime}/Float128Math/asin.cpp        |  2 +-
 .../lib/Runtime}/Float128Math/asinh.cpp       |  2 +-
 .../lib/Runtime}/Float128Math/atan.cpp        |  2 +-
 .../lib/Runtime}/Float128Math/atan2.cpp       |  2 +-
 .../lib/Runtime}/Float128Math/atanh.cpp       |  2 +-
 .../lib/Runtime}/Float128Math/ceil.cpp        |  2 +-
 .../lib/Runtime}/Float128Math/complex-math.c  |  5 +--
 .../lib/Runtime}/Float128Math/complex-math.h  |  2 +-
 .../lib/Runtime}/Float128Math/cos.cpp         |  2 +-
 .../lib/Runtime}/Float128Math/cosh.cpp        |  2 +-
 .../lib/Runtime}/Float128Math/erf.cpp         |  2 +-
 .../lib/Runtime}/Float128Math/erfc.cpp        |  2 +-
 .../lib/Runtime}/Float128Math/exp.cpp         |  2 +-
 .../lib/Runtime}/Float128Math/exponent.cpp    |  2 +-
 .../lib/Runtime}/Float128Math/floor.cpp       |  2 +-
 .../lib/Runtime}/Float128Math/fma.cpp         |  2 +-
 .../lib/Runtime}/Float128Math/fraction.cpp    |  2 +-
 .../lib/Runtime}/Float128Math/hypot.cpp       |  2 +-
 .../lib/Runtime}/Float128Math/j0.cpp          |  2 +-
 .../lib/Runtime}/Float128Math/j1.cpp          |  2 +-
 .../lib/Runtime}/Float128Math/jn.cpp          |  2 +-
 .../lib/Runtime}/Float128Math/lgamma.cpp      |  2 +-
 .../lib/Runtime}/Float128Math/llround.cpp     |  2 +-
 .../lib/Runtime}/Float128Math/log.cpp         |  2 +-
 .../lib/Runtime}/Float128Math/log10.cpp       |  2 +-
 .../lib/Runtime}/Float128Math/lround.cpp      |  2 +-
 .../lib/Runtime}/Float128Math/math-entries.h  |  8 ++--
 .../lib/Runtime}/Float128Math/mod-real.cpp    |  2 +-
 .../lib/Runtime}/Float128Math/modulo-real.cpp |  2 +-
 .../lib/Runtime}/Float128Math/nearest.cpp     |  2 +-
 .../lib/Runtime}/Float128Math/norm2.cpp       |  2 +-
 .../Float128Math/numeric-template-specs.h     |  4 +-
 .../lib/Runtime}/Float128Math/pow.cpp         |  2 +-
 .../lib/Runtime}/Float128Math/random.cpp      |  2 +-
 .../lib/Runtime}/Float128Math/round.cpp       |  2 +-
 .../lib/Runtime}/Float128Math/rrspacing.cpp   |  2 +-
 .../lib/Runtime}/Float128Math/scale.cpp       |  2 +-
 .../Runtime}/Float128Math/set-exponent.cpp    |  2 +-
 .../lib/Runtime}/Float128Math/sin.cpp         |  2 +-
 .../lib/Runtime}/Float128Math/sinh.cpp        |  2 +-
 .../lib/Runtime}/Float128Math/spacing.cpp     |  2 +-
 .../lib/Runtime}/Float128Math/sqrt.cpp        |  2 +-
 .../lib/Runtime}/Float128Math/tan.cpp         |  2 +-
 .../lib/Runtime}/Float128Math/tanh.cpp        |  2 +-
 .../lib/Runtime}/Float128Math/tgamma.cpp      |  2 +-
 .../lib/Runtime}/Float128Math/trunc.cpp       |  2 +-
 .../lib/Runtime}/Float128Math/y0.cpp          |  2 +-
 .../lib/Runtime}/Float128Math/y1.cpp          |  2 +-
 .../lib/Runtime}/Float128Math/yn.cpp          |  2 +-
 .../lib/Runtime}/ISO_Fortran_binding.cpp      |  6 +--
 .../lib/Runtime}/ISO_Fortran_util.h           |  8 ++--
 .../lib/Runtime}/allocatable.cpp              |  8 ++--
 .../lib/Runtime}/allocator-registry.cpp       |  2 +-
 .../lib/Runtime}/array-constructor.cpp        |  8 ++--
 .../lib/Runtime}/assign-impl.h                |  4 +-
 .../lib/Runtime}/assign.cpp                   |  4 +-
 .../lib/Runtime}/buffer.cpp                   |  2 +-
 .../lib/Runtime}/buffer.h                     |  6 +--
 .../lib/Runtime}/character.cpp                |  6 +--
 .../lib/Runtime}/command.cpp                  |  4 +-
 .../lib/Runtime}/complex-powi.cpp             | 15 +++----
 .../lib/Runtime}/complex-reduction.c          |  5 +--
 .../lib/Runtime}/complex-reduction.h          |  7 ++-
 .../lib/Runtime}/connection.cpp               |  2 +-
 .../lib/Runtime}/connection.h                 | 10 ++---
 .../lib/Runtime}/copy.cpp                     |  6 +--
 .../lib/Runtime}/copy.h                       |  4 +-
 .../lib/Runtime}/derived-api.cpp              |  5 +--
 .../lib/Runtime}/derived.cpp                  |  4 +-
 .../lib/Runtime}/derived.h                    |  4 +-
 .../lib/Runtime}/descriptor-io.cpp            |  2 +-
 .../lib/Runtime}/descriptor-io.h              | 12 +++---
 .../lib/Runtime}/descriptor.cpp               |  4 +-
 .../lib/Runtime}/dot-product.cpp              |  8 ++--
 .../lib/Runtime}/edit-input.cpp               |  6 +--
 .../lib/Runtime}/edit-input.h                 |  6 +--
 .../lib/Runtime}/edit-output.cpp              |  4 +-
 .../lib/Runtime}/edit-output.h                |  8 ++--
 .../lib/Runtime}/emit-encoded.h               |  4 +-
 .../lib/Runtime}/environment-default-list.h   |  5 +--
 .../lib/Runtime}/environment.cpp              |  2 +-
 .../lib/Runtime}/environment.h                |  6 +--
 .../lib/Runtime}/exceptions.cpp               |  2 +-
 .../lib/Runtime}/execute.cpp                  |  4 +-
 .../lib/Runtime}/extensions.cpp               |  6 +--
 .../lib/Runtime}/external-unit.cpp            |  2 +-
 .../lib/Runtime}/extrema.cpp                  |  4 +-
 .../lib/Runtime}/file.cpp                     |  4 +-
 .../lib/Runtime}/file.h                       |  6 +--
 .../lib/Runtime}/findloc.cpp                  |  4 +-
 .../lib/Runtime}/format-implementation.h      | 10 ++---
 .../lib/Runtime}/format.cpp                   |  2 +-
 .../lib/Runtime}/format.h                     |  8 ++--
 .../lib/Runtime}/inquiry.cpp                  |  4 +-
 .../lib/Runtime}/internal-unit.cpp            |  4 +-
 .../lib/Runtime}/internal-unit.h              |  8 ++--
 .../lib/Runtime}/io-api-common.h              | 14 +++---
 .../lib/Runtime}/io-api-minimal.cpp           |  4 +-
 .../lib/Runtime}/io-api.cpp                   |  8 ++--
 .../lib/Runtime}/io-error.cpp                 |  4 +-
 .../lib/Runtime}/io-error.h                   |  6 +--
 .../lib/Runtime}/io-stmt.cpp                  |  4 +-
 .../lib/Runtime}/io-stmt.h                    | 10 ++---
 .../lib/Runtime}/iostat.cpp                   |  2 +-
 .../lib/Runtime}/iso_fortran_env_impl.f90     |  2 +-
 .../lib/Runtime}/lock.h                       |  4 +-
 .../lib/Runtime}/main.cpp                     |  2 +-
 .../lib/Runtime}/matmul-transpose.cpp         |  6 +--
 .../lib/Runtime}/matmul.cpp                   |  6 +--
 .../lib/Runtime}/memory.cpp                   |  4 +-
 .../lib/Runtime}/misc-intrinsic.cpp           |  6 +--
 .../lib/Runtime}/namelist.cpp                 |  4 +-
 .../lib/Runtime}/namelist.h                   |  6 +--
 .../lib/Runtime}/non-tbp-dio.cpp              |  2 +-
 .../lib/Runtime}/non-tbp-dio.h                |  4 +-
 .../lib/Runtime}/numeric-templates.h          |  8 ++--
 .../lib/Runtime}/numeric.cpp                  |  4 +-
 .../lib/Runtime}/pointer.cpp                  |  2 +-
 .../lib/Runtime}/product.cpp                  |  4 +-
 .../lib/Runtime}/pseudo-unit.cpp              |  2 +-
 .../lib/Runtime}/ragged.cpp                   |  2 +-
 .../lib/Runtime}/random-templates.h           |  8 ++--
 .../lib/Runtime}/random.cpp                   |  8 ++--
 .../lib/Runtime}/reduce.cpp                   |  4 +-
 .../lib/Runtime}/reduction-templates.h        |  8 ++--
 .../lib/Runtime}/reduction.cpp                |  4 +-
 .../lib/Runtime}/stack.h                      | 10 ++---
 .../lib/Runtime}/stat.cpp                     |  4 +-
 .../lib/Runtime}/stat.h                       |  6 +--
 .../lib/Runtime}/stop.cpp                     |  2 +-
 .../lib/Runtime}/sum.cpp                      |  4 +-
 .../lib/Runtime}/support.cpp                  |  4 +-
 .../lib/Runtime}/temporary-stack.cpp          |  6 +--
 .../lib/Runtime}/terminator.cpp               |  2 +-
 .../lib/Runtime}/terminator.h                 |  4 +-
 .../lib/Runtime}/time-intrinsic.cpp           |  6 +--
 .../lib/Runtime}/tools.cpp                    |  2 +-
 .../lib/Runtime}/tools.h                      |  8 ++--
 .../lib/Runtime}/transformational.cpp         |  6 +--
 .../lib/Runtime}/type-code.cpp                |  3 +-
 .../lib/Runtime}/type-info.cpp                |  2 +-
 .../lib/Runtime}/type-info.h                  |  6 +--
 .../lib/Runtime}/unit-map.cpp                 |  2 +-
 .../lib/Runtime}/unit-map.h                   |  8 ++--
 .../lib/Runtime}/unit.cpp                     |  2 +-
 .../lib/Runtime}/unit.h                       | 14 +++---
 .../lib/Runtime}/utf.cpp                      |  2 +-
 .../lib/Runtime}/utf.h                        |  4 +-
 .../lib/Testing}/fp-testing.cpp               |  4 +-
 .../lib/Testing}/testing.cpp                  | 10 ++++-
 .../module/.clang-format                      |  0
 .../module/__cuda_builtins.f90                |  0
 .../module/__fortran_builtins.f90             |  0
 .../module/__fortran_ieee_exceptions.f90      |  0
 .../module/__fortran_type_info.f90            |  0
 .../module/__ppc_intrinsics.f90               |  0
 .../module/__ppc_types.f90                    |  0
 .../module/cudadevice.f90                     |  2 +-
 .../module/ieee_arithmetic.f90                |  0
 .../module/ieee_exceptions.f90                |  0
 .../module/ieee_features.f90                  |  0
 .../module/iso_c_binding.f90                  |  0
 .../module/iso_fortran_env.f90                |  0
 {flang => FortranRuntime}/module/mma.f90      | 43 ++++++++++++++-----
 .../unittests/Common/CMakeLists.txt           |  0
 .../unittests/Common/FastIntSetTest.cpp       |  4 +-
 .../unittests/Decimal/CMakeLists.txt          |  0
 .../unittests/Decimal/quick-sanity-test.cpp   | 10 ++++-
 .../unittests/Decimal/thorough-test.cpp       | 10 ++++-
 .../unittests/Evaluate/CMakeLists.txt         |  6 +++
 .../Evaluate/ISO-Fortran-binding.cpp          | 12 +++++-
 .../unittests/Evaluate/reshape.cpp            | 10 ++++-
 .../unittests/Runtime/AccessTest.cpp          |  4 +-
 .../unittests/Runtime/Allocatable.cpp         |  4 +-
 .../unittests/Runtime/ArrayConstructor.cpp    |  6 +--
 .../unittests/Runtime/BufferTest.cpp          |  4 +-
 .../unittests/Runtime/CMakeLists.txt          |  0
 .../unittests/Runtime/CUDA/AllocatorCUF.cpp   |  6 +--
 .../unittests/Runtime/CUDA/CMakeLists.txt     |  0
 .../unittests/Runtime/CharacterTest.cpp       |  4 +-
 .../unittests/Runtime/CommandTest.cpp         |  6 +--
 .../unittests/Runtime/Complex.cpp             |  0
 .../unittests/Runtime/CrashHandlerFixture.cpp |  4 +-
 .../unittests/Runtime/CrashHandlerFixture.h   |  8 ++--
 .../unittests/Runtime/Derived.cpp             |  6 +--
 .../unittests/Runtime/ExternalIOTest.cpp      |  4 +-
 .../unittests/Runtime/Format.cpp              |  8 ++--
 .../unittests/Runtime/Inquiry.cpp             |  6 +--
 .../unittests/Runtime/ListInputTest.cpp       |  4 +-
 .../unittests/Runtime/LogicalFormatTest.cpp   |  2 +-
 .../unittests/Runtime/Matmul.cpp              |  6 +--
 .../unittests/Runtime/MatmulTranspose.cpp     |  6 +--
 .../unittests/Runtime/MiscIntrinsic.cpp       |  6 +--
 .../unittests/Runtime/Namelist.cpp            |  6 +--
 .../unittests/Runtime/Numeric.cpp             |  4 +-
 .../unittests/Runtime/NumericalFormatTest.cpp |  2 +-
 .../unittests/Runtime/Pointer.cpp             |  6 +--
 .../unittests/Runtime/Ragged.cpp              |  2 +-
 .../unittests/Runtime/Random.cpp              |  4 +-
 .../unittests/Runtime/Reduction.cpp           |  6 +--
 .../unittests/Runtime/RuntimeCrashTest.cpp    |  6 +--
 .../unittests/Runtime/Stop.cpp                |  4 +-
 .../unittests/Runtime/Support.cpp             |  6 +--
 .../unittests/Runtime/TemporaryStack.cpp      |  8 ++--
 .../unittests/Runtime/Time.cpp                |  4 +-
 .../unittests/Runtime/Transformational.cpp    |  6 +--
 .../unittests/Runtime/tools.h                 |  6 +--
 flang/CMakeLists.txt                          |  7 +--
 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 +-
 .../include/flang/Frontend/FrontendOptions.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 +-
 .../flang/Optimizer/Builder/IntrinsicCall.h   |  1 +
 .../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          |  2 +-
 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 +-
 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     |  2 +-
 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    |  4 +-
 .../flang/{Common => Support}/Fortran.h       |  4 +-
 .../{Common => Support}/MathOptionsBase.def   |  0
 .../{Common => Support}/MathOptionsBase.h     |  8 ++--
 .../{Common => Support}/OpenMP-features.h     |  2 +-
 .../flang/{Common => Support}/Version.h       |  2 +-
 .../flang/{Common => Support}/default-kinds.h |  4 +-
 .../flang/{Common => Support}/indirection.h   |  4 +-
 .../flang/{Common => Support}/interval.h      |  4 +-
 .../{Common => Support}/reference-counted.h   |  2 +-
 .../flang/{Common => Support}/reference.h     |  2 +-
 .../static-multimap-view.h                    |  2 +-
 .../flang/{Common => Support}/template.h      |  4 +-
 .../flang/{Common => Support}/unwrap.h        |  6 +--
 flang/include/flang/Tools/CrossToolHelpers.h  |  2 +-
 flang/lib/Common/CMakeLists.txt               | 10 ++---
 flang/lib/Decimal/CMakeLists.txt              | 23 +++++-----
 flang/lib/Evaluate/call.cpp                   |  2 +-
 flang/lib/Evaluate/characteristics.cpp        |  2 +-
 flang/lib/Evaluate/common.cpp                 |  3 ++
 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/real.cpp                   |  2 +-
 flang/lib/Evaluate/shape.cpp                  |  2 +-
 flang/lib/Evaluate/target.cpp                 |  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/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 +-
 .../lib/Optimizer/Transforms/AddDebugInfo.cpp |  2 +-
 .../Transforms/AssumedRankOpConversion.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/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/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 +-
 .../{Common => Support}/Fortran-features.cpp  |  6 +--
 flang/lib/{Common => Support}/Fortran.cpp     |  6 +--
 flang/lib/{Common => Support}/Version.cpp     |  4 +-
 .../lib/{Common => Support}/default-kinds.cpp |  4 +-
 flang/lib/{Common => Support}/idioms.cpp      |  2 +-
 flang/test/lit.cfg.py                         |  2 +-
 flang/tools/bbc/bbc.cpp                       |  8 ++--
 flang/tools/f18-parse-demo/f18-parse-demo.cpp |  4 +-
 flang/tools/f18/CMakeLists.txt                |  6 ++-
 flang/unittests/CMakeLists.txt                |  6 +--
 flang/unittests/Evaluate/CMakeLists.txt       | 20 ++-------
 .../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/uint128.cpp          |  2 +-
 419 files changed, 873 insertions(+), 777 deletions(-)
 create mode 100644 FortranRuntime/.clang-format
 rename flang/runtime/config.h.cmake => FortranRuntime/cmake/config.h.cmake.in (100%)
 rename {flang => FortranRuntime}/include/flang/Common/Fortran-consts.h (100%)
 rename {flang/include/flang => FortranRuntime/include/flang/Common}/ISO_Fortran_binding.h (95%)
 rename {flang/include/flang => FortranRuntime/include/flang/Common}/ISO_Fortran_binding_wrapper.h (73%)
 rename {flang => FortranRuntime}/include/flang/Common/api-attrs.h (97%)
 rename {flang/include/flang/Decimal => FortranRuntime/include/flang/Common}/binary-floating-point.h (96%)
 rename {flang => FortranRuntime}/include/flang/Common/bit-population-count.h (98%)
 rename {flang => FortranRuntime}/include/flang/Common/constexpr-bitset.h (98%)
 rename {flang/include/flang/Decimal => FortranRuntime/include/flang/Common}/decimal.h (95%)
 rename {flang => FortranRuntime}/include/flang/Common/enum-class.h (98%)
 rename {flang => FortranRuntime}/include/flang/Common/enum-set.h (99%)
 rename {flang => FortranRuntime}/include/flang/Common/fast-int-set.h (97%)
 rename {flang => FortranRuntime}/include/flang/Common/float128.h (96%)
 rename {flang => FortranRuntime}/include/flang/Common/format.h (99%)
 rename {flang => FortranRuntime}/include/flang/Common/idioms.h (99%)
 rename {flang => FortranRuntime}/include/flang/Common/leading-zero-bit-count.h (98%)
 rename {flang => FortranRuntime}/include/flang/Common/optional.h (98%)
 rename {flang => FortranRuntime}/include/flang/Common/real.h (99%)
 rename {flang => FortranRuntime}/include/flang/Common/reference-wrapper.h (96%)
 rename {flang => FortranRuntime}/include/flang/Common/restorer.h (97%)
 rename {flang => FortranRuntime}/include/flang/Common/target-rounding.h (100%)
 rename {flang => FortranRuntime}/include/flang/Common/uint128.h (99%)
 rename {flang => FortranRuntime}/include/flang/Common/variant.h (89%)
 rename {flang => FortranRuntime}/include/flang/Common/visit.h (98%)
 rename {flang => FortranRuntime}/include/flang/Common/windows-include.h (93%)
 rename {flang => FortranRuntime}/include/flang/Runtime/CUDA/allocator.h (96%)
 rename {flang => FortranRuntime}/include/flang/Runtime/CUDA/descriptor.h (95%)
 rename {flang => FortranRuntime}/include/flang/Runtime/allocatable.h (99%)
 rename {flang => FortranRuntime}/include/flang/Runtime/allocator-registry.h (89%)
 rename {flang => FortranRuntime}/include/flang/Runtime/array-constructor.h (97%)
 rename {flang => FortranRuntime}/include/flang/Runtime/assign.h (98%)
 rename {flang => FortranRuntime}/include/flang/Runtime/c-or-cpp.h (95%)
 rename {flang => FortranRuntime}/include/flang/Runtime/character.h (99%)
 rename {flang => FortranRuntime}/include/flang/Runtime/command.h (98%)
 rename {flang => FortranRuntime}/include/flang/Runtime/cpp-type.h (98%)
 rename {flang => FortranRuntime}/include/flang/Runtime/derived-api.h (98%)
 rename {flang => FortranRuntime}/include/flang/Runtime/descriptor.h (99%)
 rename {flang => FortranRuntime}/include/flang/Runtime/entry-names.h (89%)
 rename {flang => FortranRuntime}/include/flang/Runtime/exceptions.h (86%)
 rename {flang => FortranRuntime}/include/flang/Runtime/execute.h (89%)
 rename {flang => FortranRuntime}/include/flang/Runtime/extensions.h (97%)
 rename {flang => FortranRuntime}/include/flang/Runtime/freestanding-tools.h (99%)
 rename {flang => FortranRuntime}/include/flang/Runtime/inquiry.h (91%)
 rename {flang => FortranRuntime}/include/flang/Runtime/io-api.h (99%)
 rename {flang => FortranRuntime}/include/flang/Runtime/iostat.h (98%)
 rename {flang => FortranRuntime}/include/flang/Runtime/magic-numbers.h (98%)
 rename {flang => FortranRuntime}/include/flang/Runtime/main.h (95%)
 rename {flang => FortranRuntime}/include/flang/Runtime/matmul-instances.inc (100%)
 rename {flang => FortranRuntime}/include/flang/Runtime/matmul-transpose.h (97%)
 rename {flang => FortranRuntime}/include/flang/Runtime/matmul.h (97%)
 rename {flang => FortranRuntime}/include/flang/Runtime/memory.h (99%)
 rename {flang => FortranRuntime}/include/flang/Runtime/misc-intrinsic.h (95%)
 rename {flang => FortranRuntime}/include/flang/Runtime/numeric.h (99%)
 rename {flang => FortranRuntime}/include/flang/Runtime/pointer.h (99%)
 rename {flang => FortranRuntime}/include/flang/Runtime/ragged.h (96%)
 rename {flang => FortranRuntime}/include/flang/Runtime/random.h (93%)
 rename {flang => FortranRuntime}/include/flang/Runtime/reduce.h (99%)
 rename {flang => FortranRuntime}/include/flang/Runtime/reduction.h (99%)
 rename {flang => FortranRuntime}/include/flang/Runtime/stop.h (97%)
 rename {flang => FortranRuntime}/include/flang/Runtime/support.h (94%)
 rename {flang => FortranRuntime}/include/flang/Runtime/temporary-stack.h (98%)
 rename {flang => FortranRuntime}/include/flang/Runtime/time-intrinsic.h (97%)
 rename {flang => FortranRuntime}/include/flang/Runtime/transformational.h (99%)
 rename {flang => FortranRuntime}/include/flang/Runtime/type-code.h (96%)
 rename {flang/unittests/Evaluate => FortranRuntime/include/flang/Testing}/fp-testing.h (54%)
 rename {flang/unittests/Evaluate => FortranRuntime/include/flang/Testing}/testing.h (74%)
 rename {flang/lib/Decimal => FortranRuntime/lib/Common}/big-radix-floating-point.h (97%)
 rename {flang/lib/Decimal => FortranRuntime/lib/Common}/binary-to-decimal.cpp (99%)
 rename {flang/lib/Decimal => FortranRuntime/lib/Common}/decimal-to-binary.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/CMakeLists.txt (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/CUDA/CMakeLists.txt (100%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/CUDA/allocator.cpp (94%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/CUDA/descriptor.cpp (91%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/CMakeLists.txt (100%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/acos.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/acosh.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/asin.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/asinh.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/atan.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/atan2.cpp (88%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/atanh.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/ceil.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/complex-math.c (92%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/complex-math.h (96%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/cos.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/cosh.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/erf.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/erfc.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/exp.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/exponent.cpp (90%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/floor.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/fma.cpp (89%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/fraction.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/hypot.cpp (88%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/j0.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/j1.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/jn.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/lgamma.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/llround.cpp (88%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/log.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/log10.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/lround.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/math-entries.h (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/mod-real.cpp (89%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/modulo-real.cpp (89%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/nearest.cpp (89%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/norm2.cpp (93%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/numeric-template-specs.h (92%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/pow.cpp (88%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/random.cpp (89%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/round.cpp (89%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/rrspacing.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/scale.cpp (90%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/set-exponent.cpp (88%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/sin.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/sinh.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/spacing.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/sqrt.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/tan.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/tanh.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/tgamma.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/trunc.cpp (89%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/y0.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/y1.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/Float128Math/yn.cpp (87%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/ISO_Fortran_binding.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/ISO_Fortran_util.h (95%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/allocatable.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/allocator-registry.cpp (94%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/array-constructor.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/assign-impl.h (89%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/assign.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/buffer.cpp (92%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/buffer.h (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/character.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/command.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/complex-powi.cpp (91%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/complex-reduction.c (97%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/complex-reduction.h (97%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/connection.cpp (96%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/connection.h (96%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/copy.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/copy.h (89%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/derived-api.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/derived.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/derived.h (92%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/descriptor-io.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/descriptor-io.h (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/descriptor.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/dot-product.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/edit-input.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/edit-input.h (93%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/edit-output.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/edit-output.h (97%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/emit-encoded.h (97%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/environment-default-list.h (85%)
 mode change 100755 => 100644
 rename {flang/runtime => FortranRuntime/lib/Runtime}/environment.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/environment.h (93%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/exceptions.cpp (96%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/execute.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/extensions.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/external-unit.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/extrema.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/file.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/file.h (97%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/findloc.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/format-implementation.h (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/format.cpp (92%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/format.h (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/inquiry.cpp (97%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/internal-unit.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/internal-unit.h (90%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/io-api-common.h (94%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/io-api-minimal.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/io-api.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/io-error.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/io-error.h (96%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/io-stmt.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/io-stmt.h (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/iostat.cpp (98%)
 rename {flang/module => FortranRuntime/lib/Runtime}/iso_fortran_env_impl.f90 (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/lock.h (96%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/main.cpp (94%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/matmul-transpose.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/matmul.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/memory.cpp (93%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/misc-intrinsic.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/namelist.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/namelist.h (94%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/non-tbp-dio.cpp (93%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/non-tbp-dio.h (95%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/numeric-templates.h (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/numeric.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/pointer.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/product.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/pseudo-unit.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/ragged.cpp (97%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/random-templates.h (96%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/random.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/reduce.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/reduction-templates.h (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/reduction.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/stack.h (95%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/stat.cpp (97%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/stat.h (93%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/stop.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/sum.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/support.cpp (94%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/temporary-stack.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/terminator.cpp (97%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/terminator.h (97%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/time-intrinsic.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/tools.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/tools.h (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/transformational.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/type-code.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/type-info.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/type-info.h (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/unit-map.cpp (97%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/unit-map.h (96%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/unit.cpp (99%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/unit.h (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/utf.cpp (98%)
 rename {flang/runtime => FortranRuntime/lib/Runtime}/utf.h (96%)
 rename {flang/unittests/Evaluate => FortranRuntime/lib/Testing}/fp-testing.cpp (98%)
 rename {flang/unittests/Evaluate => FortranRuntime/lib/Testing}/testing.cpp (88%)
 rename {flang => FortranRuntime}/module/.clang-format (100%)
 rename {flang => FortranRuntime}/module/__cuda_builtins.f90 (100%)
 rename {flang => FortranRuntime}/module/__fortran_builtins.f90 (100%)
 rename {flang => FortranRuntime}/module/__fortran_ieee_exceptions.f90 (100%)
 rename {flang => FortranRuntime}/module/__fortran_type_info.f90 (100%)
 rename {flang => FortranRuntime}/module/__ppc_intrinsics.f90 (100%)
 rename {flang => FortranRuntime}/module/__ppc_types.f90 (100%)
 rename {flang => FortranRuntime}/module/cudadevice.f90 (96%)
 rename {flang => FortranRuntime}/module/ieee_arithmetic.f90 (100%)
 rename {flang => FortranRuntime}/module/ieee_exceptions.f90 (100%)
 rename {flang => FortranRuntime}/module/ieee_features.f90 (100%)
 rename {flang => FortranRuntime}/module/iso_c_binding.f90 (100%)
 rename {flang => FortranRuntime}/module/iso_fortran_env.f90 (100%)
 rename {flang => FortranRuntime}/module/mma.f90 (98%)
 rename {flang => FortranRuntime}/unittests/Common/CMakeLists.txt (100%)
 rename {flang => FortranRuntime}/unittests/Common/FastIntSetTest.cpp (97%)
 rename {flang => FortranRuntime}/unittests/Decimal/CMakeLists.txt (100%)
 rename {flang => FortranRuntime}/unittests/Decimal/quick-sanity-test.cpp (91%)
 rename {flang => FortranRuntime}/unittests/Decimal/thorough-test.cpp (85%)
 create mode 100644 FortranRuntime/unittests/Evaluate/CMakeLists.txt
 rename {flang => FortranRuntime}/unittests/Evaluate/ISO-Fortran-binding.cpp (98%)
 rename {flang => FortranRuntime}/unittests/Evaluate/reshape.cpp (88%)
 rename {flang => FortranRuntime}/unittests/Runtime/AccessTest.cpp (99%)
 rename {flang => FortranRuntime}/unittests/Runtime/Allocatable.cpp (98%)
 rename {flang => FortranRuntime}/unittests/Runtime/ArrayConstructor.cpp (99%)
 rename {flang => FortranRuntime}/unittests/Runtime/BufferTest.cpp (97%)
 rename {flang => FortranRuntime}/unittests/Runtime/CMakeLists.txt (100%)
 rename {flang => FortranRuntime}/unittests/Runtime/CUDA/AllocatorCUF.cpp (95%)
 rename {flang => FortranRuntime}/unittests/Runtime/CUDA/CMakeLists.txt (100%)
 rename {flang => FortranRuntime}/unittests/Runtime/CharacterTest.cpp (99%)
 rename {flang => FortranRuntime}/unittests/Runtime/CommandTest.cpp (99%)
 rename {flang => FortranRuntime}/unittests/Runtime/Complex.cpp (100%)
 rename {flang => FortranRuntime}/unittests/Runtime/CrashHandlerFixture.cpp (92%)
 rename {flang => FortranRuntime}/unittests/Runtime/CrashHandlerFixture.h (70%)
 rename {flang => FortranRuntime}/unittests/Runtime/Derived.cpp (96%)
 rename {flang => FortranRuntime}/unittests/Runtime/ExternalIOTest.cpp (99%)
 rename {flang => FortranRuntime}/unittests/Runtime/Format.cpp (96%)
 rename {flang => FortranRuntime}/unittests/Runtime/Inquiry.cpp (98%)
 rename {flang => FortranRuntime}/unittests/Runtime/ListInputTest.cpp (98%)
 rename {flang => FortranRuntime}/unittests/Runtime/LogicalFormatTest.cpp (96%)
 rename {flang => FortranRuntime}/unittests/Runtime/Matmul.cpp (99%)
 rename {flang => FortranRuntime}/unittests/Runtime/MatmulTranspose.cpp (99%)
 rename {flang => FortranRuntime}/unittests/Runtime/MiscIntrinsic.cpp (98%)
 rename {flang => FortranRuntime}/unittests/Runtime/Namelist.cpp (99%)
 rename {flang => FortranRuntime}/unittests/Runtime/Numeric.cpp (99%)
 rename {flang => FortranRuntime}/unittests/Runtime/NumericalFormatTest.cpp (99%)
 rename {flang => FortranRuntime}/unittests/Runtime/Pointer.cpp (98%)
 rename {flang => FortranRuntime}/unittests/Runtime/Ragged.cpp (94%)
 rename {flang => FortranRuntime}/unittests/Runtime/Random.cpp (97%)
 rename {flang => FortranRuntime}/unittests/Runtime/Reduction.cpp (99%)
 rename {flang => FortranRuntime}/unittests/Runtime/RuntimeCrashTest.cpp (98%)
 rename {flang => FortranRuntime}/unittests/Runtime/Stop.cpp (96%)
 rename {flang => FortranRuntime}/unittests/Runtime/Support.cpp (97%)
 rename {flang => FortranRuntime}/unittests/Runtime/TemporaryStack.cpp (98%)
 rename {flang => FortranRuntime}/unittests/Runtime/Time.cpp (98%)
 rename {flang => FortranRuntime}/unittests/Runtime/Transformational.cpp (99%)
 rename {flang => FortranRuntime}/unittests/Runtime/tools.h (93%)
 rename flang/include/flang/{Common => Support}/Fortran-features.h (98%)
 rename flang/include/flang/{Common => Support}/Fortran.h (98%)
 rename flang/include/flang/{Common => Support}/MathOptionsBase.def (100%)
 rename flang/include/flang/{Common => Support}/MathOptionsBase.h (86%)
 rename flang/include/flang/{Common => Support}/OpenMP-features.h (94%)
 rename flang/include/flang/{Common => Support}/Version.h (95%)
 rename flang/include/flang/{Common => Support}/default-kinds.h (96%)
 rename flang/include/flang/{Common => Support}/indirection.h (98%)
 rename flang/include/flang/{Common => Support}/interval.h (97%)
 rename flang/include/flang/{Common => Support}/reference-counted.h (96%)
 rename flang/include/flang/{Common => Support}/reference.h (97%)
 rename flang/include/flang/{Common => Support}/static-multimap-view.h (97%)
 rename flang/include/flang/{Common => Support}/template.h (99%)
 rename flang/include/flang/{Common => Support}/unwrap.h (97%)
 rename flang/lib/{Common => Support}/Fortran-features.cpp (91%)
 rename flang/lib/{Common => Support}/Fortran.cpp (96%)
 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/FortranRuntime/.clang-format b/FortranRuntime/.clang-format
new file mode 100644
index 00000000000000..c1dfe06fdf5782
--- /dev/null
+++ b/FortranRuntime/.clang-format
@@ -0,0 +1,21 @@
+---
+# 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:        4
+  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
+    Priority:        3
+  - Regex:           '^"(flang|\.\.)/'
+    Priority:        2
+  - Regex:           '.*'
+    Priority:        1
+...
+
+# vim:set filetype=yaml:
diff --git a/flang/runtime/config.h.cmake b/FortranRuntime/cmake/config.h.cmake.in
similarity index 100%
rename from flang/runtime/config.h.cmake
rename to FortranRuntime/cmake/config.h.cmake.in
diff --git a/flang/include/flang/Common/Fortran-consts.h b/FortranRuntime/include/flang/Common/Fortran-consts.h
similarity index 100%
rename from flang/include/flang/Common/Fortran-consts.h
rename to FortranRuntime/include/flang/Common/Fortran-consts.h
diff --git a/flang/include/flang/ISO_Fortran_binding.h b/FortranRuntime/include/flang/Common/ISO_Fortran_binding.h
similarity index 95%
rename from flang/include/flang/ISO_Fortran_binding.h
rename to FortranRuntime/include/flang/Common/ISO_Fortran_binding.h
index 89a10ce69a2ba2..516355c01ec7d0 100644
--- a/flang/include/flang/ISO_Fortran_binding.h
+++ b/FortranRuntime/include/flang/Common/ISO_Fortran_binding.h
@@ -1,20 +1,19 @@
-/*===-- include/flang/ISO_Fortran_binding.h -----------------------*- C++ -*-===
+/*===-- include/flang/Common/ISO_Fortran_binding.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 CFI_ISO_FORTRAN_BINDING_H_
-#define CFI_ISO_FORTRAN_BINDING_H_
+#ifndef FORTRAN_COMMON_ISO_FORTRAN_BINDING_H_
+#define FORTRAN_COMMON_ISO_FORTRAN_BINDING_H_
 
 /* When this header is included into the compiler and runtime implementations,
  * 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
@@ -207,4 +206,4 @@ RT_API_ATTRS int CFI_setpointer(
 } // extern "C"
 #endif
 
-#endif /* CFI_ISO_FORTRAN_BINDING_H_ */
+#endif /* FORTRAN_COMMON_ISO_FORTRAN_BINDING_H_ */
diff --git a/flang/include/flang/ISO_Fortran_binding_wrapper.h b/FortranRuntime/include/flang/Common/ISO_Fortran_binding_wrapper.h
similarity index 73%
rename from flang/include/flang/ISO_Fortran_binding_wrapper.h
rename to FortranRuntime/include/flang/Common/ISO_Fortran_binding_wrapper.h
index 37289bdbabd03c..d1bc9be34859a4 100644
--- a/flang/include/flang/ISO_Fortran_binding_wrapper.h
+++ b/FortranRuntime/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,7 +22,7 @@
 
 /* clang-format off */
 #include <stddef.h>
-#include "Common/api-attrs.h"
+#include "flang/Common/api-attrs.h" 
 #ifdef __cplusplus
 namespace Fortran {
 namespace ISO {
@@ -36,4 +35,4 @@ namespace ISO {
 #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/api-attrs.h b/FortranRuntime/include/flang/Common/api-attrs.h
similarity index 97%
rename from flang/include/flang/Common/api-attrs.h
rename to FortranRuntime/include/flang/Common/api-attrs.h
index d73e60996bc81f..9a3001fb255c11 100644
--- a/flang/include/flang/Common/api-attrs.h
+++ b/FortranRuntime/include/flang/Common/api-attrs.h
@@ -1,11 +1,10 @@
-/*===-- include/flang/Common/api-attrs.h ---------------------------*- C -*-=//
+/*===-- include/flang/Common/api-attrs.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
  *
- *===------------------------------------------------------------------------===
- */
+ *===----------------------------------------------------------------------===*/
 
 /*
  * The file defines a set macros that can be used to apply
@@ -13,8 +12,8 @@
  * declared/defined/used in Flang runtime library.
  */
 
-#ifndef FORTRAN_RUNTIME_API_ATTRS_H_
-#define FORTRAN_RUNTIME_API_ATTRS_H_
+#ifndef FORTRAN_COMMON_API_ATTRS_H_
+#define FORTRAN_COMMON_API_ATTRS_H_
 
 /*
  * RT_EXT_API_GROUP_BEGIN/END pair is placed around definitions
@@ -178,4 +177,4 @@
 #define RT_DEVICE_NOINLINE_HOST_INLINE inline
 #endif
 
-#endif /* !FORTRAN_RUNTIME_API_ATTRS_H_ */
+#endif /* FORTRAN_COMMON_API_ATTRS_H_ */
diff --git a/flang/include/flang/Decimal/binary-floating-point.h b/FortranRuntime/include/flang/Common/binary-floating-point.h
similarity index 96%
rename from flang/include/flang/Decimal/binary-floating-point.h
rename to FortranRuntime/include/flang/Common/binary-floating-point.h
index 1e0cde97d98e61..705acc31bdfb21 100644
--- a/flang/include/flang/Decimal/binary-floating-point.h
+++ b/FortranRuntime/include/flang/Common/binary-floating-point.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Decimal/binary-floating-point.h -----------*- C++ -*-===//
+//===-- include/flang/Common/binary-floating-point.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_DECIMAL_BINARY_FLOATING_POINT_H_
-#define FORTRAN_DECIMAL_BINARY_FLOATING_POINT_H_
+#ifndef FORTRAN_COMMON_BINARY_FLOATING_POINT_H_
+#define FORTRAN_COMMON_BINARY_FLOATING_POINT_H_
 
 // Access and manipulate the fields of an IEEE-754 binary
 // floating-point value via a generalized template.
@@ -208,4 +208,4 @@ template <int BINARY_PRECISION> class BinaryFloatingPointNumber {
   RawType raw_{0};
 };
 } // namespace Fortran::decimal
-#endif
+#endif /* FORTRAN_COMMON_BINARY_FLOATING_POINT_H_ */
diff --git a/flang/include/flang/Common/bit-population-count.h b/FortranRuntime/include/flang/Common/bit-population-count.h
similarity index 98%
rename from flang/include/flang/Common/bit-population-count.h
rename to FortranRuntime/include/flang/Common/bit-population-count.h
index e1aeb78f9a3765..59ade914d14d85 100644
--- a/flang/include/flang/Common/bit-population-count.h
+++ b/FortranRuntime/include/flang/Common/bit-population-count.h
@@ -93,4 +93,4 @@ template <typename INT> inline constexpr int TrailingZeroBitCount(INT x) {
   }
 }
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_BIT_POPULATION_COUNT_H_
+#endif /* FORTRAN_COMMON_BIT_POPULATION_COUNT_H_ */
diff --git a/flang/include/flang/Common/constexpr-bitset.h b/FortranRuntime/include/flang/Common/constexpr-bitset.h
similarity index 98%
rename from flang/include/flang/Common/constexpr-bitset.h
rename to FortranRuntime/include/flang/Common/constexpr-bitset.h
index 1aafb6eff84c61..093b247b5f4eff 100644
--- a/flang/include/flang/Common/constexpr-bitset.h
+++ b/FortranRuntime/include/flang/Common/constexpr-bitset.h
@@ -144,4 +144,4 @@ template <int BITS> class BitSet {
   Word bits_{0};
 };
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_CONSTEXPR_BITSET_H_
+#endif /* FORTRAN_COMMON_CONSTEXPR_BITSET_H_ */
diff --git a/flang/include/flang/Decimal/decimal.h b/FortranRuntime/include/flang/Common/decimal.h
similarity index 95%
rename from flang/include/flang/Decimal/decimal.h
rename to FortranRuntime/include/flang/Common/decimal.h
index 443163d058e28b..c086f97129f6a5 100644
--- a/flang/include/flang/Decimal/decimal.h
+++ b/FortranRuntime/include/flang/Common/decimal.h
@@ -1,16 +1,15 @@
-/*===-- include/flang/Decimal/decimal.h ---------------------------*- C++ -*-===
+/*===-- include/flang/Common/decimal.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
  *
- * ===-----------------------------------------------------------------------===
- */
+ *===----------------------------------------------------------------------===*/
 
 /* C and C++ API for binary-to/from-decimal conversion package. */
 
-#ifndef FORTRAN_DECIMAL_DECIMAL_H_
-#define FORTRAN_DECIMAL_DECIMAL_H_
+#ifndef FORTRAN_COMMON_DECIMAL_H_
+#define FORTRAN_COMMON_DECIMAL_H_
 
 #include "flang/Common/api-attrs.h"
 #include <stddef.h>
@@ -137,4 +136,4 @@ RT_API_ATTRS enum NS(ConversionResultFlags) ConvertDecimalToLongDouble(
 #ifdef __cplusplus
 } // extern "C"
 #endif
-#endif
+#endif /* FORTRAN_COMMON_DECIMAL_H_ */
diff --git a/flang/include/flang/Common/enum-class.h b/FortranRuntime/include/flang/Common/enum-class.h
similarity index 98%
rename from flang/include/flang/Common/enum-class.h
rename to FortranRuntime/include/flang/Common/enum-class.h
index 41575d45091a8d..787648ffec48e8 100644
--- a/flang/include/flang/Common/enum-class.h
+++ b/FortranRuntime/include/flang/Common/enum-class.h
@@ -69,4 +69,4 @@ constexpr std::array<std::string_view, ITEMS> EnumNames(const char *p) {
   }
 
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_ENUM_CLASS_H_
+#endif /* FORTRAN_COMMON_ENUM_CLASS_H_ */
diff --git a/flang/include/flang/Common/enum-set.h b/FortranRuntime/include/flang/Common/enum-set.h
similarity index 99%
rename from flang/include/flang/Common/enum-set.h
rename to FortranRuntime/include/flang/Common/enum-set.h
index 5290b76debee88..6100fc5e2e31c5 100644
--- a/flang/include/flang/Common/enum-set.h
+++ b/FortranRuntime/include/flang/Common/enum-set.h
@@ -228,4 +228,4 @@ struct std::hash<Fortran::common::EnumSet<ENUM, values>> {
     return std::hash(x.bitset());
   }
 };
-#endif // FORTRAN_COMMON_ENUM_SET_H_
+#endif /* FORTRAN_COMMON_ENUM_SET_H_ */
diff --git a/flang/include/flang/Common/fast-int-set.h b/FortranRuntime/include/flang/Common/fast-int-set.h
similarity index 97%
rename from flang/include/flang/Common/fast-int-set.h
rename to FortranRuntime/include/flang/Common/fast-int-set.h
index d1c9c756a44a65..323ee4dc7e94d9 100644
--- a/flang/include/flang/Common/fast-int-set.h
+++ b/FortranRuntime/include/flang/Common/fast-int-set.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/fast-int-set.h --------------------*- C++ -*-===//
+//===-- include/flang/Common/fast-int-set.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.
@@ -103,4 +103,4 @@ template <int N> class FastIntSet {
   bool isFullyInitialized_{false}; // memory was cleared
 };
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_FAST_INT_SET_H_
+#endif /* FORTRAN_COMMON_FAST_INT_SET_H_ */
diff --git a/flang/include/flang/Common/float128.h b/FortranRuntime/include/flang/Common/float128.h
similarity index 96%
rename from flang/include/flang/Common/float128.h
rename to FortranRuntime/include/flang/Common/float128.h
index 2e76bc0a162e61..a7036bf679e5ae 100644
--- a/flang/include/flang/Common/float128.h
+++ b/FortranRuntime/include/flang/Common/float128.h
@@ -1,4 +1,4 @@
-/*===-- flang/Common/float128.h ----------------------------------*- C -*-===
+/*===-- include/flang/Common/float128.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/Common/format.h b/FortranRuntime/include/flang/Common/format.h
similarity index 99%
rename from flang/include/flang/Common/format.h
rename to FortranRuntime/include/flang/Common/format.h
index 138e84b72b733d..6f4dfc8d2376b7 100644
--- a/flang/include/flang/Common/format.h
+++ b/FortranRuntime/include/flang/Common/format.h
@@ -901,4 +901,4 @@ template <typename CHAR> bool FormatValidator<CHAR>::Check() {
 }
 
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_FORMAT_H_
+#endif /* FORTRAN_COMMON_FORMAT_H_ */
diff --git a/flang/include/flang/Common/idioms.h b/FortranRuntime/include/flang/Common/idioms.h
similarity index 99%
rename from flang/include/flang/Common/idioms.h
rename to FortranRuntime/include/flang/Common/idioms.h
index 99f383ec75b999..1ae0c0b35112e9 100644
--- a/flang/include/flang/Common/idioms.h
+++ b/FortranRuntime/include/flang/Common/idioms.h
@@ -150,4 +150,4 @@ template <typename A, typename... B>
 using IfNoLvalue = std::enable_if_t<(... && !std::is_lvalue_reference_v<B>), A>;
 template <typename... RVREF> using NoLvalue = IfNoLvalue<void, RVREF...>;
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_IDIOMS_H_
+#endif /* FORTRAN_COMMON_IDIOMS_H_ */
diff --git a/flang/include/flang/Common/leading-zero-bit-count.h b/FortranRuntime/include/flang/Common/leading-zero-bit-count.h
similarity index 98%
rename from flang/include/flang/Common/leading-zero-bit-count.h
rename to FortranRuntime/include/flang/Common/leading-zero-bit-count.h
index a296e0b446917f..e788bfa9bcfd08 100644
--- a/flang/include/flang/Common/leading-zero-bit-count.h
+++ b/FortranRuntime/include/flang/Common/leading-zero-bit-count.h
@@ -93,4 +93,4 @@ template <typename A> inline constexpr int BitsNeededFor(A x) {
   return 8 * sizeof x - LeadingZeroBitCount(x);
 }
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_LEADING_ZERO_BIT_COUNT_H_
+#endif /* FORTRAN_COMMON_LEADING_ZERO_BIT_COUNT_H_ */
diff --git a/flang/include/flang/Common/optional.h b/FortranRuntime/include/flang/Common/optional.h
similarity index 98%
rename from flang/include/flang/Common/optional.h
rename to FortranRuntime/include/flang/Common/optional.h
index c0f4278009f40a..c3db3b1329a2fd 100644
--- a/flang/include/flang/Common/optional.h
+++ b/FortranRuntime/include/flang/Common/optional.h
@@ -23,8 +23,8 @@
 //   * cuda:: namespace need to be forced for all std:: references.
 //
 //===----------------------------------------------------------------------===//
-#ifndef FORTRAN_COMMON_OPTIONAL_H
-#define FORTRAN_COMMON_OPTIONAL_H
+#ifndef FORTRAN_COMMON_OPTIONAL_H_
+#define FORTRAN_COMMON_OPTIONAL_H_
 
 #include "flang/Common/api-attrs.h"
 #include <optional>
@@ -240,4 +240,4 @@ using std::optional;
 
 } // namespace Fortran::common
 
-#endif // FORTRAN_COMMON_OPTIONAL_H
+#endif /* FORTRAN_COMMON_OPTIONAL_H_ */
diff --git a/flang/include/flang/Common/real.h b/FortranRuntime/include/flang/Common/real.h
similarity index 99%
rename from flang/include/flang/Common/real.h
rename to FortranRuntime/include/flang/Common/real.h
index b527deda0e3b4f..dc9a2404731e70 100644
--- a/flang/include/flang/Common/real.h
+++ b/FortranRuntime/include/flang/Common/real.h
@@ -141,4 +141,4 @@ class RealCharacteristics {
 };
 
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_REAL_H_
+#endif /* FORTRAN_COMMON_REAL_H_ */
diff --git a/flang/include/flang/Common/reference-wrapper.h b/FortranRuntime/include/flang/Common/reference-wrapper.h
similarity index 96%
rename from flang/include/flang/Common/reference-wrapper.h
rename to FortranRuntime/include/flang/Common/reference-wrapper.h
index 2983754108f95a..6822fb335f398c 100644
--- a/flang/include/flang/Common/reference-wrapper.h
+++ b/FortranRuntime/include/flang/Common/reference-wrapper.h
@@ -22,8 +22,8 @@
 //
 // clang-format on
 
-#ifndef FORTRAN_COMMON_REFERENCE_WRAPPER_H
-#define FORTRAN_COMMON_REFERENCE_WRAPPER_H
+#ifndef FORTRAN_COMMON_REFERENCE_WRAPPER_H_
+#define FORTRAN_COMMON_REFERENCE_WRAPPER_H_
 
 #include "flang/Common/api-attrs.h"
 #include <functional>
@@ -111,4 +111,4 @@ using std::reference_wrapper;
 
 } // namespace Fortran::common
 
-#endif // FORTRAN_COMMON_REFERENCE_WRAPPER_H
+#endif /* FORTRAN_COMMON_REFERENCE_WRAPPER_H_ */
diff --git a/flang/include/flang/Common/restorer.h b/FortranRuntime/include/flang/Common/restorer.h
similarity index 97%
rename from flang/include/flang/Common/restorer.h
rename to FortranRuntime/include/flang/Common/restorer.h
index 0f1bc48620d37e..a5c5ebe7344a1b 100644
--- a/flang/include/flang/Common/restorer.h
+++ b/FortranRuntime/include/flang/Common/restorer.h
@@ -18,8 +18,8 @@
 
 #ifndef FORTRAN_COMMON_RESTORER_H_
 #define FORTRAN_COMMON_RESTORER_H_
-#include "idioms.h"
 #include "flang/Common/api-attrs.h"
+#include "idioms.h"
 namespace Fortran::common {
 template <typename A> class Restorer {
 public:
@@ -53,4 +53,4 @@ RT_API_ATTRS common::IfNoLvalue<Restorer<A>, B> ScopedSet(
   return Restorer<A>{to, std::move(original)};
 }
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_RESTORER_H_
+#endif /* FORTRAN_COMMON_RESTORER_H_ */
diff --git a/flang/include/flang/Common/target-rounding.h b/FortranRuntime/include/flang/Common/target-rounding.h
similarity index 100%
rename from flang/include/flang/Common/target-rounding.h
rename to FortranRuntime/include/flang/Common/target-rounding.h
diff --git a/flang/include/flang/Common/uint128.h b/FortranRuntime/include/flang/Common/uint128.h
similarity index 99%
rename from flang/include/flang/Common/uint128.h
rename to FortranRuntime/include/flang/Common/uint128.h
index 821c8c3b08a52f..1b2ee6a2c14b87 100644
--- a/flang/include/flang/Common/uint128.h
+++ b/FortranRuntime/include/flang/Common/uint128.h
@@ -19,8 +19,8 @@
 #define AVOID_NATIVE_UINT128_T 0
 #endif
 
-#include "leading-zero-bit-count.h"
 #include "flang/Common/api-attrs.h"
+#include "leading-zero-bit-count.h"
 #include <cstdint>
 #include <type_traits>
 
@@ -303,4 +303,4 @@ template <int BITS>
 using HostSignedIntType = typename HostSignedIntTypeHelper<BITS>::type;
 
 } // namespace Fortran::common
-#endif
+#endif /* FORTRAN_COMMON_UINT128_H_ */
diff --git a/flang/include/flang/Common/variant.h b/FortranRuntime/include/flang/Common/variant.h
similarity index 89%
rename from flang/include/flang/Common/variant.h
rename to FortranRuntime/include/flang/Common/variant.h
index 1af85876afac00..ff9b1aed4eba91 100644
--- a/flang/include/flang/Common/variant.h
+++ b/FortranRuntime/include/flang/Common/variant.h
@@ -11,8 +11,8 @@
 // and the related names become available, though, they may correspond
 // to alternative definitions (e.g. from cuda::std namespace).
 
-#ifndef FORTRAN_COMMON_VARIANT_H
-#define FORTRAN_COMMON_VARIANT_H
+#ifndef FORTRAN_COMMON_VARIANT_H_
+#define FORTRAN_COMMON_VARIANT_H_
 
 #if RT_USE_LIBCUDACXX
 #include <cuda/std/variant>
@@ -27,4 +27,4 @@ using cuda::std::visit;
 #include <variant>
 #endif // !RT_USE_LIBCUDACXX
 
-#endif // FORTRAN_COMMON_VARIANT_H
+#endif /* FORTRAN_COMMON_VARIANT_H_ */
diff --git a/flang/include/flang/Common/visit.h b/FortranRuntime/include/flang/Common/visit.h
similarity index 98%
rename from flang/include/flang/Common/visit.h
rename to FortranRuntime/include/flang/Common/visit.h
index ad66297650b093..8030ac9be173c3 100644
--- a/flang/include/flang/Common/visit.h
+++ b/FortranRuntime/include/flang/Common/visit.h
@@ -21,8 +21,8 @@
 #ifndef FORTRAN_COMMON_VISIT_H_
 #define FORTRAN_COMMON_VISIT_H_
 
-#include "variant.h"
 #include "flang/Common/api-attrs.h"
+#include "variant.h"
 #include <type_traits>
 
 namespace Fortran::common {
@@ -100,4 +100,4 @@ using Fortran::common::log2visit::visit;
 #endif
 
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_VISIT_H_
+#endif /* FORTRAN_COMMON_VISIT_H_ */
diff --git a/flang/include/flang/Common/windows-include.h b/FortranRuntime/include/flang/Common/windows-include.h
similarity index 93%
rename from flang/include/flang/Common/windows-include.h
rename to FortranRuntime/include/flang/Common/windows-include.h
index 75ef4974251ff9..bee79d4fceb3ba 100644
--- a/flang/include/flang/Common/windows-include.h
+++ b/FortranRuntime/include/flang/Common/windows-include.h
@@ -22,4 +22,4 @@
 
 #endif // _WIN32
 
-#endif // FORTRAN_COMMON_WINDOWS_INCLUDE_H_
+#endif /* FORTRAN_COMMON_WINDOWS_INCLUDE_H_ */
diff --git a/flang/include/flang/Runtime/CUDA/allocator.h b/FortranRuntime/include/flang/Runtime/CUDA/allocator.h
similarity index 96%
rename from flang/include/flang/Runtime/CUDA/allocator.h
rename to FortranRuntime/include/flang/Runtime/CUDA/allocator.h
index 4527c9f18fa054..48185e8f34eaf6 100644
--- a/flang/include/flang/Runtime/CUDA/allocator.h
+++ b/FortranRuntime/include/flang/Runtime/CUDA/allocator.h
@@ -43,4 +43,4 @@ void *CUFAllocUnified(std::size_t);
 void CUFFreeUnified(void *);
 
 } // namespace Fortran::runtime::cuda
-#endif // FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
+#endif /* FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_ */
diff --git a/flang/include/flang/Runtime/CUDA/descriptor.h b/FortranRuntime/include/flang/Runtime/CUDA/descriptor.h
similarity index 95%
rename from flang/include/flang/Runtime/CUDA/descriptor.h
rename to FortranRuntime/include/flang/Runtime/CUDA/descriptor.h
index d593989420420f..68ad0987d9aecd 100644
--- a/flang/include/flang/Runtime/CUDA/descriptor.h
+++ b/FortranRuntime/include/flang/Runtime/CUDA/descriptor.h
@@ -27,4 +27,4 @@ void RTDECL(CUFFreeDesciptor)(
 
 } // extern "C"
 } // namespace Fortran::runtime::cuda
-#endif // FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_
+#endif /* FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_ */
diff --git a/flang/include/flang/Runtime/allocatable.h b/FortranRuntime/include/flang/Runtime/allocatable.h
similarity index 99%
rename from flang/include/flang/Runtime/allocatable.h
rename to FortranRuntime/include/flang/Runtime/allocatable.h
index 58061d9862095e..d7f3910074a760 100644
--- a/flang/include/flang/Runtime/allocatable.h
+++ b/FortranRuntime/include/flang/Runtime/allocatable.h
@@ -129,4 +129,4 @@ void RTDECL(AllocatableDeallocateNoFinal)(
     Descriptor &, const char *sourceFile = nullptr, int sourceLine = 0);
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_ALLOCATABLE_H_
+#endif /* FORTRAN_RUNTIME_ALLOCATABLE_H_ */
diff --git a/flang/include/flang/Runtime/allocator-registry.h b/FortranRuntime/include/flang/Runtime/allocator-registry.h
similarity index 89%
rename from flang/include/flang/Runtime/allocator-registry.h
rename to FortranRuntime/include/flang/Runtime/allocator-registry.h
index acfada506fafc6..4e7d9bcedfb375 100644
--- a/flang/include/flang/Runtime/allocator-registry.h
+++ b/FortranRuntime/include/flang/Runtime/allocator-registry.h
@@ -1,4 +1,4 @@
-//===-- runtime/allocator-registry.h ----------------------------*- C++ -*-===//
+//===-- include/flang/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 FORTRAN_RUNTIME_ALLOCATOR_H_
-#define FORTRAN_RUNTIME_ALLOCATOR_H_
+#ifndef FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_
+#define FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_
 
 #include "flang/Common/api-attrs.h"
 #include <cstdlib>
@@ -62,4 +62,4 @@ RT_OFFLOAD_VAR_GROUP_END
 
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_ALLOCATOR_H_
+#endif /* FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_ */
diff --git a/flang/include/flang/Runtime/array-constructor.h b/FortranRuntime/include/flang/Runtime/array-constructor.h
similarity index 97%
rename from flang/include/flang/Runtime/array-constructor.h
rename to FortranRuntime/include/flang/Runtime/array-constructor.h
index 46fc0418c7991e..82367756f5dc79 100644
--- a/flang/include/flang/Runtime/array-constructor.h
+++ b/FortranRuntime/include/flang/Runtime/array-constructor.h
@@ -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 FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
-#define FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
+#ifndef FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_
+#define FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_
 
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/entry-names.h"
@@ -115,4 +115,4 @@ void RTDECL(PushArrayConstructorSimpleScalar)(
     ArrayConstructorVector &vector, void *from);
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
+#endif /* FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_ */
diff --git a/flang/include/flang/Runtime/assign.h b/FortranRuntime/include/flang/Runtime/assign.h
similarity index 98%
rename from flang/include/flang/Runtime/assign.h
rename to FortranRuntime/include/flang/Runtime/assign.h
index a1cc9eaf4355f6..55d15a5c046868 100644
--- a/flang/include/flang/Runtime/assign.h
+++ b/FortranRuntime/include/flang/Runtime/assign.h
@@ -58,4 +58,4 @@ void RTDECL(AssignPolymorphic)(Descriptor &to, const Descriptor &from,
     const char *sourceFile = nullptr, int sourceLine = 0);
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_ASSIGN_H_
+#endif /* FORTRAN_RUNTIME_ASSIGN_H_ */
diff --git a/flang/include/flang/Runtime/c-or-cpp.h b/FortranRuntime/include/flang/Runtime/c-or-cpp.h
similarity index 95%
rename from flang/include/flang/Runtime/c-or-cpp.h
rename to FortranRuntime/include/flang/Runtime/c-or-cpp.h
index 8bac523907750c..3c0c0be643cbc3 100644
--- a/flang/include/flang/Runtime/c-or-cpp.h
+++ b/FortranRuntime/include/flang/Runtime/c-or-cpp.h
@@ -28,4 +28,4 @@
 #define NORETURN IF_CPLUSPLUS([[noreturn]])
 #define NO_ARGUMENTS IF_NOT_CPLUSPLUS(void)
 
-#endif // FORTRAN_RUNTIME_C_OR_CPP_H_
+#endif /* FORTRAN_RUNTIME_C_OR_CPP_H_ */
diff --git a/flang/include/flang/Runtime/character.h b/FortranRuntime/include/flang/Runtime/character.h
similarity index 99%
rename from flang/include/flang/Runtime/character.h
rename to FortranRuntime/include/flang/Runtime/character.h
index dd47686fe858fd..a842c30cd8120c 100644
--- a/flang/include/flang/Runtime/character.h
+++ b/FortranRuntime/include/flang/Runtime/character.h
@@ -129,4 +129,4 @@ void RTDECL(Verify)(Descriptor &result, const Descriptor &string,
     const char *sourceFile = nullptr, int sourceLine = 0);
 }
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_CHARACTER_H_
+#endif /* FORTRAN_RUNTIME_CHARACTER_H_ */
diff --git a/flang/include/flang/Runtime/command.h b/FortranRuntime/include/flang/Runtime/command.h
similarity index 98%
rename from flang/include/flang/Runtime/command.h
rename to FortranRuntime/include/flang/Runtime/command.h
index 7ab3f6442dcf92..2bbdfca7631163 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/FortranRuntime/include/flang/Runtime/command.h
@@ -62,4 +62,4 @@ std::int32_t RTNAME(GetCwd)(
 }
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_COMMAND_H_
+#endif /* FORTRAN_RUNTIME_COMMAND_H_ */
diff --git a/flang/include/flang/Runtime/cpp-type.h b/FortranRuntime/include/flang/Runtime/cpp-type.h
similarity index 98%
rename from flang/include/flang/Runtime/cpp-type.h
rename to FortranRuntime/include/flang/Runtime/cpp-type.h
index 27b43de7d0f0f6..7de1ea4f45f224 100644
--- a/flang/include/flang/Runtime/cpp-type.h
+++ b/FortranRuntime/include/flang/Runtime/cpp-type.h
@@ -110,4 +110,4 @@ template <> struct CppTypeForHelper<TypeCategory::Logical, 1> {
 };
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_CPP_TYPE_H_
+#endif /* FORTRAN_RUNTIME_CPP_TYPE_H_ */
diff --git a/flang/include/flang/Runtime/derived-api.h b/FortranRuntime/include/flang/Runtime/derived-api.h
similarity index 98%
rename from flang/include/flang/Runtime/derived-api.h
rename to FortranRuntime/include/flang/Runtime/derived-api.h
index 79aa7d82de8819..ca1681e974051c 100644
--- a/flang/include/flang/Runtime/derived-api.h
+++ b/FortranRuntime/include/flang/Runtime/derived-api.h
@@ -63,4 +63,4 @@ bool RTDECL(ExtendsTypeOf)(const Descriptor &, const Descriptor &);
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_DERIVED_API_H_
+#endif /* FORTRAN_RUNTIME_DERIVED_API_H_ */
diff --git a/flang/include/flang/Runtime/descriptor.h b/FortranRuntime/include/flang/Runtime/descriptor.h
similarity index 99%
rename from flang/include/flang/Runtime/descriptor.h
rename to FortranRuntime/include/flang/Runtime/descriptor.h
index 030d0c1031fbaa..867f4d4ee29ac0 100644
--- a/flang/include/flang/Runtime/descriptor.h
+++ b/FortranRuntime/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/memory.h"
 #include "flang/Runtime/type-code.h"
 #include <algorithm>
@@ -492,4 +492,4 @@ class alignas(Descriptor) StaticDescriptor {
 };
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_DESCRIPTOR_H_
+#endif /* FORTRAN_RUNTIME_DESCRIPTOR_H_ */
diff --git a/flang/include/flang/Runtime/entry-names.h b/FortranRuntime/include/flang/Runtime/entry-names.h
similarity index 89%
rename from flang/include/flang/Runtime/entry-names.h
rename to FortranRuntime/include/flang/Runtime/entry-names.h
index 68582b92b54941..25134771bf9185 100644
--- a/flang/include/flang/Runtime/entry-names.h
+++ b/FortranRuntime/include/flang/Runtime/entry-names.h
@@ -1,11 +1,10 @@
-/*===-- include/flang/Runtime/entry-names.h -------------------------*- C -*-=//
+/*===-- include/flang/Runtime/entry-names.h -------------------------*- C -*-===
  *
  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  * See https://llvm.org/LICENSE.txt for license information.
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  *
- *===------------------------------------------------------------------------===
- */
+ *===----------------------------------------------------------------------===*/
 
 /* Defines the macro RTNAME(n) which decorates the external name of a runtime
  * library function or object with extra characters so that it
@@ -16,8 +15,8 @@
  * The value of REVISION should not be changed until/unless the API to the
  * runtime library must change in some way that breaks backward compatibility.
  */
-#ifndef FORTRAN_RUNTIME_ENTRY_NAMES_H
-#define FORTRAN_RUNTIME_ENTRY_NAMES_H
+#ifndef FORTRAN_RUNTIME_ENTRY_NAMES_H_
+#define FORTRAN_RUNTIME_ENTRY_NAMES_H_
 
 #include "flang/Common/api-attrs.h"
 
@@ -41,4 +40,4 @@
 #define RTNAME_STRING(name) RTNAME_STRINGIFY(RTNAME(name))
 #endif
 
-#endif /* !FORTRAN_RUNTIME_ENTRY_NAMES_H */
+#endif /* FORTRAN_RUNTIME_ENTRY_NAMES_H_ */
diff --git a/flang/include/flang/Runtime/exceptions.h b/FortranRuntime/include/flang/Runtime/exceptions.h
similarity index 86%
rename from flang/include/flang/Runtime/exceptions.h
rename to FortranRuntime/include/flang/Runtime/exceptions.h
index 1ab22da103a50f..f2c67325b34d92 100644
--- a/flang/include/flang/Runtime/exceptions.h
+++ b/FortranRuntime/include/flang/Runtime/exceptions.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/exceptions.h ----------------*- C++ -*-===//
+//===-- include/flang/Runtime/exceptions.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.
@@ -26,4 +26,4 @@ std::uint32_t RTNAME(MapException)(std::uint32_t excepts);
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_EXCEPTIONS_H_
+#endif /* FORTRAN_RUNTIME_EXCEPTIONS_H_ */
diff --git a/flang/include/flang/Runtime/execute.h b/FortranRuntime/include/flang/Runtime/execute.h
similarity index 89%
rename from flang/include/flang/Runtime/execute.h
rename to FortranRuntime/include/flang/Runtime/execute.h
index ca137b9d1823c4..d1958a82594ffd 100644
--- a/flang/include/flang/Runtime/execute.h
+++ b/FortranRuntime/include/flang/Runtime/execute.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/command.h -------------------------*- C++ -*-===//
+//===-- include/flang/Runtime/execute.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.
@@ -26,4 +26,4 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait = true,
 }
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_EXECUTE_H_
+#endif /* FORTRAN_RUNTIME_EXECUTE_H_ */
diff --git a/flang/include/flang/Runtime/extensions.h b/FortranRuntime/include/flang/Runtime/extensions.h
similarity index 97%
rename from flang/include/flang/Runtime/extensions.h
rename to FortranRuntime/include/flang/Runtime/extensions.h
index fef651f3b2eedb..f46ccdd7d9528d 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/FortranRuntime/include/flang/Runtime/extensions.h
@@ -52,4 +52,4 @@ std::int64_t FORTRAN_PROCEDURE_NAME(access)(const char *name,
 #endif
 
 } // extern "C"
-#endif // FORTRAN_RUNTIME_EXTENSIONS_H_
+#endif /* FORTRAN_RUNTIME_EXTENSIONS_H_ */
diff --git a/flang/include/flang/Runtime/freestanding-tools.h b/FortranRuntime/include/flang/Runtime/freestanding-tools.h
similarity index 99%
rename from flang/include/flang/Runtime/freestanding-tools.h
rename to FortranRuntime/include/flang/Runtime/freestanding-tools.h
index e94cb0a6c938cd..8aeef54ba0af3d 100644
--- a/flang/include/flang/Runtime/freestanding-tools.h
+++ b/FortranRuntime/include/flang/Runtime/freestanding-tools.h
@@ -215,4 +215,4 @@ using std::toupper;
 #endif // !STD_TOUPPER_UNSUPPORTED
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_FREESTANDING_TOOLS_H_
+#endif /* FORTRAN_RUNTIME_FREESTANDING_TOOLS_H_ */
diff --git a/flang/include/flang/Runtime/inquiry.h b/FortranRuntime/include/flang/Runtime/inquiry.h
similarity index 91%
rename from flang/include/flang/Runtime/inquiry.h
rename to FortranRuntime/include/flang/Runtime/inquiry.h
index c7a7487f1a1b18..83b07cf2f31a47 100644
--- a/flang/include/flang/Runtime/inquiry.h
+++ b/FortranRuntime/include/flang/Runtime/inquiry.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/inquiry.h ----------------*- C++ -*-===//
+//===-- include/flang/Runtime/inquiry.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.
@@ -40,4 +40,4 @@ void RTDECL(Ubound)(void *result, const Descriptor &array, int kind,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_INQUIRY_H_
+#endif /* FORTRAN_RUNTIME_INQUIRY_H_ */
diff --git a/flang/include/flang/Runtime/io-api.h b/FortranRuntime/include/flang/Runtime/io-api.h
similarity index 99%
rename from flang/include/flang/Runtime/io-api.h
rename to FortranRuntime/include/flang/Runtime/io-api.h
index 328afc715a3f1e..367146a4925c53 100644
--- a/flang/include/flang/Runtime/io-api.h
+++ b/FortranRuntime/include/flang/Runtime/io-api.h
@@ -369,4 +369,4 @@ enum Iostat IODECL(EndIoStatement)(Cookie);
 
 } // extern "C"
 } // namespace Fortran::runtime::io
-#endif
+#endif /* FORTRAN_RUNTIME_IO_API_H_ */
diff --git a/flang/include/flang/Runtime/iostat.h b/FortranRuntime/include/flang/Runtime/iostat.h
similarity index 98%
rename from flang/include/flang/Runtime/iostat.h
rename to FortranRuntime/include/flang/Runtime/iostat.h
index 6ce7c82b424eb7..a5a2a560f05f8d 100644
--- a/flang/include/flang/Runtime/iostat.h
+++ b/FortranRuntime/include/flang/Runtime/iostat.h
@@ -92,4 +92,4 @@ enum Iostat {
 RT_API_ATTRS const char *IostatErrorString(int);
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IOSTAT_H_
+#endif /* FORTRAN_RUNTIME_IOSTAT_H_ */
diff --git a/flang/include/flang/Runtime/magic-numbers.h b/FortranRuntime/include/flang/Runtime/magic-numbers.h
similarity index 98%
rename from flang/include/flang/Runtime/magic-numbers.h
rename to FortranRuntime/include/flang/Runtime/magic-numbers.h
index bab0e9ae05299a..931df690766219 100644
--- a/flang/include/flang/Runtime/magic-numbers.h
+++ b/FortranRuntime/include/flang/Runtime/magic-numbers.h
@@ -1,10 +1,10 @@
-#if 0 /*===-- include/flang/Runtime/magic-numbers.h -----------------------===*/
-/*
+#if 0 /*===-- include/flang/Runtime/magic-numbers.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
  *
- *===----------------------------------------------------------------------===*/
+/*===----------------------------------------------------------------------===*/
 #endif
 #if 0
 This header can be included into both Fortran and C.
diff --git a/flang/include/flang/Runtime/main.h b/FortranRuntime/include/flang/Runtime/main.h
similarity index 95%
rename from flang/include/flang/Runtime/main.h
rename to FortranRuntime/include/flang/Runtime/main.h
index 88232ea64fa6ab..98fcf1250d0ad6 100644
--- a/flang/include/flang/Runtime/main.h
+++ b/FortranRuntime/include/flang/Runtime/main.h
@@ -20,4 +20,4 @@ void RTNAME(ProgramStart)(
 void RTNAME(ByteswapOption)(void); // -byteswapio
 FORTRAN_EXTERN_C_END
 
-#endif // FORTRAN_RUNTIME_MAIN_H_
+#endif /* FORTRAN_RUNTIME_MAIN_H_ */
diff --git a/flang/include/flang/Runtime/matmul-instances.inc b/FortranRuntime/include/flang/Runtime/matmul-instances.inc
similarity index 100%
rename from flang/include/flang/Runtime/matmul-instances.inc
rename to FortranRuntime/include/flang/Runtime/matmul-instances.inc
diff --git a/flang/include/flang/Runtime/matmul-transpose.h b/FortranRuntime/include/flang/Runtime/matmul-transpose.h
similarity index 97%
rename from flang/include/flang/Runtime/matmul-transpose.h
rename to FortranRuntime/include/flang/Runtime/matmul-transpose.h
index 2d79ca10e08958..077277fae2da86 100644
--- a/flang/include/flang/Runtime/matmul-transpose.h
+++ b/FortranRuntime/include/flang/Runtime/matmul-transpose.h
@@ -46,4 +46,4 @@ void RTDECL(MatmulTransposeDirect)(const Descriptor &, const Descriptor &,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_MATMUL_TRANSPOSE_H_
+#endif /* FORTRAN_RUNTIME_MATMUL_TRANSPOSE_H_ */
diff --git a/flang/include/flang/Runtime/matmul.h b/FortranRuntime/include/flang/Runtime/matmul.h
similarity index 97%
rename from flang/include/flang/Runtime/matmul.h
rename to FortranRuntime/include/flang/Runtime/matmul.h
index a72d4a06ee4594..cd375ac43d77f2 100644
--- a/flang/include/flang/Runtime/matmul.h
+++ b/FortranRuntime/include/flang/Runtime/matmul.h
@@ -45,4 +45,4 @@ void RTDECL(MatmulDirect)(const Descriptor &, const Descriptor &,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_MATMUL_H_
+#endif /* FORTRAN_RUNTIME_MATMUL_H_ */
diff --git a/flang/include/flang/Runtime/memory.h b/FortranRuntime/include/flang/Runtime/memory.h
similarity index 99%
rename from flang/include/flang/Runtime/memory.h
rename to FortranRuntime/include/flang/Runtime/memory.h
index 98412a989f890b..84af4d7189c074 100644
--- a/flang/include/flang/Runtime/memory.h
+++ b/FortranRuntime/include/flang/Runtime/memory.h
@@ -170,4 +170,4 @@ template <typename A> struct Allocator {
 };
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_MEMORY_H_
+#endif /* FORTRAN_RUNTIME_MEMORY_H_ */
diff --git a/flang/include/flang/Runtime/misc-intrinsic.h b/FortranRuntime/include/flang/Runtime/misc-intrinsic.h
similarity index 95%
rename from flang/include/flang/Runtime/misc-intrinsic.h
rename to FortranRuntime/include/flang/Runtime/misc-intrinsic.h
index 3fb3aaed49c0fb..1d4163c2e1e751 100644
--- a/flang/include/flang/Runtime/misc-intrinsic.h
+++ b/FortranRuntime/include/flang/Runtime/misc-intrinsic.h
@@ -28,4 +28,4 @@ void RTDECL(TransferSize)(Descriptor &result, const Descriptor &source,
     std::int64_t size);
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_MISC_INTRINSIC_H_
+#endif /* FORTRAN_RUNTIME_MISC_INTRINSIC_H_ */
diff --git a/flang/include/flang/Runtime/numeric.h b/FortranRuntime/include/flang/Runtime/numeric.h
similarity index 99%
rename from flang/include/flang/Runtime/numeric.h
rename to FortranRuntime/include/flang/Runtime/numeric.h
index 84a5a7cd7a361c..5fbab2e069b739 100644
--- a/flang/include/flang/Runtime/numeric.h
+++ b/FortranRuntime/include/flang/Runtime/numeric.h
@@ -455,4 +455,4 @@ CppTypeFor<TypeCategory::Real, 16> RTDECL(FPow16k)(
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_NUMERIC_H_
+#endif /* FORTRAN_RUNTIME_NUMERIC_H_ */
diff --git a/flang/include/flang/Runtime/pointer.h b/FortranRuntime/include/flang/Runtime/pointer.h
similarity index 99%
rename from flang/include/flang/Runtime/pointer.h
rename to FortranRuntime/include/flang/Runtime/pointer.h
index 704144f08114f2..b7322ad92bd583 100644
--- a/flang/include/flang/Runtime/pointer.h
+++ b/FortranRuntime/include/flang/Runtime/pointer.h
@@ -122,4 +122,4 @@ RT_API_ATTRS bool ValidatePointerPayload(const ISO::CFI_cdesc_t &);
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_POINTER_H_
+#endif /* FORTRAN_RUNTIME_POINTER_H_ */
diff --git a/flang/include/flang/Runtime/ragged.h b/FortranRuntime/include/flang/Runtime/ragged.h
similarity index 96%
rename from flang/include/flang/Runtime/ragged.h
rename to FortranRuntime/include/flang/Runtime/ragged.h
index f52a619c55b43e..8574bc1fa110c8 100644
--- a/flang/include/flang/Runtime/ragged.h
+++ b/FortranRuntime/include/flang/Runtime/ragged.h
@@ -1,4 +1,4 @@
-//===-- Runtime/ragged.h ----------------------------------------*- C++ -*-===//
+//===-- include/flang/Runtime/ragged.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.
@@ -57,4 +57,4 @@ void RTDECL(RaggedArrayDeallocate)(void *raggedArrayHeader);
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_RAGGED_H_
+#endif /* FORTRAN_RUNTIME_RAGGED_H_ */
diff --git a/flang/include/flang/Runtime/random.h b/FortranRuntime/include/flang/Runtime/random.h
similarity index 93%
rename from flang/include/flang/Runtime/random.h
rename to FortranRuntime/include/flang/Runtime/random.h
index 269297dff47dba..bb6dcb3873f21d 100644
--- a/flang/include/flang/Runtime/random.h
+++ b/FortranRuntime/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/reduce.h b/FortranRuntime/include/flang/Runtime/reduce.h
similarity index 99%
rename from flang/include/flang/Runtime/reduce.h
rename to FortranRuntime/include/flang/Runtime/reduce.h
index 60f54c393b4bbd..ae2828f04bf7c0 100644
--- a/flang/include/flang/Runtime/reduce.h
+++ b/FortranRuntime/include/flang/Runtime/reduce.h
@@ -435,4 +435,4 @@ void RTDECL(ReduceDerivedTypeDim)(Descriptor &result, const Descriptor &array,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_REDUCE_H_
+#endif /* FORTRAN_RUNTIME_REDUCE_H_ */
diff --git a/flang/include/flang/Runtime/reduction.h b/FortranRuntime/include/flang/Runtime/reduction.h
similarity index 99%
rename from flang/include/flang/Runtime/reduction.h
rename to FortranRuntime/include/flang/Runtime/reduction.h
index 97986c12e8a10e..e00593fbc9f75e 100644
--- a/flang/include/flang/Runtime/reduction.h
+++ b/FortranRuntime/include/flang/Runtime/reduction.h
@@ -444,4 +444,4 @@ bool RTDECL(DotProductLogical)(const Descriptor &, const Descriptor &,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_REDUCTION_H_
+#endif /* FORTRAN_RUNTIME_REDUCTION_H_ */
diff --git a/flang/include/flang/Runtime/stop.h b/FortranRuntime/include/flang/Runtime/stop.h
similarity index 97%
rename from flang/include/flang/Runtime/stop.h
rename to FortranRuntime/include/flang/Runtime/stop.h
index f7c4ffe7403e8e..9ba41343c6f964 100644
--- a/flang/include/flang/Runtime/stop.h
+++ b/FortranRuntime/include/flang/Runtime/stop.h
@@ -37,4 +37,4 @@ NORETURN void RTNAME(ReportFatalUserError)(
 
 FORTRAN_EXTERN_C_END
 
-#endif // FORTRAN_RUNTIME_STOP_H_
+#endif /* FORTRAN_RUNTIME_STOP_H_ */
diff --git a/flang/include/flang/Runtime/support.h b/FortranRuntime/include/flang/Runtime/support.h
similarity index 94%
rename from flang/include/flang/Runtime/support.h
rename to FortranRuntime/include/flang/Runtime/support.h
index ba9c2598bb0ddd..9c9b067a18f2e4 100644
--- a/flang/include/flang/Runtime/support.h
+++ b/FortranRuntime/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>
@@ -47,4 +47,4 @@ void RTDECL(CopyAndUpdateDescriptor)(Descriptor &to, const Descriptor &from,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_SUPPORT_H_
+#endif /* FORTRAN_RUNTIME_SUPPORT_H_ */
diff --git a/flang/include/flang/Runtime/temporary-stack.h b/FortranRuntime/include/flang/Runtime/temporary-stack.h
similarity index 98%
rename from flang/include/flang/Runtime/temporary-stack.h
rename to FortranRuntime/include/flang/Runtime/temporary-stack.h
index 3c1a4ea11a4352..f83fab7b0ac811 100644
--- a/flang/include/flang/Runtime/temporary-stack.h
+++ b/FortranRuntime/include/flang/Runtime/temporary-stack.h
@@ -64,4 +64,4 @@ void RTNAME(DestroyDescriptorStack)(void *opaquePtr);
 } // extern "C"
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_TEMPORARY_STACK_H_
+#endif /* FORTRAN_RUNTIME_TEMPORARY_STACK_H_ */
diff --git a/flang/include/flang/Runtime/time-intrinsic.h b/FortranRuntime/include/flang/Runtime/time-intrinsic.h
similarity index 97%
rename from flang/include/flang/Runtime/time-intrinsic.h
rename to FortranRuntime/include/flang/Runtime/time-intrinsic.h
index 80490a17e45597..0e63fc6a4647a4 100644
--- a/flang/include/flang/Runtime/time-intrinsic.h
+++ b/FortranRuntime/include/flang/Runtime/time-intrinsic.h
@@ -48,4 +48,4 @@ void RTNAME(Etime)(const Descriptor *values, const Descriptor *time,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_TIME_INTRINSIC_H_
+#endif /* FORTRAN_RUNTIME_TIME_INTRINSIC_H_ */
diff --git a/flang/include/flang/Runtime/transformational.h b/FortranRuntime/include/flang/Runtime/transformational.h
similarity index 99%
rename from flang/include/flang/Runtime/transformational.h
rename to FortranRuntime/include/flang/Runtime/transformational.h
index a39b872f376a69..266dd9d7aebc24 100644
--- a/flang/include/flang/Runtime/transformational.h
+++ b/FortranRuntime/include/flang/Runtime/transformational.h
@@ -154,4 +154,4 @@ void RTDECL(Unpack)(Descriptor &result, const Descriptor &vector,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_TRANSFORMATIONAL_H_
+#endif /* FORTRAN_RUNTIME_TRANSFORMATIONAL_H_ */
diff --git a/flang/include/flang/Runtime/type-code.h b/FortranRuntime/include/flang/Runtime/type-code.h
similarity index 96%
rename from flang/include/flang/Runtime/type-code.h
rename to FortranRuntime/include/flang/Runtime/type-code.h
index dd3a9f2690ee74..ec359f25dbdd12 100644
--- a/flang/include/flang/Runtime/type-code.h
+++ b/FortranRuntime/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 {
@@ -75,4 +75,4 @@ class TypeCode {
   ISO::CFI_type_t raw_{CFI_type_other};
 };
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_TYPE_CODE_H_
+#endif /* FORTRAN_RUNTIME_TYPE_CODE_H_ */
diff --git a/flang/unittests/Evaluate/fp-testing.h b/FortranRuntime/include/flang/Testing/fp-testing.h
similarity index 54%
rename from flang/unittests/Evaluate/fp-testing.h
rename to FortranRuntime/include/flang/Testing/fp-testing.h
index 9091963a99b32d..e223d2ef7d1b8b 100644
--- a/flang/unittests/Evaluate/fp-testing.h
+++ b/FortranRuntime/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/FortranRuntime/include/flang/Testing/testing.h
similarity index 74%
rename from flang/unittests/Evaluate/testing.h
rename to FortranRuntime/include/flang/Testing/testing.h
index 422e2853c05bc6..404650c9a89f2c 100644
--- a/flang/unittests/Evaluate/testing.h
+++ b/FortranRuntime/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/Decimal/big-radix-floating-point.h b/FortranRuntime/lib/Common/big-radix-floating-point.h
similarity index 97%
rename from flang/lib/Decimal/big-radix-floating-point.h
rename to FortranRuntime/lib/Common/big-radix-floating-point.h
index f9afebf5b3d703..6d247f3796eea5 100644
--- a/flang/lib/Decimal/big-radix-floating-point.h
+++ b/FortranRuntime/lib/Common/big-radix-floating-point.h
@@ -1,4 +1,4 @@
-//===-- lib/Decimal/big-radix-floating-point.h ------------------*- C++ -*-===//
+//===-- lib/Common/big-radix-floating-point.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_DECIMAL_BIG_RADIX_FLOATING_POINT_H_
-#define FORTRAN_DECIMAL_BIG_RADIX_FLOATING_POINT_H_
+#ifndef FORTRAN_COMMON_BIG_RADIX_FLOATING_POINT_H_
+#define FORTRAN_COMMON_BIG_RADIX_FLOATING_POINT_H_
 
 // This is a helper class for use in floating-point conversions between
 // binary and decimal representations.  It holds a multiple-precision
@@ -21,11 +21,11 @@
 // for conversions between binary and decimal representations; it is not
 // a general-purpose facility.
 
+#include "flang/Common/binary-floating-point.h"
 #include "flang/Common/bit-population-count.h"
+#include "flang/Common/decimal.h"
 #include "flang/Common/leading-zero-bit-count.h"
 #include "flang/Common/uint128.h"
-#include "flang/Decimal/binary-floating-point.h"
-#include "flang/Decimal/decimal.h"
 #include <cinttypes>
 #include <limits>
 #include <type_traits>
@@ -393,4 +393,4 @@ template <int PREC, int LOG10RADIX = 16> class BigRadixFloatingPointNumber {
   enum FortranRounding rounding_ { RoundNearest };
 };
 } // namespace Fortran::decimal
-#endif
+#endif /* FORTRAN_COMMON_BIG_RADIX_FLOATING_POINT_H_ */
diff --git a/flang/lib/Decimal/binary-to-decimal.cpp b/FortranRuntime/lib/Common/binary-to-decimal.cpp
similarity index 99%
rename from flang/lib/Decimal/binary-to-decimal.cpp
rename to FortranRuntime/lib/Common/binary-to-decimal.cpp
index b64865e95df24d..fb2caefdae8fa1 100644
--- a/flang/lib/Decimal/binary-to-decimal.cpp
+++ b/FortranRuntime/lib/Common/binary-to-decimal.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Decimal/binary-to-decimal.cpp ---------------------------------===//
+//===-- lib/Common/binary-to-decimal.cpp ------------------------*- 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 "big-radix-floating-point.h"
-#include "flang/Decimal/decimal.h"
+#include "flang/Common/decimal.h"
 #include <cassert>
 #include <cfloat>
 #include <string>
diff --git a/flang/lib/Decimal/decimal-to-binary.cpp b/FortranRuntime/lib/Common/decimal-to-binary.cpp
similarity index 99%
rename from flang/lib/Decimal/decimal-to-binary.cpp
rename to FortranRuntime/lib/Common/decimal-to-binary.cpp
index 94c51774237399..cbf1664e9c240d 100644
--- a/flang/lib/Decimal/decimal-to-binary.cpp
+++ b/FortranRuntime/lib/Common/decimal-to-binary.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Decimal/decimal-to-binary.cpp ---------------------------------===//
+//===-- lib/Common/decimal-to-binary.cpp ------------------------*- 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 "big-radix-floating-point.h"
+#include "flang/Common/binary-floating-point.h"
 #include "flang/Common/bit-population-count.h"
+#include "flang/Common/decimal.h"
 #include "flang/Common/leading-zero-bit-count.h"
-#include "flang/Decimal/binary-floating-point.h"
-#include "flang/Decimal/decimal.h"
 #include "flang/Runtime/freestanding-tools.h"
 #include <cinttypes>
 #include <cstring>
diff --git a/flang/runtime/CMakeLists.txt b/FortranRuntime/lib/Runtime/CMakeLists.txt
similarity index 98%
rename from flang/runtime/CMakeLists.txt
rename to FortranRuntime/lib/Runtime/CMakeLists.txt
index 4537b2d059d65b..8ecb08b4ebb8ae 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/FortranRuntime/lib/Runtime/CMakeLists.txt
@@ -45,7 +45,8 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
     add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
   endif ()
   include_directories(BEFORE
-    ${FLANG_SOURCE_DIR}/include)
+    ${FLANG_SOURCE_DIR}/include
+    ${FLANG_SOURCE_DIR}/../FortranRuntime/include)
 
   # The out of tree builds of the compiler and the Fortran runtime
   # must use the same setting of FLANG_RUNTIME_F128_MATH_LIB
@@ -89,7 +90,7 @@ else()
   set(NO_LTO_FLAGS "")
 endif()
 
-configure_file(config.h.cmake config.h)
+configure_file(../../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
diff --git a/flang/runtime/CUDA/CMakeLists.txt b/FortranRuntime/lib/Runtime/CUDA/CMakeLists.txt
similarity index 100%
rename from flang/runtime/CUDA/CMakeLists.txt
rename to FortranRuntime/lib/Runtime/CUDA/CMakeLists.txt
diff --git a/flang/runtime/CUDA/allocator.cpp b/FortranRuntime/lib/Runtime/CUDA/allocator.cpp
similarity index 94%
rename from flang/runtime/CUDA/allocator.cpp
rename to FortranRuntime/lib/Runtime/CUDA/allocator.cpp
index d4a473d58e86cd..2efd6bf0a95249 100644
--- a/flang/runtime/CUDA/allocator.cpp
+++ b/FortranRuntime/lib/Runtime/CUDA/allocator.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/allocator.cpp ----------------------------------------===//
+//===-- lib/Runtime/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.
@@ -11,9 +11,9 @@
 #include "../stat.h"
 #include "../terminator.h"
 #include "../type-info.h"
-#include "flang/Common/Fortran.h"
 #include "flang/ISO_Fortran_binding_wrapper.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/FortranRuntime/lib/Runtime/CUDA/descriptor.cpp
similarity index 91%
rename from flang/runtime/CUDA/descriptor.cpp
rename to FortranRuntime/lib/Runtime/CUDA/descriptor.cpp
index 1031b1e601b646..9664fea4ebc78a 100644
--- a/flang/runtime/CUDA/descriptor.cpp
+++ b/FortranRuntime/lib/Runtime/CUDA/descriptor.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/descriptor.cpp ---------------------------------------===//
+//===-- lib/Runtime/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.
diff --git a/flang/runtime/Float128Math/CMakeLists.txt b/FortranRuntime/lib/Runtime/Float128Math/CMakeLists.txt
similarity index 100%
rename from flang/runtime/Float128Math/CMakeLists.txt
rename to FortranRuntime/lib/Runtime/Float128Math/CMakeLists.txt
diff --git a/flang/runtime/Float128Math/acos.cpp b/FortranRuntime/lib/Runtime/Float128Math/acos.cpp
similarity index 87%
rename from flang/runtime/Float128Math/acos.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/acos.cpp
index 14ff6944856844..7b15e4a0bfd3ae 100644
--- a/flang/runtime/Float128Math/acos.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/acos.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/acos.cpp -------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/acosh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/acosh.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/acosh.cpp
index 9d70804e44a470..c873259b4545b8 100644
--- a/flang/runtime/Float128Math/acosh.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/acosh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/acosh.cpp ------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/asin.cpp
similarity index 87%
rename from flang/runtime/Float128Math/asin.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/asin.cpp
index 6781b23f0363db..8866d51430197a 100644
--- a/flang/runtime/Float128Math/asin.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/asin.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/asin.cpp -------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/asinh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/asinh.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/asinh.cpp
index 1310bc61c1de0f..288193001ce1da 100644
--- a/flang/runtime/Float128Math/asinh.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/asinh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/asinh.cpp ------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/atan.cpp
similarity index 87%
rename from flang/runtime/Float128Math/atan.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/atan.cpp
index f01382df90c0ee..390c080b4d501b 100644
--- a/flang/runtime/Float128Math/atan.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/atan.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/atan.cpp -------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/atan2.cpp
similarity index 88%
rename from flang/runtime/Float128Math/atan2.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/atan2.cpp
index dd646b0452b115..3c206b75704431 100644
--- a/flang/runtime/Float128Math/atan2.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/atan2.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/atan2.cpp ------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/atanh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/atanh.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/atanh.cpp
index 5fc5ba5debc81a..77ceb188f04e42 100644
--- a/flang/runtime/Float128Math/atanh.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/atanh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/atanh.cpp ------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/ceil.cpp
similarity index 87%
rename from flang/runtime/Float128Math/ceil.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/ceil.cpp
index ed4d164a62bedc..46bc253bd0922d 100644
--- a/flang/runtime/Float128Math/ceil.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/ceil.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/ceil.cpp -------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/complex-math.c
similarity index 92%
rename from flang/runtime/Float128Math/complex-math.c
rename to FortranRuntime/lib/Runtime/Float128Math/complex-math.c
index d0180c63a0d7bf..f34ef7da76e599 100644
--- a/flang/runtime/Float128Math/complex-math.c
+++ b/FortranRuntime/lib/Runtime/Float128Math/complex-math.c
@@ -1,11 +1,10 @@
-/*===-- runtime/Float128Math/complex-math.c -------------------------*- C -*-===
+/*===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/complex-math.h
similarity index 96%
rename from flang/runtime/Float128Math/complex-math.h
rename to FortranRuntime/lib/Runtime/Float128Math/complex-math.h
index 81dd53a175d1aa..6f5c7954bab035 100644
--- a/flang/runtime/Float128Math/complex-math.h
+++ b/FortranRuntime/lib/Runtime/Float128Math/complex-math.h
@@ -1,4 +1,4 @@
-/*===-- runtime/Float128Math/complex-math.h -------------------------*- C -*-===
+/*===-- lib/Runtime/Float128Math/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.
diff --git a/flang/runtime/Float128Math/cos.cpp b/FortranRuntime/lib/Runtime/Float128Math/cos.cpp
similarity index 87%
rename from flang/runtime/Float128Math/cos.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/cos.cpp
index b93c92f275f791..8ce47151e2914b 100644
--- a/flang/runtime/Float128Math/cos.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/cos.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/cos.cpp --------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/cosh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/cosh.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/cosh.cpp
index a3662a826dcb1c..f1ec45bcfb479d 100644
--- a/flang/runtime/Float128Math/cosh.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/cosh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/cosh.cpp -------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/erf.cpp
similarity index 87%
rename from flang/runtime/Float128Math/erf.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/erf.cpp
index 631f71c76effe7..010088467794d1 100644
--- a/flang/runtime/Float128Math/erf.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/erf.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/erf.cpp --------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/erfc.cpp
similarity index 87%
rename from flang/runtime/Float128Math/erfc.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/erfc.cpp
index ea3cd646d8c4ba..b226f8d2dc378b 100644
--- a/flang/runtime/Float128Math/erfc.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/erfc.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/erfc.cpp -------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/exp.cpp
similarity index 87%
rename from flang/runtime/Float128Math/exp.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/exp.cpp
index b1161b0f29294c..e22f9df3579e96 100644
--- a/flang/runtime/Float128Math/exp.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/exp.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/exp.cpp --------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/exponent.cpp
similarity index 90%
rename from flang/runtime/Float128Math/exponent.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/exponent.cpp
index 1be1dd0d0ac8b8..f07bf30bd1096f 100644
--- a/flang/runtime/Float128Math/exponent.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/exponent.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/exponent.cpp ---------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/floor.cpp
similarity index 87%
rename from flang/runtime/Float128Math/floor.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/floor.cpp
index 78a94984cac8a3..8744e6e2fec63c 100644
--- a/flang/runtime/Float128Math/floor.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/floor.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/floor.cpp ------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/fma.cpp
similarity index 89%
rename from flang/runtime/Float128Math/fma.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/fma.cpp
index ec67e8e6fba22b..198fec5d4bc356 100644
--- a/flang/runtime/Float128Math/fma.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/fma.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/fma.cpp --------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/fraction.cpp
similarity index 87%
rename from flang/runtime/Float128Math/fraction.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/fraction.cpp
index 8c9889b7f6871e..d4749bf3eb7e0e 100644
--- a/flang/runtime/Float128Math/fraction.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/fraction.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/fraction.cpp ---------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/hypot.cpp
similarity index 88%
rename from flang/runtime/Float128Math/hypot.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/hypot.cpp
index b4fa1d66bcfa6a..6542bf505060df 100644
--- a/flang/runtime/Float128Math/hypot.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/hypot.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/hypot.cpp ------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/j0.cpp
similarity index 87%
rename from flang/runtime/Float128Math/j0.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/j0.cpp
index 9390a7eeb3c605..27e4338cdfc2b0 100644
--- a/flang/runtime/Float128Math/j0.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/j0.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/j0.cpp ---------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/j1.cpp
similarity index 87%
rename from flang/runtime/Float128Math/j1.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/j1.cpp
index c54927123388c6..d3f897827f9f67 100644
--- a/flang/runtime/Float128Math/j1.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/j1.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/j1.cpp ---------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/jn.cpp
similarity index 87%
rename from flang/runtime/Float128Math/jn.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/jn.cpp
index 15afd83400c320..681bb5b1ff3ad5 100644
--- a/flang/runtime/Float128Math/jn.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/jn.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/jn.cpp ---------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/lgamma.cpp
similarity index 87%
rename from flang/runtime/Float128Math/lgamma.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/lgamma.cpp
index ac31c89a912b32..0426db2e3b98d3 100644
--- a/flang/runtime/Float128Math/lgamma.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/lgamma.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/lgamma.cpp -----------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/llround.cpp
similarity index 88%
rename from flang/runtime/Float128Math/llround.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/llround.cpp
index b77281c507fe7c..4c9026cce00283 100644
--- a/flang/runtime/Float128Math/llround.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/llround.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/llround.cpp ----------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/log.cpp
similarity index 87%
rename from flang/runtime/Float128Math/log.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/log.cpp
index 38e6b581fd849c..a5a431ae5ffbbb 100644
--- a/flang/runtime/Float128Math/log.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/log.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/log.cpp --------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/log10.cpp
similarity index 87%
rename from flang/runtime/Float128Math/log10.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/log10.cpp
index 3c89c0e707774f..9a83f57b6c736d 100644
--- a/flang/runtime/Float128Math/log10.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/log10.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/log10.cpp ------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/lround.cpp
similarity index 87%
rename from flang/runtime/Float128Math/lround.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/lround.cpp
index ce7a228038a1d3..65546881157948 100644
--- a/flang/runtime/Float128Math/lround.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/lround.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/lround.cpp -----------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/math-entries.h
similarity index 98%
rename from flang/runtime/Float128Math/math-entries.h
rename to FortranRuntime/lib/Runtime/Float128Math/math-entries.h
index 13fdab26470038..cb1e0130602260 100644
--- a/flang/runtime/Float128Math/math-entries.h
+++ b/FortranRuntime/lib/Runtime/Float128Math/math-entries.h
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/math-entries.h ---------------------*- C++ -*-===//
+//===-- lib/Runtime/Float128Math/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.
@@ -8,10 +8,10 @@
 
 #ifndef FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
 #define FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
-#include "terminator.h"
-#include "tools.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/entry-names.h"
+#include "terminator.h"
+#include "tools.h"
 #include <cfloat>
 #include <cmath>
 #include <type_traits>
@@ -222,4 +222,4 @@ DEFINE_SIMPLE_ALIAS(Yn, ynl)
 
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
+#endif /* FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_ */
diff --git a/flang/runtime/Float128Math/mod-real.cpp b/FortranRuntime/lib/Runtime/Float128Math/mod-real.cpp
similarity index 89%
rename from flang/runtime/Float128Math/mod-real.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/mod-real.cpp
index 42e6ce76e2fa1b..e3b96d39e76ae6 100644
--- a/flang/runtime/Float128Math/mod-real.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/mod-real.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/mod-real.cpp ---------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/modulo-real.cpp
similarity index 89%
rename from flang/runtime/Float128Math/modulo-real.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/modulo-real.cpp
index 13000aba8c8323..8edf59e9f59dd4 100644
--- a/flang/runtime/Float128Math/modulo-real.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/modulo-real.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/modulo-real.cpp ------------------------------===//
+//===-- lib/Runtime/Float128Math/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/nearest.cpp b/FortranRuntime/lib/Runtime/Float128Math/nearest.cpp
similarity index 89%
rename from flang/runtime/Float128Math/nearest.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/nearest.cpp
index 148ac4ef839160..8b9f142d79ff93 100644
--- a/flang/runtime/Float128Math/nearest.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/nearest.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/nearest.cpp ----------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/norm2.cpp
similarity index 93%
rename from flang/runtime/Float128Math/norm2.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/norm2.cpp
index 15c482f7f007ce..a0c26e40de0064 100644
--- a/flang/runtime/Float128Math/norm2.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/norm2.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/norm2.cpp ------------------------------------===//
+//===-- lib/Runtime/Float128Math/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.
diff --git a/flang/runtime/Float128Math/numeric-template-specs.h b/FortranRuntime/lib/Runtime/Float128Math/numeric-template-specs.h
similarity index 92%
rename from flang/runtime/Float128Math/numeric-template-specs.h
rename to FortranRuntime/lib/Runtime/Float128Math/numeric-template-specs.h
index a0a77230c3e9eb..2a843df2d1d861 100644
--- a/flang/runtime/Float128Math/numeric-template-specs.h
+++ b/FortranRuntime/lib/Runtime/Float128Math/numeric-template-specs.h
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/numeric-template-specs.h -----------*- C++ -*-===//
+//===-- lib/Runtime/Float128Math/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.
@@ -52,4 +52,4 @@ template <> struct SQRTTy<F128Type> {
 };
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
+#endif /* FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_ */
diff --git a/flang/runtime/Float128Math/pow.cpp b/FortranRuntime/lib/Runtime/Float128Math/pow.cpp
similarity index 88%
rename from flang/runtime/Float128Math/pow.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/pow.cpp
index 7a48828ee3e765..c11978ca068f23 100644
--- a/flang/runtime/Float128Math/pow.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/pow.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/pow.cpp --------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/random.cpp
similarity index 89%
rename from flang/runtime/Float128Math/random.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/random.cpp
index cda962b416144e..a9dc3c7a82b673 100644
--- a/flang/runtime/Float128Math/random.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/random.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/random.cpp -----------------------------------===//
+//===-- lib/Runtime/Float128Math/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.
diff --git a/flang/runtime/Float128Math/round.cpp b/FortranRuntime/lib/Runtime/Float128Math/round.cpp
similarity index 89%
rename from flang/runtime/Float128Math/round.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/round.cpp
index 6420c1bc9cd25d..5a9366b3af4785 100644
--- a/flang/runtime/Float128Math/round.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/round.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/round.cpp ------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/rrspacing.cpp
similarity index 87%
rename from flang/runtime/Float128Math/rrspacing.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/rrspacing.cpp
index feddac418eec39..2c501b3512c215 100644
--- a/flang/runtime/Float128Math/rrspacing.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/rrspacing.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/rrspacing.cpp --------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/scale.cpp
similarity index 90%
rename from flang/runtime/Float128Math/scale.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/scale.cpp
index 0be958bd9f2a72..859c955b8114e0 100644
--- a/flang/runtime/Float128Math/scale.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/scale.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/scale.cpp ------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/set-exponent.cpp
similarity index 88%
rename from flang/runtime/Float128Math/set-exponent.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/set-exponent.cpp
index 99c34af7962b9a..52258182871a14 100644
--- a/flang/runtime/Float128Math/set-exponent.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/set-exponent.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/set-exponent.cpp -----------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/sin.cpp
similarity index 87%
rename from flang/runtime/Float128Math/sin.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/sin.cpp
index 8ebc3f9881586e..99aa4095c8cf1a 100644
--- a/flang/runtime/Float128Math/sin.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/sin.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/sin.cpp --------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/sinh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/sinh.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/sinh.cpp
index aa716a3e51ef5a..a7dfe36737de43 100644
--- a/flang/runtime/Float128Math/sinh.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/sinh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/sinh.cpp -------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/spacing.cpp
similarity index 87%
rename from flang/runtime/Float128Math/spacing.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/spacing.cpp
index a86c0b30e567ab..66a01851965840 100644
--- a/flang/runtime/Float128Math/spacing.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/spacing.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/spacing.cpp ----------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/sqrt.cpp
similarity index 87%
rename from flang/runtime/Float128Math/sqrt.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/sqrt.cpp
index 83165a4c623191..cbc1e503d50fd9 100644
--- a/flang/runtime/Float128Math/sqrt.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/sqrt.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/sqrt.cpp -------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/tan.cpp
similarity index 87%
rename from flang/runtime/Float128Math/tan.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/tan.cpp
index 8f4b723ca977bd..dbe4627f585f14 100644
--- a/flang/runtime/Float128Math/tan.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/tan.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/tan.cpp --------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/tanh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/tanh.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/tanh.cpp
index b43a89520b6797..37e40966ced722 100644
--- a/flang/runtime/Float128Math/tanh.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/tanh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/tanh.cpp -------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/tgamma.cpp
similarity index 87%
rename from flang/runtime/Float128Math/tgamma.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/tgamma.cpp
index 93f97800bdc966..07a019c6d9971f 100644
--- a/flang/runtime/Float128Math/tgamma.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/tgamma.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/tgamma.cpp -----------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/trunc.cpp
similarity index 89%
rename from flang/runtime/Float128Math/trunc.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/trunc.cpp
index ca15a739c030e8..9f38bdc18e73c4 100644
--- a/flang/runtime/Float128Math/trunc.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/trunc.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/trunc.cpp ------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/y0.cpp
similarity index 87%
rename from flang/runtime/Float128Math/y0.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/y0.cpp
index d6f39aac1053a8..6eaa3396e7ea07 100644
--- a/flang/runtime/Float128Math/y0.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/y0.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/y0.cpp ---------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/y1.cpp
similarity index 87%
rename from flang/runtime/Float128Math/y1.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/y1.cpp
index 477d36a9ea3c66..c9f48ea0e26546 100644
--- a/flang/runtime/Float128Math/y1.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/y1.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/y1.cpp ---------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/FortranRuntime/lib/Runtime/Float128Math/yn.cpp
similarity index 87%
rename from flang/runtime/Float128Math/yn.cpp
rename to FortranRuntime/lib/Runtime/Float128Math/yn.cpp
index 3a040cc8858970..6bc5f4996a88d5 100644
--- a/flang/runtime/Float128Math/yn.cpp
+++ b/FortranRuntime/lib/Runtime/Float128Math/yn.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/yn.cpp ---------------------------------------===//
+//===-- lib/Runtime/Float128Math/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/ISO_Fortran_binding.cpp b/FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp
similarity index 98%
rename from flang/runtime/ISO_Fortran_binding.cpp
rename to FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp
index fe22026f31f55f..9711b2bcf49757 100644
--- a/flang/runtime/ISO_Fortran_binding.cpp
+++ b/FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/ISO_Fortran_binding.cpp -----------------------------------===//
+//===-- 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,11 +10,11 @@
 // as specified in section 18.5.5 of Fortran 2018.
 
 #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"
+#include "terminator.h"
 #include <cstdlib>
 
 namespace Fortran::ISO {
diff --git a/flang/runtime/ISO_Fortran_util.h b/FortranRuntime/lib/Runtime/ISO_Fortran_util.h
similarity index 95%
rename from flang/runtime/ISO_Fortran_util.h
rename to FortranRuntime/lib/Runtime/ISO_Fortran_util.h
index dd0eeef80bb896..7ab280733028af 100644
--- a/flang/runtime/ISO_Fortran_util.h
+++ b/FortranRuntime/lib/Runtime/ISO_Fortran_util.h
@@ -1,4 +1,4 @@
-//===-- runtime/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.
@@ -11,10 +11,10 @@
 
 // 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 "terminator.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 /* FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_ */
diff --git a/flang/runtime/allocatable.cpp b/FortranRuntime/lib/Runtime/allocatable.cpp
similarity index 98%
rename from flang/runtime/allocatable.cpp
rename to FortranRuntime/lib/Runtime/allocatable.cpp
index 5e065f47636a89..8b6c1a4c1477eb 100644
--- a/flang/runtime/allocatable.cpp
+++ b/FortranRuntime/lib/Runtime/allocatable.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/allocatable.cpp -------------------------------------------===//
+//===-- 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.
@@ -9,12 +9,12 @@
 #include "flang/Runtime/allocatable.h"
 #include "assign-impl.h"
 #include "derived.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
+#include "flang/Runtime/assign.h"
+#include "flang/Runtime/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "type-info.h"
-#include "flang/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/FortranRuntime/lib/Runtime/allocator-registry.cpp
similarity index 94%
rename from flang/runtime/allocator-registry.cpp
rename to FortranRuntime/lib/Runtime/allocator-registry.cpp
index f5670331d6dbe2..68fb8b80680558 100644
--- a/flang/runtime/allocator-registry.cpp
+++ b/FortranRuntime/lib/Runtime/allocator-registry.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/allocator-registry.cpp ------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/array-constructor.cpp b/FortranRuntime/lib/Runtime/array-constructor.cpp
similarity index 99%
rename from flang/runtime/array-constructor.cpp
rename to FortranRuntime/lib/Runtime/array-constructor.cpp
index 72e08feff7fd10..db57d4fc4c3f68 100644
--- a/flang/runtime/array-constructor.cpp
+++ b/FortranRuntime/lib/Runtime/array-constructor.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/array-constructor.cpp -------------------------------------===//
+//===-- 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.
@@ -8,12 +8,12 @@
 
 #include "flang/Runtime/array-constructor.h"
 #include "derived.h"
-#include "terminator.h"
-#include "tools.h"
-#include "type-info.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/assign.h"
 #include "flang/Runtime/descriptor.h"
+#include "terminator.h"
+#include "tools.h"
+#include "type-info.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/assign-impl.h b/FortranRuntime/lib/Runtime/assign-impl.h
similarity index 89%
rename from flang/runtime/assign-impl.h
rename to FortranRuntime/lib/Runtime/assign-impl.h
index f07a501d1d1263..d5538fab18b6b5 100644
--- a/flang/runtime/assign-impl.h
+++ b/FortranRuntime/lib/Runtime/assign-impl.h
@@ -1,4 +1,4 @@
-//===-- runtime/assign-impl.h -----------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -21,4 +21,4 @@ RT_API_ATTRS void DoFromSourceAssign(
     Descriptor &, const Descriptor &, Terminator &);
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_ASSIGN_IMPL_H_
+#endif /* FORTRAN_RUNTIME_ASSIGN_IMPL_H_ */
diff --git a/flang/runtime/assign.cpp b/FortranRuntime/lib/Runtime/assign.cpp
similarity index 99%
rename from flang/runtime/assign.cpp
rename to FortranRuntime/lib/Runtime/assign.cpp
index d558ada51cd21a..cc38e55e3a9e1e 100644
--- a/flang/runtime/assign.cpp
+++ b/FortranRuntime/lib/Runtime/assign.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/assign.cpp ------------------------------------------------===//
+//===-- 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.
@@ -9,11 +9,11 @@
 #include "flang/Runtime/assign.h"
 #include "assign-impl.h"
 #include "derived.h"
+#include "flang/Runtime/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
 #include "type-info.h"
-#include "flang/Runtime/descriptor.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/buffer.cpp b/FortranRuntime/lib/Runtime/buffer.cpp
similarity index 92%
rename from flang/runtime/buffer.cpp
rename to FortranRuntime/lib/Runtime/buffer.cpp
index 7b4869d69c2e51..ce78fe34503c46 100644
--- a/flang/runtime/buffer.cpp
+++ b/FortranRuntime/lib/Runtime/buffer.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/buffer.cpp ------------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/buffer.h b/FortranRuntime/lib/Runtime/buffer.h
similarity index 98%
rename from flang/runtime/buffer.h
rename to FortranRuntime/lib/Runtime/buffer.h
index 41a1abb1b2d907..dd3c19fa14392f 100644
--- a/flang/runtime/buffer.h
+++ b/FortranRuntime/lib/Runtime/buffer.h
@@ -1,4 +1,4 @@
-//===-- runtime/buffer.h ----------------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -11,9 +11,9 @@
 #ifndef FORTRAN_RUNTIME_BUFFER_H_
 #define FORTRAN_RUNTIME_BUFFER_H_
 
-#include "io-error.h"
 #include "flang/Runtime/freestanding-tools.h"
 #include "flang/Runtime/memory.h"
+#include "io-error.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 /* FORTRAN_RUNTIME_BUFFER_H_ */
diff --git a/flang/runtime/character.cpp b/FortranRuntime/lib/Runtime/character.cpp
similarity index 99%
rename from flang/runtime/character.cpp
rename to FortranRuntime/lib/Runtime/character.cpp
index 5049247397eb3c..32fc010c6c04dd 100644
--- a/flang/runtime/character.cpp
+++ b/FortranRuntime/lib/Runtime/character.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/character.cpp ---------------------------------------------===//
+//===-- 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,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/character.h"
-#include "terminator.h"
-#include "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 "terminator.h"
+#include "tools.h"
 #include <algorithm>
 #include <cstring>
 
diff --git a/flang/runtime/command.cpp b/FortranRuntime/lib/Runtime/command.cpp
similarity index 98%
rename from flang/runtime/command.cpp
rename to FortranRuntime/lib/Runtime/command.cpp
index a555e26f96a66c..dc57758d4f7955 100644
--- a/flang/runtime/command.cpp
+++ b/FortranRuntime/lib/Runtime/command.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/command.cpp -----------------------------------------------===//
+//===-- 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.
@@ -8,10 +8,10 @@
 
 #include "flang/Runtime/command.h"
 #include "environment.h"
+#include "flang/Runtime/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
-#include "flang/Runtime/descriptor.h"
 #include <cstdlib>
 #include <limits>
 
diff --git a/flang/runtime/complex-powi.cpp b/FortranRuntime/lib/Runtime/complex-powi.cpp
similarity index 91%
rename from flang/runtime/complex-powi.cpp
rename to FortranRuntime/lib/Runtime/complex-powi.cpp
index 77031e40242791..2eacf56386b193 100644
--- a/flang/runtime/complex-powi.cpp
+++ b/FortranRuntime/lib/Runtime/complex-powi.cpp
@@ -1,11 +1,10 @@
-/*===-- 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/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
+//
+//===----------------------------------------------------------------------===//
 #include "flang/Common/float128.h"
 #include "flang/Runtime/entry-names.h"
 #include <cstdint>
diff --git a/flang/runtime/complex-reduction.c b/FortranRuntime/lib/Runtime/complex-reduction.c
similarity index 97%
rename from flang/runtime/complex-reduction.c
rename to FortranRuntime/lib/Runtime/complex-reduction.c
index 37ce3fa410016b..138174e9122b1c 100644
--- a/flang/runtime/complex-reduction.c
+++ b/FortranRuntime/lib/Runtime/complex-reduction.c
@@ -1,11 +1,10 @@
-/*===-- flang/runtime/complex-reduction.c ---------------------------*- C -*-===
+/*===-- lib/Runtime/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/FortranRuntime/lib/Runtime/complex-reduction.h
similarity index 97%
rename from flang/runtime/complex-reduction.h
rename to FortranRuntime/lib/Runtime/complex-reduction.h
index b0f19622fdb1a5..e8e287215b7d97 100644
--- a/flang/runtime/complex-reduction.h
+++ b/FortranRuntime/lib/Runtime/complex-reduction.h
@@ -1,11 +1,10 @@
-/*===-- flang/runtime/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.
  * 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
@@ -156,4 +155,4 @@ void RTNAME(ReduceComplex16DimValue)(
     REDUCE_DIM_ARGS(CFloat128ComplexType, CFloat128ComplexType_value_op));
 #endif
 
-#endif // FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
+#endif /* FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_ */
diff --git a/flang/runtime/connection.cpp b/FortranRuntime/lib/Runtime/connection.cpp
similarity index 96%
rename from flang/runtime/connection.cpp
rename to FortranRuntime/lib/Runtime/connection.cpp
index f24f0e832eb484..f9e91f1f193ba0 100644
--- a/flang/runtime/connection.cpp
+++ b/FortranRuntime/lib/Runtime/connection.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/connection.cpp --------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/connection.h b/FortranRuntime/lib/Runtime/connection.h
similarity index 96%
rename from flang/runtime/connection.h
rename to FortranRuntime/lib/Runtime/connection.h
index 6f1ea90a160e5e..92a3a9c3860a3e 100644
--- a/flang/runtime/connection.h
+++ b/FortranRuntime/lib/Runtime/connection.h
@@ -1,4 +1,4 @@
-//===-- runtime/connection.h ------------------------------------*- C++ -*-===//
+//===-- lib/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,11 +8,11 @@
 
 // Fortran I/O connection state (abstracted over internal & external units)
 
-#ifndef FORTRAN_RUNTIME_IO_CONNECTION_H_
-#define FORTRAN_RUNTIME_IO_CONNECTION_H_
+#ifndef FORTRAN_RUNTIME_CONNECTION_H_
+#define FORTRAN_RUNTIME_CONNECTION_H_
 
-#include "format.h"
 #include "flang/Common/optional.h"
+#include "format.h"
 #include <cinttypes>
 
 namespace Fortran::runtime::io {
@@ -124,4 +124,4 @@ class SavedPosition {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IO_CONNECTION_H_
+#endif /* FORTRAN_RUNTIME_CONNECTION_H_ */
diff --git a/flang/runtime/copy.cpp b/FortranRuntime/lib/Runtime/copy.cpp
similarity index 99%
rename from flang/runtime/copy.cpp
rename to FortranRuntime/lib/Runtime/copy.cpp
index b20f68f019498b..39c7da45172a43 100644
--- a/flang/runtime/copy.cpp
+++ b/FortranRuntime/lib/Runtime/copy.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/copy.cpp -------------------------------------------------===//
+//===-- 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.
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "copy.h"
+#include "flang/Runtime/allocatable.h"
+#include "flang/Runtime/descriptor.h"
 #include "stack.h"
 #include "terminator.h"
 #include "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/FortranRuntime/lib/Runtime/copy.h
similarity index 89%
rename from flang/runtime/copy.h
rename to FortranRuntime/lib/Runtime/copy.h
index 542660530bfb65..f2c5b41718b71c 100644
--- a/flang/runtime/copy.h
+++ b/FortranRuntime/lib/Runtime/copy.h
@@ -1,4 +1,4 @@
-//===-- runtime/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.
@@ -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 /* FORTRAN_RUNTIME_COPY_H_ */
diff --git a/flang/runtime/derived-api.cpp b/FortranRuntime/lib/Runtime/derived-api.cpp
similarity index 98%
rename from flang/runtime/derived-api.cpp
rename to FortranRuntime/lib/Runtime/derived-api.cpp
index eca784be208d10..4b68cdbbed7b2c 100644
--- a/flang/runtime/derived-api.cpp
+++ b/FortranRuntime/lib/Runtime/derived-api.cpp
@@ -1,5 +1,4 @@
-//===-- runtime/derived-api.cpp
-//-----------------------------------------------===//
+//===-- 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.
@@ -9,10 +8,10 @@
 
 #include "flang/Runtime/derived-api.h"
 #include "derived.h"
+#include "flang/Runtime/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "type-info.h"
-#include "flang/Runtime/descriptor.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/derived.cpp b/FortranRuntime/lib/Runtime/derived.cpp
similarity index 99%
rename from flang/runtime/derived.cpp
rename to FortranRuntime/lib/Runtime/derived.cpp
index 659f54fa344bb0..52bf54d62c8599 100644
--- a/flang/runtime/derived.cpp
+++ b/FortranRuntime/lib/Runtime/derived.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/derived.cpp -----------------------------------------------===//
+//===-- 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.
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "derived.h"
+#include "flang/Runtime/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
 #include "type-info.h"
-#include "flang/Runtime/descriptor.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/derived.h b/FortranRuntime/lib/Runtime/derived.h
similarity index 92%
rename from flang/runtime/derived.h
rename to FortranRuntime/lib/Runtime/derived.h
index b4863df8db417c..e03e657f01cee9 100644
--- a/flang/runtime/derived.h
+++ b/FortranRuntime/lib/Runtime/derived.h
@@ -1,4 +1,4 @@
-//===-- runtime/derived.h -------------------------------------------------===//
+//===-- lib/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.
@@ -40,4 +40,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 /* FORTRAN_RUNTIME_DERIVED_H_ */
diff --git a/flang/runtime/descriptor-io.cpp b/FortranRuntime/lib/Runtime/descriptor-io.cpp
similarity index 98%
rename from flang/runtime/descriptor-io.cpp
rename to FortranRuntime/lib/Runtime/descriptor-io.cpp
index 380ad425d925f0..896fad16a67e8a 100644
--- a/flang/runtime/descriptor-io.cpp
+++ b/FortranRuntime/lib/Runtime/descriptor-io.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/descriptor-io.cpp -----------------------------------------===//
+//===-- 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/runtime/descriptor-io.h b/FortranRuntime/lib/Runtime/descriptor-io.h
similarity index 99%
rename from flang/runtime/descriptor-io.h
rename to FortranRuntime/lib/Runtime/descriptor-io.h
index ff5f683c6da52f..2ccad0cea70a29 100644
--- a/flang/runtime/descriptor-io.h
+++ b/FortranRuntime/lib/Runtime/descriptor-io.h
@@ -1,4 +1,4 @@
-//===-- runtime/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.
@@ -16,15 +16,15 @@
 
 #include "edit-input.h"
 #include "edit-output.h"
+#include "flang/Common/optional.h"
+#include "flang/Common/uint128.h"
+#include "flang/Runtime/cpp-type.h"
+#include "flang/Runtime/descriptor.h"
 #include "io-stmt.h"
 #include "namelist.h"
 #include "terminator.h"
 #include "type-info.h"
 #include "unit.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>
@@ -608,4 +608,4 @@ static RT_API_ATTRS bool DescriptorIO(IoStatementState &io,
   return false;
 }
 } // namespace Fortran::runtime::io::descr
-#endif // FORTRAN_RUNTIME_DESCRIPTOR_IO_H_
+#endif /* FORTRAN_RUNTIME_DESCRIPTOR_IO_H_ */
diff --git a/flang/runtime/descriptor.cpp b/FortranRuntime/lib/Runtime/descriptor.cpp
similarity index 99%
rename from flang/runtime/descriptor.cpp
rename to FortranRuntime/lib/Runtime/descriptor.cpp
index 32f43e89dc7a36..6756134b06e7b1 100644
--- a/flang/runtime/descriptor.cpp
+++ b/FortranRuntime/lib/Runtime/descriptor.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/descriptor.cpp --------------------------------------------===//
+//===-- 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.
@@ -9,12 +9,12 @@
 #include "flang/Runtime/descriptor.h"
 #include "ISO_Fortran_util.h"
 #include "derived.h"
+#include "flang/Runtime/allocator-registry.h"
 #include "memory.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
 #include "type-info.h"
-#include "flang/Runtime/allocator-registry.h"
 #include <cassert>
 #include <cstdlib>
 #include <cstring>
diff --git a/flang/runtime/dot-product.cpp b/FortranRuntime/lib/Runtime/dot-product.cpp
similarity index 99%
rename from flang/runtime/dot-product.cpp
rename to FortranRuntime/lib/Runtime/dot-product.cpp
index 977698269bcb46..ab1cfa58ef3d02 100644
--- a/flang/runtime/dot-product.cpp
+++ b/FortranRuntime/lib/Runtime/dot-product.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/dot-product.cpp -------------------------------------------===//
+//===-- 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.
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "float.h"
-#include "terminator.h"
-#include "tools.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/cpp-type.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/reduction.h"
+#include "float.h"
+#include "terminator.h"
+#include "tools.h"
 #include <cfloat>
 #include <cinttypes>
 
diff --git a/flang/runtime/edit-input.cpp b/FortranRuntime/lib/Runtime/edit-input.cpp
similarity index 99%
rename from flang/runtime/edit-input.cpp
rename to FortranRuntime/lib/Runtime/edit-input.cpp
index 2cee35e23f31a3..eaa9d0d7e641e7 100644
--- a/flang/runtime/edit-input.cpp
+++ b/FortranRuntime/lib/Runtime/edit-input.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/edit-input.cpp --------------------------------------------===//
+//===-- 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,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "edit-input.h"
-#include "namelist.h"
-#include "utf.h"
 #include "flang/Common/optional.h"
 #include "flang/Common/real.h"
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/freestanding-tools.h"
+#include "namelist.h"
+#include "utf.h"
 #include <algorithm>
 #include <cfenv>
 
diff --git a/flang/runtime/edit-input.h b/FortranRuntime/lib/Runtime/edit-input.h
similarity index 93%
rename from flang/runtime/edit-input.h
rename to FortranRuntime/lib/Runtime/edit-input.h
index a90180b8ee2ebd..2eda81a6d4e11d 100644
--- a/flang/runtime/edit-input.h
+++ b/FortranRuntime/lib/Runtime/edit-input.h
@@ -1,4 +1,4 @@
-//===-- runtime/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.
@@ -9,9 +9,9 @@
 #ifndef FORTRAN_RUNTIME_EDIT_INPUT_H_
 #define FORTRAN_RUNTIME_EDIT_INPUT_H_
 
+#include "flang/Common/decimal.h"
 #include "format.h"
 #include "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 /* FORTRAN_RUNTIME_EDIT_INPUT_H_ */
diff --git a/flang/runtime/edit-output.cpp b/FortranRuntime/lib/Runtime/edit-output.cpp
similarity index 99%
rename from flang/runtime/edit-output.cpp
rename to FortranRuntime/lib/Runtime/edit-output.cpp
index 9d60732258bfbc..1fab7db6d3b187 100644
--- a/flang/runtime/edit-output.cpp
+++ b/FortranRuntime/lib/Runtime/edit-output.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/edit-output.cpp -------------------------------------------===//
+//===-- 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.
@@ -8,9 +8,9 @@
 
 #include "edit-output.h"
 #include "emit-encoded.h"
-#include "utf.h"
 #include "flang/Common/real.h"
 #include "flang/Common/uint128.h"
+#include "utf.h"
 #include <algorithm>
 
 namespace Fortran::runtime::io {
diff --git a/flang/runtime/edit-output.h b/FortranRuntime/lib/Runtime/edit-output.h
similarity index 97%
rename from flang/runtime/edit-output.h
rename to FortranRuntime/lib/Runtime/edit-output.h
index 365bc2e2a4d10b..cb25b68a35f05b 100644
--- a/flang/runtime/edit-output.h
+++ b/FortranRuntime/lib/Runtime/edit-output.h
@@ -1,4 +1,4 @@
-//===-- runtime/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.
@@ -18,10 +18,10 @@
 // Drives the same fast binary-to-decimal formatting templates used
 // in the f18 front-end.
 
+#include "flang/Common/decimal.h"
+#include "flang/Common/uint128.h"
 #include "format.h"
 #include "io-stmt.h"
-#include "flang/Common/uint128.h"
-#include "flang/Decimal/decimal.h"
 
 namespace Fortran::runtime::io {
 
@@ -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 /* FORTRAN_RUNTIME_EDIT_OUTPUT_H_ */
diff --git a/flang/runtime/emit-encoded.h b/FortranRuntime/lib/Runtime/emit-encoded.h
similarity index 97%
rename from flang/runtime/emit-encoded.h
rename to FortranRuntime/lib/Runtime/emit-encoded.h
index 4b5e3900788357..11163a41720795 100644
--- a/flang/runtime/emit-encoded.h
+++ b/FortranRuntime/lib/Runtime/emit-encoded.h
@@ -1,4 +1,4 @@
-//===-- runtime/emit-encoded.h ----------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -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 /* FORTRAN_RUNTIME_EMIT_ENCODED_H_ */
diff --git a/flang/runtime/environment-default-list.h b/FortranRuntime/lib/Runtime/environment-default-list.h
old mode 100755
new mode 100644
similarity index 85%
rename from flang/runtime/environment-default-list.h
rename to FortranRuntime/lib/Runtime/environment-default-list.h
index 4da261b10b9a84..6b7542516e7134
--- a/flang/runtime/environment-default-list.h
+++ b/FortranRuntime/lib/Runtime/environment-default-list.h
@@ -1,11 +1,10 @@
-/*===-- runtime/environment-default-list.h --------------------------*- C -*-===
+/*===-- lib/Runtime/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_
diff --git a/flang/runtime/environment.cpp b/FortranRuntime/lib/Runtime/environment.cpp
similarity index 98%
rename from flang/runtime/environment.cpp
rename to FortranRuntime/lib/Runtime/environment.cpp
index 52b1d99ba536ed..272914877988a5 100644
--- a/flang/runtime/environment.cpp
+++ b/FortranRuntime/lib/Runtime/environment.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/environment.cpp -------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/environment.h b/FortranRuntime/lib/Runtime/environment.h
similarity index 93%
rename from flang/runtime/environment.h
rename to FortranRuntime/lib/Runtime/environment.h
index b8b9f10e4e57f5..7d10b3a2b934bf 100644
--- a/flang/runtime/environment.h
+++ b/FortranRuntime/lib/Runtime/environment.h
@@ -1,4 +1,4 @@
-//===-- runtime/environment.h -----------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -9,8 +9,8 @@
 #ifndef FORTRAN_RUNTIME_ENVIRONMENT_H_
 #define FORTRAN_RUNTIME_ENVIRONMENT_H_
 
+#include "flang/Common/decimal.h"
 #include "flang/Common/optional.h"
-#include "flang/Decimal/decimal.h"
 
 struct EnvironmentDefaultList;
 
@@ -64,4 +64,4 @@ RT_OFFLOAD_VAR_GROUP_END
 
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_ENVIRONMENT_H_
+#endif /* FORTRAN_RUNTIME_ENVIRONMENT_H_ */
diff --git a/flang/runtime/exceptions.cpp b/FortranRuntime/lib/Runtime/exceptions.cpp
similarity index 96%
rename from flang/runtime/exceptions.cpp
rename to FortranRuntime/lib/Runtime/exceptions.cpp
index 8239c556bcea97..7739130ae2346a 100644
--- a/flang/runtime/exceptions.cpp
+++ b/FortranRuntime/lib/Runtime/exceptions.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/exceptions.cpp --------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/execute.cpp b/FortranRuntime/lib/Runtime/execute.cpp
similarity index 99%
rename from flang/runtime/execute.cpp
rename to FortranRuntime/lib/Runtime/execute.cpp
index c7f8f386d81f4f..54f28d052873b4 100644
--- a/flang/runtime/execute.cpp
+++ b/FortranRuntime/lib/Runtime/execute.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/execute.cpp -----------------------------------------------===//
+//===-- 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.
@@ -8,10 +8,10 @@
 
 #include "flang/Runtime/execute.h"
 #include "environment.h"
+#include "flang/Runtime/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
-#include "flang/Runtime/descriptor.h"
 #include <cstdlib>
 #include <errno.h>
 #include <future>
diff --git a/flang/runtime/extensions.cpp b/FortranRuntime/lib/Runtime/extensions.cpp
similarity index 98%
rename from flang/runtime/extensions.cpp
rename to FortranRuntime/lib/Runtime/extensions.cpp
index be3833db88b07a..94bfa3059e6b45 100644
--- a/flang/runtime/extensions.cpp
+++ b/FortranRuntime/lib/Runtime/extensions.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/extensions.cpp --------------------------------------------===//
+//===-- 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,12 +10,12 @@
 // extensions that will eventually be implemented in Fortran.
 
 #include "flang/Runtime/extensions.h"
-#include "terminator.h"
-#include "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 "terminator.h"
+#include "tools.h"
 #include <chrono>
 #include <cstring>
 #include <ctime>
diff --git a/flang/runtime/external-unit.cpp b/FortranRuntime/lib/Runtime/external-unit.cpp
similarity index 99%
rename from flang/runtime/external-unit.cpp
rename to FortranRuntime/lib/Runtime/external-unit.cpp
index d17a92622f8448..f5fa2c31dafc4e 100644
--- a/flang/runtime/external-unit.cpp
+++ b/FortranRuntime/lib/Runtime/external-unit.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/external-unit.cpp -----------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/extrema.cpp b/FortranRuntime/lib/Runtime/extrema.cpp
similarity index 99%
rename from flang/runtime/extrema.cpp
rename to FortranRuntime/lib/Runtime/extrema.cpp
index d6e9633372f524..0809cb1d5f2ae2 100644
--- a/flang/runtime/extrema.cpp
+++ b/FortranRuntime/lib/Runtime/extrema.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/extrema.cpp -----------------------------------------------===//
+//===-- 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,10 +10,10 @@
 // and shapes and (for MAXLOC & MINLOC) result integer kinds.  Also implements
 // NORM2 using common infrastructure.
 
-#include "reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/character.h"
 #include "flang/Runtime/reduction.h"
+#include "reduction-templates.h"
 #include <algorithm>
 #include <cfloat>
 #include <cinttypes>
diff --git a/flang/runtime/file.cpp b/FortranRuntime/lib/Runtime/file.cpp
similarity index 99%
rename from flang/runtime/file.cpp
rename to FortranRuntime/lib/Runtime/file.cpp
index ec772903242b80..b82f1c63e397f9 100644
--- a/flang/runtime/file.cpp
+++ b/FortranRuntime/lib/Runtime/file.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/file.cpp --------------------------------------------------===//
+//===-- 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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "file.h"
-#include "tools.h"
 #include "flang/Runtime/magic-numbers.h"
 #include "flang/Runtime/memory.h"
+#include "tools.h"
 #include <algorithm>
 #include <cerrno>
 #include <cstring>
diff --git a/flang/runtime/file.h b/FortranRuntime/lib/Runtime/file.h
similarity index 97%
rename from flang/runtime/file.h
rename to FortranRuntime/lib/Runtime/file.h
index c06acbb9904cc1..66d62756634b24 100644
--- a/flang/runtime/file.h
+++ b/FortranRuntime/lib/Runtime/file.h
@@ -1,4 +1,4 @@
-//===-- runtime/file.h ------------------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -11,9 +11,9 @@
 #ifndef FORTRAN_RUNTIME_FILE_H_
 #define FORTRAN_RUNTIME_FILE_H_
 
-#include "io-error.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/memory.h"
+#include "io-error.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 /* FORTRAN_RUNTIME_FILE_H_ */
diff --git a/flang/runtime/findloc.cpp b/FortranRuntime/lib/Runtime/findloc.cpp
similarity index 99%
rename from flang/runtime/findloc.cpp
rename to FortranRuntime/lib/Runtime/findloc.cpp
index 674a21ae50b853..47c51fbcef4939 100644
--- a/flang/runtime/findloc.cpp
+++ b/FortranRuntime/lib/Runtime/findloc.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/findloc.cpp -----------------------------------------------===//
+//===-- 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,9 +9,9 @@
 // Implements FINDLOC for all required operand types and shapes and result
 // integer kinds.
 
-#include "reduction-templates.h"
 #include "flang/Runtime/character.h"
 #include "flang/Runtime/reduction.h"
+#include "reduction-templates.h"
 #include <cinttypes>
 #include <complex>
 
diff --git a/flang/runtime/format-implementation.h b/FortranRuntime/lib/Runtime/format-implementation.h
similarity index 99%
rename from flang/runtime/format-implementation.h
rename to FortranRuntime/lib/Runtime/format-implementation.h
index 46204ca927c135..8d0d0f3376eafc 100644
--- a/flang/runtime/format-implementation.h
+++ b/FortranRuntime/lib/Runtime/format-implementation.h
@@ -1,4 +1,4 @@
-//===-- runtime/format-implementation.h -------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -12,12 +12,12 @@
 #define FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_
 
 #include "emit-encoded.h"
+#include "flang/Common/decimal.h"
+#include "flang/Common/format.h"
+#include "flang/Runtime/main.h"
 #include "format.h"
 #include "io-stmt.h"
 #include "memory.h"
-#include "flang/Common/format.h"
-#include "flang/Decimal/decimal.h"
-#include "flang/Runtime/main.h"
 #include <algorithm>
 #include <cstring>
 #include <limits>
@@ -601,4 +601,4 @@ RT_API_ATTRS void FormatControl<CONTEXT>::Finish(Context &context) {
   }
 }
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_
+#endif /* FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_ */
diff --git a/flang/runtime/format.cpp b/FortranRuntime/lib/Runtime/format.cpp
similarity index 92%
rename from flang/runtime/format.cpp
rename to FortranRuntime/lib/Runtime/format.cpp
index 433acce4b73739..73a61f785c23b8 100644
--- a/flang/runtime/format.cpp
+++ b/FortranRuntime/lib/Runtime/format.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/format.cpp ------------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/format.h b/FortranRuntime/lib/Runtime/format.h
similarity index 98%
rename from flang/runtime/format.h
rename to FortranRuntime/lib/Runtime/format.h
index 815bf70685e647..3e0807ee452a7e 100644
--- a/flang/runtime/format.h
+++ b/FortranRuntime/lib/Runtime/format.h
@@ -1,4 +1,4 @@
-//===-- runtime/format.h ----------------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -12,11 +12,11 @@
 #define FORTRAN_RUNTIME_FORMAT_H_
 
 #include "environment.h"
-#include "io-error.h"
 #include "flang/Common/Fortran-consts.h"
+#include "flang/Common/decimal.h"
 #include "flang/Common/optional.h"
-#include "flang/Decimal/decimal.h"
 #include "flang/Runtime/freestanding-tools.h"
+#include "io-error.h"
 #include <cinttypes>
 
 namespace Fortran::runtime {
@@ -201,4 +201,4 @@ template <typename CONTEXT> class FormatControl {
   Iteration stack_[maxMaxHeight];
 };
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_FORMAT_H_
+#endif /* FORTRAN_RUNTIME_FORMAT_H_ */
diff --git a/flang/runtime/inquiry.cpp b/FortranRuntime/lib/Runtime/inquiry.cpp
similarity index 97%
rename from flang/runtime/inquiry.cpp
rename to FortranRuntime/lib/Runtime/inquiry.cpp
index 9fbcaa96fa3c43..172b46037d6c4b 100644
--- a/flang/runtime/inquiry.cpp
+++ b/FortranRuntime/lib/Runtime/inquiry.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/inquiry.cpp --------------------------------------===//
+//===-- 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/Runtime/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
-#include "flang/Runtime/descriptor.h"
 #include <algorithm>
 
 namespace Fortran::runtime {
diff --git a/flang/runtime/internal-unit.cpp b/FortranRuntime/lib/Runtime/internal-unit.cpp
similarity index 98%
rename from flang/runtime/internal-unit.cpp
rename to FortranRuntime/lib/Runtime/internal-unit.cpp
index f28700ee015815..81b937ba63d4b8 100644
--- a/flang/runtime/internal-unit.cpp
+++ b/FortranRuntime/lib/Runtime/internal-unit.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/internal-unit.cpp -----------------------------------------===//
+//===-- 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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "internal-unit.h"
-#include "io-error.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/freestanding-tools.h"
+#include "io-error.h"
 #include <algorithm>
 #include <type_traits>
 
diff --git a/flang/runtime/internal-unit.h b/FortranRuntime/lib/Runtime/internal-unit.h
similarity index 90%
rename from flang/runtime/internal-unit.h
rename to FortranRuntime/lib/Runtime/internal-unit.h
index a0ee6353eeda3b..c4107696810f2b 100644
--- a/flang/runtime/internal-unit.h
+++ b/FortranRuntime/lib/Runtime/internal-unit.h
@@ -1,4 +1,4 @@
-//===-- runtime/internal-unit.h ---------------------------------*- C++ -*-===//
+//===-- lib/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 FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
-#define FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
+#ifndef FORTRAN_RUNTIME_INTERNAL_UNIT_H_
+#define FORTRAN_RUNTIME_INTERNAL_UNIT_H_
 
 #include "connection.h"
 #include "flang/Runtime/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 // FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
+#endif /* FORTRAN_RUNTIME_INTERNAL_UNIT_H_ */
diff --git a/flang/runtime/io-api-common.h b/FortranRuntime/lib/Runtime/io-api-common.h
similarity index 94%
rename from flang/runtime/io-api-common.h
rename to FortranRuntime/lib/Runtime/io-api-common.h
index c7b86cab73a525..427666723501a2 100644
--- a/flang/runtime/io-api-common.h
+++ b/FortranRuntime/lib/Runtime/io-api-common.h
@@ -1,4 +1,4 @@
-//===-- runtime/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,15 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FLANG_RUNTIME_IO_API_COMMON_H_
-#define FLANG_RUNTIME_IO_API_COMMON_H_
+#ifndef FORTRAN_RUNTIME_IO_API_COMMON_H_
+#define FORTRAN_RUNTIME_IO_API_COMMON_H_
 
-#include "io-stmt.h"
-#include "terminator.h"
-#include "unit.h"
 #include "flang/Common/api-attrs.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/io-api.h"
+#include "io-stmt.h"
+#include "terminator.h"
+#include "unit.h"
 
 namespace Fortran::runtime::io {
 
@@ -94,4 +94,4 @@ RT_API_ATTRS Cookie BeginExternalListIO(
 }
 
 } // namespace Fortran::runtime::io
-#endif // FLANG_RUNTIME_IO_API_COMMON_H_
+#endif /* FORTRAN_RUNTIME_IO_API_COMMON_H_ */
diff --git a/flang/runtime/io-api-minimal.cpp b/FortranRuntime/lib/Runtime/io-api-minimal.cpp
similarity index 98%
rename from flang/runtime/io-api-minimal.cpp
rename to FortranRuntime/lib/Runtime/io-api-minimal.cpp
index ad76fe3de0324c..683694bd63c068 100644
--- a/flang/runtime/io-api-minimal.cpp
+++ b/FortranRuntime/lib/Runtime/io-api-minimal.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/io-api-minimal.cpp ----------------------------------------===//
+//===-- 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.
@@ -10,13 +10,13 @@
 // list-directed output (PRINT *) of intrinsic types.
 
 #include "edit-output.h"
+#include "flang/Runtime/io-api.h"
 #include "format.h"
 #include "io-api-common.h"
 #include "io-stmt.h"
 #include "terminator.h"
 #include "tools.h"
 #include "unit.h"
-#include "flang/Runtime/io-api.h"
 
 namespace Fortran::runtime::io {
 RT_EXT_API_GROUP_BEGIN
diff --git a/flang/runtime/io-api.cpp b/FortranRuntime/lib/Runtime/io-api.cpp
similarity index 99%
rename from flang/runtime/io-api.cpp
rename to FortranRuntime/lib/Runtime/io-api.cpp
index e3c6b9e5ca8959..102ea26b359111 100644
--- a/flang/runtime/io-api.cpp
+++ b/FortranRuntime/lib/Runtime/io-api.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/io-api.cpp ------------------------------------------------===//
+//===-- 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.
@@ -18,15 +18,15 @@
 #include "edit-input.h"
 #include "edit-output.h"
 #include "environment.h"
+#include "flang/Common/optional.h"
+#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/memory.h"
 #include "format.h"
 #include "io-api-common.h"
 #include "io-stmt.h"
 #include "terminator.h"
 #include "tools.h"
 #include "unit.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/FortranRuntime/lib/Runtime/io-error.cpp
similarity index 98%
rename from flang/runtime/io-error.cpp
rename to FortranRuntime/lib/Runtime/io-error.cpp
index 7a90966f81047f..b14a30354d2347 100644
--- a/flang/runtime/io-error.cpp
+++ b/FortranRuntime/lib/Runtime/io-error.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/io-error.cpp ----------------------------------------------===//
+//===-- 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.
@@ -8,8 +8,8 @@
 
 #include "io-error.h"
 #include "config.h"
-#include "tools.h"
 #include "flang/Runtime/magic-numbers.h"
+#include "tools.h"
 #include <cerrno>
 #include <cstdarg>
 #include <cstdio>
diff --git a/flang/runtime/io-error.h b/FortranRuntime/lib/Runtime/io-error.h
similarity index 96%
rename from flang/runtime/io-error.h
rename to FortranRuntime/lib/Runtime/io-error.h
index 426573e2faf00c..7388a2134ed0d3 100644
--- a/flang/runtime/io-error.h
+++ b/FortranRuntime/lib/Runtime/io-error.h
@@ -1,4 +1,4 @@
-//===-- runtime/io-error.h --------------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -15,9 +15,9 @@
 #ifndef FORTRAN_RUNTIME_IO_ERROR_H_
 #define FORTRAN_RUNTIME_IO_ERROR_H_
 
-#include "terminator.h"
 #include "flang/Runtime/iostat.h"
 #include "flang/Runtime/memory.h"
+#include "terminator.h"
 #include <cinttypes>
 
 namespace Fortran::runtime::io {
@@ -78,4 +78,4 @@ class IoErrorHandler : public Terminator {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IO_ERROR_H_
+#endif /* FORTRAN_RUNTIME_IO_ERROR_H_ */
diff --git a/flang/runtime/io-stmt.cpp b/FortranRuntime/lib/Runtime/io-stmt.cpp
similarity index 99%
rename from flang/runtime/io-stmt.cpp
rename to FortranRuntime/lib/Runtime/io-stmt.cpp
index 265bd0dc9d9499..5be5d98ace0d8a 100644
--- a/flang/runtime/io-stmt.cpp
+++ b/FortranRuntime/lib/Runtime/io-stmt.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/io-stmt.cpp -----------------------------------------------===//
+//===-- 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.
@@ -9,11 +9,11 @@
 #include "io-stmt.h"
 #include "connection.h"
 #include "emit-encoded.h"
+#include "flang/Runtime/memory.h"
 #include "format.h"
 #include "tools.h"
 #include "unit.h"
 #include "utf.h"
-#include "flang/Runtime/memory.h"
 #include <algorithm>
 #include <cstdio>
 #include <cstring>
diff --git a/flang/runtime/io-stmt.h b/FortranRuntime/lib/Runtime/io-stmt.h
similarity index 99%
rename from flang/runtime/io-stmt.h
rename to FortranRuntime/lib/Runtime/io-stmt.h
index 2e0ca46078ecdc..79a8b28c8aa19f 100644
--- a/flang/runtime/io-stmt.h
+++ b/FortranRuntime/lib/Runtime/io-stmt.h
@@ -1,4 +1,4 @@
-//===-- runtime/io-stmt.h ---------------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -13,14 +13,14 @@
 
 #include "connection.h"
 #include "file.h"
-#include "format.h"
-#include "internal-unit.h"
-#include "io-error.h"
 #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 "format.h"
+#include "internal-unit.h"
+#include "io-error.h"
 #include <flang/Common/variant.h>
 #include <functional>
 #include <type_traits>
@@ -789,4 +789,4 @@ class ErroneousIoStatementState : public IoStatementBase {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IO_STMT_H_
+#endif /* FORTRAN_RUNTIME_IO_STMT_H_ */
diff --git a/flang/runtime/iostat.cpp b/FortranRuntime/lib/Runtime/iostat.cpp
similarity index 98%
rename from flang/runtime/iostat.cpp
rename to FortranRuntime/lib/Runtime/iostat.cpp
index 39e224cb01286b..f23567be4910da 100644
--- a/flang/runtime/iostat.cpp
+++ b/FortranRuntime/lib/Runtime/iostat.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/iostat.cpp ------------------------------------------------===//
+//===-- 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/module/iso_fortran_env_impl.f90 b/FortranRuntime/lib/Runtime/iso_fortran_env_impl.f90
similarity index 98%
rename from flang/module/iso_fortran_env_impl.f90
rename to FortranRuntime/lib/Runtime/iso_fortran_env_impl.f90
index 4de54dda7bab1c..1a4da69266c55b 100644
--- a/flang/module/iso_fortran_env_impl.f90
+++ b/FortranRuntime/lib/Runtime/iso_fortran_env_impl.f90
@@ -1,4 +1,4 @@
-!===-- module/iso_fortran_env_impl.f90 --=--------------------------------===!
+!===-- lib/Runtime/iso_fortran_env_impl.f90 --------------------------------===!
 !
 ! 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/lock.h b/FortranRuntime/lib/Runtime/lock.h
similarity index 96%
rename from flang/runtime/lock.h
rename to FortranRuntime/lib/Runtime/lock.h
index 46ca28703a45b4..69ff6403736dae 100644
--- a/flang/runtime/lock.h
+++ b/FortranRuntime/lib/Runtime/lock.h
@@ -1,4 +1,4 @@
-//===-- runtime/lock.h ------------------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -113,4 +113,4 @@ class CriticalSection {
 };
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_LOCK_H_
+#endif /* FORTRAN_RUNTIME_LOCK_H_ */
diff --git a/flang/runtime/main.cpp b/FortranRuntime/lib/Runtime/main.cpp
similarity index 94%
rename from flang/runtime/main.cpp
rename to FortranRuntime/lib/Runtime/main.cpp
index 96454989581b71..3fe985e524548d 100644
--- a/flang/runtime/main.cpp
+++ b/FortranRuntime/lib/Runtime/main.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/main.cpp --------------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/matmul-transpose.cpp b/FortranRuntime/lib/Runtime/matmul-transpose.cpp
similarity index 99%
rename from flang/runtime/matmul-transpose.cpp
rename to FortranRuntime/lib/Runtime/matmul-transpose.cpp
index 283472650a1c69..3b4b487daa335e 100644
--- a/flang/runtime/matmul-transpose.cpp
+++ b/FortranRuntime/lib/Runtime/matmul-transpose.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/matmul-transpose.cpp --------------------------------------===//
+//===-- 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,12 +21,12 @@
 // to use the faster BLAS routines.
 
 #include "flang/Runtime/matmul-transpose.h"
-#include "terminator.h"
-#include "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 "terminator.h"
+#include "tools.h"
 #include <cstring>
 
 namespace {
diff --git a/flang/runtime/matmul.cpp b/FortranRuntime/lib/Runtime/matmul.cpp
similarity index 99%
rename from flang/runtime/matmul.cpp
rename to FortranRuntime/lib/Runtime/matmul.cpp
index 252557e2f9e7ad..62674316bc6a57 100644
--- a/flang/runtime/matmul.cpp
+++ b/FortranRuntime/lib/Runtime/matmul.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/matmul.cpp ------------------------------------------------===//
+//===-- 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,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/Common/optional.h"
 #include "flang/Runtime/c-or-cpp.h"
 #include "flang/Runtime/cpp-type.h"
 #include "flang/Runtime/descriptor.h"
+#include "terminator.h"
+#include "tools.h"
 #include <cstring>
 
 namespace {
diff --git a/flang/runtime/memory.cpp b/FortranRuntime/lib/Runtime/memory.cpp
similarity index 93%
rename from flang/runtime/memory.cpp
rename to FortranRuntime/lib/Runtime/memory.cpp
index c7068ad6479a12..bf2c4cd4a35470 100644
--- a/flang/runtime/memory.cpp
+++ b/FortranRuntime/lib/Runtime/memory.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/memory.cpp ------------------------------------------------===//
+//===-- 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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/memory.h"
+#include "flang/Runtime/freestanding-tools.h"
 #include "terminator.h"
 #include "tools.h"
-#include "flang/Runtime/freestanding-tools.h"
 #include <cstdlib>
 
 namespace Fortran::runtime {
diff --git a/flang/runtime/misc-intrinsic.cpp b/FortranRuntime/lib/Runtime/misc-intrinsic.cpp
similarity index 98%
rename from flang/runtime/misc-intrinsic.cpp
rename to FortranRuntime/lib/Runtime/misc-intrinsic.cpp
index f7d893829fc0d3..a0f41e4e3f156c 100644
--- a/flang/runtime/misc-intrinsic.cpp
+++ b/FortranRuntime/lib/Runtime/misc-intrinsic.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/misc-intrinsic.cpp ----------------------------------------===//
+//===-- 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,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/misc-intrinsic.h"
-#include "terminator.h"
-#include "tools.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/descriptor.h"
+#include "terminator.h"
+#include "tools.h"
 #include <algorithm>
 #include <cstdio>
 #include <cstring>
diff --git a/flang/runtime/namelist.cpp b/FortranRuntime/lib/Runtime/namelist.cpp
similarity index 99%
rename from flang/runtime/namelist.cpp
rename to FortranRuntime/lib/Runtime/namelist.cpp
index af092de70f7819..1c8942fc375c43 100644
--- a/flang/runtime/namelist.cpp
+++ b/FortranRuntime/lib/Runtime/namelist.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/namelist.cpp ----------------------------------------------===//
+//===-- 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.
@@ -9,8 +9,8 @@
 #include "namelist.h"
 #include "descriptor-io.h"
 #include "emit-encoded.h"
-#include "io-stmt.h"
 #include "flang/Runtime/io-api.h"
+#include "io-stmt.h"
 #include <algorithm>
 #include <cstring>
 #include <limits>
diff --git a/flang/runtime/namelist.h b/FortranRuntime/lib/Runtime/namelist.h
similarity index 94%
rename from flang/runtime/namelist.h
rename to FortranRuntime/lib/Runtime/namelist.h
index 25216a75e9367d..2c4d331ae05e85 100644
--- a/flang/runtime/namelist.h
+++ b/FortranRuntime/lib/Runtime/namelist.h
@@ -1,4 +1,4 @@
-//===-- runtime/namelist.h --------------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -11,8 +11,8 @@
 #ifndef FORTRAN_RUNTIME_NAMELIST_H_
 #define FORTRAN_RUNTIME_NAMELIST_H_
 
-#include "non-tbp-dio.h"
 #include "flang/Common/api-attrs.h"
+#include "non-tbp-dio.h"
 
 #include <cstddef>
 
@@ -51,4 +51,4 @@ class NamelistGroup {
 RT_API_ATTRS bool IsNamelistNameOrSlash(IoStatementState &);
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_NAMELIST_H_
+#endif /* FORTRAN_RUNTIME_NAMELIST_H_ */
diff --git a/flang/runtime/non-tbp-dio.cpp b/FortranRuntime/lib/Runtime/non-tbp-dio.cpp
similarity index 93%
rename from flang/runtime/non-tbp-dio.cpp
rename to FortranRuntime/lib/Runtime/non-tbp-dio.cpp
index 9419adb7631cc9..9fa04397bc9610 100644
--- a/flang/runtime/non-tbp-dio.cpp
+++ b/FortranRuntime/lib/Runtime/non-tbp-dio.cpp
@@ -1,4 +1,4 @@
-//===-- flang/runtime/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.
diff --git a/flang/runtime/non-tbp-dio.h b/FortranRuntime/lib/Runtime/non-tbp-dio.h
similarity index 95%
rename from flang/runtime/non-tbp-dio.h
rename to FortranRuntime/lib/Runtime/non-tbp-dio.h
index 8429d790fea57a..426d5a92fd37d4 100644
--- a/flang/runtime/non-tbp-dio.h
+++ b/FortranRuntime/lib/Runtime/non-tbp-dio.h
@@ -1,4 +1,4 @@
-//===-- flang/runtime/non-tbp-dio.h -----------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -53,4 +53,4 @@ struct NonTbpDefinedIoTable {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_NON_TBP_DIO_H_
+#endif /* FORTRAN_RUNTIME_NON_TBP_DIO_H_ */
diff --git a/flang/runtime/numeric-templates.h b/FortranRuntime/lib/Runtime/numeric-templates.h
similarity index 99%
rename from flang/runtime/numeric-templates.h
rename to FortranRuntime/lib/Runtime/numeric-templates.h
index 1b43498a6bfd12..f0045e8ee36e20 100644
--- a/flang/runtime/numeric-templates.h
+++ b/FortranRuntime/lib/Runtime/numeric-templates.h
@@ -1,4 +1,4 @@
-//===-- runtime/numeric-templates.h -----------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -18,10 +18,10 @@
 #ifndef FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_
 #define FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_
 
-#include "terminator.h"
-#include "tools.h"
 #include "flang/Common/api-attrs.h"
 #include "flang/Common/float128.h"
+#include "terminator.h"
+#include "tools.h"
 #include <cstdint>
 #include <limits>
 
@@ -465,4 +465,4 @@ template <typename T> inline RT_API_ATTRS T ErfcScaled(T arg) {
 
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_
+#endif /* FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_ */
diff --git a/flang/runtime/numeric.cpp b/FortranRuntime/lib/Runtime/numeric.cpp
similarity index 99%
rename from flang/runtime/numeric.cpp
rename to FortranRuntime/lib/Runtime/numeric.cpp
index 9a8ddc6615564d..a3fcfeaa9ee266 100644
--- a/flang/runtime/numeric.cpp
+++ b/FortranRuntime/lib/Runtime/numeric.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/numeric.cpp -----------------------------------------------===//
+//===-- 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,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/numeric.h"
+#include "flang/Common/float128.h"
 #include "numeric-templates.h"
 #include "terminator.h"
 #include "tools.h"
-#include "flang/Common/float128.h"
 #include <cfloat>
 #include <climits>
 #include <cmath>
diff --git a/flang/runtime/pointer.cpp b/FortranRuntime/lib/Runtime/pointer.cpp
similarity index 99%
rename from flang/runtime/pointer.cpp
rename to FortranRuntime/lib/Runtime/pointer.cpp
index 2979181ddd61bd..fba9e639fa37a8 100644
--- a/flang/runtime/pointer.cpp
+++ b/FortranRuntime/lib/Runtime/pointer.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/pointer.cpp -----------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/product.cpp b/FortranRuntime/lib/Runtime/product.cpp
similarity index 98%
rename from flang/runtime/product.cpp
rename to FortranRuntime/lib/Runtime/product.cpp
index 7fc0fcd3b107de..8c11bf4144919e 100644
--- a/flang/runtime/product.cpp
+++ b/FortranRuntime/lib/Runtime/product.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/product.cpp -----------------------------------------------===//
+//===-- 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,9 +8,9 @@
 
 // Implements PRODUCT for all required operand types and shapes.
 
-#include "reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/reduction.h"
+#include "reduction-templates.h"
 #include <cfloat>
 #include <cinttypes>
 #include <complex>
diff --git a/flang/runtime/pseudo-unit.cpp b/FortranRuntime/lib/Runtime/pseudo-unit.cpp
similarity index 98%
rename from flang/runtime/pseudo-unit.cpp
rename to FortranRuntime/lib/Runtime/pseudo-unit.cpp
index 526afd11d916e9..62c6b1df5071c7 100644
--- a/flang/runtime/pseudo-unit.cpp
+++ b/FortranRuntime/lib/Runtime/pseudo-unit.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/pseudo-unit.cpp -------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/ragged.cpp b/FortranRuntime/lib/Runtime/ragged.cpp
similarity index 97%
rename from flang/runtime/ragged.cpp
rename to FortranRuntime/lib/Runtime/ragged.cpp
index a4d9e541ba5311..681a800e29dca7 100644
--- a/flang/runtime/ragged.cpp
+++ b/FortranRuntime/lib/Runtime/ragged.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/ragged.cpp ------------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/random-templates.h b/FortranRuntime/lib/Runtime/random-templates.h
similarity index 96%
rename from flang/runtime/random-templates.h
rename to FortranRuntime/lib/Runtime/random-templates.h
index f34422f6f5d9ac..801484225bc211 100644
--- a/flang/runtime/random-templates.h
+++ b/FortranRuntime/lib/Runtime/random-templates.h
@@ -1,4 +1,4 @@
-//===-- runtime/random-templates.h ------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -9,10 +9,10 @@
 #ifndef FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_
 #define FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_
 
-#include "lock.h"
-#include "numeric-templates.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/descriptor.h"
+#include "lock.h"
+#include "numeric-templates.h"
 #include <algorithm>
 #include <random>
 
@@ -85,4 +85,4 @@ inline void Generate(const Descriptor &harvest) {
 
 } // namespace Fortran::runtime::random
 
-#endif // FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_
+#endif /* FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_ */
diff --git a/flang/runtime/random.cpp b/FortranRuntime/lib/Runtime/random.cpp
similarity index 98%
rename from flang/runtime/random.cpp
rename to FortranRuntime/lib/Runtime/random.cpp
index 69de9b8c96fb5d..8e1561960d48be 100644
--- a/flang/runtime/random.cpp
+++ b/FortranRuntime/lib/Runtime/random.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/random.cpp ------------------------------------------------===//
+//===-- 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,14 +10,14 @@
 // RANDOM_SEED.
 
 #include "flang/Runtime/random.h"
-#include "lock.h"
-#include "random-templates.h"
-#include "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 "lock.h"
+#include "random-templates.h"
+#include "terminator.h"
 #include <cmath>
 #include <cstdint>
 #include <limits>
diff --git a/flang/runtime/reduce.cpp b/FortranRuntime/lib/Runtime/reduce.cpp
similarity index 99%
rename from flang/runtime/reduce.cpp
rename to FortranRuntime/lib/Runtime/reduce.cpp
index 2f4bb6ea159cf4..4d33c2a714e5af 100644
--- a/flang/runtime/reduce.cpp
+++ b/FortranRuntime/lib/Runtime/reduce.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/reduce.cpp ------------------------------------------------===//
+//===-- 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/Runtime/descriptor.h"
 #include "reduction-templates.h"
 #include "terminator.h"
 #include "tools.h"
-#include "flang/Runtime/descriptor.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/reduction-templates.h b/FortranRuntime/lib/Runtime/reduction-templates.h
similarity index 99%
rename from flang/runtime/reduction-templates.h
rename to FortranRuntime/lib/Runtime/reduction-templates.h
index a51404c9637620..30ae641ba7b3ac 100644
--- a/flang/runtime/reduction-templates.h
+++ b/FortranRuntime/lib/Runtime/reduction-templates.h
@@ -1,4 +1,4 @@
-//===-- runtime/reduction-templates.h ---------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -21,11 +21,11 @@
 #ifndef FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_
 #define FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_
 
+#include "flang/Runtime/cpp-type.h"
+#include "flang/Runtime/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 {
@@ -412,4 +412,4 @@ template <int KIND> struct Norm2Helper {
 };
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_
+#endif /* FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_ */
diff --git a/flang/runtime/reduction.cpp b/FortranRuntime/lib/Runtime/reduction.cpp
similarity index 99%
rename from flang/runtime/reduction.cpp
rename to FortranRuntime/lib/Runtime/reduction.cpp
index 074a270cb50838..f4e1f2aa6818d5 100644
--- a/flang/runtime/reduction.cpp
+++ b/FortranRuntime/lib/Runtime/reduction.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/reduction.cpp ---------------------------------------------===//
+//===-- 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 "reduction-templates.h"
 #include "flang/Runtime/descriptor.h"
+#include "reduction-templates.h"
 #include <cinttypes>
 
 namespace Fortran::runtime {
diff --git a/flang/runtime/stack.h b/FortranRuntime/lib/Runtime/stack.h
similarity index 95%
rename from flang/runtime/stack.h
rename to FortranRuntime/lib/Runtime/stack.h
index b6e6edb595e9ad..dc5b6101d3da0f 100644
--- a/flang/runtime/stack.h
+++ b/FortranRuntime/lib/Runtime/stack.h
@@ -1,4 +1,4 @@
-//===-- runtime/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 FORTRAN_RUNTIME_STACK_H
-#define FORTRAN_RUNTIME_STACK_H
+#ifndef FORTRAN_RUNTIME_STACK_H_
+#define FORTRAN_RUNTIME_STACK_H_
 
-#include "terminator.h"
 #include "flang/Runtime/memory.h"
+#include "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 /* FORTRAN_RUNTIME_STACK_H_ */
diff --git a/flang/runtime/stat.cpp b/FortranRuntime/lib/Runtime/stat.cpp
similarity index 97%
rename from flang/runtime/stat.cpp
rename to FortranRuntime/lib/Runtime/stat.cpp
index 525a4e36cdc773..01ae922e080865 100644
--- a/flang/runtime/stat.cpp
+++ b/FortranRuntime/lib/Runtime/stat.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/stat.cpp --------------------------------------------------===//
+//===-- 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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "stat.h"
+#include "flang/Runtime/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
-#include "flang/Runtime/descriptor.h"
 
 namespace Fortran::runtime {
 RT_OFFLOAD_API_GROUP_BEGIN
diff --git a/flang/runtime/stat.h b/FortranRuntime/lib/Runtime/stat.h
similarity index 93%
rename from flang/runtime/stat.h
rename to FortranRuntime/lib/Runtime/stat.h
index 71faeb027d9085..eccd69024d726b 100644
--- a/flang/runtime/stat.h
+++ b/FortranRuntime/lib/Runtime/stat.h
@@ -1,4 +1,4 @@
-//===-- runtime/stat.h ------------------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -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 {
 
@@ -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 /* FORTRAN_RUNTIME_STAT_H_ */
diff --git a/flang/runtime/stop.cpp b/FortranRuntime/lib/Runtime/stop.cpp
similarity index 98%
rename from flang/runtime/stop.cpp
rename to FortranRuntime/lib/Runtime/stop.cpp
index cfb36b40840200..8465a53168e551 100644
--- a/flang/runtime/stop.cpp
+++ b/FortranRuntime/lib/Runtime/stop.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/stop.cpp --------------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/sum.cpp b/FortranRuntime/lib/Runtime/sum.cpp
similarity index 98%
rename from flang/runtime/sum.cpp
rename to FortranRuntime/lib/Runtime/sum.cpp
index 63d8c9029a0ef5..e33b77e20f0f11 100644
--- a/flang/runtime/sum.cpp
+++ b/FortranRuntime/lib/Runtime/sum.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/sum.cpp ---------------------------------------------------===//
+//===-- 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,9 +12,9 @@
 // cancellation on intermediate results by using "Kahan summation"
 // (basically the same as manual "double-double").
 
-#include "reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/reduction.h"
+#include "reduction-templates.h"
 #include <cfloat>
 #include <cinttypes>
 #include <complex>
diff --git a/flang/runtime/support.cpp b/FortranRuntime/lib/Runtime/support.cpp
similarity index 94%
rename from flang/runtime/support.cpp
rename to FortranRuntime/lib/Runtime/support.cpp
index a607120256d9d9..0a39ff24b0cafc 100644
--- a/flang/runtime/support.cpp
+++ b/FortranRuntime/lib/Runtime/support.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/support.cpp -----------------------------------------------===//
+//===-- 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 "type-info.h"
 #include "flang/Runtime/descriptor.h"
+#include "type-info.h"
 
 namespace Fortran::runtime {
 extern "C" {
diff --git a/flang/runtime/temporary-stack.cpp b/FortranRuntime/lib/Runtime/temporary-stack.cpp
similarity index 98%
rename from flang/runtime/temporary-stack.cpp
rename to FortranRuntime/lib/Runtime/temporary-stack.cpp
index 667b10e04dbd29..f944dfb7aa1471 100644
--- a/flang/runtime/temporary-stack.cpp
+++ b/FortranRuntime/lib/Runtime/temporary-stack.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/temporary-stack.cpp ---------------------------------------===//
+//===-- 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,11 +10,11 @@
 // temporaries. For use in HLFIR lowering.
 
 #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"
+#include "terminator.h"
 
 namespace {
 
diff --git a/flang/runtime/terminator.cpp b/FortranRuntime/lib/Runtime/terminator.cpp
similarity index 97%
rename from flang/runtime/terminator.cpp
rename to FortranRuntime/lib/Runtime/terminator.cpp
index bab9edc64fa35b..4146e28235511f 100644
--- a/flang/runtime/terminator.cpp
+++ b/FortranRuntime/lib/Runtime/terminator.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/terminate.cpp ---------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/terminator.h b/FortranRuntime/lib/Runtime/terminator.h
similarity index 97%
rename from flang/runtime/terminator.h
rename to FortranRuntime/lib/Runtime/terminator.h
index 609f059d6e0921..f475658b0eab3d 100644
--- a/flang/runtime/terminator.h
+++ b/FortranRuntime/lib/Runtime/terminator.h
@@ -1,4 +1,4 @@
-//===-- runtime/terminator.h ------------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -121,4 +121,4 @@ namespace Fortran::runtime::io {
 RT_API_ATTRS void FlushOutputOnCrash(const Terminator &);
 }
 
-#endif // FORTRAN_RUNTIME_TERMINATOR_H_
+#endif /* FORTRAN_RUNTIME_TERMINATOR_H_ */
diff --git a/flang/runtime/time-intrinsic.cpp b/FortranRuntime/lib/Runtime/time-intrinsic.cpp
similarity index 99%
rename from flang/runtime/time-intrinsic.cpp
rename to FortranRuntime/lib/Runtime/time-intrinsic.cpp
index e6f6e81c7b50cc..4b362c90c52f25 100644
--- a/flang/runtime/time-intrinsic.cpp
+++ b/FortranRuntime/lib/Runtime/time-intrinsic.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/time-intrinsic.cpp ----------------------------------------===//
+//===-- 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,10 +9,10 @@
 // Implements time-related intrinsic subroutines.
 
 #include "flang/Runtime/time-intrinsic.h"
-#include "terminator.h"
-#include "tools.h"
 #include "flang/Runtime/cpp-type.h"
 #include "flang/Runtime/descriptor.h"
+#include "terminator.h"
+#include "tools.h"
 #include <algorithm>
 #include <cstdint>
 #include <cstdio>
diff --git a/flang/runtime/tools.cpp b/FortranRuntime/lib/Runtime/tools.cpp
similarity index 99%
rename from flang/runtime/tools.cpp
rename to FortranRuntime/lib/Runtime/tools.cpp
index 73d6c2cf7e1d2b..d5c113a31fc501 100644
--- a/flang/runtime/tools.cpp
+++ b/FortranRuntime/lib/Runtime/tools.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/tools.cpp -------------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/tools.h b/FortranRuntime/lib/Runtime/tools.h
similarity index 99%
rename from flang/runtime/tools.h
rename to FortranRuntime/lib/Runtime/tools.h
index dc12e5c4533e2e..4058767ca283a9 100644
--- a/flang/runtime/tools.h
+++ b/FortranRuntime/lib/Runtime/tools.h
@@ -1,4 +1,4 @@
-//===-- runtime/tools.h -----------------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -9,13 +9,13 @@
 #ifndef FORTRAN_RUNTIME_TOOLS_H_
 #define FORTRAN_RUNTIME_TOOLS_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 "stat.h"
+#include "terminator.h"
 #include <cstring>
 #include <functional>
 #include <map>
@@ -535,4 +535,4 @@ RT_API_ATTRS void CreatePartialReductionResult(Descriptor &result,
     const char *intrinsic, TypeCode);
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_TOOLS_H_
+#endif /* FORTRAN_RUNTIME_TOOLS_H_ */
diff --git a/flang/runtime/transformational.cpp b/FortranRuntime/lib/Runtime/transformational.cpp
similarity index 99%
rename from flang/runtime/transformational.cpp
rename to FortranRuntime/lib/Runtime/transformational.cpp
index b6b204be4418c9..66dc5bd4939bae 100644
--- a/flang/runtime/transformational.cpp
+++ b/FortranRuntime/lib/Runtime/transformational.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/transformational.cpp --------------------------------------===//
+//===-- 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,10 +18,10 @@
 
 #include "flang/Runtime/transformational.h"
 #include "copy.h"
-#include "terminator.h"
-#include "tools.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/descriptor.h"
+#include "terminator.h"
+#include "tools.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/type-code.cpp b/FortranRuntime/lib/Runtime/type-code.cpp
similarity index 98%
rename from flang/runtime/type-code.cpp
rename to FortranRuntime/lib/Runtime/type-code.cpp
index cb1b944433aae5..2709ca1be75a53 100644
--- a/flang/runtime/type-code.cpp
+++ b/FortranRuntime/lib/Runtime/type-code.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/type-code.cpp ---------------------------------------------===//
+//===-- 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.
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/type-code.h"
+#include <cstdint>
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/type-info.cpp b/FortranRuntime/lib/Runtime/type-info.cpp
similarity index 99%
rename from flang/runtime/type-info.cpp
rename to FortranRuntime/lib/Runtime/type-info.cpp
index cb18c5669b5ffc..24fc9c33d92819 100644
--- a/flang/runtime/type-info.cpp
+++ b/FortranRuntime/lib/Runtime/type-info.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/type-info.cpp ---------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/type-info.h b/FortranRuntime/lib/Runtime/type-info.h
similarity index 99%
rename from flang/runtime/type-info.h
rename to FortranRuntime/lib/Runtime/type-info.h
index 32403b1db5169e..ff3523bcb2b8eb 100644
--- a/flang/runtime/type-info.h
+++ b/FortranRuntime/lib/Runtime/type-info.h
@@ -1,4 +1,4 @@
-//===-- runtime/type-info.h -------------------------------------*- C++ -*-===//
+//===-- lib/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.
@@ -12,11 +12,11 @@
 // A C++ perspective of the derived type description schemata in
 // flang/module/__fortran_type_info.f90.
 
-#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 "terminator.h"
 #include <cinttypes>
 #include <memory>
 
@@ -321,4 +321,4 @@ class DerivedType {
 };
 
 } // namespace Fortran::runtime::typeInfo
-#endif // FORTRAN_RUNTIME_TYPE_INFO_H_
+#endif /* FORTRAN_RUNTIME_TYPE_INFO_H_ */
diff --git a/flang/runtime/unit-map.cpp b/FortranRuntime/lib/Runtime/unit-map.cpp
similarity index 97%
rename from flang/runtime/unit-map.cpp
rename to FortranRuntime/lib/Runtime/unit-map.cpp
index 684a9b9e20b97a..93958be8df7ea5 100644
--- a/flang/runtime/unit-map.cpp
+++ b/FortranRuntime/lib/Runtime/unit-map.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/unit-map.cpp ----------------------------------------------===//
+//===-- 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/runtime/unit-map.h b/FortranRuntime/lib/Runtime/unit-map.h
similarity index 96%
rename from flang/runtime/unit-map.h
rename to FortranRuntime/lib/Runtime/unit-map.h
index 6f1e01bb1e64ac..4e61246f9a2d86 100644
--- a/flang/runtime/unit-map.h
+++ b/FortranRuntime/lib/Runtime/unit-map.h
@@ -1,4 +1,4 @@
-//===-- runtime/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.
@@ -12,10 +12,10 @@
 #ifndef FORTRAN_RUNTIME_UNIT_MAP_H_
 #define FORTRAN_RUNTIME_UNIT_MAP_H_
 
-#include "lock.h"
-#include "unit.h"
 #include "flang/Common/fast-int-set.h"
 #include "flang/Runtime/memory.h"
+#include "lock.h"
+#include "unit.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 /* FORTRAN_RUNTIME_UNIT_MAP_H_ */
diff --git a/flang/runtime/unit.cpp b/FortranRuntime/lib/Runtime/unit.cpp
similarity index 99%
rename from flang/runtime/unit.cpp
rename to FortranRuntime/lib/Runtime/unit.cpp
index 4aee8397d477e7..496679ee8ce5f4 100644
--- a/flang/runtime/unit.cpp
+++ b/FortranRuntime/lib/Runtime/unit.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/unit.cpp --------------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/unit.h b/FortranRuntime/lib/Runtime/unit.h
similarity index 98%
rename from flang/runtime/unit.h
rename to FortranRuntime/lib/Runtime/unit.h
index a3ea2686816803..993fbf2977cebf 100644
--- a/flang/runtime/unit.h
+++ b/FortranRuntime/lib/Runtime/unit.h
@@ -1,4 +1,4 @@
-//===-- runtime/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,21 +8,21 @@
 
 // Fortran external I/O units
 
-#ifndef FORTRAN_RUNTIME_IO_UNIT_H_
-#define FORTRAN_RUNTIME_IO_UNIT_H_
+#ifndef FORTRAN_RUNTIME_UNIT_H_
+#define FORTRAN_RUNTIME_UNIT_H_
 
 #include "buffer.h"
 #include "connection.h"
 #include "environment.h"
 #include "file.h"
+#include "flang/Common/constexpr-bitset.h"
+#include "flang/Common/optional.h"
+#include "flang/Runtime/memory.h"
 #include "format.h"
 #include "io-error.h"
 #include "io-stmt.h"
 #include "lock.h"
 #include "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 /* FORTRAN_RUNTIME_UNIT_H_ */
diff --git a/flang/runtime/utf.cpp b/FortranRuntime/lib/Runtime/utf.cpp
similarity index 98%
rename from flang/runtime/utf.cpp
rename to FortranRuntime/lib/Runtime/utf.cpp
index b09819cb2f736b..635451153d39a6 100644
--- a/flang/runtime/utf.cpp
+++ b/FortranRuntime/lib/Runtime/utf.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/utf.cpp ---------------------------------------------------===//
+//===-- 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.
diff --git a/flang/runtime/utf.h b/FortranRuntime/lib/Runtime/utf.h
similarity index 96%
rename from flang/runtime/utf.h
rename to FortranRuntime/lib/Runtime/utf.h
index 10c2d61484217a..35c03fd4cdded5 100644
--- a/flang/runtime/utf.h
+++ b/FortranRuntime/lib/Runtime/utf.h
@@ -1,4 +1,4 @@
-//===-- runtime/utf.h -----------------------------------------------------===//
+//===-- lib/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.
@@ -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 /* FORTRAN_RUNTIME_UTF_H_ */
diff --git a/flang/unittests/Evaluate/fp-testing.cpp b/FortranRuntime/lib/Testing/fp-testing.cpp
similarity index 98%
rename from flang/unittests/Evaluate/fp-testing.cpp
rename to FortranRuntime/lib/Testing/fp-testing.cpp
index 1a1d7425d58249..3301d2d8efb15f 100644
--- a/flang/unittests/Evaluate/fp-testing.cpp
+++ b/FortranRuntime/lib/Testing/fp-testing.cpp
@@ -1,4 +1,4 @@
-#include "fp-testing.h"
+#include "flang/Testing/fp-testing.h"
 #include "llvm/Support/Errno.h"
 #include <cstdio>
 #include <cstdlib>
@@ -7,8 +7,8 @@
 #include <xmmintrin.h>
 #endif
 
-using Fortran::common::RealFlag;
 using Fortran::common::RoundingMode;
+using Fortran::common::RealFlag;
 
 ScopedHostFloatingPointEnvironment::ScopedHostFloatingPointEnvironment(
 #if __x86_64__
diff --git a/flang/unittests/Evaluate/testing.cpp b/FortranRuntime/lib/Testing/testing.cpp
similarity index 88%
rename from flang/unittests/Evaluate/testing.cpp
rename to FortranRuntime/lib/Testing/testing.cpp
index b2f73bf1b265a7..37f9d88f4886b4 100644
--- a/flang/unittests/Evaluate/testing.cpp
+++ b/FortranRuntime/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/module/.clang-format b/FortranRuntime/module/.clang-format
similarity index 100%
rename from flang/module/.clang-format
rename to FortranRuntime/module/.clang-format
diff --git a/flang/module/__cuda_builtins.f90 b/FortranRuntime/module/__cuda_builtins.f90
similarity index 100%
rename from flang/module/__cuda_builtins.f90
rename to FortranRuntime/module/__cuda_builtins.f90
diff --git a/flang/module/__fortran_builtins.f90 b/FortranRuntime/module/__fortran_builtins.f90
similarity index 100%
rename from flang/module/__fortran_builtins.f90
rename to FortranRuntime/module/__fortran_builtins.f90
diff --git a/flang/module/__fortran_ieee_exceptions.f90 b/FortranRuntime/module/__fortran_ieee_exceptions.f90
similarity index 100%
rename from flang/module/__fortran_ieee_exceptions.f90
rename to FortranRuntime/module/__fortran_ieee_exceptions.f90
diff --git a/flang/module/__fortran_type_info.f90 b/FortranRuntime/module/__fortran_type_info.f90
similarity index 100%
rename from flang/module/__fortran_type_info.f90
rename to FortranRuntime/module/__fortran_type_info.f90
diff --git a/flang/module/__ppc_intrinsics.f90 b/FortranRuntime/module/__ppc_intrinsics.f90
similarity index 100%
rename from flang/module/__ppc_intrinsics.f90
rename to FortranRuntime/module/__ppc_intrinsics.f90
diff --git a/flang/module/__ppc_types.f90 b/FortranRuntime/module/__ppc_types.f90
similarity index 100%
rename from flang/module/__ppc_types.f90
rename to FortranRuntime/module/__ppc_types.f90
diff --git a/flang/module/cudadevice.f90 b/FortranRuntime/module/cudadevice.f90
similarity index 96%
rename from flang/module/cudadevice.f90
rename to FortranRuntime/module/cudadevice.f90
index 0224ecfdde7c60..dd487f6ed1ffee 100644
--- a/flang/module/cudadevice.f90
+++ b/FortranRuntime/module/cudadevice.f90
@@ -1,4 +1,4 @@
-!===-- module/cudedevice.f90 -----------------------------------------------===!
+!===-- module/cudadevice.f90 -----------------------------------------------===!
 !
 ! 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/module/ieee_arithmetic.f90 b/FortranRuntime/module/ieee_arithmetic.f90
similarity index 100%
rename from flang/module/ieee_arithmetic.f90
rename to FortranRuntime/module/ieee_arithmetic.f90
diff --git a/flang/module/ieee_exceptions.f90 b/FortranRuntime/module/ieee_exceptions.f90
similarity index 100%
rename from flang/module/ieee_exceptions.f90
rename to FortranRuntime/module/ieee_exceptions.f90
diff --git a/flang/module/ieee_features.f90 b/FortranRuntime/module/ieee_features.f90
similarity index 100%
rename from flang/module/ieee_features.f90
rename to FortranRuntime/module/ieee_features.f90
diff --git a/flang/module/iso_c_binding.f90 b/FortranRuntime/module/iso_c_binding.f90
similarity index 100%
rename from flang/module/iso_c_binding.f90
rename to FortranRuntime/module/iso_c_binding.f90
diff --git a/flang/module/iso_fortran_env.f90 b/FortranRuntime/module/iso_fortran_env.f90
similarity index 100%
rename from flang/module/iso_fortran_env.f90
rename to FortranRuntime/module/iso_fortran_env.f90
diff --git a/flang/module/mma.f90 b/FortranRuntime/module/mma.f90
similarity index 98%
rename from flang/module/mma.f90
rename to FortranRuntime/module/mma.f90
index 4c41822e000a3d..14aab69035a334 100644
--- a/flang/module/mma.f90
+++ b/FortranRuntime/module/mma.f90
@@ -55,9 +55,18 @@ pure __vector_pair function func_vpi0vp(arg1, arg2); \
     !dir$ ignore_tkr(r) arg2; \
   end function;
 
-  FUNC_VPI0VI(1) FUNC_VPI0VI(2) FUNC_VPI0VI(4) FUNC_VPI0VI(8)
-  FUNC_VPI0VU(1) FUNC_VPI0VU(2) FUNC_VPI0VU(4) FUNC_VPI0VU(8)
-  FUNC_VPI0VR(4) FUNC_VPI0VR(8)
+! FIXME: Potential Flang bug: combining multiple of those on a single line breaks after preprocessing as an explicit step as done by CMake
+! Line counting is also wrong
+  FUNC_VPI0VI(1)
+  FUNC_VPI0VI(2)
+  FUNC_VPI0VI(4)
+  FUNC_VPI0VI(8)
+  FUNC_VPI0VU(1)
+  FUNC_VPI0VU(2)
+  FUNC_VPI0VU(4)
+  FUNC_VPI0VU(8)
+  FUNC_VPI0VR(4)
+  FUNC_VPI0VR(8)
   FUNC_VPI0VP
 
 #undef FUNC_VPI0VP
@@ -144,14 +153,26 @@ elemental subroutine sub_vpvr##VKIND##vr##VKIND(pair, arg1, arg2); \
     vector(real(VKIND)), intent(in) :: arg1, arg2; \
   end subroutine ;
 
-  ELEM_SUB_VPVIVI(1) ELEM_SUB_VPVIVI(2)
-  ELEM_SUB_VPVIVI(4) ELEM_SUB_VPVIVI(8)
-  ELEM_SUB_VPVUVU(1) ELEM_SUB_VPVUVU(2)
-  ELEM_SUB_VPVUVU(4) ELEM_SUB_VPVUVU(8)
-  ELEM_SUB_VPVRVR(4) ELEM_SUB_VPVRVR(8)
-  SUB_VPI0VI(1) SUB_VPI0VI(2) SUB_VPI0VI(4) SUB_VPI0VI(8)
-  SUB_VPI0VU(1) SUB_VPI0VU(2) SUB_VPI0VU(4) SUB_VPI0VU(8)
-  SUB_VPI0VR(4) SUB_VPI0VR(8)
+  ELEM_SUB_VPVIVI(1)
+  ELEM_SUB_VPVIVI(2)
+  ELEM_SUB_VPVIVI(4)
+  ELEM_SUB_VPVIVI(8)
+  ELEM_SUB_VPVUVU(1)
+  ELEM_SUB_VPVUVU(2)
+  ELEM_SUB_VPVUVU(4)
+  ELEM_SUB_VPVUVU(8)
+  ELEM_SUB_VPVRVR(4)
+  ELEM_SUB_VPVRVR(8)
+  SUB_VPI0VI(1)
+  SUB_VPI0VI(2)
+  SUB_VPI0VI(4)
+  SUB_VPI0VI(8)
+  SUB_VPI0VU(1)
+  SUB_VPI0VU(2)
+  SUB_VPI0VU(4)
+  SUB_VPI0VU(8)
+  SUB_VPI0VR(4)
+  SUB_VPI0VR(8)
 
 #undef ELEM_SUB_VPVIVI
 #undef ELEM_SUB_VPVUVU
diff --git a/flang/unittests/Common/CMakeLists.txt b/FortranRuntime/unittests/Common/CMakeLists.txt
similarity index 100%
rename from flang/unittests/Common/CMakeLists.txt
rename to FortranRuntime/unittests/Common/CMakeLists.txt
diff --git a/flang/unittests/Common/FastIntSetTest.cpp b/FortranRuntime/unittests/Common/FastIntSetTest.cpp
similarity index 97%
rename from flang/unittests/Common/FastIntSetTest.cpp
rename to FortranRuntime/unittests/Common/FastIntSetTest.cpp
index bd1b953fa16631..a36a334e370eb9 100644
--- a/flang/unittests/Common/FastIntSetTest.cpp
+++ b/FortranRuntime/unittests/Common/FastIntSetTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Common/FastIntSetTest.cpp ---------------*- C++ -*-===//
+//===-- unittests/Common/FastIntSetTest.cpp ---------------------*- 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 "gtest/gtest.h"
 #include "flang/Common/fast-int-set.h"
+#include "gtest/gtest.h"
 #include <optional>
 
 TEST(FastIntSetTests, Sanity) {
diff --git a/flang/unittests/Decimal/CMakeLists.txt b/FortranRuntime/unittests/Decimal/CMakeLists.txt
similarity index 100%
rename from flang/unittests/Decimal/CMakeLists.txt
rename to FortranRuntime/unittests/Decimal/CMakeLists.txt
diff --git a/flang/unittests/Decimal/quick-sanity-test.cpp b/FortranRuntime/unittests/Decimal/quick-sanity-test.cpp
similarity index 91%
rename from flang/unittests/Decimal/quick-sanity-test.cpp
rename to FortranRuntime/unittests/Decimal/quick-sanity-test.cpp
index dafb075307ab6a..0e8ff0ce48b3c6 100644
--- a/flang/unittests/Decimal/quick-sanity-test.cpp
+++ b/FortranRuntime/unittests/Decimal/quick-sanity-test.cpp
@@ -1,4 +1,12 @@
-#include "flang/Decimal/decimal.h"
+//===-- unittests/Decimal/quick-sanity-test.cpp -----------------*- 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/decimal.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cinttypes>
 #include <cstdio>
diff --git a/flang/unittests/Decimal/thorough-test.cpp b/FortranRuntime/unittests/Decimal/thorough-test.cpp
similarity index 85%
rename from flang/unittests/Decimal/thorough-test.cpp
rename to FortranRuntime/unittests/Decimal/thorough-test.cpp
index 46951f33eb8fee..0648b61d7c1cda 100644
--- a/flang/unittests/Decimal/thorough-test.cpp
+++ b/FortranRuntime/unittests/Decimal/thorough-test.cpp
@@ -1,4 +1,12 @@
-#include "flang/Decimal/decimal.h"
+//===-- unittests/Decimal/thorough-test.cpp ---------------------*- 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/decimal.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cinttypes>
 #include <cstdio>
diff --git a/FortranRuntime/unittests/Evaluate/CMakeLists.txt b/FortranRuntime/unittests/Evaluate/CMakeLists.txt
new file mode 100644
index 00000000000000..b4cc72b748efd5
--- /dev/null
+++ b/FortranRuntime/unittests/Evaluate/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_flang_nongtest_unittest(reshape
+  FortranEvaluateTesting
+  FortranSemantics
+  FortranEvaluate
+  FortranRuntime
+)
diff --git a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp b/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp
similarity index 98%
rename from flang/unittests/Evaluate/ISO-Fortran-binding.cpp
rename to FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp
index 3c98363f900466..d2546e0c22d2d6 100644
--- a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp
+++ b/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp
@@ -1,6 +1,14 @@
-#include "testing.h"
-#include "flang/ISO_Fortran_binding_wrapper.h"
+//===-- 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/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/FortranRuntime/unittests/Evaluate/reshape.cpp
similarity index 88%
rename from flang/unittests/Evaluate/reshape.cpp
rename to FortranRuntime/unittests/Evaluate/reshape.cpp
index 5d138cd3d88d98..a93afd2a3c90cd 100644
--- a/flang/unittests/Evaluate/reshape.cpp
+++ b/FortranRuntime/unittests/Evaluate/reshape.cpp
@@ -1,6 +1,14 @@
-#include "testing.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/Runtime/descriptor.h"
 #include "flang/Runtime/transformational.h"
+#include "flang/Testing/testing.h"
 #include <cinttypes>
 
 using namespace Fortran::common;
diff --git a/flang/unittests/Runtime/AccessTest.cpp b/FortranRuntime/unittests/Runtime/AccessTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/AccessTest.cpp
rename to FortranRuntime/unittests/Runtime/AccessTest.cpp
index 66f19f78c7cfb6..3e9feaf945b66d 100644
--- a/flang/unittests/Runtime/AccessTest.cpp
+++ b/FortranRuntime/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.
@@ -10,9 +10,9 @@
 #ifndef _WIN32
 
 #include "CrashHandlerFixture.h"
-#include "gtest/gtest.h"
 #include "flang/Runtime/extensions.h"
 #include "llvm/ADT/Twine.h"
+#include "gtest/gtest.h"
 
 #include <fcntl.h>
 #include <sys/stat.h>
diff --git a/flang/unittests/Runtime/Allocatable.cpp b/FortranRuntime/unittests/Runtime/Allocatable.cpp
similarity index 98%
rename from flang/unittests/Runtime/Allocatable.cpp
rename to FortranRuntime/unittests/Runtime/Allocatable.cpp
index f15f26bfd9c575..c01f85598d21ed 100644
--- a/flang/unittests/Runtime/Allocatable.cpp
+++ b/FortranRuntime/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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/allocatable.h"
-#include "gtest/gtest.h"
 #include "tools.h"
+#include "gtest/gtest.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang/unittests/Runtime/ArrayConstructor.cpp b/FortranRuntime/unittests/Runtime/ArrayConstructor.cpp
similarity index 99%
rename from flang/unittests/Runtime/ArrayConstructor.cpp
rename to FortranRuntime/unittests/Runtime/ArrayConstructor.cpp
index 9d78da79623613..9011da304b6bc3 100644
--- a/flang/unittests/Runtime/ArrayConstructor.cpp
+++ b/FortranRuntime/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 "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 "tools.h"
+#include "gtest/gtest.h"
 
 #include <memory>
 
diff --git a/flang/unittests/Runtime/BufferTest.cpp b/FortranRuntime/unittests/Runtime/BufferTest.cpp
similarity index 97%
rename from flang/unittests/Runtime/BufferTest.cpp
rename to FortranRuntime/unittests/Runtime/BufferTest.cpp
index 0632324b25d22e..9a7dd86d0c1dc6 100644
--- a/flang/unittests/Runtime/BufferTest.cpp
+++ b/FortranRuntime/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 "../../lib/Runtime/buffer.h"
 #include "CrashHandlerFixture.h"
 #include "gtest/gtest.h"
 #include <algorithm>
diff --git a/flang/unittests/Runtime/CMakeLists.txt b/FortranRuntime/unittests/Runtime/CMakeLists.txt
similarity index 100%
rename from flang/unittests/Runtime/CMakeLists.txt
rename to FortranRuntime/unittests/Runtime/CMakeLists.txt
diff --git a/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp b/FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp
similarity index 95%
rename from flang/unittests/Runtime/CUDA/AllocatorCUF.cpp
rename to FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp
index b51ff0ac006cc6..d2c1600af8c631 100644
--- a/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp
+++ b/FortranRuntime/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,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#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 "gtest/gtest.h"
 
 #include "cuda_runtime.h"
 
diff --git a/flang/unittests/Runtime/CUDA/CMakeLists.txt b/FortranRuntime/unittests/Runtime/CUDA/CMakeLists.txt
similarity index 100%
rename from flang/unittests/Runtime/CUDA/CMakeLists.txt
rename to FortranRuntime/unittests/Runtime/CUDA/CMakeLists.txt
diff --git a/flang/unittests/Runtime/CharacterTest.cpp b/FortranRuntime/unittests/Runtime/CharacterTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/CharacterTest.cpp
rename to FortranRuntime/unittests/Runtime/CharacterTest.cpp
index e54fd8a5075f64..8829f5e43265b0 100644
--- a/flang/unittests/Runtime/CharacterTest.cpp
+++ b/FortranRuntime/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.
@@ -10,8 +10,8 @@
 // in Fortran.
 
 #include "flang/Runtime/character.h"
-#include "gtest/gtest.h"
 #include "flang/Runtime/descriptor.h"
+#include "gtest/gtest.h"
 #include <cstring>
 #include <functional>
 #include <tuple>
diff --git a/flang/unittests/Runtime/CommandTest.cpp b/FortranRuntime/unittests/Runtime/CommandTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/CommandTest.cpp
rename to FortranRuntime/unittests/Runtime/CommandTest.cpp
index b0c43ba01d8f33..aa79ce381ba8d0 100644
--- a/flang/unittests/Runtime/CommandTest.cpp
+++ b/FortranRuntime/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.
@@ -7,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/command.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/execute.h"
 #include "flang/Runtime/extensions.h"
 #include "flang/Runtime/main.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
 #include <cstddef>
 #include <cstdlib>
 
diff --git a/flang/unittests/Runtime/Complex.cpp b/FortranRuntime/unittests/Runtime/Complex.cpp
similarity index 100%
rename from flang/unittests/Runtime/Complex.cpp
rename to FortranRuntime/unittests/Runtime/Complex.cpp
diff --git a/flang/unittests/Runtime/CrashHandlerFixture.cpp b/FortranRuntime/unittests/Runtime/CrashHandlerFixture.cpp
similarity index 92%
rename from flang/unittests/Runtime/CrashHandlerFixture.cpp
rename to FortranRuntime/unittests/Runtime/CrashHandlerFixture.cpp
index 811603337e6608..5e0b746c7e974a 100644
--- a/flang/unittests/Runtime/CrashHandlerFixture.cpp
+++ b/FortranRuntime/unittests/Runtime/CrashHandlerFixture.cpp
@@ -1,4 +1,4 @@
-//===-- 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.
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 #include "CrashHandlerFixture.h"
-#include "../../runtime/terminator.h"
+#include "../../lib/Runtime/terminator.h"
 #include <cstdarg>
 #include <cstdlib>
 
diff --git a/flang/unittests/Runtime/CrashHandlerFixture.h b/FortranRuntime/unittests/Runtime/CrashHandlerFixture.h
similarity index 70%
rename from flang/unittests/Runtime/CrashHandlerFixture.h
rename to FortranRuntime/unittests/Runtime/CrashHandlerFixture.h
index fe0ee0da5204e4..46805775af0b39 100644
--- a/flang/unittests/Runtime/CrashHandlerFixture.h
+++ b/FortranRuntime/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,12 @@
 /// with expected message.
 //
 //===----------------------------------------------------------------------===//
-#ifndef LLVM_FLANG_UNITTESTS_RUNTIMEGTEST_CRASHHANDLERFIXTURE_H
-#define LLVM_FLANG_UNITTESTS_RUNTIMEGTEST_CRASHHANDLERFIXTURE_H
+#ifndef FORTRAN_UNITTESTS_RUNTIME_CRASHHANDLERFIXTURE_H_
+#define FORTRAN_UNITTESTS_RUNTIME_CRASHHANDLERFIXTURE_H_
 #include <gtest/gtest.h>
 
 struct CrashHandlerFixture : testing::Test {
   void SetUp();
 };
 
-#endif
+#endif /* FORTRAN_UNITTESTS_RUNTIME_CRASHHANDLERFIXTURE_H_ */
diff --git a/flang/unittests/Runtime/Derived.cpp b/FortranRuntime/unittests/Runtime/Derived.cpp
similarity index 96%
rename from flang/unittests/Runtime/Derived.cpp
rename to FortranRuntime/unittests/Runtime/Derived.cpp
index 019d5e8309e4a0..11b732fe10b790 100644
--- a/flang/unittests/Runtime/Derived.cpp
+++ b/FortranRuntime/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.
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "gtest/gtest.h"
-#include "tools.h"
 #include "flang/Runtime/derived-api.h"
 #include "flang/Runtime/descriptor.h"
+#include "tools.h"
+#include "gtest/gtest.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang/unittests/Runtime/ExternalIOTest.cpp b/FortranRuntime/unittests/Runtime/ExternalIOTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/ExternalIOTest.cpp
rename to FortranRuntime/unittests/Runtime/ExternalIOTest.cpp
index 13327964e12a48..00c2fd76ce0c04 100644
--- a/flang/unittests/Runtime/ExternalIOTest.cpp
+++ b/FortranRuntime/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.
@@ -11,12 +11,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "gtest/gtest.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/io-api.h"
 #include "flang/Runtime/main.h"
 #include "flang/Runtime/stop.h"
 #include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
 #include <cstring>
 #include <string_view>
 
diff --git a/flang/unittests/Runtime/Format.cpp b/FortranRuntime/unittests/Runtime/Format.cpp
similarity index 96%
rename from flang/unittests/Runtime/Format.cpp
rename to FortranRuntime/unittests/Runtime/Format.cpp
index 01803c628de26a..f1447608917f2d 100644
--- a/flang/unittests/Runtime/Format.cpp
+++ b/FortranRuntime/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 "../../lib/Runtime/connection.h"
+#include "../../lib/Runtime/format-implementation.h"
+#include "../../lib/Runtime/io-error.h"
 #include <optional>
 #include <string>
 #include <tuple>
diff --git a/flang/unittests/Runtime/Inquiry.cpp b/FortranRuntime/unittests/Runtime/Inquiry.cpp
similarity index 98%
rename from flang/unittests/Runtime/Inquiry.cpp
rename to FortranRuntime/unittests/Runtime/Inquiry.cpp
index 3b523e992a3179..204a97a1088ac0 100644
--- a/flang/unittests/Runtime/Inquiry.cpp
+++ b/FortranRuntime/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 "tools.h"
+#include "gtest/gtest.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang/unittests/Runtime/ListInputTest.cpp b/FortranRuntime/unittests/Runtime/ListInputTest.cpp
similarity index 98%
rename from flang/unittests/Runtime/ListInputTest.cpp
rename to FortranRuntime/unittests/Runtime/ListInputTest.cpp
index a4eba5283add68..4c30d6ed750141 100644
--- a/flang/unittests/Runtime/ListInputTest.cpp
+++ b/FortranRuntime/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.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "../../lib/Runtime/io-error.h"
 #include "CrashHandlerFixture.h"
-#include "../../runtime/io-error.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/io-api.h"
 
diff --git a/flang/unittests/Runtime/LogicalFormatTest.cpp b/FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp
similarity index 96%
rename from flang/unittests/Runtime/LogicalFormatTest.cpp
rename to FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp
index a2c19d1e1ca948..928fddec50c874 100644
--- a/flang/unittests/Runtime/LogicalFormatTest.cpp
+++ b/FortranRuntime/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.
diff --git a/flang/unittests/Runtime/Matmul.cpp b/FortranRuntime/unittests/Runtime/Matmul.cpp
similarity index 99%
rename from flang/unittests/Runtime/Matmul.cpp
rename to FortranRuntime/unittests/Runtime/Matmul.cpp
index c3fed9b972df2a..cfa5d18cc36d33 100644
--- a/flang/unittests/Runtime/Matmul.cpp
+++ b/FortranRuntime/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 "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/type-code.h"
+#include "tools.h"
+#include "gtest/gtest.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang/unittests/Runtime/MatmulTranspose.cpp b/FortranRuntime/unittests/Runtime/MatmulTranspose.cpp
similarity index 99%
rename from flang/unittests/Runtime/MatmulTranspose.cpp
rename to FortranRuntime/unittests/Runtime/MatmulTranspose.cpp
index c582e945dc7c93..146c2283fb1aca 100644
--- a/flang/unittests/Runtime/MatmulTranspose.cpp
+++ b/FortranRuntime/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 "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"
+#include "tools.h"
+#include "gtest/gtest.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang/unittests/Runtime/MiscIntrinsic.cpp b/FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp
similarity index 98%
rename from flang/unittests/Runtime/MiscIntrinsic.cpp
rename to FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp
index 7e19ed250bdc05..08229b5e48f0dd 100644
--- a/flang/unittests/Runtime/MiscIntrinsic.cpp
+++ b/FortranRuntime/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 "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
 #include "flang/Runtime/descriptor.h"
+#include "tools.h"
+#include "gtest/gtest.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang/unittests/Runtime/Namelist.cpp b/FortranRuntime/unittests/Runtime/Namelist.cpp
similarity index 99%
rename from flang/unittests/Runtime/Namelist.cpp
rename to FortranRuntime/unittests/Runtime/Namelist.cpp
index 9037fa15a97cb3..7b834dec49c3c4 100644
--- a/flang/unittests/Runtime/Namelist.cpp
+++ b/FortranRuntime/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,11 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "../../runtime/namelist.h"
+#include "../../lib/Runtime/namelist.h"
 #include "CrashHandlerFixture.h"
-#include "tools.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/io-api.h"
+#include "tools.h"
 #include <algorithm>
 #include <cinttypes>
 #include <complex>
diff --git a/flang/unittests/Runtime/Numeric.cpp b/FortranRuntime/unittests/Runtime/Numeric.cpp
similarity index 99%
rename from flang/unittests/Runtime/Numeric.cpp
rename to FortranRuntime/unittests/Runtime/Numeric.cpp
index 799756aab3839a..fb595ae262c324 100644
--- a/flang/unittests/Runtime/Numeric.cpp
+++ b/FortranRuntime/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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/numeric.h"
-#include "gtest/gtest.h"
 #include "flang/Common/float128.h"
+#include "gtest/gtest.h"
 #include <cmath>
 #include <limits>
 
diff --git a/flang/unittests/Runtime/NumericalFormatTest.cpp b/FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/NumericalFormatTest.cpp
rename to FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp
index f0055153203508..8a1dd6de1449b9 100644
--- a/flang/unittests/Runtime/NumericalFormatTest.cpp
+++ b/FortranRuntime/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.
diff --git a/flang/unittests/Runtime/Pointer.cpp b/FortranRuntime/unittests/Runtime/Pointer.cpp
similarity index 98%
rename from flang/unittests/Runtime/Pointer.cpp
rename to FortranRuntime/unittests/Runtime/Pointer.cpp
index 4ce13ebc50a565..a05bd70a64bb9f 100644
--- a/flang/unittests/Runtime/Pointer.cpp
+++ b/FortranRuntime/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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/pointer.h"
-#include "gtest/gtest.h"
-#include "tools.h"
 #include "flang/Runtime/descriptor.h"
+#include "tools.h"
+#include "gtest/gtest.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang/unittests/Runtime/Ragged.cpp b/FortranRuntime/unittests/Runtime/Ragged.cpp
similarity index 94%
rename from flang/unittests/Runtime/Ragged.cpp
rename to FortranRuntime/unittests/Runtime/Ragged.cpp
index 5049bc83405f17..feadd032f59bd4 100644
--- a/flang/unittests/Runtime/Ragged.cpp
+++ b/FortranRuntime/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/FortranRuntime/unittests/Runtime/Random.cpp
similarity index 97%
rename from flang/unittests/Runtime/Random.cpp
rename to FortranRuntime/unittests/Runtime/Random.cpp
index cb739b94514290..4e4b59cbcf40e7 100644
--- a/flang/unittests/Runtime/Random.cpp
+++ b/FortranRuntime/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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime//random.h"
-#include "gtest/gtest.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/type-code.h"
+#include "gtest/gtest.h"
 #include <cmath>
 
 using namespace Fortran::runtime;
diff --git a/flang/unittests/Runtime/Reduction.cpp b/FortranRuntime/unittests/Runtime/Reduction.cpp
similarity index 99%
rename from flang/unittests/Runtime/Reduction.cpp
rename to FortranRuntime/unittests/Runtime/Reduction.cpp
index 25eb5fd760eadb..c35f6e2fa6a41b 100644
--- a/flang/unittests/Runtime/Reduction.cpp
+++ b/FortranRuntime/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 "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 "tools.h"
+#include "gtest/gtest.h"
 #include <cstdint>
 #include <cstring>
 #include <string>
diff --git a/flang/unittests/Runtime/RuntimeCrashTest.cpp b/FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp
similarity index 98%
rename from flang/unittests/Runtime/RuntimeCrashTest.cpp
rename to FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp
index a649051fdca0c5..61580a8d46792f 100644
--- a/flang/unittests/Runtime/RuntimeCrashTest.cpp
+++ b/FortranRuntime/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.
@@ -10,11 +10,11 @@
 /// runtime components and ensure the test fixture handles crashes as we expect.
 //
 //===----------------------------------------------------------------------===//
+#include "../../lib/Runtime/terminator.h"
 #include "CrashHandlerFixture.h"
-#include "tools.h"
-#include "../../runtime/terminator.h"
 #include "flang/Runtime/io-api.h"
 #include "flang/Runtime/transformational.h"
+#include "tools.h"
 #include <gtest/gtest.h>
 
 using namespace Fortran::runtime;
diff --git a/flang/unittests/Runtime/Stop.cpp b/FortranRuntime/unittests/Runtime/Stop.cpp
similarity index 96%
rename from flang/unittests/Runtime/Stop.cpp
rename to FortranRuntime/unittests/Runtime/Stop.cpp
index b13602eaee5ea6..5fd8deaad21d6b 100644
--- a/flang/unittests/Runtime/Stop.cpp
+++ b/FortranRuntime/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.
@@ -10,8 +10,8 @@
 //
 //===----------------------------------------------------------------------===//
 #include "flang/Runtime/stop.h"
+#include "../../lib/Runtime/environment.h"
 #include "CrashHandlerFixture.h"
-#include "../../runtime/environment.h"
 #include <cstdlib>
 #include <gtest/gtest.h>
 
diff --git a/flang/unittests/Runtime/Support.cpp b/FortranRuntime/unittests/Runtime/Support.cpp
similarity index 97%
rename from flang/unittests/Runtime/Support.cpp
rename to FortranRuntime/unittests/Runtime/Support.cpp
index 9d1a417fdbf426..38c0d6efaf9db7 100644
--- a/flang/unittests/Runtime/Support.cpp
+++ b/FortranRuntime/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 "tools.h"
+#include "gtest/gtest.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang/unittests/Runtime/TemporaryStack.cpp b/FortranRuntime/unittests/Runtime/TemporaryStack.cpp
similarity index 98%
rename from flang/unittests/Runtime/TemporaryStack.cpp
rename to FortranRuntime/unittests/Runtime/TemporaryStack.cpp
index 0a9344969ca6ba..63d99416ea64cb 100644
--- a/flang/unittests/Runtime/TemporaryStack.cpp
+++ b/FortranRuntime/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.
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#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"
 #include "flang/Runtime/temporary-stack.h"
 #include "flang/Runtime/type-code.h"
+#include "tools.h"
+#include "gtest/gtest.h"
 #include <vector>
 
 using namespace Fortran::runtime;
diff --git a/flang/unittests/Runtime/Time.cpp b/FortranRuntime/unittests/Runtime/Time.cpp
similarity index 98%
rename from flang/unittests/Runtime/Time.cpp
rename to FortranRuntime/unittests/Runtime/Time.cpp
index 9309d7b1ceffa0..6fd00d669a9575 100644
--- a/flang/unittests/Runtime/Time.cpp
+++ b/FortranRuntime/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.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "gtest/gtest.h"
 #include "flang/Runtime/time-intrinsic.h"
+#include "gtest/gtest.h"
 #include <algorithm>
 #include <cctype>
 #include <cerrno>
diff --git a/flang/unittests/Runtime/Transformational.cpp b/FortranRuntime/unittests/Runtime/Transformational.cpp
similarity index 99%
rename from flang/unittests/Runtime/Transformational.cpp
rename to FortranRuntime/unittests/Runtime/Transformational.cpp
index 5836e70c740f9a..b5a4e0e8e9588b 100644
--- a/flang/unittests/Runtime/Transformational.cpp
+++ b/FortranRuntime/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 "flang/Common/float128.h"
 #include "flang/Runtime/type-code.h"
+#include "tools.h"
+#include "gtest/gtest.h"
 #include <vector>
 
 using namespace Fortran::runtime;
diff --git a/flang/unittests/Runtime/tools.h b/FortranRuntime/unittests/Runtime/tools.h
similarity index 93%
rename from flang/unittests/Runtime/tools.h
rename to FortranRuntime/unittests/Runtime/tools.h
index 0347edace5c05c..702103d225ab72 100644
--- a/flang/unittests/Runtime/tools.h
+++ b/FortranRuntime/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.
@@ -9,11 +9,11 @@
 #ifndef FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
 #define FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
 
-#include "gtest/gtest.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/type-code.h"
+#include "gtest/gtest.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 /* FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_ */
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 971e5d5c93f231..a7f23ee59d192c 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -257,7 +257,8 @@ set(LLVM_BUILD_TOOLS ON)
 
 include_directories(BEFORE
   ${FLANG_BINARY_DIR}/include
-  ${FLANG_SOURCE_DIR}/include)
+  ${FLANG_SOURCE_DIR}/include
+  ${FLANG_SOURCE_DIR}/../FortranRuntime/include)
 
 # Add Flang-centric modules to cmake path.
 list(INSERT CMAKE_MODULE_PATH 0
@@ -468,7 +469,7 @@ if (FLANG_CUF_RUNTIME)
   find_package(CUDAToolkit REQUIRED)
 endif()
 
-add_subdirectory(runtime)
+add_subdirectory(../FortranRuntime/lib/Runtime runtime)
 
 if (LLVM_INCLUDE_EXAMPLES)
   add_subdirectory(examples)
@@ -537,7 +538,7 @@ endif()
 include(GetClangResourceDir)
 get_clang_resource_dir(HEADER_BINARY_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include)
 configure_file(
-  ${FLANG_SOURCE_DIR}/include/flang/ISO_Fortran_binding.h
+  ../FortranRuntime/include/flang/Common/ISO_Fortran_binding.h
   ${HEADER_BINARY_DIR}/ISO_Fortran_binding.h)
 
 # And also install it into the install area
diff --git a/flang/include/flang/Evaluate/call.h b/flang/include/flang/Evaluate/call.h
index 7531d8a81e808d..080f78c4e80fc0 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 11533a7259b055..e40155fb287b62 100644
--- a/flang/include/flang/Evaluate/characteristics.h
+++ b/flang/include/flang/Evaluate/characteristics.h
@@ -18,13 +18,13 @@
 #include "shape.h"
 #include "tools.h"
 #include "type.h"
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
 #include <optional>
 #include <string>
 #include <variant>
diff --git a/flang/include/flang/Evaluate/common.h b/flang/include/flang/Evaluate/common.h
index 915e95169c7f81..91d38748f5a575 100644
--- a/flang/include/flang/Evaluate/common.h
+++ b/flang/include/flang/Evaluate/common.h
@@ -9,16 +9,16 @@
 #ifndef FORTRAN_EVALUATE_COMMON_H_
 #define FORTRAN_EVALUATE_COMMON_H_
 
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/Fortran.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Common/enum-set.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
 #include "flang/Common/restorer.h"
 #include "flang/Common/target-rounding.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Parser/message.h"
+#include "flang/Support/Fortran-features.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/default-kinds.h"
+#include "flang/Support/indirection.h"
 #include <cinttypes>
 #include <map>
 #include <set>
diff --git a/flang/include/flang/Evaluate/constant.h b/flang/include/flang/Evaluate/constant.h
index d9866a08889f35..a171b10026409c 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 2a40193e32306b..20e8725f91d5e5 100644
--- a/flang/include/flang/Evaluate/expression.h
+++ b/flang/include/flang/Evaluate/expression.h
@@ -21,11 +21,11 @@
 #include "formatting.h"
 #include "type.h"
 #include "variable.h"
-#include "flang/Common/Fortran.h"
 #include "flang/Common/idioms.h"
-#include "flang/Common/indirection.h"
-#include "flang/Common/template.h"
 #include "flang/Parser/char-block.h"
+#include "flang/Support/Fortran.h"
+#include "flang/Support/indirection.h"
+#include "flang/Support/template.h"
 #include <algorithm>
 #include <list>
 #include <tuple>
diff --git a/flang/include/flang/Evaluate/formatting.h b/flang/include/flang/Evaluate/formatting.h
index aa82f56107fdd3..ae9351139b1933 100644
--- a/flang/include/flang/Evaluate/formatting.h
+++ b/flang/include/flang/Evaluate/formatting.h
@@ -19,7 +19,7 @@
 // This header is meant to be included by the headers that define the several
 // representational class templates that need it, not by external clients.
 
-#include "flang/Common/indirection.h"
+#include "flang/Support/indirection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <optional>
 #include <type_traits>
diff --git a/flang/include/flang/Evaluate/intrinsics.h b/flang/include/flang/Evaluate/intrinsics.h
index 15afb772ae767b..dbe1ba7fe7ec1b 100644
--- a/flang/include/flang/Evaluate/intrinsics.h
+++ b/flang/include/flang/Evaluate/intrinsics.h
@@ -12,9 +12,9 @@
 #include "call.h"
 #include "characteristics.h"
 #include "type.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Parser/message.h"
+#include "flang/Support/default-kinds.h"
 #include <memory>
 #include <optional>
 #include <string>
diff --git a/flang/include/flang/Evaluate/shape.h b/flang/include/flang/Evaluate/shape.h
index e33044c0d34e56..8e8d89ffd8d108 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 1950a4cb6bfc76..11ac41a5deb69f 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 a0487e399d936c..9e1c25a3529380 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 7f4a67d97e64e7..508d4ca76b30f6 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 bd8887dbce4e82..93311e3d2e5ae0 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 9565826dbfaea4..161625b6887189 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/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index 82ca99672ec610..c436eb4cbac6f3 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/Lower/AbstractConverter.h b/flang/include/flang/Lower/AbstractConverter.h
index daded9091780e2..6c8d77db2202b5 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 4379ed512cdf0a..f07207c5026ebd 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -13,13 +13,13 @@
 #ifndef FORTRAN_LOWER_BRIDGE_H
 #define FORTRAN_LOWER_BRIDGE_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Lower/AbstractConverter.h"
 #include "flang/Lower/EnvironmentDefault.h"
 #include "flang/Lower/LoweringOptions.h"
 #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 <set>
 
diff --git a/flang/include/flang/Lower/CallInterface.h b/flang/include/flang/Lower/CallInterface.h
index 9a688330e8bd2d..b16ad7a91afd0a 100644
--- a/flang/include/flang/Lower/CallInterface.h
+++ b/flang/include/flang/Lower/CallInterface.h
@@ -27,8 +27,8 @@
 #ifndef FORTRAN_LOWER_CALLINTERFACE_H
 #define FORTRAN_LOWER_CALLINTERFACE_H
 
-#include "flang/Common/reference.h"
 #include "flang/Evaluate/characteristics.h"
+#include "flang/Support/reference.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/IR/BuiltinOps.h"
 #include <memory>
diff --git a/flang/include/flang/Lower/ConvertType.h b/flang/include/flang/Lower/ConvertType.h
index 7a3f92649a4e4a..179a6825840464 100644
--- a/flang/include/flang/Lower/ConvertType.h
+++ b/flang/include/flang/Lower/ConvertType.h
@@ -21,8 +21,8 @@
 #ifndef FORTRAN_LOWER_CONVERT_TYPE_H
 #define FORTRAN_LOWER_CONVERT_TYPE_H
 
-#include "flang/Common/Fortran.h"
 #include "flang/Evaluate/type.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/IR/BuiltinTypes.h"
 
 namespace mlir {
diff --git a/flang/include/flang/Lower/LoweringOptions.h b/flang/include/flang/Lower/LoweringOptions.h
index 8105ccd7ef6b15..171510393b8168 100644
--- a/flang/include/flang/Lower/LoweringOptions.h
+++ b/flang/include/flang/Lower/LoweringOptions.h
@@ -15,7 +15,7 @@
 #ifndef FLANG_LOWER_LOWERINGOPTIONS_H
 #define FLANG_LOWER_LOWERINGOPTIONS_H
 
-#include "flang/Common/MathOptionsBase.h"
+#include "flang/Support/MathOptionsBase.h"
 
 namespace Fortran::lower {
 
diff --git a/flang/include/flang/Lower/PFTBuilder.h b/flang/include/flang/Lower/PFTBuilder.h
index 7f1b93c564b4c4..b2e0d776a228b1 100644
--- a/flang/include/flang/Lower/PFTBuilder.h
+++ b/flang/include/flang/Lower/PFTBuilder.h
@@ -17,8 +17,6 @@
 #ifndef FORTRAN_LOWER_PFTBUILDER_H
 #define FORTRAN_LOWER_PFTBUILDER_H
 
-#include "flang/Common/reference.h"
-#include "flang/Common/template.h"
 #include "flang/Lower/HostAssociations.h"
 #include "flang/Lower/PFTDefs.h"
 #include "flang/Parser/parse-tree.h"
@@ -26,6 +24,8 @@
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/reference.h"
+#include "flang/Support/template.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
diff --git a/flang/include/flang/Lower/Support/Utils.h b/flang/include/flang/Lower/Support/Utils.h
index 1cc74521e22d88..08a872b228691d 100644
--- a/flang/include/flang/Lower/Support/Utils.h
+++ b/flang/include/flang/Lower/Support/Utils.h
@@ -13,9 +13,9 @@
 #ifndef FORTRAN_LOWER_SUPPORT_UTILS_H
 #define FORTRAN_LOWER_SUPPORT_UTILS_H
 
-#include "flang/Common/indirection.h"
 #include "flang/Parser/char-block.h"
 #include "flang/Semantics/tools.h"
+#include "flang/Support/indirection.h"
 #include "mlir/Dialect/Arith/IR/Arith.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/IR/BuiltinAttributes.h"
diff --git a/flang/include/flang/Lower/SymbolMap.h b/flang/include/flang/Lower/SymbolMap.h
index c03f9afd40801c..fb64db407708ad 100644
--- a/flang/include/flang/Lower/SymbolMap.h
+++ b/flang/include/flang/Lower/SymbolMap.h
@@ -13,12 +13,12 @@
 #ifndef FORTRAN_LOWER_SYMBOLMAP_H
 #define FORTRAN_LOWER_SYMBOLMAP_H
 
-#include "flang/Common/reference.h"
 #include "flang/Optimizer/Builder/BoxValue.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Dialect/FortranVariableInterface.h"
 #include "flang/Optimizer/Support/Matcher.h"
 #include "flang/Semantics/symbol.h"
+#include "flang/Support/reference.h"
 #include "mlir/IR/Value.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index f7151f26f09cb3..14c1d5033fab40 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/IntrinsicCall.h b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index 78bb82b17d4050..3fc4201bd16c6c 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -397,6 +397,7 @@ struct IntrinsicLibrary {
   fir::ExtendedValue genUbound(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
   fir::ExtendedValue genUnpack(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
   fir::ExtendedValue genVerify(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
+    fir::ExtendedValue genNumericStorageSize(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
 
   /// Implement all conversion functions like DBLE, the first argument is
   /// the value to convert. There may be an additional KIND arguments that
diff --git a/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h b/flang/include/flang/Optimizer/Builder/PPCIntrinsicCall.h
index a7c4c075d818ee..2a3e85988184b4 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 a103861f1510b8..e9fb177d311c01 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 ff0cf29e8073e6..31d1416846d0c9 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.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 f32e39b543e3f7..85615a4d69157d 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 308c82118d5020..ec21d672287e62 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 02bec4164fca08..88d38cb7574813 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 38f4f7b82e1eae..4541b31e566f95 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 37c3370b48a085..30ea08806430a9 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 668559aeec9478..c3d4a78c2c0023 100644
--- a/flang/include/flang/Parser/message.h
+++ b/flang/include/flang/Parser/message.h
@@ -16,8 +16,8 @@
 #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/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 76cbb3470dc08d..36d70b81b79236 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 548fcc81984b2a..de869f8200a261 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/OMPConstants.h"
 #include <cinttypes>
diff --git a/flang/include/flang/Parser/parsing.h b/flang/include/flang/Parser/parsing.h
index 4d329c189cb80e..0e608cb220d2c5 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 a9224b727fd054..7f29fb272c9421 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 a6efdf9546c7f3..a67fd66045a3de 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 61745a833c715c..129f9fb8fee058 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/Semantics/expression.h b/flang/include/flang/Semantics/expression.h
index c90c8c4b3cc70f..194cb746ff8a84 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 e90d3ae8baf1eb..94c50aab696816 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 e73a507e9b3f5b..72e8bab71b6c70 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 e73f9d2e85d589..abce30f725d972 100644
--- a/flang/include/flang/Semantics/semantics.h
+++ b/flang/include/flang/Semantics/semantics.h
@@ -11,12 +11,12 @@
 
 #include "scope.h"
 #include "symbol.h"
-#include "flang/Common/Fortran-features.h"
 #include "flang/Evaluate/common.h"
 #include "flang/Evaluate/intrinsics.h"
 #include "flang/Evaluate/target.h"
 #include "flang/Parser/message.h"
 #include "flang/Semantics/module-dependences.h"
+#include "flang/Support/Fortran-features.h"
 #include <iosfwd>
 #include <set>
 #include <string>
diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h
index b4db6689a94271..d207cfe7d7421a 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 15c02ecc0058cc..e31de6e958a8c4 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 e2d47d38f927f7..210ea7a129376d 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 98%
rename from flang/include/flang/Common/Fortran-features.h
rename to flang/include/flang/Support/Fortran-features.h
index 86c6e02b0f2ffd..718ce680afeeab 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.
@@ -9,9 +9,9 @@
 #ifndef FORTRAN_COMMON_FORTRAN_FEATURES_H_
 #define FORTRAN_COMMON_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 <vector>
 
 namespace Fortran::common {
diff --git a/flang/include/flang/Common/Fortran.h b/flang/include/flang/Support/Fortran.h
similarity index 98%
rename from flang/include/flang/Common/Fortran.h
rename to flang/include/flang/Support/Fortran.h
index 623607d4fad267..343a0b30d2ba9c 100644
--- a/flang/include/flang/Common/Fortran.h
+++ b/flang/include/flang/Support/Fortran.h
@@ -12,9 +12,9 @@
 // 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>
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 86%
rename from flang/include/flang/Common/MathOptionsBase.h
rename to flang/include/flang/Support/MathOptionsBase.h
index 7f8ebdbee19878..a739ba3e066599 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.
@@ -27,16 +27,16 @@ 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
diff --git a/flang/include/flang/Common/OpenMP-features.h b/flang/include/flang/Support/OpenMP-features.h
similarity index 94%
rename from flang/include/flang/Common/OpenMP-features.h
rename to flang/include/flang/Support/OpenMP-features.h
index 480c8b4c1013fe..fb73d4191d1c1a 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.
diff --git a/flang/include/flang/Common/Version.h b/flang/include/flang/Support/Version.h
similarity index 95%
rename from flang/include/flang/Common/Version.h
rename to flang/include/flang/Support/Version.h
index 3257d4a4f64593..643ddd2e27f69a 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.
diff --git a/flang/include/flang/Common/default-kinds.h b/flang/include/flang/Support/default-kinds.h
similarity index 96%
rename from flang/include/flang/Common/default-kinds.h
rename to flang/include/flang/Support/default-kinds.h
index 6c66b98e98a05b..e78a08dfae6cc3 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.
@@ -9,7 +9,7 @@
 #ifndef FORTRAN_COMMON_DEFAULT_KINDS_H_
 #define FORTRAN_COMMON_DEFAULT_KINDS_H_
 
-#include "flang/Common/Fortran.h"
+#include "flang/Support/Fortran.h"
 #include <cstdint>
 
 namespace Fortran::common {
diff --git a/flang/include/flang/Common/indirection.h b/flang/include/flang/Support/indirection.h
similarity index 98%
rename from flang/include/flang/Common/indirection.h
rename to flang/include/flang/Support/indirection.h
index 7348eb0473f072..1221a659323503 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.
@@ -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>
diff --git a/flang/include/flang/Common/interval.h b/flang/include/flang/Support/interval.h
similarity index 97%
rename from flang/include/flang/Common/interval.h
rename to flang/include/flang/Support/interval.h
index c4cab0ccf1130b..2918cc54de3926 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.
@@ -12,7 +12,7 @@
 // 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>
diff --git a/flang/include/flang/Common/reference-counted.h b/flang/include/flang/Support/reference-counted.h
similarity index 96%
rename from flang/include/flang/Common/reference-counted.h
rename to flang/include/flang/Support/reference-counted.h
index de91d4fb6ee8b7..d7a065c59d5a0f 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.
diff --git a/flang/include/flang/Common/reference.h b/flang/include/flang/Support/reference.h
similarity index 97%
rename from flang/include/flang/Common/reference.h
rename to flang/include/flang/Support/reference.h
index 0c579de44bd7fa..cb367ae231376d 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.
diff --git a/flang/include/flang/Common/static-multimap-view.h b/flang/include/flang/Support/static-multimap-view.h
similarity index 97%
rename from flang/include/flang/Common/static-multimap-view.h
rename to flang/include/flang/Support/static-multimap-view.h
index 27d2ba89c8009c..71da272a26de2f 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.
diff --git a/flang/include/flang/Common/template.h b/flang/include/flang/Support/template.h
similarity index 99%
rename from flang/include/flang/Common/template.h
rename to flang/include/flang/Support/template.h
index 51d09fb42ce368..58c9b0a5628e8a 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.
@@ -9,8 +9,8 @@
 #ifndef FORTRAN_COMMON_TEMPLATE_H_
 #define FORTRAN_COMMON_TEMPLATE_H_
 
-#include "variant.h"
 #include "flang/Common/idioms.h"
+#include "flang/Common/variant.h"
 #include <functional>
 #include <optional>
 #include <tuple>
diff --git a/flang/include/flang/Common/unwrap.h b/flang/include/flang/Support/unwrap.h
similarity index 97%
rename from flang/include/flang/Common/unwrap.h
rename to flang/include/flang/Support/unwrap.h
index 84582174e4b300..d8fa553dedda3f 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.
@@ -12,8 +12,8 @@
 #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>
diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h
index 75fd783af237d0..168c3aefe0cd41 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/MathOptionsBase.h"
 #include "flang/Frontend/CodeGenOptions.h"
 #include "flang/Frontend/LangOptions.h"
+#include "flang/Support/MathOptionsBase.h"
 #include <cstdint>
 
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
diff --git a/flang/lib/Common/CMakeLists.txt b/flang/lib/Common/CMakeLists.txt
index c6f818ad27cd19..ff7c186bff866b 100644
--- a/flang/lib/Common/CMakeLists.txt
+++ b/flang/lib/Common/CMakeLists.txt
@@ -36,11 +36,11 @@ endif()
 
 
 add_flang_library(FortranCommon
-  Fortran.cpp
-  Fortran-features.cpp
-  default-kinds.cpp
-  idioms.cpp
-  Version.cpp
+  ../Support/Fortran.cpp
+  ../Support/Fortran-features.cpp
+  ../Support/default-kinds.cpp
+  ../Support/idioms.cpp
+  ../Support/Version.cpp
   ${version_inc}
 
   LINK_COMPONENTS
diff --git a/flang/lib/Decimal/CMakeLists.txt b/flang/lib/Decimal/CMakeLists.txt
index 880b190f1c5815..6b058e4a0ae2fa 100644
--- a/flang/lib/Decimal/CMakeLists.txt
+++ b/flang/lib/Decimal/CMakeLists.txt
@@ -37,7 +37,8 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
     add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
   endif ()
   include_directories(BEFORE
-    ${FLANG_SOURCE_DIR}/include)
+    ${FLANG_SOURCE_DIR}/include
+    ${FLANG_SOURCE_DIR}/../FortranRuntime/include)
 endif()
 
 check_cxx_compiler_flag(-fno-lto FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
@@ -50,8 +51,8 @@ endif()
 add_definitions(-U_GLIBCXX_ASSERTIONS)
 
 set(sources
-  binary-to-decimal.cpp
-  decimal-to-binary.cpp
+  ../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
+  ../../../FortranRuntime/lib/Common/decimal-to-binary.cpp
 )
 
 include(AddFlangOffloadRuntime)
@@ -63,23 +64,23 @@ 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
+          ../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
+          ../../../FortranRuntime/lib/Common/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
+    ../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
+    ../../../FortranRuntime/lib/Common/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
+          ../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
+          ../../../FortranRuntime/lib/Common/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
+    ../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
+    ../../../FortranRuntime/lib/Common/decimal-to-binary.cpp
   )
   add_dependencies(FortranDecimal FortranDecimal.static FortranDecimal.dynamic
     FortranDecimal.static_dbg FortranDecimal.dynamic_dbg)
diff --git a/flang/lib/Evaluate/call.cpp b/flang/lib/Evaluate/call.cpp
index c5b50e806d2497..f77df92a7597ab 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 70e24d6e82eb8e..ffa3ec721cbd63 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/common.cpp b/flang/lib/Evaluate/common.cpp
index c633bff57b1ecd..ed040b0728c4db 100644
--- a/flang/lib/Evaluate/common.cpp
+++ b/flang/lib/Evaluate/common.cpp
@@ -11,8 +11,11 @@
 
 using namespace Fortran::parser::literals;
 
+
+
 namespace Fortran::evaluate {
 
+
 void RealFlagWarnings(
     FoldingContext &context, const RealFlags &flags, const char *operation) {
   if (context.languageFeatures().ShouldWarn(
diff --git a/flang/lib/Evaluate/fold-implementation.h b/flang/lib/Evaluate/fold-implementation.h
index 1b14a305b87f4f..86cbd971aebcb5 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 0870d56549f74d..a53fa019984b43 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 ed28d8130808fa..4f1eff492afae5 100644
--- a/flang/lib/Evaluate/intrinsics-library.cpp
+++ b/flang/lib/Evaluate/intrinsics-library.cpp
@@ -14,8 +14,8 @@
 #include "flang/Evaluate/intrinsics-library.h"
 #include "fold-implementation.h"
 #include "host.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 166dae93178c51..bcad2d831cb784 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/real.cpp b/flang/lib/Evaluate/real.cpp
index 642490646dcaf3..01d2e14cbf933e 100644
--- a/flang/lib/Evaluate/real.cpp
+++ b/flang/lib/Evaluate/real.cpp
@@ -8,8 +8,8 @@
 
 #include "flang/Evaluate/real.h"
 #include "int-power.h"
+#include "flang/Common/decimal.h"
 #include "flang/Common/idioms.h"
-#include "flang/Decimal/decimal.h"
 #include "flang/Parser/characters.h"
 #include "llvm/Support/raw_ostream.h"
 #include <limits>
diff --git a/flang/lib/Evaluate/shape.cpp b/flang/lib/Evaluate/shape.cpp
index c62d0cb0ff29dd..d77dd312eba97a 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 1e2cf6b0d298d4..79d260af6d50b9 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/CompilerInstance.cpp b/flang/lib/Frontend/CompilerInstance.cpp
index d37430e0e5773e..d86d6e678a4ed9 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 "clang/Basic/DiagnosticFrontend.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/MC/TargetRegistry.h"
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 90c327546198b5..5416234ca3e9e6 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 cda82bcb7ecc71..dced7f296e7904 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"
@@ -33,6 +32,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 79e5a04463e00b..c903c2169e4dcd 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -12,7 +12,6 @@
 
 #include "flang/Lower/Bridge.h"
 #include "DirectivesCommon.h"
-#include "flang/Common/Version.h"
 #include "flang/Lower/Allocatable.h"
 #include "flang/Lower/CallInterface.h"
 #include "flang/Lower/Coarray.h"
@@ -59,6 +58,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/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp
index c0ef96adc20c3e..9334ce009eae5e 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 62a7615e1af13c..b85043f78884f0 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 a66dae8851a866..4ff170c19d922a 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 dc0dc47bda9a9d..b98ab3e6999655 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.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 1043494b6fb48a..45354e0fe79666 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 c1debf28d00332..08d75c46faee4b 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/Transforms/AddDebugInfo.cpp b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
index 46e70d7ef9180a..f84dd6bf6c06c5 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"
@@ -22,6 +21,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 2c9c73e8a5394d..9fccbd24a74982 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/CufOpConversion.cpp b/flang/lib/Optimizer/Transforms/CufOpConversion.cpp
index c22c74d3f78af7..d7d321c6b9af3f 100644
--- a/flang/lib/Optimizer/Transforms/CufOpConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/CufOpConversion.cpp
@@ -6,7 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/Fortran.h"
 #include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
 #include "flang/Optimizer/CodeGen/TypeConverter.h"
 #include "flang/Optimizer/Dialect/CUF/CUFOps.h"
@@ -16,6 +15,7 @@
 #include "flang/Optimizer/Support/DataLayout.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/allocatable.h"
+#include "flang/Support/Fortran.h"
 #include "mlir/Pass/Pass.h"
 #include "mlir/Transforms/DialectConversion.h"
 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
diff --git a/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp b/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
index 648628fd1c9af0..3e4f46297357f9 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/IR/Attributes.h"
 #include "mlir/IR/SymbolTable.h"
 #include "mlir/Pass/Pass.h"
diff --git a/flang/lib/Optimizer/Transforms/LoopVersioning.cpp b/flang/lib/Optimizer/Transforms/LoopVersioning.cpp
index 51dc48f0fcb129..f6bd2aeb17bc20 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 c61179a7460e32..3f5178710689cb 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/FIRBuilder.h"
 #include "flang/Optimizer/Builder/LowLevelIntrinsics.h"
@@ -34,6 +33,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 8a60a9e64f704b..eb088c30e94f20 100644
--- a/flang/lib/Optimizer/Transforms/StackReclaim.cpp
+++ b/flang/lib/Optimizer/Transforms/StackReclaim.cpp
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/Fortran.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 d311167c58b4d6..54a2456e77366c 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/basic-parsers.h b/flang/lib/Parser/basic-parsers.h
index 515b5993d67376..be0f4fc44374ca 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 7f0899aaa14294..0793383efefb5f 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 9d4f7c0c302a1a..f9d920a6621aa5 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 2511a5dda9d095..4a044514916030 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/assignment.h b/flang/lib/Semantics/assignment.h
index 95d7b3cf91b17a..ba0c70f7d224cb 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 d296460127e12c..6d38bbee1eb2cb 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 6cf61a6b923db3..ac1f38801cee72 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 d8bd435bf09f38..b89b46868d2e58 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 479d32568fa66a..6da316cccc4a7b 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 d798244ff1ef2d..26530e798c9f4c 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 ec2600bac3c68e..c7b91a2725c942 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 2e602d307013c1..b227bbaaef4ba4 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 94d16a719277af..b86a95492b21c1 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 43535b07f029e9..aabd52098e63bb 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 d8cc4601de26fa..e99a02cc79db15 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 072ebe172f45a9..2a8ed892c800eb 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 4948fce77a2502..d8fcedf24bdb9e 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 e5e96ec6327e2b..e988ba8e331963 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 39392257938d66..3aa48e92d423db 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 d8f601212d8d01..ebcb864549e48e 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -14,9 +14,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"
@@ -37,6 +34,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 b4fb72ce213017..7f4efe67d7ec9f 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 8592d1e5d6217e..aa897f3011f51d 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 8d16ab71008766..3f5cf3cebbea9b 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/Common/Fortran-features.cpp b/flang/lib/Support/Fortran-features.cpp
similarity index 91%
rename from flang/lib/Common/Fortran-features.cpp
rename to flang/lib/Support/Fortran-features.cpp
index 25a948818e6560..868d18caa13c64 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 c014b1263a67f0..21eafe385015b5 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/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 d67255f353dfd7..8ee4908f28f621 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 0c708fcd605094..612adceb9d996b 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 536a5c2e5479df..906a4c1bcd9b0a 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/test/lit.cfg.py b/flang/test/lit.cfg.py
index 4acbc0606d1977..228bbb7e313d82 100644
--- a/flang/test/lit.cfg.py
+++ b/flang/test/lit.cfg.py
@@ -169,7 +169,7 @@
 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")
+    include = os.path.join(config.flang_src_dir, "..", "FortranRuntime", "include")
 
     if (
         os.path.isfile(libruntime)
diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index dcff4503f16571..917e052ef35fa1 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -14,10 +14,6 @@
 ///
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/Fortran-features.h"
-#include "flang/Common/OpenMP-features.h"
-#include "flang/Common/Version.h"
-#include "flang/Common/default-kinds.h"
 #include "flang/Frontend/TargetOptions.h"
 #include "flang/Lower/Bridge.h"
 #include "flang/Lower/PFTBuilder.h"
@@ -40,6 +36,10 @@
 #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/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/f18-parse-demo.cpp b/flang/tools/f18-parse-demo/f18-parse-demo.cpp
index 3025dbd4dca4ab..a50c88dc840643 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/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index 9d7b8633958cb7..664c18f406c08c 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -105,10 +105,12 @@ if (NOT CMAKE_CROSSCOMPILING)
     set(compile_with "-fsyntax-only")
     set(object_output "")
     set(include_in_link FALSE)
+    set(fullpath "${FLANG_SOURCE_DIR}/../FortranRuntime/module/${filename}.f90")
     if(${filename} IN_LIST MODULES_WITH_IMPLEMENTATION)
       set(object_output "${CMAKE_CURRENT_BINARY_DIR}/${filename}${CMAKE_CXX_OUTPUT_EXTENSION}")
       set(compile_with -c -o ${object_output})
       set(include_in_link TRUE)
+      set(fullpath "${FLANG_SOURCE_DIR}/../FortranRuntime/lib/Runtime/${filename}.f90")
     endif()
 
     set(base ${FLANG_INTRINSIC_MODULES_DIR}/${filename})
@@ -116,8 +118,8 @@ if (NOT CMAKE_CROSSCOMPILING)
     add_custom_command(OUTPUT ${base}.mod ${object_output}
       COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
       COMMAND flang-new ${opts} ${decls} -cpp ${compile_with} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
-        ${FLANG_SOURCE_DIR}/module/${filename}.f90
-      DEPENDS flang-new ${FLANG_SOURCE_DIR}/module/${filename}.f90 ${FLANG_SOURCE_DIR}/module/__fortran_builtins.f90 ${depends}
+        ${fullpath}
+      DEPENDS flang-new ${fullpath} ${FLANG_SOURCE_DIR}/../FortranRuntime/module/__fortran_builtins.f90 ${depends}
     )
     list(APPEND MODULE_FILES ${base}.mod)
     install(FILES ${base}.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
diff --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt
index 945067fed4f82d..2d86e991aee610 100644
--- a/flang/unittests/CMakeLists.txt
+++ b/flang/unittests/CMakeLists.txt
@@ -72,8 +72,8 @@ function(add_flang_nongtest_unittest test_name)
 endfunction()
 
 add_subdirectory(Optimizer)
-add_subdirectory(Common)
-add_subdirectory(Decimal)
+add_subdirectory(../../FortranRuntime/unittests/Common Common)
+add_subdirectory(../../FortranRuntime/unittests/Decimal Decimal)
 add_subdirectory(Evaluate)
-add_subdirectory(Runtime)
+add_subdirectory(../../FortranRuntime/unittests/Runtime Runtime)
 add_subdirectory(Frontend)
diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt
index 52eb385f4763fb..35bd7b0f18a90d 100644
--- a/flang/unittests/Evaluate/CMakeLists.txt
+++ b/flang/unittests/Evaluate/CMakeLists.txt
@@ -1,7 +1,7 @@
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
 add_library(FortranEvaluateTesting
-  testing.cpp
-  fp-testing.cpp
+  ../../../FortranRuntime/lib/Testing/testing.cpp
+  ../../../FortranRuntime/lib/Testing/fp-testing.cpp
 )
 set_target_properties(FortranEvaluateTesting PROPERTIES FOLDER "Flang/Tests")
 if (LLVM_LINK_LLVM_DYLIB)
@@ -69,23 +69,11 @@ add_flang_nongtest_unittest(real
 )
 llvm_update_compile_flags(real.test)
 
-add_flang_nongtest_unittest(reshape
-  FortranEvaluateTesting
-  FortranSemantics
-  FortranEvaluate
-  FortranRuntime
-)
-
-add_flang_nongtest_unittest(ISO-Fortran-binding
-  FortranEvaluateTesting
-  FortranEvaluate
-  FortranSemantics
-  FortranRuntime
-)
-
 add_flang_nongtest_unittest(folding
   FortranCommon
   FortranEvaluateTesting
   FortranEvaluate
   FortranSemantics
 )
+
+add_subdirectory(../../../FortranRuntime/unittests/Evaluate runtime)
\ No newline at end of file
diff --git a/flang/unittests/Evaluate/bit-population-count.cpp b/flang/unittests/Evaluate/bit-population-count.cpp
index 24e721c14f94a7..0c9529a92e5724 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 f03a6bc2a4e23c..d575f36def287e 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 4e8ff9754e4ccb..832e55d44316da 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 3eabb2434cce60..5ab22cc6443a7b 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 86c471d2c62950..cca2f8c30247e0 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 968946b69f27ea..25e2664e76df04 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 d79aff84487123..ba7d0d8d0c0e3a 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 ccbaf81f054cb5..23406fc6909aea 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/uint128.cpp b/flang/unittests/Evaluate/uint128.cpp
index f05c1c96a7e8b0..0b749abe1c080a 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 d49157d1743ba711a41d86fcd4ae724cba0d8fc5 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Tue, 1 Oct 2024 16:01:16 +0200
Subject: [PATCH 02/12] Move Module sources back to Flang

Build fix

f90 relative paths

update copyright headers

Test experimental CUDA build
---
 .../include/flang/Common/ISO_Fortran_binding_wrapper.h    | 2 +-
 .../include/flang/{Runtime => Common}/magic-numbers.h     | 0
 FortranRuntime/include/flang/Runtime/io-api.h             | 2 +-
 FortranRuntime/include/flang/Runtime/iostat.h             | 2 +-
 FortranRuntime/lib/Runtime/CMakeLists.txt                 | 4 ++--
 FortranRuntime/lib/Runtime/CUDA/CMakeLists.txt            | 2 +-
 FortranRuntime/lib/Runtime/Float128Math/CMakeLists.txt    | 2 +-
 FortranRuntime/lib/Runtime/file.cpp                       | 4 ++--
 FortranRuntime/lib/Runtime/io-error.cpp                   | 2 +-
 FortranRuntime/lib/Runtime/stat.h                         | 2 +-
 FortranRuntime/lib/Testing/fp-testing.cpp                 | 8 ++++++++
 FortranRuntime/unittests/Common/CMakeLists.txt            | 8 ++++++++
 FortranRuntime/unittests/Decimal/CMakeLists.txt           | 8 ++++++++
 FortranRuntime/unittests/Evaluate/CMakeLists.txt          | 8 ++++++++
 FortranRuntime/unittests/Runtime/CMakeLists.txt           | 8 ++++++++
 FortranRuntime/unittests/Runtime/CUDA/CMakeLists.txt      | 8 ++++++++
 FortranRuntime/unittests/Runtime/Complex.cpp              | 2 +-
 flang/CMakeLists.txt                                      | 2 +-
 .../Common => flang/include/flang}/ISO_Fortran_binding.h  | 0
 flang/lib/Evaluate/fold-logical.cpp                       | 2 +-
 {FortranRuntime => flang}/module/.clang-format            | 0
 {FortranRuntime => flang}/module/__cuda_builtins.f90      | 0
 {FortranRuntime => flang}/module/__fortran_builtins.f90   | 2 +-
 .../module/__fortran_ieee_exceptions.f90                  | 2 +-
 {FortranRuntime => flang}/module/__fortran_type_info.f90  | 0
 {FortranRuntime => flang}/module/__ppc_intrinsics.f90     | 0
 {FortranRuntime => flang}/module/__ppc_types.f90          | 0
 {FortranRuntime => flang}/module/cudadevice.f90           | 0
 {FortranRuntime => flang}/module/ieee_arithmetic.f90      | 2 +-
 {FortranRuntime => flang}/module/ieee_exceptions.f90      | 0
 {FortranRuntime => flang}/module/ieee_features.f90        | 0
 {FortranRuntime => flang}/module/iso_c_binding.f90        | 0
 {FortranRuntime => flang}/module/iso_fortran_env.f90      | 2 +-
 {FortranRuntime => flang}/module/mma.f90                  | 0
 flang/tools/f18/CMakeLists.txt                            | 4 ++--
 35 files changed, 68 insertions(+), 20 deletions(-)
 rename FortranRuntime/include/flang/{Runtime => Common}/magic-numbers.h (100%)
 rename {FortranRuntime/include/flang/Common => flang/include/flang}/ISO_Fortran_binding.h (100%)
 rename {FortranRuntime => flang}/module/.clang-format (100%)
 rename {FortranRuntime => flang}/module/__cuda_builtins.f90 (100%)
 rename {FortranRuntime => flang}/module/__fortran_builtins.f90 (99%)
 rename {FortranRuntime => flang}/module/__fortran_ieee_exceptions.f90 (98%)
 rename {FortranRuntime => flang}/module/__fortran_type_info.f90 (100%)
 rename {FortranRuntime => flang}/module/__ppc_intrinsics.f90 (100%)
 rename {FortranRuntime => flang}/module/__ppc_types.f90 (100%)
 rename {FortranRuntime => flang}/module/cudadevice.f90 (100%)
 rename {FortranRuntime => flang}/module/ieee_arithmetic.f90 (99%)
 rename {FortranRuntime => flang}/module/ieee_exceptions.f90 (100%)
 rename {FortranRuntime => flang}/module/ieee_features.f90 (100%)
 rename {FortranRuntime => flang}/module/iso_c_binding.f90 (100%)
 rename {FortranRuntime => flang}/module/iso_fortran_env.f90 (98%)
 rename {FortranRuntime => flang}/module/mma.f90 (100%)

diff --git a/FortranRuntime/include/flang/Common/ISO_Fortran_binding_wrapper.h b/FortranRuntime/include/flang/Common/ISO_Fortran_binding_wrapper.h
index d1bc9be34859a4..2c0fdc123c8759 100644
--- a/FortranRuntime/include/flang/Common/ISO_Fortran_binding_wrapper.h
+++ b/FortranRuntime/include/flang/Common/ISO_Fortran_binding_wrapper.h
@@ -28,7 +28,7 @@ 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
diff --git a/FortranRuntime/include/flang/Runtime/magic-numbers.h b/FortranRuntime/include/flang/Common/magic-numbers.h
similarity index 100%
rename from FortranRuntime/include/flang/Runtime/magic-numbers.h
rename to FortranRuntime/include/flang/Common/magic-numbers.h
diff --git a/FortranRuntime/include/flang/Runtime/io-api.h b/FortranRuntime/include/flang/Runtime/io-api.h
index 367146a4925c53..be948061c241a0 100644
--- a/FortranRuntime/include/flang/Runtime/io-api.h
+++ b/FortranRuntime/include/flang/Runtime/io-api.h
@@ -11,10 +11,10 @@
 #ifndef FORTRAN_RUNTIME_IO_API_H_
 #define FORTRAN_RUNTIME_IO_API_H_
 
+#include "flang/Common/magic-numbers.h"
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/entry-names.h"
 #include "flang/Runtime/iostat.h"
-#include "flang/Runtime/magic-numbers.h"
 #include <cinttypes>
 #include <cstddef>
 
diff --git a/FortranRuntime/include/flang/Runtime/iostat.h b/FortranRuntime/include/flang/Runtime/iostat.h
index a5a2a560f05f8d..9a52990045ee13 100644
--- a/FortranRuntime/include/flang/Runtime/iostat.h
+++ b/FortranRuntime/include/flang/Runtime/iostat.h
@@ -12,7 +12,7 @@
 #ifndef FORTRAN_RUNTIME_IOSTAT_H_
 #define FORTRAN_RUNTIME_IOSTAT_H_
 #include "flang/Common/api-attrs.h"
-#include "flang/Runtime/magic-numbers.h"
+#include "flang/Common/magic-numbers.h"
 namespace Fortran::runtime::io {
 
 // The value of IOSTAT= is zero when no error, end-of-record,
diff --git a/FortranRuntime/lib/Runtime/CMakeLists.txt b/FortranRuntime/lib/Runtime/CMakeLists.txt
index 8ecb08b4ebb8ae..d09112ab8b0d5f 100644
--- a/FortranRuntime/lib/Runtime/CMakeLists.txt
+++ b/FortranRuntime/lib/Runtime/CMakeLists.txt
@@ -1,4 +1,4 @@
-#===-- runtime/CMakeLists.txt ----------------------------------------------===#
+#===-- lib/Runtime/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.
@@ -15,7 +15,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
   set(CMAKE_CXX_EXTENSIONS OFF)
 
-  set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
+  set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../flang")
 
   set(LLVM_COMMON_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../cmake")
   set(LLVM_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../llvm/cmake")
diff --git a/FortranRuntime/lib/Runtime/CUDA/CMakeLists.txt b/FortranRuntime/lib/Runtime/CUDA/CMakeLists.txt
index 81055b2737c0f1..f75b854d1eb3ba 100644
--- a/FortranRuntime/lib/Runtime/CUDA/CMakeLists.txt
+++ b/FortranRuntime/lib/Runtime/CUDA/CMakeLists.txt
@@ -1,4 +1,4 @@
-#===-- runtime/CUDA/CMakeLists.txt -----------------------------------------===#
+#===-- lib/Runtime/CUDA/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.
diff --git a/FortranRuntime/lib/Runtime/Float128Math/CMakeLists.txt b/FortranRuntime/lib/Runtime/Float128Math/CMakeLists.txt
index a5f5bec1e7e4b8..1ff158c401855f 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/CMakeLists.txt
+++ b/FortranRuntime/lib/Runtime/Float128Math/CMakeLists.txt
@@ -1,4 +1,4 @@
-#===-- runtime/Float128Math/CMakeLists.txt ---------------------------------===#
+#===-- lib/Runtime/Float128Math/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.
diff --git a/FortranRuntime/lib/Runtime/file.cpp b/FortranRuntime/lib/Runtime/file.cpp
index b82f1c63e397f9..80829d844881e8 100644
--- a/FortranRuntime/lib/Runtime/file.cpp
+++ b/FortranRuntime/lib/Runtime/file.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "file.h"
-#include "flang/Runtime/magic-numbers.h"
-#include "flang/Runtime/memory.h"
 #include "tools.h"
+#include "flang/Common/magic-numbers.h"
+#include "flang/Runtime/memory.h"
 #include <algorithm>
 #include <cerrno>
 #include <cstring>
diff --git a/FortranRuntime/lib/Runtime/io-error.cpp b/FortranRuntime/lib/Runtime/io-error.cpp
index b14a30354d2347..400b211c1c418e 100644
--- a/FortranRuntime/lib/Runtime/io-error.cpp
+++ b/FortranRuntime/lib/Runtime/io-error.cpp
@@ -8,8 +8,8 @@
 
 #include "io-error.h"
 #include "config.h"
-#include "flang/Runtime/magic-numbers.h"
 #include "tools.h"
+#include "flang/Common/magic-numbers.h"
 #include <cerrno>
 #include <cstdarg>
 #include <cstdio>
diff --git a/FortranRuntime/lib/Runtime/stat.h b/FortranRuntime/lib/Runtime/stat.h
index eccd69024d726b..a679f9da16dd46 100644
--- a/FortranRuntime/lib/Runtime/stat.h
+++ b/FortranRuntime/lib/Runtime/stat.h
@@ -13,7 +13,7 @@
 #define FORTRAN_RUNTIME_STAT_H_
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Common/api-attrs.h"
-#include "flang/Runtime/magic-numbers.h"
+#include "flang/Common/magic-numbers.h"
 namespace Fortran::runtime {
 
 class Descriptor;
diff --git a/FortranRuntime/lib/Testing/fp-testing.cpp b/FortranRuntime/lib/Testing/fp-testing.cpp
index 3301d2d8efb15f..8541b1406334d3 100644
--- a/FortranRuntime/lib/Testing/fp-testing.cpp
+++ b/FortranRuntime/lib/Testing/fp-testing.cpp
@@ -1,3 +1,11 @@
+//===-- 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>
diff --git a/FortranRuntime/unittests/Common/CMakeLists.txt b/FortranRuntime/unittests/Common/CMakeLists.txt
index bda02ed29a5efa..72f2c50d14162d 100644
--- a/FortranRuntime/unittests/Common/CMakeLists.txt
+++ b/FortranRuntime/unittests/Common/CMakeLists.txt
@@ -1,3 +1,11 @@
+#===-- unittests/Common/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_unittest(FlangCommonTests
   FastIntSetTest.cpp
 )
diff --git a/FortranRuntime/unittests/Decimal/CMakeLists.txt b/FortranRuntime/unittests/Decimal/CMakeLists.txt
index d301a9d3628c56..40b89b48e1adeb 100644
--- a/FortranRuntime/unittests/Decimal/CMakeLists.txt
+++ b/FortranRuntime/unittests/Decimal/CMakeLists.txt
@@ -1,3 +1,11 @@
+#===-- unittests/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
+#
+#===------------------------------------------------------------------------===#
+
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
 add_flang_nongtest_unittest(quick-sanity-test
   FortranDecimal
diff --git a/FortranRuntime/unittests/Evaluate/CMakeLists.txt b/FortranRuntime/unittests/Evaluate/CMakeLists.txt
index b4cc72b748efd5..e0a284b9d39f3b 100644
--- a/FortranRuntime/unittests/Evaluate/CMakeLists.txt
+++ b/FortranRuntime/unittests/Evaluate/CMakeLists.txt
@@ -1,3 +1,11 @@
+#===-- unittests/Evaluate/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_nongtest_unittest(reshape
   FortranEvaluateTesting
   FortranSemantics
diff --git a/FortranRuntime/unittests/Runtime/CMakeLists.txt b/FortranRuntime/unittests/Runtime/CMakeLists.txt
index 2c3f8c1a9e9ac8..295b0116cbbda7 100644
--- a/FortranRuntime/unittests/Runtime/CMakeLists.txt
+++ b/FortranRuntime/unittests/Runtime/CMakeLists.txt
@@ -1,3 +1,11 @@
+#===-- unittests/Runtime/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_unittest(FlangRuntimeTests
   AccessTest.cpp
   Allocatable.cpp
diff --git a/FortranRuntime/unittests/Runtime/CUDA/CMakeLists.txt b/FortranRuntime/unittests/Runtime/CUDA/CMakeLists.txt
index ed0caece3d15db..685b4bf5596c2c 100644
--- a/FortranRuntime/unittests/Runtime/CUDA/CMakeLists.txt
+++ b/FortranRuntime/unittests/Runtime/CUDA/CMakeLists.txt
@@ -1,3 +1,11 @@
+#===-- unittests/Runtime/CUDA/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 (FLANG_CUF_RUNTIME)
 
 add_flang_unittest(FlangCufRuntimeTests
diff --git a/FortranRuntime/unittests/Runtime/Complex.cpp b/FortranRuntime/unittests/Runtime/Complex.cpp
index d714da24dc4e58..daa4b5c7960842 100644
--- a/FortranRuntime/unittests/Runtime/Complex.cpp
+++ b/FortranRuntime/unittests/Runtime/Complex.cpp
@@ -1,4 +1,4 @@
-//===-- 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.
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index a7f23ee59d192c..009eed8a085a9a 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -538,7 +538,7 @@ endif()
 include(GetClangResourceDir)
 get_clang_resource_dir(HEADER_BINARY_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include)
 configure_file(
-  ../FortranRuntime/include/flang/Common/ISO_Fortran_binding.h
+  ${FLANG_SOURCE_DIR}/include/flang/ISO_Fortran_binding.h
   ${HEADER_BINARY_DIR}/ISO_Fortran_binding.h)
 
 # And also install it into the install area
diff --git a/FortranRuntime/include/flang/Common/ISO_Fortran_binding.h b/flang/include/flang/ISO_Fortran_binding.h
similarity index 100%
rename from FortranRuntime/include/flang/Common/ISO_Fortran_binding.h
rename to flang/include/flang/ISO_Fortran_binding.h
diff --git a/flang/lib/Evaluate/fold-logical.cpp b/flang/lib/Evaluate/fold-logical.cpp
index ee6655f8387177..a7e1aad38f3586 100644
--- a/flang/lib/Evaluate/fold-logical.cpp
+++ b/flang/lib/Evaluate/fold-logical.cpp
@@ -9,8 +9,8 @@
 #include "fold-implementation.h"
 #include "fold-matmul.h"
 #include "fold-reduction.h"
+#include "flang/Common/magic-numbers.h"
 #include "flang/Evaluate/check-expression.h"
-#include "flang/Runtime/magic-numbers.h"
 
 namespace Fortran::evaluate {
 
diff --git a/FortranRuntime/module/.clang-format b/flang/module/.clang-format
similarity index 100%
rename from FortranRuntime/module/.clang-format
rename to flang/module/.clang-format
diff --git a/FortranRuntime/module/__cuda_builtins.f90 b/flang/module/__cuda_builtins.f90
similarity index 100%
rename from FortranRuntime/module/__cuda_builtins.f90
rename to flang/module/__cuda_builtins.f90
diff --git a/FortranRuntime/module/__fortran_builtins.f90 b/flang/module/__fortran_builtins.f90
similarity index 99%
rename from FortranRuntime/module/__fortran_builtins.f90
rename to flang/module/__fortran_builtins.f90
index d1d4a639e70d72..fe91305c836ff4 100644
--- a/FortranRuntime/module/__fortran_builtins.f90
+++ b/flang/module/__fortran_builtins.f90
@@ -6,7 +6,7 @@
 !
 !===------------------------------------------------------------------------===!
 
-#include '../include/flang/Runtime/magic-numbers.h'
+#include '../../FortranRuntime/include/flang/Common/magic-numbers.h'
 
 ! These naming shenanigans prevent names from Fortran intrinsic modules
 ! from being usable on INTRINSIC statements, and force the program
diff --git a/FortranRuntime/module/__fortran_ieee_exceptions.f90 b/flang/module/__fortran_ieee_exceptions.f90
similarity index 98%
rename from FortranRuntime/module/__fortran_ieee_exceptions.f90
rename to flang/module/__fortran_ieee_exceptions.f90
index 6691012eda238a..56f79a473b556a 100644
--- a/FortranRuntime/module/__fortran_ieee_exceptions.f90
+++ b/flang/module/__fortran_ieee_exceptions.f90
@@ -11,7 +11,7 @@
 ! here under another name so that IEEE_ARITHMETIC can USE it and export its
 ! declarations without clashing with a non-intrinsic module in a program.
 
-#include '../include/flang/Runtime/magic-numbers.h'
+#include '../../FortranRuntime/include/flang/Common/magic-numbers.h'
 
 module __fortran_ieee_exceptions
   use __fortran_builtins, only: &
diff --git a/FortranRuntime/module/__fortran_type_info.f90 b/flang/module/__fortran_type_info.f90
similarity index 100%
rename from FortranRuntime/module/__fortran_type_info.f90
rename to flang/module/__fortran_type_info.f90
diff --git a/FortranRuntime/module/__ppc_intrinsics.f90 b/flang/module/__ppc_intrinsics.f90
similarity index 100%
rename from FortranRuntime/module/__ppc_intrinsics.f90
rename to flang/module/__ppc_intrinsics.f90
diff --git a/FortranRuntime/module/__ppc_types.f90 b/flang/module/__ppc_types.f90
similarity index 100%
rename from FortranRuntime/module/__ppc_types.f90
rename to flang/module/__ppc_types.f90
diff --git a/FortranRuntime/module/cudadevice.f90 b/flang/module/cudadevice.f90
similarity index 100%
rename from FortranRuntime/module/cudadevice.f90
rename to flang/module/cudadevice.f90
diff --git a/FortranRuntime/module/ieee_arithmetic.f90 b/flang/module/ieee_arithmetic.f90
similarity index 99%
rename from FortranRuntime/module/ieee_arithmetic.f90
rename to flang/module/ieee_arithmetic.f90
index 7eaa7db55af9f8..667374d0660806 100644
--- a/FortranRuntime/module/ieee_arithmetic.f90
+++ b/flang/module/ieee_arithmetic.f90
@@ -8,7 +8,7 @@
 
 ! Fortran 2018 Clause 17
 
-#include '../include/flang/Runtime/magic-numbers.h'
+#include '../../FortranRuntime/include/flang/Common/magic-numbers.h'
 
 module ieee_arithmetic
   ! F18 Clause 17.1p1:
diff --git a/FortranRuntime/module/ieee_exceptions.f90 b/flang/module/ieee_exceptions.f90
similarity index 100%
rename from FortranRuntime/module/ieee_exceptions.f90
rename to flang/module/ieee_exceptions.f90
diff --git a/FortranRuntime/module/ieee_features.f90 b/flang/module/ieee_features.f90
similarity index 100%
rename from FortranRuntime/module/ieee_features.f90
rename to flang/module/ieee_features.f90
diff --git a/FortranRuntime/module/iso_c_binding.f90 b/flang/module/iso_c_binding.f90
similarity index 100%
rename from FortranRuntime/module/iso_c_binding.f90
rename to flang/module/iso_c_binding.f90
diff --git a/FortranRuntime/module/iso_fortran_env.f90 b/flang/module/iso_fortran_env.f90
similarity index 98%
rename from FortranRuntime/module/iso_fortran_env.f90
rename to flang/module/iso_fortran_env.f90
index 4e575b422c2a04..d1f956b6b86408 100644
--- a/FortranRuntime/module/iso_fortran_env.f90
+++ b/flang/module/iso_fortran_env.f90
@@ -8,7 +8,7 @@
 
 ! See Fortran 2023, subclause 16.10.2
 
-#include '../include/flang/Runtime/magic-numbers.h'
+#include '../../FortranRuntime/include/flang/Common/magic-numbers.h'
 
 module iso_fortran_env
 
diff --git a/FortranRuntime/module/mma.f90 b/flang/module/mma.f90
similarity index 100%
rename from FortranRuntime/module/mma.f90
rename to flang/module/mma.f90
diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index 664c18f406c08c..f4ebc784a26cc8 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -105,7 +105,7 @@ if (NOT CMAKE_CROSSCOMPILING)
     set(compile_with "-fsyntax-only")
     set(object_output "")
     set(include_in_link FALSE)
-    set(fullpath "${FLANG_SOURCE_DIR}/../FortranRuntime/module/${filename}.f90")
+    set(fullpath "${FLANG_SOURCE_DIR}/module/${filename}.f90")
     if(${filename} IN_LIST MODULES_WITH_IMPLEMENTATION)
       set(object_output "${CMAKE_CURRENT_BINARY_DIR}/${filename}${CMAKE_CXX_OUTPUT_EXTENSION}")
       set(compile_with -c -o ${object_output})
@@ -119,7 +119,7 @@ if (NOT CMAKE_CROSSCOMPILING)
       COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
       COMMAND flang-new ${opts} ${decls} -cpp ${compile_with} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
         ${fullpath}
-      DEPENDS flang-new ${fullpath} ${FLANG_SOURCE_DIR}/../FortranRuntime/module/__fortran_builtins.f90 ${depends}
+      DEPENDS flang-new ${fullpath} ${FLANG_SOURCE_DIR}/module/__fortran_builtins.f90 ${depends}
     )
     list(APPEND MODULE_FILES ${base}.mod)
     install(FILES ${base}.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")

>From 8b984fea71966e325e8e1306ab1da34be47ff746 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 7 Oct 2024 16:03:14 +0200
Subject: [PATCH 03/12] Move runtime tests

Due to missing lit.cfg, will only be executing again after #110217.
---
 {flang => FortranRuntime}/test/Driver/ctofortran.f90 | 0
 {flang => FortranRuntime}/test/Driver/exec.f90       | 0
 {flang => FortranRuntime}/test/Runtime/no-cpp-dep.c  | 0
 3 files changed, 0 insertions(+), 0 deletions(-)
 rename {flang => FortranRuntime}/test/Driver/ctofortran.f90 (100%)
 rename {flang => FortranRuntime}/test/Driver/exec.f90 (100%)
 rename {flang => FortranRuntime}/test/Runtime/no-cpp-dep.c (100%)

diff --git a/flang/test/Driver/ctofortran.f90 b/FortranRuntime/test/Driver/ctofortran.f90
similarity index 100%
rename from flang/test/Driver/ctofortran.f90
rename to FortranRuntime/test/Driver/ctofortran.f90
diff --git a/flang/test/Driver/exec.f90 b/FortranRuntime/test/Driver/exec.f90
similarity index 100%
rename from flang/test/Driver/exec.f90
rename to FortranRuntime/test/Driver/exec.f90
diff --git a/flang/test/Runtime/no-cpp-dep.c b/FortranRuntime/test/Runtime/no-cpp-dep.c
similarity index 100%
rename from flang/test/Runtime/no-cpp-dep.c
rename to FortranRuntime/test/Runtime/no-cpp-dep.c

>From 33ada12190ac767919836445f3a3d53f530df3e2 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Tue, 8 Oct 2024 16:38:59 +0200
Subject: [PATCH 04/12] Undo workaround not required anymore

---
 flang/module/mma.f90 | 43 +++++++++++--------------------------------
 1 file changed, 11 insertions(+), 32 deletions(-)

diff --git a/flang/module/mma.f90 b/flang/module/mma.f90
index 14aab69035a334..4c41822e000a3d 100644
--- a/flang/module/mma.f90
+++ b/flang/module/mma.f90
@@ -55,18 +55,9 @@ pure __vector_pair function func_vpi0vp(arg1, arg2); \
     !dir$ ignore_tkr(r) arg2; \
   end function;
 
-! FIXME: Potential Flang bug: combining multiple of those on a single line breaks after preprocessing as an explicit step as done by CMake
-! Line counting is also wrong
-  FUNC_VPI0VI(1)
-  FUNC_VPI0VI(2)
-  FUNC_VPI0VI(4)
-  FUNC_VPI0VI(8)
-  FUNC_VPI0VU(1)
-  FUNC_VPI0VU(2)
-  FUNC_VPI0VU(4)
-  FUNC_VPI0VU(8)
-  FUNC_VPI0VR(4)
-  FUNC_VPI0VR(8)
+  FUNC_VPI0VI(1) FUNC_VPI0VI(2) FUNC_VPI0VI(4) FUNC_VPI0VI(8)
+  FUNC_VPI0VU(1) FUNC_VPI0VU(2) FUNC_VPI0VU(4) FUNC_VPI0VU(8)
+  FUNC_VPI0VR(4) FUNC_VPI0VR(8)
   FUNC_VPI0VP
 
 #undef FUNC_VPI0VP
@@ -153,26 +144,14 @@ elemental subroutine sub_vpvr##VKIND##vr##VKIND(pair, arg1, arg2); \
     vector(real(VKIND)), intent(in) :: arg1, arg2; \
   end subroutine ;
 
-  ELEM_SUB_VPVIVI(1)
-  ELEM_SUB_VPVIVI(2)
-  ELEM_SUB_VPVIVI(4)
-  ELEM_SUB_VPVIVI(8)
-  ELEM_SUB_VPVUVU(1)
-  ELEM_SUB_VPVUVU(2)
-  ELEM_SUB_VPVUVU(4)
-  ELEM_SUB_VPVUVU(8)
-  ELEM_SUB_VPVRVR(4)
-  ELEM_SUB_VPVRVR(8)
-  SUB_VPI0VI(1)
-  SUB_VPI0VI(2)
-  SUB_VPI0VI(4)
-  SUB_VPI0VI(8)
-  SUB_VPI0VU(1)
-  SUB_VPI0VU(2)
-  SUB_VPI0VU(4)
-  SUB_VPI0VU(8)
-  SUB_VPI0VR(4)
-  SUB_VPI0VR(8)
+  ELEM_SUB_VPVIVI(1) ELEM_SUB_VPVIVI(2)
+  ELEM_SUB_VPVIVI(4) ELEM_SUB_VPVIVI(8)
+  ELEM_SUB_VPVUVU(1) ELEM_SUB_VPVUVU(2)
+  ELEM_SUB_VPVUVU(4) ELEM_SUB_VPVUVU(8)
+  ELEM_SUB_VPVRVR(4) ELEM_SUB_VPVRVR(8)
+  SUB_VPI0VI(1) SUB_VPI0VI(2) SUB_VPI0VI(4) SUB_VPI0VI(8)
+  SUB_VPI0VU(1) SUB_VPI0VU(2) SUB_VPI0VU(4) SUB_VPI0VU(8)
+  SUB_VPI0VR(4) SUB_VPI0VR(8)
 
 #undef ELEM_SUB_VPVIVI
 #undef ELEM_SUB_VPVUVU

>From 42e5abb5b291e78aeb152d7c636c75fe4d90492a Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 14 Oct 2024 13:55:16 +0200
Subject: [PATCH 05/12] Split headers in preparation for cross-compilation.
 NFC.

---
 flang/include/flang/Lower/Allocatable.h       |  2 +-
 .../flang/Optimizer/Builder/MutableBox.h      |  2 +-
 .../flang/Optimizer/CodeGen/DescriptorModel.h |  2 +-
 flang/include/flang/Runtime/CUDA/allocator.h  |  2 +-
 flang/include/flang/Runtime/CUDA/descriptor.h |  2 +-
 .../flang/Runtime/allocator-registry-consts.h | 20 +++++
 .../flang/Runtime/allocator-registry.h        |  9 +--
 .../flang/Runtime/array-constructor-consts.h  | 54 +++++++++++++
 .../include/flang/Runtime/array-constructor.h | 80 +++----------------
 .../include/flang/Runtime/descriptor-consts.h | 72 +++++++++++++++++
 flang/include/flang/Runtime/descriptor.h      | 15 +---
 flang/include/flang/Runtime/io-api-funcs.h    | 39 +++++++++
 flang/include/flang/Runtime/io-api.h          |  3 -
 flang/include/flang/Runtime/iostat-funcs.h    | 23 ++++++
 flang/include/flang/Runtime/iostat.h          |  2 -
 flang/lib/Lower/ConvertVariable.cpp           |  2 +-
 .../Builder/Runtime/ArrayConstructor.cpp      |  6 +-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp       | 18 ++---
 flang/lib/Semantics/compute-offsets.cpp       |  8 +-
 flang/runtime/environment-default-list.h      |  0
 flang/runtime/extensions.cpp                  |  2 +-
 flang/runtime/internal-unit.cpp               |  2 +
 flang/runtime/io-api-common.h                 |  2 +-
 flang/runtime/io-api-minimal.cpp              |  2 +-
 flang/runtime/io-api.cpp                      |  2 +-
 flang/runtime/io-error.h                      |  2 +-
 flang/runtime/io-stmt.h                       |  2 +-
 flang/runtime/iostat.cpp                      |  2 +-
 flang/runtime/namelist.cpp                    |  2 +-
 .../Builder/Runtime/AllocatableTest.cpp       |  2 +-
 30 files changed, 254 insertions(+), 127 deletions(-)
 create mode 100644 flang/include/flang/Runtime/allocator-registry-consts.h
 create mode 100644 flang/include/flang/Runtime/array-constructor-consts.h
 create mode 100644 flang/include/flang/Runtime/descriptor-consts.h
 create mode 100644 flang/include/flang/Runtime/io-api-funcs.h
 create mode 100644 flang/include/flang/Runtime/iostat-funcs.h
 mode change 100755 => 100644 flang/runtime/environment-default-list.h

diff --git a/flang/include/flang/Lower/Allocatable.h b/flang/include/flang/Lower/Allocatable.h
index 1209b157ed1f41..0e89af94af40f6 100644
--- a/flang/include/flang/Lower/Allocatable.h
+++ b/flang/include/flang/Lower/Allocatable.h
@@ -15,7 +15,7 @@
 
 #include "flang/Lower/AbstractConverter.h"
 #include "flang/Optimizer/Builder/MutableBox.h"
-#include "flang/Runtime/allocator-registry.h"
+#include "flang/Runtime/allocator-registry-consts.h"
 #include "llvm/ADT/StringRef.h"
 
 namespace mlir {
diff --git a/flang/include/flang/Optimizer/Builder/MutableBox.h b/flang/include/flang/Optimizer/Builder/MutableBox.h
index fea7c7204837b4..39657ddaf6e03a 100644
--- a/flang/include/flang/Optimizer/Builder/MutableBox.h
+++ b/flang/include/flang/Optimizer/Builder/MutableBox.h
@@ -14,7 +14,7 @@
 #define FORTRAN_OPTIMIZER_BUILDER_MUTABLEBOX_H
 
 #include "flang/Optimizer/Builder/BoxValue.h"
-#include "flang/Runtime/allocator-registry.h"
+#include "flang/Runtime/allocator-registry-consts.h"
 #include "llvm/ADT/StringRef.h"
 
 namespace mlir {
diff --git a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
index ff0cf29e8073e6..9cccf8db87270e 100644
--- a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
+++ b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
@@ -23,7 +23,7 @@
 #define OPTIMIZER_DESCRIPTOR_MODEL_H
 
 #include "flang/ISO_Fortran_binding_wrapper.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
 #include "mlir/IR/BuiltinTypes.h"
 #include "llvm/Support/ErrorHandling.h"
diff --git a/flang/include/flang/Runtime/CUDA/allocator.h b/flang/include/flang/Runtime/CUDA/allocator.h
index 4527c9f18fa054..cc88896b1f0bd6 100644
--- a/flang/include/flang/Runtime/CUDA/allocator.h
+++ b/flang/include/flang/Runtime/CUDA/allocator.h
@@ -9,7 +9,7 @@
 #ifndef FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
 #define FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
 
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
 
 #define CUDA_REPORT_IF_ERROR(expr) \
diff --git a/flang/include/flang/Runtime/CUDA/descriptor.h b/flang/include/flang/Runtime/CUDA/descriptor.h
index d593989420420f..501a834f43bd42 100644
--- a/flang/include/flang/Runtime/CUDA/descriptor.h
+++ b/flang/include/flang/Runtime/CUDA/descriptor.h
@@ -9,7 +9,7 @@
 #ifndef FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_
 #define FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_
 
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
 #include <cstddef>
 
diff --git a/flang/include/flang/Runtime/allocator-registry-consts.h b/flang/include/flang/Runtime/allocator-registry-consts.h
new file mode 100644
index 00000000000000..70735c2fc7a71c
--- /dev/null
+++ b/flang/include/flang/Runtime/allocator-registry-consts.h
@@ -0,0 +1,20 @@
+//===-- include/flang/Runtime/allocator-registry-consts.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_ALLOCATOR_REGISTRY_CONSTS_H_
+#define FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_CONSTS_H_
+
+static constexpr unsigned kDefaultAllocator = 0;
+
+// Allocator used for CUF
+static constexpr unsigned kPinnedAllocatorPos = 1;
+static constexpr unsigned kDeviceAllocatorPos = 2;
+static constexpr unsigned kManagedAllocatorPos = 3;
+static constexpr unsigned kUnifiedAllocatorPos = 4;
+
+#endif /* FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_CONSTS_H_ */
diff --git a/flang/include/flang/Runtime/allocator-registry.h b/flang/include/flang/Runtime/allocator-registry.h
index acfada506fafc6..c5db7b2b1f2014 100644
--- a/flang/include/flang/Runtime/allocator-registry.h
+++ b/flang/include/flang/Runtime/allocator-registry.h
@@ -10,17 +10,10 @@
 #define FORTRAN_RUNTIME_ALLOCATOR_H_
 
 #include "flang/Common/api-attrs.h"
+#include "flang/Runtime/allocator-registry-consts.h"
 #include <cstdlib>
 #include <vector>
 
-static constexpr unsigned kDefaultAllocator = 0;
-
-// Allocator used for CUF
-static constexpr unsigned kPinnedAllocatorPos = 1;
-static constexpr unsigned kDeviceAllocatorPos = 2;
-static constexpr unsigned kManagedAllocatorPos = 3;
-static constexpr unsigned kUnifiedAllocatorPos = 4;
-
 #define MAX_ALLOCATOR 7 // 3 bits are reserved in the descriptor.
 
 namespace Fortran::runtime {
diff --git a/flang/include/flang/Runtime/array-constructor-consts.h b/flang/include/flang/Runtime/array-constructor-consts.h
new file mode 100644
index 00000000000000..da058874e50487
--- /dev/null
+++ b/flang/include/flang/Runtime/array-constructor-consts.h
@@ -0,0 +1,54 @@
+//===-- include/flang/Runtime/array-constructor-consts.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
+//
+//===----------------------------------------------------------------------===//
+
+// External APIs to create temporary storage for array constructors when their
+// final extents or length parameters cannot be pre-computed.
+
+#ifndef FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_
+#define FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_
+
+#include "flang/Runtime/descriptor-consts.h"
+#include "flang/Runtime/entry-names.h"
+#include <cstdint>
+
+namespace Fortran::runtime {
+struct ArrayConstructorVector;
+
+// Max sizeof(ArrayConstructorVector) and sizeof(ArrayConstructorVector) for any
+// target.
+// TODO: Use target-specific size/alignment instead of overapproximation.
+constexpr std::size_t MaxArrayConstructorVectorSizeInBytes = 2 * 40;
+constexpr std::size_t MaxArrayConstructorVectorAlignInBytes = 8;
+
+extern "C" {
+// API to initialize an ArrayConstructorVector before any values are pushed to
+// it. Inlined code is only expected to allocate the "ArrayConstructorVector"
+// class instance storage with sufficient size (using
+// "2*sizeof(ArrayConstructorVector)" on the host should be safe regardless of
+// the target the runtime is compiled for). This avoids the need for the runtime
+// to maintain a state, or to use dynamic allocation for it. "vectorClassSize"
+// is used to validate that lowering allocated enough space for it.
+void RTDECL(InitArrayConstructorVector)(ArrayConstructorVector &vector,
+    Descriptor &to, bool useValueLengthParameters, int vectorClassSize,
+    const char *sourceFile = nullptr, int sourceLine = 0);
+
+// Generic API to push any kind of entity into the array constructor (any
+// Fortran type and any rank).
+void RTDECL(PushArrayConstructorValue)(
+    ArrayConstructorVector &vector, const Descriptor &from);
+
+// API to push scalar array constructor value of:
+//   - a numerical or logical type,
+//   - or a derived type that has no length parameters, and no allocatable
+//   component (that would require deep copies).
+// It requires no descriptor for the value that is passed via its base address.
+void RTDECL(PushArrayConstructorSimpleScalar)(
+    ArrayConstructorVector &vector, void *from);
+} // extern "C"
+} // namespace Fortran::runtime
+#endif /* FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_ */
diff --git a/flang/include/flang/Runtime/array-constructor.h b/flang/include/flang/Runtime/array-constructor.h
index 46fc0418c7991e..c068af9ba120c0 100644
--- a/flang/include/flang/Runtime/array-constructor.h
+++ b/flang/include/flang/Runtime/array-constructor.h
@@ -12,6 +12,7 @@
 #ifndef FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
 #define FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
 
+#include "flang/Runtime/array-constructor-consts.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/entry-names.h"
 #include <cstdint>
@@ -42,77 +43,14 @@ struct ArrayConstructorVector {
 private:
   unsigned char useValueLengthParameters_ : 1;
 };
+static_assert(sizeof(Fortran::runtime::ArrayConstructorVector) <=
+        MaxArrayConstructorVectorSizeInBytes,
+    "ABI requires sizeof(ArrayConstructorVector) to be smaller than "
+    "MaxArrayConstructorVectorSizeInBytes");
+static_assert(alignof(Fortran::runtime::ArrayConstructorVector) <=
+        MaxArrayConstructorVectorAlignInBytes,
+    "ABI requires alignof(ArrayConstructorVector) to be smaller than "
+    "MaxArrayConstructorVectorAlignInBytes");
 
-// This file defines an API to "push" an evaluated array constructor value
-// "from" into some storage "to" of an array constructor. It can be seen as a
-// form of std::vector::push_back() implementation for Fortran array
-// constructors. In the APIs and ArrayConstructorVector struct above:
-//
-// - "to" is a ranked-1 descriptor whose declared type is already set to the
-// array constructor derived type. It may be already allocated, even before the
-// first call to this API, or it may be unallocated. "to" extent is increased
-// every time a "from" is pushed past its current extent. At this end of the
-// API calls, its extent is the extent of the array constructor. If "to" is
-// unallocated and its extent is not null, it is assumed this is the final array
-// constructor extent value, and the first allocation already "reserves" storage
-// space accordingly to avoid reallocations.
-//  - "from" is a scalar or array descriptor for the evaluated array
-//  constructor value that must be copied into the storage of "to" at
-//  "nextValuePosition".
-//  - "useValueLengthParameters" must be set to true if the array constructor
-//  has length parameters and no type spec. If it is true and "to" is
-//  unallocated, "to" will take the length parameters of "from". If it is true
-//  and "to" is an allocated character array constructor, it will be checked
-//  that "from" length matches the one from "to". When it is false, the
-//  character length must already be set in "to" before the first call to this
-//  API and "from" character lengths are allowed to mismatch from "to".
-// - "nextValuePosition" is the zero based sequence position of "from" in the
-// array constructor. It is updated after this call by the number of "from"
-// elements. It should be set to zero by the caller of this API before the first
-// call.
-// - "actualAllocationSize" is the current allocation size of "to" storage. It
-// may be bigger than "to" extent for reallocation optimization purposes, but
-// should never be smaller, unless this is the first call and "to" is
-// unallocated. It is updated by the runtime after each successful allocation or
-// reallocation. It should be set to "to" extent if "to" is allocated before the
-// first call of this API, and can be left undefined otherwise.
-//
-// Note that this API can be used with "to" being a variable (that can be
-// discontiguous). This can be done when the variable is the left hand side of
-// an assignment from an array constructor as long as:
-//  - none of the ac-value overlaps with the variable,
-//  - this is an intrinsic assignment that is not a whole allocatable
-//  assignment, *and* for a type that has no components requiring user defined
-//  assignments,
-//  - the variable is properly finalized before using this API if its need to,
-//  - "useValueLengthParameters" should be set to false in this case, even if
-//  the array constructor has no type-spec, since the variable may have a
-//  different character length than the array constructor values.
-
-extern "C" {
-// API to initialize an ArrayConstructorVector before any values are pushed to
-// it. Inlined code is only expected to allocate the "ArrayConstructorVector"
-// class instance storage with sufficient size (using
-// "2*sizeof(ArrayConstructorVector)" on the host should be safe regardless of
-// the target the runtime is compiled for). This avoids the need for the runtime
-// to maintain a state, or to use dynamic allocation for it. "vectorClassSize"
-// is used to validate that lowering allocated enough space for it.
-void RTDECL(InitArrayConstructorVector)(ArrayConstructorVector &vector,
-    Descriptor &to, bool useValueLengthParameters, int vectorClassSize,
-    const char *sourceFile = nullptr, int sourceLine = 0);
-
-// Generic API to push any kind of entity into the array constructor (any
-// Fortran type and any rank).
-void RTDECL(PushArrayConstructorValue)(
-    ArrayConstructorVector &vector, const Descriptor &from);
-
-// API to push scalar array constructor value of:
-//   - a numerical or logical type,
-//   - or a derived type that has no length parameters, and no allocatable
-//   component (that would require deep copies).
-// It requires no descriptor for the value that is passed via its base address.
-void RTDECL(PushArrayConstructorSimpleScalar)(
-    ArrayConstructorVector &vector, void *from);
-} // extern "C"
 } // namespace Fortran::runtime
 #endif // FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h
new file mode 100644
index 00000000000000..098eb59ca01b2e
--- /dev/null
+++ b/flang/include/flang/Runtime/descriptor-consts.h
@@ -0,0 +1,72 @@
+//===-- include/flang/Runtime/descriptor-consts.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_DESCRIPTOR_CONSTS_H_
+#define FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_
+
+#include "flang/Common/api-attrs.h"
+#include "flang/ISO_Fortran_binding_wrapper.h"
+#include <cstddef>
+#include <cstdint>
+
+// Value of the addendum presence flag.
+#define _CFI_ADDENDUM_FLAG 1
+// Number of bits needed to be shifted when manipulating the allocator index.
+#define _CFI_ALLOCATOR_IDX_SHIFT 1
+// Allocator index mask.
+#define _CFI_ALLOCATOR_IDX_MASK 0b00001110
+
+namespace Fortran::runtime::typeInfo {
+using TypeParameterValue = std::int64_t;
+class DerivedType;
+} // namespace Fortran::runtime::typeInfo
+
+namespace Fortran::runtime {
+class Descriptor;
+
+/// Returns size in bytes of the descriptor (not the data)
+/// This must be at least as large as the largest descriptor of any target
+/// triple.
+static constexpr RT_API_ATTRS std::size_t MaxDescriptorSizeInBytes(
+    int rank, bool addendum = false, int lengthTypeParameters = 0) {
+  // Layout:
+  //
+  // fortran::runtime::Descriptor {
+  //   ISO::CFI_cdesc_t {
+  //     void *base_addr;           (pointer -> up to 8 bytes)
+  //     size_t elem_len;           (up to 8 bytes)
+  //     int version;               (up to 4 bytes)
+  //     CFI_rank_t rank;           (unsigned char -> 1 byte)
+  //     CFI_type_t type;           (signed char -> 1 byte)
+  //     CFI_attribute_t attribute; (unsigned char -> 1 byte)
+  //     unsigned char extra;       (1 byte)
+  //   }
+  // }
+  // fortran::runtime::Dimension[rank] {
+  //   ISO::CFI_dim_t {
+  //     CFI_index_t lower_bound; (ptrdiff_t -> up to 8 bytes)
+  //     CFI_index_t extent;      (ptrdiff_t -> up to 8 bytes)
+  //     CFI_index_t sm;          (ptrdiff_t -> up to 8 bytes)
+  //   }
+  // }
+  // fortran::runtime::DescriptorAddendum {
+  //   const typeInfo::DerivedType *derivedType_;        (pointer -> up to 8
+  //   bytes) typeInfo::TypeParameterValue len_[lenParameters]; (int64_t -> 8
+  //   bytes)
+  // }
+  std::size_t bytes{24u + rank * 24u};
+  if (addendum || lengthTypeParameters > 0) {
+    if (lengthTypeParameters < 1)
+      lengthTypeParameters = 1;
+    bytes += 8u + static_cast<std::size_t>(lengthTypeParameters) * 8u;
+  }
+  return bytes;
+}
+
+} // namespace Fortran::runtime
+#endif /* FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_ */
diff --git a/flang/include/flang/Runtime/descriptor.h b/flang/include/flang/Runtime/descriptor.h
index 030d0c1031fbaa..6d0f09c79508cb 100644
--- a/flang/include/flang/Runtime/descriptor.h
+++ b/flang/include/flang/Runtime/descriptor.h
@@ -19,6 +19,7 @@
 // but should never reference this internal header.
 
 #include "flang/ISO_Fortran_binding_wrapper.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/memory.h"
 #include "flang/Runtime/type-code.h"
 #include <algorithm>
@@ -28,11 +29,6 @@
 #include <cstdio>
 #include <cstring>
 
-namespace Fortran::runtime::typeInfo {
-using TypeParameterValue = std::int64_t;
-class DerivedType;
-} // namespace Fortran::runtime::typeInfo
-
 namespace Fortran::runtime {
 
 using SubscriptValue = ISO::CFI_index_t;
@@ -420,13 +416,6 @@ class Descriptor {
 
   void Dump(FILE * = stdout) const;
 
-// Value of the addendum presence flag.
-#define _CFI_ADDENDUM_FLAG 1
-// Number of bits needed to be shifted when manipulating the allocator index.
-#define _CFI_ALLOCATOR_IDX_SHIFT 1
-// Allocator index mask.
-#define _CFI_ALLOCATOR_IDX_MASK 0b00001110
-
   RT_API_ATTRS inline bool HasAddendum() const {
     return raw_.extra & _CFI_ADDENDUM_FLAG;
   }
@@ -464,6 +453,8 @@ class alignas(Descriptor) StaticDescriptor {
   static constexpr bool hasAddendum{ADDENDUM || MAX_LEN_PARMS > 0};
   static constexpr std::size_t byteSize{
       Descriptor::SizeInBytes(maxRank, hasAddendum, maxLengthTypeParameters)};
+  static_assert(byteSize <=
+      MaxDescriptorSizeInBytes(maxRank, hasAddendum, maxLengthTypeParameters));
   RT_OFFLOAD_VAR_GROUP_END
 
   RT_API_ATTRS Descriptor &descriptor() {
diff --git a/flang/include/flang/Runtime/io-api-funcs.h b/flang/include/flang/Runtime/io-api-funcs.h
new file mode 100644
index 00000000000000..e81c3cb8156c4e
--- /dev/null
+++ b/flang/include/flang/Runtime/io-api-funcs.h
@@ -0,0 +1,39 @@
+//===-- include/flang/Runtime/io-api-funcs.h --------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Defines API between compiled code and I/O runtime library.
+
+#ifndef FORTRAN_RUNTIME_IO_API_FUNCS_H_
+#define FORTRAN_RUNTIME_IO_API_FUNCS_H_
+
+#include "flang/Common/uint128.h"
+#include "flang/Runtime/entry-names.h"
+#include "flang/Runtime/io-api.h"
+#include "flang/Runtime/iostat.h"
+#include "flang/Runtime/magic-numbers.h"
+#include <cinttypes>
+#include <cstddef>
+
+namespace Fortran::runtime {
+class Descriptor;
+} // namespace Fortran::runtime
+
+namespace Fortran::runtime::io {
+
+struct NonTbpDefinedIoTable;
+class NamelistGroup;
+class IoStatementState;
+using Cookie = IoStatementState *;
+using ExternalUnit = int;
+using AsynchronousId = int;
+
+RT_API_ATTRS const char *InquiryKeywordHashDecode(
+    char *buffer, std::size_t, InquiryKeywordHash);
+
+} // namespace Fortran::runtime::io
+#endif /* FORTRAN_RUNTIME_IO_API_FUNCS_H_ */
diff --git a/flang/include/flang/Runtime/io-api.h b/flang/include/flang/Runtime/io-api.h
index 328afc715a3f1e..e588b46dc4b3a1 100644
--- a/flang/include/flang/Runtime/io-api.h
+++ b/flang/include/flang/Runtime/io-api.h
@@ -51,9 +51,6 @@ constexpr InquiryKeywordHash HashInquiryKeyword(const char *p) {
   return hash;
 }
 
-RT_API_ATTRS const char *InquiryKeywordHashDecode(
-    char *buffer, std::size_t, InquiryKeywordHash);
-
 extern "C" {
 
 #define IONAME(name) RTNAME(io##name)
diff --git a/flang/include/flang/Runtime/iostat-funcs.h b/flang/include/flang/Runtime/iostat-funcs.h
new file mode 100644
index 00000000000000..3ab4527ea829ae
--- /dev/null
+++ b/flang/include/flang/Runtime/iostat-funcs.h
@@ -0,0 +1,23 @@
+//===-- include/flang/Runtime/iostat-funcs.h --------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Defines the values returned by the runtime for IOSTAT= specifiers
+// on I/O statements.
+
+#ifndef FORTRAN_RUNTIME_IOSTAT_FUNCS_H_
+#define FORTRAN_RUNTIME_IOSTAT_FUNCS_H_
+
+#include "flang/Common/api-attrs.h"
+#include "flang/Runtime/iostat.h"
+
+namespace Fortran::runtime::io {
+
+RT_API_ATTRS const char *IostatErrorString(int);
+
+} // namespace Fortran::runtime::io
+#endif /* FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ */
diff --git a/flang/include/flang/Runtime/iostat.h b/flang/include/flang/Runtime/iostat.h
index 6ce7c82b424eb7..0565718f6c103d 100644
--- a/flang/include/flang/Runtime/iostat.h
+++ b/flang/include/flang/Runtime/iostat.h
@@ -89,7 +89,5 @@ enum Iostat {
   IostatNonExternalDefinedUnformattedIo,
 };
 
-RT_API_ATTRS const char *IostatErrorString(int);
-
 } // namespace Fortran::runtime::io
 #endif // FORTRAN_RUNTIME_IOSTAT_H_
diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index f76d44f5479d32..82bedca7bd41dd 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -39,7 +39,7 @@
 #include "flang/Optimizer/Support/FatalError.h"
 #include "flang/Optimizer/Support/InternalNames.h"
 #include "flang/Optimizer/Support/Utils.h"
-#include "flang/Runtime/allocator-registry.h"
+#include "flang/Runtime/allocator-registry-consts.h"
 #include "flang/Semantics/runtime-type-info.h"
 #include "flang/Semantics/tools.h"
 #include "llvm/Support/CommandLine.h"
diff --git a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp
index c786bef5cb1c4c..b7c6dc5fb2bf6c 100644
--- a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp
@@ -9,7 +9,7 @@
 #include "flang/Optimizer/Builder/Runtime/ArrayConstructor.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
-#include "flang/Runtime/array-constructor.h"
+#include "flang/Runtime/array-constructor-consts.h"
 
 using namespace Fortran::runtime;
 
@@ -29,8 +29,8 @@ mlir::Value fir::runtime::genInitArrayConstructorVector(
   // the target. The "cookieSize" argument is used to validate this wild
   // assumption until runtime interfaces are improved.
   std::size_t arrayVectorStructBitSize =
-      2 * sizeof(Fortran::runtime::ArrayConstructorVector) * 8;
-  std::size_t alignLike = alignof(Fortran::runtime::ArrayConstructorVector) * 8;
+      MaxArrayConstructorVectorSizeInBytes * 8;
+  std::size_t alignLike = MaxArrayConstructorVectorAlignInBytes * 8;
   fir::SequenceType::Extent numElem =
       (arrayVectorStructBitSize + alignLike - 1) / alignLike;
   mlir::Type intType = builder.getIntegerType(alignLike);
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 88293bcf36a780..eed389380f7cca 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -23,8 +23,8 @@
 #include "flang/Optimizer/Support/InternalNames.h"
 #include "flang/Optimizer/Support/TypeCode.h"
 #include "flang/Optimizer/Support/Utils.h"
-#include "flang/Runtime/allocator-registry.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/allocator-registry-consts.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Semantics/runtime-type-info.h"
 #include "mlir/Conversion/ArithCommon/AttrToLLVMConverter.h"
 #include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
@@ -1273,16 +1273,12 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
           insertField(rewriter, loc, descriptor, {kExtraPosInBox}, extraField);
     } else {
       // Compute the value of the extra field based on allocator_idx and
-      // addendum present using a Descriptor object.
-      Fortran::runtime::StaticDescriptor staticDescriptor;
-      Fortran::runtime::Descriptor &desc{staticDescriptor.descriptor()};
-      desc.raw().extra = 0;
-      desc.SetAllocIdx(allocatorIdx);
+      // addendum present.
+      unsigned extra = allocatorIdx << _CFI_ALLOCATOR_IDX_SHIFT;
       if (hasAddendum)
-        desc.SetHasAddendum();
-      descriptor =
-          insertField(rewriter, loc, descriptor, {kExtraPosInBox},
-                      this->genI32Constant(loc, rewriter, desc.raw().extra));
+        extra |= _CFI_ADDENDUM_FLAG;
+      descriptor = insertField(rewriter, loc, descriptor, {kExtraPosInBox},
+                               this->genI32Constant(loc, rewriter, extra));
     }
 
     if (hasAddendum) {
diff --git a/flang/lib/Semantics/compute-offsets.cpp b/flang/lib/Semantics/compute-offsets.cpp
index b5a58ddca0ecdd..c5774ed30de748 100644
--- a/flang/lib/Semantics/compute-offsets.cpp
+++ b/flang/lib/Semantics/compute-offsets.cpp
@@ -11,7 +11,7 @@
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/shape.h"
 #include "flang/Evaluate/type.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/symbol.h"
@@ -341,8 +341,12 @@ auto ComputeOffsetsHelper::GetSizeAndAlignment(
     const auto *derived{evaluate::GetDerivedTypeSpec(dyType)};
     int lenParams{derived ? CountLenParameters(*derived) : 0};
     bool needAddendum{derived || (dyType && dyType->IsUnlimitedPolymorphic())};
-    std::size_t size{runtime::Descriptor::SizeInBytes(
+
+    // FIXME: Get descriptor size from targetCharacteristics instead
+    // overapproximation
+    std::size_t size{runtime::MaxDescriptorSizeInBytes(
         symbol.Rank(), needAddendum, lenParams)};
+
     return {size, targetCharacteristics.descriptorAlignment()};
   }
   if (IsProcedurePointer(symbol)) {
diff --git a/flang/runtime/environment-default-list.h b/flang/runtime/environment-default-list.h
old mode 100755
new mode 100644
diff --git a/flang/runtime/extensions.cpp b/flang/runtime/extensions.cpp
index be3833db88b07a..8cd5f3ce696b49 100644
--- a/flang/runtime/extensions.cpp
+++ b/flang/runtime/extensions.cpp
@@ -15,7 +15,7 @@
 #include "flang/Runtime/command.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/entry-names.h"
-#include "flang/Runtime/io-api.h"
+#include "flang/Runtime/io-api-funcs.h"
 #include <chrono>
 #include <cstring>
 #include <ctime>
diff --git a/flang/runtime/internal-unit.cpp b/flang/runtime/internal-unit.cpp
index f28700ee015815..f8f3877efb20ea 100644
--- a/flang/runtime/internal-unit.cpp
+++ b/flang/runtime/internal-unit.cpp
@@ -36,6 +36,8 @@ RT_API_ATTRS InternalDescriptorUnit<DIR>::InternalDescriptorUnit(
   Descriptor &d{descriptor()};
   RUNTIME_CHECK(
       terminator, that.SizeInBytes() <= d.SizeInBytes(maxRank, true, 0));
+  RUNTIME_CHECK(terminator,
+      that.SizeInBytes() <= MaxDescriptorSizeInBytes(maxRank, true, 0));
   new (&d) Descriptor{that};
   d.Check();
   internalIoCharKind = thatType->second;
diff --git a/flang/runtime/io-api-common.h b/flang/runtime/io-api-common.h
index c7b86cab73a525..b4ac9a61c09ec3 100644
--- a/flang/runtime/io-api-common.h
+++ b/flang/runtime/io-api-common.h
@@ -14,7 +14,7 @@
 #include "unit.h"
 #include "flang/Common/api-attrs.h"
 #include "flang/Common/optional.h"
-#include "flang/Runtime/io-api.h"
+#include "flang/Runtime/io-api-funcs.h"
 
 namespace Fortran::runtime::io {
 
diff --git a/flang/runtime/io-api-minimal.cpp b/flang/runtime/io-api-minimal.cpp
index ad76fe3de0324c..82376cf9641664 100644
--- a/flang/runtime/io-api-minimal.cpp
+++ b/flang/runtime/io-api-minimal.cpp
@@ -16,7 +16,7 @@
 #include "terminator.h"
 #include "tools.h"
 #include "unit.h"
-#include "flang/Runtime/io-api.h"
+#include "flang/Runtime/io-api-funcs.h"
 
 namespace Fortran::runtime::io {
 RT_EXT_API_GROUP_BEGIN
diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index e3c6b9e5ca8959..0fe69c981d17c7 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -13,7 +13,6 @@
 // OutputReal{32,64}, OutputComplex{32,64}, OutputAscii, & EndIoStatement()
 // are in runtime/io-api-minimal.cpp.
 
-#include "flang/Runtime/io-api.h"
 #include "descriptor-io.h"
 #include "edit-input.h"
 #include "edit-output.h"
@@ -26,6 +25,7 @@
 #include "unit.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/io-api-funcs.h"
 #include "flang/Runtime/memory.h"
 #include <cstdlib>
 #include <memory>
diff --git a/flang/runtime/io-error.h b/flang/runtime/io-error.h
index 426573e2faf00c..22e43db7102882 100644
--- a/flang/runtime/io-error.h
+++ b/flang/runtime/io-error.h
@@ -16,7 +16,7 @@
 #define FORTRAN_RUNTIME_IO_ERROR_H_
 
 #include "terminator.h"
-#include "flang/Runtime/iostat.h"
+#include "flang/Runtime/iostat-funcs.h"
 #include "flang/Runtime/memory.h"
 #include <cinttypes>
 
diff --git a/flang/runtime/io-stmt.h b/flang/runtime/io-stmt.h
index 2e0ca46078ecdc..30d7bd86c54b37 100644
--- a/flang/runtime/io-stmt.h
+++ b/flang/runtime/io-stmt.h
@@ -20,7 +20,7 @@
 #include "flang/Common/reference-wrapper.h"
 #include "flang/Common/visit.h"
 #include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/io-api.h"
+#include "flang/Runtime/io-api-funcs.h"
 #include <flang/Common/variant.h>
 #include <functional>
 #include <type_traits>
diff --git a/flang/runtime/iostat.cpp b/flang/runtime/iostat.cpp
index 39e224cb01286b..0d71eb09e0a504 100644
--- a/flang/runtime/iostat.cpp
+++ b/flang/runtime/iostat.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/iostat.h"
+#include "flang/Runtime/iostat-funcs.h"
 
 namespace Fortran::runtime::io {
 RT_OFFLOAD_API_GROUP_BEGIN
diff --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp
index af092de70f7819..cfed7f2c6bf97d 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang/runtime/namelist.cpp
@@ -10,7 +10,7 @@
 #include "descriptor-io.h"
 #include "emit-encoded.h"
 #include "io-stmt.h"
-#include "flang/Runtime/io-api.h"
+#include "flang/Runtime/io-api-funcs.h"
 #include <algorithm>
 #include <cstring>
 #include <limits>
diff --git a/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp b/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp
index 1db43cacc90f07..f618e72d7b7f3c 100644
--- a/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp
+++ b/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp
@@ -9,7 +9,7 @@
 #include "flang/Optimizer/Builder/Runtime/Allocatable.h"
 #include "RuntimeCallTestBase.h"
 #include "gtest/gtest.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 
 using namespace Fortran::runtime;
 

>From 8757eb974fcc57630e85ed1ad838bb2dbbb5a162 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 14 Oct 2024 16:51:07 +0200
Subject: [PATCH 06/12] Move SubscriptValue to public header

---
 flang/include/flang/Runtime/descriptor-consts.h | 1 +
 flang/include/flang/Runtime/descriptor.h        | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h
index 098eb59ca01b2e..c08e5018d0af53 100644
--- a/flang/include/flang/Runtime/descriptor-consts.h
+++ b/flang/include/flang/Runtime/descriptor-consts.h
@@ -28,6 +28,7 @@ class DerivedType;
 
 namespace Fortran::runtime {
 class Descriptor;
+using SubscriptValue = ISO::CFI_index_t;
 
 /// 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/descriptor.h b/flang/include/flang/Runtime/descriptor.h
index 6d0f09c79508cb..dd36fba157ca92 100644
--- a/flang/include/flang/Runtime/descriptor.h
+++ b/flang/include/flang/Runtime/descriptor.h
@@ -31,7 +31,6 @@
 
 namespace Fortran::runtime {
 
-using SubscriptValue = ISO::CFI_index_t;
 class Terminator;
 
 RT_VAR_GROUP_BEGIN

>From b1dafd4a54487791d2495b07bfe265e0a4f05bba Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 14 Oct 2024 17:05:51 +0200
Subject: [PATCH 07/12] Keep common files in flang/

---
 .../Runtime/allocator-registry.h              |  11 +-
 .../Runtime/array-constructor.h               |  48 +++++++
 .../Runtime/descriptor.h                      |  22 +---
 .../FortranRuntime/Runtime/io-api-funcs.h     |  39 ++++++
 .../FortranRuntime/Runtime/iostat-funcs.h     |  23 ++++
 .../Runtime/memory.h                          |   2 +-
 .../Runtime/type-code.h                       |   2 +-
 .../include/flang/Runtime/array-constructor.h | 118 ------------------
 FortranRuntime/lib/Runtime/CMakeLists.txt     |   5 +-
 FortranRuntime/lib/Runtime/CUDA/allocator.cpp |   4 +-
 .../lib/Runtime/CUDA/descriptor.cpp           |   4 +-
 .../lib/Runtime/Float128Math/math-entries.h   |   4 +-
 .../lib/Runtime/ISO_Fortran_binding.cpp       |   6 +-
 FortranRuntime/lib/Runtime/ISO_Fortran_util.h |   6 +-
 FortranRuntime/lib/Runtime/allocatable.cpp    |  10 +-
 .../lib/Runtime/allocator-registry.cpp        |   2 +-
 .../lib/Runtime/array-constructor.cpp         |   8 +-
 FortranRuntime/lib/Runtime/assign.cpp         |   2 +-
 FortranRuntime/lib/Runtime/buffer.h           |   4 +-
 FortranRuntime/lib/Runtime/character.cpp      |   6 +-
 FortranRuntime/lib/Runtime/command.cpp        |   4 +-
 FortranRuntime/lib/Runtime/connection.h       |   2 +-
 FortranRuntime/lib/Runtime/copy.cpp           |   4 +-
 FortranRuntime/lib/Runtime/copy.h             |   2 +-
 FortranRuntime/lib/Runtime/derived-api.cpp    |   2 +-
 FortranRuntime/lib/Runtime/derived.cpp        |   2 +-
 FortranRuntime/lib/Runtime/descriptor-io.h    |   8 +-
 FortranRuntime/lib/Runtime/descriptor.cpp     |  10 +-
 FortranRuntime/lib/Runtime/dot-product.cpp    |   8 +-
 FortranRuntime/lib/Runtime/edit-input.cpp     |   4 +-
 FortranRuntime/lib/Runtime/edit-input.h       |   2 +-
 FortranRuntime/lib/Runtime/edit-output.cpp    |   2 +-
 FortranRuntime/lib/Runtime/edit-output.h      |   4 +-
 FortranRuntime/lib/Runtime/execute.cpp        |   2 +-
 FortranRuntime/lib/Runtime/extensions.cpp     |   8 +-
 FortranRuntime/lib/Runtime/extrema.cpp        |   2 +-
 FortranRuntime/lib/Runtime/file.cpp           |   4 +-
 FortranRuntime/lib/Runtime/file.h             |   4 +-
 FortranRuntime/lib/Runtime/findloc.cpp        |   2 +-
 .../lib/Runtime/format-implementation.h       |   6 +-
 FortranRuntime/lib/Runtime/format.h           |   2 +-
 FortranRuntime/lib/Runtime/inquiry.cpp        |   2 +-
 FortranRuntime/lib/Runtime/internal-unit.cpp  |   6 +-
 FortranRuntime/lib/Runtime/internal-unit.h    |   2 +-
 FortranRuntime/lib/Runtime/io-api-common.h    |   6 +-
 FortranRuntime/lib/Runtime/io-api-minimal.cpp |   2 +-
 FortranRuntime/lib/Runtime/io-api.cpp         |   8 +-
 FortranRuntime/lib/Runtime/io-error.cpp       |   2 +-
 FortranRuntime/lib/Runtime/io-error.h         |   4 +-
 FortranRuntime/lib/Runtime/io-stmt.cpp        |   2 +-
 FortranRuntime/lib/Runtime/io-stmt.h          |  10 +-
 FortranRuntime/lib/Runtime/iostat.cpp         |   2 +-
 .../lib/Runtime/matmul-transpose.cpp          |   6 +-
 FortranRuntime/lib/Runtime/matmul.cpp         |   6 +-
 FortranRuntime/lib/Runtime/memory.cpp         |   4 +-
 FortranRuntime/lib/Runtime/misc-intrinsic.cpp |   4 +-
 FortranRuntime/lib/Runtime/namelist.cpp       |   2 +-
 FortranRuntime/lib/Runtime/namelist.h         |   2 +-
 .../lib/Runtime/numeric-templates.h           |   4 +-
 FortranRuntime/lib/Runtime/numeric.cpp        |   2 +-
 FortranRuntime/lib/Runtime/product.cpp        |   2 +-
 FortranRuntime/lib/Runtime/random-templates.h |   4 +-
 FortranRuntime/lib/Runtime/random.cpp         |   8 +-
 FortranRuntime/lib/Runtime/reduce.cpp         |   2 +-
 .../lib/Runtime/reduction-templates.h         |   4 +-
 FortranRuntime/lib/Runtime/reduction.cpp      |   2 +-
 FortranRuntime/lib/Runtime/stack.h            |   2 +-
 FortranRuntime/lib/Runtime/stat.cpp           |   2 +-
 FortranRuntime/lib/Runtime/stat.h             |   2 +-
 FortranRuntime/lib/Runtime/sum.cpp            |   2 +-
 FortranRuntime/lib/Runtime/support.cpp        |   2 +-
 .../lib/Runtime/temporary-stack.cpp           |   6 +-
 FortranRuntime/lib/Runtime/time-intrinsic.cpp |   4 +-
 FortranRuntime/lib/Runtime/tools.h            |   8 +-
 .../lib/Runtime/transformational.cpp          |   4 +-
 FortranRuntime/lib/Runtime/type-code.cpp      |   2 +-
 FortranRuntime/lib/Runtime/type-info.cpp      |  10 +-
 FortranRuntime/lib/Runtime/type-info.h        |   4 +-
 FortranRuntime/lib/Runtime/unit-map.h         |   4 +-
 FortranRuntime/lib/Runtime/unit.h             |   6 +-
 .../unittests/Common/CMakeLists.txt           |  11 --
 .../unittests/Decimal/CMakeLists.txt          |  18 ---
 .../Evaluate/ISO-Fortran-binding.cpp          |   3 +-
 FortranRuntime/unittests/Evaluate/reshape.cpp |   2 +-
 .../unittests/Runtime/AccessTest.cpp          |   2 +-
 .../unittests/Runtime/Allocatable.cpp         |   2 +-
 .../unittests/Runtime/ArrayConstructor.cpp    |  10 +-
 .../unittests/Runtime/CUDA/AllocatorCUF.cpp   |  10 +-
 .../unittests/Runtime/CharacterTest.cpp       |   2 +-
 .../unittests/Runtime/CommandTest.cpp         |   6 +-
 FortranRuntime/unittests/Runtime/Derived.cpp  |   6 +-
 .../unittests/Runtime/ExternalIOTest.cpp      |   6 +-
 FortranRuntime/unittests/Runtime/Inquiry.cpp  |   4 +-
 .../unittests/Runtime/ListInputTest.cpp       |   6 +-
 .../unittests/Runtime/LogicalFormatTest.cpp   |   4 +-
 FortranRuntime/unittests/Runtime/Matmul.cpp   |   8 +-
 .../unittests/Runtime/MatmulTranspose.cpp     |   8 +-
 .../unittests/Runtime/MiscIntrinsic.cpp       |   8 +-
 FortranRuntime/unittests/Runtime/Namelist.cpp |   4 +-
 FortranRuntime/unittests/Runtime/Numeric.cpp  |   2 +-
 .../unittests/Runtime/NumericalFormatTest.cpp |   4 +-
 FortranRuntime/unittests/Runtime/Pointer.cpp  |   4 +-
 FortranRuntime/unittests/Runtime/Random.cpp   |   6 +-
 .../unittests/Runtime/Reduction.cpp           |   8 +-
 .../unittests/Runtime/RuntimeCrashTest.cpp    |   4 +-
 FortranRuntime/unittests/Runtime/Stop.cpp     |   2 +-
 FortranRuntime/unittests/Runtime/Support.cpp  |   4 +-
 .../unittests/Runtime/TemporaryStack.cpp      |   8 +-
 FortranRuntime/unittests/Runtime/Time.cpp     |   2 +-
 .../unittests/Runtime/Transformational.cpp    |   6 +-
 FortranRuntime/unittests/Runtime/tools.h      |   6 +-
 flang/CMakeLists.txt                          |   3 +-
 .../include/flang/Common/Fortran-consts.h     |   0
 .../Common/ISO_Fortran_binding_wrapper.h      |   2 +-
 flang/include/flang/Common/README.md          |  25 ++++
 .../include/flang/Common/api-attrs.h          |  11 +-
 .../flang/Common/binary-floating-point.h      |   0
 .../flang/Common/bit-population-count.h       |   2 +-
 .../include/flang/Common/constexpr-bitset.h   |   2 +-
 .../include/flang/Common/decimal.h            |   0
 .../include/flang/Common/enum-class.h         |   2 +-
 .../include/flang/Common/enum-set.h           |   2 +-
 .../include/flang/Common/fast-int-set.h       |   4 +-
 .../include/flang/Common/float128.h           |   2 +-
 .../include/flang/Common/format.h             |   2 +-
 .../include/flang/Common/idioms.h             |   2 +-
 .../flang/Common/leading-zero-bit-count.h     |   2 +-
 .../include/flang/Common/optional.h           |   6 +-
 .../include/flang/Common/real.h               |   2 +-
 .../include/flang/Common/reference-wrapper.h  |   6 +-
 .../include/flang/Common/restorer.h           |   4 +-
 .../include/flang/Common/target-rounding.h    |   0
 .../include/flang/Common/uint128.h            |   4 +-
 .../include/flang/Common/variant.h            |   6 +-
 .../include/flang/Common/visit.h              |   4 +-
 .../include/flang/Common/windows-include.h    |   2 +-
 flang/include/flang/ISO_Fortran_binding.h     |  13 +-
 flang/include/flang/Lower/Allocatable.h       |   2 +-
 .../flang/Optimizer/Builder/IntrinsicCall.h   |   1 -
 .../flang/Optimizer/Builder/MutableBox.h      |   2 +-
 .../flang/Optimizer/CodeGen/DescriptorModel.h |   2 +-
 .../include/flang/Runtime/CUDA/allocator.h    |   4 +-
 .../include/flang/Runtime/CUDA/descriptor.h   |   4 +-
 flang/include/flang/Runtime/README.md         |  25 ++++
 .../include/flang/Runtime/allocatable.h       |   7 +-
 .../flang/Runtime/allocator-registry-consts.h |  20 +++
 .../flang/Runtime/array-constructor-consts.h  |  54 ++++++++
 .../include/flang/Runtime/assign.h            |   2 +-
 .../include/flang/Runtime/c-or-cpp.h          |   2 +-
 .../include/flang/Runtime/character.h         |   2 +-
 .../include/flang/Runtime/command.h           |   2 +-
 .../include/flang/Runtime/cpp-type.h          |   2 +-
 .../include/flang/Runtime/derived-api.h       |   2 +-
 .../include/flang/Runtime/descriptor-consts.h |  72 +++++++++++
 .../include/flang/Runtime/entry-names.h       |  11 +-
 .../include/flang/Runtime/exceptions.h        |   4 +-
 .../include/flang/Runtime/execute.h           |   4 +-
 .../include/flang/Runtime/extensions.h        |   2 +-
 .../flang/Runtime/freestanding-tools.h        |   2 +-
 .../include/flang/Runtime/inquiry.h           |   4 +-
 .../include/flang/Runtime/io-api.h            |   7 +-
 .../include/flang/Runtime/iostat.h            |   6 +-
 .../include/flang/Runtime}/magic-numbers.h    |   6 +-
 .../include/flang/Runtime/main.h              |   2 +-
 .../flang/Runtime/matmul-instances.inc        |   0
 .../include/flang/Runtime/matmul-transpose.h  |   2 +-
 .../include/flang/Runtime/matmul.h            |   2 +-
 .../include/flang/Runtime/misc-intrinsic.h    |   2 +-
 .../include/flang/Runtime/numeric.h           |   2 +-
 .../include/flang/Runtime/pointer.h           |   6 +-
 .../include/flang/Runtime/ragged.h            |   4 +-
 .../include/flang/Runtime/random.h            |   0
 .../include/flang/Runtime/reduce.h            |   2 +-
 .../include/flang/Runtime/reduction.h         |   2 +-
 .../include/flang/Runtime/stop.h              |   2 +-
 .../include/flang/Runtime/support.h           |   2 +-
 .../include/flang/Runtime/temporary-stack.h   |   2 +-
 .../include/flang/Runtime/time-intrinsic.h    |   2 +-
 .../include/flang/Runtime/transformational.h  |   2 +-
 .../include/flang/Support/Fortran-features.h  |   6 +-
 flang/include/flang/Support/Fortran.h         |   8 +-
 flang/include/flang/Support/MathOptionsBase.h |   6 +-
 flang/include/flang/Support/Version.h         |   6 +-
 flang/include/flang/Support/default-kinds.h   |   6 +-
 flang/include/flang/Support/indirection.h     |   6 +-
 flang/include/flang/Support/interval.h        |   6 +-
 flang/include/flang/Support/template.h        |   6 +-
 flang/include/flang/Support/unwrap.h          |   6 +-
 flang/include/flang/Testing/README.md         |  25 ++++
 .../include/flang/Testing/fp-testing.h        |   0
 .../include/flang/Testing/testing.h           |   0
 flang/lib/Common/CMakeLists.txt               |   2 +-
 flang/lib/Common/README.md                    |  25 ++++
 .../lib/Common/big-radix-floating-point.h     |   0
 .../lib/Common/binary-to-decimal.cpp          |   0
 .../lib/Common/decimal-to-binary.cpp          |   0
 flang/lib/Decimal/CMakeLists.txt              |  23 ++--
 flang/lib/Evaluate/common.cpp                 |   3 -
 flang/lib/Evaluate/fold-logical.cpp           |   2 +-
 flang/lib/Lower/ConvertVariable.cpp           |   2 +-
 flang/lib/Optimizer/Builder/CMakeLists.txt    |   2 +-
 .../Builder/Runtime/ArrayConstructor.cpp      |   6 +-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp       |  18 ++-
 flang/lib/Optimizer/Dialect/FIRType.cpp       |   2 +-
 flang/lib/Semantics/compute-offsets.cpp       |   8 +-
 flang/lib/Testing/README.md                   |  25 ++++
 .../lib/Testing/fp-testing.cpp                |   0
 .../lib/Testing/testing.cpp                   |   0
 flang/module/__fortran_builtins.f90           |   2 +-
 flang/module/__fortran_ieee_exceptions.f90    |   2 +-
 flang/module/cudadevice.f90                   |   2 +-
 flang/module/ieee_arithmetic.f90              |   2 +-
 flang/module/iso_fortran_env.f90              |   2 +-
 .../module}/iso_fortran_env_impl.f90          |   2 +-
 flang/test/lit.cfg.py                         |   2 +-
 flang/tools/f18/CMakeLists.txt                |   6 +-
 flang/unittests/CMakeLists.txt                |   6 +-
 flang/unittests/Common/CMakeLists.txt         |   3 +
 .../unittests/Common/FastIntSetTest.cpp       |   4 +-
 flang/unittests/Decimal/CMakeLists.txt        |  10 ++
 .../unittests/Decimal/quick-sanity-test.cpp   |   8 --
 .../unittests/Decimal/thorough-test.cpp       |   8 --
 flang/unittests/Evaluate/CMakeLists.txt       |   6 +-
 .../Builder/Runtime/AllocatableTest.cpp       |   2 +-
 224 files changed, 814 insertions(+), 587 deletions(-)
 rename FortranRuntime/include/{flang => FortranRuntime}/Runtime/allocator-registry.h (82%)
 create mode 100644 FortranRuntime/include/FortranRuntime/Runtime/array-constructor.h
 rename FortranRuntime/include/{flang => FortranRuntime}/Runtime/descriptor.h (96%)
 create mode 100644 FortranRuntime/include/FortranRuntime/Runtime/io-api-funcs.h
 create mode 100644 FortranRuntime/include/FortranRuntime/Runtime/iostat-funcs.h
 rename FortranRuntime/include/{flang => FortranRuntime}/Runtime/memory.h (98%)
 rename FortranRuntime/include/{flang => FortranRuntime}/Runtime/type-code.h (97%)
 delete mode 100644 FortranRuntime/include/flang/Runtime/array-constructor.h
 delete mode 100644 FortranRuntime/unittests/Common/CMakeLists.txt
 delete mode 100644 FortranRuntime/unittests/Decimal/CMakeLists.txt
 rename {FortranRuntime => flang}/include/flang/Common/Fortran-consts.h (100%)
 rename {FortranRuntime => flang}/include/flang/Common/ISO_Fortran_binding_wrapper.h (97%)
 create mode 100644 flang/include/flang/Common/README.md
 rename {FortranRuntime => flang}/include/flang/Common/api-attrs.h (97%)
 rename {FortranRuntime => flang}/include/flang/Common/binary-floating-point.h (100%)
 rename {FortranRuntime => flang}/include/flang/Common/bit-population-count.h (98%)
 rename {FortranRuntime => flang}/include/flang/Common/constexpr-bitset.h (98%)
 rename {FortranRuntime => flang}/include/flang/Common/decimal.h (100%)
 rename {FortranRuntime => flang}/include/flang/Common/enum-class.h (98%)
 rename {FortranRuntime => flang}/include/flang/Common/enum-set.h (99%)
 rename {FortranRuntime => flang}/include/flang/Common/fast-int-set.h (97%)
 rename {FortranRuntime => flang}/include/flang/Common/float128.h (96%)
 rename {FortranRuntime => flang}/include/flang/Common/format.h (99%)
 rename {FortranRuntime => flang}/include/flang/Common/idioms.h (99%)
 rename {FortranRuntime => flang}/include/flang/Common/leading-zero-bit-count.h (98%)
 rename {FortranRuntime => flang}/include/flang/Common/optional.h (98%)
 rename {FortranRuntime => flang}/include/flang/Common/real.h (99%)
 rename {FortranRuntime => flang}/include/flang/Common/reference-wrapper.h (96%)
 rename {FortranRuntime => flang}/include/flang/Common/restorer.h (97%)
 rename {FortranRuntime => flang}/include/flang/Common/target-rounding.h (100%)
 rename {FortranRuntime => flang}/include/flang/Common/uint128.h (99%)
 rename {FortranRuntime => flang}/include/flang/Common/variant.h (89%)
 rename {FortranRuntime => flang}/include/flang/Common/visit.h (98%)
 rename {FortranRuntime => flang}/include/flang/Common/windows-include.h (93%)
 rename {FortranRuntime => flang}/include/flang/Runtime/CUDA/allocator.h (93%)
 rename {FortranRuntime => flang}/include/flang/Runtime/CUDA/descriptor.h (91%)
 create mode 100644 flang/include/flang/Runtime/README.md
 rename {FortranRuntime => flang}/include/flang/Runtime/allocatable.h (97%)
 create mode 100644 flang/include/flang/Runtime/allocator-registry-consts.h
 create mode 100644 flang/include/flang/Runtime/array-constructor-consts.h
 rename {FortranRuntime => flang}/include/flang/Runtime/assign.h (98%)
 rename {FortranRuntime => flang}/include/flang/Runtime/c-or-cpp.h (95%)
 rename {FortranRuntime => flang}/include/flang/Runtime/character.h (99%)
 rename {FortranRuntime => flang}/include/flang/Runtime/command.h (98%)
 rename {FortranRuntime => flang}/include/flang/Runtime/cpp-type.h (98%)
 rename {FortranRuntime => flang}/include/flang/Runtime/derived-api.h (98%)
 create mode 100644 flang/include/flang/Runtime/descriptor-consts.h
 rename {FortranRuntime => flang}/include/flang/Runtime/entry-names.h (89%)
 rename {FortranRuntime => flang}/include/flang/Runtime/exceptions.h (86%)
 rename {FortranRuntime => flang}/include/flang/Runtime/execute.h (89%)
 rename {FortranRuntime => flang}/include/flang/Runtime/extensions.h (97%)
 rename {FortranRuntime => flang}/include/flang/Runtime/freestanding-tools.h (99%)
 rename {FortranRuntime => flang}/include/flang/Runtime/inquiry.h (91%)
 rename {FortranRuntime => flang}/include/flang/Runtime/io-api.h (98%)
 rename {FortranRuntime => flang}/include/flang/Runtime/iostat.h (96%)
 rename {FortranRuntime/include/flang/Common => flang/include/flang/Runtime}/magic-numbers.h (98%)
 rename {FortranRuntime => flang}/include/flang/Runtime/main.h (95%)
 rename {FortranRuntime => flang}/include/flang/Runtime/matmul-instances.inc (100%)
 rename {FortranRuntime => flang}/include/flang/Runtime/matmul-transpose.h (97%)
 rename {FortranRuntime => flang}/include/flang/Runtime/matmul.h (97%)
 rename {FortranRuntime => flang}/include/flang/Runtime/misc-intrinsic.h (95%)
 rename {FortranRuntime => flang}/include/flang/Runtime/numeric.h (99%)
 rename {FortranRuntime => flang}/include/flang/Runtime/pointer.h (97%)
 rename {FortranRuntime => flang}/include/flang/Runtime/ragged.h (96%)
 rename {FortranRuntime => flang}/include/flang/Runtime/random.h (100%)
 rename {FortranRuntime => flang}/include/flang/Runtime/reduce.h (99%)
 rename {FortranRuntime => flang}/include/flang/Runtime/reduction.h (99%)
 rename {FortranRuntime => flang}/include/flang/Runtime/stop.h (97%)
 rename {FortranRuntime => flang}/include/flang/Runtime/support.h (97%)
 rename {FortranRuntime => flang}/include/flang/Runtime/temporary-stack.h (98%)
 rename {FortranRuntime => flang}/include/flang/Runtime/time-intrinsic.h (97%)
 rename {FortranRuntime => flang}/include/flang/Runtime/transformational.h (99%)
 create mode 100644 flang/include/flang/Testing/README.md
 rename {FortranRuntime => flang}/include/flang/Testing/fp-testing.h (100%)
 rename {FortranRuntime => flang}/include/flang/Testing/testing.h (100%)
 create mode 100644 flang/lib/Common/README.md
 rename {FortranRuntime => flang}/lib/Common/big-radix-floating-point.h (100%)
 rename {FortranRuntime => flang}/lib/Common/binary-to-decimal.cpp (100%)
 rename {FortranRuntime => flang}/lib/Common/decimal-to-binary.cpp (100%)
 create mode 100644 flang/lib/Testing/README.md
 rename {FortranRuntime => flang}/lib/Testing/fp-testing.cpp (100%)
 rename {FortranRuntime => flang}/lib/Testing/testing.cpp (100%)
 rename {FortranRuntime/lib/Runtime => flang/module}/iso_fortran_env_impl.f90 (98%)
 create mode 100644 flang/unittests/Common/CMakeLists.txt
 rename {FortranRuntime => flang}/unittests/Common/FastIntSetTest.cpp (97%)
 create mode 100644 flang/unittests/Decimal/CMakeLists.txt
 rename {FortranRuntime => flang}/unittests/Decimal/quick-sanity-test.cpp (92%)
 rename {FortranRuntime => flang}/unittests/Decimal/thorough-test.cpp (86%)

diff --git a/FortranRuntime/include/flang/Runtime/allocator-registry.h b/FortranRuntime/include/FortranRuntime/Runtime/allocator-registry.h
similarity index 82%
rename from FortranRuntime/include/flang/Runtime/allocator-registry.h
rename to FortranRuntime/include/FortranRuntime/Runtime/allocator-registry.h
index 4e7d9bcedfb375..30a583b88c083e 100644
--- a/FortranRuntime/include/flang/Runtime/allocator-registry.h
+++ b/FortranRuntime/include/FortranRuntime/Runtime/allocator-registry.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/allocator-registry.h --------------*- C++ -*-===//
+//===-- include/FortranRuntime/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.
@@ -10,17 +10,10 @@
 #define FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_
 
 #include "flang/Common/api-attrs.h"
+#include "flang/Runtime/allocator-registry-consts.h"
 #include <cstdlib>
 #include <vector>
 
-static constexpr unsigned kDefaultAllocator = 0;
-
-// Allocator used for CUF
-static constexpr unsigned kPinnedAllocatorPos = 1;
-static constexpr unsigned kDeviceAllocatorPos = 2;
-static constexpr unsigned kManagedAllocatorPos = 3;
-static constexpr unsigned kUnifiedAllocatorPos = 4;
-
 #define MAX_ALLOCATOR 7 // 3 bits are reserved in the descriptor.
 
 namespace Fortran::runtime {
diff --git a/FortranRuntime/include/FortranRuntime/Runtime/array-constructor.h b/FortranRuntime/include/FortranRuntime/Runtime/array-constructor.h
new file mode 100644
index 00000000000000..314d5e56599cd3
--- /dev/null
+++ b/FortranRuntime/include/FortranRuntime/Runtime/array-constructor.h
@@ -0,0 +1,48 @@
+//===-- include/FortranRuntime/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.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// External APIs to create temporary storage for array constructors when their
+// final extents or length parameters cannot be pre-computed.
+
+#ifndef FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_
+#define FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_
+
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang/Runtime/array-constructor-consts.h"
+#include "flang/Runtime/entry-names.h"
+#include <cstdint>
+
+namespace Fortran::runtime {
+
+// Runtime data structure to hold information about the storage of
+// an array constructor being constructed.
+struct ArrayConstructorVector {
+  RT_API_ATTRS ArrayConstructorVector(class Descriptor &to,
+      SubscriptValue nextValuePosition, SubscriptValue actualAllocationSize,
+      const char *sourceFile, int sourceLine, bool useValueLengthParameters)
+      : to{to}, nextValuePosition{nextValuePosition},
+        actualAllocationSize{actualAllocationSize}, sourceFile{sourceFile},
+        sourceLine{sourceLine},
+        useValueLengthParameters_{useValueLengthParameters} {}
+
+  RT_API_ATTRS bool useValueLengthParameters() const {
+    return useValueLengthParameters_;
+  }
+
+  class Descriptor &to;
+  SubscriptValue nextValuePosition;
+  SubscriptValue actualAllocationSize;
+  const char *sourceFile;
+  int sourceLine;
+
+private:
+  unsigned char useValueLengthParameters_ : 1;
+};
+
+} // namespace Fortran::runtime
+#endif /* FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_ */
diff --git a/FortranRuntime/include/flang/Runtime/descriptor.h b/FortranRuntime/include/FortranRuntime/Runtime/descriptor.h
similarity index 96%
rename from FortranRuntime/include/flang/Runtime/descriptor.h
rename to FortranRuntime/include/FortranRuntime/Runtime/descriptor.h
index 867f4d4ee29ac0..f79ad6b9637a4a 100644
--- a/FortranRuntime/include/flang/Runtime/descriptor.h
+++ b/FortranRuntime/include/FortranRuntime/Runtime/descriptor.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/descriptor.h ----------------------*- C++ -*-===//
+//===-- include/FortranRuntime/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.
@@ -18,9 +18,10 @@
 // User C code is welcome to depend on that ISO_Fortran_binding.h file,
 // but should never reference this internal header.
 
+#include "FortranRuntime/Runtime/memory.h"
+#include "FortranRuntime/Runtime/type-code.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
-#include "flang/Runtime/memory.h"
-#include "flang/Runtime/type-code.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include <algorithm>
 #include <cassert>
 #include <cinttypes>
@@ -28,14 +29,8 @@
 #include <cstdio>
 #include <cstring>
 
-namespace Fortran::runtime::typeInfo {
-using TypeParameterValue = std::int64_t;
-class DerivedType;
-} // namespace Fortran::runtime::typeInfo
-
 namespace Fortran::runtime {
 
-using SubscriptValue = ISO::CFI_index_t;
 class Terminator;
 
 RT_VAR_GROUP_BEGIN
@@ -420,13 +415,6 @@ class Descriptor {
 
   void Dump(FILE * = stdout) const;
 
-// Value of the addendum presence flag.
-#define _CFI_ADDENDUM_FLAG 1
-// Number of bits needed to be shifted when manipulating the allocator index.
-#define _CFI_ALLOCATOR_IDX_SHIFT 1
-// Allocator index mask.
-#define _CFI_ALLOCATOR_IDX_MASK 0b00001110
-
   RT_API_ATTRS inline bool HasAddendum() const {
     return raw_.extra & _CFI_ADDENDUM_FLAG;
   }
@@ -464,6 +452,8 @@ class alignas(Descriptor) StaticDescriptor {
   static constexpr bool hasAddendum{ADDENDUM || MAX_LEN_PARMS > 0};
   static constexpr std::size_t byteSize{
       Descriptor::SizeInBytes(maxRank, hasAddendum, maxLengthTypeParameters)};
+  static_assert(byteSize <=
+      MaxDescriptorSizeInBytes(maxRank, hasAddendum, maxLengthTypeParameters));
   RT_OFFLOAD_VAR_GROUP_END
 
   RT_API_ATTRS Descriptor &descriptor() {
diff --git a/FortranRuntime/include/FortranRuntime/Runtime/io-api-funcs.h b/FortranRuntime/include/FortranRuntime/Runtime/io-api-funcs.h
new file mode 100644
index 00000000000000..516fe25784656c
--- /dev/null
+++ b/FortranRuntime/include/FortranRuntime/Runtime/io-api-funcs.h
@@ -0,0 +1,39 @@
+//===-- include/FortranRuntime/Runtime/io-api-funcs.h -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Defines API between compiled code and I/O runtime library.
+
+#ifndef FORTRAN_RUNTIME_IO_API_FUNCS_H_
+#define FORTRAN_RUNTIME_IO_API_FUNCS_H_
+
+#include "flang/Common/uint128.h"
+#include "flang/Runtime/entry-names.h"
+#include "flang/Runtime/io-api.h"
+#include "flang/Runtime/iostat.h"
+#include "flang/Runtime/magic-numbers.h"
+#include <cinttypes>
+#include <cstddef>
+
+namespace Fortran::runtime {
+class Descriptor;
+} // namespace Fortran::runtime
+
+namespace Fortran::runtime::io {
+
+struct NonTbpDefinedIoTable;
+class NamelistGroup;
+class IoStatementState;
+using Cookie = IoStatementState *;
+using ExternalUnit = int;
+using AsynchronousId = int;
+
+RT_API_ATTRS const char *InquiryKeywordHashDecode(
+    char *buffer, std::size_t, InquiryKeywordHash);
+
+} // namespace Fortran::runtime::io
+#endif /* FORTRAN_RUNTIME_IO_API_FUNCS_H_ */
diff --git a/FortranRuntime/include/FortranRuntime/Runtime/iostat-funcs.h b/FortranRuntime/include/FortranRuntime/Runtime/iostat-funcs.h
new file mode 100644
index 00000000000000..10906afb01673c
--- /dev/null
+++ b/FortranRuntime/include/FortranRuntime/Runtime/iostat-funcs.h
@@ -0,0 +1,23 @@
+//===-- include/FortranRuntime/Runtime/iostat-funcs.h -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Defines the values returned by the runtime for IOSTAT= specifiers
+// on I/O statements.
+
+#ifndef FORTRAN_RUNTIME_IOSTAT_FUNCS_H_
+#define FORTRAN_RUNTIME_IOSTAT_FUNCS_H_
+
+#include "flang/Common/api-attrs.h"
+#include "flang/Runtime/iostat.h"
+
+namespace Fortran::runtime::io {
+
+RT_API_ATTRS const char *IostatErrorString(int);
+
+} // namespace Fortran::runtime::io
+#endif /* FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ */
diff --git a/FortranRuntime/include/flang/Runtime/memory.h b/FortranRuntime/include/FortranRuntime/Runtime/memory.h
similarity index 98%
rename from FortranRuntime/include/flang/Runtime/memory.h
rename to FortranRuntime/include/FortranRuntime/Runtime/memory.h
index 84af4d7189c074..3e7fd2d9ea3e3b 100644
--- a/FortranRuntime/include/flang/Runtime/memory.h
+++ b/FortranRuntime/include/FortranRuntime/Runtime/memory.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/memory.h --------------------------*- C++ -*-===//
+//===-- include/FortranRuntime/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.
diff --git a/FortranRuntime/include/flang/Runtime/type-code.h b/FortranRuntime/include/FortranRuntime/Runtime/type-code.h
similarity index 97%
rename from FortranRuntime/include/flang/Runtime/type-code.h
rename to FortranRuntime/include/FortranRuntime/Runtime/type-code.h
index ec359f25dbdd12..92ff593410c12c 100644
--- a/FortranRuntime/include/flang/Runtime/type-code.h
+++ b/FortranRuntime/include/FortranRuntime/Runtime/type-code.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/type-code.h -----------------------*- C++ -*-===//
+//===-- include/FortranRuntime/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.
diff --git a/FortranRuntime/include/flang/Runtime/array-constructor.h b/FortranRuntime/include/flang/Runtime/array-constructor.h
deleted file mode 100644
index 82367756f5dc79..00000000000000
--- a/FortranRuntime/include/flang/Runtime/array-constructor.h
+++ /dev/null
@@ -1,118 +0,0 @@
-//===-- include/flang/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.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// External APIs to create temporary storage for array constructors when their
-// final extents or length parameters cannot be pre-computed.
-
-#ifndef FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_
-#define FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_
-
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/entry-names.h"
-#include <cstdint>
-
-namespace Fortran::runtime {
-
-// Runtime data structure to hold information about the storage of
-// an array constructor being constructed.
-struct ArrayConstructorVector {
-  RT_API_ATTRS ArrayConstructorVector(class Descriptor &to,
-      SubscriptValue nextValuePosition, SubscriptValue actualAllocationSize,
-      const char *sourceFile, int sourceLine, bool useValueLengthParameters)
-      : to{to}, nextValuePosition{nextValuePosition},
-        actualAllocationSize{actualAllocationSize}, sourceFile{sourceFile},
-        sourceLine{sourceLine},
-        useValueLengthParameters_{useValueLengthParameters} {}
-
-  RT_API_ATTRS bool useValueLengthParameters() const {
-    return useValueLengthParameters_;
-  }
-
-  class Descriptor &to;
-  SubscriptValue nextValuePosition;
-  SubscriptValue actualAllocationSize;
-  const char *sourceFile;
-  int sourceLine;
-
-private:
-  unsigned char useValueLengthParameters_ : 1;
-};
-
-// This file defines an API to "push" an evaluated array constructor value
-// "from" into some storage "to" of an array constructor. It can be seen as a
-// form of std::vector::push_back() implementation for Fortran array
-// constructors. In the APIs and ArrayConstructorVector struct above:
-//
-// - "to" is a ranked-1 descriptor whose declared type is already set to the
-// array constructor derived type. It may be already allocated, even before the
-// first call to this API, or it may be unallocated. "to" extent is increased
-// every time a "from" is pushed past its current extent. At this end of the
-// API calls, its extent is the extent of the array constructor. If "to" is
-// unallocated and its extent is not null, it is assumed this is the final array
-// constructor extent value, and the first allocation already "reserves" storage
-// space accordingly to avoid reallocations.
-//  - "from" is a scalar or array descriptor for the evaluated array
-//  constructor value that must be copied into the storage of "to" at
-//  "nextValuePosition".
-//  - "useValueLengthParameters" must be set to true if the array constructor
-//  has length parameters and no type spec. If it is true and "to" is
-//  unallocated, "to" will take the length parameters of "from". If it is true
-//  and "to" is an allocated character array constructor, it will be checked
-//  that "from" length matches the one from "to". When it is false, the
-//  character length must already be set in "to" before the first call to this
-//  API and "from" character lengths are allowed to mismatch from "to".
-// - "nextValuePosition" is the zero based sequence position of "from" in the
-// array constructor. It is updated after this call by the number of "from"
-// elements. It should be set to zero by the caller of this API before the first
-// call.
-// - "actualAllocationSize" is the current allocation size of "to" storage. It
-// may be bigger than "to" extent for reallocation optimization purposes, but
-// should never be smaller, unless this is the first call and "to" is
-// unallocated. It is updated by the runtime after each successful allocation or
-// reallocation. It should be set to "to" extent if "to" is allocated before the
-// first call of this API, and can be left undefined otherwise.
-//
-// Note that this API can be used with "to" being a variable (that can be
-// discontiguous). This can be done when the variable is the left hand side of
-// an assignment from an array constructor as long as:
-//  - none of the ac-value overlaps with the variable,
-//  - this is an intrinsic assignment that is not a whole allocatable
-//  assignment, *and* for a type that has no components requiring user defined
-//  assignments,
-//  - the variable is properly finalized before using this API if its need to,
-//  - "useValueLengthParameters" should be set to false in this case, even if
-//  the array constructor has no type-spec, since the variable may have a
-//  different character length than the array constructor values.
-
-extern "C" {
-// API to initialize an ArrayConstructorVector before any values are pushed to
-// it. Inlined code is only expected to allocate the "ArrayConstructorVector"
-// class instance storage with sufficient size (using
-// "2*sizeof(ArrayConstructorVector)" on the host should be safe regardless of
-// the target the runtime is compiled for). This avoids the need for the runtime
-// to maintain a state, or to use dynamic allocation for it. "vectorClassSize"
-// is used to validate that lowering allocated enough space for it.
-void RTDECL(InitArrayConstructorVector)(ArrayConstructorVector &vector,
-    Descriptor &to, bool useValueLengthParameters, int vectorClassSize,
-    const char *sourceFile = nullptr, int sourceLine = 0);
-
-// Generic API to push any kind of entity into the array constructor (any
-// Fortran type and any rank).
-void RTDECL(PushArrayConstructorValue)(
-    ArrayConstructorVector &vector, const Descriptor &from);
-
-// API to push scalar array constructor value of:
-//   - a numerical or logical type,
-//   - or a derived type that has no length parameters, and no allocatable
-//   component (that would require deep copies).
-// It requires no descriptor for the value that is passed via its base address.
-void RTDECL(PushArrayConstructorSimpleScalar)(
-    ArrayConstructorVector &vector, void *from);
-} // extern "C"
-} // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_ */
diff --git a/FortranRuntime/lib/Runtime/CMakeLists.txt b/FortranRuntime/lib/Runtime/CMakeLists.txt
index d09112ab8b0d5f..b7f32fe30e422a 100644
--- a/FortranRuntime/lib/Runtime/CMakeLists.txt
+++ b/FortranRuntime/lib/Runtime/CMakeLists.txt
@@ -45,8 +45,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
     add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
   endif ()
   include_directories(BEFORE
-    ${FLANG_SOURCE_DIR}/include
-    ${FLANG_SOURCE_DIR}/../FortranRuntime/include)
+    ${FLANG_SOURCE_DIR}/include)
 
   # The out of tree builds of the compiler and the Fortran runtime
   # must use the same setting of FLANG_RUNTIME_F128_MATH_LIB
@@ -60,6 +59,8 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
     )
 endif()
 
+include_directories(BEFORE ../../include)
+
 include(CheckCXXSymbolExists)
 include(CheckCXXSourceCompiles)
 check_cxx_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
diff --git a/FortranRuntime/lib/Runtime/CUDA/allocator.cpp b/FortranRuntime/lib/Runtime/CUDA/allocator.cpp
index 2efd6bf0a95249..c9d62f6ea8f3bf 100644
--- a/FortranRuntime/lib/Runtime/CUDA/allocator.cpp
+++ b/FortranRuntime/lib/Runtime/CUDA/allocator.cpp
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/CUDA/allocator.h"
+#include "FortranRuntime/Runtime/CUDA/allocator.h"
+#include "FortranRuntime/Runtime/allocator-registry.h"
 #include "../derived.h"
 #include "../stat.h"
 #include "../terminator.h"
 #include "../type-info.h"
 #include "flang/ISO_Fortran_binding_wrapper.h"
-#include "flang/Runtime/allocator-registry.h"
 #include "flang/Support/Fortran.h"
 
 #include "cuda_runtime.h"
diff --git a/FortranRuntime/lib/Runtime/CUDA/descriptor.cpp b/FortranRuntime/lib/Runtime/CUDA/descriptor.cpp
index 9664fea4ebc78a..94b5feca4ce4dc 100644
--- a/FortranRuntime/lib/Runtime/CUDA/descriptor.cpp
+++ b/FortranRuntime/lib/Runtime/CUDA/descriptor.cpp
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/CUDA/descriptor.h"
-#include "flang/Runtime/CUDA/allocator.h"
+#include "FortranRuntime/Runtime/CUDA/descriptor.h"
+#include "FortranRuntime/Runtime/CUDA/allocator.h"
 
 namespace Fortran::runtime::cuda {
 extern "C" {
diff --git a/FortranRuntime/lib/Runtime/Float128Math/math-entries.h b/FortranRuntime/lib/Runtime/Float128Math/math-entries.h
index cb1e0130602260..1449000820f00e 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/math-entries.h
+++ b/FortranRuntime/lib/Runtime/Float128Math/math-entries.h
@@ -8,10 +8,10 @@
 
 #ifndef FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
 #define FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
-#include "flang/Common/float128.h"
-#include "flang/Runtime/entry-names.h"
 #include "terminator.h"
 #include "tools.h"
+#include "flang/Common/float128.h"
+#include "flang/Runtime/entry-names.h"
 #include <cfloat>
 #include <cmath>
 #include <type_traits>
diff --git a/FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp b/FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp
index 9711b2bcf49757..997226b08e96a6 100644
--- a/FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp
+++ b/FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp
@@ -9,12 +9,12 @@
 // Implements the required interoperability API from ISO_Fortran_binding.h
 // as specified in section 18.5.5 of Fortran 2018.
 
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/type-code.h"
 #include "ISO_Fortran_util.h"
+#include "terminator.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 "terminator.h"
 #include <cstdlib>
 
 namespace Fortran::ISO {
diff --git a/FortranRuntime/lib/Runtime/ISO_Fortran_util.h b/FortranRuntime/lib/Runtime/ISO_Fortran_util.h
index 7ab280733028af..e418266dddccc7 100644
--- a/FortranRuntime/lib/Runtime/ISO_Fortran_util.h
+++ b/FortranRuntime/lib/Runtime/ISO_Fortran_util.h
@@ -11,10 +11,10 @@
 
 // Internal utils for establishing CFI_cdesc_t descriptors.
 
-#include "flang/Common/ISO_Fortran_binding_wrapper.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/type-code.h"
 #include "terminator.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include <cstdlib>
 
 namespace Fortran::ISO {
diff --git a/FortranRuntime/lib/Runtime/allocatable.cpp b/FortranRuntime/lib/Runtime/allocatable.cpp
index 8b6c1a4c1477eb..4a3b89f4879c12 100644
--- a/FortranRuntime/lib/Runtime/allocatable.cpp
+++ b/FortranRuntime/lib/Runtime/allocatable.cpp
@@ -7,14 +7,18 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/allocatable.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "assign-impl.h"
 #include "derived.h"
-#include "flang/Common/ISO_Fortran_binding_wrapper.h"
-#include "flang/Runtime/assign.h"
-#include "flang/Runtime/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "type-info.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
+#include "flang/Runtime/assign.h"
+
+using Fortran::common::TypeCategory;
+
+
 
 namespace Fortran::runtime {
 extern "C" {
diff --git a/FortranRuntime/lib/Runtime/allocator-registry.cpp b/FortranRuntime/lib/Runtime/allocator-registry.cpp
index 68fb8b80680558..17883e5c54870d 100644
--- a/FortranRuntime/lib/Runtime/allocator-registry.cpp
+++ b/FortranRuntime/lib/Runtime/allocator-registry.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/allocator-registry.h"
+#include "FortranRuntime/Runtime/allocator-registry.h"
 #include "terminator.h"
 
 namespace Fortran::runtime {
diff --git a/FortranRuntime/lib/Runtime/array-constructor.cpp b/FortranRuntime/lib/Runtime/array-constructor.cpp
index db57d4fc4c3f68..002dfba2c066f5 100644
--- a/FortranRuntime/lib/Runtime/array-constructor.cpp
+++ b/FortranRuntime/lib/Runtime/array-constructor.cpp
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/array-constructor.h"
+#include "FortranRuntime/Runtime/array-constructor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "derived.h"
-#include "flang/Runtime/allocatable.h"
-#include "flang/Runtime/assign.h"
-#include "flang/Runtime/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "type-info.h"
+#include "flang/Runtime/allocatable.h"
+#include "flang/Runtime/assign.h"
 
 namespace Fortran::runtime {
 
diff --git a/FortranRuntime/lib/Runtime/assign.cpp b/FortranRuntime/lib/Runtime/assign.cpp
index cc38e55e3a9e1e..3a1486ace928a2 100644
--- a/FortranRuntime/lib/Runtime/assign.cpp
+++ b/FortranRuntime/lib/Runtime/assign.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/assign.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "assign-impl.h"
 #include "derived.h"
-#include "flang/Runtime/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/FortranRuntime/lib/Runtime/buffer.h b/FortranRuntime/lib/Runtime/buffer.h
index dd3c19fa14392f..52df0f10813c25 100644
--- a/FortranRuntime/lib/Runtime/buffer.h
+++ b/FortranRuntime/lib/Runtime/buffer.h
@@ -11,9 +11,9 @@
 #ifndef FORTRAN_RUNTIME_BUFFER_H_
 #define FORTRAN_RUNTIME_BUFFER_H_
 
-#include "flang/Runtime/freestanding-tools.h"
-#include "flang/Runtime/memory.h"
+#include "FortranRuntime/Runtime/memory.h"
 #include "io-error.h"
+#include "flang/Runtime/freestanding-tools.h"
 #include <algorithm>
 #include <cinttypes>
 #include <cstring>
diff --git a/FortranRuntime/lib/Runtime/character.cpp b/FortranRuntime/lib/Runtime/character.cpp
index 32fc010c6c04dd..1f3edd6e80392e 100644
--- a/FortranRuntime/lib/Runtime/character.cpp
+++ b/FortranRuntime/lib/Runtime/character.cpp
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/character.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "terminator.h"
+#include "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 "terminator.h"
-#include "tools.h"
 #include <algorithm>
 #include <cstring>
 
diff --git a/FortranRuntime/lib/Runtime/command.cpp b/FortranRuntime/lib/Runtime/command.cpp
index dc57758d4f7955..3fc941ab2ef861 100644
--- a/FortranRuntime/lib/Runtime/command.cpp
+++ b/FortranRuntime/lib/Runtime/command.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/command.h"
+#include "flang/Runtime//command.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "environment.h"
-#include "flang/Runtime/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/FortranRuntime/lib/Runtime/connection.h b/FortranRuntime/lib/Runtime/connection.h
index 92a3a9c3860a3e..e078bfb9f0f7e7 100644
--- a/FortranRuntime/lib/Runtime/connection.h
+++ b/FortranRuntime/lib/Runtime/connection.h
@@ -11,8 +11,8 @@
 #ifndef FORTRAN_RUNTIME_CONNECTION_H_
 #define FORTRAN_RUNTIME_CONNECTION_H_
 
-#include "flang/Common/optional.h"
 #include "format.h"
+#include "flang/Common/optional.h"
 #include <cinttypes>
 
 namespace Fortran::runtime::io {
diff --git a/FortranRuntime/lib/Runtime/copy.cpp b/FortranRuntime/lib/Runtime/copy.cpp
index 39c7da45172a43..1049b925f68e5c 100644
--- a/FortranRuntime/lib/Runtime/copy.cpp
+++ b/FortranRuntime/lib/Runtime/copy.cpp
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "copy.h"
-#include "flang/Runtime/allocatable.h"
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "stack.h"
 #include "terminator.h"
 #include "type-info.h"
+#include "flang/Runtime/allocatable.h"
 #include <cstring>
 
 namespace Fortran::runtime {
diff --git a/FortranRuntime/lib/Runtime/copy.h b/FortranRuntime/lib/Runtime/copy.h
index f2c5b41718b71c..3d179d0bec91a7 100644
--- a/FortranRuntime/lib/Runtime/copy.h
+++ b/FortranRuntime/lib/Runtime/copy.h
@@ -12,7 +12,7 @@
 #ifndef FORTRAN_RUNTIME_COPY_H_
 #define FORTRAN_RUNTIME_COPY_H_
 
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 
 namespace Fortran::runtime {
 
diff --git a/FortranRuntime/lib/Runtime/derived-api.cpp b/FortranRuntime/lib/Runtime/derived-api.cpp
index 4b68cdbbed7b2c..176fc0849f25cf 100644
--- a/FortranRuntime/lib/Runtime/derived-api.cpp
+++ b/FortranRuntime/lib/Runtime/derived-api.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/derived-api.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "derived.h"
-#include "flang/Runtime/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "type-info.h"
diff --git a/FortranRuntime/lib/Runtime/derived.cpp b/FortranRuntime/lib/Runtime/derived.cpp
index 52bf54d62c8599..cb2dca24bb4758 100644
--- a/FortranRuntime/lib/Runtime/derived.cpp
+++ b/FortranRuntime/lib/Runtime/derived.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "derived.h"
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/FortranRuntime/lib/Runtime/descriptor-io.h b/FortranRuntime/lib/Runtime/descriptor-io.h
index 2ccad0cea70a29..30d1bd48457728 100644
--- a/FortranRuntime/lib/Runtime/descriptor-io.h
+++ b/FortranRuntime/lib/Runtime/descriptor-io.h
@@ -14,17 +14,17 @@
 // some scalar I/O data transfer APIs could be changed to bypass their use
 // of descriptors in the future for better efficiency.)
 
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "edit-input.h"
 #include "edit-output.h"
-#include "flang/Common/optional.h"
-#include "flang/Common/uint128.h"
-#include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include "io-stmt.h"
 #include "namelist.h"
 #include "terminator.h"
 #include "type-info.h"
 #include "unit.h"
+#include "flang/Common/optional.h"
+#include "flang/Common/uint128.h"
+#include "flang/Runtime/cpp-type.h"
 
 namespace Fortran::runtime::io::descr {
 template <typename A>
diff --git a/FortranRuntime/lib/Runtime/descriptor.cpp b/FortranRuntime/lib/Runtime/descriptor.cpp
index 6756134b06e7b1..96fd48eb6687a9 100644
--- a/FortranRuntime/lib/Runtime/descriptor.cpp
+++ b/FortranRuntime/lib/Runtime/descriptor.cpp
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/allocator-registry.h"
 #include "ISO_Fortran_util.h"
 #include "derived.h"
-#include "flang/Runtime/allocator-registry.h"
 #include "memory.h"
 #include "stat.h"
 #include "terminator.h"
@@ -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/FortranRuntime/lib/Runtime/dot-product.cpp b/FortranRuntime/lib/Runtime/dot-product.cpp
index ab1cfa58ef3d02..2992cbb1f39ad6 100644
--- a/FortranRuntime/lib/Runtime/dot-product.cpp
+++ b/FortranRuntime/lib/Runtime/dot-product.cpp
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Common/float128.h"
-#include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/reduction.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "float.h"
 #include "terminator.h"
 #include "tools.h"
+#include "flang/Common/float128.h"
+#include "flang/Runtime/cpp-type.h"
+#include "flang/Runtime/reduction.h"
 #include <cfloat>
 #include <cinttypes>
 
diff --git a/FortranRuntime/lib/Runtime/edit-input.cpp b/FortranRuntime/lib/Runtime/edit-input.cpp
index eaa9d0d7e641e7..6ebb0e7aca4ade 100644
--- a/FortranRuntime/lib/Runtime/edit-input.cpp
+++ b/FortranRuntime/lib/Runtime/edit-input.cpp
@@ -7,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "edit-input.h"
+#include "namelist.h"
+#include "utf.h"
 #include "flang/Common/optional.h"
 #include "flang/Common/real.h"
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/freestanding-tools.h"
-#include "namelist.h"
-#include "utf.h"
 #include <algorithm>
 #include <cfenv>
 
diff --git a/FortranRuntime/lib/Runtime/edit-input.h b/FortranRuntime/lib/Runtime/edit-input.h
index 2eda81a6d4e11d..f88f6daa47be79 100644
--- a/FortranRuntime/lib/Runtime/edit-input.h
+++ b/FortranRuntime/lib/Runtime/edit-input.h
@@ -9,9 +9,9 @@
 #ifndef FORTRAN_RUNTIME_EDIT_INPUT_H_
 #define FORTRAN_RUNTIME_EDIT_INPUT_H_
 
-#include "flang/Common/decimal.h"
 #include "format.h"
 #include "io-stmt.h"
+#include "flang/Common/decimal.h"
 
 namespace Fortran::runtime::io {
 
diff --git a/FortranRuntime/lib/Runtime/edit-output.cpp b/FortranRuntime/lib/Runtime/edit-output.cpp
index 1fab7db6d3b187..ccaf8085f016fd 100644
--- a/FortranRuntime/lib/Runtime/edit-output.cpp
+++ b/FortranRuntime/lib/Runtime/edit-output.cpp
@@ -8,9 +8,9 @@
 
 #include "edit-output.h"
 #include "emit-encoded.h"
+#include "utf.h"
 #include "flang/Common/real.h"
 #include "flang/Common/uint128.h"
-#include "utf.h"
 #include <algorithm>
 
 namespace Fortran::runtime::io {
diff --git a/FortranRuntime/lib/Runtime/edit-output.h b/FortranRuntime/lib/Runtime/edit-output.h
index cb25b68a35f05b..7e6c6cdedde3ac 100644
--- a/FortranRuntime/lib/Runtime/edit-output.h
+++ b/FortranRuntime/lib/Runtime/edit-output.h
@@ -18,10 +18,10 @@
 // Drives the same fast binary-to-decimal formatting templates used
 // in the f18 front-end.
 
-#include "flang/Common/decimal.h"
-#include "flang/Common/uint128.h"
 #include "format.h"
 #include "io-stmt.h"
+#include "flang/Common/decimal.h"
+#include "flang/Common/uint128.h"
 
 namespace Fortran::runtime::io {
 
diff --git a/FortranRuntime/lib/Runtime/execute.cpp b/FortranRuntime/lib/Runtime/execute.cpp
index 54f28d052873b4..b333c61c8a59f4 100644
--- a/FortranRuntime/lib/Runtime/execute.cpp
+++ b/FortranRuntime/lib/Runtime/execute.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/execute.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "environment.h"
-#include "flang/Runtime/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/FortranRuntime/lib/Runtime/extensions.cpp b/FortranRuntime/lib/Runtime/extensions.cpp
index 94bfa3059e6b45..bb25fe6ee9d886 100644
--- a/FortranRuntime/lib/Runtime/extensions.cpp
+++ b/FortranRuntime/lib/Runtime/extensions.cpp
@@ -10,12 +10,12 @@
 // extensions that will eventually be implemented in Fortran.
 
 #include "flang/Runtime/extensions.h"
-#include "flang/Runtime/command.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/entry-names.h"
-#include "flang/Runtime/io-api.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/io-api-funcs.h"
 #include "terminator.h"
 #include "tools.h"
+#include "flang/Runtime/command.h"
+#include "flang/Runtime/entry-names.h"
 #include <chrono>
 #include <cstring>
 #include <ctime>
diff --git a/FortranRuntime/lib/Runtime/extrema.cpp b/FortranRuntime/lib/Runtime/extrema.cpp
index 0809cb1d5f2ae2..be9da63d7bd6b8 100644
--- a/FortranRuntime/lib/Runtime/extrema.cpp
+++ b/FortranRuntime/lib/Runtime/extrema.cpp
@@ -10,10 +10,10 @@
 // and shapes and (for MAXLOC & MINLOC) result integer kinds.  Also implements
 // NORM2 using common infrastructure.
 
+#include "reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/character.h"
 #include "flang/Runtime/reduction.h"
-#include "reduction-templates.h"
 #include <algorithm>
 #include <cfloat>
 #include <cinttypes>
diff --git a/FortranRuntime/lib/Runtime/file.cpp b/FortranRuntime/lib/Runtime/file.cpp
index 80829d844881e8..de52dafd12df9a 100644
--- a/FortranRuntime/lib/Runtime/file.cpp
+++ b/FortranRuntime/lib/Runtime/file.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "file.h"
+#include "FortranRuntime/Runtime/memory.h"
 #include "tools.h"
-#include "flang/Common/magic-numbers.h"
-#include "flang/Runtime/memory.h"
+#include "flang/Runtime/magic-numbers.h"
 #include <algorithm>
 #include <cerrno>
 #include <cstring>
diff --git a/FortranRuntime/lib/Runtime/file.h b/FortranRuntime/lib/Runtime/file.h
index 66d62756634b24..60ddf2a2741610 100644
--- a/FortranRuntime/lib/Runtime/file.h
+++ b/FortranRuntime/lib/Runtime/file.h
@@ -11,9 +11,9 @@
 #ifndef FORTRAN_RUNTIME_FILE_H_
 #define FORTRAN_RUNTIME_FILE_H_
 
-#include "flang/Common/optional.h"
-#include "flang/Runtime/memory.h"
+#include "FortranRuntime/Runtime/memory.h"
 #include "io-error.h"
+#include "flang/Common/optional.h"
 #include <cinttypes>
 
 namespace Fortran::runtime::io {
diff --git a/FortranRuntime/lib/Runtime/findloc.cpp b/FortranRuntime/lib/Runtime/findloc.cpp
index 47c51fbcef4939..da5fe0c0a0a467 100644
--- a/FortranRuntime/lib/Runtime/findloc.cpp
+++ b/FortranRuntime/lib/Runtime/findloc.cpp
@@ -9,9 +9,9 @@
 // Implements FINDLOC for all required operand types and shapes and result
 // integer kinds.
 
+#include "reduction-templates.h"
 #include "flang/Runtime/character.h"
 #include "flang/Runtime/reduction.h"
-#include "reduction-templates.h"
 #include <cinttypes>
 #include <complex>
 
diff --git a/FortranRuntime/lib/Runtime/format-implementation.h b/FortranRuntime/lib/Runtime/format-implementation.h
index 8d0d0f3376eafc..f17f0a2cb4bfd9 100644
--- a/FortranRuntime/lib/Runtime/format-implementation.h
+++ b/FortranRuntime/lib/Runtime/format-implementation.h
@@ -12,12 +12,12 @@
 #define FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_
 
 #include "emit-encoded.h"
-#include "flang/Common/decimal.h"
-#include "flang/Common/format.h"
-#include "flang/Runtime/main.h"
 #include "format.h"
 #include "io-stmt.h"
 #include "memory.h"
+#include "flang/Common/decimal.h"
+#include "flang/Common/format.h"
+#include "flang/Runtime/main.h"
 #include <algorithm>
 #include <cstring>
 #include <limits>
diff --git a/FortranRuntime/lib/Runtime/format.h b/FortranRuntime/lib/Runtime/format.h
index 3e0807ee452a7e..098a251a04d568 100644
--- a/FortranRuntime/lib/Runtime/format.h
+++ b/FortranRuntime/lib/Runtime/format.h
@@ -12,11 +12,11 @@
 #define FORTRAN_RUNTIME_FORMAT_H_
 
 #include "environment.h"
+#include "io-error.h"
 #include "flang/Common/Fortran-consts.h"
 #include "flang/Common/decimal.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/freestanding-tools.h"
-#include "io-error.h"
 #include <cinttypes>
 
 namespace Fortran::runtime {
diff --git a/FortranRuntime/lib/Runtime/inquiry.cpp b/FortranRuntime/lib/Runtime/inquiry.cpp
index 172b46037d6c4b..c24492754b4f43 100644
--- a/FortranRuntime/lib/Runtime/inquiry.cpp
+++ b/FortranRuntime/lib/Runtime/inquiry.cpp
@@ -10,8 +10,8 @@
 // inquire about shape information of arrays -- LBOUND and SIZE.
 
 #include "flang/Runtime/inquiry.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "copy.h"
-#include "flang/Runtime/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include <algorithm>
diff --git a/FortranRuntime/lib/Runtime/internal-unit.cpp b/FortranRuntime/lib/Runtime/internal-unit.cpp
index 81b937ba63d4b8..4494de9dddc1a1 100644
--- a/FortranRuntime/lib/Runtime/internal-unit.cpp
+++ b/FortranRuntime/lib/Runtime/internal-unit.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "internal-unit.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/freestanding-tools.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "io-error.h"
+#include "flang/Runtime/freestanding-tools.h"
 #include <algorithm>
 #include <type_traits>
 
@@ -36,6 +36,8 @@ RT_API_ATTRS InternalDescriptorUnit<DIR>::InternalDescriptorUnit(
   Descriptor &d{descriptor()};
   RUNTIME_CHECK(
       terminator, that.SizeInBytes() <= d.SizeInBytes(maxRank, true, 0));
+  RUNTIME_CHECK(terminator,
+      that.SizeInBytes() <= MaxDescriptorSizeInBytes(maxRank, true, 0));
   new (&d) Descriptor{that};
   d.Check();
   internalIoCharKind = thatType->second;
diff --git a/FortranRuntime/lib/Runtime/internal-unit.h b/FortranRuntime/lib/Runtime/internal-unit.h
index c4107696810f2b..7579016f14646d 100644
--- a/FortranRuntime/lib/Runtime/internal-unit.h
+++ b/FortranRuntime/lib/Runtime/internal-unit.h
@@ -11,8 +11,8 @@
 #ifndef FORTRAN_RUNTIME_INTERNAL_UNIT_H_
 #define FORTRAN_RUNTIME_INTERNAL_UNIT_H_
 
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "connection.h"
-#include "flang/Runtime/descriptor.h"
 #include <cinttypes>
 #include <type_traits>
 
diff --git a/FortranRuntime/lib/Runtime/io-api-common.h b/FortranRuntime/lib/Runtime/io-api-common.h
index 427666723501a2..fed1d11d6ce6a6 100644
--- a/FortranRuntime/lib/Runtime/io-api-common.h
+++ b/FortranRuntime/lib/Runtime/io-api-common.h
@@ -9,12 +9,12 @@
 #ifndef FORTRAN_RUNTIME_IO_API_COMMON_H_
 #define FORTRAN_RUNTIME_IO_API_COMMON_H_
 
-#include "flang/Common/api-attrs.h"
-#include "flang/Common/optional.h"
-#include "flang/Runtime/io-api.h"
+#include "FortranRuntime/Runtime/io-api-funcs.h"
 #include "io-stmt.h"
 #include "terminator.h"
 #include "unit.h"
+#include "flang/Common/api-attrs.h"
+#include "flang/Common/optional.h"
 
 namespace Fortran::runtime::io {
 
diff --git a/FortranRuntime/lib/Runtime/io-api-minimal.cpp b/FortranRuntime/lib/Runtime/io-api-minimal.cpp
index 683694bd63c068..8cde2333804572 100644
--- a/FortranRuntime/lib/Runtime/io-api-minimal.cpp
+++ b/FortranRuntime/lib/Runtime/io-api-minimal.cpp
@@ -9,8 +9,8 @@
 // Implements the subset of the I/O statement API needed for basic
 // list-directed output (PRINT *) of intrinsic types.
 
+#include "FortranRuntime/Runtime/io-api-funcs.h"
 #include "edit-output.h"
-#include "flang/Runtime/io-api.h"
 #include "format.h"
 #include "io-api-common.h"
 #include "io-stmt.h"
diff --git a/FortranRuntime/lib/Runtime/io-api.cpp b/FortranRuntime/lib/Runtime/io-api.cpp
index 102ea26b359111..fa95d68a004b51 100644
--- a/FortranRuntime/lib/Runtime/io-api.cpp
+++ b/FortranRuntime/lib/Runtime/io-api.cpp
@@ -13,20 +13,20 @@
 // OutputReal{32,64}, OutputComplex{32,64}, OutputAscii, & EndIoStatement()
 // are in runtime/io-api-minimal.cpp.
 
-#include "flang/Runtime/io-api.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/io-api-funcs.h"
+#include "FortranRuntime/Runtime/memory.h"
 #include "descriptor-io.h"
 #include "edit-input.h"
 #include "edit-output.h"
 #include "environment.h"
-#include "flang/Common/optional.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/memory.h"
 #include "format.h"
 #include "io-api-common.h"
 #include "io-stmt.h"
 #include "terminator.h"
 #include "tools.h"
 #include "unit.h"
+#include "flang/Common/optional.h"
 #include <cstdlib>
 #include <memory>
 
diff --git a/FortranRuntime/lib/Runtime/io-error.cpp b/FortranRuntime/lib/Runtime/io-error.cpp
index 400b211c1c418e..053667462058de 100644
--- a/FortranRuntime/lib/Runtime/io-error.cpp
+++ b/FortranRuntime/lib/Runtime/io-error.cpp
@@ -9,7 +9,7 @@
 #include "io-error.h"
 #include "config.h"
 #include "tools.h"
-#include "flang/Common/magic-numbers.h"
+#include "flang/Runtime/magic-numbers.h"
 #include <cerrno>
 #include <cstdarg>
 #include <cstdio>
diff --git a/FortranRuntime/lib/Runtime/io-error.h b/FortranRuntime/lib/Runtime/io-error.h
index 7388a2134ed0d3..e2018cc2ea0ab1 100644
--- a/FortranRuntime/lib/Runtime/io-error.h
+++ b/FortranRuntime/lib/Runtime/io-error.h
@@ -15,8 +15,8 @@
 #ifndef FORTRAN_RUNTIME_IO_ERROR_H_
 #define FORTRAN_RUNTIME_IO_ERROR_H_
 
-#include "flang/Runtime/iostat.h"
-#include "flang/Runtime/memory.h"
+#include "FortranRuntime/Runtime/iostat-funcs.h"
+#include "FortranRuntime/Runtime/memory.h"
 #include "terminator.h"
 #include <cinttypes>
 
diff --git a/FortranRuntime/lib/Runtime/io-stmt.cpp b/FortranRuntime/lib/Runtime/io-stmt.cpp
index 5be5d98ace0d8a..fe02e221671665 100644
--- a/FortranRuntime/lib/Runtime/io-stmt.cpp
+++ b/FortranRuntime/lib/Runtime/io-stmt.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "io-stmt.h"
+#include "FortranRuntime/Runtime/memory.h"
 #include "connection.h"
 #include "emit-encoded.h"
-#include "flang/Runtime/memory.h"
 #include "format.h"
 #include "tools.h"
 #include "unit.h"
diff --git a/FortranRuntime/lib/Runtime/io-stmt.h b/FortranRuntime/lib/Runtime/io-stmt.h
index 79a8b28c8aa19f..21746ff1966218 100644
--- a/FortranRuntime/lib/Runtime/io-stmt.h
+++ b/FortranRuntime/lib/Runtime/io-stmt.h
@@ -11,16 +11,16 @@
 #ifndef FORTRAN_RUNTIME_IO_STMT_H_
 #define FORTRAN_RUNTIME_IO_STMT_H_
 
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/io-api-funcs.h"
 #include "connection.h"
 #include "file.h"
-#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 "format.h"
 #include "internal-unit.h"
 #include "io-error.h"
+#include "flang/Common/optional.h"
+#include "flang/Common/reference-wrapper.h"
+#include "flang/Common/visit.h"
 #include <flang/Common/variant.h>
 #include <functional>
 #include <type_traits>
diff --git a/FortranRuntime/lib/Runtime/iostat.cpp b/FortranRuntime/lib/Runtime/iostat.cpp
index f23567be4910da..8d769a09252fd6 100644
--- a/FortranRuntime/lib/Runtime/iostat.cpp
+++ b/FortranRuntime/lib/Runtime/iostat.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/iostat.h"
+#include "FortranRuntime/Runtime/iostat-funcs.h"
 
 namespace Fortran::runtime::io {
 RT_OFFLOAD_API_GROUP_BEGIN
diff --git a/FortranRuntime/lib/Runtime/matmul-transpose.cpp b/FortranRuntime/lib/Runtime/matmul-transpose.cpp
index 3b4b487daa335e..ec5388e3fca793 100644
--- a/FortranRuntime/lib/Runtime/matmul-transpose.cpp
+++ b/FortranRuntime/lib/Runtime/matmul-transpose.cpp
@@ -21,12 +21,12 @@
 // to use the faster BLAS routines.
 
 #include "flang/Runtime/matmul-transpose.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "terminator.h"
+#include "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 "terminator.h"
-#include "tools.h"
 #include <cstring>
 
 namespace {
diff --git a/FortranRuntime/lib/Runtime/matmul.cpp b/FortranRuntime/lib/Runtime/matmul.cpp
index 62674316bc6a57..01be7f7c75bc45 100644
--- a/FortranRuntime/lib/Runtime/matmul.cpp
+++ b/FortranRuntime/lib/Runtime/matmul.cpp
@@ -20,12 +20,12 @@
 // Places where BLAS routines could be called are marked as TODO items.
 
 #include "flang/Runtime/matmul.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "terminator.h"
+#include "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 "terminator.h"
-#include "tools.h"
 #include <cstring>
 
 namespace {
diff --git a/FortranRuntime/lib/Runtime/memory.cpp b/FortranRuntime/lib/Runtime/memory.cpp
index bf2c4cd4a35470..a4cebf7edc6c64 100644
--- a/FortranRuntime/lib/Runtime/memory.cpp
+++ b/FortranRuntime/lib/Runtime/memory.cpp
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/memory.h"
-#include "flang/Runtime/freestanding-tools.h"
+#include "FortranRuntime/Runtime/memory.h"
 #include "terminator.h"
 #include "tools.h"
+#include "flang/Runtime/freestanding-tools.h"
 #include <cstdlib>
 
 namespace Fortran::runtime {
diff --git a/FortranRuntime/lib/Runtime/misc-intrinsic.cpp b/FortranRuntime/lib/Runtime/misc-intrinsic.cpp
index a0f41e4e3f156c..91a3b136e009a5 100644
--- a/FortranRuntime/lib/Runtime/misc-intrinsic.cpp
+++ b/FortranRuntime/lib/Runtime/misc-intrinsic.cpp
@@ -7,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/misc-intrinsic.h"
-#include "flang/Common/optional.h"
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
+#include "flang/Common/optional.h"
 #include <algorithm>
 #include <cstdio>
 #include <cstring>
diff --git a/FortranRuntime/lib/Runtime/namelist.cpp b/FortranRuntime/lib/Runtime/namelist.cpp
index 1c8942fc375c43..46036549bcd316 100644
--- a/FortranRuntime/lib/Runtime/namelist.cpp
+++ b/FortranRuntime/lib/Runtime/namelist.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "namelist.h"
+#include "FortranRuntime/Runtime/io-api-funcs.h"
 #include "descriptor-io.h"
 #include "emit-encoded.h"
-#include "flang/Runtime/io-api.h"
 #include "io-stmt.h"
 #include <algorithm>
 #include <cstring>
diff --git a/FortranRuntime/lib/Runtime/namelist.h b/FortranRuntime/lib/Runtime/namelist.h
index 2c4d331ae05e85..04432f8a08cb97 100644
--- a/FortranRuntime/lib/Runtime/namelist.h
+++ b/FortranRuntime/lib/Runtime/namelist.h
@@ -11,8 +11,8 @@
 #ifndef FORTRAN_RUNTIME_NAMELIST_H_
 #define FORTRAN_RUNTIME_NAMELIST_H_
 
-#include "flang/Common/api-attrs.h"
 #include "non-tbp-dio.h"
+#include "flang/Common/api-attrs.h"
 
 #include <cstddef>
 
diff --git a/FortranRuntime/lib/Runtime/numeric-templates.h b/FortranRuntime/lib/Runtime/numeric-templates.h
index f0045e8ee36e20..159b8b0b9579ad 100644
--- a/FortranRuntime/lib/Runtime/numeric-templates.h
+++ b/FortranRuntime/lib/Runtime/numeric-templates.h
@@ -18,10 +18,10 @@
 #ifndef FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_
 #define FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_
 
-#include "flang/Common/api-attrs.h"
-#include "flang/Common/float128.h"
 #include "terminator.h"
 #include "tools.h"
+#include "flang/Common/api-attrs.h"
+#include "flang/Common/float128.h"
 #include <cstdint>
 #include <limits>
 
diff --git a/FortranRuntime/lib/Runtime/numeric.cpp b/FortranRuntime/lib/Runtime/numeric.cpp
index a3fcfeaa9ee266..b0f68a7fc81d29 100644
--- a/FortranRuntime/lib/Runtime/numeric.cpp
+++ b/FortranRuntime/lib/Runtime/numeric.cpp
@@ -7,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/numeric.h"
-#include "flang/Common/float128.h"
 #include "numeric-templates.h"
 #include "terminator.h"
 #include "tools.h"
+#include "flang/Common/float128.h"
 #include <cfloat>
 #include <climits>
 #include <cmath>
diff --git a/FortranRuntime/lib/Runtime/product.cpp b/FortranRuntime/lib/Runtime/product.cpp
index 8c11bf4144919e..e4a6e81bd0c508 100644
--- a/FortranRuntime/lib/Runtime/product.cpp
+++ b/FortranRuntime/lib/Runtime/product.cpp
@@ -8,9 +8,9 @@
 
 // Implements PRODUCT for all required operand types and shapes.
 
+#include "reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/reduction.h"
-#include "reduction-templates.h"
 #include <cfloat>
 #include <cinttypes>
 #include <complex>
diff --git a/FortranRuntime/lib/Runtime/random-templates.h b/FortranRuntime/lib/Runtime/random-templates.h
index 801484225bc211..9faa9c7cfa7002 100644
--- a/FortranRuntime/lib/Runtime/random-templates.h
+++ b/FortranRuntime/lib/Runtime/random-templates.h
@@ -9,10 +9,10 @@
 #ifndef FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_
 #define FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_
 
-#include "flang/Common/optional.h"
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "lock.h"
 #include "numeric-templates.h"
+#include "flang/Common/optional.h"
 #include <algorithm>
 #include <random>
 
diff --git a/FortranRuntime/lib/Runtime/random.cpp b/FortranRuntime/lib/Runtime/random.cpp
index 8e1561960d48be..911b59b508eb4f 100644
--- a/FortranRuntime/lib/Runtime/random.cpp
+++ b/FortranRuntime/lib/Runtime/random.cpp
@@ -10,14 +10,14 @@
 // RANDOM_SEED.
 
 #include "flang/Runtime/random.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "lock.h"
+#include "random-templates.h"
+#include "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 "lock.h"
-#include "random-templates.h"
-#include "terminator.h"
 #include <cmath>
 #include <cstdint>
 #include <limits>
diff --git a/FortranRuntime/lib/Runtime/reduce.cpp b/FortranRuntime/lib/Runtime/reduce.cpp
index 4d33c2a714e5af..a020ffef6fe6a5 100644
--- a/FortranRuntime/lib/Runtime/reduce.cpp
+++ b/FortranRuntime/lib/Runtime/reduce.cpp
@@ -9,7 +9,7 @@
 // REDUCE() implementation
 
 #include "flang/Runtime/reduce.h"
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "reduction-templates.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/FortranRuntime/lib/Runtime/reduction-templates.h b/FortranRuntime/lib/Runtime/reduction-templates.h
index 30ae641ba7b3ac..714584ec613ba3 100644
--- a/FortranRuntime/lib/Runtime/reduction-templates.h
+++ b/FortranRuntime/lib/Runtime/reduction-templates.h
@@ -21,11 +21,11 @@
 #ifndef FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_
 #define FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_
 
-#include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "numeric-templates.h"
 #include "terminator.h"
 #include "tools.h"
+#include "flang/Runtime/cpp-type.h"
 #include <algorithm>
 
 namespace Fortran::runtime {
diff --git a/FortranRuntime/lib/Runtime/reduction.cpp b/FortranRuntime/lib/Runtime/reduction.cpp
index f4e1f2aa6818d5..21930fee07ead7 100644
--- a/FortranRuntime/lib/Runtime/reduction.cpp
+++ b/FortranRuntime/lib/Runtime/reduction.cpp
@@ -14,7 +14,7 @@
 // NORM2, MAXLOC, MINLOC, MAXVAL, and MINVAL are in extrema.cpp.
 
 #include "flang/Runtime/reduction.h"
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "reduction-templates.h"
 #include <cinttypes>
 
diff --git a/FortranRuntime/lib/Runtime/stack.h b/FortranRuntime/lib/Runtime/stack.h
index dc5b6101d3da0f..36e2d0a103a887 100644
--- a/FortranRuntime/lib/Runtime/stack.h
+++ b/FortranRuntime/lib/Runtime/stack.h
@@ -13,7 +13,7 @@
 #ifndef FORTRAN_RUNTIME_STACK_H_
 #define FORTRAN_RUNTIME_STACK_H_
 
-#include "flang/Runtime/memory.h"
+#include "FortranRuntime/Runtime/memory.h"
 #include "terminator.h"
 
 namespace Fortran::runtime {
diff --git a/FortranRuntime/lib/Runtime/stat.cpp b/FortranRuntime/lib/Runtime/stat.cpp
index 01ae922e080865..1af6c43102518b 100644
--- a/FortranRuntime/lib/Runtime/stat.cpp
+++ b/FortranRuntime/lib/Runtime/stat.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "stat.h"
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 
diff --git a/FortranRuntime/lib/Runtime/stat.h b/FortranRuntime/lib/Runtime/stat.h
index a679f9da16dd46..eccd69024d726b 100644
--- a/FortranRuntime/lib/Runtime/stat.h
+++ b/FortranRuntime/lib/Runtime/stat.h
@@ -13,7 +13,7 @@
 #define FORTRAN_RUNTIME_STAT_H_
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Common/api-attrs.h"
-#include "flang/Common/magic-numbers.h"
+#include "flang/Runtime/magic-numbers.h"
 namespace Fortran::runtime {
 
 class Descriptor;
diff --git a/FortranRuntime/lib/Runtime/sum.cpp b/FortranRuntime/lib/Runtime/sum.cpp
index e33b77e20f0f11..64982b9fd53690 100644
--- a/FortranRuntime/lib/Runtime/sum.cpp
+++ b/FortranRuntime/lib/Runtime/sum.cpp
@@ -12,9 +12,9 @@
 // cancellation on intermediate results by using "Kahan summation"
 // (basically the same as manual "double-double").
 
+#include "reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/reduction.h"
-#include "reduction-templates.h"
 #include <cfloat>
 #include <cinttypes>
 #include <complex>
diff --git a/FortranRuntime/lib/Runtime/support.cpp b/FortranRuntime/lib/Runtime/support.cpp
index 0a39ff24b0cafc..798d502ba248e2 100644
--- a/FortranRuntime/lib/Runtime/support.cpp
+++ b/FortranRuntime/lib/Runtime/support.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/support.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "ISO_Fortran_util.h"
-#include "flang/Runtime/descriptor.h"
 #include "type-info.h"
 
 namespace Fortran::runtime {
diff --git a/FortranRuntime/lib/Runtime/temporary-stack.cpp b/FortranRuntime/lib/Runtime/temporary-stack.cpp
index f944dfb7aa1471..d8ff08e51cc211 100644
--- a/FortranRuntime/lib/Runtime/temporary-stack.cpp
+++ b/FortranRuntime/lib/Runtime/temporary-stack.cpp
@@ -10,11 +10,11 @@
 // temporaries. For use in HLFIR lowering.
 
 #include "flang/Runtime/temporary-stack.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/memory.h"
+#include "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"
-#include "terminator.h"
 
 namespace {
 
diff --git a/FortranRuntime/lib/Runtime/time-intrinsic.cpp b/FortranRuntime/lib/Runtime/time-intrinsic.cpp
index 4b362c90c52f25..15c42077c0afd5 100644
--- a/FortranRuntime/lib/Runtime/time-intrinsic.cpp
+++ b/FortranRuntime/lib/Runtime/time-intrinsic.cpp
@@ -9,10 +9,10 @@
 // Implements time-related intrinsic subroutines.
 
 #include "flang/Runtime/time-intrinsic.h"
-#include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
+#include "flang/Runtime/cpp-type.h"
 #include <algorithm>
 #include <cstdint>
 #include <cstdio>
diff --git a/FortranRuntime/lib/Runtime/tools.h b/FortranRuntime/lib/Runtime/tools.h
index 4058767ca283a9..332ffac77f2595 100644
--- a/FortranRuntime/lib/Runtime/tools.h
+++ b/FortranRuntime/lib/Runtime/tools.h
@@ -9,13 +9,13 @@
 #ifndef FORTRAN_RUNTIME_TOOLS_H_
 #define FORTRAN_RUNTIME_TOOLS_H_
 
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/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 "stat.h"
-#include "terminator.h"
 #include <cstring>
 #include <functional>
 #include <map>
diff --git a/FortranRuntime/lib/Runtime/transformational.cpp b/FortranRuntime/lib/Runtime/transformational.cpp
index 66dc5bd4939bae..28dd02a28036de 100644
--- a/FortranRuntime/lib/Runtime/transformational.cpp
+++ b/FortranRuntime/lib/Runtime/transformational.cpp
@@ -17,11 +17,11 @@
 // of the standard but it more likely to conform with its intent.
 
 #include "flang/Runtime/transformational.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "copy.h"
-#include "flang/Common/float128.h"
-#include "flang/Runtime/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
+#include "flang/Common/float128.h"
 
 namespace Fortran::runtime {
 
diff --git a/FortranRuntime/lib/Runtime/type-code.cpp b/FortranRuntime/lib/Runtime/type-code.cpp
index 2709ca1be75a53..16f5497bc7a709 100644
--- a/FortranRuntime/lib/Runtime/type-code.cpp
+++ b/FortranRuntime/lib/Runtime/type-code.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/type-code.h"
+#include "FortranRuntime/Runtime/type-code.h"
 #include <cstdint>
 
 namespace Fortran::runtime {
diff --git a/FortranRuntime/lib/Runtime/type-info.cpp b/FortranRuntime/lib/Runtime/type-info.cpp
index 24fc9c33d92819..19e9211fc063f4 100644
--- a/FortranRuntime/lib/Runtime/type-info.cpp
+++ b/FortranRuntime/lib/Runtime/type-info.cpp
@@ -84,10 +84,14 @@ RT_API_ATTRS std::size_t Component::SizeInBytes(
     return GetElementByteSize(instance) * GetElements(instance);
   } else if (category() == TypeCategory::Derived) {
     const DerivedType *type{derivedType()};
-    return Descriptor::SizeInBytes(
-        rank_, true, type ? type->LenParameters() : 0);
+    auto bytes {Descriptor::SizeInBytes(
+        rank_, true, type ? type->LenParameters() : 0)};
+    assert(bytes <=  MaxDescriptorSizeInBytes(  rank_, true, type ? type->LenParameters() : 0));
+    return bytes;
   } else {
-    return Descriptor::SizeInBytes(rank_);
+    auto bytes{ Descriptor::SizeInBytes(rank_)};
+        assert(bytes <=  MaxDescriptorSizeInBytes(  rank_));
+        return bytes;
   }
 }
 
diff --git a/FortranRuntime/lib/Runtime/type-info.h b/FortranRuntime/lib/Runtime/type-info.h
index ff3523bcb2b8eb..150942547c2ee8 100644
--- a/FortranRuntime/lib/Runtime/type-info.h
+++ b/FortranRuntime/lib/Runtime/type-info.h
@@ -12,11 +12,11 @@
 // A C++ perspective of the derived type description schemata in
 // flang/module/__fortran_type_info.f90.
 
+#include "FortranRuntime/Runtime/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 "terminator.h"
 #include <cinttypes>
 #include <memory>
 
diff --git a/FortranRuntime/lib/Runtime/unit-map.h b/FortranRuntime/lib/Runtime/unit-map.h
index 4e61246f9a2d86..f37e2df7f3b15a 100644
--- a/FortranRuntime/lib/Runtime/unit-map.h
+++ b/FortranRuntime/lib/Runtime/unit-map.h
@@ -12,10 +12,10 @@
 #ifndef FORTRAN_RUNTIME_UNIT_MAP_H_
 #define FORTRAN_RUNTIME_UNIT_MAP_H_
 
-#include "flang/Common/fast-int-set.h"
-#include "flang/Runtime/memory.h"
+#include "FortranRuntime/Runtime/memory.h"
 #include "lock.h"
 #include "unit.h"
+#include "flang/Common/fast-int-set.h"
 #include <cstdint>
 #include <cstdlib>
 
diff --git a/FortranRuntime/lib/Runtime/unit.h b/FortranRuntime/lib/Runtime/unit.h
index 993fbf2977cebf..4a7444aedbe5b6 100644
--- a/FortranRuntime/lib/Runtime/unit.h
+++ b/FortranRuntime/lib/Runtime/unit.h
@@ -11,18 +11,18 @@
 #ifndef FORTRAN_RUNTIME_UNIT_H_
 #define FORTRAN_RUNTIME_UNIT_H_
 
+#include "FortranRuntime/Runtime/memory.h"
 #include "buffer.h"
 #include "connection.h"
 #include "environment.h"
 #include "file.h"
-#include "flang/Common/constexpr-bitset.h"
-#include "flang/Common/optional.h"
-#include "flang/Runtime/memory.h"
 #include "format.h"
 #include "io-error.h"
 #include "io-stmt.h"
 #include "lock.h"
 #include "terminator.h"
+#include "flang/Common/constexpr-bitset.h"
+#include "flang/Common/optional.h"
 #include <cstdlib>
 #include <cstring>
 #include <flang/Common/variant.h>
diff --git a/FortranRuntime/unittests/Common/CMakeLists.txt b/FortranRuntime/unittests/Common/CMakeLists.txt
deleted file mode 100644
index 72f2c50d14162d..00000000000000
--- a/FortranRuntime/unittests/Common/CMakeLists.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-#===-- unittests/Common/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_unittest(FlangCommonTests
-  FastIntSetTest.cpp
-)
diff --git a/FortranRuntime/unittests/Decimal/CMakeLists.txt b/FortranRuntime/unittests/Decimal/CMakeLists.txt
deleted file mode 100644
index 40b89b48e1adeb..00000000000000
--- a/FortranRuntime/unittests/Decimal/CMakeLists.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-#===-- unittests/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
-#
-#===------------------------------------------------------------------------===#
-
-set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-add_flang_nongtest_unittest(quick-sanity-test
-  FortranDecimal
-)
-
-# This test is not run by default as it takes a long time to execute.
-add_flang_nongtest_unittest(thorough-test
-  SLOW_TEST
-  FortranDecimal
-)
diff --git a/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp b/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp
index d2546e0c22d2d6..fd7073ca1d7db0 100644
--- a/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp
+++ b/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "FortranRuntime/Runtime/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>
@@ -28,6 +28,7 @@ template <int rank> class Test_CFI_CDESC_T {
     MATCH(false, std::is_const<type>::value);
     MATCH(false, std::is_volatile<type>::value);
     // suitable in size
+      MATCH(true, Descriptor::SizeInBytes(rank_, false) <= Fortran::common::MaxDescriptorSizeInBytes(  rank_, false));
     if (rank > 0) {
       MATCH(sizeof(dvStorage_), Descriptor::SizeInBytes(rank_, false));
     } else { // C++ implementation over-allocates for rank=0 by 24bytes.
diff --git a/FortranRuntime/unittests/Evaluate/reshape.cpp b/FortranRuntime/unittests/Evaluate/reshape.cpp
index a93afd2a3c90cd..0233ab37e25c6e 100644
--- a/FortranRuntime/unittests/Evaluate/reshape.cpp
+++ b/FortranRuntime/unittests/Evaluate/reshape.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "flang/Runtime/transformational.h"
 #include "flang/Testing/testing.h"
 #include <cinttypes>
diff --git a/FortranRuntime/unittests/Runtime/AccessTest.cpp b/FortranRuntime/unittests/Runtime/AccessTest.cpp
index 3e9feaf945b66d..e72386cc9ac247 100644
--- a/FortranRuntime/unittests/Runtime/AccessTest.cpp
+++ b/FortranRuntime/unittests/Runtime/AccessTest.cpp
@@ -10,9 +10,9 @@
 #ifndef _WIN32
 
 #include "CrashHandlerFixture.h"
+#include "gtest/gtest.h"
 #include "flang/Runtime/extensions.h"
 #include "llvm/ADT/Twine.h"
-#include "gtest/gtest.h"
 
 #include <fcntl.h>
 #include <sys/stat.h>
diff --git a/FortranRuntime/unittests/Runtime/Allocatable.cpp b/FortranRuntime/unittests/Runtime/Allocatable.cpp
index c01f85598d21ed..8e10dc408ceae8 100644
--- a/FortranRuntime/unittests/Runtime/Allocatable.cpp
+++ b/FortranRuntime/unittests/Runtime/Allocatable.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/allocatable.h"
-#include "tools.h"
 #include "gtest/gtest.h"
+#include "tools.h"
 
 using namespace Fortran::runtime;
 
diff --git a/FortranRuntime/unittests/Runtime/ArrayConstructor.cpp b/FortranRuntime/unittests/Runtime/ArrayConstructor.cpp
index 9011da304b6bc3..9d9a4ddae8689f 100644
--- a/FortranRuntime/unittests/Runtime/ArrayConstructor.cpp
+++ b/FortranRuntime/unittests/Runtime/ArrayConstructor.cpp
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "FortranRuntime/Runtime/array-constructor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/type-code.h"
+#include "gtest/gtest.h"
+#include "tools.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 "tools.h"
-#include "gtest/gtest.h"
 
 #include <memory>
 
diff --git a/FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp b/FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp
index d2c1600af8c631..d2a2e5a11abf80 100644
--- a/FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp
+++ b/FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "FortranRuntime/Runtime/CUDA/allocator.h"
+#include "FortranRuntime/Runtime/CUDA/descriptor.h"
+#include "FortranRuntime/Runtime/allocatable.h"
+#include "FortranRuntime/Runtime/allocator-registry.h"
+#include "gtest/gtest.h"
 #include "../../../runtime/terminator.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 "gtest/gtest.h"
 
 #include "cuda_runtime.h"
 
diff --git a/FortranRuntime/unittests/Runtime/CharacterTest.cpp b/FortranRuntime/unittests/Runtime/CharacterTest.cpp
index 8829f5e43265b0..610061e2122cd5 100644
--- a/FortranRuntime/unittests/Runtime/CharacterTest.cpp
+++ b/FortranRuntime/unittests/Runtime/CharacterTest.cpp
@@ -10,7 +10,7 @@
 // in Fortran.
 
 #include "flang/Runtime/character.h"
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "gtest/gtest.h"
 #include <cstring>
 #include <functional>
diff --git a/FortranRuntime/unittests/Runtime/CommandTest.cpp b/FortranRuntime/unittests/Runtime/CommandTest.cpp
index aa79ce381ba8d0..a7d68508c5abca 100644
--- a/FortranRuntime/unittests/Runtime/CommandTest.cpp
+++ b/FortranRuntime/unittests/Runtime/CommandTest.cpp
@@ -7,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/command.h"
-#include "flang/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
 #include "flang/Runtime/execute.h"
 #include "flang/Runtime/extensions.h"
 #include "flang/Runtime/main.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 #include <cstddef>
 #include <cstdlib>
 
diff --git a/FortranRuntime/unittests/Runtime/Derived.cpp b/FortranRuntime/unittests/Runtime/Derived.cpp
index 11b732fe10b790..22361352fdf5d9 100644
--- a/FortranRuntime/unittests/Runtime/Derived.cpp
+++ b/FortranRuntime/unittests/Runtime/Derived.cpp
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/derived-api.h"
-#include "flang/Runtime/descriptor.h"
-#include "tools.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "gtest/gtest.h"
+#include "tools.h"
+#include "flang/Runtime/derived-api.h"
 
 using namespace Fortran::runtime;
 
diff --git a/FortranRuntime/unittests/Runtime/ExternalIOTest.cpp b/FortranRuntime/unittests/Runtime/ExternalIOTest.cpp
index 00c2fd76ce0c04..7ff4aa3c14bdc5 100644
--- a/FortranRuntime/unittests/Runtime/ExternalIOTest.cpp
+++ b/FortranRuntime/unittests/Runtime/ExternalIOTest.cpp
@@ -11,12 +11,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/io-api.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/io-api-funcs.h"
+#include "gtest/gtest.h"
 #include "flang/Runtime/main.h"
 #include "flang/Runtime/stop.h"
 #include "llvm/Support/raw_ostream.h"
-#include "gtest/gtest.h"
 #include <cstring>
 #include <string_view>
 
diff --git a/FortranRuntime/unittests/Runtime/Inquiry.cpp b/FortranRuntime/unittests/Runtime/Inquiry.cpp
index 204a97a1088ac0..3e5f0037177f1c 100644
--- a/FortranRuntime/unittests/Runtime/Inquiry.cpp
+++ b/FortranRuntime/unittests/Runtime/Inquiry.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/inquiry.h"
-#include "flang/Runtime/type-code.h"
-#include "tools.h"
+#include "FortranRuntime/Runtime/type-code.h"
 #include "gtest/gtest.h"
+#include "tools.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/FortranRuntime/unittests/Runtime/ListInputTest.cpp b/FortranRuntime/unittests/Runtime/ListInputTest.cpp
index 4c30d6ed750141..e0fe4dfeac3949 100644
--- a/FortranRuntime/unittests/Runtime/ListInputTest.cpp
+++ b/FortranRuntime/unittests/Runtime/ListInputTest.cpp
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "../../lib/Runtime/io-error.h"
 #include "CrashHandlerFixture.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/io-api.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/io-api-funcs.h"
+#include "../../lib/Runtime/io-error.h"
 
 using namespace Fortran::runtime;
 using namespace Fortran::runtime::io;
diff --git a/FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp b/FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp
index 928fddec50c874..9fa0c2f4260edb 100644
--- a/FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp
+++ b/FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/io-api.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/io-api-funcs.h"
 #include <algorithm>
 #include <array>
 #include <cstring>
diff --git a/FortranRuntime/unittests/Runtime/Matmul.cpp b/FortranRuntime/unittests/Runtime/Matmul.cpp
index cfa5d18cc36d33..6eb4012e785ff1 100644
--- a/FortranRuntime/unittests/Runtime/Matmul.cpp
+++ b/FortranRuntime/unittests/Runtime/Matmul.cpp
@@ -7,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/matmul.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/type-code.h"
+#include "gtest/gtest.h"
+#include "tools.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
-#include "tools.h"
-#include "gtest/gtest.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/FortranRuntime/unittests/Runtime/MatmulTranspose.cpp b/FortranRuntime/unittests/Runtime/MatmulTranspose.cpp
index 146c2283fb1aca..199062f820c303 100644
--- a/FortranRuntime/unittests/Runtime/MatmulTranspose.cpp
+++ b/FortranRuntime/unittests/Runtime/MatmulTranspose.cpp
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/type-code.h"
+#include "gtest/gtest.h"
+#include "tools.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"
-#include "tools.h"
-#include "gtest/gtest.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp b/FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp
index 08229b5e48f0dd..1033dda9d636f7 100644
--- a/FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp
+++ b/FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp
@@ -6,12 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime//misc-intrinsic.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "gtest/gtest.h"
+#include "tools.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
-#include "tools.h"
-#include "gtest/gtest.h"
+#include "flang/Runtime/misc-intrinsic.h"
 
 using namespace Fortran::runtime;
 
diff --git a/FortranRuntime/unittests/Runtime/Namelist.cpp b/FortranRuntime/unittests/Runtime/Namelist.cpp
index 7b834dec49c3c4..544ab85234fd65 100644
--- a/FortranRuntime/unittests/Runtime/Namelist.cpp
+++ b/FortranRuntime/unittests/Runtime/Namelist.cpp
@@ -8,8 +8,8 @@
 
 #include "../../lib/Runtime/namelist.h"
 #include "CrashHandlerFixture.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/io-api.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/io-api-funcs.h"
 #include "tools.h"
 #include <algorithm>
 #include <cinttypes>
diff --git a/FortranRuntime/unittests/Runtime/Numeric.cpp b/FortranRuntime/unittests/Runtime/Numeric.cpp
index fb595ae262c324..d15919b972bca7 100644
--- a/FortranRuntime/unittests/Runtime/Numeric.cpp
+++ b/FortranRuntime/unittests/Runtime/Numeric.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/numeric.h"
-#include "flang/Common/float128.h"
 #include "gtest/gtest.h"
+#include "flang/Common/float128.h"
 #include <cmath>
 #include <limits>
 
diff --git a/FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp b/FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp
index 8a1dd6de1449b9..c588c739686bed 100644
--- a/FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp
+++ b/FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/io-api.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/io-api-funcs.h"
 #include <algorithm>
 #include <array>
 #include <cstring>
diff --git a/FortranRuntime/unittests/Runtime/Pointer.cpp b/FortranRuntime/unittests/Runtime/Pointer.cpp
index a05bd70a64bb9f..733cd42232875f 100644
--- a/FortranRuntime/unittests/Runtime/Pointer.cpp
+++ b/FortranRuntime/unittests/Runtime/Pointer.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/pointer.h"
-#include "flang/Runtime/descriptor.h"
-#include "tools.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "gtest/gtest.h"
+#include "tools.h"
 
 using namespace Fortran::runtime;
 
diff --git a/FortranRuntime/unittests/Runtime/Random.cpp b/FortranRuntime/unittests/Runtime/Random.cpp
index 4e4b59cbcf40e7..81497a682660a8 100644
--- a/FortranRuntime/unittests/Runtime/Random.cpp
+++ b/FortranRuntime/unittests/Runtime/Random.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime//random.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
+#include "flang/Runtime/random.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/type-code.h"
 #include "gtest/gtest.h"
 #include <cmath>
 
diff --git a/FortranRuntime/unittests/Runtime/Reduction.cpp b/FortranRuntime/unittests/Runtime/Reduction.cpp
index c35f6e2fa6a41b..a382f4b7a71770 100644
--- a/FortranRuntime/unittests/Runtime/Reduction.cpp
+++ b/FortranRuntime/unittests/Runtime/Reduction.cpp
@@ -7,14 +7,14 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/reduction.h"
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/type-code.h"
+#include "gtest/gtest.h"
+#include "tools.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 "tools.h"
-#include "gtest/gtest.h"
 #include <cstdint>
 #include <cstring>
 #include <string>
diff --git a/FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp b/FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp
index 61580a8d46792f..7ce1ee796d739b 100644
--- a/FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp
+++ b/FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp
@@ -10,11 +10,11 @@
 /// runtime components and ensure the test fixture handles crashes as we expect.
 //
 //===----------------------------------------------------------------------===//
-#include "../../lib/Runtime/terminator.h"
 #include "CrashHandlerFixture.h"
+#include "tools.h"
+#include "../../lib/Runtime/terminator.h"
 #include "flang/Runtime/io-api.h"
 #include "flang/Runtime/transformational.h"
-#include "tools.h"
 #include <gtest/gtest.h>
 
 using namespace Fortran::runtime;
diff --git a/FortranRuntime/unittests/Runtime/Stop.cpp b/FortranRuntime/unittests/Runtime/Stop.cpp
index 5fd8deaad21d6b..c12ec097068438 100644
--- a/FortranRuntime/unittests/Runtime/Stop.cpp
+++ b/FortranRuntime/unittests/Runtime/Stop.cpp
@@ -10,8 +10,8 @@
 //
 //===----------------------------------------------------------------------===//
 #include "flang/Runtime/stop.h"
-#include "../../lib/Runtime/environment.h"
 #include "CrashHandlerFixture.h"
+#include "../../lib/Runtime/environment.h"
 #include <cstdlib>
 #include <gtest/gtest.h>
 
diff --git a/FortranRuntime/unittests/Runtime/Support.cpp b/FortranRuntime/unittests/Runtime/Support.cpp
index 38c0d6efaf9db7..05328e6baa411c 100644
--- a/FortranRuntime/unittests/Runtime/Support.cpp
+++ b/FortranRuntime/unittests/Runtime/Support.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/support.h"
-#include "flang/Runtime/descriptor.h"
-#include "tools.h"
+#include "FortranRuntime/Runtime/descriptor.h"
 #include "gtest/gtest.h"
+#include "tools.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/FortranRuntime/unittests/Runtime/TemporaryStack.cpp b/FortranRuntime/unittests/Runtime/TemporaryStack.cpp
index 63d99416ea64cb..b0b1041f0f09e7 100644
--- a/FortranRuntime/unittests/Runtime/TemporaryStack.cpp
+++ b/FortranRuntime/unittests/Runtime/TemporaryStack.cpp
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/type-code.h"
+#include "gtest/gtest.h"
+#include "tools.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 "tools.h"
-#include "gtest/gtest.h"
 #include <vector>
 
 using namespace Fortran::runtime;
diff --git a/FortranRuntime/unittests/Runtime/Time.cpp b/FortranRuntime/unittests/Runtime/Time.cpp
index 6fd00d669a9575..548c0834e34a36 100644
--- a/FortranRuntime/unittests/Runtime/Time.cpp
+++ b/FortranRuntime/unittests/Runtime/Time.cpp
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/time-intrinsic.h"
 #include "gtest/gtest.h"
+#include "flang/Runtime/time-intrinsic.h"
 #include <algorithm>
 #include <cctype>
 #include <cerrno>
diff --git a/FortranRuntime/unittests/Runtime/Transformational.cpp b/FortranRuntime/unittests/Runtime/Transformational.cpp
index b5a4e0e8e9588b..6b8903750d0aec 100644
--- a/FortranRuntime/unittests/Runtime/Transformational.cpp
+++ b/FortranRuntime/unittests/Runtime/Transformational.cpp
@@ -7,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/transformational.h"
-#include "flang/Common/float128.h"
-#include "flang/Runtime/type-code.h"
-#include "tools.h"
+#include "FortranRuntime/Runtime/type-code.h"
 #include "gtest/gtest.h"
+#include "tools.h"
+#include "flang/Common/float128.h"
 #include <vector>
 
 using namespace Fortran::runtime;
diff --git a/FortranRuntime/unittests/Runtime/tools.h b/FortranRuntime/unittests/Runtime/tools.h
index 702103d225ab72..8000d83fc0c394 100644
--- a/FortranRuntime/unittests/Runtime/tools.h
+++ b/FortranRuntime/unittests/Runtime/tools.h
@@ -9,11 +9,11 @@
 #ifndef FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
 #define FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
 
+#include "FortranRuntime/Runtime/descriptor.h"
+#include "FortranRuntime/Runtime/type-code.h"
+#include "gtest/gtest.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
-#include "gtest/gtest.h"
 #include <cstdint>
 #include <cstring>
 #include <vector>
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 009eed8a085a9a..733a2ba1ed7ccc 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -257,8 +257,7 @@ set(LLVM_BUILD_TOOLS ON)
 
 include_directories(BEFORE
   ${FLANG_BINARY_DIR}/include
-  ${FLANG_SOURCE_DIR}/include
-  ${FLANG_SOURCE_DIR}/../FortranRuntime/include)
+  ${FLANG_SOURCE_DIR}/include)
 
 # Add Flang-centric modules to cmake path.
 list(INSERT CMAKE_MODULE_PATH 0
diff --git a/FortranRuntime/include/flang/Common/Fortran-consts.h b/flang/include/flang/Common/Fortran-consts.h
similarity index 100%
rename from FortranRuntime/include/flang/Common/Fortran-consts.h
rename to flang/include/flang/Common/Fortran-consts.h
diff --git a/FortranRuntime/include/flang/Common/ISO_Fortran_binding_wrapper.h b/flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
similarity index 97%
rename from FortranRuntime/include/flang/Common/ISO_Fortran_binding_wrapper.h
rename to flang/include/flang/Common/ISO_Fortran_binding_wrapper.h
index 2c0fdc123c8759..ccfc360dfc820c 100644
--- a/FortranRuntime/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 "flang/Common/api-attrs.h"  
 #ifdef __cplusplus
 namespace Fortran {
 namespace ISO {
diff --git a/flang/include/flang/Common/README.md b/flang/include/flang/Common/README.md
new file mode 100644
index 00000000000000..a722732fb76407
--- /dev/null
+++ b/flang/include/flang/Common/README.md
@@ -0,0 +1,25 @@
+Files in this directory are used by Flang (the compiler) and FortranRuntime
+(the runtime library for Flang-compiled programs). They must be compatible by
+both. For definitions used only by Flang, consider
+`flang/{lib,include/flang}/Support` instead. For definitions used only by
+FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.
+
+The requirements for common code include:
+
+ * No dependence to LLVM, including LLVMSupport.
+
+ * No link-dependence to the C++ runtime. This means that e.g. `std::string`
+   cannot be used.
+
+ * No use of `std::optional<T>`; `fortran::common::optional<T>` can be used
+   instead.
+
+ * Preprocessor macros from `config.h` and CMake
+   `(target/add)_compile_definitions` must be defined by both build scripts.
+   See `flang/cmake/modules/FlangCommon.cmake`.
+
+ * Some header files are included from `.c` files.
+   `#include <flang/Common/c-or-cpp.h>` can help to support C++ and C.
+
+ * Global declarations may need to be annotated using definitions from
+   `api-attrs.h`.
diff --git a/FortranRuntime/include/flang/Common/api-attrs.h b/flang/include/flang/Common/api-attrs.h
similarity index 97%
rename from FortranRuntime/include/flang/Common/api-attrs.h
rename to flang/include/flang/Common/api-attrs.h
index 9a3001fb255c11..d73e60996bc81f 100644
--- a/FortranRuntime/include/flang/Common/api-attrs.h
+++ b/flang/include/flang/Common/api-attrs.h
@@ -1,10 +1,11 @@
-/*===-- include/flang/Common/api-attrs.h ----------------------------*- C -*-===
+/*===-- include/flang/Common/api-attrs.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
  *
- *===----------------------------------------------------------------------===*/
+ *===------------------------------------------------------------------------===
+ */
 
 /*
  * The file defines a set macros that can be used to apply
@@ -12,8 +13,8 @@
  * declared/defined/used in Flang runtime library.
  */
 
-#ifndef FORTRAN_COMMON_API_ATTRS_H_
-#define FORTRAN_COMMON_API_ATTRS_H_
+#ifndef FORTRAN_RUNTIME_API_ATTRS_H_
+#define FORTRAN_RUNTIME_API_ATTRS_H_
 
 /*
  * RT_EXT_API_GROUP_BEGIN/END pair is placed around definitions
@@ -177,4 +178,4 @@
 #define RT_DEVICE_NOINLINE_HOST_INLINE inline
 #endif
 
-#endif /* FORTRAN_COMMON_API_ATTRS_H_ */
+#endif /* !FORTRAN_RUNTIME_API_ATTRS_H_ */
diff --git a/FortranRuntime/include/flang/Common/binary-floating-point.h b/flang/include/flang/Common/binary-floating-point.h
similarity index 100%
rename from FortranRuntime/include/flang/Common/binary-floating-point.h
rename to flang/include/flang/Common/binary-floating-point.h
diff --git a/FortranRuntime/include/flang/Common/bit-population-count.h b/flang/include/flang/Common/bit-population-count.h
similarity index 98%
rename from FortranRuntime/include/flang/Common/bit-population-count.h
rename to flang/include/flang/Common/bit-population-count.h
index 59ade914d14d85..e1aeb78f9a3765 100644
--- a/FortranRuntime/include/flang/Common/bit-population-count.h
+++ b/flang/include/flang/Common/bit-population-count.h
@@ -93,4 +93,4 @@ template <typename INT> inline constexpr int TrailingZeroBitCount(INT x) {
   }
 }
 } // namespace Fortran::common
-#endif /* FORTRAN_COMMON_BIT_POPULATION_COUNT_H_ */
+#endif // FORTRAN_COMMON_BIT_POPULATION_COUNT_H_
diff --git a/FortranRuntime/include/flang/Common/constexpr-bitset.h b/flang/include/flang/Common/constexpr-bitset.h
similarity index 98%
rename from FortranRuntime/include/flang/Common/constexpr-bitset.h
rename to flang/include/flang/Common/constexpr-bitset.h
index 093b247b5f4eff..1aafb6eff84c61 100644
--- a/FortranRuntime/include/flang/Common/constexpr-bitset.h
+++ b/flang/include/flang/Common/constexpr-bitset.h
@@ -144,4 +144,4 @@ template <int BITS> class BitSet {
   Word bits_{0};
 };
 } // namespace Fortran::common
-#endif /* FORTRAN_COMMON_CONSTEXPR_BITSET_H_ */
+#endif // FORTRAN_COMMON_CONSTEXPR_BITSET_H_
diff --git a/FortranRuntime/include/flang/Common/decimal.h b/flang/include/flang/Common/decimal.h
similarity index 100%
rename from FortranRuntime/include/flang/Common/decimal.h
rename to flang/include/flang/Common/decimal.h
diff --git a/FortranRuntime/include/flang/Common/enum-class.h b/flang/include/flang/Common/enum-class.h
similarity index 98%
rename from FortranRuntime/include/flang/Common/enum-class.h
rename to flang/include/flang/Common/enum-class.h
index 787648ffec48e8..41575d45091a8d 100644
--- a/FortranRuntime/include/flang/Common/enum-class.h
+++ b/flang/include/flang/Common/enum-class.h
@@ -69,4 +69,4 @@ constexpr std::array<std::string_view, ITEMS> EnumNames(const char *p) {
   }
 
 } // namespace Fortran::common
-#endif /* FORTRAN_COMMON_ENUM_CLASS_H_ */
+#endif // FORTRAN_COMMON_ENUM_CLASS_H_
diff --git a/FortranRuntime/include/flang/Common/enum-set.h b/flang/include/flang/Common/enum-set.h
similarity index 99%
rename from FortranRuntime/include/flang/Common/enum-set.h
rename to flang/include/flang/Common/enum-set.h
index 6100fc5e2e31c5..5290b76debee88 100644
--- a/FortranRuntime/include/flang/Common/enum-set.h
+++ b/flang/include/flang/Common/enum-set.h
@@ -228,4 +228,4 @@ struct std::hash<Fortran::common::EnumSet<ENUM, values>> {
     return std::hash(x.bitset());
   }
 };
-#endif /* FORTRAN_COMMON_ENUM_SET_H_ */
+#endif // FORTRAN_COMMON_ENUM_SET_H_
diff --git a/FortranRuntime/include/flang/Common/fast-int-set.h b/flang/include/flang/Common/fast-int-set.h
similarity index 97%
rename from FortranRuntime/include/flang/Common/fast-int-set.h
rename to flang/include/flang/Common/fast-int-set.h
index 323ee4dc7e94d9..d1c9c756a44a65 100644
--- a/FortranRuntime/include/flang/Common/fast-int-set.h
+++ b/flang/include/flang/Common/fast-int-set.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Common/fast-int-set.h ---------------------*- C++ -*-===//
+//===-- include/flang/Common/fast-int-set.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.
@@ -103,4 +103,4 @@ template <int N> class FastIntSet {
   bool isFullyInitialized_{false}; // memory was cleared
 };
 } // namespace Fortran::common
-#endif /* FORTRAN_COMMON_FAST_INT_SET_H_ */
+#endif // FORTRAN_COMMON_FAST_INT_SET_H_
diff --git a/FortranRuntime/include/flang/Common/float128.h b/flang/include/flang/Common/float128.h
similarity index 96%
rename from FortranRuntime/include/flang/Common/float128.h
rename to flang/include/flang/Common/float128.h
index a7036bf679e5ae..2e76bc0a162e61 100644
--- a/FortranRuntime/include/flang/Common/float128.h
+++ b/flang/include/flang/Common/float128.h
@@ -1,4 +1,4 @@
-/*===-- include/flang/Common/float128.h -----------------------------*- C -*-===
+/*===-- flang/Common/float128.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/FortranRuntime/include/flang/Common/format.h b/flang/include/flang/Common/format.h
similarity index 99%
rename from FortranRuntime/include/flang/Common/format.h
rename to flang/include/flang/Common/format.h
index 6f4dfc8d2376b7..138e84b72b733d 100644
--- a/FortranRuntime/include/flang/Common/format.h
+++ b/flang/include/flang/Common/format.h
@@ -901,4 +901,4 @@ template <typename CHAR> bool FormatValidator<CHAR>::Check() {
 }
 
 } // namespace Fortran::common
-#endif /* FORTRAN_COMMON_FORMAT_H_ */
+#endif // FORTRAN_COMMON_FORMAT_H_
diff --git a/FortranRuntime/include/flang/Common/idioms.h b/flang/include/flang/Common/idioms.h
similarity index 99%
rename from FortranRuntime/include/flang/Common/idioms.h
rename to flang/include/flang/Common/idioms.h
index 1ae0c0b35112e9..99f383ec75b999 100644
--- a/FortranRuntime/include/flang/Common/idioms.h
+++ b/flang/include/flang/Common/idioms.h
@@ -150,4 +150,4 @@ template <typename A, typename... B>
 using IfNoLvalue = std::enable_if_t<(... && !std::is_lvalue_reference_v<B>), A>;
 template <typename... RVREF> using NoLvalue = IfNoLvalue<void, RVREF...>;
 } // namespace Fortran::common
-#endif /* FORTRAN_COMMON_IDIOMS_H_ */
+#endif // FORTRAN_COMMON_IDIOMS_H_
diff --git a/FortranRuntime/include/flang/Common/leading-zero-bit-count.h b/flang/include/flang/Common/leading-zero-bit-count.h
similarity index 98%
rename from FortranRuntime/include/flang/Common/leading-zero-bit-count.h
rename to flang/include/flang/Common/leading-zero-bit-count.h
index e788bfa9bcfd08..a296e0b446917f 100644
--- a/FortranRuntime/include/flang/Common/leading-zero-bit-count.h
+++ b/flang/include/flang/Common/leading-zero-bit-count.h
@@ -93,4 +93,4 @@ template <typename A> inline constexpr int BitsNeededFor(A x) {
   return 8 * sizeof x - LeadingZeroBitCount(x);
 }
 } // namespace Fortran::common
-#endif /* FORTRAN_COMMON_LEADING_ZERO_BIT_COUNT_H_ */
+#endif // FORTRAN_COMMON_LEADING_ZERO_BIT_COUNT_H_
diff --git a/FortranRuntime/include/flang/Common/optional.h b/flang/include/flang/Common/optional.h
similarity index 98%
rename from FortranRuntime/include/flang/Common/optional.h
rename to flang/include/flang/Common/optional.h
index c3db3b1329a2fd..c0f4278009f40a 100644
--- a/FortranRuntime/include/flang/Common/optional.h
+++ b/flang/include/flang/Common/optional.h
@@ -23,8 +23,8 @@
 //   * cuda:: namespace need to be forced for all std:: references.
 //
 //===----------------------------------------------------------------------===//
-#ifndef FORTRAN_COMMON_OPTIONAL_H_
-#define FORTRAN_COMMON_OPTIONAL_H_
+#ifndef FORTRAN_COMMON_OPTIONAL_H
+#define FORTRAN_COMMON_OPTIONAL_H
 
 #include "flang/Common/api-attrs.h"
 #include <optional>
@@ -240,4 +240,4 @@ using std::optional;
 
 } // namespace Fortran::common
 
-#endif /* FORTRAN_COMMON_OPTIONAL_H_ */
+#endif // FORTRAN_COMMON_OPTIONAL_H
diff --git a/FortranRuntime/include/flang/Common/real.h b/flang/include/flang/Common/real.h
similarity index 99%
rename from FortranRuntime/include/flang/Common/real.h
rename to flang/include/flang/Common/real.h
index dc9a2404731e70..b527deda0e3b4f 100644
--- a/FortranRuntime/include/flang/Common/real.h
+++ b/flang/include/flang/Common/real.h
@@ -141,4 +141,4 @@ class RealCharacteristics {
 };
 
 } // namespace Fortran::common
-#endif /* FORTRAN_COMMON_REAL_H_ */
+#endif // FORTRAN_COMMON_REAL_H_
diff --git a/FortranRuntime/include/flang/Common/reference-wrapper.h b/flang/include/flang/Common/reference-wrapper.h
similarity index 96%
rename from FortranRuntime/include/flang/Common/reference-wrapper.h
rename to flang/include/flang/Common/reference-wrapper.h
index 6822fb335f398c..2983754108f95a 100644
--- a/FortranRuntime/include/flang/Common/reference-wrapper.h
+++ b/flang/include/flang/Common/reference-wrapper.h
@@ -22,8 +22,8 @@
 //
 // clang-format on
 
-#ifndef FORTRAN_COMMON_REFERENCE_WRAPPER_H_
-#define FORTRAN_COMMON_REFERENCE_WRAPPER_H_
+#ifndef FORTRAN_COMMON_REFERENCE_WRAPPER_H
+#define FORTRAN_COMMON_REFERENCE_WRAPPER_H
 
 #include "flang/Common/api-attrs.h"
 #include <functional>
@@ -111,4 +111,4 @@ using std::reference_wrapper;
 
 } // namespace Fortran::common
 
-#endif /* FORTRAN_COMMON_REFERENCE_WRAPPER_H_ */
+#endif // FORTRAN_COMMON_REFERENCE_WRAPPER_H
diff --git a/FortranRuntime/include/flang/Common/restorer.h b/flang/include/flang/Common/restorer.h
similarity index 97%
rename from FortranRuntime/include/flang/Common/restorer.h
rename to flang/include/flang/Common/restorer.h
index a5c5ebe7344a1b..0f1bc48620d37e 100644
--- a/FortranRuntime/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 "flang/Common/api-attrs.h"
 #include "idioms.h"
+#include "flang/Common/api-attrs.h"
 namespace Fortran::common {
 template <typename A> class Restorer {
 public:
@@ -53,4 +53,4 @@ RT_API_ATTRS common::IfNoLvalue<Restorer<A>, B> ScopedSet(
   return Restorer<A>{to, std::move(original)};
 }
 } // namespace Fortran::common
-#endif /* FORTRAN_COMMON_RESTORER_H_ */
+#endif // FORTRAN_COMMON_RESTORER_H_
diff --git a/FortranRuntime/include/flang/Common/target-rounding.h b/flang/include/flang/Common/target-rounding.h
similarity index 100%
rename from FortranRuntime/include/flang/Common/target-rounding.h
rename to flang/include/flang/Common/target-rounding.h
diff --git a/FortranRuntime/include/flang/Common/uint128.h b/flang/include/flang/Common/uint128.h
similarity index 99%
rename from FortranRuntime/include/flang/Common/uint128.h
rename to flang/include/flang/Common/uint128.h
index 1b2ee6a2c14b87..821c8c3b08a52f 100644
--- a/FortranRuntime/include/flang/Common/uint128.h
+++ b/flang/include/flang/Common/uint128.h
@@ -19,8 +19,8 @@
 #define AVOID_NATIVE_UINT128_T 0
 #endif
 
-#include "flang/Common/api-attrs.h"
 #include "leading-zero-bit-count.h"
+#include "flang/Common/api-attrs.h"
 #include <cstdint>
 #include <type_traits>
 
@@ -303,4 +303,4 @@ template <int BITS>
 using HostSignedIntType = typename HostSignedIntTypeHelper<BITS>::type;
 
 } // namespace Fortran::common
-#endif /* FORTRAN_COMMON_UINT128_H_ */
+#endif
diff --git a/FortranRuntime/include/flang/Common/variant.h b/flang/include/flang/Common/variant.h
similarity index 89%
rename from FortranRuntime/include/flang/Common/variant.h
rename to flang/include/flang/Common/variant.h
index ff9b1aed4eba91..1af85876afac00 100644
--- a/FortranRuntime/include/flang/Common/variant.h
+++ b/flang/include/flang/Common/variant.h
@@ -11,8 +11,8 @@
 // and the related names become available, though, they may correspond
 // to alternative definitions (e.g. from cuda::std namespace).
 
-#ifndef FORTRAN_COMMON_VARIANT_H_
-#define FORTRAN_COMMON_VARIANT_H_
+#ifndef FORTRAN_COMMON_VARIANT_H
+#define FORTRAN_COMMON_VARIANT_H
 
 #if RT_USE_LIBCUDACXX
 #include <cuda/std/variant>
@@ -27,4 +27,4 @@ using cuda::std::visit;
 #include <variant>
 #endif // !RT_USE_LIBCUDACXX
 
-#endif /* FORTRAN_COMMON_VARIANT_H_ */
+#endif // FORTRAN_COMMON_VARIANT_H
diff --git a/FortranRuntime/include/flang/Common/visit.h b/flang/include/flang/Common/visit.h
similarity index 98%
rename from FortranRuntime/include/flang/Common/visit.h
rename to flang/include/flang/Common/visit.h
index 8030ac9be173c3..ad66297650b093 100644
--- a/FortranRuntime/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 "flang/Common/api-attrs.h"
 #include "variant.h"
+#include "flang/Common/api-attrs.h"
 #include <type_traits>
 
 namespace Fortran::common {
@@ -100,4 +100,4 @@ using Fortran::common::log2visit::visit;
 #endif
 
 } // namespace Fortran::common
-#endif /* FORTRAN_COMMON_VISIT_H_ */
+#endif // FORTRAN_COMMON_VISIT_H_
diff --git a/FortranRuntime/include/flang/Common/windows-include.h b/flang/include/flang/Common/windows-include.h
similarity index 93%
rename from FortranRuntime/include/flang/Common/windows-include.h
rename to flang/include/flang/Common/windows-include.h
index bee79d4fceb3ba..75ef4974251ff9 100644
--- a/FortranRuntime/include/flang/Common/windows-include.h
+++ b/flang/include/flang/Common/windows-include.h
@@ -22,4 +22,4 @@
 
 #endif // _WIN32
 
-#endif /* FORTRAN_COMMON_WINDOWS_INCLUDE_H_ */
+#endif // FORTRAN_COMMON_WINDOWS_INCLUDE_H_
diff --git a/flang/include/flang/ISO_Fortran_binding.h b/flang/include/flang/ISO_Fortran_binding.h
index 516355c01ec7d0..89a10ce69a2ba2 100644
--- a/flang/include/flang/ISO_Fortran_binding.h
+++ b/flang/include/flang/ISO_Fortran_binding.h
@@ -1,19 +1,20 @@
-/*===-- include/flang/Common/ISO_Fortran_binding.h ------------------*- C -*-===
+/*===-- include/flang/ISO_Fortran_binding.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_COMMON_ISO_FORTRAN_BINDING_H_
-#define FORTRAN_COMMON_ISO_FORTRAN_BINDING_H_
+#ifndef CFI_ISO_FORTRAN_BINDING_H_
+#define CFI_ISO_FORTRAN_BINDING_H_
 
 /* When this header is included into the compiler and runtime implementations,
  * it does so by means of a wrapper header that establishes namespaces and
  * a macro for extra function attributes (RT_API_ATTRS).
  */
-#ifndef FORTRAN_COMMON_ISO_FORTRAN_BINDING_WRAPPER_H_
+#ifndef FORTRAN_ISO_FORTRAN_BINDING_WRAPPER_H_
 #include <stddef.h>
 #define FORTRAN_ISO_NAMESPACE_
 #endif
@@ -206,4 +207,4 @@ RT_API_ATTRS int CFI_setpointer(
 } // extern "C"
 #endif
 
-#endif /* FORTRAN_COMMON_ISO_FORTRAN_BINDING_H_ */
+#endif /* CFI_ISO_FORTRAN_BINDING_H_ */
diff --git a/flang/include/flang/Lower/Allocatable.h b/flang/include/flang/Lower/Allocatable.h
index 1209b157ed1f41..0e89af94af40f6 100644
--- a/flang/include/flang/Lower/Allocatable.h
+++ b/flang/include/flang/Lower/Allocatable.h
@@ -15,7 +15,7 @@
 
 #include "flang/Lower/AbstractConverter.h"
 #include "flang/Optimizer/Builder/MutableBox.h"
-#include "flang/Runtime/allocator-registry.h"
+#include "flang/Runtime/allocator-registry-consts.h"
 #include "llvm/ADT/StringRef.h"
 
 namespace mlir {
diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index 3fc4201bd16c6c..78bb82b17d4050 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -397,7 +397,6 @@ struct IntrinsicLibrary {
   fir::ExtendedValue genUbound(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
   fir::ExtendedValue genUnpack(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
   fir::ExtendedValue genVerify(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
-    fir::ExtendedValue genNumericStorageSize(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
 
   /// Implement all conversion functions like DBLE, the first argument is
   /// the value to convert. There may be an additional KIND arguments that
diff --git a/flang/include/flang/Optimizer/Builder/MutableBox.h b/flang/include/flang/Optimizer/Builder/MutableBox.h
index fea7c7204837b4..39657ddaf6e03a 100644
--- a/flang/include/flang/Optimizer/Builder/MutableBox.h
+++ b/flang/include/flang/Optimizer/Builder/MutableBox.h
@@ -14,7 +14,7 @@
 #define FORTRAN_OPTIMIZER_BUILDER_MUTABLEBOX_H
 
 #include "flang/Optimizer/Builder/BoxValue.h"
-#include "flang/Runtime/allocator-registry.h"
+#include "flang/Runtime/allocator-registry-consts.h"
 #include "llvm/ADT/StringRef.h"
 
 namespace mlir {
diff --git a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
index 31d1416846d0c9..b9a8a670d07938 100644
--- a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
+++ b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h
@@ -23,7 +23,7 @@
 #define OPTIMIZER_DESCRIPTOR_MODEL_H
 
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
 #include "mlir/IR/BuiltinTypes.h"
 #include "llvm/Support/ErrorHandling.h"
diff --git a/FortranRuntime/include/flang/Runtime/CUDA/allocator.h b/flang/include/flang/Runtime/CUDA/allocator.h
similarity index 93%
rename from FortranRuntime/include/flang/Runtime/CUDA/allocator.h
rename to flang/include/flang/Runtime/CUDA/allocator.h
index 48185e8f34eaf6..cc88896b1f0bd6 100644
--- a/FortranRuntime/include/flang/Runtime/CUDA/allocator.h
+++ b/flang/include/flang/Runtime/CUDA/allocator.h
@@ -9,7 +9,7 @@
 #ifndef FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
 #define FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
 
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
 
 #define CUDA_REPORT_IF_ERROR(expr) \
@@ -43,4 +43,4 @@ void *CUFAllocUnified(std::size_t);
 void CUFFreeUnified(void *);
 
 } // namespace Fortran::runtime::cuda
-#endif /* FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_ */
+#endif // FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
diff --git a/FortranRuntime/include/flang/Runtime/CUDA/descriptor.h b/flang/include/flang/Runtime/CUDA/descriptor.h
similarity index 91%
rename from FortranRuntime/include/flang/Runtime/CUDA/descriptor.h
rename to flang/include/flang/Runtime/CUDA/descriptor.h
index 68ad0987d9aecd..501a834f43bd42 100644
--- a/FortranRuntime/include/flang/Runtime/CUDA/descriptor.h
+++ b/flang/include/flang/Runtime/CUDA/descriptor.h
@@ -9,7 +9,7 @@
 #ifndef FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_
 #define FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_
 
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
 #include <cstddef>
 
@@ -27,4 +27,4 @@ void RTDECL(CUFFreeDesciptor)(
 
 } // extern "C"
 } // namespace Fortran::runtime::cuda
-#endif /* FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_ */
+#endif // FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_
diff --git a/flang/include/flang/Runtime/README.md b/flang/include/flang/Runtime/README.md
new file mode 100644
index 00000000000000..a722732fb76407
--- /dev/null
+++ b/flang/include/flang/Runtime/README.md
@@ -0,0 +1,25 @@
+Files in this directory are used by Flang (the compiler) and FortranRuntime
+(the runtime library for Flang-compiled programs). They must be compatible by
+both. For definitions used only by Flang, consider
+`flang/{lib,include/flang}/Support` instead. For definitions used only by
+FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.
+
+The requirements for common code include:
+
+ * No dependence to LLVM, including LLVMSupport.
+
+ * No link-dependence to the C++ runtime. This means that e.g. `std::string`
+   cannot be used.
+
+ * No use of `std::optional<T>`; `fortran::common::optional<T>` can be used
+   instead.
+
+ * Preprocessor macros from `config.h` and CMake
+   `(target/add)_compile_definitions` must be defined by both build scripts.
+   See `flang/cmake/modules/FlangCommon.cmake`.
+
+ * Some header files are included from `.c` files.
+   `#include <flang/Common/c-or-cpp.h>` can help to support C++ and C.
+
+ * Global declarations may need to be annotated using definitions from
+   `api-attrs.h`.
diff --git a/FortranRuntime/include/flang/Runtime/allocatable.h b/flang/include/flang/Runtime/allocatable.h
similarity index 97%
rename from FortranRuntime/include/flang/Runtime/allocatable.h
rename to flang/include/flang/Runtime/allocatable.h
index d7f3910074a760..480e987ed5ec6b 100644
--- a/FortranRuntime/include/flang/Runtime/allocatable.h
+++ b/flang/include/flang/Runtime/allocatable.h
@@ -11,10 +11,13 @@
 #ifndef FORTRAN_RUNTIME_ALLOCATABLE_H_
 #define FORTRAN_RUNTIME_ALLOCATABLE_H_
 
-#include "flang/Runtime/descriptor.h"
+#include "flang/Common/Fortran-consts.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
 
 namespace Fortran::runtime {
+using SubscriptValue = ISO::CFI_index_t;
+using common::TypeCategory;
 
 extern "C" {
 
@@ -129,4 +132,4 @@ void RTDECL(AllocatableDeallocateNoFinal)(
     Descriptor &, const char *sourceFile = nullptr, int sourceLine = 0);
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_ALLOCATABLE_H_ */
+#endif // FORTRAN_RUNTIME_ALLOCATABLE_H_
diff --git a/flang/include/flang/Runtime/allocator-registry-consts.h b/flang/include/flang/Runtime/allocator-registry-consts.h
new file mode 100644
index 00000000000000..70735c2fc7a71c
--- /dev/null
+++ b/flang/include/flang/Runtime/allocator-registry-consts.h
@@ -0,0 +1,20 @@
+//===-- include/flang/Runtime/allocator-registry-consts.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_ALLOCATOR_REGISTRY_CONSTS_H_
+#define FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_CONSTS_H_
+
+static constexpr unsigned kDefaultAllocator = 0;
+
+// Allocator used for CUF
+static constexpr unsigned kPinnedAllocatorPos = 1;
+static constexpr unsigned kDeviceAllocatorPos = 2;
+static constexpr unsigned kManagedAllocatorPos = 3;
+static constexpr unsigned kUnifiedAllocatorPos = 4;
+
+#endif /* FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_CONSTS_H_ */
diff --git a/flang/include/flang/Runtime/array-constructor-consts.h b/flang/include/flang/Runtime/array-constructor-consts.h
new file mode 100644
index 00000000000000..da058874e50487
--- /dev/null
+++ b/flang/include/flang/Runtime/array-constructor-consts.h
@@ -0,0 +1,54 @@
+//===-- include/flang/Runtime/array-constructor-consts.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
+//
+//===----------------------------------------------------------------------===//
+
+// External APIs to create temporary storage for array constructors when their
+// final extents or length parameters cannot be pre-computed.
+
+#ifndef FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_
+#define FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_
+
+#include "flang/Runtime/descriptor-consts.h"
+#include "flang/Runtime/entry-names.h"
+#include <cstdint>
+
+namespace Fortran::runtime {
+struct ArrayConstructorVector;
+
+// Max sizeof(ArrayConstructorVector) and sizeof(ArrayConstructorVector) for any
+// target.
+// TODO: Use target-specific size/alignment instead of overapproximation.
+constexpr std::size_t MaxArrayConstructorVectorSizeInBytes = 2 * 40;
+constexpr std::size_t MaxArrayConstructorVectorAlignInBytes = 8;
+
+extern "C" {
+// API to initialize an ArrayConstructorVector before any values are pushed to
+// it. Inlined code is only expected to allocate the "ArrayConstructorVector"
+// class instance storage with sufficient size (using
+// "2*sizeof(ArrayConstructorVector)" on the host should be safe regardless of
+// the target the runtime is compiled for). This avoids the need for the runtime
+// to maintain a state, or to use dynamic allocation for it. "vectorClassSize"
+// is used to validate that lowering allocated enough space for it.
+void RTDECL(InitArrayConstructorVector)(ArrayConstructorVector &vector,
+    Descriptor &to, bool useValueLengthParameters, int vectorClassSize,
+    const char *sourceFile = nullptr, int sourceLine = 0);
+
+// Generic API to push any kind of entity into the array constructor (any
+// Fortran type and any rank).
+void RTDECL(PushArrayConstructorValue)(
+    ArrayConstructorVector &vector, const Descriptor &from);
+
+// API to push scalar array constructor value of:
+//   - a numerical or logical type,
+//   - or a derived type that has no length parameters, and no allocatable
+//   component (that would require deep copies).
+// It requires no descriptor for the value that is passed via its base address.
+void RTDECL(PushArrayConstructorSimpleScalar)(
+    ArrayConstructorVector &vector, void *from);
+} // extern "C"
+} // namespace Fortran::runtime
+#endif /* FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_ */
diff --git a/FortranRuntime/include/flang/Runtime/assign.h b/flang/include/flang/Runtime/assign.h
similarity index 98%
rename from FortranRuntime/include/flang/Runtime/assign.h
rename to flang/include/flang/Runtime/assign.h
index 55d15a5c046868..a1cc9eaf4355f6 100644
--- a/FortranRuntime/include/flang/Runtime/assign.h
+++ b/flang/include/flang/Runtime/assign.h
@@ -58,4 +58,4 @@ void RTDECL(AssignPolymorphic)(Descriptor &to, const Descriptor &from,
     const char *sourceFile = nullptr, int sourceLine = 0);
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_ASSIGN_H_ */
+#endif // FORTRAN_RUNTIME_ASSIGN_H_
diff --git a/FortranRuntime/include/flang/Runtime/c-or-cpp.h b/flang/include/flang/Runtime/c-or-cpp.h
similarity index 95%
rename from FortranRuntime/include/flang/Runtime/c-or-cpp.h
rename to flang/include/flang/Runtime/c-or-cpp.h
index 3c0c0be643cbc3..8bac523907750c 100644
--- a/FortranRuntime/include/flang/Runtime/c-or-cpp.h
+++ b/flang/include/flang/Runtime/c-or-cpp.h
@@ -28,4 +28,4 @@
 #define NORETURN IF_CPLUSPLUS([[noreturn]])
 #define NO_ARGUMENTS IF_NOT_CPLUSPLUS(void)
 
-#endif /* FORTRAN_RUNTIME_C_OR_CPP_H_ */
+#endif // FORTRAN_RUNTIME_C_OR_CPP_H_
diff --git a/FortranRuntime/include/flang/Runtime/character.h b/flang/include/flang/Runtime/character.h
similarity index 99%
rename from FortranRuntime/include/flang/Runtime/character.h
rename to flang/include/flang/Runtime/character.h
index a842c30cd8120c..dd47686fe858fd 100644
--- a/FortranRuntime/include/flang/Runtime/character.h
+++ b/flang/include/flang/Runtime/character.h
@@ -129,4 +129,4 @@ void RTDECL(Verify)(Descriptor &result, const Descriptor &string,
     const char *sourceFile = nullptr, int sourceLine = 0);
 }
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_CHARACTER_H_ */
+#endif // FORTRAN_RUNTIME_CHARACTER_H_
diff --git a/FortranRuntime/include/flang/Runtime/command.h b/flang/include/flang/Runtime/command.h
similarity index 98%
rename from FortranRuntime/include/flang/Runtime/command.h
rename to flang/include/flang/Runtime/command.h
index 2bbdfca7631163..7ab3f6442dcf92 100644
--- a/FortranRuntime/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -62,4 +62,4 @@ std::int32_t RTNAME(GetCwd)(
 }
 } // namespace Fortran::runtime
 
-#endif /* FORTRAN_RUNTIME_COMMAND_H_ */
+#endif // FORTRAN_RUNTIME_COMMAND_H_
diff --git a/FortranRuntime/include/flang/Runtime/cpp-type.h b/flang/include/flang/Runtime/cpp-type.h
similarity index 98%
rename from FortranRuntime/include/flang/Runtime/cpp-type.h
rename to flang/include/flang/Runtime/cpp-type.h
index 7de1ea4f45f224..27b43de7d0f0f6 100644
--- a/FortranRuntime/include/flang/Runtime/cpp-type.h
+++ b/flang/include/flang/Runtime/cpp-type.h
@@ -110,4 +110,4 @@ template <> struct CppTypeForHelper<TypeCategory::Logical, 1> {
 };
 
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_CPP_TYPE_H_ */
+#endif // FORTRAN_RUNTIME_CPP_TYPE_H_
diff --git a/FortranRuntime/include/flang/Runtime/derived-api.h b/flang/include/flang/Runtime/derived-api.h
similarity index 98%
rename from FortranRuntime/include/flang/Runtime/derived-api.h
rename to flang/include/flang/Runtime/derived-api.h
index ca1681e974051c..79aa7d82de8819 100644
--- a/FortranRuntime/include/flang/Runtime/derived-api.h
+++ b/flang/include/flang/Runtime/derived-api.h
@@ -63,4 +63,4 @@ bool RTDECL(ExtendsTypeOf)(const Descriptor &, const Descriptor &);
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_DERIVED_API_H_ */
+#endif // FORTRAN_RUNTIME_DERIVED_API_H_
diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h
new file mode 100644
index 00000000000000..2d746c6337b518
--- /dev/null
+++ b/flang/include/flang/Runtime/descriptor-consts.h
@@ -0,0 +1,72 @@
+//===-- include/flang/Runtime/descriptor-consts.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_DESCRIPTOR_CONSTS_H_
+#define FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_
+
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
+#include "flang/Common/api-attrs.h"
+#include <cstddef>
+#include <cstdint>
+
+// Value of the addendum presence flag.
+#define _CFI_ADDENDUM_FLAG 1
+// Number of bits needed to be shifted when manipulating the allocator index.
+#define _CFI_ALLOCATOR_IDX_SHIFT 1
+// Allocator index mask.
+#define _CFI_ALLOCATOR_IDX_MASK 0b00001110
+
+namespace Fortran::runtime::typeInfo {
+using TypeParameterValue = std::int64_t;
+class DerivedType;
+} // namespace Fortran::runtime::typeInfo
+
+namespace Fortran::runtime {
+class Descriptor;
+
+/// Returns size in bytes of the descriptor (not the data)
+/// This must be at least as large as the largest descriptor of any target
+/// triple.
+static constexpr RT_API_ATTRS std::size_t MaxDescriptorSizeInBytes(
+    int rank, bool addendum = false, int lengthTypeParameters = 0) {
+  // Layout:
+  //
+  // fortran::runtime::Descriptor {
+  //   ISO::CFI_cdesc_t {
+  //     void *base_addr;           (pointer -> up to 8 bytes)
+  //     size_t elem_len;           (up to 8 bytes)
+  //     int version;               (up to 4 bytes)
+  //     CFI_rank_t rank;           (unsigned char -> 1 byte)
+  //     CFI_type_t type;           (signed char -> 1 byte)
+  //     CFI_attribute_t attribute; (unsigned char -> 1 byte)
+  //     unsigned char extra;       (1 byte)
+  //   }
+  // }
+  // fortran::runtime::Dimension[rank] {
+  //   ISO::CFI_dim_t {
+  //     CFI_index_t lower_bound; (ptrdiff_t -> up to 8 bytes)
+  //     CFI_index_t extent;      (ptrdiff_t -> up to 8 bytes)
+  //     CFI_index_t sm;          (ptrdiff_t -> up to 8 bytes)
+  //   }
+  // }
+  // fortran::runtime::DescriptorAddendum {
+  //   const typeInfo::DerivedType *derivedType_;        (pointer -> up to 8
+  //   bytes) typeInfo::TypeParameterValue len_[lenParameters]; (int64_t -> 8
+  //   bytes)
+  // }
+  std::size_t bytes{24u + rank * 24u};
+  if (addendum || lengthTypeParameters > 0) {
+    if (lengthTypeParameters < 1)
+      lengthTypeParameters = 1;
+    bytes += 8u + static_cast<std::size_t>(lengthTypeParameters) * 8u;
+  }
+  return bytes;
+}
+
+} // namespace Fortran::runtime
+#endif /* FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_ */
diff --git a/FortranRuntime/include/flang/Runtime/entry-names.h b/flang/include/flang/Runtime/entry-names.h
similarity index 89%
rename from FortranRuntime/include/flang/Runtime/entry-names.h
rename to flang/include/flang/Runtime/entry-names.h
index 25134771bf9185..68582b92b54941 100644
--- a/FortranRuntime/include/flang/Runtime/entry-names.h
+++ b/flang/include/flang/Runtime/entry-names.h
@@ -1,10 +1,11 @@
-/*===-- include/flang/Runtime/entry-names.h -------------------------*- C -*-===
+/*===-- include/flang/Runtime/entry-names.h -------------------------*- C -*-=//
  *
  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  * See https://llvm.org/LICENSE.txt for license information.
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  *
- *===----------------------------------------------------------------------===*/
+ *===------------------------------------------------------------------------===
+ */
 
 /* Defines the macro RTNAME(n) which decorates the external name of a runtime
  * library function or object with extra characters so that it
@@ -15,8 +16,8 @@
  * The value of REVISION should not be changed until/unless the API to the
  * runtime library must change in some way that breaks backward compatibility.
  */
-#ifndef FORTRAN_RUNTIME_ENTRY_NAMES_H_
-#define FORTRAN_RUNTIME_ENTRY_NAMES_H_
+#ifndef FORTRAN_RUNTIME_ENTRY_NAMES_H
+#define FORTRAN_RUNTIME_ENTRY_NAMES_H
 
 #include "flang/Common/api-attrs.h"
 
@@ -40,4 +41,4 @@
 #define RTNAME_STRING(name) RTNAME_STRINGIFY(RTNAME(name))
 #endif
 
-#endif /* FORTRAN_RUNTIME_ENTRY_NAMES_H_ */
+#endif /* !FORTRAN_RUNTIME_ENTRY_NAMES_H */
diff --git a/FortranRuntime/include/flang/Runtime/exceptions.h b/flang/include/flang/Runtime/exceptions.h
similarity index 86%
rename from FortranRuntime/include/flang/Runtime/exceptions.h
rename to flang/include/flang/Runtime/exceptions.h
index f2c67325b34d92..1ab22da103a50f 100644
--- a/FortranRuntime/include/flang/Runtime/exceptions.h
+++ b/flang/include/flang/Runtime/exceptions.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/exceptions.h ----------------------*- C++ -*-===//
+//===-- include/flang/Runtime/exceptions.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.
@@ -26,4 +26,4 @@ std::uint32_t RTNAME(MapException)(std::uint32_t excepts);
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_EXCEPTIONS_H_ */
+#endif // FORTRAN_RUNTIME_EXCEPTIONS_H_
diff --git a/FortranRuntime/include/flang/Runtime/execute.h b/flang/include/flang/Runtime/execute.h
similarity index 89%
rename from FortranRuntime/include/flang/Runtime/execute.h
rename to flang/include/flang/Runtime/execute.h
index d1958a82594ffd..ca137b9d1823c4 100644
--- a/FortranRuntime/include/flang/Runtime/execute.h
+++ b/flang/include/flang/Runtime/execute.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/execute.h -------------------------*- C++ -*-===//
+//===-- include/flang/Runtime/command.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.
@@ -26,4 +26,4 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait = true,
 }
 } // namespace Fortran::runtime
 
-#endif /* FORTRAN_RUNTIME_EXECUTE_H_ */
+#endif // FORTRAN_RUNTIME_EXECUTE_H_
diff --git a/FortranRuntime/include/flang/Runtime/extensions.h b/flang/include/flang/Runtime/extensions.h
similarity index 97%
rename from FortranRuntime/include/flang/Runtime/extensions.h
rename to flang/include/flang/Runtime/extensions.h
index f46ccdd7d9528d..fef651f3b2eedb 100644
--- a/FortranRuntime/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -52,4 +52,4 @@ std::int64_t FORTRAN_PROCEDURE_NAME(access)(const char *name,
 #endif
 
 } // extern "C"
-#endif /* FORTRAN_RUNTIME_EXTENSIONS_H_ */
+#endif // FORTRAN_RUNTIME_EXTENSIONS_H_
diff --git a/FortranRuntime/include/flang/Runtime/freestanding-tools.h b/flang/include/flang/Runtime/freestanding-tools.h
similarity index 99%
rename from FortranRuntime/include/flang/Runtime/freestanding-tools.h
rename to flang/include/flang/Runtime/freestanding-tools.h
index 8aeef54ba0af3d..e94cb0a6c938cd 100644
--- a/FortranRuntime/include/flang/Runtime/freestanding-tools.h
+++ b/flang/include/flang/Runtime/freestanding-tools.h
@@ -215,4 +215,4 @@ using std::toupper;
 #endif // !STD_TOUPPER_UNSUPPORTED
 
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_FREESTANDING_TOOLS_H_ */
+#endif // FORTRAN_RUNTIME_FREESTANDING_TOOLS_H_
diff --git a/FortranRuntime/include/flang/Runtime/inquiry.h b/flang/include/flang/Runtime/inquiry.h
similarity index 91%
rename from FortranRuntime/include/flang/Runtime/inquiry.h
rename to flang/include/flang/Runtime/inquiry.h
index 83b07cf2f31a47..c7a7487f1a1b18 100644
--- a/FortranRuntime/include/flang/Runtime/inquiry.h
+++ b/flang/include/flang/Runtime/inquiry.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/inquiry.h -------------------------*- C++ -*-===//
+//===-- include/flang/Runtime/inquiry.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.
@@ -40,4 +40,4 @@ void RTDECL(Ubound)(void *result, const Descriptor &array, int kind,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_INQUIRY_H_ */
+#endif // FORTRAN_RUNTIME_INQUIRY_H_
diff --git a/FortranRuntime/include/flang/Runtime/io-api.h b/flang/include/flang/Runtime/io-api.h
similarity index 98%
rename from FortranRuntime/include/flang/Runtime/io-api.h
rename to flang/include/flang/Runtime/io-api.h
index be948061c241a0..e588b46dc4b3a1 100644
--- a/FortranRuntime/include/flang/Runtime/io-api.h
+++ b/flang/include/flang/Runtime/io-api.h
@@ -11,10 +11,10 @@
 #ifndef FORTRAN_RUNTIME_IO_API_H_
 #define FORTRAN_RUNTIME_IO_API_H_
 
-#include "flang/Common/magic-numbers.h"
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/entry-names.h"
 #include "flang/Runtime/iostat.h"
+#include "flang/Runtime/magic-numbers.h"
 #include <cinttypes>
 #include <cstddef>
 
@@ -51,9 +51,6 @@ constexpr InquiryKeywordHash HashInquiryKeyword(const char *p) {
   return hash;
 }
 
-RT_API_ATTRS const char *InquiryKeywordHashDecode(
-    char *buffer, std::size_t, InquiryKeywordHash);
-
 extern "C" {
 
 #define IONAME(name) RTNAME(io##name)
@@ -369,4 +366,4 @@ enum Iostat IODECL(EndIoStatement)(Cookie);
 
 } // extern "C"
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_RUNTIME_IO_API_H_ */
+#endif
diff --git a/FortranRuntime/include/flang/Runtime/iostat.h b/flang/include/flang/Runtime/iostat.h
similarity index 96%
rename from FortranRuntime/include/flang/Runtime/iostat.h
rename to flang/include/flang/Runtime/iostat.h
index 9a52990045ee13..0565718f6c103d 100644
--- a/FortranRuntime/include/flang/Runtime/iostat.h
+++ b/flang/include/flang/Runtime/iostat.h
@@ -12,7 +12,7 @@
 #ifndef FORTRAN_RUNTIME_IOSTAT_H_
 #define FORTRAN_RUNTIME_IOSTAT_H_
 #include "flang/Common/api-attrs.h"
-#include "flang/Common/magic-numbers.h"
+#include "flang/Runtime/magic-numbers.h"
 namespace Fortran::runtime::io {
 
 // The value of IOSTAT= is zero when no error, end-of-record,
@@ -89,7 +89,5 @@ enum Iostat {
   IostatNonExternalDefinedUnformattedIo,
 };
 
-RT_API_ATTRS const char *IostatErrorString(int);
-
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_RUNTIME_IOSTAT_H_ */
+#endif // FORTRAN_RUNTIME_IOSTAT_H_
diff --git a/FortranRuntime/include/flang/Common/magic-numbers.h b/flang/include/flang/Runtime/magic-numbers.h
similarity index 98%
rename from FortranRuntime/include/flang/Common/magic-numbers.h
rename to flang/include/flang/Runtime/magic-numbers.h
index 931df690766219..bab0e9ae05299a 100644
--- a/FortranRuntime/include/flang/Common/magic-numbers.h
+++ b/flang/include/flang/Runtime/magic-numbers.h
@@ -1,10 +1,10 @@
-#if 0 /*===-- include/flang/Runtime/magic-numbers.h ---------------*- C -*-===*/
- *
+#if 0 /*===-- include/flang/Runtime/magic-numbers.h -----------------------===*/
+/*
  * 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
  *
-/*===----------------------------------------------------------------------===*/
+ *===----------------------------------------------------------------------===*/
 #endif
 #if 0
 This header can be included into both Fortran and C.
diff --git a/FortranRuntime/include/flang/Runtime/main.h b/flang/include/flang/Runtime/main.h
similarity index 95%
rename from FortranRuntime/include/flang/Runtime/main.h
rename to flang/include/flang/Runtime/main.h
index 98fcf1250d0ad6..88232ea64fa6ab 100644
--- a/FortranRuntime/include/flang/Runtime/main.h
+++ b/flang/include/flang/Runtime/main.h
@@ -20,4 +20,4 @@ void RTNAME(ProgramStart)(
 void RTNAME(ByteswapOption)(void); // -byteswapio
 FORTRAN_EXTERN_C_END
 
-#endif /* FORTRAN_RUNTIME_MAIN_H_ */
+#endif // FORTRAN_RUNTIME_MAIN_H_
diff --git a/FortranRuntime/include/flang/Runtime/matmul-instances.inc b/flang/include/flang/Runtime/matmul-instances.inc
similarity index 100%
rename from FortranRuntime/include/flang/Runtime/matmul-instances.inc
rename to flang/include/flang/Runtime/matmul-instances.inc
diff --git a/FortranRuntime/include/flang/Runtime/matmul-transpose.h b/flang/include/flang/Runtime/matmul-transpose.h
similarity index 97%
rename from FortranRuntime/include/flang/Runtime/matmul-transpose.h
rename to flang/include/flang/Runtime/matmul-transpose.h
index 077277fae2da86..2d79ca10e08958 100644
--- a/FortranRuntime/include/flang/Runtime/matmul-transpose.h
+++ b/flang/include/flang/Runtime/matmul-transpose.h
@@ -46,4 +46,4 @@ void RTDECL(MatmulTransposeDirect)(const Descriptor &, const Descriptor &,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_MATMUL_TRANSPOSE_H_ */
+#endif // FORTRAN_RUNTIME_MATMUL_TRANSPOSE_H_
diff --git a/FortranRuntime/include/flang/Runtime/matmul.h b/flang/include/flang/Runtime/matmul.h
similarity index 97%
rename from FortranRuntime/include/flang/Runtime/matmul.h
rename to flang/include/flang/Runtime/matmul.h
index cd375ac43d77f2..a72d4a06ee4594 100644
--- a/FortranRuntime/include/flang/Runtime/matmul.h
+++ b/flang/include/flang/Runtime/matmul.h
@@ -45,4 +45,4 @@ void RTDECL(MatmulDirect)(const Descriptor &, const Descriptor &,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_MATMUL_H_ */
+#endif // FORTRAN_RUNTIME_MATMUL_H_
diff --git a/FortranRuntime/include/flang/Runtime/misc-intrinsic.h b/flang/include/flang/Runtime/misc-intrinsic.h
similarity index 95%
rename from FortranRuntime/include/flang/Runtime/misc-intrinsic.h
rename to flang/include/flang/Runtime/misc-intrinsic.h
index 1d4163c2e1e751..3fb3aaed49c0fb 100644
--- a/FortranRuntime/include/flang/Runtime/misc-intrinsic.h
+++ b/flang/include/flang/Runtime/misc-intrinsic.h
@@ -28,4 +28,4 @@ void RTDECL(TransferSize)(Descriptor &result, const Descriptor &source,
     std::int64_t size);
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_MISC_INTRINSIC_H_ */
+#endif // FORTRAN_RUNTIME_MISC_INTRINSIC_H_
diff --git a/FortranRuntime/include/flang/Runtime/numeric.h b/flang/include/flang/Runtime/numeric.h
similarity index 99%
rename from FortranRuntime/include/flang/Runtime/numeric.h
rename to flang/include/flang/Runtime/numeric.h
index 5fbab2e069b739..84a5a7cd7a361c 100644
--- a/FortranRuntime/include/flang/Runtime/numeric.h
+++ b/flang/include/flang/Runtime/numeric.h
@@ -455,4 +455,4 @@ CppTypeFor<TypeCategory::Real, 16> RTDECL(FPow16k)(
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_NUMERIC_H_ */
+#endif // FORTRAN_RUNTIME_NUMERIC_H_
diff --git a/FortranRuntime/include/flang/Runtime/pointer.h b/flang/include/flang/Runtime/pointer.h
similarity index 97%
rename from FortranRuntime/include/flang/Runtime/pointer.h
rename to flang/include/flang/Runtime/pointer.h
index b7322ad92bd583..c6d29db7218376 100644
--- a/FortranRuntime/include/flang/Runtime/pointer.h
+++ b/flang/include/flang/Runtime/pointer.h
@@ -12,10 +12,14 @@
 #ifndef FORTRAN_RUNTIME_POINTER_H_
 #define FORTRAN_RUNTIME_POINTER_H_
 
-#include "flang/Runtime/descriptor.h"
+#include "flang/Common/Fortran-consts.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
 
 namespace Fortran::runtime {
+using SubscriptValue = ISO::CFI_index_t;
+using common::TypeCategory;
+
 extern "C" {
 
 // Data pointer initialization for NULLIFY(), "p=>NULL()`, & for ALLOCATE().
diff --git a/FortranRuntime/include/flang/Runtime/ragged.h b/flang/include/flang/Runtime/ragged.h
similarity index 96%
rename from FortranRuntime/include/flang/Runtime/ragged.h
rename to flang/include/flang/Runtime/ragged.h
index 8574bc1fa110c8..f52a619c55b43e 100644
--- a/FortranRuntime/include/flang/Runtime/ragged.h
+++ b/flang/include/flang/Runtime/ragged.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/ragged.h --------------------------*- C++ -*-===//
+//===-- Runtime/ragged.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.
@@ -57,4 +57,4 @@ void RTDECL(RaggedArrayDeallocate)(void *raggedArrayHeader);
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_RAGGED_H_ */
+#endif // FORTRAN_RUNTIME_RAGGED_H_
diff --git a/FortranRuntime/include/flang/Runtime/random.h b/flang/include/flang/Runtime/random.h
similarity index 100%
rename from FortranRuntime/include/flang/Runtime/random.h
rename to flang/include/flang/Runtime/random.h
diff --git a/FortranRuntime/include/flang/Runtime/reduce.h b/flang/include/flang/Runtime/reduce.h
similarity index 99%
rename from FortranRuntime/include/flang/Runtime/reduce.h
rename to flang/include/flang/Runtime/reduce.h
index ae2828f04bf7c0..60f54c393b4bbd 100644
--- a/FortranRuntime/include/flang/Runtime/reduce.h
+++ b/flang/include/flang/Runtime/reduce.h
@@ -435,4 +435,4 @@ void RTDECL(ReduceDerivedTypeDim)(Descriptor &result, const Descriptor &array,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_REDUCE_H_ */
+#endif // FORTRAN_RUNTIME_REDUCE_H_
diff --git a/FortranRuntime/include/flang/Runtime/reduction.h b/flang/include/flang/Runtime/reduction.h
similarity index 99%
rename from FortranRuntime/include/flang/Runtime/reduction.h
rename to flang/include/flang/Runtime/reduction.h
index e00593fbc9f75e..97986c12e8a10e 100644
--- a/FortranRuntime/include/flang/Runtime/reduction.h
+++ b/flang/include/flang/Runtime/reduction.h
@@ -444,4 +444,4 @@ bool RTDECL(DotProductLogical)(const Descriptor &, const Descriptor &,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_REDUCTION_H_ */
+#endif // FORTRAN_RUNTIME_REDUCTION_H_
diff --git a/FortranRuntime/include/flang/Runtime/stop.h b/flang/include/flang/Runtime/stop.h
similarity index 97%
rename from FortranRuntime/include/flang/Runtime/stop.h
rename to flang/include/flang/Runtime/stop.h
index 9ba41343c6f964..f7c4ffe7403e8e 100644
--- a/FortranRuntime/include/flang/Runtime/stop.h
+++ b/flang/include/flang/Runtime/stop.h
@@ -37,4 +37,4 @@ NORETURN void RTNAME(ReportFatalUserError)(
 
 FORTRAN_EXTERN_C_END
 
-#endif /* FORTRAN_RUNTIME_STOP_H_ */
+#endif // FORTRAN_RUNTIME_STOP_H_
diff --git a/FortranRuntime/include/flang/Runtime/support.h b/flang/include/flang/Runtime/support.h
similarity index 97%
rename from FortranRuntime/include/flang/Runtime/support.h
rename to flang/include/flang/Runtime/support.h
index 9c9b067a18f2e4..4a6d4357e87103 100644
--- a/FortranRuntime/include/flang/Runtime/support.h
+++ b/flang/include/flang/Runtime/support.h
@@ -47,4 +47,4 @@ void RTDECL(CopyAndUpdateDescriptor)(Descriptor &to, const Descriptor &from,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_SUPPORT_H_ */
+#endif // FORTRAN_RUNTIME_SUPPORT_H_
diff --git a/FortranRuntime/include/flang/Runtime/temporary-stack.h b/flang/include/flang/Runtime/temporary-stack.h
similarity index 98%
rename from FortranRuntime/include/flang/Runtime/temporary-stack.h
rename to flang/include/flang/Runtime/temporary-stack.h
index f83fab7b0ac811..3c1a4ea11a4352 100644
--- a/FortranRuntime/include/flang/Runtime/temporary-stack.h
+++ b/flang/include/flang/Runtime/temporary-stack.h
@@ -64,4 +64,4 @@ void RTNAME(DestroyDescriptorStack)(void *opaquePtr);
 } // extern "C"
 } // namespace Fortran::runtime
 
-#endif /* FORTRAN_RUNTIME_TEMPORARY_STACK_H_ */
+#endif // FORTRAN_RUNTIME_TEMPORARY_STACK_H_
diff --git a/FortranRuntime/include/flang/Runtime/time-intrinsic.h b/flang/include/flang/Runtime/time-intrinsic.h
similarity index 97%
rename from FortranRuntime/include/flang/Runtime/time-intrinsic.h
rename to flang/include/flang/Runtime/time-intrinsic.h
index 0e63fc6a4647a4..80490a17e45597 100644
--- a/FortranRuntime/include/flang/Runtime/time-intrinsic.h
+++ b/flang/include/flang/Runtime/time-intrinsic.h
@@ -48,4 +48,4 @@ void RTNAME(Etime)(const Descriptor *values, const Descriptor *time,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_TIME_INTRINSIC_H_ */
+#endif // FORTRAN_RUNTIME_TIME_INTRINSIC_H_
diff --git a/FortranRuntime/include/flang/Runtime/transformational.h b/flang/include/flang/Runtime/transformational.h
similarity index 99%
rename from FortranRuntime/include/flang/Runtime/transformational.h
rename to flang/include/flang/Runtime/transformational.h
index 266dd9d7aebc24..a39b872f376a69 100644
--- a/FortranRuntime/include/flang/Runtime/transformational.h
+++ b/flang/include/flang/Runtime/transformational.h
@@ -154,4 +154,4 @@ void RTDECL(Unpack)(Descriptor &result, const Descriptor &vector,
 
 } // extern "C"
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_TRANSFORMATIONAL_H_ */
+#endif // FORTRAN_RUNTIME_TRANSFORMATIONAL_H_
diff --git a/flang/include/flang/Support/Fortran-features.h b/flang/include/flang/Support/Fortran-features.h
index 718ce680afeeab..1423d2c83d22cc 100644
--- a/flang/include/flang/Support/Fortran-features.h
+++ b/flang/include/flang/Support/Fortran-features.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#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/enum-set.h"
 #include "flang/Common/idioms.h"
@@ -191,4 +191,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/Support/Fortran.h b/flang/include/flang/Support/Fortran.h
index 343a0b30d2ba9c..7a9b0d56d6b2ac 100644
--- a/flang/include/flang/Support/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,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#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.
@@ -107,4 +107,4 @@ inline std::string GetExternalAssemblyName(
 }
 
 } // namespace Fortran::common
-#endif // FORTRAN_COMMON_FORTRAN_H_
+#endif /* FORTRAN_SUPPORT_FORTRAN_H_ */
diff --git a/flang/include/flang/Support/MathOptionsBase.h b/flang/include/flang/Support/MathOptionsBase.h
index a739ba3e066599..072aed20da4708 100644
--- a/flang/include/flang/Support/MathOptionsBase.h
+++ b/flang/include/flang/Support/MathOptionsBase.h
@@ -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 {
 
@@ -41,4 +41,4 @@ class MathOptionsBase {
 
 } // namespace Fortran::common
 
-#endif // FORTRAN_COMMON_MATHOPTIONSBASE_H
+#endif /* FORTRAN_SUPPORT_MATHOPTIONSBASE_H_ */
diff --git a/flang/include/flang/Support/Version.h b/flang/include/flang/Support/Version.h
index 643ddd2e27f69a..4ceb19e7f4d714 100644
--- a/flang/include/flang/Support/Version.h
+++ b/flang/include/flang/Support/Version.h
@@ -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/Support/default-kinds.h b/flang/include/flang/Support/default-kinds.h
index e78a08dfae6cc3..92f06e6fe2d272 100644
--- a/flang/include/flang/Support/default-kinds.h
+++ b/flang/include/flang/Support/default-kinds.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#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/Support/Fortran.h"
 #include <cstdint>
@@ -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/Support/indirection.h b/flang/include/flang/Support/indirection.h
index 1221a659323503..aeb1698516bae9 100644
--- a/flang/include/flang/Support/indirection.h
+++ b/flang/include/flang/Support/indirection.h
@@ -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
@@ -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/Support/interval.h b/flang/include/flang/Support/interval.h
index 2918cc54de3926..99c0784f006a80 100644
--- a/flang/include/flang/Support/interval.h
+++ b/flang/include/flang/Support/interval.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#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).
@@ -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/Support/template.h b/flang/include/flang/Support/template.h
index 58c9b0a5628e8a..36fa6f7072b40c 100644
--- a/flang/include/flang/Support/template.h
+++ b/flang/include/flang/Support/template.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_COMMON_TEMPLATE_H_
-#define FORTRAN_COMMON_TEMPLATE_H_
+#ifndef FORTRAN_SUPPORT_TEMPLATE_H_
+#define FORTRAN_SUPPORT_TEMPLATE_H_
 
 #include "flang/Common/idioms.h"
 #include "flang/Common/variant.h"
@@ -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/Support/unwrap.h b/flang/include/flang/Support/unwrap.h
index d8fa553dedda3f..e890753499d1a1 100644
--- a/flang/include/flang/Support/unwrap.h
+++ b/flang/include/flang/Support/unwrap.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#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"
@@ -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/Testing/README.md b/flang/include/flang/Testing/README.md
new file mode 100644
index 00000000000000..a722732fb76407
--- /dev/null
+++ b/flang/include/flang/Testing/README.md
@@ -0,0 +1,25 @@
+Files in this directory are used by Flang (the compiler) and FortranRuntime
+(the runtime library for Flang-compiled programs). They must be compatible by
+both. For definitions used only by Flang, consider
+`flang/{lib,include/flang}/Support` instead. For definitions used only by
+FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.
+
+The requirements for common code include:
+
+ * No dependence to LLVM, including LLVMSupport.
+
+ * No link-dependence to the C++ runtime. This means that e.g. `std::string`
+   cannot be used.
+
+ * No use of `std::optional<T>`; `fortran::common::optional<T>` can be used
+   instead.
+
+ * Preprocessor macros from `config.h` and CMake
+   `(target/add)_compile_definitions` must be defined by both build scripts.
+   See `flang/cmake/modules/FlangCommon.cmake`.
+
+ * Some header files are included from `.c` files.
+   `#include <flang/Common/c-or-cpp.h>` can help to support C++ and C.
+
+ * Global declarations may need to be annotated using definitions from
+   `api-attrs.h`.
diff --git a/FortranRuntime/include/flang/Testing/fp-testing.h b/flang/include/flang/Testing/fp-testing.h
similarity index 100%
rename from FortranRuntime/include/flang/Testing/fp-testing.h
rename to flang/include/flang/Testing/fp-testing.h
diff --git a/FortranRuntime/include/flang/Testing/testing.h b/flang/include/flang/Testing/testing.h
similarity index 100%
rename from FortranRuntime/include/flang/Testing/testing.h
rename to flang/include/flang/Testing/testing.h
diff --git a/flang/lib/Common/CMakeLists.txt b/flang/lib/Common/CMakeLists.txt
index ff7c186bff866b..04b719861a86cb 100644
--- a/flang/lib/Common/CMakeLists.txt
+++ b/flang/lib/Common/CMakeLists.txt
@@ -35,7 +35,7 @@ if(FLANG_VENDOR)
 endif()
 
 
-add_flang_library(FortranCommon
+add_flang_library(FortranCommon PARTIAL_SOURCES_INTENDED
   ../Support/Fortran.cpp
   ../Support/Fortran-features.cpp
   ../Support/default-kinds.cpp
diff --git a/flang/lib/Common/README.md b/flang/lib/Common/README.md
new file mode 100644
index 00000000000000..a722732fb76407
--- /dev/null
+++ b/flang/lib/Common/README.md
@@ -0,0 +1,25 @@
+Files in this directory are used by Flang (the compiler) and FortranRuntime
+(the runtime library for Flang-compiled programs). They must be compatible by
+both. For definitions used only by Flang, consider
+`flang/{lib,include/flang}/Support` instead. For definitions used only by
+FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.
+
+The requirements for common code include:
+
+ * No dependence to LLVM, including LLVMSupport.
+
+ * No link-dependence to the C++ runtime. This means that e.g. `std::string`
+   cannot be used.
+
+ * No use of `std::optional<T>`; `fortran::common::optional<T>` can be used
+   instead.
+
+ * Preprocessor macros from `config.h` and CMake
+   `(target/add)_compile_definitions` must be defined by both build scripts.
+   See `flang/cmake/modules/FlangCommon.cmake`.
+
+ * Some header files are included from `.c` files.
+   `#include <flang/Common/c-or-cpp.h>` can help to support C++ and C.
+
+ * Global declarations may need to be annotated using definitions from
+   `api-attrs.h`.
diff --git a/FortranRuntime/lib/Common/big-radix-floating-point.h b/flang/lib/Common/big-radix-floating-point.h
similarity index 100%
rename from FortranRuntime/lib/Common/big-radix-floating-point.h
rename to flang/lib/Common/big-radix-floating-point.h
diff --git a/FortranRuntime/lib/Common/binary-to-decimal.cpp b/flang/lib/Common/binary-to-decimal.cpp
similarity index 100%
rename from FortranRuntime/lib/Common/binary-to-decimal.cpp
rename to flang/lib/Common/binary-to-decimal.cpp
diff --git a/FortranRuntime/lib/Common/decimal-to-binary.cpp b/flang/lib/Common/decimal-to-binary.cpp
similarity index 100%
rename from FortranRuntime/lib/Common/decimal-to-binary.cpp
rename to flang/lib/Common/decimal-to-binary.cpp
diff --git a/flang/lib/Decimal/CMakeLists.txt b/flang/lib/Decimal/CMakeLists.txt
index 6b058e4a0ae2fa..5dd82e10a66556 100644
--- a/flang/lib/Decimal/CMakeLists.txt
+++ b/flang/lib/Decimal/CMakeLists.txt
@@ -37,8 +37,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
     add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
   endif ()
   include_directories(BEFORE
-    ${FLANG_SOURCE_DIR}/include
-    ${FLANG_SOURCE_DIR}/../FortranRuntime/include)
+    ${FLANG_SOURCE_DIR}/include)
 endif()
 
 check_cxx_compiler_flag(-fno-lto FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
@@ -51,8 +50,8 @@ endif()
 add_definitions(-U_GLIBCXX_ASSERTIONS)
 
 set(sources
-  ../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
-  ../../../FortranRuntime/lib/Common/decimal-to-binary.cpp
+  ../Common/binary-to-decimal.cpp
+  ../Common/decimal-to-binary.cpp
 )
 
 include(AddFlangOffloadRuntime)
@@ -64,23 +63,23 @@ 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
-          ../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
-          ../../../FortranRuntime/lib/Common/decimal-to-binary.cpp
+          ../Common/binary-to-decimal.cpp
+          ../Common/decimal-to-binary.cpp
   )
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
   add_flang_library(FortranDecimal.dynamic INSTALL_WITH_TOOLCHAIN
-    ../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
-    ../../../FortranRuntime/lib/Common/decimal-to-binary.cpp
+    ../Common/binary-to-decimal.cpp
+    ../Common/decimal-to-binary.cpp
   )
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
   add_flang_library(FortranDecimal.static_dbg INSTALL_WITH_TOOLCHAIN
-          ../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
-          ../../../FortranRuntime/lib/Common/decimal-to-binary.cpp
+          ../Common/binary-to-decimal.cpp
+          ../Common/decimal-to-binary.cpp
   )
   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL)
   add_flang_library(FortranDecimal.dynamic_dbg INSTALL_WITH_TOOLCHAIN
-    ../../../FortranRuntime/lib/Common/binary-to-decimal.cpp
-    ../../../FortranRuntime/lib/Common/decimal-to-binary.cpp
+    ../Common/binary-to-decimal.cpp
+    ../Common/decimal-to-binary.cpp
   )
   add_dependencies(FortranDecimal FortranDecimal.static FortranDecimal.dynamic
     FortranDecimal.static_dbg FortranDecimal.dynamic_dbg)
diff --git a/flang/lib/Evaluate/common.cpp b/flang/lib/Evaluate/common.cpp
index ed040b0728c4db..c633bff57b1ecd 100644
--- a/flang/lib/Evaluate/common.cpp
+++ b/flang/lib/Evaluate/common.cpp
@@ -11,11 +11,8 @@
 
 using namespace Fortran::parser::literals;
 
-
-
 namespace Fortran::evaluate {
 
-
 void RealFlagWarnings(
     FoldingContext &context, const RealFlags &flags, const char *operation) {
   if (context.languageFeatures().ShouldWarn(
diff --git a/flang/lib/Evaluate/fold-logical.cpp b/flang/lib/Evaluate/fold-logical.cpp
index a7e1aad38f3586..ee6655f8387177 100644
--- a/flang/lib/Evaluate/fold-logical.cpp
+++ b/flang/lib/Evaluate/fold-logical.cpp
@@ -9,8 +9,8 @@
 #include "fold-implementation.h"
 #include "fold-matmul.h"
 #include "fold-reduction.h"
-#include "flang/Common/magic-numbers.h"
 #include "flang/Evaluate/check-expression.h"
+#include "flang/Runtime/magic-numbers.h"
 
 namespace Fortran::evaluate {
 
diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index f76d44f5479d32..82bedca7bd41dd 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -39,7 +39,7 @@
 #include "flang/Optimizer/Support/FatalError.h"
 #include "flang/Optimizer/Support/InternalNames.h"
 #include "flang/Optimizer/Support/Utils.h"
-#include "flang/Runtime/allocator-registry.h"
+#include "flang/Runtime/allocator-registry-consts.h"
 #include "flang/Semantics/runtime-type-info.h"
 #include "flang/Semantics/tools.h"
 #include "llvm/Support/CommandLine.h"
diff --git a/flang/lib/Optimizer/Builder/CMakeLists.txt b/flang/lib/Optimizer/Builder/CMakeLists.txt
index 05164d41a4cb55..1d63401f36a616 100644
--- a/flang/lib/Optimizer/Builder/CMakeLists.txt
+++ b/flang/lib/Optimizer/Builder/CMakeLists.txt
@@ -1,7 +1,7 @@
 get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
 get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS)
 
-add_flang_library(FIRBuilder
+add_flang_library(FIRBuilder PARTIAL_SOURCES_INTENDED
   BoxValue.cpp
   Character.cpp
   Complex.cpp
diff --git a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp
index c786bef5cb1c4c..b7c6dc5fb2bf6c 100644
--- a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp
@@ -9,7 +9,7 @@
 #include "flang/Optimizer/Builder/Runtime/ArrayConstructor.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
-#include "flang/Runtime/array-constructor.h"
+#include "flang/Runtime/array-constructor-consts.h"
 
 using namespace Fortran::runtime;
 
@@ -29,8 +29,8 @@ mlir::Value fir::runtime::genInitArrayConstructorVector(
   // the target. The "cookieSize" argument is used to validate this wild
   // assumption until runtime interfaces are improved.
   std::size_t arrayVectorStructBitSize =
-      2 * sizeof(Fortran::runtime::ArrayConstructorVector) * 8;
-  std::size_t alignLike = alignof(Fortran::runtime::ArrayConstructorVector) * 8;
+      MaxArrayConstructorVectorSizeInBytes * 8;
+  std::size_t alignLike = MaxArrayConstructorVectorAlignInBytes * 8;
   fir::SequenceType::Extent numElem =
       (arrayVectorStructBitSize + alignLike - 1) / alignLike;
   mlir::Type intType = builder.getIntegerType(alignLike);
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 88293bcf36a780..eed389380f7cca 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -23,8 +23,8 @@
 #include "flang/Optimizer/Support/InternalNames.h"
 #include "flang/Optimizer/Support/TypeCode.h"
 #include "flang/Optimizer/Support/Utils.h"
-#include "flang/Runtime/allocator-registry.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/allocator-registry-consts.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Semantics/runtime-type-info.h"
 #include "mlir/Conversion/ArithCommon/AttrToLLVMConverter.h"
 #include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
@@ -1273,16 +1273,12 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
           insertField(rewriter, loc, descriptor, {kExtraPosInBox}, extraField);
     } else {
       // Compute the value of the extra field based on allocator_idx and
-      // addendum present using a Descriptor object.
-      Fortran::runtime::StaticDescriptor staticDescriptor;
-      Fortran::runtime::Descriptor &desc{staticDescriptor.descriptor()};
-      desc.raw().extra = 0;
-      desc.SetAllocIdx(allocatorIdx);
+      // addendum present.
+      unsigned extra = allocatorIdx << _CFI_ALLOCATOR_IDX_SHIFT;
       if (hasAddendum)
-        desc.SetHasAddendum();
-      descriptor =
-          insertField(rewriter, loc, descriptor, {kExtraPosInBox},
-                      this->genI32Constant(loc, rewriter, desc.raw().extra));
+        extra |= _CFI_ADDENDUM_FLAG;
+      descriptor = insertField(rewriter, loc, descriptor, {kExtraPosInBox},
+                               this->genI32Constant(loc, rewriter, extra));
     }
 
     if (hasAddendum) {
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 08d75c46faee4b..ca0b50de9bdb93 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -1467,4 +1467,4 @@ fir::getTypeSizeAndAlignmentOrCrash(mlir::Location loc, mlir::Type ty,
   if (result)
     return *result;
   TODO(loc, "computing size of a component");
-}
\ No newline at end of file
+}
diff --git a/flang/lib/Semantics/compute-offsets.cpp b/flang/lib/Semantics/compute-offsets.cpp
index b5a58ddca0ecdd..c5774ed30de748 100644
--- a/flang/lib/Semantics/compute-offsets.cpp
+++ b/flang/lib/Semantics/compute-offsets.cpp
@@ -11,7 +11,7 @@
 #include "flang/Evaluate/fold.h"
 #include "flang/Evaluate/shape.h"
 #include "flang/Evaluate/type.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Semantics/scope.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/symbol.h"
@@ -341,8 +341,12 @@ auto ComputeOffsetsHelper::GetSizeAndAlignment(
     const auto *derived{evaluate::GetDerivedTypeSpec(dyType)};
     int lenParams{derived ? CountLenParameters(*derived) : 0};
     bool needAddendum{derived || (dyType && dyType->IsUnlimitedPolymorphic())};
-    std::size_t size{runtime::Descriptor::SizeInBytes(
+
+    // FIXME: Get descriptor size from targetCharacteristics instead
+    // overapproximation
+    std::size_t size{runtime::MaxDescriptorSizeInBytes(
         symbol.Rank(), needAddendum, lenParams)};
+
     return {size, targetCharacteristics.descriptorAlignment()};
   }
   if (IsProcedurePointer(symbol)) {
diff --git a/flang/lib/Testing/README.md b/flang/lib/Testing/README.md
new file mode 100644
index 00000000000000..a722732fb76407
--- /dev/null
+++ b/flang/lib/Testing/README.md
@@ -0,0 +1,25 @@
+Files in this directory are used by Flang (the compiler) and FortranRuntime
+(the runtime library for Flang-compiled programs). They must be compatible by
+both. For definitions used only by Flang, consider
+`flang/{lib,include/flang}/Support` instead. For definitions used only by
+FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.
+
+The requirements for common code include:
+
+ * No dependence to LLVM, including LLVMSupport.
+
+ * No link-dependence to the C++ runtime. This means that e.g. `std::string`
+   cannot be used.
+
+ * No use of `std::optional<T>`; `fortran::common::optional<T>` can be used
+   instead.
+
+ * Preprocessor macros from `config.h` and CMake
+   `(target/add)_compile_definitions` must be defined by both build scripts.
+   See `flang/cmake/modules/FlangCommon.cmake`.
+
+ * Some header files are included from `.c` files.
+   `#include <flang/Common/c-or-cpp.h>` can help to support C++ and C.
+
+ * Global declarations may need to be annotated using definitions from
+   `api-attrs.h`.
diff --git a/FortranRuntime/lib/Testing/fp-testing.cpp b/flang/lib/Testing/fp-testing.cpp
similarity index 100%
rename from FortranRuntime/lib/Testing/fp-testing.cpp
rename to flang/lib/Testing/fp-testing.cpp
diff --git a/FortranRuntime/lib/Testing/testing.cpp b/flang/lib/Testing/testing.cpp
similarity index 100%
rename from FortranRuntime/lib/Testing/testing.cpp
rename to flang/lib/Testing/testing.cpp
diff --git a/flang/module/__fortran_builtins.f90 b/flang/module/__fortran_builtins.f90
index fe91305c836ff4..d1d4a639e70d72 100644
--- a/flang/module/__fortran_builtins.f90
+++ b/flang/module/__fortran_builtins.f90
@@ -6,7 +6,7 @@
 !
 !===------------------------------------------------------------------------===!
 
-#include '../../FortranRuntime/include/flang/Common/magic-numbers.h'
+#include '../include/flang/Runtime/magic-numbers.h'
 
 ! These naming shenanigans prevent names from Fortran intrinsic modules
 ! from being usable on INTRINSIC statements, and force the program
diff --git a/flang/module/__fortran_ieee_exceptions.f90 b/flang/module/__fortran_ieee_exceptions.f90
index 56f79a473b556a..6691012eda238a 100644
--- a/flang/module/__fortran_ieee_exceptions.f90
+++ b/flang/module/__fortran_ieee_exceptions.f90
@@ -11,7 +11,7 @@
 ! here under another name so that IEEE_ARITHMETIC can USE it and export its
 ! declarations without clashing with a non-intrinsic module in a program.
 
-#include '../../FortranRuntime/include/flang/Common/magic-numbers.h'
+#include '../include/flang/Runtime/magic-numbers.h'
 
 module __fortran_ieee_exceptions
   use __fortran_builtins, only: &
diff --git a/flang/module/cudadevice.f90 b/flang/module/cudadevice.f90
index dd487f6ed1ffee..0224ecfdde7c60 100644
--- a/flang/module/cudadevice.f90
+++ b/flang/module/cudadevice.f90
@@ -1,4 +1,4 @@
-!===-- module/cudadevice.f90 -----------------------------------------------===!
+!===-- module/cudedevice.f90 -----------------------------------------------===!
 !
 ! 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/module/ieee_arithmetic.f90 b/flang/module/ieee_arithmetic.f90
index 667374d0660806..7eaa7db55af9f8 100644
--- a/flang/module/ieee_arithmetic.f90
+++ b/flang/module/ieee_arithmetic.f90
@@ -8,7 +8,7 @@
 
 ! Fortran 2018 Clause 17
 
-#include '../../FortranRuntime/include/flang/Common/magic-numbers.h'
+#include '../include/flang/Runtime/magic-numbers.h'
 
 module ieee_arithmetic
   ! F18 Clause 17.1p1:
diff --git a/flang/module/iso_fortran_env.f90 b/flang/module/iso_fortran_env.f90
index d1f956b6b86408..4e575b422c2a04 100644
--- a/flang/module/iso_fortran_env.f90
+++ b/flang/module/iso_fortran_env.f90
@@ -8,7 +8,7 @@
 
 ! See Fortran 2023, subclause 16.10.2
 
-#include '../../FortranRuntime/include/flang/Common/magic-numbers.h'
+#include '../include/flang/Runtime/magic-numbers.h'
 
 module iso_fortran_env
 
diff --git a/FortranRuntime/lib/Runtime/iso_fortran_env_impl.f90 b/flang/module/iso_fortran_env_impl.f90
similarity index 98%
rename from FortranRuntime/lib/Runtime/iso_fortran_env_impl.f90
rename to flang/module/iso_fortran_env_impl.f90
index 1a4da69266c55b..4de54dda7bab1c 100644
--- a/FortranRuntime/lib/Runtime/iso_fortran_env_impl.f90
+++ b/flang/module/iso_fortran_env_impl.f90
@@ -1,4 +1,4 @@
-!===-- lib/Runtime/iso_fortran_env_impl.f90 --------------------------------===!
+!===-- module/iso_fortran_env_impl.f90 --=--------------------------------===!
 !
 ! 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/test/lit.cfg.py b/flang/test/lit.cfg.py
index 228bbb7e313d82..4acbc0606d1977 100644
--- a/flang/test/lit.cfg.py
+++ b/flang/test/lit.cfg.py
@@ -169,7 +169,7 @@
 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, "..", "FortranRuntime", "include")
+    include = os.path.join(config.flang_src_dir, "include")
 
     if (
         os.path.isfile(libruntime)
diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index f4ebc784a26cc8..9d7b8633958cb7 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -105,12 +105,10 @@ if (NOT CMAKE_CROSSCOMPILING)
     set(compile_with "-fsyntax-only")
     set(object_output "")
     set(include_in_link FALSE)
-    set(fullpath "${FLANG_SOURCE_DIR}/module/${filename}.f90")
     if(${filename} IN_LIST MODULES_WITH_IMPLEMENTATION)
       set(object_output "${CMAKE_CURRENT_BINARY_DIR}/${filename}${CMAKE_CXX_OUTPUT_EXTENSION}")
       set(compile_with -c -o ${object_output})
       set(include_in_link TRUE)
-      set(fullpath "${FLANG_SOURCE_DIR}/../FortranRuntime/lib/Runtime/${filename}.f90")
     endif()
 
     set(base ${FLANG_INTRINSIC_MODULES_DIR}/${filename})
@@ -118,8 +116,8 @@ if (NOT CMAKE_CROSSCOMPILING)
     add_custom_command(OUTPUT ${base}.mod ${object_output}
       COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
       COMMAND flang-new ${opts} ${decls} -cpp ${compile_with} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
-        ${fullpath}
-      DEPENDS flang-new ${fullpath} ${FLANG_SOURCE_DIR}/module/__fortran_builtins.f90 ${depends}
+        ${FLANG_SOURCE_DIR}/module/${filename}.f90
+      DEPENDS flang-new ${FLANG_SOURCE_DIR}/module/${filename}.f90 ${FLANG_SOURCE_DIR}/module/__fortran_builtins.f90 ${depends}
     )
     list(APPEND MODULE_FILES ${base}.mod)
     install(FILES ${base}.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
diff --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt
index 2d86e991aee610..a3fed6c27d125b 100644
--- a/flang/unittests/CMakeLists.txt
+++ b/flang/unittests/CMakeLists.txt
@@ -10,6 +10,8 @@ endif()
 add_custom_target(FlangUnitTests)
 set_target_properties(FlangUnitTests PROPERTIES FOLDER "Flang/Tests")
 
+include_directories("../../FortranRuntime/include")
+
 function(add_flang_unittest_offload_properties target)
   # Set CUDA_RESOLVE_DEVICE_SYMBOLS.
   if (FLANG_EXPERIMENTAL_CUDA_RUNTIME)
@@ -72,8 +74,8 @@ function(add_flang_nongtest_unittest test_name)
 endfunction()
 
 add_subdirectory(Optimizer)
-add_subdirectory(../../FortranRuntime/unittests/Common Common)
-add_subdirectory(../../FortranRuntime/unittests/Decimal Decimal)
+add_subdirectory(Common)
+add_subdirectory(Decimal)
 add_subdirectory(Evaluate)
 add_subdirectory(../../FortranRuntime/unittests/Runtime Runtime)
 add_subdirectory(Frontend)
diff --git a/flang/unittests/Common/CMakeLists.txt b/flang/unittests/Common/CMakeLists.txt
new file mode 100644
index 00000000000000..bda02ed29a5efa
--- /dev/null
+++ b/flang/unittests/Common/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_flang_unittest(FlangCommonTests
+  FastIntSetTest.cpp
+)
diff --git a/FortranRuntime/unittests/Common/FastIntSetTest.cpp b/flang/unittests/Common/FastIntSetTest.cpp
similarity index 97%
rename from FortranRuntime/unittests/Common/FastIntSetTest.cpp
rename to flang/unittests/Common/FastIntSetTest.cpp
index a36a334e370eb9..bd1b953fa16631 100644
--- a/FortranRuntime/unittests/Common/FastIntSetTest.cpp
+++ b/flang/unittests/Common/FastIntSetTest.cpp
@@ -1,4 +1,4 @@
-//===-- unittests/Common/FastIntSetTest.cpp ---------------------*- C++ -*-===//
+//===-- flang/unittests/Common/FastIntSetTest.cpp ---------------*- 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/fast-int-set.h"
 #include "gtest/gtest.h"
+#include "flang/Common/fast-int-set.h"
 #include <optional>
 
 TEST(FastIntSetTests, Sanity) {
diff --git a/flang/unittests/Decimal/CMakeLists.txt b/flang/unittests/Decimal/CMakeLists.txt
new file mode 100644
index 00000000000000..d301a9d3628c56
--- /dev/null
+++ b/flang/unittests/Decimal/CMakeLists.txt
@@ -0,0 +1,10 @@
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+add_flang_nongtest_unittest(quick-sanity-test
+  FortranDecimal
+)
+
+# This test is not run by default as it takes a long time to execute.
+add_flang_nongtest_unittest(thorough-test
+  SLOW_TEST
+  FortranDecimal
+)
diff --git a/FortranRuntime/unittests/Decimal/quick-sanity-test.cpp b/flang/unittests/Decimal/quick-sanity-test.cpp
similarity index 92%
rename from FortranRuntime/unittests/Decimal/quick-sanity-test.cpp
rename to flang/unittests/Decimal/quick-sanity-test.cpp
index 0e8ff0ce48b3c6..c36c73b817e1f9 100644
--- a/FortranRuntime/unittests/Decimal/quick-sanity-test.cpp
+++ b/flang/unittests/Decimal/quick-sanity-test.cpp
@@ -1,11 +1,3 @@
-//===-- unittests/Decimal/quick-sanity-test.cpp -----------------*- 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/decimal.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cinttypes>
diff --git a/FortranRuntime/unittests/Decimal/thorough-test.cpp b/flang/unittests/Decimal/thorough-test.cpp
similarity index 86%
rename from FortranRuntime/unittests/Decimal/thorough-test.cpp
rename to flang/unittests/Decimal/thorough-test.cpp
index 0648b61d7c1cda..0f7a2d4b33e764 100644
--- a/FortranRuntime/unittests/Decimal/thorough-test.cpp
+++ b/flang/unittests/Decimal/thorough-test.cpp
@@ -1,11 +1,3 @@
-//===-- unittests/Decimal/thorough-test.cpp ---------------------*- 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/decimal.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cinttypes>
diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt
index 35bd7b0f18a90d..c80c04b18035e5 100644
--- a/flang/unittests/Evaluate/CMakeLists.txt
+++ b/flang/unittests/Evaluate/CMakeLists.txt
@@ -1,7 +1,7 @@
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
 add_library(FortranEvaluateTesting
-  ../../../FortranRuntime/lib/Testing/testing.cpp
-  ../../../FortranRuntime/lib/Testing/fp-testing.cpp
+  ../../lib/Testing/testing.cpp
+  ../../lib/Testing/fp-testing.cpp
 )
 set_target_properties(FortranEvaluateTesting PROPERTIES FOLDER "Flang/Tests")
 if (LLVM_LINK_LLVM_DYLIB)
@@ -76,4 +76,4 @@ add_flang_nongtest_unittest(folding
   FortranSemantics
 )
 
-add_subdirectory(../../../FortranRuntime/unittests/Evaluate runtime)
\ No newline at end of file
+add_subdirectory(../../../FortranRuntime/unittests/Evaluate runtime)
diff --git a/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp b/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp
index 1db43cacc90f07..f618e72d7b7f3c 100644
--- a/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp
+++ b/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp
@@ -9,7 +9,7 @@
 #include "flang/Optimizer/Builder/Runtime/Allocatable.h"
 #include "RuntimeCallTestBase.h"
 #include "gtest/gtest.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 
 using namespace Fortran::runtime;
 

>From 3beb59b881182def71e991c6fa7dcd382ccb5314 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 14 Oct 2024 17:14:45 +0200
Subject: [PATCH 08/12] build fix

---
 flang/include/flang/Runtime/descriptor-consts.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h
index 2d746c6337b518..aa5e2e4ee8b45f 100644
--- a/flang/include/flang/Runtime/descriptor-consts.h
+++ b/flang/include/flang/Runtime/descriptor-consts.h
@@ -28,6 +28,7 @@ class DerivedType;
 
 namespace Fortran::runtime {
 class Descriptor;
+using SubscriptValue = ISO::CFI_index_t;
 
 /// Returns size in bytes of the descriptor (not the data)
 /// This must be at least as large as the largest descriptor of any target

>From b3f9e91d6d362cde01062f06c079de0854c47cd8 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Tue, 15 Oct 2024 11:22:50 +0200
Subject: [PATCH 09/12] Re-add ISO-Fortran-binding unittest & cleanup

---
 FortranRuntime/cmake/config.h.cmake.in                    | 8 ++++++++
 FortranRuntime/lib/Runtime/command.cpp                    | 2 +-
 FortranRuntime/unittests/Evaluate/CMakeLists.txt          | 7 +++++++
 FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp | 4 +++-
 flang/include/flang/Runtime/README.md                     | 2 ++
 flang/unittests/Evaluate/CMakeLists.txt                   | 4 ++--
 6 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/FortranRuntime/cmake/config.h.cmake.in b/FortranRuntime/cmake/config.h.cmake.in
index 0a1d1394b9bc49..8a4668b90addda 100644
--- a/FortranRuntime/cmake/config.h.cmake.in
+++ b/FortranRuntime/cmake/config.h.cmake.in
@@ -1,3 +1,11 @@
+/*===-- 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
 
diff --git a/FortranRuntime/lib/Runtime/command.cpp b/FortranRuntime/lib/Runtime/command.cpp
index 3fc941ab2ef861..64b2e62461dd58 100644
--- a/FortranRuntime/lib/Runtime/command.cpp
+++ b/FortranRuntime/lib/Runtime/command.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime//command.h"
+#include "flang/Runtime/command.h"
 #include "FortranRuntime/Runtime/descriptor.h"
 #include "environment.h"
 #include "stat.h"
diff --git a/FortranRuntime/unittests/Evaluate/CMakeLists.txt b/FortranRuntime/unittests/Evaluate/CMakeLists.txt
index e0a284b9d39f3b..ceb9e178d34ec1 100644
--- a/FortranRuntime/unittests/Evaluate/CMakeLists.txt
+++ b/FortranRuntime/unittests/Evaluate/CMakeLists.txt
@@ -12,3 +12,10 @@ add_flang_nongtest_unittest(reshape
   FortranEvaluate
   FortranRuntime
 )
+
+add_flang_nongtest_unittest(ISO-Fortran-binding
+  FortranEvaluateTesting
+  FortranEvaluate
+  FortranSemantics
+  FortranRuntime
+)
diff --git a/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp b/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp
index fd7073ca1d7db0..b68dfbcbd5b335 100644
--- a/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp
+++ b/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp
@@ -28,7 +28,9 @@ template <int rank> class Test_CFI_CDESC_T {
     MATCH(false, std::is_const<type>::value);
     MATCH(false, std::is_volatile<type>::value);
     // suitable in size
-      MATCH(true, Descriptor::SizeInBytes(rank_, false) <= Fortran::common::MaxDescriptorSizeInBytes(  rank_, false));
+    MATCH(true,
+        Descriptor::SizeInBytes(rank_, false) <=
+            MaxDescriptorSizeInBytes(rank_, false));
     if (rank > 0) {
       MATCH(sizeof(dvStorage_), Descriptor::SizeInBytes(rank_, false));
     } else { // C++ implementation over-allocates for rank=0 by 24bytes.
diff --git a/flang/include/flang/Runtime/README.md b/flang/include/flang/Runtime/README.md
index a722732fb76407..a13a7e23162e98 100644
--- a/flang/include/flang/Runtime/README.md
+++ b/flang/include/flang/Runtime/README.md
@@ -23,3 +23,5 @@ The requirements for common code include:
 
  * Global declarations may need to be annotated using definitions from
    `api-attrs.h`.
+
+ * The `Runtime` component is header-only.
diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt
index c80c04b18035e5..5694f5a144c4c5 100644
--- a/flang/unittests/Evaluate/CMakeLists.txt
+++ b/flang/unittests/Evaluate/CMakeLists.txt
@@ -1,7 +1,7 @@
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
 add_library(FortranEvaluateTesting
-  ../../lib/Testing/testing.cpp
-  ../../lib/Testing/fp-testing.cpp
+  ${FLANG_SOURCE_DIR}/lib/Testing/testing.cpp
+  ${FLANG_SOURCE_DIR}/lib/Testing/fp-testing.cpp
 )
 set_target_properties(FortranEvaluateTesting PROPERTIES FOLDER "Flang/Tests")
 if (LLVM_LINK_LLVM_DYLIB)

>From 765c2f9ed768c30138e560567f73849d5bb66390 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Wed, 16 Oct 2024 12:01:09 +0200
Subject: [PATCH 10/12] FortranRuntime -> flang-rt

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

diff --git a/FortranRuntime/.clang-format b/flang-rt/.clang-format
similarity index 100%
rename from FortranRuntime/.clang-format
rename to flang-rt/.clang-format
diff --git a/FortranRuntime/cmake/config.h.cmake.in b/flang-rt/cmake/config.h.cmake.in
similarity index 100%
rename from FortranRuntime/cmake/config.h.cmake.in
rename to flang-rt/cmake/config.h.cmake.in
diff --git a/flang/include/flang/Runtime/CUDA/allocator.h b/flang-rt/include/flang-rt/CufRuntime/allocator.h
similarity index 85%
rename from flang/include/flang/Runtime/CUDA/allocator.h
rename to flang-rt/include/flang-rt/CufRuntime/allocator.h
index cc88896b1f0bd6..63406e0de6d2fa 100644
--- a/flang/include/flang/Runtime/CUDA/allocator.h
+++ b/flang-rt/include/flang-rt/CufRuntime/allocator.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/CUDA/allocator.h ------------------*- C++ -*-===//
+//===-- include/flang-rt/CufRuntime/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,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
-#define FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
+#ifndef FORTRAN_CUFRUNTIME_ALLOCATOR_H_
+#define FORTRAN_CUFRUNTIME_ALLOCATOR_H_
 
 #include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
@@ -43,4 +43,4 @@ void *CUFAllocUnified(std::size_t);
 void CUFFreeUnified(void *);
 
 } // namespace Fortran::runtime::cuda
-#endif // FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
+#endif /* FORTRAN_CUFRUNTIME_ALLOCATOR_H_ */
diff --git a/FortranRuntime/include/FortranRuntime/Runtime/allocator-registry.h b/flang-rt/include/flang-rt/flang_rt/allocator-registry.h
similarity index 87%
rename from FortranRuntime/include/FortranRuntime/Runtime/allocator-registry.h
rename to flang-rt/include/flang-rt/flang_rt/allocator-registry.h
index 30a583b88c083e..ecad61ab4043d7 100644
--- a/FortranRuntime/include/FortranRuntime/Runtime/allocator-registry.h
+++ b/flang-rt/include/flang-rt/flang_rt/allocator-registry.h
@@ -1,4 +1,4 @@
-//===-- include/FortranRuntime/Runtime/allocator-registry.h -----*- C++ -*-===//
+//===-- include/flang-rt/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 FORTRAN_FLANG_RT_ALLOCATOR_REGISTRY_H_
+#define FORTRAN_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 /* FORTRAN_FLANG_RT_ALLOCATOR_REGISTRY_H_ */
diff --git a/FortranRuntime/include/FortranRuntime/Runtime/array-constructor.h b/flang-rt/include/flang-rt/flang_rt/array-constructor.h
similarity index 85%
rename from FortranRuntime/include/FortranRuntime/Runtime/array-constructor.h
rename to flang-rt/include/flang-rt/flang_rt/array-constructor.h
index 314d5e56599cd3..e8fffc762b6fbe 100644
--- a/FortranRuntime/include/FortranRuntime/Runtime/array-constructor.h
+++ b/flang-rt/include/flang-rt/flang_rt/array-constructor.h
@@ -1,4 +1,4 @@
-//===-- include/FortranRuntime/Runtime/array-constructor.h ------*- C++ -*-===//
+//===-- include/flang-rt/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,10 +9,10 @@
 // External APIs to create temporary storage for array constructors when their
 // final extents or length parameters cannot be pre-computed.
 
-#ifndef FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_
-#define FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_
+#ifndef FORTRAN_FLANG_RT_ARRAY_CONSTRUCTOR_H_
+#define FORTRAN_FLANG_RT_ARRAY_CONSTRUCTOR_H_
 
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "flang/Runtime/array-constructor-consts.h"
 #include "flang/Runtime/entry-names.h"
 #include <cstdint>
@@ -45,4 +45,4 @@ struct ArrayConstructorVector {
 };
 
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_H_ */
+#endif /* FORTRAN_FLANG_RT_ARRAY_CONSTRUCTOR_H_ */
diff --git a/FortranRuntime/include/FortranRuntime/Runtime/descriptor.h b/flang-rt/include/flang-rt/flang_rt/descriptor.h
similarity index 98%
rename from FortranRuntime/include/FortranRuntime/Runtime/descriptor.h
rename to flang-rt/include/flang-rt/flang_rt/descriptor.h
index f79ad6b9637a4a..fea5b55c1922ce 100644
--- a/FortranRuntime/include/FortranRuntime/Runtime/descriptor.h
+++ b/flang-rt/include/flang-rt/flang_rt/descriptor.h
@@ -1,4 +1,4 @@
-//===-- include/FortranRuntime/Runtime/descriptor.h -------------*- C++ -*-===//
+//===-- include/flang-rt/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 FORTRAN_FLANG_RT_DESCRIPTOR_H_
+#define FORTRAN_FLANG_RT_DESCRIPTOR_H_
 
 // Defines data structures used during execution of a Fortran program
 // to implement nontrivial dummy arguments, pointers, allocatables,
@@ -18,8 +18,8 @@
 // User C code is welcome to depend on that ISO_Fortran_binding.h file,
 // but should never reference this internal header.
 
-#include "FortranRuntime/Runtime/memory.h"
-#include "FortranRuntime/Runtime/type-code.h"
+#include "flang-rt/flang_rt/memory.h"
+#include "flang-rt/flang_rt/type-code.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/descriptor-consts.h"
 #include <algorithm>
@@ -482,4 +482,4 @@ class alignas(Descriptor) StaticDescriptor {
 };
 
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_DESCRIPTOR_H_ */
+#endif /* FORTRAN_FLANG_RT_DESCRIPTOR_H_ */
diff --git a/FortranRuntime/include/FortranRuntime/Runtime/io-api-funcs.h b/flang-rt/include/flang-rt/flang_rt/io-api-funcs.h
similarity index 84%
rename from FortranRuntime/include/FortranRuntime/Runtime/io-api-funcs.h
rename to flang-rt/include/flang-rt/flang_rt/io-api-funcs.h
index 516fe25784656c..00cb49ad015437 100644
--- a/FortranRuntime/include/FortranRuntime/Runtime/io-api-funcs.h
+++ b/flang-rt/include/flang-rt/flang_rt/io-api-funcs.h
@@ -1,4 +1,4 @@
-//===-- include/FortranRuntime/Runtime/io-api-funcs.h -----------*- C++ -*-===//
+//===-- include/flang-rt/flang_rt/io-api-funcs.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 API between compiled code and I/O runtime library.
 
-#ifndef FORTRAN_RUNTIME_IO_API_FUNCS_H_
-#define FORTRAN_RUNTIME_IO_API_FUNCS_H_
+#ifndef FORTRAN_FLANG_RT_IO_API_FUNCS_H_
+#define FORTRAN_FLANG_RT_IO_API_FUNCS_H_
 
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/entry-names.h"
@@ -36,4 +36,4 @@ RT_API_ATTRS const char *InquiryKeywordHashDecode(
     char *buffer, std::size_t, InquiryKeywordHash);
 
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_RUNTIME_IO_API_FUNCS_H_ */
+#endif /* FORTRAN_FLANG_RT_IO_API_FUNCS_H_ */
diff --git a/FortranRuntime/include/FortranRuntime/Runtime/iostat-funcs.h b/flang-rt/include/flang-rt/flang_rt/iostat-funcs.h
similarity index 75%
rename from FortranRuntime/include/FortranRuntime/Runtime/iostat-funcs.h
rename to flang-rt/include/flang-rt/flang_rt/iostat-funcs.h
index 10906afb01673c..dd24d41fbaad10 100644
--- a/FortranRuntime/include/FortranRuntime/Runtime/iostat-funcs.h
+++ b/flang-rt/include/flang-rt/flang_rt/iostat-funcs.h
@@ -1,4 +1,4 @@
-//===-- include/FortranRuntime/Runtime/iostat-funcs.h -----------*- C++ -*-===//
+//===-- include/flang-rt/flang_rt/iostat-funcs.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 IOSTAT= specifiers
 // on I/O statements.
 
-#ifndef FORTRAN_RUNTIME_IOSTAT_FUNCS_H_
-#define FORTRAN_RUNTIME_IOSTAT_FUNCS_H_
+#ifndef FORTRAN_FLANG_RT_IOSTAT_FUNCS_H_
+#define FORTRAN_FLANG_RT_IOSTAT_FUNCS_H_
 
 #include "flang/Common/api-attrs.h"
 #include "flang/Runtime/iostat.h"
@@ -20,4 +20,4 @@ namespace Fortran::runtime::io {
 RT_API_ATTRS const char *IostatErrorString(int);
 
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ */
+#endif /* FORTRAN_FLANG_RT_IOSTAT_FUNCS_H_ */
diff --git a/FortranRuntime/include/FortranRuntime/Runtime/memory.h b/flang-rt/include/flang-rt/flang_rt/memory.h
similarity index 96%
rename from FortranRuntime/include/FortranRuntime/Runtime/memory.h
rename to flang-rt/include/flang-rt/flang_rt/memory.h
index 3e7fd2d9ea3e3b..b97f6525d60036 100644
--- a/FortranRuntime/include/FortranRuntime/Runtime/memory.h
+++ b/flang-rt/include/flang-rt/flang_rt/memory.h
@@ -1,4 +1,4 @@
-//===-- include/FortranRuntime/Runtime/memory.h -----------------*- C++ -*-===//
+//===-- include/flang-rt/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 FORTRAN_FLANG_RT_MEMORY_H_
+#define FORTRAN_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 /* FORTRAN_FLANG_RT_MEMORY_H_ */
diff --git a/FortranRuntime/include/FortranRuntime/Runtime/type-code.h b/flang-rt/include/flang-rt/flang_rt/type-code.h
similarity index 93%
rename from FortranRuntime/include/FortranRuntime/Runtime/type-code.h
rename to flang-rt/include/flang-rt/flang_rt/type-code.h
index 92ff593410c12c..7c694a13431b13 100644
--- a/FortranRuntime/include/FortranRuntime/Runtime/type-code.h
+++ b/flang-rt/include/flang-rt/flang_rt/type-code.h
@@ -1,4 +1,4 @@
-//===-- include/FortranRuntime/Runtime/type-code.h --------------*- C++ -*-===//
+//===-- include/flang-rt/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 FORTRAN_FLANG_RT_TYPE_CODE_H_
+#define FORTRAN_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 /* FORTRAN_FLANG_RT_TYPE_CODE_H_ */
diff --git a/FortranRuntime/lib/Runtime/CUDA/CMakeLists.txt b/flang-rt/lib/CufRuntime/CMakeLists.txt
similarity index 93%
rename from FortranRuntime/lib/Runtime/CUDA/CMakeLists.txt
rename to flang-rt/lib/CufRuntime/CMakeLists.txt
index f75b854d1eb3ba..2b07b249007167 100644
--- a/FortranRuntime/lib/Runtime/CUDA/CMakeLists.txt
+++ b/flang-rt/lib/CufRuntime/CMakeLists.txt
@@ -1,4 +1,4 @@
-#===-- lib/Runtime/CUDA/CMakeLists.txt -------------------------------------===#
+#===-- lib/CufRuntime/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.
diff --git a/FortranRuntime/lib/Runtime/CUDA/allocator.cpp b/flang-rt/lib/CufRuntime/allocator.cpp
similarity index 81%
rename from FortranRuntime/lib/Runtime/CUDA/allocator.cpp
rename to flang-rt/lib/CufRuntime/allocator.cpp
index c9d62f6ea8f3bf..8c16fb77f2ac46 100644
--- a/FortranRuntime/lib/Runtime/CUDA/allocator.cpp
+++ b/flang-rt/lib/CufRuntime/allocator.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/CUDA/allocator.cpp --------------------------*- C++ -*-===//
+//===-- lib/CufRuntime/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 "FortranRuntime/Runtime/CUDA/allocator.h"
-#include "FortranRuntime/Runtime/allocator-registry.h"
-#include "../derived.h"
-#include "../stat.h"
-#include "../terminator.h"
-#include "../type-info.h"
-#include "flang/ISO_Fortran_binding_wrapper.h"
-#include "flang/Support/Fortran.h"
+#include "flang-rt/CufRuntime/allocator.h"
+#include "flang-rt/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/Fortran-consts.h"
+#include "flang/Common/ISO_Fortran_binding_wrapper.h"
 
 #include "cuda_runtime.h"
 
diff --git a/FortranRuntime/lib/Runtime/CUDA/descriptor.cpp b/flang-rt/lib/CufRuntime/descriptor.cpp
similarity index 82%
rename from FortranRuntime/lib/Runtime/CUDA/descriptor.cpp
rename to flang-rt/lib/CufRuntime/descriptor.cpp
index 94b5feca4ce4dc..b034fc76b67d4d 100644
--- a/FortranRuntime/lib/Runtime/CUDA/descriptor.cpp
+++ b/flang-rt/lib/CufRuntime/descriptor.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/CUDA/descriptor.cpp -------------------------*- C++ -*-===//
+//===-- lib/CufRuntime/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,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/CUDA/descriptor.h"
-#include "FortranRuntime/Runtime/CUDA/allocator.h"
+#include "flang/Runtime/CUDA/descriptor.h"
+#include "flang-rt/CufRuntime/allocator.h"
 
 namespace Fortran::runtime::cuda {
 extern "C" {
diff --git a/FortranRuntime/lib/Runtime/Float128Math/CMakeLists.txt b/flang-rt/lib/FortranFloat128Math/CMakeLists.txt
similarity index 98%
rename from FortranRuntime/lib/Runtime/Float128Math/CMakeLists.txt
rename to flang-rt/lib/FortranFloat128Math/CMakeLists.txt
index 1ff158c401855f..756f07dd5b996d 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/CMakeLists.txt
+++ b/flang-rt/lib/FortranFloat128Math/CMakeLists.txt
@@ -1,4 +1,4 @@
-#===-- lib/Runtime/Float128Math/CMakeLists.txt -----------------------------===#
+#===-- lib/FortranFloat128Math/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.
diff --git a/FortranRuntime/lib/Runtime/Float128Math/acos.cpp b/flang-rt/lib/FortranFloat128Math/acos.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/acos.cpp
rename to flang-rt/lib/FortranFloat128Math/acos.cpp
index 7b15e4a0bfd3ae..e204c6c871f3fa 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/acos.cpp
+++ b/flang-rt/lib/FortranFloat128Math/acos.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/acos.cpp -----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/acosh.cpp b/flang-rt/lib/FortranFloat128Math/acosh.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/acosh.cpp
rename to flang-rt/lib/FortranFloat128Math/acosh.cpp
index c873259b4545b8..90ff7886e6909d 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/acosh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/acosh.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/acosh.cpp ----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/asin.cpp b/flang-rt/lib/FortranFloat128Math/asin.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/asin.cpp
rename to flang-rt/lib/FortranFloat128Math/asin.cpp
index 8866d51430197a..18368044d72b0f 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/asin.cpp
+++ b/flang-rt/lib/FortranFloat128Math/asin.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/asin.cpp -----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/asinh.cpp b/flang-rt/lib/FortranFloat128Math/asinh.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/asinh.cpp
rename to flang-rt/lib/FortranFloat128Math/asinh.cpp
index 288193001ce1da..2c1f040cfc3872 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/asinh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/asinh.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/asinh.cpp ----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/atan.cpp b/flang-rt/lib/FortranFloat128Math/atan.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/atan.cpp
rename to flang-rt/lib/FortranFloat128Math/atan.cpp
index 390c080b4d501b..8bd9a2626caf83 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/atan.cpp
+++ b/flang-rt/lib/FortranFloat128Math/atan.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/atan.cpp -----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/atan2.cpp b/flang-rt/lib/FortranFloat128Math/atan2.cpp
similarity index 91%
rename from FortranRuntime/lib/Runtime/Float128Math/atan2.cpp
rename to flang-rt/lib/FortranFloat128Math/atan2.cpp
index 3c206b75704431..4994be699a0b67 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/atan2.cpp
+++ b/flang-rt/lib/FortranFloat128Math/atan2.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/atan2.cpp ----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/atanh.cpp b/flang-rt/lib/FortranFloat128Math/atanh.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/atanh.cpp
rename to flang-rt/lib/FortranFloat128Math/atanh.cpp
index 77ceb188f04e42..f5ace35ac51caa 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/atanh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/atanh.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/atanh.cpp ----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/ceil.cpp b/flang-rt/lib/FortranFloat128Math/ceil.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/ceil.cpp
rename to flang-rt/lib/FortranFloat128Math/ceil.cpp
index 46bc253bd0922d..834da9396c071d 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/ceil.cpp
+++ b/flang-rt/lib/FortranFloat128Math/ceil.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/ceil.cpp -----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/complex-math.c b/flang-rt/lib/FortranFloat128Math/complex-math.c
similarity index 96%
rename from FortranRuntime/lib/Runtime/Float128Math/complex-math.c
rename to flang-rt/lib/FortranFloat128Math/complex-math.c
index f34ef7da76e599..493ffe942f7e31 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/complex-math.c
+++ b/flang-rt/lib/FortranFloat128Math/complex-math.c
@@ -1,4 +1,4 @@
-/*===-- lib/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.
diff --git a/FortranRuntime/lib/Runtime/Float128Math/complex-math.h b/flang-rt/lib/FortranFloat128Math/complex-math.h
similarity index 88%
rename from FortranRuntime/lib/Runtime/Float128Math/complex-math.h
rename to flang-rt/lib/FortranFloat128Math/complex-math.h
index 6f5c7954bab035..bb67523e1bddcc 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/complex-math.h
+++ b/flang-rt/lib/FortranFloat128Math/complex-math.h
@@ -1,4 +1,4 @@
-/*===-- lib/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 FORTRAN_FORTRANFLOAT128MATH_COMPLEX_MATH_H_
+#define FORTRAN_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 /* FORTRAN_FORTRANFLOAT128MATH_COMPLEX_MATH_H_ */
diff --git a/FortranRuntime/lib/Runtime/Float128Math/cos.cpp b/flang-rt/lib/FortranFloat128Math/cos.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/cos.cpp
rename to flang-rt/lib/FortranFloat128Math/cos.cpp
index 8ce47151e2914b..2651982666118b 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/cos.cpp
+++ b/flang-rt/lib/FortranFloat128Math/cos.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/cos.cpp ------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/cosh.cpp b/flang-rt/lib/FortranFloat128Math/cosh.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/cosh.cpp
rename to flang-rt/lib/FortranFloat128Math/cosh.cpp
index f1ec45bcfb479d..dda01e5abef66d 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/cosh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/cosh.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/cosh.cpp -----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/erf.cpp b/flang-rt/lib/FortranFloat128Math/erf.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/erf.cpp
rename to flang-rt/lib/FortranFloat128Math/erf.cpp
index 010088467794d1..f5e713d93cac61 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/erf.cpp
+++ b/flang-rt/lib/FortranFloat128Math/erf.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/erf.cpp ------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/erfc.cpp b/flang-rt/lib/FortranFloat128Math/erfc.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/erfc.cpp
rename to flang-rt/lib/FortranFloat128Math/erfc.cpp
index b226f8d2dc378b..3f8b78ba0e64f9 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/erfc.cpp
+++ b/flang-rt/lib/FortranFloat128Math/erfc.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/erfc.cpp -----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/exp.cpp b/flang-rt/lib/FortranFloat128Math/exp.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/exp.cpp
rename to flang-rt/lib/FortranFloat128Math/exp.cpp
index e22f9df3579e96..0b694b159f3621 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/exp.cpp
+++ b/flang-rt/lib/FortranFloat128Math/exp.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/exp.cpp ------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/exponent.cpp b/flang-rt/lib/FortranFloat128Math/exponent.cpp
similarity index 92%
rename from FortranRuntime/lib/Runtime/Float128Math/exponent.cpp
rename to flang-rt/lib/FortranFloat128Math/exponent.cpp
index f07bf30bd1096f..a9c1b867e7ea37 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/exponent.cpp
+++ b/flang-rt/lib/FortranFloat128Math/exponent.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/exponent.cpp -------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/floor.cpp b/flang-rt/lib/FortranFloat128Math/floor.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/floor.cpp
rename to flang-rt/lib/FortranFloat128Math/floor.cpp
index 8744e6e2fec63c..27cfed2f1f9599 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/floor.cpp
+++ b/flang-rt/lib/FortranFloat128Math/floor.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/floor.cpp ----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/fma.cpp b/flang-rt/lib/FortranFloat128Math/fma.cpp
similarity index 91%
rename from FortranRuntime/lib/Runtime/Float128Math/fma.cpp
rename to flang-rt/lib/FortranFloat128Math/fma.cpp
index 198fec5d4bc356..a9ac1581002cec 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/fma.cpp
+++ b/flang-rt/lib/FortranFloat128Math/fma.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/fma.cpp ------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/fraction.cpp b/flang-rt/lib/FortranFloat128Math/fraction.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/fraction.cpp
rename to flang-rt/lib/FortranFloat128Math/fraction.cpp
index d4749bf3eb7e0e..39c59a25812abb 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/fraction.cpp
+++ b/flang-rt/lib/FortranFloat128Math/fraction.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/fraction.cpp -------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/hypot.cpp b/flang-rt/lib/FortranFloat128Math/hypot.cpp
similarity index 91%
rename from FortranRuntime/lib/Runtime/Float128Math/hypot.cpp
rename to flang-rt/lib/FortranFloat128Math/hypot.cpp
index 6542bf505060df..c130e204f9951e 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/hypot.cpp
+++ b/flang-rt/lib/FortranFloat128Math/hypot.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/hypot.cpp ----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/j0.cpp b/flang-rt/lib/FortranFloat128Math/j0.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/j0.cpp
rename to flang-rt/lib/FortranFloat128Math/j0.cpp
index 27e4338cdfc2b0..d6454b56c8a86b 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/j0.cpp
+++ b/flang-rt/lib/FortranFloat128Math/j0.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/j0.cpp -------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/j1.cpp b/flang-rt/lib/FortranFloat128Math/j1.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/j1.cpp
rename to flang-rt/lib/FortranFloat128Math/j1.cpp
index d3f897827f9f67..2b7283aea0fe46 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/j1.cpp
+++ b/flang-rt/lib/FortranFloat128Math/j1.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/j1.cpp -------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/jn.cpp b/flang-rt/lib/FortranFloat128Math/jn.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/jn.cpp
rename to flang-rt/lib/FortranFloat128Math/jn.cpp
index 681bb5b1ff3ad5..cdc9af9b3dd6a5 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/jn.cpp
+++ b/flang-rt/lib/FortranFloat128Math/jn.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/jn.cpp -------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/lgamma.cpp b/flang-rt/lib/FortranFloat128Math/lgamma.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/lgamma.cpp
rename to flang-rt/lib/FortranFloat128Math/lgamma.cpp
index 0426db2e3b98d3..cecf9e90ad29ba 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/lgamma.cpp
+++ b/flang-rt/lib/FortranFloat128Math/lgamma.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/lgamma.cpp ---------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/llround.cpp b/flang-rt/lib/FortranFloat128Math/llround.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/llround.cpp
rename to flang-rt/lib/FortranFloat128Math/llround.cpp
index 4c9026cce00283..7853ac10f53e88 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/llround.cpp
+++ b/flang-rt/lib/FortranFloat128Math/llround.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/llround.cpp --------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/log.cpp b/flang-rt/lib/FortranFloat128Math/log.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/log.cpp
rename to flang-rt/lib/FortranFloat128Math/log.cpp
index a5a431ae5ffbbb..d705eaf441c31f 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/log.cpp
+++ b/flang-rt/lib/FortranFloat128Math/log.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/log.cpp ------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/log10.cpp b/flang-rt/lib/FortranFloat128Math/log10.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/log10.cpp
rename to flang-rt/lib/FortranFloat128Math/log10.cpp
index 9a83f57b6c736d..af61f8762371b9 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/log10.cpp
+++ b/flang-rt/lib/FortranFloat128Math/log10.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/log10.cpp ----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/lround.cpp b/flang-rt/lib/FortranFloat128Math/lround.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/lround.cpp
rename to flang-rt/lib/FortranFloat128Math/lround.cpp
index 65546881157948..24278f1040e9e3 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/lround.cpp
+++ b/flang-rt/lib/FortranFloat128Math/lround.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/lround.cpp ---------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/math-entries.h b/flang-rt/lib/FortranFloat128Math/math-entries.h
similarity index 97%
rename from FortranRuntime/lib/Runtime/Float128Math/math-entries.h
rename to flang-rt/lib/FortranFloat128Math/math-entries.h
index 1449000820f00e..9b13c10836f877 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/math-entries.h
+++ b/flang-rt/lib/FortranFloat128Math/math-entries.h
@@ -1,4 +1,4 @@
-//===-- lib/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,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
-#define FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
+#ifndef FORTRAN_FORTRANFLOAT128MATH_MATH_ENTRIES_H_
+#define FORTRAN_FORTRANFLOAT128MATH_MATH_ENTRIES_H_
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Common/float128.h"
@@ -222,4 +222,4 @@ DEFINE_SIMPLE_ALIAS(Yn, ynl)
 
 } // namespace Fortran::runtime
 
-#endif /* FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_ */
+#endif /* FORTRAN_FORTRANFLOAT128MATH_MATH_ENTRIES_H_ */
diff --git a/FortranRuntime/lib/Runtime/Float128Math/mod-real.cpp b/flang-rt/lib/FortranFloat128Math/mod-real.cpp
similarity index 91%
rename from FortranRuntime/lib/Runtime/Float128Math/mod-real.cpp
rename to flang-rt/lib/FortranFloat128Math/mod-real.cpp
index e3b96d39e76ae6..b3c2b715b21995 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/mod-real.cpp
+++ b/flang-rt/lib/FortranFloat128Math/mod-real.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/mod-real.cpp -------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/modulo-real.cpp b/flang-rt/lib/FortranFloat128Math/modulo-real.cpp
similarity index 91%
rename from FortranRuntime/lib/Runtime/Float128Math/modulo-real.cpp
rename to flang-rt/lib/FortranFloat128Math/modulo-real.cpp
index 8edf59e9f59dd4..f5e3cf8a259a73 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/modulo-real.cpp
+++ b/flang-rt/lib/FortranFloat128Math/modulo-real.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/modulo-real.cpp ----------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/nearest.cpp b/flang-rt/lib/FortranFloat128Math/nearest.cpp
similarity index 91%
rename from FortranRuntime/lib/Runtime/Float128Math/nearest.cpp
rename to flang-rt/lib/FortranFloat128Math/nearest.cpp
index 8b9f142d79ff93..eb34c2ddb6ab48 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/nearest.cpp
+++ b/flang-rt/lib/FortranFloat128Math/nearest.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/nearest.cpp --------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/norm2.cpp b/flang-rt/lib/FortranFloat128Math/norm2.cpp
similarity index 94%
rename from FortranRuntime/lib/Runtime/Float128Math/norm2.cpp
rename to flang-rt/lib/FortranFloat128Math/norm2.cpp
index a0c26e40de0064..d000fde1bb0bea 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/norm2.cpp
+++ b/flang-rt/lib/FortranFloat128Math/norm2.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/norm2.cpp ----------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/Float128Math/numeric-template-specs.h b/flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
similarity index 84%
rename from FortranRuntime/lib/Runtime/Float128Math/numeric-template-specs.h
rename to flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
index 2a843df2d1d861..f34ee5f4e3a8de 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/numeric-template-specs.h
+++ b/flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
@@ -1,4 +1,4 @@
-//===-- lib/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,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
-#define FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
+#ifndef FORTRAN_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
+#define FORTRAN_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
 
 #include "math-entries.h"
 #include "numeric-templates.h"
@@ -52,4 +52,4 @@ template <> struct SQRTTy<F128Type> {
 };
 
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_ */
+#endif /* FORTRAN_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_ */
diff --git a/FortranRuntime/lib/Runtime/Float128Math/pow.cpp b/flang-rt/lib/FortranFloat128Math/pow.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/pow.cpp
rename to flang-rt/lib/FortranFloat128Math/pow.cpp
index c11978ca068f23..f5deb00a556f48 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/pow.cpp
+++ b/flang-rt/lib/FortranFloat128Math/pow.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/pow.cpp ------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/random.cpp b/flang-rt/lib/FortranFloat128Math/random.cpp
similarity index 91%
rename from FortranRuntime/lib/Runtime/Float128Math/random.cpp
rename to flang-rt/lib/FortranFloat128Math/random.cpp
index a9dc3c7a82b673..3a01c2c88b1d66 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/random.cpp
+++ b/flang-rt/lib/FortranFloat128Math/random.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/random.cpp ---------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/Float128Math/round.cpp b/flang-rt/lib/FortranFloat128Math/round.cpp
similarity index 92%
rename from FortranRuntime/lib/Runtime/Float128Math/round.cpp
rename to flang-rt/lib/FortranFloat128Math/round.cpp
index 5a9366b3af4785..3453f4ea8a1a26 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/round.cpp
+++ b/flang-rt/lib/FortranFloat128Math/round.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/round.cpp ----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/rrspacing.cpp b/flang-rt/lib/FortranFloat128Math/rrspacing.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/rrspacing.cpp
rename to flang-rt/lib/FortranFloat128Math/rrspacing.cpp
index 2c501b3512c215..0809815027f859 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/rrspacing.cpp
+++ b/flang-rt/lib/FortranFloat128Math/rrspacing.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/rrspacing.cpp ------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/scale.cpp b/flang-rt/lib/FortranFloat128Math/scale.cpp
similarity index 92%
rename from FortranRuntime/lib/Runtime/Float128Math/scale.cpp
rename to flang-rt/lib/FortranFloat128Math/scale.cpp
index 859c955b8114e0..37528330bfb115 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/scale.cpp
+++ b/flang-rt/lib/FortranFloat128Math/scale.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/scale.cpp ----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/set-exponent.cpp b/flang-rt/lib/FortranFloat128Math/set-exponent.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/set-exponent.cpp
rename to flang-rt/lib/FortranFloat128Math/set-exponent.cpp
index 52258182871a14..52f8f08f7003ef 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/set-exponent.cpp
+++ b/flang-rt/lib/FortranFloat128Math/set-exponent.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/set-exponent.cpp ---------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/sin.cpp b/flang-rt/lib/FortranFloat128Math/sin.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/sin.cpp
rename to flang-rt/lib/FortranFloat128Math/sin.cpp
index 99aa4095c8cf1a..1a24e7c57ba469 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/sin.cpp
+++ b/flang-rt/lib/FortranFloat128Math/sin.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/sin.cpp ------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/sinh.cpp b/flang-rt/lib/FortranFloat128Math/sinh.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/sinh.cpp
rename to flang-rt/lib/FortranFloat128Math/sinh.cpp
index a7dfe36737de43..7a4127cee970cd 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/sinh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/sinh.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/sinh.cpp -----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/spacing.cpp b/flang-rt/lib/FortranFloat128Math/spacing.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/spacing.cpp
rename to flang-rt/lib/FortranFloat128Math/spacing.cpp
index 66a01851965840..d3ed077d5412dc 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/spacing.cpp
+++ b/flang-rt/lib/FortranFloat128Math/spacing.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/spacing.cpp --------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/sqrt.cpp b/flang-rt/lib/FortranFloat128Math/sqrt.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/sqrt.cpp
rename to flang-rt/lib/FortranFloat128Math/sqrt.cpp
index cbc1e503d50fd9..a9f5246f35388f 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/sqrt.cpp
+++ b/flang-rt/lib/FortranFloat128Math/sqrt.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/sqrt.cpp -----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/tan.cpp b/flang-rt/lib/FortranFloat128Math/tan.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/tan.cpp
rename to flang-rt/lib/FortranFloat128Math/tan.cpp
index dbe4627f585f14..dc386c5be6ab74 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/tan.cpp
+++ b/flang-rt/lib/FortranFloat128Math/tan.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/tan.cpp ------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/tanh.cpp b/flang-rt/lib/FortranFloat128Math/tanh.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/tanh.cpp
rename to flang-rt/lib/FortranFloat128Math/tanh.cpp
index 37e40966ced722..5f8af3f1cd8d77 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/tanh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/tanh.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/tanh.cpp -----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/tgamma.cpp b/flang-rt/lib/FortranFloat128Math/tgamma.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/tgamma.cpp
rename to flang-rt/lib/FortranFloat128Math/tgamma.cpp
index 07a019c6d9971f..b1a42cdc5d0f41 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/tgamma.cpp
+++ b/flang-rt/lib/FortranFloat128Math/tgamma.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/tgamma.cpp ---------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/trunc.cpp b/flang-rt/lib/FortranFloat128Math/trunc.cpp
similarity index 91%
rename from FortranRuntime/lib/Runtime/Float128Math/trunc.cpp
rename to flang-rt/lib/FortranFloat128Math/trunc.cpp
index 9f38bdc18e73c4..455204ece3b2f6 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/trunc.cpp
+++ b/flang-rt/lib/FortranFloat128Math/trunc.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/trunc.cpp ----------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/y0.cpp b/flang-rt/lib/FortranFloat128Math/y0.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/y0.cpp
rename to flang-rt/lib/FortranFloat128Math/y0.cpp
index 6eaa3396e7ea07..58bd71105efea6 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/y0.cpp
+++ b/flang-rt/lib/FortranFloat128Math/y0.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/y0.cpp -------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/y1.cpp b/flang-rt/lib/FortranFloat128Math/y1.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/y1.cpp
rename to flang-rt/lib/FortranFloat128Math/y1.cpp
index c9f48ea0e26546..5d7b48e276b6f9 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/y1.cpp
+++ b/flang-rt/lib/FortranFloat128Math/y1.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/y1.cpp -------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/Float128Math/yn.cpp b/flang-rt/lib/FortranFloat128Math/yn.cpp
similarity index 90%
rename from FortranRuntime/lib/Runtime/Float128Math/yn.cpp
rename to flang-rt/lib/FortranFloat128Math/yn.cpp
index 6bc5f4996a88d5..9f19861931d84c 100644
--- a/FortranRuntime/lib/Runtime/Float128Math/yn.cpp
+++ b/flang-rt/lib/FortranFloat128Math/yn.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/Float128Math/yn.cpp -------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/CMakeLists.txt b/flang-rt/lib/flang_rt/CMakeLists.txt
similarity index 98%
rename from FortranRuntime/lib/Runtime/CMakeLists.txt
rename to flang-rt/lib/flang_rt/CMakeLists.txt
index b7f32fe30e422a..dc6fc6323d49a6 100644
--- a/FortranRuntime/lib/Runtime/CMakeLists.txt
+++ b/flang-rt/lib/flang_rt/CMakeLists.txt
@@ -1,4 +1,4 @@
-#===-- lib/Runtime/CMakeLists.txt ------------------------------------------===#
+#===-- lib/flang_rt/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.
@@ -105,7 +105,7 @@ append(${NO_LTO_FLAGS} CMAKE_CXX_FLAGS)
 add_definitions(-U_GLIBCXX_ASSERTIONS)
 add_definitions(-U_LIBCPP_ENABLE_ASSERTIONS)
 
-add_subdirectory(Float128Math)
+add_subdirectory(../FortranFloat128Math Float128Math)
 
 set(sources
   ISO_Fortran_binding.cpp
@@ -312,5 +312,5 @@ if (TARGET flang-new AND TARGET module_files)
 endif()
 
 if (FLANG_CUF_RUNTIME)
-  add_subdirectory(CUDA)
+  add_subdirectory(../CufRuntime CUDA)
 endif()
diff --git a/FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp b/flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp
rename to flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
index 997226b08e96a6..37bc1b9dfe426b 100644
--- a/FortranRuntime/lib/Runtime/ISO_Fortran_binding.cpp
+++ b/flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/ISO_Fortran_binding.cpp ---------------------*- C++ -*-===//
+//===-- 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.
@@ -9,9 +9,9 @@
 // Implements the required interoperability API from ISO_Fortran_binding.h
 // as specified in section 18.5.5 of Fortran 2018.
 
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/type-code.h"
 #include "ISO_Fortran_util.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/type-code.h"
 #include "terminator.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/pointer.h"
diff --git a/FortranRuntime/lib/Runtime/ISO_Fortran_util.h b/flang-rt/lib/flang_rt/ISO_Fortran_util.h
similarity index 91%
rename from FortranRuntime/lib/Runtime/ISO_Fortran_util.h
rename to flang-rt/lib/flang_rt/ISO_Fortran_util.h
index e418266dddccc7..a7bb1d21679063 100644
--- a/FortranRuntime/lib/Runtime/ISO_Fortran_util.h
+++ b/flang-rt/lib/flang_rt/ISO_Fortran_util.h
@@ -1,4 +1,4 @@
-//===-- lib/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,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_
-#define FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_
+#ifndef FORTRAN_FLANG_RT_ISO_FORTRAN_UTIL_H_
+#define FORTRAN_FLANG_RT_ISO_FORTRAN_UTIL_H_
 
 // Internal utils for establishing CFI_cdesc_t descriptors.
 
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/type-code.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/type-code.h"
 #include "terminator.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 /* FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_ */
+#endif /* FORTRAN_FLANG_RT_ISO_FORTRAN_UTIL_H_ */
diff --git a/FortranRuntime/lib/Runtime/allocatable.cpp b/flang-rt/lib/flang_rt/allocatable.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/allocatable.cpp
rename to flang-rt/lib/flang_rt/allocatable.cpp
index 4a3b89f4879c12..b9be74f8cb6f1b 100644
--- a/FortranRuntime/lib/Runtime/allocatable.cpp
+++ b/flang-rt/lib/flang_rt/allocatable.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/allocatable.cpp -----------------------------*- C++ -*-===//
+//===-- 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,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/allocatable.h"
-#include "FortranRuntime/Runtime/descriptor.h"
 #include "assign-impl.h"
 #include "derived.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "type-info.h"
diff --git a/FortranRuntime/lib/Runtime/allocator-registry.cpp b/flang-rt/lib/flang_rt/allocator-registry.cpp
similarity index 91%
rename from FortranRuntime/lib/Runtime/allocator-registry.cpp
rename to flang-rt/lib/flang_rt/allocator-registry.cpp
index 17883e5c54870d..538feceec13db6 100644
--- a/FortranRuntime/lib/Runtime/allocator-registry.cpp
+++ b/flang-rt/lib/flang_rt/allocator-registry.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/allocator-registry.cpp ----------------------*- C++ -*-===//
+//===-- 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,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/allocator-registry.h"
+#include "flang-rt/flang_rt/allocator-registry.h"
 #include "terminator.h"
 
 namespace Fortran::runtime {
diff --git a/FortranRuntime/lib/Runtime/array-constructor.cpp b/flang-rt/lib/flang_rt/array-constructor.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/array-constructor.cpp
rename to flang-rt/lib/flang_rt/array-constructor.cpp
index 002dfba2c066f5..daaa1e3b04a3b6 100644
--- a/FortranRuntime/lib/Runtime/array-constructor.cpp
+++ b/flang-rt/lib/flang_rt/array-constructor.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/array-constructor.cpp -----------------------*- C++ -*-===//
+//===-- 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,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/array-constructor.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/array-constructor.h"
 #include "derived.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "type-info.h"
diff --git a/FortranRuntime/lib/Runtime/assign-impl.h b/flang-rt/lib/flang_rt/assign-impl.h
similarity index 100%
rename from FortranRuntime/lib/Runtime/assign-impl.h
rename to flang-rt/lib/flang_rt/assign-impl.h
diff --git a/FortranRuntime/lib/Runtime/assign.cpp b/flang-rt/lib/flang_rt/assign.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/assign.cpp
rename to flang-rt/lib/flang_rt/assign.cpp
index 3a1486ace928a2..4916fc48888189 100644
--- a/FortranRuntime/lib/Runtime/assign.cpp
+++ b/flang-rt/lib/flang_rt/assign.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/assign.cpp ----------------------------------*- C++ -*-===//
+//===-- 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,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/assign.h"
-#include "FortranRuntime/Runtime/descriptor.h"
 #include "assign-impl.h"
 #include "derived.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/FortranRuntime/lib/Runtime/buffer.cpp b/flang-rt/lib/flang_rt/buffer.cpp
similarity index 93%
rename from FortranRuntime/lib/Runtime/buffer.cpp
rename to flang-rt/lib/flang_rt/buffer.cpp
index ce78fe34503c46..9913cdf2e7ec40 100644
--- a/FortranRuntime/lib/Runtime/buffer.cpp
+++ b/flang-rt/lib/flang_rt/buffer.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/buffer.cpp ----------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/buffer.h b/flang-rt/lib/flang_rt/buffer.h
similarity index 97%
rename from FortranRuntime/lib/Runtime/buffer.h
rename to flang-rt/lib/flang_rt/buffer.h
index 52df0f10813c25..eb9b0712819a6c 100644
--- a/FortranRuntime/lib/Runtime/buffer.h
+++ b/flang-rt/lib/flang_rt/buffer.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/buffer.h ------------------------------------*- C++ -*-===//
+//===-- lib/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,10 +8,10 @@
 
 // External file buffering
 
-#ifndef FORTRAN_RUNTIME_BUFFER_H_
-#define FORTRAN_RUNTIME_BUFFER_H_
+#ifndef FORTRAN_FLANG_RT_BUFFER_H_
+#define FORTRAN_FLANG_RT_BUFFER_H_
 
-#include "FortranRuntime/Runtime/memory.h"
+#include "flang-rt/flang_rt/memory.h"
 #include "io-error.h"
 #include "flang/Runtime/freestanding-tools.h"
 #include <algorithm>
@@ -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 /* FORTRAN_FLANG_RT_BUFFER_H_ */
diff --git a/FortranRuntime/lib/Runtime/character.cpp b/flang-rt/lib/flang_rt/character.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/character.cpp
rename to flang-rt/lib/flang_rt/character.cpp
index 1f3edd6e80392e..aeb26098c399c8 100644
--- a/FortranRuntime/lib/Runtime/character.cpp
+++ b/flang-rt/lib/flang_rt/character.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/character.cpp -------------------------------*- C++ -*-===//
+//===-- 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,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/character.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Common/bit-population-count.h"
diff --git a/FortranRuntime/lib/Runtime/command.cpp b/flang-rt/lib/flang_rt/command.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/command.cpp
rename to flang-rt/lib/flang_rt/command.cpp
index 64b2e62461dd58..5c7497518f3da3 100644
--- a/FortranRuntime/lib/Runtime/command.cpp
+++ b/flang-rt/lib/flang_rt/command.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/command.cpp ---------------------------------*- C++ -*-===//
+//===-- 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,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/command.h"
-#include "FortranRuntime/Runtime/descriptor.h"
 #include "environment.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/FortranRuntime/lib/Runtime/complex-powi.cpp b/flang-rt/lib/flang_rt/complex-powi.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/complex-powi.cpp
rename to flang-rt/lib/flang_rt/complex-powi.cpp
index 2eacf56386b193..90013c117aea41 100644
--- a/FortranRuntime/lib/Runtime/complex-powi.cpp
+++ b/flang-rt/lib/flang_rt/complex-powi.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/complex-powi.cpp ----------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/complex-reduction.c b/flang-rt/lib/flang_rt/complex-reduction.c
similarity index 98%
rename from FortranRuntime/lib/Runtime/complex-reduction.c
rename to flang-rt/lib/flang_rt/complex-reduction.c
index 138174e9122b1c..23f1edb58b2d4e 100644
--- a/FortranRuntime/lib/Runtime/complex-reduction.c
+++ b/flang-rt/lib/flang_rt/complex-reduction.c
@@ -1,4 +1,4 @@
-/*===-- lib/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.
diff --git a/FortranRuntime/lib/Runtime/complex-reduction.h b/flang-rt/lib/flang_rt/complex-reduction.h
similarity index 97%
rename from FortranRuntime/lib/Runtime/complex-reduction.h
rename to flang-rt/lib/flang_rt/complex-reduction.h
index e8e287215b7d97..b386b25cd0fff8 100644
--- a/FortranRuntime/lib/Runtime/complex-reduction.h
+++ b/flang-rt/lib/flang_rt/complex-reduction.h
@@ -1,4 +1,4 @@
-/*===-- lib/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.
@@ -11,8 +11,8 @@
  * with C++ build compilers that don't support C's _Complex.
  */
 
-#ifndef FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
-#define FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
+#ifndef FORTRAN_FLANG_RT_COMPLEX_REDUCTION_H_
+#define FORTRAN_FLANG_RT_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 /* FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_ */
+#endif /* FORTRAN_FLANG_RT_COMPLEX_REDUCTION_H_ */
diff --git a/FortranRuntime/lib/Runtime/connection.cpp b/flang-rt/lib/flang_rt/connection.cpp
similarity index 97%
rename from FortranRuntime/lib/Runtime/connection.cpp
rename to flang-rt/lib/flang_rt/connection.cpp
index f9e91f1f193ba0..d623190f22f6f9 100644
--- a/FortranRuntime/lib/Runtime/connection.cpp
+++ b/flang-rt/lib/flang_rt/connection.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/connection.cpp ------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/connection.h b/flang-rt/lib/flang_rt/connection.h
similarity index 96%
rename from FortranRuntime/lib/Runtime/connection.h
rename to flang-rt/lib/flang_rt/connection.h
index e078bfb9f0f7e7..f8b9b3f9debcda 100644
--- a/FortranRuntime/lib/Runtime/connection.h
+++ b/flang-rt/lib/flang_rt/connection.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/connection.h --------------------------------*- C++ -*-===//
+//===-- lib/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_CONNECTION_H_
-#define FORTRAN_RUNTIME_CONNECTION_H_
+#ifndef FORTRAN_FLANG_RT_CONNECTION_H_
+#define FORTRAN_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_CONNECTION_H_ */
+#endif /* FORTRAN_FLANG_RT_CONNECTION_H_ */
diff --git a/FortranRuntime/lib/Runtime/copy.cpp b/flang-rt/lib/flang_rt/copy.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/copy.cpp
rename to flang-rt/lib/flang_rt/copy.cpp
index 1049b925f68e5c..fc5c0af6b95851 100644
--- a/FortranRuntime/lib/Runtime/copy.cpp
+++ b/flang-rt/lib/flang_rt/copy.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/copy.cpp ------------------------------------*- C++ -*-===//
+//===-- 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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "copy.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "stack.h"
 #include "terminator.h"
 #include "type-info.h"
diff --git a/FortranRuntime/lib/Runtime/copy.h b/flang-rt/lib/flang_rt/copy.h
similarity index 78%
rename from FortranRuntime/lib/Runtime/copy.h
rename to flang-rt/lib/flang_rt/copy.h
index 3d179d0bec91a7..8f27c3a90b7847 100644
--- a/FortranRuntime/lib/Runtime/copy.h
+++ b/flang-rt/lib/flang_rt/copy.h
@@ -1,4 +1,4 @@
-//===-- lib/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 FORTRAN_FLANG_RT_COPY_H_
+#define FORTRAN_FLANG_RT_COPY_H_
 
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/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 /* FORTRAN_FLANG_RT_COPY_H_ */
diff --git a/FortranRuntime/lib/Runtime/derived-api.cpp b/flang-rt/lib/flang_rt/derived-api.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/derived-api.cpp
rename to flang-rt/lib/flang_rt/derived-api.cpp
index 176fc0849f25cf..faf24508981bae 100644
--- a/FortranRuntime/lib/Runtime/derived-api.cpp
+++ b/flang-rt/lib/flang_rt/derived-api.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/derived-api.cpp -----------------------------*- C++ -*-===//
+//===-- 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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/derived-api.h"
-#include "FortranRuntime/Runtime/descriptor.h"
 #include "derived.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "type-info.h"
diff --git a/FortranRuntime/lib/Runtime/derived.cpp b/flang-rt/lib/flang_rt/derived.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/derived.cpp
rename to flang-rt/lib/flang_rt/derived.cpp
index cb2dca24bb4758..9b17a0d437375c 100644
--- a/FortranRuntime/lib/Runtime/derived.cpp
+++ b/flang-rt/lib/flang_rt/derived.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/derived.cpp ---------------------------------*- C++ -*-===//
+//===-- 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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "derived.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/FortranRuntime/lib/Runtime/derived.h b/flang-rt/lib/flang_rt/derived.h
similarity index 88%
rename from FortranRuntime/lib/Runtime/derived.h
rename to flang-rt/lib/flang_rt/derived.h
index e03e657f01cee9..3d6563f39c0663 100644
--- a/FortranRuntime/lib/Runtime/derived.h
+++ b/flang-rt/lib/flang_rt/derived.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/derived.h -----------------------------------*- C++ -*-===//
+//===-- lib/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 FORTRAN_FLANG_RT_DERIVED_H_
+#define FORTRAN_FLANG_RT_DERIVED_H_
 
 #include "flang/Common/api-attrs.h"
 
@@ -40,4 +40,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 /* FORTRAN_FLANG_RT_DERIVED_H_ */
diff --git a/FortranRuntime/lib/Runtime/descriptor-io.cpp b/flang-rt/lib/flang_rt/descriptor-io.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/descriptor-io.cpp
rename to flang-rt/lib/flang_rt/descriptor-io.cpp
index 896fad16a67e8a..c5cfa4d7fc5972 100644
--- a/FortranRuntime/lib/Runtime/descriptor-io.cpp
+++ b/flang-rt/lib/flang_rt/descriptor-io.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/descriptor-io.cpp ---------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/descriptor-io.h b/flang-rt/lib/flang_rt/descriptor-io.h
similarity index 98%
rename from FortranRuntime/lib/Runtime/descriptor-io.h
rename to flang-rt/lib/flang_rt/descriptor-io.h
index 30d1bd48457728..2e48b4a0353e2a 100644
--- a/FortranRuntime/lib/Runtime/descriptor-io.h
+++ b/flang-rt/lib/flang_rt/descriptor-io.h
@@ -1,4 +1,4 @@
-//===-- lib/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,17 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_DESCRIPTOR_IO_H_
-#define FORTRAN_RUNTIME_DESCRIPTOR_IO_H_
+#ifndef FORTRAN_FLANG_RT_DESCRIPTOR_IO_H_
+#define FORTRAN_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;
 // some scalar I/O data transfer APIs could be changed to bypass their use
 // of descriptors in the future for better efficiency.)
 
-#include "FortranRuntime/Runtime/descriptor.h"
 #include "edit-input.h"
 #include "edit-output.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "io-stmt.h"
 #include "namelist.h"
 #include "terminator.h"
@@ -608,4 +608,4 @@ static RT_API_ATTRS bool DescriptorIO(IoStatementState &io,
   return false;
 }
 } // namespace Fortran::runtime::io::descr
-#endif /* FORTRAN_RUNTIME_DESCRIPTOR_IO_H_ */
+#endif /* FORTRAN_FLANG_RT_DESCRIPTOR_IO_H_ */
diff --git a/FortranRuntime/lib/Runtime/descriptor.cpp b/flang-rt/lib/flang_rt/descriptor.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/descriptor.cpp
rename to flang-rt/lib/flang_rt/descriptor.cpp
index 96fd48eb6687a9..77536e760ad1cd 100644
--- a/FortranRuntime/lib/Runtime/descriptor.cpp
+++ b/flang-rt/lib/flang_rt/descriptor.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/descriptor.cpp ------------------------------*- C++ -*-===//
+//===-- 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,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/allocator-registry.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "ISO_Fortran_util.h"
 #include "derived.h"
+#include "flang-rt/flang_rt/allocator-registry.h"
 #include "memory.h"
 #include "stat.h"
 #include "terminator.h"
diff --git a/FortranRuntime/lib/Runtime/dot-product.cpp b/flang-rt/lib/flang_rt/dot-product.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/dot-product.cpp
rename to flang-rt/lib/flang_rt/dot-product.cpp
index 2992cbb1f39ad6..01e15ad331d7c4 100644
--- a/FortranRuntime/lib/Runtime/dot-product.cpp
+++ b/flang-rt/lib/flang_rt/dot-product.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/dot-product.cpp -----------------------------*- C++ -*-===//
+//===-- 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.
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "float.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/FortranRuntime/lib/Runtime/edit-input.cpp b/flang-rt/lib/flang_rt/edit-input.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/edit-input.cpp
rename to flang-rt/lib/flang_rt/edit-input.cpp
index 6ebb0e7aca4ade..9e3f102cf86684 100644
--- a/FortranRuntime/lib/Runtime/edit-input.cpp
+++ b/flang-rt/lib/flang_rt/edit-input.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/edit-input.cpp ------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/edit-input.h b/flang-rt/lib/flang_rt/edit-input.h
similarity index 90%
rename from FortranRuntime/lib/Runtime/edit-input.h
rename to flang-rt/lib/flang_rt/edit-input.h
index f88f6daa47be79..59f601afa306a3 100644
--- a/FortranRuntime/lib/Runtime/edit-input.h
+++ b/flang-rt/lib/flang_rt/edit-input.h
@@ -1,4 +1,4 @@
-//===-- lib/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,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_EDIT_INPUT_H_
-#define FORTRAN_RUNTIME_EDIT_INPUT_H_
+#ifndef FORTRAN_FLANG_RT_EDIT_INPUT_H_
+#define FORTRAN_FLANG_RT_EDIT_INPUT_H_
 
 #include "format.h"
 #include "io-stmt.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 /* FORTRAN_RUNTIME_EDIT_INPUT_H_ */
+#endif /* FORTRAN_FLANG_RT_EDIT_INPUT_H_ */
diff --git a/FortranRuntime/lib/Runtime/edit-output.cpp b/flang-rt/lib/flang_rt/edit-output.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/edit-output.cpp
rename to flang-rt/lib/flang_rt/edit-output.cpp
index ccaf8085f016fd..2e353f1ad80a21 100644
--- a/FortranRuntime/lib/Runtime/edit-output.cpp
+++ b/flang-rt/lib/flang_rt/edit-output.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/edit-output.cpp -----------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/edit-output.h b/flang-rt/lib/flang_rt/edit-output.h
similarity index 96%
rename from FortranRuntime/lib/Runtime/edit-output.h
rename to flang-rt/lib/flang_rt/edit-output.h
index 7e6c6cdedde3ac..325658b4a25dc6 100644
--- a/FortranRuntime/lib/Runtime/edit-output.h
+++ b/flang-rt/lib/flang_rt/edit-output.h
@@ -1,4 +1,4 @@
-//===-- lib/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 FORTRAN_FLANG_RT_EDIT_OUTPUT_H_
+#define FORTRAN_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
@@ -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 /* FORTRAN_FLANG_RT_EDIT_OUTPUT_H_ */
diff --git a/FortranRuntime/lib/Runtime/emit-encoded.h b/flang-rt/lib/flang_rt/emit-encoded.h
similarity index 94%
rename from FortranRuntime/lib/Runtime/emit-encoded.h
rename to flang-rt/lib/flang_rt/emit-encoded.h
index 11163a41720795..87216e5808a286 100644
--- a/FortranRuntime/lib/Runtime/emit-encoded.h
+++ b/flang-rt/lib/flang_rt/emit-encoded.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/emit-encoded.h ------------------------------*- C++ -*-===//
+//===-- lib/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 FORTRAN_FLANG_RT_EMIT_ENCODED_H_
+#define FORTRAN_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 /* FORTRAN_FLANG_RT_EMIT_ENCODED_H_ */
diff --git a/FortranRuntime/lib/Runtime/environment-default-list.h b/flang-rt/lib/flang_rt/environment-default-list.h
similarity index 100%
rename from FortranRuntime/lib/Runtime/environment-default-list.h
rename to flang-rt/lib/flang_rt/environment-default-list.h
diff --git a/FortranRuntime/lib/Runtime/environment.cpp b/flang-rt/lib/flang_rt/environment.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/environment.cpp
rename to flang-rt/lib/flang_rt/environment.cpp
index 272914877988a5..9ff65f1e60ddcd 100644
--- a/FortranRuntime/lib/Runtime/environment.cpp
+++ b/flang-rt/lib/flang_rt/environment.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/environment.cpp -----------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/environment.h b/flang-rt/lib/flang_rt/environment.h
similarity index 91%
rename from FortranRuntime/lib/Runtime/environment.h
rename to flang-rt/lib/flang_rt/environment.h
index 7d10b3a2b934bf..125c9b39528b94 100644
--- a/FortranRuntime/lib/Runtime/environment.h
+++ b/flang-rt/lib/flang_rt/environment.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/environment.h -------------------------------*- C++ -*-===//
+//===-- lib/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 FORTRAN_FLANG_RT_ENVIRONMENT_H_
+#define FORTRAN_FLANG_RT_ENVIRONMENT_H_
 
 #include "flang/Common/decimal.h"
 #include "flang/Common/optional.h"
@@ -64,4 +64,4 @@ RT_OFFLOAD_VAR_GROUP_END
 
 } // namespace Fortran::runtime
 
-#endif /* FORTRAN_RUNTIME_ENVIRONMENT_H_ */
+#endif /* FORTRAN_FLANG_RT_ENVIRONMENT_H_ */
diff --git a/FortranRuntime/lib/Runtime/exceptions.cpp b/flang-rt/lib/flang_rt/exceptions.cpp
similarity index 97%
rename from FortranRuntime/lib/Runtime/exceptions.cpp
rename to flang-rt/lib/flang_rt/exceptions.cpp
index 7739130ae2346a..9ad5fe6849b076 100644
--- a/FortranRuntime/lib/Runtime/exceptions.cpp
+++ b/flang-rt/lib/flang_rt/exceptions.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/exceptions.cpp ------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/execute.cpp b/flang-rt/lib/flang_rt/execute.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/execute.cpp
rename to flang-rt/lib/flang_rt/execute.cpp
index b333c61c8a59f4..d3d42a49737fed 100644
--- a/FortranRuntime/lib/Runtime/execute.cpp
+++ b/flang-rt/lib/flang_rt/execute.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/execute.cpp ---------------------------------*- C++ -*-===//
+//===-- 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,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/execute.h"
-#include "FortranRuntime/Runtime/descriptor.h"
 #include "environment.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/FortranRuntime/lib/Runtime/extensions.cpp b/flang-rt/lib/flang_rt/extensions.cpp
similarity index 97%
rename from FortranRuntime/lib/Runtime/extensions.cpp
rename to flang-rt/lib/flang_rt/extensions.cpp
index bb25fe6ee9d886..4cd9791cd0e5cb 100644
--- a/FortranRuntime/lib/Runtime/extensions.cpp
+++ b/flang-rt/lib/flang_rt/extensions.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/extensions.cpp ------------------------------*- C++ -*-===//
+//===-- 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,8 +10,8 @@
 // extensions that will eventually be implemented in Fortran.
 
 #include "flang/Runtime/extensions.h"
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/io-api-funcs.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/io-api-funcs.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Runtime/command.h"
diff --git a/FortranRuntime/lib/Runtime/external-unit.cpp b/flang-rt/lib/flang_rt/external-unit.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/external-unit.cpp
rename to flang-rt/lib/flang_rt/external-unit.cpp
index f5fa2c31dafc4e..1942cc1ff4daec 100644
--- a/FortranRuntime/lib/Runtime/external-unit.cpp
+++ b/flang-rt/lib/flang_rt/external-unit.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/external-unit.cpp ---------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/extrema.cpp b/flang-rt/lib/flang_rt/extrema.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/extrema.cpp
rename to flang-rt/lib/flang_rt/extrema.cpp
index be9da63d7bd6b8..7a230afc4190c6 100644
--- a/FortranRuntime/lib/Runtime/extrema.cpp
+++ b/flang-rt/lib/flang_rt/extrema.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/extrema.cpp ---------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/file.cpp b/flang-rt/lib/flang_rt/file.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/file.cpp
rename to flang-rt/lib/flang_rt/file.cpp
index de52dafd12df9a..d98c8afeca3514 100644
--- a/FortranRuntime/lib/Runtime/file.cpp
+++ b/flang-rt/lib/flang_rt/file.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/file.cpp ------------------------------------*- C++ -*-===//
+//===-- 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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "file.h"
-#include "FortranRuntime/Runtime/memory.h"
+#include "flang-rt/flang_rt/memory.h"
 #include "tools.h"
 #include "flang/Runtime/magic-numbers.h"
 #include <algorithm>
diff --git a/FortranRuntime/lib/Runtime/file.h b/flang-rt/lib/flang_rt/file.h
similarity index 94%
rename from FortranRuntime/lib/Runtime/file.h
rename to flang-rt/lib/flang_rt/file.h
index 60ddf2a2741610..b4068e3dce0d14 100644
--- a/FortranRuntime/lib/Runtime/file.h
+++ b/flang-rt/lib/flang_rt/file.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/file.h --------------------------------------*- C++ -*-===//
+//===-- lib/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,10 +8,10 @@
 
 // Raw system I/O wrappers
 
-#ifndef FORTRAN_RUNTIME_FILE_H_
-#define FORTRAN_RUNTIME_FILE_H_
+#ifndef FORTRAN_FLANG_RT_FILE_H_
+#define FORTRAN_FLANG_RT_FILE_H_
 
-#include "FortranRuntime/Runtime/memory.h"
+#include "flang-rt/flang_rt/memory.h"
 #include "io-error.h"
 #include "flang/Common/optional.h"
 #include <cinttypes>
@@ -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 /* FORTRAN_FLANG_RT_FILE_H_ */
diff --git a/FortranRuntime/lib/Runtime/findloc.cpp b/flang-rt/lib/flang_rt/findloc.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/findloc.cpp
rename to flang-rt/lib/flang_rt/findloc.cpp
index da5fe0c0a0a467..8ee4c7c6cf7800 100644
--- a/FortranRuntime/lib/Runtime/findloc.cpp
+++ b/flang-rt/lib/flang_rt/findloc.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/findloc.cpp ---------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/format-implementation.h b/flang-rt/lib/flang_rt/format-implementation.h
similarity index 98%
rename from FortranRuntime/lib/Runtime/format-implementation.h
rename to flang-rt/lib/flang_rt/format-implementation.h
index f17f0a2cb4bfd9..9b7ad6f2ce1fc6 100644
--- a/FortranRuntime/lib/Runtime/format-implementation.h
+++ b/flang-rt/lib/flang_rt/format-implementation.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/format-implementation.h ---------------------*- C++ -*-===//
+//===-- lib/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 FORTRAN_FLANG_RT_FORMAT_IMPLEMENTATION_H_
+#define FORTRAN_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 /* FORTRAN_FLANG_RT_FORMAT_IMPLEMENTATION_H_ */
diff --git a/FortranRuntime/lib/Runtime/format.cpp b/flang-rt/lib/flang_rt/format.cpp
similarity index 93%
rename from FortranRuntime/lib/Runtime/format.cpp
rename to flang-rt/lib/flang_rt/format.cpp
index 73a61f785c23b8..aedf04b8a40a1b 100644
--- a/FortranRuntime/lib/Runtime/format.cpp
+++ b/flang-rt/lib/flang_rt/format.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/format.cpp ----------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/format.h b/flang-rt/lib/flang_rt/format.h
similarity index 97%
rename from FortranRuntime/lib/Runtime/format.h
rename to flang-rt/lib/flang_rt/format.h
index 098a251a04d568..b41eec9564baaa 100644
--- a/FortranRuntime/lib/Runtime/format.h
+++ b/flang-rt/lib/flang_rt/format.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/format.h ------------------------------------*- C++ -*-===//
+//===-- lib/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 FORTRAN_FLANG_RT_FORMAT_H_
+#define FORTRAN_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 /* FORTRAN_FLANG_RT_FORMAT_H_ */
diff --git a/FortranRuntime/lib/Runtime/inquiry.cpp b/flang-rt/lib/flang_rt/inquiry.cpp
similarity index 96%
rename from FortranRuntime/lib/Runtime/inquiry.cpp
rename to flang-rt/lib/flang_rt/inquiry.cpp
index c24492754b4f43..b29ab4ee3c6663 100644
--- a/FortranRuntime/lib/Runtime/inquiry.cpp
+++ b/flang-rt/lib/flang_rt/inquiry.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/inquiry.cpp ---------------------------------*- C++ -*-===//
+//===-- 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.
@@ -10,8 +10,8 @@
 // inquire about shape information of arrays -- LBOUND and SIZE.
 
 #include "flang/Runtime/inquiry.h"
-#include "FortranRuntime/Runtime/descriptor.h"
 #include "copy.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include <algorithm>
diff --git a/FortranRuntime/lib/Runtime/internal-unit.cpp b/flang-rt/lib/flang_rt/internal-unit.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/internal-unit.cpp
rename to flang-rt/lib/flang_rt/internal-unit.cpp
index 4494de9dddc1a1..7775ded1e86d57 100644
--- a/FortranRuntime/lib/Runtime/internal-unit.cpp
+++ b/flang-rt/lib/flang_rt/internal-unit.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/internal-unit.cpp ---------------------------*- C++ -*-===//
+//===-- 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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "internal-unit.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "io-error.h"
 #include "flang/Runtime/freestanding-tools.h"
 #include <algorithm>
diff --git a/FortranRuntime/lib/Runtime/internal-unit.h b/flang-rt/lib/flang_rt/internal-unit.h
similarity index 89%
rename from FortranRuntime/lib/Runtime/internal-unit.h
rename to flang-rt/lib/flang_rt/internal-unit.h
index 7579016f14646d..2f7d0220b84b37 100644
--- a/FortranRuntime/lib/Runtime/internal-unit.h
+++ b/flang-rt/lib/flang_rt/internal-unit.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/internal-unit.h -----------------------------*- C++ -*-===//
+//===-- lib/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_INTERNAL_UNIT_H_
-#define FORTRAN_RUNTIME_INTERNAL_UNIT_H_
+#ifndef FORTRAN_FLANG_RT_INTERNAL_UNIT_H_
+#define FORTRAN_FLANG_RT_INTERNAL_UNIT_H_
 
-#include "FortranRuntime/Runtime/descriptor.h"
 #include "connection.h"
+#include "flang-rt/flang_rt/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_INTERNAL_UNIT_H_ */
+#endif /* FORTRAN_FLANG_RT_INTERNAL_UNIT_H_ */
diff --git a/FortranRuntime/lib/Runtime/io-api-common.h b/flang-rt/lib/flang_rt/io-api-common.h
similarity index 92%
rename from FortranRuntime/lib/Runtime/io-api-common.h
rename to flang-rt/lib/flang_rt/io-api-common.h
index fed1d11d6ce6a6..5ff1b57c73cda6 100644
--- a/FortranRuntime/lib/Runtime/io-api-common.h
+++ b/flang-rt/lib/flang_rt/io-api-common.h
@@ -1,4 +1,4 @@
-//===-- lib/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,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_IO_API_COMMON_H_
-#define FORTRAN_RUNTIME_IO_API_COMMON_H_
+#ifndef FORTRAN_FLANG_RT_IO_API_COMMON_H_
+#define FORTRAN_FLANG_RT_IO_API_COMMON_H_
 
-#include "FortranRuntime/Runtime/io-api-funcs.h"
+#include "flang-rt/flang_rt/io-api-funcs.h"
 #include "io-stmt.h"
 #include "terminator.h"
 #include "unit.h"
@@ -94,4 +94,4 @@ RT_API_ATTRS Cookie BeginExternalListIO(
 }
 
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_RUNTIME_IO_API_COMMON_H_ */
+#endif /* FORTRAN_FLANG_RT_IO_API_COMMON_H_ */
diff --git a/FortranRuntime/lib/Runtime/io-api-minimal.cpp b/flang-rt/lib/flang_rt/io-api-minimal.cpp
similarity index 97%
rename from FortranRuntime/lib/Runtime/io-api-minimal.cpp
rename to flang-rt/lib/flang_rt/io-api-minimal.cpp
index 8cde2333804572..92524430650126 100644
--- a/FortranRuntime/lib/Runtime/io-api-minimal.cpp
+++ b/flang-rt/lib/flang_rt/io-api-minimal.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/io-api-minimal.cpp --------------------------*- C++ -*-===//
+//===-- 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.
@@ -9,8 +9,8 @@
 // Implements the subset of the I/O statement API needed for basic
 // list-directed output (PRINT *) of intrinsic types.
 
-#include "FortranRuntime/Runtime/io-api-funcs.h"
 #include "edit-output.h"
+#include "flang-rt/flang_rt/io-api-funcs.h"
 #include "format.h"
 #include "io-api-common.h"
 #include "io-stmt.h"
diff --git a/FortranRuntime/lib/Runtime/io-api.cpp b/flang-rt/lib/flang_rt/io-api.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/io-api.cpp
rename to flang-rt/lib/flang_rt/io-api.cpp
index fa95d68a004b51..0de1e24f71dac5 100644
--- a/FortranRuntime/lib/Runtime/io-api.cpp
+++ b/flang-rt/lib/flang_rt/io-api.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/io-api.cpp ----------------------------------*- C++ -*-===//
+//===-- 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.
@@ -13,13 +13,13 @@
 // OutputReal{32,64}, OutputComplex{32,64}, OutputAscii, & EndIoStatement()
 // are in runtime/io-api-minimal.cpp.
 
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/io-api-funcs.h"
-#include "FortranRuntime/Runtime/memory.h"
 #include "descriptor-io.h"
 #include "edit-input.h"
 #include "edit-output.h"
 #include "environment.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/io-api-funcs.h"
+#include "flang-rt/flang_rt/memory.h"
 #include "format.h"
 #include "io-api-common.h"
 #include "io-stmt.h"
diff --git a/FortranRuntime/lib/Runtime/io-error.cpp b/flang-rt/lib/flang_rt/io-error.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/io-error.cpp
rename to flang-rt/lib/flang_rt/io-error.cpp
index 053667462058de..215c839d98cc35 100644
--- a/FortranRuntime/lib/Runtime/io-error.cpp
+++ b/flang-rt/lib/flang_rt/io-error.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/io-error.cpp --------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/io-error.h b/flang-rt/lib/flang_rt/io-error.h
similarity index 90%
rename from FortranRuntime/lib/Runtime/io-error.h
rename to flang-rt/lib/flang_rt/io-error.h
index e2018cc2ea0ab1..7798d0830a1323 100644
--- a/FortranRuntime/lib/Runtime/io-error.h
+++ b/flang-rt/lib/flang_rt/io-error.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/io-error.h ----------------------------------*- C++ -*-===//
+//===-- lib/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,11 +12,11 @@
 // 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 FORTRAN_FLANG_RT_IO_ERROR_H_
+#define FORTRAN_FLANG_RT_IO_ERROR_H_
 
-#include "FortranRuntime/Runtime/iostat-funcs.h"
-#include "FortranRuntime/Runtime/memory.h"
+#include "flang-rt/flang_rt/iostat-funcs.h"
+#include "flang-rt/flang_rt/memory.h"
 #include "terminator.h"
 #include <cinttypes>
 
@@ -78,4 +78,4 @@ class IoErrorHandler : public Terminator {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_RUNTIME_IO_ERROR_H_ */
+#endif /* FORTRAN_FLANG_RT_IO_ERROR_H_ */
diff --git a/FortranRuntime/lib/Runtime/io-stmt.cpp b/flang-rt/lib/flang_rt/io-stmt.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/io-stmt.cpp
rename to flang-rt/lib/flang_rt/io-stmt.cpp
index fe02e221671665..7c243a8c934a7a 100644
--- a/FortranRuntime/lib/Runtime/io-stmt.cpp
+++ b/flang-rt/lib/flang_rt/io-stmt.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/io-stmt.cpp ---------------------------------*- C++ -*-===//
+//===-- 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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "io-stmt.h"
-#include "FortranRuntime/Runtime/memory.h"
 #include "connection.h"
 #include "emit-encoded.h"
+#include "flang-rt/flang_rt/memory.h"
 #include "format.h"
 #include "tools.h"
 #include "unit.h"
diff --git a/FortranRuntime/lib/Runtime/io-stmt.h b/flang-rt/lib/flang_rt/io-stmt.h
similarity index 99%
rename from FortranRuntime/lib/Runtime/io-stmt.h
rename to flang-rt/lib/flang_rt/io-stmt.h
index 21746ff1966218..78bc42502be687 100644
--- a/FortranRuntime/lib/Runtime/io-stmt.h
+++ b/flang-rt/lib/flang_rt/io-stmt.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/io-stmt.h -----------------------------------*- C++ -*-===//
+//===-- lib/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,13 +8,13 @@
 
 // Representations of the state of an I/O statement in progress
 
-#ifndef FORTRAN_RUNTIME_IO_STMT_H_
-#define FORTRAN_RUNTIME_IO_STMT_H_
+#ifndef FORTRAN_FLANG_RT_IO_STMT_H_
+#define FORTRAN_FLANG_RT_IO_STMT_H_
 
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/io-api-funcs.h"
 #include "connection.h"
 #include "file.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/io-api-funcs.h"
 #include "format.h"
 #include "internal-unit.h"
 #include "io-error.h"
@@ -789,4 +789,4 @@ class ErroneousIoStatementState : public IoStatementBase {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_RUNTIME_IO_STMT_H_ */
+#endif /* FORTRAN_FLANG_RT_IO_STMT_H_ */
diff --git a/FortranRuntime/lib/Runtime/iostat.cpp b/flang-rt/lib/flang_rt/iostat.cpp
similarity index 97%
rename from FortranRuntime/lib/Runtime/iostat.cpp
rename to flang-rt/lib/flang_rt/iostat.cpp
index 8d769a09252fd6..39f4474dcf7229 100644
--- a/FortranRuntime/lib/Runtime/iostat.cpp
+++ b/flang-rt/lib/flang_rt/iostat.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/iostat.cpp ----------------------------------*- C++ -*-===//
+//===-- 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.
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/iostat-funcs.h"
+#include "flang-rt/flang_rt/iostat-funcs.h"
 
 namespace Fortran::runtime::io {
 RT_OFFLOAD_API_GROUP_BEGIN
diff --git a/FortranRuntime/lib/Runtime/lock.h b/flang-rt/lib/flang_rt/lock.h
similarity index 94%
rename from FortranRuntime/lib/Runtime/lock.h
rename to flang-rt/lib/flang_rt/lock.h
index 69ff6403736dae..955059a711c47d 100644
--- a/FortranRuntime/lib/Runtime/lock.h
+++ b/flang-rt/lib/flang_rt/lock.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/lock.h --------------------------------------*- C++ -*-===//
+//===-- lib/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 FORTRAN_FLANG_RT_LOCK_H_
+#define FORTRAN_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 /* FORTRAN_FLANG_RT_LOCK_H_ */
diff --git a/FortranRuntime/lib/Runtime/main.cpp b/flang-rt/lib/flang_rt/main.cpp
similarity index 95%
rename from FortranRuntime/lib/Runtime/main.cpp
rename to flang-rt/lib/flang_rt/main.cpp
index 3fe985e524548d..71ed7f8319f60f 100644
--- a/FortranRuntime/lib/Runtime/main.cpp
+++ b/flang-rt/lib/flang_rt/main.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/main.cpp ------------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/matmul-transpose.cpp b/flang-rt/lib/flang_rt/matmul-transpose.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/matmul-transpose.cpp
rename to flang-rt/lib/flang_rt/matmul-transpose.cpp
index ec5388e3fca793..2c7c4a89117f04 100644
--- a/FortranRuntime/lib/Runtime/matmul-transpose.cpp
+++ b/flang-rt/lib/flang_rt/matmul-transpose.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/matmul-transpose.cpp ------------------------*- C++ -*-===//
+//===-- 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,7 +21,7 @@
 // to use the faster BLAS routines.
 
 #include "flang/Runtime/matmul-transpose.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Common/optional.h"
diff --git a/FortranRuntime/lib/Runtime/matmul.cpp b/flang-rt/lib/flang_rt/matmul.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/matmul.cpp
rename to flang-rt/lib/flang_rt/matmul.cpp
index 01be7f7c75bc45..8157911f34fd38 100644
--- a/FortranRuntime/lib/Runtime/matmul.cpp
+++ b/flang-rt/lib/flang_rt/matmul.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/matmul.cpp ----------------------------------*- C++ -*-===//
+//===-- 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,7 +20,7 @@
 // Places where BLAS routines could be called are marked as TODO items.
 
 #include "flang/Runtime/matmul.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Common/optional.h"
diff --git a/FortranRuntime/lib/Runtime/memory.cpp b/flang-rt/lib/flang_rt/memory.cpp
similarity index 92%
rename from FortranRuntime/lib/Runtime/memory.cpp
rename to flang-rt/lib/flang_rt/memory.cpp
index a4cebf7edc6c64..66aa5be0cddc60 100644
--- a/FortranRuntime/lib/Runtime/memory.cpp
+++ b/flang-rt/lib/flang_rt/memory.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/memory.cpp ----------------------------------*- C++ -*-===//
+//===-- 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,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/memory.h"
+#include "flang-rt/flang_rt/memory.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Runtime/freestanding-tools.h"
diff --git a/FortranRuntime/lib/Runtime/misc-intrinsic.cpp b/flang-rt/lib/flang_rt/misc-intrinsic.cpp
similarity index 97%
rename from FortranRuntime/lib/Runtime/misc-intrinsic.cpp
rename to flang-rt/lib/flang_rt/misc-intrinsic.cpp
index 91a3b136e009a5..00098c5b4e20b0 100644
--- a/FortranRuntime/lib/Runtime/misc-intrinsic.cpp
+++ b/flang-rt/lib/flang_rt/misc-intrinsic.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/misc-intrinsic.cpp --------------------------*- C++ -*-===//
+//===-- 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,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/misc-intrinsic.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Common/optional.h"
diff --git a/FortranRuntime/lib/Runtime/namelist.cpp b/flang-rt/lib/flang_rt/namelist.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/namelist.cpp
rename to flang-rt/lib/flang_rt/namelist.cpp
index 46036549bcd316..92dbd33b7f9609 100644
--- a/FortranRuntime/lib/Runtime/namelist.cpp
+++ b/flang-rt/lib/flang_rt/namelist.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/namelist.cpp --------------------------------*- C++ -*-===//
+//===-- 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.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "namelist.h"
-#include "FortranRuntime/Runtime/io-api-funcs.h"
 #include "descriptor-io.h"
 #include "emit-encoded.h"
+#include "flang-rt/flang_rt/io-api-funcs.h"
 #include "io-stmt.h"
 #include <algorithm>
 #include <cstring>
diff --git a/FortranRuntime/lib/Runtime/namelist.h b/flang-rt/lib/flang_rt/namelist.h
similarity index 91%
rename from FortranRuntime/lib/Runtime/namelist.h
rename to flang-rt/lib/flang_rt/namelist.h
index 04432f8a08cb97..519ec5dd2ddbc5 100644
--- a/FortranRuntime/lib/Runtime/namelist.h
+++ b/flang-rt/lib/flang_rt/namelist.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/namelist.h ----------------------------------*- C++ -*-===//
+//===-- lib/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 FORTRAN_FLANG_RT_NAMELIST_H_
+#define FORTRAN_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 /* FORTRAN_FLANG_RT_NAMELIST_H_ */
diff --git a/FortranRuntime/lib/Runtime/non-tbp-dio.cpp b/flang-rt/lib/flang_rt/non-tbp-dio.cpp
similarity index 93%
rename from FortranRuntime/lib/Runtime/non-tbp-dio.cpp
rename to flang-rt/lib/flang_rt/non-tbp-dio.cpp
index 9fa04397bc9610..3aade68cbb6d3e 100644
--- a/FortranRuntime/lib/Runtime/non-tbp-dio.cpp
+++ b/flang-rt/lib/flang_rt/non-tbp-dio.cpp
@@ -1,4 +1,4 @@
-//===-- lib/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.
diff --git a/FortranRuntime/lib/Runtime/non-tbp-dio.h b/flang-rt/lib/flang_rt/non-tbp-dio.h
similarity index 91%
rename from FortranRuntime/lib/Runtime/non-tbp-dio.h
rename to flang-rt/lib/flang_rt/non-tbp-dio.h
index 426d5a92fd37d4..dfc96603a8eb1c 100644
--- a/FortranRuntime/lib/Runtime/non-tbp-dio.h
+++ b/flang-rt/lib/flang_rt/non-tbp-dio.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/non-tbp-dio.h -------------------------------*- C++ -*-===//
+//===-- lib/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 FORTRAN_FLANG_RT_NON_TBP_DIO_H_
+#define FORTRAN_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 /* FORTRAN_FLANG_RT_NON_TBP_DIO_H_ */
diff --git a/FortranRuntime/lib/Runtime/numeric-templates.h b/flang-rt/lib/flang_rt/numeric-templates.h
similarity index 98%
rename from FortranRuntime/lib/Runtime/numeric-templates.h
rename to flang-rt/lib/flang_rt/numeric-templates.h
index 159b8b0b9579ad..0471b89f9153ad 100644
--- a/FortranRuntime/lib/Runtime/numeric-templates.h
+++ b/flang-rt/lib/flang_rt/numeric-templates.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/numeric-templates.h -------------------------*- C++ -*-===//
+//===-- lib/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 FORTRAN_FLANG_RT_NUMERIC_TEMPLATES_H_
+#define FORTRAN_FLANG_RT_NUMERIC_TEMPLATES_H_
 
 #include "terminator.h"
 #include "tools.h"
@@ -465,4 +465,4 @@ template <typename T> inline RT_API_ATTRS T ErfcScaled(T arg) {
 
 } // namespace Fortran::runtime
 
-#endif /* FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_ */
+#endif /* FORTRAN_FLANG_RT_NUMERIC_TEMPLATES_H_ */
diff --git a/FortranRuntime/lib/Runtime/numeric.cpp b/flang-rt/lib/flang_rt/numeric.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/numeric.cpp
rename to flang-rt/lib/flang_rt/numeric.cpp
index b0f68a7fc81d29..4c2c0394ede188 100644
--- a/FortranRuntime/lib/Runtime/numeric.cpp
+++ b/flang-rt/lib/flang_rt/numeric.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/numeric.cpp ---------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/pointer.cpp b/flang-rt/lib/flang_rt/pointer.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/pointer.cpp
rename to flang-rt/lib/flang_rt/pointer.cpp
index fba9e639fa37a8..7479cd780709fa 100644
--- a/FortranRuntime/lib/Runtime/pointer.cpp
+++ b/flang-rt/lib/flang_rt/pointer.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/pointer.cpp ---------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/product.cpp b/flang-rt/lib/flang_rt/product.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/product.cpp
rename to flang-rt/lib/flang_rt/product.cpp
index e4a6e81bd0c508..cd0c4e9440ceb3 100644
--- a/FortranRuntime/lib/Runtime/product.cpp
+++ b/flang-rt/lib/flang_rt/product.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/product.cpp ---------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/pseudo-unit.cpp b/flang-rt/lib/flang_rt/pseudo-unit.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/pseudo-unit.cpp
rename to flang-rt/lib/flang_rt/pseudo-unit.cpp
index 62c6b1df5071c7..9ce39ca9307c9c 100644
--- a/FortranRuntime/lib/Runtime/pseudo-unit.cpp
+++ b/flang-rt/lib/flang_rt/pseudo-unit.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/pseudo-unit.cpp -----------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/ragged.cpp b/flang-rt/lib/flang_rt/ragged.cpp
similarity index 97%
rename from FortranRuntime/lib/Runtime/ragged.cpp
rename to flang-rt/lib/flang_rt/ragged.cpp
index 681a800e29dca7..df6469e9c5ba27 100644
--- a/FortranRuntime/lib/Runtime/ragged.cpp
+++ b/flang-rt/lib/flang_rt/ragged.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/ragged.cpp ----------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/random-templates.h b/flang-rt/lib/flang_rt/random-templates.h
similarity index 91%
rename from FortranRuntime/lib/Runtime/random-templates.h
rename to flang-rt/lib/flang_rt/random-templates.h
index 9faa9c7cfa7002..475c972a823226 100644
--- a/FortranRuntime/lib/Runtime/random-templates.h
+++ b/flang-rt/lib/flang_rt/random-templates.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/random-templates.h --------------------------*- C++ -*-===//
+//===-- lib/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,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_
-#define FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_
+#ifndef FORTRAN_FLANG_RT_RANDOM_TEMPLATES_H_
+#define FORTRAN_FLANG_RT_RANDOM_TEMPLATES_H_
 
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "lock.h"
 #include "numeric-templates.h"
 #include "flang/Common/optional.h"
@@ -85,4 +85,4 @@ inline void Generate(const Descriptor &harvest) {
 
 } // namespace Fortran::runtime::random
 
-#endif /* FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_ */
+#endif /* FORTRAN_FLANG_RT_RANDOM_TEMPLATES_H_ */
diff --git a/FortranRuntime/lib/Runtime/random.cpp b/flang-rt/lib/flang_rt/random.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/random.cpp
rename to flang-rt/lib/flang_rt/random.cpp
index 911b59b508eb4f..9922ae87b084a8 100644
--- a/FortranRuntime/lib/Runtime/random.cpp
+++ b/flang-rt/lib/flang_rt/random.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/random.cpp ----------------------------------*- C++ -*-===//
+//===-- 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,7 +10,7 @@
 // RANDOM_SEED.
 
 #include "flang/Runtime/random.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "lock.h"
 #include "random-templates.h"
 #include "terminator.h"
diff --git a/FortranRuntime/lib/Runtime/reduce.cpp b/flang-rt/lib/flang_rt/reduce.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/reduce.cpp
rename to flang-rt/lib/flang_rt/reduce.cpp
index a020ffef6fe6a5..6997d4c63065b9 100644
--- a/FortranRuntime/lib/Runtime/reduce.cpp
+++ b/flang-rt/lib/flang_rt/reduce.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/reduce.cpp ----------------------------------*- C++ -*-===//
+//===-- 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,7 +9,7 @@
 // REDUCE() implementation
 
 #include "flang/Runtime/reduce.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "reduction-templates.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/FortranRuntime/lib/Runtime/reduction-templates.h b/flang-rt/lib/flang_rt/reduction-templates.h
similarity index 98%
rename from FortranRuntime/lib/Runtime/reduction-templates.h
rename to flang-rt/lib/flang_rt/reduction-templates.h
index 714584ec613ba3..774b6f3c99850f 100644
--- a/FortranRuntime/lib/Runtime/reduction-templates.h
+++ b/flang-rt/lib/flang_rt/reduction-templates.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/reduction-templates.h -----------------------*- C++ -*-===//
+//===-- lib/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,10 +18,10 @@
 // * 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 FORTRAN_FLANG_RT_REDUCTION_TEMPLATES_H_
+#define FORTRAN_FLANG_RT_REDUCTION_TEMPLATES_H_
 
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "numeric-templates.h"
 #include "terminator.h"
 #include "tools.h"
@@ -412,4 +412,4 @@ template <int KIND> struct Norm2Helper {
 };
 
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_ */
+#endif /* FORTRAN_FLANG_RT_REDUCTION_TEMPLATES_H_ */
diff --git a/FortranRuntime/lib/Runtime/reduction.cpp b/flang-rt/lib/flang_rt/reduction.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/reduction.cpp
rename to flang-rt/lib/flang_rt/reduction.cpp
index 21930fee07ead7..f9d5f442e8928f 100644
--- a/FortranRuntime/lib/Runtime/reduction.cpp
+++ b/flang-rt/lib/flang_rt/reduction.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/reduction.cpp -------------------------------*- C++ -*-===//
+//===-- 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,7 +14,7 @@
 // NORM2, MAXLOC, MINLOC, MAXVAL, and MINVAL are in extrema.cpp.
 
 #include "flang/Runtime/reduction.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "reduction-templates.h"
 #include <cinttypes>
 
diff --git a/FortranRuntime/lib/Runtime/stack.h b/flang-rt/lib/flang_rt/stack.h
similarity index 94%
rename from FortranRuntime/lib/Runtime/stack.h
rename to flang-rt/lib/flang_rt/stack.h
index 36e2d0a103a887..4c1ab4e85ed71f 100644
--- a/FortranRuntime/lib/Runtime/stack.h
+++ b/flang-rt/lib/flang_rt/stack.h
@@ -1,4 +1,4 @@
-//===-- lib/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,10 +10,10 @@
 // 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 FORTRAN_FLANG_RT_STACK_H_
+#define FORTRAN_FLANG_RT_STACK_H_
 
-#include "FortranRuntime/Runtime/memory.h"
+#include "flang-rt/flang_rt/memory.h"
 #include "terminator.h"
 
 namespace Fortran::runtime {
@@ -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 /* FORTRAN_FLANG_RT_STACK_H_ */
diff --git a/FortranRuntime/lib/Runtime/stat.cpp b/flang-rt/lib/flang_rt/stat.cpp
similarity index 96%
rename from FortranRuntime/lib/Runtime/stat.cpp
rename to flang-rt/lib/flang_rt/stat.cpp
index 1af6c43102518b..77eefe3d1ac518 100644
--- a/FortranRuntime/lib/Runtime/stat.cpp
+++ b/flang-rt/lib/flang_rt/stat.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/stat.cpp ------------------------------------*- C++ -*-===//
+//===-- 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.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "stat.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 
diff --git a/FortranRuntime/lib/Runtime/stat.h b/flang-rt/lib/flang_rt/stat.h
similarity index 93%
rename from FortranRuntime/lib/Runtime/stat.h
rename to flang-rt/lib/flang_rt/stat.h
index eccd69024d726b..dbab381001d7d8 100644
--- a/FortranRuntime/lib/Runtime/stat.h
+++ b/flang-rt/lib/flang_rt/stat.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/stat.h --------------------------------------*- C++ -*-===//
+//===-- lib/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 FORTRAN_FLANG_RT_STAT_H_
+#define FORTRAN_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 /* FORTRAN_FLANG_RT_STAT_H_ */
diff --git a/FortranRuntime/lib/Runtime/stop.cpp b/flang-rt/lib/flang_rt/stop.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/stop.cpp
rename to flang-rt/lib/flang_rt/stop.cpp
index 8465a53168e551..ea50d1ba4747ff 100644
--- a/FortranRuntime/lib/Runtime/stop.cpp
+++ b/flang-rt/lib/flang_rt/stop.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/stop.cpp ------------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/sum.cpp b/flang-rt/lib/flang_rt/sum.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/sum.cpp
rename to flang-rt/lib/flang_rt/sum.cpp
index 64982b9fd53690..3c225efe8a2788 100644
--- a/FortranRuntime/lib/Runtime/sum.cpp
+++ b/flang-rt/lib/flang_rt/sum.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/sum.cpp -------------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/support.cpp b/flang-rt/lib/flang_rt/support.cpp
similarity index 93%
rename from FortranRuntime/lib/Runtime/support.cpp
rename to flang-rt/lib/flang_rt/support.cpp
index 798d502ba248e2..436ae6f87ae692 100644
--- a/FortranRuntime/lib/Runtime/support.cpp
+++ b/flang-rt/lib/flang_rt/support.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/support.cpp ---------------------------------*- C++ -*-===//
+//===-- 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.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/support.h"
-#include "FortranRuntime/Runtime/descriptor.h"
 #include "ISO_Fortran_util.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "type-info.h"
 
 namespace Fortran::runtime {
diff --git a/FortranRuntime/lib/Runtime/temporary-stack.cpp b/flang-rt/lib/flang_rt/temporary-stack.cpp
similarity index 97%
rename from FortranRuntime/lib/Runtime/temporary-stack.cpp
rename to flang-rt/lib/flang_rt/temporary-stack.cpp
index d8ff08e51cc211..f566e6d8a086ff 100644
--- a/FortranRuntime/lib/Runtime/temporary-stack.cpp
+++ b/flang-rt/lib/flang_rt/temporary-stack.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/temporary-stack.cpp -------------------------*- C++ -*-===//
+//===-- 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,8 +10,8 @@
 // temporaries. For use in HLFIR lowering.
 
 #include "flang/Runtime/temporary-stack.h"
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/memory.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/memory.h"
 #include "terminator.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/assign.h"
diff --git a/FortranRuntime/lib/Runtime/terminator.cpp b/flang-rt/lib/flang_rt/terminator.cpp
similarity index 97%
rename from FortranRuntime/lib/Runtime/terminator.cpp
rename to flang-rt/lib/flang_rt/terminator.cpp
index 4146e28235511f..2e8d895a9025a6 100644
--- a/FortranRuntime/lib/Runtime/terminator.cpp
+++ b/flang-rt/lib/flang_rt/terminator.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/terminator.cpp ------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/terminator.h b/flang-rt/lib/flang_rt/terminator.h
similarity index 95%
rename from FortranRuntime/lib/Runtime/terminator.h
rename to flang-rt/lib/flang_rt/terminator.h
index f475658b0eab3d..61c6452a282d12 100644
--- a/FortranRuntime/lib/Runtime/terminator.h
+++ b/flang-rt/lib/flang_rt/terminator.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/terminator.h --------------------------------*- C++ -*-===//
+//===-- lib/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 FORTRAN_FLANG_RT_TERMINATOR_H_
+#define FORTRAN_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 /* FORTRAN_FLANG_RT_TERMINATOR_H_ */
diff --git a/FortranRuntime/lib/Runtime/time-intrinsic.cpp b/flang-rt/lib/flang_rt/time-intrinsic.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/time-intrinsic.cpp
rename to flang-rt/lib/flang_rt/time-intrinsic.cpp
index 15c42077c0afd5..daba1bd8f6b8f5 100644
--- a/FortranRuntime/lib/Runtime/time-intrinsic.cpp
+++ b/flang-rt/lib/flang_rt/time-intrinsic.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/time-intrinsic.cpp --------------------------*- C++ -*-===//
+//===-- 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,7 +9,7 @@
 // Implements time-related intrinsic subroutines.
 
 #include "flang/Runtime/time-intrinsic.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Runtime/cpp-type.h"
diff --git a/FortranRuntime/lib/Runtime/tools.cpp b/flang-rt/lib/flang_rt/tools.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/tools.cpp
rename to flang-rt/lib/flang_rt/tools.cpp
index d5c113a31fc501..228b781b207ddd 100644
--- a/FortranRuntime/lib/Runtime/tools.cpp
+++ b/flang-rt/lib/flang_rt/tools.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/tools.cpp -----------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/tools.h b/flang-rt/lib/flang_rt/tools.h
similarity index 98%
rename from FortranRuntime/lib/Runtime/tools.h
rename to flang-rt/lib/flang_rt/tools.h
index 332ffac77f2595..9880d0e93f5a82 100644
--- a/FortranRuntime/lib/Runtime/tools.h
+++ b/flang-rt/lib/flang_rt/tools.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/tools.h -------------------------------------*- C++ -*-===//
+//===-- lib/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,11 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_TOOLS_H_
-#define FORTRAN_RUNTIME_TOOLS_H_
+#ifndef FORTRAN_FLANG_RT_TOOLS_H_
+#define FORTRAN_FLANG_RT_TOOLS_H_
 
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/memory.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/memory.h"
 #include "stat.h"
 #include "terminator.h"
 #include "flang/Common/optional.h"
@@ -535,4 +535,4 @@ RT_API_ATTRS void CreatePartialReductionResult(Descriptor &result,
     const char *intrinsic, TypeCode);
 
 } // namespace Fortran::runtime
-#endif /* FORTRAN_RUNTIME_TOOLS_H_ */
+#endif /* FORTRAN_FLANG_RT_TOOLS_H_ */
diff --git a/FortranRuntime/lib/Runtime/transformational.cpp b/flang-rt/lib/flang_rt/transformational.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/transformational.cpp
rename to flang-rt/lib/flang_rt/transformational.cpp
index 28dd02a28036de..f21c63fbfd7a1b 100644
--- a/FortranRuntime/lib/Runtime/transformational.cpp
+++ b/flang-rt/lib/flang_rt/transformational.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/transformational.cpp ------------------------*- C++ -*-===//
+//===-- 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.
@@ -17,8 +17,8 @@
 // of the standard but it more likely to conform with its intent.
 
 #include "flang/Runtime/transformational.h"
-#include "FortranRuntime/Runtime/descriptor.h"
 #include "copy.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Common/float128.h"
diff --git a/FortranRuntime/lib/Runtime/type-code.cpp b/flang-rt/lib/flang_rt/type-code.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/type-code.cpp
rename to flang-rt/lib/flang_rt/type-code.cpp
index 16f5497bc7a709..96fabf7ec7698f 100644
--- a/FortranRuntime/lib/Runtime/type-code.cpp
+++ b/flang-rt/lib/flang_rt/type-code.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/type-code.cpp -------------------------------*- C++ -*-===//
+//===-- 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 "FortranRuntime/Runtime/type-code.h"
+#include "flang-rt/flang_rt/type-code.h"
 #include <cstdint>
 
 namespace Fortran::runtime {
diff --git a/FortranRuntime/lib/Runtime/type-info.cpp b/flang-rt/lib/flang_rt/type-info.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/type-info.cpp
rename to flang-rt/lib/flang_rt/type-info.cpp
index 19e9211fc063f4..031721833ddebc 100644
--- a/FortranRuntime/lib/Runtime/type-info.cpp
+++ b/flang-rt/lib/flang_rt/type-info.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/type-info.cpp -------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/type-info.h b/flang-rt/lib/flang_rt/type-info.h
similarity index 98%
rename from FortranRuntime/lib/Runtime/type-info.h
rename to flang-rt/lib/flang_rt/type-info.h
index 150942547c2ee8..3b0b193d63379c 100644
--- a/FortranRuntime/lib/Runtime/type-info.h
+++ b/flang-rt/lib/flang_rt/type-info.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/type-info.h ---------------------------------*- C++ -*-===//
+//===-- lib/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,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_TYPE_INFO_H_
-#define FORTRAN_RUNTIME_TYPE_INFO_H_
+#ifndef FORTRAN_FLANG_RT_TYPE_INFO_H_
+#define FORTRAN_FLANG_RT_TYPE_INFO_H_
 
 // A C++ perspective of the derived type description schemata in
 // flang/module/__fortran_type_info.f90.
 
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "terminator.h"
 #include "flang/Common/Fortran-consts.h"
 #include "flang/Common/bit-population-count.h"
@@ -321,4 +321,4 @@ class DerivedType {
 };
 
 } // namespace Fortran::runtime::typeInfo
-#endif /* FORTRAN_RUNTIME_TYPE_INFO_H_ */
+#endif /* FORTRAN_FLANG_RT_TYPE_INFO_H_ */
diff --git a/FortranRuntime/lib/Runtime/unit-map.cpp b/flang-rt/lib/flang_rt/unit-map.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/unit-map.cpp
rename to flang-rt/lib/flang_rt/unit-map.cpp
index 93958be8df7ea5..0fda53ac071b27 100644
--- a/FortranRuntime/lib/Runtime/unit-map.cpp
+++ b/flang-rt/lib/flang_rt/unit-map.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/unit-map.cpp --------------------------------*- C++ -*-===//
+//===-- 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/FortranRuntime/lib/Runtime/unit-map.h b/flang-rt/lib/flang_rt/unit-map.h
similarity index 93%
rename from FortranRuntime/lib/Runtime/unit-map.h
rename to flang-rt/lib/flang_rt/unit-map.h
index f37e2df7f3b15a..7215a5677f006b 100644
--- a/FortranRuntime/lib/Runtime/unit-map.h
+++ b/flang-rt/lib/flang_rt/unit-map.h
@@ -1,4 +1,4 @@
-//===-- lib/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,10 +9,10 @@
 // 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 FORTRAN_FLANG_RT_UNIT_MAP_H_
+#define FORTRAN_FLANG_RT_UNIT_MAP_H_
 
-#include "FortranRuntime/Runtime/memory.h"
+#include "flang-rt/flang_rt/memory.h"
 #include "lock.h"
 #include "unit.h"
 #include "flang/Common/fast-int-set.h"
@@ -100,4 +100,4 @@ class UnitMap {
   int emergencyNewUnit_{maxNewUnits_}; // not recycled
 };
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_RUNTIME_UNIT_MAP_H_ */
+#endif /* FORTRAN_FLANG_RT_UNIT_MAP_H_ */
diff --git a/FortranRuntime/lib/Runtime/unit.cpp b/flang-rt/lib/flang_rt/unit.cpp
similarity index 99%
rename from FortranRuntime/lib/Runtime/unit.cpp
rename to flang-rt/lib/flang_rt/unit.cpp
index 496679ee8ce5f4..d65ae8962541e4 100644
--- a/FortranRuntime/lib/Runtime/unit.cpp
+++ b/flang-rt/lib/flang_rt/unit.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/unit.cpp ------------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/unit.h b/flang-rt/lib/flang_rt/unit.h
similarity index 98%
rename from FortranRuntime/lib/Runtime/unit.h
rename to flang-rt/lib/flang_rt/unit.h
index 4a7444aedbe5b6..077a34833734ac 100644
--- a/FortranRuntime/lib/Runtime/unit.h
+++ b/flang-rt/lib/flang_rt/unit.h
@@ -1,4 +1,4 @@
-//===-- lib/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,14 +8,14 @@
 
 // Fortran external I/O units
 
-#ifndef FORTRAN_RUNTIME_UNIT_H_
-#define FORTRAN_RUNTIME_UNIT_H_
+#ifndef FORTRAN_FLANG_RT_UNIT_H_
+#define FORTRAN_FLANG_RT_UNIT_H_
 
-#include "FortranRuntime/Runtime/memory.h"
 #include "buffer.h"
 #include "connection.h"
 #include "environment.h"
 #include "file.h"
+#include "flang-rt/flang_rt/memory.h"
 #include "format.h"
 #include "io-error.h"
 #include "io-stmt.h"
@@ -291,4 +291,4 @@ class ChildIo {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_RUNTIME_UNIT_H_ */
+#endif /* FORTRAN_FLANG_RT_UNIT_H_ */
diff --git a/FortranRuntime/lib/Runtime/utf.cpp b/flang-rt/lib/flang_rt/utf.cpp
similarity index 98%
rename from FortranRuntime/lib/Runtime/utf.cpp
rename to flang-rt/lib/flang_rt/utf.cpp
index 635451153d39a6..46400668745ce7 100644
--- a/FortranRuntime/lib/Runtime/utf.cpp
+++ b/flang-rt/lib/flang_rt/utf.cpp
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/utf.cpp -------------------------------------*- C++ -*-===//
+//===-- 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.
diff --git a/FortranRuntime/lib/Runtime/utf.h b/flang-rt/lib/flang_rt/utf.h
similarity index 94%
rename from FortranRuntime/lib/Runtime/utf.h
rename to flang-rt/lib/flang_rt/utf.h
index 35c03fd4cdded5..71dc7b05a77513 100644
--- a/FortranRuntime/lib/Runtime/utf.h
+++ b/flang-rt/lib/flang_rt/utf.h
@@ -1,4 +1,4 @@
-//===-- lib/Runtime/utf.h ---------------------------------------*- C++ -*-===//
+//===-- lib/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 FORTRAN_FLANG_RT_UTF_H_
+#define FORTRAN_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 /* FORTRAN_FLANG_RT_UTF_H_ */
diff --git a/FortranRuntime/test/Driver/ctofortran.f90 b/flang-rt/test/Driver/ctofortran.f90
similarity index 100%
rename from FortranRuntime/test/Driver/ctofortran.f90
rename to flang-rt/test/Driver/ctofortran.f90
diff --git a/FortranRuntime/test/Driver/exec.f90 b/flang-rt/test/Driver/exec.f90
similarity index 100%
rename from FortranRuntime/test/Driver/exec.f90
rename to flang-rt/test/Driver/exec.f90
diff --git a/FortranRuntime/test/Runtime/no-cpp-dep.c b/flang-rt/test/Runtime/no-cpp-dep.c
similarity index 100%
rename from FortranRuntime/test/Runtime/no-cpp-dep.c
rename to flang-rt/test/Runtime/no-cpp-dep.c
diff --git a/FortranRuntime/unittests/Evaluate/CMakeLists.txt b/flang-rt/unittests/Evaluate/CMakeLists.txt
similarity index 100%
rename from FortranRuntime/unittests/Evaluate/CMakeLists.txt
rename to flang-rt/unittests/Evaluate/CMakeLists.txt
diff --git a/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp b/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp
similarity index 99%
rename from FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp
rename to flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp
index b68dfbcbd5b335..03cc59291787aa 100644
--- a/FortranRuntime/unittests/Evaluate/ISO-Fortran-binding.cpp
+++ b/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Testing/testing.h"
 #include "llvm/Support/raw_ostream.h"
diff --git a/FortranRuntime/unittests/Evaluate/reshape.cpp b/flang-rt/unittests/Evaluate/reshape.cpp
similarity index 98%
rename from FortranRuntime/unittests/Evaluate/reshape.cpp
rename to flang-rt/unittests/Evaluate/reshape.cpp
index 0233ab37e25c6e..c9ead4fe744f91 100644
--- a/FortranRuntime/unittests/Evaluate/reshape.cpp
+++ b/flang-rt/unittests/Evaluate/reshape.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "flang/Runtime/transformational.h"
 #include "flang/Testing/testing.h"
 #include <cinttypes>
diff --git a/FortranRuntime/unittests/Runtime/AccessTest.cpp b/flang-rt/unittests/Runtime/AccessTest.cpp
similarity index 100%
rename from FortranRuntime/unittests/Runtime/AccessTest.cpp
rename to flang-rt/unittests/Runtime/AccessTest.cpp
diff --git a/FortranRuntime/unittests/Runtime/Allocatable.cpp b/flang-rt/unittests/Runtime/Allocatable.cpp
similarity index 100%
rename from FortranRuntime/unittests/Runtime/Allocatable.cpp
rename to flang-rt/unittests/Runtime/Allocatable.cpp
diff --git a/FortranRuntime/unittests/Runtime/ArrayConstructor.cpp b/flang-rt/unittests/Runtime/ArrayConstructor.cpp
similarity index 97%
rename from FortranRuntime/unittests/Runtime/ArrayConstructor.cpp
rename to flang-rt/unittests/Runtime/ArrayConstructor.cpp
index 9d9a4ddae8689f..c52ce8e4ea54fd 100644
--- a/FortranRuntime/unittests/Runtime/ArrayConstructor.cpp
+++ b/flang-rt/unittests/Runtime/ArrayConstructor.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/array-constructor.h"
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/type-code.h"
+#include "flang-rt/flang_rt/array-constructor.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Runtime/allocatable.h"
diff --git a/FortranRuntime/unittests/Runtime/BufferTest.cpp b/flang-rt/unittests/Runtime/BufferTest.cpp
similarity index 99%
rename from FortranRuntime/unittests/Runtime/BufferTest.cpp
rename to flang-rt/unittests/Runtime/BufferTest.cpp
index 9a7dd86d0c1dc6..41c660e638e712 100644
--- a/FortranRuntime/unittests/Runtime/BufferTest.cpp
+++ b/flang-rt/unittests/Runtime/BufferTest.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "../../lib/Runtime/buffer.h"
+#include "../../lib/flang_rt/buffer.h"
 #include "CrashHandlerFixture.h"
 #include "gtest/gtest.h"
 #include <algorithm>
diff --git a/FortranRuntime/unittests/Runtime/CMakeLists.txt b/flang-rt/unittests/Runtime/CMakeLists.txt
similarity index 100%
rename from FortranRuntime/unittests/Runtime/CMakeLists.txt
rename to flang-rt/unittests/Runtime/CMakeLists.txt
diff --git a/FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
similarity index 90%
rename from FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp
rename to flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
index d2a2e5a11abf80..46461a863c0696 100644
--- a/FortranRuntime/unittests/Runtime/CUDA/AllocatorCUF.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
@@ -6,16 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/CUDA/allocator.h"
-#include "FortranRuntime/Runtime/CUDA/descriptor.h"
-#include "FortranRuntime/Runtime/allocatable.h"
-#include "FortranRuntime/Runtime/allocator-registry.h"
+#include "cuda_runtime.h"
+#include "flang-rt/flang_rt/allocator-registry.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "gtest/gtest.h"
-#include "../../../runtime/terminator.h"
+#include "../../../lib/flang_rt/terminator.h"
+#include "flang-rt/CufRuntime/allocator.h"
+#include "flang/Runtime/CUDA/descriptor.h"
+#include "flang/Runtime/allocatable.h"
 #include "flang/Support/Fortran.h"
 
-#include "cuda_runtime.h"
-
 using namespace Fortran::runtime;
 using namespace Fortran::runtime::cuda;
 
diff --git a/FortranRuntime/unittests/Runtime/CUDA/CMakeLists.txt b/flang-rt/unittests/Runtime/CUDA/CMakeLists.txt
similarity index 100%
rename from FortranRuntime/unittests/Runtime/CUDA/CMakeLists.txt
rename to flang-rt/unittests/Runtime/CUDA/CMakeLists.txt
diff --git a/FortranRuntime/unittests/Runtime/CharacterTest.cpp b/flang-rt/unittests/Runtime/CharacterTest.cpp
similarity index 99%
rename from FortranRuntime/unittests/Runtime/CharacterTest.cpp
rename to flang-rt/unittests/Runtime/CharacterTest.cpp
index 610061e2122cd5..3a4b5706e53849 100644
--- a/FortranRuntime/unittests/Runtime/CharacterTest.cpp
+++ b/flang-rt/unittests/Runtime/CharacterTest.cpp
@@ -10,7 +10,7 @@
 // in Fortran.
 
 #include "flang/Runtime/character.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "gtest/gtest.h"
 #include <cstring>
 #include <functional>
diff --git a/FortranRuntime/unittests/Runtime/CommandTest.cpp b/flang-rt/unittests/Runtime/CommandTest.cpp
similarity index 99%
rename from FortranRuntime/unittests/Runtime/CommandTest.cpp
rename to flang-rt/unittests/Runtime/CommandTest.cpp
index a7d68508c5abca..15b2ed2e42bba1 100644
--- a/FortranRuntime/unittests/Runtime/CommandTest.cpp
+++ b/flang-rt/unittests/Runtime/CommandTest.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/command.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include "flang/Runtime/execute.h"
diff --git a/FortranRuntime/unittests/Runtime/Complex.cpp b/flang-rt/unittests/Runtime/Complex.cpp
similarity index 100%
rename from FortranRuntime/unittests/Runtime/Complex.cpp
rename to flang-rt/unittests/Runtime/Complex.cpp
diff --git a/FortranRuntime/unittests/Runtime/CrashHandlerFixture.cpp b/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp
similarity index 96%
rename from FortranRuntime/unittests/Runtime/CrashHandlerFixture.cpp
rename to flang-rt/unittests/Runtime/CrashHandlerFixture.cpp
index 5e0b746c7e974a..3959b0d4b78809 100644
--- a/FortranRuntime/unittests/Runtime/CrashHandlerFixture.cpp
+++ b/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 #include "CrashHandlerFixture.h"
-#include "../../lib/Runtime/terminator.h"
+#include "../../lib/flang_rt/terminator.h"
 #include <cstdarg>
 #include <cstdlib>
 
diff --git a/FortranRuntime/unittests/Runtime/CrashHandlerFixture.h b/flang-rt/unittests/Runtime/CrashHandlerFixture.h
similarity index 100%
rename from FortranRuntime/unittests/Runtime/CrashHandlerFixture.h
rename to flang-rt/unittests/Runtime/CrashHandlerFixture.h
diff --git a/FortranRuntime/unittests/Runtime/Derived.cpp b/flang-rt/unittests/Runtime/Derived.cpp
similarity index 98%
rename from FortranRuntime/unittests/Runtime/Derived.cpp
rename to flang-rt/unittests/Runtime/Derived.cpp
index 22361352fdf5d9..055174a3b5a907 100644
--- a/FortranRuntime/unittests/Runtime/Derived.cpp
+++ b/flang-rt/unittests/Runtime/Derived.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Runtime/derived-api.h"
diff --git a/FortranRuntime/unittests/Runtime/ExternalIOTest.cpp b/flang-rt/unittests/Runtime/ExternalIOTest.cpp
similarity index 99%
rename from FortranRuntime/unittests/Runtime/ExternalIOTest.cpp
rename to flang-rt/unittests/Runtime/ExternalIOTest.cpp
index 7ff4aa3c14bdc5..a93ee97da8f5f7 100644
--- a/FortranRuntime/unittests/Runtime/ExternalIOTest.cpp
+++ b/flang-rt/unittests/Runtime/ExternalIOTest.cpp
@@ -11,8 +11,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/io-api-funcs.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/io-api-funcs.h"
 #include "gtest/gtest.h"
 #include "flang/Runtime/main.h"
 #include "flang/Runtime/stop.h"
diff --git a/FortranRuntime/unittests/Runtime/Format.cpp b/flang-rt/unittests/Runtime/Format.cpp
similarity index 97%
rename from FortranRuntime/unittests/Runtime/Format.cpp
rename to flang-rt/unittests/Runtime/Format.cpp
index f1447608917f2d..3012806a8eacc1 100644
--- a/FortranRuntime/unittests/Runtime/Format.cpp
+++ b/flang-rt/unittests/Runtime/Format.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "../../lib/Runtime/connection.h"
-#include "../../lib/Runtime/format-implementation.h"
-#include "../../lib/Runtime/io-error.h"
+#include "../../lib/flang_rt/connection.h"
+#include "../../lib/flang_rt/format-implementation.h"
+#include "../../lib/flang_rt/io-error.h"
 #include <optional>
 #include <string>
 #include <tuple>
diff --git a/FortranRuntime/unittests/Runtime/Inquiry.cpp b/flang-rt/unittests/Runtime/Inquiry.cpp
similarity index 99%
rename from FortranRuntime/unittests/Runtime/Inquiry.cpp
rename to flang-rt/unittests/Runtime/Inquiry.cpp
index 3e5f0037177f1c..0bda07aaef295c 100644
--- a/FortranRuntime/unittests/Runtime/Inquiry.cpp
+++ b/flang-rt/unittests/Runtime/Inquiry.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/inquiry.h"
-#include "FortranRuntime/Runtime/type-code.h"
+#include "flang-rt/flang_rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 
diff --git a/FortranRuntime/unittests/Runtime/ListInputTest.cpp b/flang-rt/unittests/Runtime/ListInputTest.cpp
similarity index 98%
rename from FortranRuntime/unittests/Runtime/ListInputTest.cpp
rename to flang-rt/unittests/Runtime/ListInputTest.cpp
index e0fe4dfeac3949..7e04ab834eb247 100644
--- a/FortranRuntime/unittests/Runtime/ListInputTest.cpp
+++ b/flang-rt/unittests/Runtime/ListInputTest.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/io-api-funcs.h"
-#include "../../lib/Runtime/io-error.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/io-api-funcs.h"
+#include "../../lib/flang_rt/io-error.h"
 
 using namespace Fortran::runtime;
 using namespace Fortran::runtime::io;
diff --git a/FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp b/flang-rt/unittests/Runtime/LogicalFormatTest.cpp
similarity index 95%
rename from FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp
rename to flang-rt/unittests/Runtime/LogicalFormatTest.cpp
index 9fa0c2f4260edb..b5a9e2d317841f 100644
--- a/FortranRuntime/unittests/Runtime/LogicalFormatTest.cpp
+++ b/flang-rt/unittests/Runtime/LogicalFormatTest.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/io-api-funcs.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/io-api-funcs.h"
 #include <algorithm>
 #include <array>
 #include <cstring>
diff --git a/FortranRuntime/unittests/Runtime/Matmul.cpp b/flang-rt/unittests/Runtime/Matmul.cpp
similarity index 98%
rename from FortranRuntime/unittests/Runtime/Matmul.cpp
rename to flang-rt/unittests/Runtime/Matmul.cpp
index 6eb4012e785ff1..e833b3861badac 100644
--- a/FortranRuntime/unittests/Runtime/Matmul.cpp
+++ b/flang-rt/unittests/Runtime/Matmul.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/matmul.h"
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/type-code.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Runtime/allocatable.h"
diff --git a/FortranRuntime/unittests/Runtime/MatmulTranspose.cpp b/flang-rt/unittests/Runtime/MatmulTranspose.cpp
similarity index 99%
rename from FortranRuntime/unittests/Runtime/MatmulTranspose.cpp
rename to flang-rt/unittests/Runtime/MatmulTranspose.cpp
index 199062f820c303..560f62935e35bc 100644
--- a/FortranRuntime/unittests/Runtime/MatmulTranspose.cpp
+++ b/flang-rt/unittests/Runtime/MatmulTranspose.cpp
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/type-code.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Runtime/allocatable.h"
diff --git a/FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp b/flang-rt/unittests/Runtime/MiscIntrinsic.cpp
similarity index 98%
rename from FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp
rename to flang-rt/unittests/Runtime/MiscIntrinsic.cpp
index 1033dda9d636f7..ca3a3e4fd3b839 100644
--- a/FortranRuntime/unittests/Runtime/MiscIntrinsic.cpp
+++ b/flang-rt/unittests/Runtime/MiscIntrinsic.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Runtime/allocatable.h"
diff --git a/FortranRuntime/unittests/Runtime/Namelist.cpp b/flang-rt/unittests/Runtime/Namelist.cpp
similarity index 99%
rename from FortranRuntime/unittests/Runtime/Namelist.cpp
rename to flang-rt/unittests/Runtime/Namelist.cpp
index 544ab85234fd65..d30625f23bfc1c 100644
--- a/FortranRuntime/unittests/Runtime/Namelist.cpp
+++ b/flang-rt/unittests/Runtime/Namelist.cpp
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "../../lib/Runtime/namelist.h"
+#include "../../lib/flang_rt/namelist.h"
 #include "CrashHandlerFixture.h"
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/io-api-funcs.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/io-api-funcs.h"
 #include "tools.h"
 #include <algorithm>
 #include <cinttypes>
diff --git a/FortranRuntime/unittests/Runtime/Numeric.cpp b/flang-rt/unittests/Runtime/Numeric.cpp
similarity index 100%
rename from FortranRuntime/unittests/Runtime/Numeric.cpp
rename to flang-rt/unittests/Runtime/Numeric.cpp
diff --git a/FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
similarity index 99%
rename from FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp
rename to flang-rt/unittests/Runtime/NumericalFormatTest.cpp
index c588c739686bed..6c11bb0d4a49d6 100644
--- a/FortranRuntime/unittests/Runtime/NumericalFormatTest.cpp
+++ b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/io-api-funcs.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/io-api-funcs.h"
 #include <algorithm>
 #include <array>
 #include <cstring>
diff --git a/FortranRuntime/unittests/Runtime/Pointer.cpp b/flang-rt/unittests/Runtime/Pointer.cpp
similarity index 98%
rename from FortranRuntime/unittests/Runtime/Pointer.cpp
rename to flang-rt/unittests/Runtime/Pointer.cpp
index 733cd42232875f..c787ed9e71eee9 100644
--- a/FortranRuntime/unittests/Runtime/Pointer.cpp
+++ b/flang-rt/unittests/Runtime/Pointer.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/pointer.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 
diff --git a/FortranRuntime/unittests/Runtime/Ragged.cpp b/flang-rt/unittests/Runtime/Ragged.cpp
similarity index 100%
rename from FortranRuntime/unittests/Runtime/Ragged.cpp
rename to flang-rt/unittests/Runtime/Ragged.cpp
diff --git a/FortranRuntime/unittests/Runtime/Random.cpp b/flang-rt/unittests/Runtime/Random.cpp
similarity index 95%
rename from FortranRuntime/unittests/Runtime/Random.cpp
rename to flang-rt/unittests/Runtime/Random.cpp
index 81497a682660a8..bd4fcfd5e87975 100644
--- a/FortranRuntime/unittests/Runtime/Random.cpp
+++ b/flang-rt/unittests/Runtime/Random.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/random.h"
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/type-code.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/type-code.h"
 #include "gtest/gtest.h"
 #include <cmath>
 
diff --git a/FortranRuntime/unittests/Runtime/Reduction.cpp b/flang-rt/unittests/Runtime/Reduction.cpp
similarity index 99%
rename from FortranRuntime/unittests/Runtime/Reduction.cpp
rename to flang-rt/unittests/Runtime/Reduction.cpp
index a382f4b7a71770..0f3789b017c6f6 100644
--- a/FortranRuntime/unittests/Runtime/Reduction.cpp
+++ b/flang-rt/unittests/Runtime/Reduction.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/reduction.h"
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/type-code.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Common/float128.h"
diff --git a/FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp b/flang-rt/unittests/Runtime/RuntimeCrashTest.cpp
similarity index 99%
rename from FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp
rename to flang-rt/unittests/Runtime/RuntimeCrashTest.cpp
index 7ce1ee796d739b..f1ea6c897d515e 100644
--- a/FortranRuntime/unittests/Runtime/RuntimeCrashTest.cpp
+++ b/flang-rt/unittests/Runtime/RuntimeCrashTest.cpp
@@ -12,7 +12,7 @@
 //===----------------------------------------------------------------------===//
 #include "CrashHandlerFixture.h"
 #include "tools.h"
-#include "../../lib/Runtime/terminator.h"
+#include "../../lib/flang_rt/terminator.h"
 #include "flang/Runtime/io-api.h"
 #include "flang/Runtime/transformational.h"
 #include <gtest/gtest.h>
diff --git a/FortranRuntime/unittests/Runtime/Stop.cpp b/flang-rt/unittests/Runtime/Stop.cpp
similarity index 98%
rename from FortranRuntime/unittests/Runtime/Stop.cpp
rename to flang-rt/unittests/Runtime/Stop.cpp
index c12ec097068438..9aaabc2e6c6384 100644
--- a/FortranRuntime/unittests/Runtime/Stop.cpp
+++ b/flang-rt/unittests/Runtime/Stop.cpp
@@ -11,7 +11,7 @@
 //===----------------------------------------------------------------------===//
 #include "flang/Runtime/stop.h"
 #include "CrashHandlerFixture.h"
-#include "../../lib/Runtime/environment.h"
+#include "../../lib/flang_rt/environment.h"
 #include <cstdlib>
 #include <gtest/gtest.h>
 
diff --git a/FortranRuntime/unittests/Runtime/Support.cpp b/flang-rt/unittests/Runtime/Support.cpp
similarity index 98%
rename from FortranRuntime/unittests/Runtime/Support.cpp
rename to flang-rt/unittests/Runtime/Support.cpp
index 05328e6baa411c..d37369df025f45 100644
--- a/FortranRuntime/unittests/Runtime/Support.cpp
+++ b/flang-rt/unittests/Runtime/Support.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/support.h"
-#include "FortranRuntime/Runtime/descriptor.h"
+#include "flang-rt/flang_rt/descriptor.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 
diff --git a/FortranRuntime/unittests/Runtime/TemporaryStack.cpp b/flang-rt/unittests/Runtime/TemporaryStack.cpp
similarity index 99%
rename from FortranRuntime/unittests/Runtime/TemporaryStack.cpp
rename to flang-rt/unittests/Runtime/TemporaryStack.cpp
index b0b1041f0f09e7..8a9f2dfe6d22f1 100644
--- a/FortranRuntime/unittests/Runtime/TemporaryStack.cpp
+++ b/flang-rt/unittests/Runtime/TemporaryStack.cpp
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/type-code.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
diff --git a/FortranRuntime/unittests/Runtime/Time.cpp b/flang-rt/unittests/Runtime/Time.cpp
similarity index 100%
rename from FortranRuntime/unittests/Runtime/Time.cpp
rename to flang-rt/unittests/Runtime/Time.cpp
diff --git a/FortranRuntime/unittests/Runtime/Transformational.cpp b/flang-rt/unittests/Runtime/Transformational.cpp
similarity index 99%
rename from FortranRuntime/unittests/Runtime/Transformational.cpp
rename to flang-rt/unittests/Runtime/Transformational.cpp
index 6b8903750d0aec..e8981e9b122eb7 100644
--- a/FortranRuntime/unittests/Runtime/Transformational.cpp
+++ b/flang-rt/unittests/Runtime/Transformational.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/transformational.h"
-#include "FortranRuntime/Runtime/type-code.h"
+#include "flang-rt/flang_rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Common/float128.h"
diff --git a/FortranRuntime/unittests/Runtime/tools.h b/flang-rt/unittests/Runtime/tools.h
similarity index 95%
rename from FortranRuntime/unittests/Runtime/tools.h
rename to flang-rt/unittests/Runtime/tools.h
index 8000d83fc0c394..7edeff7f7eb579 100644
--- a/FortranRuntime/unittests/Runtime/tools.h
+++ b/flang-rt/unittests/Runtime/tools.h
@@ -9,8 +9,8 @@
 #ifndef FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
 #define FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
 
-#include "FortranRuntime/Runtime/descriptor.h"
-#include "FortranRuntime/Runtime/type-code.h"
+#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/flang_rt/type-code.h"
 #include "gtest/gtest.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 733a2ba1ed7ccc..455b6f597ff846 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -468,7 +468,7 @@ if (FLANG_CUF_RUNTIME)
   find_package(CUDAToolkit REQUIRED)
 endif()
 
-add_subdirectory(../FortranRuntime/lib/Runtime runtime)
+add_subdirectory(../flang-rt/lib/flang_rt runtime)
 
 if (LLVM_INCLUDE_EXAMPLES)
   add_subdirectory(examples)
diff --git a/flang/include/flang/Common/README.md b/flang/include/flang/Common/README.md
index a722732fb76407..4900caab478d94 100644
--- a/flang/include/flang/Common/README.md
+++ b/flang/include/flang/Common/README.md
@@ -2,7 +2,7 @@ Files in this directory are used by Flang (the compiler) and FortranRuntime
 (the runtime library for Flang-compiled programs). They must be compatible by
 both. For definitions used only by Flang, consider
 `flang/{lib,include/flang}/Support` instead. For definitions used only by
-FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.
+the runtime, consider `flang-rt/{lib,include/flang-rt}/flang_rt`.
 
 The requirements for common code include:
 
@@ -23,3 +23,5 @@ The requirements for common code include:
 
  * Global declarations may need to be annotated using definitions from
    `api-attrs.h`.
+
+ * The `Runtime` component is header-only.
diff --git a/flang/include/flang/ISO_Fortran_binding.h b/flang/include/flang/ISO_Fortran_binding.h
index 89a10ce69a2ba2..b211bcd98af868 100644
--- a/flang/include/flang/ISO_Fortran_binding.h
+++ b/flang/include/flang/ISO_Fortran_binding.h
@@ -1,3 +1,11 @@
+//===-- include/flang/ISO_Fortran_binding.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
+//
+//===----------------------------------------------------------------------===//
+
 /*===-- include/flang/ISO_Fortran_binding.h -----------------------*- C++ -*-===
  *
  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -7,14 +15,14 @@
  * ===-----------------------------------------------------------------------===
  */
 
-#ifndef CFI_ISO_FORTRAN_BINDING_H_
-#define CFI_ISO_FORTRAN_BINDING_H_
+#ifndef FORTRAN_ISO_FORTRAN_BINDING_H_
+#define FORTRAN_ISO_FORTRAN_BINDING_H_
 
 /* When this header is included into the compiler and runtime implementations,
  * 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
@@ -207,4 +215,4 @@ RT_API_ATTRS int CFI_setpointer(
 } // extern "C"
 #endif
 
-#endif /* CFI_ISO_FORTRAN_BINDING_H_ */
+#endif /* FORTRAN_ISO_FORTRAN_BINDING_H_ */
diff --git a/flang/include/flang/Runtime/README.md b/flang/include/flang/Runtime/README.md
index a13a7e23162e98..4900caab478d94 100644
--- a/flang/include/flang/Runtime/README.md
+++ b/flang/include/flang/Runtime/README.md
@@ -2,7 +2,7 @@ Files in this directory are used by Flang (the compiler) and FortranRuntime
 (the runtime library for Flang-compiled programs). They must be compatible by
 both. For definitions used only by Flang, consider
 `flang/{lib,include/flang}/Support` instead. For definitions used only by
-FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.
+the runtime, consider `flang-rt/{lib,include/flang-rt}/flang_rt`.
 
 The requirements for common code include:
 
diff --git a/flang/include/flang/Testing/README.md b/flang/include/flang/Testing/README.md
index a722732fb76407..4900caab478d94 100644
--- a/flang/include/flang/Testing/README.md
+++ b/flang/include/flang/Testing/README.md
@@ -2,7 +2,7 @@ Files in this directory are used by Flang (the compiler) and FortranRuntime
 (the runtime library for Flang-compiled programs). They must be compatible by
 both. For definitions used only by Flang, consider
 `flang/{lib,include/flang}/Support` instead. For definitions used only by
-FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.
+the runtime, consider `flang-rt/{lib,include/flang-rt}/flang_rt`.
 
 The requirements for common code include:
 
@@ -23,3 +23,5 @@ The requirements for common code include:
 
  * Global declarations may need to be annotated using definitions from
    `api-attrs.h`.
+
+ * The `Runtime` component is header-only.
diff --git a/flang/lib/Common/README.md b/flang/lib/Common/README.md
index a722732fb76407..4900caab478d94 100644
--- a/flang/lib/Common/README.md
+++ b/flang/lib/Common/README.md
@@ -2,7 +2,7 @@ Files in this directory are used by Flang (the compiler) and FortranRuntime
 (the runtime library for Flang-compiled programs). They must be compatible by
 both. For definitions used only by Flang, consider
 `flang/{lib,include/flang}/Support` instead. For definitions used only by
-FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.
+the runtime, consider `flang-rt/{lib,include/flang-rt}/flang_rt`.
 
 The requirements for common code include:
 
@@ -23,3 +23,5 @@ The requirements for common code include:
 
  * Global declarations may need to be annotated using definitions from
    `api-attrs.h`.
+
+ * The `Runtime` component is header-only.
diff --git a/flang/lib/Optimizer/Transforms/CufOpConversion.cpp b/flang/lib/Optimizer/Transforms/CufOpConversion.cpp
index d7d321c6b9af3f..68ce3ab7045505 100644
--- a/flang/lib/Optimizer/Transforms/CufOpConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/CufOpConversion.cpp
@@ -1,4 +1,4 @@
-//===-- CufOpConversion.cpp -----------------------------------------------===//
+//===-- lib/Optimizer/Transforms/CufOpConversion.cpp ------------*- 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/Testing/README.md b/flang/lib/Testing/README.md
index a722732fb76407..256195b0a1916d 100644
--- a/flang/lib/Testing/README.md
+++ b/flang/lib/Testing/README.md
@@ -2,7 +2,7 @@ Files in this directory are used by Flang (the compiler) and FortranRuntime
 (the runtime library for Flang-compiled programs). They must be compatible by
 both. For definitions used only by Flang, consider
 `flang/{lib,include/flang}/Support` instead. For definitions used only by
-FortranRuntime, consider `FortranRuntime/{lib,include/FortranRuntime}/Runtime`.
+FortranRuntime, consider `flang-rt/{lib,include/flang-rt}/flang_rt`.
 
 The requirements for common code include:
 
diff --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt
index a3fed6c27d125b..4a279c9bbf3260 100644
--- a/flang/unittests/CMakeLists.txt
+++ b/flang/unittests/CMakeLists.txt
@@ -10,7 +10,7 @@ endif()
 add_custom_target(FlangUnitTests)
 set_target_properties(FlangUnitTests PROPERTIES FOLDER "Flang/Tests")
 
-include_directories("../../FortranRuntime/include")
+include_directories("../../flang-rt/include")
 
 function(add_flang_unittest_offload_properties target)
   # Set CUDA_RESOLVE_DEVICE_SYMBOLS.
@@ -77,5 +77,5 @@ add_subdirectory(Optimizer)
 add_subdirectory(Common)
 add_subdirectory(Decimal)
 add_subdirectory(Evaluate)
-add_subdirectory(../../FortranRuntime/unittests/Runtime Runtime)
+add_subdirectory(../../flang-rt/unittests/Runtime Runtime)
 add_subdirectory(Frontend)
diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt
index 5694f5a144c4c5..8557b68991dfe4 100644
--- a/flang/unittests/Evaluate/CMakeLists.txt
+++ b/flang/unittests/Evaluate/CMakeLists.txt
@@ -76,4 +76,4 @@ add_flang_nongtest_unittest(folding
   FortranSemantics
 )
 
-add_subdirectory(../../../FortranRuntime/unittests/Evaluate runtime)
+add_subdirectory(../../../flang-rt/unittests/Evaluate runtime)

>From e3072f9e7c8bd9bedd3f515c8f6e3bb2bbaeabfe Mon Sep 17 00:00:00 2001
From: "U-BERGUFFLEN\\meinersbur" <llvm-project at meinersbur.de>
Date: Thu, 17 Oct 2024 11:45:19 +0200
Subject: [PATCH 11/12] Address review comments

 * remove library part of include files
 * move CufRuntime files into CUDA subdir
---
 .../flang-rt/{CufRuntime => CUDA}/allocator.h        |  8 ++++----
 .../flang-rt/{flang_rt => }/allocator-registry.h     |  8 ++++----
 .../flang-rt/{flang_rt => }/array-constructor.h      | 10 +++++-----
 .../include/flang-rt/{flang_rt => }/descriptor.h     | 12 ++++++------
 .../include/flang-rt/{flang_rt => }/io-api-funcs.h   |  8 ++++----
 .../include/flang-rt/{flang_rt => }/iostat-funcs.h   |  8 ++++----
 flang-rt/include/flang-rt/{flang_rt => }/memory.h    |  8 ++++----
 flang-rt/include/flang-rt/{flang_rt => }/type-code.h |  8 ++++----
 flang-rt/lib/CufRuntime/allocator.cpp                |  4 ++--
 flang-rt/lib/CufRuntime/descriptor.cpp               |  2 +-
 flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp        |  4 ++--
 flang-rt/lib/flang_rt/ISO_Fortran_util.h             | 10 +++++-----
 flang-rt/lib/flang_rt/allocatable.cpp                |  2 +-
 flang-rt/lib/flang_rt/allocator-registry.cpp         |  2 +-
 flang-rt/lib/flang_rt/array-constructor.cpp          |  4 ++--
 flang-rt/lib/flang_rt/assign.cpp                     |  2 +-
 flang-rt/lib/flang_rt/buffer.h                       |  8 ++++----
 flang-rt/lib/flang_rt/character.cpp                  |  2 +-
 flang-rt/lib/flang_rt/command.cpp                    |  2 +-
 flang-rt/lib/flang_rt/copy.cpp                       |  2 +-
 flang-rt/lib/flang_rt/copy.h                         |  8 ++++----
 flang-rt/lib/flang_rt/derived-api.cpp                |  2 +-
 flang-rt/lib/flang_rt/derived.cpp                    |  2 +-
 flang-rt/lib/flang_rt/descriptor-io.h                |  8 ++++----
 flang-rt/lib/flang_rt/descriptor.cpp                 |  4 ++--
 flang-rt/lib/flang_rt/dot-product.cpp                |  2 +-
 flang-rt/lib/flang_rt/execute.cpp                    |  2 +-
 flang-rt/lib/flang_rt/extensions.cpp                 |  4 ++--
 flang-rt/lib/flang_rt/file.cpp                       |  2 +-
 flang-rt/lib/flang_rt/file.h                         |  8 ++++----
 flang-rt/lib/flang_rt/inquiry.cpp                    |  2 +-
 flang-rt/lib/flang_rt/internal-unit.cpp              |  2 +-
 flang-rt/lib/flang_rt/internal-unit.h                |  8 ++++----
 flang-rt/lib/flang_rt/io-api-common.h                |  8 ++++----
 flang-rt/lib/flang_rt/io-api-minimal.cpp             |  2 +-
 flang-rt/lib/flang_rt/io-api.cpp                     |  6 +++---
 flang-rt/lib/flang_rt/io-error.h                     | 10 +++++-----
 flang-rt/lib/flang_rt/io-stmt.cpp                    |  2 +-
 flang-rt/lib/flang_rt/io-stmt.h                      | 10 +++++-----
 flang-rt/lib/flang_rt/iostat.cpp                     |  2 +-
 flang-rt/lib/flang_rt/matmul-transpose.cpp           |  2 +-
 flang-rt/lib/flang_rt/matmul.cpp                     |  2 +-
 flang-rt/lib/flang_rt/memory.cpp                     |  2 +-
 flang-rt/lib/flang_rt/misc-intrinsic.cpp             |  2 +-
 flang-rt/lib/flang_rt/namelist.cpp                   |  2 +-
 flang-rt/lib/flang_rt/random-templates.h             |  8 ++++----
 flang-rt/lib/flang_rt/random.cpp                     |  2 +-
 flang-rt/lib/flang_rt/reduce.cpp                     |  2 +-
 flang-rt/lib/flang_rt/reduction-templates.h          |  8 ++++----
 flang-rt/lib/flang_rt/reduction.cpp                  |  2 +-
 flang-rt/lib/flang_rt/stack.h                        |  8 ++++----
 flang-rt/lib/flang_rt/stat.cpp                       |  2 +-
 flang-rt/lib/flang_rt/support.cpp                    |  2 +-
 flang-rt/lib/flang_rt/temporary-stack.cpp            |  4 ++--
 flang-rt/lib/flang_rt/time-intrinsic.cpp             |  2 +-
 flang-rt/lib/flang_rt/tools.h                        | 10 +++++-----
 flang-rt/lib/flang_rt/transformational.cpp           |  2 +-
 flang-rt/lib/flang_rt/type-code.cpp                  |  2 +-
 flang-rt/lib/flang_rt/type-info.h                    |  8 ++++----
 flang-rt/lib/flang_rt/unit-map.h                     |  8 ++++----
 flang-rt/lib/flang_rt/unit.h                         |  8 ++++----
 flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp  |  2 +-
 flang-rt/unittests/Evaluate/reshape.cpp              |  2 +-
 flang-rt/unittests/Runtime/ArrayConstructor.cpp      |  6 +++---
 flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp     |  6 +++---
 flang-rt/unittests/Runtime/CharacterTest.cpp         |  2 +-
 flang-rt/unittests/Runtime/CommandTest.cpp           |  2 +-
 flang-rt/unittests/Runtime/Derived.cpp               |  2 +-
 flang-rt/unittests/Runtime/ExternalIOTest.cpp        |  4 ++--
 flang-rt/unittests/Runtime/Inquiry.cpp               |  2 +-
 flang-rt/unittests/Runtime/ListInputTest.cpp         |  4 ++--
 flang-rt/unittests/Runtime/LogicalFormatTest.cpp     |  4 ++--
 flang-rt/unittests/Runtime/Matmul.cpp                |  4 ++--
 flang-rt/unittests/Runtime/MatmulTranspose.cpp       |  4 ++--
 flang-rt/unittests/Runtime/MiscIntrinsic.cpp         |  2 +-
 flang-rt/unittests/Runtime/Namelist.cpp              |  4 ++--
 flang-rt/unittests/Runtime/NumericalFormatTest.cpp   |  4 ++--
 flang-rt/unittests/Runtime/Pointer.cpp               |  2 +-
 flang-rt/unittests/Runtime/Random.cpp                |  4 ++--
 flang-rt/unittests/Runtime/Reduction.cpp             |  4 ++--
 flang-rt/unittests/Runtime/Support.cpp               |  2 +-
 flang-rt/unittests/Runtime/TemporaryStack.cpp        |  4 ++--
 flang-rt/unittests/Runtime/Transformational.cpp      |  2 +-
 flang-rt/unittests/Runtime/tools.h                   | 10 +++++-----
 84 files changed, 189 insertions(+), 189 deletions(-)
 rename flang-rt/include/flang-rt/{CufRuntime => CUDA}/allocator.h (85%)
 rename flang-rt/include/flang-rt/{flang_rt => }/allocator-registry.h (87%)
 rename flang-rt/include/flang-rt/{flang_rt => }/array-constructor.h (85%)
 rename flang-rt/include/flang-rt/{flang_rt => }/descriptor.h (98%)
 rename flang-rt/include/flang-rt/{flang_rt => }/io-api-funcs.h (84%)
 rename flang-rt/include/flang-rt/{flang_rt => }/iostat-funcs.h (75%)
 rename flang-rt/include/flang-rt/{flang_rt => }/memory.h (96%)
 rename flang-rt/include/flang-rt/{flang_rt => }/type-code.h (93%)

diff --git a/flang-rt/include/flang-rt/CufRuntime/allocator.h b/flang-rt/include/flang-rt/CUDA/allocator.h
similarity index 85%
rename from flang-rt/include/flang-rt/CufRuntime/allocator.h
rename to flang-rt/include/flang-rt/CUDA/allocator.h
index 63406e0de6d2fa..2899931a9cb545 100644
--- a/flang-rt/include/flang-rt/CufRuntime/allocator.h
+++ b/flang-rt/include/flang-rt/CUDA/allocator.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/CufRuntime/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,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_CUFRUNTIME_ALLOCATOR_H_
-#define FORTRAN_CUFRUNTIME_ALLOCATOR_H_
+#ifndef FLANGRT_CUDA_ALLOCATOR_H_
+#define FLANGRT_CUDA_ALLOCATOR_H_
 
 #include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
@@ -43,4 +43,4 @@ void *CUFAllocUnified(std::size_t);
 void CUFFreeUnified(void *);
 
 } // namespace Fortran::runtime::cuda
-#endif /* FORTRAN_CUFRUNTIME_ALLOCATOR_H_ */
+#endif /* FLANGRT_CUDA_ALLOCATOR_H_ */
diff --git a/flang-rt/include/flang-rt/flang_rt/allocator-registry.h b/flang-rt/include/flang-rt/allocator-registry.h
similarity index 87%
rename from flang-rt/include/flang-rt/flang_rt/allocator-registry.h
rename to flang-rt/include/flang-rt/allocator-registry.h
index ecad61ab4043d7..33e30523acaa48 100644
--- a/flang-rt/include/flang-rt/flang_rt/allocator-registry.h
+++ b/flang-rt/include/flang-rt/allocator-registry.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/flang_rt/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_FLANG_RT_ALLOCATOR_REGISTRY_H_
-#define FORTRAN_FLANG_RT_ALLOCATOR_REGISTRY_H_
+#ifndef FLANGRT_ALLOCATOR_REGISTRY_H_
+#define FLANGRT_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_FLANG_RT_ALLOCATOR_REGISTRY_H_ */
+#endif /* FLANGRT_ALLOCATOR_REGISTRY_H_ */
diff --git a/flang-rt/include/flang-rt/flang_rt/array-constructor.h b/flang-rt/include/flang-rt/array-constructor.h
similarity index 85%
rename from flang-rt/include/flang-rt/flang_rt/array-constructor.h
rename to flang-rt/include/flang-rt/array-constructor.h
index e8fffc762b6fbe..e39c6fe9d050c7 100644
--- a/flang-rt/include/flang-rt/flang_rt/array-constructor.h
+++ b/flang-rt/include/flang-rt/array-constructor.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/flang_rt/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,10 +9,10 @@
 // External APIs to create temporary storage for array constructors when their
 // final extents or length parameters cannot be pre-computed.
 
-#ifndef FORTRAN_FLANG_RT_ARRAY_CONSTRUCTOR_H_
-#define FORTRAN_FLANG_RT_ARRAY_CONSTRUCTOR_H_
+#ifndef FLANGRT_ARRAY_CONSTRUCTOR_H_
+#define FLANGRT_ARRAY_CONSTRUCTOR_H_
 
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/array-constructor-consts.h"
 #include "flang/Runtime/entry-names.h"
 #include <cstdint>
@@ -45,4 +45,4 @@ struct ArrayConstructorVector {
 };
 
 } // namespace Fortran::runtime
-#endif /* FORTRAN_FLANG_RT_ARRAY_CONSTRUCTOR_H_ */
+#endif /* FLANGRT_ARRAY_CONSTRUCTOR_H_ */
diff --git a/flang-rt/include/flang-rt/flang_rt/descriptor.h b/flang-rt/include/flang-rt/descriptor.h
similarity index 98%
rename from flang-rt/include/flang-rt/flang_rt/descriptor.h
rename to flang-rt/include/flang-rt/descriptor.h
index fea5b55c1922ce..adb69440be987c 100644
--- a/flang-rt/include/flang-rt/flang_rt/descriptor.h
+++ b/flang-rt/include/flang-rt/descriptor.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/flang_rt/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_FLANG_RT_DESCRIPTOR_H_
-#define FORTRAN_FLANG_RT_DESCRIPTOR_H_
+#ifndef FLANGRT_DESCRIPTOR_H_
+#define FLANGRT_DESCRIPTOR_H_
 
 // Defines data structures used during execution of a Fortran program
 // to implement nontrivial dummy arguments, pointers, allocatables,
@@ -18,8 +18,8 @@
 // User C code is welcome to depend on that ISO_Fortran_binding.h file,
 // but should never reference this internal header.
 
-#include "flang-rt/flang_rt/memory.h"
-#include "flang-rt/flang_rt/type-code.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/type-code.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/descriptor-consts.h"
 #include <algorithm>
@@ -482,4 +482,4 @@ class alignas(Descriptor) StaticDescriptor {
 };
 
 } // namespace Fortran::runtime
-#endif /* FORTRAN_FLANG_RT_DESCRIPTOR_H_ */
+#endif /* FLANGRT_DESCRIPTOR_H_ */
diff --git a/flang-rt/include/flang-rt/flang_rt/io-api-funcs.h b/flang-rt/include/flang-rt/io-api-funcs.h
similarity index 84%
rename from flang-rt/include/flang-rt/flang_rt/io-api-funcs.h
rename to flang-rt/include/flang-rt/io-api-funcs.h
index 00cb49ad015437..356f2d684d2f2d 100644
--- a/flang-rt/include/flang-rt/flang_rt/io-api-funcs.h
+++ b/flang-rt/include/flang-rt/io-api-funcs.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/flang_rt/io-api-funcs.h ----------------*- C++ -*-===//
+//===-- include/flang-rt/io-api-funcs.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 API between compiled code and I/O runtime library.
 
-#ifndef FORTRAN_FLANG_RT_IO_API_FUNCS_H_
-#define FORTRAN_FLANG_RT_IO_API_FUNCS_H_
+#ifndef FLANGRT_IO_API_FUNCS_H_
+#define FLANGRT_IO_API_FUNCS_H_
 
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/entry-names.h"
@@ -36,4 +36,4 @@ RT_API_ATTRS const char *InquiryKeywordHashDecode(
     char *buffer, std::size_t, InquiryKeywordHash);
 
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_FLANG_RT_IO_API_FUNCS_H_ */
+#endif /* FLANGRT_IO_API_FUNCS_H_ */
diff --git a/flang-rt/include/flang-rt/flang_rt/iostat-funcs.h b/flang-rt/include/flang-rt/iostat-funcs.h
similarity index 75%
rename from flang-rt/include/flang-rt/flang_rt/iostat-funcs.h
rename to flang-rt/include/flang-rt/iostat-funcs.h
index dd24d41fbaad10..101256103cbf29 100644
--- a/flang-rt/include/flang-rt/flang_rt/iostat-funcs.h
+++ b/flang-rt/include/flang-rt/iostat-funcs.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/flang_rt/iostat-funcs.h ----------------*- C++ -*-===//
+//===-- include/flang-rt/iostat-funcs.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 IOSTAT= specifiers
 // on I/O statements.
 
-#ifndef FORTRAN_FLANG_RT_IOSTAT_FUNCS_H_
-#define FORTRAN_FLANG_RT_IOSTAT_FUNCS_H_
+#ifndef FLANGRT_IOSTAT_FUNCS_H_
+#define FLANGRT_IOSTAT_FUNCS_H_
 
 #include "flang/Common/api-attrs.h"
 #include "flang/Runtime/iostat.h"
@@ -20,4 +20,4 @@ namespace Fortran::runtime::io {
 RT_API_ATTRS const char *IostatErrorString(int);
 
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_FLANG_RT_IOSTAT_FUNCS_H_ */
+#endif /* FLANGRT_IOSTAT_FUNCS_H_ */
diff --git a/flang-rt/include/flang-rt/flang_rt/memory.h b/flang-rt/include/flang-rt/memory.h
similarity index 96%
rename from flang-rt/include/flang-rt/flang_rt/memory.h
rename to flang-rt/include/flang-rt/memory.h
index b97f6525d60036..84cc6c5266a8ea 100644
--- a/flang-rt/include/flang-rt/flang_rt/memory.h
+++ b/flang-rt/include/flang-rt/memory.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/flang_rt/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_FLANG_RT_MEMORY_H_
-#define FORTRAN_FLANG_RT_MEMORY_H_
+#ifndef FLANGRT_MEMORY_H_
+#define FLANGRT_MEMORY_H_
 
 #include "flang/Common/api-attrs.h"
 #include <cassert>
@@ -170,4 +170,4 @@ template <typename A> struct Allocator {
 };
 } // namespace Fortran::runtime
 
-#endif /* FORTRAN_FLANG_RT_MEMORY_H_ */
+#endif /* FLANGRT_MEMORY_H_ */
diff --git a/flang-rt/include/flang-rt/flang_rt/type-code.h b/flang-rt/include/flang-rt/type-code.h
similarity index 93%
rename from flang-rt/include/flang-rt/flang_rt/type-code.h
rename to flang-rt/include/flang-rt/type-code.h
index 7c694a13431b13..409d47b82c17d8 100644
--- a/flang-rt/include/flang-rt/flang_rt/type-code.h
+++ b/flang-rt/include/flang-rt/type-code.h
@@ -1,4 +1,4 @@
-//===-- include/flang-rt/flang_rt/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_FLANG_RT_TYPE_CODE_H_
-#define FORTRAN_FLANG_RT_TYPE_CODE_H_
+#ifndef FLANGRT_TYPE_CODE_H_
+#define FLANGRT_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_FLANG_RT_TYPE_CODE_H_ */
+#endif /* FLANGRT_TYPE_CODE_H_ */
diff --git a/flang-rt/lib/CufRuntime/allocator.cpp b/flang-rt/lib/CufRuntime/allocator.cpp
index 8c16fb77f2ac46..5a5eb532595bcb 100644
--- a/flang-rt/lib/CufRuntime/allocator.cpp
+++ b/flang-rt/lib/CufRuntime/allocator.cpp
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/CufRuntime/allocator.h"
-#include "flang-rt/flang_rt/allocator-registry.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"
diff --git a/flang-rt/lib/CufRuntime/descriptor.cpp b/flang-rt/lib/CufRuntime/descriptor.cpp
index b034fc76b67d4d..5926d6e0a0f8fd 100644
--- a/flang-rt/lib/CufRuntime/descriptor.cpp
+++ b/flang-rt/lib/CufRuntime/descriptor.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/descriptor.h"
-#include "flang-rt/CufRuntime/allocator.h"
+#include "flang-rt/CUDA/allocator.h"
 
 namespace Fortran::runtime::cuda {
 extern "C" {
diff --git a/flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp b/flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
index 37bc1b9dfe426b..ce526266d22a33 100644
--- a/flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
+++ b/flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
@@ -10,8 +10,8 @@
 // as specified in section 18.5.5 of Fortran 2018.
 
 #include "ISO_Fortran_util.h"
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/type-code.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "terminator.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/pointer.h"
diff --git a/flang-rt/lib/flang_rt/ISO_Fortran_util.h b/flang-rt/lib/flang_rt/ISO_Fortran_util.h
index a7bb1d21679063..3c1163851bee6b 100644
--- a/flang-rt/lib/flang_rt/ISO_Fortran_util.h
+++ b/flang-rt/lib/flang_rt/ISO_Fortran_util.h
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_FLANG_RT_ISO_FORTRAN_UTIL_H_
-#define FORTRAN_FLANG_RT_ISO_FORTRAN_UTIL_H_
+#ifndef FLANGRT_ISO_FORTRAN_UTIL_H_
+#define FLANGRT_ISO_FORTRAN_UTIL_H_
 
 // Internal utils for establishing CFI_cdesc_t descriptors.
 
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/type-code.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "terminator.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 /* FORTRAN_FLANG_RT_ISO_FORTRAN_UTIL_H_ */
+#endif /* FLANGRT_ISO_FORTRAN_UTIL_H_ */
diff --git a/flang-rt/lib/flang_rt/allocatable.cpp b/flang-rt/lib/flang_rt/allocatable.cpp
index b9be74f8cb6f1b..393f1ecd44220f 100644
--- a/flang-rt/lib/flang_rt/allocatable.cpp
+++ b/flang-rt/lib/flang_rt/allocatable.cpp
@@ -9,7 +9,7 @@
 #include "flang/Runtime/allocatable.h"
 #include "assign-impl.h"
 #include "derived.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "type-info.h"
diff --git a/flang-rt/lib/flang_rt/allocator-registry.cpp b/flang-rt/lib/flang_rt/allocator-registry.cpp
index 538feceec13db6..b53f70bf604483 100644
--- a/flang-rt/lib/flang_rt/allocator-registry.cpp
+++ b/flang-rt/lib/flang_rt/allocator-registry.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/flang_rt/allocator-registry.h"
+#include "flang-rt/allocator-registry.h"
 #include "terminator.h"
 
 namespace Fortran::runtime {
diff --git a/flang-rt/lib/flang_rt/array-constructor.cpp b/flang-rt/lib/flang_rt/array-constructor.cpp
index daaa1e3b04a3b6..44a711ad4754fa 100644
--- a/flang-rt/lib/flang_rt/array-constructor.cpp
+++ b/flang-rt/lib/flang_rt/array-constructor.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/flang_rt/array-constructor.h"
+#include "flang-rt/array-constructor.h"
 #include "derived.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "type-info.h"
diff --git a/flang-rt/lib/flang_rt/assign.cpp b/flang-rt/lib/flang_rt/assign.cpp
index 4916fc48888189..f7fe8159dee512 100644
--- a/flang-rt/lib/flang_rt/assign.cpp
+++ b/flang-rt/lib/flang_rt/assign.cpp
@@ -9,7 +9,7 @@
 #include "flang/Runtime/assign.h"
 #include "assign-impl.h"
 #include "derived.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/flang-rt/lib/flang_rt/buffer.h b/flang-rt/lib/flang_rt/buffer.h
index eb9b0712819a6c..01a6aa28c4ac94 100644
--- a/flang-rt/lib/flang_rt/buffer.h
+++ b/flang-rt/lib/flang_rt/buffer.h
@@ -8,10 +8,10 @@
 
 // External file buffering
 
-#ifndef FORTRAN_FLANG_RT_BUFFER_H_
-#define FORTRAN_FLANG_RT_BUFFER_H_
+#ifndef FLANGRT_BUFFER_H_
+#define FLANGRT_BUFFER_H_
 
-#include "flang-rt/flang_rt/memory.h"
+#include "flang-rt/memory.h"
 #include "io-error.h"
 #include "flang/Runtime/freestanding-tools.h"
 #include <algorithm>
@@ -221,4 +221,4 @@ template <typename STORE, std::size_t minBuffer = 65536> class FileFrame {
   bool dirty_{false};
 };
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_FLANG_RT_BUFFER_H_ */
+#endif /* FLANGRT_BUFFER_H_ */
diff --git a/flang-rt/lib/flang_rt/character.cpp b/flang-rt/lib/flang_rt/character.cpp
index aeb26098c399c8..95a7c1f50a7118 100644
--- a/flang-rt/lib/flang_rt/character.cpp
+++ b/flang-rt/lib/flang_rt/character.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/character.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Common/bit-population-count.h"
diff --git a/flang-rt/lib/flang_rt/command.cpp b/flang-rt/lib/flang_rt/command.cpp
index 5c7497518f3da3..9e16b73bf62335 100644
--- a/flang-rt/lib/flang_rt/command.cpp
+++ b/flang-rt/lib/flang_rt/command.cpp
@@ -8,7 +8,7 @@
 
 #include "flang/Runtime/command.h"
 #include "environment.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/flang-rt/lib/flang_rt/copy.cpp b/flang-rt/lib/flang_rt/copy.cpp
index fc5c0af6b95851..7ef3c09b19722f 100644
--- a/flang-rt/lib/flang_rt/copy.cpp
+++ b/flang-rt/lib/flang_rt/copy.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "copy.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "stack.h"
 #include "terminator.h"
 #include "type-info.h"
diff --git a/flang-rt/lib/flang_rt/copy.h b/flang-rt/lib/flang_rt/copy.h
index 8f27c3a90b7847..f0520c23e4a471 100644
--- a/flang-rt/lib/flang_rt/copy.h
+++ b/flang-rt/lib/flang_rt/copy.h
@@ -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_FLANG_RT_COPY_H_
-#define FORTRAN_FLANG_RT_COPY_H_
+#ifndef FLANGRT_COPY_H_
+#define FLANGRT_COPY_H_
 
-#include "flang-rt/flang_rt/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_FLANG_RT_COPY_H_ */
+#endif /* FLANGRT_COPY_H_ */
diff --git a/flang-rt/lib/flang_rt/derived-api.cpp b/flang-rt/lib/flang_rt/derived-api.cpp
index faf24508981bae..5f8bb0c546715b 100644
--- a/flang-rt/lib/flang_rt/derived-api.cpp
+++ b/flang-rt/lib/flang_rt/derived-api.cpp
@@ -8,7 +8,7 @@
 
 #include "flang/Runtime/derived-api.h"
 #include "derived.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "type-info.h"
diff --git a/flang-rt/lib/flang_rt/derived.cpp b/flang-rt/lib/flang_rt/derived.cpp
index 9b17a0d437375c..27b8bb233b47e9 100644
--- a/flang-rt/lib/flang_rt/derived.cpp
+++ b/flang-rt/lib/flang_rt/derived.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "derived.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/flang-rt/lib/flang_rt/descriptor-io.h b/flang-rt/lib/flang_rt/descriptor-io.h
index 2e48b4a0353e2a..3c5abd6f97993a 100644
--- a/flang-rt/lib/flang_rt/descriptor-io.h
+++ b/flang-rt/lib/flang_rt/descriptor-io.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_FLANG_RT_DESCRIPTOR_IO_H_
-#define FORTRAN_FLANG_RT_DESCRIPTOR_IO_H_
+#ifndef FLANGRT_DESCRIPTOR_IO_H_
+#define FLANGRT_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,7 +16,7 @@
 
 #include "edit-input.h"
 #include "edit-output.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "io-stmt.h"
 #include "namelist.h"
 #include "terminator.h"
@@ -608,4 +608,4 @@ static RT_API_ATTRS bool DescriptorIO(IoStatementState &io,
   return false;
 }
 } // namespace Fortran::runtime::io::descr
-#endif /* FORTRAN_FLANG_RT_DESCRIPTOR_IO_H_ */
+#endif /* FLANGRT_DESCRIPTOR_IO_H_ */
diff --git a/flang-rt/lib/flang_rt/descriptor.cpp b/flang-rt/lib/flang_rt/descriptor.cpp
index 77536e760ad1cd..39192d6c795993 100644
--- a/flang-rt/lib/flang_rt/descriptor.cpp
+++ b/flang-rt/lib/flang_rt/descriptor.cpp
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "ISO_Fortran_util.h"
 #include "derived.h"
-#include "flang-rt/flang_rt/allocator-registry.h"
+#include "flang-rt/allocator-registry.h"
 #include "memory.h"
 #include "stat.h"
 #include "terminator.h"
diff --git a/flang-rt/lib/flang_rt/dot-product.cpp b/flang-rt/lib/flang_rt/dot-product.cpp
index 01e15ad331d7c4..8571dadf1bd69b 100644
--- a/flang-rt/lib/flang_rt/dot-product.cpp
+++ b/flang-rt/lib/flang_rt/dot-product.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "float.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/flang-rt/lib/flang_rt/execute.cpp b/flang-rt/lib/flang_rt/execute.cpp
index d3d42a49737fed..5acc00c6a64029 100644
--- a/flang-rt/lib/flang_rt/execute.cpp
+++ b/flang-rt/lib/flang_rt/execute.cpp
@@ -8,7 +8,7 @@
 
 #include "flang/Runtime/execute.h"
 #include "environment.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "stat.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/flang-rt/lib/flang_rt/extensions.cpp b/flang-rt/lib/flang_rt/extensions.cpp
index 4cd9791cd0e5cb..b71762b4a3717d 100644
--- a/flang-rt/lib/flang_rt/extensions.cpp
+++ b/flang-rt/lib/flang_rt/extensions.cpp
@@ -10,8 +10,8 @@
 // extensions that will eventually be implemented in Fortran.
 
 #include "flang/Runtime/extensions.h"
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/io-api-funcs.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-api-funcs.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Runtime/command.h"
diff --git a/flang-rt/lib/flang_rt/file.cpp b/flang-rt/lib/flang_rt/file.cpp
index d98c8afeca3514..16fdcd72b8035b 100644
--- a/flang-rt/lib/flang_rt/file.cpp
+++ b/flang-rt/lib/flang_rt/file.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "file.h"
-#include "flang-rt/flang_rt/memory.h"
+#include "flang-rt/memory.h"
 #include "tools.h"
 #include "flang/Runtime/magic-numbers.h"
 #include <algorithm>
diff --git a/flang-rt/lib/flang_rt/file.h b/flang-rt/lib/flang_rt/file.h
index b4068e3dce0d14..6975bccb987583 100644
--- a/flang-rt/lib/flang_rt/file.h
+++ b/flang-rt/lib/flang_rt/file.h
@@ -8,10 +8,10 @@
 
 // Raw system I/O wrappers
 
-#ifndef FORTRAN_FLANG_RT_FILE_H_
-#define FORTRAN_FLANG_RT_FILE_H_
+#ifndef FLANGRT_FILE_H_
+#define FLANGRT_FILE_H_
 
-#include "flang-rt/flang_rt/memory.h"
+#include "flang-rt/memory.h"
 #include "io-error.h"
 #include "flang/Common/optional.h"
 #include <cinttypes>
@@ -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_FLANG_RT_FILE_H_ */
+#endif /* FLANGRT_FILE_H_ */
diff --git a/flang-rt/lib/flang_rt/inquiry.cpp b/flang-rt/lib/flang_rt/inquiry.cpp
index b29ab4ee3c6663..bc69ed233360e9 100644
--- a/flang-rt/lib/flang_rt/inquiry.cpp
+++ b/flang-rt/lib/flang_rt/inquiry.cpp
@@ -11,7 +11,7 @@
 
 #include "flang/Runtime/inquiry.h"
 #include "copy.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include <algorithm>
diff --git a/flang-rt/lib/flang_rt/internal-unit.cpp b/flang-rt/lib/flang_rt/internal-unit.cpp
index 7775ded1e86d57..5e0029f95c2f62 100644
--- a/flang-rt/lib/flang_rt/internal-unit.cpp
+++ b/flang-rt/lib/flang_rt/internal-unit.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "internal-unit.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "io-error.h"
 #include "flang/Runtime/freestanding-tools.h"
 #include <algorithm>
diff --git a/flang-rt/lib/flang_rt/internal-unit.h b/flang-rt/lib/flang_rt/internal-unit.h
index 2f7d0220b84b37..a825e09cdd203e 100644
--- a/flang-rt/lib/flang_rt/internal-unit.h
+++ b/flang-rt/lib/flang_rt/internal-unit.h
@@ -8,11 +8,11 @@
 
 // Fortran internal I/O "units"
 
-#ifndef FORTRAN_FLANG_RT_INTERNAL_UNIT_H_
-#define FORTRAN_FLANG_RT_INTERNAL_UNIT_H_
+#ifndef FLANGRT_INTERNAL_UNIT_H_
+#define FLANGRT_INTERNAL_UNIT_H_
 
 #include "connection.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/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_FLANG_RT_INTERNAL_UNIT_H_ */
+#endif /* FLANGRT_INTERNAL_UNIT_H_ */
diff --git a/flang-rt/lib/flang_rt/io-api-common.h b/flang-rt/lib/flang_rt/io-api-common.h
index 5ff1b57c73cda6..39c87ba326bea4 100644
--- a/flang-rt/lib/flang_rt/io-api-common.h
+++ b/flang-rt/lib/flang_rt/io-api-common.h
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_FLANG_RT_IO_API_COMMON_H_
-#define FORTRAN_FLANG_RT_IO_API_COMMON_H_
+#ifndef FLANGRT_IO_API_COMMON_H_
+#define FLANGRT_IO_API_COMMON_H_
 
-#include "flang-rt/flang_rt/io-api-funcs.h"
+#include "flang-rt/io-api-funcs.h"
 #include "io-stmt.h"
 #include "terminator.h"
 #include "unit.h"
@@ -94,4 +94,4 @@ RT_API_ATTRS Cookie BeginExternalListIO(
 }
 
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_FLANG_RT_IO_API_COMMON_H_ */
+#endif /* FLANGRT_IO_API_COMMON_H_ */
diff --git a/flang-rt/lib/flang_rt/io-api-minimal.cpp b/flang-rt/lib/flang_rt/io-api-minimal.cpp
index 92524430650126..f8623f95246a06 100644
--- a/flang-rt/lib/flang_rt/io-api-minimal.cpp
+++ b/flang-rt/lib/flang_rt/io-api-minimal.cpp
@@ -10,7 +10,7 @@
 // list-directed output (PRINT *) of intrinsic types.
 
 #include "edit-output.h"
-#include "flang-rt/flang_rt/io-api-funcs.h"
+#include "flang-rt/io-api-funcs.h"
 #include "format.h"
 #include "io-api-common.h"
 #include "io-stmt.h"
diff --git a/flang-rt/lib/flang_rt/io-api.cpp b/flang-rt/lib/flang_rt/io-api.cpp
index 0de1e24f71dac5..0d7ccd3b9b41ab 100644
--- a/flang-rt/lib/flang_rt/io-api.cpp
+++ b/flang-rt/lib/flang_rt/io-api.cpp
@@ -17,9 +17,9 @@
 #include "edit-input.h"
 #include "edit-output.h"
 #include "environment.h"
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/io-api-funcs.h"
-#include "flang-rt/flang_rt/memory.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-api-funcs.h"
+#include "flang-rt/memory.h"
 #include "format.h"
 #include "io-api-common.h"
 #include "io-stmt.h"
diff --git a/flang-rt/lib/flang_rt/io-error.h b/flang-rt/lib/flang_rt/io-error.h
index 7798d0830a1323..775c5d66d83530 100644
--- a/flang-rt/lib/flang_rt/io-error.h
+++ b/flang-rt/lib/flang_rt/io-error.h
@@ -12,11 +12,11 @@
 // IOSTAT error codes are raw errno values augmented with values for
 // Fortran-specific errors.
 
-#ifndef FORTRAN_FLANG_RT_IO_ERROR_H_
-#define FORTRAN_FLANG_RT_IO_ERROR_H_
+#ifndef FLANGRT_IO_ERROR_H_
+#define FLANGRT_IO_ERROR_H_
 
-#include "flang-rt/flang_rt/iostat-funcs.h"
-#include "flang-rt/flang_rt/memory.h"
+#include "flang-rt/iostat-funcs.h"
+#include "flang-rt/memory.h"
 #include "terminator.h"
 #include <cinttypes>
 
@@ -78,4 +78,4 @@ class IoErrorHandler : public Terminator {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_FLANG_RT_IO_ERROR_H_ */
+#endif /* FLANGRT_IO_ERROR_H_ */
diff --git a/flang-rt/lib/flang_rt/io-stmt.cpp b/flang-rt/lib/flang_rt/io-stmt.cpp
index 7c243a8c934a7a..4757da189210e6 100644
--- a/flang-rt/lib/flang_rt/io-stmt.cpp
+++ b/flang-rt/lib/flang_rt/io-stmt.cpp
@@ -9,7 +9,7 @@
 #include "io-stmt.h"
 #include "connection.h"
 #include "emit-encoded.h"
-#include "flang-rt/flang_rt/memory.h"
+#include "flang-rt/memory.h"
 #include "format.h"
 #include "tools.h"
 #include "unit.h"
diff --git a/flang-rt/lib/flang_rt/io-stmt.h b/flang-rt/lib/flang_rt/io-stmt.h
index 78bc42502be687..c7bde114457f0e 100644
--- a/flang-rt/lib/flang_rt/io-stmt.h
+++ b/flang-rt/lib/flang_rt/io-stmt.h
@@ -8,13 +8,13 @@
 
 // Representations of the state of an I/O statement in progress
 
-#ifndef FORTRAN_FLANG_RT_IO_STMT_H_
-#define FORTRAN_FLANG_RT_IO_STMT_H_
+#ifndef FLANGRT_IO_STMT_H_
+#define FLANGRT_IO_STMT_H_
 
 #include "connection.h"
 #include "file.h"
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/io-api-funcs.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-api-funcs.h"
 #include "format.h"
 #include "internal-unit.h"
 #include "io-error.h"
@@ -789,4 +789,4 @@ class ErroneousIoStatementState : public IoStatementBase {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_FLANG_RT_IO_STMT_H_ */
+#endif /* FLANGRT_IO_STMT_H_ */
diff --git a/flang-rt/lib/flang_rt/iostat.cpp b/flang-rt/lib/flang_rt/iostat.cpp
index 39f4474dcf7229..fd2dafd67d15d2 100644
--- a/flang-rt/lib/flang_rt/iostat.cpp
+++ b/flang-rt/lib/flang_rt/iostat.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/flang_rt/iostat-funcs.h"
+#include "flang-rt/iostat-funcs.h"
 
 namespace Fortran::runtime::io {
 RT_OFFLOAD_API_GROUP_BEGIN
diff --git a/flang-rt/lib/flang_rt/matmul-transpose.cpp b/flang-rt/lib/flang_rt/matmul-transpose.cpp
index 2c7c4a89117f04..9ada515133f644 100644
--- a/flang-rt/lib/flang_rt/matmul-transpose.cpp
+++ b/flang-rt/lib/flang_rt/matmul-transpose.cpp
@@ -21,7 +21,7 @@
 // to use the faster BLAS routines.
 
 #include "flang/Runtime/matmul-transpose.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Common/optional.h"
diff --git a/flang-rt/lib/flang_rt/matmul.cpp b/flang-rt/lib/flang_rt/matmul.cpp
index 8157911f34fd38..e9b4af8f30eaf5 100644
--- a/flang-rt/lib/flang_rt/matmul.cpp
+++ b/flang-rt/lib/flang_rt/matmul.cpp
@@ -20,7 +20,7 @@
 // Places where BLAS routines could be called are marked as TODO items.
 
 #include "flang/Runtime/matmul.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Common/optional.h"
diff --git a/flang-rt/lib/flang_rt/memory.cpp b/flang-rt/lib/flang_rt/memory.cpp
index 66aa5be0cddc60..50e3f46d8254dd 100644
--- a/flang-rt/lib/flang_rt/memory.cpp
+++ b/flang-rt/lib/flang_rt/memory.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/flang_rt/memory.h"
+#include "flang-rt/memory.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Runtime/freestanding-tools.h"
diff --git a/flang-rt/lib/flang_rt/misc-intrinsic.cpp b/flang-rt/lib/flang_rt/misc-intrinsic.cpp
index 00098c5b4e20b0..5860bdfbc93e69 100644
--- a/flang-rt/lib/flang_rt/misc-intrinsic.cpp
+++ b/flang-rt/lib/flang_rt/misc-intrinsic.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/misc-intrinsic.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Common/optional.h"
diff --git a/flang-rt/lib/flang_rt/namelist.cpp b/flang-rt/lib/flang_rt/namelist.cpp
index 92dbd33b7f9609..2b30315a3a1cc4 100644
--- a/flang-rt/lib/flang_rt/namelist.cpp
+++ b/flang-rt/lib/flang_rt/namelist.cpp
@@ -9,7 +9,7 @@
 #include "namelist.h"
 #include "descriptor-io.h"
 #include "emit-encoded.h"
-#include "flang-rt/flang_rt/io-api-funcs.h"
+#include "flang-rt/io-api-funcs.h"
 #include "io-stmt.h"
 #include <algorithm>
 #include <cstring>
diff --git a/flang-rt/lib/flang_rt/random-templates.h b/flang-rt/lib/flang_rt/random-templates.h
index 475c972a823226..8ed5757ec76a76 100644
--- a/flang-rt/lib/flang_rt/random-templates.h
+++ b/flang-rt/lib/flang_rt/random-templates.h
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_FLANG_RT_RANDOM_TEMPLATES_H_
-#define FORTRAN_FLANG_RT_RANDOM_TEMPLATES_H_
+#ifndef FLANGRT_RANDOM_TEMPLATES_H_
+#define FLANGRT_RANDOM_TEMPLATES_H_
 
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "lock.h"
 #include "numeric-templates.h"
 #include "flang/Common/optional.h"
@@ -85,4 +85,4 @@ inline void Generate(const Descriptor &harvest) {
 
 } // namespace Fortran::runtime::random
 
-#endif /* FORTRAN_FLANG_RT_RANDOM_TEMPLATES_H_ */
+#endif /* FLANGRT_RANDOM_TEMPLATES_H_ */
diff --git a/flang-rt/lib/flang_rt/random.cpp b/flang-rt/lib/flang_rt/random.cpp
index 9922ae87b084a8..922411d84fc845 100644
--- a/flang-rt/lib/flang_rt/random.cpp
+++ b/flang-rt/lib/flang_rt/random.cpp
@@ -10,7 +10,7 @@
 // RANDOM_SEED.
 
 #include "flang/Runtime/random.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "lock.h"
 #include "random-templates.h"
 #include "terminator.h"
diff --git a/flang-rt/lib/flang_rt/reduce.cpp b/flang-rt/lib/flang_rt/reduce.cpp
index 6997d4c63065b9..d227bd1794c321 100644
--- a/flang-rt/lib/flang_rt/reduce.cpp
+++ b/flang-rt/lib/flang_rt/reduce.cpp
@@ -9,7 +9,7 @@
 // REDUCE() implementation
 
 #include "flang/Runtime/reduce.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "reduction-templates.h"
 #include "terminator.h"
 #include "tools.h"
diff --git a/flang-rt/lib/flang_rt/reduction-templates.h b/flang-rt/lib/flang_rt/reduction-templates.h
index 774b6f3c99850f..6764706c3fa951 100644
--- a/flang-rt/lib/flang_rt/reduction-templates.h
+++ b/flang-rt/lib/flang_rt/reduction-templates.h
@@ -18,10 +18,10 @@
 // * Character-valued reductions (MAXVAL & MINVAL) return arbitrary
 //   length results, dynamically allocated in a caller-supplied descriptor
 
-#ifndef FORTRAN_FLANG_RT_REDUCTION_TEMPLATES_H_
-#define FORTRAN_FLANG_RT_REDUCTION_TEMPLATES_H_
+#ifndef FLANGRT_REDUCTION_TEMPLATES_H_
+#define FLANGRT_REDUCTION_TEMPLATES_H_
 
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "numeric-templates.h"
 #include "terminator.h"
 #include "tools.h"
@@ -412,4 +412,4 @@ template <int KIND> struct Norm2Helper {
 };
 
 } // namespace Fortran::runtime
-#endif /* FORTRAN_FLANG_RT_REDUCTION_TEMPLATES_H_ */
+#endif /* FLANGRT_REDUCTION_TEMPLATES_H_ */
diff --git a/flang-rt/lib/flang_rt/reduction.cpp b/flang-rt/lib/flang_rt/reduction.cpp
index f9d5f442e8928f..dd53ac3d27597b 100644
--- a/flang-rt/lib/flang_rt/reduction.cpp
+++ b/flang-rt/lib/flang_rt/reduction.cpp
@@ -14,7 +14,7 @@
 // NORM2, MAXLOC, MINLOC, MAXVAL, and MINVAL are in extrema.cpp.
 
 #include "flang/Runtime/reduction.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "reduction-templates.h"
 #include <cinttypes>
 
diff --git a/flang-rt/lib/flang_rt/stack.h b/flang-rt/lib/flang_rt/stack.h
index 4c1ab4e85ed71f..4b0de1e59e4596 100644
--- a/flang-rt/lib/flang_rt/stack.h
+++ b/flang-rt/lib/flang_rt/stack.h
@@ -10,10 +10,10 @@
 // It is a list based stack with dynamic allocation/deallocation
 // of the list nodes.
 
-#ifndef FORTRAN_FLANG_RT_STACK_H_
-#define FORTRAN_FLANG_RT_STACK_H_
+#ifndef FLANGRT_STACK_H_
+#define FLANGRT_STACK_H_
 
-#include "flang-rt/flang_rt/memory.h"
+#include "flang-rt/memory.h"
 #include "terminator.h"
 
 namespace Fortran::runtime {
@@ -133,4 +133,4 @@ template <typename T, unsigned N = 0> class Stack : public StackStorage<T, N> {
   Terminator &terminator_;
 };
 } // namespace Fortran::runtime
-#endif /* FORTRAN_FLANG_RT_STACK_H_ */
+#endif /* FLANGRT_STACK_H_ */
diff --git a/flang-rt/lib/flang_rt/stat.cpp b/flang-rt/lib/flang_rt/stat.cpp
index 77eefe3d1ac518..db6ddf741966e7 100644
--- a/flang-rt/lib/flang_rt/stat.cpp
+++ b/flang-rt/lib/flang_rt/stat.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "stat.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 
diff --git a/flang-rt/lib/flang_rt/support.cpp b/flang-rt/lib/flang_rt/support.cpp
index 436ae6f87ae692..3a037fd3180264 100644
--- a/flang-rt/lib/flang_rt/support.cpp
+++ b/flang-rt/lib/flang_rt/support.cpp
@@ -8,7 +8,7 @@
 
 #include "flang/Runtime/support.h"
 #include "ISO_Fortran_util.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "type-info.h"
 
 namespace Fortran::runtime {
diff --git a/flang-rt/lib/flang_rt/temporary-stack.cpp b/flang-rt/lib/flang_rt/temporary-stack.cpp
index f566e6d8a086ff..6b84f5ebdd9edb 100644
--- a/flang-rt/lib/flang_rt/temporary-stack.cpp
+++ b/flang-rt/lib/flang_rt/temporary-stack.cpp
@@ -10,8 +10,8 @@
 // temporaries. For use in HLFIR lowering.
 
 #include "flang/Runtime/temporary-stack.h"
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/memory.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/memory.h"
 #include "terminator.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/assign.h"
diff --git a/flang-rt/lib/flang_rt/time-intrinsic.cpp b/flang-rt/lib/flang_rt/time-intrinsic.cpp
index daba1bd8f6b8f5..43559ccc380974 100644
--- a/flang-rt/lib/flang_rt/time-intrinsic.cpp
+++ b/flang-rt/lib/flang_rt/time-intrinsic.cpp
@@ -9,7 +9,7 @@
 // Implements time-related intrinsic subroutines.
 
 #include "flang/Runtime/time-intrinsic.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Runtime/cpp-type.h"
diff --git a/flang-rt/lib/flang_rt/tools.h b/flang-rt/lib/flang_rt/tools.h
index 9880d0e93f5a82..bc2f4ff034cb13 100644
--- a/flang-rt/lib/flang_rt/tools.h
+++ b/flang-rt/lib/flang_rt/tools.h
@@ -6,11 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_FLANG_RT_TOOLS_H_
-#define FORTRAN_FLANG_RT_TOOLS_H_
+#ifndef FLANGRT_TOOLS_H_
+#define FLANGRT_TOOLS_H_
 
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/memory.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/memory.h"
 #include "stat.h"
 #include "terminator.h"
 #include "flang/Common/optional.h"
@@ -535,4 +535,4 @@ RT_API_ATTRS void CreatePartialReductionResult(Descriptor &result,
     const char *intrinsic, TypeCode);
 
 } // namespace Fortran::runtime
-#endif /* FORTRAN_FLANG_RT_TOOLS_H_ */
+#endif /* FLANGRT_TOOLS_H_ */
diff --git a/flang-rt/lib/flang_rt/transformational.cpp b/flang-rt/lib/flang_rt/transformational.cpp
index f21c63fbfd7a1b..2ad48db1453f15 100644
--- a/flang-rt/lib/flang_rt/transformational.cpp
+++ b/flang-rt/lib/flang_rt/transformational.cpp
@@ -18,7 +18,7 @@
 
 #include "flang/Runtime/transformational.h"
 #include "copy.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Common/float128.h"
diff --git a/flang-rt/lib/flang_rt/type-code.cpp b/flang-rt/lib/flang_rt/type-code.cpp
index 96fabf7ec7698f..937b3fa73eb8f1 100644
--- a/flang-rt/lib/flang_rt/type-code.cpp
+++ b/flang-rt/lib/flang_rt/type-code.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/flang_rt/type-code.h"
+#include "flang-rt/type-code.h"
 #include <cstdint>
 
 namespace Fortran::runtime {
diff --git a/flang-rt/lib/flang_rt/type-info.h b/flang-rt/lib/flang_rt/type-info.h
index 3b0b193d63379c..891a6a0d032127 100644
--- a/flang-rt/lib/flang_rt/type-info.h
+++ b/flang-rt/lib/flang_rt/type-info.h
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_FLANG_RT_TYPE_INFO_H_
-#define FORTRAN_FLANG_RT_TYPE_INFO_H_
+#ifndef FLANGRT_TYPE_INFO_H_
+#define FLANGRT_TYPE_INFO_H_
 
 // A C++ perspective of the derived type description schemata in
 // flang/module/__fortran_type_info.f90.
 
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "terminator.h"
 #include "flang/Common/Fortran-consts.h"
 #include "flang/Common/bit-population-count.h"
@@ -321,4 +321,4 @@ class DerivedType {
 };
 
 } // namespace Fortran::runtime::typeInfo
-#endif /* FORTRAN_FLANG_RT_TYPE_INFO_H_ */
+#endif /* FLANGRT_TYPE_INFO_H_ */
diff --git a/flang-rt/lib/flang_rt/unit-map.h b/flang-rt/lib/flang_rt/unit-map.h
index 7215a5677f006b..50aa74aeed05bf 100644
--- a/flang-rt/lib/flang_rt/unit-map.h
+++ b/flang-rt/lib/flang_rt/unit-map.h
@@ -9,10 +9,10 @@
 // Maps Fortran unit numbers to their ExternalFileUnit instances.
 // A simple hash table with forward-linked chains per bucket.
 
-#ifndef FORTRAN_FLANG_RT_UNIT_MAP_H_
-#define FORTRAN_FLANG_RT_UNIT_MAP_H_
+#ifndef FLANGRT_UNIT_MAP_H_
+#define FLANGRT_UNIT_MAP_H_
 
-#include "flang-rt/flang_rt/memory.h"
+#include "flang-rt/memory.h"
 #include "lock.h"
 #include "unit.h"
 #include "flang/Common/fast-int-set.h"
@@ -100,4 +100,4 @@ class UnitMap {
   int emergencyNewUnit_{maxNewUnits_}; // not recycled
 };
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_FLANG_RT_UNIT_MAP_H_ */
+#endif /* FLANGRT_UNIT_MAP_H_ */
diff --git a/flang-rt/lib/flang_rt/unit.h b/flang-rt/lib/flang_rt/unit.h
index 077a34833734ac..5049f3c5db80f7 100644
--- a/flang-rt/lib/flang_rt/unit.h
+++ b/flang-rt/lib/flang_rt/unit.h
@@ -8,14 +8,14 @@
 
 // Fortran external I/O units
 
-#ifndef FORTRAN_FLANG_RT_UNIT_H_
-#define FORTRAN_FLANG_RT_UNIT_H_
+#ifndef FLANGRT_UNIT_H_
+#define FLANGRT_UNIT_H_
 
 #include "buffer.h"
 #include "connection.h"
 #include "environment.h"
 #include "file.h"
-#include "flang-rt/flang_rt/memory.h"
+#include "flang-rt/memory.h"
 #include "format.h"
 #include "io-error.h"
 #include "io-stmt.h"
@@ -291,4 +291,4 @@ class ChildIo {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FORTRAN_FLANG_RT_UNIT_H_ */
+#endif /* FLANGRT_UNIT_H_ */
diff --git a/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp b/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp
index 03cc59291787aa..90fb820d3df7be 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/flang_rt/descriptor.h"
+#include "flang-rt/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 c9ead4fe744f91..a45e06ad0f69d1 100644
--- a/flang-rt/unittests/Evaluate/reshape.cpp
+++ b/flang-rt/unittests/Evaluate/reshape.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/transformational.h"
 #include "flang/Testing/testing.h"
 #include <cinttypes>
diff --git a/flang-rt/unittests/Runtime/ArrayConstructor.cpp b/flang-rt/unittests/Runtime/ArrayConstructor.cpp
index c52ce8e4ea54fd..9cc30cb5d2abbe 100644
--- a/flang-rt/unittests/Runtime/ArrayConstructor.cpp
+++ b/flang-rt/unittests/Runtime/ArrayConstructor.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/flang_rt/array-constructor.h"
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/type-code.h"
+#include "flang-rt/array-constructor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Runtime/allocatable.h"
diff --git a/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
index 46461a863c0696..1f516e7821e3e0 100644
--- a/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "cuda_runtime.h"
-#include "flang-rt/flang_rt/allocator-registry.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/CUDA/allocator.h"
+#include "flang-rt/allocator-registry.h"
+#include "flang-rt/descriptor.h"
 #include "gtest/gtest.h"
 #include "../../../lib/flang_rt/terminator.h"
-#include "flang-rt/CufRuntime/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/CharacterTest.cpp b/flang-rt/unittests/Runtime/CharacterTest.cpp
index 3a4b5706e53849..ecda7e61b15de8 100644
--- a/flang-rt/unittests/Runtime/CharacterTest.cpp
+++ b/flang-rt/unittests/Runtime/CharacterTest.cpp
@@ -10,7 +10,7 @@
 // in Fortran.
 
 #include "flang/Runtime/character.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "gtest/gtest.h"
 #include <cstring>
 #include <functional>
diff --git a/flang-rt/unittests/Runtime/CommandTest.cpp b/flang-rt/unittests/Runtime/CommandTest.cpp
index 15b2ed2e42bba1..15d869f0b38231 100644
--- a/flang-rt/unittests/Runtime/CommandTest.cpp
+++ b/flang-rt/unittests/Runtime/CommandTest.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/command.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include "flang/Runtime/execute.h"
diff --git a/flang-rt/unittests/Runtime/Derived.cpp b/flang-rt/unittests/Runtime/Derived.cpp
index 055174a3b5a907..9e7e11f36237cb 100644
--- a/flang-rt/unittests/Runtime/Derived.cpp
+++ b/flang-rt/unittests/Runtime/Derived.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Runtime/derived-api.h"
diff --git a/flang-rt/unittests/Runtime/ExternalIOTest.cpp b/flang-rt/unittests/Runtime/ExternalIOTest.cpp
index a93ee97da8f5f7..e0ca108126f14d 100644
--- a/flang-rt/unittests/Runtime/ExternalIOTest.cpp
+++ b/flang-rt/unittests/Runtime/ExternalIOTest.cpp
@@ -11,8 +11,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/io-api-funcs.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-api-funcs.h"
 #include "gtest/gtest.h"
 #include "flang/Runtime/main.h"
 #include "flang/Runtime/stop.h"
diff --git a/flang-rt/unittests/Runtime/Inquiry.cpp b/flang-rt/unittests/Runtime/Inquiry.cpp
index 0bda07aaef295c..f30f73940aabe7 100644
--- a/flang-rt/unittests/Runtime/Inquiry.cpp
+++ b/flang-rt/unittests/Runtime/Inquiry.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/inquiry.h"
-#include "flang-rt/flang_rt/type-code.h"
+#include "flang-rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 
diff --git a/flang-rt/unittests/Runtime/ListInputTest.cpp b/flang-rt/unittests/Runtime/ListInputTest.cpp
index 7e04ab834eb247..3c40f2c1353aaa 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/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/io-api-funcs.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-api-funcs.h"
 #include "../../lib/flang_rt/io-error.h"
 
 using namespace Fortran::runtime;
diff --git a/flang-rt/unittests/Runtime/LogicalFormatTest.cpp b/flang-rt/unittests/Runtime/LogicalFormatTest.cpp
index b5a9e2d317841f..0b09c9478eb0c0 100644
--- a/flang-rt/unittests/Runtime/LogicalFormatTest.cpp
+++ b/flang-rt/unittests/Runtime/LogicalFormatTest.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/io-api-funcs.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-api-funcs.h"
 #include <algorithm>
 #include <array>
 #include <cstring>
diff --git a/flang-rt/unittests/Runtime/Matmul.cpp b/flang-rt/unittests/Runtime/Matmul.cpp
index e833b3861badac..797743379076e1 100644
--- a/flang-rt/unittests/Runtime/Matmul.cpp
+++ b/flang-rt/unittests/Runtime/Matmul.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/matmul.h"
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/type-code.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Runtime/allocatable.h"
diff --git a/flang-rt/unittests/Runtime/MatmulTranspose.cpp b/flang-rt/unittests/Runtime/MatmulTranspose.cpp
index 560f62935e35bc..beff22322174af 100644
--- a/flang-rt/unittests/Runtime/MatmulTranspose.cpp
+++ b/flang-rt/unittests/Runtime/MatmulTranspose.cpp
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/type-code.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Runtime/allocatable.h"
diff --git a/flang-rt/unittests/Runtime/MiscIntrinsic.cpp b/flang-rt/unittests/Runtime/MiscIntrinsic.cpp
index ca3a3e4fd3b839..1c3e064ac756b7 100644
--- a/flang-rt/unittests/Runtime/MiscIntrinsic.cpp
+++ b/flang-rt/unittests/Runtime/MiscIntrinsic.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Runtime/allocatable.h"
diff --git a/flang-rt/unittests/Runtime/Namelist.cpp b/flang-rt/unittests/Runtime/Namelist.cpp
index d30625f23bfc1c..a96cc3c0230579 100644
--- a/flang-rt/unittests/Runtime/Namelist.cpp
+++ b/flang-rt/unittests/Runtime/Namelist.cpp
@@ -8,8 +8,8 @@
 
 #include "../../lib/flang_rt/namelist.h"
 #include "CrashHandlerFixture.h"
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/io-api-funcs.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-api-funcs.h"
 #include "tools.h"
 #include <algorithm>
 #include <cinttypes>
diff --git a/flang-rt/unittests/Runtime/NumericalFormatTest.cpp b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
index 6c11bb0d4a49d6..bb3c5d091e980b 100644
--- a/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
+++ b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/io-api-funcs.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-api-funcs.h"
 #include <algorithm>
 #include <array>
 #include <cstring>
diff --git a/flang-rt/unittests/Runtime/Pointer.cpp b/flang-rt/unittests/Runtime/Pointer.cpp
index c787ed9e71eee9..76663d6e7a1807 100644
--- a/flang-rt/unittests/Runtime/Pointer.cpp
+++ b/flang-rt/unittests/Runtime/Pointer.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/pointer.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 
diff --git a/flang-rt/unittests/Runtime/Random.cpp b/flang-rt/unittests/Runtime/Random.cpp
index bd4fcfd5e87975..bc60a59dd63d48 100644
--- a/flang-rt/unittests/Runtime/Random.cpp
+++ b/flang-rt/unittests/Runtime/Random.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/random.h"
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/type-code.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "gtest/gtest.h"
 #include <cmath>
 
diff --git a/flang-rt/unittests/Runtime/Reduction.cpp b/flang-rt/unittests/Runtime/Reduction.cpp
index 0f3789b017c6f6..b054c38512f666 100644
--- a/flang-rt/unittests/Runtime/Reduction.cpp
+++ b/flang-rt/unittests/Runtime/Reduction.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/reduction.h"
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/type-code.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Common/float128.h"
diff --git a/flang-rt/unittests/Runtime/Support.cpp b/flang-rt/unittests/Runtime/Support.cpp
index d37369df025f45..fc547b7bedc932 100644
--- a/flang-rt/unittests/Runtime/Support.cpp
+++ b/flang-rt/unittests/Runtime/Support.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/support.h"
-#include "flang-rt/flang_rt/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 
diff --git a/flang-rt/unittests/Runtime/TemporaryStack.cpp b/flang-rt/unittests/Runtime/TemporaryStack.cpp
index 8a9f2dfe6d22f1..aa594e66359f10 100644
--- a/flang-rt/unittests/Runtime/TemporaryStack.cpp
+++ b/flang-rt/unittests/Runtime/TemporaryStack.cpp
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/type-code.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
diff --git a/flang-rt/unittests/Runtime/Transformational.cpp b/flang-rt/unittests/Runtime/Transformational.cpp
index e8981e9b122eb7..0757cc04c21903 100644
--- a/flang-rt/unittests/Runtime/Transformational.cpp
+++ b/flang-rt/unittests/Runtime/Transformational.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/transformational.h"
-#include "flang-rt/flang_rt/type-code.h"
+#include "flang-rt/type-code.h"
 #include "gtest/gtest.h"
 #include "tools.h"
 #include "flang/Common/float128.h"
diff --git a/flang-rt/unittests/Runtime/tools.h b/flang-rt/unittests/Runtime/tools.h
index 7edeff7f7eb579..414175bde07d04 100644
--- a/flang-rt/unittests/Runtime/tools.h
+++ b/flang-rt/unittests/Runtime/tools.h
@@ -6,11 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
-#define FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
+#ifndef FLANGRT_UNITTESTS_RUNTIME_TOOLS_H_
+#define FLANGRT_UNITTESTS_RUNTIME_TOOLS_H_
 
-#include "flang-rt/flang_rt/descriptor.h"
-#include "flang-rt/flang_rt/type-code.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "gtest/gtest.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
@@ -54,4 +54,4 @@ static OwningPtr<Descriptor> MakeArray(const std::vector<int> &shape,
 }
 
 } // namespace Fortran::runtime
-#endif /* FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_ */
+#endif /* FLANGRT_UNITTESTS_RUNTIME_TOOLS_H_ */

>From 68ed6280b24aad2a31b99f0bfe1a7caf1b60aca1 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 11 Nov 2024 17:16:39 +0100
Subject: [PATCH 12/12] FLANGRT -> FLANG_RT

---
 flang-rt/include/flang-rt/CUDA/allocator.h     | 6 +++---
 flang-rt/include/flang-rt/allocator-registry.h | 6 +++---
 flang-rt/include/flang-rt/array-constructor.h  | 6 +++---
 flang-rt/include/flang-rt/descriptor.h         | 6 +++---
 flang-rt/include/flang-rt/io-api-funcs.h       | 6 +++---
 flang-rt/include/flang-rt/iostat-funcs.h       | 6 +++---
 flang-rt/include/flang-rt/memory.h             | 6 +++---
 flang-rt/include/flang-rt/type-code.h          | 6 +++---
 flang-rt/lib/flang_rt/ISO_Fortran_util.h       | 6 +++---
 flang-rt/lib/flang_rt/buffer.h                 | 6 +++---
 flang-rt/lib/flang_rt/copy.h                   | 6 +++---
 flang-rt/lib/flang_rt/descriptor-io.h          | 6 +++---
 flang-rt/lib/flang_rt/file.h                   | 6 +++---
 flang-rt/lib/flang_rt/internal-unit.h          | 6 +++---
 flang-rt/lib/flang_rt/io-api-common.h          | 6 +++---
 flang-rt/lib/flang_rt/io-error.h               | 6 +++---
 flang-rt/lib/flang_rt/io-stmt.h                | 6 +++---
 flang-rt/lib/flang_rt/random-templates.h       | 6 +++---
 flang-rt/lib/flang_rt/reduction-templates.h    | 6 +++---
 flang-rt/lib/flang_rt/stack.h                  | 6 +++---
 flang-rt/lib/flang_rt/tools.h                  | 6 +++---
 flang-rt/lib/flang_rt/type-info.h              | 6 +++---
 flang-rt/lib/flang_rt/unit-map.h               | 6 +++---
 flang-rt/lib/flang_rt/unit.h                   | 6 +++---
 flang-rt/unittests/Runtime/tools.h             | 6 +++---
 25 files changed, 75 insertions(+), 75 deletions(-)

diff --git a/flang-rt/include/flang-rt/CUDA/allocator.h b/flang-rt/include/flang-rt/CUDA/allocator.h
index 2899931a9cb545..31ca99c646ca77 100644
--- a/flang-rt/include/flang-rt/CUDA/allocator.h
+++ b/flang-rt/include/flang-rt/CUDA/allocator.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FLANGRT_CUDA_ALLOCATOR_H_
-#define FLANGRT_CUDA_ALLOCATOR_H_
+#ifndef FLANG_RT_CUDA_ALLOCATOR_H_
+#define FLANG_RT_CUDA_ALLOCATOR_H_
 
 #include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
@@ -43,4 +43,4 @@ void *CUFAllocUnified(std::size_t);
 void CUFFreeUnified(void *);
 
 } // namespace Fortran::runtime::cuda
-#endif /* FLANGRT_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 33e30523acaa48..1f004462ca6241 100644
--- a/flang-rt/include/flang-rt/allocator-registry.h
+++ b/flang-rt/include/flang-rt/allocator-registry.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FLANGRT_ALLOCATOR_REGISTRY_H_
-#define FLANGRT_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 /* FLANGRT_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 e39c6fe9d050c7..a0aee59beac744 100644
--- a/flang-rt/include/flang-rt/array-constructor.h
+++ b/flang-rt/include/flang-rt/array-constructor.h
@@ -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 FLANGRT_ARRAY_CONSTRUCTOR_H_
-#define FLANGRT_ARRAY_CONSTRUCTOR_H_
+#ifndef FLANG_RT_ARRAY_CONSTRUCTOR_H_
+#define FLANG_RT_ARRAY_CONSTRUCTOR_H_
 
 #include "flang-rt/descriptor.h"
 #include "flang/Runtime/array-constructor-consts.h"
@@ -45,4 +45,4 @@ struct ArrayConstructorVector {
 };
 
 } // namespace Fortran::runtime
-#endif /* FLANGRT_ARRAY_CONSTRUCTOR_H_ */
+#endif /* FLANG_RT_ARRAY_CONSTRUCTOR_H_ */
diff --git a/flang-rt/include/flang-rt/descriptor.h b/flang-rt/include/flang-rt/descriptor.h
index adb69440be987c..4e129468e4fe6e 100644
--- a/flang-rt/include/flang-rt/descriptor.h
+++ b/flang-rt/include/flang-rt/descriptor.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FLANGRT_DESCRIPTOR_H_
-#define FLANGRT_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,
@@ -482,4 +482,4 @@ class alignas(Descriptor) StaticDescriptor {
 };
 
 } // namespace Fortran::runtime
-#endif /* FLANGRT_DESCRIPTOR_H_ */
+#endif /* FLANG_RT_DESCRIPTOR_H_ */
diff --git a/flang-rt/include/flang-rt/io-api-funcs.h b/flang-rt/include/flang-rt/io-api-funcs.h
index 356f2d684d2f2d..dda2f5dc96184b 100644
--- a/flang-rt/include/flang-rt/io-api-funcs.h
+++ b/flang-rt/include/flang-rt/io-api-funcs.h
@@ -8,8 +8,8 @@
 
 // Defines API between compiled code and I/O runtime library.
 
-#ifndef FLANGRT_IO_API_FUNCS_H_
-#define FLANGRT_IO_API_FUNCS_H_
+#ifndef FLANG_RT_IO_API_FUNCS_H_
+#define FLANG_RT_IO_API_FUNCS_H_
 
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/entry-names.h"
@@ -36,4 +36,4 @@ RT_API_ATTRS const char *InquiryKeywordHashDecode(
     char *buffer, std::size_t, InquiryKeywordHash);
 
 } // namespace Fortran::runtime::io
-#endif /* FLANGRT_IO_API_FUNCS_H_ */
+#endif /* FLANG_RT_IO_API_FUNCS_H_ */
diff --git a/flang-rt/include/flang-rt/iostat-funcs.h b/flang-rt/include/flang-rt/iostat-funcs.h
index 101256103cbf29..0edb8f402c4fe8 100644
--- a/flang-rt/include/flang-rt/iostat-funcs.h
+++ b/flang-rt/include/flang-rt/iostat-funcs.h
@@ -9,8 +9,8 @@
 // Defines the values returned by the runtime for IOSTAT= specifiers
 // on I/O statements.
 
-#ifndef FLANGRT_IOSTAT_FUNCS_H_
-#define FLANGRT_IOSTAT_FUNCS_H_
+#ifndef FLANG_RT_IOSTAT_FUNCS_H_
+#define FLANG_RT_IOSTAT_FUNCS_H_
 
 #include "flang/Common/api-attrs.h"
 #include "flang/Runtime/iostat.h"
@@ -20,4 +20,4 @@ namespace Fortran::runtime::io {
 RT_API_ATTRS const char *IostatErrorString(int);
 
 } // namespace Fortran::runtime::io
-#endif /* FLANGRT_IOSTAT_FUNCS_H_ */
+#endif /* FLANG_RT_IOSTAT_FUNCS_H_ */
diff --git a/flang-rt/include/flang-rt/memory.h b/flang-rt/include/flang-rt/memory.h
index 84cc6c5266a8ea..afbb1b34c1d2c0 100644
--- a/flang-rt/include/flang-rt/memory.h
+++ b/flang-rt/include/flang-rt/memory.h
@@ -9,8 +9,8 @@
 // Thin wrapper around malloc()/free() to isolate the dependency,
 // ease porting, and provide an owning pointer.
 
-#ifndef FLANGRT_MEMORY_H_
-#define FLANGRT_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 /* FLANGRT_MEMORY_H_ */
+#endif /* FLANG_RT_MEMORY_H_ */
diff --git a/flang-rt/include/flang-rt/type-code.h b/flang-rt/include/flang-rt/type-code.h
index 409d47b82c17d8..1d057481261a1d 100644
--- a/flang-rt/include/flang-rt/type-code.h
+++ b/flang-rt/include/flang-rt/type-code.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FLANGRT_TYPE_CODE_H_
-#define FLANGRT_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 /* FLANGRT_TYPE_CODE_H_ */
+#endif /* FLANG_RT_TYPE_CODE_H_ */
diff --git a/flang-rt/lib/flang_rt/ISO_Fortran_util.h b/flang-rt/lib/flang_rt/ISO_Fortran_util.h
index 3c1163851bee6b..dcbd76cc6bce24 100644
--- a/flang-rt/lib/flang_rt/ISO_Fortran_util.h
+++ b/flang-rt/lib/flang_rt/ISO_Fortran_util.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FLANGRT_ISO_FORTRAN_UTIL_H_
-#define FLANGRT_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.
 
@@ -99,4 +99,4 @@ static inline RT_API_ATTRS void EstablishDescriptor(CFI_cdesc_t *descriptor,
   }
 }
 } // namespace Fortran::ISO
-#endif /* FLANGRT_ISO_FORTRAN_UTIL_H_ */
+#endif /* FLANG_RT_ISO_FORTRAN_UTIL_H_ */
diff --git a/flang-rt/lib/flang_rt/buffer.h b/flang-rt/lib/flang_rt/buffer.h
index 01a6aa28c4ac94..84fe4c34cea0e3 100644
--- a/flang-rt/lib/flang_rt/buffer.h
+++ b/flang-rt/lib/flang_rt/buffer.h
@@ -8,8 +8,8 @@
 
 // External file buffering
 
-#ifndef FLANGRT_BUFFER_H_
-#define FLANGRT_BUFFER_H_
+#ifndef FLANG_RT_BUFFER_H_
+#define FLANG_RT_BUFFER_H_
 
 #include "flang-rt/memory.h"
 #include "io-error.h"
@@ -221,4 +221,4 @@ template <typename STORE, std::size_t minBuffer = 65536> class FileFrame {
   bool dirty_{false};
 };
 } // namespace Fortran::runtime::io
-#endif /* FLANGRT_BUFFER_H_ */
+#endif /* FLANG_RT_BUFFER_H_ */
diff --git a/flang-rt/lib/flang_rt/copy.h b/flang-rt/lib/flang_rt/copy.h
index f0520c23e4a471..468c2439baf618 100644
--- a/flang-rt/lib/flang_rt/copy.h
+++ b/flang-rt/lib/flang_rt/copy.h
@@ -9,8 +9,8 @@
 // Utilities that copy data in a type-aware fashion, allocating & duplicating
 // allocatable/automatic components of derived types along the way.
 
-#ifndef FLANGRT_COPY_H_
-#define FLANGRT_COPY_H_
+#ifndef FLANG_RT_COPY_H_
+#define FLANG_RT_COPY_H_
 
 #include "flang-rt/descriptor.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 /* FLANGRT_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 3c5abd6f97993a..2276dfe13230ed 100644
--- a/flang-rt/lib/flang_rt/descriptor-io.h
+++ b/flang-rt/lib/flang_rt/descriptor-io.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FLANGRT_DESCRIPTOR_IO_H_
-#define FLANGRT_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;
@@ -608,4 +608,4 @@ static RT_API_ATTRS bool DescriptorIO(IoStatementState &io,
   return false;
 }
 } // namespace Fortran::runtime::io::descr
-#endif /* FLANGRT_DESCRIPTOR_IO_H_ */
+#endif /* FLANG_RT_DESCRIPTOR_IO_H_ */
diff --git a/flang-rt/lib/flang_rt/file.h b/flang-rt/lib/flang_rt/file.h
index 6975bccb987583..13a7133677c6ce 100644
--- a/flang-rt/lib/flang_rt/file.h
+++ b/flang-rt/lib/flang_rt/file.h
@@ -8,8 +8,8 @@
 
 // Raw system I/O wrappers
 
-#ifndef FLANGRT_FILE_H_
-#define FLANGRT_FILE_H_
+#ifndef FLANG_RT_FILE_H_
+#define FLANG_RT_FILE_H_
 
 #include "flang-rt/memory.h"
 #include "io-error.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 /* FLANGRT_FILE_H_ */
+#endif /* FLANG_RT_FILE_H_ */
diff --git a/flang-rt/lib/flang_rt/internal-unit.h b/flang-rt/lib/flang_rt/internal-unit.h
index a825e09cdd203e..cae95855a895df 100644
--- a/flang-rt/lib/flang_rt/internal-unit.h
+++ b/flang-rt/lib/flang_rt/internal-unit.h
@@ -8,8 +8,8 @@
 
 // Fortran internal I/O "units"
 
-#ifndef FLANGRT_INTERNAL_UNIT_H_
-#define FLANGRT_INTERNAL_UNIT_H_
+#ifndef FLANG_RT_INTERNAL_UNIT_H_
+#define FLANG_RT_INTERNAL_UNIT_H_
 
 #include "connection.h"
 #include "flang-rt/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 /* FLANGRT_INTERNAL_UNIT_H_ */
+#endif /* FLANG_RT_INTERNAL_UNIT_H_ */
diff --git a/flang-rt/lib/flang_rt/io-api-common.h b/flang-rt/lib/flang_rt/io-api-common.h
index 39c87ba326bea4..22de04b3d5b077 100644
--- a/flang-rt/lib/flang_rt/io-api-common.h
+++ b/flang-rt/lib/flang_rt/io-api-common.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FLANGRT_IO_API_COMMON_H_
-#define FLANGRT_IO_API_COMMON_H_
+#ifndef FLANG_RT_IO_API_COMMON_H_
+#define FLANG_RT_IO_API_COMMON_H_
 
 #include "flang-rt/io-api-funcs.h"
 #include "io-stmt.h"
@@ -94,4 +94,4 @@ RT_API_ATTRS Cookie BeginExternalListIO(
 }
 
 } // namespace Fortran::runtime::io
-#endif /* FLANGRT_IO_API_COMMON_H_ */
+#endif /* FLANG_RT_IO_API_COMMON_H_ */
diff --git a/flang-rt/lib/flang_rt/io-error.h b/flang-rt/lib/flang_rt/io-error.h
index 775c5d66d83530..958ce2e3fc42b8 100644
--- a/flang-rt/lib/flang_rt/io-error.h
+++ b/flang-rt/lib/flang_rt/io-error.h
@@ -12,8 +12,8 @@
 // IOSTAT error codes are raw errno values augmented with values for
 // Fortran-specific errors.
 
-#ifndef FLANGRT_IO_ERROR_H_
-#define FLANGRT_IO_ERROR_H_
+#ifndef FLANG_RT_IO_ERROR_H_
+#define FLANG_RT_IO_ERROR_H_
 
 #include "flang-rt/iostat-funcs.h"
 #include "flang-rt/memory.h"
@@ -78,4 +78,4 @@ class IoErrorHandler : public Terminator {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FLANGRT_IO_ERROR_H_ */
+#endif /* FLANG_RT_IO_ERROR_H_ */
diff --git a/flang-rt/lib/flang_rt/io-stmt.h b/flang-rt/lib/flang_rt/io-stmt.h
index c7bde114457f0e..b4089ea67e1f7c 100644
--- a/flang-rt/lib/flang_rt/io-stmt.h
+++ b/flang-rt/lib/flang_rt/io-stmt.h
@@ -8,8 +8,8 @@
 
 // Representations of the state of an I/O statement in progress
 
-#ifndef FLANGRT_IO_STMT_H_
-#define FLANGRT_IO_STMT_H_
+#ifndef FLANG_RT_IO_STMT_H_
+#define FLANG_RT_IO_STMT_H_
 
 #include "connection.h"
 #include "file.h"
@@ -789,4 +789,4 @@ class ErroneousIoStatementState : public IoStatementBase {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FLANGRT_IO_STMT_H_ */
+#endif /* FLANG_RT_IO_STMT_H_ */
diff --git a/flang-rt/lib/flang_rt/random-templates.h b/flang-rt/lib/flang_rt/random-templates.h
index 8ed5757ec76a76..36701501b94ef5 100644
--- a/flang-rt/lib/flang_rt/random-templates.h
+++ b/flang-rt/lib/flang_rt/random-templates.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FLANGRT_RANDOM_TEMPLATES_H_
-#define FLANGRT_RANDOM_TEMPLATES_H_
+#ifndef FLANG_RT_RANDOM_TEMPLATES_H_
+#define FLANG_RT_RANDOM_TEMPLATES_H_
 
 #include "flang-rt/descriptor.h"
 #include "lock.h"
@@ -85,4 +85,4 @@ inline void Generate(const Descriptor &harvest) {
 
 } // namespace Fortran::runtime::random
 
-#endif /* FLANGRT_RANDOM_TEMPLATES_H_ */
+#endif /* FLANG_RT_RANDOM_TEMPLATES_H_ */
diff --git a/flang-rt/lib/flang_rt/reduction-templates.h b/flang-rt/lib/flang_rt/reduction-templates.h
index 6764706c3fa951..496372de1752a4 100644
--- a/flang-rt/lib/flang_rt/reduction-templates.h
+++ b/flang-rt/lib/flang_rt/reduction-templates.h
@@ -18,8 +18,8 @@
 // * Character-valued reductions (MAXVAL & MINVAL) return arbitrary
 //   length results, dynamically allocated in a caller-supplied descriptor
 
-#ifndef FLANGRT_REDUCTION_TEMPLATES_H_
-#define FLANGRT_REDUCTION_TEMPLATES_H_
+#ifndef FLANG_RT_REDUCTION_TEMPLATES_H_
+#define FLANG_RT_REDUCTION_TEMPLATES_H_
 
 #include "flang-rt/descriptor.h"
 #include "numeric-templates.h"
@@ -412,4 +412,4 @@ template <int KIND> struct Norm2Helper {
 };
 
 } // namespace Fortran::runtime
-#endif /* FLANGRT_REDUCTION_TEMPLATES_H_ */
+#endif /* FLANG_RT_REDUCTION_TEMPLATES_H_ */
diff --git a/flang-rt/lib/flang_rt/stack.h b/flang-rt/lib/flang_rt/stack.h
index 4b0de1e59e4596..07b34f3eef2c3d 100644
--- a/flang-rt/lib/flang_rt/stack.h
+++ b/flang-rt/lib/flang_rt/stack.h
@@ -10,8 +10,8 @@
 // It is a list based stack with dynamic allocation/deallocation
 // of the list nodes.
 
-#ifndef FLANGRT_STACK_H_
-#define FLANGRT_STACK_H_
+#ifndef FLANG_RT_STACK_H_
+#define FLANG_RT_STACK_H_
 
 #include "flang-rt/memory.h"
 #include "terminator.h"
@@ -133,4 +133,4 @@ template <typename T, unsigned N = 0> class Stack : public StackStorage<T, N> {
   Terminator &terminator_;
 };
 } // namespace Fortran::runtime
-#endif /* FLANGRT_STACK_H_ */
+#endif /* FLANG_RT_STACK_H_ */
diff --git a/flang-rt/lib/flang_rt/tools.h b/flang-rt/lib/flang_rt/tools.h
index bc2f4ff034cb13..9892ef0fc28393 100644
--- a/flang-rt/lib/flang_rt/tools.h
+++ b/flang-rt/lib/flang_rt/tools.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FLANGRT_TOOLS_H_
-#define FLANGRT_TOOLS_H_
+#ifndef FLANG_RT_TOOLS_H_
+#define FLANG_RT_TOOLS_H_
 
 #include "flang-rt/descriptor.h"
 #include "flang-rt/memory.h"
@@ -535,4 +535,4 @@ RT_API_ATTRS void CreatePartialReductionResult(Descriptor &result,
     const char *intrinsic, TypeCode);
 
 } // namespace Fortran::runtime
-#endif /* FLANGRT_TOOLS_H_ */
+#endif /* FLANG_RT_TOOLS_H_ */
diff --git a/flang-rt/lib/flang_rt/type-info.h b/flang-rt/lib/flang_rt/type-info.h
index 891a6a0d032127..69ad4e4a341a3d 100644
--- a/flang-rt/lib/flang_rt/type-info.h
+++ b/flang-rt/lib/flang_rt/type-info.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FLANGRT_TYPE_INFO_H_
-#define FLANGRT_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.
@@ -321,4 +321,4 @@ class DerivedType {
 };
 
 } // namespace Fortran::runtime::typeInfo
-#endif /* FLANGRT_TYPE_INFO_H_ */
+#endif /* FLANG_RT_TYPE_INFO_H_ */
diff --git a/flang-rt/lib/flang_rt/unit-map.h b/flang-rt/lib/flang_rt/unit-map.h
index 50aa74aeed05bf..e37438c58a2968 100644
--- a/flang-rt/lib/flang_rt/unit-map.h
+++ b/flang-rt/lib/flang_rt/unit-map.h
@@ -9,8 +9,8 @@
 // Maps Fortran unit numbers to their ExternalFileUnit instances.
 // A simple hash table with forward-linked chains per bucket.
 
-#ifndef FLANGRT_UNIT_MAP_H_
-#define FLANGRT_UNIT_MAP_H_
+#ifndef FLANG_RT_UNIT_MAP_H_
+#define FLANG_RT_UNIT_MAP_H_
 
 #include "flang-rt/memory.h"
 #include "lock.h"
@@ -100,4 +100,4 @@ class UnitMap {
   int emergencyNewUnit_{maxNewUnits_}; // not recycled
 };
 } // namespace Fortran::runtime::io
-#endif /* FLANGRT_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 5049f3c5db80f7..0a31de632136d2 100644
--- a/flang-rt/lib/flang_rt/unit.h
+++ b/flang-rt/lib/flang_rt/unit.h
@@ -8,8 +8,8 @@
 
 // Fortran external I/O units
 
-#ifndef FLANGRT_UNIT_H_
-#define FLANGRT_UNIT_H_
+#ifndef FLANG_RT_UNIT_H_
+#define FLANG_RT_UNIT_H_
 
 #include "buffer.h"
 #include "connection.h"
@@ -291,4 +291,4 @@ class ChildIo {
 };
 
 } // namespace Fortran::runtime::io
-#endif /* FLANGRT_UNIT_H_ */
+#endif /* FLANG_RT_UNIT_H_ */
diff --git a/flang-rt/unittests/Runtime/tools.h b/flang-rt/unittests/Runtime/tools.h
index 414175bde07d04..0db44c7ad0189c 100644
--- a/flang-rt/unittests/Runtime/tools.h
+++ b/flang-rt/unittests/Runtime/tools.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FLANGRT_UNITTESTS_RUNTIME_TOOLS_H_
-#define FLANGRT_UNITTESTS_RUNTIME_TOOLS_H_
+#ifndef FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_
+#define FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_
 
 #include "flang-rt/descriptor.h"
 #include "flang-rt/type-code.h"
@@ -54,4 +54,4 @@ static OwningPtr<Descriptor> MakeArray(const std::vector<int> &shape,
 }
 
 } // namespace Fortran::runtime
-#endif /* FLANGRT_UNITTESTS_RUNTIME_TOOLS_H_ */
+#endif /* FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_ */



More information about the llvm-branch-commits mailing list