[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-15 Thread via cfe-commits

github-actions[bot] wrote:



@oraluben Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-15 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 closed 
https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-15 Thread Yichen Yan via cfe-commits

https://github.com/oraluben updated 
https://github.com/llvm/llvm-project/pull/85222

>From 9d6fe5f8522ddedde66525e93f4b66e547ddadc6 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 19:43:49 +0800
Subject: [PATCH 1/6] [NVPTX] Add `-march=general` option to mirror default
 configuration

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 4 ++--
 clang/test/Driver/cuda-cross-compiling.c | 9 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index c6007d3cfab864..4cb98f9f28963c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,8 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  // TODO: We should accept 'generic' as a valid architecture.
-  if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
+  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
   } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index 086840accebe7f..e5aeca8300f85c 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,10 +32,15 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
 // ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+//  GENERIC: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} 
"-target-cpu" "sm_52" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" 
"[[PTX:.+]].s"
+// GENERIC-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_52" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// GENERIC-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_52" {{.*}} 
"[[CUBIN]].cubin"
 
 //
 // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 
-// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
+// COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

>From ecea39a30bf3b3fb6a11744bf4888b49ccc66179 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:13:02 +0800
Subject: [PATCH 2/6] fmt

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 4cb98f9f28963c..6114e4f015ab35 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,7 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  if ((!DAL->hasArg(options::OPT_march_EQ) &&
+   OffloadKind != Action::OFK_None) ||
   (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));

>From b0ae86c6a50981ae4a5514763c97fec7ac57db68 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:33:07 +0800
Subject: [PATCH 3/6] Correct `-march=generic`'s semantic in test

Co-authored-by: Joseph Huber 
---
 clang/test/Driver/cuda-cross-compiling.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index e5aeca8300f85c..d72eeace88c88f 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,15 +32,10 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
-// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-t

[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-15 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

Thanks, I'll merge it once it passes CI.

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-15 Thread Yichen Yan via cfe-commits

https://github.com/oraluben updated 
https://github.com/llvm/llvm-project/pull/85222

>From 9d6fe5f8522ddedde66525e93f4b66e547ddadc6 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 19:43:49 +0800
Subject: [PATCH 1/5] [NVPTX] Add `-march=general` option to mirror default
 configuration

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 4 ++--
 clang/test/Driver/cuda-cross-compiling.c | 9 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index c6007d3cfab864..4cb98f9f28963c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,8 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  // TODO: We should accept 'generic' as a valid architecture.
-  if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
+  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
   } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index 086840accebe7f..e5aeca8300f85c 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,10 +32,15 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
 // ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+//  GENERIC: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} 
"-target-cpu" "sm_52" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" 
"[[PTX:.+]].s"
+// GENERIC-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_52" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// GENERIC-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_52" {{.*}} 
"[[CUBIN]].cubin"
 
 //
 // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 
-// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
+// COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

>From ecea39a30bf3b3fb6a11744bf4888b49ccc66179 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:13:02 +0800
Subject: [PATCH 2/5] fmt

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 4cb98f9f28963c..6114e4f015ab35 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,7 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  if ((!DAL->hasArg(options::OPT_march_EQ) &&
+   OffloadKind != Action::OFK_None) ||
   (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));

>From b0ae86c6a50981ae4a5514763c97fec7ac57db68 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:33:07 +0800
Subject: [PATCH 3/5] Correct `-march=generic`'s semantic in test

Co-authored-by: Joseph Huber 
---
 clang/test/Driver/cuda-cross-compiling.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index e5aeca8300f85c..d72eeace88c88f 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,15 +32,10 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
-// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-t

