[llvm] 5e442a5 - [Attributor][NFC] Do not delete dead blocks but "clear" them

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 30 22:10:16 PDT 2019


Author: Johannes Doerfert
Date: 2019-10-31T00:09:50-05:00
New Revision: 5e442a51bce73f3e69eef022674acfb28224619d

URL: https://github.com/llvm/llvm-project/commit/5e442a51bce73f3e69eef022674acfb28224619d
DIFF: https://github.com/llvm/llvm-project/commit/5e442a51bce73f3e69eef022674acfb28224619d.diff

LOG: [Attributor][NFC] Do not delete dead blocks but "clear" them

Deleting blocks will require us to deal with dead edges, e.g.,
  `br i1 false, label %live, label %dead`
explicitly. For now we just clear the blocks and move on.
This will be revisited once we actually fold branches.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/Attributor.cpp
    llvm/test/Transforms/FunctionAttrs/liveness.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 11a4939da781..129eb1976745 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -4644,9 +4644,12 @@ ChangeStatus Attributor::run(Module &M) {
       SmallVector<BasicBlock *, 8> ToBeDeletedBBs;
       ToBeDeletedBBs.reserve(NumDeadBlocks);
       ToBeDeletedBBs.append(ToBeDeletedBlocks.begin(), ToBeDeletedBlocks.end());
-      DeleteDeadBlocks(ToBeDeletedBBs);
-      STATS_DECLTRACK(AAIsDead, BasicBlock,
-                      "Number of dead basic blocks deleted.");
+      // Actually we do not delete the blocks but squash them into a single
+      // unreachable but untangling branches that jump here is something we need
+      // to do in a more generic way.
+      DetatchDeadBlocks(ToBeDeletedBBs, nullptr);
+      STATS_DECL(AAIsDead, BasicBlock, "Number of dead basic blocks deleted.");
+      BUILD_STAT_NAME(AAIsDead, BasicBlock) += ToBeDeletedBlocks.size();
     }
 
     STATS_DECL(AAIsDead, Function, "Number of dead functions deleted.");

diff  --git a/llvm/test/Transforms/FunctionAttrs/liveness.ll b/llvm/test/Transforms/FunctionAttrs/liveness.ll
index e1bcb31d288a..f029f9476b75 100644
--- a/llvm/test/Transforms/FunctionAttrs/liveness.ll
+++ b/llvm/test/Transforms/FunctionAttrs/liveness.ll
@@ -56,7 +56,6 @@ entry:
   call void @no_return_call()
   ; CHECK: call void @no_return_call()
   ; CHECK-NEXT: unreachable
-  ; CHECK-NEXT: }
   call i32 @dead_internal_func(i32 10)
   %cmp = icmp eq i32 %a, 0
   br i1 %cmp, label %cond.true, label %cond.false
@@ -130,7 +129,6 @@ cond.false:                                       ; preds = %entry
   ; CHECK: call void @no_return_call()
   ; CHECK-NEXT: unreachable
   call i32 @dead_internal_func(i32 10)
-  ; CHECK-NEXT: }
   %call1 = call i32 @bar()
   br label %cond.end
 
@@ -526,7 +524,6 @@ define linkonce_odr void @non_exact3() {
 ; CHECK-NEXT:   call void @non_dead_d15()
 ; CHECK-NEXT:   %nr = call i32 @foo_noreturn()
 ; CHECK-NEXT:   unreachable
-; CHECK-NEXT: }
 
 define internal void @non_dead_a0() { ret void }
 define internal void @non_dead_a1() { ret void }


        


More information about the llvm-commits mailing list