To: J3 J3/21-193 From: Mark LeAir Subject: Flang Liaison Report Date: 2021-October-19 Flang Open Source Fortran Report ================================ Flang is an open source compiler for Fortran, sponsored by the US Department of Energy Exascale Computing Project (particularly, LLNL, Sandia and LANL). The goals of the project are to - Create a new, open source Fortran 2018 compiler with Apache 2.0 licensing, - that can be used for language and parallelization experimentation, - that exists as a peer in the LLVM community of languages, like Clang, - that can rely on LLVM code generation and parallelism support for CPUs and GPUs. There is a Slack workspace for Flang and a number of conference calls related to Flang development. - Flang biweekly sync call ("umbrella call") - Flang biweekly technical call - "Classic Flang" biweekly call - OpenMP in Flang Technical Call Details can be found on the Getting Involved page http://flang.llvm.org/docs/GettingInvolved.html. The New LLVM Flang Compiler --------------------------- The new front-end is available at https://github.com/llvm/llvm-project (the LLVM monorepo) in the flang/ directory. As of LLVM 12, it will be a full-fledged member of the LLVM projects. LLVM Flang is being developed under the Apache 2.0 license with LLVM exceptions (the same as LLVM, Clang, OpenMP, etc.). Recent efforts have concentrated on - upstreaming the lowering code from the 'fir-dev' branch to LLVM 'main' - adding Fortran 95 semantics - adding intrinsics, including folding and runtime support - OpenMP semantics and runtime - fixing issues identified from test cases Flang Front-End Work that has been completed between July 1, 2021 and September 30, 2021: - Implementation of runtime support for Fortran 95 and later features, including assignment to derived types, finalization, and intrinsic procedures. - Implemented support for a "-E" option to emit what looks like traditional preprocessed output (rather than just a dump of the fully cooked input to the parser). This work has been merged to the LLVM project branch. Flang Lowering work that has been completed between July 1, 2021 and September 30, 2021: Note: Lowering is the translation of Fortran syntax into the semantic-based Fortran IR (FIR) and then into LLVM IR. - Lowering of default initialization (both static and dynamic). - Derived type assignments (Implemented case with an array on left hand side, or where one of the components is allocatable, or requires user defined assignment. The simple scalar case was previously done.). - Elemental calls (Lowered character arguments, character results and elemental subroutine calls, the rest was previously done). - F77 Function and variable naming interoperability with other Fortran programs. F18 compiled binaries now can link with binaries compiled by other Fortran compilers, for interfaces defined with F77 features. - Lowering of IO input statement containing input items with vector subscripts. The current state of the LLVM Flang compiler is - written in modern C++ following LLVM conventions - over 200,000 lines of code, tests and scripts - parses all of Fortran 2018 to abstract syntax trees (AST) - parses OpenMP 4.5 and some OpenMP 5.0 - parses OpenACC 3.0 - defines a "Fortran Intermediate Representation" (FIR) based on LLVM's MLIR - can lower most OpenMP and OpenACC constructs - can compile and correctly run Fortran 77 programs (passes FCVS test suite) Upcoming work: - The plan is to finish Fortran 95 feature implementation in Q4 of this year. - Fortran 95 Features that are mostly complete include lowering of internal procedures, FORALL and WHERE statements. - Fortran 95 Features that are actively being worked on include user defined assignments and CHARACTER lowering in array contexts. - As the project gets closer to wrapping up Fortran 95 feature work, the plan is to spend more time and resources in the upstreaming of code from fir-dev to the LLVM project branch. - After the Fortran 95 work is wrapped up, the plan is to begin the lowering of Fortran 2003 language features. Current ("Classic") Flang Compiler ---------------------------------- The initial version of Flang, now known as Classic Flang, is derived from the PGI Fortran compiler, with some proprietary features removed (e.g., OpenACC support, inter-procedure analysis). It is the basis of the Arm and AMD commercial Fortran compilers. Recent development on Classic Flang include - Adding support for LLVM 12.0 and LLVM 13.0. - Adding Quad-precision FP support. - Adding use of new LLVM metadata (e.g., LLVM loop access) - Adding support for Windows and MacOS. Classic Flang is available for Linux on x86-64, OpenPOWER and Arm processors, and is the basis of the Arm and AMD commercial Fortran compilers. Huawei has made significant contributions as well. Detailed status can be found in the biweekly call Google doc //docs.google.com/document/d/1-OuiKx4d7O6eLEJDBDKSRnSiUO2rgRR-c2Ga4AkrzOI