[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-12-14 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki added a comment.

Thanks, @tra.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-12-14 Thread Artem Belevich via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4e94cba5b4e4: [HIPSPV][2/4] Add HIPSPV tool chain (authored 
by linjamaki, committed by tra).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h

Index: clang/lib/Driver/ToolChains/HIPSPV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.h
@@ -0,0 +1,103 @@
+//===--- HIPSPV.h - HIP ToolChain Implementations ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+
+#include "SPIRV.h"
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace HIPSPV {
+
+// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
+// device library, then compiles it to SPIR-V in a shared object.
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+
+private:
+  void constructLinkAndEmitSpirvCommand(Compilation , const JobAction ,
+const InputInfoList ,
+const InputInfo ,
+const llvm::opt::ArgList ) const;
+};
+
+} // namespace HIPSPV
+} // namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
+public:
+  HIPSPVToolChain(const Driver , const llvm::Triple ,
+  const ToolChain , const llvm::opt::ArgList );
+
+  const llvm::Triple *getAuxTriple() const override {
+return ();
+  }
+
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+  void addClangWarningOptions(llvm::opt::ArgStringList ) const override;
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
+  void AddHIPIncludeArgs(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  llvm::SmallVector
+  getHIPDeviceLibs(const llvm::opt::ArgList ) const override;
+
+  SanitizerMask getSupportedSanitizers() const override;
+
+  VersionTuple
+  computeMSVCVersion(const Driver *D,
+ const llvm::opt::ArgList ) const override;
+
+  void adjustDebugInfoKind(codegenoptions::DebugInfoKind ,
+   const llvm::opt::ArgList ) const override;
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault(const llvm::opt::ArgList ) const override {
+return false;
+  }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return false; }
+
+  const ToolChain 
+
+protected:
+  Tool *buildLinker() const override;
+};
+
+} // end namespace toolchains
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -0,0 +1,292 @@
+//===--- HIPSPV.cpp - HIPSPV ToolChain Implementation ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the 

[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-12-14 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki added a comment.

This patch should be ready to land. @tra, could you please commit this to the 
LLVM for us. Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-12-14 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki updated this revision to Diff 394208.
linjamaki added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h

Index: clang/lib/Driver/ToolChains/HIPSPV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.h
@@ -0,0 +1,103 @@
+//===--- HIPSPV.h - HIP ToolChain Implementations ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+
+#include "SPIRV.h"
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace HIPSPV {
+
+// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
+// device library, then compiles it to SPIR-V in a shared object.
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+
+private:
+  void constructLinkAndEmitSpirvCommand(Compilation , const JobAction ,
+const InputInfoList ,
+const InputInfo ,
+const llvm::opt::ArgList ) const;
+};
+
+} // namespace HIPSPV
+} // namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
+public:
+  HIPSPVToolChain(const Driver , const llvm::Triple ,
+  const ToolChain , const llvm::opt::ArgList );
+
+  const llvm::Triple *getAuxTriple() const override {
+return ();
+  }
+
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+  void addClangWarningOptions(llvm::opt::ArgStringList ) const override;
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
+  void AddHIPIncludeArgs(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  llvm::SmallVector
+  getHIPDeviceLibs(const llvm::opt::ArgList ) const override;
+
+  SanitizerMask getSupportedSanitizers() const override;
+
+  VersionTuple
+  computeMSVCVersion(const Driver *D,
+ const llvm::opt::ArgList ) const override;
+
+  void adjustDebugInfoKind(codegenoptions::DebugInfoKind ,
+   const llvm::opt::ArgList ) const override;
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault(const llvm::opt::ArgList ) const override {
+return false;
+  }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return false; }
+
+  const ToolChain 
+
+protected:
+  Tool *buildLinker() const override;
+};
+
+} // end namespace toolchains
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -0,0 +1,292 @@
+//===--- HIPSPV.cpp - HIPSPV ToolChain Implementation ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH 

