From 93011fe2a5268aab9bf59e71b9d21a3818d1e199 Mon Sep 17 00:00:00 2001 From: Alexandros Lamprineas Date: Tue, 7 Jan 2025 08:51:23 +0000 Subject: [FMV][AArch64][clang] Emit fmv-features metadata in LLVM IR. (#118544) We need to be able to propagate information about FMV attribute strings from C/C++ source to LLVM IR. This is necessary so that we can distinguish which target-features are coming from the cmdline, which are coming from the target attribute, and which are coming from feature dependency expansion. We need this for static resolution of calls in LLVM. Here's a motivating example: Suppose you have target_version("i8mm+dotprod") and target_version("fcma"). The first version clearly has higher priority. Now suppose you specify -march=armv8-a+i8mm on the command line. Then the versions would have target-features "+i8mm,+dotprod" and "+i8mm,+fcma" respectively. If you are using those to deduce version priority, then you would incorrectly deduce that the second version was higher priority than the first. --- clang/lib/CodeGen/CodeGenModule.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index c49f763..5f15f0f 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2748,7 +2748,21 @@ bool CodeGenModule::GetCPUAndFeaturesAttributes(GlobalDecl GD, Attrs.addAttribute("target-features", llvm::join(Features, ",")); AddedAttr = true; } - + if (getTarget().getTriple().isAArch64()) { + llvm::SmallVector Feats; + if (TV) + TV->getFeatures(Feats); + else if (TC) + TC->getFeatures(Feats, GD.getMultiVersionIndex()); + if (!Feats.empty()) { + llvm::sort(Feats); + std::string FMVFeatures; + for (StringRef F : Feats) + FMVFeatures.append(",+" + F.str()); + Attrs.addAttribute("fmv-features", FMVFeatures.substr(1)); + AddedAttr = true; + } + } return AddedAttr; } -- cgit v1.1 From 8e65940161cd5a7dea5896fe4ae057d4cc07c703 Mon Sep 17 00:00:00 2001 From: Alexandros Lamprineas Date: Wed, 8 Jan 2025 18:59:07 +0000 Subject: [FMV][AArch64] Simplify version selection according to ACLE. (#121921) Currently, the more features a version has, the higher its priority is. We are changing ACLE https://github.com/ARM-software/acle/pull/370 as follows: "Among any two versions, the higher priority version is determined by identifying the highest priority feature that is specified in exactly one of the versions, and selecting that version." --- clang/lib/CodeGen/CodeGenModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 5f15f0f..7db1ed7 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4241,7 +4241,7 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) { static void ReplaceUsesOfNonProtoTypeWithRealFunction(llvm::GlobalValue *Old, llvm::Function *NewFn); -static unsigned getFMVPriority(const TargetInfo &TI, +static uint64_t getFMVPriority(const TargetInfo &TI, const CodeGenFunction::FMVResolverOption &RO) { llvm::SmallVector Features{RO.Features}; if (RO.Architecture) -- cgit v1.1