-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV] Teach .option arch to support experimental extensions. #89727
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
Conversation
Previously .option arch denied extenions are not belongs to RISC-V features. But experimental features have experimental- prefix, so .option arch can not serve for experimental extension. This patch uses the features of extensions to identify extension existance.
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-mc Author: Yeting Kuo (yetingk) ChangesPreviously .option arch denied extenions are not belongs to RISC-V features. But experimental features have experimental- prefix, so .option arch can not serve for experimental extension. Full diff: https://github.com/llvm/llvm-project/pull/89727.diff 2 Files Affected:
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 3f4a73ad89bf8a..80ff70f1095f4c 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -2824,8 +2824,9 @@ bool RISCVAsmParser::parseDirectiveOption() {
break;
}
- auto Ext = llvm::lower_bound(RISCVFeatureKV, Arch);
- if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Arch ||
+ std::string &&Feature = RISCVISAInfo::getTargetFeatureForExtension(Arch);
+ auto Ext = llvm::lower_bound(RISCVFeatureKV, Feature);
+ if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Feature ||
!RISCVISAInfo::isSupportedExtension(Arch)) {
if (isDigit(Arch.back()))
return Error(
@@ -2834,7 +2835,7 @@ bool RISCVAsmParser::parseDirectiveOption() {
return Error(Loc, "unknown extension feature");
}
- Args.emplace_back(Type, Ext->Key);
+ Args.emplace_back(Type, Arch.str());
if (Type == RISCVOptionArchArgType::Plus) {
FeatureBitset OldFeatureBits = STI->getFeatureBits();
diff --git a/llvm/test/MC/RISCV/option-arch.s b/llvm/test/MC/RISCV/option-arch.s
index 6ee133c7159a27..40675f9e4b434b 100644
--- a/llvm/test/MC/RISCV/option-arch.s
+++ b/llvm/test/MC/RISCV/option-arch.s
@@ -1,7 +1,7 @@
# RUN: llvm-mc -triple riscv32 -show-encoding < %s \
# RUN: | FileCheck -check-prefixes=CHECK %s
# RUN: llvm-mc -triple riscv32 -filetype=obj < %s \
-# RUN: | llvm-objdump --triple=riscv32 --mattr=+c,+m,+a,+f,+zba -d -M no-aliases - \
+# RUN: | llvm-objdump --triple=riscv32 --mattr=+c,+m,+a,+f,+zba,+experimental-zicfiss -d -M no-aliases - \
# RUN: | FileCheck -check-prefixes=CHECK-INST %s
# Test '.option arch, +' and '.option arch, -' directive
@@ -78,6 +78,13 @@ lr.w t0, (t1)
# CHECK: encoding: [0xb3,0x22,0x73,0x20]
sh1add t0, t1, t2
+# Test experimental extension
+# CHECK: .option arch, +zicfiss
+.option arch, +zicfiss
+# CHECK-INST: sspopchk ra
+# CHECK: encoding: [0x73,0xc0,0xc0,0xcd]
+sspopchk ra
+
# Test '.option arch, <arch-string>' directive
# CHECK: .option arch, rv32i2p1_m2p0_a2p1_c2p0
.option arch, rv32i2p1_m2p0_a2p1_c2p0
|
I’m concerned about testing this; experimental extensions are, by policy, transient in LLVM, eventually either being promoted to non-experimental or being dropped, which means churn in this test every time the chosen extension is no longer present and experimental. What are your thoughts there? |
Also, does this obey -menable-experimental-extensions? |
IMO, I prefer this feature depends on |
Yes, I believe it should. My question is whether it currently does, especially given I don’t believe your current patch is testing it? |
It currently doesn't obey |
@@ -51,6 +51,9 @@ STATISTIC(RISCVNumInstrsCompressed, | |||
|
|||
static cl::opt<bool> AddBuildAttributes("riscv-add-build-attributes", | |||
cl::init(false)); | |||
static cl::opt<bool> | |||
DisableExperimentalExtension("riscv-disable-experimental-ext", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why disable instead of enable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since only clang needs specific option to allows experimental extensions.
@@ -2824,8 +2827,12 @@ bool RISCVAsmParser::parseDirectiveOption() { | |||
break; | |||
} | |||
|
|||
auto Ext = llvm::lower_bound(RISCVFeatureKV, Arch); | |||
if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Arch || | |||
std::string &&Feature = RISCVISAInfo::getTargetFeatureForExtension(Arch); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why an rvalue reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might less call a string constructor() and just use the return string value. But acutally I am not really sure how does rvalue reference work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should just use std::string Feature
. I think std::string &&Feature
will just make a reference to a hidden temporary object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Does this disable use of experimental extensions for a |
No. my patch could not block the case. I will try to think this problem after my sleep. |
I fix the issue by using feature to control the permission of experimental extension.
|
1f6185b
to
2414946
Compare
@@ -169,6 +169,9 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple, | |||
Features.push_back("-relax"); | |||
} | |||
|
|||
if (!Args.hasArg(options::OPT_menable_experimental_extensions)) | |||
Features.push_back("+no-experimental-ext"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also check OPT_menable_experimental_extensions
in getArchFeatures
and push a different feature when it is set. Do we need 2 extensions that are the opposite of each other?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Only use +experimental feature.
2414946
to
a27e003
Compare
@@ -51,7 +51,6 @@ STATISTIC(RISCVNumInstrsCompressed, | |||
|
|||
static cl::opt<bool> AddBuildAttributes("riscv-add-build-attributes", | |||
cl::init(false)); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
StringRef(Feature).starts_with("experimental-")) | ||
return Error(Loc, "Unexpected experimental extensions."); | ||
auto Ext = llvm::lower_bound(RISCVFeatureKV, Feature); | ||
if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Feature || | ||
!RISCVISAInfo::isSupportedExtension(Arch)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need the RISCVISAInfo::isSupportedExtension(Arch)
check here? Did RISCVISAInfo::getTargetFeatureForExtension
already take care of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@topperc Sorry, there was a quick fix after the approve. |
@yetingk, the two tests you added are failing on a couple of build bots:
Can you take a look and revert if you need time to investigate? |
6217abc should fix the test failures. |
Driver tests are supposed to verify Driver behavior. That is, use |
@zmodem very thank you for the help. |
@pogo59 Thank you for the advise. I will update the test cases. |
PR llvm#89727 added the two test cases to verify `.option arch` should only work when having -menable-experimental-extensions. And the test idea could be splitted to 1. When having menable-experimental-extensions, clang passes +experimental. 2. `.option arch` only enabled when +experimental enabled. And we already had the two kind of test.
@@ -0,0 +1,7 @@ | |||
// RUN: %clang --target=riscv64 -menable-experimental-extensions -c -o /dev/null %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these clang tests? This is entirely testing llvm/ code. Never mind the weirdness of putting them in Driver/, nor the fact that they’re missing a REQUIRES: riscv-registered-target given they use the backend, they don’t belong in clang/ at all surely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I am sorry that I didn't find out the obvious mistake. I am going to review my development process.
@@ -0,0 +1,7 @@ | |||
// RUN: %clang --target=riscv64 -menable-experimental-extensions -c -o /dev/null %s | |||
// RUN: ! %clang --target=riscv64 -c -o /dev/null %s 2>&1 | FileCheck -check-prefixes=CHECK-ERR %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use not rather than !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion. I will fix this if #91324 could not remove the tests.
PR #89727 added the two test cases to verify `.option arch` should only work when having -menable-experimental-extensions. And the test idea could be splitted to 1. When having menable-experimental-extensions, clang passes +experimental. 2. `.option arch` only enabled when +experimental enabled. And we already had the two kind of tests.
The clang/test/Driver codegen tests might have been removed. Note: clang/test/Driver is to test how clangDriver passes options to cc1, not for sema/codegen/etc. |
Thank you for the reminder. |
Previously
.option arch
denied extenions are not belongs to RISC-V features. But experimental features have experimental- prefix, so.option arch
can not serve for experimental extension.This patch uses the features of extensions to identify extension existance.