[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-12-08 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki updated this revision to Diff 392665.
linjamaki added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h

Index: clang/lib/Driver/ToolChains/HIPSPV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.h
@@ -0,0 +1,103 @@
+//===--- HIPSPV.h - HIP ToolChain Implementations ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+
+#include "SPIRV.h"
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace HIPSPV {
+
+// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
+// device library, then compiles it to SPIR-V in a shared object.
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+
+private:
+  void constructLinkAndEmitSpirvCommand(Compilation , const JobAction ,
+const InputInfoList ,
+const InputInfo ,
+const llvm::opt::ArgList ) const;
+};
+
+} // namespace HIPSPV
+} // namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
+public:
+  HIPSPVToolChain(const Driver , const llvm::Triple ,
+  const ToolChain , const llvm::opt::ArgList );
+
+  const llvm::Triple *getAuxTriple() const override {
+return ();
+  }
+
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+  void addClangWarningOptions(llvm::opt::ArgStringList ) const override;
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
+  void AddHIPIncludeArgs(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  llvm::SmallVector
+  getHIPDeviceLibs(const llvm::opt::ArgList ) const override;
+
+  SanitizerMask getSupportedSanitizers() const override;
+
+  VersionTuple
+  computeMSVCVersion(const Driver *D,
+ const llvm::opt::ArgList ) const override;
+
+  void adjustDebugInfoKind(codegenoptions::DebugInfoKind ,
+   const llvm::opt::ArgList ) const override;
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault(const llvm::opt::ArgList ) const override {
+return false;
+  }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return false; }
+
+  const ToolChain 
+
+protected:
+  Tool *buildLinker() const override;
+};
+
+} // end namespace toolchains
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -0,0 +1,292 @@
+//===--- HIPSPV.cpp - HIPSPV ToolChain Implementation ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH 

[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-12-02 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D110618#3152939 , @linjamaki wrote:

> In D110618#3148501 , @Anastasia 
> wrote:
>
>> Could you please clarify the interface to SPIRV-LLVM-Translator tool, 
>> specifically:
>>
>> - Does clang lookup the path to the translator or assume any default path?
>
> HIPSPV primarily relies on the system’s PATH for locating the translator.
>
> Additionally, the translator is sought in the same directory where the Clang 
> driver is installed in. This is rather a side-effect than a feature. The 
> directory is added to Clang’s internal search paths for looking up the 
> `clang-offload-bundler` tool required by the HIPSPV tool chain.
>
>> - Is there any diagnostic provided if the translator not installed/found?
>
> Clang displays the following standard error if the translator is not found:
>
>   error: unable to execute command: Executable "llvm-spirv" doesn't exist!
>
>
>
>> - How does clang synchronize with the translator versions i.e. some LLVM IR 
>> might not be ingested by certain version of the translator. Would this 
>> results in the translator ICE or error in the translator, or is it something 
>> that can be diagnosed early by clang or during clang build/installation?
>
> A version mismatch may result in an error in the translator. This is a known 
> issue and a reason we want to switch to the SPIR-V backend when it lands on 
> the LLVM - **the translator is meant to be used temporarily by the HIPSPV**. 
> The synchronization could be improved by having the Clang to seek a SPIR-V 
> Translator binary that is named with the LLVM version it has been built 
> against - e.g. “llvm-spirv-14” for the next LLVM release.
>
> AFAIK, Clang’s infrastructure does not support early diagnosis on external 
> tools. The diagnosis during Clang’s build and installation probably won’t 
> matter much if the Clang is distributed as binary to other systems - the 
> destination system might not have the required translator version.

Alternatively, we could see if translator could emit a diagnostic by looking at 
the clang version emitted in metadata... I presume this might not be too hard 
to implement...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-11-25 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki updated this revision to Diff 389702.
linjamaki added a comment.

Disable debug info generation for device code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h

Index: clang/lib/Driver/ToolChains/HIPSPV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.h
@@ -0,0 +1,103 @@
+//===--- HIPSPV.h - HIP ToolChain Implementations ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+
+#include "SPIRV.h"
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace HIPSPV {
+
+// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
+// device library, then compiles it to SPIR-V in a shared object.
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+
+private:
+  void constructLinkAndEmitSpirvCommand(Compilation , const JobAction ,
+const InputInfoList ,
+const InputInfo ,
+const llvm::opt::ArgList ) const;
+};
+
+} // namespace HIPSPV
+} // namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
+public:
+  HIPSPVToolChain(const Driver , const llvm::Triple ,
+  const ToolChain , const llvm::opt::ArgList );
+
+  const llvm::Triple *getAuxTriple() const override {
+return ();
+  }
+
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+  void addClangWarningOptions(llvm::opt::ArgStringList ) const override;
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
+  void AddHIPIncludeArgs(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  llvm::SmallVector
+  getHIPDeviceLibs(const llvm::opt::ArgList ) const override;
+
+  SanitizerMask getSupportedSanitizers() const override;
+
+  VersionTuple
+  computeMSVCVersion(const Driver *D,
+ const llvm::opt::ArgList ) const override;
+
+  void adjustDebugInfoKind(codegenoptions::DebugInfoKind ,
+   const llvm::opt::ArgList ) const override;
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault(const llvm::opt::ArgList ) const override {
+return false;
+  }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return false; }
+
+  const ToolChain 
+
+protected:
+  Tool *buildLinker() const override;
+};
+
+} // end namespace toolchains
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -0,0 +1,292 @@
+//===--- HIPSPV.cpp - HIPSPV ToolChain Implementation ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// 