[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-15 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 edited 
https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-15 Thread Joseph Huber via cfe-commits


@@ -750,10 +750,11 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  // TODO: We should accept 'generic' as a valid architecture.
   if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
+  } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "generic") {

jhuber6 wrote:

```suggestion
  } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "generic"
 && OffloadKind == Action::OFK_None) {
```
Ah, forgot, we probably don't want to expose this to CUDA just yet. 

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-15 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 approved this pull request.

LG, thanks for the patch.

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits

https://github.com/oraluben edited 
https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits

https://github.com/oraluben updated 
https://github.com/llvm/llvm-project/pull/85222

>From 9d6fe5f8522ddedde66525e93f4b66e547ddadc6 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 19:43:49 +0800
Subject: [PATCH 1/4] [NVPTX] Add `-march=general` option to mirror default
 configuration

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 4 ++--
 clang/test/Driver/cuda-cross-compiling.c | 9 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index c6007d3cfab864..4cb98f9f28963c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,8 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  // TODO: We should accept 'generic' as a valid architecture.
-  if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
+  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
   } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index 086840accebe7f..e5aeca8300f85c 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,10 +32,15 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
 // ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+//  GENERIC: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} 
"-target-cpu" "sm_52" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" 
"[[PTX:.+]].s"
+// GENERIC-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_52" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// GENERIC-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_52" {{.*}} 
"[[CUBIN]].cubin"
 
 //
 // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 
-// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
+// COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

>From ecea39a30bf3b3fb6a11744bf4888b49ccc66179 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:13:02 +0800
Subject: [PATCH 2/4] fmt

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 4cb98f9f28963c..6114e4f015ab35 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,7 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  if ((!DAL->hasArg(options::OPT_march_EQ) &&
+   OffloadKind != Action::OFK_None) ||
   (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));

>From b0ae86c6a50981ae4a5514763c97fec7ac57db68 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:33:07 +0800
Subject: [PATCH 3/4] Correct `-march=generic`'s semantic in test

Co-authored-by: Joseph Huber 
---
 clang/test/Driver/cuda-cross-compiling.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index e5aeca8300f85c..d72eeace88c88f 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,15 +32,10 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
-// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-t

[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

FWIW I think you can kind of do this with `-march=sm_52 -march=` to just set it 
to empty.

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits

https://github.com/oraluben updated 
https://github.com/llvm/llvm-project/pull/85222

>From 9d6fe5f8522ddedde66525e93f4b66e547ddadc6 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 19:43:49 +0800
Subject: [PATCH 1/3] [NVPTX] Add `-march=general` option to mirror default
 configuration

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 4 ++--
 clang/test/Driver/cuda-cross-compiling.c | 9 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index c6007d3cfab864..4cb98f9f28963c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,8 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  // TODO: We should accept 'generic' as a valid architecture.
-  if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
+  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
   } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index 086840accebe7f..e5aeca8300f85c 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,10 +32,15 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
 // ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+//  GENERIC: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} 
"-target-cpu" "sm_52" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" 
"[[PTX:.+]].s"
+// GENERIC-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_52" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// GENERIC-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_52" {{.*}} 
"[[CUBIN]].cubin"
 
 //
 // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 
-// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
+// COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

>From ecea39a30bf3b3fb6a11744bf4888b49ccc66179 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:13:02 +0800
Subject: [PATCH 2/3] fmt

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 4cb98f9f28963c..6114e4f015ab35 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,7 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  if ((!DAL->hasArg(options::OPT_march_EQ) &&
+   OffloadKind != Action::OFK_None) ||
   (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));

>From b0ae86c6a50981ae4a5514763c97fec7ac57db68 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:33:07 +0800
Subject: [PATCH 3/3] Correct `-march=generic`'s semantic in test

Co-authored-by: Joseph Huber 
---
 clang/test/Driver/cuda-cross-compiling.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index e5aeca8300f85c..d72eeace88c88f 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,15 +32,10 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
-// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-t

[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits

https://github.com/oraluben updated 
https://github.com/llvm/llvm-project/pull/85222

>From 9d6fe5f8522ddedde66525e93f4b66e547ddadc6 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 19:43:49 +0800
Subject: [PATCH 1/3] [NVPTX] Add `-march=general` option to mirror default
 configuration

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 4 ++--
 clang/test/Driver/cuda-cross-compiling.c | 9 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index c6007d3cfab864..4cb98f9f28963c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,8 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  // TODO: We should accept 'generic' as a valid architecture.
-  if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
+  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
   } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index 086840accebe7f..e5aeca8300f85c 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,10 +32,15 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
 // ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+//  GENERIC: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} 
