diff --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md --- a/flang/docs/FlangDriver.md +++ b/flang/docs/FlangDriver.md @@ -239,12 +239,12 @@ as a temporary substitute for Flang's compiler driver while the actual driver is in development. -## Adding new Compiler Options +# Adding new Compiler Options Adding a new compiler option in Flang consists of two steps: * define the new option in a dedicated TableGen file, * parse and implement the option in the relevant drivers that support it. -### Option Definition +## Option Definition All of Flang's compiler and frontend driver options are defined in `clang/include/clang/Driver/Options.td` in Clang. When adding a new option to Flang, you will either: @@ -280,7 +280,7 @@ There are also other groups and occasionally you will use them instead of the groups listed above. -### Option Implementation +## Option Implementation First, every option needs to be parsed. Flang compiler options are parsed in two different places, depending on which driver they belong to: @@ -304,7 +304,7 @@ flags (e.g. `-fsyntax-only`) are usually more complex overall, but also more structured in terms of the implementation. -### Action Options +## Action Options For options that correspond to an action (i.e. marked as `Action_Group`), you will have to define a dedicated instance of `FrontendActions` in `flang/include/flang/Frontend/FrontendOptions.h`. For example, for @@ -337,6 +337,30 @@ At this point you should be able to trigger that frontend action that you have just added using your new frontend option. +# Frontend vs Optimiser vs Backend +Depending on the context, compiler frontend and backend can mean different +things. From the point of view of the Flang drivers, the **frontend** includes all +the stages implemented in the Flang sub-project: + +* parsing, semantic analysis, lowering from parse tree to MLIR, lowering from + MLIR to LLVM IR. + +Broadly speaking, the frontend consumes Fortran source files and generates LLVM +IR output (it can also consume and generate most of the intermediate +representations). The generated LLVM IR is then passed onto the **optimiser** +that is implemented within the LLVM sub-project and that transforms the input +LLVM IR into optimized LLVM IR output. These transformations are mostly +target-agnostic. The output generated by the optimiser is then passed onto one +of the many **backends** (e.g. AArch64 or X86), also implemented inside the +LLVM sub-project. A backend will lower the target agnostic LLVM IR into a +target specific assembly or machine-code representation. It may also perform +some target specific micro-optimisations. + +This classification is reflected in the naming used for various driver +components inside Flang. Note that other parts of the Flang frontend my refer +to LLVM (or LLVM IR) as the backaned without making a distinction into the +optimiser and one of the LLVM hardware backends. + # Testing In LIT, we define two variables that you can use to invoke Flang's drivers: * `%flang` is expanded as `flang-new` (i.e. the compiler driver)