Skip to content

Commit 9eef2e9

Browse files
committed
[DebugInfo] Remove Expr from debug variables used as DenseMap keys
We do keep the fragment part of the expression as it is important to identify fragments separately. A variable with less fragments should be considered a superset of variables with more fragments, but that would require to change a lot of code. (cherry picked from commit b293099)
1 parent 91aa53f commit 9eef2e9

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

include/swift/SIL/SILDebugInfoExpression.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,16 @@ class SILDebugInfoExpression {
296296
return Elements.size() &&
297297
Elements[0].getAsOperator() == SILDIExprOperator::Dereference;
298298
}
299+
300+
/// Return the part of this SILDebugInfoExpression corresponding to fragments
301+
SILDebugInfoExpression getFragmentPart() const {
302+
for (auto it = element_begin(), end = element_end(); it != end; ++it) {
303+
if (it->getAsOperator() == SILDIExprOperator::Fragment
304+
|| it->getAsOperator() == SILDIExprOperator::TupleFragment)
305+
return SILDebugInfoExpression(ArrayRef(it, element_end()));
306+
}
307+
return {};
308+
}
299309
};
300310

301311
/// Returns the hashcode for the di expr element.

lib/SILOptimizer/Mandatory/DebugInfoCanonicalizer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ bool DebugInfoCanonicalizer::process() {
221221
LLVM_DEBUG(llvm::dbgs() << " Has no var info?! Skipping!\n");
222222
continue;
223223
}
224+
// Strip things we don't need in the map.
225+
debugInfo->DIExpr = debugInfo->DIExpr.getFragmentPart();
226+
debugInfo->Type = {};
224227

225228
// Otherwise, we may have a new debug_value to track. Try to begin
226229
// tracking it...

lib/SILOptimizer/Mandatory/MoveOnlyUtils.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@ static bool isLetAllocation(MarkUnresolvedNonCopyableValueInst *mmci) {
336336
}
337337

338338
if (auto *asi = dyn_cast<AllocStackInst>(mmci->getOperand()))
339-
if (auto varInfo = asi->getVarInfo())
340-
return varInfo->isLet();
339+
return asi->isLet();
341340

342341
return false;
343342
}

lib/SILOptimizer/Mandatory/MovedAsyncVarDebugInfoPropagator.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,11 @@ struct DebugInfoPropagator {
347347
// var with a count already and return that value. If we did not, we insert
348348
// with the new count before expanding the set (initializing the map with
349349
// the correct value).
350+
auto debugVariable = debugVar;
351+
debugVariable.DIExpr = debugVariable.DIExpr.getFragmentPart();
352+
debugVariable.Type = {};
350353
auto iter = dbgVarToDbgVarIndexMap.insert(
351-
{debugVar, dbgVarToDbgVarIndexMap.size()});
354+
{debugVariable, dbgVarToDbgVarIndexMap.size()});
352355
LLVM_DEBUG(if (iter.second) llvm::dbgs()
353356
<< "Mapping: [" << iter.first->second
354357
<< "] = " << iter.first->first.Name << '\n';);

test/SILOptimizer/debuginfo_canonicalizer.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ bb3:
118118
// CHECK: } // end sil function 'testUndefDiamond'
119119
sil @testUndefDiamond : $@convention(thin) (@guaranteed Klass) -> () {
120120
bb0(%0 : $Klass):
121-
debug_value [moveable_value_debuginfo] %0 : $Klass, let, name "arg"
121+
debug_value [moveable_value_debuginfo] %0 : $Klass, let, (name "arg", loc "debuginfo_canonicalizer.sil":121:3)
122122
%f = function_ref @yieldOnceCoroutine : $@yield_once @convention(method) (@guaranteed Klass) -> @yields @inout Int64
123123
(%3, %token) = begin_apply %f(%0) : $@yield_once @convention(method) (@guaranteed Klass) -> @yields @inout Int64
124124
cond_br undef, bb1, bb2
@@ -128,7 +128,7 @@ bb1:
128128
br bb3
129129

130130
bb2:
131-
debug_value [moveable_value_debuginfo] undef : $Klass, let, name "arg"
131+
debug_value [moveable_value_debuginfo] undef : $Klass, let, (name "arg", loc "debuginfo_canonicalizer.sil":121:3)
132132
abort_apply %token
133133
br bb3
134134

0 commit comments

Comments
 (0)