@@ -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
28522853static std::optional<std::pair<Value &, DIExpression &>>
28532854salvageDebugInfoImpl (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
29302933void 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
29722975void 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
0 commit comments