@@ -5429,6 +5429,36 @@ static void handleTimeTrace(Compilation &C, const ArgList &Args,
54295429 C.addResultFile (ResultFile, JA);
54305430}
54315431
5432+ static void handleVFSTrace (Compilation &C, const ArgList &Args,
5433+ const JobAction *JA, const char *BaseInput,
5434+ const InputInfo &Result) {
5435+ Arg *A = Args.getLastArg (options::OPT_fvfs_trace, options::OPT_fvfs_trace_EQ);
5436+ if (!A)
5437+ return ;
5438+ SmallString<128 > Path;
5439+ if (A->getOption ().matches (options::OPT_fvfs_trace_EQ)) {
5440+ Path = A->getValue ();
5441+ if (llvm::sys::fs::is_directory (Path)) {
5442+ SmallString<128 > Tmp (Result.getFilename ());
5443+ llvm::sys::path::replace_extension (Tmp, " vfs.txt" );
5444+ llvm::sys::path::append (Path, llvm::sys::path::filename (Tmp));
5445+ }
5446+ } else {
5447+ if (Arg *DumpDir = Args.getLastArgNoClaim (options::OPT_dumpdir)) {
5448+ // The trace file is ${dumpdir}${basename}.vfs.txt. Note that dumpdir may
5449+ // not end with a path separator.
5450+ Path = DumpDir->getValue ();
5451+ Path += llvm::sys::path::filename (BaseInput);
5452+ } else {
5453+ Path = Result.getFilename ();
5454+ }
5455+ llvm::sys::path::replace_extension (Path, " vfs.txt" );
5456+ }
5457+ const char *ResultFile = C.getArgs ().MakeArgString (Path);
5458+ C.addVFSTraceFile (ResultFile, JA);
5459+ C.addResultFile (ResultFile, JA);
5460+ }
5461+
54325462InputInfoList Driver::BuildJobsForActionNoCache (
54335463 Compilation &C, const Action *A, const ToolChain *TC, StringRef BoundArch,
54345464 bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput,
@@ -5678,8 +5708,10 @@ InputInfoList Driver::BuildJobsForActionNoCache(
56785708 AtTopLevel, MultipleArchs,
56795709 OffloadingPrefix),
56805710 BaseInput);
5681- if (T->canEmitIR () && OffloadingPrefix.empty ())
5711+ if (T->canEmitIR () && OffloadingPrefix.empty ()) {
56825712 handleTimeTrace (C, Args, JA, BaseInput, Result);
5713+ handleVFSTrace (C, Args, JA, BaseInput, Result);
5714+ }
56835715 }
56845716
56855717 if (CCCPrintBindings && !CCGenDiagnostics) {
0 commit comments