@@ -355,6 +355,15 @@ namespace driver {
355
355
PendingExecution.insert (Cmd);
356
356
}
357
357
358
+ // Sort for ease of testing
359
+ template <typename Jobs>
360
+ void scheduleCommandsInSortedOrder (const Jobs &jobs) {
361
+ llvm::SmallVector<const Job *, 16 > sortedJobs;
362
+ Comp.sortJobsToMatchCompilationInputs (jobs, sortedJobs);
363
+ for (const Job *Cmd : sortedJobs)
364
+ scheduleCommandIfNecessaryAndPossible (Cmd);
365
+ }
366
+
358
367
void addPendingJobToTaskQueue (const Job *Cmd) {
359
368
// FIXME: Failing here should not take down the whole process.
360
369
bool success =
@@ -393,8 +402,7 @@ namespace driver {
393
402
<< LogJobArray (AllBlocked) << " \n " ;
394
403
}
395
404
BlockingCommands.erase (BlockedIter);
396
- for (auto *Blocked : AllBlocked)
397
- scheduleCommandIfNecessaryAndPossible (Blocked);
405
+ scheduleCommandsInSortedOrder (AllBlocked);
398
406
}
399
407
}
400
408
@@ -496,8 +504,7 @@ namespace driver {
496
504
break ;
497
505
dependencyLoadFailed (DependenciesFile);
498
506
// Better try compiling whatever was waiting on more info.
499
- for (const Job *Cmd : DeferredCommands)
500
- scheduleCommandIfNecessaryAndPossible (Cmd);
507
+ scheduleCommandsInSortedOrder (DeferredCommands);
501
508
DeferredCommands.clear ();
502
509
break ;
503
510
@@ -696,18 +703,9 @@ namespace driver {
696
703
noteBuildingJobs (DependentsInEffect, useRangesForScheduling,
697
704
" because of dependencies discovered later" );
698
705
699
- // Sort dependents for more deterministic behavior
700
- llvm::SmallVector<const Job *, 16 > UnsortedDependents;
701
- for (const Job *j : DependentsInEffect)
702
- UnsortedDependents.push_back (j);
703
- llvm::SmallVector<const Job *, 16 > SortedDependents;
704
- Comp.sortJobsToMatchCompilationInputs (UnsortedDependents,
705
- SortedDependents);
706
-
707
- for (const Job *Cmd : SortedDependents) {
706
+ scheduleCommandsInSortedOrder (DependentsInEffect);
707
+ for (const Job *Cmd : DependentsInEffect)
708
708
DeferredCommands.erase (Cmd);
709
- scheduleCommandIfNecessaryAndPossible (Cmd);
710
- }
711
709
return TaskFinishedResponse::ContinueExecution;
712
710
}
713
711
@@ -2087,17 +2085,22 @@ void Compilation::addDependencyPathOrCreateDummy(
2087
2085
}
2088
2086
}
2089
2087
2088
+ template <typename JobCollection>
2090
2089
void Compilation::sortJobsToMatchCompilationInputs (
2091
- const ArrayRef< const Job *> unsortedJobs,
2090
+ const JobCollection & unsortedJobs,
2092
2091
SmallVectorImpl<const Job *> &sortedJobs) const {
2093
2092
llvm::DenseMap<StringRef, const Job *> jobsByInput;
2094
2093
for (const Job *J : unsortedJobs) {
2095
- const CompileJobAction *CJA = cast<CompileJobAction>(&J->getSource ());
2096
- const InputAction *IA = CJA->findSingleSwiftInput ();
2097
- auto R =
2098
- jobsByInput.insert (std::make_pair (IA->getInputArg ().getValue (), J));
2099
- assert (R.second );
2100
- (void )R;
2094
+ // Only worry about sorting compilation jobs
2095
+ if (const CompileJobAction *CJA =
2096
+ dyn_cast<CompileJobAction>(&J->getSource ())) {
2097
+ const InputAction *IA = CJA->findSingleSwiftInput ();
2098
+ auto R =
2099
+ jobsByInput.insert (std::make_pair (IA->getInputArg ().getValue (), J));
2100
+ assert (R.second );
2101
+ (void )R;
2102
+ } else
2103
+ sortedJobs.push_back (J);
2101
2104
}
2102
2105
for (const InputPair &P : getInputFiles ()) {
2103
2106
auto I = jobsByInput.find (P.second ->getValue ());
@@ -2106,3 +2109,8 @@ void Compilation::sortJobsToMatchCompilationInputs(
2106
2109
}
2107
2110
}
2108
2111
}
2112
+
2113
+ template void
2114
+ Compilation::sortJobsToMatchCompilationInputs<ArrayRef<const Job *>>(
2115
+ const ArrayRef<const Job *> &,
2116
+ SmallVectorImpl<const Job *> &sortedJobs) const ;
0 commit comments