Skip to content

[opt-remark] If we have a SIL remark streamer, always emit remarks. #33018

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
5 changes: 4 additions & 1 deletion lib/SILOptimizer/Transforms/OptRemarkGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ class OptRemarkGenerator : public SILFunctionTransform {
bool isOptRemarksEnabled() {
// TODO: Put this on LangOpts as a helper.
auto &langOpts = getFunction()->getASTContext().LangOpts;

// If we have a remark streamer, emit everything.
return bool(langOpts.OptimizationRemarkMissedPattern) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

@francisvm This whole predicate seems a little odd. Seems like we can clean up a bunch of checks in the emitter itself if it had a direct reference to the module's remark streamer instead of the module itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

The only issue I see is that the remark streamer is only used to serialize remarks, while the emitter is used to emit both diagnostics and serialize remarks.

bool(langOpts.OptimizationRemarkPassedPattern);
bool(langOpts.OptimizationRemarkPassedPattern) ||
getFunction()->getModule().getSILRemarkStreamer();
}

/// The entry point to the transformation.
Expand Down
40 changes: 40 additions & 0 deletions test/SILOptimizer/opt-remark-generator.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
// RUN: %target-swiftc_driver -O -Rpass-missed=sil-opt-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -emit-sil %s -o /dev/null -Xfrontend -verify

// RUN: %empty-directory(%t)
// RUN: %target-swiftc_driver -wmo -O -Xllvm -sil-disable-pass=FunctionSignatureOpts -emit-sil -save-optimization-record=yaml -save-optimization-record-path %t/note.yaml %s -o /dev/null && %FileCheck --input-file=%t/note.yaml %s

// CHECK: --- !Missed
// CHECK-NEXT: Pass: sil-opt-remark-gen
// CHECK-NEXT: Name: sil.memory-management
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator.swift',
// CHECK-NEXT: Line: 49, Column: 5 }
// CHECK-NEXT: Function: 'getGlobal()'
// CHECK-NEXT: Args:
// CHECK-NEXT: - String: Unable to remove retain
// CHECK-NEXT: ...
// CHECK-NEXT: --- !Missed
// CHECK-NEXT: Pass: sil-opt-remark-gen
// CHECK-NEXT: Name: sil.memory-management
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator.swift',
// CHECK-NEXT: Line: 56, Column: 5 }
// CHECK-NEXT: Function: 'useGlobal()'
// CHECK-NEXT: Args:
// CHECK-NEXT: - String: Unable to remove retain
// CHECK-NEXT: ...
// CHECK-NEXT: --- !Missed
// CHECK-NEXT: Pass: sil-opt-remark-gen
// CHECK-NEXT: Name: sil.memory-management
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator.swift',
// CHECK-NEXT: Line: 56, Column: 12 }
// CHECK-NEXT: Function: 'useGlobal()'
// CHECK-NEXT: Args:
// CHECK-NEXT: - String: Unable to remove release
// CHECK-NEXT: ...
// CHECK-NEXT: --- !Missed
// CHECK-NEXT: Pass: sil-opt-remark-gen
// CHECK-NEXT: Name: sil.memory-management
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator.swift',
// CHECK-NEXT: Line: 56, Column: 12 }
// CHECK-NEXT: Function: 'useGlobal()'
// CHECK-NEXT: Args:
// CHECK-NEXT: - String: Unable to remove release
// CHECK-NEXT: ...

public class Klass {}

public var global = Klass()
Expand Down