Commit Graph

2053 Commits

Author SHA1 Message Date
Erik Eckstein
afedd6d72f copy required stuff from SideEffectAnalysis to AccessStorageAnalysis
... before we delete SideEffectAnalysis at all.
2022-12-21 17:41:46 +01:00
Erik Eckstein
beb46eb624 Use the new escape and side effects in alias analysis 2022-12-21 17:41:46 +01:00
Michael Gottesman
c33b9ee8e3 [move-only] Refactor both implementations to use the same diagnostic infrastructure.
This let me clean up the parts of the address infrastructure that rely on the
object checker.
2022-12-15 09:59:35 -08:00
Nate Chandler
9ad44a5056 [ClosureLifetimeFixup] Dealloc args on frontier.
Previously, the dealloc_stacks created for the alloc_stacks used to pass
@in_guaranteed arguments to on_stack closures were created after the
users of the closure.  When SILGen created these alloc_stacks in the
same block as the users, this happened to work.  Now that
AddressLowering creates such alloc_stacks elsewhere, this approach
results in invalid SIL.

Here, the dealloc_stacks are instead at the end of each block in the
dominance frontier of the alloc_stack.
2022-12-13 11:46:47 -08:00
Erik Eckstein
d4d1620f28 Swift SIL: rework Instruction and BasicBlock lists to support deleting instructions during iteration
Replace the generic `List` with the (non-generic) `InstructionList` and `BasicBlockList`.
The `InstructionList` is now a bit different than the `BasicBlockList` because it supports that instructions are deleted while iterating over the list.
Also add a test pass which tests instruction modification while iteration.
2022-12-12 19:08:57 +01:00
Erik Eckstein
c180d1363e SIL: simplify deleting instruction while iterating over instructions.
Add `deletableInstructions()` and `reverseDeletableInstructions()` in SILBasicBlock.
It allows deleting instructions while iterating over all instructions of the block.
This is a replacement for `InstructionDeleter::updatingRange()`.
It's a simpler implementation than the existing `UpdatingListIterator` and `UpdatingInstructionIteratorRegistry`, because it just needs to keep the prev/next pointers for "deleted" instructions instead of the iterator-registration machinery.
It's also safer, because it doesn't require to delete instructions via a specific instance of an InstructionDeleter (which can be missed easily).
2022-12-12 19:08:54 +01:00
Saleem Abdulrasool
a630fa7a9a SILOptimzer: correct a case of UB
The current `UpdatingInstructionIteratorRegistry` referenced `this` in
the member initializer list.  As per class.cdtor 11.9.5p1, this is UB as
for any class with a non-trivial constructor, referencing the base class
of the object before the constructor begins execution is not permitted.
We attempted to capture `this` in the lambda that was used to initialise
the member.  This was being exploited by the MSVC compiler resulting in
incorrect execution of the instruction deleter.
2022-12-11 19:05:07 -08:00
Anthony Latsis
4cb63c8a0f [NFC] Migrate remnant Jira issue references to GitHub issues 2022-12-04 08:20:34 +03:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Erik Eckstein
096f02b3ef SILOptimizer: rename ANALYSIS macro to SIL_ANALYSIS
Avoids a conflict with clang's `ANALYSIS` macro.

Fixes a macro redefinition warning.
2022-11-21 19:22:15 +01:00
Erik Eckstein
e0c862fc94 Remove uses of llvm::empty
It's deprecated in rebranch
2022-11-14 09:36:13 +01:00
Erik Eckstein
8ca0143279 Remove uses of std::iterator
It's deprecated in C++17
2022-11-14 09:35:40 +01:00
Erik Eckstein
ef302ce4ac SILOptimizer: enable stack protection by default
The pass to decide which functions should get stack protection was added in https://github.com/apple/swift/pull/60933, but was disabled by default.

This PR enables stack protection by default, but not the possibility to move arguments into temporaries - to keep the risk low.
Moving to temporaries can be enabled with the new frontend option `-enable-move-inout-stack-protector`.

rdar://93677524
2022-11-11 17:14:08 +01:00
swift-ci
4478bc86fd Merge pull request #61592 from eltociear/patch-39
[caller-analysis] fix typo in CallerAnalysis.h
2022-11-10 01:05:49 -08:00
Erik Eckstein
0403a21d34 use the new side effects in the performance inliner 2022-11-09 08:06:19 +01:00
Allan Shortlidge
cfb5ad8836 Merge pull request #61779 from tshortli/break-cycle-loop-can-duplicate
SILOptimizer: Break circular dependency with SIL library by moving `canDuplicate()`
2022-10-27 22:43:47 -07:00
Allan Shortlidge
0921480486 SILOptimizer: Break circular dependency with SIL library by moving canDuplicate().
Fixes a cycle introduced by https://github.com/apple/swift/pull/61051.
2022-10-27 16:12:05 -07:00
Allan Shortlidge
4f8d33ffb5 SILOptimizer: Break circular dependency with SIL library by moving extendStoreBorrow(). 2022-10-27 15:29:37 -07:00
Andrew Trick
cdbc9170c5 Merge pull request #61648 from atrick/jump-thread
[NFC] OSSA jump-threading support
2022-10-24 21:23:13 -07:00
Nate Chandler
d40500bbca [Gardening] Tweaked doc to avoid warning. 2022-10-24 12:27:05 -07:00
Andrew Trick
04aa16f97d OSSA: CheckedCastBrJumpThreading: support using RAUW utility.
Begin adding support for OSSA to checked-cast jump-threading based on
the new ownership utilities.

