[llvm] [clang] [AMDGPU] Add code model (#70760) test for amdgpu target. (PR #71019)
Pravin Jagtap via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 7 01:02:56 PST 2023
https://github.com/pravinjagtap updated https://github.com/llvm/llvm-project/pull/71019
>From ef0118818249da417706db7f8e7086d051d17d50 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/5] [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 f4c4ec2dd7829267b0df84a2a651b98e9c18a4e0 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/5] 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 fb3bbccb0c68157..d546d5d81db5261 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -13,6 +13,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"
@@ -29,3 +34,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 9dc7689983b74dd381df556bc9e61165e08d85b4 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/5] 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 d546d5d81db5261..ab7207252452b47 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -13,11 +13,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 d171525cc83f5c60a7725b54eeaa26540b9d1390 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/5] 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 79f7fba22570746..61c4e7801157f35 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5743,10 +5743,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 ab7207252452b47..1a7fae6a7371a3d 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -13,9 +13,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
@@ -34,8 +34,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 fe514951082ae3206381322394520a3a058767d0 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/5] 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 61c4e7801157f35..2d918a45d4c1e72 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5752,7 +5752,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) {
More information about the cfe-commits
mailing list