-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Skip meta instructions for Builder.init with automatic location #73864
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// RUN: %target-sil-opt -enable-sil-verify-all %s -simplification -simplify-instruction=checked_cast_br -sil-print-debuginfo | %FileCheck %s | ||
|
||
// REQUIRES: swift_in_compiler | ||
|
||
import Swift | ||
import Builtin | ||
|
||
protocol P : AnyObject {} | ||
class B : P {} | ||
class X : B {} | ||
|
||
// CHECK-LABEL: sil [ossa] @test_ossa : | ||
// CHECK: %0 = alloc_ref | ||
// CHECK-NEXT: checked_cast_br AnyObject in %0 : $X | ||
// CHECK: bb2([[A:%.*]] : @owned $X): | ||
// CHECK-NEXT: [[U:%.*]] = upcast [[A]] : $X to $B, loc "takethis":1:1 | ||
// CHECK-NEXT: [[E:%.*]] = init_existential_ref [[U]] {{.+}}, loc "takethis":1:1 | ||
// CHECK-NEXT: debug_value [[E]] : $AnyObject, let, name "me", loc "ignore-this-meta-inst":1:1 | ||
// CHECK-NEXT: destroy_value [[E]] : $AnyObject, loc "takethis":1:1 | ||
// CHECK: } // end sil function 'test_ossa' | ||
sil [ossa] @test_ossa : $@convention(thin) () -> @owned X { | ||
bb0: | ||
%0 = alloc_ref $X | ||
%1 = upcast %0 : $X to $B | ||
%2 = init_existential_ref %1 : $B : $B, $AnyObject | ||
debug_value %2 : $AnyObject, name "x" | ||
checked_cast_br AnyObject in %2 : $AnyObject to X, bb1, bb2 | ||
|
||
bb1(%5 : @owned $X): | ||
return %5 : $X | ||
|
||
bb2(%7 : @owned $AnyObject): | ||
debug_value %7 : $AnyObject, let, name "me", loc "ignore-this-meta-inst":1:1 | ||
destroy_value %7: $AnyObject, loc "takethis":1:1 | ||
unreachable | ||
} | ||
|
||
sil_vtable X { | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a good definition of the term "meta instruction" - and also a better name. The term is not used anywhere else in SIL (I just figured out now that it's borrowed from LLVM's machine instructions).
In
SILInstruction::isMetaInstruction()
we define it as: "Every instruction that doesn't generate code should be in this list."But this is not even true for
alloc_stack
: if the allocated type is generic,alloc_stack
can generate code (metadata instantiation). On the other hand, there are a lot of instructions which really don't generate code, likedealloc_stack
,begin_borrow
, etc. and are not considered as "meta instructions".So, what makes
alloc_stack
special in terms of debug info?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we copied this term of art from MIR: https://www.llvm.org/doxygen/classllvm_1_1MachineInstr.html#aeffeb27bd92437aa2fd7b7567b01d078
I think the definition we really mean in SIL is: Should a new SIL instruction inserted after this instruction inherit this instruction's SILLocation and scope?
Since alloc_stack instructions are often hoisted to the beginning of a function, they can have a scope and location that is out-of-order. You are correct that alloc_stack instruction generate code in the form of an LLVM alloca but these instructions are part of the function prologue and don't have any scope or location.
In modern SIL alloc_stack instructions can actually have two SIL location/scope pairs, one for the instruction, and one for the variable. We could side-step the problem by setting the location of the alloc_stack instruction to a compiler-generated (or prologue?) location and relying on the variable carrying its own scope and location. Then we don't need an IsMetaInstruction helper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, but that would still not solve the problem of what scope an alloc_stack should have. If we don't skip alloc_stacks in SILBuilderWithScope, then we'd need to reparent an alloc_stack every time it's moved. So I think we may still want to be able to skip them in SILBuilderWithScope.
So back to finding a better name for the function:
Since meta instruction is already a term of art in LLVM, I'd want to keep it.
The fact that dealloc_stack and begin_borrow are not classified as meta instructions is probably more a bug than a significant difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Writing this in the doc comment:
"A meta instruction is an instruction whose location is not interesting as it is impossible to set a breakpoint on it. That could be because the instruction does not generate code (such as
debug_value
), or because the generated code would be in the prologue (alloc_stack
). Other instructions should not inherit this instruction's location."We could add other instructions to the list, but we would have to do it on both the C++ and the Swift side, so I think it should be in a separate PR.