[llvm-dev] RFC for f18+runtimes in LLVM

Stephen Scalpone via llvm-dev llvm-dev at lists.llvm.org
Mon Feb 25 10:06:07 PST 2019


Hi, everyone,

As you may know, NVIDIA has developed an open-source Fortran frontend for LLVM (http://flang-compiler.org), which consists of the flang frontend itself along with the corresponding Fortran runtime library. The existing frontend's code is mostly written in C, and while a production-quality implementation, does not follow modern software-engineering practices.

Our long-standing desire is that our work forms the basis of a Fortran frontend that is part of the LLVM project and developed within the LLVM community. In addition, we would like the frontend to be useful in the many ways that Clang is useful: not just as a frontend, but also for static analysis and tooling.

Recognizing that the current flang's code base will not meet these needs, we started a ground-up rewrite of the frontend in modern C++. This effort is called f18.

At this point, we have documented and implemented a healthy subset of the compiler for symbol tables and scoping, name resolution, USE statements and module files, constant representation, constant folding and much of declaration, label and expression semantics. The parser handles all of Fortran 2018 and OpenMP 4.5 and implements a Fortran-aware preprocessor. The Fortran control flow graph (CFG) is in review now.  We continue to update other documentation, such as the style guide and runtime descriptor design.

Before this effort proceeds much farther, we'd like to contribute f18, and the existing Fortran runtime libraries, to the LLVM project. The Fortran frontend would become a proper LLVM subproject, design discussions would take place on an associated LLVM mailing list, code reviews would use phabricator, and so on.

We're committed to developing LLVM's Fortran frontend for years to come, and together with other members of the LLVM community (e.g., ARM, US Dept of Energy) would like to do so as part of the LLVM project.

* The Fortran runtime library will be moved into a subdirectory of this new LLVM subproject, or compiler-rt, or its own subproject (based on feedback here).

* The current f18 code will be committed to the new LLVM subproject.  The f18 code is a set of libraries that implements the Fortran compiler.  Today, there’s a rudimentary driver; however, we propose to adapt the clang driver to accept Fortran source and invoke f18 as appropriate. We would also adapt the f18 libraries to fit into the existing llvm build systems and testing infrastructure.

The f18 compiler source code complies with most of LLVM's coding guidelines; however, the code uses several C++17 features.  We've documented our use of C++17 here:

  https://github.com/flang-compiler/f18/blob/master/documentation/C++17.md

In particular, the parse tree and the lowered forms of expressions and variables are defined in terms of C++17 std::variant. Most of the compiler uses C++17 std::visit to walk these data structures.

It’s possible to reimplement the most important functionality of std:variant as a subset class, say llvm:variant; however, variant gets its power from the C++17 features generic lambdas and parameter pack expansion on “using”.  Without these C++17 features, use of variant would be impractical.

Our thinking when we started was that llvm would adopt C++17 before mid-2020, which lines up with our projected completion date. If we were to adopt C++11 or C++14, we would likely create substitutes for these classes, certainly at a cost of calendar time and perhaps type safety and notational convenience.  One of our principles is to take advantage of the standard library as much as possible, so casual readers will better understand our code and so we avoid the time and bugs associated with writing class libraries.

Our request would be to get a waiver for the C++11 requirement based on the fact that we're skating to where the puck will be.  In the meantime, because F18 only exists as a stand-alone program, early adopters would still have a useful parser and analyzer for Fortran.

Also, as part of the ongoing flang effort, NVIDIA has developed a library of scalar, vector, and masked math functions. This library should be useful for autovectorization, and OpenMP SIMD, in general. We’ll create another RFC to discuss this contribution.

Please let us know if you have any feedback or concerns.

- Steve





-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190225/77110757/attachment.html>


More information about the llvm-dev mailing list