[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-11-24 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki added a comment.

In D110618#3148501 , @Anastasia wrote:

> Could you please clarify the interface to SPIRV-LLVM-Translator tool, 
> specifically:
>
> - Does clang lookup the path to the translator or assume any default path?

HIPSPV primarily relies on the system’s PATH for locating the translator.

Additionally, the translator is sought in the same directory where the Clang 
driver is installed in. This is rather a side-effect than a feature. The 
directory is added to Clang’s internal search paths for looking up the 
`clang-offload-bundler` tool required by the HIPSPV tool chain.

> - Is there any diagnostic provided if the translator not installed/found?

Clang displays the following standard error if the translator is not found:

  error: unable to execute command: Executable "llvm-spirv" doesn't exist!



> - How does clang synchronize with the translator versions i.e. some LLVM IR 
> might not be ingested by certain version of the translator. Would this 
> results in the translator ICE or error in the translator, or is it something 
> that can be diagnosed early by clang or during clang build/installation?

A version mismatch may result in an error in the translator. This is a known 
issue and a reason we want to switch to the SPIR-V backend when it lands on the 
LLVM - **the translator is meant to be used temporarily by the HIPSPV**. The 
synchronization could be improved by having the Clang to seek a SPIR-V 
Translator binary that is named with the LLVM version it has been built against 
- e.g. “llvm-spirv-14” for the next LLVM release.

AFAIK, Clang’s infrastructure does not support early diagnosis on external 
tools. The diagnosis during Clang’s build and installation probably won’t 
matter much if the Clang is distributed as binary to other systems - the 
destination system might not have the required translator version.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-11-23 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

Could you please clarify the interface to SPIRV-LLVM-Translator tool, 
specifically:

- Does clang lookup the path to the translator or assume any default path?
- Is there any diagnostic provided if the translator not installed/found?
- How does clang synchronize with the translator versions i.e. some LLVM IR 
might not be ingested by certain version of the translator. Would this results 
in the translator ICE or error in the translator, or is it something that can 
be diagnosed early by clang or during clang build/installation?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-11-23 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki marked 4 inline comments as done.
linjamaki added a comment.

Thanks for the review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-11-23 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki updated this revision to Diff 389118.
linjamaki added a comment.

Retry push changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h

Index: clang/lib/Driver/ToolChains/HIPSPV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.h
@@ -0,0 +1,102 @@
+//===--- HIPSPV.h - HIP ToolChain Implementations ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+
+#include "SPIRV.h"
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace HIPSPV {
+
+// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
+// device library, then compiles it to SPIR-V in a shared object.
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+
+private:
+  void constructLinkAndEmitSpirvCommand(Compilation , const JobAction ,
+const InputInfoList ,
+const InputInfo ,
+const llvm::opt::ArgList ) const;
+};
+
+} // namespace HIPSPV
+} // namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
+public:
+  HIPSPVToolChain(const Driver , const llvm::Triple ,
+  const ToolChain , const llvm::opt::ArgList );
+
+  const llvm::Triple *getAuxTriple() const override {
+return ();
+  }
+
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+  void addClangWarningOptions(llvm::opt::ArgStringList ) const override;
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
+  void AddHIPIncludeArgs(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  llvm::SmallVector
+  getHIPDeviceLibs(const llvm::opt::ArgList ) const override;
+
+  SanitizerMask getSupportedSanitizers() const override;
+
+  VersionTuple
+  computeMSVCVersion(const Driver *D,
+ const llvm::opt::ArgList ) const override;
+
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault(const llvm::opt::ArgList ) const override {
+return false;
+  }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return false; }
+
+  const ToolChain 
+
+protected:
+  Tool *buildLinker() const override;
+};
+
+} // end namespace toolchains
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -0,0 +1,283 @@
+//===--- HIPSPV.cpp - HIPSPV ToolChain Implementation ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//

