diff options
author | Justin Bogner <mail@justinbogner.com> | 2023-08-09 16:10:30 -0700 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2023-08-15 16:37:17 -0700 |
commit | cb6fe61be3dee67bb8b080c73dd2c48f2d0ce2c7 (patch) | |
tree | c0e985118e14220e59a8ae08e8c9f6207b24cf1f /clang/lib/Driver/Driver.cpp | |
parent | e7866ea2125efe4baed98f6f9545966acf1ebad0 (diff) | |
download | llvm-cb6fe61be3dee67bb8b080c73dd2c48f2d0ce2c7.zip llvm-cb6fe61be3dee67bb8b080c73dd2c48f2d0ce2c7.tar.gz llvm-cb6fe61be3dee67bb8b080c73dd2c48f2d0ce2c7.tar.bz2 |
[Driver][DXC] Handle -Fo and -Fc flags
This splits the backend and assemble actions for HLSL inputs and
handles the options in GetNamedOutputPath instead of aliasing `-o`.
This also moves how we default to emitting asm to stdout, since doing
this in the HLSL toolchain rather than the driver pollutes how the
clang driver works as well.
When both options are specified we disable collapsing the assemble
action and attempt to generate both outputs. Note that while this
handles the driver aspects, we can't actually run in that mode for now
since -cc1as doesn't understand DXIL as an input yet.
Differential Revision: https://reviews.llvm.org/D157582
Diffstat (limited to 'clang/lib/Driver/Driver.cpp')
-rw-r--r-- | clang/lib/Driver/Driver.cpp | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 3947ae9..ede9967 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -484,6 +484,10 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const { DAL->append(A); } + // DXC mode quits before assembly if an output object file isn't specified. + if (IsDXCMode() && !Args.hasArg(options::OPT_dxc_Fo)) + DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_S)); + // Enforce -static if -miamcu is present. if (Args.hasFlag(options::OPT_miamcu, options::OPT_mno_iamcu, false)) DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_static)); @@ -5023,7 +5027,8 @@ class ToolSelector final { return TC.useIntegratedAs() && !SaveTemps && !C.getArgs().hasArg(options::OPT_via_file_asm) && !C.getArgs().hasArg(options::OPT__SLASH_FA) && - !C.getArgs().hasArg(options::OPT__SLASH_Fa); + !C.getArgs().hasArg(options::OPT__SLASH_Fa) && + !C.getArgs().hasArg(options::OPT_dxc_Fc); } /// Return true if a preprocessor action can be collapsed. @@ -5776,8 +5781,21 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA, return "-"; } - if (IsDXCMode() && !C.getArgs().hasArg(options::OPT_o)) - return "-"; + if (JA.getType() == types::TY_PP_Asm && + C.getArgs().hasArg(options::OPT_dxc_Fc)) { + StringRef FcValue = C.getArgs().getLastArgValue(options::OPT_dxc_Fc); + // TODO: Should we use `MakeCLOutputFilename` here? If so, we can probably + // handle this as part of the SLASH_Fa handling below. + return C.addResultFile(C.getArgs().MakeArgString(FcValue.str()), &JA); + } + + if (JA.getType() == types::TY_Object && + C.getArgs().hasArg(options::OPT_dxc_Fo)) { + StringRef FoValue = C.getArgs().getLastArgValue(options::OPT_dxc_Fo); + // TODO: Should we use `MakeCLOutputFilename` here? If so, we can probably + // handle this as part of the SLASH_Fo handling below. + return C.addResultFile(C.getArgs().MakeArgString(FoValue.str()), &JA); + } // Is this the assembly listing for /FA? if (JA.getType() == types::TY_PP_Asm && @@ -5791,6 +5809,11 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA, &JA); } + // DXC defaults to standard out when generating assembly. We check this after + // any DXC flags that might specify a file. + if (AtTopLevel && JA.getType() == types::TY_PP_Asm && IsDXCMode()) + return "-"; + bool SpecifiedModuleOutput = C.getArgs().hasArg(options::OPT_fmodule_output) || C.getArgs().hasArg(options::OPT_fmodule_output_EQ); @@ -5809,7 +5832,8 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA, CCGenDiagnostics) { StringRef Name = llvm::sys::path::filename(BaseInput); std::pair<StringRef, StringRef> Split = Name.split('.'); - const char *Suffix = types::getTypeTempSuffix(JA.getType(), IsCLMode()); + const char *Suffix = + types::getTypeTempSuffix(JA.getType(), IsCLMode() || IsDXCMode()); // The non-offloading toolchain on Darwin requires deterministic input // file name for binaries to be deterministic, therefore it needs unique // directory. @@ -5900,7 +5924,8 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA, NamedOutput = MakeCLOutputFilename(C.getArgs(), Val, BaseName, types::TY_Object); } else { - const char *Suffix = types::getTypeTempSuffix(JA.getType(), IsCLMode()); + const char *Suffix = + types::getTypeTempSuffix(JA.getType(), IsCLMode() || IsDXCMode()); assert(Suffix && "All types used for output should have a suffix."); std::string::size_type End = std::string::npos; @@ -5961,7 +5986,8 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA, StringRef Name = llvm::sys::path::filename(BaseInput); std::pair<StringRef, StringRef> Split = Name.split('.'); std::string TmpName = GetTemporaryPath( - Split.first, types::getTypeTempSuffix(JA.getType(), IsCLMode())); + Split.first, + types::getTypeTempSuffix(JA.getType(), IsCLMode() || IsDXCMode())); return C.addTempFile(C.getArgs().MakeArgString(TmpName)); } } |