diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -32,7 +32,19 @@ bool HasC = false; bool HasB = false; bool HasV = false; + bool HasZbb = false; + bool HasZbc = false; + bool HasZbe = false; + bool HasZbf = false; + bool HasZbm = false; + bool HasZbp = false; + bool HasZbproposedc = false; + bool HasZbr = false; + bool HasZbs = false; + bool HasZbt = false; bool HasZfh = false; + bool HasZvamo = false; + bool HasZvlsseg = false; public: RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &) diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp --- a/clang/lib/Basic/Targets/RISCV.cpp +++ b/clang/lib/Basic/Targets/RISCV.cpp @@ -109,13 +109,18 @@ if (ABIName == "ilp32e") Builder.defineMacro("__riscv_abi_rve"); + Builder.defineMacro("__riscv_arch_test"); + Builder.defineMacro("__riscv_i", "2000000"); + if (HasM) { + Builder.defineMacro("__riscv_m", "2000000"); Builder.defineMacro("__riscv_mul"); Builder.defineMacro("__riscv_div"); Builder.defineMacro("__riscv_muldiv"); } if (HasA) { + Builder.defineMacro("__riscv_a", "2000000"); Builder.defineMacro("__riscv_atomic"); Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1"); Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2"); @@ -125,22 +130,68 @@ } if (HasF || HasD) { + Builder.defineMacro("__riscv_f", "2000000"); Builder.defineMacro("__riscv_flen", HasD ? "64" : "32"); Builder.defineMacro("__riscv_fdiv"); Builder.defineMacro("__riscv_fsqrt"); } - if (HasC) + if (HasD) + Builder.defineMacro("__riscv_d", "2000000"); + + if (HasC) { + Builder.defineMacro("__riscv_c", "2000000"); Builder.defineMacro("__riscv_compressed"); + } - if (HasB) + if (HasB) { + Builder.defineMacro("__riscv_b", "92000"); Builder.defineMacro("__riscv_bitmanip"); + } - if (HasV) + if (HasV) { + Builder.defineMacro("__riscv_v", "9000"); Builder.defineMacro("__riscv_vector"); + } + + if (HasZbb) + Builder.defineMacro("__riscv_zbb", "92000"); + + if (HasZbc) + Builder.defineMacro("__riscv_zbc", "92000"); + + if (HasZbe) + Builder.defineMacro("__riscv_zbe", "92000"); + + if (HasZbf) + Builder.defineMacro("__riscv_zbf", "92000"); + + if (HasZbm) + Builder.defineMacro("__riscv_zbm", "92000"); + + if (HasZbp) + Builder.defineMacro("__riscv_zbp", "92000"); + + if (HasZbproposedc) + Builder.defineMacro("__riscv_zbproposedc", "92000"); + + if (HasZbr) + Builder.defineMacro("__riscv_zbr", "92000"); + + if (HasZbs) + Builder.defineMacro("__riscv_zbs", "92000"); + + if (HasZbt) + Builder.defineMacro("__riscv_zbt", "92000"); if (HasZfh) - Builder.defineMacro("__riscv_zfh"); + Builder.defineMacro("__riscv_zfh", "1000"); + + if (HasZvamo) + Builder.defineMacro("__riscv_zvamo", "9000"); + + if (HasZvlsseg) + Builder.defineMacro("__riscv_zvlsseg", "9000"); } /// Return true if has this feature, need to sync with handleTargetFeatures. @@ -157,7 +208,19 @@ .Case("c", HasC) .Case("experimental-b", HasB) .Case("experimental-v", HasV) + .Case("experimental-zbb", HasZbb) + .Case("experimental-zbc", HasZbc) + .Case("experimental-zbe", HasZbe) + .Case("experimental-zbf", HasZbf) + .Case("experimental-zbm", HasZbm) + .Case("experimental-zbp", HasZbp) + .Case("experimental-zbproposedc", HasZbproposedc) + .Case("experimental-zbr", HasZbr) + .Case("experimental-zbs", HasZbs) + .Case("experimental-zbt", HasZbt) .Case("experimental-zfh", HasZfh) + .Case("experimental-zvamo", HasZvamo) + .Case("experimental-zvlsseg", HasZvlsseg) .Default(false); } @@ -179,8 +242,32 @@ HasB = true; else if (Feature == "+experimental-v") HasV = true; + else if (Feature == "+experimental-zbb") + HasZbb = true; + else if (Feature == "+experimental-zbc") + HasZbc = true; + else if (Feature == "+experimental-zbe") + HasZbe = true; + else if (Feature == "+experimental-zbf") + HasZbf = true; + else if (Feature == "+experimental-zbm") + HasZbm = true; + else if (Feature == "+experimental-zbp") + HasZbp = true; + else if (Feature == "+experimental-zbproposedc") + HasZbproposedc = true; + else if (Feature == "+experimental-zbr") + HasZbr = true; + else if (Feature == "+experimental-zbs") + HasZbs = true; + else if (Feature == "+experimental-zbt") + HasZbt = true; else if (Feature == "+experimental-zfh") HasZfh = true; + else if (Feature == "+experimental-zvamo") + HasZvamo = true; + else if (Feature == "+experimental-zvlsseg") + HasZvlsseg = true; } return true; diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp --- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp +++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp @@ -412,9 +412,21 @@ break; case 'b': Features.push_back("+experimental-b"); + Features.push_back("+experimental-zbb"); + Features.push_back("+experimental-zbb"); + Features.push_back("+experimental-zbc"); + Features.push_back("+experimental-zbe"); + Features.push_back("+experimental-zbf"); + Features.push_back("+experimental-zbm"); + Features.push_back("+experimental-zbp"); + Features.push_back("+experimental-zbr"); + Features.push_back("+experimental-zbs"); + Features.push_back("+experimental-zbt"); break; case 'v': Features.push_back("+experimental-v"); + Features.push_back("+experimental-zvamo"); + Features.push_back("+experimental-zvlsseg"); break; } diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c --- a/clang/test/Preprocessor/riscv-target-features.c +++ b/clang/test/Preprocessor/riscv-target-features.c @@ -12,12 +12,26 @@ // CHECK-NOT: __riscv_fdiv // CHECK-NOT: __riscv_fsqrt // CHECK-NOT: __riscv_atomic +// CHECK-NOT: __riscv_zbb +// CHECK-NOT: __riscv_zbc +// CHECK-NOT: __riscv_zbe +// CHECK-NOT: __riscv_zbf +// CHECK-NOT: __riscv_zbm +// CHECK-NOT: __riscv_zbp +// CHECK-NOT: __riscv_zbproposedc +// CHECK-NOT: __riscv_zbr +// CHECK-NOT: __riscv_zbs +// CHECK-NOT: __riscv_zbt +// CHECK-NOT: __riscv_zfh +// CHECK-NOT: __riscv_zvamo +// CHECK-NOT: __riscv_zvlsseg // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s // RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64im -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s // CHECK-M-EXT: __riscv_div 1 +// CHECK-M-EXT: __riscv_m 2000000 // CHECK-M-EXT: __riscv_mul 1 // CHECK-M-EXT: __riscv_muldiv 1 @@ -25,12 +39,14 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-A-EXT %s // RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ia -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-A-EXT %s +// CHECK-A-EXT: __riscv_a 2000000 // CHECK-A-EXT: __riscv_atomic 1 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32if -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-F-EXT %s // RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64if -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-F-EXT %s +// CHECK-F-EXT: __riscv_f 2000000 // CHECK-F-EXT: __riscv_fdiv 1 // CHECK-F-EXT: __riscv_flen 32 // CHECK-F-EXT: __riscv_fsqrt 1 @@ -39,6 +55,8 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-D-EXT %s // RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ifd -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-D-EXT %s +// CHECK-D-EXT: __riscv_d 2000000 +// CHECK-D-EXT: __riscv_f 2000000 // CHECK-D-EXT: __riscv_fdiv 1 // CHECK-D-EXT: __riscv_flen 64 // CHECK-D-EXT: __riscv_fsqrt 1 @@ -47,13 +65,24 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s // RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ic -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s +// CHECK-C-EXT: __riscv_c 2000000 // CHECK-C-EXT: __riscv_compressed 1 // RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32ib0p92 -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s // RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64ib0p92 -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s +// CHECK-B-EXT: __riscv_b 92000 // CHECK-B-EXT: __riscv_bitmanip 1 +// CHECK-B-EXT: __riscv_zbb 92000 +// CHECK-B-EXT: __riscv_zbc 92000 +// CHECK-B-EXT: __riscv_zbe 92000 +// CHECK-B-EXT: __riscv_zbf 92000 +// CHECK-B-EXT: __riscv_zbm 92000 +// CHECK-B-EXT: __riscv_zbp 92000 +// CHECK-B-EXT: __riscv_zbr 92000 +// CHECK-B-EXT: __riscv_zbs 92000 +// CHECK-B-EXT: __riscv_zbt 92000 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ifd -mabi=ilp32 -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-SOFT %s @@ -85,10 +114,85 @@ // RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions \ // RUN: -march=rv64iv0p9 -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-V-EXT %s +// CHECK-V-EXT: __riscv_v 9000 // CHECK-V-EXT: __riscv_vector 1 -// +// CHECK-V-EXT: __riscv_zvamo 9000 +// CHECK-V-EXT: __riscv_zvlsseg 9000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izbb0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBB-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64izbb0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBB-EXT %s +// CHECK-ZBB-EXT: __riscv_zbb 92000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izbc0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBC-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64izbc0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBC-EXT %s +// CHECK-ZBC-EXT: __riscv_zbc 92000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izbe0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBE-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64izbe0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBE-EXT %s +// CHECK-ZBE-EXT: __riscv_zbe 92000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izbf0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBF-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64izbf0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBF-EXT %s +// CHECK-ZBF-EXT: __riscv_zbf 92000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izbm0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBM-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64izbm0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBM-EXT %s +// CHECK-ZBM-EXT: __riscv_zbm 92000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izbp0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBP-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64izbp0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBP-EXT %s +// CHECK-ZBP-EXT: __riscv_zbp 92000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izbproposedc0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBPROPOSEDC-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv32izbproposedc0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBPROPOSEDC-EXT %s +// CHECK-ZBPROPOSEDC-EXT: __riscv_zbproposedc 92000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izbr0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBR-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64izbr0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBR-EXT %s +// CHECK-ZBR-EXT: __riscv_zbr 92000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izbs0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBS-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64izbs0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBS-EXT %s +// CHECK-ZBS-EXT: __riscv_zbs 92000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izbt0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBT-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64izbt0p92 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZBT-EXT %s +// CHECK-ZBT-EXT: __riscv_zbt 92000 + // RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izfh0p1 -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-ZFH-EXT %s // RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64izfh0p1 -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-ZFH-EXT %s -// CHECK-ZFH-EXT: __riscv_zfh 1 +// CHECK-ZFH-EXT: __riscv_zfh 1000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izvamo0p9 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZVAMO-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv32izvamo0p9 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZVAMO-EXT %s +// CHECK-ZVAMO-EXT: __riscv_zvamo 9000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izvlsseg0p9 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZVLSSEG-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv32izvlsseg0p9 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZVLSSEG-EXT %s +// CHECK-ZVLSSEG-EXT: __riscv_zvlsseg 9000