Factory.ai

Open-Source Wikis

/

LLVM

/

Subprojects

/

flang-rt

llvm/llvm-project

flang-rt

flang-rt/ is the runtime support library for code compiled by Flang. It implements the bits of Fortran semantics that can't be reduced to inline machine code: I/O, allocatable and pointer descriptor management, intrinsic procedures with non-trivial implementations, OpenMP runtime entry points, and similar functionality.

Purpose

A Fortran program lowered through Flang's pipeline ends up calling into flang-rt for any operation whose implementation is large enough or sufficiently runtime-state-dependent that inlining it would bloat every callsite. Examples include READ/WRITE against formatted/unformatted units, ALLOCATE/DEALLOCATE with shape and bounds tracking, derived-type assignment, transformational intrinsics like RESHAPE and MATMUL, and the runtime descriptors that back assumed-shape arrays.

History

The Flang runtime originally lived inside flang/ as flang/runtime/. It was carved out into its own top-level subproject (flang-rt/) so it could be built like other LLVM runtime libraries — through LLVM_ENABLE_RUNTIMES rather than LLVM_ENABLE_PROJECTS, with the option of cross-compiling for offload targets. See flang-rt/README.md for the rationale and the migration plan.

Directory layout

flang-rt/
├── include/flang-rt/   # Public headers (descriptor types, runtime-side interface)
├── lib/                # Implementation — IO, allocations, intrinsics, exceptions, ...
├── unittests/
├── test/               # lit regression tests (driven against built artifacts)
├── cmake/
├── docs/
├── examples/
└── README.md

What it implements

A non-exhaustive list of what flang-rt provides at runtime:

  • Descriptors — the C structures that back allocatable, pointer, and assumed-shape arrays. The same shape descriptors are exposed at the C / BIND(C) interop boundary.
  • I/OREAD, WRITE, OPEN, CLOSE, INQUIRE, list-directed/formatted/unformatted/namelist transfers, recursive I/O, asynchronous I/O.
  • Memory and lifetimeALLOCATE, DEALLOCATE, MOVE_ALLOC, automatic cleanup at scope exit, finalization of derived types.
  • Intrinsics that don't inlineRESHAPE, TRANSFER, MATMUL, DOT_PRODUCT, SUM, MINVAL/MAXVAL, PACK/UNPACK, SPREAD, EOSHIFT/CSHIFT, character-handling intrinsics.
  • Exception flags / IEEE features — environment for IEEE-arithmetic state.
  • Stop / error handlingSTOP, ERROR STOP, image control statements.

Integration points

  • Flang lowers calls into flang-rt via well-defined symbol names (_FortranA*, _FortranAio*, ...). The naming convention is documented inside flang-rt/include/flang-rt/ and flang/include/flang/Runtime/.
  • MLIR / FIR lowering inserts the runtime calls at lowering time; FIR ops have direct counterparts that emit the right runtime entry points.
  • OpenMP / Offload runtimes (openmp, offload) cooperate with flang-rt for offloaded Fortran code.

Entry points for modification

Reference

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

flang-rt – LLVM wiki | Factory