TODO:

Finish migrating to the new utilities in OwnershipOptUtils.

Ensure full unit test coverage.
2022-10-22 21:57:47 -07:00
Meghana Gupta
97013100dc [NFC] Move SimplifyCFG class to its own header so that it can be accessed by the unit test infra 2022-10-21 16:48:28 -07:00
Nate Chandler
2f18af8979 [Test] Allowed referring to block arguments. 2022-10-21 13:58:42 -07:00
Nate Chandler
b9a8334756 [Test] Contextualized bare test_spec refs.
Made bare @instruction and @block more useful.  Rather than referring to
the first instruction and block in the current function, instead, they
now refer to the instruction after the test_specification instruction
(which must always exist) and the block containing the
test_specification instruction.
2022-10-20 13:34:13 -07:00
Nate Chandler
b970e950ed [Test] Allow insts to be taken as values. 2022-10-20 13:34:13 -07:00
Erik Eckstein
ed54253d29 SIL Optimizer: remove legacy C++ passes
They were used as a backup during the transition to Swift passes. Now they are not needed anymore.
2022-10-20 18:31:06 +02:00
Erik Eckstein
9ae24f8a47 Swift compiler sources: remove the unused RCIdentity bridging structs. 2022-10-20 09:20:29 +02:00
Erik Eckstein
7db7065740 swift side effects: add CalleeAnalysis.getSideEffects(of: apply) 2022-10-20 09:20:28 +02:00
Erik Eckstein
ecbcacdecf SIL Analysis: Rename InvalidationKind::FunctionData to InvalidationKind::Effects
This invalidation kind is used when a compute-effects pass changes function effects.
Also, let optimization passes which don't change effects only invalidate the `FunctionBody` and not `Everything`.
2022-10-20 09:20:28 +02:00
Nate Chandler
4b85d0a9ca [DestroyHoisting] Barriers use callee analysis.
Pass a BasicCalleeAnalysis instance to isDeinitBarrier.  This enables
LexicalDestroyHoisting to hoist destroys over applies of functions which
are not deinit barriers.
2022-10-18 21:23:22 -07:00
Nate Chandler
f85074d1ba [ShrinkBorrowScope] Barriers use callee analysis.
Pass a BasicCalleeAnalysis instance to isDeinitBarrier.  This will allow
ShrinkBorrowScope to hoist end_borrows over applies of functions which
are not deinit barriers.
2022-10-18 21:23:22 -07:00
Nate Chandler
7ea336367d [NFC] Port isDeinitBarrier to Swift.
Added new C++-to-Swift callback for isDeinitBarrier.

And pass it CalleeAnalysis so it can depend on function effects.  For
now, the argument is ignored.  And, all callers just pass nullptr.

Promoted to API the mayAccessPointer component predicate of
isDeinitBarrier which needs to remain in C++.  That predicate will also
depends on function effects.  For that reason, it too is now passed a
BasicCalleeAnalysis and is moved into SILOptimizer.

Also, added more conservative versions of isDeinitBarrier and
maySynchronize which will never consider side-effects.
2022-10-18 21:23:22 -07:00
Erik Eckstein
5208d6d467 Swift Optimizer: make the RunUnitTests a module pass
Which makes more sense. At the time RunUnitTests was added, there were no module passes, yet.
2022-10-17 11:45:30 +02:00
Ikko Ashimine
58359d2726 [caller-analysis] fix typo in CallerAnalysis.h
Auxillary -> Auxiliary
2022-10-16 22:16:00 +09:00
Nate Chandler
ffa0cc423d [Gardening] Doc'd test arg parsing helper. 2022-10-14 07:52:39 -07:00
Nate Chandler
6d62770ffe [SILUnitTests] Added check for remaining args. 2022-10-14 07:47:52 -07:00
Nate Chandler
82cd580145 [SILOptimizer] Add faux unit testing mechanism.
The testing works by way of a new pass "UnitTestRunner" and a new
instruction test_specification.  When a function contains
test_specification instructions, it invokes the UnitTest subclass named
in the test_specification instruction with the arguments specified in
that instruction.

For example, when running the unit-test-runner class, having the
instructions

```
test_specification "my-neato-utility 19 @function[callee].block[2] @trace[2]"
test_specification "my-neato-utility 43 @block @trace"
```

