Skip to content

Commit 867ece1

Browse files
dtcxzywSForeKeeper
andauthored
[RISCV] Add processor definition for XiangShan-NanHu (#70294)
This PR adds the processor definition for XiangShan-NanHu, an open-source high-performance RISC-V processor. According to the official [documentation](https://xiangshan-doc.readthedocs.io/zh-cn/latest/arch/), NanHu core supports `RV64IMAFDC_zba_zbb_zbc_zbs_zbkb_zbkc_zbkx_zknd_zkne_zknh_zksed_zksh_svinval`. I found that NanHu also supports `zicbom` and `zicboz`. You can find them in the [source code](https://github.com/OpenXiangShan/XiangShan/blob/5931ace35325a644a12f8ea27830a2de7489e7e7/src/main/scala/xiangshan/backend/decode/DecodeUnit.scala#L426-L436). Features supported by NanHu have been confirmed by @poemonsense. --------- Co-authored-by: SForeKeeper <[email protected]>
1 parent 2d739f1 commit 867ece1

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

clang/test/Driver/riscv-cpus.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020
// MCPU-SYNTACORE-SCR1-MAX: "-target-feature" "+zicsr" "-target-feature" "+zifencei"
2121
// MCPU-SYNTACORE-SCR1-MAX: "-target-abi" "ilp32"
2222

23+
// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=xiangshan-nanhu | FileCheck -check-prefix=MCPU-XIANGSHAN-NANHU %s
24+
// MCPU-XIANGSHAN-NANHU: "-nostdsysteminc" "-target-cpu" "xiangshan-nanhu"
25+
// MCPU-XIANGSHAN-NANHU-SAME: "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d"
26+
// MCPU-XIANGSHAN-NANHU-SAME: "-target-feature" "+c"
27+
// MCPU-XIANGSHAN-NANHU-SAME: "-target-feature" "+zicbom" "-target-feature" "+zicboz" "-target-feature" "+zicsr" "-target-feature" "+zifencei"
28+
// MCPU-XIANGSHAN-NANHU-SAME: "-target-feature" "+zba" "-target-feature" "+zbb" "-target-feature" "+zbc"
29+
// MCPU-XIANGSHAN-NANHU-SAME: "-target-feature" "+zbkb" "-target-feature" "+zbkc" "-target-feature" "+zbkx" "-target-feature" "+zbs"
30+
// MCPU-XIANGSHAN-NANHU-SAME: "-target-feature" "+zkn" "-target-feature" "+zknd" "-target-feature" "+zkne" "-target-feature" "+zknh"
31+
// MCPU-XIANGSHAN-NANHU-SAME: "-target-feature" "+zks" "-target-feature" "+zksed" "-target-feature" "+zksh" "-target-feature" "+svinval"
32+
// MCPU-XIANGSHAN-NANHU-SAME: "-target-abi" "lp64d"
33+
2334
// We cannot check much for -mcpu=native, but it should be replaced by a valid CPU string.
2435
// RUN: %clang --target=riscv64 -### -c %s -mcpu=native 2> %t.err || true
2536
// RUN: FileCheck --input-file=%t.err -check-prefix=MCPU-NATIVE %s
@@ -62,6 +73,9 @@
6273
// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=veyron-v1 | FileCheck -check-prefix=MTUNE-VEYRON-V1 %s
6374
// MTUNE-VEYRON-V1: "-tune-cpu" "veyron-v1"
6475

76+
// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=xiangshan-nanhu | FileCheck -check-prefix=MTUNE-XIANGSHAN-NANHU %s
77+
// MTUNE-XIANGSHAN-NANHU: "-tune-cpu" "xiangshan-nanhu"
78+
6579
// Check mtune alias CPU has resolved to the right CPU according XLEN.
6680
// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=generic | FileCheck -check-prefix=MTUNE-GENERIC-32 %s
6781
// MTUNE-GENERIC-32: "-tune-cpu" "generic"

clang/test/Misc/target-invalid-cpu-note.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@
8585

8686
// RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix RISCV64
8787
// RISCV64: error: unknown target CPU 'not-a-cpu'
88-
// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, sifive-u74, sifive-x280, veyron-v1{{$}}
88+
// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, sifive-u74, sifive-x280, veyron-v1, xiangshan-nanhu{{$}}
8989

9090
// RUN: not %clang_cc1 -triple riscv32 -tune-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix TUNE-RISCV32
9191
// TUNE-RISCV32: error: unknown target CPU 'not-a-cpu'
9292
// TUNE-RISCV32-NEXT: note: valid target CPU values are: generic-rv32, rocket-rv32, sifive-e20, sifive-e21, sifive-e24, sifive-e31, sifive-e34, sifive-e76, syntacore-scr1-base, syntacore-scr1-max, generic, rocket, sifive-7-series{{$}}
9393

9494
// RUN: not %clang_cc1 -triple riscv64 -tune-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix TUNE-RISCV64
9595
// TUNE-RISCV64: error: unknown target CPU 'not-a-cpu'
96-
// TUNE-RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, sifive-u74, sifive-x280, veyron-v1, generic, rocket, sifive-7-series{{$}}
96+
// TUNE-RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, sifive-u74, sifive-x280, veyron-v1, xiangshan-nanhu, generic, rocket, sifive-7-series{{$}}

llvm/lib/Target/RISCV/RISCVProcessors.td

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,24 @@ def VENTANA_VEYRON_V1 : RISCVProcessorModel<"veyron-v1",
244244
FeatureStdExtZicboz,
245245
FeatureVendorXVentanaCondOps],
246246
[TuneVentanaVeyron]>;
247+
248+
def XIANGSHAN_NANHU : RISCVProcessorModel<"xiangshan-nanhu",
249+
NoSchedModel,
250+
[Feature64Bit,
251+
FeatureStdExtZicsr,
252+
FeatureStdExtZifencei,
253+
FeatureStdExtM,
254+
FeatureStdExtA,
255+
FeatureStdExtF,
256+
FeatureStdExtD,
257+
FeatureStdExtC,
258+
FeatureStdExtZba,
259+
FeatureStdExtZbb,
260+
FeatureStdExtZbc,
261+
FeatureStdExtZbs,
262+
FeatureStdExtZkn,
263+
FeatureStdExtZksed,
264+
FeatureStdExtZksh,
265+
FeatureStdExtSvinval,
266+
FeatureStdExtZicbom,
267+
FeatureStdExtZicboz]>;

0 commit comments

Comments
 (0)