@@ -400,7 +400,8 @@ struct RefPrunePass : public FunctionPass {
400
400
SmallBBSet tail_nodes;
401
401
tail_nodes.insert (decref->getParent ());
402
402
if (!verifyFanoutBackward (incref, incref->getParent (),
403
- &tail_nodes))
403
+ &tail_nodes, false ))
404
+
404
405
continue ;
405
406
406
407
// scan the CFG between the incref and decref BBs, if
@@ -495,6 +496,29 @@ struct RefPrunePass : public FunctionPass {
495
496
* │ MORE CFG │
496
497
* └────────────┘
497
498
*
499
+ * a complex pattern about fanout-raise
500
+ * https://github.com/numba/llvmlite/issues/1023
501
+ * ┌────────────┐
502
+ * │ incref │
503
+ * │ incref │
504
+ * └────────────┘
505
+ * / \
506
+ * / \
507
+ * ┌────────────┐ \
508
+ * │ decref | \
509
+ * └────────────┘ \
510
+ * / \ \
511
+ * / \ \
512
+ * ┌────────────┐ ┌────────────┐ \
513
+ * │ decref | │ incref | \
514
+ * └────────────┘ └────────────┘ \
515
+ * / \ \
516
+ * / \ \
517
+ * ┌────────────┐ ┌────────────┐
518
+ * │ decref | │ raise |
519
+ * │ decref | └────────────┘
520
+ * └────────────┘
521
+ *
498
522
* Parameters:
499
523
* - F a Function
500
524
* - prune_raise_exit, if false case 1 is considered, if true case 2 is
@@ -648,10 +672,12 @@ struct RefPrunePass : public FunctionPass {
648
672
for (BasicBlock *bb : *decref_blocks) {
649
673
raising_blocks.insert (bb);
650
674
}
651
- if (verifyFanoutBackward (incref, head_node, p_raising_blocks))
675
+ if (verifyFanoutBackward (incref, head_node, p_raising_blocks,
676
+ prune_raise_exit))
652
677
return true ;
653
678
654
- } else if (verifyFanoutBackward (incref, head_node, decref_blocks)) {
679
+ } else if (verifyFanoutBackward (incref, head_node, decref_blocks,
680
+ prune_raise_exit)) {
655
681
return true ;
656
682
}
657
683
}
@@ -844,7 +870,8 @@ struct RefPrunePass : public FunctionPass {
844
870
*
845
871
*/
846
872
bool verifyFanoutBackward (CallInst *incref, BasicBlock *head_node,
847
- const SmallBBSet *tail_nodes) {
873
+ const SmallBBSet *tail_nodes,
874
+ bool prune_raise_exit) {
848
875
// push the tail nodes into a work list
849
876
SmallVector<BasicBlock *, 10 > todo;
850
877
for (BasicBlock *bb : *tail_nodes) {
@@ -864,6 +891,10 @@ struct RefPrunePass : public FunctionPass {
864
891
while (workstack.size () > 0 ) {
865
892
// Get a basic block
866
893
BasicBlock *cur_node = workstack.pop_back_val ();
894
+ // If cur_node is a raising block, then skip it
895
+ if (prune_raise_exit && isRaising (cur_node)) {
896
+ continue ;
897
+ }
867
898
// if the block has been seen before then skip
868
899
if (visited.count (cur_node)) {
869
900
// Already visited
0 commit comments