[PATCH] D130858: [HLSL] emit-obj when set output.

Xiang Li via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 31 15:18:13 PDT 2022


python3kgae created this revision.
python3kgae added reviewers: amccarth, craig.topper, hans, rnk, stefan_reinalter, beanz, pow2clk, bogner.
Herald added subscribers: Anastasia, StephenFan.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

When not set output, set default output to stdout.
When set output with -Fo and no -fcgl, set -emit-obj to generate dx container.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130858

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/HLSL.cpp
  clang/test/Driver/dxc_Fo.hlsl


Index: clang/test/Driver/dxc_Fo.hlsl
===================================================================
--- /dev/null
+++ clang/test/Driver/dxc_Fo.hlsl
@@ -0,0 +1,15 @@
+// RUN: %clang_dxc -T lib_6_7 foo.hlsl -### %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
+// RUN: %clang_dxc -fcgl -T lib_6_7 foo.hlsl -### %s 2>&1 | FileCheck %s --check-prefix=FCGL
+// RUN: %clang_dxc  -T lib_6_7 foo.hlsl -Fo foo.dxc -### %s 2>&1 | FileCheck %s --check-prefix=EMITOBJ
+
+
+// Make sure default use "-" as output and not emit obj.
+// DEFAULT-NOT:"-emit-obj"
+// DEFAULT:"-o" "-"
+
+// Make sure -fcgl without -Fo use "-" as output.
+// FCGL:"-o" "-"
+
+
+// Make sure emit-obj when set -Fo.
+// EMITOBJ:"-emit-obj"
Index: clang/lib/Driver/ToolChains/HLSL.cpp
===================================================================
--- clang/lib/Driver/ToolChains/HLSL.cpp
+++ clang/lib/Driver/ToolChains/HLSL.cpp
@@ -169,6 +169,15 @@
     }
     DAL->append(A);
   }
+
+  if (DAL->hasArg(options::OPT_o)) {
+    // When run the whole pipeline.
+    if (!DAL->hasArg(options::OPT_emit_llvm))
+      // Emit obj if write to file.
+      DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_emit_obj));
+  } else
+    DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_o), "-");
+
   // Add default validator version if not set.
   // TODO: remove this once read validator version from validator.
   if (!DAL->hasArg(options::OPT_dxil_validator_version)) {
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3513,6 +3513,7 @@
                                          options::OPT_I,
                                          options::OPT_S,
                                          options::OPT_emit_llvm,
+                                         options::OPT_emit_obj,
                                          options::OPT_disable_llvm_passes,
                                          options::OPT_fnative_half_type};
 
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5595,6 +5595,9 @@
     return "-";
   }
 
+  if (IsDXCMode() && !C.getArgs().hasArg(options::OPT_o))
+    return "-";
+
   // Is this the assembly listing for /FA?
   if (JA.getType() == types::TY_PP_Asm &&
       (C.getArgs().hasArg(options::OPT__SLASH_FA) ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130858.448890.patch
Type: text/x-patch
Size: 2498 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220731/9e289e15/attachment.bin>


More information about the cfe-commits mailing list