forked from OSchip/llvm-project
Fix a TODO dealing with canonicalizing attributes on functions by
using a string map to canonicalize. Fix up a couple of testcases that needed changing since we are no longer simply appending features to the list, but all of their mask dependencies as well. llvm-svn: 241129
This commit is contained in:
parent
4b6698917d
commit
2249b81697
|
@ -1493,12 +1493,16 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
|
||||||
// avoid putting features in the target-features set if we know it'll be
|
// avoid putting features in the target-features set if we know it'll be
|
||||||
// one of the default features in the backend, e.g. corei7-avx and +avx or
|
// one of the default features in the backend, e.g. corei7-avx and +avx or
|
||||||
// figure out non-explicit dependencies.
|
// figure out non-explicit dependencies.
|
||||||
std::vector<std::string> Features(getTarget().getTargetOpts().Features);
|
// Canonicalize the existing features in a new feature map.
|
||||||
|
// TODO: Migrate the existing backends to keep the map around rather than
|
||||||
|
// the vector.
|
||||||
|
llvm::StringMap<bool> FeatureMap;
|
||||||
|
for (auto F : getTarget().getTargetOpts().Features) {
|
||||||
|
const char *Name = F.c_str();
|
||||||
|
bool Enabled = Name[0] == '+';
|
||||||
|
getTarget().setFeatureEnabled(FeatureMap, Name + 1, Enabled);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: The target attribute complicates this further by allowing multiple
|
|
||||||
// additional features to be tacked on to the feature string for a
|
|
||||||
// particular function. For now we simply append to the set of features and
|
|
||||||
// let backend resolution fix them up.
|
|
||||||
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl);
|
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl);
|
||||||
if (FD) {
|
if (FD) {
|
||||||
if (const TargetAttr *TD = FD->getAttr<TargetAttr>()) {
|
if (const TargetAttr *TD = FD->getAttr<TargetAttr>()) {
|
||||||
|
@ -1507,7 +1511,7 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
|
||||||
FeaturesStr.split(AttrFeatures, ",");
|
FeaturesStr.split(AttrFeatures, ",");
|
||||||
|
|
||||||
// Grab the various features and prepend a "+" to turn on the feature to
|
// Grab the various features and prepend a "+" to turn on the feature to
|
||||||
// the backend and add them to our existing set of Features.
|
// the backend and add them to our existing set of features.
|
||||||
for (auto &Feature : AttrFeatures) {
|
for (auto &Feature : AttrFeatures) {
|
||||||
// While we're here iterating check for a different target cpu.
|
// While we're here iterating check for a different target cpu.
|
||||||
if (Feature.startswith("arch="))
|
if (Feature.startswith("arch="))
|
||||||
|
@ -1521,13 +1525,21 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
|
||||||
// attributes on the function.
|
// attributes on the function.
|
||||||
;
|
;
|
||||||
else if (Feature.startswith("mno-"))
|
else if (Feature.startswith("mno-"))
|
||||||
Features.push_back("-" + Feature.split("-").second.str());
|
getTarget().setFeatureEnabled(FeatureMap, Feature.split("-").second,
|
||||||
|
false);
|
||||||
else
|
else
|
||||||
Features.push_back("+" + Feature.str());
|
getTarget().setFeatureEnabled(FeatureMap, Feature, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Produce the canonical string for this set of features.
|
||||||
|
std::vector<std::string> Features;
|
||||||
|
for (llvm::StringMap<bool>::const_iterator it = FeatureMap.begin(),
|
||||||
|
ie = FeatureMap.end();
|
||||||
|
it != ie; ++it)
|
||||||
|
Features.push_back((it->second ? "+" : "-") + it->first().str());
|
||||||
|
|
||||||
// Now add the target-cpu and target-features to the function.
|
// Now add the target-cpu and target-features to the function.
|
||||||
if (TargetCPU != "")
|
if (TargetCPU != "")
|
||||||
FuncAttrs.addAttribute("target-cpu", TargetCPU);
|
FuncAttrs.addAttribute("target-cpu", TargetCPU);
|
||||||
|
|
|
@ -21,5 +21,5 @@ int bar(int a) { return baz(a) + foo(a); }
|
||||||
// CHECK: echidna{{.*}} #2
|
// CHECK: echidna{{.*}} #2
|
||||||
// CHECK: bar{{.*}} #0
|
// CHECK: bar{{.*}} #0
|
||||||
// CHECK: #0 = {{.*}}"target-cpu"="x86-64" "target-features"="+sse,+sse2"
|
// CHECK: #0 = {{.*}}"target-cpu"="x86-64" "target-features"="+sse,+sse2"
|
||||||
// CHECK: #1 = {{.*}}"target-cpu"="ivybridge" "target-features"="+sse,+sse2,+avx,+sse4.2"
|
// CHECK: #1 = {{.*}}"target-cpu"="ivybridge" "target-features"="+sse4.2,+ssse3,+sse3,+sse,+sse2,+sse4.1,+avx"
|
||||||
// CHECK: #2 = {{.*}}"target-cpu"="x86-64" "target-features"="+sse,+sse2,-sse2"
|
// CHECK: #2 = {{.*}}"target-cpu"="x86-64" "target-features"="-sse4a,-sse3,-avx2,-avx512bw,-avx512er,-avx512dq,-avx512pf,-fma4,-avx512vl,+sse,-pclmul,-avx512cd,-avx,-f16c,-ssse3,-avx512f,-fma,-xop,-aes,-sha,-sse2,-sse4.1,-sse4.2"
|
||||||
|
|
|
@ -17,7 +17,7 @@ void foo() {}
|
||||||
|
|
||||||
// AVX-FEATURE: "target-features"{{.*}}+avx
|
// AVX-FEATURE: "target-features"{{.*}}+avx
|
||||||
// AVX-NO-CPU-NOT: target-cpu
|
// AVX-NO-CPU-NOT: target-cpu
|
||||||
// TWO-AVX: "target-features"={{.*}}+avx512er{{.*}}+avx512f
|
// TWO-AVX: "target-features"={{.*}}+avx512f{{.*}}+avx512er
|
||||||
// CORE-CPU: "target-cpu"="corei7"
|
// CORE-CPU: "target-cpu"="corei7"
|
||||||
// CORE-CPU-AND-FEATURES: "target-cpu"="corei7" "target-features"={{.*}}+avx
|
// CORE-CPU-AND-FEATURES: "target-cpu"="corei7" "target-features"={{.*}}+avx
|
||||||
// X86-64-CPU: "target-cpu"="x86-64"
|
// X86-64-CPU: "target-cpu"="x86-64"
|
||||||
|
|
Loading…
Reference in New Issue