"-target-cpu" "sm_52" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" 
"[[PTX:.+]].s"
+// GENERIC-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_52" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// GENERIC-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_52" {{.*}} 
"[[CUBIN]].cubin"
 
 //
 // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 
-// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
+// COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

>From ecea39a30bf3b3fb6a11744bf4888b49ccc66179 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:13:02 +0800
Subject: [PATCH 2/3] fmt

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 4cb98f9f28963c..6114e4f015ab35 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,7 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  if ((!DAL->hasArg(options::OPT_march_EQ) &&
+   OffloadKind != Action::OFK_None) ||
   (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));

>From be938328dfb6fd6efeef57a832424d248bd9f955 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:33:07 +0800
Subject: [PATCH 3/3] Correct `-march=generic`'s semantic in test

Co-authored-by: Joseph Huber 
---
 clang/test/Driver/cuda-cross-compiling.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index e5aeca8300f85c..4fdc0b77d22e7f 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,15 +32,10 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
-// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-

[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits

https://github.com/oraluben converted_to_draft 
https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits

https://github.com/oraluben updated 
https://github.com/llvm/llvm-project/pull/85222

>From 9d6fe5f8522ddedde66525e93f4b66e547ddadc6 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 19:43:49 +0800
Subject: [PATCH 1/3] [NVPTX] Add `-march=general` option to mirror default
 configuration

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 4 ++--
 clang/test/Driver/cuda-cross-compiling.c | 9 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index c6007d3cfab864..4cb98f9f28963c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,8 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  // TODO: We should accept 'generic' as a valid architecture.
-  if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
+  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
   } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index 086840accebe7f..e5aeca8300f85c 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,10 +32,15 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
 // ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+//  GENERIC: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} 
"-target-cpu" "sm_52" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" 
"[[PTX:.+]].s"
+// GENERIC-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_52" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// GENERIC-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_52" {{.*}} 
"[[CUBIN]].cubin"
 
 //
 // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 
-// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
+// COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

>From ecea39a30bf3b3fb6a11744bf4888b49ccc66179 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:13:02 +0800
Subject: [PATCH 2/3] fmt

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 4cb98f9f28963c..6114e4f015ab35 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,7 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  if ((!DAL->hasArg(options::OPT_march_EQ) &&
+   OffloadKind != Action::OFK_None) ||
   (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));

>From cb795dd784d26a7f21a207bfcb94c3ba7d62103b Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:33:07 +0800
Subject: [PATCH 3/3] Update clang/test/Driver/cuda-cross-compiling.c

Co-authored-by: Joseph Huber 
---
 clang/test/Driver/cuda-cross-compiling.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index e5aeca8300f85c..7d10d218119687 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -91,5 +91,6 @@
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=COMPILE %s
-
+// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_52 -march=generic -flto 
-c %s -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=GENERIC %s
 // COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

__

[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits


@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 

oraluben wrote:

I see, thanks for clarifying!

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Joseph Huber via cfe-commits


@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 

jhuber6 wrote:

```suggestion
// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_52 -march=generic -flto -c 
%s -### 2>&1 \
// RUN:   | FileCheck -check-prefix=GENERIC %s
```
The test should look like this, using `-march=generic` overrides the previous 
`-march` and results in the same output as if `-march` was not passed at all.

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 requested changes to this pull request.

Thanks for looking at this. When the user compiles with `-march=xyz` it 
introduces a lot of subtarget specific metadata intro the output IR. The 
purpose of the original patch was to keep `-target-cpu` unset in cases where 
`-march=xyz` was not passed in. The expected semantics here is that 
`-march=sm_52 -march=generic` will override `-march=sm_52` and result in no 
`-target-cpu` being set just like if you didn't pass `-march` at all.

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 edited 
https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits

https://github.com/oraluben updated 
https://github.com/llvm/llvm-project/pull/85222

>From 9d6fe5f8522ddedde66525e93f4b66e547ddadc6 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 19:43:49 +0800
Subject: [PATCH 1/2] [NVPTX] Add `-march=general` option to mirror default
 configuration

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 4 ++--
 clang/test/Driver/cuda-cross-compiling.c | 9 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index c6007d3cfab864..4cb98f9f28963c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,8 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  // TODO: We should accept 'generic' as a valid architecture.
-  if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
+  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
   } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index 086840accebe7f..e5aeca8300f85c 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,10 +32,15 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
 // ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+//  GENERIC: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} 
