Skip to content

Commit c4f7441

Browse files
committed
[RISCV] Add B extension
It seems that we have `B` extension again: https://github.com/riscv/riscv-b According to the spec, `B` extension represents the collection of the `Zba`, `Zbb`, `Zbs` extensions. Though it hasn't been ratified, I set its version to `1.0`.
1 parent 0ad83bc commit c4f7441

File tree

7 files changed

+31
-10
lines changed

7 files changed

+31
-10
lines changed

clang/test/Driver/riscv-arch.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,6 @@
233233
// RV32-STD: error: invalid arch name 'rv32imqc',
234234
// RV32-STD: unsupported standard user-level extension 'q'
235235

236-
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ib -### %s \
237-
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-B %s
238-
// RV32-B: error: invalid arch name 'rv32ib',
239-
// RV32-B: unsupported standard user-level extension 'b'
240-
241236
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32xabc -### %s \
242237
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32X %s
243238
// RV32X: error: invalid arch name 'rv32xabc',

clang/test/Preprocessor/riscv-target-features.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// CHECK-NOT: __riscv_64e {{.*$}}
88
// CHECK-NOT: __riscv_a {{.*$}}
99
// CHECK-NOT: __riscv_atomic
10+
// CHECK-NOT: __riscv_b {{.*$}}
1011
// CHECK-NOT: __riscv_c {{.*$}}
1112
// CHECK-NOT: __riscv_compressed {{.*$}}
1213
// CHECK-NOT: __riscv_d {{.*$}}
@@ -159,6 +160,17 @@
159160
// CHECK-A-EXT: __riscv_a 2001000{{$}}
160161
// CHECK-A-EXT: __riscv_atomic 1
161162

163+
// RUN: %clang --target=riscv32-unknown-linux-gnu \
164+
// RUN: -march=rv32ib -x c -E -dM %s \
165+
// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
166+
// RUN: %clang --target=riscv64-unknown-linux-gnu \
167+
// RUN: -march=rv64ib -x c -E -dM %s \
168+
// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
169+
// CHECK-B-EXT: __riscv_b 1000000{{$}}
170+
// CHECK-B-EXT: __riscv_zba 1000000{{$}}
171+
// CHECK-B-EXT: __riscv_zbb 1000000{{$}}
172+
// CHECK-B-EXT: __riscv_zbs 1000000{{$}}
173+
162174
// RUN: %clang --target=riscv32-unknown-linux-gnu \
163175
// RUN: -march=rv32ic -x c -E -dM %s \
164176
// RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s

