diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6736,6 +6736,8 @@ def dxc_Group : OptionGroup<"">, Flags<[DXCOption]>, HelpText<"dxc compatibility options">; +class DXCFlag : Option<["/", "-"], name, KIND_FLAG>, + Group, Flags<[DXCOption, NoXarchOption]>; class DXCJoinedOrSeparate : Option<["/", "-"], name, KIND_JOINED_OR_SEPARATE>, Group, Flags<[DXCOption, NoXarchOption]>; @@ -6760,3 +6762,8 @@ "lib_6_3, lib_6_4, lib_6_5, lib_6_6, lib_6_7, lib_6_x," "ms_6_5, ms_6_6, ms_6_7," "as_6_5, as_6_6, as_6_7">; +def emit_pristine_llvm : DXCFlag<"emit-pristine-llvm">, + HelpText<"Emit pristine LLVM IR from the frontend by not running any LLVM passes at all." + "Same as -S + -emit-llvm + -disable-llvm-passes.">; +def fcgl : DXCFlag<"fcgl">, Alias, + HelpText<"Emit pristine LLVM IR from the frontend by not running any LLVM passes at all.">; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3470,7 +3470,9 @@ static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs, types::ID InputType) { - const unsigned ForwardedArguments[] = {options::OPT_dxil_validator_version}; + const unsigned ForwardedArguments[] = {options::OPT_dxil_validator_version, + options::OPT_S, options::OPT_emit_llvm, + options::OPT_disable_llvm_passes}; for (const auto &Arg : ForwardedArguments) if (const auto *A = Args.getLastArg(Arg)) diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp --- a/clang/lib/Driver/ToolChains/HLSL.cpp +++ b/clang/lib/Driver/ToolChains/HLSL.cpp @@ -169,6 +169,15 @@ if (!isLegalValidatorVersion(ValVerStr, getDriver())) continue; } + if (A->getOption().getID() == options::OPT_emit_pristine_llvm) { + // Translate fcgl into -S -emit-llvm and -disable-llvm-passes. + DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_S)); + DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_emit_llvm)); + DAL->AddFlagArg(nullptr, + Opts.getOption(options::OPT_disable_llvm_passes)); + A->claim(); + continue; + } DAL->append(A); } // Add default validator version if not set. diff --git a/clang/test/Driver/dxc_fcgl.hlsl b/clang/test/Driver/dxc_fcgl.hlsl new file mode 100644 --- /dev/null +++ b/clang/test/Driver/dxc_fcgl.hlsl @@ -0,0 +1,5 @@ +// RUN: %clang_dxc -fcgl foo.hlsl -### %s 2>&1 | FileCheck %s + +// Make sure fcgl option flag which translated into "-S" "-emit-llvm" "-disable-llvm-passes". +// CHECK:"-S" "-emit-llvm" "-disable-llvm-passes" +