aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/FrontendTool
AgeCommit message (Collapse)AuthorFilesLines
2023-12-13[flang] Use StringRef::{starts,ends}_with (NFC)Kazu Hirata1-1/+1
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-08-31[Flang][Driver] Add warning support for invalid R_Group optionsVictor Kingi1-0/+19
With the R_Group options, invalid values e.g. '-Rpa' will not emit a warning like clang. This patch enables warning reporting, as well as suggestions on what option the user intended to select. Depends on D158174 and D158436. The former, adds backend support to R_Group options while the latter, implements regex support with some tests refactoring that cause a merge conflict. Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D158593
2023-08-31[Flang][Driver] Add regex support for R_Group optionsVictor Kingi1-3/+0
Add regex handling for all variations of OPT_R_Joined, i.e. `-Rpass`, `-Rpass-analysis`, `-Rpass-missed`. Depends on D158174. That patch implements backend support for R_Group options. Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D158436
2023-08-23[Flang][Driver] Implement OPT_R_Joined optionsVictor Kingi1-0/+32
Add a BackendRemarkConsumer class, responsible for handling diagnostics received from LLVM. The diagnostics being information on middle and backend passes used or not used. Clang by default has all remarks ignored but manually sets the severity of `R_Group` to visible(`clang::diag::clang::Severity::Remark`). This patch does the same for Flang. Depends on D157410. That patch adds the R family of options to `FlangOption` and `FC1Option` in `clang/include/clang/Driver/Options.td` Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D158174
2023-08-15[Driver] Refactor to use llvm Option's new Visibility flagsJustin Bogner1-3/+2
This is a big refactor of the clang driver's option handling to use the Visibility flags introduced in https://reviews.llvm.org/D157149. There are a few distinct parts, but they can't really be split into separate commits and still be made to compile. 1. We split out some of the flags in ClangFlags to ClangVisibility. Note that this does not include any subtractive flags. 2. We update the Flag definitions and OptIn/OptOut constructs in Options.td by hand. 3. We introduce and use a script, update_options_td_flags, to ease migration of flag definitions in Options.td, and we run that on Options.td. I intend to remove this later, but I'm committing it so that downstream forks can use the script to simplify merging. 4. We update calls to OptTable in the clang driver, cc1as, flang, and clangd to use the visibility APIs instead of Include/Exclude flags. 5. We deprecate the Include/Exclude APIs and add a release note. *if you are running into conflicts with this change:* Note that https://reviews.llvm.org/D157150 may also be the culprit and if so it should be handled first. The script in `clang/utils/update_options_td_flags.py` can help. Take the downstream side of all conflicts and then run the following: ``` % cd clang/include/clang/Driver % ../../../utils/update_options_td_flags.py Options.td > Options.td.new % mv Options.td.new Options.td ``` This will hopefully be sufficient, please take a look at the diff. Differential Revision: https://reviews.llvm.org/D157151
2023-06-01[flang][hlfir] Separate -emit-fir and -emit-hlfir for flang-newTom Eccles1-2/+4
In review for https://reviews.llvm.org/D146278, @vzakhari asked to separate -emit-fir and -emit-hlfir. This will allow FIR to be easily outputted after the HLFIR passes have been run. The new semantics are as follows: | Action | -flang-experimental-hlfir? | Result | | =========== | ========================== | =============================== | | -emit-hlfir | N | Outputs HLFIR | | -emit-hlfir | Y | Outputs HLFIR | | -emit-fir | N | Outputs FIR, using old lowering | | -emit-fir | Y | Outputs FIR, lowering via HLFIR | A patch for bbc will follow. Differential Revision: https://reviews.llvm.org/D151088
2023-04-16[flang] Refine how Clang dependencies are expressed #58663Ezike Ebuka1-9/+1
Fixes #58663 Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D140998
2022-11-03[Flang] Run clang-format on all flang filesPeter Steinfeld1-3/+4
This will make it easier for me to do reviews. Differential Revision: https://reviews.llvm.org/D137291
2022-10-28[flang] Fix building against clang dylibMichał Górny1-3/+12
Differential Revision: https://reviews.llvm.org/D136606
2022-07-27[Flang][Driver] Add support for AsmPrinter -mmlir optionsPrabhdeep Singh Soni1-0/+2
This patch adds support for AsmPrinter `-mmlir` options to the Flang driver. Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D130598
2022-06-22[flang][Driver] Refine _when_ driver diagnostics are formattedPeixin Qiao1-0/+3
This patch refines //when// driver diagnostics are formatted so that `flang-new` and `flang-new -fc1` behave consistently with `clang` and `clang -cc1`, respectively. This change only applies to driver diagnostics. Scanning, parsing and semantic diagnostics are separate and not covered here. **NEW BEHAVIOUR** To illustrate the new behaviour, consider the following input file: ```! file.f90 program m integer :: i = k end ``` In the following invocations, "error: Semantic errors in file.f90" _will be_ formatted: ``` $ flang-new file.f90 error: Semantic errors in file.f90 ./file.f90:2:18: error: Must be a constant value integer :: i = k $ flang-new -fc1 -fcolor-diagnostics file.f90 error: Semantic errors in file.f90 ./file.f90:2:18: error: Must be a constant value integer :: i = k ``` However, in the following invocations, "error: Semantic errors in file.f90" _will not be_ formatted: ``` $ flang-new -fno-color-diagnostics file.f90 error: Semantic errors in file.f90 ./file.f90:2:18: error: Must be a constant value integer :: i = k $ flang-new -fc1 file.f90 error: Semantic errors in file.f90 ./file.f90:2:18: error: Must be a constant value integer :: i = k ``` Before this change, none of the above would be formatted. Note also that the default behaviour in `flang-new` is different to `flang-new -fc1` (this is consistent with Clang). **NOTES ON IMPLEMENTATION** Note that the diagnostic options are parsed in `createAndPopulateDiagOpt`s in driver.cpp. That's where the driver's `DiagnosticEngine` options are set. Like most command-line compiler driver options, these flags are "claimed" in Flang.cpp (i.e. when creating a frontend driver invocation) by calling `getLastArg` rather than in driver.cpp. In Clang's Options.td, `defm color_diagnostics` is replaced with two separate definitions: `def fcolor_diagnostics` and def fno_color_diagnostics`. That's because originally `color_diagnostics` derived from `OptInCC1FFlag`, which is a multiclass for opt-in options in CC1. In order to preserve the current behaviour in `clang -cc1` (i.e. to keep `-fno-color-diagnostics` unavailable in `clang -cc1`) and to implement similar behaviour in `flang-new -fc1`, we can't re-use `OptInCC1FFlag`. Formatting is only available in consoles that support it and will normally mean that the message is printed in bold + color. Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com> Reviewed By: rovka Differential Revision: https://reviews.llvm.org/D126164
2022-05-14[flang][driver] Switch to the MLIR coding style in the driver (nfc)Andrzej Warzynski3-26/+42
This patch re-factors the driver code in LLVM Flang (frontend + compiler) to use the MLIR style. For more context, please see: https://discourse.llvm.org/t/rfc-coding-style-in-the-driver/ Most changes here are rather self-explanatory. Accessors are renamed to be more consistent with the rest of LLVM (e.g. allSource --> getAllSources). Additionally, MLIR clang-tidy files are added in the affected directories. clang-tidy and clang-format files were copied from MLIR. Small additional changes are made to silence clang-tidy/clang-format warnings. [1] https://mlir.llvm.org/getting_started/DeveloperGuide/ Differential Revision: https://reviews.llvm.org/D125007
2022-05-05[flang][driver] Re-organise the code-gen actions (nfc)Andrzej Warzynski1-4/+2
All frontend actions that generate code (MLIR, LLVM IR/BC, Assembly/Object Code) are re-factored as essentially one action, `CodeGenAction`, with minor specialisations. To facilate all this, `CodeGenAction` is extended to hold `TargetMachine` and backend action type (MLIR vs LLVM IR vs LLVM BC vs Assembly vs Object Code). `CodeGenAction` is no longer a pure abstract class and the corresponding `ExecuteAction` is implemented so that it covers all use cases. All this allows a much better code re-use. Key functionality is extracted into some helpful hooks: * `SetUpTargetMachine` * `GetOutputStream` * `EmitObjectCodeHelper` * `EmitBCHelper` I hope that this clarifies the overall structure. I suspect that we may need to revisit this again as the functionality grows in complexity. Differential Revision: https://reviews.llvm.org/D124665
2022-04-27[flang][driver] NFC: Make code more in line with LLVM styleAndrzej Warzynski1-20/+3
This patch basically implements [1] in ExecuteCompilerInvocation.cpp. It also: * replaces `CreateFrontendBaseAction` with `CreateFrontendAction` (only one method is needed ATM, this change removes the extra indirection) * removes `InvalidAction` from the `ActionKind` enum (I don't think it adds much and keeping it would mean adding a new void case in `CreateFrontendAction`) * sets the default frontend action in FrontendOptions.h to `ParseSyntaxOnly` (note that this is still overridden independently in `ParseFrontendArg` in CompilerInvocation.cpp) No new functionality is added, hence no tests. [1] https://llvm.org/docs/CodingStandards.html#don-t-use-default-labels-in-fully-covered-switches-over-enumerations Differential Revision: https://reviews.llvm.org/D124245
2022-04-14[flang][driver] Add support for `-mmlir`Andrzej Warzynski2-0/+18
The semantics of `-mmlir` are identical to `-mllvm`. The only notable difference is that `-mmlir` options should be forwarded to MLIR rather than LLVM. Note that MLIR llvm::cl options are lazily constructed on demand (see the definition of options in PassManagerOptions.cpp). This means that: * MLIR global options are only visible when explicitly initialised and displayed only when using `-mmlir --help`, * Flang and LLVM global options are always visible and displayed when using either `-mllvm -help` or `-mmlir --help`. In other words, `-mmlir --help` is a superset of `-mllvm --help`. This is not ideal, but we'd need to refactor all option definitions in Flang and LLVM to improve this. I suggesting leaving this for later. Differential Revision: https://reviews.llvm.org/D123297
2022-04-13[flang][driver] Add support for generating LLVM bytecode filesAndrzej Warzynski1-0/+2
Support for generating LLVM BC files is added in Flang's compiler and frontend drivers. This requires the `BitcodeWriterPass` pass to be run on the input LLVM IR module and is implemented as a dedicated frontend aciton. The new functionality as seen by the user (compiler driver): ``` flang-new -c -emit-llvm file.90 ``` or (frontend driver): ``` flang-new -fc1 -emit-llvm-bc file.f90 ``` The new behaviour is consistent with `clang` and `clang -cc1`. Differential Revision: https://reviews.llvm.org/D123211
2022-03-16[flang][driver] Add support for `-mllvm`Andrzej Warzynski1-0/+13
This option is added in both `flang-new` (the compiler driver) and `flang-new -fc1` (the frontend driver). The semantics are consistent with `clang` and `clang -cc1`. As Flang does not run any LLVM passes when invoked with `-emit-llvm` (i.e. `flang-new -S -emit-llvm <file>`), the tests use `-S`/`-c`/`-emit-obj` instead. These options require an LLVM backend to be run by the driver to generate the output (this makese `-mllvm` relevant here). Differential Revision: https://reviews.llvm.org/D121374
2022-03-09[flang][driver] Add support for -S and implement -c/-emit-objAndrzej Warzynski1-1/+5
This patch adds support for: * `-S` in Flang's compiler and frontend drivers, and implements: * `-emit-obj` in Flang's frontend driver and `-c` in Flang's compiler driver (this is consistent with Clang). (these options were already available before, but only as placeholders). The semantics of these options in Clang and Flang are identical. The `EmitObjAction` frontend action is renamed as `BackendAction`. This new name more accurately reflects the fact that this action will primarily run the code-gen/backend pipeline in LLVM. It also makes more sense as an action implementing both `-emit-obj` and `-S` (originally, it was just `-emit-obj`). `tripleName` from FirContext.cpp is deleted and, when a target triple is required, `mlir::LLVM::LLVMDialect::getTargetTripleAttrName()` is used instead. In practice, this means that `fir.triple` is replaced with `llvm.target_triple`. The former was effectively ignored. The latter is used when lowering from the LLVM dialect in MLIR to LLVM IR (i.e. it's embedded in the generated LLVM IR module). The driver can then re-use it when configuring the backend. With this change, the LLVM IR files generated by e.g. `tco` will from now on contain the correct target triple. The code-gen.f90 test is replaced with code-gen-x86.f90 and code-gen-aarch64.f90. With 2 seperate files we can verify that `--target` is correctly taken into account. LIT configuration is updated to enable e.g.: ``` ! REQUIRES: aarch64-registered-target ``` Differential Revision: https://reviews.llvm.org/D120568
2022-03-08[flang][driver] Add support for `-debug-dump-pft`Andrzej Warzynski1-0/+2
This patch adds support for dumping the pre-FIR tree in `flang-new -fc1`, i.e. Flang's frontend driver. This flag is functionally identical to `-pft-test` in `bbc` and semantically similar to `-fdebug-dump-parse-tree` from `flang-new -fc1`. Differential Revision: https://reviews.llvm.org/D121198
2022-02-17[flang][driver] Add support for `-emit-llvm`Andrzej Warzynski1-0/+2
This patch adds support for the `-emit-llvm` option in the frontend driver (i.e. `flang-new -fc1`). Similarly to Clang, `flang-new -fc1 -emit-llvm file.f` will generate a textual LLVM IR file. Depends on D118985 Differential Revision: https://reviews.llvm.org/D119012
2022-02-09[flang][driver] Add support for `-emit-mlir`Andrzej Warzynski2-0/+5
This patch adds support for generating MLIR files in Flang's frontend driver (i.e. `flang-new -fc1`). `-emit-fir` is added as an alias for `-emit-mlir`. We may want to decide to split the two in the future. A new parent class for code-gen frontend actions is introduced: `CodeGenAction`. We will be using this class to encapsulate logic shared between all code-generation actions, but not required otherwise. For now, it will: * run prescanning, parsing and semantic checks, * lower the input to MLIR. `EmitObjAction` is updated to inherit from this class. This means that the behaviour of `flang-new -fc1 -emit-obj` is also updated (previously, it would just exit immediately). This change required `flang/test/Driver/syntax-only.f90` to be updated. For `-emit-fir`, a specialisation of `CodeGenAction` is introduced: `EmitMLIRAction`. The key logic for this class is implemented in `EmitMLIRAction::ExecuteAction`. Differential Revision: https://reviews.llvm.org/D118985
2021-08-12[flang][driver] Add support for Frontend PluginsStuart Ellis1-0/+31
Introducing a plugin API and a simple HelloWorld Plugin example. This patch adds the `-load` and `-plugin` flags to frontend driver and the code around using custom frontend actions from within a plugin shared library object. It also adds to the Driver-help test to check the help option with the updated driver flags. Additionally, the patch creates a plugin-example test to check the HelloWorld plugin example runs correctly. As part of this, a new CMake flag (`FLANG_BUILD_EXAMPLES`) is added to allow the example to be built and for the test to run. This Plugin API has only been tested on Linux. Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D106137
2021-08-02[flang][nfc] Fix variable names in `FrontendOptions` & `PreprocessorOptions`Andrzej Warzynski1-3/+3
As all member variables in `FrontendOptions` and `PreprocessorOptions` are public, we should be naming them as `variable` rather than `variable_` [1]. This patch fixes that. Also, `FrontendOptions` & `PreprocessorOptions` are re-defined as a structs rather than classes (all fields are meant to be public). [1] https://github.com/llvm/llvm-project/blob/main/flang/docs/C%2B%2Bstyle.md#naming Differential Revision: https://reviews.llvm.org/D107062
2021-07-30[flang] Produce proper "preprocessor output" for -E optionpeter klausler1-18/+0
Rename the current -E option to "-E -Xflang -fno-reformat". Add a new Parsing::EmitPreprocessedSource() routine to convert the cooked character stream output of the prescanner back to something more closely resembling output from a traditional preprocessor; call this new routine when -E appears. The new -E output is suitable for use as fixed form Fortran source to compilation by (one hopes) any Fortran compiler. If the original top-level source file had been free form source, the output will be suitable for use as free form source as well; otherwise there may be diagnostics about missing spaces if they were indeed absent in the original fixed form source. Unless the -P option appears, #line directives are interspersed with the output (but be advised, f18 will ignore these if presented with them in a later compilation). An effort has been made to preserve original alphabetic character case and source indentation. Add -P and -fno-reformat to the new drivers. Tweak test options to avoid confusion with prior -E output; use -fno-reformat where needed, but prefer to keep -E, sometimes in concert with -P, on most, updating expected results accordingly. Differential Revision: https://reviews.llvm.org/D106727
2021-07-01[flang] Revert "PoC for Flang Driver Plugins"Andrzej Warzynski1-67/+0
This patch has not been reviewed and was commited by accident. This reverts commit 788a5d4afe6407e647454a9832a7b4a27fba06bf.
2021-07-01PoC for Flang Driver PluginsStuart Ellis1-0/+67
2021-06-24[OptTable] Rename PrintHelp to printHelpFangrui Song1-1/+1
To be consistent with other member functions and match the coding standard.
2021-06-16[flang][driver] Add `-fdebug-dump-all`Andrzej Warzynski1-0/+3
The new option will run the semantic checks and then dump the parse tree and all the symbols. This is equivalent to running the driver twice, once with `-fdebug-dump-parse-tree` and then with the `-fdebug-dump-symbols` action flag. Currently we wouldn't be able to achieve the same by simply running: ``` flang-new -fc1 -fdebug-dump-parse-tree -fdebug-dump-symbols <input-file> ``` That's because the new driver will only run one frontend action per invocation (both of the flags used here are action flags). Diverging from this design would lead to costly compromises and it's best avoided. We may want to consider re-designing our debugging actions (and action options) in the future so that there's more code re-use. For now, I'm focusing on making sure that we support all the major cases requested by our users. Differential Revision: https://reviews.llvm.org/D104305
2021-06-07[flang][driver] Add support for the "-init-only" optionStuart Ellis1-0/+3
Adding the `-init-only` option and corresponding frontend action to generate a diagnostic. `-init-only` vs `-test-io`: `-init-only` ignores the input (it never calls the prescanner) `-test-io` is similar to `-init-only`, but does read and print the input without calling the prescanner. This patch also adds a Driver test to check this action. Reviewed By: awarzynski, AMDChirag Differential Revision: https://reviews.llvm.org/D102849
2021-04-21[flang][driver] Add support for `-fget-definition`Andrzej Warzynski1-0/+3
This patch adds `-fget-definition` to `flang-new`. The semantics of this option are identical in both drivers. The error message in the "throwaway" driver is updated so that it matches the one from `flang-new` (which is auto-generated and cannot be changed easily). Tests are updated accordingly. A dedicated test for error handling was added: get-definition.f90 (for the sake of simplicity, getdefinition01.f90 no longer tests for errors). The `ParseFrontendArgs` function is updated so that it can return errors. This change is required in order to report invalid values following `-fget-definition`. The actual implementation of `GetDefinitionAction::ExecuteAction()` was extracted from f18.cpp (i.e. the bit that deals with `-fget-definition`). Depends on: https://reviews.llvm.org/D100556 Differential Revision: https://reviews.llvm.org/D100558
2021-04-08[flang][driver] Add debug options not requiring semantic checksAndrzej Warzynski1-0/+6
This patch adds two debugging options in the new Flang driver (flang-new): *fdebug-unparse-no-sema *fdebug-dump-parse-tree-no-sema Each of these options combines two options from the "throwaway" driver (left: f18, right: flang-new): * `-fdebug-uparse -fdebug-no-semantics` --> `-fdebug-unparse-no-sema` * `-fdebug-dump-parse-tree -fdebug-no-semantics` --> `-fdebug-dump-parse-tree-no-sema` There are no plans to implement `-fdebug-no-semantics` in the new driver. Such option would be too powerful. Also, it would only make sense when combined with specific frontend actions (`-fdebug-unparse` and `-fdebug-dump-parse-tree`). Instead, this patch adds 2 specialised options listed above. Each of these is implemented through a dedicated FrontendAction (also added). The new frontend actions are implemented in terms of a new abstract base action: `PrescanAndSemaAction`. This new base class was required so that we can have finer control over what steps within the frontend are executed: * `PrescanAction`: run the _prescanner_ * `PrescanAndSemaAction`: run the _prescanner_ and the _parser_ (new in this patch) * `PrescanAndSemaAction`: run the _prescanner_, _parser_ and run the _semantic checks_ This patch introduces `PrescanAndParseAction::BeginSourceFileAction`. Apart from the semantic checks removed at the end, it is similar to `PrescanAndSemaAction::BeginSourceFileAction`. Differential Revision: https://reviews.llvm.org/D99645
2021-03-18[flang][driver] Add support for `-fget-symbols-sources`Andrzej Warzynski1-0/+3
Adds support for `-fget-symbols-sources` in the new Flang driver. All relevant tests are updated to use the new driver when `FLANG_BUILD_NEW_DRIVER` is set. `RUN` lines in tests are updated so `-fsyntax-only` comes before `-fget-symbols-sources`. That's because: * both `-fsyntax-only` and `-fget-symbols-sources` are action flags, and * the new driver, flang-new, will only consider the right-most action flag. In other words, this change is needed so that the tests work with both `f18` (requires both flags) and `flang-new` (only considers the last action flag). Differential Revision: https://reviews.llvm.org/D98191
2021-03-10[flang][driver] Add `-fdebug-dump-parsing-log`Andrzej Warzynski1-0/+3
This patch adds `-fdebug-dump-parsing-log` in the new driver. This option is semantically identical to `-fdebug-instrumented-parse` in `f18` (the former is added as an alias in `f18`). As dumping the parsing log makes only sense for instrumented parses, we set Fortran::parser::Options::instrumentedParse to `True` when `-fdebug-dump-parsing-log` is used. This is consistent with `f18`. To facilitate tweaking the configuration of the frontend based on the action being requested, `setUpFrontendBasedOnAction` is introduced in CompilerInvocation.cpp. Differential Revision: https://reviews.llvm.org/D97457
2021-02-19[flang][driver] Add debug measure-parse-tree and pre-fir-tree optionsFaris Rehman1-0/+6
Add the following options: * -fdebug-measure-parse-tree * -fdebug-pre-fir-tree Summary of changes: - Add 2 new frontend actions: DebugMeasureParseTreeAction and DebugPreFIRTreeAction - Add MeasurementVisitor to FrontendActions.h - Make reportFatalSemanticErrors return true if there are any fatal errors - Port most of the `-fdebug-pre-fir-tree` tests to use the new driver if built, otherwise use f18. Differential Revision: https://reviews.llvm.org/D96884
2021-02-18[flang][driver] Add debug dump optionsFaris Rehman1-0/+9
Add the following options: * -fdebug-dump-symbols * -fdebug-dump-parse-tree * -fdebug-dump-provenance Summary of changes: - Add 3 new frontend actions: DebugDumpSymbolsAction, DebugDumpParseTreeAction and DebugDumpProvenanceAction - Add a unique pointer to the Semantics instance created in PrescanAndSemaAction - Move fatal semantic error reporting to its own method, FrontendActions#reportFatalSemanticErrors - Port most tests using `-fdebug-dump-symbols` and `-fdebug-dump-parse-tree` to the new driver if built, otherwise default to f18 Differential Revision: https://reviews.llvm.org/D96716
2021-02-16[flang][driver] Add options for unparsingAndrzej Warzynski1-0/+6
This patch adds the following compiler frontend driver options: * -fdebug-unparse (f18 spelling: -funparse) * -fdebug-unparse-with-symbols (f18 spelling: -funparse-with-symbols) The new driver will only accept the new spelling. `f18` will accept both the original and the new spelling. A new base class for frontend actions is added: `PrescanAndSemaAction`. This is added to reduce code duplication that otherwise these new options would lead to. Implementation from * `ParseSyntaxOnlyAction::ExecutionAction` is moved to: * `PrescanAndSemaAction::BeginSourceFileAction` This implementation is now shared between: * PrescanAndSemaAction * ParseSyntaxOnlyAction * DebugUnparseAction * DebugUnparseWithSymbolsAction All tests that don't require other yet unimplemented options are updated. This way `flang-new -fc1` is used instead of `f18` when `FLANG_BUILD_NEW_DRIVER` is set to `On`. In order to facilitate this, `%flang_fc1` is added in the LIT configuration (lit.cfg.py). `asFortran` from f18.cpp is duplicated as `getBasicAsFortran` in FrontendOptions.cpp. At this stage it's hard to find a good place to share this method. I suggest that we revisit this once a switch from `f18` to `flang-new` is complete. Differential Revision: https://reviews.llvm.org/D96483
2021-01-19[flang][driver] Move isFixedFormSuffix and isFreeFormSuffix to flangFrontendAndrzej Warzynski1-15/+0
isFixedFormSuffix and isFreeFormSuffix should be defined in flangFrontend rather than flangFrontendTool library. That's for 2 reasons: * these methods are used in flangFrontend rather than flangFrontendTool * flangFrontendTool depends on flangFrontend As mentioned in the post-commit review for D94228, without this change shared library builds fail. Differential Revision: https://reviews.llvm.org/D94968
2021-01-19[flang][driver] Add support for fixed form detectionFaris Rehman1-0/+15
Currently the new flang driver always runs in free form mode. This patch adds support for fixed form mode detection based on the file extensions. Like `f18`, `flang-new` will treat files ending with ".f", ".F" and ".ff" as fixed form. Additionally, ".for", ".FOR", ".fpp" and ".FPP" file extensions are recognised as fixed form files. This is consistent with gfortran [1]. In summary, files with the following extensions are treated as fixed-form: * ".f", ".F", ".ff", ".for", ".FOR", ".fpp", ".FPP" For consistency with flang/test/lit.cfg.py and f18, this patch also adds support for the following file extensions: * ".ff", ".FOR", ".for", ".ff90", ".fpp", ".FPP" This is added in flang/lib/Frontend/FrontendOptions.cpp. Additionally, the following extensions are included: * ".f03", ".F03", ".f08", ".F08" This is for compatibility with gfortran [1] and other popular Fortran compilers [2]. NOTE: internally Flang will only differentiate between fixed and free form files. Currently Flang does not support switching between language standards, so in this regard file extensions are irrelevant. More specifically, both `file.f03` and `file.f18` are represented with `Language::Fortran` (as opposed to e.g. `Language::Fortran03`). Summary of changes: - Set Fortran::parser::Options::sFixedForm according to the file type - Add isFixedFormSuffix and isFreeFormSuffix helper functions to FrontendTool/Utils.h - Change FrontendOptions::GetInputKindForExtension to support the missing file extensions that f18 supports and some additional ones - FrontendActionTest.cpp is updated to make sure that the test input is treated as free-form [1] https://gcc.gnu.org/onlinedocs/gfortran/GNU-Fortran-and-GCC.html [2] https://github.com/llvm/llvm-project/blob/master/flang/docs/OptionComparison.md#notes Differential Revision: https://reviews.llvm.org/D94228
2021-01-07[flang][driver] Add support for `-c` and `-emit-obj`Andrzej Warzynski1-0/+2
This patch adds a frontend action for emitting object files. While Flang does not support code-generation, this action remains a placeholder. This patch simply provides glue-code to connect the compiler driver with the appropriate frontend action. The new action is triggered with the `-c` compiler driver flag, i.e. `flang-new -c`. This is then translated to `flang-new -fc1 -emit-obj`, so `-emit-obj` has to be marked as supported as well. As code-generation is not available yet, `flang-new -c` results in a driver error: ``` error: code-generation is not available yet ``` Hopefully this will help communicating the level of available functionality within Flang. The definition of `emit-obj` is updated so that it can be shared between Clang and Flang. As the original definition was enclosed within a Clang-specific TableGen `let` statement, it is extracted into a new `let` statement. That felt like the cleanest option. I also commented out `-triple` in Flang::ConstructJob and updated some comments there. This is similar to https://reviews.llvm.org/D93027. I wanted to make sure that it's clear that we can't support `-triple` until we have code-generation. However, once code-generation is available we _will need_ `-triple`. As this patch adds `-emit-obj`, the emit-obj.f90 becomes irrelevant and is deleted. Instead, phases.f90 is added to demonstrate that users can control compilation phases (indeed, `-c` is a phase control flag). Reviewed By: SouraVX, clementval Differential Revision: https://reviews.llvm.org/D93301
2020-12-18[flang][driver] Add support for `-fsyntax-only`Andrzej Warzynski1-0/+3
The behaviour triggered with this flag is consistent with `-fparse-only` in `flang` (i.e. the throwaway driver). This new spelling is consistent with Clang and gfortran, and was proposed and agreed on for the new driver in [1]. This patch also adds some minimal logic to communicate whether the semantic checks have failed or not. When semantic checks fail, a frontend driver error is generated. The return code from the frontend driver is then determined by checking the driver diagnostics - the presence of driver errors means that the compilation has failed. This logic is consistent with `clang -cc1`. [1] http://lists.llvm.org/pipermail/flang-dev/2020-November/000588.html Differential Revision: https://reviews.llvm.org/D92854
2020-11-02[Flang][Driver] Add PrintPreprocessedInput FrontendAction (`flang-new -E`)Caroline Concatto1-0/+3
This patch implements the first frontend action for the Flang parser (i.e. Fortran::parser). This action runs the preprocessor and is invoked with the `-E` flag. (i.e. `flang-new -E <input-file>). The generated output is printed to either stdout or the output file (specified with `-` or `-o <output-file>`). Note that currently there is no mechanism to map options for the frontend driver (i.e. Fortran::frontend::FrontendOptions) to options for the parser (i.e. Fortran::parser::Options). Instead, Frotran::parser::options are hard-coded to: ``` std::vector<std::string> searchDirectories{"."s}; searchDirectories = searchDirectories; isFixedForm = false; _encoding(Fortran::parser::Encoding::UTF_8); ``` These default settings are compatible with the current Flang driver. Further work is required in order for CompilerInvocation to read and map clang::driver::options to Fortran::parser::options. Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com> Differential Revision: https://reviews.llvm.org/D88381
2020-11-02[flang][driver] Rename the accessors/mutators (NFC)Andrzej Warzynski1-3/+3
As per point 3 in [1]: ``` Accessor member functions are named with the non-public data member's name, less the trailing underscore. Mutator member functions are named set_... ``` Originally we just followed the LLVM's style, which is incompatible with Flang. This patch renames the accessors and mutators accordingly. `getDiagnostics` and `GetDiagnostics` are replaced with one accessor: `diagnostics`. `SetDiagnostics` was neither implemented nor used, so it's deleted. [1] https://github.com/llvm/llvm-project/blob/master/flang/docs/C++style.md#naming Differential Revision: https://reviews.llvm.org/D90300
2020-10-24[Flang][Driver] Add infrastructure for basic frontend actions and file I/OCaroline Concatto2-2/+43
This patch introduces the dependencies required to read and manage input files provided by the command line option. It also adds the infrastructure to create and write to output files. The output is sent to either stdout or a file (specified with the `-o` flag). Separately, in order to be able to test the code for file I/O, it adds infrastructure to create frontend actions. As a basic testable example, it adds the `InputOutputTest` FrontendAction. The sole purpose of this action is to read a file from the command line and print it either to stdout or the output file. This action is run by using the `-test-io` flag also introduced in this patch (available for `flang-new` and `flang-new -fc1`). With this patch: ``` flang-new -test-io input-file.f90 ``` will read input-file.f90 and print it in the output file. The `InputOutputTest` frontend action has been introduced primarily to facilitate testing. It is hidden from users (i.e. it's only displayed with `--help-hidden`). Currently Clang doesn’t have an equivalent action. `-test-io` is used to trigger the InputOutputTest action in the Flang frontend driver. This patch makes sure that “flang-new” forwards it to “flang-new -fc1" by creating a preprocessor job. However, in Flang.cpp, `-test-io` is passed to “flang-new -fc1” without `-E`. This way we make sure that the preprocessor is _not_ run in the frontend driver. This is the desired behaviour: `-test-io` should only read the input file and print it to the output stream. co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com> Differential Revision: https://reviews.llvm.org/D87989
2020-09-24[flang][driver] Add missing dependency in CMake filesAndrzej Warzynski1-0/+3
The Flang driver depends on libclangBasic. This means, among other things, that some of the tablegen files (e.g. diagnostic definitions) need to be generated before various libclangBasic header files can be included (e.g. DiagnosticIDs.h). If we are lucky, libclangBasic is indeed built before various flang driver libraries that depend on it are. This patch makes sure that this is deterministic - i.e. libclangBasic is built before the Flang driver libraries are. Differential Revision: https://reviews.llvm.org/D88110
2020-09-24[flang][driver] Fix options flag in the frontend driverAndrzej Warzynski1-1/+1
In the frontend driver we should be using FC1Option (frontend driver options) instead of FlangOption (flang driver options). Differential Revision: https://reviews.llvm.org/D88108
2020-09-11[flang][driver] Add the new flang compiler and frontend driversCaroline Concatto2-0/+50
Summary: This is the first patch implementing the new Flang driver as outlined in [1], [2] & [3]. It creates Flang driver (`flang-new`) and Flang frontend driver (`flang-new -fc1`). These will be renamed as `flang` and `flang -fc1` once the current Flang throwaway driver, `flang`, can be replaced with `flang-new`. Currently only 2 options are supported: `-help` and `--version`. `flang-new` is implemented in terms of libclangDriver, defaulting the driver mode to `FlangMode` (added to libclangDriver in [4]). This ensures that the driver runs in Flang mode regardless of the name of the binary inferred from argv[0]. The design of the new Flang compiler and frontend drivers is inspired by it counterparts in Clang [3]. Currently, the new Flang compiler and frontend drivers re-use Clang libraries: clangBasic, clangDriver and clangFrontend. To identify Flang options, this patch adds FlangOption/FC1Option enums. Driver::printHelp is updated so that `flang-new` prints only Flang options. The new Flang driver is disabled by default. To enable it, set `-DBUILD_FLANG_NEW_DRIVER=ON` when configuring CMake and add clang to `LLVM_ENABLE_PROJECTS` (e.g. -DLLVM_ENABLE_PROJECTS=“clang;flang;mlir”). [1] “RFC: new Flang driver - next steps” http://lists.llvm.org/pipermail/flang-dev/2020-July/000470.html [2] “RFC: Adding a fortran mode to the clang driver for flang” http://lists.llvm.org/pipermail/cfe-dev/2019-June/062669.html [3] “RFC: refactoring libclangDriver/libclangFrontend to share with Flang” http://lists.llvm.org/pipermail/cfe-dev/2020-July/066393.html [4] https://reviews.llvm.org/rG6bf55804924d5a1d902925ad080b1a2b57c5c75c co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com> Reviewed By: richard.barton.arm, sameeranjoshi Differential Revision: https://reviews.llvm.org/D86089