llvm/docs/RISCVUsage.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ on support follow.
8585
Extension Status
8686
=============== =========================================================
8787
``A`` Supported
88+
``B`` Supported
8889
``C`` Supported
8990
``D`` Supported
9091
``F`` Supported

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static const char *RISCVGImplications[] = {
4646
// NOTE: This table should be sorted alphabetically by extension name.
4747
static const RISCVSupportedExtension SupportedExtensions[] = {
4848
{"a", {2, 1}},
49+
{"b", {1, 0}},
4950
{"c", {2, 0}},
5051
{"d", {2, 2}},
5152
{"e", {2, 0}},
@@ -848,7 +849,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
848849
}
849850

850851
// The order is OK, then push it into features.
851-
// Currently LLVM supports only "mafdcvh".
852+
// Currently LLVM supports only "mafdcbvh".
852853
if (!isSupportedExtension(StringRef(&C, 1))) {
853854
if (IgnoreUnknown) {
854855
GoToNextExt(I, ConsumeLength, Exts.end());
@@ -998,6 +999,7 @@ Error RISCVISAInfo::checkDependency() {
998999
return Error::success();
9991000
}
10001001

1002+
static const char *ImpliedExtsB[] = {"zba", "zbb", "zbs"};
10011003
static const char *ImpliedExtsD[] = {"f"};
10021004
static const char *ImpliedExtsF[] = {"zicsr"};
10031005
static const char *ImpliedExtsV[] = {"zvl128b", "zve64d"};
@@ -1072,6 +1074,7 @@ struct ImpliedExtsEntry {
10721074

10731075
// Note: The table needs to be sorted by name.
10741076
static constexpr ImpliedExtsEntry ImpliedExts[] = {
1077+
{{"b"}, {ImpliedExtsB}},
10751078
{{"d"}, {ImpliedExtsD}},
10761079
{{"f"}, {ImpliedExtsF}},
10771080
{{"v"}, {ImpliedExtsV}},

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ def HasStdExtZbs : Predicate<"Subtarget->hasStdExtZbs()">,
225225
AssemblerPredicate<(all_of FeatureStdExtZbs),
226226
"'Zbs' (Single-Bit Instructions)">;
227227

228+
def FeatureStdExtB
229+
: SubtargetFeature<"b", "HasStdExtB", "true",
230+
"'B' (the collection of the Zba, Zbb, Zbs extensions)",
231+
[FeatureStdExtZba, FeatureStdExtZbb, FeatureStdExtZbs]>;
232+
def HasStdExtB : Predicate<"Subtarget->hasStdExtB()">,
233+
AssemblerPredicate<(all_of FeatureStdExtB),
234+
"'B' (the collection of the Zba, Zbb, Zbs extensions)">;
235+
228236
def FeatureStdExtZbkb
229237
: SubtargetFeature<"zbkb", "HasStdExtZbkb", "true",
230238
"'Zbkb' (Bitmanip instructions for Cryptography)">;

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
; RUN: llc -mtriple=riscv32 -mattr=+zmmul %s -o - | FileCheck --check-prefixes=CHECK,RV32ZMMUL %s
66
; RUN: llc -mtriple=riscv32 -mattr=+m,+zmmul %s -o - | FileCheck --check-prefixes=CHECK,RV32MZMMUL %s
77
; RUN: llc -mtriple=riscv32 -mattr=+a %s -o - | FileCheck --check-prefixes=CHECK,RV32A %s
8+
; RUN: llc -mtriple=riscv32 -mattr=+b %s -o - | FileCheck --check-prefixes=CHECK,RV32B %s
89
; RUN: llc -mtriple=riscv32 -mattr=+f %s -o - | FileCheck --check-prefixes=CHECK,RV32F %s
910
; RUN: llc -mtriple=riscv32 -mattr=+d %s -o - | FileCheck --check-prefixes=CHECK,RV32D %s
1011
; RUN: llc -mtriple=riscv32 -mattr=+c %s -o - | FileCheck --check-prefixes=CHECK,RV32C %s
@@ -100,6 +101,7 @@
100101
; RUN: llc -mtriple=riscv64 -mattr=+zmmul %s -o - | FileCheck --check-prefixes=CHECK,RV64ZMMUL %s
101102
; RUN: llc -mtriple=riscv64 -mattr=+m,+zmmul %s -o - | FileCheck --check-prefixes=CHECK,RV64MZMMUL %s
102103
; RUN: llc -mtriple=riscv64 -mattr=+a %s -o - | FileCheck --check-prefixes=CHECK,RV64A %s
104+
; RUN: llc -mtriple=riscv64 -mattr=+b %s -o - | FileCheck --check-prefixes=CHECK,RV64B %s
103105
; RUN: llc -mtriple=riscv64 -mattr=+f %s -o - | FileCheck --check-prefixes=CHECK,RV64F %s
104106
; RUN: llc -mtriple=riscv64 -mattr=+d %s -o - | FileCheck --check-prefixes=CHECK,RV64D %s
105107
; RUN: llc -mtriple=riscv64 -mattr=+c %s -o - | FileCheck --check-prefixes=CHECK,RV64C %s
@@ -202,6 +204,7 @@
202204
; RV32ZMMUL: .attribute 5, "rv32i2p1_zmmul1p0"
203205
; RV32MZMMUL: .attribute 5, "rv32i2p1_m2p0_zmmul1p0"
204206
; RV32A: .attribute 5, "rv32i2p1_a2p1"
207+
; RV32B: .attribute 5, "rv32i2p1_b1p0_zba1p0_zbb1p0_zbs1p0"
205208
; RV32F: .attribute 5, "rv32i2p1_f2p2_zicsr2p0"
206209
; RV32D: .attribute 5, "rv32i2p1_f2p2_d2p2_zicsr2p0"
207210
; RV32C: .attribute 5, "rv32i2p1_c2p0"
@@ -296,6 +299,7 @@
296299
; RV64ZMMUL: .attribute 5, "rv64i2p1_zmmul1p0"
297300
; RV64MZMMUL: .attribute 5, "rv64i2p1_m2p0_zmmul1p0"
298301
; RV64A: .attribute 5, "rv64i2p1_a2p1"
302+
; RV64B: .attribute 5, "rv64i2p1_b1p0_zba1p0_zbb1p0_zbs1p0"
299303
; RV64F: .attribute 5, "rv64i2p1_f2p2_zicsr2p0"
300304
; RV64D: .attribute 5, "rv64i2p1_f2p2_d2p2_zicsr2p0"
301305
; RV64C: .attribute 5, "rv64i2p1_c2p0"

llvm/unittests/Support/RISCVISAInfoTest.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ TEST(ParseArchString, RequiresCanonicalOrderForSingleLetterExtensions) {
222222
}
223223

224224
TEST(ParseArchString, RejectsUnrecognizedExtensionNamesByDefault) {
225-
EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv64ib", true).takeError()),
226-
"unsupported standard user-level extension 'b'");
227225
EXPECT_EQ(
228226
toString(
229227
RISCVISAInfo::parseArchString("rv32i_zmadeup", true).takeError()),
@@ -239,8 +237,7 @@ TEST(ParseArchString, RejectsUnrecognizedExtensionNamesByDefault) {
239237
}
240238

241239
TEST(ParseArchString, IgnoresUnrecognizedExtensionNamesWithIgnoreUnknown) {
242-
for (StringRef Input : {"rv32ib", "rv32i_zmadeup",
243-
"rv64i_smadeup", "rv64i_xmadeup"}) {
240+
for (StringRef Input : {"rv32i_zmadeup", "rv64i_smadeup", "rv64i_xmadeup"}) {
244241
auto MaybeISAInfo = RISCVISAInfo::parseArchString(Input, true, false, true);
245242
ASSERT_THAT_EXPECTED(MaybeISAInfo, Succeeded());
246243
RISCVISAInfo &Info = **MaybeISAInfo;
@@ -673,6 +670,7 @@ R"(All available -march extensions for RISC-V
673670
f 2.2
674671
d 2.2
675672
c 2.0
673+
b 1.0
676674
v 1.0
677675
h 1.0
678676
zic64b 1.0

0 commit comments

Comments
 (0)