craig.topper created this revision.
craig.topper added reviewers: echristo, erichkeane, nickdesaulniers.
Herald added a project: clang.
craig.topper requested review of this revision.
We can use this to remove some calls to initFeatureMap from Sema
and CodeGen when a function doesn't have a target attribute.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D85807
Files:
clang/include/clang/Basic/TargetOptions.h
clang/lib/AST/ASTContext.cpp
clang/lib/Basic/Targets.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -4948,11 +4948,7 @@
static CudaArch getCudaArch(CodeGenModule &CGM) {
if (!CGM.getTarget().hasFeature("ptx"))
return CudaArch::UNKNOWN;
- llvm::StringMap<bool> Features;
- CGM.getTarget().initFeatureMap(Features, CGM.getDiags(),
- CGM.getTarget().getTargetOpts().CPU,
- CGM.getTarget().getTargetOpts().Features);
- for (const auto &Feature : Features) {
+ for (const auto &Feature : CGM.getTarget().getTargetOpts().FeatureMap) {
if (Feature.getValue()) {
CudaArch Arch = StringToCudaArch(Feature.getKey());
if (Arch != CudaArch::UNKNOWN)
Index: clang/lib/Basic/Targets.cpp
===================================================================
--- clang/lib/Basic/Targets.cpp
+++ clang/lib/Basic/Targets.cpp
@@ -666,14 +666,13 @@
// Compute the default target features, we need the target to handle this
// because features may have dependencies on one another.
- llvm::StringMap<bool> Features;
- if (!Target->initFeatureMap(Features, Diags, Opts->CPU,
+ if (!Target->initFeatureMap(Opts->FeatureMap, Diags, Opts->CPU,
Opts->FeaturesAsWritten))
return nullptr;
// Add the features to the compile options.
Opts->Features.clear();
- for (const auto &F : Features)
+ for (const auto &F : Opts->FeatureMap)
Opts->Features.push_back((F.getValue() ? "+" : "-") + F.getKey().str());
// Sort here, so we handle the features in a predictable order. (This matters
// when we're dealing with features that overlap.)
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11186,8 +11186,7 @@
std::vector<std::string> Features(FeaturesTmp.begin(), FeaturesTmp.end());
Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features);
} else {
- Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU,
- Target->getTargetOpts().Features);
+ FeatureMap = Target->getTargetOpts().FeatureMap;
}
}
Index: clang/include/clang/Basic/TargetOptions.h
===================================================================
--- clang/include/clang/Basic/TargetOptions.h
+++ clang/include/clang/Basic/TargetOptions.h
@@ -54,6 +54,10 @@
/// be a list of strings starting with by '+' or '-'.
std::vector<std::string> Features;
+ /// The map of which features have been enabled disabled based on the command
+ /// line.
+ llvm::StringMap<bool> FeatureMap;
+
/// Supported OpenCL extensions and optional core features.
OpenCLOptions SupportedOpenCLOptions;
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -4948,11 +4948,7 @@
static CudaArch getCudaArch(CodeGenModule &CGM) {
if (!CGM.getTarget().hasFeature("ptx"))
return CudaArch::UNKNOWN;
- llvm::StringMap<bool> Features;
- CGM.getTarget().initFeatureMap(Features, CGM.getDiags(),
- CGM.getTarget().getTargetOpts().CPU,
- CGM.getTarget().getTargetOpts().Features);
- for (const auto &Feature : Features) {
+ for (const auto &Feature : CGM.getTarget().getTargetOpts().FeatureMap) {
if (Feature.getValue()) {
CudaArch Arch = StringToCudaArch(Feature.getKey());
if (Arch != CudaArch::UNKNOWN)
Index: clang/lib/Basic/Targets.cpp
===================================================================
--- clang/lib/Basic/Targets.cpp
+++ clang/lib/Basic/Targets.cpp
@@ -666,14 +666,13 @@
// Compute the default target features, we need the target to handle this
// because features may have dependencies on one another.
- llvm::StringMap<bool> Features;
- if (!Target->initFeatureMap(Features, Diags, Opts->CPU,
+ if (!Target->initFeatureMap(Opts->FeatureMap, Diags, Opts->CPU,
Opts->FeaturesAsWritten))
return nullptr;
// Add the features to the compile options.
Opts->Features.clear();
- for (const auto &F : Features)
+ for (const auto &F : Opts->FeatureMap)
Opts->Features.push_back((F.getValue() ? "+" : "-") + F.getKey().str());
// Sort here, so we handle the features in a predictable order. (This matters
// when we're dealing with features that overlap.)
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11186,8 +11186,7 @@
std::vector<std::string> Features(FeaturesTmp.begin(), FeaturesTmp.end());
Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features);
} else {
- Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU,
- Target->getTargetOpts().Features);
+ FeatureMap = Target->getTargetOpts().FeatureMap;
}
}
Index: clang/include/clang/Basic/TargetOptions.h
===================================================================
--- clang/include/clang/Basic/TargetOptions.h
+++ clang/include/clang/Basic/TargetOptions.h
@@ -54,6 +54,10 @@
/// be a list of strings starting with by '+' or '-'.
std::vector<std::string> Features;
+ /// The map of which features have been enabled disabled based on the command
+ /// line.
+ llvm::StringMap<bool> FeatureMap;
+
/// Supported OpenCL extensions and optional core features.
OpenCLOptions SupportedOpenCLOptions;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits