[PATCH] D115529: [flang][nfc] Clarify the frontend/backend distinction

Andrzej Warzynski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 10 08:26:22 PST 2021


awarzynski created this revision.
Herald added a reviewer: sscalpone.
Herald added a project: Flang.
awarzynski requested review of this revision.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115529

Files:
  flang/docs/FlangDriver.md


Index: flang/docs/FlangDriver.md
===================================================================
--- flang/docs/FlangDriver.md
+++ 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115529.393505.patch
Type: text/x-patch
Size: 3141 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211210/448f2d46/attachment.bin>


More information about the llvm-commits mailing list