Skip to content

Commit 5c1fe4e

Browse files
committed
[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
1 parent e3d38b7 commit 5c1fe4e

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
@@ -11186,8 +11186,7 @@ void ASTContext::getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
1118611186
std::vector<std::string> Features(FeaturesTmp.begin(), FeaturesTmp.end());
1118711187
Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features);
1118811188
} else {
11189-
Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU,
11190-
Target->getTargetOpts().Features);
11189+
FeatureMap = Target->getTargetOpts().FeatureMap;
1119111190
}
1119211191
}
1119311192

clang/lib/Basic/Targets.cpp

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

667667
// Compute the default target features, we need the target to handle this
668668
// because features may have dependencies on one another.
669-
llvm::StringMap<bool> Features;
670-
if (!Target->initFeatureMap(Features, Diags, Opts->CPU,
669+
if (!Target->initFeatureMap(Opts->FeatureMap, Diags, Opts->CPU,
671670
Opts->FeaturesAsWritten))
672671
return nullptr;
673672

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

clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4948,11 +4948,7 @@ bool CGOpenMPRuntimeGPU::hasAllocateAttributeForGlobalVar(const VarDecl *VD,
49484948
static CudaArch getCudaArch(CodeGenModule &CGM) {
49494949
if (!CGM.getTarget().hasFeature("ptx"))
49504950
return CudaArch::UNKNOWN;
4951-
llvm::StringMap<bool> Features;
4952-
CGM.getTarget().initFeatureMap(Features, CGM.getDiags(),
4953-
CGM.getTarget().getTargetOpts().CPU,
4954-
CGM.getTarget().getTargetOpts().Features);
4955-
for (const auto &Feature : Features) {
4951+
for (const auto &Feature : CGM.getTarget().getTargetOpts().FeatureMap) {
49564952
if (Feature.getValue()) {
49574953
CudaArch Arch = StringToCudaArch(Feature.getKey());
49584954
if (Arch != CudaArch::UNKNOWN)

0 commit comments

Comments
 (0)