Skip to content

Commit 1bebb99

Browse files
authored
[RISCV] Add B extension (#76893)
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 607afa0 commit 1bebb99

File tree

7 files changed

+28
-12
lines changed

7 files changed

+28
-12
lines changed

clang/test/Driver/riscv-arch.c

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

234-
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ib -### %s \
235-
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-B %s
236-
// RV32-B: error: invalid arch name 'rv32ib',
237-
// RV32-B: unsupported standard user-level extension 'b'
238-
239234
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32xabc -### %s \
240235
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32X %s
241236
// 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 {{.*$}}
@@ -194,6 +195,17 @@
194195
// CHECK-A-EXT: __riscv_a 2001000{{$}}
195196
// CHECK-A-EXT: __riscv_atomic 1
196197

198+
// RUN: %clang --target=riscv32-unknown-linux-gnu \
199+
// RUN: -march=rv32ib -x c -E -dM %s \
200+
// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
201+
// RUN: %clang --target=riscv64-unknown-linux-gnu \
202+
// RUN: -march=rv64ib -x c -E -dM %s \
203+
// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
204+
// CHECK-B-EXT: __riscv_b 1000000{{$}}
205+
// CHECK-B-EXT: __riscv_zba 1000000{{$}}
206+
// CHECK-B-EXT: __riscv_zbb 1000000{{$}}
207+
// CHECK-B-EXT: __riscv_zbs 1000000{{$}}
208+
197209
// RUN: %clang --target=riscv32-unknown-linux-gnu \
198210
// RUN: -march=rv32ic -E -dM %s \
199211
// 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/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ Changes to the RISC-V Backend
152152
* Zaamo and Zalrsc are no longer experimental.
153153
* Processors that enable post reg-alloc scheduling (PostMachineScheduler) by default should use the `UsePostRAScheduler` subtarget feature. Setting `PostRAScheduler = 1` in the scheduler model will have no effect on the enabling of the PostMachineScheduler.
154154
* Zabha is no longer experimental.
155+
* B (the collection of the Zba, Zbb, Zbs extensions) is supported.
155156

156157
Changes to the WebAssembly Backend
157158
----------------------------------

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,14 @@ def HasStdExtZbs : Predicate<"Subtarget->hasStdExtZbs()">,
477477

478478
// Bitmanip Extensions for Cryptography Extensions
479479

480+
def FeatureStdExtB
481+
: RISCVExtension<"b", 1, 0,
482+
"'B' (the collection of the Zba, Zbb, Zbs extensions)",
483+
[FeatureStdExtZba, FeatureStdExtZbb, FeatureStdExtZbs]>;
484+
def HasStdExtB : Predicate<"Subtarget->hasStdExtB()">,
485+
AssemblerPredicate<(all_of FeatureStdExtB),
486+
"'B' (the collection of the Zba, Zbb, Zbs extensions)">;
487+
480488
def FeatureStdExtZbkb
481489
: RISCVExtension<"zbkb", 1, 0,
482490
"'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
@@ -131,6 +132,7 @@
131132
; RUN: llc -mtriple=riscv64 -mattr=+zmmul %s -o - | FileCheck --check-prefixes=CHECK,RV64ZMMUL %s
132133
; RUN: llc -mtriple=riscv64 -mattr=+m,+zmmul %s -o - | FileCheck --check-prefixes=CHECK,RV64MZMMUL %s
133134
; RUN: llc -mtriple=riscv64 -mattr=+a %s -o - | FileCheck --check-prefixes=CHECK,RV64A %s
135+
; RUN: llc -mtriple=riscv64 -mattr=+b %s -o - | FileCheck --check-prefixes=CHECK,RV64B %s
134136
; RUN: llc -mtriple=riscv64 -mattr=+f %s -o - | FileCheck --check-prefixes=CHECK,RV64F %s
135137
; RUN: llc -mtriple=riscv64 -mattr=+d %s -o - | FileCheck --check-prefixes=CHECK,RV64D %s
136138
; RUN: llc -mtriple=riscv64 -mattr=+c %s -o - | FileCheck --check-prefixes=CHECK,RV64C %s
@@ -277,6 +279,7 @@
277279
; RV32ZMMUL: .attribute 5, "rv32i2p1_zmmul1p0"
278280
; RV32MZMMUL: .attribute 5, "rv32i2p1_m2p0_zmmul1p0"
279281
; RV32A: .attribute 5, "rv32i2p1_a2p1"
282+
; RV32B: .attribute 5, "rv32i2p1_b1p0_zba1p0_zbb1p0_zbs1p0"
280283
; RV32F: .attribute 5, "rv32i2p1_f2p2_zicsr2p0"
281284
; RV32D: .attribute 5, "rv32i2p1_f2p2_d2p2_zicsr2p0"
282285
; RV32C: .attribute 5, "rv32i2p1_c2p0"
@@ -402,6 +405,7 @@
402405
; RV64ZMMUL: .attribute 5, "rv64i2p1_zmmul1p0"
403406
; RV64MZMMUL: .attribute 5, "rv64i2p1_m2p0_zmmul1p0"
404407
; RV64A: .attribute 5, "rv64i2p1_a2p1"
408+
; RV64B: .attribute 5, "rv64i2p1_b1p0_zba1p0_zbb1p0_zbs1p0"
405409
; RV64F: .attribute 5, "rv64i2p1_f2p2_zicsr2p0"
406410
; RV64D: .attribute 5, "rv64i2p1_f2p2_d2p2_zicsr2p0"
407411
; RV64C: .attribute 5, "rv64i2p1_c2p0"

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,6 @@ TEST(ParseArchString, AcceptsSupportedBaseISAsAndSetsXLenAndFLen) {
312312
}
313313

314314
TEST(ParseArchString, RejectsUnrecognizedExtensionNamesByDefault) {
315-
EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv64ib", true).takeError()),
316-
"unsupported standard user-level extension 'b'");
317315
EXPECT_EQ(
318316
toString(
319317
RISCVISAInfo::parseArchString("rv32i_zmadeup", true).takeError()),
@@ -326,9 +324,6 @@ TEST(ParseArchString, RejectsUnrecognizedExtensionNamesByDefault) {
326324
toString(
327325
RISCVISAInfo::parseArchString("rv64g_xmadeup", true).takeError()),
328326
"unsupported non-standard user-level extension 'xmadeup'");
329-
EXPECT_EQ(
330-
toString(RISCVISAInfo::parseArchString("rv64ib1p0", true).takeError()),
331-
"unsupported standard user-level extension 'b'");
332327
EXPECT_EQ(
333328
toString(
334329
RISCVISAInfo::parseArchString("rv32i_zmadeup1p0", true).takeError()),
@@ -344,8 +339,7 @@ TEST(ParseArchString, RejectsUnrecognizedExtensionNamesByDefault) {
344339
}
345340

346341
TEST(ParseArchString, IgnoresUnrecognizedExtensionNamesWithIgnoreUnknown) {
347-
for (StringRef Input : {"rv32ib", "rv32i_zmadeup",
348-
"rv64i_smadeup", "rv64i_xmadeup"}) {
342+
for (StringRef Input : {"rv32i_zmadeup", "rv64i_smadeup", "rv64i_xmadeup"}) {
349343
auto MaybeISAInfo = RISCVISAInfo::parseArchString(Input, true, false, true);
350344
ASSERT_THAT_EXPECTED(MaybeISAInfo, Succeeded());
351345
RISCVISAInfo &Info = **MaybeISAInfo;
@@ -913,6 +907,7 @@ R"(All available -march extensions for RISC-V
913907
f 2.2
914908
d 2.2
915909
c 2.0
910+
b 1.0
916911
v 1.0
917912
h 1.0
918913
zic64b 1.0

0 commit comments

Comments
 (0)