r366027 - [clang][Driver][ARM] Favor -mfpu over default CPU features

2019-07-14 Thread Alexandros Lamprineas via cfe-commits
Author: alelab01
Date: Sun Jul 14 11:32:42 2019
New Revision: 366027

URL: http://llvm.org/viewvc/llvm-project?rev=366027&view=rev
Log:
[clang][Driver][ARM] Favor -mfpu over default CPU features

When processing the command line options march, mcpu and mfpu, we store
the implied target features on a vector. The change D62998 introduced a
temporary vector, where the processed features get accumulated. When
calling DecodeARMFeaturesFromCPU, which sets the default features for
the specified CPU, we certainly don't want to override the features
that have been explicitly specified on the command line. Therefore, the
default features should appear first in the final vector. This problem
became evident once I added the missing (unhandled) target features in
ARM::getExtensionFeatures.

Differential Revision: https://reviews.llvm.org/D63936

Modified:
cfe/trunk/lib/Driver/ToolChains/Arch/ARM.cpp
cfe/trunk/test/CodeGen/arm-target-features.c

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/ARM.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/ARM.cpp?rev=366027&r1=366026&r2=366027&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/ARM.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/ARM.cpp Sun Jul 14 11:32:42 2019
@@ -376,7 +376,11 @@ void arm::getARMTargetFeatures(const Too
 Features.push_back(
 Args.MakeArgString((F.second ? "+" : "-") + F.first()));
   } else if (!CPUName.empty()) {
-DecodeARMFeaturesFromCPU(D, CPUName, ExtensionFeatures);
+// This sets the default features for the specified CPU. We certainly don't
+// want to override the features that have been explicitly specified on the
+// command line. Therefore, process them directly instead of appending them
+// at the end later.
+DecodeARMFeaturesFromCPU(D, CPUName, Features);
   }
 
   if (CPUArg)

Modified: cfe/trunk/test/CodeGen/arm-target-features.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-target-features.c?rev=366027&r1=366026&r2=366027&view=diff
==
--- cfe/trunk/test/CodeGen/arm-target-features.c (original)
+++ cfe/trunk/test/CodeGen/arm-target-features.c Sun Jul 14 11:32:42 2019
@@ -32,7 +32,7 @@
 
 // RUN: %clang_cc1 -triple thumbv8-linux-gnueabihf -target-cpu exynos-m4 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V82
 // RUN: %clang_cc1 -triple thumbv8-linux-gnueabihf -target-cpu exynos-m5 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V82
-// CHECK-BASIC-V82: 
"target-features"="+armv8.2-a,+crc,+crypto,+d32,+dotprod,+dsp,+fp-armv8,+fp-armv8d16,+fp-armv8d16sp,+fp-armv8sp,+fp16,+fp64,+fpregs,+hwdiv,+hwdiv-arm,+neon,+ras,+thumb-mode,+vfp2,+vfp2d16,+vfp2d16sp,+vfp2sp,+vfp3,+vfp3d16,+vfp3d16sp,+vfp3sp,+vfp4,+vfp4d16,+vfp4d16sp,+vfp4sp"
+// CHECK-BASIC-V82: 
"target-features"="+armv8.2-a,+crc,+crypto,+d32,+dotprod,+dsp,+fp-armv8,+fp-armv8d16,+fp-armv8d16sp,+fp-armv8sp,+fp16,+fp64,+fpregs,+fullfp16,+hwdiv,+hwdiv-arm,+neon,+ras,+thumb-mode,+vfp2,+vfp2d16,+vfp2d16sp,+vfp2sp,+vfp3,+vfp3d16,+vfp3d16sp,+vfp3sp,+vfp4,+vfp4d16,+vfp4d16sp,+vfp4sp"
 
 // RUN: %clang_cc1 -triple armv8-linux-gnueabi -target-cpu cortex-a53 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V8-ARM
 // CHECK-BASIC-V8-ARM: 
"target-features"="+armv8-a,+crc,+crypto,+d32,+dsp,+fp-armv8,+fp-armv8d16,+fp-armv8d16sp,+fp-armv8sp,+fp16,+fp64,+fpregs,+hwdiv,+hwdiv-arm,+neon,+vfp2,+vfp2d16,+vfp2d16sp,+vfp2sp,+vfp3,+vfp3d16,+vfp3d16sp,+vfp3sp,+vfp4,+vfp4d16,+vfp4d16sp,+vfp4sp,-thumb-mode"


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r366031 - [TargetParser][ARM] Account dependencies when processing target features

2019-07-14 Thread Alexandros Lamprineas via cfe-commits
Author: alelab01
Date: Sun Jul 14 13:31:15 2019
New Revision: 366031

URL: http://llvm.org/viewvc/llvm-project?rev=366031&view=rev
Log:
[TargetParser][ARM] Account dependencies when processing target features

Teaches ARM::appendArchExtFeatures to account dependencies when processing
target features: i.e. when you say -march=armv8.1-m.main+mve.fp+nofp it
means mve.fp should get discarded too. (Split from D63936)

Differential Revision: https://reviews.llvm.org/D64048

Modified:
cfe/trunk/test/Preprocessor/arm-target-features.c

Modified: cfe/trunk/test/Preprocessor/arm-target-features.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/arm-target-features.c?rev=366031&r1=366030&r2=366031&view=diff
==
--- cfe/trunk/test/Preprocessor/arm-target-features.c (original)
+++ cfe/trunk/test/Preprocessor/arm-target-features.c Sun Jul 14 13:31:15 2019
@@ -762,12 +762,29 @@
 // CHECK-V81M-MVE: #define __ARM_FEATURE_MVE 1
 // CHECK-V81M-MVE: #define __ARM_FEATURE_SIMD32 1
 
-// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp -x c -E 
-dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVE-FP %s
-// CHECK-V81M-MVE-FP: #define __ARM_FEATURE_DSP 1
-// CHECK-V81M-MVE-FP: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1
-// CHECK-V81M-MVE-FP: #define __ARM_FEATURE_MVE 3
-// CHECK-V81M-MVE-FP: #define __ARM_FEATURE_SIMD32 1
-// CHECK-V81M-MVE-FP: #define __ARM_FPV5__ 1
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp -x c -E 
-dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVEFP %s
+// CHECK-V81M-MVEFP: #define __ARM_FEATURE_DSP 1
+// CHECK-V81M-MVEFP: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1
+// CHECK-V81M-MVEFP: #define __ARM_FEATURE_MVE 3
+// CHECK-V81M-MVEFP: #define __ARM_FEATURE_SIMD32 1
+// CHECK-V81M-MVEFP: #define __ARM_FPV5__ 1
+
+// nofp discards mve.fp
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp+nofp -x 
c -E -dM %s -o - | FileCheck -match-full-lines 
--check-prefix=CHECK-V81M-MVEFP-NOFP %s
+// CHECK-V81M-MVEFP-NOFP-NOT: #define __ARM_FEATURE_MVE
+
+// nomve discards mve.fp
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve.fp+nomve -x 
c -E -dM %s -o - | FileCheck -match-full-lines 
--check-prefix=CHECK-V81M-MVEFP-NOMVE %s
+// CHECK-V81M-MVEFP-NOMVE-NOT: #define __ARM_FEATURE_MVE
+
+// mve+fp doesn't imply mve.fp
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve+fp -x c -E 
-dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81M-MVE-FP %s
+// CHECK-V81M-MVE-FP: #define __ARM_FEATURE_MVE 1
+
+// nodsp discards both dsp and mve
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main+mve+nodsp -x c 
-E -dM %s -o - | FileCheck -match-full-lines 
--check-prefix=CHECK-V81M-MVE-NODSP %s
+// CHECK-V81M-MVE-NODSP-NOT: #define __ARM_FEATURE_MVE
+// CHECK-V81M-MVE-NODSP-NOT: #define __ARM_FEATURE_DSP
 
 // RUN: %clang -target armv8.1a-none-none-eabi -x c -E -dM %s -o - | FileCheck 
-match-full-lines --check-prefix=CHECK-V81A %s
 // CHECK-V81A: #define __ARM_ARCH 8


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r364895 - [clang][Driver][ARM] NFC: Remove unused function parameter

2019-07-02 Thread Alexandros Lamprineas via cfe-commits
Author: alelab01
Date: Tue Jul  2 02:45:24 2019
New Revision: 364895

URL: http://llvm.org/viewvc/llvm-project?rev=364895&view=rev
Log:
[clang][Driver][ARM] NFC: Remove unused function parameter

Removes a vector reference that was added by D62998, since the
preexisting function parameter is sufficient.

Differential Revision: https://reviews.llvm.org/D64044

Modified:
cfe/trunk/lib/Driver/ToolChains/Arch/ARM.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/ARM.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/ARM.cpp?rev=364895&r1=364894&r2=364895&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/ARM.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/ARM.cpp Tue Jul  2 02:45:24 2019
@@ -100,7 +100,6 @@ static void DecodeARMFeaturesFromCPU(con
 static void checkARMArchName(const Driver &D, const Arg *A, const ArgList 
&Args,
  llvm::StringRef ArchName, llvm::StringRef CPUName,
  std::vector &Features,
- std::vector &ExtensionFeatures,
  const llvm::Triple &Triple) {
   std::pair Split = ArchName.split("+");
 
@@ -108,7 +107,7 @@ static void checkARMArchName(const Drive
   llvm::ARM::ArchKind ArchKind = llvm::ARM::parseArch(MArch);
   if (ArchKind == llvm::ARM::ArchKind::INVALID ||
   (Split.second.size() && !DecodeARMFeatures(
-D, Split.second, CPUName, ArchKind, ExtensionFeatures)))
+D, Split.second, CPUName, ArchKind, Features)))
 D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
 }
 
@@ -116,7 +115,6 @@ static void checkARMArchName(const Drive
 static void checkARMCPUName(const Driver &D, const Arg *A, const ArgList &Args,
 llvm::StringRef CPUName, llvm::StringRef ArchName,
 std::vector &Features,
-std::vector &ExtensionFeatures,
 const llvm::Triple &Triple) {
   std::pair Split = CPUName.split("+");
 
@@ -125,7 +123,7 @@ static void checkARMCPUName(const Driver
 arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
   if (ArchKind == llvm::ARM::ArchKind::INVALID ||
   (Split.second.size() && !DecodeARMFeatures(
-D, Split.second, CPU, ArchKind, ExtensionFeatures)))
+D, Split.second, CPU, ArchKind, Features)))
 D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
 }
 
@@ -361,13 +359,13 @@ void arm::getARMTargetFeatures(const Too
   << ArchArg->getAsString(Args);
 ArchName = StringRef(WaArch->getValue()).substr(7);
 checkARMArchName(D, WaArch, Args, ArchName, CPUName,
- Features, ExtensionFeatures, Triple);
+ ExtensionFeatures, Triple);
 // FIXME: Set Arch.
 D.Diag(clang::diag::warn_drv_unused_argument) << WaArch->getAsString(Args);
   } else if (ArchArg) {
 ArchName = ArchArg->getValue();
 checkARMArchName(D, ArchArg, Args, ArchName, CPUName,
- Features, ExtensionFeatures, Triple);
+ ExtensionFeatures, Triple);
   }
 
   // Add CPU features for generic CPUs
