Skip to content

[opt-remark] Print out the type when we retain/release. #33171

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
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
3 changes: 2 additions & 1 deletion lib/SIL/Utils/OptimizationRemark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ Argument::Argument(ArgumentKey key, SILFunction *f) : key(key) {
Argument::Argument(StringRef key, SILType ty)
: key(ArgumentKeyKind::Default, key) {
llvm::raw_string_ostream stream(val);
ty.print(stream);
PrintOptions subPrinter = PrintOptions::printSIL();
ty.getASTType().print(stream, subPrinter);
}

Argument::Argument(StringRef key, CanType ty)
Expand Down
12 changes: 8 additions & 4 deletions lib/SILOptimizer/Transforms/OptRemarkGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ void OptRemarkGeneratorInstructionVisitor::visitStrongRetainInst(
// Retains begin a lifetime scope so we infer scan forward.
auto remark = RemarkMissed("memory", *sri,
SourceLocInferenceBehavior::ForwardScanOnly)
<< "retain";
<< "retain of type '"
<< NV("ValueType", sri->getOperand()->getType()) << "'";
for (auto arg : inferredArgs) {
remark << arg;
}
Expand All @@ -269,7 +270,8 @@ void OptRemarkGeneratorInstructionVisitor::visitStrongReleaseInst(

auto remark = RemarkMissed("memory", *sri,
SourceLocInferenceBehavior::BackwardScanOnly)
<< "release";
<< "release of type '"
<< NV("ValueType", sri->getOperand()->getType()) << "'";
for (auto arg : inferredArgs) {
remark << arg;
}
Expand All @@ -288,7 +290,8 @@ void OptRemarkGeneratorInstructionVisitor::visitRetainValueInst(
// Retains begin a lifetime scope, so we infer scan forwards.
auto remark = RemarkMissed("memory", *rvi,
SourceLocInferenceBehavior::ForwardScanOnly)
<< "retain";
<< "retain of type '"
<< NV("ValueType", rvi->getOperand()->getType()) << "'";
for (auto arg : inferredArgs) {
remark << arg;
}
Expand All @@ -308,7 +311,8 @@ void OptRemarkGeneratorInstructionVisitor::visitReleaseValueInst(
// Releases end a lifetime scope so we infer scan backward.
auto remark = RemarkMissed("memory", *rvi,
SourceLocInferenceBehavior::BackwardScanOnly)
<< "release";
<< "release of type '"
<< NV("ValueType", rvi->getOperand()->getType()) << "'";
for (auto arg : inferredArgs) {
remark << arg;
}
Expand Down
60 changes: 34 additions & 26 deletions test/SILOptimizer/opt-remark-generator-yaml.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,78 @@
// works without burdening opt-remark-generator-yaml.swift with having to update all
// of the yaml test cases everytime new code is added.

public class Klass {}

public var global = Klass()

// CHECK: --- !Missed
// CHECK-NEXT: Pass: sil-opt-remark-gen
// CHECK-NEXT: Name: sil.memory
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator-yaml.swift',
// CHECK-NEXT: Line: 63, Column: 5 }
// CHECK-NEXT: Line: [[# @LINE + 12]], Column: 5 }
// CHECK-NEXT: Function: 'getGlobal()'
// CHECK-NEXT: Args:
// CHECK-NEXT: - String: retain
// CHECK-NEXT: - String: 'retain of type '''
// CHECK-NEXT: - ValueType: Klass
// CHECK-NEXT: - String: ''''
// CHECK-NEXT: - InferredValue: 'of ''global'''
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator-yaml.swift',
// CHECK-NEXT: Line: 59, Column: 12 }
// CHECK-NEXT: Line: [[# @LINE - 14]], Column: 12 }
// CHECK-NEXT: ...
@inline(never)
public func getGlobal() -> Klass {
return global // expected-remark @:5 {{retain of type 'Klass'}}
// expected-note @-19:12 {{of 'global'}}
}

// CHECK-NEXT: --- !Missed
// CHECK-NEXT: Pass: sil-opt-remark-gen
// CHECK-NEXT: Name: sil.memory
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator-yaml.swift',
// CHECK-NEXT: Line: 71, Column: 5 }
// CHECK-NEXT: Line: [[# @LINE + 40]], Column: 5 }
// CHECK-NEXT: Function: 'useGlobal()'
// CHECK-NEXT: Args:
// CHECK-NEXT: - String: retain
// CHECK-NEXT: - String: 'retain of type '''
// CHECK-NEXT: - ValueType: Klass
// CHECK-NEXT: - String: ''''
// CHECK-NEXT: - InferredValue: 'of ''x'''
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator-yaml.swift',
// CHECK-NEXT: Line: 68, Column: 9 }
// CHECK-NEXT: Line: [[# @LINE + 29]], Column: 9 }
// CHECK-NEXT: ...
// CHECK-NEXT: --- !Missed
// CHECK-NEXT: Pass: sil-opt-remark-gen
// CHECK-NEXT: Name: sil.memory
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator-yaml.swift',
// CHECK-NEXT: Line: 71, Column: 12 }
// CHECK-NEXT: Line: [[# @LINE + 26]], Column: 12 }
// CHECK-NEXT: Function: 'useGlobal()'
// CHECK-NEXT: Args:
// CHECK-NEXT: - String: release

// CHECK-NEXT: - String: 'release of type '''
// CHECK-NEXT: - ValueType: {{'Array<Any>'|__ContiguousArrayStorageBase}}
// CHECK-NEXT: - String: ''''
// CHECK-NEXT: ...
// CHECK-NEXT: --- !Missed
// CHECK-NEXT: Pass: sil-opt-remark-gen
// CHECK-NEXT: Name: sil.memory
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator-yaml.swift',
// CHECK-NEXT: Line: 71, Column: 12 }
// CHECK-NEXT: Line: [[# @LINE + 15]], Column: 12 }
// CHECK-NEXT: Function: 'useGlobal()'
// CHECK-NEXT: Args:
// CHECK-NEXT: - String: release
// CHECK-NEXT: - String: 'release of type '''
// CHECK-NEXT: - ValueType: Klass
// CHECK-NEXT: - String: ''''
// CHECK-NEXT: - InferredValue: 'of ''x'''
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator-yaml.swift',
// CHECK-NEXT: Line: 68, Column: 9 }
// CHECK-NEXT: Line: [[# @LINE + 4]], Column: 9 }
// CHECK-NEXT: ...

public class Klass {}

public var global = Klass()

@inline(never)
public func getGlobal() -> Klass {
return global // expected-remark @:5 {{retain}}
// expected-note @-5:12 {{of 'global'}}
}

public func useGlobal() {
let x = getGlobal()
// Make sure that the retain msg is at the beginning of the print and the
// releases are the end of the print.
print(x) // expected-remark @:5 {{retain}}
print(x) // expected-remark @:5 {{retain of type 'Klass'}}
// expected-note @-4:9 {{of 'x'}}
// expected-remark @-2:12 {{release}}
// expected-remark @-3:12 {{release}}
// expected-note @-7:9 {{of 'x'}}
// We test the type emission above since FileCheck can handle regex.
// expected-remark @-3:12 {{release of type}}
// expected-remark @-4:12 {{release of type 'Klass'}}
// expected-note @-8:9 {{of 'x'}}
}
8 changes: 4 additions & 4 deletions test/SILOptimizer/opt-remark-generator.sil
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import Builtin

sil @foo : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
bb0(%0 : $Builtin.NativeObject):
strong_retain %0 : $Builtin.NativeObject // expected-remark {{retain}}
retain_value %0 : $Builtin.NativeObject // expected-remark {{retain}}
strong_release %0 : $Builtin.NativeObject // expected-remark {{release}}
release_value %0 : $Builtin.NativeObject // expected-remark {{release}}
strong_retain %0 : $Builtin.NativeObject // expected-remark {{retain of type 'Builtin.NativeObject'}}
retain_value %0 : $Builtin.NativeObject // expected-remark {{retain of type 'Builtin.NativeObject'}}
strong_release %0 : $Builtin.NativeObject // expected-remark {{release of type 'Builtin.NativeObject'}}
release_value %0 : $Builtin.NativeObject // expected-remark {{release of type 'Builtin.NativeObject'}}
%9999 = tuple()
return %9999 : $()
}
Loading