[clang] [clang] [test] Skip a test that sets PATH= on Windows (PR #95096)

2024-06-11 Thread Henry Linjamäki via cfe-commits

linehill wrote:

Could the single test with the PATH manipulation be moved to a separate test 
file which is disabled on Windows? That way we could keep running the other 
tests on Windows.

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


[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-05-31 Thread Henry Linjamäki via cfe-commits

linehill wrote:

Thanks, @svenvh.

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


[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-05-31 Thread Henry Linjamäki via cfe-commits

linehill wrote:

Ping, @svenvh. The patch has been rebased, good for landing?

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


[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-05-24 Thread Henry Linjamäki via cfe-commits

https://github.com/linehill updated 
https://github.com/llvm/llvm-project/pull/77897

From 13609260c7ef2b57751975a6c7847439958978d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henry=20Linjam=C3=A4ki?= 
Date: Thu, 21 Dec 2023 08:43:16 +0200
Subject: [PATCH 1/2] [SPIR-V] Prefer llvm-spirv- tool

Prefer using `llvm-spirv-` tool
(i.e. `llvm-spirv-18`) over plain `llvm-spirv`. If the versioned tool
is not found in PATH, fall back to use the plain `llvm-spirv`.

An issue with the using `llvm-spirv` is that the one found in PATH
might be compiled against older LLVM version which could lead to
crashes or obscure bugs. For example, `llvm-spirv` distributed by
Ubuntu links against different LLVM version depending on the Ubuntu
release (LLVM-10 in 20.04LTS, LLVM-13 in 22.04LTS).
---
 clang/lib/Driver/ToolChains/SPIRV.cpp  | 12 ++--
 clang/test/Driver/hipspv-toolchain.hip | 13 +
 clang/test/Driver/spirv-toolchain.cl   | 10 ++
 clang/test/lit.site.cfg.py.in  |  1 +
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
index 27de69550853c..ce900600cbee5 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.cpp
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 #include "SPIRV.h"
 #include "CommonArgs.h"
+#include "clang/Basic/Version.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/InputInfo.h"
@@ -32,8 +33,15 @@ void SPIRV::constructTranslateCommand(Compilation &C, const 
Tool &T,
 
   CmdArgs.append({"-o", Output.getFilename()});
 
-  const char *Exec =
-  C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
+  // Try to find "llvm-spirv-". Otherwise, fall back to
+  // plain "llvm-spirv".
+  using namespace std::string_literals;
+  auto VersionedTool = "llvm-spirv-"s + std::to_string(LLVM_VERSION_MAJOR);
+  std::string ExeCand = T.getToolChain().GetProgramPath(VersionedTool.c_str());
+  if (!llvm::sys::fs::can_execute(ExeCand))
+ExeCand = T.getToolChain().GetProgramPath("llvm-spirv");
+
+  const char *Exec = C.getArgs().MakeArgString(ExeCand);
   C.addCommand(std::make_unique(JA, T, ResponseFileSupport::None(),
  Exec, CmdArgs, Input, Output));
 }
diff --git a/clang/test/Driver/hipspv-toolchain.hip 
b/clang/test/Driver/hipspv-toolchain.hip
index 4602cd3fc8d68..4005d9889051f 100644
--- a/clang/test/Driver/hipspv-toolchain.hip
+++ b/clang/test/Driver/hipspv-toolchain.hip
@@ -34,3 +34,16 @@
 // CHECK-SAME: "-o" [[OBJ_HOST:".*o"]] "-x" "hip"
 
 // CHECK: {{".*ld.*"}} {{.*}}[[OBJ_HOST]]
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### -target x86_64-linux-gnu \
+// RUN:   --offload=spirv64 --hip-path=%S/Inputs/hipspv -nohipwrapperinc \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major \
+// RUN:   --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/Driver/spirv-toolchain.cl 
b/clang/test/Driver/spirv-toolchain.cl
index db3ee4d3fe02f..de818177cb19f 100644
--- a/clang/test/Driver/spirv-toolchain.cl
+++ b/clang/test/Driver/spirv-toolchain.cl
@@ -77,3 +77,13 @@
 
 // XTOR: {{llvm-spirv.*"}}
 // BACKEND-NOT: {{llvm-spirv.*"}}
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### --target=spirv64 -x cl -c %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index ec6d30e6c2203..1cbd876ac5bb9 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -43,6 +43,7 @@ config.llvm_external_lit = path(r"@LLVM_EXTERNAL_LIT@")
 config.standalone_build = @CLANG_BUILT_STANDALONE@
 config.ppc_linux_default_ieeelongdouble = @PPC_LINUX_DEFAULT_IEEELONGDOUBLE@
 config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@
+config.substitutions.append(("%llvm-version-major", "@LLVM_VERSION_MAJOR@"))
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)

From 28c8da48fa98b18de1e7f77c4316bb3bfff933e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henry=20Linjam=C3=A4ki?= 
Date: Mon, 22 Jan 2024 11:25:46 +0200
Subject: [PATCH 2/2] Document llvm-spirv-

---
 clang/docs/UsersManual.rst | 6 +++---
 1 file changed, 3

[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-05-24 Thread Henry Linjamäki via cfe-commits

linehill wrote:

Thanks for the review. Could you merge this PR on my behalf (I don't have write 
access)?

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


[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-01-22 Thread Henry Linjamäki via cfe-commits

linehill wrote:

@AnastasiaStulova, @MaskRay, gentle ping.

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


[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-01-22 Thread Henry Linjamäki via cfe-commits

https://github.com/linehill updated 
https://github.com/llvm/llvm-project/pull/77897

From 6165987ab890156a503d7afa38ad5c88510368b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henry=20Linjam=C3=A4ki?= 
Date: Thu, 21 Dec 2023 08:43:16 +0200
Subject: [PATCH 1/2] [SPIR-V] Prefer llvm-spirv- tool

Prefer using `llvm-spirv-` tool
(i.e. `llvm-spirv-18`) over plain `llvm-spirv`. If the versioned tool
is not found in PATH, fall back to use the plain `llvm-spirv`.

An issue with the using `llvm-spirv` is that the one found in PATH
might be compiled against older LLVM version which could lead to
crashes or obscure bugs. For example, `llvm-spirv` distributed by
Ubuntu links against different LLVM version depending on the Ubuntu
release (LLVM-10 in 20.04LTS, LLVM-13 in 22.04LTS).
---
 clang/lib/Driver/ToolChains/SPIRV.cpp  | 12 ++--
 clang/test/Driver/hipspv-toolchain.hip | 13 +
 clang/test/Driver/spirv-toolchain.cl   | 10 ++
 clang/test/lit.site.cfg.py.in  |  1 +
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
index 27de69550853cf9..ce900600cbee515 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.cpp
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 #include "SPIRV.h"
 #include "CommonArgs.h"
+#include "clang/Basic/Version.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/InputInfo.h"
@@ -32,8 +33,15 @@ void SPIRV::constructTranslateCommand(Compilation &C, const 
Tool &T,
 
   CmdArgs.append({"-o", Output.getFilename()});
 
-  const char *Exec =
-  C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
+  // Try to find "llvm-spirv-". Otherwise, fall back to
+  // plain "llvm-spirv".
+  using namespace std::string_literals;
+  auto VersionedTool = "llvm-spirv-"s + std::to_string(LLVM_VERSION_MAJOR);
+  std::string ExeCand = T.getToolChain().GetProgramPath(VersionedTool.c_str());
+  if (!llvm::sys::fs::can_execute(ExeCand))
+ExeCand = T.getToolChain().GetProgramPath("llvm-spirv");
+
+  const char *Exec = C.getArgs().MakeArgString(ExeCand);
   C.addCommand(std::make_unique(JA, T, ResponseFileSupport::None(),
  Exec, CmdArgs, Input, Output));
 }
diff --git a/clang/test/Driver/hipspv-toolchain.hip 
b/clang/test/Driver/hipspv-toolchain.hip
index bfae41049ba4dd1..5f6dcc069afe8b7 100644
--- a/clang/test/Driver/hipspv-toolchain.hip
+++ b/clang/test/Driver/hipspv-toolchain.hip
@@ -34,3 +34,16 @@
 // CHECK-SAME: "-o" [[OBJ_HOST:".*o"]] "-x" "hip"
 
 // CHECK: {{".*ld.*"}} {{.*}}[[OBJ_HOST]]
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### -target x86_64-linux-gnu \
+// RUN:   --offload=spirv64 --hip-path=%S/Inputs/hipspv -nohipwrapperinc \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major \
+// RUN:   --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/Driver/spirv-toolchain.cl 
b/clang/test/Driver/spirv-toolchain.cl
index db3ee4d3fe02f82..de818177cb19f15 100644
--- a/clang/test/Driver/spirv-toolchain.cl
+++ b/clang/test/Driver/spirv-toolchain.cl
@@ -77,3 +77,13 @@
 
 // XTOR: {{llvm-spirv.*"}}
 // BACKEND-NOT: {{llvm-spirv.*"}}
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### --target=spirv64 -x cl -c %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index ef75770a2c3c9ac..b4e88096aaa0f3c 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -41,6 +41,7 @@ config.llvm_external_lit = path(r"@LLVM_EXTERNAL_LIT@")
 config.standalone_build = @CLANG_BUILT_STANDALONE@
 config.ppc_linux_default_ieeelongdouble = @PPC_LINUX_DEFAULT_IEEELONGDOUBLE@
 config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@
+config.substitutions.append(("%llvm-version-major", "@LLVM_VERSION_MAJOR@"))
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)

From fc1e2d0693d196b6bc4a0f1c51fd5ecc71e60f92 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henry=20Linjam=C3=A4ki?= 
Date: Mon, 22 Jan 2024 11:25:46 +0200
Subject: [PATCH 2/2] Document llvm-spirv-

---
 clang/docs/UsersManual.rst | 6 +++---
 1

[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-01-12 Thread Henry Linjamäki via cfe-commits

https://github.com/linehill created 
https://github.com/llvm/llvm-project/pull/77897

Prefer using `llvm-spirv-` tool (i.e. `llvm-spirv-18`) over 
plain `llvm-spirv`. If the versioned tool is not found in PATH, fall back to 
use the plain `llvm-spirv`.

An issue with the using `llvm-spirv` is that the one found in PATH might be 
compiled against older LLVM version which could lead to crashes or obscure 
bugs. For example, `llvm-spirv` distributed by Ubuntu links against different 
LLVM version depending on the Ubuntu release (LLVM-10 in 20.04LTS, LLVM-13 in 
22.04LTS).

From 6165987ab890156a503d7afa38ad5c88510368b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henry=20Linjam=C3=A4ki?= 
Date: Thu, 21 Dec 2023 08:43:16 +0200
Subject: [PATCH] [SPIR-V] Prefer llvm-spirv- tool

Prefer using `llvm-spirv-` tool
(i.e. `llvm-spirv-18`) over plain `llvm-spirv`. If the versioned tool
is not found in PATH, fall back to use the plain `llvm-spirv`.

An issue with the using `llvm-spirv` is that the one found in PATH
might be compiled against older LLVM version which could lead to
crashes or obscure bugs. For example, `llvm-spirv` distributed by
Ubuntu links against different LLVM version depending on the Ubuntu
release (LLVM-10 in 20.04LTS, LLVM-13 in 22.04LTS).
---
 clang/lib/Driver/ToolChains/SPIRV.cpp  | 12 ++--
 clang/test/Driver/hipspv-toolchain.hip | 13 +
 clang/test/Driver/spirv-toolchain.cl   | 10 ++
 clang/test/lit.site.cfg.py.in  |  1 +
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
index 27de69550853cf..ce900600cbee51 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.cpp
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 #include "SPIRV.h"
 #include "CommonArgs.h"
+#include "clang/Basic/Version.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/InputInfo.h"
@@ -32,8 +33,15 @@ void SPIRV::constructTranslateCommand(Compilation &C, const 
Tool &T,
 
   CmdArgs.append({"-o", Output.getFilename()});
 
-  const char *Exec =
-  C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
+  // Try to find "llvm-spirv-". Otherwise, fall back to
+  // plain "llvm-spirv".
+  using namespace std::string_literals;
+  auto VersionedTool = "llvm-spirv-"s + std::to_string(LLVM_VERSION_MAJOR);
+  std::string ExeCand = T.getToolChain().GetProgramPath(VersionedTool.c_str());
+  if (!llvm::sys::fs::can_execute(ExeCand))
+ExeCand = T.getToolChain().GetProgramPath("llvm-spirv");
+
+  const char *Exec = C.getArgs().MakeArgString(ExeCand);
   C.addCommand(std::make_unique(JA, T, ResponseFileSupport::None(),
  Exec, CmdArgs, Input, Output));
 }
diff --git a/clang/test/Driver/hipspv-toolchain.hip 
b/clang/test/Driver/hipspv-toolchain.hip
index bfae41049ba4dd..5f6dcc069afe8b 100644
--- a/clang/test/Driver/hipspv-toolchain.hip
+++ b/clang/test/Driver/hipspv-toolchain.hip
@@ -34,3 +34,16 @@
 // CHECK-SAME: "-o" [[OBJ_HOST:".*o"]] "-x" "hip"
 
 // CHECK: {{".*ld.*"}} {{.*}}[[OBJ_HOST]]
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### -target x86_64-linux-gnu \
+// RUN:   --offload=spirv64 --hip-path=%S/Inputs/hipspv -nohipwrapperinc \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major \
+// RUN:   --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/Driver/spirv-toolchain.cl 
b/clang/test/Driver/spirv-toolchain.cl
index db3ee4d3fe02f8..de818177cb19f1 100644
--- a/clang/test/Driver/spirv-toolchain.cl
+++ b/clang/test/Driver/spirv-toolchain.cl
@@ -77,3 +77,13 @@
 
 // XTOR: {{llvm-spirv.*"}}
 // BACKEND-NOT: {{llvm-spirv.*"}}
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### --target=spirv64 -x cl -c %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index ef75770a2c3c9a..b4e88096aaa0f3 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -41,6 +41,7 @@ config.llvm_external_lit = path(r"@LLVM_EXTERNAL_LIT@")
 config.standalone_build = @CLANG_BUILT_STANDALONE@
 config.ppc_linux_default_ieeelong

[clang] Add SPIRV support to HIPAMD toolchain (PR #75357)

2024-01-03 Thread Henry Linjamäki via cfe-commits

linehill wrote:

> > Perhaps we should consider prefixing it in some way (e.g. `hip-spirv` or 
> > `amd-spirv`) that leaves the door open for some special handling (enable a 
> > particular set of extensions only for amdgpu targeting SPIRV, try to deal 
> > with missing builtins etc.) / flexibility?
> 
> I think amd-spirv may be a good choice since spirv itself is ambiguous about 
> which HIP toolchain to choose since there are two HIP toolchains that support 
> SPIRV: HIPAMD and HIPSPV.

> > I wonder if `-mcpu` is the correct way to encode this. Targeting SPIR-V is 
> > more like the triple than the architecture as far as I'm aware.
> 
> I will see whether I can use triple instead.

How about using `--offload=` which can take a target triple? E.g.

* `--offload=spirv64-amd` or something like that: pick HIPAMD tool chain.
* `--offload=spirv64`: pick HIPSPV tool chain.

And also remove this 
[limitation](https://github.com/llvm/llvm-project/blob/5fc712c4bbe84e6cbaa1f7d2a0300f613f11b0c3/clang/lib/Driver/Driver.cpp#L3130-L3136)
 if you want `--offload` to work along with `--offload-arch`. 

Or alternatively allow multiple `--offload` options, deprecate `--offload-arch` 
and use `--offload` instead. For convenience and easy transition, options like 
`--offload=` could be allowed where the `` is treated as 
an alias for an offload target (E.g. `--offload=gfx900` could imply 
`--offload=amdgcn-amd-amdhsa:gfx900` or something like that).


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