Fully integrating the Flang Fortran compiler with standard MLIR

Nick Brown
2024-09-27
Abstract:Fortran is the lingua franca of HPC code development and as such it is crucial that we as a community have open source Fortran compilers capable of generating high performance executables. Flang is LLVM's Fortran compiler and leverages MLIR which is a reusable compiler infrastructure which, as part of LLVM, has become popular in recent years. However, whilst Flang leverages MLIR it does not fully integrate with it and instead provides bespoke translation and optimisation passes to target LLVM-IR. In this paper we first explore the performance of Flang against other compilers popular in HPC for a range of benchmarks before describing a mapping between Fortran and standard MLIR, exploring the performance of this. The result of this work is an up to three times speed up compared with Flang's existing approach across the benchmarks and experiments run, demonstrating that the Flang community should seriously consider leveraging standard MLIR.
Distributed, Parallel, and Cluster Computing,Programming Languages
What problem does this paper attempt to address?
The problem that this paper attempts to solve is to improve the performance of the Flang compiler in high - performance computing (HPC). Specifically, Flang is a Fortran compiler under the LLVM project. Currently, although it utilizes MLIR (Multi - Level Intermediate Representation), a reusable compiler infrastructure, its integration with standard MLIR is not sufficient. The paper proposes a new method, which is to lower Flang's MLIR dialects to standard MLIR dialects, and then use the existing MLIR transformation and optimization processes to generate binary files. Through this method, the paper aims to explore whether the performance of Flang can be improved by integrating standard MLIR more closely, especially for the performance of a series of benchmark tests, so as to narrow the performance gap between Flang and other more mature Fortran compilers. The main contributions of the paper include: 1. A performance comparison between Flang and other compilers commonly found in HPC environments (such as Cray and Gfortran) was carried out, which helps to understand the performance differences among these compilers. 2. The mapping relationship between Fortran concepts and standard MLIR dialects was described, and how to represent the main constructs of Fortran in standard MLIR was explored. 3. The performance differences between the existing Flang method and the method using the standard MLIR process were explored. Through these studies, the paper hopes to provide a reference for the Flang community, that is, the possible performance improvement brought by more closely integrating standard MLIR, and the specific technical path for achieving this integration. This will not only help to improve the performance of Flang, but also reduce repetitive work, enabling Flang to make better use of the development achievements of the MLIR community.