Skip to content

Commit e2e54d3

Browse files
gribozavrcjdb
authored andcommitted
Revert "[Coroutines] Salvage the debug information for coroutine frames within optimizations"
This reverts commit 522c253. This series of commits causes Clang crashes. The reproducer is posted on llvm@08a0dec.
1 parent f4fcfee commit e2e54d3

File tree

5 files changed

+31
-65
lines changed

5 files changed

+31
-65
lines changed

clang/test/CodeGenCoroutines/coro-dwarf-O2.cpp

Lines changed: 0 additions & 39 deletions
This file was deleted.

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,8 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
19141914
}
19151915
// This dbg.declare is for the main function entry point. It
19161916
// will be deleted in all coro-split functions.
1917-
coro::salvageDebugInfo(ArgToAllocaMap, *DDI, false /*UseEntryValue*/);
1917+
coro::salvageDebugInfo(ArgToAllocaMap, *DDI, Shape.OptimizeFrame,
1918+
false /*UseEntryValue*/);
19181919
};
19191920
for_each(DIs, SalvageOne);
19201921
for_each(DVRs, SalvageOne);
@@ -2851,8 +2852,9 @@ static void collectFrameAlloca(AllocaInst *AI, coro::Shape &Shape,
28512852

28522853
static std::optional<std::pair<Value &, DIExpression &>>
28532854
salvageDebugInfoImpl(SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
2854-
bool UseEntryValue, Function *F, Value *Storage,
2855-
DIExpression *Expr, bool SkipOutermostLoad) {
2855+
bool OptimizeFrame, bool UseEntryValue, Function *F,
2856+
Value *Storage, DIExpression *Expr,
2857+
bool SkipOutermostLoad) {
28562858
IRBuilder<> Builder(F->getContext());
28572859
auto InsertPt = F->getEntryBlock().getFirstInsertionPt();
28582860
while (isa<IntrinsicInst>(InsertPt))
@@ -2904,9 +2906,10 @@ salvageDebugInfoImpl(SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
29042906

29052907
// If the coroutine frame is an Argument, store it in an alloca to improve
29062908
// its availability (e.g. registers may be clobbered).
2907-
// Avoid this if the value is guaranteed to be available through other means
2908-
// (e.g. swift ABI guarantees).
2909-
if (StorageAsArg && !IsSwiftAsyncArg) {
2909+
// Avoid this if optimizations are enabled (they would remove the alloca) or
2910+
// if the value is guaranteed to be available through other means (e.g. swift
2911+
// ABI guarantees).
2912+
if (StorageAsArg && !OptimizeFrame && !IsSwiftAsyncArg) {
29102913
auto &Cached = ArgToAllocaMap[StorageAsArg];
29112914
if (!Cached) {
29122915
Cached = Builder.CreateAlloca(Storage->getType(), 0, nullptr,
@@ -2929,17 +2932,17 @@ salvageDebugInfoImpl(SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
29292932

29302933
void coro::salvageDebugInfo(
29312934
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
2932-
DbgVariableIntrinsic &DVI, bool UseEntryValue) {
2935+
DbgVariableIntrinsic &DVI, bool OptimizeFrame, bool UseEntryValue) {
29332936

29342937
Function *F = DVI.getFunction();
29352938
// Follow the pointer arithmetic all the way to the incoming
29362939
// function argument and convert into a DIExpression.
29372940
bool SkipOutermostLoad = !isa<DbgValueInst>(DVI);
29382941
Value *OriginalStorage = DVI.getVariableLocationOp(0);
29392942

2940-
auto SalvagedInfo =
2941-
::salvageDebugInfoImpl(ArgToAllocaMap, UseEntryValue, F, OriginalStorage,
2942-
DVI.getExpression(), SkipOutermostLoad);
2943+
auto SalvagedInfo = ::salvageDebugInfoImpl(
2944+
ArgToAllocaMap, OptimizeFrame, UseEntryValue, F, OriginalStorage,
2945+
DVI.getExpression(), SkipOutermostLoad);
29432946
if (!SalvagedInfo)
29442947
return;
29452948

@@ -2971,17 +2974,17 @@ void coro::salvageDebugInfo(
29712974

29722975
void coro::salvageDebugInfo(
29732976
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
2974-
DbgVariableRecord &DVR, bool UseEntryValue) {
2977+
DbgVariableRecord &DVR, bool OptimizeFrame, bool UseEntryValue) {
29752978

29762979
Function *F = DVR.getFunction();
29772980
// Follow the pointer arithmetic all the way to the incoming
29782981
// function argument and convert into a DIExpression.
29792982
bool SkipOutermostLoad = DVR.isDbgDeclare();
29802983
Value *OriginalStorage = DVR.getVariableLocationOp(0);
29812984

2982-
auto SalvagedInfo =
2983-
::salvageDebugInfoImpl(ArgToAllocaMap, UseEntryValue, F, OriginalStorage,
2984-
DVR.getExpression(), SkipOutermostLoad);
2985+
auto SalvagedInfo = ::salvageDebugInfoImpl(
2986+
ArgToAllocaMap, OptimizeFrame, UseEntryValue, F, OriginalStorage,
2987+
DVR.getExpression(), SkipOutermostLoad);
29852988
if (!SalvagedInfo)
29862989
return;
29872990

llvm/lib/Transforms/Coroutines/CoroInternal.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ void replaceCoroFree(CoroIdInst *CoroId, bool Elide);
2929
/// Attempts to rewrite the location operand of debug intrinsics in terms of
3030
/// the coroutine frame pointer, folding pointer offsets into the DIExpression
3131
/// of the intrinsic.
32-
/// If the frame pointer is an Argument, store it into an alloca to enhance the
33-
/// debugability.
32+
/// If the frame pointer is an Argument, store it into an alloca if
33+
/// OptimizeFrame is false.
3434
void salvageDebugInfo(
3535
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
36-
DbgVariableIntrinsic &DVI, bool IsEntryPoint);
36+
DbgVariableIntrinsic &DVI, bool OptimizeFrame, bool IsEntryPoint);
3737
void salvageDebugInfo(
3838
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
39-
DbgVariableRecord &DVR, bool UseEntryValue);
39+
DbgVariableRecord &DVR, bool OptimizeFrame, bool UseEntryValue);
4040

4141
// Keeps data and helper functions for lowering coroutine intrinsics.
4242
struct LowererBase {

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -735,9 +735,11 @@ void CoroCloner::salvageDebugInfo() {
735735
bool UseEntryValue =
736736
llvm::Triple(OrigF.getParent()->getTargetTriple()).isArch64Bit();
737737
for (DbgVariableIntrinsic *DVI : Worklist)
738-
coro::salvageDebugInfo(ArgToAllocaMap, *DVI, UseEntryValue);
738+
coro::salvageDebugInfo(ArgToAllocaMap, *DVI, Shape.OptimizeFrame,
739+
UseEntryValue);
739740
for (DbgVariableRecord *DVR : DbgVariableRecords)
740-
coro::salvageDebugInfo(ArgToAllocaMap, *DVR, UseEntryValue);
741+
coro::salvageDebugInfo(ArgToAllocaMap, *DVR, Shape.OptimizeFrame,
742+
UseEntryValue);
741743

742744
// Remove all salvaged dbg.declare intrinsics that became
743745
// either unreachable or stale due to the CoroSplit transformation.
@@ -1960,9 +1962,11 @@ splitCoroutine(Function &F, SmallVectorImpl<Function *> &Clones,
19601962
SmallDenseMap<Argument *, AllocaInst *, 4> ArgToAllocaMap;
19611963
auto [DbgInsts, DbgVariableRecords] = collectDbgVariableIntrinsics(F);
19621964
for (auto *DDI : DbgInsts)
1963-
coro::salvageDebugInfo(ArgToAllocaMap, *DDI, false /*UseEntryValue*/);
1965+
coro::salvageDebugInfo(ArgToAllocaMap, *DDI, Shape.OptimizeFrame,
1966+
false /*UseEntryValue*/);
19641967
for (DbgVariableRecord *DVR : DbgVariableRecords)
1965-
coro::salvageDebugInfo(ArgToAllocaMap, *DVR, false /*UseEntryValue*/);
1968+
coro::salvageDebugInfo(ArgToAllocaMap, *DVR, Shape.OptimizeFrame,
1969+
false /*UseEntryValue*/);
19661970
return Shape;
19671971
}
19681972

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split<reuse-storage>),function(sroa)' -S | FileCheck %s
22
; RUN: opt --try-experimental-debuginfo-iterators < %s -passes='module(coro-early),cgscc(coro-split<reuse-storage>),function(sroa)' -S | FileCheck %s
33

4-
; Checks the dbg informations about promise and coroutine frames under O2.
4+
; Checks whether the dbg.declare for `__promise` remains valid under O2.
55

66
; CHECK-LABEL: define internal fastcc void @f.resume({{.*}})
77
; CHECK: entry.resume:
8-
; CHECK: #dbg_value(ptr poison, ![[PROMISEVAR_RESUME:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 16
9-
; CHECK: #dbg_value(ptr %begin, ![[CORO_FRAME:[0-9]+]], !DIExpression(DW_OP_deref)
8+
; CHECK: #dbg_declare(ptr %begin, ![[PROMISEVAR_RESUME:[0-9]+]], !DIExpression(
109
;
11-
; CHECK: ![[CORO_FRAME]] = !DILocalVariable(name: "__coro_frame"
1210
; CHECK: ![[PROMISEVAR_RESUME]] = !DILocalVariable(name: "__promise"
1311
%promise_type = type { i32, i32, double }
1412

0 commit comments

Comments
 (0)