Skip to content

Commit 2d01032

Browse files
topperczmodem
authored andcommitted
[Target] Cache the command line derived feature map in TargetOptions.
We can use this to remove some calls to initFeatureMap from Sema and CodeGen when a function doesn't have a target attribute. This reduces compile time of the linux kernel where this map is needed to diagnose some inline assembly constraints based on whether sse, avx, or avx512 is enabled. Differential Revision: https://reviews.llvm.org/D85807 (cherry picked from commit 5c1fe4e)
1 parent d9b3d75 commit 2d01032

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

clang/include/clang/Basic/TargetOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ class TargetOptions {
5454
/// be a list of strings starting with by '+' or '-'.
5555
std::vector<std::string> Features;
5656

57+
/// The map of which features have been enabled disabled based on the command
58+
/// line.
59+
llvm::StringMap<bool> FeatureMap;
60+
5761
/// Supported OpenCL extensions and optional core features.
5862
OpenCLOptions SupportedOpenCLOptions;
5963

clang/lib/AST/ASTContext.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11147,8 +11147,7 @@ void ASTContext::getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
1114711147
std::vector<std::string> Features(FeaturesTmp.begin(), FeaturesTmp.end());
1114811148
Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features);
1114911149
} else {
11150-
Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU,
11151-
Target->getTargetOpts().Features);
11150+
FeatureMap = Target->getTargetOpts().FeatureMap;
1115211151
}
1115311152
}
1115411153

clang/lib/Basic/Targets.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,13 @@ TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
662662

663663
// Compute the default target features, we need the target to handle this
664664
// because features may have dependencies on one another.
665-
llvm::StringMap<bool> Features;
666-
if (!Target->initFeatureMap(Features, Diags, Opts->CPU,
665+
if (!Target->initFeatureMap(Opts->FeatureMap, Diags, Opts->CPU,
667666
Opts->FeaturesAsWritten))
668667
return nullptr;
669668

670669
// Add the features to the compile options.
671670
Opts->Features.clear();
672-
for (const auto &F : Features)
671+
for (const auto &F : Opts->FeatureMap)
673672
Opts->Features.push_back((F.getValue() ? "+" : "-") + F.getKey().str());
674673
// Sort here, so we handle the features in a predictable order. (This matters
675674
// when we're dealing with features that overlap.)

clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4956,11 +4956,7 @@ bool CGOpenMPRuntimeNVPTX::hasAllocateAttributeForGlobalVar(const VarDecl *VD,
49564956
static CudaArch getCudaArch(CodeGenModule &CGM) {
49574957
if (!CGM.getTarget().hasFeature("ptx"))
49584958
return CudaArch::UNKNOWN;
4959-
llvm::StringMap<bool> Features;
4960-
CGM.getTarget().initFeatureMap(Features, CGM.getDiags(),
4961-
CGM.getTarget().getTargetOpts().CPU,
4962-
CGM.getTarget().getTargetOpts().Features);
4963-
for (const auto &Feature : Features) {
4959+
for (const auto &Feature : CGM.getTarget().getTargetOpts().FeatureMap) {
49644960
if (Feature.getValue()) {
49654961
CudaArch Arch = StringToCudaArch(Feature.getKey());
49664962
if (Arch != CudaArch::UNKNOWN)

0 commit comments

Comments
 (0)