@@ -1876,6 +1876,54 @@ Driver::computeCompilerMode(const DerivedArgList &Args,
18761876 return OutputInfo::Mode::StandardCompile;
18771877}
18781878
1879+ namespace {
1880+ // / Encapsulates the computation of input jobs that are relevant to the
1881+ // / merge-modules job the scheduler can insert if we are not in a single compile
1882+ // / mode.
1883+ class ModuleInputs final {
1884+ private:
1885+ using InputInfo = IncrementalJobAction::InputInfo;
1886+ SmallVector<const Action *, 2 > AllModuleInputs;
1887+ InputInfo StatusBound;
1888+
1889+ public:
1890+ explicit ModuleInputs ()
1891+ : StatusBound
1892+ {InputInfo::Status::UpToDate, llvm::sys::TimePoint<>::min ()} {}
1893+
1894+ public:
1895+ void addInput (const Action *inputAction) {
1896+ if (auto *IJA = dyn_cast<IncrementalJobAction>(inputAction)) {
1897+ // Take the upper bound of the status of any incremental inputs to
1898+ // ensure that the merge-modules job gets run if *any* input job is run.
1899+ const auto conservativeStatus =
1900+ std::max (StatusBound.status , IJA->getInputInfo ().status );
1901+ // The modification time here is not important to the rest of the
1902+ // incremental build. We take the upper bound in case an attempt to
1903+ // compare the swiftmodule output's mod time and any input files is
1904+ // made. If the compilation has been correctly scheduled, the
1905+ // swiftmodule's mod time will always strictly exceed the mod time of
1906+ // any of its inputs when we are able to skip it.
1907+ const auto conservativeModTime = std::max (
1908+ StatusBound.previousModTime , IJA->getInputInfo ().previousModTime );
1909+ StatusBound = InputInfo{conservativeStatus, conservativeModTime};
1910+ }
1911+ AllModuleInputs.push_back (inputAction);
1912+ }
1913+
1914+ public:
1915+ // / Returns \c true if no inputs have been registered with this instance.
1916+ bool empty () const { return AllModuleInputs.empty (); }
1917+
1918+ public:
1919+ // / Consumes this \c ModuleInputs instance and returns a merge-modules action
1920+ // / from the list of input actions and status it has computed thus far.
1921+ JobAction *intoAction (Compilation &C) && {
1922+ return C.createAction <MergeModuleJobAction>(AllModuleInputs, StatusBound);
1923+ }
1924+ };
1925+ } // namespace
1926+
18791927void Driver::buildActions (SmallVectorImpl<const Action *> &TopLevelActions,
18801928 const ToolChain &TC, const OutputInfo &OI,
18811929 const InputInfoMap *OutOfDateMap,
0 commit comments