Skip to content

Commit dec144c

Browse files
Merge pull request #2994 from adrian-prantl/77181156
CoroSplit: Replace ad-hoc implementation of reachability with API from CFG.h
2 parents 22c2c44 + b6b31c9 commit dec144c

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)