Skip to content
Permalink
Browse files

[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
  • Loading branch information...
kito-cheng committed Sep 17, 2019
1 parent 3ee98a1 commit 645593844164187a2de37b40e62cd790cfb48a03
Showing with 28 additions and 2 deletions.
  1. +8 −2 clang/lib/Basic/Targets/RISCV.cpp
  2. +20 −0 clang/test/Preprocessor/riscv-cmodel.c
@@ -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")
@@ -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

0 comments on commit 6455938

Please sign in to comment.
You can’t perform that action at this time.