[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-11-23 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki updated this revision to Diff 389112.
linjamaki added a comment.

Combine options with append().


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h

Index: clang/lib/Driver/ToolChains/HIPSPV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.h
@@ -0,0 +1,102 @@
+//===--- HIPSPV.h - HIP ToolChain Implementations ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+
+#include "SPIRV.h"
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace HIPSPV {
+
+// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
+// device library, then compiles it to SPIR-V in a shared object.
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+
+private:
+  void constructLinkAndEmitSpirvCommand(Compilation , const JobAction ,
+const InputInfoList ,
+const InputInfo ,
+const llvm::opt::ArgList ) const;
+};
+
+} // namespace HIPSPV
+} // namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
+public:
+  HIPSPVToolChain(const Driver , const llvm::Triple ,
+  const ToolChain , const llvm::opt::ArgList );
+
+  const llvm::Triple *getAuxTriple() const override {
+return ();
+  }
+
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+  void addClangWarningOptions(llvm::opt::ArgStringList ) const override;
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
+  void AddHIPIncludeArgs(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  llvm::SmallVector
+  getHIPDeviceLibs(const llvm::opt::ArgList ) const override;
+
+  SanitizerMask getSupportedSanitizers() const override;
+
+  VersionTuple
+  computeMSVCVersion(const Driver *D,
+ const llvm::opt::ArgList ) const override;
+
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault(const llvm::opt::ArgList ) const override {
+return false;
+  }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return false; }
+
+  const ToolChain 
+
+protected:
+  Tool *buildLinker() const override;
+};
+
+} // end namespace toolchains
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -0,0 +1,288 @@
+//===--- HIPSPV.cpp - HIPSPV ToolChain Implementation ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//

[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-11-22 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM in general, modulo push_back/append nits.




Comment at: clang/include/clang/Driver/Options.td:3701
   " do not include the default CUDA/HIP wrapper headers">;
+def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">,
+  HelpText<"Do not include the default HIP wrapper headers">;

linjamaki wrote:
> tra wrote:
> > Is the idea to still add relevant include paths to the wrappers and SDK 
> > headers, but not `-include` the wrapper?
> > 
> > If that's the case, it should probably be generalized into 
> > `-nogpuwrapperinc` and apply to both CUDA and HIP.
> > 
> > Is the idea to still add relevant include paths to the wrappers and SDK 
> > headers, but not `-include` the wrapper?
> > 
> Include paths are meant to be excluded too. I’ll fix the option description.
> 
> > If that's the case, it should probably be generalized into 
> > `-nogpuwrapperinc` and apply to both CUDA and HIP.
> > 
> I don’t see an immediate need to generalize the option as I don’t think there 
> will be a need for it in the CUDA path. The option could be generalized later 
> if the need comes (add generalized option, set -nohipwrapperinc to be alias 
> to it).
> 
Fair enough. Indeed, without the wrappers, we will not be able to parse CUDA 
SDK headers.



Comment at: clang/lib/Driver/ToolChains/HIPSPV.cpp:145
+
+  CC1Args.push_back("-fcuda-allow-variadic-functions");
+

Nit: combine with `-fcuda-is-device` into `append({})`



Comment at: clang/lib/Driver/ToolChains/HIPSPV.cpp:151-152
+ options::OPT_fvisibility_ms_compat)) {
+CC1Args.append({"-fvisibility", "hidden"});
+CC1Args.push_back("-fapply-global-visibility-to-externs");
+  }

Nit: Combine all unconditional `push_back()` calls  into `append()`;



Comment at: clang/lib/Driver/ToolChains/HIPSPV.cpp:164-165
+  // TODO: Allow autovectorization when SPIR-V backend arrives.
+  CC1Args.append({"-mllvm", "-vectorize-loops=false"});
+  CC1Args.append({"-mllvm", "-vectorize-slp=false"});
+}

