[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
Fri Jan 24 10:43:14 PST 2025


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

>From 7e369b5626b6de43de394212efe5024a4fdebf48 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 24 Jan 2025 16:47:29 +0100
Subject: [PATCH] [Flang][NFC] Move runtime library files to flang-rt

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

diff --git a/flang-rt/.clang-format b/flang-rt/.clang-format
new file mode 100644
index 00000000000000..23f4c5ae2dcf24
--- /dev/null
+++ b/flang-rt/.clang-format
@@ -0,0 +1,25 @@
+---
+# See: https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+BasedOnStyle: LLVM
+AlignAfterOpenBracket: DontAlign
+AlignEscapedNewlines: DontAlign
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignOperands: false
+AlignTrailingComments: false
+IncludeCategories:
+  - Regex:           '^<'
+    Priority:        6
+  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
+    Priority:        5
+  - Regex:           '^"flang/'     # Headers shared with Flang
+    Priority:        4
+  - Regex:           '^"flang-rt/'  # Public Flang-RT headers
+    Priority:        3
+  - Regex:           '^[^/]*$'      # Private headers from same library
+    Priority:        1
+  - Regex:           '.*'           # Private headers from sibling libraries
+    Priority:        2
+...
+
+# vim:set filetype=yaml:
diff --git a/flang-rt/cmake/config.h.cmake.in b/flang-rt/cmake/config.h.cmake.in
new file mode 100644
index 00000000000000..8a4668b90addda
--- /dev/null
+++ b/flang-rt/cmake/config.h.cmake.in
@@ -0,0 +1,19 @@
+/*===-- cmake/config.cmake.in ---------------------------------------*- C -*-===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===----------------------------------------------------------------------===*/
+
+#ifndef FORTRAN_RUNTIME_CONFIG_H
+#define FORTRAN_RUNTIME_CONFIG_H
+
+/* Define to 1 if you have the `strerror_r' function. */
+#cmakedefine01 HAVE_STRERROR_R
+
+/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you
+   don't. */
+#cmakedefine01 HAVE_DECL_STRERROR_S
+
+#endif
diff --git a/flang/include/flang/Runtime/CUDA/allocator.h b/flang-rt/include/flang-rt/CUDA/allocator.h
similarity index 78%
rename from flang/include/flang/Runtime/CUDA/allocator.h
rename to flang-rt/include/flang-rt/CUDA/allocator.h
index 4fb4c94c5e9b0a..fb09b5ff2402ae 100644
--- a/flang/include/flang/Runtime/CUDA/allocator.h
+++ b/flang-rt/include/flang-rt/CUDA/allocator.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/CUDA/allocator.h ------------------*- C++ -*-===//
+//===-- include/flang-rt/CUDA/allocator.h -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
-#define FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
+#ifndef FLANG_RT_CUDA_ALLOCATOR_H_
+#define FLANG_RT_CUDA_ALLOCATOR_H_
 
-#include "common.h"
+#include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
 
@@ -33,4 +33,4 @@ void *CUFAllocUnified(std::size_t);
 void CUFFreeUnified(void *);
 
 } // namespace Fortran::runtime::cuda
-#endif // FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
+#endif /* FLANG_RT_CUDA_ALLOCATOR_H_ */
diff --git a/flang/include/flang/Runtime/allocator-registry.h b/flang-rt/include/flang-rt/allocator-registry.h
similarity index 88%
rename from flang/include/flang/Runtime/allocator-registry.h
rename to flang-rt/include/flang-rt/allocator-registry.h
index 29302c5d825bc9..1f004462ca6241 100644
--- a/flang/include/flang/Runtime/allocator-registry.h
+++ b/flang-rt/include/flang-rt/allocator-registry.h
@@ -1,4 +1,4 @@
-//===-- runtime/allocator-registry.h ----------------------------*- C++ -*-===//
+//===-- include/flang-rt/allocator-registry.h -------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_
-#define FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_
+#ifndef FLANG_RT_ALLOCATOR_REGISTRY_H_
+#define FLANG_RT_ALLOCATOR_REGISTRY_H_
 
 #include "flang/Common/api-attrs.h"
 #include "flang/Runtime/allocator-registry-consts.h"
@@ -55,4 +55,4 @@ RT_OFFLOAD_VAR_GROUP_END
 
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_
+#endif /* FLANG_RT_ALLOCATOR_REGISTRY_H_ */
diff --git a/flang/include/flang/Runtime/array-constructor.h b/flang-rt/include/flang-rt/array-constructor.h
similarity index 89%
rename from flang/include/flang/Runtime/array-constructor.h
rename to flang-rt/include/flang-rt/array-constructor.h
index 2f6aaae17c6508..7ff0779e46c6a0 100644
--- a/flang/include/flang/Runtime/array-constructor.h
+++ b/flang-rt/include/flang-rt/array-constructor.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/array-constructor.h ---------------*- C++ -*-===//
+//===-- include/flang-rt/array-constructor.h --------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,11 +9,11 @@
 // External APIs to create temporary storage for array constructors when their
 // final extents or length parameters cannot be pre-computed.
 
-#ifndef FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
-#define FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
+#ifndef FLANG_RT_ARRAY_CONSTRUCTOR_H_
+#define FLANG_RT_ARRAY_CONSTRUCTOR_H_
 
+#include "descriptor.h"
 #include "flang/Runtime/array-constructor-consts.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/entry-names.h"
 #include <cstdint>
 
@@ -54,4 +54,4 @@ static_assert(alignof(Fortran::runtime::ArrayConstructorVector) <=
     "MaxArrayConstructorVectorAlignInBytes");
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
+#endif /* FLANG_RT_ARRAY_CONSTRUCTOR_H_ */
diff --git a/flang/runtime/assign-impl.h b/flang-rt/include/flang-rt/assign-impl.h
similarity index 85%
rename from flang/runtime/assign-impl.h
rename to flang-rt/include/flang-rt/assign-impl.h
index aaa320ef7f9591..7e2cef9df753bb 100644
--- a/flang/runtime/assign-impl.h
+++ b/flang-rt/include/flang-rt/assign-impl.h
@@ -1,4 +1,4 @@
-//===-- runtime/assign-impl.h -----------------------------------*- C++ -*-===//
+//===-- include/flang-rt/assign-impl.h --------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_ASSIGN_IMPL_H_
-#define FORTRAN_RUNTIME_ASSIGN_IMPL_H_
+#ifndef FLANG_RT_ASSIGN_IMPL_H_
+#define FLANG_RT_ASSIGN_IMPL_H_
 
 #include "flang/Runtime/freestanding-tools.h"
 
