@@ -129,10 +129,9 @@ static void optimizeDiagnosticOpts(DiagnosticOptions &Opts,
129129 Opts.Remarks .clear ();
130130}
131131
132- static void optimizeCWD (FileSystemOptions &FSOpts, CodeGenOptions &CGOpts,
133- const std::string &CWD) {
134- FSOpts.WorkingDir .clear ();
135- if (CGOpts.DwarfVersion ) {
132+ static void optimizeCWD (CowCompilerInvocation &BuildInvocation, StringRef CWD) {
133+ BuildInvocation.getMutFileSystemOpts ().WorkingDir .clear ();
134+ if (BuildInvocation.getCodeGenOpts ().DwarfVersion ) {
136135 // It is necessary to explicitly set the DebugCompilationDir
137136 // to a common directory (e.g. root) if IgnoreCWD is true.
138137 // When IgnoreCWD is true, the module's content should not
@@ -145,7 +144,16 @@ static void optimizeCWD(FileSystemOptions &FSOpts, CodeGenOptions &CGOpts,
145144 // ignore the CWD. Thus in such cases,
146145 // CGOpts.DebugCompilationDir is explicitly set to a common
147146 // directory.
148- CGOpts.DebugCompilationDir = llvm::sys::path::root_path (CWD);
147+ // FIXME: It is still excessive to create a copy of
148+ // CodeGenOpts for each module. Since we do not modify the
149+ // CodeGenOpts otherwise per module, the following code
150+ // ends up generating identical CodeGenOpts for each module
151+ // with DebugCompilationDir pointing to the root directory.
152+ // We can optimize this away by creating a _single_ copy of
153+ // CodeGenOpts whose DebugCompilationDir points to the root
154+ // directory and reuse it across modules.
155+ BuildInvocation.getMutCodeGenOpts ().DebugCompilationDir =
156+ llvm::sys::path::root_path (CWD);
149157 }
150158}
151159
@@ -765,8 +773,7 @@ ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
765773 MDC.ScanInstance .getVirtualFileSystem ()
766774 .getCurrentWorkingDirectory ();
767775 if (CWD)
768- optimizeCWD (BuildInvocation.getMutFileSystemOpts (),
769- BuildInvocation.getMutCodeGenOpts (), *CWD);
776+ optimizeCWD (BuildInvocation, *CWD);
770777 }
771778 });
772779
0 commit comments