Commit Graph

2768 Commits

Author SHA1 Message Date
Nate Chandler
389fb97b44 [StackNesting] NFC: Added helper.
Just pull the notion that the alloc corresponds to operand 0 into a
helper method.
2023-06-05 08:11:28 -07:00
Nate Chandler
8c8f5dfc2a [StackNesting] Gardening: Fixed typos. 2023-06-05 08:11:27 -07:00
Meghana Gupta
2c6139dce4 Rename SILArgument::isEscaping -> SILArgument::hasPointerEscape 2023-05-26 15:58:30 -07:00
Erik Eckstein
a80d0cb8a7 remove now unused utilities
* StaticInitCloner
* some APIs in SILGlobalVariable
2023-05-22 15:34:26 +02:00
Andrew Trick
664ec221ae Remove disabled code in splitAggregateLoad.
It is no longer necessary to use debug fragments for load splitting.
2023-05-16 10:18:48 -07:00
Andrew Trick
5d3793d843 Call salvageLoadDebugInfo from splitAggregateLoad
Fixes a know issue in which load splitting drops debug info.

After splitting the load, create a new debug_value instruction for the
loaded memory location, inserting a dereference expression if needed.

This fixes debug information for -Onone debugging. Later, after fixing
optimizations, it will also be called at -O, but not on 5.9.

Fixes rdar://104700920 (At -Onone preserve debug info after splitting loads)
Issue: LLDB missing variables in certain case #62241
2023-05-16 10:18:48 -07:00
Andrew Trick
11053dc4f1 Add salvageLoadDebugInfo to handle LoadInst
Before deleting a load, simply rewrite its debug info to refer to the
loaded address:

%l = load %a
debug_value %l, loc0, scope0, var0

--->

debug_value %a, loc0, scope0, var0, expr op_deref
%l = load %a

Note that alloc_stack addresses do not require the addition of
op_deref because they are already special-cased in IRGen.

This will be called from salvageDebugInfo when it is supported by
optmizations. Until then, it is only called selectively at -Onone.
2023-05-16 09:54:25 -07:00
Andrew Trick
094b204270 Update a comment in splitAggregateLoad 2023-05-15 15:20:57 -07:00
swift-ci
cd06759029 Merge pull request #65835 from meg-gupta/newflags
Add new flags "reborrow" and "escaping" to SILArgument.
2023-05-11 17:27:36 -07:00
Meghana Gupta
1dc713e2f7 Add new flags "reborrow" and "escaping" to SILArgument.
"reborrow" flag on the SILArgument avoids transitive walk over the phi operandsi
to determine if it is a reborrow in multiple utilities.
SIL transforms must keep the flag up-to-date by calling SILArgument::setReborrow.
SILVerifier checks to ensure the flag is not invalidated.

Currently "escaping" is not used anywhere.
2023-05-11 12:31:37 -07:00
Erik Eckstein
6d13bf188f SIL Optimizer: handle dead-end infinite loops in StackNesting
Fixes a verifier crash caused by a not properly nested alloc-dealloc pair

rdar://109204178
2023-05-11 16:16:13 +02:00
nate-chandler
3d146b8230 Merge pull request #65686 from nate-chandler/canonicalize-guaranteed-value/dont-hoist-forwards
[CanonicalizeGuaranteedValue] Rewrite forwards in place.
2023-05-11 07:01:12 -07:00
Erik Eckstein
82734b6ac2 Swift Optimizer: simplification for apply, try_apply, begin_apply and partial_apply
* move the apply of partial_apply transformation from simplify-apply to simplify-partial_apply
* delete dead partial_apply instructions
* devirtualize apply, try_apply and begin_apply
2023-05-11 08:11:44 +02:00
Erik Eckstein
6488da99fa SILOptimizer: don't copy move-only partial_apply arguments to temporaries
Instead bail when trying to deleted a dead closure or when performing the apply-of-partial_apply optimization.

TODO: In OSSA this should be solvable without the need of copies to temporaries.
2023-05-11 08:11:44 +02:00
Erik Eckstein
9326da0698 allow deleting dead non-escaping closures in OSSA 2023-05-11 08:03:19 +02:00
Erik Eckstein
edb08dabd5 GenericSpecializer: fix the function convention if specialization removes the self parameter of a method
When dropping the self metatype parameter of a method, it must become a "thin" function.

Fixes a crash when using performance annotations.

