-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV][FMV] Support target_version #99040
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
Changes from all commits
54b5d68
68cbc16
c7ad1a9
5414680
7c6f108
5e00115
2fcfc9c
a487f19
b89211c
8cd911d
e98d84f
e449161
9c70204
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -10319,7 +10319,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, | |||
// Handle attributes. | ||||
ProcessDeclAttributes(S, NewFD, D); | ||||
const auto *NewTVA = NewFD->getAttr<TargetVersionAttr>(); | ||||
if (NewTVA && !NewTVA->isDefaultVersion() && | ||||
if (Context.getTargetInfo().getTriple().isAArch64() && NewTVA && | ||||
!NewTVA->isDefaultVersion() && | ||||
!Context.getTargetInfo().hasFeature("fmv")) { | ||||
// Don't add to scope fmv functions declarations if fmv disabled | ||||
AddToScope = false; | ||||
|
@@ -11028,7 +11029,15 @@ static bool CheckMultiVersionValue(Sema &S, const FunctionDecl *FD) { | |||
|
||||
if (TVA) { | ||||
llvm::SmallVector<StringRef, 8> Feats; | ||||
TVA->getFeatures(Feats); | ||||
if (S.getASTContext().getTargetInfo().getTriple().isRISCV()) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The need to version all of this by target is unfortunate. Is there a way we can reduce the duplication here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reduce the part of duplication, and the remain part is causing by different syntax between aarch64 and RISC-V. To reducing the remain part of duplication, we could implement the RISC-V syntax inside By the way, the parsing of target_clones syntax is controlled by the target. (Reference: llvm-project/clang/lib/Sema/SemaDeclAttr.cpp Line 3121 in 9cd9377
|
||||
ParsedTargetAttr ParseInfo = | ||||
S.getASTContext().getTargetInfo().parseTargetAttr(TVA->getName()); | ||||
for (auto &Feat : ParseInfo.Features) | ||||
Feats.push_back(StringRef{Feat}.substr(1)); | ||||
} else { | ||||
assert(S.getASTContext().getTargetInfo().getTriple().isAArch64()); | ||||
TVA->getFeatures(Feats); | ||||
BeMg marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
} | ||||
for (const auto &Feat : Feats) { | ||||
if (!TargetInfo.validateCpuSupports(Feat)) { | ||||
S.Diag(FD->getLocation(), diag::err_bad_multiversion_option) | ||||
|
@@ -11314,7 +11323,8 @@ static bool PreviousDeclsHaveMultiVersionAttribute(const FunctionDecl *FD) { | |||
} | ||||
|
||||
static void patchDefaultTargetVersion(FunctionDecl *From, FunctionDecl *To) { | ||||
if (!From->getASTContext().getTargetInfo().getTriple().isAArch64()) | ||||
if (!From->getASTContext().getTargetInfo().getTriple().isAArch64() && | ||||
!From->getASTContext().getTargetInfo().getTriple().isRISCV()) | ||||
return; | ||||
|
||||
MultiVersionKind MVKindFrom = From->getMultiVersionKind(); | ||||
|
@@ -15501,7 +15511,8 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D, | |||
FD->setInvalidDecl(); | ||||
} | ||||
if (const auto *Attr = FD->getAttr<TargetVersionAttr>()) { | ||||
if (!Context.getTargetInfo().hasFeature("fmv") && | ||||
if (Context.getTargetInfo().getTriple().isAArch64() && | ||||
!Context.getTargetInfo().hasFeature("fmv") && | ||||
!Attr->isDefaultVersion()) { | ||||
// If function multi versioning disabled skip parsing function body | ||||
// defined with non-default target_version attribute | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// RUN: not %clang_cc1 -triple riscv64 -target-feature +i -emit-llvm -o - %s 2>&1 | FileCheck %s --check-prefix=CHECK-UNSUPPORT-OS | ||
|
||
// CHECK-UNSUPPORT-OS: error: function multiversioning is currently only supported on Linux | ||
__attribute__((target_version("default"))) int foo(void) { | ||
return 2; | ||
} | ||
|
||
__attribute__((target_version("arch=+c"))) int foo(void) { | ||
return 2; | ||
} | ||
|
||
|
||
int bar() { return foo(); } |
Uh oh!
There was an error while loading. Please reload this page.