To: J3 J3/22-125 From: Mark LeAir Subject: Flang Liaison Report Date: 2022-February-23 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' - Wrapping up Fortran 95 semantics - OpenMP semantics and runtime - fixing issues identified from test cases Flang Front-End Work that has been completed in Q4 (i.e., between October 1, 2021 and December 31, 2021): Development of Fortran semantic analysis continues. Most of the work done in the Front-End in Q4 resulted from the stepped-up internal testing. We continue to add test codes and applications to our test suites which provide opportunities for additional semantic checks. Front-End work completed in Q4 include: - Added CALL FLUSH(n), a legacy extension. - Implemented folding of ac-implied-do indices in structure constructors. - Implemented folding of EXPONENT() intrinsic function. - Addressed errors with MAX/MIN with keyword= arguments. - Implemented reversed comparison in RESHAPE() runtime. - Implemented INQUIRE(PAD=) and (POSITION=) for predefined units. - Implemented results from folding MAXEXPONENT and MINEXPONENT. - Implemented the argument keyword for AIMAG(Z=...). - Fixed an issue with INQUIRE(IOLENGTH=) output. - Implemented folding of EPSILON(). - Addressed a bogus folding error for ISHFT(x, negative). - Fixed a NAMELIST input bug with multiple subscript triplets. - Implemented DOT_PRODUCT for logical. - Implemented RESHAPE with ORDER= argument. - Implemented folding of EPSILON(). - Implemented combined folding of FINDLOC/MAXLOC/MINLOC. - Addressed a crash with "call system_clock(count_max=j)". - Addressed a crash in a semantic error recovery situation. - Implemented NAMELIST look-ahead case. - Implemented constant folding of SPREAD, BTEST, and LGE/LGT/LLE/LLT. - Added support for negative character lengths in semantics. - Added support for implicit procedure pointers to associate with explicit procedures. - Added support for ENTRY names in IsPureProcedure() predicate. - Added support for legacy usage of 'A' edit descriptors for integer & real. - Added support for NAMELIST input of short arrays. - Added support for NULL() in generic procedure resolution cases. - Re-folded bounds expressions in DATA implied DO loops. - Allowed exterior branch to outermost WHERE construct statement. - Made subscript list argument a nullable pointer. - Distinguished error/warning cases for bad jumps into constructs. - Improved error message for misuse of NULL(mold) as data statement constant. - Expunged bogus semantic check for ELEMENTAL without dummies. - Added error checking for IBCLR/IBSET and ISHFT/SHIFT[ALR]. - Defined IEEE_SCALB, IEEE_NEXT_AFTER, IEEE_NEXT_DOWN, and IEEE_NEXT_UP. This work has been merged to the LLVM project branch. Flang Lowering work that has been completed in Q4 (i.e., between October 1, 2021 and December 31, 2021): Note: Lowering is the translation of Fortran syntax into the semantic-based Fortran IR (FIR) and then into LLVM IR. We continue to work towards Fortran 95 compliance. Most of the Lowering work in Q4 fell into two categories: Work on TODOs left over on Fortran 95 features and addressing issues that were exposed by our test runs. Lowering features completed in Q4 include: - Wrapped up WHERE and FORALL implementations. - Implemented a lazy buffer for allocating temporaries related to caching intermediates like mask values in array expressions. - Fixed mask evaluation issues. - Fixed expression matching issues. - Eliminated the scalar lowering framework that was specific to the FORALL context. - Fixed issue when RHS inside FORALL is a scalar expression referencing arrays. - Fixed lowering of array references that do not use FORALL indexes. - Fixed pointer assignments inside FORALL. - Ensured base array lower bounds are applied. - Added code to lower the LHS of scalar assignments inside FORALL. - Lowered IO INQUIRE(IOLENGTH). - Lowered IO READ SIZE control-spec. - Lowered LBOUND and UBOUND intrinsics with non-constant DIM arguments. - Refactored lowering code to better shareable. Runtime Changes in Q4 (i.e., between October 1, 2021 and December 31, 2021): - Added support for handling sequential formatted I/O. - Removed runtime check from OpenFile::Close(). - Avoided potential deadlock in CloseAll(). - Returned arrays in Transfer runtime with SIZE argument. - Avoided closing stderr in runtime (fixed STOP output). - Rearranged prototype & code placement of IsCoarray(). - Defined & implemented a lowering support API IsContiguous() in runtime. - Moved IsCoarray() to fix shared library build. - Connected predefined unit 0 to stderr. - Skipped `Fortran STOP: ` before message when NO_STOP_MESSAGE is set. - Allowed write after non advancing read in IO runtime. - Sped up common runtime cases of DOT_PRODUCT & MATMUL. - Fixed crash on empty formatted external READs. - Performance improvements to real formatted input. - Fixed output of BOZ editing of "negative" values. - Fixed vector CSHIFT runtime with non-zero lower bounds. 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: - Wrap up the Fortran 95 work. This includes addressing all known issues in the frontend, the runtime and in the lowering code, that came out of internal testing. - Clean up asserts and improve error messages. - Continue (and wrap up) the work of upstreaming code from fir-dev to the LLVM project repository. 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. 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 at: docs.google.com/document/d/1-OuiKx4d7O6eLEJDBDKSRnSiUO2rgRR-c2Ga4AkrzOI