To: J3 J3/24-175r2 From: Mark LeAir Subject: Flang Liaison Report Date: 2024-October-24 #Reference: 24-135 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 LLVM Fortran compiler is available at https://github.com/llvm/llvm-project (the LLVM monorepo) in the flang/ directory. LLVM Flang is being developed under the Apache 2.0 license with LLVM exceptions (the same as LLVM, Clang, OpenMP, etc.). New features added between 16-June-2024 and 10-October-2024: - Added support for more intrinsics: IEEE_NEXT_AFTER, IEEE_NEXT_DOWN, IEEE_NEXT_UP, NEAREST, IEEE_RINT, IEEE_INT as well as INT2 and INT8 extensions. - New semantic checks and warnings were added: Catch impure calls in nested concurrent-headers. Catch attempts to subscribe empty arrays. Finer error detection in separate module procedure case. Warn about impure calls in concurrent headers. Warn on useless IOMSG=. Catch structure constructor in its own type definition. Disallow references to some IEEE procedures in DO CONCURRENT. Warn about automatic data in main program, disallow in BLOCK. Detect use-before-decl errors on type parameters. Warn about undefined function results. Check assignment conformance for derived types. Catch untyped entities in interfaces with IMPLICIT NONE. - Assumed-rank lowering has been enabled by default after most features were implemented for it, and more semantics checks added. One TODO remains for RANK(*) of polymorphic assumed rank selector in SELECT-RANK. - Added a new "-fhermetic-module-files" option to bundle module files of a program into a single module file. - Handle BOZ as right-hand side of assignment as now allowed by F2023 C7119. Improvements to existing features added between 16-June-2024 and 10-October-2024: - Improved preprocessor to handle Fortran INCLUDE statement like other compilers (not expanded with -E, and no macro expansion inside such included files). Better handling of directives in line continuation, handling of #line before free-form continuation, mix preprocessing directives with free form line continuation, handle initial "MACRO&" with no space, ] Accept a compiler directive sentinel after a semicolon, expand some keyword macros in quoted character. - Added support for procedure pointers and dummy procedures in REDUCE. - The IEEE_SUPPORT intrinsics are now handled in constant expressions. - Added runtime support for SPACING of REAL KIND 2 and 3 (f16, bf16). - Relaxed more errors to warning after analysis: Accept missing commas in edit descriptor. Accept passing implicit procedures as dummy arguments even when they require an explicit interface. Accept combining generic containing subroutine with a derived type of the same name via use association. Accept initialized SAVE local in specification expression. - Improved warning and error messages: Improve warnings for invalid arguments when folding host runtime. Better error reporting for MOD/MODULO/NEAREST. Better parser errors for misplaced declarations, bad subroutine/function statements, and for bad statements after CONTAINS. Improve error messages about overflowed integer conversions. - Improved runtime checks: Interoperable POINTER deallocation validation. Better handling of "fort.N" opening errors. - Implemented IO extensions: Accept some real input for integer NAMELIST. Accept '\n' as space in internal list-directed input. - Make flang generated assembly names more portable (avoiding dots). - It is now possible to disable the support for some type KINDs inside the driver. - Lowering CUDA Fortran extensions to FIR has made progress. The lowering from FIR to LLVM still does not allow end-to-end compilation. - Minor updates of OpenACC Lowering to FIR. - It is possible to override CFI_MAX_RANK macro from ISO_Fortran_binding.h. - IGNORE_TKR extension directive is now accepted on a separate module procedure. - Various NFCs (avoiding recursions in the runtime code, update error messages, typo fixes in comments, refactoring, documentation update, build fixes, new and deleted FIR operations, reverts). - Intrinsic extensions ~ Implement GETUID and GETGID intrinsic extension. ~ Add MALLOC and FREE intrinsic extension for Cray pointers. ~ Implement SECOND intrinsic extension. ~ Implement getenv intrinsic extension as alternate spelling for get_environment_variable. New OpenMP features added between 16-June-2024 and 19-October-2024: - Added version checks for OpenMP clauses. - Added support for Masked construct and deprecate Master construct. - Added support for proc_bind=primary. - Implemented copyin for pointers and allocatables. - Command line support ~ Added support for -fno-openmp. ~ Added support for -fopenmp-targets. - Partial support (Work in Progress) ~ Added lowering support for DISTRIBUTE SIMD. ~ Added lowering support for DO SIMD. ~ DISTRIBUTE PARALLEL DO SIMD lowering. ~ Lowering nontemporal clause to MLIR for SIMD directive. Improvements to existing OpenMP features added between 16-June-2024 and 19-October-2024: - Restrict certain loops not allowed in associated loops. - Improvements for Atomic ~ Added support Complex types in atomic instructions. ~ Added Semantic Checks for Atomic Capture Construct. - Improvements to privatization ~ Introduce delayed privatization for parallel, target and distribute constructs. ~ Improved nested privatization of allocatable. ~ Improved do concurrent index. ~ Improved lastprivate with collapse, allocatables, reallocated variable, on simd construct. ~ Improved privatizing loop index marked shared. ~ Added support lastprivate modifiers. ~ Don't privatize associate names. ~ Prohibit privatization of variables in stmt functions. ~ Added support privatization of global values. ~ Don't privatize loop index marked shared. - Improvements in reduction ~ Don't reduce variables in namelist. ~ Reduction support for sections. - Improvements in mapping ~ Parsing support for map type. ~ Improved dynamic-extent array mapping. Improvements to Debug support added between 16-June-2024 and 21-October-2024: - Added support for assumed-size arrays, derived types, abd imported modules. - Improved support of non-default lower bounds, stride information and lowerbound for assumed shape arrays and dummy character arguments. - Improved generation of a subroutine type. - Added support for Common Block in MLIR. (Support in Flang is TODO). - Improved debugging of the main program. 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 many 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. Since our last report, Classic Flang now works with LLVM 19 and improvements were made to Classic Flang's alignment of complex variables. Detailed status can be found in the biweekly call Google doc at: docs.google.com/document/d/1-OuiKx4d7O6eLEJDBDKSRnSiUO2rgRR-c2Ga4AkrzOI