Nit: combine into single `append`.



Comment at: clang/lib/Driver/ToolChains/HIPSPV.cpp:209-210
+  llvm::sys::path::append(P, "include");
+  CC1Args.push_back("-isystem");
+  CC1Args.push_back(DriverArgs.MakeArgString(P));
+}

-> `append({})`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-11-18 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

LGTM. I will leave to @tra about -nohipwrapperinc


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-11-16 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki added a comment.

Gentle ping.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-11-16 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki updated this revision to Diff 387508.
linjamaki added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h

Index: clang/lib/Driver/ToolChains/HIPSPV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.h
@@ -0,0 +1,102 @@
+//===--- HIPSPV.h - HIP ToolChain Implementations ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+
+#include "SPIRV.h"
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace HIPSPV {
+
+// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
+// device library, then compiles it to SPIR-V in a shared object.
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+
+private:
+  void constructLinkAndEmitSpirvCommand(Compilation , const JobAction ,
+const InputInfoList ,
+const InputInfo ,
+const llvm::opt::ArgList ) const;
+};
+
+} // namespace HIPSPV
+} // namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
+public:
+  HIPSPVToolChain(const Driver , const llvm::Triple ,
+  const ToolChain , const llvm::opt::ArgList );
+
+  const llvm::Triple *getAuxTriple() const override {
+return ();
+  }
+
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+  void addClangWarningOptions(llvm::opt::ArgStringList ) const override;
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
+  void AddHIPIncludeArgs(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  llvm::SmallVector
+  getHIPDeviceLibs(const llvm::opt::ArgList ) const override;
+
+  SanitizerMask getSupportedSanitizers() const override;
+
+  VersionTuple
+  computeMSVCVersion(const Driver *D,
+ const llvm::opt::ArgList ) const override;
+
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault(const llvm::opt::ArgList ) const override {
+return false;
+  }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return false; }
+
+  const ToolChain 
+
+protected:
+  Tool *buildLinker() const override;
+};
+
+} // end namespace toolchains
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -0,0 +1,288 @@
+//===--- HIPSPV.cpp - HIPSPV ToolChain Implementation ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//

[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-10-28 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki updated this revision to Diff 382932.
linjamaki added a comment.

Update for changes in D112404 .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h

Index: clang/lib/Driver/ToolChains/HIPSPV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.h
@@ -0,0 +1,100 @@
+//===--- HIPSPV.h - HIP ToolChain Implementations ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+
+#include "SPIRV.h"
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace HIPSPV {
+
+// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
+// device library, then compiles it to SPIR-V in a shared object.
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+
+private:
+  void constructLinkAndEmitSpirvCommand(Compilation , const JobAction ,
+const InputInfoList ,
+const InputInfo ,
+const llvm::opt::ArgList ) const;
+};
+
+} // namespace HIPSPV
+} // namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
+public:
+  HIPSPVToolChain(const Driver , const llvm::Triple ,
+  const ToolChain , const llvm::opt::ArgList );
+
+  const llvm::Triple *getAuxTriple() const override {
+return ();
+  }
+
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+  void addClangWarningOptions(llvm::opt::ArgStringList ) const override;
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
+  void AddHIPIncludeArgs(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  llvm::SmallVector
+  getHIPDeviceLibs(const llvm::opt::ArgList ) const override;
+
+  SanitizerMask getSupportedSanitizers() const override;
+
+  VersionTuple
+  computeMSVCVersion(const Driver *D,
+ const llvm::opt::ArgList ) const override;
+
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return false; }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return false; }
+
+  const ToolChain 
+
+protected:
+  Tool *buildLinker() const override;
+};
+
+} // end namespace toolchains
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -0,0 +1,288 @@
+//===--- HIPSPV.cpp - HIPSPV ToolChain Implementation ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//

