[llvm-branch-commits] [flang] [flang][Semantics] Add LangOptions to SemanticsContext (PR #110013)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Sep 25 09:48:05 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
@llvm/pr-subscribers-flang-driver
Author: Krzysztof Parzyszek (kparzysz)
<details>
<summary>Changes</summary>
The motivation for this is to make OpenMP settings visible in the semantic checks (OpenMP version in particular).
---
Full diff: https://github.com/llvm/llvm-project/pull/110013.diff
4 Files Affected:
- (modified) flang/include/flang/Semantics/semantics.h (+8-2)
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+2-1)
- (modified) flang/lib/Semantics/semantics.cpp (+2-1)
- (modified) flang/tools/bbc/bbc.cpp (+17-1)
``````````diff
diff --git a/flang/include/flang/Semantics/semantics.h b/flang/include/flang/Semantics/semantics.h
index e73f9d2e85d589..4ea9f9e081b701 100644
--- a/flang/include/flang/Semantics/semantics.h
+++ b/flang/include/flang/Semantics/semantics.h
@@ -12,6 +12,7 @@
#include "scope.h"
#include "symbol.h"
#include "flang/Common/Fortran-features.h"
+#include "flang/Common/LangOptions.h"
#include "flang/Evaluate/common.h"
#include "flang/Evaluate/intrinsics.h"
#include "flang/Evaluate/target.h"
@@ -65,7 +66,8 @@ using ConstructStack = std::vector<ConstructNode>;
class SemanticsContext {
public:
SemanticsContext(const common::IntrinsicTypeDefaultKinds &,
- const common::LanguageFeatureControl &, parser::AllCookedSources &);
+ const common::LanguageFeatureControl &, const common::LangOptions &,
+ parser::AllCookedSources &);
~SemanticsContext();
const common::IntrinsicTypeDefaultKinds &defaultKinds() const {
@@ -73,7 +75,10 @@ class SemanticsContext {
}
const common::LanguageFeatureControl &languageFeatures() const {
return languageFeatures_;
- };
+ }
+ const common::LangOptions &langOptions() const {
+ return langOpts_;
+ }
int GetDefaultKind(TypeCategory) const;
int doublePrecisionKind() const {
return defaultKinds_.doublePrecisionKind();
@@ -273,6 +278,7 @@ class SemanticsContext {
const common::IntrinsicTypeDefaultKinds &defaultKinds_;
const common::LanguageFeatureControl &languageFeatures_;
+ const common::LangOptions &langOpts_;
parser::AllCookedSources &allCookedSources_;
std::optional<parser::CharBlock> location_;
std::vector<std::string> searchDirectories_;
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 52ca9f61c56f74..05b03ba9ebdf30 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1531,7 +1531,8 @@ CompilerInvocation::getSemanticsCtx(
auto &fortranOptions = getFortranOpts();
auto semanticsContext = std::make_unique<semantics::SemanticsContext>(
- getDefaultKinds(), fortranOptions.features, allCookedSources);
+ getDefaultKinds(), fortranOptions.features, getLangOpts(),
+ allCookedSources);
semanticsContext->set_moduleDirectory(getModuleDir())
.set_searchDirectories(fortranOptions.searchDirectories)
diff --git a/flang/lib/Semantics/semantics.cpp b/flang/lib/Semantics/semantics.cpp
index 8592d1e5d6217e..1f2980b07b3e0e 100644
--- a/flang/lib/Semantics/semantics.cpp
+++ b/flang/lib/Semantics/semantics.cpp
@@ -348,9 +348,10 @@ class CommonBlockMap {
SemanticsContext::SemanticsContext(
const common::IntrinsicTypeDefaultKinds &defaultKinds,
const common::LanguageFeatureControl &languageFeatures,
+ const common::LangOptions &langOpts,
parser::AllCookedSources &allCookedSources)
: defaultKinds_{defaultKinds}, languageFeatures_{languageFeatures},
- allCookedSources_{allCookedSources},
+ langOpts_{langOpts}, allCookedSources_{allCookedSources},
intrinsics_{evaluate::IntrinsicProcTable::Configure(defaultKinds_)},
globalScope_{*this}, intrinsicModulesScope_{globalScope_.MakeScope(
Scope::Kind::IntrinsicModules, nullptr)},
diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index dcff4503f16571..2a976d5a52fae6 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -15,6 +15,7 @@
//===----------------------------------------------------------------------===//
#include "flang/Common/Fortran-features.h"
+#include "flang/Common/LangOptions.h"
#include "flang/Common/OpenMP-features.h"
#include "flang/Common/Version.h"
#include "flang/Common/default-kinds.h"
@@ -507,6 +508,21 @@ int main(int argc, char **argv) {
options.predefinitions.emplace_back(
"__flang_patchlevel__"s, std::string{FLANG_VERSION_PATCHLEVEL_STRING});
+ Fortran::common::LangOptions langOpts;
+ langOpts.NoGPULib = setNoGPULib;
+ langOpts.OpenMPVersion = setOpenMPVersion;
+ langOpts.OpenMPIsTargetDevice = enableOpenMPDevice;
+ langOpts.OpenMPIsGPU = enableOpenMPGPU;
+ langOpts.OpenMPForceUSM = enableOpenMPForceUSM;
+ langOpts.OpenMPTargetDebug = setOpenMPTargetDebug;
+ langOpts.OpenMPThreadSubscription = setOpenMPThreadSubscription;
+ langOpts.OpenMPTeamSubscription = setOpenMPTeamSubscription;
+ langOpts.OpenMPNoThreadState = setOpenMPNoThreadState;
+ langOpts.OpenMPNoNestedParallelism = setOpenMPNoNestedParallelism;
+ std::transform(targetTriplesOpenMP.begin(), targetTriplesOpenMP.end(),
+ std::back_inserter(langOpts.OMPTargetTriples),
+ [](const std::string &str) { return llvm::Triple(str); });
+
// enable parsing of OpenMP
if (enableOpenMP) {
options.features.Enable(Fortran::common::LanguageFeature::OpenMP);
@@ -538,7 +554,7 @@ int main(int argc, char **argv) {
Fortran::parser::AllSources allSources;
Fortran::parser::AllCookedSources allCookedSources(allSources);
Fortran::semantics::SemanticsContext semanticsContext{
- defaultKinds, options.features, allCookedSources};
+ defaultKinds, options.features, langOpts, allCookedSources};
semanticsContext.set_moduleDirectory(moduleDir)
.set_moduleFileSuffix(moduleSuffix)
.set_searchDirectories(includeDirs)
``````````
</details>
https://github.com/llvm/llvm-project/pull/110013
More information about the llvm-branch-commits
mailing list