Skip to content

Commit b6b31c9

Browse files
committed
CoroSplit: Replace ad-hoc implementation of reachability with API from CFG.h
The current ad-hoc implementation used to determine whether a basic block is unreachable doesn't work correctly in the general case (for example it won't detect successors of unreachable blocks as unreachable). This patch replaces it with the correct API that uses a DominatorTree to answer the question correctly and quickly. rdar://77181156 Differential Revision: https://reviews.llvm.org/D102963
1 parent d9cbdf5 commit b6b31c9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/ADT/SmallVector.h"
2727
#include "llvm/ADT/StringRef.h"
2828
#include "llvm/ADT/Twine.h"
29+
#include "llvm/Analysis/CFG.h"
2930
#include "llvm/Analysis/CallGraph.h"
3031
#include "llvm/Analysis/CallGraphSCCPass.h"
3132
#include "llvm/Analysis/LazyCallGraph.h"
@@ -37,6 +38,7 @@
3738
#include "llvm/IR/Constants.h"
3839
#include "llvm/IR/DataLayout.h"
3940
#include "llvm/IR/DerivedTypes.h"
41+
#include "llvm/IR/Dominators.h"
4042
#include "llvm/IR/Function.h"
4143
#include "llvm/IR/GlobalValue.h"
4244
#include "llvm/IR/GlobalVariable.h"
@@ -659,8 +661,10 @@ static void salvageCoroDebugInfo(llvm::Function &NewF) {
659661

660662
// Remove all salvaged dbg.declare intrinsics that became
661663
// either unreachable or stale due to the CoroSplit transformation.
664+
DominatorTree DomTree(NewF);
665+
SmallDenseMap<BasicBlock *, bool, 8> UnreachableCache;
662666
auto IsUnreachableBlock = [&](BasicBlock *BB) {
663-
return BB->hasNPredecessors(0) && BB != &NewF.getEntryBlock();
667+
return !isPotentiallyReachable(&NewF.getEntryBlock(), BB, &DomTree);
664668
};
665669
for (DbgDeclareInst *DDI : Worklist) {
666670
if (IsUnreachableBlock(DDI->getParent()))

llvm/test/Transforms/Coroutines/coro-debug.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ entry:
2020
store i8* %2, i8** %coro_hdl, align 8, !dbg !16
2121
%3 = call i8 @llvm.coro.suspend(token none, i1 false), !dbg !17
2222
%conv = sext i8 %3 to i32, !dbg !17
23+
%late_local = alloca i32, align 4
2324
call void @coro.devirt.trigger(i8* null)
2425
switch i32 %conv, label %sw.default [
2526
i32 0, label %sw.bb
@@ -57,6 +58,7 @@ coro_Cleanup: ; preds = %sw.epilog, %sw.bb1
5758
coro_Suspend: ; preds = %coro_Cleanup, %sw.default
5859
%7 = call i1 @llvm.coro.end(i8* null, i1 false) #7, !dbg !24
5960
%8 = load i8*, i8** %coro_hdl, align 8, !dbg !24
61+
store i32 0, i32* %late_local, !dbg !24
6062
ret i8* %8, !dbg !24
6163
}
6264

@@ -147,6 +149,8 @@ attributes #7 = { noduplicate }
147149
; CHECK: store %f.Frame* {{.*}}, %f.Frame** %[[DBG_PTR]]
148150
; CHECK-NOT: alloca %struct.test*
149151
; CHECK: call void @llvm.dbg.declare(metadata i32 0, metadata ![[RESUME_CONST:[0-9]+]], metadata !DIExpression())
152+
; Note that keeping the undef value here could be acceptable, too.
153+
; CHECK-NOT: call void @llvm.dbg.declare(metadata i32* undef, metadata !{{[0-9]+}}, metadata !DIExpression())
150154
; CHECK: call void @coro.devirt.trigger(i8* null)
151155
; CHECK: define internal fastcc void @f.destroy(%f.Frame* noalias nonnull align 8 dereferenceable(32) %FramePtr) #0 !dbg ![[DESTROY:[0-9]+]]
152156
; CHECK: define internal fastcc void @f.cleanup(%f.Frame* noalias nonnull align 8 dereferenceable(32) %FramePtr) #0 !dbg ![[CLEANUP:[0-9]+]]

0 commit comments

Comments
 (0)