@@ -383,7 +381,7 @@ void arm::getARMTargetFeatures(const Too
 
   if (CPUArg)
 checkARMCPUName(D, CPUArg, Args, CPUName, ArchName,
-Features, ExtensionFeatures, Triple);
+ExtensionFeatures, Triple);
   // Honor -mfpu=. ClangAs gives preference to -Wa,-mfpu=.
   const Arg *FPUArg = Args.getLastArg(options::OPT_mfpu_EQ);
   if (WaFPU) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libc] [libcxx] [llvm] [clang] [flang] [clang-tools-extra] [compiler-rt] [LAA] Add a test case to show incorrect dependency classification (NFC). (PR #70473)

2023-10-31 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/70473

>From 454d423f0018db65dbbc0739ddf9ecbb8d38fef6 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Fri, 27 Oct 2023 16:45:11 +0100
Subject: [PATCH] [LAA] Add a test case to show incorrect dependency
 classification (NFC).

Currently the loop access analysis classifies this loop as unsafe to vectorize
because the memory dependencies are 'ForwardButPreventsForwarding'. However,
the access pattern is 'write-after-read' with no subsequent read accessing
the written memory locations. I can't see how store-to-load forwarding is
applicable here.

void vectorizable_Read_Write(int *A) {
  for (unsigned i = 1022; i >= 0; i--)
A[i+1] = A[i] + 1;
}
---
 .../forward-negative-step.ll  | 40 +++
 1 file changed, 40 insertions(+)
 create mode 100644 
llvm/test/Analysis/LoopAccessAnalysis/forward-negative-step.ll

diff --git a/llvm/test/Analysis/LoopAccessAnalysis/forward-negative-step.ll 
b/llvm/test/Analysis/LoopAccessAnalysis/forward-negative-step.ll
new file mode 100644
index 000..89c1737fb730513
--- /dev/null
+++ b/llvm/test/Analysis/LoopAccessAnalysis/forward-negative-step.ll
@@ -0,0 +1,40 @@
+; RUN: opt -passes='print' -disable-output  < %s 2>&1 | FileCheck 
%s
+
+target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
+
+; FIXME: This should be vectorizable
+
+; void vectorizable_Read_Write(int *A) {
+;  for (unsigned i = 1022; i >= 0; i--)
+;A[i+1] = A[i] + 1;
+; }
+
+; CHECK: function 'vectorizable_Read_Write':
+; CHECK-NEXT:   for.body:
+; CHECK-NEXT: Report: unsafe dependent memory operations in loop
+; CHECK-NEXT: Forward loop carried data dependence that prevents 
store-to-load forwarding.
+; CHECK-NEXT: Dependences:
+; CHECK-NEXT:   ForwardButPreventsForwarding:
+; CHECK-NEXT:   %0 = load i32, ptr %arrayidx, align 4 ->
+; CHECK-NEXT:   store i32 %add, ptr %gep, align 4
+
+define void @vectorizable_Read_Write(ptr nocapture %A) {
+entry:
+  %invariant.gep = getelementptr i32, ptr %A, i64 1
+  br label %for.body
+
+for.cond.cleanup:
+  ret void
+
+for.body:
+  %indvars.iv = phi i64 [ 1022, %entry ], [ %indvars.iv.next, %for.body ]
+  %arrayidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
+  %0 = load i32, ptr %arrayidx, align 4
+  %add = add nsw i32 %0, 1
+  %gep = getelementptr i32, ptr %invariant.gep, i64 %indvars.iv
+  store i32 %add, ptr %gep, align 4
+  %indvars.iv.next = add nsw i64 %indvars.iv, -1
+  %cmp.not = icmp eq i64 %indvars.iv, 0
+  br i1 %cmp.not, label %for.cond.cleanup, label %for.body
+}
+

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-14 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/84405

>From bde335c2b4a85ee5e7f57ff9081c38b4dd9839ca Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 7 Mar 2024 22:25:13 +
Subject: [PATCH] [FMV] Emit the resolver along with the default version
 definition.

We would like the resolver to be generated eagerly, even if the
versioned function is not called from the current translation
unit. Fixes #81494. It further allows Multi Versioning to work
even if the default target version attribute is omitted from
function declarations.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  54 +-
 clang/lib/CodeGen/CodeGenModule.h |   5 +
 clang/test/CodeGen/attr-target-version.c  | 550 +-
 clang/test/CodeGenCXX/attr-target-version.cpp | 261 +++--
 4 files changed, 651 insertions(+), 219 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 8ceecff28cbc63..3a969f37f51ac3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3447,6 +3447,9 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl 
*Global) {
   // Implicit template instantiations may change linkage if they are later
   // explicitly instantiated, so they should not be emitted eagerly.
   return false;
+// Defer until all versions have been semantically checked.
+if (FD->hasAttr() && !FD->isMultiVersion())
+  return false;
   }
   if (const auto *VD = dyn_cast(Global)) {
 if (Context.getInlineVariableDefinitionKind(VD) ==
@@ -3995,10 +3998,13 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
 // Ensure that the resolver function is also emitted.
 GetOrCreateMultiVersionResolver(GD);
-  } else if (FD->hasAttr()) {
-GetOrCreateMultiVersionResolver(GD);
   } else
 EmitGlobalFunctionDefinition(GD, GV);
+
+  // Defer the resolver emission until we can reason whether the TU
+  // contains a default target version implementation.
+  if (FD->isTargetVersionMultiVersion())
+AddDeferredMultiVersionResolverToEmit(GD);
 }
 
 void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) 
{
@@ -4091,10 +4097,11 @@ void CodeGenModule::emitMultiVersionFunctions() {
 const auto *FD = cast(GD.getDecl());
 assert(FD && "Expected a FunctionDecl");
 
+bool EmitResolver = !FD->isTargetVersionMultiVersion();
 SmallVector Options;
 if (FD->isTargetMultiVersion()) {
   getContext().forEachMultiversionedFunctionVersion(
-  FD, [this, &GD, &Options](const FunctionDecl *CurFD) {
+  FD, [this, &GD, &Options, &EmitResolver](const FunctionDecl *CurFD) {
 GlobalDecl CurGD{
 (CurFD->isDefined() ? CurFD->getDefinition() : CurFD)};
 StringRef MangledName = getMangledName(CurGD);
@@ -4120,6 +4127,9 @@ void CodeGenModule::emitMultiVersionFunctions() {
TA->getArchitecture(), Feats);
 } else {
   const auto *TVA = CurFD->getAttr();
+  if (TVA->isDefaultVersion() &&
+  CurFD->doesThisDeclarationHaveABody())
+EmitResolver = true;
   llvm::SmallVector Feats;
   TVA->getFeatures(Feats);
   Options.emplace_back(cast(Func),
@@ -4175,22 +4185,27 @@ void CodeGenModule::emitMultiVersionFunctions() {
   continue;
 }
 
+if (!EmitResolver)
+  continue;
+
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
   if (FD->isTargetClonesMultiVersion() ||
   FD->isTargetVersionMultiVersion()) {
-const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
-llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
 *this, GD, FD, /*OmitMultiVersionMangling=*/true);
-// In prior versions of Clang, the mangling for ifuncs incorrectly
-// included an .ifunc suffix. This alias is generated for backward
-// compatibility. It is deprecated, and may be removed in the future.
-auto *Alias = llvm::GlobalAlias::create(
-DeclTy, 0, getMultiversionLinkage(*this, GD),
-MangledName + ".ifunc", IFunc, &getModule());
-SetCommonAttributes(FD, Alias);
+if (!GetGlobalValue(MangledName + ".ifunc")) {
+  const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
+  llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
+  // In prior versions of Clang, the mangling for ifuncs incorrectly
+  // included an .ifunc suffix. This alias is generated for backward
+  // compatibility. It is deprecated, and may b

[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-14 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

The key takeaway from my conversation with @DanielKristofKiss was that it is 
important for Function Multi Versioning to work even when the default target 
attribute is omitted. It was quite a headache to get this working in clang, but 
the latest revision supports the desired behavior. It also fixes the previously 
discovered bug I had mentioned in the test file.

https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits


@@ -4120,6 +4127,9 @@ void CodeGenModule::emitMultiVersionFunctions() {
TA->getArchitecture(), Feats);
 } else {
   const auto *TVA = CurFD->getAttr();
+  if (TVA->isDefaultVersion() &&
+  CurFD->doesThisDeclarationHaveABody())
+EmitResolver = true;
   llvm::SmallVector Feats;
   TVA->getFeatures(Feats);
   Options.emplace_back(cast(Func),

labrinea wrote:

It is initialized with `!FD->isTargetVersionMultiVersion()` so it is set to 
true for target clones. However I've just found a bug when we don't have a 
default definition but we do have a caller in the TU. In that case we should be 
checking `isUsed()` too. I'll fix this.

https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits


@@ -4347,6 +4362,19 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl 
GD) {
   }
 }
 
+/// Adds a declaration to the list of multi version functions if not present.
+void CodeGenModule::AddDeferredMultiVersionResolverToEmit(GlobalDecl GD) {
+  const auto *FD = cast(GD.getDecl());
+  assert(FD && "Not a FunctionDecl?");
+
+  if (FD->isTargetVersionMultiVersion()) {
+StringRef NamePrefix = getMangledName(GD).split('.').first;

labrinea wrote:

Initially I was using `FD->getName()` as the key here but this wouldn't work 
for C++ mangled names. `getMangledName()` internally calls 
`getMangledNameImpl()` which returns the multi versioned name (this would be 
"foo.bar.baz._Mlse" in you example). The key needs to be the prefix 
"foo.bar.baz" so that we don't push every multi version of "foo.bar.baz" in the 
list `MultiVersionFuncs` to be processed by `emitMultiVersionFunctions()`. This 
would generate a resolver body with multiple copies of the basic blocks 
corresponding to each version. Hmm, I am not sure how to handle this example 
properly, perhaps with `rsplit()`.

https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits


@@ -84,9 +84,33 @@ int hoo(void) {
   return fp1() + fp2();
 }
 
+// This should generate one target version but no resolver.
+__attribute__((target_version("default"))) int 
unused_with_forward_default_decl(void);
+__attribute__((target_version("mops"))) int 
unused_with_forward_default_decl(void) { return 0; }
 
+// This should also generate one target version but no resolver.
+extern int unused_with_implicit_extern_forward_default_decl(void);
+__attribute__((target_version("dotprod")))
+int unused_with_implicit_extern_forward_default_decl(void) { return 0; }
 
+// This should also generate one target version but no resolver.
+__attribute__((target_version("aes"))) int unused_with_default_decl(void) { 
return 0; }
+__attribute__((target_version("default"))) int unused_with_default_decl(void);
 
+// This should generate two target versions and the resolver.
+__attribute__((target_version("sve"))) int unused_with_default_def(void) { 
return 0; }
+__attribute__((target_version("default"))) int unused_with_default_def(void) { 
return 1; }
+
+// This should also generate two target versions and the resolver.
+__attribute__((target_version("fp16"))) int 
unused_with_implicit_default_def(void) { return 0; }
+int unused_with_implicit_default_def(void) { return 1; }
+
+// This should also generate two target versions and the resolver.
+int unused_with_implicit_forward_default_def(void) { return 0; }
+__attribute__((target_version("lse"))) int 
unused_with_implicit_forward_default_def(void) { return 1; }
+
+// This should generate a normal function.
+__attribute__((target_version("rdm"))) int unused_without_default(void) { 
return 0; }

labrinea wrote:

I do remember this use case from another review 
(https://godbolt.org/z/3zaM9MzPb) so I wanted to make sure we support it, which 
is the case! Now if we would further like to support multi versioning in the 
absense of default declaration (the header not included) that's a different 
story. I am not opposing, but will have to check how feasible it is to 
implement and what do the rest of the stakeholders think about it.

https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits


@@ -4347,6 +4362,19 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl 
GD) {
   }
 }
 
+/// Adds a declaration to the list of multi version functions if not present.
+void CodeGenModule::AddDeferredMultiVersionResolverToEmit(GlobalDecl GD) {
+  const auto *FD = cast(GD.getDecl());
+  assert(FD && "Not a FunctionDecl?");
+
+  if (FD->isTargetVersionMultiVersion()) {
+StringRef NamePrefix = getMangledName(GD).split('.').first;

labrinea wrote:

I tried experimenting with __asm__ but couldn't construct a sensible example in 
regards to multi versioning. Can you please show me?

https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits


@@ -4347,6 +4362,19 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl 
GD) {
   }
 }
 
+/// Adds a declaration to the list of multi version functions if not present.
+void CodeGenModule::AddDeferredMultiVersionResolverToEmit(GlobalDecl GD) {
+  const auto *FD = cast(GD.getDecl());
+  assert(FD && "Not a FunctionDecl?");
+
+  if (FD->isTargetVersionMultiVersion()) {
+StringRef NamePrefix = getMangledName(GD).split('.').first;

labrinea wrote:

As far as I can tell `target_version` and `asm` cannot be combined according to 
clang's semantic checker, therefore a function declaration which has been 
renamed via `asm` cannot reach `AddDeferredMultiVersionResolverToEmit()`. In 
any case I will use `rsplit()` instead.

https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits


@@ -84,9 +84,33 @@ int hoo(void) {
   return fp1() + fp2();
 }
 
+// This should generate one target version but no resolver.
+__attribute__((target_version("default"))) int 
unused_with_forward_default_decl(void);
+__attribute__((target_version("mops"))) int 
unused_with_forward_default_decl(void) { return 0; }
 
+// This should also generate one target version but no resolver.
+extern int unused_with_implicit_extern_forward_default_decl(void);
+__attribute__((target_version("dotprod")))
+int unused_with_implicit_extern_forward_default_decl(void) { return 0; }
 
+// This should also generate one target version but no resolver.
+__attribute__((target_version("aes"))) int unused_with_default_decl(void) { 
return 0; }
+__attribute__((target_version("default"))) int unused_with_default_decl(void);
 
+// This should generate two target versions and the resolver.
+__attribute__((target_version("sve"))) int unused_with_default_def(void) { 
return 0; }
+__attribute__((target_version("default"))) int unused_with_default_def(void) { 
return 1; }
+
+// This should also generate two target versions and the resolver.
+__attribute__((target_version("fp16"))) int 
unused_with_implicit_default_def(void) { return 0; }
+int unused_with_implicit_default_def(void) { return 1; }
+
+// This should also generate two target versions and the resolver.
+int unused_with_implicit_forward_default_def(void) { return 0; }
+__attribute__((target_version("lse"))) int 
unused_with_implicit_forward_default_def(void) { return 1; }
+
+// This should generate a normal function.
+__attribute__((target_version("rdm"))) int unused_without_default(void) { 
return 0; }

labrinea wrote:

Anyway, I think this has to do with semantics so it's unrelated to this patch 
and deserves a separate review if pursued. A quick glance in 
`clang/lib/Sema/SemaDecl.cpp` suggests that in order to fix it we'd have to 
remove the early exit in `CheckMultiVersionFirstFunction()`. Let's keep it in 
mind. 

https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/84405

>From 2576857fe4b5c0b99c1a29c07f92c80498687665 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 7 Mar 2024 22:25:13 +
Subject: [PATCH] [FMV] Emit the resolver along with the default version
 definition.

We would like the resolver to be generated eagerly, even if the
versioned function is not called from the current translation
unit. Fixes #81494. It further allows Multi Versioning to work
even if the default target version attribute is omitted from
function declarations.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  54 +-
 clang/lib/CodeGen/CodeGenModule.h |   5 +
 clang/test/CodeGen/attr-target-version.c  | 546 --
 clang/test/CodeGenCXX/attr-target-version.cpp | 261 +++--
 4 files changed, 628 insertions(+), 238 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 8ceecff28cbc63..ae47e4f1f1eed3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3447,6 +3447,9 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl 
*Global) {
   // Implicit template instantiations may change linkage if they are later
   // explicitly instantiated, so they should not be emitted eagerly.
   return false;
+// Defer until all versions have been semantically checked.
+if (FD->hasAttr() && !FD->isMultiVersion())
+  return false;
   }
   if (const auto *VD = dyn_cast(Global)) {
 if (Context.getInlineVariableDefinitionKind(VD) ==
@@ -3995,10 +3998,13 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
 // Ensure that the resolver function is also emitted.
 GetOrCreateMultiVersionResolver(GD);
-  } else if (FD->hasAttr()) {
-GetOrCreateMultiVersionResolver(GD);
   } else
 EmitGlobalFunctionDefinition(GD, GV);
+
+  // Defer the resolver emission until we can reason whether the TU
+  // contains a default target version implementation.
+  if (FD->isTargetVersionMultiVersion())
+AddDeferredMultiVersionResolverToEmit(GD);
 }
 
 void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) 
{
@@ -4091,10 +4097,11 @@ void CodeGenModule::emitMultiVersionFunctions() {
 const auto *FD = cast(GD.getDecl());
 assert(FD && "Expected a FunctionDecl");
 
+bool EmitResolver = !FD->isTargetVersionMultiVersion();
 SmallVector Options;
 if (FD->isTargetMultiVersion()) {
   getContext().forEachMultiversionedFunctionVersion(
-  FD, [this, &GD, &Options](const FunctionDecl *CurFD) {
+  FD, [this, &GD, &Options, &EmitResolver](const FunctionDecl *CurFD) {
 GlobalDecl CurGD{
 (CurFD->isDefined() ? CurFD->getDefinition() : CurFD)};
 StringRef MangledName = getMangledName(CurGD);
@@ -4120,6 +4127,9 @@ void CodeGenModule::emitMultiVersionFunctions() {
TA->getArchitecture(), Feats);
 } else {
   const auto *TVA = CurFD->getAttr();
+  if (CurFD->isUsed() || (TVA->isDefaultVersion() &&
+  CurFD->doesThisDeclarationHaveABody()))
+EmitResolver = true;
   llvm::SmallVector Feats;
   TVA->getFeatures(Feats);
   Options.emplace_back(cast(Func),
@@ -4175,22 +4185,27 @@ void CodeGenModule::emitMultiVersionFunctions() {
   continue;
 }
 
+if (!EmitResolver)
+  continue;
+
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
   if (FD->isTargetClonesMultiVersion() ||
   FD->isTargetVersionMultiVersion()) {
-const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
-llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
 *this, GD, FD, /*OmitMultiVersionMangling=*/true);
-// In prior versions of Clang, the mangling for ifuncs incorrectly
-// included an .ifunc suffix. This alias is generated for backward
-// compatibility. It is deprecated, and may be removed in the future.
-auto *Alias = llvm::GlobalAlias::create(
-DeclTy, 0, getMultiversionLinkage(*this, GD),
-MangledName + ".ifunc", IFunc, &getModule());
-SetCommonAttributes(FD, Alias);
+if (!GetGlobalValue(MangledName + ".ifunc")) {
+  const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
+  llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
+  // In prior versions of Clang, the mangling for ifuncs incorrectly
+  // included an .ifunc suffix. This alias is generated for backward
+  // compatibility. It is 

[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits


@@ -4347,6 +4362,19 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl 
GD) {
   }
 }
 
+/// Adds a declaration to the list of multi version functions if not present.
+void CodeGenModule::AddDeferredMultiVersionResolverToEmit(GlobalDecl GD) {
+  const auto *FD = cast(GD.getDecl());
+  assert(FD && "Not a FunctionDecl?");
+
+  if (FD->isTargetVersionMultiVersion()) {
+StringRef NamePrefix = getMangledName(GD).split('.').first;

labrinea wrote:

Right, I see. I've just thought of another issue with `getMangledNameImpl()`. 
Even though it would be more reliable to not split strings, we can't use its 
return value (std::string) as the key to a DenseSet. But let me double check it.

https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits


@@ -4347,6 +4362,19 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl 
GD) {
   }
 }
 
+/// Adds a declaration to the list of multi version functions if not present.
+void CodeGenModule::AddDeferredMultiVersionResolverToEmit(GlobalDecl GD) {
+  const auto *FD = cast(GD.getDecl());
+  assert(FD && "Not a FunctionDecl?");
+
+  if (FD->isTargetVersionMultiVersion()) {
+StringRef NamePrefix = getMangledName(GD).split('.').first;

labrinea wrote:

Surprisingly it didn't seem necessary. I inserted the std::string to the 
DenseSet (which still expects a StringRef) and I am now running the Address 
sanitizer just to be sure :D

https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits


@@ -4347,6 +4362,19 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl 
GD) {
   }
 }
 
+/// Adds a declaration to the list of multi version functions if not present.
+void CodeGenModule::AddDeferredMultiVersionResolverToEmit(GlobalDecl GD) {
+  const auto *FD = cast(GD.getDecl());
+  assert(FD && "Not a FunctionDecl?");
+
+  if (FD->isTargetVersionMultiVersion()) {
+StringRef NamePrefix = getMangledName(GD).split('.').first;

labrinea wrote:

Nopes, it didn't like it!

https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/84405

>From 6a495010024b93bb8871eebe6e10c62d1f5d2fc5 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 7 Mar 2024 22:25:13 +
Subject: [PATCH] [FMV] Emit the resolver along with the default version
 definition.

We would like the resolver to be generated eagerly, even if the
versioned function is not called from the current translation
unit. Fixes #81494. It further allows Multi Versioning to work
even if the default target version attribute is omitted from
function declarations.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  55 +-
 clang/lib/CodeGen/CodeGenModule.h |   5 +
 clang/test/CodeGen/attr-target-version.c  | 546 --
 clang/test/CodeGenCXX/attr-target-version.cpp | 261 +++--
 4 files changed, 629 insertions(+), 238 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 8ceecff28cbc63..a5eb46277d5f63 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3447,6 +3447,9 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl 
*Global) {
   // Implicit template instantiations may change linkage if they are later
   // explicitly instantiated, so they should not be emitted eagerly.
   return false;
+// Defer until all versions have been semantically checked.
+if (FD->hasAttr() && !FD->isMultiVersion())
+  return false;
   }
   if (const auto *VD = dyn_cast(Global)) {
 if (Context.getInlineVariableDefinitionKind(VD) ==
@@ -3995,10 +3998,13 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
 // Ensure that the resolver function is also emitted.
 GetOrCreateMultiVersionResolver(GD);
-  } else if (FD->hasAttr()) {
-GetOrCreateMultiVersionResolver(GD);
   } else
 EmitGlobalFunctionDefinition(GD, GV);
+
+  // Defer the resolver emission until we can reason whether the TU
+  // contains a default target version implementation.
+  if (FD->isTargetVersionMultiVersion())
+AddDeferredMultiVersionResolverToEmit(GD);
 }
 
 void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) 
{
@@ -4091,10 +4097,11 @@ void CodeGenModule::emitMultiVersionFunctions() {
 const auto *FD = cast(GD.getDecl());
 assert(FD && "Expected a FunctionDecl");
 
+bool EmitResolver = !FD->isTargetVersionMultiVersion();
 SmallVector Options;
 if (FD->isTargetMultiVersion()) {
   getContext().forEachMultiversionedFunctionVersion(
-  FD, [this, &GD, &Options](const FunctionDecl *CurFD) {
+  FD, [this, &GD, &Options, &EmitResolver](const FunctionDecl *CurFD) {
 GlobalDecl CurGD{
 (CurFD->isDefined() ? CurFD->getDefinition() : CurFD)};
 StringRef MangledName = getMangledName(CurGD);
@@ -4120,6 +4127,9 @@ void CodeGenModule::emitMultiVersionFunctions() {
TA->getArchitecture(), Feats);
 } else {
   const auto *TVA = CurFD->getAttr();
+  if (CurFD->isUsed() || (TVA->isDefaultVersion() &&
+  CurFD->doesThisDeclarationHaveABody()))
+EmitResolver = true;
   llvm::SmallVector Feats;
   TVA->getFeatures(Feats);
   Options.emplace_back(cast(Func),
@@ -4175,22 +4185,27 @@ void CodeGenModule::emitMultiVersionFunctions() {
   continue;
 }
 
+if (!EmitResolver)
+  continue;
+
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
   if (FD->isTargetClonesMultiVersion() ||
   FD->isTargetVersionMultiVersion()) {
-const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
-llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
 *this, GD, FD, /*OmitMultiVersionMangling=*/true);
-// In prior versions of Clang, the mangling for ifuncs incorrectly
-// included an .ifunc suffix. This alias is generated for backward
-// compatibility. It is deprecated, and may be removed in the future.
-auto *Alias = llvm::GlobalAlias::create(
-DeclTy, 0, getMultiversionLinkage(*this, GD),
-MangledName + ".ifunc", IFunc, &getModule());
-SetCommonAttributes(FD, Alias);
+if (!GetGlobalValue(MangledName + ".ifunc")) {
+  const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
+  llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
+  // In prior versions of Clang, the mangling for ifuncs incorrectly
+  // included an .ifunc suffix. This alias is generated for backward
+  // c

[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow fmv without default declaration. (PR #85454)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/85454

This was a limitation which has now been lifted upon request.
Please read the thread below for more details:

https://github.com/llvm/llvm-project/pull/84405#discussion_r1525583647

Basically it allows to separate versioned implementations across
different TUs without having to share private header files which
contain the default declaration.

>From 6a495010024b93bb8871eebe6e10c62d1f5d2fc5 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 7 Mar 2024 22:25:13 +
Subject: [PATCH 1/2] [FMV] Emit the resolver along with the default version
 definition.

We would like the resolver to be generated eagerly, even if the
versioned function is not called from the current translation
unit. Fixes #81494. It further allows Multi Versioning to work
even if the default target version attribute is omitted from
function declarations.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  55 +-
 clang/lib/CodeGen/CodeGenModule.h |   5 +
 clang/test/CodeGen/attr-target-version.c  | 546 --
 clang/test/CodeGenCXX/attr-target-version.cpp | 261 +++--
 4 files changed, 629 insertions(+), 238 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 8ceecff28cbc63..a5eb46277d5f63 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3447,6 +3447,9 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl 
*Global) {
   // Implicit template instantiations may change linkage if they are later
   // explicitly instantiated, so they should not be emitted eagerly.
   return false;
+// Defer until all versions have been semantically checked.
+if (FD->hasAttr() && !FD->isMultiVersion())
+  return false;
   }
   if (const auto *VD = dyn_cast(Global)) {
 if (Context.getInlineVariableDefinitionKind(VD) ==
@@ -3995,10 +3998,13 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
 // Ensure that the resolver function is also emitted.
 GetOrCreateMultiVersionResolver(GD);
-  } else if (FD->hasAttr()) {
-GetOrCreateMultiVersionResolver(GD);
   } else
 EmitGlobalFunctionDefinition(GD, GV);
+
+  // Defer the resolver emission until we can reason whether the TU
+  // contains a default target version implementation.
+  if (FD->isTargetVersionMultiVersion())
+AddDeferredMultiVersionResolverToEmit(GD);
 }
 
 void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) 
{
@@ -4091,10 +4097,11 @@ void CodeGenModule::emitMultiVersionFunctions() {
 const auto *FD = cast(GD.getDecl());
 assert(FD && "Expected a FunctionDecl");
 
+bool EmitResolver = !FD->isTargetVersionMultiVersion();
 SmallVector Options;
 if (FD->isTargetMultiVersion()) {
   getContext().forEachMultiversionedFunctionVersion(
-  FD, [this, &GD, &Options](const FunctionDecl *CurFD) {
+  FD, [this, &GD, &Options, &EmitResolver](const FunctionDecl *CurFD) {
 GlobalDecl CurGD{
 (CurFD->isDefined() ? CurFD->getDefinition() : CurFD)};
 StringRef MangledName = getMangledName(CurGD);
@@ -4120,6 +4127,9 @@ void CodeGenModule::emitMultiVersionFunctions() {
TA->getArchitecture(), Feats);
 } else {
   const auto *TVA = CurFD->getAttr();
+  if (CurFD->isUsed() || (TVA->isDefaultVersion() &&
+  CurFD->doesThisDeclarationHaveABody()))
+EmitResolver = true;
   llvm::SmallVector Feats;
   TVA->getFeatures(Feats);
   Options.emplace_back(cast(Func),
@@ -4175,22 +4185,27 @@ void CodeGenModule::emitMultiVersionFunctions() {
   continue;
 }
 
+if (!EmitResolver)
+  continue;
+
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
   if (FD->isTargetClonesMultiVersion() ||
   FD->isTargetVersionMultiVersion()) {
-const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
-llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
 *this, GD, FD, /*OmitMultiVersionMangling=*/true);
-// In prior versions of Clang, the mangling for ifuncs incorrectly
-// included an .ifunc suffix. This alias is generated for backward
-// compatibility. It is deprecated, and may be removed in the future.
-auto *Alias = llvm::GlobalAlias::create(
-DeclTy, 0, getMultiversionLinkage(*this, GD),
-MangledName + ".ifunc", IFunc, &getModule());
-SetCommonAttributes(FD, Alias);
+if (!GetGlo

[clang] [FMV] Allow fmv without default declaration. (PR #85454)

2024-03-15 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

I think I messed up the review, this is based on #84405 so it shows unrelated 
changes. Ignore for now. I'll rebase

https://github.com/llvm/llvm-project/pull/85454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow fmv without default declaration. (PR #85454)

2024-03-17 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

Hmm, I am now having second thoughts about this change. All is well without a 
default declaration as long as we don't have a caller in the TU. In that case 
(if there is a caller) a resolver is needed, but without a default declaration 
we can't create a complete resolver (the resolver contains calls to the target 
versions it can see in the TU) :/

https://github.com/llvm/llvm-project/pull/85454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-17 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

> In the current patch, it just gets the non-mangled name. And the fact that we 
> get a not-mangled function that uses `feature` without going through a 
> resolver is concerning to me.

I am not sure I understand. Are you refering to the StringSet I added which 
keeps non-mangled names of versioned functions? Those unique non-mangled names 
will be appended to `MultiVersionFuncs` which are iterated by the outer loop of 
`CodeGenModule::emitMultiVersionFunctions()`. Then for each of these 
declarations there is a chain of declarations (mangled function versions), 
which is iterated by the inner loop (forEachMultiversionedFunctionVersion). In 
that inner loop we either create (emit) a version or we just get a reference to 
its declaration. All these mangled versions that are part of the chain and are 
passed to `EmitMultiVersionResolver()` via `Options`. The reason we are using a 
Set is to avoid duplicates in the outer loop, which would result in multiple 
copies of the corresponding basic blocks in the resolver's body. Oh, and btw 
the default versions always have an implicit target_version attribute by the 
time they are processed by emitMultiVersionFunctions (added by the sema 
checker), so they are already mangled. I am not sure I answered. Perhaps we 
could decipher the concern offline.



https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-17 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

Ah, I see. That is addressed in #85454 but I have already expressed a concern.

https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-19 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

I have raised two related pull requests stacked on this one:
- https://github.com/labrinea/llvm-project/pull/1
- https://github.com/labrinea/llvm-project/pull/2

Is there anything else we would like to address in this patch?

https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-20 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[FMV] Emit the resolver along with the default version definition." (PR #85914)

2024-03-20 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/85914

Reverts llvm/llvm-project#84405

In between of passing the precommit tests on github and being merged
some change (perhaps in the AArch64 backend?) landed which resulted
in altering the generated resolver. I will regenerate the tests
perhaps using a less sensitive runline to such changes.

>From 06f3d687a8ecbef5d5c21bc73723e4e4c55997bd Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Wed, 20 Mar 2024 10:08:24 +
Subject: [PATCH] =?UTF-8?q?Revert=20"[FMV]=20Emit=20the=20resolver=20along?=
 =?UTF-8?q?=20with=20the=20default=20version=20definition.=20(#=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit e6b5bd5854c80eac05f415ad282ba84b840b8af8.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  55 +-
 clang/lib/CodeGen/CodeGenModule.h |   5 -
 clang/test/CodeGen/attr-target-version.c  | 546 ++
 clang/test/CodeGenCXX/attr-target-version.cpp | 261 ++---
 4 files changed, 238 insertions(+), 629 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cb153066b28dd1..bb26bfcddaeb78 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3449,9 +3449,6 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl 
*Global) {
   // Implicit template instantiations may change linkage if they are later
   // explicitly instantiated, so they should not be emitted eagerly.
   return false;
-// Defer until all versions have been semantically checked.
-if (FD->hasAttr() && !FD->isMultiVersion())
-  return false;
   }
   if (const auto *VD = dyn_cast(Global)) {
 if (Context.getInlineVariableDefinitionKind(VD) ==
@@ -4000,13 +3997,10 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
 // Ensure that the resolver function is also emitted.
 GetOrCreateMultiVersionResolver(GD);
+  } else if (FD->hasAttr()) {
+GetOrCreateMultiVersionResolver(GD);
   } else
 EmitGlobalFunctionDefinition(GD, GV);
-
-  // Defer the resolver emission until we can reason whether the TU
-  // contains a default target version implementation.
-  if (FD->isTargetVersionMultiVersion())
-AddDeferredMultiVersionResolverToEmit(GD);
 }
 
 void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) 
{
@@ -4099,11 +4093,10 @@ void CodeGenModule::emitMultiVersionFunctions() {
 const auto *FD = cast(GD.getDecl());
 assert(FD && "Expected a FunctionDecl");
 
-bool EmitResolver = !FD->isTargetVersionMultiVersion();
 SmallVector Options;
 if (FD->isTargetMultiVersion()) {
   getContext().forEachMultiversionedFunctionVersion(
-  FD, [this, &GD, &Options, &EmitResolver](const FunctionDecl *CurFD) {
+  FD, [this, &GD, &Options](const FunctionDecl *CurFD) {
 GlobalDecl CurGD{
 (CurFD->isDefined() ? CurFD->getDefinition() : CurFD)};
 StringRef MangledName = getMangledName(CurGD);
@@ -4129,9 +4122,6 @@ void CodeGenModule::emitMultiVersionFunctions() {
TA->getArchitecture(), Feats);
 } else {
   const auto *TVA = CurFD->getAttr();
-  if (CurFD->isUsed() || (TVA->isDefaultVersion() &&
-  CurFD->doesThisDeclarationHaveABody()))
-EmitResolver = true;
   llvm::SmallVector Feats;
   TVA->getFeatures(Feats);
   Options.emplace_back(cast(Func),
@@ -4187,27 +4177,22 @@ void CodeGenModule::emitMultiVersionFunctions() {
   continue;
 }
 
-if (!EmitResolver)
-  continue;
-
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
   if (FD->isTargetClonesMultiVersion() ||
   FD->isTargetVersionMultiVersion()) {
+const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
+llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
 *this, GD, FD, /*OmitMultiVersionMangling=*/true);
-if (!GetGlobalValue(MangledName + ".ifunc")) {
-  const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
-  llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
-  // In prior versions of Clang, the mangling for ifuncs incorrectly
-  // included an .ifunc suffix. This alias is generated for backward
-  // compatibility. It is deprecated, and may be removed in the future.
-  auto *Alias = llvm::GlobalAlias::create(
-  DeclTy, 0, getMultiversionLinkage(*this, GD),
-  Mangled

[clang] Reland [FMV] Emit the resolver along with the default version definit… (PR #85923)

2024-03-20 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/85923

…ion.

This was reverted because the resolver didn't look as expected in one of the 
tests. I believe it had some interaction with #84146. I have now regenerated it 
using -target-feature -fp-armv8.

>From 20a44fd71d408ed5f5c8c8062dff2747f31dd27e Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Wed, 20 Mar 2024 10:32:58 +
Subject: [PATCH] Reland [FMV] Emit the resolver along with the default version
 definition.

This was reverted because the resolver didn't look as expected in one of
the tests. I believe it had some interaction with #84146. I have now
regenerated it using -target-feature -fp-armv8.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  55 +-
 clang/lib/CodeGen/CodeGenModule.h |   5 +
 clang/test/CodeGen/attr-target-version.c  | 546 --
 clang/test/CodeGenCXX/attr-target-version.cpp | 261 +++--
 4 files changed, 629 insertions(+), 238 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index bb26bfcddaeb78..cb153066b28dd1 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3449,6 +3449,9 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl 
*Global) {
   // Implicit template instantiations may change linkage if they are later
   // explicitly instantiated, so they should not be emitted eagerly.
   return false;
+// Defer until all versions have been semantically checked.
+if (FD->hasAttr() && !FD->isMultiVersion())
+  return false;
   }
   if (const auto *VD = dyn_cast(Global)) {
 if (Context.getInlineVariableDefinitionKind(VD) ==
@@ -3997,10 +4000,13 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
 // Ensure that the resolver function is also emitted.
 GetOrCreateMultiVersionResolver(GD);
-  } else if (FD->hasAttr()) {
-GetOrCreateMultiVersionResolver(GD);
   } else
 EmitGlobalFunctionDefinition(GD, GV);
+
+  // Defer the resolver emission until we can reason whether the TU
+  // contains a default target version implementation.
+  if (FD->isTargetVersionMultiVersion())
+AddDeferredMultiVersionResolverToEmit(GD);
 }
 
 void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) 
{
@@ -4093,10 +4099,11 @@ void CodeGenModule::emitMultiVersionFunctions() {
 const auto *FD = cast(GD.getDecl());
 assert(FD && "Expected a FunctionDecl");
 
+bool EmitResolver = !FD->isTargetVersionMultiVersion();
 SmallVector Options;
 if (FD->isTargetMultiVersion()) {
   getContext().forEachMultiversionedFunctionVersion(
-  FD, [this, &GD, &Options](const FunctionDecl *CurFD) {
+  FD, [this, &GD, &Options, &EmitResolver](const FunctionDecl *CurFD) {
 GlobalDecl CurGD{
 (CurFD->isDefined() ? CurFD->getDefinition() : CurFD)};
 StringRef MangledName = getMangledName(CurGD);
@@ -4122,6 +4129,9 @@ void CodeGenModule::emitMultiVersionFunctions() {
TA->getArchitecture(), Feats);
 } else {
   const auto *TVA = CurFD->getAttr();
+  if (CurFD->isUsed() || (TVA->isDefaultVersion() &&
+  CurFD->doesThisDeclarationHaveABody()))
+EmitResolver = true;
   llvm::SmallVector Feats;
   TVA->getFeatures(Feats);
   Options.emplace_back(cast(Func),
@@ -4177,22 +4187,27 @@ void CodeGenModule::emitMultiVersionFunctions() {
   continue;
 }
 
+if (!EmitResolver)
+  continue;
+
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
   if (FD->isTargetClonesMultiVersion() ||
   FD->isTargetVersionMultiVersion()) {
-const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
-llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
 *this, GD, FD, /*OmitMultiVersionMangling=*/true);
-// In prior versions of Clang, the mangling for ifuncs incorrectly
-// included an .ifunc suffix. This alias is generated for backward
-// compatibility. It is deprecated, and may be removed in the future.
-auto *Alias = llvm::GlobalAlias::create(
-DeclTy, 0, getMultiversionLinkage(*this, GD),
-MangledName + ".ifunc", IFunc, &getModule());
-SetCommonAttributes(FD, Alias);
+if (!GetGlobalValue(MangledName + ".ifunc")) {
+  const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
+  llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
+  // In prior versions of Clang, the 

[clang] Reland [FMV] Emit the resolver along with the default version definit… (PR #85923)

2024-03-20 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/85923

>From c0c07deebef4e2c76d935b4ce8fc1d4abddab4db Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Wed, 20 Mar 2024 10:32:58 +
Subject: [PATCH] Reland [FMV] Emit the resolver along with the default version
 definition.

This was reverted because the resolver didn't look as expected in one of
the tests. I believe it had some interaction with #84146. I have now
regenerated it using -target-feature -fp-armv8.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  55 +-
 clang/lib/CodeGen/CodeGenModule.h |   5 +
 clang/test/CodeGen/attr-target-version.c  | 546 --
 clang/test/CodeGenCXX/attr-target-version.cpp | 261 +++--
 4 files changed, 629 insertions(+), 238 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index bb26bfcddaeb78..cb153066b28dd1 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3449,6 +3449,9 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl 
*Global) {
   // Implicit template instantiations may change linkage if they are later
   // explicitly instantiated, so they should not be emitted eagerly.
   return false;
+// Defer until all versions have been semantically checked.
+if (FD->hasAttr() && !FD->isMultiVersion())
+  return false;
   }
   if (const auto *VD = dyn_cast(Global)) {
 if (Context.getInlineVariableDefinitionKind(VD) ==
@@ -3997,10 +4000,13 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
 // Ensure that the resolver function is also emitted.
 GetOrCreateMultiVersionResolver(GD);
-  } else if (FD->hasAttr()) {
-GetOrCreateMultiVersionResolver(GD);
   } else
 EmitGlobalFunctionDefinition(GD, GV);
+
+  // Defer the resolver emission until we can reason whether the TU
+  // contains a default target version implementation.
+  if (FD->isTargetVersionMultiVersion())
+AddDeferredMultiVersionResolverToEmit(GD);
 }
 
 void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) 
{
@@ -4093,10 +4099,11 @@ void CodeGenModule::emitMultiVersionFunctions() {
 const auto *FD = cast(GD.getDecl());
 assert(FD && "Expected a FunctionDecl");
 
+bool EmitResolver = !FD->isTargetVersionMultiVersion();
 SmallVector Options;
 if (FD->isTargetMultiVersion()) {
   getContext().forEachMultiversionedFunctionVersion(
-  FD, [this, &GD, &Options](const FunctionDecl *CurFD) {
+  FD, [this, &GD, &Options, &EmitResolver](const FunctionDecl *CurFD) {
 GlobalDecl CurGD{
 (CurFD->isDefined() ? CurFD->getDefinition() : CurFD)};
 StringRef MangledName = getMangledName(CurGD);
@@ -4122,6 +4129,9 @@ void CodeGenModule::emitMultiVersionFunctions() {
TA->getArchitecture(), Feats);
 } else {
   const auto *TVA = CurFD->getAttr();
+  if (CurFD->isUsed() || (TVA->isDefaultVersion() &&
+  CurFD->doesThisDeclarationHaveABody()))
+EmitResolver = true;
   llvm::SmallVector Feats;
   TVA->getFeatures(Feats);
   Options.emplace_back(cast(Func),
@@ -4177,22 +4187,27 @@ void CodeGenModule::emitMultiVersionFunctions() {
   continue;
 }
 
+if (!EmitResolver)
+  continue;
+
 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
 if (auto *IFunc = dyn_cast(ResolverConstant)) {
   ResolverConstant = IFunc->getResolver();
   if (FD->isTargetClonesMultiVersion() ||
   FD->isTargetVersionMultiVersion()) {
-const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
-llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
 std::string MangledName = getMangledNameImpl(
 *this, GD, FD, /*OmitMultiVersionMangling=*/true);
-// In prior versions of Clang, the mangling for ifuncs incorrectly
-// included an .ifunc suffix. This alias is generated for backward
-// compatibility. It is deprecated, and may be removed in the future.
-auto *Alias = llvm::GlobalAlias::create(
-DeclTy, 0, getMultiversionLinkage(*this, GD),
-MangledName + ".ifunc", IFunc, &getModule());
-SetCommonAttributes(FD, Alias);
+if (!GetGlobalValue(MangledName + ".ifunc")) {
+  const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
+  llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
+  // In prior versions of Clang, the mangling for ifuncs incorrectly
+  // included an .ifunc suffix. This alias is generated for backward
+  // compatibility. It is deprecated, and may be removed in the future.
+

[clang] Reland [FMV] Emit the resolver along with the default version definit… (PR #85923)

2024-03-20 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/85923
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow fmv without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/85454

>From 60a6fcd7560ec434a8369240f7a9cd13cf035c42 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Fri, 15 Mar 2024 19:25:16 +
Subject: [PATCH] [FMV] Allow multi versioning without default declaration.

This was a limitation which has now been lifted. Please read the
thread below for more details:

https://github.com/llvm/llvm-project/pull/84405#discussion_r1525583647

Basically it allows to separate versioned implementations across
different TUs without having to share private header files which
contain the default declaration.

The ACLE spec has been updated accordingly to make this explicit:
"Each version declaration should be visible at the translation
 unit in which the corresponding function version resides."

https://github.com/ARM-software/acle/pull/310

If a resolver is required (because there is a caller in the TU),
then a default declaration is implicitly generated.
---
 clang/lib/CodeGen/CodeGenModule.cpp   | 124 
 clang/lib/Sema/SemaDecl.cpp   |   6 +-
 clang/lib/Sema/SemaOverload.cpp   |  44 ++-
 clang/test/CodeGen/attr-target-version.c  | 298 --
 clang/test/CodeGenCXX/attr-target-version.cpp |  62 ++--
 clang/test/Sema/aarch64-sme-func-attrs.c  |   8 +-
 clang/test/Sema/attr-target-version.c |   8 +-
 clang/test/SemaCXX/attr-target-version.cpp|  11 +-
 8 files changed, 339 insertions(+), 222 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cb153066b28dd1..72a6dd63ce51b0 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4092,6 +4092,23 @@ llvm::GlobalValue::LinkageTypes 
getMultiversionLinkage(CodeGenModule &CGM,
   return llvm::GlobalValue::WeakODRLinkage;
 }
 
+static FunctionDecl *createDefaultTargetVersionFrom(const FunctionDecl *FD) {
+  DeclContext *DeclCtx = FD->getASTContext().getTranslationUnitDecl();
+  TypeSourceInfo *TInfo = FD->getTypeSourceInfo();
+  StorageClass SC = FD->getStorageClass();
+  DeclarationName Name = FD->getNameInfo().getName();
+
+  FunctionDecl *NewDecl =
+  FunctionDecl::Create(FD->getASTContext(), DeclCtx, FD->getBeginLoc(),
+   FD->getEndLoc(), Name, TInfo->getType(), TInfo, SC);
+
+  NewDecl->setIsMultiVersion();
+  NewDecl->addAttr(TargetVersionAttr::CreateImplicit(
+  NewDecl->getASTContext(), "default", NewDecl->getSourceRange()));
+
+  return NewDecl;
+}
+
 void CodeGenModule::emitMultiVersionFunctions() {
   std::vector MVFuncsToEmit;
   MultiVersionFuncs.swap(MVFuncsToEmit);
@@ -4099,70 +4116,54 @@ void CodeGenModule::emitMultiVersionFunctions() {
 const auto *FD = cast(GD.getDecl());
 assert(FD && "Expected a FunctionDecl");
 
-bool EmitResolver = !FD->isTargetVersionMultiVersion();
+auto createFunction = [&](const FunctionDecl *Decl, unsigned MVIdx = 0) {
+  GlobalDecl CurGD{Decl->isDefined() ? Decl->getDefinition() : Decl, 
MVIdx};
+  StringRef MangledName = getMangledName(CurGD);
+  llvm::Constant *Func = GetGlobalValue(MangledName);
+  if (!Func) {
+if (Decl->isDefined()) {
+  EmitGlobalFunctionDefinition(CurGD, nullptr);
+  Func = GetGlobalValue(MangledName);
+} else {
+  const CGFunctionInfo &FI = 
getTypes().arrangeGlobalDeclaration(CurGD);
+  llvm::FunctionType *Ty = getTypes().GetFunctionType(FI);
+  Func = GetAddrOfFunction(CurGD, Ty, /*ForVTable=*/false,
+   /*DontDefer=*/false, ForDefinition);
+}
+assert(Func && "This should have just been created");
+  }
+  return cast(Func);
+};
+
+bool HasDefaultDecl = !FD->isTargetVersionMultiVersion();
+bool ShouldEmitResolver = !FD->isTargetVersionMultiVersion();
 SmallVector Options;
 if (FD->isTargetMultiVersion()) {
   getContext().forEachMultiversionedFunctionVersion(
-  FD, [this, &GD, &Options, &EmitResolver](const FunctionDecl *CurFD) {
-GlobalDecl CurGD{
-(CurFD->isDefined() ? CurFD->getDefinition() : CurFD)};
-StringRef MangledName = getMangledName(CurGD);
-llvm::Constant *Func = GetGlobalValue(MangledName);
-if (!Func) {
-  if (CurFD->isDefined()) {
-EmitGlobalFunctionDefinition(CurGD, nullptr);
-Func = GetGlobalValue(MangledName);
-  } else {
-const CGFunctionInfo &FI =
-getTypes().arrangeGlobalDeclaration(GD);
-llvm::FunctionType *Ty = getTypes().GetFunctionType(FI);
-Func = GetAddrOfFunction(CurGD, Ty, /*ForVTable=*/false,
- /*DontDefer=*/false, ForDefinition);
-  }
-  assert(Func && "This should have just been created");
-}
-if (CurF

[clang] [FMV] Allow fmv without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/85454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow fmv without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

Update: The ACLE spec is now explicit about this (see 
https://github.com/ARM-software/acle/pull/310), so we can safely implement the 
change in the compiler. Implementation-wise I have moved the static cast to 
`llvm::Function` inside the `createFunction()` lambda.

https://github.com/llvm/llvm-project/pull/85454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/85454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits


@@ -70,17 +69,23 @@ int __attribute__((target_version("lse"))) extc(void) { 
return 1; }
 
 auto __attribute__((target_version("default"))) ret1(void) { return 1; }
 auto __attribute__((target_version("dpb"))) ret2(void) { return 1; }
+// expected-error@-1 {{attribute 'target_version' multiversioned functions do 
not yet support deduced return types}}
 auto __attribute__((target_version("dpb2"))) ret3(void) -> int { return 1; }
 
 class Cls {
   __attribute__((target_version("rng"))) Cls();
+  // expected-error@-1 {{attribute 'target_version' multiversioned functions 
do not yet support constructors}}
   __attribute__((target_version("sve-i8mm"))) ~Cls();
+  // expected-error@-1 {{attribute 'target_version' multiversioned functions 
do not yet support destructors}}
 
   Cls &__attribute__((target_version("f32mm"))) operator=(const Cls &) = 
default;
+  // expected-error@-1 {{attribute 'target_version' multiversioned functions 
do not yet support defaulted functions}}
   Cls &__attribute__((target_version("ssbs"))) operator=(Cls &&) = delete;
+  // expected-error@-1 {{attribute 'target_version' multiversioned functions 
do not yet support deleted functions}}

labrinea wrote:

Without a default declaration target_version was ignored so these errors 
wouldn't trigger.

https://github.com/llvm/llvm-project/pull/85454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits


@@ -483,14 +483,16 @@ void just_fine(void) {}
 
 __arm_locally_streaming
 __attribute__((target_version("sme2")))
-void just_fine_locally_streaming(void) {}
+void incompatible_locally_streaming(void) {}
+// expected-error@-1 {{attribute 'target_version' multiversioning cannot be 
combined with attribute '__arm_locally_streaming'}}
+// expected-cpp-error@-2 {{attribute 'target_version' multiversioning cannot 
be combined with attribute '__arm_locally_streaming'}}

labrinea wrote:

I believe this has to do with the order of parsing. Before only after we saw 
the default we then acknowledged the sme2 version, so this diagnostic was 
missed. But I am not 100% sure this is the reason.

https://github.com/llvm/llvm-project/pull/85454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits


@@ -109,9 +109,22 @@ int unused_with_implicit_default_def(void) { return 1; }
 int unused_with_implicit_forward_default_def(void) { return 0; }
 __attribute__((target_version("lse"))) int 
unused_with_implicit_forward_default_def(void) { return 1; }
 
-// This should generate a normal function.
+// This should generate a target version despite the default not being 
declared.
 __attribute__((target_version("rdm"))) int unused_without_default(void) { 
return 0; }
 
+// The following is guarded because in NOFMV we get errors for calling 
undeclared functions.
+#ifdef __HAVE_FUNCTION_MULTI_VERSIONING
+// This should generate a default declaration, two target versions and the 
resolver.
+__attribute__((target_version("jscvt"))) int 
used_def_without_default_decl(void) { return 1; }
+__attribute__((target_version("rdma"))) int 
used_def_without_default_decl(void) { return 2; }
+
+// This should generate a default declaration and the resolver.
+__attribute__((target_version("jscvt"))) int 
used_decl_without_default_decl(void);
+__attribute__((target_version("rdma"))) int 
used_decl_without_default_decl(void);
+
+int caller(void) { return used_def_without_default_decl() + 
used_decl_without_default_decl(); }

labrinea wrote:

Hmm, your second example is interesting. We have stated in ACLE 
(https://github.com/ARM-software/acle/pull/310) that a declaration of a version 
should be visible to the TU where its definition resides. In this case only the 
default definition exists in the TU, so I believe rightfully we will generate a 
normal (unmangled) definition without the ".default" suffix for it.

https://github.com/llvm/llvm-project/pull/85454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits


@@ -68,13 +68,15 @@ int __attribute__((target_version(""))) unsup1(void) { 
return 1; }
 void __attribute__((target_version("crc32"))) unsup2(void) {}
 
 void __attribute__((target_version("default+fp16"))) koo(void) {}
+//expected-error@-1 {{function multiversioning doesn't support feature 
'default'}}
 void __attribute__((target_version("default+default+default"))) loo(void) {}
+//expected-error@-1 {{function multiversioning doesn't support feature 
'default'}}

labrinea wrote:

This diagnostic is unrelated to the patch. I believe it deserves a separate PR 
if at all. I am not confused by the message itself to be honest as the ACLE is 
clear that the attribute string is eather "default" or a list of features with 
'+' in between. What bothers me is the inconsistency with `target_clones`, 
where "default+fp16" is treated as a warning and "default" is ignored. Both 
attributes should either warn or error.

https://github.com/llvm/llvm-project/pull/85454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/85454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits


@@ -109,9 +109,22 @@ int unused_with_implicit_default_def(void) { return 1; }
 int unused_with_implicit_forward_default_def(void) { return 0; }
 __attribute__((target_version("lse"))) int 
unused_with_implicit_forward_default_def(void) { return 1; }
 
-// This should generate a normal function.
+// This should generate a target version despite the default not being 
declared.
 __attribute__((target_version("rdm"))) int unused_without_default(void) { 
return 0; }
 
+// The following is guarded because in NOFMV we get errors for calling 
undeclared functions.
+#ifdef __HAVE_FUNCTION_MULTI_VERSIONING
+// This should generate a default declaration, two target versions and the 
resolver.
+__attribute__((target_version("jscvt"))) int 
used_def_without_default_decl(void) { return 1; }
+__attribute__((target_version("rdma"))) int 
used_def_without_default_decl(void) { return 2; }
+
+// This should generate a default declaration and the resolver.
+__attribute__((target_version("jscvt"))) int 
used_decl_without_default_decl(void);
+__attribute__((target_version("rdma"))) int 
used_decl_without_default_decl(void);
+
+int caller(void) { return used_def_without_default_decl() + 
used_decl_without_default_decl(); }

labrinea wrote:

Let me think about this a little more. The behavior is inconsistent when the 
order of declaration changes. If the default comes last then it is mangled and 
a resolver is generated. Perhaps this is preferable in case the other versions 
reside in another TU.

https://github.com/llvm/llvm-project/pull/85454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-23 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/85454

>From 289d36fd371f9f47e2ceb3a682e3c6d122341f3b Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Fri, 15 Mar 2024 19:25:16 +
Subject: [PATCH] [FMV] Allow multi versioning without default declaration.

This was a limitation which has now been lifted. Please read the
thread below for more details:

https://github.com/llvm/llvm-project/pull/84405#discussion_r1525583647

Basically it allows to separate versioned implementations across
different TUs without having to share private header files which
contain the default declaration.

The ACLE spec has been updated accordingly to make this explicit:
"Each version declaration should be visible at the translation
 unit in which the corresponding function version resides."

https://github.com/ARM-software/acle/pull/310

If a resolver is required (because there is a caller in the TU),
then a default declaration is implicitly generated.
---
 clang/lib/CodeGen/CodeGenModule.cpp   | 131 ---
 clang/lib/Sema/SemaDecl.cpp   |   6 +-
 clang/lib/Sema/SemaOverload.cpp   |  44 ++-
 clang/test/CodeGen/attr-target-version.c  | 368 --
 clang/test/CodeGenCXX/attr-target-version.cpp |  62 +--
 clang/test/Sema/aarch64-sme-func-attrs.c  |   8 +-
 clang/test/Sema/attr-target-version.c |   8 +-
 clang/test/SemaCXX/attr-target-version.cpp|  11 +-
 8 files changed, 403 insertions(+), 235 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cb153066b28dd1..ac81df8cf7adfe 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3711,7 +3711,8 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
 
 // Forward declarations are emitted lazily on first use.
 if (!FD->doesThisDeclarationHaveABody()) {
-  if (!FD->doesDeclarationForceExternallyVisibleDefinition())
+  if (!FD->doesDeclarationForceExternallyVisibleDefinition() &&
+  !FD->isTargetVersionMultiVersion())
 return;
 
   StringRef MangledName = getMangledName(GD);
@@ -4092,6 +4093,23 @@ llvm::GlobalValue::LinkageTypes 
getMultiversionLinkage(CodeGenModule &CGM,
   return llvm::GlobalValue::WeakODRLinkage;
 }
 
+static FunctionDecl *createDefaultTargetVersionFrom(const FunctionDecl *FD) {
+  DeclContext *DeclCtx = FD->getASTContext().getTranslationUnitDecl();
+  TypeSourceInfo *TInfo = FD->getTypeSourceInfo();
+  StorageClass SC = FD->getStorageClass();
+  DeclarationName Name = FD->getNameInfo().getName();
+
+  FunctionDecl *NewDecl =
+  FunctionDecl::Create(FD->getASTContext(), DeclCtx, FD->getBeginLoc(),
+   FD->getEndLoc(), Name, TInfo->getType(), TInfo, SC);
+
+  NewDecl->setIsMultiVersion();
+  NewDecl->addAttr(TargetVersionAttr::CreateImplicit(
+  NewDecl->getASTContext(), "default", NewDecl->getSourceRange()));
+
+  return NewDecl;
+}
+
 void CodeGenModule::emitMultiVersionFunctions() {
   std::vector MVFuncsToEmit;
   MultiVersionFuncs.swap(MVFuncsToEmit);
@@ -4099,70 +4117,54 @@ void CodeGenModule::emitMultiVersionFunctions() {
 const auto *FD = cast(GD.getDecl());
 assert(FD && "Expected a FunctionDecl");
 
-bool EmitResolver = !FD->isTargetVersionMultiVersion();
+auto createFunction = [&](const FunctionDecl *Decl, unsigned MVIdx = 0) {
+  GlobalDecl CurGD{Decl->isDefined() ? Decl->getDefinition() : Decl, 
MVIdx};
+  StringRef MangledName = getMangledName(CurGD);
+  llvm::Constant *Func = GetGlobalValue(MangledName);
+  if (!Func) {
+if (Decl->isDefined()) {
+  EmitGlobalFunctionDefinition(CurGD, nullptr);
+  Func = GetGlobalValue(MangledName);
+} else {
+  const CGFunctionInfo &FI = 
getTypes().arrangeGlobalDeclaration(CurGD);
+  llvm::FunctionType *Ty = getTypes().GetFunctionType(FI);
+  Func = GetAddrOfFunction(CurGD, Ty, /*ForVTable=*/false,
+   /*DontDefer=*/false, ForDefinition);
+}
+assert(Func && "This should have just been created");
+  }
+  return cast(Func);
+};
+
+bool HasDefaultDecl = !FD->isTargetVersionMultiVersion();
+bool ShouldEmitResolver = !FD->isTargetVersionMultiVersion();
 SmallVector Options;
 if (FD->isTargetMultiVersion()) {
   getContext().forEachMultiversionedFunctionVersion(
-  FD, [this, &GD, &Options, &EmitResolver](const FunctionDecl *CurFD) {
-GlobalDecl CurGD{
-(CurFD->isDefined() ? CurFD->getDefinition() : CurFD)};
-StringRef MangledName = getMangledName(CurGD);
-llvm::Constant *Func = GetGlobalValue(MangledName);
-if (!Func) {
-  if (CurFD->isDefined()) {
-EmitGlobalFunctionDefinition(CurGD, nullptr);
-Func = GetGlobalValue(MangledName);
-  } else {
-const

[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-23 Thread Alexandros Lamprineas via cfe-commits


@@ -109,9 +109,22 @@ int unused_with_implicit_default_def(void) { return 1; }
 int unused_with_implicit_forward_default_def(void) { return 0; }
 __attribute__((target_version("lse"))) int 
unused_with_implicit_forward_default_def(void) { return 1; }
 
-// This should generate a normal function.
+// This should generate a target version despite the default not being 
declared.
 __attribute__((target_version("rdm"))) int unused_without_default(void) { 
return 0; }
 
+// The following is guarded because in NOFMV we get errors for calling 
undeclared functions.
+#ifdef __HAVE_FUNCTION_MULTI_VERSIONING
+// This should generate a default declaration, two target versions and the 
resolver.
+__attribute__((target_version("jscvt"))) int 
used_def_without_default_decl(void) { return 1; }
+__attribute__((target_version("rdma"))) int 
used_def_without_default_decl(void) { return 2; }
+
+// This should generate a default declaration and the resolver.
+__attribute__((target_version("jscvt"))) int 
used_decl_without_default_decl(void);
+__attribute__((target_version("rdma"))) int 
used_decl_without_default_decl(void);
+
+int caller(void) { return used_def_without_default_decl() + 
used_decl_without_default_decl(); }

labrinea wrote:

With the latest revision we generate a mangled default and a resolver along 
side it. I believe that would be the user intended behavior in this example.

https://github.com/llvm/llvm-project/pull/85454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-25 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/85454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow mixing target_version with target_clones. (PR #86493)

2024-03-25 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/86493

The latest ACLE allows it and further clarifies the following
in regards to the combination of the two attributes:

"If the `default` matches with another explicitly provided
 version in the same translation unit, then the compiler can
 emit only one function instead of the two. The explicitly
 provided version shall be preferred."

("default" refers to the default clone here)

https://github.com/ARM-software/acle/pull/310

>From 65bfc47298131d6fb5dfeed722dc3f2d9d85eadd Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Fri, 22 Mar 2024 17:21:13 +
Subject: [PATCH] [FMV] Allow mixing target_version with target_clones.

The latest ACLE allows it and further clarifies the following
in regards to the combination of the two attributes:

"If the `default` matches with another explicitly provided
 version in the same translation unit, then the compiler can
 emit only one function instead of the two. The explicitly
 provided version shall be preferred."

("default" refers to the default clone here)

https://github.com/ARM-software/acle/pull/310
---
 clang/include/clang/Basic/Attr.td |  14 +
 clang/lib/AST/ASTContext.cpp  |  15 +-
 clang/lib/CodeGen/CodeGenModule.cpp   | 105 ---
 clang/lib/Sema/SemaDecl.cpp   | 192 
 .../CodeGen/aarch64-mixed-target-attributes.c | 278 ++
 .../test/CodeGen/attr-target-clones-aarch64.c |  94 +++---
 .../CodeGenCXX/attr-target-clones-aarch64.cpp |  28 +-
 clang/test/Sema/attr-target-clones-aarch64.c  |   2 +-
 8 files changed, 539 insertions(+), 189 deletions(-)
 create mode 100644 clang/test/CodeGen/aarch64-mixed-target-attributes.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 3e03e55612645b..318d4e5ac5ba44 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3088,6 +3088,20 @@ def TargetClones : InheritableAttr {
 StringRef getFeatureStr(unsigned Index) const {
   return *(featuresStrs_begin() + Index);
 }
+bool isDefaultVersion(unsigned Index) const {
+  return getFeatureStr(Index) == "default";
+}
+void getFeatures(llvm::SmallVectorImpl &Out,
+ unsigned Index) const {
+  if (isDefaultVersion(Index)) return;
+  StringRef Features = getFeatureStr(Index);
+  SmallVector AttrFeatures;
+  Features.split(AttrFeatures, "+");
+  for (auto &Feature : AttrFeatures) {
+Feature = Feature.trim();
+Out.push_back(Feature);
+  }
+}
 // Given an index into the 'featuresStrs' sequence, compute a unique
 // ID to be used with function name mangling for the associated variant.
 // This mapping is necessary due to a requirement that the mangling ID
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index fcf801adeaf5ef..0b5f20a572a742 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -13676,22 +13676,19 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
 Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features);
   } else if (const auto *TC = FD->getAttr()) {
 std::vector Features;
-StringRef VersionStr = TC->getFeatureStr(GD.getMultiVersionIndex());
 if (Target->getTriple().isAArch64()) {
   // TargetClones for AArch64
-  if (VersionStr != "default") {
-SmallVector VersionFeatures;
-VersionStr.split(VersionFeatures, "+");
-for (auto &VFeature : VersionFeatures) {
-  VFeature = VFeature.trim();
+  llvm::SmallVector Feats;
+  TC->getFeatures(Feats, GD.getMultiVersionIndex());
+  for (StringRef Feat : Feats)
+if (Target->validateCpuSupports(Feat.str()))
   // Use '?' to mark features that came from AArch64 TargetClones.
-  Features.push_back((StringRef{"?"} + VFeature).str());
-}
-  }
+  Features.push_back("?" + Feat.str());
   Features.insert(Features.begin(),
   Target->getTargetOpts().FeaturesAsWritten.begin(),
   Target->getTargetOpts().FeaturesAsWritten.end());
 } else {
+  StringRef VersionStr = TC->getFeatureStr(GD.getMultiVersionIndex());
   if (VersionStr.starts_with("arch="))
 TargetCPU = VersionStr.drop_front(sizeof("arch=") - 1);
   else if (VersionStr != "default")
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index ac81df8cf7adfe..bc7d7ac561113b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3712,7 +3712,8 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
 // Forward declarations are emitted lazily on first use.
 if (!FD->doesThisDeclarationHaveABody()) {
   if (!FD->doesDeclarationForceExternallyVisibleDefinition() &&
-  !FD->isTargetVersionMultiVersi

[clang] [FMV] Allow mixing target_version with target_clones. (PR #86493)

2024-03-25 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/86493

>From dfef9d04c0a65423a051ac00044b39f8911aa731 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Fri, 22 Mar 2024 17:21:13 +
Subject: [PATCH] [FMV] Allow mixing target_version with target_clones.

The latest ACLE allows it and further clarifies the following
in regards to the combination of the two attributes:

"If the `default` matches with another explicitly provided
 version in the same translation unit, then the compiler can
 emit only one function instead of the two. The explicitly
 provided version shall be preferred."

("default" refers to the default clone here)

https://github.com/ARM-software/acle/pull/310
---
 clang/include/clang/Basic/Attr.td |  14 +
 clang/lib/AST/ASTContext.cpp  |  15 +-
 clang/lib/CodeGen/CodeGenModule.cpp   | 105 ---
 clang/lib/Sema/SemaDecl.cpp   | 190 
 .../CodeGen/aarch64-mixed-target-attributes.c | 278 ++
 .../test/CodeGen/attr-target-clones-aarch64.c |  94 +++---
 .../CodeGenCXX/attr-target-clones-aarch64.cpp |  28 +-
 clang/test/Sema/attr-target-clones-aarch64.c  |   2 +-
 8 files changed, 537 insertions(+), 189 deletions(-)
 create mode 100644 clang/test/CodeGen/aarch64-mixed-target-attributes.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 3e03e55612645b..318d4e5ac5ba44 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3088,6 +3088,20 @@ def TargetClones : InheritableAttr {
 StringRef getFeatureStr(unsigned Index) const {
   return *(featuresStrs_begin() + Index);
 }
+bool isDefaultVersion(unsigned Index) const {
+  return getFeatureStr(Index) == "default";
+}
+void getFeatures(llvm::SmallVectorImpl &Out,
+ unsigned Index) const {
+  if (isDefaultVersion(Index)) return;
+  StringRef Features = getFeatureStr(Index);
+  SmallVector AttrFeatures;
+  Features.split(AttrFeatures, "+");
+  for (auto &Feature : AttrFeatures) {
+Feature = Feature.trim();
+Out.push_back(Feature);
+  }
+}
 // Given an index into the 'featuresStrs' sequence, compute a unique
 // ID to be used with function name mangling for the associated variant.
 // This mapping is necessary due to a requirement that the mangling ID
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index fcf801adeaf5ef..0b5f20a572a742 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -13676,22 +13676,19 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
 Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features);
   } else if (const auto *TC = FD->getAttr()) {
 std::vector Features;
-StringRef VersionStr = TC->getFeatureStr(GD.getMultiVersionIndex());
 if (Target->getTriple().isAArch64()) {
   // TargetClones for AArch64
-  if (VersionStr != "default") {
-SmallVector VersionFeatures;
-VersionStr.split(VersionFeatures, "+");
-for (auto &VFeature : VersionFeatures) {
-  VFeature = VFeature.trim();
+  llvm::SmallVector Feats;
+  TC->getFeatures(Feats, GD.getMultiVersionIndex());
+  for (StringRef Feat : Feats)
+if (Target->validateCpuSupports(Feat.str()))
   // Use '?' to mark features that came from AArch64 TargetClones.
-  Features.push_back((StringRef{"?"} + VFeature).str());
-}
-  }
+  Features.push_back("?" + Feat.str());
   Features.insert(Features.begin(),
   Target->getTargetOpts().FeaturesAsWritten.begin(),
   Target->getTargetOpts().FeaturesAsWritten.end());
 } else {
+  StringRef VersionStr = TC->getFeatureStr(GD.getMultiVersionIndex());
   if (VersionStr.starts_with("arch="))
 TargetCPU = VersionStr.drop_front(sizeof("arch=") - 1);
   else if (VersionStr != "default")
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index ac81df8cf7adfe..bc7d7ac561113b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3712,7 +3712,8 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
 // Forward declarations are emitted lazily on first use.
 if (!FD->doesThisDeclarationHaveABody()) {
   if (!FD->doesDeclarationForceExternallyVisibleDefinition() &&
-  !FD->isTargetVersionMultiVersion())
+  (!FD->isMultiVersion() ||
+   !FD->getASTContext().getTargetInfo().getTriple().isAArch64()))
 return;
 
   StringRef MangledName = getMangledName(GD);
@@ -3994,10 +3995,11 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 auto *Spec = FD->getAttr();
 for (unsigned I = 0; I < Spec->cpus_size(); ++I)
   EmitGlobalFunctionDefinition(GD.getWithMultiVersion

[clang] [FMV] Allow mixing target_version with target_clones. (PR #86493)

2024-03-25 Thread Alexandros Lamprineas via cfe-commits


@@ -0,0 +1,278 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --check-attributes --check-globals 
--include-generated-funcs
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature -v9.5a -S 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature -fmv -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-NOFMV
+
+// The following is guarded because in NOFMV we get an error for redefining 
the default.
+#ifdef __HAVE_FUNCTION_MULTI_VERSIONING
+int explicit_default(void) { return 0; }
+__attribute__((target_version("jscvt"))) int explicit_default(void) { return 
1; }
+__attribute__((target_clones("dotprod", "lse"))) int explicit_default(void) { 
return 2; }
+__attribute__((target_version("rdma"))) int explicit_default(void) { return 3; 
}
+
+int foo(void) { return explicit_default(); }
+#endif
+
+__attribute__((target_version("jscvt"))) int implicit_default(void) { return 
1; }
+__attribute__((target_clones("dotprod", "lse"))) int implicit_default(void) { 
return 2; }
+__attribute__((target_version("rdma"))) int implicit_default(void) { return 3; 
}
+
+int bar(void) { return implicit_default(); }
+
+// These shouldn't generate anything.
+int unused_version_declarations(void);
+__attribute__((target_clones("dotprod", "lse"))) int 
unused_version_declarations(void);
+__attribute__((target_version("jscvt"))) int unused_version_declarations(void);
+
+// These should generate the default (mangled) version and the resolver.
+int default_def_with_version_decls(void) { return 0; }
+__attribute__((target_clones("dotprod", "lse"))) int 
default_def_with_version_decls(void);
+__attribute__((target_version("jscvt"))) int 
default_def_with_version_decls(void);
+
+//.
+// CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
+// CHECK: @explicit_default.ifunc = weak_odr alias i32 (), ptr 
@explicit_default
+// CHECK: @implicit_default.ifunc = weak_odr alias i32 (), ptr 
@implicit_default
+// CHECK: @default_def_with_version_decls.ifunc = weak_odr alias i32 (), ptr 
@default_def_with_version_decls
+// CHECK: @explicit_default = weak_odr ifunc i32 (), ptr 
@explicit_default.resolver
+// CHECK: @implicit_default = weak_odr ifunc i32 (), ptr 
@implicit_default.resolver
+// CHECK: @default_def_with_version_decls = weak_odr ifunc i32 (), ptr 
@default_def_with_version_decls.resolver
+//.
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@explicit_default.default
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 0
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@explicit_default._Mjscvt
+// CHECK-SAME: () #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 1
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@explicit_default._Mdotprod
+// CHECK-SAME: () #[[ATTR2:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 2
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@explicit_default._Mlse
+// CHECK-SAME: () #[[ATTR3:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 2
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@explicit_default.resolver() comdat {
+// CHECK-NEXT:  resolver_entry:
+// CHECK-NEXT:call void @__init_cpu_features_resolver()
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 1048576
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 1048576
+// CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
+// CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
+// CHECK:   resolver_return:
+// CHECK-NEXT:ret ptr @explicit_default._Mjscvt
+// CHECK:   resolver_else:
+// CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 64
+// CHECK-NEXT:[[TMP6:%.*]] = icmp eq i64 [[TMP5]], 64
+// CHECK-NEXT:[[TMP7:%.*]] = and i1 true, [[TMP6]]
+// CHECK-NEXT:br i1 [[TMP7]], label [[RESOLVER_RETURN1:%.*]], label 
[[RESOLVER_ELSE2:%.*]]
+// CHECK:   resolver_return1:
+// CHECK-NEXT:ret ptr @explicit_default._Mrdm
+// CHECK:   resolver_else2:
+// CHECK-NEXT:[[TMP8:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP9:%.*]] = and i64 [[TMP8]], 16
+// CHECK-NEXT:[[TMP10:%.*]] = icmp eq i64 [[TMP9]], 16
+// CHECK-NEXT:[[TMP11:%.*]] = and i1 true, [[TMP10]]
+// CHECK-NEXT:br i1 [[TMP11]], label [[RESOLVER_RETURN3:%.*]], label 
[[RESOLVER_ELSE4:%.*]]
+// CHECK:   resolver_return3:
+// CHECK-NEXT:ret ptr @explicit_default._Mdotprod
+// CHECK:   resolver_else4:
+// CHECK-NEXT:[[TMP12:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[

[clang] [FMV] Allow mixing target_version with target_clones. (PR #86493)

2024-03-25 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/86493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow mixing target_version with target_clones. (PR #86493)

2024-03-25 Thread Alexandros Lamprineas via cfe-commits


@@ -0,0 +1,278 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --check-attributes --check-globals 
--include-generated-funcs
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature -v9.5a -S 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature -fmv -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-NOFMV
+
+// The following is guarded because in NOFMV we get an error for redefining 
the default.
+#ifdef __HAVE_FUNCTION_MULTI_VERSIONING
+int explicit_default(void) { return 0; }
+__attribute__((target_version("jscvt"))) int explicit_default(void) { return 
1; }
+__attribute__((target_clones("dotprod", "lse"))) int explicit_default(void) { 
return 2; }
+__attribute__((target_version("rdma"))) int explicit_default(void) { return 3; 
}
+
+int foo(void) { return explicit_default(); }
+#endif
+
+__attribute__((target_version("jscvt"))) int implicit_default(void) { return 
1; }
+__attribute__((target_clones("dotprod", "lse"))) int implicit_default(void) { 
return 2; }
+__attribute__((target_version("rdma"))) int implicit_default(void) { return 3; 
}
+
+int bar(void) { return implicit_default(); }
+
+// These shouldn't generate anything.
+int unused_version_declarations(void);
+__attribute__((target_clones("dotprod", "lse"))) int 
unused_version_declarations(void);
+__attribute__((target_version("jscvt"))) int unused_version_declarations(void);
+
+// These should generate the default (mangled) version and the resolver.
+int default_def_with_version_decls(void) { return 0; }
+__attribute__((target_clones("dotprod", "lse"))) int 
default_def_with_version_decls(void);
+__attribute__((target_version("jscvt"))) int 
default_def_with_version_decls(void);
+
+//.
+// CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
+// CHECK: @explicit_default.ifunc = weak_odr alias i32 (), ptr 
@explicit_default
+// CHECK: @implicit_default.ifunc = weak_odr alias i32 (), ptr 
@implicit_default
+// CHECK: @default_def_with_version_decls.ifunc = weak_odr alias i32 (), ptr 
@default_def_with_version_decls
+// CHECK: @explicit_default = weak_odr ifunc i32 (), ptr 
@explicit_default.resolver
+// CHECK: @implicit_default = weak_odr ifunc i32 (), ptr 
@implicit_default.resolver
+// CHECK: @default_def_with_version_decls = weak_odr ifunc i32 (), ptr 
@default_def_with_version_decls.resolver
+//.
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@explicit_default.default
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 0
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@explicit_default._Mjscvt
+// CHECK-SAME: () #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 1
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@explicit_default._Mdotprod
+// CHECK-SAME: () #[[ATTR2:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 2
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@explicit_default._Mlse
+// CHECK-SAME: () #[[ATTR3:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 2
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@explicit_default.resolver() comdat {
+// CHECK-NEXT:  resolver_entry:
+// CHECK-NEXT:call void @__init_cpu_features_resolver()
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 1048576
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 1048576
+// CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
+// CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
+// CHECK:   resolver_return:
+// CHECK-NEXT:ret ptr @explicit_default._Mjscvt
+// CHECK:   resolver_else:
+// CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 64
+// CHECK-NEXT:[[TMP6:%.*]] = icmp eq i64 [[TMP5]], 64
+// CHECK-NEXT:[[TMP7:%.*]] = and i1 true, [[TMP6]]
+// CHECK-NEXT:br i1 [[TMP7]], label [[RESOLVER_RETURN1:%.*]], label 
[[RESOLVER_ELSE2:%.*]]
+// CHECK:   resolver_return1:
+// CHECK-NEXT:ret ptr @explicit_default._Mrdm
+// CHECK:   resolver_else2:
+// CHECK-NEXT:[[TMP8:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP9:%.*]] = and i64 [[TMP8]], 16
+// CHECK-NEXT:[[TMP10:%.*]] = icmp eq i64 [[TMP9]], 16
+// CHECK-NEXT:[[TMP11:%.*]] = and i1 true, [[TMP10]]
+// CHECK-NEXT:br i1 [[TMP11]], label [[RESOLVER_RETURN3:%.*]], label 
[[RESOLVER_ELSE4:%.*]]
+// CHECK:   resolver_return3:
+// CHECK-NEXT:ret ptr @explicit_default._Mdotprod
+// CHECK:   resolver_else4:
+// CHECK-NEXT:[[TMP12:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[

[clang] [FMV] Allow mixing target_version with target_clones. (PR #86493)

2024-03-25 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/86493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow mixing target_version with target_clones. (PR #86493)

2024-03-26 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/86493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][FMV] Direct-call FMV callees from FMV callers (PR #80093)

2024-03-31 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

@erichkeane while I agree that Clang might not be the best place for such an 
optimization, I have some concerns about implementing it in LLVM:
* We cannot distinguish a FMV resolver from any other ifunc resolver.
* There is no information at the LLVM IR level about function versions or which 
resolver they are associated with. 
* We cannot use target-features to determine version priority since this 
information is encoded via front-end features in the TargetParser. We can only 
rely on the resolver's basic block layout under the assumption that predecessor 
basic blocks correspond to versions of higher priority than successor basic 
blocks. This is fragile and unreliable:
```
void discoverResolvedIFuncsInPriorityOrder(GlobalIFunc *IFunc) {
  DenseMap> ResolvedIFuncs;

  std::function visitValue = [&](Value *V) {
if (auto *Func = dyn_cast(V)) {
  ResolvedIFuncs[IFunc].push_back(Func);
} else if (auto *Sel = dyn_cast(V)) {
  visitValue(Sel->getTrueValue());
  visitValue(Sel->getFalseValue());
} else if (auto *Phi = dyn_cast(V)) {
  for (unsigned I = 0, E = Phi->getNumIncomingValues(); I != E; ++I)
visitValue(Phi->getIncomingValue(I));
}
  };

  for (BasicBlock &BB : *IFunc->getResolverFunction())
if (auto *Ret = dyn_cast_or_null(BB.getTerminator()))
  visitValue(Ret->getReturnValue());
  // discard default
  if (!ResolvedIFuncs[IFunc].empty())
ResolvedIFuncs[IFunc].pop_back();
}
```

https://github.com/llvm/llvm-project/pull/80093
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Fix -Wunused-function on target_version'd file-scope Fn's (PR #81167)

2024-02-08 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea approved this pull request.

LGTM. Good catch, thanks for fixing the bug!

https://github.com/llvm/llvm-project/pull/81167
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][fmv] Drop .ifunc from target_version's entrypoint's mangling (PR #81194)

2024-02-09 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

Looks like we've done something similar for `target_clones` to fix a linker 
issue: 
https://github.com/llvm/llvm-project/commit/cee5b8777fa98312b05bf8aa81554910a8f867c5.
 What is the motive in this case?

https://github.com/llvm/llvm-project/pull/81194
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][fmv] Drop .ifunc from target_version's entrypoint's mangling (PR #81194)

2024-02-09 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:




> Looks like we've done something similar for `target_clones` to fix a linker 
> issue: 
> [cee5b87](https://github.com/llvm/llvm-project/commit/cee5b8777fa98312b05bf8aa81554910a8f867c5).
>  What is the motive in this case?

Ah, I just saw that it fixes https://github.com/llvm/llvm-project/issues/81043.

https://github.com/llvm/llvm-project/pull/81194
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][fmv] Drop .ifunc from target_version's entrypoint's mangling (PR #81194)

2024-02-09 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/81194
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [TargetParser][AArch64] Add alias for FEAT_RDM. (PR #80540)

2024-02-10 Thread Alexandros Lamprineas via cfe-commits


@@ -673,7 +673,7 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MlseMrdm
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MlseMrdma

labrinea wrote:

I raised this with the GCC team, I don't have an answer yet but I believe GCC 
only accepts "rdma" on the attribute (so I suppose that makes its way to the 
mangled name?). I remember you raised this matter again in a previous review, 
when we changed priorities and the mangling was affected. That is a good point 
but I think first we need to agree whether those functions are part of the ABI 
or not. Right now I don't see why they need to be. We could even make then have 
internal linkage, no? If I am mistaken a counter example would help, thanks!

https://github.com/llvm/llvm-project/pull/80540
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [TargetParser][AArch64] Add alias for FEAT_RDM. (PR #80540)

2024-02-12 Thread Alexandros Lamprineas via cfe-commits


@@ -673,7 +673,7 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MlseMrdm
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MlseMrdma

labrinea wrote:

Right, I didn't know that the resolver contains references to every 
target-version declaration that is visible in its translation unit even if the 
definition actually resides in another translation unit. That would be a 
problem if the definition has a mangled name that doesn't match because of the 
alias. Thanks for clarifying!

https://github.com/llvm/llvm-project/pull/80540
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow target version definitions in any order. (PR #83887)

2024-03-06 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/83887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Remove duplicate features from mangled name. (PR #84165)

2024-03-06 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/84165

ACLE suggests: https://github.com/ARM-software/acle/pull/308 GCC emits 
diagnostics for attribute strings which contain duplicate features, but for now 
let's follow the SPEC in regards to mangling rules and we can change the 
semantic behavior of the compiler later if there's value to it.

>From 1c10c683bc73fd928e7f3dfb58bc8de2b6776a88 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Wed, 6 Mar 2024 12:30:30 +
Subject: [PATCH] [FMV] Remove duplicate features from mangled name.

ACLE suggests: https://github.com/ARM-software/acle/pull/308
GCC emits diagnostics for attribute strings which contain
duplicate features, but for now let's follow the SPEC in
regards to mangling rules and we can change the semantic
behavior of the compiler later if there's value to it.
---
 clang/lib/CodeGen/Targets/AArch64.cpp| 4 +++-
 clang/test/CodeGen/attr-target-version.c | 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index 725e8a70fddfe6..85117366de0ee8 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -886,9 +886,11 @@ void AArch64ABIInfo::appendAttributeMangling(StringRef 
AttrStr,
 return LHS.compare(RHS) < 0;
   });
 
+  llvm::SmallDenseSet UniqueFeats;
   for (auto &Feat : Features)
 if (auto Ext = llvm::AArch64::parseArchExtension(Feat))
-  Out << 'M' << Ext->Name;
+  if (UniqueFeats.insert(Ext->Name).second)
+Out << 'M' << Ext->Name;
 }
 
 std::unique_ptr
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index ae1a8772f6cc07..b7112c783da913 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -273,7 +273,7 @@ int hoo(void) {
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @fmv_inline._MfcmaMfp16Mfp16MrdmMsme
+// CHECK-NEXT:ret ptr @fmv_inline._MfcmaMfp16MrdmMsme
 // CHECK:   resolver_else:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
 // CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 864726312827224064
@@ -582,7 +582,7 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MfcmaMfp16Mfp16MrdmMsme
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MfcmaMfp16MrdmMsme
 // CHECK-SAME: () #[[ATTR13:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 2

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Remove duplicate features from mangled name. (PR #84165)

2024-03-07 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/84165
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-07 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/84405

We would like the resolver to be generated eagerly, even if the versioned 
function is not called from the current translation unit. Fixes #81494.

>From d2572439a8e130c03febd60366962c96b5b4501d Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 7 Mar 2024 22:25:13 +
Subject: [PATCH] [FMV] Emit the resolver along with the default version
 definition.

We would like the resolver to be generated eagerly, even if the
versioned function is not called from the current translation
unit. Fixes #81494.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |   7 +-
 clang/test/CodeGen/attr-target-version.c  | 403 +++---
 clang/test/CodeGenCXX/attr-target-version.cpp | 172 +---
 3 files changed, 364 insertions(+), 218 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 967319bdfc4571..ee688a4c17c1d4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3969,8 +3969,11 @@ void 
CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
 EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
 // Ensure that the resolver function is also emitted.
 GetOrCreateMultiVersionResolver(GD);
-  } else if (FD->hasAttr()) {
-GetOrCreateMultiVersionResolver(GD);
+  } else if (auto *TVA = FD->getAttr()) {
+EmitGlobalFunctionDefinition(GD, GV);
+// Emit the resolver alongside with the default version definition.
+if (TVA->isDefaultVersion() && FD->doesThisDeclarationHaveABody())
+  GetOrCreateMultiVersionResolver(GD);
   } else
 EmitGlobalFunctionDefinition(GD, GV);
 }
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index b7112c783da913..cb425b12702db3 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -85,7 +85,21 @@ int hoo(void) {
 }
 
 
+// This should generate one target version but no resolver.
+__attribute__((target_version("default"))) int 
unused_with_forward_default_decl(void);
+__attribute__((target_version("mops"))) int 
unused_with_forward_default_decl(void) { return 0; }
 
+// FIXME: If the default declaration follows the non-default definition,
+//then target versioning does not trigger.
+__attribute__((target_version("aes"))) int unused_with_default_decl(void) { 
return 0; }
+__attribute__((target_version("default"))) int unused_with_default_decl(void);
+
+// This should generate two target versions and the resolver.
+__attribute__((target_version("sve"))) int unused_with_default_def(void) { 
return 0; }
+__attribute__((target_version("default"))) int unused_with_default_def(void) { 
return 1; }
+
+// This should generate a normal function.
+__attribute__((target_version("rdm"))) int unused_without_default(void) { 
return 0; }
 
 
 //.
@@ -97,6 +111,7 @@ int hoo(void) {
 // CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
 // CHECK: @fmv_inline.ifunc = weak_odr alias i32 (), ptr @fmv_inline
 // CHECK: @fmv_d.ifunc = internal alias i32 (), ptr @fmv_d
+// CHECK: @unused_with_default_def.ifunc = weak_odr alias i32 (), ptr 
@unused_with_default_def
 // CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
 // CHECK: @fmv_one = weak_odr ifunc i32 (), ptr @fmv_one.resolver
 // CHECK: @fmv_two = weak_odr ifunc i32 (), ptr @fmv_two.resolver
@@ -104,6 +119,7 @@ int hoo(void) {
 // CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 // CHECK: @fmv_inline = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
 // CHECK: @fmv_d = internal ifunc i32 (), ptr @fmv_d.resolver
+// CHECK: @unused_with_default_def = weak_odr ifunc i32 (), ptr 
@unused_with_default_def.resolver
 //.
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@fmv._MflagmMfp16fmlMrng
@@ -113,29 +129,66 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_one._Mls64Msimd
+// CHECK-LABEL: define {{[^@]+}}@fmv._Mflagm2Msme-i16i64
 // CHECK-SAME: () #[[ATTR1:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:ret i32 1
+// CHECK-NEXT:ret i32 2
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_two._Mfp
-// CHECK-SAME: () #[[ATTR1]] {
+// CHECK-LABEL: define {{[^@]+}}@fmv._MlseMsha2
+// CHECK-SAME: () #[[ATTR2:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:ret i32 1
+// CHECK-NEXT:ret i32 3
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@foo
-// CHECK-SAME: () #[[ATTR2:[0-9]+]] {
+// CHECK-LABEL: define {{[^@]+}}@fmv._MdotprodMls64_accdata
+// CHECK-SAME: () #[[ATTR3:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[CALL:%.*]] = call i32 @fmv()
-// CHECK-NEXT:[[CALL1:%.*]] = call i32 @fmv_one()
-// CHECK-NEXT:[[ADD:%.*]] = add nsw i32 [[CALL]], [[C

[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-07 Thread Alexandros Lamprineas via cfe-commits


@@ -85,7 +85,21 @@ int hoo(void) {
 }
 
 
+// This should generate one target version but no resolver.
+__attribute__((target_version("default"))) int 
unused_with_forward_default_decl(void);
+__attribute__((target_version("mops"))) int 
unused_with_forward_default_decl(void) { return 0; }
 
+// FIXME: If the default declaration follows the non-default definition,

labrinea wrote:

This bug (if we consider it as such) seems unrelated to this patch, but since I 
found it it deserves a test at least to monitor what we are currently 
generating for it.

https://github.com/llvm/llvm-project/pull/84405
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-26 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/81893

>From 20734a17b90e4b425aa86f152777301cda810e63 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 15 Feb 2024 15:53:51 +
Subject: [PATCH] [clang] Refactor target attribute mangling.

Before this patch all of the 'target', 'target_version' and 'target_clones'
attributes were sharing a common mangling logic across different targets.
However we would like to differenciate this logic, therefore I have moved
the default path to ABIInfo and provided overrides for AArch64. This
way we can resolve feature aliases without affecting the name mangling
The PR #80540 demonstrates a motivating case.
---
 clang/lib/CodeGen/ABIInfo.cpp |  51 
 clang/lib/CodeGen/ABIInfo.h   |   8 ++
 clang/lib/CodeGen/CodeGenModule.cpp   | 111 --
 clang/lib/CodeGen/Targets/AArch64.cpp |  34 
 4 files changed, 109 insertions(+), 95 deletions(-)

diff --git a/clang/lib/CodeGen/ABIInfo.cpp b/clang/lib/CodeGen/ABIInfo.cpp
index 1b56cf7c596d06..7eb0b2e31159b9 100644
--- a/clang/lib/CodeGen/ABIInfo.cpp
+++ b/clang/lib/CodeGen/ABIInfo.cpp
@@ -184,6 +184,57 @@ ABIArgInfo ABIInfo::getNaturalAlignIndirectInReg(QualType 
Ty,
   /*ByVal*/ false, Realign);
 }
 
+std::string ABIInfo::getManglingSuffixFromAttr(TargetAttr *Attr) const {
+  if (Attr->isDefaultVersion())
+return {};
+
+  return getManglingSuffixFromStr(Attr->getFeaturesStr());
+}
+
+std::string ABIInfo::getManglingSuffixFromAttr(TargetVersionAttr *Attr) const {
+  return getManglingSuffixFromStr(Attr->getNamesStr());
+}
+
+std::string ABIInfo::getManglingSuffixFromAttr(TargetClonesAttr *Attr,
+   unsigned Index) const {
+  std::string Suffix = getManglingSuffixFromStr(Attr->getFeatureStr(Index));
+  Suffix.append("." + Twine(Attr->getMangledIndex(Index)).str());
+  return Suffix;
+}
+
+std::string ABIInfo::getManglingSuffixFromStr(StringRef AttrStr) const {
+  if (AttrStr == "default")
+return ".default";
+
+  std::string ManglingSuffix(".");
+  const TargetInfo &TI = CGT.getTarget();
+  ParsedTargetAttr Info = TI.parseTargetAttr(AttrStr);
+
+  llvm::sort(Info.Features, [&TI](StringRef LHS, StringRef RHS) {
+// Multiversioning doesn't allow "no-${feature}", so we can
+// only have "+" prefixes here.
+assert(LHS.starts_with("+") && RHS.starts_with("+") &&
+   "Features should always have a prefix.");
+return TI.multiVersionSortPriority(LHS.substr(1)) >
+   TI.multiVersionSortPriority(RHS.substr(1));
+  });
+
+  bool IsFirst = true;
+  if (!Info.CPU.empty()) {
+IsFirst = false;
+ManglingSuffix.append(Twine("arch_", Info.CPU).str());
+  }
+
+  for (StringRef Feat : Info.Features) {
+if (!IsFirst)
+  ManglingSuffix.append("_");
+IsFirst = false;
+ManglingSuffix.append(Feat.substr(1).str());
+  }
+
+  return ManglingSuffix;
+}
+
 // Pin the vtable to this file.
 SwiftABIInfo::~SwiftABIInfo() = default;
 
diff --git a/clang/lib/CodeGen/ABIInfo.h b/clang/lib/CodeGen/ABIInfo.h
index b9a5ef6e436693..56b4a89d2507f1 100644
--- a/clang/lib/CodeGen/ABIInfo.h
+++ b/clang/lib/CodeGen/ABIInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
 #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
 
+#include "clang/AST/Attr.h"
 #include "clang/AST/CharUnits.h"
 #include "clang/AST/Type.h"
 #include "llvm/IR/CallingConv.h"
@@ -111,6 +112,13 @@ class ABIInfo {
 
   CodeGen::ABIArgInfo getNaturalAlignIndirectInReg(QualType Ty,
bool Realign = false) const;
+
+  virtual std::string getManglingSuffixFromAttr(TargetAttr *Attr) const;
+  virtual std::string getManglingSuffixFromAttr(TargetVersionAttr *Attr) const;
+  virtual std::string getManglingSuffixFromAttr(TargetClonesAttr *Attr,
+unsigned VersionIndex) const;
+
+  virtual std::string getManglingSuffixFromStr(StringRef AttrStr) const;
 };
 
 /// Target specific hooks for defining how a type should be passed or returned
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 95e457bef28ed3..e9bbc2706a693c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1726,59 +1726,6 @@ static void AppendCPUSpecificCPUDispatchMangling(const 
CodeGenModule &CGM,
 Out << ".resolver";
 }
 
-static void AppendTargetVersionMangling(const CodeGenModule &CGM,
-const TargetVersionAttr *Attr,
-raw_ostream &Out) {
-  if (Attr->isDefaultVersion()) {
-Out << ".default";
-return;
-  }
-  Out << "._";
-  const TargetInfo &TI = CGM.getTarget();
-  llvm::SmallVector Feats;
-  Attr->getFeatures(Feats);
-  llvm::stable_sort(Feats, [&TI](const StringRef FeatL, const StringRef FeatR) 
{
-return TI.multiVersionSortPriori

[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-26 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/81893
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-27 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

ping

https://github.com/llvm/llvm-project/pull/81893
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-28 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/81893

>From 4bff4f1378140b084256cf1647d26466e95d6ef7 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 15 Feb 2024 15:53:51 +
Subject: [PATCH] [clang] Refactor target attribute mangling.

Before this patch all of the 'target', 'target_version' and 'target_clones'
attributes were sharing a common mangling logic across different targets.
However we would like to differenciate this logic, therefore I have moved
the default path to ABIInfo and provided overrides for AArch64. This
way we can resolve feature aliases without affecting the name mangling
The PR #80540 demonstrates a motivating case.
---
 clang/lib/CodeGen/ABIInfo.cpp |  52 
 clang/lib/CodeGen/ABIInfo.h   |   8 ++
 clang/lib/CodeGen/CodeGenModule.cpp   | 111 --
 clang/lib/CodeGen/Targets/AArch64.cpp |  37 +
 4 files changed, 113 insertions(+), 95 deletions(-)

diff --git a/clang/lib/CodeGen/ABIInfo.cpp b/clang/lib/CodeGen/ABIInfo.cpp
index 1b56cf7c596d06..efcff958ce5452 100644
--- a/clang/lib/CodeGen/ABIInfo.cpp
+++ b/clang/lib/CodeGen/ABIInfo.cpp
@@ -184,6 +184,58 @@ ABIArgInfo ABIInfo::getNaturalAlignIndirectInReg(QualType 
Ty,
   /*ByVal*/ false, Realign);
 }
 
+void ABIInfo::appendAttributeMangling(TargetAttr *Attr,
+  raw_ostream &Out) const {
+  if (Attr->isDefaultVersion())
+return;
+  appendAttributeMangling(Attr->getFeaturesStr(), Out);
+}
+
+void ABIInfo::appendAttributeMangling(TargetVersionAttr *Attr,
+  raw_ostream &Out) const {
+  appendAttributeMangling(Attr->getNamesStr(), Out);
+}
+
+void ABIInfo::appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
+  raw_ostream &Out) const {
+  appendAttributeMangling(Attr->getFeatureStr(Index), Out);
+  Out << '.' << Attr->getMangledIndex(Index);
+}
+
+void ABIInfo::appendAttributeMangling(StringRef AttrStr,
+  raw_ostream &Out) const {
+  if (AttrStr == "default") {
+Out << ".default";
+return;
+  }
+
+  Out << '.';
+  const TargetInfo &TI = CGT.getTarget();
+  ParsedTargetAttr Info = TI.parseTargetAttr(AttrStr);
+
+  llvm::sort(Info.Features, [&TI](StringRef LHS, StringRef RHS) {
+// Multiversioning doesn't allow "no-${feature}", so we can
+// only have "+" prefixes here.
+assert(LHS.starts_with("+") && RHS.starts_with("+") &&
+   "Features should always have a prefix.");
+return TI.multiVersionSortPriority(LHS.substr(1)) >
+   TI.multiVersionSortPriority(RHS.substr(1));
+  });
+
+  bool IsFirst = true;
+  if (!Info.CPU.empty()) {
+IsFirst = false;
+Out << "arch_" << Info.CPU;
+  }
+
+  for (StringRef Feat : Info.Features) {
+if (!IsFirst)
+  Out << '_';
+IsFirst = false;
+Out << Feat.substr(1);
+  }
+}
+
 // Pin the vtable to this file.
 SwiftABIInfo::~SwiftABIInfo() = default;
 
diff --git a/clang/lib/CodeGen/ABIInfo.h b/clang/lib/CodeGen/ABIInfo.h
index b9a5ef6e436693..dccd23c0f97411 100644
--- a/clang/lib/CodeGen/ABIInfo.h
+++ b/clang/lib/CodeGen/ABIInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
 #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
 
+#include "clang/AST/Attr.h"
 #include "clang/AST/CharUnits.h"
 #include "clang/AST/Type.h"
 #include "llvm/IR/CallingConv.h"
@@ -111,6 +112,13 @@ class ABIInfo {
 
   CodeGen::ABIArgInfo getNaturalAlignIndirectInReg(QualType Ty,
bool Realign = false) const;
+
+  virtual void appendAttributeMangling(TargetAttr *Attr, raw_ostream &Out) 
const;
+  virtual void appendAttributeMangling(TargetVersionAttr *Attr,
+   raw_ostream &Out) const;
+  virtual void appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
+   raw_ostream &Out) const;
+  virtual void appendAttributeMangling(StringRef AttrStr, raw_ostream &Out) 
const;
 };
 
 /// Target specific hooks for defining how a type should be passed or returned
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 95e457bef28ed3..160917d47da1f3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1726,59 +1726,6 @@ static void AppendCPUSpecificCPUDispatchMangling(const 
CodeGenModule &CGM,
 Out << ".resolver";
 }
 
-static void AppendTargetVersionMangling(const CodeGenModule &CGM,
-const TargetVersionAttr *Attr,
-raw_ostream &Out) {
-  if (Attr->isDefaultVersion()) {
-Out << ".default";
-return;
-  }
-  Out << "._";
-  const TargetInfo &TI = CGM.getTarget();
-  llvm::SmallVector Feats;
-  Attr->getFeatures(Feats);
-  llvm::stable_sort(Feats, [&TI](const StringRef FeatL, const StringRef 

[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-28 Thread Alexandros Lamprineas via cfe-commits


@@ -857,6 +864,36 @@ void AArch64TargetCodeGenInfo::checkFunctionCallABI(
   << Callee->getDeclName();
 }
 
+void AArch64ABIInfo::appendAttributeMangling(TargetClonesAttr *Attr,
+ unsigned Index,
+ raw_ostream &Out) const {
+  appendAttributeMangling(Attr->getFeatureStr(Index), Out);
+}
+
+void AArch64ABIInfo::appendAttributeMangling(StringRef AttrStr,
+ raw_ostream &Out) const {
+  if (AttrStr == "default") {
+Out << ".default";
+return;
+  }
+
+  Out << "._";
+  SmallVector Features;
+  AttrStr.split(Features, "+");
+  for (auto &Feat : Features)
+Feat = Feat.trim();
+
+  // TODO Lexicographical order won't break the ABI if priorities change.

labrinea wrote:

I can change this to say FIXME instead and write a more descriptive comment. 
For context please read 
https://github.com/llvm/llvm-project/pull/79316#discussion_r1469932618. It 
shouldn't stick around for long, as soon as we reach a conclusion I can update 
the sorting criteria of this lambda.

https://github.com/llvm/llvm-project/pull/81893
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-28 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/81893

>From ed8c2af0e301885101097c23cc96c872e8650529 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 15 Feb 2024 15:53:51 +
Subject: [PATCH] [clang] Refactor target attribute mangling.

Before this patch all of the 'target', 'target_version' and 'target_clones'
attributes were sharing a common mangling logic across different targets.
However we would like to differenciate this logic, therefore I have moved
the default path to ABIInfo and provided overrides for AArch64. This
way we can resolve feature aliases without affecting the name mangling
The PR #80540 demonstrates a motivating case.
---
 clang/lib/CodeGen/ABIInfo.cpp |  52 
 clang/lib/CodeGen/ABIInfo.h   |  10 +++
 clang/lib/CodeGen/CodeGenModule.cpp   | 111 --
 clang/lib/CodeGen/Targets/AArch64.cpp |  40 ++
 4 files changed, 118 insertions(+), 95 deletions(-)

diff --git a/clang/lib/CodeGen/ABIInfo.cpp b/clang/lib/CodeGen/ABIInfo.cpp
index 1b56cf7c596d06..efcff958ce5452 100644
--- a/clang/lib/CodeGen/ABIInfo.cpp
+++ b/clang/lib/CodeGen/ABIInfo.cpp
@@ -184,6 +184,58 @@ ABIArgInfo ABIInfo::getNaturalAlignIndirectInReg(QualType 
Ty,
   /*ByVal*/ false, Realign);
 }
 
+void ABIInfo::appendAttributeMangling(TargetAttr *Attr,
+  raw_ostream &Out) const {
+  if (Attr->isDefaultVersion())
+return;
+  appendAttributeMangling(Attr->getFeaturesStr(), Out);
+}
+
+void ABIInfo::appendAttributeMangling(TargetVersionAttr *Attr,
+  raw_ostream &Out) const {
+  appendAttributeMangling(Attr->getNamesStr(), Out);
+}
+
+void ABIInfo::appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
+  raw_ostream &Out) const {
+  appendAttributeMangling(Attr->getFeatureStr(Index), Out);
+  Out << '.' << Attr->getMangledIndex(Index);
+}
+
+void ABIInfo::appendAttributeMangling(StringRef AttrStr,
+  raw_ostream &Out) const {
+  if (AttrStr == "default") {
+Out << ".default";
+return;
+  }
+
+  Out << '.';
+  const TargetInfo &TI = CGT.getTarget();
+  ParsedTargetAttr Info = TI.parseTargetAttr(AttrStr);
+
+  llvm::sort(Info.Features, [&TI](StringRef LHS, StringRef RHS) {
+// Multiversioning doesn't allow "no-${feature}", so we can
+// only have "+" prefixes here.
+assert(LHS.starts_with("+") && RHS.starts_with("+") &&
+   "Features should always have a prefix.");
+return TI.multiVersionSortPriority(LHS.substr(1)) >
+   TI.multiVersionSortPriority(RHS.substr(1));
+  });
+
+  bool IsFirst = true;
+  if (!Info.CPU.empty()) {
+IsFirst = false;
+Out << "arch_" << Info.CPU;
+  }
+
+  for (StringRef Feat : Info.Features) {
+if (!IsFirst)
+  Out << '_';
+IsFirst = false;
+Out << Feat.substr(1);
+  }
+}
+
 // Pin the vtable to this file.
 SwiftABIInfo::~SwiftABIInfo() = default;
 
diff --git a/clang/lib/CodeGen/ABIInfo.h b/clang/lib/CodeGen/ABIInfo.h
index b9a5ef6e436693..ff4ae44a42c332 100644
--- a/clang/lib/CodeGen/ABIInfo.h
+++ b/clang/lib/CodeGen/ABIInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
 #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
 
+#include "clang/AST/Attr.h"
 #include "clang/AST/CharUnits.h"
 #include "clang/AST/Type.h"
 #include "llvm/IR/CallingConv.h"
@@ -111,6 +112,15 @@ class ABIInfo {
 
   CodeGen::ABIArgInfo getNaturalAlignIndirectInReg(QualType Ty,
bool Realign = false) const;
+
+  virtual void appendAttributeMangling(TargetAttr *Attr,
+   raw_ostream &Out) const;
+  virtual void appendAttributeMangling(TargetVersionAttr *Attr,
+   raw_ostream &Out) const;
+  virtual void appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
+   raw_ostream &Out) const;
+  virtual void appendAttributeMangling(StringRef AttrStr,
+   raw_ostream &Out) const;
 };
 
 /// Target specific hooks for defining how a type should be passed or returned
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 95e457bef28ed3..160917d47da1f3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1726,59 +1726,6 @@ static void AppendCPUSpecificCPUDispatchMangling(const 
CodeGenModule &CGM,
 Out << ".resolver";
 }
 
-static void AppendTargetVersionMangling(const CodeGenModule &CGM,
-const TargetVersionAttr *Attr,
-raw_ostream &Out) {
-  if (Attr->isDefaultVersion()) {
-Out << ".default";
-return;
-  }
-  Out << "._";
-  const TargetInfo &TI = CGM.getTarget();
-  llvm::SmallVector Feats;
-  Attr->getFeatures(F

[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-28 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/81893
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-28 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/81893
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [TargetParser][AArch64] Add alias for FEAT_RDM. (PR #80540)

2024-02-28 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/80540

>From fb56f1c31f7f6fb847b95e0ffe97a39ac76759a9 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Tue, 30 Jan 2024 11:17:55 +
Subject: [PATCH] [TargetParser][AArch64] Add alias for FEAT_RDM.

This patch allows using the name "rdma" as an alias for "rdm".
The name makes its way to target attributes as well as the
command line via the -march and -mcpu options. The motivation
was originally to support this in Function Multi Versioning
but it also makes sense to align with GCC on the command line.
---
 clang/docs/ReleaseNotes.rst   |  5 +
 clang/test/CodeGen/attr-target-version.c  | 12 ++--
 clang/test/Driver/aarch64-rdm.c   |  3 +++
 clang/test/Sema/attr-target-clones-aarch64.c  |  2 +-
 clang/test/SemaCXX/attr-target-version.cpp|  1 +
 .../llvm/TargetParser/AArch64TargetParser.h   | 13 -
 llvm/lib/TargetParser/AArch64TargetParser.cpp | 15 +--
 7 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e16b9f0c67dbd1..6ab31498ff33b9d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -325,6 +325,11 @@ Arm and AArch64 Support
   improvements for most targets. We have not changed the default behavior for
   ARMv6, but may revisit that decision in the future. Users can restore the old
   behavior with -m[no-]unaligned-access.
+- An alias identifier (rdma) has been added for targeting the AArch64
+  Architecture Extension which uses Rounding Doubling Multiply Accumulate
+  instructions (rdm). The identifier is available on the command line as
+  a feature modifier for -march and -mcpu as well as via target attributes
+  like ``target_version`` or ``target_clones``.
 
 Android Support
 ^^^
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index c27d48f3ecf681d..9eb9f3c73178479 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -25,7 +25,7 @@ int foo() {
 }
 
 inline int __attribute__((target_version("sha1+pmull+f64mm"))) 
fmv_inline(void) { return 1; }
-inline int __attribute__((target_version("fp16+fcma+sme+ fp16 "))) 
fmv_inline(void) { return 2; }
+inline int __attribute__((target_version("fp16+fcma+rdma+sme+ fp16 "))) 
fmv_inline(void) { return 2; }
 inline int __attribute__((target_version("sha3+i8mm+f32mm"))) fmv_inline(void) 
{ return 12; }
 inline int __attribute__((target_version("dit+sve-ebf16"))) fmv_inline(void) { 
return 8; }
 inline int __attribute__((target_version("dpb+rcpc2 "))) fmv_inline(void) { 
return 6; }
@@ -261,12 +261,12 @@ int hoo(void) {
 // CHECK-NEXT:  resolver_entry:
 // CHECK-NEXT:call void @__init_cpu_features_resolver()
 // CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 4398048608256
-// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 4398048608256
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 4398048608320
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 4398048608320
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @fmv_inline._Mfp16Mfp16MfcmaMsme
+// CHECK-NEXT:ret ptr @fmv_inline._MrdmMfp16Mfp16MfcmaMsme
 // CHECK:   resolver_else:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
 // CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 864726312827224064
@@ -575,7 +575,7 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Mfp16Mfp16MfcmaMsme
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MrdmMfp16Mfp16MfcmaMsme
 // CHECK-SAME: () #[[ATTR13:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 2
@@ -829,7 +829,7 @@ int hoo(void) {
 // CHECK: attributes #[[ATTR10]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+bf16,+fullfp16,+ls64,+sme,+sme2" }
 // CHECK: attributes #[[ATTR11]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+ccpp,+fullfp16,+ls64" }
 // CHECK: attributes #[[ATTR12]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+aes,+f64mm,+fp-armv8,+fullfp16,+ls64,+neon,+sve" }
-// CHECK: attributes #[[ATTR13]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+bf16,+complxnum,+fp-armv8,+fullfp16,+ls64,+neon,+sme" }
+// CHECK: attributes #[[ATTR13]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-fea

[clang] [FMV] Use lexicographic order of feature names when mangling. (PR #83464)

2024-02-29 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/83464

This decouples feature priorities from name mangling. Doing so will prevent ABI 
breakages in case we change the feature priorities. Formalized in ACLE here: 
https://github.com/ARM-software/acle/pull/303.

>From 7aefd2164bca3edfe9b373bfd2a29a49a6a4a8e2 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 29 Feb 2024 17:54:12 +
Subject: [PATCH] [FMV] Use lexicographic order of feature names when mangling.

This decouples feature priorities from name mangling. Doing so will
prevent ABI breakages in case we change the feature priorities.
---
 clang/lib/CodeGen/Targets/AArch64.cpp |  6 +-
 .../test/CodeGen/attr-target-clones-aarch64.c | 20 ++---
 clang/test/CodeGen/attr-target-version.c  | 52 ++---
 .../CodeGenCXX/attr-target-clones-aarch64.cpp | 74 +++
 clang/test/CodeGenCXX/attr-target-version.cpp |  4 +-
 5 files changed, 99 insertions(+), 57 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index adfdd516351901..4eb0f945d59df9 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -883,13 +883,9 @@ void AArch64ABIInfo::appendAttributeMangling(StringRef 
AttrStr,
   for (auto &Feat : Features)
 Feat = Feat.trim();
 
-  // FIXME: It was brought up in #79316 that sorting the features which are
-  // used for mangling based on their multiversion priority is not a good
-  // practice. Changing the feature priorities will break the ABI. Perhaps
-  // it would be preferable to perform a lexicographical sort instead.
   const TargetInfo &TI = CGT.getTarget();
   llvm::sort(Features, [&TI](const StringRef LHS, const StringRef RHS) {
-return TI.multiVersionSortPriority(LHS) < TI.multiVersionSortPriority(RHS);
+return LHS.compare(RHS) < 0;
   });
 
   for (auto &Feat : Features)
diff --git a/clang/test/CodeGen/attr-target-clones-aarch64.c 
b/clang/test/CodeGen/attr-target-clones-aarch64.c
index 5ea3f4a9b0b112..276a7b87b7a1b4 100644
--- a/clang/test/CodeGen/attr-target-clones-aarch64.c
+++ b/clang/test/CodeGen/attr-target-clones-aarch64.c
@@ -43,7 +43,7 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 // CHECK: @ftc_inline3 = weak_odr ifunc i32 (), ptr @ftc_inline3.resolver
 //.
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: @ftc._MlseMaes(
+// CHECK-LABEL: @ftc._MaesMlse(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 0
 //
@@ -69,7 +69,7 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @ftc._MlseMaes
+// CHECK-NEXT:ret ptr @ftc._MaesMlse
 // CHECK:   resolver_else:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
 // CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 68719476736
@@ -89,7 +89,7 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: @ftc_def._Msha2Mmemtag2(
+// CHECK-LABEL: @ftc_def._Mmemtag2Msha2(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 1
 //
@@ -109,7 +109,7 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @ftc_def._Msha2Mmemtag2
+// CHECK-NEXT:ret ptr @ftc_def._Mmemtag2Msha2
 // CHECK:   resolver_else:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
 // CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 4096
@@ -155,7 +155,7 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: @ftc_dup2._MdotprodMcrc(
+// CHECK-LABEL: @ftc_dup2._McrcMdotprod(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 3
 //
@@ -175,7 +175,7 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @ftc_dup2._MdotprodMcrc
+// CHECK-NEXT:ret ptr @ftc_dup2._McrcMdotprod
 // CHECK:   resolver_else:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
 // CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 256
@@ -239,7 +239,7 @@ inline int __attribute__((target_clones("fp16", 
"sve2-bitperm+fcma", "default"))
 // CHECK-NEXT:[[TMP7:%.*]] = and i1 true, [[TMP6]]
 // 

[clang] [FMV] Use lexicographic order of feature names when mangling. (PR #83464)

2024-03-01 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/83464
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [TargetParser][AArch64] Add alias for FEAT_RDM. (PR #80540)

2024-03-01 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/80540

>From 6f1f4e18de7ebad5e090ea268f3f053562db444c Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Tue, 30 Jan 2024 11:17:55 +
Subject: [PATCH] [TargetParser][AArch64] Add alias for FEAT_RDM.

This patch allows using the name "rdma" as an alias for "rdm".
The name makes its way to target attributes as well as the
command line via the -march and -mcpu options. The motivation
was originally to support this in Function Multi Versioning
but it also makes sense to align with GCC on the command line.
---
 clang/docs/ReleaseNotes.rst   |  5 +
 clang/test/CodeGen/attr-target-version.c  | 12 ++--
 clang/test/Driver/aarch64-rdm.c   |  3 +++
 clang/test/Sema/attr-target-clones-aarch64.c  |  2 +-
 clang/test/SemaCXX/attr-target-version.cpp|  1 +
 .../llvm/TargetParser/AArch64TargetParser.h   | 13 -
 llvm/lib/TargetParser/AArch64TargetParser.cpp | 15 +--
 7 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f44fef28b9f17f..530158dda66689 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -333,6 +333,11 @@ Arm and AArch64 Support
   improvements for most targets. We have not changed the default behavior for
   ARMv6, but may revisit that decision in the future. Users can restore the old
   behavior with -m[no-]unaligned-access.
+- An alias identifier (rdma) has been added for targeting the AArch64
+  Architecture Extension which uses Rounding Doubling Multiply Accumulate
+  instructions (rdm). The identifier is available on the command line as
+  a feature modifier for -march and -mcpu as well as via target attributes
+  like ``target_version`` or ``target_clones``.
 
 Android Support
 ^^^
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index ae97977a9144f6..56a42499d0a7ca 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -25,7 +25,7 @@ int foo() {
 }
 
 inline int __attribute__((target_version("sha1+pmull+f64mm"))) 
fmv_inline(void) { return 1; }
-inline int __attribute__((target_version("fp16+fcma+sme+ fp16 "))) 
fmv_inline(void) { return 2; }
+inline int __attribute__((target_version("fp16+fcma+rdma+sme+ fp16 "))) 
fmv_inline(void) { return 2; }
 inline int __attribute__((target_version("sha3+i8mm+f32mm"))) fmv_inline(void) 
{ return 12; }
 inline int __attribute__((target_version("dit+sve-ebf16"))) fmv_inline(void) { 
return 8; }
 inline int __attribute__((target_version("dpb+rcpc2 "))) fmv_inline(void) { 
return 6; }
@@ -261,12 +261,12 @@ int hoo(void) {
 // CHECK-NEXT:  resolver_entry:
 // CHECK-NEXT:call void @__init_cpu_features_resolver()
 // CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 4398048608256
-// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 4398048608256
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 4398048608320
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 4398048608320
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @fmv_inline._MfcmaMfp16Mfp16Msme
+// CHECK-NEXT:ret ptr @fmv_inline._MfcmaMfp16Mfp16MrdmMsme
 // CHECK:   resolver_else:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
 // CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 864726312827224064
@@ -575,7 +575,7 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MfcmaMfp16Mfp16Msme
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MfcmaMfp16Mfp16MrdmMsme
 // CHECK-SAME: () #[[ATTR13:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 2
@@ -829,7 +829,7 @@ int hoo(void) {
 // CHECK: attributes #[[ATTR10]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+bf16,+fullfp16,+ls64,+sme,+sme2" }
 // CHECK: attributes #[[ATTR11]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+ccpp,+fullfp16,+ls64" }
 // CHECK: attributes #[[ATTR12]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+aes,+f64mm,+fp-armv8,+fullfp16,+ls64,+neon,+sve" }
-// CHECK: attributes #[[ATTR13]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+bf16,+complxnum,+fp-armv8,+fullfp16,+ls64,+neon,+sme" }
+// CHECK: attributes #[[ATTR13]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-feature

[clang] [clang] Remove unused lambda capture. (PR #83550)

2024-03-01 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/83550

Fixes the `sanitizer-x86_64-linux-android` buildbot.

>From df67789e087ff560d39b038f7073b3ae90061ff2 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Fri, 1 Mar 2024 09:59:51 +
Subject: [PATCH] [clang] Remove unused lambda capture.

Fixes the `sanitizer-x86_64-linux-android` buildbot.
---
 clang/lib/CodeGen/Targets/AArch64.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index 79a9c1d5978a14..725e8a70fddfe6 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -882,8 +882,7 @@ void AArch64ABIInfo::appendAttributeMangling(StringRef 
AttrStr,
   for (auto &Feat : Features)
 Feat = Feat.trim();
 
-  const TargetInfo &TI = CGT.getTarget();
-  llvm::sort(Features, [&TI](const StringRef LHS, const StringRef RHS) {
+  llvm::sort(Features, [](const StringRef LHS, const StringRef RHS) {
 return LHS.compare(RHS) < 0;
   });
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Remove unused lambda capture. (PR #83550)

2024-03-01 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

Thanks for the quick respose!

https://github.com/llvm/llvm-project/pull/83550
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Remove unused lambda capture. (PR #83550)

2024-03-01 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/83550
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [TargetParser][AArch64] Add alias for FEAT_RDM. (PR #80540)

2024-03-01 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/80540

>From d2c973c8ebd7605b47a8c5fc928d2d85426c8a6d Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Tue, 30 Jan 2024 11:17:55 +
Subject: [PATCH] [TargetParser][AArch64] Add alias for FEAT_RDM.

This patch allows using the name "rdma" as an alias for "rdm".
The name makes its way to target attributes as well as the
command line via the -march and -mcpu options. The motivation
was originally to support this in Function Multi Versioning
but it also makes sense to align with GCC on the command line.
---
 clang/docs/ReleaseNotes.rst   |  5 +
 clang/test/CodeGen/attr-target-version.c  | 12 ++--
 clang/test/Driver/aarch64-rdm.c   |  3 +++
 clang/test/Sema/attr-target-clones-aarch64.c  |  2 +-
 clang/test/SemaCXX/attr-target-version.cpp|  1 +
 .../llvm/TargetParser/AArch64TargetParser.h   | 13 -
 llvm/lib/TargetParser/AArch64TargetParser.cpp | 15 +--
 7 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f44fef28b9f17f..530158dda66689 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -333,6 +333,11 @@ Arm and AArch64 Support
   improvements for most targets. We have not changed the default behavior for
   ARMv6, but may revisit that decision in the future. Users can restore the old
   behavior with -m[no-]unaligned-access.
+- An alias identifier (rdma) has been added for targeting the AArch64
+  Architecture Extension which uses Rounding Doubling Multiply Accumulate
+  instructions (rdm). The identifier is available on the command line as
+  a feature modifier for -march and -mcpu as well as via target attributes
+  like ``target_version`` or ``target_clones``.
 
 Android Support
 ^^^
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index ae97977a9144f6..56a42499d0a7ca 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -25,7 +25,7 @@ int foo() {
 }
 
 inline int __attribute__((target_version("sha1+pmull+f64mm"))) 
fmv_inline(void) { return 1; }
-inline int __attribute__((target_version("fp16+fcma+sme+ fp16 "))) 
fmv_inline(void) { return 2; }
+inline int __attribute__((target_version("fp16+fcma+rdma+sme+ fp16 "))) 
fmv_inline(void) { return 2; }
 inline int __attribute__((target_version("sha3+i8mm+f32mm"))) fmv_inline(void) 
{ return 12; }
 inline int __attribute__((target_version("dit+sve-ebf16"))) fmv_inline(void) { 
return 8; }
 inline int __attribute__((target_version("dpb+rcpc2 "))) fmv_inline(void) { 
return 6; }
@@ -261,12 +261,12 @@ int hoo(void) {
 // CHECK-NEXT:  resolver_entry:
 // CHECK-NEXT:call void @__init_cpu_features_resolver()
 // CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 4398048608256
-// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 4398048608256
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 4398048608320
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 4398048608320
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @fmv_inline._MfcmaMfp16Mfp16Msme
+// CHECK-NEXT:ret ptr @fmv_inline._MfcmaMfp16Mfp16MrdmMsme
 // CHECK:   resolver_else:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
 // CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 864726312827224064
@@ -575,7 +575,7 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MfcmaMfp16Mfp16Msme
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MfcmaMfp16Mfp16MrdmMsme
 // CHECK-SAME: () #[[ATTR13:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 2
@@ -829,7 +829,7 @@ int hoo(void) {
 // CHECK: attributes #[[ATTR10]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+bf16,+fullfp16,+ls64,+sme,+sme2" }
 // CHECK: attributes #[[ATTR11]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+ccpp,+fullfp16,+ls64" }
 // CHECK: attributes #[[ATTR12]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+aes,+f64mm,+fp-armv8,+fullfp16,+ls64,+neon,+sve" }
-// CHECK: attributes #[[ATTR13]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+bf16,+complxnum,+fp-armv8,+fullfp16,+ls64,+neon,+sme" }
+// CHECK: attributes #[[ATTR13]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-feature

[clang] [llvm] [TargetParser][AArch64] Add alias for FEAT_RDM. (PR #80540)

2024-03-01 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

ping

https://github.com/llvm/llvm-project/pull/80540
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [TargetParser][AArch64] Add alias for FEAT_RDM. (PR #80540)

2024-03-01 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

Thanks!

https://github.com/llvm/llvm-project/pull/80540
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [TargetParser][AArch64] Add alias for FEAT_RDM. (PR #80540)

2024-03-01 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/80540

>From 5354d6c6736f84881466b6b5b99479137eddbf29 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Tue, 30 Jan 2024 11:17:55 +
Subject: [PATCH] [TargetParser][AArch64] Add alias for FEAT_RDM.

This patch allows using the name "rdma" as an alias for "rdm".
The name makes its way to target attributes as well as the
command line via the -march and -mcpu options. The motivation
was originally to support this in Function Multi Versioning
but it also makes sense to align with GCC on the command line.
---
 clang/docs/ReleaseNotes.rst   |  5 +
 clang/test/CodeGen/attr-target-version.c  | 12 ++--
 clang/test/Driver/aarch64-rdm.c   |  3 +++
 clang/test/Sema/attr-target-clones-aarch64.c  |  2 +-
 clang/test/SemaCXX/attr-target-version.cpp|  1 +
 .../llvm/TargetParser/AArch64TargetParser.h   | 13 -
 llvm/lib/TargetParser/AArch64TargetParser.cpp | 15 +--
 7 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cfe0ac6a5dca61..6f6ce7c68a7a71 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -346,6 +346,11 @@ Arm and AArch64 Support
   improvements for most targets. We have not changed the default behavior for
   ARMv6, but may revisit that decision in the future. Users can restore the old
   behavior with -m[no-]unaligned-access.
+- An alias identifier (rdma) has been added for targeting the AArch64
+  Architecture Extension which uses Rounding Doubling Multiply Accumulate
+  instructions (rdm). The identifier is available on the command line as
+  a feature modifier for -march and -mcpu as well as via target attributes
+  like ``target_version`` or ``target_clones``.
 
 Android Support
 ^^^
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index ae97977a9144f6..56a42499d0a7ca 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -25,7 +25,7 @@ int foo() {
 }
 
 inline int __attribute__((target_version("sha1+pmull+f64mm"))) 
fmv_inline(void) { return 1; }
-inline int __attribute__((target_version("fp16+fcma+sme+ fp16 "))) 
fmv_inline(void) { return 2; }
+inline int __attribute__((target_version("fp16+fcma+rdma+sme+ fp16 "))) 
fmv_inline(void) { return 2; }
 inline int __attribute__((target_version("sha3+i8mm+f32mm"))) fmv_inline(void) 
{ return 12; }
 inline int __attribute__((target_version("dit+sve-ebf16"))) fmv_inline(void) { 
return 8; }
 inline int __attribute__((target_version("dpb+rcpc2 "))) fmv_inline(void) { 
return 6; }
@@ -261,12 +261,12 @@ int hoo(void) {
 // CHECK-NEXT:  resolver_entry:
 // CHECK-NEXT:call void @__init_cpu_features_resolver()
 // CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 4398048608256
-// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 4398048608256
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 4398048608320
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 4398048608320
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @fmv_inline._MfcmaMfp16Mfp16Msme
+// CHECK-NEXT:ret ptr @fmv_inline._MfcmaMfp16Mfp16MrdmMsme
 // CHECK:   resolver_else:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
 // CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 864726312827224064
@@ -575,7 +575,7 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MfcmaMfp16Mfp16Msme
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MfcmaMfp16Mfp16MrdmMsme
 // CHECK-SAME: () #[[ATTR13:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 2
@@ -829,7 +829,7 @@ int hoo(void) {
 // CHECK: attributes #[[ATTR10]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+bf16,+fullfp16,+ls64,+sme,+sme2" }
 // CHECK: attributes #[[ATTR11]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+ccpp,+fullfp16,+ls64" }
 // CHECK: attributes #[[ATTR12]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+aes,+f64mm,+fp-armv8,+fullfp16,+ls64,+neon,+sve" }
-// CHECK: attributes #[[ATTR13]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+bf16,+complxnum,+fp-armv8,+fullfp16,+ls64,+neon,+sme" }
+// CHECK: attributes #[[ATTR13]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-feature

[clang] [llvm] [TargetParser][AArch64] Add alias for FEAT_RDM. (PR #80540)

2024-03-01 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/80540
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow target version definitions in any order. (PR #83887)

2024-03-04 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/83887

This patch fixes #71698. It allows defining the default target version prior to 
other version definitions without raising semantic errors.

>From 5a717769aa20dfbbaa8edd4bcd3048ebedee20a2 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Mon, 4 Mar 2024 18:12:22 +
Subject: [PATCH] [FMV] Allow target version definitions in any order.

This patch fixes #71698. It allows defining the default target
version prior to other version definitions without raising
semantic errors.
---
 clang/lib/Sema/SemaDecl.cpp  | 15 +--
 clang/test/CodeGen/attr-target-version.c | 56 
 clang/test/Sema/attr-target-version.c|  5 +--
 3 files changed, 41 insertions(+), 35 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3ae78748a4e499..81c5a11c58094e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11429,6 +11429,16 @@ static bool CheckTargetCausesMultiVersioning(Sema &S, 
FunctionDecl *OldFD,
  bool &Redeclaration,
  NamedDecl *&OldDecl,
  LookupResult &Previous) {
+  assert(!OldFD->isMultiVersion() && "Unexpected MultiVersion");
+
+  // The definitions should be allowed in any order. If we have discovered
+  // a new target version and the preceeding was the default, then add the
+  // corresponding attribute to it.
+  if (OldFD->getMultiVersionKind() == MultiVersionKind::None &&
+  NewFD->getMultiVersionKind() == MultiVersionKind::TargetVersion)
+OldFD->addAttr(TargetVersionAttr::CreateImplicit(
+S.Context, "default", OldFD->getSourceRange()));
+
   const auto *NewTA = NewFD->getAttr();
   const auto *NewTVA = NewFD->getAttr();
   const auto *OldTA = OldFD->getAttr();
@@ -11455,9 +11465,8 @@ static bool CheckTargetCausesMultiVersioning(Sema &S, 
FunctionDecl *OldFD,
   }
 
   // If this is 'default', permit the forward declaration.
-  if (!OldFD->isMultiVersion() &&
-  ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||
-   (NewTVA && NewTVA->isDefaultVersion() && !OldTVA))) {
+  if ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||
+  (NewTVA && NewTVA->isDefaultVersion() && !OldTVA)) {
 Redeclaration = true;
 OldDecl = OldFD;
 OldFD->setIsMultiVersion();
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 56a42499d0a7ca..ae1a8772f6cc07 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -94,16 +94,16 @@ int hoo(void) {
 // CHECK: @fmv_one.ifunc = weak_odr alias i32 (), ptr @fmv_one
 // CHECK: @fmv_two.ifunc = weak_odr alias i32 (), ptr @fmv_two
 // CHECK: @fmv_e.ifunc = weak_odr alias i32 (), ptr @fmv_e
+// CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
 // CHECK: @fmv_inline.ifunc = weak_odr alias i32 (), ptr @fmv_inline
 // CHECK: @fmv_d.ifunc = internal alias i32 (), ptr @fmv_d
-// CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
 // CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
 // CHECK: @fmv_one = weak_odr ifunc i32 (), ptr @fmv_one.resolver
 // CHECK: @fmv_two = weak_odr ifunc i32 (), ptr @fmv_two.resolver
 // CHECK: @fmv_e = weak_odr ifunc i32 (), ptr @fmv_e.resolver
+// CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 // CHECK: @fmv_inline = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
 // CHECK: @fmv_d = internal ifunc i32 (), ptr @fmv_d.resolver
-// CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 //.
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@fmv._MflagmMfp16fmlMrng
@@ -238,11 +238,18 @@ int hoo(void) {
 // CHECK-NEXT:ret i32 111
 //
 //
-// CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_c._Mssbs
-// CHECK-SAME: () #[[ATTR2]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:ret void
+// CHECK-LABEL: define {{[^@]+}}@fmv_c.resolver() comdat {
+// CHECK-NEXT:  resolver_entry:
+// CHECK-NEXT:call void @__init_cpu_features_resolver()
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 281474976710656
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 281474976710656
+// CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
+// CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
+// CHECK:   resolver_return:
+// CHECK-NEXT:ret ptr @fmv_c._Mssbs
+// CHECK:   resolver_else:
+// CHECK-NEXT:ret ptr @fmv_c.default
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
@@ -405,20 +412,6 @@ int hoo(void) {
 // CHECK-NEXT:ret ptr @fmv_d.default
 //
 //
-// CHECK-LABEL: define {{[^@]+}}@fmv_c.resolver() comdat {
-// CHECK-NEXT:  resolver_entry:
-// CHECK-NEXT:

[clang] [FMV] Allow target version definitions in any order. (PR #83887)

2024-03-04 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

I appreciate there's some code repetition between 
`CheckTargetCausesMultiVersioning` and `CheckMultiVersionAdditionalDecl`. 
Perhaps they deserve some refactoring in a separate patch. Please advise if you 
have any suggestions for moving the fix elsewhere.

https://github.com/llvm/llvm-project/pull/83887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow target version definitions in any order. (PR #83887)

2024-03-04 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/83887

>From 65a192641b5856714b9247372d9c471e03520762 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Mon, 4 Mar 2024 18:12:22 +
Subject: [PATCH] [FMV] Allow target version definitions in any order.

This patch fixes #71698. It allows defining the default target
version prior to other version definitions without raising
semantic errors.
---
 clang/lib/Sema/SemaDecl.cpp  | 15 +--
 clang/test/CodeGen/attr-target-version.c | 56 
 clang/test/Sema/attr-target-version.c|  5 +--
 3 files changed, 41 insertions(+), 35 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3ae78748a4e499..bd3235ea7efb92 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11429,6 +11429,16 @@ static bool CheckTargetCausesMultiVersioning(Sema &S, 
FunctionDecl *OldFD,
  bool &Redeclaration,
  NamedDecl *&OldDecl,
  LookupResult &Previous) {
+  assert(!OldFD->isMultiVersion() && "Unexpected MultiVersion");
+
+  // The definitions should be allowed in any order. If we have discovered
+  // a new target version and the preceeding was the default, then add the
+  // corresponding attribute to it.
+  if (OldFD->getMultiVersionKind() == MultiVersionKind::None &&
+  NewFD->getMultiVersionKind() == MultiVersionKind::TargetVersion)
+OldFD->addAttr(TargetVersionAttr::CreateImplicit(S.Context, "default",
+ OldFD->getSourceRange()));
+
   const auto *NewTA = NewFD->getAttr();
   const auto *NewTVA = NewFD->getAttr();
   const auto *OldTA = OldFD->getAttr();
@@ -11455,9 +11465,8 @@ static bool CheckTargetCausesMultiVersioning(Sema &S, 
FunctionDecl *OldFD,
   }
 
   // If this is 'default', permit the forward declaration.
-  if (!OldFD->isMultiVersion() &&
-  ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||
-   (NewTVA && NewTVA->isDefaultVersion() && !OldTVA))) {
+  if ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||
+  (NewTVA && NewTVA->isDefaultVersion() && !OldTVA)) {
 Redeclaration = true;
 OldDecl = OldFD;
 OldFD->setIsMultiVersion();
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 56a42499d0a7ca..ae1a8772f6cc07 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -94,16 +94,16 @@ int hoo(void) {
 // CHECK: @fmv_one.ifunc = weak_odr alias i32 (), ptr @fmv_one
 // CHECK: @fmv_two.ifunc = weak_odr alias i32 (), ptr @fmv_two
 // CHECK: @fmv_e.ifunc = weak_odr alias i32 (), ptr @fmv_e
+// CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
 // CHECK: @fmv_inline.ifunc = weak_odr alias i32 (), ptr @fmv_inline
 // CHECK: @fmv_d.ifunc = internal alias i32 (), ptr @fmv_d
-// CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
 // CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
 // CHECK: @fmv_one = weak_odr ifunc i32 (), ptr @fmv_one.resolver
 // CHECK: @fmv_two = weak_odr ifunc i32 (), ptr @fmv_two.resolver
 // CHECK: @fmv_e = weak_odr ifunc i32 (), ptr @fmv_e.resolver
+// CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 // CHECK: @fmv_inline = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
 // CHECK: @fmv_d = internal ifunc i32 (), ptr @fmv_d.resolver
-// CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 //.
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@fmv._MflagmMfp16fmlMrng
@@ -238,11 +238,18 @@ int hoo(void) {
 // CHECK-NEXT:ret i32 111
 //
 //
-// CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_c._Mssbs
-// CHECK-SAME: () #[[ATTR2]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:ret void
+// CHECK-LABEL: define {{[^@]+}}@fmv_c.resolver() comdat {
+// CHECK-NEXT:  resolver_entry:
+// CHECK-NEXT:call void @__init_cpu_features_resolver()
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 281474976710656
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 281474976710656
+// CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
+// CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
+// CHECK:   resolver_return:
+// CHECK-NEXT:ret ptr @fmv_c._Mssbs
+// CHECK:   resolver_else:
+// CHECK-NEXT:ret ptr @fmv_c.default
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
@@ -405,20 +412,6 @@ int hoo(void) {
 // CHECK-NEXT:ret ptr @fmv_d.default
 //
 //
-// CHECK-LABEL: define {{[^@]+}}@fmv_c.resolver() comdat {
-// CHECK-NEXT:  resolver_entry:
-// CHECK-NEXT:call void @__init_cpu_features_resolver()
-// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarc

[clang] [FMV] Allow target version definitions in any order. (PR #83887)

2024-03-05 Thread Alexandros Lamprineas via cfe-commits


@@ -11455,9 +11465,8 @@ static bool CheckTargetCausesMultiVersioning(Sema &S, 
FunctionDecl *OldFD,
   }
 
   // If this is 'default', permit the forward declaration.
-  if (!OldFD->isMultiVersion() &&
-  ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||
-   (NewTVA && NewTVA->isDefaultVersion() && !OldTVA))) {
+  if ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||

labrinea wrote:

As far as I can tell yes, this is astatic function with exactly one call site.

https://github.com/llvm/llvm-project/pull/83887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow target version definitions in any order. (PR #83887)

2024-03-05 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/83887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FMV] Allow target version definitions in any order. (PR #83887)

2024-03-05 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/83887

>From f11c97d7f7f67edaf6de4390bcceb13dfea376a1 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Mon, 4 Mar 2024 18:12:22 +
Subject: [PATCH] [FMV] Allow target version definitions in any order.

This patch fixes #71698. It allows defining the default target
version prior to other version definitions without raising
semantic errors.
---
 clang/lib/Sema/SemaDecl.cpp  | 15 +--
 clang/test/CodeGen/attr-target-version.c | 56 
 clang/test/Sema/attr-target-version.c| 25 ---
 3 files changed, 59 insertions(+), 37 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3ae78748a4e499..bd3235ea7efb92 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11429,6 +11429,16 @@ static bool CheckTargetCausesMultiVersioning(Sema &S, 
FunctionDecl *OldFD,
  bool &Redeclaration,
  NamedDecl *&OldDecl,
  LookupResult &Previous) {
+  assert(!OldFD->isMultiVersion() && "Unexpected MultiVersion");
+
+  // The definitions should be allowed in any order. If we have discovered
+  // a new target version and the preceeding was the default, then add the
+  // corresponding attribute to it.
+  if (OldFD->getMultiVersionKind() == MultiVersionKind::None &&
+  NewFD->getMultiVersionKind() == MultiVersionKind::TargetVersion)
+OldFD->addAttr(TargetVersionAttr::CreateImplicit(S.Context, "default",
+ OldFD->getSourceRange()));
+
   const auto *NewTA = NewFD->getAttr();
   const auto *NewTVA = NewFD->getAttr();
   const auto *OldTA = OldFD->getAttr();
@@ -11455,9 +11465,8 @@ static bool CheckTargetCausesMultiVersioning(Sema &S, 
FunctionDecl *OldFD,
   }
 
   // If this is 'default', permit the forward declaration.
-  if (!OldFD->isMultiVersion() &&
-  ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||
-   (NewTVA && NewTVA->isDefaultVersion() && !OldTVA))) {
+  if ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||
+  (NewTVA && NewTVA->isDefaultVersion() && !OldTVA)) {
 Redeclaration = true;
 OldDecl = OldFD;
 OldFD->setIsMultiVersion();
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 56a42499d0a7ca..ae1a8772f6cc07 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -94,16 +94,16 @@ int hoo(void) {
 // CHECK: @fmv_one.ifunc = weak_odr alias i32 (), ptr @fmv_one
 // CHECK: @fmv_two.ifunc = weak_odr alias i32 (), ptr @fmv_two
 // CHECK: @fmv_e.ifunc = weak_odr alias i32 (), ptr @fmv_e
+// CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
 // CHECK: @fmv_inline.ifunc = weak_odr alias i32 (), ptr @fmv_inline
 // CHECK: @fmv_d.ifunc = internal alias i32 (), ptr @fmv_d
-// CHECK: @fmv_c.ifunc = weak_odr alias void (), ptr @fmv_c
 // CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver
 // CHECK: @fmv_one = weak_odr ifunc i32 (), ptr @fmv_one.resolver
 // CHECK: @fmv_two = weak_odr ifunc i32 (), ptr @fmv_two.resolver
 // CHECK: @fmv_e = weak_odr ifunc i32 (), ptr @fmv_e.resolver
+// CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 // CHECK: @fmv_inline = weak_odr ifunc i32 (), ptr @fmv_inline.resolver
 // CHECK: @fmv_d = internal ifunc i32 (), ptr @fmv_d.resolver
-// CHECK: @fmv_c = weak_odr ifunc void (), ptr @fmv_c.resolver
 //.
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@fmv._MflagmMfp16fmlMrng
@@ -238,11 +238,18 @@ int hoo(void) {
 // CHECK-NEXT:ret i32 111
 //
 //
-// CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_c._Mssbs
-// CHECK-SAME: () #[[ATTR2]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:ret void
+// CHECK-LABEL: define {{[^@]+}}@fmv_c.resolver() comdat {
+// CHECK-NEXT:  resolver_entry:
+// CHECK-NEXT:call void @__init_cpu_features_resolver()
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 281474976710656
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 281474976710656
+// CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
+// CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
+// CHECK:   resolver_return:
+// CHECK-NEXT:ret ptr @fmv_c._Mssbs
+// CHECK:   resolver_else:
+// CHECK-NEXT:ret ptr @fmv_c.default
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
@@ -405,20 +412,6 @@ int hoo(void) {
 // CHECK-NEXT:ret ptr @fmv_d.default
 //
 //
-// CHECK-LABEL: define {{[^@]+}}@fmv_c.resolver() comdat {
-// CHECK-NEXT:  resolver_entry:
-// CHECK-NEXT:call void @__init_cpu_features_resolver()
-// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr

[llvm] [clang] [TargetParser][AArch64] Add alias for FEAT_RDM. (PR #80540)

2024-02-03 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/80540

This patch allows using the name "rdma" as an alias for "rdm". The name makes 
its way to target attributes as well as the command line via the -march and 
-mcpu options. The motivation was originally to support this in Function Multi 
Versioning but it also makes sense to align with GCC on the command line.

>From 0804c8c74d940a49c6a21722b136d0b090458242 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Tue, 30 Jan 2024 11:17:55 +
Subject: [PATCH] [TargetParser][AArch64] Add alias for FEAT_RDM.

This patch allows using the name "rdma" as an alias for "rdm".
The name makes its way to target attributes as well as the
command line via the -march and -mcpu options. The motivation
was originally to support this in Function Multi Versioning
but it also makes sense to align with GCC on the command line.
---
 clang/docs/ReleaseNotes.rst   |  6 ++
 clang/test/CodeGen/attr-target-version.c  |  6 +++---
 clang/test/Driver/aarch64-rdm.c   |  3 +++
 clang/test/Sema/attr-target-clones-aarch64.c  |  2 +-
 clang/test/SemaCXX/attr-target-version.cpp|  1 +
 .../llvm/TargetParser/AArch64TargetParser.h   | 13 -
 llvm/lib/TargetParser/AArch64TargetParser.cpp | 15 +--
 7 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e634db3c718c9..5d525b74c056d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -222,6 +222,12 @@ X86 Support
 Arm and AArch64 Support
 ^^^
 
+- An alias identifier (rdma) has been added for targeting the AArch64
+  Architecture Extension which uses Rounding Doubling Multiply Accumulate
+  instructions (rdm). The identifier is available on the command line as
+  a feature modifier for -march and -mcpu as well as via target attributes
+  like ``target_version`` or ``target_clones``.
+
 Android Support
 ^^^
 
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 2a96697e4291b..2ad6f3a5b0c44 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -39,7 +39,7 @@ inline int 
__attribute__((target_version("memtag3+rcpc3+mops"))) fmv_inline(void
 inline int __attribute__((target_version("aes+dotprod"))) fmv_inline(void) { 
return 13; }
 inline int __attribute__((target_version("simd+fp16fml"))) fmv_inline(void) { 
return 14; }
 inline int __attribute__((target_version("fp+sm4"))) fmv_inline(void) { return 
15; }
-inline int __attribute__((target_version("lse+rdm"))) fmv_inline(void) { 
return 16; }
+inline int __attribute__((target_version("lse+rdma"))) fmv_inline(void) { 
return 16; }
 inline int __attribute__((target_version("default"))) fmv_inline(void) { 
return 3; }
 
 __attribute__((target_version("ls64"))) int fmv_e(void);
@@ -385,7 +385,7 @@ int hoo(void) {
 // CHECK-NEXT:[[TMP59:%.*]] = and i1 true, [[TMP58]]
 // CHECK-NEXT:br i1 [[TMP59]], label [[RESOLVER_RETURN27:%.*]], label 
[[RESOLVER_ELSE28:%.*]]
 // CHECK:   resolver_return27:
-// CHECK-NEXT:ret ptr @fmv_inline._MlseMrdm
+// CHECK-NEXT:ret ptr @fmv_inline._MlseMrdma
 // CHECK:   resolver_else28:
 // CHECK-NEXT:[[TMP60:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
 // CHECK-NEXT:[[TMP61:%.*]] = and i64 [[TMP60]], 32
@@ -673,7 +673,7 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MlseMrdm
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MlseMrdma
 // CHECK-SAME: () #[[ATTR25:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 16
diff --git a/clang/test/Driver/aarch64-rdm.c b/clang/test/Driver/aarch64-rdm.c
index f2542b381e7c2..62e1a4def4ce1 100644
--- a/clang/test/Driver/aarch64-rdm.c
+++ b/clang/test/Driver/aarch64-rdm.c
@@ -1,13 +1,16 @@
 // RUN: %clang --target=aarch64-none-elf -march=armv8a+rdm -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
+// RUN: %clang --target=aarch64-none-elf -march=armv8a+rdma -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
 // RUN: %clang --target=aarch64-none-elf -mcpu=generic+rdm -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
 // RUN: %clang --target=aarch64-none-elf -mcpu=falkor -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
 // RUN: %clang --target=aarch64-none-elf -mcpu=thunderx2t99 -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-RDM %s
 // CHECK-RDM: "-target-feature" "+rdm"
 
 // RUN: %clang --target=aarch64-none-elf -march=armv8a+nordm -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-NORDM %s
+// RUN: %clang --target=aarch64-none-elf -march=armv8a+nordma -### -c %s 2>&1 
| FileCheck --check-prefix=CHECK-NORDM %s
 // RUN: %clang --target=aarch64-none-elf -mcpu=generic+nordm -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-NORDM %s

[clang] [llvm] [FMV] Add alias for FEAT_RDM and change priorities according to ACLE. (PR #79316)

2024-01-24 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/79316

This patch follows the latest ACLE spec (see PR #279). It adds a name alias for 
FEAT_RDM and adjusts priorities for FEAT_DOTPROD, FEAT_SM4, FEAT_FP16FML, 
FEAT_RDM.

>From cd0a99001387a64d23d606367a0e08bb88b0bfc6 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Wed, 24 Jan 2024 15:26:01 +
Subject: [PATCH] [FMV] Add alias for FEAT_RDM and change priorities according
 to ACLE.

This patch follows the latest ACLE spec (see PR #279). It adds a name
alias for FEAT_RDM and adjusts priorities for FEAT_DOTPROD, FEAT_SM4,
FEAT_FP16FML, FEAT_RDM.
---
 clang/test/CodeGen/attr-target-version.c  | 21 +--
 clang/test/Sema/attr-target-clones-aarch64.c  |  2 +-
 clang/test/SemaCXX/attr-target-version.cpp|  1 +
 .../llvm/TargetParser/AArch64TargetParser.h   | 19 ++---
 llvm/lib/TargetParser/AArch64TargetParser.cpp | 15 +++--
 5 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 89279852a8c91d..8d53a073b37cbe 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -36,6 +36,7 @@ inline int 
__attribute__((target_version("sve2-aes+sve2-sha3"))) fmv_inline(void
 inline int __attribute__((target_version("sve2+sve2-pmull128+sve2-bitperm"))) 
fmv_inline(void) { return 9; }
 inline int __attribute__((target_version("sve2-sm4+memtag2"))) 
fmv_inline(void) { return 10; }
 inline int __attribute__((target_version("memtag3+rcpc3+mops"))) 
fmv_inline(void) { return 11; }
+inline int __attribute__((target_version("rdma+sm4"))) fmv_inline(void) { 
return 12; }
 inline int __attribute__((target_version("default"))) fmv_inline(void) { 
return 3; }
 
 __attribute__((target_version("ls64"))) int fmv_e(void);
@@ -359,6 +360,14 @@ int hoo(void) {
 // CHECK:   resolver_return21:
 // CHECK-NEXT:ret ptr @fmv_inline._Mdpb2Mjscvt
 // CHECK:   resolver_else22:
+// CHECK-NEXT:[[TMP48:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP49:%.*]] = and i64 [[TMP48]], 96
+// CHECK-NEXT:[[TMP50:%.*]] = icmp eq i64 [[TMP49]], 96
+// CHECK-NEXT:[[TMP51:%.*]] = and i1 true, [[TMP50]]
+// CHECK-NEXT:br i1 [[TMP51]], label [[RESOLVER_RETURN23:%.*]], label 
[[RESOLVER_ELSE24:%.*]]
+// CHECK:   resolver_return23:
+// CHECK-NEXT:ret ptr @fmv_inline._Msm4Mrdma
+// CHECK:   resolver_else24:
 // CHECK-NEXT:ret ptr @fmv_inline.default
 //
 //
@@ -616,6 +625,13 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Msm4Mrdma
+// CHECK-SAME: () #[[ATTR24:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 12
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@fmv_inline.default
 // CHECK-SAME: () #[[ATTR2]] {
 // CHECK-NEXT:  entry:
@@ -624,7 +640,7 @@ int hoo(void) {
 //
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@fmv_d._Msb
-// CHECK-SAME: () #[[ATTR24:[0-9]+]] {
+// CHECK-SAME: () #[[ATTR25:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 0
 //
@@ -769,7 +785,8 @@ int hoo(void) {
 // CHECK: attributes #[[ATTR21]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+fp-armv8,+fullfp16,+ls64,+neon,+sve,+sve2,+sve2-aes,+sve2-bitperm"
 }
 // CHECK: attributes #[[ATTR22]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+fp-armv8,+fullfp16,+ls64,+mte,+neon,+sve,+sve2,+sve2-sm4" }
 // CHECK: attributes #[[ATTR23]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+fullfp16,+ls64,+mops,+mte,+rcpc,+rcpc3" }
-// CHECK: attributes #[[ATTR24]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+fullfp16,+ls64,+sb" }
+// CHECK: attributes #[[ATTR24]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+fp-armv8,+fullfp16,+ls64,+neon,+rdm,+sm4" }
+// CHECK: attributes #[[ATTR25]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+fullfp16,+ls64,+sb" }
 //.
 // CHECK-NOFMV: attributes #[[ATTR0]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="-fmv" }
 // CHECK-NOFMV: attributes #[[ATTR1:[0-9]+]] = { "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-features"="-fmv" }
diff --git a/clang/test/Sema/attr-target-clones-aarch64.c 
b/clang/test/Sema/attr-target-clones-aarch64.c
index 4054b7c837ec99..0ce277f41884c6 100644
--- a/clang/test/Sema/attr-target-clones-aarch64.c
+++ b/clang/test/Sema/attr-target-clones

[clang] [llvm] [FMV] Add alias for FEAT_RDM and change priorities according to ACLE. (PR #79316)

2024-01-24 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/79316
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][FMV] Add tests to demonstrate feature priorities. (PR #79455)

2024-01-25 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/79455

Adds tests showing that we select function version according to the highest 
feature priority. This will make the changes introduced by #79316 more evident.

>From 07719ca748ad94e3c458293e46538491d771cc00 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 25 Jan 2024 14:09:06 +
Subject: [PATCH] [NFC][FMV] Add tests to demonstrate feature priorities.

Adds tests showing that we select function version according
to the highest feature priority. This will make the changes
introduced by #79316 more evident.
---
 clang/test/CodeGen/attr-target-version.c | 70 +++-
 1 file changed, 68 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 89279852a8c91da..feb6c094ab62b1a 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -36,6 +36,10 @@ inline int 
__attribute__((target_version("sve2-aes+sve2-sha3"))) fmv_inline(void
 inline int __attribute__((target_version("sve2+sve2-pmull128+sve2-bitperm"))) 
fmv_inline(void) { return 9; }
 inline int __attribute__((target_version("sve2-sm4+memtag2"))) 
fmv_inline(void) { return 10; }
 inline int __attribute__((target_version("memtag3+rcpc3+mops"))) 
fmv_inline(void) { return 11; }
+inline int __attribute__((target_version("aes+dotprod"))) fmv_inline(void) { 
return 13; }
+inline int __attribute__((target_version("simd+fp16fml"))) fmv_inline(void) { 
return 14; }
+inline int __attribute__((target_version("fp+sm4"))) fmv_inline(void) { return 
15; }
+inline int __attribute__((target_version("lse+rdm"))) fmv_inline(void) { 
return 16; }
 inline int __attribute__((target_version("default"))) fmv_inline(void) { 
return 3; }
 
 __attribute__((target_version("ls64"))) int fmv_e(void);
@@ -359,6 +363,38 @@ int hoo(void) {
 // CHECK:   resolver_return21:
 // CHECK-NEXT:ret ptr @fmv_inline._Mdpb2Mjscvt
 // CHECK:   resolver_else22:
+// CHECK-NEXT:[[TMP48:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP49:%.*]] = and i64 [[TMP48]], 16400
+// CHECK-NEXT:[[TMP50:%.*]] = icmp eq i64 [[TMP49]], 16400
+// CHECK-NEXT:[[TMP51:%.*]] = and i1 true, [[TMP50]]
+// CHECK-NEXT:br i1 [[TMP51]], label [[RESOLVER_RETURN23:%.*]], label 
[[RESOLVER_ELSE24:%.*]]
+// CHECK:   resolver_return23:
+// CHECK-NEXT:ret ptr @fmv_inline._MdotprodMaes
+// CHECK:   resolver_else24:
+// CHECK-NEXT:[[TMP52:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP53:%.*]] = and i64 [[TMP52]], 8
+// CHECK-NEXT:[[TMP54:%.*]] = icmp eq i64 [[TMP53]], 8
+// CHECK-NEXT:[[TMP55:%.*]] = and i1 true, [[TMP54]]
+// CHECK-NEXT:br i1 [[TMP55]], label [[RESOLVER_RETURN25:%.*]], label 
[[RESOLVER_ELSE26:%.*]]
+// CHECK:   resolver_return25:
+// CHECK-NEXT:ret ptr @fmv_inline._Mfp16fmlMsimd
+// CHECK:   resolver_else26:
+// CHECK-NEXT:[[TMP56:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP57:%.*]] = and i64 [[TMP56]], 32
+// CHECK-NEXT:[[TMP58:%.*]] = icmp eq i64 [[TMP57]], 32
+// CHECK-NEXT:[[TMP59:%.*]] = and i1 true, [[TMP58]]
+// CHECK-NEXT:br i1 [[TMP59]], label [[RESOLVER_RETURN27:%.*]], label 
[[RESOLVER_ELSE28:%.*]]
+// CHECK:   resolver_return27:
+// CHECK-NEXT:ret ptr @fmv_inline._Msm4Mfp
+// CHECK:   resolver_else28:
+// CHECK-NEXT:[[TMP60:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP61:%.*]] = and i64 [[TMP60]], 192
+// CHECK-NEXT:[[TMP62:%.*]] = icmp eq i64 [[TMP61]], 192
+// CHECK-NEXT:[[TMP63:%.*]] = and i1 true, [[TMP62]]
+// CHECK-NEXT:br i1 [[TMP63]], label [[RESOLVER_RETURN29:%.*]], label 
[[RESOLVER_ELSE30:%.*]]
+// CHECK:   resolver_return29:
+// CHECK-NEXT:ret ptr @fmv_inline._MrdmMlse
+// CHECK:   resolver_else30:
 // CHECK-NEXT:ret ptr @fmv_inline.default
 //
 //
@@ -616,6 +652,34 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MdotprodMaes
+// CHECK-SAME: () #[[ATTR6]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 13
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Mfp16fmlMsimd
+// CHECK-SAME: () #[[ATTR7]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 14
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Msm4Mfp
+// CHECK-SAME: () #[[ATTR24:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 15
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MrdmMlse
+// CHECK-SAME: () #[[ATTR25:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 16
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@f

[clang] [llvm] [FMV] Add alias for FEAT_RDM and change priorities according to ACLE. (PR #79316)

2024-01-25 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/79316

>From 07719ca748ad94e3c458293e46538491d771cc00 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 25 Jan 2024 14:09:06 +
Subject: [PATCH 1/2] [NFC][FMV] Add tests to demonstrate feature priorities.

Adds tests showing that we select function version according
to the highest feature priority. This will make the changes
introduced by #79316 more evident.
---
 clang/test/CodeGen/attr-target-version.c | 70 +++-
 1 file changed, 68 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 89279852a8c91d..feb6c094ab62b1 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -36,6 +36,10 @@ inline int 
__attribute__((target_version("sve2-aes+sve2-sha3"))) fmv_inline(void
 inline int __attribute__((target_version("sve2+sve2-pmull128+sve2-bitperm"))) 
fmv_inline(void) { return 9; }
 inline int __attribute__((target_version("sve2-sm4+memtag2"))) 
fmv_inline(void) { return 10; }
 inline int __attribute__((target_version("memtag3+rcpc3+mops"))) 
fmv_inline(void) { return 11; }
+inline int __attribute__((target_version("aes+dotprod"))) fmv_inline(void) { 
return 13; }
+inline int __attribute__((target_version("simd+fp16fml"))) fmv_inline(void) { 
return 14; }
+inline int __attribute__((target_version("fp+sm4"))) fmv_inline(void) { return 
15; }
+inline int __attribute__((target_version("lse+rdm"))) fmv_inline(void) { 
return 16; }
 inline int __attribute__((target_version("default"))) fmv_inline(void) { 
return 3; }
 
 __attribute__((target_version("ls64"))) int fmv_e(void);
@@ -359,6 +363,38 @@ int hoo(void) {
 // CHECK:   resolver_return21:
 // CHECK-NEXT:ret ptr @fmv_inline._Mdpb2Mjscvt
 // CHECK:   resolver_else22:
+// CHECK-NEXT:[[TMP48:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP49:%.*]] = and i64 [[TMP48]], 16400
+// CHECK-NEXT:[[TMP50:%.*]] = icmp eq i64 [[TMP49]], 16400
+// CHECK-NEXT:[[TMP51:%.*]] = and i1 true, [[TMP50]]
+// CHECK-NEXT:br i1 [[TMP51]], label [[RESOLVER_RETURN23:%.*]], label 
[[RESOLVER_ELSE24:%.*]]
+// CHECK:   resolver_return23:
+// CHECK-NEXT:ret ptr @fmv_inline._MdotprodMaes
+// CHECK:   resolver_else24:
+// CHECK-NEXT:[[TMP52:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP53:%.*]] = and i64 [[TMP52]], 8
+// CHECK-NEXT:[[TMP54:%.*]] = icmp eq i64 [[TMP53]], 8
+// CHECK-NEXT:[[TMP55:%.*]] = and i1 true, [[TMP54]]
+// CHECK-NEXT:br i1 [[TMP55]], label [[RESOLVER_RETURN25:%.*]], label 
[[RESOLVER_ELSE26:%.*]]
+// CHECK:   resolver_return25:
+// CHECK-NEXT:ret ptr @fmv_inline._Mfp16fmlMsimd
+// CHECK:   resolver_else26:
+// CHECK-NEXT:[[TMP56:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP57:%.*]] = and i64 [[TMP56]], 32
+// CHECK-NEXT:[[TMP58:%.*]] = icmp eq i64 [[TMP57]], 32
+// CHECK-NEXT:[[TMP59:%.*]] = and i1 true, [[TMP58]]
+// CHECK-NEXT:br i1 [[TMP59]], label [[RESOLVER_RETURN27:%.*]], label 
[[RESOLVER_ELSE28:%.*]]
+// CHECK:   resolver_return27:
+// CHECK-NEXT:ret ptr @fmv_inline._Msm4Mfp
+// CHECK:   resolver_else28:
+// CHECK-NEXT:[[TMP60:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP61:%.*]] = and i64 [[TMP60]], 192
+// CHECK-NEXT:[[TMP62:%.*]] = icmp eq i64 [[TMP61]], 192
+// CHECK-NEXT:[[TMP63:%.*]] = and i1 true, [[TMP62]]
+// CHECK-NEXT:br i1 [[TMP63]], label [[RESOLVER_RETURN29:%.*]], label 
[[RESOLVER_ELSE30:%.*]]
+// CHECK:   resolver_return29:
+// CHECK-NEXT:ret ptr @fmv_inline._MrdmMlse
+// CHECK:   resolver_else30:
 // CHECK-NEXT:ret ptr @fmv_inline.default
 //
 //
@@ -616,6 +652,34 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MdotprodMaes
+// CHECK-SAME: () #[[ATTR6]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 13
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Mfp16fmlMsimd
+// CHECK-SAME: () #[[ATTR7]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 14
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Msm4Mfp
+// CHECK-SAME: () #[[ATTR24:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 15
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MrdmMlse
+// CHECK-SAME: () #[[ATTR25:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 16
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@fmv_inline.default
 // CHECK-SAME: () #[[ATTR2]] {
 // CHECK-NEXT:  entry:
@@ -624,7 +688,7 @@ int hoo(void) {
 //
 // CHECK: Function Attrs: noinline nounwi

[clang] [NFC][FMV] Add tests to demonstrate feature priorities. (PR #79455)

2024-01-26 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/79455
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [FMV] Add alias for FEAT_RDM and change priorities according to ACLE. (PR #79316)

2024-01-26 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/79316

>From 3e0a3fe637ad6e815d0ca62f38d39c2a27f8b5d5 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Wed, 24 Jan 2024 15:26:01 +
Subject: [PATCH] [FMV] Change feature priorities according to ACLE.

This patch follows the latest ACLE specification as shown in PR
https://github.com/ARM-software/acle/pull/279. It adjusts the
priorities for FEAT_DOTPROD, FEAT_SM4, FEAT_FP16FML, FEAT_RDM.
---
 clang/test/CodeGen/attr-target-version.c  | 30 +--
 .../llvm/TargetParser/AArch64TargetParser.h   |  8 ++---
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index feb6c094ab62b1a..2a96697e4291b9b 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -364,36 +364,36 @@ int hoo(void) {
 // CHECK-NEXT:ret ptr @fmv_inline._Mdpb2Mjscvt
 // CHECK:   resolver_else22:
 // CHECK-NEXT:[[TMP48:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
-// CHECK-NEXT:[[TMP49:%.*]] = and i64 [[TMP48]], 16400
-// CHECK-NEXT:[[TMP50:%.*]] = icmp eq i64 [[TMP49]], 16400
+// CHECK-NEXT:[[TMP49:%.*]] = and i64 [[TMP48]], 8
+// CHECK-NEXT:[[TMP50:%.*]] = icmp eq i64 [[TMP49]], 8
 // CHECK-NEXT:[[TMP51:%.*]] = and i1 true, [[TMP50]]
 // CHECK-NEXT:br i1 [[TMP51]], label [[RESOLVER_RETURN23:%.*]], label 
[[RESOLVER_ELSE24:%.*]]
 // CHECK:   resolver_return23:
-// CHECK-NEXT:ret ptr @fmv_inline._MdotprodMaes
+// CHECK-NEXT:ret ptr @fmv_inline._MsimdMfp16fml
 // CHECK:   resolver_else24:
 // CHECK-NEXT:[[TMP52:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
-// CHECK-NEXT:[[TMP53:%.*]] = and i64 [[TMP52]], 8
-// CHECK-NEXT:[[TMP54:%.*]] = icmp eq i64 [[TMP53]], 8
+// CHECK-NEXT:[[TMP53:%.*]] = and i64 [[TMP52]], 16400
+// CHECK-NEXT:[[TMP54:%.*]] = icmp eq i64 [[TMP53]], 16400
 // CHECK-NEXT:[[TMP55:%.*]] = and i1 true, [[TMP54]]
 // CHECK-NEXT:br i1 [[TMP55]], label [[RESOLVER_RETURN25:%.*]], label 
[[RESOLVER_ELSE26:%.*]]
 // CHECK:   resolver_return25:
-// CHECK-NEXT:ret ptr @fmv_inline._Mfp16fmlMsimd
+// CHECK-NEXT:ret ptr @fmv_inline._MdotprodMaes
 // CHECK:   resolver_else26:
 // CHECK-NEXT:[[TMP56:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
-// CHECK-NEXT:[[TMP57:%.*]] = and i64 [[TMP56]], 32
-// CHECK-NEXT:[[TMP58:%.*]] = icmp eq i64 [[TMP57]], 32
+// CHECK-NEXT:[[TMP57:%.*]] = and i64 [[TMP56]], 192
+// CHECK-NEXT:[[TMP58:%.*]] = icmp eq i64 [[TMP57]], 192
 // CHECK-NEXT:[[TMP59:%.*]] = and i1 true, [[TMP58]]
 // CHECK-NEXT:br i1 [[TMP59]], label [[RESOLVER_RETURN27:%.*]], label 
[[RESOLVER_ELSE28:%.*]]
 // CHECK:   resolver_return27:
-// CHECK-NEXT:ret ptr @fmv_inline._Msm4Mfp
+// CHECK-NEXT:ret ptr @fmv_inline._MlseMrdm
 // CHECK:   resolver_else28:
 // CHECK-NEXT:[[TMP60:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
-// CHECK-NEXT:[[TMP61:%.*]] = and i64 [[TMP60]], 192
-// CHECK-NEXT:[[TMP62:%.*]] = icmp eq i64 [[TMP61]], 192
+// CHECK-NEXT:[[TMP61:%.*]] = and i64 [[TMP60]], 32
+// CHECK-NEXT:[[TMP62:%.*]] = icmp eq i64 [[TMP61]], 32
 // CHECK-NEXT:[[TMP63:%.*]] = and i1 true, [[TMP62]]
 // CHECK-NEXT:br i1 [[TMP63]], label [[RESOLVER_RETURN29:%.*]], label 
[[RESOLVER_ELSE30:%.*]]
 // CHECK:   resolver_return29:
-// CHECK-NEXT:ret ptr @fmv_inline._MrdmMlse
+// CHECK-NEXT:ret ptr @fmv_inline._MfpMsm4
 // CHECK:   resolver_else30:
 // CHECK-NEXT:ret ptr @fmv_inline.default
 //
@@ -659,21 +659,21 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Mfp16fmlMsimd
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MsimdMfp16fml
 // CHECK-SAME: () #[[ATTR7]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 14
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Msm4Mfp
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MfpMsm4
 // CHECK-SAME: () #[[ATTR24:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 15
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MrdmMlse
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MlseMrdm
 // CHECK-SAME: () #[[ATTR25:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 16
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 623fdc21ba65a6e..1ac041591b5637f 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -222,7 +222,7 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"d128", AArch64::AEK_D128, "+d128", "-d128", FEAT_INIT, "", 0},
 {"dgh", AArch64::AEK_NONE, {}, {}, FEAT_DGH, 

[llvm] [clang] [FMV] Change feature priorities according to ACLE. (PR #79316)

2024-01-26 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/79316
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [FMV] Change feature priorities according to ACLE. (PR #79316)

2024-01-26 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/79316
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [FMV] Change feature priorities according to ACLE. (PR #79316)

2024-01-26 Thread Alexandros Lamprineas via cfe-commits


@@ -114,6 +121,10 @@ const AArch64::ArchInfo *AArch64::parseArch(StringRef 
Arch) {
 }
 
 std::optional AArch64::parseArchExtension(StringRef 
ArchExt) {
+  // Resolve aliases first.
+  ArchExt = resolveExtAlias(ArchExt);

labrinea wrote:

I will separate this change to another PR and leave this review just for the 
adjustment of feature priorities.

https://github.com/llvm/llvm-project/pull/79316
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [AArch64][TargetParser] Add mcpu alias for Microsoft Azure Cobalt 100. (PR #79614)

2024-01-26 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/79614

With a690e86 we added -mcpu/mtune=native support to handle the Microsoft Azure 
Cobalt 100 CPU as a Neoverse N2. This patch adds a CPU alias in TargetParser to 
maintain compatibility with GCC.

>From 3586485f35963b382b95ad566917c26f59e5a0bd Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Fri, 26 Jan 2024 10:28:19 +
Subject: [PATCH] [AArch64][TargetParser] Add mcpu alias for Microsoft Azure
 Cobalt 100.

With a690e86 we added -mcpu/mtune=native support to handle the
Microsoft Azure Cobalt 100 CPU as a Neoverse N2. This patch adds
a CPU alias in TargetParser to maintain compatibility with GCC.
---
 clang/test/Driver/aarch64-mcpu.c | 3 +++
 clang/test/Misc/target-invalid-cpu-note.c| 4 ++--
 llvm/include/llvm/TargetParser/AArch64TargetParser.h | 5 -
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/clang/test/Driver/aarch64-mcpu.c b/clang/test/Driver/aarch64-mcpu.c
index 511482a420da268..3e07f3597f34081 100644
--- a/clang/test/Driver/aarch64-mcpu.c
+++ b/clang/test/Driver/aarch64-mcpu.c
@@ -72,6 +72,9 @@
 // RUN: %clang --target=aarch64 -mcpu=cortex-r82  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXR82 %s
 // CORTEXR82: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-r82"
 
+// RUN: %clang --target=aarch64 -mcpu=cobalt-100 -### -c %s 2>&1 | FileCheck 
-check-prefix=COBALT-100 %s
+// COBALT-100: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"neoverse-n2"
+
 // RUN: %clang --target=aarch64 -mcpu=grace -### -c %s 2>&1 | FileCheck 
-check-prefix=GRACE %s
 // GRACE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "neoverse-v2"
 
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 84aed5c9c36fe47..2f10bfb1fd82fe3 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-a720, 
cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, cortex-x4, 
neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-a720, 
cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, cortex-x4, 
neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, cobalt-100, 
grace{{$}}
 
 // RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE_AARCH64
 // TUNE_AARCH64: error: unknown target CPU 'not-a-cpu'
-// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, 
cortex-a720, cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, 
cortex-x4, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
+// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, 
co

[clang] [llvm] [AArch64][TargetParser] Add mcpu alias for Microsoft Azure Cobalt 100. (PR #79614)

2024-01-26 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/79614

>From e2fe85fb1615abc6e3e82788e7ff26abe329ceeb Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Fri, 26 Jan 2024 10:28:19 +
Subject: [PATCH] [AArch64][TargetParser] Add mcpu alias for Microsoft Azure
 Cobalt 100.

With a690e86 we added -mcpu/mtune=native support to handle the
Microsoft Azure Cobalt 100 CPU as a Neoverse N2. This patch adds
a CPU alias in TargetParser to maintain compatibility with GCC.
---
 clang/test/Driver/aarch64-mcpu.c | 3 +++
 clang/test/Misc/target-invalid-cpu-note.c| 4 ++--
 llvm/include/llvm/TargetParser/AArch64TargetParser.h | 3 ++-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/clang/test/Driver/aarch64-mcpu.c b/clang/test/Driver/aarch64-mcpu.c
index 511482a420da268..3e07f3597f34081 100644
--- a/clang/test/Driver/aarch64-mcpu.c
+++ b/clang/test/Driver/aarch64-mcpu.c
@@ -72,6 +72,9 @@
 // RUN: %clang --target=aarch64 -mcpu=cortex-r82  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXR82 %s
 // CORTEXR82: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-r82"
 
+// RUN: %clang --target=aarch64 -mcpu=cobalt-100 -### -c %s 2>&1 | FileCheck 
-check-prefix=COBALT-100 %s
+// COBALT-100: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"neoverse-n2"
+
 // RUN: %clang --target=aarch64 -mcpu=grace -### -c %s 2>&1 | FileCheck 
-check-prefix=GRACE %s
 // GRACE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "neoverse-v2"
 
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 84aed5c9c36fe47..2f10bfb1fd82fe3 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-a720, 
cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, cortex-x4, 
neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-a720, 
cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, cortex-x4, 
neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, cobalt-100, 
grace{{$}}
 
 // RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE_AARCH64
 // TUNE_AARCH64: error: unknown target CPU 'not-a-cpu'
-// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, 
cortex-a720, cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, 
cortex-x4, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
+// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, 
cortex-a720, cortex-r82, cortex-x1, cortex-x1c

[clang] [llvm] [AArch64][TargetParser] Add mcpu alias for Microsoft Azure Cobalt 100. (PR #79614)

2024-01-29 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/79614

>From 9c7d2d02f59af921cd49f5969b35cbddbec7dfec Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Fri, 26 Jan 2024 10:28:19 +
Subject: [PATCH] [AArch64][TargetParser] Add mcpu alias for Microsoft Azure
 Cobalt 100.

With a690e86 we added -mcpu/mtune=native support to handle the
Microsoft Azure Cobalt 100 CPU as a Neoverse N2. This patch adds
a CPU alias in TargetParser to maintain compatibility with GCC.
---
 clang/test/Driver/aarch64-mcpu.c | 3 +++
 clang/test/Misc/target-invalid-cpu-note.c| 4 ++--
 llvm/include/llvm/TargetParser/AArch64TargetParser.h | 3 ++-
 llvm/unittests/TargetParser/TargetParserTest.cpp | 2 +-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/clang/test/Driver/aarch64-mcpu.c b/clang/test/Driver/aarch64-mcpu.c
index 511482a420da268..3e07f3597f34081 100644
--- a/clang/test/Driver/aarch64-mcpu.c
+++ b/clang/test/Driver/aarch64-mcpu.c
@@ -72,6 +72,9 @@
 // RUN: %clang --target=aarch64 -mcpu=cortex-r82  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXR82 %s
 // CORTEXR82: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-r82"
 
+// RUN: %clang --target=aarch64 -mcpu=cobalt-100 -### -c %s 2>&1 | FileCheck 
-check-prefix=COBALT-100 %s
+// COBALT-100: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"neoverse-n2"
+
 // RUN: %clang --target=aarch64 -mcpu=grace -### -c %s 2>&1 | FileCheck 
-check-prefix=GRACE %s
 // GRACE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "neoverse-v2"
 
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 84aed5c9c36fe47..2f10bfb1fd82fe3 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-a720, 
cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, cortex-x4, 
neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-a720, 
cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, cortex-x4, 
neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, cobalt-100, 
grace{{$}}
 
 // RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE_AARCH64
 // TUNE_AARCH64: error: unknown target CPU 'not-a-cpu'
-// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-a715, 
cortex-a720, cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, 
cortex-x4, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, grace{{$}}
+// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, cortex-a77, cortex-a78, cortex-a78c, cortex-a710,

  1   2   3   4   5   6   >