@@ -28,4 +28,4 @@ RT_API_ATTRS void DoFromSourceAssign(Descriptor &, const Descriptor &,
 #endif
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_ASSIGN_IMPL_H_
+#endif /* FLANG_RT_ASSIGN_IMPL_H_ */
diff --git a/flang/runtime/buffer.h b/flang-rt/include/flang-rt/buffer.h
similarity index 97%
rename from flang/runtime/buffer.h
rename to flang-rt/include/flang-rt/buffer.h
index 41a1abb1b2d907..ba172448a93a53 100644
--- a/flang/runtime/buffer.h
+++ b/flang-rt/include/flang-rt/buffer.h
@@ -1,4 +1,4 @@
-//===-- runtime/buffer.h ----------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/buffer.h -------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,12 +8,12 @@
 
 // External file buffering
 
-#ifndef FORTRAN_RUNTIME_BUFFER_H_
-#define FORTRAN_RUNTIME_BUFFER_H_
+#ifndef FLANG_RT_BUFFER_H_
+#define FLANG_RT_BUFFER_H_
 
 #include "io-error.h"
+#include "memory.h"
 #include "flang/Runtime/freestanding-tools.h"
-#include "flang/Runtime/memory.h"
 #include <algorithm>
 #include <cinttypes>
 #include <cstring>
@@ -221,4 +221,4 @@ template <typename STORE, std::size_t minBuffer = 65536> class FileFrame {
   bool dirty_{false};
 };
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_BUFFER_H_
+#endif /* FLANG_RT_BUFFER_H_ */
diff --git a/flang/runtime/connection.h b/flang-rt/include/flang-rt/connection.h
similarity index 96%
rename from flang/runtime/connection.h
rename to flang-rt/include/flang-rt/connection.h
index 6f1ea90a160e5e..7f594deee69c65 100644
--- a/flang/runtime/connection.h
+++ b/flang-rt/include/flang-rt/connection.h
@@ -1,4 +1,4 @@
-//===-- runtime/connection.h ------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/connection.h ---------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,8 +8,8 @@
 
 // Fortran I/O connection state (abstracted over internal & external units)
 
-#ifndef FORTRAN_RUNTIME_IO_CONNECTION_H_
-#define FORTRAN_RUNTIME_IO_CONNECTION_H_
+#ifndef FLANG_RT_CONNECTION_H_
+#define FLANG_RT_CONNECTION_H_
 
 #include "format.h"
 #include "flang/Common/optional.h"
@@ -124,4 +124,4 @@ class SavedPosition {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IO_CONNECTION_H_
+#endif /* FLANG_RT_CONNECTION_H_ */
diff --git a/flang/runtime/derived.h b/flang-rt/include/flang-rt/derived.h
similarity index 90%
rename from flang/runtime/derived.h
rename to flang-rt/include/flang-rt/derived.h
index f5a1e219b848c4..797a089e767c44 100644
--- a/flang/runtime/derived.h
+++ b/flang-rt/include/flang-rt/derived.h
@@ -1,4 +1,4 @@
-//===-- runtime/derived.h -------------------------------------------------===//
+//===-- include/flang-rt/derived.h ------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,8 +8,8 @@
 
 // Internal runtime utilities for derived type operations.
 
-#ifndef FORTRAN_RUNTIME_DERIVED_H_
-#define FORTRAN_RUNTIME_DERIVED_H_
+#ifndef FLANG_RT_DERIVED_H_
+#define FLANG_RT_DERIVED_H_
 
 #include "flang/Common/api-attrs.h"
 
@@ -48,4 +48,4 @@ RT_API_ATTRS void Destroy(const Descriptor &, bool finalize,
 RT_API_ATTRS bool HasDynamicComponent(const Descriptor &);
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_DERIVED_H_
+#endif /* FLANG_RT_DERIVED_H_ */
diff --git a/flang/include/flang/Runtime/descriptor.h b/flang-rt/include/flang-rt/descriptor.h
similarity index 98%
rename from flang/include/flang/Runtime/descriptor.h
rename to flang-rt/include/flang-rt/descriptor.h
index 628ac8c927a51e..27f80bec4ba932 100644
--- a/flang/include/flang/Runtime/descriptor.h
+++ b/flang-rt/include/flang-rt/descriptor.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/descriptor.h ----------------------*- C++ -*-===//
+//===-- include/flang-rt/descriptor.h ---------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_DESCRIPTOR_H_
-#define FORTRAN_RUNTIME_DESCRIPTOR_H_
+#ifndef FLANG_RT_DESCRIPTOR_H_
+#define FLANG_RT_DESCRIPTOR_H_
 
 // Defines data structures used during execution of a Fortran program
 // to implement nontrivial dummy arguments, pointers, allocatables,
@@ -18,10 +18,10 @@
 // User C code is welcome to depend on that ISO_Fortran_binding.h file,
 // but should never reference this internal header.
 
+#include "memory.h"
+#include "type-code.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/descriptor-consts.h"
-#include "flang/Runtime/memory.h"
-#include "flang/Runtime/type-code.h"
 #include <algorithm>
 #include <cassert>
 #include <cinttypes>
@@ -482,4 +482,4 @@ class alignas(Descriptor) StaticDescriptor {
 };
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_DESCRIPTOR_H_
+#endif /* FLANG_RT_DESCRIPTOR_H_ */
diff --git a/flang/runtime/emit-encoded.h b/flang-rt/include/flang-rt/emit-encoded.h
similarity index 94%
rename from flang/runtime/emit-encoded.h
rename to flang-rt/include/flang-rt/emit-encoded.h
index 4b5e3900788357..f3cb7a9f790e42 100644
--- a/flang/runtime/emit-encoded.h
+++ b/flang-rt/include/flang-rt/emit-encoded.h
@@ -1,4 +1,4 @@
-//===-- runtime/emit-encoded.h ----------------------------------*- C++ -*-===//
+//===-- include/flang-rt/emit-encoded.h -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,8 +8,8 @@
 
 // Templates for emitting CHARACTER values with conversion
 
-#ifndef FORTRAN_RUNTIME_EMIT_ENCODED_H_
-#define FORTRAN_RUNTIME_EMIT_ENCODED_H_
+#ifndef FLANG_RT_EMIT_ENCODED_H_
+#define FLANG_RT_EMIT_ENCODED_H_
 
 #include "connection.h"
 #include "environment.h"
@@ -114,4 +114,4 @@ RT_API_ATTRS bool EmitRepeated(CONTEXT &to, char ch, std::size_t n) {
 }
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_EMIT_ENCODED_H_
+#endif /* FLANG_RT_EMIT_ENCODED_H_ */
diff --git a/flang/runtime/environment.h b/flang-rt/include/flang-rt/environment.h
similarity index 91%
rename from flang/runtime/environment.h
rename to flang-rt/include/flang-rt/environment.h
index b8b9f10e4e57f5..55e896b0e08611 100644
--- a/flang/runtime/environment.h
+++ b/flang-rt/include/flang-rt/environment.h
@@ -1,4 +1,4 @@
-//===-- runtime/environment.h -----------------------------------*- C++ -*-===//
+//===-- include/flang-rt/environment.h --------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_ENVIRONMENT_H_
-#define FORTRAN_RUNTIME_ENVIRONMENT_H_
+#ifndef FLANG_RT_ENVIRONMENT_H_
+#define FLANG_RT_ENVIRONMENT_H_
 
 #include "flang/Common/optional.h"
 #include "flang/Decimal/decimal.h"
@@ -64,4 +64,4 @@ RT_OFFLOAD_VAR_GROUP_END
 
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_ENVIRONMENT_H_
+#endif /* FLANG_RT_ENVIRONMENT_H_ */
diff --git a/flang/runtime/file.h b/flang-rt/include/flang-rt/file.h
similarity index 95%
rename from flang/runtime/file.h
rename to flang-rt/include/flang-rt/file.h
index c06acbb9904cc1..ca95156e1fba43 100644
--- a/flang/runtime/file.h
+++ b/flang-rt/include/flang-rt/file.h
@@ -1,4 +1,4 @@
-//===-- runtime/file.h ------------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/file.h ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,12 +8,12 @@
 
 // Raw system I/O wrappers
 
-#ifndef FORTRAN_RUNTIME_FILE_H_
-#define FORTRAN_RUNTIME_FILE_H_
+#ifndef FLANG_RT_FILE_H_
+#define FLANG_RT_FILE_H_
 
 #include "io-error.h"
+#include "memory.h"
 #include "flang/Common/optional.h"
-#include "flang/Runtime/memory.h"
 #include <cinttypes>
 
 namespace Fortran::runtime::io {
@@ -113,4 +113,4 @@ RT_API_ATTRS bool MayWrite(const char *path);
 RT_API_ATTRS bool MayReadAndWrite(const char *path);
 RT_API_ATTRS std::int64_t SizeInBytes(const char *path);
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_FILE_H_
+#endif /* FLANG_RT_FILE_H_ */
diff --git a/flang/runtime/format-implementation.h b/flang-rt/include/flang-rt/format-implementation.h
similarity index 98%
rename from flang/runtime/format-implementation.h
rename to flang-rt/include/flang-rt/format-implementation.h
index 46204ca927c135..52f265d06f9bf3 100644
--- a/flang/runtime/format-implementation.h
+++ b/flang-rt/include/flang-rt/format-implementation.h
@@ -1,4 +1,4 @@
-//===-- runtime/format-implementation.h -------------------------*- C++ -*-===//
+//===-- include/flang-rt/format-implementation.h ----------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,8 +8,8 @@
 
 // Implements out-of-line member functions of template class FormatControl
 
-#ifndef FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_
-#define FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_
+#ifndef FLANG_RT_FORMAT_IMPLEMENTATION_H_
+#define FLANG_RT_FORMAT_IMPLEMENTATION_H_
 
 #include "emit-encoded.h"
 #include "format.h"
@@ -601,4 +601,4 @@ RT_API_ATTRS void FormatControl<CONTEXT>::Finish(Context &context) {
   }
 }
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_
+#endif /* FLANG_RT_FORMAT_IMPLEMENTATION_H_ */
diff --git a/flang/runtime/format.h b/flang-rt/include/flang-rt/format.h
similarity index 97%
rename from flang/runtime/format.h
rename to flang-rt/include/flang-rt/format.h
index 815bf70685e647..d81241e41877c9 100644
--- a/flang/runtime/format.h
+++ b/flang-rt/include/flang-rt/format.h
@@ -1,4 +1,4 @@
-//===-- runtime/format.h ----------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/format.h -------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,8 +8,8 @@
 
 // FORMAT string processing
 
-#ifndef FORTRAN_RUNTIME_FORMAT_H_
-#define FORTRAN_RUNTIME_FORMAT_H_
+#ifndef FLANG_RT_FORMAT_H_
+#define FLANG_RT_FORMAT_H_
 
 #include "environment.h"
 #include "io-error.h"
@@ -201,4 +201,4 @@ template <typename CONTEXT> class FormatControl {
   Iteration stack_[maxMaxHeight];
 };
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_FORMAT_H_
+#endif /* FLANG_RT_FORMAT_H_ */
diff --git a/flang/runtime/internal-unit.h b/flang-rt/include/flang-rt/internal-unit.h
similarity index 89%
rename from flang/runtime/internal-unit.h
rename to flang-rt/include/flang-rt/internal-unit.h
index a0ee6353eeda3b..21e64b5624196d 100644
--- a/flang/runtime/internal-unit.h
+++ b/flang-rt/include/flang-rt/internal-unit.h
@@ -1,4 +1,4 @@
-//===-- runtime/internal-unit.h ---------------------------------*- C++ -*-===//
+//===-- include/flang-rt/internal-unit.h ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,11 +8,11 @@
 
 // Fortran internal I/O "units"
 
-#ifndef FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
-#define FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
+#ifndef FLANG_RT_INTERNAL_UNIT_H_
+#define FLANG_RT_INTERNAL_UNIT_H_
 
 #include "connection.h"
-#include "flang/Runtime/descriptor.h"
+#include "descriptor.h"
 #include <cinttypes>
 #include <type_traits>
 
@@ -56,4 +56,4 @@ template <Direction DIR> class InternalDescriptorUnit : public ConnectionState {
 extern template class InternalDescriptorUnit<Direction::Output>;
 extern template class InternalDescriptorUnit<Direction::Input>;
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_
+#endif /* FLANG_RT_INTERNAL_UNIT_H_ */
diff --git a/flang/runtime/io-error.h b/flang-rt/include/flang-rt/io-error.h
similarity index 92%
rename from flang/runtime/io-error.h
rename to flang-rt/include/flang-rt/io-error.h
index 39a343c8e0a516..c74c08970f94a0 100644
--- a/flang/runtime/io-error.h
+++ b/flang-rt/include/flang-rt/io-error.h
@@ -1,4 +1,4 @@
-//===-- runtime/io-error.h --------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/io-error.h -----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -12,12 +12,12 @@
 // IOSTAT error codes are raw errno values augmented with values for
 // Fortran-specific errors.
 
-#ifndef FORTRAN_RUNTIME_IO_ERROR_H_
-#define FORTRAN_RUNTIME_IO_ERROR_H_
+#ifndef FLANG_RT_IO_ERROR_H_
+#define FLANG_RT_IO_ERROR_H_
 
+#include "memory.h"
 #include "terminator.h"
 #include "flang/Runtime/iostat.h"
-#include "flang/Runtime/memory.h"
 #include <cinttypes>
 
 namespace Fortran::runtime::io {
@@ -80,4 +80,4 @@ class IoErrorHandler : public Terminator {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IO_ERROR_H_
+#endif /* FLANG_RT_IO_ERROR_H_ */
diff --git a/flang/runtime/io-stmt.h b/flang-rt/include/flang-rt/io-stmt.h
similarity index 99%
rename from flang/runtime/io-stmt.h
rename to flang-rt/include/flang-rt/io-stmt.h
index 1f1419b249e5e5..87fd93c353d76b 100644
--- a/flang/runtime/io-stmt.h
+++ b/flang-rt/include/flang-rt/io-stmt.h
@@ -1,4 +1,4 @@
-//===-- runtime/io-stmt.h ---------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/io-stmt.h ------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,10 +8,11 @@
 
 // Representations of the state of an I/O statement in progress
 
-#ifndef FORTRAN_RUNTIME_IO_STMT_H_
-#define FORTRAN_RUNTIME_IO_STMT_H_
+#ifndef FLANG_RT_IO_STMT_H_
+#define FLANG_RT_IO_STMT_H_
 
 #include "connection.h"
+#include "descriptor.h"
 #include "file.h"
 #include "format.h"
 #include "internal-unit.h"
@@ -19,7 +20,6 @@
 #include "flang/Common/optional.h"
 #include "flang/Common/reference-wrapper.h"
 #include "flang/Common/visit.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/io-api.h"
 #include <flang/Common/variant.h>
 #include <functional>
@@ -791,4 +791,4 @@ class ErroneousIoStatementState : public IoStatementBase {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IO_STMT_H_
+#endif /* FLANG_RT_IO_STMT_H_ */
diff --git a/flang/runtime/lock.h b/flang-rt/include/flang-rt/lock.h
similarity index 94%
rename from flang/runtime/lock.h
rename to flang-rt/include/flang-rt/lock.h
index 46ca28703a45b4..f57e97184edd52 100644
--- a/flang/runtime/lock.h
+++ b/flang-rt/include/flang-rt/lock.h
@@ -1,4 +1,4 @@
-//===-- runtime/lock.h ------------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/lock.h ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,8 +8,8 @@
 
 // Wraps a mutex
 
-#ifndef FORTRAN_RUNTIME_LOCK_H_
-#define FORTRAN_RUNTIME_LOCK_H_
+#ifndef FLANG_RT_LOCK_H_
+#define FLANG_RT_LOCK_H_
 
 #include "terminator.h"
 #include "tools.h"
@@ -113,4 +113,4 @@ class CriticalSection {
 };
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_LOCK_H_
+#endif /* FLANG_RT_LOCK_H_ */
diff --git a/flang/include/flang/Runtime/memory.h b/flang-rt/include/flang-rt/memory.h
similarity index 96%
rename from flang/include/flang/Runtime/memory.h
rename to flang-rt/include/flang-rt/memory.h
index 98412a989f890b..afbb1b34c1d2c0 100644
--- a/flang/include/flang/Runtime/memory.h
+++ b/flang-rt/include/flang-rt/memory.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/memory.h --------------------------*- C++ -*-===//
+//===-- include/flang-rt/memory.h -------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,8 +9,8 @@
 // Thin wrapper around malloc()/free() to isolate the dependency,
 // ease porting, and provide an owning pointer.
 
-#ifndef FORTRAN_RUNTIME_MEMORY_H_
-#define FORTRAN_RUNTIME_MEMORY_H_
+#ifndef FLANG_RT_MEMORY_H_
+#define FLANG_RT_MEMORY_H_
 
 #include "flang/Common/api-attrs.h"
 #include <cassert>
@@ -170,4 +170,4 @@ template <typename A> struct Allocator {
 };
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_MEMORY_H_
+#endif /* FLANG_RT_MEMORY_H_ */
diff --git a/flang/runtime/namelist.h b/flang-rt/include/flang-rt/namelist.h
similarity index 91%
rename from flang/runtime/namelist.h
rename to flang-rt/include/flang-rt/namelist.h
index 25216a75e9367d..5757bfb3b71093 100644
--- a/flang/runtime/namelist.h
+++ b/flang-rt/include/flang-rt/namelist.h
@@ -1,4 +1,4 @@
-//===-- runtime/namelist.h --------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/namelist.h -----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,8 +8,8 @@
 
 // Defines the data structure used for NAMELIST I/O
 
-#ifndef FORTRAN_RUNTIME_NAMELIST_H_
-#define FORTRAN_RUNTIME_NAMELIST_H_
+#ifndef FLANG_RT_NAMELIST_H_
+#define FLANG_RT_NAMELIST_H_
 
 #include "non-tbp-dio.h"
 #include "flang/Common/api-attrs.h"
@@ -51,4 +51,4 @@ class NamelistGroup {
 RT_API_ATTRS bool IsNamelistNameOrSlash(IoStatementState &);
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_NAMELIST_H_
+#endif /* FLANG_RT_NAMELIST_H_ */
diff --git a/flang/runtime/non-tbp-dio.h b/flang-rt/include/flang-rt/non-tbp-dio.h
similarity index 91%
rename from flang/runtime/non-tbp-dio.h
rename to flang-rt/include/flang-rt/non-tbp-dio.h
index 8429d790fea57a..58ed29ba7a1024 100644
--- a/flang/runtime/non-tbp-dio.h
+++ b/flang-rt/include/flang-rt/non-tbp-dio.h
@@ -1,4 +1,4 @@
-//===-- flang/runtime/non-tbp-dio.h -----------------------------*- C++ -*-===//
+//===-- include/flang-rt/non-tbp-dio.h --------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -19,8 +19,8 @@
 // a containing scope has become inaccessible in a nested scope due
 // to the use of "IMPORT, NONE" or "IMPORT, ONLY:".
 
-#ifndef FORTRAN_RUNTIME_NON_TBP_DIO_H_
-#define FORTRAN_RUNTIME_NON_TBP_DIO_H_
+#ifndef FLANG_RT_NON_TBP_DIO_H_
+#define FLANG_RT_NON_TBP_DIO_H_
 
 #include "flang/Common/Fortran-consts.h"
 #include "flang/Common/api-attrs.h"
@@ -53,4 +53,4 @@ struct NonTbpDefinedIoTable {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_NON_TBP_DIO_H_
+#endif /* FLANG_RT_NON_TBP_DIO_H_ */
diff --git a/flang/runtime/numeric-templates.h b/flang-rt/include/flang-rt/numeric-templates.h
similarity index 98%
rename from flang/runtime/numeric-templates.h
rename to flang-rt/include/flang-rt/numeric-templates.h
index fbb371bffc27a4..7019151c3a207d 100644
--- a/flang/runtime/numeric-templates.h
+++ b/flang-rt/include/flang-rt/numeric-templates.h
@@ -1,4 +1,4 @@
-//===-- runtime/numeric-templates.h -----------------------------*- C++ -*-===//
+//===-- include/flang-rt/numeric-templates.h --------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -15,8 +15,8 @@
 // for the data type corresponding to CppTypeFor<TypeCategory::Real, 16>
 // on the target.
 
-#ifndef FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_
-#define FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_
+#ifndef FLANG_RT_NUMERIC_TEMPLATES_H_
+#define FLANG_RT_NUMERIC_TEMPLATES_H_
 
 #include "terminator.h"
 #include "tools.h"
@@ -368,4 +368,4 @@ template <typename T> inline RT_API_ATTRS T ErfcScaled(T arg) {
 
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_
+#endif /* FLANG_RT_NUMERIC_TEMPLATES_H_ */
diff --git a/flang/runtime/random-templates.h b/flang-rt/include/flang-rt/random-templates.h
similarity index 93%
rename from flang/runtime/random-templates.h
rename to flang-rt/include/flang-rt/random-templates.h
index 3885941704d4af..f320f2cd328f5a 100644
--- a/flang/runtime/random-templates.h
+++ b/flang-rt/include/flang-rt/random-templates.h
@@ -1,4 +1,4 @@
-//===-- runtime/random-templates.h ------------------------------*- C++ -*-===//
+//===-- include/flang-rt/random-templates.h ---------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_
-#define FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_
+#ifndef FLANG_RT_RANDOM_TEMPLATES_H_
+#define FLANG_RT_RANDOM_TEMPLATES_H_
 
+#include "descriptor.h"
 #include "lock.h"
 #include "numeric-templates.h"
 #include "flang/Common/optional.h"
-#include "flang/Runtime/descriptor.h"
 #include <algorithm>
 #include <random>
 
@@ -108,4 +108,4 @@ inline void GenerateUnsigned(const Descriptor &harvest) {
 
 } // namespace Fortran::runtime::random
 
-#endif // FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_
+#endif /* FLANG_RT_RANDOM_TEMPLATES_H_ */
diff --git a/flang/runtime/reduction-templates.h b/flang-rt/include/flang-rt/reduction-templates.h
similarity index 98%
rename from flang/runtime/reduction-templates.h
rename to flang-rt/include/flang-rt/reduction-templates.h
index b20b03655c3d00..513b3e4478498f 100644
--- a/flang/runtime/reduction-templates.h
+++ b/flang-rt/include/flang-rt/reduction-templates.h
@@ -1,4 +1,4 @@
-//===-- runtime/reduction-templates.h ---------------------------*- C++ -*-===//
+//===-- include/flang-rt/reduction-templates.h ------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -18,14 +18,14 @@
 // * Character-valued reductions (MAXVAL & MINVAL) return arbitrary
 //   length results, dynamically allocated in a caller-supplied descriptor
 
-#ifndef FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_
-#define FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_
+#ifndef FLANG_RT_REDUCTION_TEMPLATES_H_
+#define FLANG_RT_REDUCTION_TEMPLATES_H_
 
+#include "descriptor.h"
 #include "numeric-templates.h"
 #include "terminator.h"
 #include "tools.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include <algorithm>
 
 namespace Fortran::runtime {
@@ -416,4 +416,4 @@ template <int KIND> struct Norm2Helper {
 };
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_
+#endif /* FLANG_RT_REDUCTION_TEMPLATES_H_ */
diff --git a/flang/runtime/stat.h b/flang-rt/include/flang-rt/stat.h
similarity index 93%
rename from flang/runtime/stat.h
rename to flang-rt/include/flang-rt/stat.h
index 572cb6d10b4893..95ae286a03b495 100644
--- a/flang/runtime/stat.h
+++ b/flang-rt/include/flang-rt/stat.h
@@ -1,4 +1,4 @@
-//===-- runtime/stat.h ------------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/stat.h ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,8 +9,8 @@
 // Defines the values returned by the runtime for STAT= specifiers
 // on executable statements.
 
-#ifndef FORTRAN_RUNTIME_STAT_H_
-#define FORTRAN_RUNTIME_STAT_H_
+#ifndef FLANG_RT_STAT_H_
+#define FLANG_RT_STAT_H_
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Common/api-attrs.h"
 #include "flang/Runtime/magic-numbers.h"
@@ -60,4 +60,4 @@ RT_API_ATTRS int ToErrmsg(const Descriptor *errmsg, int stat); // returns stat
 RT_API_ATTRS int ReturnError(Terminator &, int stat,
     const Descriptor *errmsg = nullptr, bool hasStat = false);
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_STAT_H
+#endif /* FLANG_RT_STAT_H_ */
diff --git a/flang/runtime/terminator.h b/flang-rt/include/flang-rt/terminator.h
similarity index 95%
rename from flang/runtime/terminator.h
rename to flang-rt/include/flang-rt/terminator.h
index 609f059d6e0921..800ed6f3755b75 100644
--- a/flang/runtime/terminator.h
+++ b/flang-rt/include/flang-rt/terminator.h
@@ -1,4 +1,4 @@
-//===-- runtime/terminator.h ------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/terminator.h ---------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,8 +8,8 @@
 
 // Termination of the image
 
-#ifndef FORTRAN_RUNTIME_TERMINATOR_H_
-#define FORTRAN_RUNTIME_TERMINATOR_H_
+#ifndef FLANG_RT_TERMINATOR_H_
+#define FLANG_RT_TERMINATOR_H_
 
 #include "flang/Common/api-attrs.h"
 #include <cstdarg>
@@ -121,4 +121,4 @@ namespace Fortran::runtime::io {
 RT_API_ATTRS void FlushOutputOnCrash(const Terminator &);
 }
 
-#endif // FORTRAN_RUNTIME_TERMINATOR_H_
+#endif /* FLANG_RT_TERMINATOR_H_ */
diff --git a/flang/runtime/tools.h b/flang-rt/include/flang-rt/tools.h
similarity index 98%
rename from flang/runtime/tools.h
rename to flang-rt/include/flang-rt/tools.h
index facbd231610570..38804a1f409916 100644
--- a/flang/runtime/tools.h
+++ b/flang-rt/include/flang-rt/tools.h
@@ -1,4 +1,4 @@
-//===-- runtime/tools.h -----------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/tools.h --------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,16 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_TOOLS_H_
-#define FORTRAN_RUNTIME_TOOLS_H_
+#ifndef FLANG_RT_TOOLS_H_
+#define FLANG_RT_TOOLS_H_
 
+#include "descriptor.h"
+#include "memory.h"
 #include "stat.h"
 #include "terminator.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/freestanding-tools.h"
-#include "flang/Runtime/memory.h"
 #include <cstring>
 #include <functional>
 #include <map>
@@ -570,4 +570,4 @@ RT_API_ATTRS void CreatePartialReductionResult(Descriptor &result,
     const char *intrinsic, TypeCode);
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_TOOLS_H_
+#endif /* FLANG_RT_TOOLS_H_ */
diff --git a/flang/include/flang/Runtime/type-code.h b/flang-rt/include/flang-rt/type-code.h
similarity index 93%
rename from flang/include/flang/Runtime/type-code.h
rename to flang-rt/include/flang-rt/type-code.h
index ae854ed2145e46..1d057481261a1d 100644
--- a/flang/include/flang/Runtime/type-code.h
+++ b/flang-rt/include/flang-rt/type-code.h
@@ -1,4 +1,4 @@
-//===-- include/flang/Runtime/type-code.h -----------------------*- C++ -*-===//
+//===-- include/flang-rt/type-code.h ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_TYPE_CODE_H_
-#define FORTRAN_RUNTIME_TYPE_CODE_H_
+#ifndef FLANG_RT_TYPE_CODE_H_
+#define FLANG_RT_TYPE_CODE_H_
 
 #include "flang/Common/Fortran-consts.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
@@ -75,4 +75,4 @@ class TypeCode {
   ISO::CFI_type_t raw_{CFI_type_other};
 };
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_TYPE_CODE_H_
+#endif /* FLANG_RT_TYPE_CODE_H_ */
diff --git a/flang/runtime/type-info.h b/flang-rt/include/flang-rt/type-info.h
similarity index 98%
rename from flang/runtime/type-info.h
rename to flang-rt/include/flang-rt/type-info.h
index 32403b1db5169e..52e208c93fe25d 100644
--- a/flang/runtime/type-info.h
+++ b/flang-rt/include/flang-rt/type-info.h
@@ -1,4 +1,4 @@
-//===-- runtime/type-info.h -------------------------------------*- C++ -*-===//
+//===-- include/flang-rt/type-info.h ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,17 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_TYPE_INFO_H_
-#define FORTRAN_RUNTIME_TYPE_INFO_H_
+#ifndef FLANG_RT_TYPE_INFO_H_
+#define FLANG_RT_TYPE_INFO_H_
 
 // A C++ perspective of the derived type description schemata in
 // flang/module/__fortran_type_info.f90.
 
+#include "descriptor.h"
 #include "terminator.h"
 #include "flang/Common/Fortran-consts.h"
 #include "flang/Common/bit-population-count.h"
 #include "flang/Common/optional.h"
-#include "flang/Runtime/descriptor.h"
 #include <cinttypes>
 #include <memory>
 
@@ -321,4 +321,4 @@ class DerivedType {
 };
 
 } // namespace Fortran::runtime::typeInfo
-#endif // FORTRAN_RUNTIME_TYPE_INFO_H_
+#endif /* FLANG_RT_TYPE_INFO_H_ */
diff --git a/flang/runtime/utf.h b/flang-rt/include/flang-rt/utf.h
similarity index 94%
rename from flang/runtime/utf.h
rename to flang-rt/include/flang-rt/utf.h
index 10c2d61484217a..4d1e23b9ccb941 100644
--- a/flang/runtime/utf.h
+++ b/flang-rt/include/flang-rt/utf.h
@@ -1,4 +1,4 @@
-//===-- runtime/utf.h -----------------------------------------------------===//
+//===-- include/flang-rt/utf.h ----------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -38,8 +38,8 @@
 // standard maximum.  However, we support extended forms up to 32 bits so that
 // CHARACTER(KIND=4) can be abused to hold arbitrary 32-bit data.
 
-#ifndef FORTRAN_RUNTIME_UTF_H_
-#define FORTRAN_RUNTIME_UTF_H_
+#ifndef FLANG_RT_UTF_H_
+#define FLANG_RT_UTF_H_
 
 #include "flang/Common/optional.h"
 #include <cstddef>
@@ -70,4 +70,4 @@ RT_API_ATTRS Fortran::common::optional<char32_t> DecodeUTF8(const char *);
 RT_API_ATTRS std::size_t EncodeUTF8(char *, char32_t);
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_UTF_H_
+#endif /* FLANG_RT_UTF_H_ */
diff --git a/flang/runtime/Float128Math/acos.cpp b/flang-rt/lib/FortranFloat128Math/acos.cpp
similarity index 87%
rename from flang/runtime/Float128Math/acos.cpp
rename to flang-rt/lib/FortranFloat128Math/acos.cpp
index d9b4950aa1e35c..7f206547527543 100644
--- a/flang/runtime/Float128Math/acos.cpp
+++ b/flang-rt/lib/FortranFloat128Math/acos.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/acos.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/acos.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/acosh.cpp b/flang-rt/lib/FortranFloat128Math/acosh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/acosh.cpp
rename to flang-rt/lib/FortranFloat128Math/acosh.cpp
index c572673ef55e62..73b64230f08c71 100644
--- a/flang/runtime/Float128Math/acosh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/acosh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/acosh.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/acosh.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/asin.cpp b/flang-rt/lib/FortranFloat128Math/asin.cpp
similarity index 87%
rename from flang/runtime/Float128Math/asin.cpp
rename to flang-rt/lib/FortranFloat128Math/asin.cpp
index 57b6ffd9673605..b51ecb6b674d3a 100644
--- a/flang/runtime/Float128Math/asin.cpp
+++ b/flang-rt/lib/FortranFloat128Math/asin.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/asin.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/asin.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/asinh.cpp b/flang-rt/lib/FortranFloat128Math/asinh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/asinh.cpp
rename to flang-rt/lib/FortranFloat128Math/asinh.cpp
index 03dded722b2543..2fc181d075aec9 100644
--- a/flang/runtime/Float128Math/asinh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/asinh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/asinh.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/asinh.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/atan.cpp b/flang-rt/lib/FortranFloat128Math/atan.cpp
similarity index 87%
rename from flang/runtime/Float128Math/atan.cpp
rename to flang-rt/lib/FortranFloat128Math/atan.cpp
index 19c86cae8867bc..ff1ec39bfdebd7 100644
--- a/flang/runtime/Float128Math/atan.cpp
+++ b/flang-rt/lib/FortranFloat128Math/atan.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/atan.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/atan.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/atan2.cpp b/flang-rt/lib/FortranFloat128Math/atan2.cpp
similarity index 88%
rename from flang/runtime/Float128Math/atan2.cpp
rename to flang-rt/lib/FortranFloat128Math/atan2.cpp
index 09d666ae14304c..4e809cb547a1b8 100644
--- a/flang/runtime/Float128Math/atan2.cpp
+++ b/flang-rt/lib/FortranFloat128Math/atan2.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/atan2.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/atan2.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/atanh.cpp b/flang-rt/lib/FortranFloat128Math/atanh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/atanh.cpp
rename to flang-rt/lib/FortranFloat128Math/atanh.cpp
index 442d9beafae47e..d4e3e7426b16d9 100644
--- a/flang/runtime/Float128Math/atanh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/atanh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/atanh.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/atanh.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/ceil.cpp b/flang-rt/lib/FortranFloat128Math/ceil.cpp
similarity index 87%
rename from flang/runtime/Float128Math/ceil.cpp
rename to flang-rt/lib/FortranFloat128Math/ceil.cpp
index 48e20b2b415774..f439f22c0565aa 100644
--- a/flang/runtime/Float128Math/ceil.cpp
+++ b/flang-rt/lib/FortranFloat128Math/ceil.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/ceil.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/ceil.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/complex-math.c b/flang-rt/lib/FortranFloat128Math/complex-math.c
similarity index 92%
rename from flang/runtime/Float128Math/complex-math.c
rename to flang-rt/lib/FortranFloat128Math/complex-math.c
index a7e32f3ef755b7..fed37dfce6332a 100644
--- a/flang/runtime/Float128Math/complex-math.c
+++ b/flang-rt/lib/FortranFloat128Math/complex-math.c
@@ -1,11 +1,10 @@
-/*===-- runtime/Float128Math/complex-math.c -------------------------*- C -*-===
+/*===-- lib/FortranFloat128Math/complex-math.c ----------------------*- C -*-===
  *
  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  * See https://llvm.org/LICENSE.txt for license information.
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  *
- * ===-----------------------------------------------------------------------===
- */
+ *===----------------------------------------------------------------------===*/
 
 #include "complex-math.h"
 
diff --git a/flang/runtime/Float128Math/complex-math.h b/flang-rt/lib/FortranFloat128Math/complex-math.h
similarity index 88%
rename from flang/runtime/Float128Math/complex-math.h
rename to flang-rt/lib/FortranFloat128Math/complex-math.h
index cf5e980a39b6bb..24ccc794fd144a 100644
--- a/flang/runtime/Float128Math/complex-math.h
+++ b/flang-rt/lib/FortranFloat128Math/complex-math.h
@@ -1,4 +1,4 @@
-/*===-- runtime/Float128Math/complex-math.h -------------------------*- C -*-===
+/*===-- lib/FortranFloat128Math/complex-math.h ----------------------*- C -*-===
  *
  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  * See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
  *
  *===----------------------------------------------------------------------===*/
 
-#ifndef FORTRAN_RUNTIME_FLOAT128MATH_COMPLEX_MATH_H_
-#define FORTRAN_RUNTIME_FLOAT128MATH_COMPLEX_MATH_H_
+#ifndef FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_
+#define FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_
 
 #include "flang/Common/float128.h"
 #include "flang/Runtime/entry-names.h"
@@ -59,4 +59,4 @@
 #error "Float128Math build with glibc>=2.26 is unsupported yet"
 #endif
 
-#endif /* FORTRAN_RUNTIME_FLOAT128MATH_COMPLEX_MATH_H_ */
+#endif /* FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_ */
diff --git a/flang/runtime/Float128Math/cos.cpp b/flang-rt/lib/FortranFloat128Math/cos.cpp
similarity index 87%
rename from flang/runtime/Float128Math/cos.cpp
rename to flang-rt/lib/FortranFloat128Math/cos.cpp
index d1b3e0e736ca34..aed337c325836e 100644
--- a/flang/runtime/Float128Math/cos.cpp
+++ b/flang-rt/lib/FortranFloat128Math/cos.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/cos.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/cos.cpp -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/cosh.cpp b/flang-rt/lib/FortranFloat128Math/cosh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/cosh.cpp
rename to flang-rt/lib/FortranFloat128Math/cosh.cpp
index 9fe5b61d8f95f7..bddbff766b5758 100644
--- a/flang/runtime/Float128Math/cosh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/cosh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/cosh.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/cosh.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/erf.cpp b/flang-rt/lib/FortranFloat128Math/erf.cpp
similarity index 87%
rename from flang/runtime/Float128Math/erf.cpp
rename to flang-rt/lib/FortranFloat128Math/erf.cpp
index 2a553bd395e88f..a56430040248dc 100644
--- a/flang/runtime/Float128Math/erf.cpp
+++ b/flang-rt/lib/FortranFloat128Math/erf.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/erf.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/erf.cpp -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/erfc.cpp b/flang-rt/lib/FortranFloat128Math/erfc.cpp
similarity index 87%
rename from flang/runtime/Float128Math/erfc.cpp
rename to flang-rt/lib/FortranFloat128Math/erfc.cpp
index 2435ed2786cb32..255a2a7b4edac0 100644
--- a/flang/runtime/Float128Math/erfc.cpp
+++ b/flang-rt/lib/FortranFloat128Math/erfc.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/erfc.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/erfc.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/exp.cpp b/flang-rt/lib/FortranFloat128Math/exp.cpp
similarity index 87%
rename from flang/runtime/Float128Math/exp.cpp
rename to flang-rt/lib/FortranFloat128Math/exp.cpp
index 5ca87d9dd25d2f..9bc87d959cf691 100644
--- a/flang/runtime/Float128Math/exp.cpp
+++ b/flang-rt/lib/FortranFloat128Math/exp.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/exp.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/exp.cpp -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/exponent.cpp b/flang-rt/lib/FortranFloat128Math/exponent.cpp
similarity index 90%
rename from flang/runtime/Float128Math/exponent.cpp
rename to flang-rt/lib/FortranFloat128Math/exponent.cpp
index 237cde34e86914..bf27a26a734276 100644
--- a/flang/runtime/Float128Math/exponent.cpp
+++ b/flang-rt/lib/FortranFloat128Math/exponent.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/exponent.cpp ---------------------------------===//
+//===-- lib/FortranFloat128Math/exponent.cpp --------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/floor.cpp b/flang-rt/lib/FortranFloat128Math/floor.cpp
similarity index 87%
rename from flang/runtime/Float128Math/floor.cpp
rename to flang-rt/lib/FortranFloat128Math/floor.cpp
index 28f9c7b55dd513..abda5fadfd2965 100644
--- a/flang/runtime/Float128Math/floor.cpp
+++ b/flang-rt/lib/FortranFloat128Math/floor.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/floor.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/floor.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/fma.cpp b/flang-rt/lib/FortranFloat128Math/fma.cpp
similarity index 89%
rename from flang/runtime/Float128Math/fma.cpp
rename to flang-rt/lib/FortranFloat128Math/fma.cpp
index 87176c25dd6047..2e7aabedf1e8c5 100644
--- a/flang/runtime/Float128Math/fma.cpp
+++ b/flang-rt/lib/FortranFloat128Math/fma.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/fma.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/fma.cpp -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/fraction.cpp b/flang-rt/lib/FortranFloat128Math/fraction.cpp
similarity index 87%
rename from flang/runtime/Float128Math/fraction.cpp
rename to flang-rt/lib/FortranFloat128Math/fraction.cpp
index 45ec12cd775187..bf1da6f63e5ce7 100644
--- a/flang/runtime/Float128Math/fraction.cpp
+++ b/flang-rt/lib/FortranFloat128Math/fraction.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/fraction.cpp ---------------------------------===//
+//===-- lib/FortranFloat128Math/fraction.cpp --------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/hypot.cpp b/flang-rt/lib/FortranFloat128Math/hypot.cpp
similarity index 88%
rename from flang/runtime/Float128Math/hypot.cpp
rename to flang-rt/lib/FortranFloat128Math/hypot.cpp
index 03049b06d3a248..910bda798c1a06 100644
--- a/flang/runtime/Float128Math/hypot.cpp
+++ b/flang-rt/lib/FortranFloat128Math/hypot.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/hypot.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/hypot.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/j0.cpp b/flang-rt/lib/FortranFloat128Math/j0.cpp
similarity index 87%
rename from flang/runtime/Float128Math/j0.cpp
rename to flang-rt/lib/FortranFloat128Math/j0.cpp
index 7207cbe1a92e75..d2fac98c3ec694 100644
--- a/flang/runtime/Float128Math/j0.cpp
+++ b/flang-rt/lib/FortranFloat128Math/j0.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/j0.cpp ---------------------------------------===//
+//===-- lib/FortranFloat128Math/j0.cpp --------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/j1.cpp b/flang-rt/lib/FortranFloat128Math/j1.cpp
similarity index 87%
rename from flang/runtime/Float128Math/j1.cpp
rename to flang-rt/lib/FortranFloat128Math/j1.cpp
index 9e49bcbc32ca4b..60401030124c88 100644
--- a/flang/runtime/Float128Math/j1.cpp
+++ b/flang-rt/lib/FortranFloat128Math/j1.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/j1.cpp ---------------------------------------===//
+//===-- lib/FortranFloat128Math/j1.cpp --------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/jn.cpp b/flang-rt/lib/FortranFloat128Math/jn.cpp
similarity index 87%
rename from flang/runtime/Float128Math/jn.cpp
rename to flang-rt/lib/FortranFloat128Math/jn.cpp
index 37e5f428e5e260..71e11335d08307 100644
--- a/flang/runtime/Float128Math/jn.cpp
+++ b/flang-rt/lib/FortranFloat128Math/jn.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/jn.cpp ---------------------------------------===//
+//===-- lib/FortranFloat128Math/jn.cpp --------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/lgamma.cpp b/flang-rt/lib/FortranFloat128Math/lgamma.cpp
similarity index 87%
rename from flang/runtime/Float128Math/lgamma.cpp
rename to flang-rt/lib/FortranFloat128Math/lgamma.cpp
index 54d0dd80838685..1ae4cc4d95d61c 100644
--- a/flang/runtime/Float128Math/lgamma.cpp
+++ b/flang-rt/lib/FortranFloat128Math/lgamma.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/lgamma.cpp -----------------------------------===//
+//===-- lib/FortranFloat128Math/lgamma.cpp ----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/llround.cpp b/flang-rt/lib/FortranFloat128Math/llround.cpp
similarity index 87%
rename from flang/runtime/Float128Math/llround.cpp
rename to flang-rt/lib/FortranFloat128Math/llround.cpp
index f0c53ccdf66fd8..5bd4cc26dd4978 100644
--- a/flang/runtime/Float128Math/llround.cpp
+++ b/flang-rt/lib/FortranFloat128Math/llround.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/llround.cpp ----------------------------------===//
+//===-- lib/FortranFloat128Math/llround.cpp ---------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/log.cpp b/flang-rt/lib/FortranFloat128Math/log.cpp
similarity index 87%
rename from flang/runtime/Float128Math/log.cpp
rename to flang-rt/lib/FortranFloat128Math/log.cpp
index 28fec1958f10b3..414e41ae0ce291 100644
--- a/flang/runtime/Float128Math/log.cpp
+++ b/flang-rt/lib/FortranFloat128Math/log.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/log.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/log.cpp -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/log10.cpp b/flang-rt/lib/FortranFloat128Math/log10.cpp
similarity index 87%
rename from flang/runtime/Float128Math/log10.cpp
rename to flang-rt/lib/FortranFloat128Math/log10.cpp
index f844d508f8d3bc..55db1b1a2dc1ff 100644
--- a/flang/runtime/Float128Math/log10.cpp
+++ b/flang-rt/lib/FortranFloat128Math/log10.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/log10.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/log10.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/lround.cpp b/flang-rt/lib/FortranFloat128Math/lround.cpp
similarity index 87%
rename from flang/runtime/Float128Math/lround.cpp
rename to flang-rt/lib/FortranFloat128Math/lround.cpp
index 8c2d3315c62a7a..a0bea492436817 100644
--- a/flang/runtime/Float128Math/lround.cpp
+++ b/flang-rt/lib/FortranFloat128Math/lround.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/lround.cpp -----------------------------------===//
+//===-- lib/FortranFloat128Math/lround.cpp ----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/math-entries.h b/flang-rt/lib/FortranFloat128Math/math-entries.h
similarity index 96%
rename from flang/runtime/Float128Math/math-entries.h
rename to flang-rt/lib/FortranFloat128Math/math-entries.h
index a94503fe8e67a0..b9821163d94fb5 100644
--- a/flang/runtime/Float128Math/math-entries.h
+++ b/flang-rt/lib/FortranFloat128Math/math-entries.h
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/math-entries.h ---------------------*- C++ -*-===//
+//===-- lib/FortranFloat128Math/math-entries.h ------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
-#define FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
-#include "terminator.h"
-#include "tools.h"
+#ifndef FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_
+#define FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_
+
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/entry-names.h"
 #include <cfloat>
@@ -231,4 +232,4 @@ DEFINE_SIMPLE_ALIAS(Yn, ynl)
 
 } // namespace Fortran::runtime
 
-#endif // FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
+#endif /* FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_ */
diff --git a/flang/runtime/Float128Math/mod-real.cpp b/flang-rt/lib/FortranFloat128Math/mod-real.cpp
similarity index 88%
rename from flang/runtime/Float128Math/mod-real.cpp
rename to flang-rt/lib/FortranFloat128Math/mod-real.cpp
index e831c2df4abc1f..beb412f719c520 100644
--- a/flang/runtime/Float128Math/mod-real.cpp
+++ b/flang-rt/lib/FortranFloat128Math/mod-real.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/mod-real.cpp ---------------------------------===//
+//===-- lib/FortranFloat128Math/mod-real.cpp --------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/modulo-real.cpp b/flang-rt/lib/FortranFloat128Math/modulo-real.cpp
similarity index 89%
rename from flang/runtime/Float128Math/modulo-real.cpp
rename to flang-rt/lib/FortranFloat128Math/modulo-real.cpp
index 88729da7e39875..c8160b1d274513 100644
--- a/flang/runtime/Float128Math/modulo-real.cpp
+++ b/flang-rt/lib/FortranFloat128Math/modulo-real.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/modulo-real.cpp ------------------------------===//
+//===-- lib/FortranFloat128Math/modulo-real.cpp -----------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/nearbyint.cpp b/flang-rt/lib/FortranFloat128Math/nearbyint.cpp
similarity index 87%
rename from flang/runtime/Float128Math/nearbyint.cpp
rename to flang-rt/lib/FortranFloat128Math/nearbyint.cpp
index 9eecb0c5f3e2f7..d572641e2b0d46 100644
--- a/flang/runtime/Float128Math/nearbyint.cpp
+++ b/flang-rt/lib/FortranFloat128Math/nearbyint.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/nearbyint.cpp --------------------------------===//
+//===-- lib/FortranFloat128Math/nearbyint.cpp -------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/nearest.cpp b/flang-rt/lib/FortranFloat128Math/nearest.cpp
similarity index 88%
rename from flang/runtime/Float128Math/nearest.cpp
rename to flang-rt/lib/FortranFloat128Math/nearest.cpp
index 50f6e7ea75a604..3e32de7ea9d0ae 100644
--- a/flang/runtime/Float128Math/nearest.cpp
+++ b/flang-rt/lib/FortranFloat128Math/nearest.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/nearest.cpp ----------------------------------===//
+//===-- lib/FortranFloat128Math/nearest.cpp ---------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/norm2.cpp b/flang-rt/lib/FortranFloat128Math/norm2.cpp
similarity index 90%
rename from flang/runtime/Float128Math/norm2.cpp
rename to flang-rt/lib/FortranFloat128Math/norm2.cpp
index 18e9c8cc8a2b96..8f6b2c87eec326 100644
--- a/flang/runtime/Float128Math/norm2.cpp
+++ b/flang-rt/lib/FortranFloat128Math/norm2.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/norm2.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/norm2.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,7 +8,7 @@
 
 #include "math-entries.h"
 #include "numeric-template-specs.h"
-#include "reduction-templates.h"
+#include "flang-rt/reduction-templates.h"
 
 namespace Fortran::runtime {
 extern "C" {
diff --git a/flang/runtime/Float128Math/numeric-template-specs.h b/flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
similarity index 82%
rename from flang/runtime/Float128Math/numeric-template-specs.h
rename to flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
index a0a77230c3e9eb..fc912f75075a75 100644
--- a/flang/runtime/Float128Math/numeric-template-specs.h
+++ b/flang-rt/lib/FortranFloat128Math/numeric-template-specs.h
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/numeric-template-specs.h -----------*- C++ -*-===//
+//===-- lib/FortranFloat128Math/numeric-template-specs.h --------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,11 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
-#define FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
+#ifndef FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
+#define FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
 
 #include "math-entries.h"
-#include "numeric-templates.h"
+#include "flang-rt/numeric-templates.h"
 
 namespace Fortran::runtime {
 using F128Type = CppTypeFor<TypeCategory::Real, 16>;
@@ -52,4 +52,4 @@ template <> struct SQRTTy<F128Type> {
 };
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
+#endif /* FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_ */
diff --git a/flang/runtime/Float128Math/pow.cpp b/flang-rt/lib/FortranFloat128Math/pow.cpp
similarity index 88%
rename from flang/runtime/Float128Math/pow.cpp
rename to flang-rt/lib/FortranFloat128Math/pow.cpp
index 99aae04c65ecbe..bbdda217c5108c 100644
--- a/flang/runtime/Float128Math/pow.cpp
+++ b/flang-rt/lib/FortranFloat128Math/pow.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/pow.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/pow.cpp -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/random.cpp b/flang-rt/lib/FortranFloat128Math/random.cpp
similarity index 84%
rename from flang/runtime/Float128Math/random.cpp
rename to flang-rt/lib/FortranFloat128Math/random.cpp
index 93c5c14cee37dc..701f9429fcb6cb 100644
--- a/flang/runtime/Float128Math/random.cpp
+++ b/flang-rt/lib/FortranFloat128Math/random.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/random.cpp -----------------------------------===//
+//===-- lib/FortranFloat128Math/random.cpp ----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,7 +8,7 @@
 
 #include "math-entries.h"
 #include "numeric-template-specs.h"
-#include "random-templates.h"
+#include "flang-rt/random-templates.h"
 
 using namespace Fortran::runtime::random;
 extern "C" {
diff --git a/flang/runtime/Float128Math/remainder.cpp b/flang-rt/lib/FortranFloat128Math/remainder.cpp
similarity index 88%
rename from flang/runtime/Float128Math/remainder.cpp
rename to flang-rt/lib/FortranFloat128Math/remainder.cpp
index e5c2793dab71af..ca4165a357eda9 100644
--- a/flang/runtime/Float128Math/remainder.cpp
+++ b/flang-rt/lib/FortranFloat128Math/remainder.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/remainder.cpp --------------------------------===//
+//===-- lib/FortranFloat128Math/remainder.cpp -------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/round.cpp b/flang-rt/lib/FortranFloat128Math/round.cpp
similarity index 89%
rename from flang/runtime/Float128Math/round.cpp
rename to flang-rt/lib/FortranFloat128Math/round.cpp
index e79ce30536b3bf..348f7ff8a67712 100644
--- a/flang/runtime/Float128Math/round.cpp
+++ b/flang-rt/lib/FortranFloat128Math/round.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/round.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/round.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/rrspacing.cpp b/flang-rt/lib/FortranFloat128Math/rrspacing.cpp
similarity index 87%
rename from flang/runtime/Float128Math/rrspacing.cpp
rename to flang-rt/lib/FortranFloat128Math/rrspacing.cpp
index 04cefc049bbee2..0a87a5c572652c 100644
--- a/flang/runtime/Float128Math/rrspacing.cpp
+++ b/flang-rt/lib/FortranFloat128Math/rrspacing.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/rrspacing.cpp --------------------------------===//
+//===-- lib/FortranFloat128Math/rrspacing.cpp -------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/scale.cpp b/flang-rt/lib/FortranFloat128Math/scale.cpp
similarity index 90%
rename from flang/runtime/Float128Math/scale.cpp
rename to flang-rt/lib/FortranFloat128Math/scale.cpp
index 6b083afbdf4d1a..a316a2a0cd7062 100644
--- a/flang/runtime/Float128Math/scale.cpp
+++ b/flang-rt/lib/FortranFloat128Math/scale.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/scale.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/scale.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/set-exponent.cpp b/flang-rt/lib/FortranFloat128Math/set-exponent.cpp
similarity index 88%
rename from flang/runtime/Float128Math/set-exponent.cpp
rename to flang-rt/lib/FortranFloat128Math/set-exponent.cpp
index 63c5b325085fb2..335c68f632f185 100644
--- a/flang/runtime/Float128Math/set-exponent.cpp
+++ b/flang-rt/lib/FortranFloat128Math/set-exponent.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/set-exponent.cpp -----------------------------===//
+//===-- lib/FortranFloat128Math/set-exponent.cpp ----------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/sin.cpp b/flang-rt/lib/FortranFloat128Math/sin.cpp
similarity index 87%
rename from flang/runtime/Float128Math/sin.cpp
rename to flang-rt/lib/FortranFloat128Math/sin.cpp
index 99fa3e493e6941..bd5f62808fc31e 100644
--- a/flang/runtime/Float128Math/sin.cpp
+++ b/flang-rt/lib/FortranFloat128Math/sin.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/sin.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/sin.cpp -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/sinh.cpp b/flang-rt/lib/FortranFloat128Math/sinh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/sinh.cpp
rename to flang-rt/lib/FortranFloat128Math/sinh.cpp
index b6cd96963612e7..07f12d437ed56b 100644
--- a/flang/runtime/Float128Math/sinh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/sinh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/sinh.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/sinh.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/spacing.cpp b/flang-rt/lib/FortranFloat128Math/spacing.cpp
similarity index 87%
rename from flang/runtime/Float128Math/spacing.cpp
rename to flang-rt/lib/FortranFloat128Math/spacing.cpp
index fc6aa2c4ec2d8f..b10351ab95555a 100644
--- a/flang/runtime/Float128Math/spacing.cpp
+++ b/flang-rt/lib/FortranFloat128Math/spacing.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/spacing.cpp ----------------------------------===//
+//===-- lib/FortranFloat128Math/spacing.cpp ---------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/sqrt.cpp b/flang-rt/lib/FortranFloat128Math/sqrt.cpp
similarity index 87%
rename from flang/runtime/Float128Math/sqrt.cpp
rename to flang-rt/lib/FortranFloat128Math/sqrt.cpp
index 871c66e0079845..b6fd6eabc267ba 100644
--- a/flang/runtime/Float128Math/sqrt.cpp
+++ b/flang-rt/lib/FortranFloat128Math/sqrt.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/sqrt.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/sqrt.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/tan.cpp b/flang-rt/lib/FortranFloat128Math/tan.cpp
similarity index 87%
rename from flang/runtime/Float128Math/tan.cpp
rename to flang-rt/lib/FortranFloat128Math/tan.cpp
index 2d6f448ba89554..437c0692191e86 100644
--- a/flang/runtime/Float128Math/tan.cpp
+++ b/flang-rt/lib/FortranFloat128Math/tan.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/tan.cpp --------------------------------------===//
+//===-- lib/FortranFloat128Math/tan.cpp -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/tanh.cpp b/flang-rt/lib/FortranFloat128Math/tanh.cpp
similarity index 87%
rename from flang/runtime/Float128Math/tanh.cpp
rename to flang-rt/lib/FortranFloat128Math/tanh.cpp
index f6321f48191911..48544d4bb75f40 100644
--- a/flang/runtime/Float128Math/tanh.cpp
+++ b/flang-rt/lib/FortranFloat128Math/tanh.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/tanh.cpp -------------------------------------===//
+//===-- lib/FortranFloat128Math/tanh.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/tgamma.cpp b/flang-rt/lib/FortranFloat128Math/tgamma.cpp
similarity index 87%
rename from flang/runtime/Float128Math/tgamma.cpp
rename to flang-rt/lib/FortranFloat128Math/tgamma.cpp
index 98fd792a633304..8d7963caa61c5a 100644
--- a/flang/runtime/Float128Math/tgamma.cpp
+++ b/flang-rt/lib/FortranFloat128Math/tgamma.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/tgamma.cpp -----------------------------------===//
+//===-- lib/FortranFloat128Math/tgamma.cpp ----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/trunc.cpp b/flang-rt/lib/FortranFloat128Math/trunc.cpp
similarity index 89%
rename from flang/runtime/Float128Math/trunc.cpp
rename to flang-rt/lib/FortranFloat128Math/trunc.cpp
index 54fa33176813ca..4a3dddeb1326cd 100644
--- a/flang/runtime/Float128Math/trunc.cpp
+++ b/flang-rt/lib/FortranFloat128Math/trunc.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/trunc.cpp ------------------------------------===//
+//===-- lib/FortranFloat128Math/trunc.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/y0.cpp b/flang-rt/lib/FortranFloat128Math/y0.cpp
similarity index 87%
rename from flang/runtime/Float128Math/y0.cpp
rename to flang-rt/lib/FortranFloat128Math/y0.cpp
index 0b3059b4cfe25d..c5b266b5cec03f 100644
--- a/flang/runtime/Float128Math/y0.cpp
+++ b/flang-rt/lib/FortranFloat128Math/y0.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/y0.cpp ---------------------------------------===//
+//===-- lib/FortranFloat128Math/y0.cpp --------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/y1.cpp b/flang-rt/lib/FortranFloat128Math/y1.cpp
similarity index 87%
rename from flang/runtime/Float128Math/y1.cpp
rename to flang-rt/lib/FortranFloat128Math/y1.cpp
index cb39d87034dc75..8b492c69e37415 100644
--- a/flang/runtime/Float128Math/y1.cpp
+++ b/flang-rt/lib/FortranFloat128Math/y1.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/y1.cpp ---------------------------------------===//
+//===-- lib/FortranFloat128Math/y1.cpp --------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/Float128Math/yn.cpp b/flang-rt/lib/FortranFloat128Math/yn.cpp
similarity index 87%
rename from flang/runtime/Float128Math/yn.cpp
rename to flang-rt/lib/FortranFloat128Math/yn.cpp
index bef8f9457df2fd..cb212b400f6e0d 100644
--- a/flang/runtime/Float128Math/yn.cpp
+++ b/flang-rt/lib/FortranFloat128Math/yn.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/Float128Math/yn.cpp ---------------------------------------===//
+//===-- lib/FortranFloat128Math/yn.cpp --------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/CUDA/allocatable.cpp b/flang-rt/lib/flang_rt/CUDA/allocatable.cpp
similarity index 94%
rename from flang/runtime/CUDA/allocatable.cpp
rename to flang-rt/lib/flang_rt/CUDA/allocatable.cpp
index 9be54e8906903d..2281e2148d4aef 100644
--- a/flang/runtime/CUDA/allocatable.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/allocatable.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/allocatable.cpp --------------------------------------===//
+//===-- lib/flang_rt/CUDA/allocatable.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,9 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/allocatable.h"
-#include "../assign-impl.h"
-#include "../stat.h"
-#include "../terminator.h"
+#include "flang-rt/assign-impl.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/CUDA/memmove-function.h"
diff --git a/flang/runtime/CUDA/allocator.cpp b/flang-rt/lib/flang_rt/CUDA/allocator.cpp
similarity index 86%
rename from flang/runtime/CUDA/allocator.cpp
rename to flang-rt/lib/flang_rt/CUDA/allocator.cpp
index 368c1124ef70a5..dc1ce5920e2221 100644
--- a/flang/runtime/CUDA/allocator.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/allocator.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/allocator.cpp ----------------------------------------===//
+//===-- lib/flang_rt/CUDA/allocator.cpp -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/CUDA/allocator.h"
-#include "../derived.h"
-#include "../stat.h"
-#include "../terminator.h"
-#include "../type-info.h"
+#include "flang-rt/CUDA/allocator.h"
+#include "flang-rt/allocator-registry.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/type-info.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/CUDA/common.h"
-#include "flang/Runtime/allocator-registry.h"
 #include "flang/Support/Fortran.h"
 
 #include "cuda_runtime.h"
diff --git a/flang/runtime/CUDA/descriptor.cpp b/flang-rt/lib/flang_rt/CUDA/descriptor.cpp
similarity index 90%
rename from flang/runtime/CUDA/descriptor.cpp
rename to flang-rt/lib/flang_rt/CUDA/descriptor.cpp
index 947eeb66aa3d6c..9ec79ccea22c33 100644
--- a/flang/runtime/CUDA/descriptor.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/descriptor.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/descriptor.cpp ---------------------------------------===//
+//===-- lib/flang_rt/CUDA/descriptor.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/descriptor.h"
-#include "../terminator.h"
-#include "flang/Runtime/CUDA/allocator.h"
+#include "flang-rt/CUDA/allocator.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
-#include "flang/Runtime/descriptor.h"
 
 #include "cuda_runtime.h"
 
diff --git a/flang/runtime/CUDA/kernel.cpp b/flang-rt/lib/flang_rt/CUDA/kernel.cpp
similarity index 97%
rename from flang/runtime/CUDA/kernel.cpp
rename to flang-rt/lib/flang_rt/CUDA/kernel.cpp
index bdc04ccb17672b..fce6e24ae0f125 100644
--- a/flang/runtime/CUDA/kernel.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/kernel.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/kernel.cpp -------------------------------------------===//
+//===-- lib/flang_rt/CUDA/kernel.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/kernel.h"
-#include "../terminator.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 
 #include "cuda_runtime.h"
diff --git a/flang/runtime/CUDA/memmove-function.cpp b/flang-rt/lib/flang_rt/CUDA/memmove-function.cpp
similarity index 91%
rename from flang/runtime/CUDA/memmove-function.cpp
rename to flang-rt/lib/flang_rt/CUDA/memmove-function.cpp
index 3ba9fa7e0f7f73..ca04e20379d038 100644
--- a/flang/runtime/CUDA/memmove-function.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/memmove-function.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/memmove-function.cpp ---------------------------------===//
+//===-- lib/flang_rt/CUDA/memmove-function.cpp ------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/memmove-function.h"
-#include "../terminator.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 
 #include "cuda_runtime.h"
diff --git a/flang/runtime/CUDA/memory.cpp b/flang-rt/lib/flang_rt/CUDA/memory.cpp
similarity index 97%
rename from flang/runtime/CUDA/memory.cpp
rename to flang-rt/lib/flang_rt/CUDA/memory.cpp
index 0bbb493d2db919..3d4a74f5f9e52e 100644
--- a/flang/runtime/CUDA/memory.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/memory.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/memory.cpp -------------------------------------------===//
+//===-- lib/flang_rt/CUDA/memory.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/memory.h"
-#include "../assign-impl.h"
-#include "../terminator.h"
+#include "flang-rt/assign-impl.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/CUDA/memmove-function.h"
diff --git a/flang/runtime/CUDA/registration.cpp b/flang-rt/lib/flang_rt/CUDA/registration.cpp
similarity index 93%
rename from flang/runtime/CUDA/registration.cpp
rename to flang-rt/lib/flang_rt/CUDA/registration.cpp
index b7b6ef389bffba..f8a7b197bed3b4 100644
--- a/flang/runtime/CUDA/registration.cpp
+++ b/flang-rt/lib/flang_rt/CUDA/registration.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/CUDA/registration.cpp -------------------------------------===//
+//===-- lib/flang_rt/CUDA/registration.cpp ----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/registration.h"
-#include "../terminator.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 
 #include "cuda_runtime.h"
diff --git a/flang/runtime/ISO_Fortran_binding.cpp b/flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
similarity index 98%
rename from flang/runtime/ISO_Fortran_binding.cpp
rename to flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
index 64e239f498230c..d9b0bfe9aeb6b5 100644
--- a/flang/runtime/ISO_Fortran_binding.cpp
+++ b/flang-rt/lib/flang_rt/ISO_Fortran_binding.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/ISO_Fortran_binding.cpp -----------------------------------===//
+//===-- lib/flang_rt/ISO_Fortran_binding.cpp --------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,11 +10,11 @@
 // as specified in section 18.5.5 of Fortran 2018.
 
 #include "ISO_Fortran_util.h"
-#include "terminator.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/type-code.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/pointer.h"
-#include "flang/Runtime/type-code.h"
 #include <cstdlib>
 
 namespace Fortran::ISO {
diff --git a/flang/runtime/ISO_Fortran_util.h b/flang-rt/lib/flang_rt/ISO_Fortran_util.h
similarity index 91%
rename from flang/runtime/ISO_Fortran_util.h
rename to flang-rt/lib/flang_rt/ISO_Fortran_util.h
index aca9aee8c5718e..6128faba5bcead 100644
--- a/flang/runtime/ISO_Fortran_util.h
+++ b/flang-rt/lib/flang_rt/ISO_Fortran_util.h
@@ -1,4 +1,4 @@
-//===-- runtime/ISO_Fortran_util.h ------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/ISO_Fortran_util.h -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,15 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_
-#define FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_
+#ifndef FLANG_RT_ISO_FORTRAN_UTIL_H_
+#define FLANG_RT_ISO_FORTRAN_UTIL_H_
 
 // Internal utils for establishing CFI_cdesc_t descriptors.
 
-#include "terminator.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/type-code.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
 #include <cstdlib>
 
 namespace Fortran::ISO {
@@ -99,4 +99,4 @@ static inline RT_API_ATTRS void EstablishDescriptor(CFI_cdesc_t *descriptor,
   }
 }
 } // namespace Fortran::ISO
-#endif // FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_
+#endif /* FLANG_RT_ISO_FORTRAN_UTIL_H_ */
diff --git a/flang/runtime/allocatable.cpp b/flang-rt/lib/flang_rt/allocatable.cpp
similarity index 96%
rename from flang/runtime/allocatable.cpp
rename to flang-rt/lib/flang_rt/allocatable.cpp
index 686114bf86eafa..63ef99b8a72d11 100644
--- a/flang/runtime/allocatable.cpp
+++ b/flang-rt/lib/flang_rt/allocatable.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/allocatable.cpp -------------------------------------------===//
+//===-- lib/flang_rt/allocatable.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,14 +7,14 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/allocatable.h"
-#include "assign-impl.h"
-#include "derived.h"
-#include "stat.h"
-#include "terminator.h"
-#include "type-info.h"
+#include "flang-rt/assign-impl.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/type-info.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/assign.h"
-#include "flang/Runtime/descriptor.h"
 
 namespace Fortran::runtime {
 extern "C" {
diff --git a/flang/runtime/allocator-registry.cpp b/flang-rt/lib/flang_rt/allocator-registry.cpp
similarity index 88%
rename from flang/runtime/allocator-registry.cpp
rename to flang-rt/lib/flang_rt/allocator-registry.cpp
index f5670331d6dbe2..11847de68724d8 100644
--- a/flang/runtime/allocator-registry.cpp
+++ b/flang-rt/lib/flang_rt/allocator-registry.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/allocator-registry.cpp ------------------------------------===//
+//===-- lib/flang_rt/allocator-registry.cpp ---------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/allocator-registry.h"
-#include "terminator.h"
+#include "flang-rt/allocator-registry.h"
+#include "flang-rt/terminator.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/array-constructor.cpp b/flang-rt/lib/flang_rt/array-constructor.cpp
similarity index 96%
rename from flang/runtime/array-constructor.cpp
rename to flang-rt/lib/flang_rt/array-constructor.cpp
index c6953167f5fb2e..d2765c9439b75c 100644
--- a/flang/runtime/array-constructor.cpp
+++ b/flang-rt/lib/flang_rt/array-constructor.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/array-constructor.cpp -------------------------------------===//
+//===-- lib/flang_rt/array-constructor.cpp ----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/array-constructor.h"
-#include "derived.h"
-#include "terminator.h"
-#include "tools.h"
-#include "type-info.h"
+#include "flang-rt/array-constructor.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-info.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/assign.h"
-#include "flang/Runtime/descriptor.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/assign.cpp b/flang-rt/lib/flang_rt/assign.cpp
similarity index 98%
rename from flang/runtime/assign.cpp
rename to flang-rt/lib/flang_rt/assign.cpp
index 8f0efaa376c198..0d6045eac503a1 100644
--- a/flang/runtime/assign.cpp
+++ b/flang-rt/lib/flang_rt/assign.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/assign.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/assign.cpp ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/assign.h"
-#include "assign-impl.h"
-#include "derived.h"
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "type-info.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/assign-impl.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-info.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/buffer.cpp b/flang-rt/lib/flang_rt/buffer.cpp
similarity index 89%
rename from flang/runtime/buffer.cpp
rename to flang-rt/lib/flang_rt/buffer.cpp
index 7b4869d69c2e51..e084155068bc5a 100644
--- a/flang/runtime/buffer.cpp
+++ b/flang-rt/lib/flang_rt/buffer.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/buffer.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/buffer.cpp ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "buffer.h"
+#include "flang-rt/buffer.h"
 #include <algorithm>
 
 namespace Fortran::runtime::io {
diff --git a/flang/runtime/character.cpp b/flang-rt/lib/flang_rt/character.cpp
similarity index 99%
rename from flang/runtime/character.cpp
rename to flang-rt/lib/flang_rt/character.cpp
index 5049247397eb3c..79d4ebdb0afbfe 100644
--- a/flang/runtime/character.cpp
+++ b/flang-rt/lib/flang_rt/character.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/character.cpp ---------------------------------------------===//
+//===-- lib/flang_rt/character.cpp ------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/character.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/bit-population-count.h"
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/character.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include <algorithm>
 #include <cstring>
 
diff --git a/flang/runtime/command.cpp b/flang-rt/lib/flang_rt/command.cpp
similarity index 96%
rename from flang/runtime/command.cpp
rename to flang-rt/lib/flang_rt/command.cpp
index a555e26f96a66c..498ae8db172241 100644
--- a/flang/runtime/command.cpp
+++ b/flang-rt/lib/flang_rt/command.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/command.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/command.cpp --------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/command.h"
-#include "environment.h"
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include <cstdlib>
 #include <limits>
 
diff --git a/flang/runtime/complex-powi.cpp b/flang-rt/lib/flang_rt/complex-powi.cpp
similarity index 92%
rename from flang/runtime/complex-powi.cpp
rename to flang-rt/lib/flang_rt/complex-powi.cpp
index 62f73e037b76f7..287bafc4220575 100644
--- a/flang/runtime/complex-powi.cpp
+++ b/flang-rt/lib/flang_rt/complex-powi.cpp
@@ -1,11 +1,11 @@
-/*===-- flang/runtime/complex-powi.cpp ----------------------------*- C++ -*-===
- *
- * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
- * See https://llvm.org/LICENSE.txt for license information.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- *
- * ===-----------------------------------------------------------------------===
- */
+//===-- lib/flang_rt/complex-powi.cpp ---------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
 #include "flang/Common/float128.h"
 #include "flang/Runtime/cpp-type.h"
 #include "flang/Runtime/entry-names.h"
diff --git a/flang/runtime/complex-reduction.c b/flang-rt/lib/flang_rt/complex-reduction.c
similarity index 97%
rename from flang/runtime/complex-reduction.c
rename to flang-rt/lib/flang_rt/complex-reduction.c
index de1ff3d6830840..967f26c05e7023 100644
--- a/flang/runtime/complex-reduction.c
+++ b/flang-rt/lib/flang_rt/complex-reduction.c
@@ -1,11 +1,10 @@
-/*===-- flang/runtime/complex-reduction.c ---------------------------*- C -*-===
+/*===-- lib/flang_rt/complex-reduction.c ----------------------------*- C -*-===
  *
  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  * See https://llvm.org/LICENSE.txt for license information.
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  *
- * ===-----------------------------------------------------------------------===
- */
+ *===----------------------------------------------------------------------===*/
 
 #include "complex-reduction.h"
 #include <float.h>
diff --git a/flang/runtime/complex-reduction.h b/flang-rt/lib/flang_rt/complex-reduction.h
similarity index 96%
rename from flang/runtime/complex-reduction.h
rename to flang-rt/lib/flang_rt/complex-reduction.h
index 5ff2a828fb3ecc..2678dbf4e6472d 100644
--- a/flang/runtime/complex-reduction.h
+++ b/flang-rt/lib/flang_rt/complex-reduction.h
@@ -1,19 +1,18 @@
-/*===-- flang/runtime/complex-reduction.h ---------------------------*- C -*-===
+/*===-- lib/flang_rt/complex-reduction.h ----------------------------*- C -*-===
  *
  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  * See https://llvm.org/LICENSE.txt for license information.
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  *
- * ===-----------------------------------------------------------------------===
- */
+ *===----------------------------------------------------------------------===*/
 
 /* Wraps the C++-coded complex-valued SUM and PRODUCT reductions with
  * C-coded wrapper functions returning _Complex values, to avoid problems
  * with C++ build compilers that don't support C's _Complex.
  */
 
-#ifndef FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
-#define FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
+#ifndef FLANG_RT_COMPLEX_REDUCTION_H_
+#define FLANG_RT_COMPLEX_REDUCTION_H_
 
 #include "flang/Common/float128.h"
 #include "flang/Runtime/entry-names.h"
@@ -156,4 +155,4 @@ void RTNAME(ReduceComplex16DimValue)(
     REDUCE_DIM_ARGS(CFloat128ComplexType, CFloat128ComplexType_value_op));
 #endif
 
-#endif // FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
+#endif /* FLANG_RT_COMPLEX_REDUCTION_H_ */
diff --git a/flang/runtime/connection.cpp b/flang-rt/lib/flang_rt/connection.cpp
similarity index 91%
rename from flang/runtime/connection.cpp
rename to flang-rt/lib/flang_rt/connection.cpp
index f24f0e832eb484..1c454b81389acc 100644
--- a/flang/runtime/connection.cpp
+++ b/flang-rt/lib/flang_rt/connection.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/connection.cpp --------------------------------------------===//
+//===-- lib/flang_rt/connection.cpp -----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "connection.h"
-#include "environment.h"
-#include "io-stmt.h"
+#include "flang-rt/connection.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/io-stmt.h"
 #include <algorithm>
 
 namespace Fortran::runtime::io {
diff --git a/flang/runtime/copy.cpp b/flang-rt/lib/flang_rt/copy.cpp
similarity index 98%
rename from flang/runtime/copy.cpp
rename to flang-rt/lib/flang_rt/copy.cpp
index b20f68f019498b..0ad6946d3161ac 100644
--- a/flang/runtime/copy.cpp
+++ b/flang-rt/lib/flang_rt/copy.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/copy.cpp -------------------------------------------------===//
+//===-- lib/flang_rt/copy.cpp -----------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,10 +8,10 @@
 
 #include "copy.h"
 #include "stack.h"
-#include "terminator.h"
-#include "type-info.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/type-info.h"
 #include "flang/Runtime/allocatable.h"
-#include "flang/Runtime/descriptor.h"
 #include <cstring>
 
 namespace Fortran::runtime {
diff --git a/flang/runtime/copy.h b/flang-rt/lib/flang_rt/copy.h
similarity index 79%
rename from flang/runtime/copy.h
rename to flang-rt/lib/flang_rt/copy.h
index 542660530bfb65..468c2439baf618 100644
--- a/flang/runtime/copy.h
+++ b/flang-rt/lib/flang_rt/copy.h
@@ -1,4 +1,4 @@
-//===-- runtime/copy.h ------------------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/copy.h -------------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,10 +9,10 @@
 // Utilities that copy data in a type-aware fashion, allocating & duplicating
 // allocatable/automatic components of derived types along the way.
 
-#ifndef FORTRAN_RUNTIME_COPY_H_
-#define FORTRAN_RUNTIME_COPY_H_
+#ifndef FLANG_RT_COPY_H_
+#define FLANG_RT_COPY_H_
 
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 
 namespace Fortran::runtime {
 
@@ -22,4 +22,4 @@ RT_API_ATTRS void CopyElement(const Descriptor &to, const SubscriptValue toAt[],
     const Descriptor &from, const SubscriptValue fromAt[], Terminator &);
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_COPY_H_
+#endif /* FLANG_RT_COPY_H_ */
diff --git a/flang/runtime/derived-api.cpp b/flang-rt/lib/flang_rt/derived-api.cpp
similarity index 96%
rename from flang/runtime/derived-api.cpp
rename to flang-rt/lib/flang_rt/derived-api.cpp
index c8ffd8e3bb67c6..353bc4a83ebd98 100644
--- a/flang/runtime/derived-api.cpp
+++ b/flang-rt/lib/flang_rt/derived-api.cpp
@@ -1,5 +1,4 @@
-//===-- runtime/derived-api.cpp
-//-----------------------------------------------===//
+//===-- lib/flang_rt/derived-api.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/derived-api.h"
-#include "derived.h"
-#include "terminator.h"
-#include "tools.h"
-#include "type-info.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-info.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/derived.cpp b/flang-rt/lib/flang_rt/derived.cpp
similarity index 98%
rename from flang/runtime/derived.cpp
rename to flang-rt/lib/flang_rt/derived.cpp
index 10813c62e5da1f..cace9e1074e659 100644
--- a/flang/runtime/derived.cpp
+++ b/flang-rt/lib/flang_rt/derived.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/derived.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/derived.cpp --------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,12 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "derived.h"
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "type-info.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-info.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/descriptor-io.cpp b/flang-rt/lib/flang_rt/descriptor-io.cpp
similarity index 98%
rename from flang/runtime/descriptor-io.cpp
rename to flang-rt/lib/flang_rt/descriptor-io.cpp
index 380ad425d925f0..c5cfa4d7fc5972 100644
--- a/flang/runtime/descriptor-io.cpp
+++ b/flang-rt/lib/flang_rt/descriptor-io.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/descriptor-io.cpp -----------------------------------------===//
+//===-- lib/flang_rt/descriptor-io.cpp --------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/descriptor-io.h b/flang-rt/lib/flang_rt/descriptor-io.h
similarity index 98%
rename from flang/runtime/descriptor-io.h
rename to flang-rt/lib/flang_rt/descriptor-io.h
index 1034958bf654ab..763ebb1735752b 100644
--- a/flang/runtime/descriptor-io.h
+++ b/flang-rt/lib/flang_rt/descriptor-io.h
@@ -1,4 +1,4 @@
-//===-- runtime/descriptor-io.h ---------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/descriptor-io.h ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_DESCRIPTOR_IO_H_
-#define FORTRAN_RUNTIME_DESCRIPTOR_IO_H_
+#ifndef FLANG_RT_DESCRIPTOR_IO_H_
+#define FLANG_RT_DESCRIPTOR_IO_H_
 
 // Implementation of I/O data list item transfers based on descriptors.
 // (All I/O items come through here so that the code is exercised for test;
@@ -16,15 +16,15 @@
 
 #include "edit-input.h"
 #include "edit-output.h"
-#include "io-stmt.h"
-#include "namelist.h"
-#include "terminator.h"
-#include "type-info.h"
 #include "unit.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-stmt.h"
+#include "flang-rt/namelist.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/type-info.h"
 #include "flang/Common/optional.h"
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 
 namespace Fortran::runtime::io::descr {
 template <typename A>
@@ -626,4 +626,4 @@ static RT_API_ATTRS bool DescriptorIO(IoStatementState &io,
   return false;
 }
 } // namespace Fortran::runtime::io::descr
-#endif // FORTRAN_RUNTIME_DESCRIPTOR_IO_H_
+#endif /* FLANG_RT_DESCRIPTOR_IO_H_ */
diff --git a/flang/runtime/descriptor.cpp b/flang-rt/lib/flang_rt/descriptor.cpp
similarity index 95%
rename from flang/runtime/descriptor.cpp
rename to flang-rt/lib/flang_rt/descriptor.cpp
index 32f43e89dc7a36..cdf01f12e71347 100644
--- a/flang/runtime/descriptor.cpp
+++ b/flang-rt/lib/flang_rt/descriptor.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/descriptor.cpp --------------------------------------------===//
+//===-- lib/flang_rt/descriptor.cpp -----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,15 +6,15 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "ISO_Fortran_util.h"
-#include "derived.h"
 #include "memory.h"
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "type-info.h"
-#include "flang/Runtime/allocator-registry.h"
+#include "flang-rt/allocator-registry.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-info.h"
 #include <cassert>
 #include <cstdlib>
 #include <cstring>
@@ -141,8 +141,10 @@ RT_API_ATTRS OwningPtr<Descriptor> Descriptor::Create(
 
 RT_API_ATTRS std::size_t Descriptor::SizeInBytes() const {
   const DescriptorAddendum *addendum{Addendum()};
-  return sizeof *this - sizeof(Dimension) + raw_.rank * sizeof(Dimension) +
-      (addendum ? addendum->SizeInBytes() : 0);
+  std::size_t bytes{ sizeof *this - sizeof(Dimension) + raw_.rank * sizeof(Dimension) +
+      (addendum ? addendum->SizeInBytes() : 0)};
+  assert (bytes <= MaxDescriptorSizeInBytes(raw_.rank,addendum) && "Descriptor must fit compiler-allocated space");
+  return bytes;
 }
 
 RT_API_ATTRS std::size_t Descriptor::Elements() const {
diff --git a/flang/runtime/dot-product.cpp b/flang-rt/lib/flang_rt/dot-product.cpp
similarity index 98%
rename from flang/runtime/dot-product.cpp
rename to flang-rt/lib/flang_rt/dot-product.cpp
index 712497a3a50aca..ad600a4228463b 100644
--- a/flang/runtime/dot-product.cpp
+++ b/flang-rt/lib/flang_rt/dot-product.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/dot-product.cpp -------------------------------------------===//
+//===-- lib/flang_rt/dot-product.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "float.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/reduction.h"
 #include <cfloat>
 #include <cinttypes>
diff --git a/flang/runtime/edit-input.cpp b/flang-rt/lib/flang_rt/edit-input.cpp
similarity index 99%
rename from flang/runtime/edit-input.cpp
rename to flang-rt/lib/flang_rt/edit-input.cpp
index 317f0b676bd21b..7121f6e42dea65 100644
--- a/flang/runtime/edit-input.cpp
+++ b/flang-rt/lib/flang_rt/edit-input.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/edit-input.cpp --------------------------------------------===//
+//===-- lib/flang_rt/edit-input.cpp -----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "edit-input.h"
-#include "namelist.h"
-#include "utf.h"
+#include "flang-rt/namelist.h"
+#include "flang-rt/utf.h"
 #include "flang/Common/optional.h"
 #include "flang/Common/real.h"
 #include "flang/Common/uint128.h"
diff --git a/flang/runtime/edit-input.h b/flang-rt/lib/flang_rt/edit-input.h
similarity index 89%
rename from flang/runtime/edit-input.h
rename to flang-rt/lib/flang_rt/edit-input.h
index 55a7a455781719..2d6a3f241a0059 100644
--- a/flang/runtime/edit-input.h
+++ b/flang-rt/lib/flang_rt/edit-input.h
@@ -1,4 +1,4 @@
-//===-- runtime/edit-input.h ------------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/edit-input.h -------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,11 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_EDIT_INPUT_H_
-#define FORTRAN_RUNTIME_EDIT_INPUT_H_
+#ifndef FLANG_RT_EDIT_INPUT_H_
+#define FLANG_RT_EDIT_INPUT_H_
 
-#include "format.h"
-#include "io-stmt.h"
+#include "flang-rt/format.h"
+#include "flang-rt/io-stmt.h"
 #include "flang/Decimal/decimal.h"
 
 namespace Fortran::runtime::io {
@@ -50,4 +50,4 @@ extern template RT_API_ATTRS bool EditCharacterInput(
     IoStatementState &, const DataEdit &, char32_t *, std::size_t);
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_EDIT_INPUT_H_
+#endif /* FLANG_RT_EDIT_INPUT_H_ */
diff --git a/flang/runtime/edit-output.cpp b/flang-rt/lib/flang_rt/edit-output.cpp
similarity index 99%
rename from flang/runtime/edit-output.cpp
rename to flang-rt/lib/flang_rt/edit-output.cpp
index 9db9a3d4a511b0..096bd4567a42a6 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang-rt/lib/flang_rt/edit-output.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/edit-output.cpp -------------------------------------------===//
+//===-- lib/flang_rt/edit-output.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "edit-output.h"
-#include "emit-encoded.h"
-#include "utf.h"
+#include "flang-rt/emit-encoded.h"
+#include "flang-rt/utf.h"
 #include "flang/Common/real.h"
 #include "flang/Common/uint128.h"
 #include <algorithm>
diff --git a/flang/runtime/edit-output.h b/flang-rt/lib/flang_rt/edit-output.h
similarity index 96%
rename from flang/runtime/edit-output.h
rename to flang-rt/lib/flang_rt/edit-output.h
index 42cc993f98cc1c..59f5d820c4ad56 100644
--- a/flang/runtime/edit-output.h
+++ b/flang-rt/lib/flang_rt/edit-output.h
@@ -1,4 +1,4 @@
-//===-- runtime/edit-output.h -----------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/edit-output.h ------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_RUNTIME_EDIT_OUTPUT_H_
-#define FORTRAN_RUNTIME_EDIT_OUTPUT_H_
+#ifndef FLANG_RT_EDIT_OUTPUT_H_
+#define FLANG_RT_EDIT_OUTPUT_H_
 
 // Output data editing templates implementing the FORMAT data editing
 // descriptors E, EN, ES, EX, D, F, and G for REAL data (and COMPLEX
@@ -18,8 +18,8 @@
 // Drives the same fast binary-to-decimal formatting templates used
 // in the f18 front-end.
 
-#include "format.h"
-#include "io-stmt.h"
+#include "flang-rt/format.h"
+#include "flang-rt/io-stmt.h"
 #include "flang/Common/uint128.h"
 #include "flang/Decimal/decimal.h"
 
@@ -138,4 +138,4 @@ extern template class RealOutputEditing<10>;
 extern template class RealOutputEditing<16>;
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_EDIT_OUTPUT_H_
+#endif /* FLANG_RT_EDIT_OUTPUT_H_ */
diff --git a/flang/runtime/environment-default-list.h b/flang-rt/lib/flang_rt/environment-default-list.h
similarity index 70%
rename from flang/runtime/environment-default-list.h
rename to flang-rt/lib/flang_rt/environment-default-list.h
index 4da261b10b9a84..76c0955bcce6d9 100644
--- a/flang/runtime/environment-default-list.h
+++ b/flang-rt/lib/flang_rt/environment-default-list.h
@@ -1,14 +1,13 @@
-/*===-- runtime/environment-default-list.h --------------------------*- C -*-===
+/*===-- lib/flang_rt/environment-default-list.h ---------------------*- C -*-===
  *
  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  * See https://llvm.org/LICENSE.txt for license information.
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  *
- * ===-----------------------------------------------------------------------===
- */
+ *===----------------------------------------------------------------------===*/
 
-#ifndef FORTRAN_RUNTIME_ENVIRONMENT_DEFAULT_LIST_H_
-#define FORTRAN_RUNTIME_ENVIRONMENT_DEFAULT_LIST_H_
+#ifndef FLANG_RT_ENVIRONMENT_DEFAULT_LIST_H_
+#define FLANG_RT_ENVIRONMENT_DEFAULT_LIST_H_
 
 /* Try to maintain C compatibility to make it easier to both define environment
  * defaults in non-Fortran main programs as well as pass through the environment
@@ -28,4 +27,4 @@ struct EnvironmentDefaultList {
   const struct EnvironmentDefaultItem *item;
 };
 
-#endif /* FORTRAN_RUNTIME_ENVIRONMENT_DEFAULT_LIST_H_ */
+#endif /* FLANG_RT_ENVIRONMENT_DEFAULT_LIST_H_ */
diff --git a/flang/runtime/environment.cpp b/flang-rt/lib/flang_rt/environment.cpp
similarity index 96%
rename from flang/runtime/environment.cpp
rename to flang-rt/lib/flang_rt/environment.cpp
index 52b1d99ba536ed..b8d96b933f5b6f 100644
--- a/flang/runtime/environment.cpp
+++ b/flang-rt/lib/flang_rt/environment.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/environment.cpp -------------------------------------------===//
+//===-- lib/flang_rt/environment.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "environment.h"
+#include "flang-rt/environment.h"
 #include "environment-default-list.h"
 #include "memory.h"
-#include "tools.h"
+#include "flang-rt/tools.h"
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
diff --git a/flang/runtime/exceptions.cpp b/flang-rt/lib/flang_rt/exceptions.cpp
similarity index 96%
rename from flang/runtime/exceptions.cpp
rename to flang-rt/lib/flang_rt/exceptions.cpp
index f541b8e844aded..c6ddc5d05ccf32 100644
--- a/flang/runtime/exceptions.cpp
+++ b/flang-rt/lib/flang_rt/exceptions.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/exceptions.cpp --------------------------------------===//
+//===-- lib/flang_rt/exceptions.cpp -----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,7 +9,7 @@
 // Runtime exception support.
 
 #include "flang/Runtime/exceptions.h"
-#include "terminator.h"
+#include "flang-rt/terminator.h"
 #include <cfenv>
 #if __x86_64__
 #include <xmmintrin.h>
diff --git a/flang/runtime/execute.cpp b/flang-rt/lib/flang_rt/execute.cpp
similarity index 97%
rename from flang/runtime/execute.cpp
rename to flang-rt/lib/flang_rt/execute.cpp
index c7f8f386d81f4f..8d56581c12a49f 100644
--- a/flang/runtime/execute.cpp
+++ b/flang-rt/lib/flang_rt/execute.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/execute.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/execute.cpp --------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/execute.h"
-#include "environment.h"
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include <cstdlib>
 #include <errno.h>
 #include <future>
diff --git a/flang/runtime/extensions.cpp b/flang-rt/lib/flang_rt/extensions.cpp
similarity index 97%
rename from flang/runtime/extensions.cpp
rename to flang-rt/lib/flang_rt/extensions.cpp
index 50d3c72fe650d0..aee71164575a2f 100644
--- a/flang/runtime/extensions.cpp
+++ b/flang-rt/lib/flang_rt/extensions.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/extensions.cpp --------------------------------------------===//
+//===-- lib/flang_rt/extensions.cpp -----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,10 +10,10 @@
 // extensions that will eventually be implemented in Fortran.
 
 #include "flang/Runtime/extensions.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/command.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/entry-names.h"
 #include "flang/Runtime/io-api.h"
 #include <chrono>
diff --git a/flang/runtime/external-unit.cpp b/flang-rt/lib/flang_rt/external-unit.cpp
similarity index 98%
rename from flang/runtime/external-unit.cpp
rename to flang-rt/lib/flang_rt/external-unit.cpp
index d17a92622f8448..4be90cbbcc4c88 100644
--- a/flang/runtime/external-unit.cpp
+++ b/flang-rt/lib/flang_rt/external-unit.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/external-unit.cpp -----------------------------------------===//
+//===-- lib/flang_rt/external-unit.cpp --------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,11 +10,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "io-error.h"
-#include "lock.h"
-#include "tools.h"
 #include "unit-map.h"
 #include "unit.h"
+#include "flang-rt/io-error.h"
+#include "flang-rt/lock.h"
+#include "flang-rt/tools.h"
 
 // NOTE: the header files above may define OpenMP declare target
 // variables, so they have to be included unconditionally
diff --git a/flang/runtime/extrema.cpp b/flang-rt/lib/flang_rt/extrema.cpp
similarity index 99%
rename from flang/runtime/extrema.cpp
rename to flang-rt/lib/flang_rt/extrema.cpp
index 7ecdf4b91702e0..8ecd7fbe91d772 100644
--- a/flang/runtime/extrema.cpp
+++ b/flang-rt/lib/flang_rt/extrema.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/extrema.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/extrema.cpp --------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,7 +10,7 @@
 // and shapes and (for MAXLOC & MINLOC) result integer kinds.  Also implements
 // NORM2 using common infrastructure.
 
-#include "reduction-templates.h"
+#include "flang-rt/reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/character.h"
 #include "flang/Runtime/reduction.h"
diff --git a/flang/runtime/file.cpp b/flang-rt/lib/flang_rt/file.cpp
similarity index 98%
rename from flang/runtime/file.cpp
rename to flang-rt/lib/flang_rt/file.cpp
index 9e077b8cea44bb..c9fcf0f97b718f 100644
--- a/flang/runtime/file.cpp
+++ b/flang-rt/lib/flang_rt/file.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/file.cpp --------------------------------------------------===//
+//===-- lib/flang_rt/file.cpp -----------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "file.h"
-#include "tools.h"
+#include "flang-rt/file.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/magic-numbers.h"
-#include "flang/Runtime/memory.h"
 #include <algorithm>
 #include <cerrno>
 #include <cstring>
diff --git a/flang/runtime/findloc.cpp b/flang-rt/lib/flang_rt/findloc.cpp
similarity index 99%
rename from flang/runtime/findloc.cpp
rename to flang-rt/lib/flang_rt/findloc.cpp
index b9b1d7f7ab689f..ac432676f5efcb 100644
--- a/flang/runtime/findloc.cpp
+++ b/flang-rt/lib/flang_rt/findloc.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/findloc.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/findloc.cpp --------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,7 +9,7 @@
 // Implements FINDLOC for all required operand types and shapes and result
 // integer kinds.
 
-#include "reduction-templates.h"
+#include "flang-rt/reduction-templates.h"
 #include "flang/Runtime/character.h"
 #include "flang/Runtime/reduction.h"
 #include <cinttypes>
diff --git a/flang/runtime/format.cpp b/flang-rt/lib/flang_rt/format.cpp
similarity index 88%
rename from flang/runtime/format.cpp
rename to flang-rt/lib/flang_rt/format.cpp
index 433acce4b73739..abd01b56919a4d 100644
--- a/flang/runtime/format.cpp
+++ b/flang-rt/lib/flang_rt/format.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/format.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/format.cpp ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "format-implementation.h"
+#include "flang-rt/format-implementation.h"
 
 namespace Fortran::runtime::io {
 RT_OFFLOAD_API_GROUP_BEGIN
diff --git a/flang/runtime/inquiry.cpp b/flang-rt/lib/flang_rt/inquiry.cpp
similarity index 94%
rename from flang/runtime/inquiry.cpp
rename to flang-rt/lib/flang_rt/inquiry.cpp
index 9fbcaa96fa3c43..e98d3900987dc7 100644
--- a/flang/runtime/inquiry.cpp
+++ b/flang-rt/lib/flang_rt/inquiry.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/inquiry.cpp --------------------------------------===//
+//===-- lib/flang_rt/inquiry.cpp --------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -11,9 +11,9 @@
 
 #include "flang/Runtime/inquiry.h"
 #include "copy.h"
-#include "terminator.h"
-#include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include <algorithm>
 
 namespace Fortran::runtime {
diff --git a/flang/runtime/internal-unit.cpp b/flang-rt/lib/flang_rt/internal-unit.cpp
similarity index 97%
rename from flang/runtime/internal-unit.cpp
rename to flang-rt/lib/flang_rt/internal-unit.cpp
index f8f3877efb20ea..12d702de4c5980 100644
--- a/flang/runtime/internal-unit.cpp
+++ b/flang-rt/lib/flang_rt/internal-unit.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/internal-unit.cpp -----------------------------------------===//
+//===-- lib/flang_rt/internal-unit.cpp --------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "internal-unit.h"
-#include "io-error.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/internal-unit.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-error.h"
 #include "flang/Runtime/freestanding-tools.h"
 #include <algorithm>
 #include <type_traits>
diff --git a/flang/runtime/io-api-common.h b/flang-rt/lib/flang_rt/io-api-common.h
similarity index 93%
rename from flang/runtime/io-api-common.h
rename to flang-rt/lib/flang_rt/io-api-common.h
index c7b86cab73a525..ba8c7177c2811f 100644
--- a/flang/runtime/io-api-common.h
+++ b/flang-rt/lib/flang_rt/io-api-common.h
@@ -1,4 +1,4 @@
-//===-- runtime/io-api-common.h ---------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/io-api-common.h ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,12 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FLANG_RUNTIME_IO_API_COMMON_H_
-#define FLANG_RUNTIME_IO_API_COMMON_H_
+#ifndef FLANG_RT_IO_API_COMMON_H_
+#define FLANG_RT_IO_API_COMMON_H_
 
-#include "io-stmt.h"
-#include "terminator.h"
 #include "unit.h"
+#include "flang-rt/io-stmt.h"
+#include "flang-rt/terminator.h"
 #include "flang/Common/api-attrs.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/io-api.h"
@@ -94,4 +94,4 @@ RT_API_ATTRS Cookie BeginExternalListIO(
 }
 
 } // namespace Fortran::runtime::io
-#endif // FLANG_RUNTIME_IO_API_COMMON_H_
+#endif /* FLANG_RT_IO_API_COMMON_H_ */
diff --git a/flang/runtime/io-api-minimal.cpp b/flang-rt/lib/flang_rt/io-api-minimal.cpp
similarity index 96%
rename from flang/runtime/io-api-minimal.cpp
rename to flang-rt/lib/flang_rt/io-api-minimal.cpp
index 68768427be0c23..c3234c78c10c80 100644
--- a/flang/runtime/io-api-minimal.cpp
+++ b/flang-rt/lib/flang_rt/io-api-minimal.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/io-api-minimal.cpp ----------------------------------------===//
+//===-- lib/flang_rt/io-api-minimal.cpp -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,12 +10,12 @@
 // list-directed output (PRINT *) of intrinsic types.
 
 #include "edit-output.h"
-#include "format.h"
 #include "io-api-common.h"
-#include "io-stmt.h"
-#include "terminator.h"
-#include "tools.h"
 #include "unit.h"
+#include "flang-rt/format.h"
+#include "flang-rt/io-stmt.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/io-api.h"
 
 namespace Fortran::runtime::io {
diff --git a/flang/runtime/io-api.cpp b/flang-rt/lib/flang_rt/io-api.cpp
similarity index 99%
rename from flang/runtime/io-api.cpp
rename to flang-rt/lib/flang_rt/io-api.cpp
index 7023f61ba34de7..ce1330ff323d49 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang-rt/lib/flang_rt/io-api.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/io-api.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/io-api.cpp ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -17,16 +17,16 @@
 #include "descriptor-io.h"
 #include "edit-input.h"
 #include "edit-output.h"
-#include "environment.h"
-#include "format.h"
 #include "io-api-common.h"
-#include "io-stmt.h"
-#include "terminator.h"
-#include "tools.h"
 #include "unit.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/format.h"
+#include "flang-rt/io-stmt.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/optional.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/memory.h"
 #include <cstdlib>
 #include <memory>
 
diff --git a/flang/runtime/io-error.cpp b/flang-rt/lib/flang_rt/io-error.cpp
similarity index 97%
rename from flang/runtime/io-error.cpp
rename to flang-rt/lib/flang_rt/io-error.cpp
index 37909e8e6dad2c..b356642c95f85f 100644
--- a/flang/runtime/io-error.cpp
+++ b/flang-rt/lib/flang_rt/io-error.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/io-error.cpp ----------------------------------------------===//
+//===-- lib/flang_rt/io-error.cpp -------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "io-error.h"
+#include "flang-rt/io-error.h"
 #include "config.h"
-#include "tools.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/magic-numbers.h"
 #include <cerrno>
 #include <cstdarg>
diff --git a/flang/runtime/io-stmt.cpp b/flang-rt/lib/flang_rt/io-stmt.cpp
similarity index 99%
rename from flang/runtime/io-stmt.cpp
rename to flang-rt/lib/flang_rt/io-stmt.cpp
index f24eb929ce748a..a07bf70a6593e1 100644
--- a/flang/runtime/io-stmt.cpp
+++ b/flang-rt/lib/flang_rt/io-stmt.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/io-stmt.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/io-stmt.cpp --------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "io-stmt.h"
-#include "connection.h"
-#include "emit-encoded.h"
-#include "format.h"
-#include "tools.h"
+#include "flang-rt/io-stmt.h"
 #include "unit.h"
-#include "utf.h"
-#include "flang/Runtime/memory.h"
+#include "flang-rt/connection.h"
+#include "flang-rt/emit-encoded.h"
+#include "flang-rt/format.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/utf.h"
 #include <algorithm>
 #include <cstdio>
 #include <cstring>
diff --git a/flang/runtime/iostat.cpp b/flang-rt/lib/flang_rt/iostat.cpp
similarity index 98%
rename from flang/runtime/iostat.cpp
rename to flang-rt/lib/flang_rt/iostat.cpp
index 39e224cb01286b..ab2fc63cf7b211 100644
--- a/flang/runtime/iostat.cpp
+++ b/flang-rt/lib/flang_rt/iostat.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/iostat.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/iostat.cpp ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/main.cpp b/flang-rt/lib/flang_rt/main.cpp
similarity index 90%
rename from flang/runtime/main.cpp
rename to flang-rt/lib/flang_rt/main.cpp
index 96454989581b71..dac7268f82b166 100644
--- a/flang/runtime/main.cpp
+++ b/flang-rt/lib/flang_rt/main.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/main.cpp --------------------------------------------------===//
+//===-- lib/flang_rt/main.cpp -----------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/main.h"
-#include "environment.h"
-#include "terminator.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/terminator.h"
 #include <cfenv>
 #include <cstdio>
 #include <cstdlib>
diff --git a/flang/runtime/matmul-transpose.cpp b/flang-rt/lib/flang_rt/matmul-transpose.cpp
similarity index 98%
rename from flang/runtime/matmul-transpose.cpp
rename to flang-rt/lib/flang_rt/matmul-transpose.cpp
index bafa05056bebc4..307995bb8ab1e7 100644
--- a/flang/runtime/matmul-transpose.cpp
+++ b/flang-rt/lib/flang_rt/matmul-transpose.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/matmul-transpose.cpp --------------------------------------===//
+//===-- lib/flang_rt/matmul-transpose.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -21,12 +21,12 @@
 // to use the faster BLAS routines.
 
 #include "flang/Runtime/matmul-transpose.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/c-or-cpp.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include <cstring>
 
 namespace {
diff --git a/flang/runtime/matmul.cpp b/flang-rt/lib/flang_rt/matmul.cpp
similarity index 99%
rename from flang/runtime/matmul.cpp
rename to flang-rt/lib/flang_rt/matmul.cpp
index f72601073a6007..c5036e24f86f4c 100644
--- a/flang/runtime/matmul.cpp
+++ b/flang-rt/lib/flang_rt/matmul.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/matmul.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/matmul.cpp ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -20,12 +20,12 @@
 // Places where BLAS routines could be called are marked as TODO items.
 
 #include "flang/Runtime/matmul.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/optional.h"
 #include "flang/Runtime/c-or-cpp.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include <cstring>
 
 namespace {
diff --git a/flang/runtime/memory.cpp b/flang-rt/lib/flang_rt/memory.cpp
similarity index 87%
rename from flang/runtime/memory.cpp
rename to flang-rt/lib/flang_rt/memory.cpp
index c7068ad6479a12..e09e45898da8e6 100644
--- a/flang/runtime/memory.cpp
+++ b/flang-rt/lib/flang_rt/memory.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/memory.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/memory.cpp ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/memory.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/freestanding-tools.h"
 #include <cstdlib>
 
diff --git a/flang/runtime/misc-intrinsic.cpp b/flang-rt/lib/flang_rt/misc-intrinsic.cpp
similarity index 96%
rename from flang/runtime/misc-intrinsic.cpp
rename to flang-rt/lib/flang_rt/misc-intrinsic.cpp
index f7d893829fc0d3..1a5bc8114e8aec 100644
--- a/flang/runtime/misc-intrinsic.cpp
+++ b/flang-rt/lib/flang_rt/misc-intrinsic.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/misc-intrinsic.cpp ----------------------------------------===//
+//===-- lib/flang_rt/misc-intrinsic.cpp -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/misc-intrinsic.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/optional.h"
-#include "flang/Runtime/descriptor.h"
 #include <algorithm>
 #include <cstdio>
 #include <cstring>
diff --git a/flang/runtime/namelist.cpp b/flang-rt/lib/flang_rt/namelist.cpp
similarity index 99%
rename from flang/runtime/namelist.cpp
rename to flang-rt/lib/flang_rt/namelist.cpp
index af092de70f7819..4cf1cd2062ac51 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang-rt/lib/flang_rt/namelist.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/namelist.cpp ----------------------------------------------===//
+//===-- lib/flang_rt/namelist.cpp -------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "namelist.h"
+#include "flang-rt/namelist.h"
 #include "descriptor-io.h"
-#include "emit-encoded.h"
-#include "io-stmt.h"
+#include "flang-rt/emit-encoded.h"
+#include "flang-rt/io-stmt.h"
 #include "flang/Runtime/io-api.h"
 #include <algorithm>
 #include <cstring>
diff --git a/flang/runtime/non-tbp-dio.cpp b/flang-rt/lib/flang_rt/non-tbp-dio.cpp
similarity index 87%
rename from flang/runtime/non-tbp-dio.cpp
rename to flang-rt/lib/flang_rt/non-tbp-dio.cpp
index 9419adb7631cc9..5663c2ee338d72 100644
--- a/flang/runtime/non-tbp-dio.cpp
+++ b/flang-rt/lib/flang_rt/non-tbp-dio.cpp
@@ -1,4 +1,4 @@
-//===-- flang/runtime/non-tbp-dio.cpp ---------------------------*- C++ -*-===//
+//===-- lib/flang_rt/non-tbp-dio.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "non-tbp-dio.h"
-#include "type-info.h"
+#include "flang-rt/non-tbp-dio.h"
+#include "flang-rt/type-info.h"
 
 namespace Fortran::runtime::io {
 
diff --git a/flang/runtime/numeric.cpp b/flang-rt/lib/flang_rt/numeric.cpp
similarity index 99%
rename from flang/runtime/numeric.cpp
rename to flang-rt/lib/flang_rt/numeric.cpp
index 45fb56348fd44f..b63c604cadcfb3 100644
--- a/flang/runtime/numeric.cpp
+++ b/flang-rt/lib/flang_rt/numeric.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/numeric.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/numeric.cpp --------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/numeric.h"
-#include "numeric-templates.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/numeric-templates.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/float128.h"
 #include <cfloat>
 #include <climits>
diff --git a/flang/runtime/pointer.cpp b/flang-rt/lib/flang_rt/pointer.cpp
similarity index 97%
rename from flang/runtime/pointer.cpp
rename to flang-rt/lib/flang_rt/pointer.cpp
index 2979181ddd61bd..3138a54f1d122e 100644
--- a/flang/runtime/pointer.cpp
+++ b/flang-rt/lib/flang_rt/pointer.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/pointer.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/pointer.cpp --------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/pointer.h"
-#include "assign-impl.h"
-#include "derived.h"
-#include "environment.h"
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "type-info.h"
+#include "flang-rt/assign-impl.h"
+#include "flang-rt/derived.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-info.h"
 
 namespace Fortran::runtime {
 extern "C" {
diff --git a/flang/runtime/product.cpp b/flang-rt/lib/flang_rt/product.cpp
similarity index 98%
rename from flang/runtime/product.cpp
rename to flang-rt/lib/flang_rt/product.cpp
index 293ffd301ba2ec..c7b6d23d3014e4 100644
--- a/flang/runtime/product.cpp
+++ b/flang-rt/lib/flang_rt/product.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/product.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/product.cpp --------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,7 +8,7 @@
 
 // Implements PRODUCT for all required operand types and shapes.
 
-#include "reduction-templates.h"
+#include "flang-rt/reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/reduction.h"
 #include <cfloat>
diff --git a/flang/runtime/pseudo-unit.cpp b/flang-rt/lib/flang_rt/pseudo-unit.cpp
similarity index 97%
rename from flang/runtime/pseudo-unit.cpp
rename to flang-rt/lib/flang_rt/pseudo-unit.cpp
index 526afd11d916e9..f4d204890581ec 100644
--- a/flang/runtime/pseudo-unit.cpp
+++ b/flang-rt/lib/flang_rt/pseudo-unit.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/pseudo-unit.cpp -------------------------------------------===//
+//===-- lib/flang_rt/pseudo-unit.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -11,9 +11,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "io-error.h"
-#include "tools.h"
 #include "unit.h"
+#include "flang-rt/io-error.h"
+#include "flang-rt/tools.h"
 
 // NOTE: the header files above may define OpenMP declare target
 // variables, so they have to be included unconditionally
diff --git a/flang/runtime/ragged.cpp b/flang-rt/lib/flang_rt/ragged.cpp
similarity index 96%
rename from flang/runtime/ragged.cpp
rename to flang-rt/lib/flang_rt/ragged.cpp
index a4d9e541ba5311..798b3464e7bcac 100644
--- a/flang/runtime/ragged.cpp
+++ b/flang-rt/lib/flang_rt/ragged.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/ragged.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/ragged.cpp ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/ragged.h"
-#include "tools.h"
+#include "flang-rt/tools.h"
 #include <cstdlib>
 
 namespace Fortran::runtime {
diff --git a/flang/runtime/random.cpp b/flang-rt/lib/flang_rt/random.cpp
similarity index 96%
rename from flang/runtime/random.cpp
rename to flang-rt/lib/flang_rt/random.cpp
index 8f158007a5a65a..76971cf3fc888e 100644
--- a/flang/runtime/random.cpp
+++ b/flang-rt/lib/flang_rt/random.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/random.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/random.cpp ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,14 +10,14 @@
 // RANDOM_SEED.
 
 #include "flang/Runtime/random.h"
-#include "lock.h"
-#include "random-templates.h"
-#include "terminator.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/lock.h"
+#include "flang-rt/random-templates.h"
+#include "flang-rt/terminator.h"
 #include "flang/Common/float128.h"
 #include "flang/Common/leading-zero-bit-count.h"
 #include "flang/Common/uint128.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include <cmath>
 #include <cstdint>
 #include <limits>
diff --git a/flang/runtime/reduce.cpp b/flang-rt/lib/flang_rt/reduce.cpp
similarity index 99%
rename from flang/runtime/reduce.cpp
rename to flang-rt/lib/flang_rt/reduce.cpp
index 6c42c5ef50e4f0..4bb6dc10ea9dac 100644
--- a/flang/runtime/reduce.cpp
+++ b/flang-rt/lib/flang_rt/reduce.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/reduce.cpp ------------------------------------------------===//
+//===-- lib/flang_rt/reduce.cpp ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,10 +9,10 @@
 // REDUCE() implementation
 
 #include "flang/Runtime/reduce.h"
-#include "reduction-templates.h"
-#include "terminator.h"
-#include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/reduction-templates.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/reduction.cpp b/flang-rt/lib/flang_rt/reduction.cpp
similarity index 99%
rename from flang/runtime/reduction.cpp
rename to flang-rt/lib/flang_rt/reduction.cpp
index a8fcde7b3a1664..9ceaeffc6541ae 100644
--- a/flang/runtime/reduction.cpp
+++ b/flang-rt/lib/flang_rt/reduction.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/reduction.cpp ---------------------------------------------===//
+//===-- lib/flang_rt/reduction.cpp ------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -14,8 +14,8 @@
 // NORM2, MAXLOC, MINLOC, MAXVAL, and MINVAL are in extrema.cpp.
 
 #include "flang/Runtime/reduction.h"
-#include "reduction-templates.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/reduction-templates.h"
 #include <cinttypes>
 
 namespace Fortran::runtime {
diff --git a/flang/runtime/stack.h b/flang-rt/lib/flang_rt/stack.h
similarity index 94%
rename from flang/runtime/stack.h
rename to flang-rt/lib/flang_rt/stack.h
index b6e6edb595e9ad..88cd276456fbc1 100644
--- a/flang/runtime/stack.h
+++ b/flang-rt/lib/flang_rt/stack.h
@@ -1,4 +1,4 @@
-//===-- runtime/stack.h -----------------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/stack.h ------------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,11 +10,11 @@
 // It is a list based stack with dynamic allocation/deallocation
 // of the list nodes.
 
-#ifndef FORTRAN_RUNTIME_STACK_H
-#define FORTRAN_RUNTIME_STACK_H
+#ifndef FLANG_RT_STACK_H_
+#define FLANG_RT_STACK_H_
 
-#include "terminator.h"
-#include "flang/Runtime/memory.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/terminator.h"
 
 namespace Fortran::runtime {
 // Storage for the Stack elements of type T.
@@ -133,4 +133,4 @@ template <typename T, unsigned N = 0> class Stack : public StackStorage<T, N> {
   Terminator &terminator_;
 };
 } // namespace Fortran::runtime
-#endif // FORTRAN_RUNTIME_STACK_H
+#endif /* FLANG_RT_STACK_H_ */
diff --git a/flang/runtime/stat.cpp b/flang-rt/lib/flang_rt/stat.cpp
similarity index 93%
rename from flang/runtime/stat.cpp
rename to flang-rt/lib/flang_rt/stat.cpp
index 525a4e36cdc773..883e85d0fbf2f6 100644
--- a/flang/runtime/stat.cpp
+++ b/flang-rt/lib/flang_rt/stat.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/stat.cpp --------------------------------------------------===//
+//===-- lib/flang_rt/stat.cpp -----------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "stat.h"
-#include "terminator.h"
-#include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/stat.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 
 namespace Fortran::runtime {
 RT_OFFLOAD_API_GROUP_BEGIN
diff --git a/flang/runtime/stop.cpp b/flang-rt/lib/flang_rt/stop.cpp
similarity index 96%
rename from flang/runtime/stop.cpp
rename to flang-rt/lib/flang_rt/stop.cpp
index a7be8a082e026b..68141383246c3a 100644
--- a/flang/runtime/stop.cpp
+++ b/flang-rt/lib/flang_rt/stop.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/stop.cpp --------------------------------------------------===//
+//===-- lib/flang_rt/stop.cpp -----------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,11 +8,11 @@
 
 #include "flang/Runtime/stop.h"
 #include "config.h"
-#include "environment.h"
-#include "file.h"
-#include "io-error.h"
-#include "terminator.h"
 #include "unit.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/file.h"
+#include "flang-rt/io-error.h"
+#include "flang-rt/terminator.h"
 #include <cfenv>
 #include <cstdio>
 #include <cstdlib>
diff --git a/flang/runtime/sum.cpp b/flang-rt/lib/flang_rt/sum.cpp
similarity index 98%
rename from flang/runtime/sum.cpp
rename to flang-rt/lib/flang_rt/sum.cpp
index 3cb7a2b2857790..fd98525b8c9b28 100644
--- a/flang/runtime/sum.cpp
+++ b/flang-rt/lib/flang_rt/sum.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/sum.cpp ---------------------------------------------------===//
+//===-- lib/flang_rt/sum.cpp ------------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -12,7 +12,7 @@
 // cancellation on intermediate results by using "Kahan summation"
 // (basically the same as manual "double-double").
 
-#include "reduction-templates.h"
+#include "flang-rt/reduction-templates.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/reduction.h"
 #include <cfloat>
diff --git a/flang/runtime/support.cpp b/flang-rt/lib/flang_rt/support.cpp
similarity index 90%
rename from flang/runtime/support.cpp
rename to flang-rt/lib/flang_rt/support.cpp
index a607120256d9d9..2673176bd81858 100644
--- a/flang/runtime/support.cpp
+++ b/flang-rt/lib/flang_rt/support.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/support.cpp -----------------------------------------------===//
+//===-- lib/flang_rt/support.cpp --------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,8 +8,8 @@
 
 #include "flang/Runtime/support.h"
 #include "ISO_Fortran_util.h"
-#include "type-info.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-info.h"
 
 namespace Fortran::runtime {
 extern "C" {
diff --git a/flang/runtime/temporary-stack.cpp b/flang-rt/lib/flang_rt/temporary-stack.cpp
similarity index 97%
rename from flang/runtime/temporary-stack.cpp
rename to flang-rt/lib/flang_rt/temporary-stack.cpp
index 93340266b1b44d..32ec4dacc872d1 100644
--- a/flang/runtime/temporary-stack.cpp
+++ b/flang-rt/lib/flang_rt/temporary-stack.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/temporary-stack.cpp ---------------------------------------===//
+//===-- lib/flang_rt/temporary-stack.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,11 +10,11 @@
 // temporaries. For use in HLFIR lowering.
 
 #include "flang/Runtime/temporary-stack.h"
-#include "terminator.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/terminator.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/assign.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/memory.h"
 
 namespace {
 
diff --git a/flang/runtime/terminator.cpp b/flang-rt/lib/flang_rt/terminator.cpp
similarity index 96%
rename from flang/runtime/terminator.cpp
rename to flang-rt/lib/flang_rt/terminator.cpp
index bab9edc64fa35b..0dfc08eb703709 100644
--- a/flang/runtime/terminator.cpp
+++ b/flang-rt/lib/flang_rt/terminator.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/terminate.cpp ---------------------------------------------===//
+//===-- lib/flang_rt/terminator.cpp -----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "terminator.h"
+#include "flang-rt/terminator.h"
 #include <cstdio>
 #include <cstdlib>
 
diff --git a/flang/runtime/time-intrinsic.cpp b/flang-rt/lib/flang_rt/time-intrinsic.cpp
similarity index 99%
rename from flang/runtime/time-intrinsic.cpp
rename to flang-rt/lib/flang_rt/time-intrinsic.cpp
index 942604a92aaad7..1929fccbd4cf38 100644
--- a/flang/runtime/time-intrinsic.cpp
+++ b/flang-rt/lib/flang_rt/time-intrinsic.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/time-intrinsic.cpp ----------------------------------------===//
+//===-- lib/flang_rt/time-intrinsic.cpp -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,10 +9,10 @@
 // Implements time-related intrinsic subroutines.
 
 #include "flang/Runtime/time-intrinsic.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include <algorithm>
 #include <cstdint>
 #include <cstdio>
diff --git a/flang/runtime/tools.cpp b/flang-rt/lib/flang_rt/tools.cpp
similarity index 98%
rename from flang/runtime/tools.cpp
rename to flang-rt/lib/flang_rt/tools.cpp
index 73d6c2cf7e1d2b..9b460f81ad5c21 100644
--- a/flang/runtime/tools.cpp
+++ b/flang-rt/lib/flang_rt/tools.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/tools.cpp -------------------------------------------------===//
+//===-- lib/flang_rt/tools.cpp ----------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "tools.h"
-#include "terminator.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/terminator.h"
 #include <algorithm>
 #include <cstdint>
 #include <cstdlib>
diff --git a/flang/runtime/transformational.cpp b/flang-rt/lib/flang_rt/transformational.cpp
similarity index 99%
rename from flang/runtime/transformational.cpp
rename to flang-rt/lib/flang_rt/transformational.cpp
index ab303bdef9b1d1..7453bf18323e9f 100644
--- a/flang/runtime/transformational.cpp
+++ b/flang-rt/lib/flang_rt/transformational.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/transformational.cpp --------------------------------------===//
+//===-- lib/flang_rt/transformational.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -18,10 +18,10 @@
 
 #include "flang/Runtime/transformational.h"
 #include "copy.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include "flang/Common/float128.h"
-#include "flang/Runtime/descriptor.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/type-code.cpp b/flang-rt/lib/flang_rt/type-code.cpp
similarity index 98%
rename from flang/runtime/type-code.cpp
rename to flang-rt/lib/flang_rt/type-code.cpp
index d6948983bfe9f3..432c7591520cbc 100644
--- a/flang/runtime/type-code.cpp
+++ b/flang-rt/lib/flang_rt/type-code.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/type-code.cpp ---------------------------------------------===//
+//===-- lib/flang_rt/type-code.cpp ------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime/type-code.h"
+#include "flang-rt/type-code.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/runtime/type-info.cpp b/flang-rt/lib/flang_rt/type-info.cpp
similarity index 98%
rename from flang/runtime/type-info.cpp
rename to flang-rt/lib/flang_rt/type-info.cpp
index d4daa72aee6a13..e1859e4864ca13 100644
--- a/flang/runtime/type-info.cpp
+++ b/flang-rt/lib/flang_rt/type-info.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/type-info.cpp ---------------------------------------------===//
+//===-- lib/flang_rt/type-info.cpp ------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "type-info.h"
-#include "terminator.h"
-#include "tools.h"
+#include "flang-rt/type-info.h"
+#include "flang-rt/terminator.h"
+#include "flang-rt/tools.h"
 #include <cstdio>
 
 namespace Fortran::runtime::typeInfo {
@@ -86,7 +86,7 @@ RT_API_ATTRS std::size_t Component::SizeInBytes(
   } else if (category() == TypeCategory::Derived) {
     const DerivedType *type{derivedType()};
     return Descriptor::SizeInBytes(
-        rank_, true, type ? type->LenParameters() : 0);
+         rank_, true, type ? type->LenParameters() : 0);
   } else {
     return Descriptor::SizeInBytes(rank_);
   }
diff --git a/flang/runtime/unit-map.cpp b/flang-rt/lib/flang_rt/unit-map.cpp
similarity index 97%
rename from flang/runtime/unit-map.cpp
rename to flang-rt/lib/flang_rt/unit-map.cpp
index 684a9b9e20b97a..0fda53ac071b27 100644
--- a/flang/runtime/unit-map.cpp
+++ b/flang-rt/lib/flang_rt/unit-map.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/unit-map.cpp ----------------------------------------------===//
+//===-- lib/flang_rt/unit-map.cpp -------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/runtime/unit-map.h b/flang-rt/lib/flang_rt/unit-map.h
similarity index 92%
rename from flang/runtime/unit-map.h
rename to flang-rt/lib/flang_rt/unit-map.h
index 6f1e01bb1e64ac..6f7eb692b970a7 100644
--- a/flang/runtime/unit-map.h
+++ b/flang-rt/lib/flang_rt/unit-map.h
@@ -1,4 +1,4 @@
-//===-- runtime/unit-map.h --------------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/unit-map.h ---------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,13 +9,13 @@
 // Maps Fortran unit numbers to their ExternalFileUnit instances.
 // A simple hash table with forward-linked chains per bucket.
 
-#ifndef FORTRAN_RUNTIME_UNIT_MAP_H_
-#define FORTRAN_RUNTIME_UNIT_MAP_H_
+#ifndef FLANG_RT_UNIT_MAP_H_
+#define FLANG_RT_UNIT_MAP_H_
 
-#include "lock.h"
 #include "unit.h"
+#include "flang-rt/lock.h"
+#include "flang-rt/memory.h"
 #include "flang/Common/fast-int-set.h"
-#include "flang/Runtime/memory.h"
 #include <cstdint>
 #include <cstdlib>
 
@@ -100,4 +100,4 @@ class UnitMap {
   int emergencyNewUnit_{maxNewUnits_}; // not recycled
 };
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_UNIT_MAP_H_
+#endif /* FLANG_RT_UNIT_MAP_H_ */
diff --git a/flang/runtime/unit.cpp b/flang-rt/lib/flang_rt/unit.cpp
similarity index 99%
rename from flang/runtime/unit.cpp
rename to flang-rt/lib/flang_rt/unit.cpp
index 4aee8397d477e7..f05c4b5236dd57 100644
--- a/flang/runtime/unit.cpp
+++ b/flang-rt/lib/flang_rt/unit.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/unit.cpp --------------------------------------------------===//
+//===-- lib/flang_rt/unit.cpp -----------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -11,9 +11,9 @@
 //
 //===----------------------------------------------------------------------===//
 #include "unit.h"
-#include "io-error.h"
-#include "lock.h"
-#include "tools.h"
+#include "flang-rt/io-error.h"
+#include "flang-rt/lock.h"
+#include "flang-rt/tools.h"
 #include <limits>
 #include <utility>
 
diff --git a/flang/runtime/unit.h b/flang-rt/lib/flang_rt/unit.h
similarity index 96%
rename from flang/runtime/unit.h
rename to flang-rt/lib/flang_rt/unit.h
index a3ea2686816803..3b20c9870897ac 100644
--- a/flang/runtime/unit.h
+++ b/flang-rt/lib/flang_rt/unit.h
@@ -1,4 +1,4 @@
-//===-- runtime/unit.h ------------------------------------------*- C++ -*-===//
+//===-- lib/flang_rt/unit.h -------------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,21 +8,21 @@
 
 // Fortran external I/O units
 
-#ifndef FORTRAN_RUNTIME_IO_UNIT_H_
-#define FORTRAN_RUNTIME_IO_UNIT_H_
-
-#include "buffer.h"
-#include "connection.h"
-#include "environment.h"
-#include "file.h"
-#include "format.h"
-#include "io-error.h"
-#include "io-stmt.h"
-#include "lock.h"
-#include "terminator.h"
+#ifndef FLANG_RT_UNIT_H_
+#define FLANG_RT_UNIT_H_
+
+#include "flang-rt/buffer.h"
+#include "flang-rt/connection.h"
+#include "flang-rt/environment.h"
+#include "flang-rt/file.h"
+#include "flang-rt/format.h"
+#include "flang-rt/io-error.h"
+#include "flang-rt/io-stmt.h"
+#include "flang-rt/lock.h"
+#include "flang-rt/memory.h"
+#include "flang-rt/terminator.h"
 #include "flang/Common/constexpr-bitset.h"
 #include "flang/Common/optional.h"
-#include "flang/Runtime/memory.h"
 #include <cstdlib>
 #include <cstring>
 #include <flang/Common/variant.h>
@@ -291,4 +291,4 @@ class ChildIo {
 };
 
 } // namespace Fortran::runtime::io
-#endif // FORTRAN_RUNTIME_IO_UNIT_H_
+#endif /* FLANG_RT_UNIT_H_ */
diff --git a/flang/runtime/utf.cpp b/flang-rt/lib/flang_rt/utf.cpp
similarity index 97%
rename from flang/runtime/utf.cpp
rename to flang-rt/lib/flang_rt/utf.cpp
index b09819cb2f736b..dd74889c025c5c 100644
--- a/flang/runtime/utf.cpp
+++ b/flang-rt/lib/flang_rt/utf.cpp
@@ -1,4 +1,4 @@
-//===-- runtime/utf.cpp ---------------------------------------------------===//
+//===-- lib/flang_rt/utf.cpp ------------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "utf.h"
+#include "flang-rt/utf.h"
 
 namespace Fortran::runtime {
 
diff --git a/flang/test/Driver/ctofortran.f90 b/flang-rt/test/Driver/ctofortran.f90
similarity index 100%
rename from flang/test/Driver/ctofortran.f90
rename to flang-rt/test/Driver/ctofortran.f90
diff --git a/flang/test/Driver/exec.f90 b/flang-rt/test/Driver/exec.f90
similarity index 100%
rename from flang/test/Driver/exec.f90
rename to flang-rt/test/Driver/exec.f90
diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang-rt/test/Runtime/no-cpp-dep.c
similarity index 100%
rename from flang/test/Runtime/no-cpp-dep.c
rename to flang-rt/test/Runtime/no-cpp-dep.c
diff --git a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp b/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp
similarity index 98%
rename from flang/unittests/Evaluate/ISO-Fortran-binding.cpp
rename to flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp
index 2884686b3f26ef..d1417b715e959c 100644
--- a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp
+++ b/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp
@@ -1,5 +1,13 @@
+//===-- unittests/Evaluate/ISO-Fortran-binding.cpp --------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang-rt/descriptor.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Testing/testing.h"
 #include "llvm/Support/raw_ostream.h"
 #include <type_traits>
diff --git a/flang/unittests/Evaluate/reshape.cpp b/flang-rt/unittests/Evaluate/reshape.cpp
similarity index 88%
rename from flang/unittests/Evaluate/reshape.cpp
rename to flang-rt/unittests/Evaluate/reshape.cpp
index 16cba15dcef608..a45e06ad0f69d1 100644
--- a/flang/unittests/Evaluate/reshape.cpp
+++ b/flang-rt/unittests/Evaluate/reshape.cpp
@@ -1,4 +1,12 @@
-#include "flang/Runtime/descriptor.h"
+//===-- unittests/Evaluate/reshape.cpp --------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/transformational.h"
 #include "flang/Testing/testing.h"
 #include <cinttypes>
diff --git a/flang/unittests/Runtime/AccessTest.cpp b/flang-rt/unittests/Runtime/AccessTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/AccessTest.cpp
rename to flang-rt/unittests/Runtime/AccessTest.cpp
index c2a2d7d398220c..d431d0d19bd615 100644
--- a/flang/unittests/Runtime/AccessTest.cpp
+++ b/flang-rt/unittests/Runtime/AccessTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/AccessTest.cpp ----------------------------===//
+//===-- unittests/Runtime/AccessTest.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/unittests/Runtime/Allocatable.cpp b/flang-rt/unittests/Runtime/Allocatable.cpp
similarity index 97%
rename from flang/unittests/Runtime/Allocatable.cpp
rename to flang-rt/unittests/Runtime/Allocatable.cpp
index f15f26bfd9c575..b03003a93fe09a 100644
--- a/flang/unittests/Runtime/Allocatable.cpp
+++ b/flang-rt/unittests/Runtime/Allocatable.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Allocatable.cpp--------- ---------*- C++-*-===//
+//===-- unittests/Runtime/Allocatable.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,7 +8,7 @@
 
 #include "flang/Runtime/allocatable.h"
 #include "gtest/gtest.h"
-#include "tools.h"
+#include "flang-rt/tools.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang/unittests/Runtime/ArrayConstructor.cpp b/flang-rt/unittests/Runtime/ArrayConstructor.cpp
similarity index 97%
rename from flang/unittests/Runtime/ArrayConstructor.cpp
rename to flang-rt/unittests/Runtime/ArrayConstructor.cpp
index 53774a0eea07d6..5c84cd162a2931 100644
--- a/flang/unittests/Runtime/ArrayConstructor.cpp
+++ b/flang-rt/unittests/Runtime/ArrayConstructor.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/ArrayConstructor.cpp-------------*- C++ -*-===//
+//===-- unittests/Runtime/ArrayConstructor.cpp ------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "gtest/gtest.h"
 #include "tools.h"
+#include "gtest/gtest.h"
+#include "flang-rt/array-constructor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "flang/Runtime/allocatable.h"
-#include "flang/Runtime/array-constructor.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
 
 #include <memory>
 
diff --git a/flang/unittests/Runtime/BufferTest.cpp b/flang-rt/unittests/Runtime/BufferTest.cpp
similarity index 97%
rename from flang/unittests/Runtime/BufferTest.cpp
rename to flang-rt/unittests/Runtime/BufferTest.cpp
index 0632324b25d22e..7795a79593eb2c 100644
--- a/flang/unittests/Runtime/BufferTest.cpp
+++ b/flang-rt/unittests/Runtime/BufferTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/BufferTest.cpp ------------------*- C++ -*-===//
+//===-- unittests/Runtime/BufferTest.cpp ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "../../runtime/buffer.h"
+#include "flang-rt/buffer.h"
 #include "CrashHandlerFixture.h"
 #include "gtest/gtest.h"
 #include <algorithm>
diff --git a/flang/unittests/Runtime/CUDA/Allocatable.cpp b/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp
similarity index 89%
rename from flang/unittests/Runtime/CUDA/Allocatable.cpp
rename to flang-rt/unittests/Runtime/CUDA/Allocatable.cpp
index bdfa8f5cc3213c..db6589990be184 100644
--- a/flang/unittests/Runtime/CUDA/Allocatable.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Allocatable.cpp ------------------*- C++-*-===//
+//===-- unittests/Runtime/CUDA/Allocatable.cpp ------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,16 +7,16 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/allocatable.h"
+#include "cuda_runtime.h"
 #include "gtest/gtest.h"
-#include "../../../runtime/terminator.h"
-#include "flang/Runtime/CUDA/allocator.h"
+#include "flang-rt/CUDA/allocator.h"
+#include "flang-rt/allocator-registry.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
-#include "flang/Runtime/allocator-registry.h"
 #include "flang/Support/Fortran.h"
 
-#include "cuda_runtime.h"
-
 using namespace Fortran::runtime;
 using namespace Fortran::runtime::cuda;
 
diff --git a/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
similarity index 91%
rename from flang/unittests/Runtime/CUDA/AllocatorCUF.cpp
rename to flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
index 5ec122e4c5777f..86c13d0dd290c2 100644
--- a/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/AllocatableCUF.cpp ---------------*- C++-*-===//
+//===-- unittests/Runtime/CUDA/AllocatorCUF.cpp -----------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,16 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "cuda_runtime.h"
 #include "gtest/gtest.h"
-#include "../../../runtime/terminator.h"
-#include "flang/Runtime/CUDA/allocator.h"
+#include "flang-rt/CUDA/allocator.h"
+#include "flang-rt/allocator-registry.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/allocatable.h"
-#include "flang/Runtime/allocator-registry.h"
 #include "flang/Support/Fortran.h"
 
-#include "cuda_runtime.h"
-
 using namespace Fortran::runtime;
 using namespace Fortran::runtime::cuda;
 
diff --git a/flang/unittests/Runtime/CUDA/Memory.cpp b/flang-rt/unittests/Runtime/CUDA/Memory.cpp
similarity index 92%
rename from flang/unittests/Runtime/CUDA/Memory.cpp
rename to flang-rt/unittests/Runtime/CUDA/Memory.cpp
index 61c9d1131ee567..32609795c01699 100644
--- a/flang/unittests/Runtime/CUDA/Memory.cpp
+++ b/flang-rt/unittests/Runtime/CUDA/Memory.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Memory.cpp -----------------------*- C++-*-===//
+//===-- unittests/Runtime/CUDA/Memory.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,18 +7,17 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/CUDA/memory.h"
-#include "gtest/gtest.h"
-#include "../../../runtime/terminator.h"
+#include "cuda_runtime.h"
 #include "../tools.h"
-#include "flang/Runtime/CUDA/allocator.h"
+#include "gtest/gtest.h"
+#include "flang-rt/CUDA/allocator.h"
+#include "flang-rt/allocator-registry.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/CUDA/common.h"
 #include "flang/Runtime/CUDA/descriptor.h"
 #include "flang/Runtime/allocatable.h"
-#include "flang/Runtime/allocator-registry.h"
 #include "flang/Support/Fortran.h"
 
-#include "cuda_runtime.h"
-
 using namespace Fortran::runtime;
 using namespace Fortran::runtime::cuda;
 
diff --git a/flang/unittests/Runtime/CharacterTest.cpp b/flang-rt/unittests/Runtime/CharacterTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/CharacterTest.cpp
rename to flang-rt/unittests/Runtime/CharacterTest.cpp
index d462c9120fd8c7..696ab6b06e9e72 100644
--- a/flang/unittests/Runtime/CharacterTest.cpp
+++ b/flang-rt/unittests/Runtime/CharacterTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/CharacterTest.cpp ---------------*- C++ -*-===//
+//===-- unittests/Runtime/CharacterTest.cpp ---------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -11,7 +11,7 @@
 
 #include "flang/Runtime/character.h"
 #include "gtest/gtest.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include <cstring>
 #include <functional>
 #include <tuple>
diff --git a/flang/unittests/Runtime/CommandTest.cpp b/flang-rt/unittests/Runtime/CommandTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/CommandTest.cpp
rename to flang-rt/unittests/Runtime/CommandTest.cpp
index ecb325330f1ad1..a34c329750f39e 100644
--- a/flang/unittests/Runtime/CommandTest.cpp
+++ b/flang-rt/unittests/Runtime/CommandTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/CommandTest.cpp ---------------------------===//
+//===-- unittests/Runtime/CommandTest.cpp -----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,7 +9,7 @@
 #include "flang/Runtime/command.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/execute.h"
 #include "flang/Runtime/extensions.h"
 #include "flang/Runtime/main.h"
diff --git a/flang/unittests/Runtime/Complex.cpp b/flang-rt/unittests/Runtime/Complex.cpp
similarity index 98%
rename from flang/unittests/Runtime/Complex.cpp
rename to flang-rt/unittests/Runtime/Complex.cpp
index d714da24dc4e58..d7e5f55414fe2b 100644
--- a/flang/unittests/Runtime/Complex.cpp
+++ b/flang-rt/unittests/Runtime/Complex.cpp
@@ -1,10 +1,11 @@
-//===-- flang/unittests/Runtime/Complex.cpp ---------------------*- C++ -*-===//
+//===-- unittests/Runtime/Complex.cpp ---------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+
 #include "gmock/gmock.h"
 #include "gtest/gtest-matchers.h"
 #include <limits>
diff --git a/flang/unittests/Runtime/CrashHandlerFixture.cpp b/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp
similarity index 92%
rename from flang/unittests/Runtime/CrashHandlerFixture.cpp
rename to flang-rt/unittests/Runtime/CrashHandlerFixture.cpp
index 811603337e6608..939cc62c433f09 100644
--- a/flang/unittests/Runtime/CrashHandlerFixture.cpp
+++ b/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp
@@ -1,12 +1,13 @@
-//===-- flang/unittests/Runtime/CrashHandlerFixture.cpp ---------*- C++ -*-===//
+//===-- unittests/Runtime/CrashHandlerFixture.cpp ---------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+
 #include "CrashHandlerFixture.h"
-#include "../../runtime/terminator.h"
+#include "flang-rt/terminator.h"
 #include <cstdarg>
 #include <cstdlib>
 
diff --git a/flang/unittests/Runtime/CrashHandlerFixture.h b/flang-rt/unittests/Runtime/CrashHandlerFixture.h
similarity index 70%
rename from flang/unittests/Runtime/CrashHandlerFixture.h
rename to flang-rt/unittests/Runtime/CrashHandlerFixture.h
index fe0ee0da5204e4..74531d1e728f4e 100644
--- a/flang/unittests/Runtime/CrashHandlerFixture.h
+++ b/flang-rt/unittests/Runtime/CrashHandlerFixture.h
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/CrashHandlerFixture.h -----------*- C++ -*-===//
+//===-- unittests/Runtime/CrashHandlerFixture.h -----------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,12 +10,13 @@
 /// with expected message.
 //
 //===----------------------------------------------------------------------===//
-#ifndef LLVM_FLANG_UNITTESTS_RUNTIMEGTEST_CRASHHANDLERFIXTURE_H
-#define LLVM_FLANG_UNITTESTS_RUNTIMEGTEST_CRASHHANDLERFIXTURE_H
+
+#ifndef FLANG_RT_UNITTESTS_RUNTIME_CRASHHANDLERFIXTURE_H_
+#define FLANG_RT_UNITTESTS_RUNTIME_CRASHHANDLERFIXTURE_H_
 #include <gtest/gtest.h>
 
 struct CrashHandlerFixture : testing::Test {
   void SetUp();
 };
 
-#endif
+#endif /* FLANG_RT_UNITTESTS_RUNTIME_CRASHHANDLERFIXTURE_H_ */
diff --git a/flang/unittests/Runtime/Derived.cpp b/flang-rt/unittests/Runtime/Derived.cpp
similarity index 94%
rename from flang/unittests/Runtime/Derived.cpp
rename to flang-rt/unittests/Runtime/Derived.cpp
index 019d5e8309e4a0..2f45dfb80f7fd4 100644
--- a/flang/unittests/Runtime/Derived.cpp
+++ b/flang-rt/unittests/Runtime/Derived.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Pointer.cpp--------- -------------*- C++-*-===//
+//===-- unittests/Runtime/Derived.cpp ---------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "gtest/gtest.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/tools.h"
 #include "flang/Runtime/derived-api.h"
-#include "flang/Runtime/descriptor.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang/unittests/Runtime/ExternalIOTest.cpp b/flang-rt/unittests/Runtime/ExternalIOTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/ExternalIOTest.cpp
rename to flang-rt/unittests/Runtime/ExternalIOTest.cpp
index b9407b5e7a591e..a5481e071916d3 100644
--- a/flang/unittests/Runtime/ExternalIOTest.cpp
+++ b/flang-rt/unittests/Runtime/ExternalIOTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/RuntimeGTest/ExternalIOTest.cpp ---------*- C++ -*-===//
+//===-- unittests/Runtime/ExternalIOTest.cpp --------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -12,7 +12,7 @@
 
 #include "CrashHandlerFixture.h"
 #include "gtest/gtest.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/io-api-consts.h"
 #include "flang/Runtime/main.h"
 #include "flang/Runtime/stop.h"
diff --git a/flang/unittests/Runtime/Format.cpp b/flang-rt/unittests/Runtime/Format.cpp
similarity index 96%
rename from flang/unittests/Runtime/Format.cpp
rename to flang-rt/unittests/Runtime/Format.cpp
index 01803c628de26a..83650e0f999ac1 100644
--- a/flang/unittests/Runtime/Format.cpp
+++ b/flang-rt/unittests/Runtime/Format.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Format.cpp ----------------------*- C++ -*-===//
+//===-- unittests/Runtime/Format.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "../runtime/connection.h"
-#include "../runtime/format-implementation.h"
-#include "../runtime/io-error.h"
+#include "flang-rt/connection.h"
+#include "flang-rt/format-implementation.h"
+#include "flang-rt/io-error.h"
 #include <optional>
 #include <string>
 #include <tuple>
diff --git a/flang/unittests/Runtime/Inquiry.cpp b/flang-rt/unittests/Runtime/Inquiry.cpp
similarity index 98%
rename from flang/unittests/Runtime/Inquiry.cpp
rename to flang-rt/unittests/Runtime/Inquiry.cpp
index 3b523e992a3179..f6097484bd4815 100644
--- a/flang/unittests/Runtime/Inquiry.cpp
+++ b/flang-rt/unittests/Runtime/Inquiry.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Inquiry.cpp -------------------------------===//
+//===-- unittests/Runtime/Inquiry.cpp ---------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/inquiry.h"
-#include "gtest/gtest.h"
 #include "tools.h"
-#include "flang/Runtime/type-code.h"
+#include "gtest/gtest.h"
+#include "flang-rt/type-code.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang/unittests/Runtime/ListInputTest.cpp b/flang-rt/unittests/Runtime/ListInputTest.cpp
similarity index 98%
rename from flang/unittests/Runtime/ListInputTest.cpp
rename to flang-rt/unittests/Runtime/ListInputTest.cpp
index 38c758b7ef9662..0c6c59d6a325e5 100644
--- a/flang/unittests/Runtime/ListInputTest.cpp
+++ b/flang-rt/unittests/Runtime/ListInputTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/ListInputTest.cpp ---------------*- C++ -*-===//
+//===-- unittests/Runtime/ListInputTest.cpp ---------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "../../runtime/io-error.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/io-error.h"
 #include "flang/Runtime/io-api-consts.h"
 
 using namespace Fortran::runtime;
diff --git a/flang/unittests/Runtime/LogicalFormatTest.cpp b/flang-rt/unittests/Runtime/LogicalFormatTest.cpp
similarity index 95%
rename from flang/unittests/Runtime/LogicalFormatTest.cpp
rename to flang-rt/unittests/Runtime/LogicalFormatTest.cpp
index 26c9374be13389..07f62ee02fc66d 100644
--- a/flang/unittests/Runtime/LogicalFormatTest.cpp
+++ b/flang-rt/unittests/Runtime/LogicalFormatTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/LogicalFormatTest.cpp -----------*- C++ -*-===//
+//===-- unittests/Runtime/LogicalFormatTest.cpp -----------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/io-api-consts.h"
 #include <algorithm>
 #include <array>
diff --git a/flang/unittests/Runtime/Matmul.cpp b/flang-rt/unittests/Runtime/Matmul.cpp
similarity index 98%
rename from flang/unittests/Runtime/Matmul.cpp
rename to flang-rt/unittests/Runtime/Matmul.cpp
index c3fed9b972df2a..28bf2327da949e 100644
--- a/flang/unittests/Runtime/Matmul.cpp
+++ b/flang-rt/unittests/Runtime/Matmul.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Matmul.cpp--------- -------------*- C++ -*-===//
+//===-- unittests/Runtime/Matmul.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/matmul.h"
-#include "gtest/gtest.h"
 #include "tools.h"
+#include "gtest/gtest.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang/unittests/Runtime/MatmulTranspose.cpp b/flang-rt/unittests/Runtime/MatmulTranspose.cpp
similarity index 98%
rename from flang/unittests/Runtime/MatmulTranspose.cpp
rename to flang-rt/unittests/Runtime/MatmulTranspose.cpp
index c582e945dc7c93..b06afa29ce28ef 100644
--- a/flang/unittests/Runtime/MatmulTranspose.cpp
+++ b/flang-rt/unittests/Runtime/MatmulTranspose.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/MatmulTranspose.cpp -------------*- C++ -*-===//
+//===-- unittests/Runtime/MatmulTranspose.cpp -------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "gtest/gtest.h"
 #include "tools.h"
+#include "gtest/gtest.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/matmul-transpose.h"
-#include "flang/Runtime/type-code.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang/unittests/Runtime/MiscIntrinsic.cpp b/flang-rt/unittests/Runtime/MiscIntrinsic.cpp
similarity index 96%
rename from flang/unittests/Runtime/MiscIntrinsic.cpp
rename to flang-rt/unittests/Runtime/MiscIntrinsic.cpp
index 7e19ed250bdc05..61b05b31f45a90 100644
--- a/flang/unittests/Runtime/MiscIntrinsic.cpp
+++ b/flang-rt/unittests/Runtime/MiscIntrinsic.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/MiscIntrinsic.cpp ---------------*- C++ -*-===//
+//===-- unittests/Runtime/MiscIntrinsic.cpp ---------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,12 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "gtest/gtest.h"
 #include "tools.h"
-#include "flang/Runtime//misc-intrinsic.h"
+#include "gtest/gtest.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/misc-intrinsic.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang/unittests/Runtime/Namelist.cpp b/flang-rt/unittests/Runtime/Namelist.cpp
similarity index 99%
rename from flang/unittests/Runtime/Namelist.cpp
rename to flang-rt/unittests/Runtime/Namelist.cpp
index 0a28f3590b86ed..d48a0273bf556f 100644
--- a/flang/unittests/Runtime/Namelist.cpp
+++ b/flang-rt/unittests/Runtime/Namelist.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Namelist.cpp --------------------*- C++ -*-===//
+//===-- unittests/Runtime/Namelist.cpp --------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "../../runtime/namelist.h"
+#include "flang-rt/namelist.h"
 #include "CrashHandlerFixture.h"
 #include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/io-api-consts.h"
 #include <algorithm>
 #include <cinttypes>
diff --git a/flang/unittests/Runtime/Numeric.cpp b/flang-rt/unittests/Runtime/Numeric.cpp
similarity index 99%
rename from flang/unittests/Runtime/Numeric.cpp
rename to flang-rt/unittests/Runtime/Numeric.cpp
index 29ebbc8ad7aa70..4baad3fc9ad0eb 100644
--- a/flang/unittests/Runtime/Numeric.cpp
+++ b/flang-rt/unittests/Runtime/Numeric.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Numeric.cpp ---------------------*- C++ -*-===//
+//===-- unittests/Runtime/Numeric.cpp ---------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/unittests/Runtime/NumericalFormatTest.cpp b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
similarity index 99%
rename from flang/unittests/Runtime/NumericalFormatTest.cpp
rename to flang-rt/unittests/Runtime/NumericalFormatTest.cpp
index 274498b8e86951..a86e6b807fc53f 100644
--- a/flang/unittests/Runtime/NumericalFormatTest.cpp
+++ b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/NumericalFormatTest.cpp ---------*- C++ -*-===//
+//===-- unittests/Runtime/NumericalFormatTest.cpp ---------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "CrashHandlerFixture.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
 #include "flang/Runtime/io-api-consts.h"
 #include <algorithm>
 #include <array>
diff --git a/flang/unittests/Runtime/Pointer.cpp b/flang-rt/unittests/Runtime/Pointer.cpp
similarity index 96%
rename from flang/unittests/Runtime/Pointer.cpp
rename to flang-rt/unittests/Runtime/Pointer.cpp
index 4ce13ebc50a565..13f1922e6c5c3f 100644
--- a/flang/unittests/Runtime/Pointer.cpp
+++ b/flang-rt/unittests/Runtime/Pointer.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Pointer.cpp--------- -------------*- C++-*-===//
+//===-- unittests/Runtime/Pointer.cpp ---------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,8 +8,8 @@
 
 #include "flang/Runtime/pointer.h"
 #include "gtest/gtest.h"
-#include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/tools.h"
 
 using namespace Fortran::runtime;
 
diff --git a/flang/unittests/Runtime/Ragged.cpp b/flang-rt/unittests/Runtime/Ragged.cpp
similarity index 94%
rename from flang/unittests/Runtime/Ragged.cpp
rename to flang-rt/unittests/Runtime/Ragged.cpp
index 5049bc83405f17..feadd032f59bd4 100644
--- a/flang/unittests/Runtime/Ragged.cpp
+++ b/flang-rt/unittests/Runtime/Ragged.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Ragged.cpp ----------------------*- C++ -*-===//
+//===-- unittests/Runtime/Ragged.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/unittests/Runtime/Random.cpp b/flang-rt/unittests/Runtime/Random.cpp
similarity index 92%
rename from flang/unittests/Runtime/Random.cpp
rename to flang-rt/unittests/Runtime/Random.cpp
index cb739b94514290..dba480cffa9c95 100644
--- a/flang/unittests/Runtime/Random.cpp
+++ b/flang-rt/unittests/Runtime/Random.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Random.cpp ----------------------*- C++ -*-===//
+//===-- unittests/Runtime/Random.cpp ----------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "flang/Runtime//random.h"
+#include "flang/Runtime/random.h"
 #include "gtest/gtest.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include <cmath>
 
 using namespace Fortran::runtime;
diff --git a/flang/unittests/Runtime/Reduction.cpp b/flang-rt/unittests/Runtime/Reduction.cpp
similarity index 99%
rename from flang/unittests/Runtime/Reduction.cpp
rename to flang-rt/unittests/Runtime/Reduction.cpp
index 29675399abf5c1..cb84512639933f 100644
--- a/flang/unittests/Runtime/Reduction.cpp
+++ b/flang-rt/unittests/Runtime/Reduction.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Reductions.cpp ----------------------------===//
+//===-- unittests/Runtime/Reduction.cpp -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,14 +7,14 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/reduction.h"
-#include "gtest/gtest.h"
 #include "tools.h"
+#include "gtest/gtest.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "flang/Common/float128.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/reduce.h"
-#include "flang/Runtime/type-code.h"
 #include <cstdint>
 #include <cstring>
 #include <string>
diff --git a/flang/unittests/Runtime/RuntimeCrashTest.cpp b/flang-rt/unittests/Runtime/RuntimeCrashTest.cpp
similarity index 98%
rename from flang/unittests/Runtime/RuntimeCrashTest.cpp
rename to flang-rt/unittests/Runtime/RuntimeCrashTest.cpp
index 72a0b290cf8643..23a60d98bf6ade 100644
--- a/flang/unittests/Runtime/RuntimeCrashTest.cpp
+++ b/flang-rt/unittests/Runtime/RuntimeCrashTest.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/CrashHandlerFixture.cpp ---------*- C++ -*-===//
+//===-- unittests/Runtime/RuntimeCrashTest.cpp ------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -12,7 +12,7 @@
 //===----------------------------------------------------------------------===//
 #include "CrashHandlerFixture.h"
 #include "tools.h"
-#include "../../runtime/terminator.h"
+#include "flang-rt/terminator.h"
 #include "flang/Runtime/io-api-consts.h"
 #include "flang/Runtime/transformational.h"
 #include <gtest/gtest.h>
diff --git a/flang/unittests/Runtime/Stop.cpp b/flang-rt/unittests/Runtime/Stop.cpp
similarity index 96%
rename from flang/unittests/Runtime/Stop.cpp
rename to flang-rt/unittests/Runtime/Stop.cpp
index b13602eaee5ea6..102fecd1afb22d 100644
--- a/flang/unittests/Runtime/Stop.cpp
+++ b/flang-rt/unittests/Runtime/Stop.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Stop.cpp ----------------------------------===//
+//===-- unittests/Runtime/Stop.cpp ------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,9 +9,10 @@
 /// Test runtime API for STOP statement and runtime API to kill the program.
 //
 //===----------------------------------------------------------------------===//
+
 #include "flang/Runtime/stop.h"
 #include "CrashHandlerFixture.h"
-#include "../../runtime/environment.h"
+#include "flang-rt/environment.h"
 #include <cstdlib>
 #include <gtest/gtest.h>
 
diff --git a/flang/unittests/Runtime/Support.cpp b/flang-rt/unittests/Runtime/Support.cpp
similarity index 96%
rename from flang/unittests/Runtime/Support.cpp
rename to flang-rt/unittests/Runtime/Support.cpp
index 8c8de73b5b9798..0159bd74aa60cc 100644
--- a/flang/unittests/Runtime/Support.cpp
+++ b/flang-rt/unittests/Runtime/Support.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Support.cpp ----------------------*- C++-*-===//
+//===-- unittests/Runtime/Support.cpp ---------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/support.h"
-#include "gtest/gtest.h"
 #include "tools.h"
-#include "flang/Runtime/descriptor.h"
+#include "gtest/gtest.h"
+#include "flang-rt/descriptor.h"
 
 using namespace Fortran::runtime;
 using Fortran::common::TypeCategory;
diff --git a/flang/unittests/Runtime/TemporaryStack.cpp b/flang-rt/unittests/Runtime/TemporaryStack.cpp
similarity index 98%
rename from flang/unittests/Runtime/TemporaryStack.cpp
rename to flang-rt/unittests/Runtime/TemporaryStack.cpp
index 4f701e09b29452..d5cb9e5bfb9da1 100644
--- a/flang/unittests/Runtime/TemporaryStack.cpp
+++ b/flang-rt/unittests/Runtime/TemporaryStack.cpp
@@ -1,4 +1,4 @@
-//===--- flang/unittests/Runtime/TemporaryStack.cpp -------------*- C++ -*-===//
+//===-- unittests/Runtime/TemporaryStack.cpp --------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "gtest/gtest.h"
-#include "tools.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/tools.h"
+#include "flang-rt/type-code.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/temporary-stack.h"
-#include "flang/Runtime/type-code.h"
 #include <vector>
 
 using namespace Fortran::runtime;
diff --git a/flang/unittests/Runtime/Time.cpp b/flang-rt/unittests/Runtime/Time.cpp
similarity index 98%
rename from flang/unittests/Runtime/Time.cpp
rename to flang-rt/unittests/Runtime/Time.cpp
index 9309d7b1ceffa0..548c0834e34a36 100644
--- a/flang/unittests/Runtime/Time.cpp
+++ b/flang-rt/unittests/Runtime/Time.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Time.cpp ----------------------------===//
+//===-- unittests/Runtime/Time.cpp ------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/flang/unittests/Runtime/Transformational.cpp b/flang-rt/unittests/Runtime/Transformational.cpp
similarity index 99%
rename from flang/unittests/Runtime/Transformational.cpp
rename to flang-rt/unittests/Runtime/Transformational.cpp
index 1d84b7e23779a7..8805613738a609 100644
--- a/flang/unittests/Runtime/Transformational.cpp
+++ b/flang-rt/unittests/Runtime/Transformational.cpp
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/Transformational.cpp ----------------------===//
+//===-- unittests/Runtime/Transformational.cpp ------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,10 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Runtime/transformational.h"
-#include "gtest/gtest.h"
 #include "tools.h"
+#include "gtest/gtest.h"
+#include "flang-rt/type-code.h"
 #include "flang/Common/float128.h"
-#include "flang/Runtime/type-code.h"
 #include <vector>
 
 using namespace Fortran::runtime;
diff --git a/flang/unittests/Runtime/tools.h b/flang-rt/unittests/Runtime/tools.h
similarity index 85%
rename from flang/unittests/Runtime/tools.h
rename to flang-rt/unittests/Runtime/tools.h
index 0347edace5c05c..ff39d7ccb2a244 100644
--- a/flang/unittests/Runtime/tools.h
+++ b/flang-rt/unittests/Runtime/tools.h
@@ -1,4 +1,4 @@
-//===-- flang/unittests/Runtime/tools.h -------------------------*- C++ -*-===//
+//===-- unittests/Runtime/tools.h -------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
-#define FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
+#ifndef FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_
+#define FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_
 
 #include "gtest/gtest.h"
+#include "flang-rt/descriptor.h"
+#include "flang-rt/type-code.h"
 #include "flang/Runtime/allocatable.h"
 #include "flang/Runtime/cpp-type.h"
-#include "flang/Runtime/descriptor.h"
-#include "flang/Runtime/type-code.h"
 #include <cstdint>
 #include <cstring>
 #include <vector>
@@ -54,4 +54,4 @@ static OwningPtr<Descriptor> MakeArray(const std::vector<int> &shape,
 }
 
 } // namespace Fortran::runtime
-#endif // FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_
+#endif /* FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_ */
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 8a8b8bfa73b007..0044779da011d7 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -23,6 +23,7 @@ if (LLVM_ENABLE_EH)
 endif()
 
 set(FLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(FLANG_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../flang-rt")
 
 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE)
   message(FATAL_ERROR "In-source builds are not allowed. \
diff --git a/flang/include/flang/Runtime/allocatable.h b/flang/include/flang/Runtime/allocatable.h
index 58061d9862095e..714d85ec073c60 100644
--- a/flang/include/flang/Runtime/allocatable.h
+++ b/flang/include/flang/Runtime/allocatable.h
@@ -11,7 +11,7 @@
 #ifndef FORTRAN_RUNTIME_ALLOCATABLE_H_
 #define FORTRAN_RUNTIME_ALLOCATABLE_H_
 
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
 
 namespace Fortran::runtime {
diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h
index abcdbc4a12002c..acd7bc5ddbdef3 100644
--- a/flang/include/flang/Runtime/descriptor-consts.h
+++ b/flang/include/flang/Runtime/descriptor-consts.h
@@ -9,6 +9,7 @@
 #ifndef FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_
 #define FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_
 
+#include "flang/Common/Fortran-consts.h"
 #include "flang/Common/ISO_Fortran_binding_wrapper.h"
 #include "flang/Common/api-attrs.h"
 #include <cstddef>
@@ -29,6 +30,7 @@ class DerivedType;
 namespace Fortran::runtime {
 class Descriptor;
 using SubscriptValue = ISO::CFI_index_t;
+using common::TypeCategory;
 
 /// Returns size in bytes of the descriptor (not the data)
 /// This must be at least as large as the largest descriptor of any target
diff --git a/flang/include/flang/Runtime/pointer.h b/flang/include/flang/Runtime/pointer.h
index 704144f08114f2..67c4fe266f55cf 100644
--- a/flang/include/flang/Runtime/pointer.h
+++ b/flang/include/flang/Runtime/pointer.h
@@ -12,7 +12,7 @@
 #ifndef FORTRAN_RUNTIME_POINTER_H_
 #define FORTRAN_RUNTIME_POINTER_H_
 
-#include "flang/Runtime/descriptor.h"
+#include "flang/Runtime/descriptor-consts.h"
 #include "flang/Runtime/entry-names.h"
 
 namespace Fortran::runtime {
diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index 3e32daba52a818..2bdcfca4cba857 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -16,6 +16,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   set(CMAKE_CXX_EXTENSIONS OFF)
 
   set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
+  set(FLANG_RT_SOURCE_DIR "${FLANG_SOURCE_DIR}/../flang-rt")
 
   set(LLVM_COMMON_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../cmake")
   set(LLVM_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../llvm/cmake")
@@ -57,8 +58,31 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
     REAL(16) is mapped to __float128, or libm for targets where REAL(16) \
     is mapped to long double, etc."
     )
+
+  option(FLANG_CUF_RUNTIME
+    "Compile CUDA Fortran runtime sources" OFF)
+  if (FLANG_CUF_RUNTIME)
+    find_package(CUDAToolkit REQUIRED)
+  endif()
 endif()
 
+# Runtime files are in Flang-RT's source dir.
+function (runtime_source_files outvar)
+  cmake_parse_arguments(ARG "" "SUBDIR" "" ${ARGN})
+
+  set(new_sources "")
+  foreach (source IN LISTS "${outvar}")
+    set(new_source "${FLANG_RT_SOURCE_DIR}/lib/flang_rt")
+    cmake_path(APPEND new_source "${ARG_SUBDIR}")
+    cmake_path(APPEND new_source "${source}")
+    list(APPEND new_sources "${new_source}")
+  endforeach ()
+  set("${outvar}" ${new_sources} PARENT_SCOPE)
+endfunction ()
+
+# Runtime includes are in Flang-RT's source dir.
+include_directories(BEFORE "${FLANG_RT_SOURCE_DIR}/include")
+
 # function checks
 find_package(Backtrace)
 set(HAVE_BACKTRACE ${Backtrace_FOUND})
@@ -94,7 +118,7 @@ else()
   set(NO_LTO_FLAGS "")
 endif()
 
-configure_file(config.h.cmake config.h)
+configure_file("${FLANG_RT_SOURCE_DIR}/cmake/config.h.cmake.in" config.h)
 # include_directories is used here instead of target_include_directories
 # because add_flang_library creates multiple objects (STATIC/SHARED, OBJECT)
 # with different names
@@ -236,6 +260,7 @@ set(supported_files
   utf.cpp
   )
 
+runtime_source_files(supported_files)
 enable_cuda_compilation(flang_rt "${supported_files}")
 enable_omp_offload_compilation("${supported_files}")
 
@@ -269,6 +294,9 @@ if (NOT TARGET FortranFloat128Math)
   endif()
 endif()
 
+runtime_source_files(sources)
+
+
 if (NOT DEFINED MSVC)
   add_flang_library(flang_rt
     ${sources}
diff --git a/flang/runtime/CUDA/CMakeLists.txt b/flang/runtime/CUDA/CMakeLists.txt
index 744df95267e6fc..86a76658042ebb 100644
--- a/flang/runtime/CUDA/CMakeLists.txt
+++ b/flang/runtime/CUDA/CMakeLists.txt
@@ -13,7 +13,7 @@ include_directories(${CUDAToolkit_INCLUDE_DIRS})
 # added to the library name.
 set(CUFRT_LIBNAME CufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR})
 
-add_flang_library(${CUFRT_LIBNAME}
+set(sources
   allocator.cpp
   allocatable.cpp
   descriptor.cpp
@@ -22,6 +22,11 @@ add_flang_library(${CUFRT_LIBNAME}
   memory.cpp
   registration.cpp
 )
+runtime_source_files(sources SUBDIR "CUDA")
+
+add_flang_library(${CUFRT_LIBNAME}
+  ${sources}
+)
 
 if (BUILD_SHARED_LIBS)
   set(CUDA_RT_TARGET CUDA::cudart)
diff --git a/flang/runtime/Float128Math/CMakeLists.txt b/flang/runtime/Float128Math/CMakeLists.txt
index d65193be05ab5c..2cd7e46c80407d 100644
--- a/flang/runtime/Float128Math/CMakeLists.txt
+++ b/flang/runtime/Float128Math/CMakeLists.txt
@@ -17,56 +17,56 @@
 include(CheckLibraryExists)
 
 set(sources
-  acos.cpp
-  acosh.cpp
-  asin.cpp
-  asinh.cpp
-  atan.cpp
-  atan2.cpp
-  atanh.cpp
-  ceil.cpp
-  complex-math.c
-  cos.cpp
-  cosh.cpp
-  erf.cpp
-  erfc.cpp
-  exp.cpp
-  exponent.cpp
-  floor.cpp
-  fma.cpp
-  fraction.cpp
-  hypot.cpp
-  j0.cpp
-  j1.cpp
-  jn.cpp
-  lgamma.cpp
-  llround.cpp
-  log.cpp
-  log10.cpp
-  lround.cpp
-  mod-real.cpp
-  modulo-real.cpp
-  nearest.cpp
-  nearbyint.cpp
-  norm2.cpp
-  pow.cpp
-  random.cpp
-  remainder.cpp
-  round.cpp
-  rrspacing.cpp
-  scale.cpp
-  set-exponent.cpp
-  sin.cpp
-  sinh.cpp
-  spacing.cpp
-  sqrt.cpp
-  tan.cpp
-  tanh.cpp
-  tgamma.cpp
-  trunc.cpp
-  y0.cpp
-  y1.cpp
-  yn.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/acos.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/acosh.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/asin.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/asinh.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/atan.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/atan2.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/atanh.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/ceil.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/complex-math.c
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/cos.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/cosh.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/erf.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/erfc.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/exp.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/exponent.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/floor.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/fma.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/fraction.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/hypot.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/j0.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/j1.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/jn.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/lgamma.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/llround.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/log.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/log10.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/lround.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/mod-real.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/modulo-real.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/nearest.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/nearbyint.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/norm2.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/pow.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/random.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/remainder.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/round.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/rrspacing.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/scale.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/set-exponent.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/sin.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/sinh.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/spacing.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/sqrt.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/tan.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/tanh.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/tgamma.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/trunc.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/y0.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/y1.cpp
+  ${FLANG_RT_SOURCE_DIR}/lib/FortranFloat128Math/yn.cpp
   )
 
 include_directories(AFTER "${CMAKE_CURRENT_SOURCE_DIR}/..")
diff --git a/flang/runtime/config.h.cmake b/flang/runtime/config.h.cmake
deleted file mode 100644
index a2271be77b8c68..00000000000000
--- a/flang/runtime/config.h.cmake
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef FORTRAN_RUNTIME_CONFIG_H
-#define FORTRAN_RUNTIME_CONFIG_H
-
-/* Define to 1 if you have the `strerror_r' function. */
-#cmakedefine01 HAVE_STRERROR_R
-
-/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you
-   don't. */
-#cmakedefine01 HAVE_DECL_STRERROR_S
-
-/* Define to 1 if you have the `backtrace' function. */
-#cmakedefine HAVE_BACKTRACE ${HAVE_BACKTRACE}
-
-#define BACKTRACE_HEADER <${BACKTRACE_HEADER}>
-
-#endif
diff --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt
index 7b0f85638f14e4..b946d39fad54b0 100644
--- a/flang/unittests/CMakeLists.txt
+++ b/flang/unittests/CMakeLists.txt
@@ -12,6 +12,8 @@ endif()
 add_custom_target(FlangUnitTests)
 set_target_properties(FlangUnitTests PROPERTIES FOLDER "Flang/Tests")
 
+include_directories("${FLANG_RT_SOURCE_DIR}/include")
+
 function(add_flang_unittest_offload_properties target)
   # Do not apply runtime properties if not even compiling the runtime.
   if (NOT FLANG_INCLUDE_RUNTIME)
@@ -61,7 +63,13 @@ function(add_flang_nongtest_unittest test_name)
       set(suffix .test)
   endif()
 
-  add_executable(${test_name}${suffix} ${test_name}.cpp)
+  # Sources for runtime tests are in Flang-RT.
+  set(test_filepath "${FLANG_RT_SOURCE_DIR}/unittests/Evaluate/${test_name}.cpp")
+  if (NOT EXISTS "${test_filepath}")
+    set(test_filepath "${test_name}.cpp")
+  endif ()
+
+  add_executable(${test_name}${suffix} "${test_filepath}")
   set_target_properties(${test_name}${suffix} PROPERTIES FOLDER "Flang/Tests/Unit")
 
   if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
diff --git a/flang/unittests/Runtime/CMakeLists.txt b/flang/unittests/Runtime/CMakeLists.txt
index a60b43d422878d..2e873914027442 100644
--- a/flang/unittests/Runtime/CMakeLists.txt
+++ b/flang/unittests/Runtime/CMakeLists.txt
@@ -1,34 +1,34 @@
 add_flang_unittest(FlangRuntimeTests
-  AccessTest.cpp
-  Allocatable.cpp
-  ArrayConstructor.cpp
-  BufferTest.cpp
-  CharacterTest.cpp
-  CommandTest.cpp
-  Complex.cpp
-  CrashHandlerFixture.cpp
-  Derived.cpp
-  ExternalIOTest.cpp
-  Format.cpp
-  Inquiry.cpp
-  ListInputTest.cpp
-  LogicalFormatTest.cpp
-  Matmul.cpp
-  MatmulTranspose.cpp
-  MiscIntrinsic.cpp
-  Namelist.cpp
-  Numeric.cpp
-  NumericalFormatTest.cpp
-  Pointer.cpp
-  Ragged.cpp
-  Random.cpp
-  Reduction.cpp
-  RuntimeCrashTest.cpp
-  Stop.cpp
-  Support.cpp
-  Time.cpp
-  TemporaryStack.cpp
-  Transformational.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/AccessTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Allocatable.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/ArrayConstructor.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/BufferTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CharacterTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CommandTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Complex.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CrashHandlerFixture.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Derived.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/ExternalIOTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Format.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Inquiry.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/ListInputTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/LogicalFormatTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Matmul.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/MatmulTranspose.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/MiscIntrinsic.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Namelist.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Numeric.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/NumericalFormatTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Pointer.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Ragged.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Random.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Reduction.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/RuntimeCrashTest.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Stop.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Support.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Time.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/TemporaryStack.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Transformational.cpp
 )
 
 target_link_libraries(FlangRuntimeTests
diff --git a/flang/unittests/Runtime/CUDA/CMakeLists.txt b/flang/unittests/Runtime/CUDA/CMakeLists.txt
index 38888e32e6ed8a..762df4b4601077 100644
--- a/flang/unittests/Runtime/CUDA/CMakeLists.txt
+++ b/flang/unittests/Runtime/CUDA/CMakeLists.txt
@@ -1,9 +1,9 @@
 if (FLANG_CUF_RUNTIME)
 
 add_flang_unittest(FlangCufRuntimeTests
-  Allocatable.cpp
-  AllocatorCUF.cpp
-  Memory.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CUDA/Allocatable.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CUDA/AllocatorCUF.cpp
+  ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CUDA/Memory.cpp
 )
 
 if (BUILD_SHARED_LIBS)



More information about the llvm-branch-commits mailing list