Skip to content

Commit

Permalink
[flang][Semantics] Add LangOptions to SemanticsContext
Browse files Browse the repository at this point in the history
The motivation for this is to make OpenMP settings visible
in the semantic checks (OpenMP version in particular).
  • Loading branch information
kparzysz committed Sep 25, 2024
1 parent cd9f0e1 commit cfbea65
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
10 changes: 8 additions & 2 deletions flang/include/flang/Semantics/semantics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -65,15 +66,19 @@ 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 {
return defaultKinds_;
}
const common::LanguageFeatureControl &languageFeatures() const {
return languageFeatures_;
};
}
const common::LangOptions &langOptions() const {
return langOpts_;
}
int GetDefaultKind(TypeCategory) const;
int doublePrecisionKind() const {
return defaultKinds_.doublePrecisionKind();
Expand Down Expand Up @@ -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_;
Expand Down
3 changes: 2 additions & 1 deletion flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,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)
Expand Down
3 changes: 2 additions & 1 deletion flang/lib/Semantics/semantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
18 changes: 17 additions & 1 deletion flang/tools/bbc/bbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -524,6 +525,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);
Expand Down Expand Up @@ -555,7 +571,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)
Expand Down

0 comments on commit cfbea65

Please sign in to comment.