9898
9999namespace llvm {
100100
101+ // Allow debug logging in this inline function.
102+ #define DEBUG_TYPE " cgscc"
103+
101104struct CGSCCUpdateResult ;
102105
103106// / Extern template declaration for the analysis set for this IR unit.
@@ -299,20 +302,19 @@ template <typename CGSCCPassT>
299302class ModuleToPostOrderCGSCCPassAdaptor
300303 : public PassInfoMixin<ModuleToPostOrderCGSCCPassAdaptor<CGSCCPassT>> {
301304public:
302- explicit ModuleToPostOrderCGSCCPassAdaptor (CGSCCPassT Pass, bool DebugLogging = false )
303- : Pass(std::move(Pass)), DebugLogging(DebugLogging) {}
305+ explicit ModuleToPostOrderCGSCCPassAdaptor (CGSCCPassT Pass)
306+ : Pass(std::move(Pass)) {}
304307 // We have to explicitly define all the special member functions because MSVC
305308 // refuses to generate them.
306309 ModuleToPostOrderCGSCCPassAdaptor (
307310 const ModuleToPostOrderCGSCCPassAdaptor &Arg)
308- : Pass(Arg.Pass), DebugLogging(Arg.DebugLogging) {}
311+ : Pass(Arg.Pass) {}
309312 ModuleToPostOrderCGSCCPassAdaptor (ModuleToPostOrderCGSCCPassAdaptor &&Arg)
310- : Pass(std::move(Arg.Pass)), DebugLogging(Arg.DebugLogging) {}
313+ : Pass(std::move(Arg.Pass)) {}
311314 friend void swap (ModuleToPostOrderCGSCCPassAdaptor &LHS,
312315 ModuleToPostOrderCGSCCPassAdaptor &RHS) {
313316 using std::swap;
314317 swap (LHS.Pass , RHS.Pass );
315- swap (LHS.DebugLogging , RHS.DebugLogging );
316318 }
317319 ModuleToPostOrderCGSCCPassAdaptor &
318320 operator =(ModuleToPostOrderCGSCCPassAdaptor RHS) {
@@ -369,16 +371,15 @@ class ModuleToPostOrderCGSCCPassAdaptor
369371 do {
370372 LazyCallGraph::RefSCC *RC = RCWorklist.pop_back_val ();
371373 if (InvalidRefSCCSet.count (RC)) {
372- if (DebugLogging)
373- dbgs () << " Skipping an invalid RefSCC...\n " ;
374+ DEBUG (dbgs () << " Skipping an invalid RefSCC...\n " );
374375 continue ;
375376 }
376377
377378 assert (CWorklist.empty () &&
378379 " Should always start with an empty SCC worklist" );
379380
380- if (DebugLogging)
381- dbgs () << " Running an SCC pass across the RefSCC: " << *RC << " \n " ;
381+ DEBUG ( dbgs () << " Running an SCC pass across the RefSCC: " << *RC
382+ << " \n " ) ;
382383
383384 // Push the initial SCCs in reverse post-order as we'll pop off the the
384385 // back and so see this in post-order.
@@ -392,14 +393,12 @@ class ModuleToPostOrderCGSCCPassAdaptor
392393 // other RefSCCs should be queued above, so we just need to skip both
393394 // scenarios here.
394395 if (InvalidSCCSet.count (C)) {
395- if (DebugLogging)
396- dbgs () << " Skipping an invalid SCC...\n " ;
396+ DEBUG (dbgs () << " Skipping an invalid SCC...\n " );
397397 continue ;
398398 }
399399 if (&C->getOuterRefSCC () != RC) {
400- if (DebugLogging)
401- dbgs () << " Skipping an SCC that is now part of some other "
402- " RefSCC...\n " ;
400+ DEBUG (dbgs () << " Skipping an SCC that is now part of some other "
401+ " RefSCC...\n " );
403402 continue ;
404403 }
405404
@@ -437,10 +436,10 @@ class ModuleToPostOrderCGSCCPassAdaptor
437436 // iterate there too.
438437 RC = UR.UpdatedRC ? UR.UpdatedRC : RC;
439438 C = UR.UpdatedC ? UR.UpdatedC : C;
440- if (DebugLogging && UR.UpdatedC )
441- dbgs () << " Re-running SCC passes after a refinement of the "
442- " current SCC: "
443- << *UR.UpdatedC << " \n " ;
439+ if (UR.UpdatedC )
440+ DEBUG ( dbgs () << " Re-running SCC passes after a refinement of the "
441+ " current SCC: "
442+ << *UR.UpdatedC << " \n " ) ;
444443
445444 // Note that both `C` and `RC` may at this point refer to deleted,
446445 // invalid SCC and RefSCCs respectively. But we will short circuit
@@ -466,15 +465,14 @@ class ModuleToPostOrderCGSCCPassAdaptor
466465
467466private:
468467 CGSCCPassT Pass;
469- bool DebugLogging;
470468};
471469
472470// / \brief A function to deduce a function pass type and wrap it in the
473471// / templated adaptor.
474472template <typename CGSCCPassT>
475473ModuleToPostOrderCGSCCPassAdaptor<CGSCCPassT>
476- createModuleToPostOrderCGSCCPassAdaptor (CGSCCPassT Pass, bool DebugLogging = false ) {
477- return ModuleToPostOrderCGSCCPassAdaptor<CGSCCPassT>(std::move (Pass), DebugLogging );
474+ createModuleToPostOrderCGSCCPassAdaptor (CGSCCPassT Pass) {
475+ return ModuleToPostOrderCGSCCPassAdaptor<CGSCCPassT>(std::move (Pass));
478476}
479477
480478// / A proxy from a \c FunctionAnalysisManager to an \c SCC.
@@ -523,7 +521,7 @@ typedef OuterAnalysisManagerProxy<CGSCCAnalysisManager, Function>
523521// / update result struct for the overall CGSCC walk.
524522LazyCallGraph::SCC &updateCGAndAnalysisManagerForFunctionPass (
525523 LazyCallGraph &G, LazyCallGraph::SCC &C, LazyCallGraph::Node &N,
526- CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR, bool DebugLogging = false );
524+ CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR);
527525
528526// / \brief Adaptor that maps from a SCC to its functions.
529527// /
@@ -537,19 +535,18 @@ template <typename FunctionPassT>
537535class CGSCCToFunctionPassAdaptor
538536 : public PassInfoMixin<CGSCCToFunctionPassAdaptor<FunctionPassT>> {
539537public:
540- explicit CGSCCToFunctionPassAdaptor (FunctionPassT Pass, bool DebugLogging = false )
541- : Pass(std::move(Pass)), DebugLogging(DebugLogging) {}
538+ explicit CGSCCToFunctionPassAdaptor (FunctionPassT Pass)
539+ : Pass(std::move(Pass)) {}
542540 // We have to explicitly define all the special member functions because MSVC
543541 // refuses to generate them.
544542 CGSCCToFunctionPassAdaptor (const CGSCCToFunctionPassAdaptor &Arg)
545- : Pass(Arg.Pass), DebugLogging(Arg.DebugLogging) {}
543+ : Pass(Arg.Pass) {}
546544 CGSCCToFunctionPassAdaptor (CGSCCToFunctionPassAdaptor &&Arg)
547- : Pass(std::move(Arg.Pass)), DebugLogging(Arg.DebugLogging) {}
545+ : Pass(std::move(Arg.Pass)) {}
548546 friend void swap (CGSCCToFunctionPassAdaptor &LHS,
549547 CGSCCToFunctionPassAdaptor &RHS) {
550548 using std::swap;
551549 swap (LHS.Pass , RHS.Pass );
552- swap (LHS.DebugLogging , RHS.DebugLogging );
553550 }
554551 CGSCCToFunctionPassAdaptor &operator =(CGSCCToFunctionPassAdaptor RHS) {
555552 swap (*this , RHS);
@@ -572,8 +569,7 @@ class CGSCCToFunctionPassAdaptor
572569 // a pointer we can overwrite.
573570 LazyCallGraph::SCC *CurrentC = &C;
574571
575- if (DebugLogging)
576- dbgs () << " Running function passes across an SCC: " << C << " \n " ;
572+ DEBUG (dbgs () << " Running function passes across an SCC: " << C << " \n " );
577573
578574 PreservedAnalyses PA = PreservedAnalyses::all ();
579575 for (LazyCallGraph::Node *N : Nodes) {
@@ -599,8 +595,8 @@ class CGSCCToFunctionPassAdaptor
599595 // a smaller, more refined SCC.
600596 auto PAC = PA.getChecker <LazyCallGraphAnalysis>();
601597 if (!PAC.preserved () && !PAC.preservedSet <AllAnalysesOn<Module>>()) {
602- CurrentC = &updateCGAndAnalysisManagerForFunctionPass (
603- CG, *CurrentC, *N, AM, UR, DebugLogging );
598+ CurrentC = &updateCGAndAnalysisManagerForFunctionPass (CG, *CurrentC, *N,
599+ AM, UR);
604600 assert (
605601 CG.lookupSCC (*N) == CurrentC &&
606602 " Current SCC not updated to the SCC containing the current node!" );
@@ -622,16 +618,14 @@ class CGSCCToFunctionPassAdaptor
622618
623619private:
624620 FunctionPassT Pass;
625- bool DebugLogging;
626621};
627622
628623// / \brief A function to deduce a function pass type and wrap it in the
629624// / templated adaptor.
630625template <typename FunctionPassT>
631626CGSCCToFunctionPassAdaptor<FunctionPassT>
632- createCGSCCToFunctionPassAdaptor (FunctionPassT Pass, bool DebugLogging = false ) {
633- return CGSCCToFunctionPassAdaptor<FunctionPassT>(std::move (Pass),
634- DebugLogging);
627+ createCGSCCToFunctionPassAdaptor (FunctionPassT Pass) {
628+ return CGSCCToFunctionPassAdaptor<FunctionPassT>(std::move (Pass));
635629}
636630
637631// / A helper that repeats an SCC pass each time an indirect call is refined to
@@ -652,10 +646,8 @@ template <typename PassT>
652646class DevirtSCCRepeatedPass
653647 : public PassInfoMixin<DevirtSCCRepeatedPass<PassT>> {
654648public:
655- explicit DevirtSCCRepeatedPass (PassT Pass, int MaxIterations,
656- bool DebugLogging = false )
657- : Pass(std::move(Pass)), MaxIterations(MaxIterations),
658- DebugLogging(DebugLogging) {}
649+ explicit DevirtSCCRepeatedPass (PassT Pass, int MaxIterations)
650+ : Pass(std::move(Pass)), MaxIterations(MaxIterations) {}
659651
660652 // / Runs the wrapped pass up to \c MaxIterations on the SCC, iterating
661653 // / whenever an indirect call is refined.
@@ -733,10 +725,9 @@ class DevirtSCCRepeatedPass
733725 if (!F)
734726 return false ;
735727
736- if (DebugLogging)
737- dbgs () << " Found devirutalized call from "
738- << CS.getParent ()->getParent ()->getName () << " to "
739- << F->getName () << " \n " ;
728+ DEBUG (dbgs () << " Found devirutalized call from "
729+ << CS.getParent ()->getParent ()->getName () << " to "
730+ << F->getName () << " \n " );
740731
741732 // We now have a direct call where previously we had an indirect call,
742733 // so iterate to process this devirtualization site.
@@ -770,17 +761,16 @@ class DevirtSCCRepeatedPass
770761
771762 // Otherwise, if we've already hit our max, we're done.
772763 if (Iteration >= MaxIterations) {
773- if (DebugLogging)
774- dbgs () << " Found another devirtualization after hitting the max "
775- " number of repetitions ("
776- << MaxIterations << " ) on SCC: " << *C << " \n " ;
764+ DEBUG (dbgs () << " Found another devirtualization after hitting the max "
765+ " number of repetitions ("
766+ << MaxIterations << " ) on SCC: " << *C << " \n " );
777767 PA.intersect (std::move (PassPA));
778768 break ;
779769 }
780770
781- if (DebugLogging )
782- dbgs () << " Repeating an SCC pass after finding a devirtualization in: "
783- << *C << " \n " ;
771+ DEBUG ( dbgs ( )
772+ << " Repeating an SCC pass after finding a devirtualization in: "
773+ << *C << " \n " ) ;
784774
785775 // Move over the new call counts in preparation for iterating.
786776 CallCounts = std::move (NewCallCounts);
@@ -800,18 +790,18 @@ class DevirtSCCRepeatedPass
800790private:
801791 PassT Pass;
802792 int MaxIterations;
803- bool DebugLogging;
804793};
805794
806795// / \brief A function to deduce a function pass type and wrap it in the
807796// / templated adaptor.
808797template <typename PassT>
809- DevirtSCCRepeatedPass<PassT>
810- createDevirtSCCRepeatedPass (PassT Pass, int MaxIterations,
811- bool DebugLogging = false ) {
812- return DevirtSCCRepeatedPass<PassT>(std::move (Pass), MaxIterations,
813- DebugLogging);
798+ DevirtSCCRepeatedPass<PassT> createDevirtSCCRepeatedPass (PassT Pass,
799+ int MaxIterations) {
800+ return DevirtSCCRepeatedPass<PassT>(std::move (Pass), MaxIterations);
814801}
802+
803+ // Clear out the debug logging macro.
804+ #undef DEBUG_TYPE
815805}
816806
817807#endif
0 commit comments