[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
This commit is contained in:
Xiang Li 2022-07-31 15:16:24 -07:00
parent 3b52341116
commit 549542b494
4 changed files with 28 additions and 0 deletions

View File

@ -5664,6 +5664,9 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
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) ||

View File

@ -3513,6 +3513,7 @@ static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs,
options::OPT_I,
options::OPT_S,
options::OPT_emit_llvm,
options::OPT_emit_obj,
options::OPT_disable_llvm_passes,
options::OPT_fnative_half_type,
options::OPT_hlsl_entrypoint};

View File

@ -175,6 +175,15 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
}
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)) {

View File

@ -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"