would result in the test associated with "my-neato-utility" in
UnitTestRunner.cpp being invoked twice.  Once with (19, aBlock, aValue),
and once with (43, anotherBlock, someOtherValue).  That UnitTest
subclass class would need to call takeUInt, takeBlock, and takeTrace on
the Arguments struct it is invoked with.  It would then pass those
arguments along to myNeatoUtility and dump out interesting results.  The
results would then be FileChecked.
2022-10-11 17:29:59 -07:00
Nate Chandler
03253dbf48 [CanonicalizeOSSALifetime] Extend Onone lifetimes.
To improve the debugging experience of values whose lifetimes are
canonicalized without compromising the semantics expressed in the source
language, when canonicalizing OSSA lifetimes at Onone, lengthen
lifetimes as much as possible without incurring copies that would be
eliminated at O.

rdar://99618502
2022-10-08 16:08:35 -07:00
Nate Chandler
c1bbfc1f8a [CanonicalizeOSSALifetime] Separated steps.
Rather than having finding the boundary be a single combined step,
separate finding the original boundary from extending that boundary.
This enables inserting an optional step between those steps, namely to
extend unconsumed liveness to its original extent at Onone.
2022-10-08 16:08:35 -07:00
Nate Chandler
8cf65c6c8a [CanonicalizeOSSALifetime] Handle live phis.
It is possible for phis to be marked live.  With guaranteed phis, they
will be the last uses and be non-consuming.  In this case, the
merge block will have multiple predecessors whose terminators are on the
boundary.  When inserting destroys, track whether a merge point has been
visited previously.

To facilitate this, restructure the boundary extension and destroy
insertion code.

Previously, the extender was building up a list of places at which to
insert destroys.  In particular it was using the "boundary edge"
collection for all blocks at the beginning of which a destroy should be
created.  In particular, it would add merge blocks. Such blocks are not
boundary blocks.

Here, the extender produces a PrunedLivenessBoundary which doesn't
violate that invariant.

This required some changes to the destroy insertion code to find where
to insert destroys.  It is now similar to
PrunedLivenessBoundary::visitInsertionPoints and could be used as a
template for a PrunedLivenessBoundary::visitBoundaryPoints through which
::visitInsertionPoints might be factored.
2022-10-08 15:56:23 -07:00
Nate Chandler
65ffed3cf9 [CanonicalizeOSSALifetime] Minor cleanup. 2022-10-08 15:15:03 -07:00
Nate Chandler
2c5ee0f7ad [CanonicalizeOSSALifetime] Fixed caching bug.
Previously, the destroys set (now set vector) wasn't ever being cleared.
The result was that users could get overly pessimistic behavior if they
had previously used the utility with a destroy that came after the
destroys relevant for its current run. Here, it is cleared when the
utility is initialized with a new def.  Addresses a TODO in the
copy_propagation test.
2022-10-06 13:45:54 -07:00
Nate Chandler
9cd4cdb11b [NFC] Removed unused field. 2022-10-05 17:59:08 -07:00
Nate Chandler
4fc42a63a3 [CanonicalizeOSSALifetime] Renamed file.
Matched to the name of the utility.
2022-10-05 17:07:05 -07:00
Nate Chandler
8a3dc109ec [CanonicalizeOSSABoundary] Used ::computeBoundary.
Previously, CanonicalizeOSSALifetime had its own copy of a variation of
the code for computing the liveness boundary that PrunedLiveness has.
Here, it is switched over to using PrunedLiveness' version.

In order to do that without complicating the interface for PrunedLivness
by adding a visitor, the extra bookkeeping that was being done for
destroy_values and debug_values is dropped.  Instead, after getting an
original boundary from PrunedLiveness::computeBoundary, the boundary is
extended out to preexisting destroys which are not separated from the
original boundary by "interesting" instructions.
2022-10-05 17:07:05 -07:00
Nate Chandler
91d530f15e [CanonicalizeOSSALifetime] Ignore debug_values.
Added Kind::DebugValueInst to the list of opcodes that
CanonicalizeOSSALifetime doesn't go out of its way to hoist over.
2022-10-05 13:04:52 -07:00
Nate Chandler
2f36201504 [NFC] Removed unused field.
It should have been removed when poison mode was removed from
CanonicalizeOSSALifetime.
2022-10-05 10:53:18 -07:00
Nate Chandler
9171f77313 [NFC] Removed unused field.
It should have been removed when poison mode was removed from
CanonicalizeOSSALifetime.
2022-10-05 10:53:18 -07:00
Erik Eckstein
741c6c38df Swift Optimizer: add the ComputeSideEffects pass.
Computes the side effects for a function, which consists of argument- and global effects.
This is similar to the ComputeEscapeEffects pass, just for side-effects.
2022-10-05 07:38:11 +02:00
Erik Eckstein
e1c65bd1d6 Swift Optimizer: rename the ComputeEffects pass to ComputeEscapeEffects 2022-10-05 07:38:11 +02:00