[HLSL] Pass flags to cc1 based on language

Having the flags only pass through if you're using the dxc-driver means
that the clang driver doesn't work for HLSL, which is undesirable. This
change switches to instead passing flags based on the language mode
similar to how OpenCL does it. This allows the clang driver to be used
for HLSL source files as well.

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D133958
This commit is contained in:
Chris Bieneman 2022-09-20 10:41:43 -05:00
parent 837caa99a2
commit 0c89b34337
4 changed files with 12 additions and 4 deletions

View File

@ -95,6 +95,9 @@ namespace types {
/// isOpenCL - Is this an "OpenCL" input.
bool isOpenCL(ID Id);
/// isHLSL - Is this an HLSL input.
bool isHLSL(ID Id);
/// isSrcFile - Is this a source file, i.e. something that still has to be
/// preprocessed. The logic behind this is the same that decides if the first
/// compilation phase is a preprocessing one.

View File

@ -3529,12 +3529,14 @@ static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs,
options::OPT_disable_llvm_passes,
options::OPT_fnative_half_type,
options::OPT_hlsl_entrypoint};
if (!types::isHLSL(InputType))
return;
for (const auto &Arg : ForwardedArguments)
if (const auto *A = Args.getLastArg(Arg))
A->renderAsInput(Args, CmdArgs);
// Add the default headers if dxc_no_stdinc is not set.
if (!Args.hasArg(options::OPT_dxc_no_stdinc))
if (!Args.hasArg(options::OPT_dxc_no_stdinc) &&
!Args.hasArg(options::OPT_nostdinc))
CmdArgs.push_back("-finclude-default-header");
}
@ -6389,8 +6391,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
RenderOpenCLOptions(Args, CmdArgs, InputType);
// Forward hlsl options to -cc1
if (C.getDriver().IsDXCMode())
RenderHLSLOptions(Args, CmdArgs, InputType);
RenderHLSLOptions(Args, CmdArgs, InputType);
if (IsHIP) {
if (Args.hasFlag(options::OPT_fhip_new_launch_api,

View File

@ -286,6 +286,8 @@ bool types::isHIP(ID Id) {
}
}
bool types::isHLSL(ID Id) { return Id == TY_HLSL; }
bool types::isSrcFile(ID Id) {
return Id != TY_Object && getPreprocessedType(Id) != TY_INVALID;
}

View File

@ -1,5 +1,7 @@
// RUN: %clang_dxc -Tlib_6_7 -fcgl -Fo - %s -### 2>&1 | FileCheck %s --check-prefix=STDINC
// RUN: %clang -target dxil-pc-shadermodel6.3-library -o - %s -### 2>&1 | FileCheck %s --check-prefix=STDINC
// RUN: %clang_dxc -Tlib_6_7 -hlsl-no-stdinc -fcgl -Fo - %s -### 2>&1 | FileCheck %s --check-prefix=NOSTDINC
// RUN: %clang -target dxil-pc-shadermodel6.3-library -nostdinc -o - %s -### 2>&1 | FileCheck %s --check-prefix=NOSTDINC
// RUN: %clang -cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -ast-dump -o - %s -verify