Skip to content

Commit 549542b

Browse files
committed
[HLSL] emit-obj when set output.
When not set output, set default output to stdout. When set output with -Fo and no -fcgl, set -emit-obj to generate dx container. Reviewed By: beanz Differential Revision: https://reviews.llvm.org/D130858
1 parent 3b52341 commit 549542b

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5664,6 +5664,9 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
56645664
return "-";
56655665
}
56665666

5667+
if (IsDXCMode() && !C.getArgs().hasArg(options::OPT_o))
5668+
return "-";
5669+
56675670
// Is this the assembly listing for /FA?
56685671
if (JA.getType() == types::TY_PP_Asm &&
56695672
(C.getArgs().hasArg(options::OPT__SLASH_FA) ||

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3513,6 +3513,7 @@ static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs,
35133513
options::OPT_I,
35143514
options::OPT_S,
35153515
options::OPT_emit_llvm,
3516+
options::OPT_emit_obj,
35163517
options::OPT_disable_llvm_passes,
35173518
options::OPT_fnative_half_type,
35183519
options::OPT_hlsl_entrypoint};

clang/lib/Driver/ToolChains/HLSL.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
175175
}
176176
DAL->append(A);
177177
}
178+
179+
if (DAL->hasArg(options::OPT_o)) {
180+
// When run the whole pipeline.
181+
if (!DAL->hasArg(options::OPT_emit_llvm))
182+
// Emit obj if write to file.
183+
DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_emit_obj));
184+
} else
185+
DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_o), "-");
186+
178187
// Add default validator version if not set.
179188
// TODO: remove this once read validator version from validator.
180189
if (!DAL->hasArg(options::OPT_dxil_validator_version)) {

clang/test/Driver/dxc_Fo.hlsl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_dxc -T lib_6_7 foo.hlsl -### %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
2+
// RUN: %clang_dxc -fcgl -T lib_6_7 foo.hlsl -### %s 2>&1 | FileCheck %s --check-prefix=FCGL
3+
// RUN: %clang_dxc -T lib_6_7 foo.hlsl -Fo foo.dxc -### %s 2>&1 | FileCheck %s --check-prefix=EMITOBJ
4+
5+
6+
// Make sure default use "-" as output and not emit obj.
7+
// DEFAULT-NOT:"-emit-obj"
8+
// DEFAULT:"-o" "-"
9+
10+
// Make sure -fcgl without -Fo use "-" as output.
11+
// FCGL:"-o" "-"
12+
13+
14+
// Make sure emit-obj when set -Fo.
15+
// EMITOBJ:"-emit-obj"

0 commit comments

Comments
 (0)