1515#include " llvm/ADT/SmallPtrSet.h"
1616#include " llvm/ADT/TypeSwitch.h"
1717#include " llvm/Support/Debug.h"
18+ #include " llvm/Support/DebugLog.h"
1819#include < queue>
1920
2021#define DEBUG_TYPE " pdl-predicate-tree"
@@ -544,7 +545,7 @@ static void visitUpward(std::vector<PositionalPredicate> &predList,
544545 Value value = opIndex.parent ;
545546 TypeSwitch<Operation *>(value.getDefiningOp ())
546547 .Case <pdl::OperationOp>([&](auto operationOp) {
547- LLVM_DEBUG ( llvm::dbgs ( ) << " * Value: " << value << " \n " ) ;
548+ LDBG ( ) << " * Value: " << value;
548549
549550 // Get users and iterate over them.
550551 Position *usersPos = builder.getUsers (pos, /* useRepresentative=*/ true );
@@ -618,31 +619,27 @@ static Value buildPredicateList(pdl::PatternOp pattern,
618619 RootOrderingGraph graph;
619620 ParentMaps parentMaps;
620621 buildCostGraph (roots, graph, parentMaps);
621- LLVM_DEBUG ({
622- llvm::dbgs () << " Graph:\n " ;
623- for (auto &target : graph) {
624- llvm::dbgs () << " * " << target.first .getLoc () << " " << target.first
625- << " \n " ;
626- for (auto &source : target.second ) {
627- RootOrderingEntry &entry = source.second ;
628- llvm::dbgs () << " <- " << source.first << " : " << entry.cost .first
629- << " :" << entry.cost .second << " via "
630- << entry.connector .getLoc () << " \n " ;
631- }
622+ LDBG () << " Graph:" ;
623+ for (auto &target : graph) {
624+ LDBG () << " * " << target.first .getLoc () << " " << target.first ;
625+ for (auto &source : target.second ) {
626+ RootOrderingEntry &entry = source.second ;
627+ LDBG () << " <- " << source.first << " : " << entry.cost .first << " :"
628+ << entry.cost .second << " via " << entry.connector .getLoc ();
632629 }
633- });
630+ }
634631
635632 // Solve the optimal branching problem for each candidate root, or use the
636633 // provided one.
637634 Value bestRoot = pattern.getRewriter ().getRoot ();
638635 OptimalBranching::EdgeList bestEdges;
639636 if (!bestRoot) {
640637 unsigned bestCost = 0 ;
641- LLVM_DEBUG ( llvm::dbgs ( ) << " Candidate roots:\n " ) ;
638+ LDBG ( ) << " Candidate roots:" ;
642639 for (Value root : roots) {
643640 OptimalBranching solver (graph, root);
644641 unsigned cost = solver.solve ();
645- LLVM_DEBUG ( llvm::dbgs ( ) << " * " << root << " : " << cost << " \n " ) ;
642+ LDBG ( ) << " * " << root << " : " << cost;
646643 if (!bestRoot || bestCost > cost) {
647644 bestCost = cost;
648645 bestRoot = root;
@@ -656,18 +653,15 @@ static Value buildPredicateList(pdl::PatternOp pattern,
656653 }
657654
658655 // Print the best solution.
659- LLVM_DEBUG ({
660- llvm::dbgs () << " Best tree:\n " ;
661- for (const std::pair<Value, Value> &edge : bestEdges) {
662- llvm::dbgs () << " * " << edge.first ;
663- if (edge.second )
664- llvm::dbgs () << " <- " << edge.second ;
665- llvm::dbgs () << " \n " ;
666- }
667- });
656+ LDBG () << " Best tree:" ;
657+ for (const std::pair<Value, Value> &edge : bestEdges) {
658+ if (edge.second )
659+ LDBG () << " * " << edge.first << " <- " << edge.second ;
660+ else
661+ LDBG () << " * " << edge.first ;
662+ }
668663
669- LLVM_DEBUG (llvm::dbgs () << " Calling key getTreePredicates:\n " );
670- LLVM_DEBUG (llvm::dbgs () << " * Value: " << bestRoot << " \n " );
664+ LDBG () << " Calling key getTreePredicates (Value: " << bestRoot << " )" ;
671665
672666 // The best root is the starting point for the traversal. Get the tree
673667 // predicates for the DAG rooted at bestRoot.
@@ -691,7 +685,7 @@ static Value buildPredicateList(pdl::PatternOp pattern,
691685 // Determine the connector.
692686 Value connector = graph[target][source].connector ;
693687 assert (connector && " invalid edge" );
694- LLVM_DEBUG ( llvm::dbgs ( ) << " * Connector: " << connector.getLoc () << " \n " );
688+ LDBG ( ) << " * Connector: " << connector.getLoc ();
695689 DenseMap<Value, OpIndex> parentMap = parentMaps.lookup (target);
696690 Position *pos = valueToPosition.lookup (connector);
697691 assert (pos && " connector has not been traversed yet" );
0 commit comments