diff options
author | Faris Rehman <faris.rehman@arm.com> | 2021-02-10 09:24:45 +0000 |
---|---|---|
committer | Faris Rehman <faris.rehman@arm.com> | 2021-02-10 09:59:35 +0000 |
commit | 6d48a1a53fabae8715091a9aca128cc4a5d9b0a6 (patch) | |
tree | cb93fd459fb90eb87cecb63e587a18e0d82702a0 /flang/lib/Frontend/CompilerInvocation.cpp | |
parent | a7d01772ac370bfc5ef1838c8d18b7be070edfbe (diff) | |
download | llvm-6d48a1a53fabae8715091a9aca128cc4a5d9b0a6.zip llvm-6d48a1a53fabae8715091a9aca128cc4a5d9b0a6.tar.gz llvm-6d48a1a53fabae8715091a9aca128cc4a5d9b0a6.tar.bz2 |
[flang][driver] Add support for -fopenmp and -fopenacc
Add support for the following options:
* -fopenmp
* -fopenacc
Update OpenMP and OpenACC semantics tests to use the new driver if it is built, otherwise use f18.
OpenMP tests that include `use omp_lib` or run `test_symbols.sh` have not been updated as they require options `-intrinsic-module-directory` and `-funparse-with-symbols` which are currently not implemented in the new driver.
Similarly OpenACC tests that run `test_symbols.sh` have not been updated.
This patch also moves semanticsContext to CompilerInvocation and creates it in CompilerInvocation#setSemanticsOpts so that the semantics context can use Fortran::parser::Options#features.
Summary of changes:
- Move semanticsContext to CompilerInvocation.h
- Update OpenMP and OpenACC semantics tests that do not rely on `-intrinsic-module-directory` and `-funparse-with-symbols` to use %flang
Differential Revision: https://reviews.llvm.org/D96032
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | flang/lib/Frontend/CompilerInvocation.cpp | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 445feaa..078cb95 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -7,7 +7,9 @@ //===----------------------------------------------------------------------===// #include "flang/Frontend/CompilerInvocation.h" +#include "flang/Common/Fortran-features.h" #include "flang/Frontend/PreprocessorOptions.h" +#include "flang/Semantics/semantics.h" #include "flang/Version.inc" #include "clang/Basic/AllDiagnostics.h" #include "clang/Basic/DiagnosticDriver.h" @@ -21,6 +23,7 @@ #include "llvm/Option/OptTable.h" #include "llvm/Support/Process.h" #include "llvm/Support/raw_ostream.h" +#include <memory> using namespace Fortran::frontend; @@ -196,6 +199,14 @@ static InputKind ParseFrontendArgs(FrontendOptions &opts, opts.fixedFormColumns_ = columns; } } + + // Extensions + if (args.hasArg(clang::driver::options::OPT_fopenacc)) { + opts.features_.Enable(Fortran::common::LanguageFeature::OpenACC); + } + if (args.hasArg(clang::driver::options::OPT_fopenmp)) { + opts.features_.Enable(Fortran::common::LanguageFeature::OpenMP); + } return dashX; } @@ -322,6 +333,7 @@ void CompilerInvocation::SetDefaultFortranOpts() { // TODO: When expanding this list of standard predefinitions, consider // creating a dedicated API for this. Also at some point we will need to // differentiate between different targets. + // TODO: Move to setDefaultPredefinitions fortranOptions.predefinitions.emplace_back("__flang__", "1"); fortranOptions.predefinitions.emplace_back( "__flang_major__", FLANG_VERSION_MAJOR_STRING); @@ -331,6 +343,21 @@ void CompilerInvocation::SetDefaultFortranOpts() { "__flang_patchlevel__", FLANG_VERSION_PATCHLEVEL_STRING); } +void CompilerInvocation::setDefaultPredefinitions() { + auto &fortranOptions = fortranOpts(); + const auto &frontendOptions = frontendOpts(); + + // Add predefinitions based on extensions enabled + if (frontendOptions.features_.IsEnabled( + Fortran::common::LanguageFeature::OpenACC)) { + fortranOptions.predefinitions.emplace_back("_OPENACC", "202011"); + } + if (frontendOptions.features_.IsEnabled( + Fortran::common::LanguageFeature::OpenMP)) { + fortranOptions.predefinitions.emplace_back("_OPENMP", "201511"); + } +} + void CompilerInvocation::setFortranOpts() { auto &fortranOptions = fortranOpts(); const auto &frontendOptions = frontendOpts(); @@ -343,6 +370,8 @@ void CompilerInvocation::setFortranOpts() { } fortranOptions.fixedFormColumns = frontendOptions.fixedFormColumns_; + fortranOptions.features = frontendOptions.features_; + collectMacroDefinitions(preprocessorOptions, fortranOptions); fortranOptions.searchDirectories.insert( @@ -357,10 +386,14 @@ void CompilerInvocation::setFortranOpts() { } void CompilerInvocation::setSemanticsOpts( - Fortran::semantics::SemanticsContext &semaCtxt) { - auto &fortranOptions = fortranOpts(); + Fortran::parser::AllCookedSources &allCookedSources) { + const auto &fortranOptions = fortranOpts(); + + semanticsContext_ = std::make_unique<semantics::SemanticsContext>( + *(new Fortran::common::IntrinsicTypeDefaultKinds()), + fortranOptions.features, allCookedSources); + auto &moduleDirJ = moduleDir(); - semaCtxt.set_moduleDirectory(moduleDirJ) + semanticsContext_->set_moduleDirectory(moduleDirJ) .set_searchDirectories(fortranOptions.searchDirectories); - return; } |