@@ -103,6 +103,7 @@ void Analysis::setSignature() {
103
103
}
104
104
Signature += " )" ;
105
105
DEBUG_PRINT (" Signature: " << Signature);
106
+ // outs() << "Signature: " << Signature << "\n";
106
107
}
107
108
108
109
void Analysis::extractCondChains () {
@@ -327,11 +328,15 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
327
328
BaseCond *Condition = BlkCond.Condition ;
328
329
bool Flag = BlkCond.Flag ;
329
330
bool InLoop = BlkCond.InLoop ;
331
+ vector<unsigned > LoopBlks = BlkCond.LoopBlks ;
330
332
unsigned ID = Blk->getBlockID ();
331
333
332
334
DEBUG_PRINT (" Block: " << ID << " Parent: " << Parent);
333
335
// DEBUG_EXEC(dumpBlkChain());
334
336
337
+ if (ID == 43 )
338
+ int A = 0 ;
339
+
335
340
if (ColorOfBlk[ID] == 0 )
336
341
ColorOfBlk[ID] = 1 ;
337
342
@@ -351,6 +356,8 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
351
356
if (binary_search (SortedPath.begin (), SortedPath.end (), Blk)) {
352
357
DEBUG_PRINT (" Loop detected at Block " << Blk->getBlockID () << " in "
353
358
<< Signature);
359
+ if (Blk->getBlockID () == 44 )
360
+ int A = 0 ;
354
361
DEBUG_EXEC (unsigned I = 0 ; for (const CFGBlock *Blk
355
362
: Path) {
356
363
if (I++ > 0 )
@@ -364,16 +371,23 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
364
371
if (LoopInner[Blk->getBlockID ()].find (Adj->getBlockID ()) !=
365
372
LoopInner[Blk->getBlockID ()].end ())
366
373
continue ;
367
- Stack.push ({Parent, Adj, Condition, Flag, true });
374
+ outs () << " Stack push " << Adj->getBlockID () << " \n " ;
375
+ vector<unsigned > Loop = {};
376
+ for (const CFGBlock *Blk : Path) {
377
+ Loop.push_back (Blk->getBlockID ());
378
+ }
379
+ Stack.push ({Parent, Adj, Condition, Flag, true , Loop});
368
380
Traverse = true ;
369
381
}
370
382
}
371
383
}
384
+ // FIXME: consider remove this
372
385
if (!Traverse && InLoop) {
373
386
unsigned PathSize = Path.size ();
374
387
for (unsigned I = PathSize - 1 ; I > 0 ; --I) {
375
388
const CFGBlock *Succ = Path[I];
376
389
const CFGBlock *Pred = Path[I - 1 ];
390
+ outs () << " Clear Block " << Succ->getBlockID () << " \n " ;
377
391
CondChainForBlk[Succ->getBlockID ()] = {}; // clear
378
392
bool IsSucc = isSucc (Pred, Succ);
379
393
if (!IsSucc) {
@@ -398,7 +412,8 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
398
412
if (Terminator) {
399
413
switch (Terminator->getStmtClass ()) {
400
414
default :
401
- errs () << " Unhandled Terminator: " << Terminator->getStmtClassName () << " \n " ;
415
+ errs () << " Unhandled Terminator: " << Terminator->getStmtClassName ()
416
+ << " \n " ;
402
417
break ;
403
418
case Stmt::ConditionalOperatorClass:
404
419
case Stmt::BinaryOperatorClass:
@@ -411,16 +426,16 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
411
426
const CFGBlock::AdjacentBlock *Adj = Blk->succ_begin ();
412
427
if (Cond) {
413
428
if (Adj->isReachable ()) {
414
- Stack.push ({ID, *Adj, Cond, true , InLoop});
429
+ Stack.push ({ID, *Adj, Cond, true , InLoop, LoopBlks });
415
430
}
416
431
if (Blk->succ_size () == 2 ) {
417
432
++Adj;
418
433
if (Adj->isReachable ()) {
419
- Stack.push ({ID, *Adj, Cond, false , InLoop});
434
+ Stack.push ({ID, *Adj, Cond, false , InLoop, LoopBlks });
420
435
}
421
436
}
422
437
} else if (Adj->isReachable ()) {
423
- Stack.push ({ID, *Adj, nullptr , false , InLoop});
438
+ Stack.push ({ID, *Adj, nullptr , false , InLoop, LoopBlks });
424
439
}
425
440
break ;
426
441
}
@@ -444,7 +459,7 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
444
459
Cond = new CaseCond (cast<Expr>(InnerCond)->IgnoreParenImpCasts (),
445
460
Case);
446
461
}
447
- Stack.push ({ID, Adj, Cond, true , InLoop});
462
+ Stack.push ({ID, Adj, Cond, true , InLoop, LoopBlks });
448
463
} else {
449
464
// Default case
450
465
assert (Label->getStmtClass () == Stmt::DefaultStmtClass);
@@ -456,7 +471,7 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
456
471
if (InnerCond) {
457
472
Cond = new DefaultCond (InnerCond, Cases);
458
473
}
459
- Stack.push ({ID, DefaultBlk, Cond, false , InLoop});
474
+ Stack.push ({ID, DefaultBlk, Cond, false , InLoop, LoopBlks });
460
475
}
461
476
break ;
462
477
}
@@ -472,31 +487,35 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
472
487
const CFGBlock::AdjacentBlock *Adj = Blk->succ_begin ();
473
488
if (InnerCond) {
474
489
if (Adj->isReachable ()) {
475
- Stack.push ({ID, *Adj, Cond, true , InLoop});
490
+ outs () << " Stack push " << (*Adj)->getBlockID () << " \n " ;
491
+ Stack.push ({ID, *Adj, Cond, true , InLoop, LoopBlks});
476
492
}
477
493
if (Blk->succ_size () == 2 ) {
478
494
++Adj;
479
495
if (Adj->isReachable ()) {
480
- Stack.push ({ID, *Adj, Cond, false , InLoop});
496
+ outs () << " Stack push " << (*Adj)->getBlockID () << " \n " ;
497
+ Stack.push ({ID, *Adj, Cond, false , InLoop, LoopBlks});
481
498
}
482
499
}
483
500
} else if (Adj->isReachable ()) {
484
- Stack.push ({ID, *Adj, nullptr , false , InLoop});
501
+ outs () << " Stack push " << (*Adj)->getBlockID () << " \n " ;
502
+ Stack.push ({ID, *Adj, nullptr , false , InLoop, LoopBlks});
485
503
}
486
504
break ;
487
505
}
488
506
case Stmt::BreakStmtClass:
489
507
case Stmt::ContinueStmtClass:
490
508
case Stmt::GotoStmtClass: {
491
509
if (Blk->succ_begin ()->isReachable ()) {
492
- Stack.push ({ID, *Blk->succ_begin (), nullptr , false , InLoop});
510
+ Stack.push (
511
+ {ID, *Blk->succ_begin (), nullptr , false , InLoop, LoopBlks});
493
512
}
494
513
break ;
495
514
}
496
515
}
497
516
} else if (Blk->succ_size () == 1 ) {
498
517
if (Blk->succ_begin ()->isReachable ()) {
499
- Stack.push ({ID, *Blk->succ_begin (), nullptr , false , InLoop});
518
+ Stack.push ({ID, *Blk->succ_begin (), nullptr , false , InLoop, LoopBlks });
500
519
}
501
520
} else if (Blk->getBlockID () == Cfg->getExit ().getBlockID ()) {
502
521
// Exit Block
0 commit comments