diff options
author | Kito Cheng <kito.cheng@gmail.com> | 2019-09-17 08:09:56 +0000 |
---|---|---|
committer | Kito Cheng <kito.cheng@gmail.com> | 2019-09-17 08:09:56 +0000 |
commit | 645593844164187a2de37b40e62cd790cfb48a03 (patch) | |
tree | 0d790bd63cedfb8052a44b7507d1c67840f4326a | |
parent | 3ee98a1455cbd1ba6fcb3f74ddf137c503734a97 (diff) | |
download | bcm5719-llvm-645593844164187a2de37b40e62cd790cfb48a03.tar.gz bcm5719-llvm-645593844164187a2de37b40e62cd790cfb48a03.zip |
[RISCV] Define __riscv_cmodel_medlow and __riscv_cmodel_medany correctly
RISC-V LLVM was only implement small/medlow code model, so it defined
__riscv_cmodel_medlow directly without check.
Now, we have medium/medany code model in RISC-V back-end, it should
define according the actually code model.
Reviewed By: lewis-revill
Differential Revision: https://reviews.llvm.org/D67065
llvm-svn: 372078
-rw-r--r-- | clang/lib/Basic/Targets/RISCV.cpp | 10 | ||||
-rw-r--r-- | clang/test/Preprocessor/riscv-cmodel.c | 20 |
2 files changed, 28 insertions, 2 deletions
diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp index 0a8df86fc88..ab8272c034f 100644 --- a/clang/lib/Basic/Targets/RISCV.cpp +++ b/clang/lib/Basic/Targets/RISCV.cpp @@ -88,8 +88,14 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__riscv"); bool Is64Bit = getTriple().getArch() == llvm::Triple::riscv64; Builder.defineMacro("__riscv_xlen", Is64Bit ? "64" : "32"); - // TODO: modify when more code models are supported. - Builder.defineMacro("__riscv_cmodel_medlow"); + StringRef CodeModel = getTargetOpts().CodeModel; + if (CodeModel == "default") + CodeModel = "small"; + + if (CodeModel == "small") + Builder.defineMacro("__riscv_cmodel_medlow"); + else if (CodeModel == "medium") + Builder.defineMacro("__riscv_cmodel_medany"); StringRef ABIName = getABI(); if (ABIName == "ilp32f" || ABIName == "lp64f") diff --git a/clang/test/Preprocessor/riscv-cmodel.c b/clang/test/Preprocessor/riscv-cmodel.c new file mode 100644 index 00000000000..b28c27c9cc0 --- /dev/null +++ b/clang/test/Preprocessor/riscv-cmodel.c @@ -0,0 +1,20 @@ +// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-MEDLOW %s +// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64i -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-MEDLOW %s + +// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \ +// RUN: -mcmodel=small -o - | FileCheck --check-prefix=CHECK-MEDLOW %s +// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64i -x c -E -dM %s \ +// RUN: -mcmodel=small -o - | FileCheck --check-prefix=CHECK-MEDLOW %s + +// CHECK-MEDLOW: #define __riscv_cmodel_medlow 1 +// CHECK-MEDLOW-NOT: __riscv_cmodel_medany + +// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \ +// RUN: -mcmodel=medium -o - | FileCheck --check-prefix=CHECK-MEDANY %s +// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64i -x c -E -dM %s \ +// RUN: -mcmodel=medium -o - | FileCheck --check-prefix=CHECK-MEDANY %s + +// CHECK-MEDANY: #define __riscv_cmodel_medany 1 +// CHECK-MEDANY-NOT: __riscv_cmodel_medlow |