[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
MaskRay wrote: LGTM https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
https://github.com/SixWeining closed https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
https://github.com/wangleiat approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
zjiaz wrote: FWIW, `mcmodel=medium` option is used in [chromium's build config file](https://source.chromium.org/chromium/chromium/src/+/main:build/config/compiler/BUILD.gn;l=1451?q=mcmodel=chromium%2Fchromium%2Fsrc:build%2F), and now chromium's llvm toolchain has been affected by this issue: > clang++: error: unsupported argument 'medium' to option '-mcmodel=' for > target 'loongarch64-unknown-linux-gnu' https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
https://github.com/SixWeining edited https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
https://github.com/SixWeining updated https://github.com/llvm/llvm-project/pull/72514 >From 8dd5bebcd4681e5e7849743aba0ce90c2959ee23 Mon Sep 17 00:00:00 2001 From: Weining Lu Date: Thu, 16 Nov 2023 21:57:03 +0800 Subject: [PATCH 1/2] [Driver] Support -mcmodel= for LoongArch 7e42545 rejects unsupported mcmodel options, but small/medium/large should be supported models for LoongArch. In addition, to be compatible with gcc, mapping some of their values to clang's. The mapping is: gcc[1] vs clang[2] "normal""small" "medium""medium" "extreme" "large" And AFAIK, gcc side doesn't plan to implement the "large" code model. [1]: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html [2]: https://reviews.llvm.org/D150522 --- clang/lib/Driver/ToolChains/Clang.cpp | 10 ++ clang/test/Driver/mcmodel.c | 13 + 2 files changed, 23 insertions(+) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index b462f5a44057d94..3a7e56f37259cb8 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation , const JobAction , if (CM == "large" && RelocationModel != llvm::Reloc::Static) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-fno-pic"; +} else if (Triple.isLoongArch()) { + CM = llvm::StringSwitch(CM) + .Case("normal", "small") + .Case("extreme", "large") + .Default(CM); + if (CM == "large" && + Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false)) +D.Diag(diag::err_drv_argument_not_allowed_with) +<< A->getAsString(Args) << "-fplt"; + Ok = CM == "small" || CM == "medium" || CM == "large"; } else if (Triple.isPPC64() || Triple.isOSAIX()) { Ok = CM == "small" || CM == "medium" || CM == "large"; } else if (Triple.isRISCV()) { diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c index d8a41b0f5abd9aa..72be740216a81b3 100644 --- a/clang/test/Driver/mcmodel.c +++ b/clang/test/Driver/mcmodel.c @@ -15,6 +15,15 @@ // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-AARCH64_32 %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=SMALL %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | FileCheck --check-prefix=SMALL %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | FileCheck --check-prefix=LARGE %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=ERR-TINY %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=large -fplt %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-PLT-LARGE %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=extreme -fplt %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-PLT-EXTREME %s // TINY: "-mcmodel=tiny" // SMALL: "-mcmodel=small" @@ -25,9 +34,13 @@ // INVALID: error: unsupported argument 'lager' to option '-mcmodel=' for target '{{.*}}' +// ERR-TINY: error: unsupported argument 'tiny' to option '-mcmodel=' for target '{{.*}}' // ERR-MEDIUM: error: unsupported argument 'medium' to option '-mcmodel=' for target '{{.*}}' // ERR-KERNEL: error: unsupported argument 'kernel' to option '-mcmodel=' for target '{{.*}}' // ERR-LARGE: error: unsupported argument 'large' to option '-mcmodel=' for target '{{.*}}' // AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed with '-fno-pic' // ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' for target 'aarch64_32-unknown-linux' + +// ERR-LOONGARCH64-PLT-LARGE: error: invalid argument '-mcmodel=large' not allowed with '-fplt' +// ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not allowed with '-fplt' >From 240149f7196c88d418d9c39c60b478b5c3aeb11c Mon Sep 17 00:00:00 2001 From: Weining Lu Date: Fri, 24 Nov 2023 13:56:28 +0800 Subject: [PATCH 2/2] Reject small and large. Only accept normal, medium and extreme --- clang/lib/Driver/ToolChains/Clang.cpp | 16 +--- clang/test/Driver/mcmodel.c | 8 2 files changed, 13 insertions(+), 11 deletions(-) diff --git
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
SixWeining wrote: > [gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html](https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html) > says > > ‘large (Not implemented yet)’ ‘extreme’ This mode does not limit the size of > the code segment and data segment. The -mcmodel=extreme option is > incompatible with -fplt, and it requires -mexplicit-relocs=always. > > Is there a psABI defining 'extreme' or 'large'? Currently there is no definition in psABI except in gcc doc: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html. Maybe we can define them in next psABI version. https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
@@ -15,6 +15,15 @@ // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-AARCH64_32 %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=SMALL %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | FileCheck --check-prefix=SMALL %s MaskRay wrote: If `-mcmodel=normal` is canonical, we probably should not add Clang-specific alias `small`. Reject `normal`. https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
MaskRay wrote: [gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html](https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html) says ‘large (Not implemented yet)’ ‘extreme’ This mode does not limit the size of the code segment and data segment. The -mcmodel=extreme option is incompatible with -fplt, and it requires -mexplicit-relocs=always. Is there a psABI defining 'extreme' or 'large'? https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
@@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation , const JobAction , if (CM == "large" && RelocationModel != llvm::Reloc::Static) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-fno-pic"; +} else if (Triple.isLoongArch()) { + CM = llvm::StringSwitch(CM) + .Case("normal", "small") + .Case("extreme", "large") + .Default(CM); + if (CM == "large" && + Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false)) MaskRay wrote: `hasFlagNoClaim` is slightly better https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
@@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation , const JobAction , if (CM == "large" && RelocationModel != llvm::Reloc::Static) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-fno-pic"; +} else if (Triple.isLoongArch()) { + CM = llvm::StringSwitch(CM) + .Case("normal", "small") + .Case("extreme", "large") + .Default(CM); + if (CM == "large" && + Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false)) MaskRay wrote: nvm. this is fine https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
@@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation , const JobAction , if (CM == "large" && RelocationModel != llvm::Reloc::Static) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-fno-pic"; +} else if (Triple.isLoongArch()) { + CM = llvm::StringSwitch(CM) + .Case("normal", "small") + .Case("extreme", "large") + .Default(CM); + if (CM == "large" && + Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false)) MaskRay wrote: I consider -fno-pic/-fpic a more fundamental difference than -mcmodel=, so I place the aarch64 compatibility check in this large `if` condition. -mcmodel= is a more fundamental difference than -fplt, so the -fplt compatibility check should probably belong to -fplt. You can move ``` if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt, false)) { ``` below CodeModel check and add the diagnostic there. https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
SixWeining wrote: > > And AFAIK, gcc side doesn't plan to implement the "large" code model. > > Why did we distinguish "large" and "extreme" in the first place? If we don't > need a different "large" code model then I guess we should make it an alias > of "extreme" for GCC too. @ChenghuaXu @chenglulu326 What do you think? https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
xry111 wrote: > And AFAIK, gcc side doesn't plan to implement the "large" code model. Why did we distinguish "large" and "extreme" in the first place? If we don't need a different "large" code model then I guess we should make it an alias of "extreme" for GCC too. https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
SixWeining wrote: cc @xen0n @xry111 https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Lu Weining (SixWeining) Changes 7e42545 rejects unsupported mcmodel options, but small/medium/large should be supported models for LoongArch. In addition, to be compatible with gcc, mapping some of their values to clang's. The mapping is: ``` gcc vs clang "normal""small" "medium""medium" "extreme" "large" ``` And AFAIK, gcc side doesn't plan to implement the "large" code model. Link: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html Link: https://reviews.llvm.org/D150522 --- Full diff: https://github.com/llvm/llvm-project/pull/72514.diff 2 Files Affected: - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+10) - (modified) clang/test/Driver/mcmodel.c (+13) ``diff diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index b462f5a44057d94..3a7e56f37259cb8 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation , const JobAction , if (CM == "large" && RelocationModel != llvm::Reloc::Static) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-fno-pic"; +} else if (Triple.isLoongArch()) { + CM = llvm::StringSwitch(CM) + .Case("normal", "small") + .Case("extreme", "large") + .Default(CM); + if (CM == "large" && + Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false)) +D.Diag(diag::err_drv_argument_not_allowed_with) +<< A->getAsString(Args) << "-fplt"; + Ok = CM == "small" || CM == "medium" || CM == "large"; } else if (Triple.isPPC64() || Triple.isOSAIX()) { Ok = CM == "small" || CM == "medium" || CM == "large"; } else if (Triple.isRISCV()) { diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c index d8a41b0f5abd9aa..72be740216a81b3 100644 --- a/clang/test/Driver/mcmodel.c +++ b/clang/test/Driver/mcmodel.c @@ -15,6 +15,15 @@ // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-AARCH64_32 %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=SMALL %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | FileCheck --check-prefix=SMALL %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | FileCheck --check-prefix=LARGE %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=ERR-TINY %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=large -fplt %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-PLT-LARGE %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=extreme -fplt %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-PLT-EXTREME %s // TINY: "-mcmodel=tiny" // SMALL: "-mcmodel=small" @@ -25,9 +34,13 @@ // INVALID: error: unsupported argument 'lager' to option '-mcmodel=' for target '{{.*}}' +// ERR-TINY: error: unsupported argument 'tiny' to option '-mcmodel=' for target '{{.*}}' // ERR-MEDIUM: error: unsupported argument 'medium' to option '-mcmodel=' for target '{{.*}}' // ERR-KERNEL: error: unsupported argument 'kernel' to option '-mcmodel=' for target '{{.*}}' // ERR-LARGE: error: unsupported argument 'large' to option '-mcmodel=' for target '{{.*}}' // AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed with '-fno-pic' // ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' for target 'aarch64_32-unknown-linux' + +// ERR-LOONGARCH64-PLT-LARGE: error: invalid argument '-mcmodel=large' not allowed with '-fplt' +// ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not allowed with '-fplt' `` https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Lu Weining (SixWeining) Changes 7e42545 rejects unsupported mcmodel options, but small/medium/large should be supported models for LoongArch. In addition, to be compatible with gcc, mapping some of their values to clang's. The mapping is: ``` gcc vs clang "normal""small" "medium""medium" "extreme" "large" ``` And AFAIK, gcc side doesn't plan to implement the "large" code model. Link: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html Link: https://reviews.llvm.org/D150522 --- Full diff: https://github.com/llvm/llvm-project/pull/72514.diff 2 Files Affected: - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+10) - (modified) clang/test/Driver/mcmodel.c (+13) ``diff diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index b462f5a44057d94..3a7e56f37259cb8 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation , const JobAction , if (CM == "large" && RelocationModel != llvm::Reloc::Static) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-fno-pic"; +} else if (Triple.isLoongArch()) { + CM = llvm::StringSwitch(CM) + .Case("normal", "small") + .Case("extreme", "large") + .Default(CM); + if (CM == "large" && + Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false)) +D.Diag(diag::err_drv_argument_not_allowed_with) +<< A->getAsString(Args) << "-fplt"; + Ok = CM == "small" || CM == "medium" || CM == "large"; } else if (Triple.isPPC64() || Triple.isOSAIX()) { Ok = CM == "small" || CM == "medium" || CM == "large"; } else if (Triple.isRISCV()) { diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c index d8a41b0f5abd9aa..72be740216a81b3 100644 --- a/clang/test/Driver/mcmodel.c +++ b/clang/test/Driver/mcmodel.c @@ -15,6 +15,15 @@ // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-AARCH64_32 %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=SMALL %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | FileCheck --check-prefix=SMALL %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | FileCheck --check-prefix=LARGE %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=ERR-TINY %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=large -fplt %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-PLT-LARGE %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=extreme -fplt %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-PLT-EXTREME %s // TINY: "-mcmodel=tiny" // SMALL: "-mcmodel=small" @@ -25,9 +34,13 @@ // INVALID: error: unsupported argument 'lager' to option '-mcmodel=' for target '{{.*}}' +// ERR-TINY: error: unsupported argument 'tiny' to option '-mcmodel=' for target '{{.*}}' // ERR-MEDIUM: error: unsupported argument 'medium' to option '-mcmodel=' for target '{{.*}}' // ERR-KERNEL: error: unsupported argument 'kernel' to option '-mcmodel=' for target '{{.*}}' // ERR-LARGE: error: unsupported argument 'large' to option '-mcmodel=' for target '{{.*}}' // AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed with '-fno-pic' // ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' for target 'aarch64_32-unknown-linux' + +// ERR-LOONGARCH64-PLT-LARGE: error: invalid argument '-mcmodel=large' not allowed with '-fplt' +// ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not allowed with '-fplt' `` https://github.com/llvm/llvm-project/pull/72514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)
https://github.com/SixWeining created https://github.com/llvm/llvm-project/pull/72514 7e42545 rejects unsupported mcmodel options, but small/medium/large should be supported models for LoongArch. In addition, to be compatible with gcc, mapping some of their values to clang's. The mapping is: ``` gcc vs clang "normal""small" "medium""medium" "extreme" "large" ``` And AFAIK, gcc side doesn't plan to implement the "large" code model. Link: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html Link: https://reviews.llvm.org/D150522 >From 8dd5bebcd4681e5e7849743aba0ce90c2959ee23 Mon Sep 17 00:00:00 2001 From: Weining Lu Date: Thu, 16 Nov 2023 21:57:03 +0800 Subject: [PATCH] [Driver] Support -mcmodel= for LoongArch 7e42545 rejects unsupported mcmodel options, but small/medium/large should be supported models for LoongArch. In addition, to be compatible with gcc, mapping some of their values to clang's. The mapping is: gcc[1] vs clang[2] "normal""small" "medium""medium" "extreme" "large" And AFAIK, gcc side doesn't plan to implement the "large" code model. [1]: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html [2]: https://reviews.llvm.org/D150522 --- clang/lib/Driver/ToolChains/Clang.cpp | 10 ++ clang/test/Driver/mcmodel.c | 13 + 2 files changed, 23 insertions(+) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index b462f5a44057d94..3a7e56f37259cb8 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation , const JobAction , if (CM == "large" && RelocationModel != llvm::Reloc::Static) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-fno-pic"; +} else if (Triple.isLoongArch()) { + CM = llvm::StringSwitch(CM) + .Case("normal", "small") + .Case("extreme", "large") + .Default(CM); + if (CM == "large" && + Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false)) +D.Diag(diag::err_drv_argument_not_allowed_with) +<< A->getAsString(Args) << "-fplt"; + Ok = CM == "small" || CM == "medium" || CM == "large"; } else if (Triple.isPPC64() || Triple.isOSAIX()) { Ok = CM == "small" || CM == "medium" || CM == "large"; } else if (Triple.isRISCV()) { diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c index d8a41b0f5abd9aa..72be740216a81b3 100644 --- a/clang/test/Driver/mcmodel.c +++ b/clang/test/Driver/mcmodel.c @@ -15,6 +15,15 @@ // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=ERR-AARCH64_32 %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=SMALL %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | FileCheck --check-prefix=SMALL %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s +// RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | FileCheck --check-prefix=LARGE %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=ERR-TINY %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=ERR-KERNEL %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=large -fplt %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-PLT-LARGE %s +// RUN: not %clang --target=loongarch64 -### -S -mcmodel=extreme -fplt %s 2>&1 | FileCheck --check-prefix=ERR-LOONGARCH64-PLT-EXTREME %s // TINY: "-mcmodel=tiny" // SMALL: "-mcmodel=small" @@ -25,9 +34,13 @@ // INVALID: error: unsupported argument 'lager' to option '-mcmodel=' for target '{{.*}}' +// ERR-TINY: error: unsupported argument 'tiny' to option '-mcmodel=' for target '{{.*}}' // ERR-MEDIUM: error: unsupported argument 'medium' to option '-mcmodel=' for target '{{.*}}' // ERR-KERNEL: error: unsupported argument 'kernel' to option '-mcmodel=' for target '{{.*}}' // ERR-LARGE: error: unsupported argument 'large' to option '-mcmodel=' for target '{{.*}}' // AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed with '-fno-pic' // ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' for target 'aarch64_32-unknown-linux' + +// ERR-LOONGARCH64-PLT-LARGE: error: invalid argument '-mcmodel=large' not allowed with '-fplt' +//