rdar://107202455
2023-05-11 08:03:19 +02:00
Erik Eckstein
2b117fd3ee Swift Optimizer: add APIs to copy from or to a global static initializer
* `Context.copyStaticInitializer(fromInitValue:, to:)`
* `FunctionPassContext.createStaticInitializer(for:,initValue:)`
2023-05-08 21:23:36 +02:00
Erik Eckstein
ee2924fd27 Inliner: don't distinguish between the "mid-level" and "late" inliner
Now that we handle inlined global initializers in LICM, CSE and the StringOptimization, we don't need to have a separate mid-level inliner pass, which treats global accessors specially.
2023-05-08 21:23:36 +02:00
Erik Eckstein
9b51e69dac Swift Optimizer: constant fold builtins in the simplification passes 2023-05-08 21:23:36 +02:00
Erik Eckstein
85aa1c12db handle debug_step in static initializers of globals and in the const expression evaluator 2023-05-08 21:23:36 +02:00
Slava Pestov
ee386558b9 SILOptimizer: Handle alloc_pack in StackNesting 2023-05-05 22:45:03 -04:00
Nate Chandler
ea10281db6 [CanonGuaranteedValue] Don't insert fwd destroy.
When rewriting forwards, don't fix the lifetime which results in
spurious lifetime ends.
2023-05-04 20:12:16 -07:00
Nate Chandler
e5e1481add [CanonGuaranteedValue] Rewrite fwds in place. 2023-05-04 20:12:16 -07:00
Nate Chandler
88103a7287 [InstructionDeleter] Add fixLifetime argument.
Clients may not want the lifetime to be fixed up.
2023-05-04 20:12:16 -07:00
Nate Chandler
3e08f5141b [CanonicalizeBorrowScope] Adopted BitfieldRef. 2023-05-02 11:51:53 -07:00
Nate Chandler
8882c92f82 [CanonicalizeBorrowScope] Removed spurious call.
When canonicalizing an argument, liveness is not used (it being the full
body of the function), so there's no need to invalidate it.
2023-05-02 11:51:52 -07:00
Nate Chandler
3c4275a422 [CanonicalizeOSSALifetime] Renamed member.
The member just clears the values.  After it adopted BitfieldRef, the
call to invalidate on the liveness instance was already superfluous.
2023-05-02 11:51:52 -07:00
nate-chandler
f0d76faee9 Merge pull request #65458 from nate-chandler/guaranteed-copy-propagation/forwarding-inner-uses-during-outer-rewriting
[CanonicalizeBorrowScope] Allow inner forwarding value unmapped to outer value during outer rewriting.
2023-04-27 06:58:40 -07:00
Nate Chandler
78d0660597 [CanonBorrowScope] Allow inner val without outer.
When rewriting outer uses of the borrow, `recursivelyRewriterOuterUses`
is called recursively.  First, it is called with the borrow itself.
Subsequently, it is called with forwarding users of the borrow.  Such a
user may not be rewriteable as outer uses.  If it isn't
`innerToOuterMap` won't have an entry for it.

Previously, failing to find an entry would raise an assertion.  Here,
the function is made to return a "null" SILValue.  Its caller
RewriteOuterBorrowUses::visitForwardingUse was already written to handle
such a result.
2023-04-26 18:43:17 -07:00
Nate Chandler
8c8b24fc63 [Gardening] Tweaked comment. 2023-04-26 18:18:21 -07:00
Michael Gottesman
b957fbb4df [generic-spec] Add an option -sil-generic-dump-functions-after-specialization that makes it easy to look for errors around specialization. 2023-04-24 16:02:35 -07:00
Nate Chandler
14cd090cb9 [PartialApplyCombiner] Handled moved PAIs.
Look through `move_value` instructions when combining `partial_apply`
instructions.

rdar://108386395
2023-04-21 14:59:43 -07:00
Slava Pestov
43a35992fd SILOptimizer: Teach constant folding about add, sub, mul variants without overflow checks 2023-04-12 18:27:50 -04:00
Erik Eckstein
7d70a70acf SIL: add the drop_deinit instruction
his instruction is a marker for a following destroy instruction to suppress the call of the move-only type's deinitializer.
2023-04-11 10:25:48 +02:00
Ravi Kandhadai
1b6d160c5c Merge pull request #65003 from ravikandhadai/main
[Constant Evaluator] Enable SILConstants::setIndexedElement function to work with aggregates containing unknown values
2023-04-07 17:27:11 -07:00
Ravi Kandhadai
e02d27c7d2 [Constant Evaluator] Enable SILConstants::setIndexedElement function
to work with aggregates containing unknown values. Such aggregates
can be generated when an instruction is skipped during constant
evaluation and its results are used to create a struct.
2023-04-06 21:41:39 -07:00
Adrian Prantl
829491b230 Merge pull request #64551 from adrian-prantl/88274783
Rebase SILScope generation on top of ASTScope
2023-04-05 08:30:13 -07:00
Adrian Prantl
158772c2ab Rebase SILScope generation on top of ASTScope.
This patch replaces the stateful generation of SILScope information in
SILGenFunction with data derived from the ASTScope hierarchy, which should be
100% in sync with the scopes needed for local variables. The goal is to
eliminate the surprising effects that the stack of cleanup operations can have
on the current state of SILBuilder leading to a fully deterministic (in the
sense of: predictible by a human) association of SILDebugScopes with
SILInstructions. The patch also eliminates the need to many workarounds. There
are still some accomodations for several Sema transformation passes such as
ResultBuilders, which don't correctly update the source locations when moving
around nodes. If these were implemented as macros, this problem would disappear.

