@@ -453,8 +453,9 @@ static void countStatsPostSema(UnifiedStatsReporter &Stats,
453
453
C.NumReferencedMemberNames = R->getUsedMembers ().size ();
454
454
}
455
455
456
- if (auto *SF = Instance.getPrimarySourceFile ()) {
457
- countStatsOfSourceFile (Stats, Instance, SF);
456
+ if (!Instance.getPrimarySourceFiles ().empty ()) {
457
+ for (auto SF : Instance.getPrimarySourceFiles ())
458
+ countStatsOfSourceFile (Stats, Instance, SF);
458
459
} else if (auto *M = Instance.getMainModule ()) {
459
460
// No primary source file, but a main module; this is WMO-mode
460
461
for (auto *F : M->getFiles ()) {
@@ -630,8 +631,6 @@ static bool performCompile(CompilerInstance &Instance,
630
631
return Context.hadError ();
631
632
}
632
633
633
- SourceFile *PrimarySourceFile = Instance.getPrimarySourceFile ();
634
-
635
634
// We've been told to dump the AST (either after parsing or type-checking,
636
635
// which is already differentiated in CompilerInstance::performSema()),
637
636
// so dump or print the main source file and return.
@@ -642,7 +641,7 @@ static bool performCompile(CompilerInstance &Instance,
642
641
Action == FrontendOptions::ActionType::DumpScopeMaps ||
643
642
Action == FrontendOptions::ActionType::DumpTypeRefinementContexts ||
644
643
Action == FrontendOptions::ActionType::DumpInterfaceHash) {
645
- SourceFile *SF = PrimarySourceFile ;
644
+ SourceFile *SF = Instance. getPrimarySourceFile () ;
646
645
if (!SF) {
647
646
SourceFileKind Kind = Invocation.getSourceFileKind ();
648
647
SF = &Instance.getMainModule ()->getMainSourceFile (Kind);
@@ -717,9 +716,12 @@ static bool performCompile(CompilerInstance &Instance,
717
716
(void )emitMakeDependencies (Context.Diags , *Instance.getDependencyTracker (),
718
717
opts);
719
718
720
- if (shouldTrackReferences)
721
- emitReferenceDependencies (Context.Diags , Instance.getPrimarySourceFile (),
722
- *Instance.getDependencyTracker (), opts);
719
+ if (shouldTrackReferences) {
720
+ for (auto *SF : Instance.getPrimarySourceFiles ()) {
721
+ emitReferenceDependencies (Context.Diags , SF,
722
+ *Instance.getDependencyTracker (), opts);
723
+ }
724
+ }
723
725
724
726
if (!opts.LoadedModuleTracePath .empty ())
725
727
(void )emitLoadedModuleTrace (Context, *Instance.getDependencyTracker (),
@@ -730,7 +732,8 @@ static bool performCompile(CompilerInstance &Instance,
730
732
if (Context.hadError ()) {
731
733
if (shouldIndex) {
732
734
// Emit the index store data even if there were compiler errors.
733
- if (emitIndexData (PrimarySourceFile, Invocation, Instance))
735
+ if (emitIndexData (Instance.getPrimarySourceFile (),
736
+ Invocation, Instance))
734
737
return true ;
735
738
}
736
739
return true ;
@@ -749,7 +752,8 @@ static bool performCompile(CompilerInstance &Instance,
749
752
return printAsObjC (opts.ObjCHeaderOutputPath , Instance.getMainModule (),
750
753
opts.ImplicitObjCHeaderPath , moduleIsPublic);
751
754
if (shouldIndex) {
752
- if (emitIndexData (PrimarySourceFile, Invocation, Instance))
755
+ if (emitIndexData (Instance.getPrimarySourceFile (),
756
+ Invocation, Instance))
753
757
return true ;
754
758
}
755
759
return Context.hadError ();
@@ -780,7 +784,7 @@ static bool performCompile(CompilerInstance &Instance,
780
784
return SASTF && SASTF->isSIB ();
781
785
};
782
786
if (opts.Inputs .hasPrimaryInputs ()) {
783
- FileUnit *PrimaryFile = PrimarySourceFile ;
787
+ FileUnit *PrimaryFile = Instance. getPrimarySourceFile () ;
784
788
if (!PrimaryFile) {
785
789
for (FileUnit *fileUnit : Instance.getMainModule ()->getFiles ()) {
786
790
if (auto SASTF = dyn_cast<SerializedASTFile>(fileUnit)) {
@@ -827,8 +831,7 @@ static bool performCompile(CompilerInstance &Instance,
827
831
if (Invocation.getSILOptions ().LinkMode == SILOptions::LinkAll)
828
832
performSILLinking (SM.get (), true );
829
833
830
- auto DC = PrimarySourceFile ? ModuleOrSourceFile (PrimarySourceFile) :
831
- Instance.getMainModule ();
834
+ auto DC = Instance.getPrimarySourceFileOrMainModule ();
832
835
if (!opts.ModuleOutputPath .empty ()) {
833
836
SerializationOptions serializationOpts;
834
837
serializationOpts.OutputPath = opts.ModuleOutputPath .c_str ();
@@ -884,8 +887,7 @@ static bool performCompile(CompilerInstance &Instance,
884
887
885
888
auto SerializeSILModuleAction = [&]() {
886
889
if (!opts.ModuleOutputPath .empty () || !opts.ModuleDocOutputPath .empty ()) {
887
- auto DC = PrimarySourceFile ? ModuleOrSourceFile (PrimarySourceFile)
888
- : Instance.getMainModule ();
890
+ auto DC = Instance.getPrimarySourceFileOrMainModule ();
889
891
if (!opts.ModuleOutputPath .empty ()) {
890
892
SerializationOptions serializationOpts;
891
893
serializationOpts.OutputPath = opts.ModuleOutputPath .c_str ();
@@ -956,8 +958,9 @@ static bool performCompile(CompilerInstance &Instance,
956
958
957
959
// Get the main source file's private discriminator and attach it to
958
960
// the compile unit's flags.
959
- if (PrimarySourceFile) {
960
- Identifier PD = PrimarySourceFile->getPrivateDiscriminator ();
961
+ if (IRGenOpts.DebugInfoKind != IRGenDebugInfoKind::None &&
962
+ Instance.getPrimarySourceFile ()) {
963
+ Identifier PD = Instance.getPrimarySourceFile ()->getPrivateDiscriminator ();
961
964
if (!PD.empty ())
962
965
IRGenOpts.DWARFDebugFlags += (" -private-discriminator " +PD.str ()).str ();
963
966
}
@@ -968,8 +971,7 @@ static bool performCompile(CompilerInstance &Instance,
968
971
}
969
972
970
973
if (Action == FrontendOptions::ActionType::EmitSIB) {
971
- auto DC = PrimarySourceFile ? ModuleOrSourceFile (PrimarySourceFile) :
972
- Instance.getMainModule ();
974
+ auto DC = Instance.getPrimarySourceFileOrMainModule ();
973
975
if (!opts.ModuleOutputPath .empty ()) {
974
976
SerializationOptions serializationOpts;
975
977
serializationOpts.OutputPath = opts.ModuleOutputPath .c_str ();
@@ -988,7 +990,8 @@ static bool performCompile(CompilerInstance &Instance,
988
990
if (Action == FrontendOptions::ActionType::MergeModules ||
989
991
Action == FrontendOptions::ActionType::EmitModuleOnly) {
990
992
if (shouldIndex) {
991
- if (emitIndexData (PrimarySourceFile, Invocation, Instance))
993
+ if (emitIndexData (Instance.getPrimarySourceFile (),
994
+ Invocation, Instance))
992
995
return true ;
993
996
}
994
997
return Context.hadError ();
@@ -1019,7 +1022,8 @@ static bool performCompile(CompilerInstance &Instance,
1019
1022
// TODO: remove once the frontend understands what action it should perform
1020
1023
IRGenOpts.OutputKind = getOutputKind (Action);
1021
1024
if (Action == FrontendOptions::ActionType::Immediate) {
1022
- assert (!PrimarySourceFile && " -i doesn't work in -primary-file mode" );
1025
+ assert (Instance.getPrimarySourceFiles ().empty () &&
1026
+ " -i doesn't work in -primary-file mode" );
1023
1027
IRGenOpts.UseJIT = true ;
1024
1028
IRGenOpts.DebugInfoKind = IRGenDebugInfoKind::Normal;
1025
1029
const ProcessCmdLine &CmdLine = ProcessCmdLine (opts.ImmediateArgv .begin (),
@@ -1040,8 +1044,10 @@ static bool performCompile(CompilerInstance &Instance,
1040
1044
auto &LLVMContext = getGlobalLLVMContext ();
1041
1045
std::unique_ptr<llvm::Module> IRModule;
1042
1046
llvm::GlobalVariable *HashGlobal;
1043
- if (PrimarySourceFile) {
1044
- IRModule = performIRGeneration (IRGenOpts, *PrimarySourceFile, std::move (SM),
1047
+ if (!Instance.getPrimarySourceFiles ().empty ()) {
1048
+ IRModule = performIRGeneration (IRGenOpts,
1049
+ *Instance.getPrimarySourceFile (),
1050
+ std::move (SM),
1045
1051
opts.getSingleOutputFilename (), LLVMContext,
1046
1052
0 , &HashGlobal);
1047
1053
} else {
@@ -1054,7 +1060,7 @@ static bool performCompile(CompilerInstance &Instance,
1054
1060
// Walk the AST for indexing after IR generation. Walking it before seems
1055
1061
// to cause miscompilation issues.
1056
1062
if (shouldIndex) {
1057
- if (emitIndexData (PrimarySourceFile , Invocation, Instance))
1063
+ if (emitIndexData (Instance. getPrimarySourceFile () , Invocation, Instance))
1058
1064
return true ;
1059
1065
}
1060
1066
@@ -1083,8 +1089,9 @@ static bool performCompile(CompilerInstance &Instance,
1083
1089
const auto &SILOpts = Invocation.getSILOptions ();
1084
1090
const auto hasMultipleIGMs = SILOpts.hasMultipleIGMs ();
1085
1091
bool error;
1086
- if (PrimarySourceFile)
1087
- error = validateTBD (PrimarySourceFile, *IRModule, hasMultipleIGMs,
1092
+ if (!Instance.getPrimarySourceFiles ().empty ())
1093
+ error = validateTBD (Instance.getPrimarySourceFile (),
1094
+ *IRModule, hasMultipleIGMs,
1088
1095
allSymbols);
1089
1096
else
1090
1097
error = validateTBD (Instance.getMainModule (), *IRModule, hasMultipleIGMs,
0 commit comments