@@ -688,7 +688,6 @@ namespace driver {
688
688
NonBatchable.insert (Cmd);
689
689
}
690
690
}
691
- PendingExecution.clear ();
692
691
}
693
692
694
693
// / If \p Batch is nonempty, construct a new \c BatchJob from its
@@ -770,6 +769,30 @@ namespace driver {
770
769
}
771
770
}
772
771
772
+ // FIXME: at the moment we're not passing OutputFileMaps to frontends, so
773
+ // due to the multiplication of the number of additional files and the
774
+ // number of files in a batch, it's pretty easy to construct too-long
775
+ // command lines here, which will then fail to exec. We address this crudely
776
+ // by re-forming batches with a finer partition when we overflow.
777
+ bool shouldRetryWithMorePartitions (std::vector<const Job *> const &Batches,
778
+ size_t &NumPartitions) {
779
+
780
+ // Stop rebatching if we can't subdivide batches any further.
781
+ if (NumPartitions > PendingExecution.size ())
782
+ return false ;
783
+
784
+ for (auto const *B : Batches) {
785
+ if (!llvm::sys::commandLineFitsWithinSystemLimits (B->getExecutable (),
786
+ B->getArguments ())) {
787
+ // To avoid redoing the batch loop too many times, repartition pretty
788
+ // aggressively by doubling partition count / halving size.
789
+ NumPartitions *= 2 ;
790
+ return true ;
791
+ }
792
+ }
793
+ return false ;
794
+ }
795
+
773
796
// / Select jobs that are batch-combinable from \c PendingExecution, combine
774
797
// / them together into \p BatchJob instances (also inserted into \p
775
798
// / BatchJobs), and enqueue all \c PendingExecution jobs (whether batched or
@@ -783,23 +806,29 @@ namespace driver {
783
806
return ;
784
807
}
785
808
786
- // Split the batchable from non-batchable pending jobs.
809
+ size_t NumPartitions = Comp. NumberOfParallelCommands ;
787
810
CommandSetVector Batchable, NonBatchable;
788
- getPendingBatchableJobs (Batchable, NonBatchable);
811
+ std::vector<const Job *> Batches;
812
+ do {
813
+ // We might be restarting loop; clear these before proceeding.
814
+ Batchable.clear ();
815
+ NonBatchable.clear ();
816
+ Batches.clear ();
789
817
790
- // Partition the batchable jobs into sets.
791
- // FIXME: at present we set a maximum batch size of TOO_MANY_FILES
792
- // so that we don't overflow command-line lengths. This can go away
793
- // when we're passing OFMs to the frontend processes.
794
- BatchPartition Partition (std::max (size_t (Comp.NumberOfParallelCommands ),
795
- Batchable.size () / TOO_MANY_FILES));
796
- partitionIntoBatches (Batchable.takeVector (), Partition);
818
+ // Split the batchable from non-batchable pending jobs.
819
+ getPendingBatchableJobs (Batchable, NonBatchable);
797
820
798
- // Construct a BatchJob from each batch in the partition.
799
- std::vector<const Job *> Batches;
800
- for (auto const &Batch : Partition) {
801
- formBatchJobFromPartitionBatch (Batches, Batch);
802
- }
821
+ // Partition the batchable jobs into sets.
822
+ BatchPartition Partition (NumPartitions);
823
+ partitionIntoBatches (Batchable.takeVector (), Partition);
824
+
825
+ // Construct a BatchJob from each batch in the partition.
826
+ for (auto const &Batch : Partition) {
827
+ formBatchJobFromPartitionBatch (Batches, Batch);
828
+ }
829
+
830
+ } while (shouldRetryWithMorePartitions (Batches, NumPartitions));
831
+ PendingExecution.clear ();
803
832
804
833
// Save batches so we can locate and decompose them on task-exit.
805
834
for (const Job *Cmd : Batches)
0 commit comments