Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RISCV] Disallow target attribute use in multiversioning #85899

Merged
merged 3 commits into from
Apr 12, 2024

Conversation

BeMg
Copy link
Contributor

@BeMg BeMg commented Mar 20, 2024

For RISC-V target only target_clones and target_version can enable function multiversion(FMV).

This patch make target attribute trigger redefinition instead of emit FMV.

Here is spec https://github.com/riscv-non-isa/riscv-c-api-doc/blob/master/riscv-c-api.md#__attribute__targetattr-string

@BeMg BeMg marked this pull request as ready for review March 27, 2024 00:44
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 27, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 27, 2024

@llvm/pr-subscribers-backend-risc-v

@llvm/pr-subscribers-clang

Author: Piyou Chen (BeMg)

Changes

For RISC-V target only target_clones and target_version can enable function multiversion(FMV).

This patch make target attribute trigger redefinition instead of emit FMV.


Full diff: https://github.com/llvm/llvm-project/pull/85899.diff

1 Files Affected:

  • (modified) clang/lib/Sema/SemaDecl.cpp (+4)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5850cd0ab6b9aa..e543aff77e67ea 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11853,6 +11853,10 @@ static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD,
   if (NewTA && S.getASTContext().getTargetInfo().getTriple().isAArch64())
     return false;
 
+  // Target attribute on RISCV is not used for multiversioning
+  if (NewTA && S.getASTContext().getTargetInfo().getTriple().isRISCV())
+    return false;
+
   if (!OldDecl || !OldDecl->getAsFunction() ||
       OldDecl->getDeclContext()->getRedeclContext() !=
           NewFD->getDeclContext()->getRedeclContext()) {

@BeMg BeMg requested review from kito-cheng and topperc March 27, 2024 00:46
@BeMg
Copy link
Contributor Author

BeMg commented Mar 27, 2024

The proposal could be found here riscv-non-isa/riscv-c-api-doc#48.

@kito-cheng
Copy link
Member

Add a testcase like AArch64 https://reviews.llvm.org/D150867 ?

@@ -11853,6 +11853,10 @@ static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD,
if (NewTA && S.getASTContext().getTargetInfo().getTriple().isAArch64())
return false;

// Target attribute on RISCV is not used for multiversioning
if (NewTA && S.getASTContext().getTargetInfo().getTriple().isRISCV())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we share S.getASTContext().getTargetInfo().getTriple() with AArch64

@BeMg BeMg requested a review from topperc April 8, 2024 05:15
Copy link
Member

@kito-cheng kito-cheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@BeMg BeMg force-pushed the IFUNC/disable-target-attr-FMV branch from 6757bf5 to b9a2a5e Compare April 11, 2024 06:38
@BeMg BeMg merged commit 334e07f into llvm:main Apr 12, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:RISC-V clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants