linjamaki created this revision.
Herald added subscribers: dang, yaxunl.
linjamaki updated this revision to Diff 376838.
linjamaki added a comment.
linjamaki edited the summary of this revision.
linjamaki added a reviewer: Anastasia.
linjamaki updated this revision to Diff 376848.
linjamaki published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Rebase.


linjamaki added a comment.

Remove metavar from --spirv-use-llc.


Add two hidden options for emitting SPIR-V binary via LLC. The options are only 
meant for testing and development.

´--spirv-use-llc´ invokes in-tree llc. Not usable at the moment until the 
SPIR-V backend lands on LLVM.

´--spirv-use-llc=<path-to-llc>´ invokes llc tool given as path. Meant for 
trying out out-of-tree SPIR-V backend.

The HIPSPV tool chain is the only one responding to these options.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110685

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/test/Driver/hipspv-options.hip


Index: clang/test/Driver/hipspv-options.hip
===================================================================
--- /dev/null
+++ clang/test/Driver/hipspv-options.hip
@@ -0,0 +1,12 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// UNSUPPORTED: system-windows
+
+// RUN: %clang -### -target x86_64-linux-gnu --offload=spirv64 \
+// RUN:   --hip-path=%S/Inputs/hipspv -nogpuinc -nogpulib %s \
+// RUN:   --spirv-use-llc=/foo/bar/llc 2>&1 | FileCheck %s
+
+// CHECK-NOT: llvm-spirv
+// CHECK: "/foo/bar/llc" "--mattr=+spirv1.1" "--filetype=obj" "{{.*}}.bc"
+// CHECK-SAME: "-o" "{{.*}}.out"
+
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===================================================================
--- clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -97,6 +97,25 @@
 
   // Emit SPIR-V binary.
 
+  // Use llc. Meant for testing out LLVM SPIR-V backend. Eventually HIPSPV will
+  // switch to use in-tree SPIR-V backend for binary emission.
+  if (auto *A = Args.getLastArg(options::OPT_spirv_use_llc,
+                                options::OPT_spirv_use_llc_EQ)) {
+    assert(A->getNumValues() <= 1);
+    const char *LlcExe = nullptr;
+    if (A->getNumValues() == 1 && !StringRef(A->getValue()).empty())
+      LlcExe = A->getValue();
+    else
+      LlcExe = Args.MakeArgString(getToolChain().GetProgramPath("llc"));
+    ArgStringList LlcArgs{"--mattr=+spirv1.1", "--filetype=obj", TempFile, 
"-o",
+                          Output.getFilename()};
+    C.addCommand(std::make_unique<Command>(JA, *this,
+                                           ResponseFileSupport::None(), LlcExe,
+                                           LlcArgs, Inputs, Output));
+    return;
+  }
+
+  // Use SPIRV-LLVM Translator.
   ArgStringList LlvmSpirvArgs{"-spirv-max-version=1.1", "--spirv-ext=+all",
                               TempFile, "-o", Output.getFilename()};
   const char *LlvmSpirv =
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1528,6 +1528,12 @@
     Group<f_Group>, Flags<[CC1Option]>, MetaVarName<"<directory>">,
     HelpText<"Enable heap memory profiling and dump results into <directory>">;
 
+def spirv_use_llc : Flag<["--"], "spirv-use-llc">, Flags<[HelpHidden]>,
+    HelpText<"Use (in-tree) llc to emit SPIR-V. Use for development and 
testing only.">;
+def spirv_use_llc_EQ : Joined<["--"], "spirv-use-llc=">,
+    MetaVarName<"<path>">, Flags<[HelpHidden]>,
+    HelpText<"Use speficied llc to emit SPIR-V. Use for development and 
testing only.">;
+
 // Begin sanitizer flags. These should all be core options exposed in all 
driver
 // modes.
 let Flags = [CC1Option, CoreOption] in {


Index: clang/test/Driver/hipspv-options.hip
===================================================================
--- /dev/null
+++ clang/test/Driver/hipspv-options.hip
@@ -0,0 +1,12 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// UNSUPPORTED: system-windows
+
+// RUN: %clang -### -target x86_64-linux-gnu --offload=spirv64 \
+// RUN:   --hip-path=%S/Inputs/hipspv -nogpuinc -nogpulib %s \
+// RUN:   --spirv-use-llc=/foo/bar/llc 2>&1 | FileCheck %s
+
+// CHECK-NOT: llvm-spirv
+// CHECK: "/foo/bar/llc" "--mattr=+spirv1.1" "--filetype=obj" "{{.*}}.bc"
+// CHECK-SAME: "-o" "{{.*}}.out"
+
Index: clang/lib/Driver/ToolChains/HIPSPV.cpp
===================================================================
--- clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -97,6 +97,25 @@
 
   // Emit SPIR-V binary.
 
+  // Use llc. Meant for testing out LLVM SPIR-V backend. Eventually HIPSPV will
+  // switch to use in-tree SPIR-V backend for binary emission.
+  if (auto *A = Args.getLastArg(options::OPT_spirv_use_llc,
+                                options::OPT_spirv_use_llc_EQ)) {
+    assert(A->getNumValues() <= 1);
+    const char *LlcExe = nullptr;
+    if (A->getNumValues() == 1 && !StringRef(A->getValue()).empty())
+      LlcExe = A->getValue();
+    else
+      LlcExe = Args.MakeArgString(getToolChain().GetProgramPath("llc"));
+    ArgStringList LlcArgs{"--mattr=+spirv1.1", "--filetype=obj", TempFile, "-o",
+                          Output.getFilename()};
+    C.addCommand(std::make_unique<Command>(JA, *this,
+                                           ResponseFileSupport::None(), LlcExe,
+                                           LlcArgs, Inputs, Output));
+    return;
+  }
+
+  // Use SPIRV-LLVM Translator.
   ArgStringList LlvmSpirvArgs{"-spirv-max-version=1.1", "--spirv-ext=+all",
                               TempFile, "-o", Output.getFilename()};
   const char *LlvmSpirv =
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1528,6 +1528,12 @@
     Group<f_Group>, Flags<[CC1Option]>, MetaVarName<"<directory>">,
     HelpText<"Enable heap memory profiling and dump results into <directory>">;
 
+def spirv_use_llc : Flag<["--"], "spirv-use-llc">, Flags<[HelpHidden]>,
+    HelpText<"Use (in-tree) llc to emit SPIR-V. Use for development and testing only.">;
+def spirv_use_llc_EQ : Joined<["--"], "spirv-use-llc=">,
+    MetaVarName<"<path>">, Flags<[HelpHidden]>,
+    HelpText<"Use speficied llc to emit SPIR-V. Use for development and testing only.">;
+
 // Begin sanitizer flags. These should all be core options exposed in all driver
 // modes.
 let Flags = [CC1Option, CoreOption] in {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to