Skip to content

Disable SROA debug info for variables with expressions #61168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/SIL/IR/SILInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ SILDebugVariable::createFromAllocation(const AllocationInst *AI) {
// TODO: Support AllocBoxInst

if (!VarInfo)
return VarInfo;
return {};

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

// Coalesce the debug loc attached on AI into VarInfo
SILType Type = AI->getType();
Expand Down
5 changes: 2 additions & 3 deletions lib/SILOptimizer/Transforms/SILSROA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,8 @@ createAllocas(llvm::SmallVector<AllocStackInst *, 4> &NewAllocations) {
Optional<SILDebugVariable> NewDebugVarInfo =
SILDebugVariable::createFromAllocation(AI);
if (NewDebugVarInfo)
// TODO: Handle DIExpr that is already attached
NewDebugVarInfo->DIExpr = SILDebugInfoExpression::createFragment(VD);

NewDebugVarInfo->DIExpr.append(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking: what if we don't clear out DIExpr from the existing VarInfo in SILDebugVariable::createFromAllocation so that this line will append fragment of the inner member. But then I realized we can't have more than one fragment inside a single DIExpression, right? If that's the case, then I do think this is the best solution we have now (until we have the infrastructure to merge two fragments inside a DIExpression)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right — just appending the fragments would be the right thing to do, but it's currently not actually supported. I don't think there's much missing from making this work though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! then I think this LGTM.

SILDebugInfoExpression::createFragment(VD));
NewAllocations.push_back(B.createAllocStack(
Loc, Type.getFieldType(VD, M, TypeExpansionContext(B.getFunction())),
NewDebugVarInfo, AI->hasDynamicLifetime(), AI->isLexical()));
Expand Down
9 changes: 6 additions & 3 deletions test/DebugInfo/sil_based_dbg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ struct TheStruct {
}
// CHECK_DBG_SCOPE-LABEL: sil {{.*}}test_debug_scope
public func test_debug_scope(val : Int) -> Int {
// CHECK_DBG_SCOPE: alloc_stack $Builtin.Int{{[0-9]+}}, var, (name "the_struct",
// CHECK_DBG_SCOPE-SAME: loc
// TODO: Repeated SROA of the same variable is currently disabled.
// CHECK_DBG_SCOPE: alloc_stack $Builtin.Int{{[0-9]+}},
// CHECK_DBG_SCOPE-NOT: var,
// DISABLED_DBG_SCOPE-SAME: var, (name "the_struct",
// DISABLED_DBG_SCOPE-SAME: loc
// The auxiliary debug scope should be removed
// CHECK_DBG_SCOPE-NOT: scope {{[0-9]+}})
// DISABLED_DBG_SCOPE-NOT: scope {{[0-9]+}})
var the_struct = TheStruct(the_member: 0)
the_struct.the_member = val + 13
return the_struct.the_member
Expand Down
55 changes: 55 additions & 0 deletions test/DebugInfo/srosroa_mem2reg.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// RUN: %target-sil-opt -enable-sil-verify-all -sil-print-debuginfo -sroa %s | %FileCheck --check-prefix=CHECK-SROA %s
sil_stage canonical

import Builtin
import Swift

struct MyStruct {
@_hasStorage var x: Int64 { get set }
@_hasStorage var y: Int64 { get set }
init(x: Int64, y: Int64)
}

struct MyContainer {
@_hasStorage var z: MyStruct { get set }
}

sil_scope 1 { loc "sroa.swift":2:8 parent @MyStructInit : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct }

// MyStruct.init(x:y:)
sil hidden @MyStructInit : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct {
bb0(%0 : $Int64, %1 : $Int64, %2 : $@thin MyStruct.Type):
%3 = struct $MyStruct (%0 : $Int64, %1 : $Int64), loc "sroa.swift":2:8, scope 1
return %3 : $MyStruct, loc "sroa.swift":2:8, scope 1
} // end sil function 'MyStructInit'

sil_scope 2 { loc "sroa.swift":7:6 parent @foo : $@convention(thin) (Int64, Int64) -> Int64 }

// foo(in_x:in_y:)
sil hidden @foo : $@convention(thin) (Int64, Int64) -> Int64 {
bb0(%0 : $Int64, %1 : $Int64):
debug_value %0 : $Int64, let, name "in_x", argno 1, loc "sroa.swift":7:10, scope 2
debug_value %1 : $Int64, let, name "in_y", argno 2, loc "sroa.swift":7:21, scope 2
%4 = alloc_stack $MyStruct, var, name "my_struct", type $*MyContainer, expr op_fragment:#MyContainer.z, loc "sroa.swift":8:9, scope 2
// Recursive SROA of already SROA-ed aggregates is not yet supported.
// CHECK-SROA: alloc_stack $Int64
// CHECK-SROA-NOT: var,
// CHECK-SROA: alloc_stack $Int64
// CHECK-SROA-NOT: var,
// CHECK-SROA: metatype
%5 = metatype $@thin MyStruct.Type, loc "sroa.swift":8:21, scope 2
%6 = integer_literal $Builtin.Int64, 0, loc "sroa.swift":8:33, scope 2
%7 = struct $Int64 (%6 : $Builtin.Int64), loc "sroa.swift":8:33, scope 2
%8 = integer_literal $Builtin.Int64, 0, loc "sroa.swift":8:39, scope 2
%9 = struct $Int64 (%8 : $Builtin.Int64), loc "sroa.swift":8:39, scope 2
// function_ref MyStruct.init(x:y:)
%10 = function_ref @MyStructInit : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct, loc "sroa.swift":8:21, scope 2
%11 = apply %10(%7, %9, %5) : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct, loc "sroa.swift":8:21, scope 2
store %11 to %4 : $*MyStruct, loc "sroa.swift":8:21, scope 2
%13 = struct_element_addr %4 : $*MyStruct, #MyStruct.x, loc "sroa.swift":9:17, scope 2
store %0 to %13 : $*Int64, loc "sroa.swift":9:17, scope 2
%15 = struct_element_addr %4 : $*MyStruct, #MyStruct.y, loc "sroa.swift":10:17, scope 2
store %1 to %15 : $*Int64, loc "sroa.swift":10:17, scope 2
dealloc_stack %4 : $*MyStruct, loc "sroa.swift":8:9, scope 2
return %0 : $Int64, loc "sroa.swift":11:5, scope 2
} // end sil function 'foo'