diff options
author | Alexandros Lamprineas <alexandros.lamprineas@arm.com> | 2025-01-10 17:50:35 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-10 17:50:35 +0000 |
commit | b93ffa8e4a11b89a8da02f409139f2ea862aabf0 (patch) | |
tree | c52b67d32e4a6efd17fb9d9dbeb51af55f201a2b /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 6f53886a9a5e65136619ada7713f31942a1cc1fa (diff) | |
download | llvm-b93ffa8e4a11b89a8da02f409139f2ea862aabf0.zip llvm-b93ffa8e4a11b89a8da02f409139f2ea862aabf0.tar.gz llvm-b93ffa8e4a11b89a8da02f409139f2ea862aabf0.tar.bz2 |
[FMV][AArch64] Changes in fmv-features metadata. (#122192)
* We want the default version to have this attribute too otherwise it
becomes indistinguishable from non-versioned functions.
* We don't need the '+' unlike target-features which can negate. This
will allow using the parsing API of target_version/clones for the
metadata too.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 7db1ed7..dfb51b1 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -73,6 +73,7 @@ #include "llvm/TargetParser/X86TargetParser.h" #include "llvm/Transforms/Utils/BuildLibCalls.h" #include <optional> +#include <set> using namespace clang; using namespace CodeGen; @@ -2748,17 +2749,26 @@ bool CodeGenModule::GetCPUAndFeaturesAttributes(GlobalDecl GD, Attrs.addAttribute("target-features", llvm::join(Features, ",")); AddedAttr = true; } + // Add metadata for AArch64 Function Multi Versioning. if (getTarget().getTriple().isAArch64()) { llvm::SmallVector<StringRef, 8> Feats; - if (TV) + bool IsDefault = false; + if (TV) { + IsDefault = TV->isDefaultVersion(); TV->getFeatures(Feats); - else if (TC) + } else if (TC) { + IsDefault = TC->isDefaultVersion(GD.getMultiVersionIndex()); TC->getFeatures(Feats, GD.getMultiVersionIndex()); - if (!Feats.empty()) { - llvm::sort(Feats); + } + if (IsDefault) { + Attrs.addAttribute("fmv-features"); + AddedAttr = true; + } else if (!Feats.empty()) { + // Sort features and remove duplicates. + std::set<StringRef> OrderedFeats(Feats.begin(), Feats.end()); std::string FMVFeatures; - for (StringRef F : Feats) - FMVFeatures.append(",+" + F.str()); + for (StringRef F : OrderedFeats) + FMVFeatures.append("," + F.str()); Attrs.addAttribute("fmv-features", FMVFeatures.substr(1)); AddedAttr = true; } @@ -2800,6 +2810,7 @@ void CodeGenModule::setNonAliasAttributes(GlobalDecl GD, llvm::AttributeMask RemoveAttrs; RemoveAttrs.addAttribute("target-cpu"); RemoveAttrs.addAttribute("target-features"); + RemoveAttrs.addAttribute("fmv-features"); RemoveAttrs.addAttribute("tune-cpu"); F->removeFnAttrs(RemoveAttrs); F->addFnAttrs(Attrs); |