@@ -380,18 +380,47 @@ SupplementaryOutputPathsComputer::getSupplementaryOutputPathsFromArguments()
380
380
options::OPT_emit_module_semantic_info_path);
381
381
auto optRecordOutput = getSupplementaryFilenamesFromArguments (
382
382
options::OPT_save_optimization_record_path);
383
+ auto silOutput =
384
+ getSupplementaryFilenamesFromArguments (options::OPT_sil_output_path);
385
+ auto irOutput =
386
+ getSupplementaryFilenamesFromArguments (options::OPT_ir_output_path);
383
387
if (!clangHeaderOutput || !moduleOutput || !moduleDocOutput ||
384
388
!dependenciesFile || !referenceDependenciesFile ||
385
389
!serializedDiagnostics || !loadedModuleTrace || !TBD ||
386
- !moduleInterfaceOutput || !privateModuleInterfaceOutput || !packageModuleInterfaceOutput ||
387
- !moduleSourceInfoOutput || !moduleSummaryOutput || !abiDescriptorOutput ||
388
- !moduleSemanticInfoOutput || !optRecordOutput) {
390
+ !moduleInterfaceOutput || !privateModuleInterfaceOutput ||
391
+ !packageModuleInterfaceOutput || !moduleSourceInfoOutput ||
392
+ !moduleSummaryOutput || !abiDescriptorOutput ||
393
+ !moduleSemanticInfoOutput || !optRecordOutput || !silOutput ||
394
+ !irOutput) {
389
395
return std::nullopt ;
390
396
}
391
397
std::vector<SupplementaryOutputPaths> result;
392
398
393
399
const unsigned N =
394
400
InputsAndOutputs.countOfFilesProducingSupplementaryOutput ();
401
+
402
+ // Find the index of SIL output path matching module name
403
+ auto findSILIndexForModuleName = [&]() -> unsigned {
404
+ if (!InputsAndOutputs.hasPrimaryInputs () && silOutput->size () > 1 ) {
405
+ // In WMO mode with multiple SIL output paths, find the one whose matches
406
+ // module name
407
+ for (unsigned i = 0 ; i < silOutput->size (); ++i) {
408
+ StringRef silPath = (*silOutput)[i];
409
+ if (!silPath.empty ()) {
410
+ StringRef basename = llvm::sys::path::stem (silPath);
411
+ if (basename == ModuleName) {
412
+ return i;
413
+ }
414
+ }
415
+ }
416
+ // If no match found, fall back to first
417
+ return 0 ;
418
+ }
419
+ return 0 ;
420
+ };
421
+
422
+ unsigned silOutputIndex = findSILIndexForModuleName ();
423
+
395
424
for (unsigned i = 0 ; i < N; ++i) {
396
425
SupplementaryOutputPaths sop;
397
426
sop.ClangHeaderOutputPath = (*clangHeaderOutput)[i];
@@ -413,6 +442,8 @@ SupplementaryOutputPathsComputer::getSupplementaryOutputPathsFromArguments()
413
442
sop.ModuleSemanticInfoOutputPath = (*moduleSemanticInfoOutput)[i];
414
443
sop.YAMLOptRecordPath = (*optRecordOutput)[i];
415
444
sop.BitstreamOptRecordPath = (*optRecordOutput)[i];
445
+ sop.SILOutputPath = (*silOutput)[silOutputIndex];
446
+ sop.LLVMIROutputPath = (*irOutput)[i];
416
447
result.push_back (sop);
417
448
}
418
449
return result;
@@ -439,6 +470,15 @@ SupplementaryOutputPathsComputer::getSupplementaryFilenamesFromArguments(
439
470
paths.emplace_back ();
440
471
return paths;
441
472
}
473
+ // Special handling for SIL and IR output paths: allow multiple paths per file
474
+ // type
475
+ else if ((pathID == options::OPT_sil_output_path ||
476
+ pathID == options::OPT_ir_output_path) &&
477
+ paths.size () > N) {
478
+ // For parallel compilation, we can have multiple SIL/IR output paths
479
+ // so return all the paths.
480
+ return paths;
481
+ }
442
482
443
483
if (paths.empty ())
444
484
return std::vector<std::string>(N, std::string ());
@@ -613,6 +653,9 @@ SupplementaryOutputPathsComputer::computeOutputPathsForOneInput(
613
653
file_types::TY_BitstreamOptRecord, " " ,
614
654
defaultSupplementaryOutputPathExcludingExtension);
615
655
656
+ auto SILOutputPath = pathsFromArguments.SILOutputPath ;
657
+ auto LLVMIROutputPath = pathsFromArguments.LLVMIROutputPath ;
658
+
616
659
SupplementaryOutputPaths sop;
617
660
sop.ClangHeaderOutputPath = clangHeaderOutputPath;
618
661
sop.ModuleOutputPath = moduleOutputPath;
@@ -635,6 +678,8 @@ SupplementaryOutputPathsComputer::computeOutputPathsForOneInput(
635
678
sop.ModuleSemanticInfoOutputPath = ModuleSemanticInfoOutputPath;
636
679
sop.YAMLOptRecordPath = YAMLOptRecordPath;
637
680
sop.BitstreamOptRecordPath = bitstreamOptRecordPath;
681
+ sop.SILOutputPath = SILOutputPath;
682
+ sop.LLVMIROutputPath = LLVMIROutputPath;
638
683
return sop;
639
684
}
640
685
@@ -741,18 +786,18 @@ createFromTypeToPathMap(const TypeToPathMap *map) {
741
786
742
787
std::optional<std::vector<SupplementaryOutputPaths>>
743
788
SupplementaryOutputPathsComputer::readSupplementaryOutputFileMap () const {
744
- if (Arg *A = Args.getLastArg (options::OPT_emit_objc_header_path,
745
- options::OPT_emit_module_path,
746
- options::OPT_emit_module_doc_path,
747
- options::OPT_emit_dependencies_path,
748
- options::OPT_emit_reference_dependencies_path,
749
- options::OPT_serialize_diagnostics_path,
750
- options::OPT_emit_loaded_module_trace_path,
751
- options::OPT_emit_module_interface_path,
752
- options::OPT_emit_private_module_interface_path,
753
- options::OPT_emit_package_module_interface_path,
754
- options::OPT_emit_module_source_info_path,
755
- options::OPT_emit_tbd_path )) {
789
+ if (Arg *A = Args.getLastArg (
790
+ options::OPT_emit_objc_header_path, options::OPT_emit_module_path,
791
+ options::OPT_emit_module_doc_path,
792
+ options::OPT_emit_dependencies_path,
793
+ options::OPT_emit_reference_dependencies_path,
794
+ options::OPT_serialize_diagnostics_path,
795
+ options::OPT_emit_loaded_module_trace_path,
796
+ options::OPT_emit_module_interface_path,
797
+ options::OPT_emit_private_module_interface_path,
798
+ options::OPT_emit_package_module_interface_path,
799
+ options::OPT_emit_module_source_info_path, options::OPT_emit_tbd_path ,
800
+ options::OPT_sil_output_path, options::OPT_ir_output_path )) {
756
801
Diags.diagnose (SourceLoc (),
757
802
diag::error_cannot_have_supplementary_outputs,
758
803
A->getSpelling (), " -supplementary-output-file-map" );
0 commit comments