Skip to content

Task 1 - libTooling for Flang with basic functionality to support Fortran

No due date 0% complete

This task begins the process of developing functionality for modern Fortran similar to that provided for C and
modern C++ in SALT. While LLVM Flang has been under development in its current form only since 2019, it is
still relatively immature but it has been making fast progress. In comparison, Clang has been under continuous
development since its first …

This task begins the process of developing functionality for modern Fortran similar to that provided for C and
modern C++ in SALT. While LLVM Flang has been under development in its current form only since 2019, it is
still relatively immature but it has been making fast progress. In comparison, Clang has been under continuous
development since its first release more than 15 years ago.
Clang has a component called libTooling,18 which provides support for writing Clang-based standalone tools.
The library enables such tools to have an interface that is identical to that provided by the actual Clang compiler
and handles command-line processing and exposes an API for access to the Clang Abstract Syntax Tree. One
of the limitations we will face in developing a Fortran instrumentor is that Flang currently has no equivalent to
Clang’s libTooling.19
A prototype, minimal libTooling for Flang will be created to demonstrate the feasibility of of developing a full
libTooling-like system for Flang. Communications will be established with the Flang developers through the
Flang mailing lists, Slack, and bi-weekly conference call to ensure that there is no duplication of efforts and that
our efforts are in line with LLVM/Flang policies and design specifications.
A challenge we will face in developing the Fortran instrumentor is that, in addition to lacking an equivalent to
libTooling, the design of the Flang front end does not include an Abstract Syntax Tree at all.20 Instead, the
Flang front-end provides direct access to the parse tree, a concrete syntax tree that represents the Fortran gram-
mar precisely without any additional layer of abstraction. This is then lowered directly to a custom intermediate
language, Flang Intermediate Representation (FIR), which is then lowered to MLIR and then finally to LLVM IR.
Additionally, the development of the lowering stages is still under intense development.
During any follow-on Phase II efforts, this “libTooling for Flang” library will be extended to more robustly support
the generic instrumentation use cases, and other other program transformations such as wrapper generation and
code translation. In addition, the feasibility of creating a simplified API onto the Flang parse tree would be explored
during Phase II. Functionality relating to this will be abstracted from—and factored out of—the libTooling for
Flang library and the instrumentor application, to be put into a dedicated library component. The ultimate goal
is contributing the libTooling for Flang library component back upstream to LLVM, which will help ensure it’s
continued maintenance and development.

Loading