Skip to content

Commit d70267f

Browse files
authored
[RISCV] Teach .option arch to support experimental extensions. (#89727)
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.
1 parent 947b062 commit d70267f

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

clang/test/Driver/riscv-option-arch.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %clang --target=riscv64 -menable-experimental-extensions -c -o /dev/null %s
2+
// RUN: ! %clang --target=riscv64 -c -o /dev/null %s 2>&1 | FileCheck -check-prefixes=CHECK-ERR %s
3+
4+
void foo() {
5+
asm volatile (".option arch, +zicfiss");
6+
// CHECK-ERR: Unexpected experimental extensions.
7+
}

clang/test/Driver/riscv-option-arch.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# RUN: %clang --target=riscv64 -menable-experimental-extensions -c -o /dev/null %s
2+
# RUN: ! %clang --target=riscv64 -c -o /dev/null %s 2>&1 | FileCheck -check-prefixes=CHECK-ERR %s
3+
4+
.option arch, +zicfiss
5+
# CHECK-ERR: Unexpected experimental extensions.

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class RISCVAsmParser : public MCTargetAsmParser {
8484
SMLoc getLoc() const { return getParser().getTok().getLoc(); }
8585
bool isRV64() const { return getSTI().hasFeature(RISCV::Feature64Bit); }
8686
bool isRVE() const { return getSTI().hasFeature(RISCV::FeatureStdExtE); }
87+
bool enableExperimentalExtension() const {
88+
return getSTI().hasFeature(RISCV::Experimental);
89+
}
8790

8891
RISCVTargetStreamer &getTargetStreamer() {
8992
assert(getParser().getStreamer().getTargetStreamer() &&
@@ -2824,17 +2827,19 @@ bool RISCVAsmParser::parseDirectiveOption() {
28242827
break;
28252828
}
28262829

2827-
auto Ext = llvm::lower_bound(RISCVFeatureKV, Arch);
2828-
if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Arch ||
2829-
!RISCVISAInfo::isSupportedExtension(Arch)) {
2830-
if (isDigit(Arch.back()))
2831-
return Error(
2832-
Loc,
2833-
"Extension version number parsing not currently implemented");
2830+
if (isDigit(Arch.back()))
2831+
return Error(
2832+
Loc, "Extension version number parsing not currently implemented");
2833+
2834+
std::string Feature = RISCVISAInfo::getTargetFeatureForExtension(Arch);
2835+
if (!enableExperimentalExtension() &&
2836+
StringRef(Feature).starts_with("experimental-"))
2837+
return Error(Loc, "Unexpected experimental extensions.");
2838+
auto Ext = llvm::lower_bound(RISCVFeatureKV, Feature);
2839+
if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Feature)
28342840
return Error(Loc, "unknown extension feature");
2835-
}
28362841

2837-
Args.emplace_back(Type, Ext->Key);
2842+
Args.emplace_back(Type, Arch.str());
28382843

28392844
if (Type == RISCVOptionArchArgType::Plus) {
28402845
FeatureBitset OldFeatureBits = STI->getFeatureBits();

llvm/test/MC/RISCV/option-arch.s

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# RUN: llvm-mc -triple riscv32 -show-encoding < %s \
1+
# RUN: llvm-mc -triple riscv32 -mattr=+experimental -show-encoding < %s \
22
# RUN: | FileCheck -check-prefixes=CHECK %s
3-
# RUN: llvm-mc -triple riscv32 -filetype=obj < %s \
4-
# RUN: | llvm-objdump --triple=riscv32 --mattr=+c,+m,+a,+f,+zba -d -M no-aliases - \
3+
# RUN: llvm-mc -triple riscv32 -mattr=+experimental -filetype=obj < %s \
4+
# RUN: | llvm-objdump --triple=riscv32 --mattr=+c,+m,+a,+f,+zba,+experimental-zicfiss -d -M no-aliases - \
55
# RUN: | FileCheck -check-prefixes=CHECK-INST %s
66

77
# Test '.option arch, +' and '.option arch, -' directive
@@ -78,6 +78,13 @@ lr.w t0, (t1)
7878
# CHECK: encoding: [0xb3,0x22,0x73,0x20]
7979
sh1add t0, t1, t2
8080

81+
# Test experimental extension
82+
# CHECK: .option arch, +zicfiss
83+
.option arch, +zicfiss
84+
# CHECK-INST: sspopchk ra
85+
# CHECK: encoding: [0x73,0xc0,0xc0,0xcd]
86+
sspopchk ra
87+
8188
# Test '.option arch, <arch-string>' directive
8289
# CHECK: .option arch, rv32i2p1_m2p0_a2p1_c2p0
8390
.option arch, rv32i2p1_m2p0_a2p1_c2p0

0 commit comments

Comments
 (0)