@@ -101,6 +101,22 @@ struct SemiNCAInfo {
101
101
102
102
static bool AlwaysDescend (NodePtr, NodePtr) { return true ; }
103
103
104
+ struct BlockNamePrinter {
105
+ NodePtr N;
106
+
107
+ BlockNamePrinter (NodePtr Block) : N(Block) {}
108
+ BlockNamePrinter (TreeNodePtr TN) : N(TN ? TN->getBlock () : nullptr) {}
109
+
110
+ friend raw_ostream &operator <<(raw_ostream &O, const BlockNamePrinter &BP) {
111
+ if (!BP.N )
112
+ O << " nullptr" ;
113
+ else
114
+ BP.N ->printAsOperand (O, false );
115
+
116
+ return O;
117
+ }
118
+ };
119
+
104
120
// Custom DFS implementation which can skip nodes based on a provided
105
121
// predicate. It also collects ReverseChildren so that we don't have to spend
106
122
// time getting predecessors in SemiNCA.
@@ -281,9 +297,8 @@ struct SemiNCAInfo {
281
297
// Loop over all of the discovered blocks in the function...
282
298
for (size_t i = 1 , e = NumToNode.size (); i != e; ++i) {
283
299
NodePtr W = NumToNode[i];
284
- DEBUG (dbgs () << " \t discovereed a new reachable node " );
285
- DEBUG (PrintBlockOrNullptr (dbgs (), W));
286
- DEBUG (dbgs () << " \n " );
300
+ DEBUG (dbgs () << " \t discovered a new reachable node "
301
+ << BlockNamePrinter (W) << " \n " );
287
302
288
303
// Don't replace this with 'count', the insertion side effect is important
289
304
if (DT.DomTreeNodes [W]) continue ; // Haven't calculated this node yet?
@@ -300,13 +315,6 @@ struct SemiNCAInfo {
300
315
}
301
316
}
302
317
303
- static void PrintBlockOrNullptr (raw_ostream &O, NodePtr Obj) {
304
- if (!Obj)
305
- O << " nullptr" ;
306
- else
307
- Obj->printAsOperand (O, false );
308
- }
309
-
310
318
// Checks if the tree contains all reachable nodes in the input graph.
311
319
bool verifyReachability (const DomTreeT &DT) {
312
320
clear ();
@@ -320,9 +328,8 @@ struct SemiNCAInfo {
320
328
if (DT.isVirtualRoot (TN)) continue ;
321
329
322
330
if (NodeToInfo.count (BB) == 0 ) {
323
- errs () << " DomTree node " ;
324
- PrintBlockOrNullptr (errs (), BB);
325
- errs () << " not found by DFS walk!\n " ;
331
+ errs () << " DomTree node " << BlockNamePrinter (BB)
332
+ << " not found by DFS walk!\n " ;
326
333
errs ().flush ();
327
334
328
335
return false ;
@@ -331,9 +338,8 @@ struct SemiNCAInfo {
331
338
332
339
for (const NodePtr N : NumToNode) {
333
340
if (N && !DT.getNode (N)) {
334
- errs () << " CFG node " ;
335
- PrintBlockOrNullptr (errs (), N);
336
- errs () << " not found in the DomTree!\n " ;
341
+ errs () << " CFG node " << BlockNamePrinter (N)
342
+ << " not found in the DomTree!\n " ;
337
343
errs ().flush ();
338
344
339
345
return false ;
@@ -353,20 +359,18 @@ struct SemiNCAInfo {
353
359
354
360
const TreeNodePtr IDom = TN->getIDom ();
355
361
if (!IDom && TN->getLevel () != 0 ) {
356
- errs () << " Node without an IDom " ;
357
- PrintBlockOrNullptr (errs (), BB);
358
- errs () << " has a nonzero level " << TN->getLevel () << " !\n " ;
362
+ errs () << " Node without an IDom " << BlockNamePrinter (BB)
363
+ << " has a nonzero level " << TN->getLevel () << " !\n " ;
359
364
errs ().flush ();
360
365
361
366
return false ;
362
367
}
363
368
364
369
if (IDom && TN->getLevel () != IDom->getLevel () + 1 ) {
365
- errs () << " Node " ;
366
- PrintBlockOrNullptr (errs (), BB);
367
- errs () << " has level " << TN->getLevel () << " while it's IDom " ;
368
- PrintBlockOrNullptr (errs (), IDom->getBlock ());
369
- errs () << " has level " << IDom->getLevel () << " !\n " ;
370
+ errs () << " Node " << BlockNamePrinter (BB) << " has level "
371
+ << TN->getLevel () << " while its IDom "
372
+ << BlockNamePrinter (IDom->getBlock ()) << " has level "
373
+ << IDom->getLevel () << " !\n " ;
370
374
errs ().flush ();
371
375
372
376
return false ;
@@ -396,15 +400,11 @@ struct SemiNCAInfo {
396
400
const TreeNodePtr NCDTN = DT.getNode (NCD);
397
401
const TreeNodePtr ToIDom = ToTN->getIDom ();
398
402
if (NCDTN != ToTN && NCDTN != ToIDom) {
399
- errs () << " NearestCommonDominator verification failed:\n\t NCD(From:" ;
400
- PrintBlockOrNullptr (errs (), From);
401
- errs () << " , To:" ;
402
- PrintBlockOrNullptr (errs (), To);
403
- errs () << " ) = " ;
404
- PrintBlockOrNullptr (errs (), NCD);
405
- errs () << " ,\t (should be To or IDom[To]: " ;
406
- PrintBlockOrNullptr (errs (), ToIDom ? ToIDom->getBlock () : nullptr );
407
- errs () << " )\n " ;
403
+ errs () << " NearestCommonDominator verification failed:\n\t NCD(From:"
404
+ << BlockNamePrinter (From) << " , To:" << BlockNamePrinter (To)
405
+ << " ) = " << BlockNamePrinter (NCD)
406
+ << " ,\t (should be To or IDom[To]: " << BlockNamePrinter (ToIDom)
407
+ << " )\n " ;
408
408
errs ().flush ();
409
409
410
410
return false ;
@@ -470,11 +470,9 @@ struct SemiNCAInfo {
470
470
471
471
for (TreeNodePtr Child : TN->getChildren ())
472
472
if (NodeToInfo.count (Child->getBlock ()) != 0 ) {
473
- errs () << " Child " ;
474
- PrintBlockOrNullptr (errs (), Child->getBlock ());
475
- errs () << " reachable after its parent " ;
476
- PrintBlockOrNullptr (errs (), BB);
477
- errs () << " is removed!\n " ;
473
+ errs () << " Child " << BlockNamePrinter (Child)
474
+ << " reachable after its parent " << BlockNamePrinter (BB)
475
+ << " is removed!\n " ;
478
476
errs ().flush ();
479
477
480
478
return false ;
@@ -507,11 +505,9 @@ struct SemiNCAInfo {
507
505
if (S == N) continue ;
508
506
509
507
if (NodeToInfo.count (S->getBlock ()) == 0 ) {
510
- errs () << " Node " ;
511
- PrintBlockOrNullptr (errs (), S->getBlock ());
512
- errs () << " not reachable when its sibling " ;
513
- PrintBlockOrNullptr (errs (), N->getBlock ());
514
- errs () << " is removed!\n " ;
508
+ errs () << " Node " << BlockNamePrinter (S)
509
+ << " not reachable when its sibling " << BlockNamePrinter (N)
510
+ << " is removed!\n " ;
515
511
errs ().flush ();
516
512
517
513
return false ;
0 commit comments