"-target-cpu" "sm_52" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" 
"[[PTX:.+]].s"
+// GENERIC-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_52" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// GENERIC-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_52" {{.*}} 
"[[CUBIN]].cubin"
 
 //
 // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 
-// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
+// COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

>From ecea39a30bf3b3fb6a11744bf4888b49ccc66179 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:13:02 +0800
Subject: [PATCH 2/2] fmt

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 4cb98f9f28963c..6114e4f015ab35 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,7 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  if ((!DAL->hasArg(options::OPT_march_EQ) &&
+   OffloadKind != Action::OFK_None) ||
   (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits

oraluben wrote:

@jhuber6 @Artem-B You might want to check if this LGTY :)

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 34ba90745fa55777436a2429a51a3799c83c6d4c 
9d6fe5f8522ddedde66525e93f4b66e547ddadc6 -- 
clang/lib/Driver/ToolChains/Cuda.cpp clang/test/Driver/cuda-cross-compiling.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 4cb98f9f28..6114e4f015 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,7 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  if ((!DAL->hasArg(options::OPT_march_EQ) &&
+   OffloadKind != Action::OFK_None) ||
   (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));

``




https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yichen Yan (oraluben)


Changes

This PR adds `-march=generic` support for the NVPTX backend. This fulfills a 
TODO introduced in #79873.

With this PR, users can explicitly request the default CUDA architecture. This 
default is regularly updated, and the most recent configuration as of commit 
ab202aa sets it to `sm_52`. This value is also assumed when no `-march` option 
is provided.

This PR does not address any compatibility issues between different CUDA 
versions.


---
Full diff: https://github.com/llvm/llvm-project/pull/85222.diff


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Cuda.cpp (+2-2) 
- (modified) clang/test/Driver/cuda-cross-compiling.c (+7-2) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index c6007d3cfab864..4cb98f9f28963c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,8 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  // TODO: We should accept 'generic' as a valid architecture.
-  if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
+  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
   } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index 086840accebe7f..e5aeca8300f85c 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,10 +32,15 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
 // ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+//  GENERIC: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} 
"-target-cpu" "sm_52" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" 
"[[PTX:.+]].s"
+// GENERIC-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_52" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// GENERIC-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_52" {{.*}} 
"[[CUBIN]].cubin"
 
 //
 // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 
-// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
+// COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

``




https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits

https://github.com/oraluben created 
https://github.com/llvm/llvm-project/pull/85222

This PR adds `-march=generic` support for the NVPTX backend. This fulfills a 
TODO introduced in #79873.

With this PR, users can explicitly request the default CUDA architecture. This 
default is regularly updated, and the most recent configuration as of commit 
ab202aa sets it to `sm_52`. This value is also assumed when no `-march` option 
is provided.

This PR does not address any compatibility issues between different CUDA 
versions.


>From 9d6fe5f8522ddedde66525e93f4b66e547ddadc6 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 19:43:49 +0800
Subject: [PATCH] [NVPTX] Add `-march=general` option to mirror default
 configuration

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 4 ++--
 clang/test/Driver/cuda-cross-compiling.c | 9 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index c6007d3cfab864..4cb98f9f28963c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,8 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  // TODO: We should accept 'generic' as a valid architecture.
-  if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
+  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
   } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index 086840accebe7f..e5aeca8300f85c 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,10 +32,15 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
 // ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+//  GENERIC: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} 
"-target-cpu" "sm_52" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" 
"[[PTX:.+]].s"
+// GENERIC-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_52" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// GENERIC-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_52" {{.*}} 
"[[CUBIN]].cubin"
 
 //
 // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 
-// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
+// COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits