Skip to content

Commit 83bfb55

Browse files
committed
[PM] Switch the CGSCC debug messages to use the standard LLVM debug
printing techniques with a DEBUG_TYPE controlling them. It was a mistake to start re-purposing the pass manager `DebugLogging` variable for generic debug printing -- those logs are intended to be very minimal and primarily used for testing. More detailed and comprehensive logging doesn't make sense there (it would only make for brittle tests). Moreover, we kept forgetting to propagate the `DebugLogging` variable to various places making it also ineffective and/or unavailable. Switching to `DEBUG_TYPE` makes this a non-issue. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310695 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 9306f4a commit 83bfb55

File tree

5 files changed

+77
-98
lines changed

5 files changed

+77
-98
lines changed

include/llvm/Analysis/CGSCCPassManager.h

Lines changed: 46 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898

9999
namespace llvm {
100100

101+
// Allow debug logging in this inline function.
102+
#define DEBUG_TYPE "cgscc"
103+
101104
struct CGSCCUpdateResult;
102105

103106
/// Extern template declaration for the analysis set for this IR unit.
@@ -299,20 +302,19 @@ template <typename CGSCCPassT>
299302
class ModuleToPostOrderCGSCCPassAdaptor
300303
: public PassInfoMixin<ModuleToPostOrderCGSCCPassAdaptor<CGSCCPassT>> {
301304
public:
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

467466
private:
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.
474472
template <typename CGSCCPassT>
475473
ModuleToPostOrderCGSCCPassAdaptor<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.
524522
LazyCallGraph::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>
537535
class CGSCCToFunctionPassAdaptor
538536
: public PassInfoMixin<CGSCCToFunctionPassAdaptor<FunctionPassT>> {
539537
public:
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

623619
private:
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.
630625
template <typename FunctionPassT>
631626
CGSCCToFunctionPassAdaptor<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>
652646
class DevirtSCCRepeatedPass
653647
: public PassInfoMixin<DevirtSCCRepeatedPass<PassT>> {
654648
public:
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
800790
private:
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.
808797
template <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

lib/Analysis/CGSCCPassManager.cpp

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "llvm/IR/CallSite.h"
1212
#include "llvm/IR/InstIterator.h"
1313

14+
#define DEBUG_TYPE "cgscc"
15+
1416
using namespace llvm;
1517

1618
// Explicit template instantiations and specialization defininitions for core
@@ -322,17 +324,15 @@ template <typename SCCRangeT>
322324
LazyCallGraph::SCC *
323325
incorporateNewSCCRange(const SCCRangeT &NewSCCRange, LazyCallGraph &G,
324326
LazyCallGraph::Node &N, LazyCallGraph::SCC *C,
325-
CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR,
326-
bool DebugLogging = false) {
327+
CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR) {
327328
typedef LazyCallGraph::SCC SCC;
328329

329330
if (NewSCCRange.begin() == NewSCCRange.end())
330331
return C;
331332

332333
// Add the current SCC to the worklist as its shape has changed.
333334
UR.CWorklist.insert(C);
334-
if (DebugLogging)
335-
dbgs() << "Enqueuing the existing SCC in the worklist:" << *C << "\n";
335+
DEBUG(dbgs() << "Enqueuing the existing SCC in the worklist:" << *C << "\n");
336336

337337
SCC *OldC = C;
338338

@@ -368,8 +368,7 @@ incorporateNewSCCRange(const SCCRangeT &NewSCCRange, LazyCallGraph &G,
368368
assert(C != &NewC && "No need to re-visit the current SCC!");
369369
assert(OldC != &NewC && "Already handled the original SCC!");
370370
UR.CWorklist.insert(&NewC);
371-
if (DebugLogging)
372-
dbgs() << "Enqueuing a newly formed SCC:" << NewC << "\n";
371+
DEBUG(dbgs() << "Enqueuing a newly formed SCC:" << NewC << "\n");
373372

374373
// Ensure new SCCs' function analyses are updated.
375374
if (NeedFAMProxy)
@@ -385,7 +384,7 @@ incorporateNewSCCRange(const SCCRangeT &NewSCCRange, LazyCallGraph &G,
385384

386385
LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
387386
LazyCallGraph &G, LazyCallGraph::SCC &InitialC, LazyCallGraph::Node &N,
388-
CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR, bool DebugLogging) {
387+
CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR) {
389388
typedef LazyCallGraph::Node Node;
390389
typedef LazyCallGraph::Edge Edge;
391390
typedef LazyCallGraph::SCC SCC;
@@ -475,7 +474,7 @@ LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
475474
} else {
476475
// Now update the call graph.
477476
C = incorporateNewSCCRange(RC->switchInternalEdgeToRef(N, E.getNode()),
478-
G, N, C, AM, UR, DebugLogging);
477+
G, N, C, AM, UR);
479478
}
480479
}
481480

@@ -495,9 +494,8 @@ LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
495494
return false;
496495

497496
RC->removeOutgoingEdge(N, *TargetN);
498-
if (DebugLogging)
499-
dbgs() << "Deleting outgoing edge from '" << N
500-
<< "' to '" << TargetN << "'\n";
497+
DEBUG(dbgs() << "Deleting outgoing edge from '" << N
498+
<< "' to '" << TargetN << "'\n");
501499
return true;
502500
}),
503501
DeadTargets.end());
@@ -528,9 +526,8 @@ LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
528526
assert(NewRC != RC && "Should not encounter the current RefSCC further "
529527
"in the postorder list of new RefSCCs.");
530528
UR.RCWorklist.insert(NewRC);
531-
if (DebugLogging)
532-
dbgs() << "Enqueuing a new RefSCC in the update worklist: " << *NewRC
533-
<< "\n";
529+
DEBUG(dbgs() << "Enqueuing a new RefSCC in the update worklist: "
530+
<< *NewRC << "\n");
534531
}
535532
}
536533

@@ -547,9 +544,8 @@ LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
547544
assert(RC->isAncestorOf(TargetRC) &&
548545
"Cannot potentially form RefSCC cycles here!");
549546
RC->switchOutgoingEdgeToRef(N, *RefTarget);
550-
if (DebugLogging)
551-
dbgs() << "Switch outgoing call edge to a ref edge from '" << N
552-
<< "' to '" << *RefTarget << "'\n";
547+
DEBUG(dbgs() << "Switch outgoing call edge to a ref edge from '" << N
548+
<< "' to '" << *RefTarget << "'\n");
553549
continue;
554550
}
555551

@@ -563,7 +559,7 @@ LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
563559

564560
// Now update the call graph.
565561
C = incorporateNewSCCRange(RC->switchInternalEdgeToRef(N, *RefTarget), G, N,
566-
C, AM, UR, DebugLogging);
562+
C, AM, UR);
567563
}
568564

569565
// Now promote ref edges into call edges.
@@ -577,14 +573,12 @@ LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
577573
assert(RC->isAncestorOf(TargetRC) &&
578574
"Cannot potentially form RefSCC cycles here!");
579575
RC->switchOutgoingEdgeToCall(N, *CallTarget);
580-
if (DebugLogging)
581-
dbgs() << "Switch outgoing ref edge to a call edge from '" << N
582-
<< "' to '" << *CallTarget << "'\n";
576+
DEBUG(dbgs() << "Switch outgoing ref edge to a call edge from '" << N
577+
<< "' to '" << *CallTarget << "'\n");
583578
continue;
584579
}
585-
if (DebugLogging)
586-
dbgs() << "Switch an internal ref edge to a call edge from '" << N
587-
<< "' to '" << *CallTarget << "'\n";
580+
DEBUG(dbgs() << "Switch an internal ref edge to a call edge from '" << N
581+
<< "' to '" << *CallTarget << "'\n");
588582

589583
// Otherwise we are switching an internal ref edge to a call edge. This
590584
// may merge away some SCCs, and we add those to the UpdateResult. We also
@@ -647,15 +641,14 @@ LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
647641
// post-order sequence, and may end up observing more precise context to
648642
// optimize the current SCC.
649643
UR.CWorklist.insert(C);
650-
if (DebugLogging)
651-
dbgs() << "Enqueuing the existing SCC in the worklist: " << *C << "\n";
644+
DEBUG(dbgs() << "Enqueuing the existing SCC in the worklist: " << *C
645+
<< "\n");
652646
// Enqueue in reverse order as we pop off the back of the worklist.
653647
for (SCC &MovedC : reverse(make_range(RC->begin() + InitialSCCIndex,
654648
RC->begin() + NewSCCIndex))) {
655649
UR.CWorklist.insert(&MovedC);
656-
if (DebugLogging)
657-
dbgs() << "Enqueuing a newly earlier in post-order SCC: " << MovedC
658-
<< "\n";
650+
DEBUG(dbgs() << "Enqueuing a newly earlier in post-order SCC: "
651+
<< MovedC << "\n");
659652
}
660653
}
661654
}

0 commit comments

Comments
 (0)