[clang] [llvm] [AMDGPU] Add code model (#70760) test for amdgpu target. (PR #71019)
Pravin Jagtap via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 28 21:56:14 PST 2023
https://github.com/pravinjagtap updated https://github.com/llvm/llvm-project/pull/71019
>From 2477ae87e7bb82b4551e42b8255dfe93dadff453 Mon Sep 17 00:00:00 2001
From: Pravin Jagtap <Pravin.Jagtap at amd.com>
Date: Thu, 2 Nov 2023 01:05:35 -0400
Subject: [PATCH 1/6] [AMDGPU] Add code model (#70760) test for amdgpu target.
---
llvm/test/CodeGen/AMDGPU/codemodel.ll | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644 llvm/test/CodeGen/AMDGPU/codemodel.ll
diff --git a/llvm/test/CodeGen/AMDGPU/codemodel.ll b/llvm/test/CodeGen/AMDGPU/codemodel.ll
new file mode 100644
index 000000000000000..8b60257b2076aed
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/codemodel.ll
@@ -0,0 +1,9 @@
+; RUN: not llc -verify-machineinstrs -o - -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 -code-model=tiny < %s 2>&1 | FileCheck %s --check-prefix=TINY
+; RUN: not llc -verify-machineinstrs -o - -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 -code-model=kernel < %s 2>&1 | FileCheck %s --check-prefix=KERNEL
+
+; TINY: Target does not support the tiny CodeModel
+; KERNEL: Target does not support the kernel CodeModel
+
+define void @foo() {
+ ret void
+}
>From 4b3cf8a9f312caffd4492747026bc001086ef197 Mon Sep 17 00:00:00 2001
From: Pravin Jagtap <Pravin.Jagtap at amd.com>
Date: Thu, 2 Nov 2023 05:51:50 -0400
Subject: [PATCH 2/6] Added clang driver test for code model.
---
clang/test/Driver/mcmodel.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c
index d8a41b0f5abd9aa..3b3ff08ba9ad275 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -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 --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-TINY %s
+// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=small %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-SMALL %s
+// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -S -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-KERNEL %s
+// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-MEDIUM %s
+// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-LARGE %s
// TINY: "-mcmodel=tiny"
// SMALL: "-mcmodel=small"
@@ -31,3 +36,8 @@
// 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: "-mcmodel=tiny"
+// AMDGPU-MCMODEL-SMALL: "-mcmodel=small"
+// AMDGPU-MCMODEL-KERNEL: "-mcmodel=kernel"
+// AMDGPU-MCMODEL-MEDIUM: "-mcmodel=medium"
+// AMDGPU-MCMODEL-LARGE: "-mcmodel=large"
>From 7def0ff2a9051deb2179be91dde532b8d06caf9f Mon Sep 17 00:00:00 2001
From: Pravin Jagtap <Pravin.Jagtap at amd.com>
Date: Thu, 2 Nov 2023 06:46:22 -0400
Subject: [PATCH 3/6] Updated the mcodel test to target hip
---
clang/test/Driver/mcmodel.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c
index 3b3ff08ba9ad275..6d302657489f7fd 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -15,11 +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 --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-TINY %s
-// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=small %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-SMALL %s
-// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -S -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-KERNEL %s
-// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -c -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-MEDIUM %s
-// RUN: %clang --target=amdgcn-amd-amdhsa -nogpulib -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-LARGE %s
+// RUN: %clang --offload-arch=gfx906 -nogpulib -### -c -x hip -mcmodel=tiny %s 2>&1 | FileCheck --check-prefix=AMDGPU-MCMODEL-TINY %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 %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
// TINY: "-mcmodel=tiny"
// SMALL: "-mcmodel=small"
>From f704e9259ef28ce2df93fb5875b3880e433cc021 Mon Sep 17 00:00:00 2001
From: Pravin Jagtap <Pravin.Jagtap at amd.com>
Date: Tue, 7 Nov 2023 03:49:12 -0500
Subject: [PATCH 4/6] Warn about CM tiny and kernel
---
clang/lib/Driver/ToolChains/Clang.cpp | 11 +++++++++--
clang/test/Driver/mcmodel.c | 8 ++++----
llvm/test/CodeGen/AMDGPU/codemodel.ll | 9 ---------
3 files changed, 13 insertions(+), 15 deletions(-)
delete mode 100644 llvm/test/CodeGen/AMDGPU/codemodel.ll
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 2d73f42772a29dc..bcbeb46b2bdfe6f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5767,10 +5767,17 @@ 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 does not accept CM tiny and kernel.
+ if (CM == "tiny" || CM == "kernel") {
+ D.Diag(diag::warn_ignored_clang_option) << A->getSpelling() << CM << TripleStr;
+ }
}
if (Ok) {
CmdArgs.push_back(Args.MakeArgString("-mcmodel=" + CM));
diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c
index 6d302657489f7fd..d7a05c48434ce50 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -15,9 +15,9 @@
// 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 %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 %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
@@ -36,8 +36,8 @@
// 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: "-mcmodel=tiny"
+// AMDGPU-MCMODEL-TINY-WARNING: warning: the flag '-mcmodel=' has been deprecated and will be ignored
// AMDGPU-MCMODEL-SMALL: "-mcmodel=small"
-// AMDGPU-MCMODEL-KERNEL: "-mcmodel=kernel"
+// 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"
diff --git a/llvm/test/CodeGen/AMDGPU/codemodel.ll b/llvm/test/CodeGen/AMDGPU/codemodel.ll
deleted file mode 100644
index 8b60257b2076aed..000000000000000
--- a/llvm/test/CodeGen/AMDGPU/codemodel.ll
+++ /dev/null
@@ -1,9 +0,0 @@
-; RUN: not llc -verify-machineinstrs -o - -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 -code-model=tiny < %s 2>&1 | FileCheck %s --check-prefix=TINY
-; RUN: not llc -verify-machineinstrs -o - -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 -code-model=kernel < %s 2>&1 | FileCheck %s --check-prefix=KERNEL
-
-; TINY: Target does not support the tiny CodeModel
-; KERNEL: Target does not support the kernel CodeModel
-
-define void @foo() {
- ret void
-}
>From fca9ce52e2f9b1552700540c99278e84b9759868 Mon Sep 17 00:00:00 2001
From: Pravin Jagtap <Pravin.Jagtap at amd.com>
Date: Tue, 7 Nov 2023 04:02:32 -0500
Subject: [PATCH 5/6] clang-format
---
clang/lib/Driver/ToolChains/Clang.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index bcbeb46b2bdfe6f..a3651cd9160a907 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5776,7 +5776,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Ok = true;
// AMDGPU target does not accept CM tiny and kernel.
if (CM == "tiny" || CM == "kernel") {
- D.Diag(diag::warn_ignored_clang_option) << A->getSpelling() << CM << TripleStr;
+ D.Diag(diag::warn_ignored_clang_option)
+ << A->getSpelling() << CM << TripleStr;
}
}
if (Ok) {
>From 34c14bbf355d4f54e2a6bf2620dff6f47947c700 Mon Sep 17 00:00:00 2001
From: Pravin Jagtap <Pravin.Jagtap at amd.com>
Date: Tue, 7 Nov 2023 05:57:56 -0500
Subject: [PATCH 6/6] Handled skipping of tiny and kernel CM + rebase +
clang-format
---
clang/lib/Driver/ToolChains/Clang.cpp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index a3651cd9160a907..7c22f556fb11d5f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5749,6 +5749,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)) {
@@ -5774,13 +5775,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
} else if (Triple.isAMDGPU()) {
// AMDGPU does not care about the code model.
Ok = true;
- // AMDGPU target does not accept CM tiny and kernel.
+ // 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;
}
}
- 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)
More information about the cfe-commits
mailing list