Skip to content

Commit 1f8a5d6

Browse files
Merge pull request #61168 from adrian-prantl/99874371
Disable SROA debug info for variables with expressions
2 parents 2415288 + 90bbe51 commit 1f8a5d6

File tree

4 files changed

+67
-9
lines changed

4 files changed

+67
-9
lines changed

lib/SIL/IR/SILInstructions.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ SILDebugVariable::createFromAllocation(const AllocationInst *AI) {
169169
// TODO: Support AllocBoxInst
170170

171171
if (!VarInfo)
172-
return VarInfo;
172+
return {};
173173

174-
// Copy everything but the DIExpr
175-
VarInfo->DIExpr.clear();
174+
// TODO: Support variables with expressions.
175+
if (VarInfo->DIExpr)
176+
return {};
176177

177178
// Coalesce the debug loc attached on AI into VarInfo
178179
SILType Type = AI->getType();

lib/SILOptimizer/Transforms/SILSROA.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,8 @@ createAllocas(llvm::SmallVector<AllocStackInst *, 4> &NewAllocations) {
213213
Optional<SILDebugVariable> NewDebugVarInfo =
214214
SILDebugVariable::createFromAllocation(AI);
215215
if (NewDebugVarInfo)
216-
// TODO: Handle DIExpr that is already attached
217-
NewDebugVarInfo->DIExpr = SILDebugInfoExpression::createFragment(VD);
218-
216+
NewDebugVarInfo->DIExpr.append(
217+
SILDebugInfoExpression::createFragment(VD));
219218
NewAllocations.push_back(B.createAllocStack(
220219
Loc, Type.getFieldType(VD, M, TypeExpansionContext(B.getFunction())),
221220
NewDebugVarInfo, AI->hasDynamicLifetime(), AI->isLexical()));

test/DebugInfo/sil_based_dbg.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ struct TheStruct {
2929
}
3030
// CHECK_DBG_SCOPE-LABEL: sil {{.*}}test_debug_scope
3131
public func test_debug_scope(val : Int) -> Int {
32-
// CHECK_DBG_SCOPE: alloc_stack $Builtin.Int{{[0-9]+}}, var, (name "the_struct",
33-
// CHECK_DBG_SCOPE-SAME: loc
32+
// TODO: Repeated SROA of the same variable is currently disabled.
33+
// CHECK_DBG_SCOPE: alloc_stack $Builtin.Int{{[0-9]+}},
34+
// CHECK_DBG_SCOPE-NOT: var,
35+
// DISABLED_DBG_SCOPE-SAME: var, (name "the_struct",
36+
// DISABLED_DBG_SCOPE-SAME: loc
3437
// The auxiliary debug scope should be removed
35-
// CHECK_DBG_SCOPE-NOT: scope {{[0-9]+}})
38+
// DISABLED_DBG_SCOPE-NOT: scope {{[0-9]+}})
3639
var the_struct = TheStruct(the_member: 0)
3740
the_struct.the_member = val + 13
3841
return the_struct.the_member

test/DebugInfo/srosroa_mem2reg.sil

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all -sil-print-debuginfo -sroa %s | %FileCheck --check-prefix=CHECK-SROA %s
2+
sil_stage canonical
3+
4+
import Builtin
5+
import Swift
6+
7+
struct MyStruct {
8+
@_hasStorage var x: Int64 { get set }
9+
@_hasStorage var y: Int64 { get set }
10+
init(x: Int64, y: Int64)
11+
}
12+
13+
struct MyContainer {
14+
@_hasStorage var z: MyStruct { get set }
15+
}
16+
17+
sil_scope 1 { loc "sroa.swift":2:8 parent @MyStructInit : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct }
18+
19+
// MyStruct.init(x:y:)
20+
sil hidden @MyStructInit : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct {
21+
bb0(%0 : $Int64, %1 : $Int64, %2 : $@thin MyStruct.Type):
22+
%3 = struct $MyStruct (%0 : $Int64, %1 : $Int64), loc "sroa.swift":2:8, scope 1
23+
return %3 : $MyStruct, loc "sroa.swift":2:8, scope 1
24+
} // end sil function 'MyStructInit'
25+
26+
sil_scope 2 { loc "sroa.swift":7:6 parent @foo : $@convention(thin) (Int64, Int64) -> Int64 }
27+
28+
// foo(in_x:in_y:)
29+
sil hidden @foo : $@convention(thin) (Int64, Int64) -> Int64 {
30+
bb0(%0 : $Int64, %1 : $Int64):
31+
debug_value %0 : $Int64, let, name "in_x", argno 1, loc "sroa.swift":7:10, scope 2
32+
debug_value %1 : $Int64, let, name "in_y", argno 2, loc "sroa.swift":7:21, scope 2
33+
%4 = alloc_stack $MyStruct, var, name "my_struct", type $*MyContainer, expr op_fragment:#MyContainer.z, loc "sroa.swift":8:9, scope 2
34+
// Recursive SROA of already SROA-ed aggregates is not yet supported.
35+
// CHECK-SROA: alloc_stack $Int64
36+
// CHECK-SROA-NOT: var,
37+
// CHECK-SROA: alloc_stack $Int64
38+
// CHECK-SROA-NOT: var,
39+
// CHECK-SROA: metatype
40+
%5 = metatype $@thin MyStruct.Type, loc "sroa.swift":8:21, scope 2
41+
%6 = integer_literal $Builtin.Int64, 0, loc "sroa.swift":8:33, scope 2
42+
%7 = struct $Int64 (%6 : $Builtin.Int64), loc "sroa.swift":8:33, scope 2
43+
%8 = integer_literal $Builtin.Int64, 0, loc "sroa.swift":8:39, scope 2
44+
%9 = struct $Int64 (%8 : $Builtin.Int64), loc "sroa.swift":8:39, scope 2
45+
// function_ref MyStruct.init(x:y:)
46+
%10 = function_ref @MyStructInit : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct, loc "sroa.swift":8:21, scope 2
47+
%11 = apply %10(%7, %9, %5) : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct, loc "sroa.swift":8:21, scope 2
48+
store %11 to %4 : $*MyStruct, loc "sroa.swift":8:21, scope 2
49+
%13 = struct_element_addr %4 : $*MyStruct, #MyStruct.x, loc "sroa.swift":9:17, scope 2
50+
store %0 to %13 : $*Int64, loc "sroa.swift":9:17, scope 2
51+
%15 = struct_element_addr %4 : $*MyStruct, #MyStruct.y, loc "sroa.swift":10:17, scope 2
52+
store %1 to %15 : $*Int64, loc "sroa.swift":10:17, scope 2
53+
dealloc_stack %4 : $*MyStruct, loc "sroa.swift":8:9, scope 2
54+
return %0 : $Int64, loc "sroa.swift":11:5, scope 2
55+
} // end sil function 'foo'

0 commit comments

Comments
 (0)