[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-10-26 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki added a comment.

Gentle ping. Is anything needed to be addressed to get this patch accepted?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-10-25 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki updated this revision to Diff 381854.
linjamaki added a comment.

Rebase and use SPIRV::constructTranslateCommand() to contruct
the LLVM-SPIR-V translation command.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h

Index: clang/lib/Driver/ToolChains/HIPSPV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.h
@@ -0,0 +1,100 @@
+//===--- HIPSPV.h - HIP ToolChain Implementations ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+
+#include "SPIRV.h"
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace HIPSPV {
+
+// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
+// device library, then compiles it to SPIR-V in a shared object.
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+
+private:
+  void constructLinkAndEmitSpirvCommand(Compilation , const JobAction ,
+const InputInfoList ,
+const InputInfo ,
+const llvm::opt::ArgList ) const;
+};
+
+} // namespace HIPSPV
+} // namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
+public:
+  HIPSPVToolChain(const Driver , const llvm::Triple ,
+  const ToolChain , const llvm::opt::ArgList );
+
+  const llvm::Triple *getAuxTriple() const override {
+return ();
+  }
+
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+  void addClangWarningOptions(llvm::opt::ArgStringList ) const override;
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
+  void AddHIPIncludeArgs(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  llvm::SmallVector
+  getHIPDeviceLibs(const llvm::opt::ArgList ) const override;
+
+  SanitizerMask getSupportedSanitizers() const override;
+
+  VersionTuple
+  computeMSVCVersion(const Driver *D,
+ const llvm::opt::ArgList ) const override;
+
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return false; }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return false; }
+
+  const ToolChain 
+
+protected:
+  Tool *buildLinker() const override;
+};
+
+} // end namespace toolchains
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -0,0 +1,293 @@
+//===--- HIPSPV.cpp - HIPSPV ToolChain Implementation ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-10-13 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D110618#3054257 , 
@pekka.jaaskelainen wrote:

>> I don't feel it is different for OpenCL though... I am not in favour of 
>> repeating the same functionality for every language since the requirement 
>> will be likely identical. There is no timeline for when this functionality 
>> will be dropped so we have to assume that even though temporary it might be 
>> a solution for long enough.
>
> If it is likely the SPIR-V backend won’t land soon and it is expected that 
> also other languages might benefit from the calls to the llvm-spirv tool, the 
> functionality to do so would be better placed in a more generally useful 
> place. Do you have suggestions where this functionality could be moved?
>
> I believe it concerns mostly the call to the llvm-spriv (this is sought in 
> PATH, not given via a command line parameter) inside 
> constructEmitSpirvCommand(). This could be extracted to another function in a 
> utility library so it could be accessed by other languages/tools in the 
> future. Does it sound OK?

I believe this is indeed the most common functionality at this point, so if we 
could factor it out already now it would make sense. However, towards the 
common tooling we would probably need to create a special Tool/ToolChain for 
SPIR-V which could be derived from or used for the languages/toochains that 
target SPIR-V generation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-10-11 Thread Pekka Jääskeläinen via Phabricator via cfe-commits
pekka.jaaskelainen added a comment.

> I don't feel it is different for OpenCL though... I am not in favour of 
> repeating the same functionality for every language since the requirement 
> will be likely identical. There is no timeline for when this functionality 
> will be dropped so we have to assume that even though temporary it might be a 
> solution for long enough.

If it is likely the SPIR-V backend won’t land soon and it is expected that also 
other languages might benefit from the calls to the llvm-spirv tool, the 
functionality to do so would be better placed in a more generally useful place. 
Do you have suggestions where this functionality could be moved?

I believe it concerns mostly the call to the llvm-spriv (this is sought in 
PATH, not given via a command line parameter) inside 
constructEmitSpirvCommand(). This could be extracted to another function in a 
utility library so it could be accessed by other languages/tools in the future. 
Does it sound OK?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-10-06 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D110618#3039275 , @linjamaki wrote:

> In D110618#3032899 , @Anastasia 
> wrote:
>
>> Considering that SPIR-V translation step is also required for other 
>> languages would it make sense to add `llvm-spirv` as a common tool like for 
>> example C/C++ linkers and create a bit of common infrastructure? It might be 
>> something we can do as a separate step too but it would be good to make sure 
>> nothing prevents us from doing this in the future... We should probably also 
>> think about the command line interface unification as it probably doesn't 
>> make sense for every language to add their own flags for locating SPIR-V 
>> translator.
>
> I don’t think it would work out well. llvm-spirv (or other tool relying on 
> LLVM bitcode input) and LLVM may have version differences that cause obscure 
> error cases - like newer LLVM producing bitcode with new features the tools 
> are not expecting and ready for them. The usage of llvm-spirv tool in the 
> HIPSPV tool chain is not intended to be a longer term solution due to this 
> shortcoming.

