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

Pravin Jagtap via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 15 22:53:43 PST 2023


https://github.com/pravinjagtap updated https://github.com/llvm/llvm-project/pull/71019

>From 88e45f090a0eb7023a155dd464097467cab018bd 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 18eed23790cff1f3ba1bf4b474aeea49430033ff 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 8066f5ff6b885681dcccade9e9fcc4f1b1ba1c3a 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 2f6058ce7da8b0cb9ef560e74472356f5797a10a 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 b462f5a44057d94..e38e7bf45129bca 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5750,10 +5750,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 93820ad7c6d7399fc557eef4cfc9f7490c683457 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 e38e7bf45129bca..ed1286ce99ef4ae 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5759,7 +5759,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 7b3d4dc00d8331fcdfc19c81829d63c9106d318c 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 and rebase

---
 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 ed1286ce99ef4ae..970526a13c60c79 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5732,6 +5732,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)) {
@@ -5757,13 +5758,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