This necessary rewrite of the macro scope handling included in this patch also
adds proper support nested macro expansions.

This fixes

rdar://88274783

and either fixes or at least partially addresses the following:

rdar://89252827
rdar://105186946
rdar://105757810
rdar://105997826
rdar://105102288
2023-04-04 15:20:11 -07:00
Nate Chandler
63e3ca7e17 [CanOSSALifetime] Xfer lexical value to callees.
When canonicalizing a lexical lifetime, don't treat applies which
consume a copy of the value as deinit barriers.  Doing so forces another
copy of the def being canonicalized to remain after the apply.

Instead, allow the lifetime to be transferred into the callee.  This is
the same behavior that already exists for lexical lifetimes represented
with the `begin_borrow [lexical]` + `copy_value` instruction sequence.
2023-04-03 16:29:21 -07:00
nate-chandler
c0d7a8218e Merge pull request #63606 from nate-chandler/canonicalize_ossa_lifetime/lexical_values
[CanonicalizeOSSALifetime] Run on lexical lifetimes.
2023-03-27 07:02:31 -07:00
Erik Eckstein
a6a75f066b GenericSpecializer: fix a crash with -cross-module-optimization
If a thunk needs to be generated for a partial_apply specialization, but the specialization doesn't have a body, bail.

rdar://107165121
2023-03-27 09:08:48 +02:00
Nate Chandler
ec3f005f31 [CanonOSSALifetime] Run on lexical lifetimes.
Previously, the utility bailed out on lexical lifetimes because it
didn't respect deinit barriers.  Here, deinit barriers are found and
added to liveness if the value is lexical.  This enables copies to be
propagated without hoisting destroys over deinit barriers.

rdar://104630103
2023-03-25 21:17:26 -07:00
Nate Chandler
f88ca5108b [CanonOSSALifetime] Fixed term boundary extension.
If multiple terminators which branch to the same merge block are added
to the boundary, depending on whether a destroy_value can be found
within the block either (a) every terminator must be added to the
boundary or (b) the destroy_value must be added to the boundary exactly
once.
2023-03-25 16:04:14 -07:00
Nate Chandler
4d4042931b [Reachability] NFC: Allow more initial blocks.
Allow clients to specify any number (an array) of blocks beyond which
dataflow won't propagate rather than 1 or 0 (a pointer).
2023-03-25 12:27:57 -07:00
nate-chandler
8155d08adc Merge pull request #64614 from nate-chandler/rdar107198526
[CopyPropagation] Fix destroy recording.
2023-03-24 18:17:35 -07:00
Nate Chandler
7493b7e5ed [CopyPropagation] Correctly recorded destroys.
Now that destory_values implicitly end borrow scopes for
`partial_apply [on_stack]`s, they show up as users of values whose
lifetimes are being canonicalized.  Handle that properly by
(1) only adding the `destroy_value`s whose operand is a transitive copy
    of the def to the set of destroys
(2) not considering a `destroy_value` with another operand (i.e. one
    which does not destroy a transitive copy of the def) to be lifetime
    ending

rdar://107198526
2023-03-24 13:20:11 -07:00
Nate Chandler
0b09ed6cc1 NFC: CopyPropagation: Replaced copy walk with set.
Whenever attempting to determine whether a given instruction is a
destroy of the def being canonicalized, just check for membership in the
set of destroys that's already collected.
2023-03-24 13:19:55 -07:00
Meghana Gupta
3f6bfca2f9 Merge pull request #64554 from meg-gupta/fixsilcombineubci
Fix OSSA RAUW utility's insertion point
2023-03-24 12:26:06 -04:00
Meghana Gupta
a4c693fcf3 Update OSSA RAUW utils to insert borrows before the value being replaced 2023-03-23 11:45:51 -07:00
Slava Pestov
ac15cdf6ea Merge pull request #64527 from slavapestov/protocol-conformance-cleanup
AST: Rename ProtocolConformance::getSubstitutions() to getSubstitutionMap() and remove ModuleDecl parameter
2023-03-22 20:30:25 -04:00