Skip to content

Commit 16c57ae

Browse files
committed
[DebugInfo] Salvage integer literals
1 parent 84dae7c commit 16c57ae

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,25 @@ void swift::salvageDebugInfo(SILInstruction *I) {
19641964
}
19651965
}
19661966
}
1967+
1968+
if (auto *IL = dyn_cast<IntegerLiteralInst>(I)) {
1969+
APInt value = IL->getValue();
1970+
const SILDIExprElement ExprElements[2] = {
1971+
SILDIExprElement::createOperator(value.isNegative() ?
1972+
SILDIExprOperator::ConstSInt : SILDIExprOperator::ConstUInt),
1973+
SILDIExprElement::createConstInt(value.getLimitedValue()),
1974+
};
1975+
for (Operand *U : getDebugUses(IL)) {
1976+
auto *DbgInst = cast<DebugValueInst>(U->getUser());
1977+
auto VarInfo = DbgInst->getVarInfo();
1978+
if (!VarInfo)
1979+
continue;
1980+
VarInfo->DIExpr.prependElements(ExprElements);
1981+
// Create a new debug_value, with undef, and the correct const int
1982+
SILBuilder(DbgInst, DbgInst->getDebugScope())
1983+
.createDebugValue(DbgInst->getLoc(), SILUndef::get(IL), *VarInfo);
1984+
}
1985+
}
19671986
}
19681987

19691988
void swift::salvageLoadDebugInfo(LoadOperation load) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend -O -g -emit-sil %s | %FileCheck %s
2+
3+
// In optimized code, a + b will be folded to 5, but we should still keep their
4+
// debug values.
5+
6+
// CHECK-LABEL: sil
7+
public func f() -> Int {
8+
let a = 2
9+
let b = 3
10+
// CHECK: debug_value undef : $Builtin.Int64, let, name "a", type $Int, expr op_constu:2:op_fragment:#Int._value
11+
// CHECK: debug_value undef : $Builtin.Int64, let, name "b", type $Int, expr op_constu:3:op_fragment:#Int._value
12+
return a + b
13+
}

test/SILOptimizer/dead_array_elim.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -O -emit-sil -primary-file %s | %FileCheck %s
1+
// RUN: %target-swift-frontend -O -emit-sil -primary-file %s | grep -v debug_value | %FileCheck %s
22

33
// REQUIRES: swift_stdlib_no_asserts
44
// REQUIRES: swift_in_compiler
@@ -62,9 +62,7 @@ func testDeadArrayElimWithAddressOnlyValues<T>(x: T, y: T) {
6262
// RLE needs to handle the new init pattern - rdar://117751668
6363
// TODO-LABEL: sil hidden {{.*}}@$s15dead_array_elim31testDeadArrayAfterOptimizationsySiSSF
6464
// TODO: bb0(%0 : $String):
65-
// TODO-NEXT: debug_value
6665
// TODO-NEXT: integer_literal $Builtin.Int{{[0-9]+}}, 21
67-
// TODO-NEXT: debug_value
6866
// TODO-NEXT: struct $Int
6967
// TODO-NEXT: return
7068
// TODO: } // end sil function '$s15dead_array_elim31testDeadArrayAfterOptimizationsySiSSF'
@@ -85,7 +83,6 @@ func testDeadArrayAfterOptimizations(_ stringParameter: String) -> Int {
8583
// CHECK-LABEL: sil hidden @$s15dead_array_elim15testNestedArraySiyF
8684
// CHECK: bb0:
8785
// CHECK-NEXT: integer_literal $Builtin.Int{{[0-9]+}}, 3
88-
// CHECK-NEXT: debug_value
8986
// CHECK-NEXT: struct $Int
9087
// CHECK-NEXT: return
9188
// CHECK: } // end sil function '$s15dead_array_elim15testNestedArraySiyF'

test/SILOptimizer/optionset.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-frontend -parse-as-library -primary-file %s -O -sil-verify-all -module-name=test -emit-sil | %FileCheck %s
2-
// RUN: %target-swift-frontend -parse-as-library -primary-file %s -Osize -sil-verify-all -module-name=test -emit-sil | %FileCheck %s
1+
// RUN: %target-swift-frontend -parse-as-library -primary-file %s -O -sil-verify-all -module-name=test -emit-sil | grep -v debug_value | %FileCheck %s
2+
// RUN: %target-swift-frontend -parse-as-library -primary-file %s -Osize -sil-verify-all -module-name=test -emit-sil | grep -v debug_value | %FileCheck %s
33
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
44
// REQUIRES: swift_in_compiler
55

0 commit comments

Comments
 (0)