Skip to content

Commit 1296d20

Browse files
authored
[Driver] Support -mcmodel= for LoongArch (#72514)
7e42545 rejects unsupported mcmodel options, but normal/medium/extreme should be supported models for LoongArch according to [gcc document](https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html). The mappings among `gcc`, `clang driver`, `clang cc1` and `LLVM (i.e. llc --code-model=)` are: | gcc | clang driver | clang cc1 | LLVM | | ------------- | ------------------ | ----------------- | -------------- | | normal | normal | small | small | | medium | medium | medium | medium | | extreme | extreme | large | large | Link: https://reviews.llvm.org/D150522
1 parent ce570d1 commit 1296d20

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5756,6 +5756,18 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
57565756
if (CM == "large" && RelocationModel != llvm::Reloc::Static)
57575757
D.Diag(diag::err_drv_argument_only_allowed_with)
57585758
<< A->getAsString(Args) << "-fno-pic";
5759+
} else if (Triple.isLoongArch()) {
5760+
if (CM == "extreme" &&
5761+
Args.hasFlagNoClaim(options::OPT_fplt, options::OPT_fno_plt, false))
5762+
D.Diag(diag::err_drv_argument_not_allowed_with)
5763+
<< A->getAsString(Args) << "-fplt";
5764+
Ok = CM == "normal" || CM == "medium" || CM == "extreme";
5765+
// Convert to LLVM recognizable names.
5766+
if (Ok)
5767+
CM = llvm::StringSwitch<StringRef>(CM)
5768+
.Case("normal", "small")
5769+
.Case("extreme", "large")
5770+
.Default(CM);
57595771
} else if (Triple.isPPC64() || Triple.isOSAIX()) {
57605772
Ok = CM == "small" || CM == "medium" || CM == "large";
57615773
} else if (Triple.isRISCV()) {

clang/test/Driver/mcmodel.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
// RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s
1616
// RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s
1717
// RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-AARCH64_32 %s
18+
// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | FileCheck --check-prefix=SMALL %s
19+
// RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s
20+
// RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | FileCheck --check-prefix=LARGE %s
21+
// RUN: not %clang --target=loongarch64 -### -S -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=ERR-TINY %s
22+
// RUN: not %clang --target=loongarch64 -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-SMALL %s
23+
// RUN: not %clang --target=loongarch64 -### -S -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s
24+
// RUN: not %clang --target=loongarch64 -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=ERR-LARGE %s
25+
// RUN: not %clang --target=loongarch64 -### -S -mcmodel=extreme -fplt %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-PLT-EXTREME %s
1826

1927
// TINY: "-mcmodel=tiny"
2028
// SMALL: "-mcmodel=small"
@@ -25,9 +33,14 @@
2533

2634
// INVALID: error: unsupported argument 'lager' to option '-mcmodel=' for target '{{.*}}'
2735

36+
// ERR-TINY: error: unsupported argument 'tiny' to option '-mcmodel=' for target '{{.*}}'
37+
// ERR-SMALL: error: unsupported argument 'small' to option '-mcmodel=' for target '{{.*}}'
2838
// ERR-MEDIUM: error: unsupported argument 'medium' to option '-mcmodel=' for target '{{.*}}'
2939
// ERR-KERNEL: error: unsupported argument 'kernel' to option '-mcmodel=' for target '{{.*}}'
3040
// ERR-LARGE: error: unsupported argument 'large' to option '-mcmodel=' for target '{{.*}}'
3141

3242
// AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed with '-fno-pic'
3343
// ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' for target 'aarch64_32-unknown-linux'
44+
45+
// ERR-LOONGARCH64-PLT-LARGE: error: invalid argument '-mcmodel=large' not allowed with '-fplt'
46+
// ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not allowed with '-fplt'

0 commit comments

Comments
 (0)