I don't feel it is different for OpenCL though... I am not in favour of 
repeating the same functionality for every language since the requirement will 
be likely identical. There is no timeline for when this functionality will be 
dropped so we have to assume that even though temporary it might be a solution 
for long enough.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-10-04 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki updated this revision to Diff 376822.
linjamaki added a comment.

Update option description.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h

Index: clang/lib/Driver/ToolChains/HIPSPV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.h
@@ -0,0 +1,99 @@
+//===--- HIPSPV.h - HIP ToolChain Implementations ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace HIPSPV {
+
+// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
+// device library, then compiles it to SPIR-V in a shared object.
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+
+private:
+  void constructEmitSpirvCommand(Compilation , const JobAction ,
+ const InputInfoList ,
+ const InputInfo ,
+ const llvm::opt::ArgList ) const;
+};
+
+} // namespace HIPSPV
+} // namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
+public:
+  HIPSPVToolChain(const Driver , const llvm::Triple ,
+  const ToolChain , const llvm::opt::ArgList );
+
+  const llvm::Triple *getAuxTriple() const override {
+return ();
+  }
+
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+  void addClangWarningOptions(llvm::opt::ArgStringList ) const override;
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
+  void AddHIPIncludeArgs(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  llvm::SmallVector
+  getHIPDeviceLibs(const llvm::opt::ArgList ) const override;
+
+  SanitizerMask getSupportedSanitizers() const override;
+
+  VersionTuple
+  computeMSVCVersion(const Driver *D,
+ const llvm::opt::ArgList ) const override;
+
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const override { return false; }
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return false; }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return false; }
+
+  const ToolChain 
+
+protected:
+  Tool *buildLinker() const override;
+};
+
+} // end namespace toolchains
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -0,0 +1,290 @@
+//===--- HIPSPV.cpp - HIPSPV ToolChain Implementation ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "HIPSPV.h"
+#include 

