@@ -206,9 +206,6 @@ void InitTimers();
206206 if (!CheckBuiltins ())
207207 return ;
208208#if CLANG_VERSION_MAJOR > 16
209- Sema& S = m_CI.getSema ();
210- RequestOptions opts{};
211- SetRequestOptions (opts);
212209 // Traverse all constexpr FunctionDecls for the static graph only once to
213210 // differentiate them immeditely.
214211 {
@@ -218,19 +215,17 @@ void InitTimers();
218215 continue ;
219216 auto * FD = cast<FunctionDecl>(D);
220217 if (FD ->isConstexpr () || !m_Multiplexer) {
221- DiffCollector collector (CladEnabledRange, m_DiffRequestGraph, S,
222- opts, m_AllAnalysisDC);
223- collector.Walk (DGR );
218+ getScheduler ().Plan (DGR );
224219 break ;
225220 }
226221 }
227222 }
228223
229- for (DiffRequest& request : m_DiffRequestGraph .getNodes ()) {
224+ for (DiffRequest& request : getScheduler (). getGraph () .getNodes ()) {
230225 if (request.ImmediateMode && request.Function ->isConstexpr ()) {
231- m_DiffRequestGraph .setCurrentProcessingNode (request);
226+ getScheduler (). getGraph () .setCurrentProcessingNode (request);
232227 ProcessDiffRequest (request);
233- m_DiffRequestGraph .markCurrentNodeProcessed ();
228+ getScheduler (). getGraph () .markCurrentNodeProcessed ();
234229 }
235230 }
236231#endif
@@ -349,8 +344,8 @@ void InitTimers();
349344 FunctionDecl* CladPlugin::ProcessDiffRequest (DiffRequest& request) {
350345 Sema& S = m_CI.getSema ();
351346 if (!m_DerivativeBuilder)
352- m_DerivativeBuilder = std::make_unique<DerivativeBuilder>(
353- S, *this , m_DFC, m_DiffRequestGraph );
347+ m_DerivativeBuilder =
348+ std::make_unique<DerivativeBuilder>( S, *this , getScheduler () );
354349
355350 if (request.Global ) {
356351 auto deriveResult = m_DerivativeBuilder->Derive (request);
@@ -366,7 +361,7 @@ void InitTimers();
366361 // FIXME: These requests are not fully generated in the diffplanner and we
367362 // have to update diff params on this stage.
368363 if (request.CurrentDerivativeOrder > 1 ||
369- m_DFC .IsCladDerivative (request.Function ))
364+ getScheduler (). getDerivedFns () .IsCladDerivative (request.Function ))
370365 request.UpdateDiffParamsInfo (m_CI.getSema ());
371366 const FunctionDecl* FD = request.Function ;
372367 ASTContext& C = S.getASTContext ();
@@ -397,7 +392,7 @@ void InitTimers();
397392 {
398393 llvm::SaveAndRestore<unsigned > Saved (request.RequestedDerivativeOrder ,
399394 1 );
400- auto DFI = m_DFC .Find (request);
395+ auto DFI = getScheduler (). getDerivedFns () .Find (request);
401396 if (DFI .IsValid ()) {
402397 DerivativeDecl = DFI .DerivedFn ();
403398 OverloadedDerivativeDecl = DFI .OverloadedDerivedFn ();
@@ -413,8 +408,8 @@ void InitTimers();
413408 utils::hasEmptyBody (DerivativeDecl))
414409 return nullptr ;
415410 if (DerivativeDecl)
416- m_DFC. Add (DerivedFnInfo (request, DerivativeDecl,
417- OverloadedDerivativeDecl));
411+ getScheduler (). getDerivedFns (). Add (DerivedFnInfo (
412+ request, DerivativeDecl, OverloadedDerivativeDecl));
418413 }
419414 }
420415
@@ -595,6 +590,16 @@ void InitTimers();
595590 SetUsefulAnalysisOptions (m_DO, opts);
596591 }
597592
593+ DiffScheduler& CladPlugin::getScheduler () {
594+ if (!m_Scheduler) {
595+ RequestOptions Opts{};
596+ SetRequestOptions (Opts);
597+ m_Scheduler = std::make_unique<DiffScheduler>(m_CI.getSema (), Opts,
598+ CladEnabledRange);
599+ }
600+ return *m_Scheduler;
601+ }
602+
598603 void CladPlugin::FinalizeTranslationUnit () {
599604 Sema& S = m_CI.getSema ();
600605 // Restore the TUScope that became a 0 in Sema::ActOnEndOfTranslationUnit.
@@ -606,16 +611,16 @@ void InitTimers();
606611 Sema::LocalEagerInstantiationScope LocalInstantiations (
607612 S CLAD_COMPAT_CLANG21_AtEndOfTUParam);
608613
609- if (!m_DiffRequestGraph .isProcessingNode ()) {
614+ if (!getScheduler (). getGraph () .isProcessingNode ()) {
610615 // This check is to avoid recursive processing of the graph, as
611616 // HandleTopLevelDecl can be called recursively in non-standard
612617 // setup for code generation.
613- DiffRequest request = m_DiffRequestGraph .getNextToProcessNode ();
618+ DiffRequest request = getScheduler (). getGraph () .getNextToProcessNode ();
614619 while (request.Function || request.Global ) {
615- m_DiffRequestGraph .setCurrentProcessingNode (request);
620+ getScheduler (). getGraph () .setCurrentProcessingNode (request);
616621 ProcessDiffRequest (request);
617- m_DiffRequestGraph .markCurrentNodeProcessed ();
618- request = m_DiffRequestGraph .getNextToProcessNode ();
622+ getScheduler (). getGraph () .markCurrentNodeProcessed ();
623+ request = getScheduler (). getGraph () .getNextToProcessNode ();
619624 }
620625 }
621626
@@ -631,9 +636,6 @@ void InitTimers();
631636 void CladPlugin::HandleTranslationUnit (ASTContext& C) {
632637 // In case of diagnostics, don't bother, just let the compiler finish.
633638 if (!m_CI.getDiagnostics ().hasErrorOccurred ()) {
634- Sema& S = m_CI.getSema ();
635- RequestOptions opts{};
636- SetRequestOptions (opts);
637639 // Traverse all collected DeclGroupRef only once to create the static
638640 // graph.
639641 TimedAnalysisRegion R (" Rest of TU" );
@@ -642,16 +644,14 @@ void InitTimers();
642644 if (const auto * FD = dyn_cast<FunctionDecl>(D))
643645 if (FD ->isConstexpr ())
644646 continue ;
645- DiffCollector collector (CladEnabledRange, m_DiffRequestGraph, S,
646- opts, m_AllAnalysisDC);
647- collector.Walk (DCI .m_DGR );
647+ getScheduler ().Plan (DCI .m_DGR );
648648 break ;
649649 }
650650
651651 if (m_CI.getFrontendOpts ().ShowStats ) {
652652 // Print the graph of the diff requests.
653653 llvm::errs () << " \n *** INFORMATION ABOUT THE DIFF REQUESTS\n " ;
654- m_DiffRequestGraph .dump ();
654+ getScheduler (). getGraph () .dump ();
655655 }
656656
657657 FinalizeTranslationUnit ();
0 commit comments