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,32 @@ } 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 (HasZfh) - Builder.defineMacro("__riscv_zfh"); + Builder.defineMacro("__riscv_zfh", "1000"); } /// Return true if has this feature, need to sync with handleTargetFeatures. 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 @@ -18,6 +18,7 @@ // 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 +26,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 +42,7 @@ // 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_fdiv 1 // CHECK-D-EXT: __riscv_flen 64 // CHECK-D-EXT: __riscv_fsqrt 1 @@ -47,12 +51,14 @@ // 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 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ifd -mabi=ilp32 -x c -E -dM %s \ @@ -85,10 +91,11 @@ // 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 // // 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