Skip to content

CoroSplit: Replace ad-hoc implementation of reachability with API from CFG.h #2994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion llvm/lib/Transforms/Coroutines/CoroSplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/Analysis/LazyCallGraph.h"
Expand All @@ -37,6 +38,7 @@
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
Expand Down Expand Up @@ -659,8 +661,10 @@ static void salvageCoroDebugInfo(llvm::Function &NewF) {

// Remove all salvaged dbg.declare intrinsics that became
// either unreachable or stale due to the CoroSplit transformation.
DominatorTree DomTree(NewF);
SmallDenseMap<BasicBlock *, bool, 8> UnreachableCache;
auto IsUnreachableBlock = [&](BasicBlock *BB) {
return BB->hasNPredecessors(0) && BB != &NewF.getEntryBlock();
return !isPotentiallyReachable(&NewF.getEntryBlock(), BB, &DomTree);
};
for (DbgDeclareInst *DDI : Worklist) {
if (IsUnreachableBlock(DDI->getParent()))
Expand Down
4 changes: 4 additions & 0 deletions llvm/test/Transforms/Coroutines/coro-debug.ll
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ entry:
store i8* %2, i8** %coro_hdl, align 8, !dbg !16
%3 = call i8 @llvm.coro.suspend(token none, i1 false), !dbg !17
%conv = sext i8 %3 to i32, !dbg !17
%late_local = alloca i32, align 4
call void @coro.devirt.trigger(i8* null)
switch i32 %conv, label %sw.default [
i32 0, label %sw.bb
Expand Down Expand Up @@ -57,6 +58,7 @@ coro_Cleanup: ; preds = %sw.epilog, %sw.bb1
coro_Suspend: ; preds = %coro_Cleanup, %sw.default
%7 = call i1 @llvm.coro.end(i8* null, i1 false) #7, !dbg !24
%8 = load i8*, i8** %coro_hdl, align 8, !dbg !24
store i32 0, i32* %late_local, !dbg !24
ret i8* %8, !dbg !24
}

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