To: J3 J3/23-123 From: Mark LeAir Subject: Flang Liaison Report Date: 2023-February-17 Flang Open Source Fortran Report ================================ Flang is an open-source compiler for Fortran. It is an official subproject of the LLVM Project (llvm.org). NVIDIA's portion of the work was partially sponsored by the US Department of Energy Exascale Computing Project (particularly, LLNL, Sandia and LANL). The current goals of the project are to - Create an open source Fortran compiler with LLVM 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. LLVM Flang is being developed under the LLVM license with LLVM exceptions (the same as LLVM, Clang, OpenMP, etc.). Flang Work that has been completed in Q4 (i.e., between October 1, 2022 and December 31, 2022): During Q4, the Flang Community implemented support for submodules and made considerable progress updating expression lowering, adding support for polymorphic entities, and adding support for the Block construct. * Updating Expression Lowering - Adding Higher Level FIR (HLFIR) ops to ease expression lowering. - HLFIR improves integration with MLIR (Multi-Level Intermediate Representation). Ensures MLIR passes, like inlining, cannot break the variable representation in HLFIR. * Polymorphic Entities - The Flang Community implemented the following features for polymorphic entities in Q4: + Representation of polymorphic and unlimited polymorphic entity types + Pointer assignment involving polymorphic entities + Assignment involving polymorphic entities + Dynamic dispatch + Allocation of polymorphic entities + Select type construct. + Emboxing/reboxing of polymorphic entities + Fir.dispatch_table and fir.dt_entry lowering * Block and Submodules - The Flang Community added support for Submodules in Flang on 12/13/2022. - Implementation of the Block construct began in Q4. Work will continue into Q1 2023. Upcoming work for Q1 2023 (i.e., between January 1, 2023 and March 31, 2023): * Polymorphic Entities - Lowering and runtime function for same_type_as - Lowering and runtime function for extends_type_of - Lowering and runtime function for storage_size - Finalization of polymorphic entities (derived-type finalization is not implemented yet) - Optimization such as devirtualization of dispatch calls - Allocation with MOLD/SOURCE (missing for all entity types). * Block Construct - Add name mangling for block-level global names - Add support for deallocation and finalization of block entities - Add support for deallocation and finalization for early exits. * OpenMP - Work has started on target offload and other target data constructs. - Continue to test Flang's OpenMP implementation with open-source OpenMP test suites, Spec-2017 speed, Spec OMP 2012, and Spec HPC test suites. Testing in Q4 (i.e., between October 1, 2022 and December 31, 2022): During Q4, NVIDIA increased the number of tests they run nightly from approximately 17,500 to 25,600. Almost 70% of these tests are from the Numerical Algorithms Group (NAG) proprietary test suite. The increase in tests run this quarter comes as a result of incorporating NAG tests of compile-time errors and the GNU Fortran regression test suite. There are about 2400 tests in the NAG suite that involve polymorphic entities. Of these, approximately 910 tests pass, and the rest are a work in progress. Summary The current state of the LLVM Flang compiler: - 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 analyze most OpenMP and OpenACC constructs - can compile and correctly run Fortran 77 programs (passes FCVS test suite), nearly all Fortran 95 programs, and some programs that use Fortran 2003+ modern features. - supports end-to-end compilation of all OpenMP 1.1 except for reduction, privatization, and one atomic construct. - for later versions of OpenMP, Flang has support for simd, task, taskgroup etc. Current ("Classic") Flang Compiler ---------------------------------- The previous 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 for commercial Fortran compilers from Arm, AMD, and Huawei. Classic Flang is available for Linux on x86-64, OpenPOWER, and Arm processors. OpenPower support is not currently being maintained but it is still available. The Classic Flang Community recently added a Platform-independent python build script for Classic Flang, fixes for COMMON Blocks and derived types, support for opaque pointers in the LLVM IR generated by Classic Flang (which is the default with LLVM-16), more support for quad-precision, support for LLVM-15, and a compiler flag (msve-vector-bits) to specify vector length in VLA architectures. Moreover, the Classic Flang Community has made progress with supporting Classic Flang on Windows. Detailed status can be found in the biweekly call Google doc at: docs.google.com/document/d/1-OuiKx4d7O6eLEJDBDKSRnSiUO2rgRR-c2Ga4AkrzOI