[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-10-04 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki added a comment.

In D110618#3032899 , @Anastasia wrote:

> Considering that SPIR-V translation step is also required for other languages 
> would it make sense to add `llvm-spirv` as a common tool like for example 
> C/C++ linkers and create a bit of common infrastructure? It might be 
> something we can do as a separate step too but it would be good to make sure 
> nothing prevents us from doing this in the future... We should probably also 
> think about the command line interface unification as it probably doesn't 
> make sense for every language to add their own flags for locating SPIR-V 
> translator.

I don’t think it would work out well. llvm-spirv (or other tool relying on LLVM 
bitcode input) and LLVM may have version differences that cause obscure error 
cases - like newer LLVM producing bitcode with new features the tools are not 
expecting and ready for them. The usage of llvm-spirv tool in the HIPSPV tool 
chain is not intended to be a longer term solution due to this shortcoming.

> Another question I have is whether `--hipspv-pass-plugin` would be needed 
> when we switch to SPIR-V backend or is this something that would be 
> integrated fully upstream eventually. Then we might need to think more of the 
> suitable transition path.

It’s too early to say if we can integrate --hipspv-pass-plugin fully in the 
future. It would be the preferred outcome. We are not finished with the HIP 
expanders we need for supporting various HIP features so we don’t know for 
certain what will be the outcome for the integration. It’s possible that some 
of the solutions are going to be tightly coupled with runtimes (HIPLZ, HIPCL) 
and others that may not generalize for different SPIR-V execution environments.




Comment at: clang/include/clang/Driver/Options.td:3701
   " do not include the default CUDA/HIP wrapper headers">;
+def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">,
+  HelpText<"Do not include the default HIP wrapper headers">;

tra wrote:
> Is the idea to still add relevant include paths to the wrappers and SDK 
> headers, but not `-include` the wrapper?
> 
> If that's the case, it should probably be generalized into `-nogpuwrapperinc` 
> and apply to both CUDA and HIP.
> 
> Is the idea to still add relevant include paths to the wrappers and SDK 
> headers, but not `-include` the wrapper?
> 
Include paths are meant to be excluded too. I’ll fix the option description.

> If that's the case, it should probably be generalized into `-nogpuwrapperinc` 
> and apply to both CUDA and HIP.
> 
I don’t see an immediate need to generalize the option as I don’t think there 
will be a need for it in the CUDA path. The option could be generalized later 
if the need comes (add generalized option, set -nohipwrapperinc to be alias to 
it).



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-09-30 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

Considering that SPIR-V translation step is also required for other languages 
would it make sense to add `llvm-spirv` as a common tool like for example C/C++ 
linkers and create a bit of common infrastructure? It might be something we can 
do as a separate step too but it would be good to make sure nothing prevents us 
from doing this in the future... We should probably also think about the 
command line interface unification as it probably doesn't make sense for every 
language to add their own flags for locating SPIR-V translator.

Another question I have is whether `--hipspv-pass-plugin` would be needed when 
we switch to SPIR-V backend or is this something that would be integrated fully 
upstream eventually. Then we might need to think more of the suitable 
transition path.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-09-29 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3701
   " do not include the default CUDA/HIP wrapper headers">;
+def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">,
+  HelpText<"Do not include the default HIP wrapper headers">;

Is the idea to still add relevant include paths to the wrappers and SDK 
headers, but not `-include` the wrapper?

If that's the case, it should probably be generalized into `-nogpuwrapperinc` 
and apply to both CUDA and HIP.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110618/new/

https://reviews.llvm.org/D110618

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


[PATCH] D110618: [HIPSPV][2/4] Add HIPSPV tool chain

2021-09-28 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki created this revision.
Herald added subscribers: dang, kerbowa, yaxunl, mgorny, nhaehnle, jvesely.
linjamaki updated this revision to Diff 375526.
linjamaki added a comment.
linjamaki published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Style fixes.


This patch adds a new tool chain, HIPSPVToolChain, for emitting HIP
device code as SPIR-V binary. The SPIR-V binary is emitted by using an
external tool, SPIRV-LLVM-Translator, temporarily. We intend to switch
the translator to the llc tool when the SPIR-V backend lands on LLVM
and proves to work well on HIP implementations which consume SPIR-V.

Before the SPIR-V emission the tool chain loads an optional external
pass plugin, either automatically from a HIP installation or from a
path pointed by --hipspv-pass-plugin, and runs passes that are meant
to expand/lower HIP features that do not have direct counterpart in
SPIR-V (e.g. dynamic shared memory).

Code emission for SPIR-V will be enabled and HIPSPVToolChain tests
will be added in the follow up patch part 3.

Other changes: New option ‘-nohipwrapperinc’ is added to exclude HIP
include wrappers. The reason for the addition is that they cause
compile errors when compiling HIP sources for the host side for HIPCL
and HIPLZ implementations. New option is added to avoid this issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110618

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h

Index: clang/lib/Driver/ToolChains/HIPSPV.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/HIPSPV.h
@@ -0,0 +1,99 @@
+//===--- HIPSPV.h - HIP ToolChain Implementations ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HIPSPV_H
+
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace HIPSPV {
+
+// Runs llvm-link/opt/llc/lld, which links multiple LLVM bitcode, together with
+// device library, then compiles it to SPIR-V in a shared object.
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("HIPSPV::Linker", "hipspv-link", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;
+
+private:
+  void constructEmitSpirvCommand(Compilation , const JobAction ,
+ const InputInfoList ,
+ const InputInfo ,
+ const llvm::opt::ArgList ) const;
+};
+
+} // namespace HIPSPV
+} // namespace tools
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY HIPSPVToolChain final : public ToolChain {
+public:
+  HIPSPVToolChain(const Driver , const llvm::Triple ,
+  const ToolChain , const llvm::opt::ArgList );
+
+  const llvm::Triple *getAuxTriple() const override {
+return ();
+  }
+
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+  void addClangWarningOptions(llvm::opt::ArgStringList ) const override;
+  CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList ) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
+  void AddHIPIncludeArgs(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  llvm::SmallVector
+  getHIPDeviceLibs(const llvm::opt::ArgList ) const override;
+
+  SanitizerMask getSupportedSanitizers() const override;
+
+  VersionTuple
+  computeMSVCVersion(const Driver *D,
+ const llvm::opt::ArgList ) const override;
+
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+  bool IsMathErrnoDefault() const