Skip to content

[AMDGPU] Add code model (#70760) test for amdgpu target. #71019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5747,6 +5747,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
StringRef CM = A->getValue();
bool Ok = false;
bool Skip = false;
if (Triple.isOSAIX() && CM == "medium")
CM = "large";
if (Triple.isAArch64(64)) {
Expand Down Expand Up @@ -5777,12 +5778,23 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
} else if (Triple.getArch() == llvm::Triple::x86_64) {
Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"},
CM);
} else if (Triple.isNVPTX() || Triple.isAMDGPU()) {
// NVPTX/AMDGPU does not care about the code model and will accept
} else if (Triple.isNVPTX()) {
// NVPTX does not care about the code model and will accept
// whatever works for the host.
Ok = true;
} else if (Triple.isAMDGPU()) {
// AMDGPU does not care about the code model.
Ok = true;
// AMDGPU target ignores CM tiny and kernel.
if (CM == "tiny" || CM == "kernel") {
Skip = true;
D.Diag(diag::warn_ignored_clang_option)
<< A->getSpelling() << CM << TripleStr;
}
Comment on lines +5785 to +5793
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is doing more than adding the test?

}
if (Ok) {
if (Skip) {
// CM option is not propogated further.
} else if (Ok) {
CmdArgs.push_back(Args.MakeArgString("-mcmodel=" + CM));
} else {
D.Diag(diag::err_drv_unsupported_option_argument_for_target)
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Driver/mcmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
// 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 --offload-arch=gfx906 -nogpulib -### -c -x hip -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-TINY-WARNING %s
// RUN: %clang --offload-arch=gfx906 -nogpulib -### -c -x hip -mcmodel=small %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-SMALL %s
// RUN: %clang --offload-arch=gfx906 -nogpulib -### -S -x hip -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-KERNEL-WARNING %s
// RUN: %clang --offload-arch=gfx906 -nogpulib -### -c -x hip -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-MEDIUM %s
// RUN: %clang --offload-arch=gfx906 -nogpulib -### -S -x hip -mcmodel=large %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-LARGE %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=extreme %s 2>&1 | FileCheck --check-prefix=LARGE %s
Expand All @@ -41,6 +46,11 @@

// 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'
// AMDGPU-MCMODEL-TINY-WARNING: warning: the flag '-mcmodel=' has been deprecated and will be ignored
// AMDGPU-MCMODEL-SMALL: "-mcmodel=small"
// AMDGPU-MCMODEL-KERNEL-WARNING: warning: the flag '-mcmodel=' has been deprecated and will be ignored
// AMDGPU-MCMODEL-MEDIUM: "-mcmodel=medium"
// AMDGPU-MCMODEL-LARGE: "-mcmodel=large"

// 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'