Commit Graph

49 Commits

Author SHA1 Message Date
swift-ci
995c41c008 Merge pull request #66826 from nate-chandler/rdar110862719
[FieldSensitivePL] NFC: Added unit tests.
2023-06-23 14:51:38 -07:00
Nate Chandler
7322ccb25b [FieldSensitivePL] NFC: Added unit tests.
Ported versions of the unit tests that Andy added to pruned liveness to
FieldSensitivePL.

rdar://110862719
2023-06-23 10:16:53 -07:00
Meghana Gupta
031255c2d8 Rename hasPointerEscape -> findPointerEscape 2023-06-20 21:13:55 -07:00
Nate Chandler
9b6904498e [TypeLowering] Move-only types are lexical.
Vars of such types should be given lexical `alloc_stack`s by
`AllocBoxToStack` which requires that the `alloc_box` insts formed for
them have an associated borrow scope which in turn requires that type
lowering for move only structs and enums have their lexical bits set.

rdar://110901430
2023-06-16 08:26:04 -07:00
Nate Chandler
e6f15b92c5 [UnitTestRunner] Gardening: Fixed typo. 2023-06-05 08:11:28 -07: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
1e4086fd34 [Test] Unit test lexical destroy folding.
Adapt a preexisting test to be a unit test that runs the utility.
2023-03-25 12:27:57 -07:00
Andrew Trick
37ff9ad1a0 Add a MultiDefUseLivenessTest
This provides a way to test liveness based on non-SSA values. The move
checker is now using pruned liveness this way. So we need a way to
test that liveness no longer makes any assumptions about SSA
values. These test cases need to explicitly specify all the def and
use instructions.
2023-03-23 10:39:32 -07:00
Andrew Trick
aa469544c7 ParseTestSpecification: handle multi-line strings
We need this for specifications that involve multiple components and long instruction lists.
2023-03-23 01:56:19 -07:00
Andrew Trick
119e712c32 Merge pull request #64534 from atrick/liveblocks-bitfield
Cleanup PrunedLiveBlocks
2023-03-22 16:33:08 -07:00
Andrew Trick
15796e3ff9 PrunedLiveness: add a SILFunction argument
So that liveness can migrate to using a SILBitfield.
2023-03-22 01:36:48 -07:00
Erik Eckstein
ae7770d911 Swift Bridging: use C++ instead of C bridging for BridgedFunction 2023-03-21 15:33:09 +01:00
Nate Chandler
af1ac900f9 [SIL] Add hasPointerEscape(SILValue).
There is a preexisting function with this name that takes a
BorrowedValue.  The new function calls that preexisting function if a
BorrowedValue can be constructed from the SILValue.  Otherwise, it looks
for direct uses of the value which qualify as "pointer escapes".
2023-03-10 10:49:53 -08:00
Andrew Trick
b0affc4931 Add unit test runner for OSSSLifetimeCompletion 2023-03-01 21:41:47 -08:00
Nate Chandler
7ea4523ee6 [SIL] Phi with incoming lexical value is lexical.
Added SILPhiArgument::isLexical.  It's true for phis which have an
incoming value that's lexical.  Dispatch to this member from
ValueBase::isLexical.
2023-02-23 16:26:44 -08:00
Andrew Trick
13e1aa4467 Add OwnershipLiveness utilities
Encapsulate all the complexity of reborrows and guaranteed phi in 3
ownership liveness interfaces:

LinerLiveness, InteriorLiveness, and ExtendedLiveness.
2023-02-10 09:39:18 -08:00
Andrew Trick
049d7856f4 Add visitAccessPathBaseUses API
For the move-only checker
2023-02-09 15:34:56 -08:00
Andrew Trick
4224d940ec Add visitInnerAdjacentPhis OSSA helper
This API is the inverse of visitEnclosingDefs when called on a phi.

This replaces the visitAdjacentReborrowsOfPhi algorithm with a small
loop that simply checks all the phis in the current block.

This should all be fairly efficient once SILArgument has a "reborrow"
flag.
2023-02-06 23:11:23 -08:00
Nate Chandler
4f845ccc52 [CanOSSALifetime] Option to shrink to scopes.
For most uses, some access scopes must be "respected"--if an extended
value's original lifetime originally extends beyond an access scope, its
canonicalized lifetime must not end _within_ such scopes (although
ending before them is fine).  Currently, to be conservative, the utility
applies this behavior to all access scopes.

For move-only values, however, lifetimes end at final consumes without
regard to access scopes.

Allow this behavior to be controlled by whether or not a
NonLocalAccessBlockAnalysis is provided to the utility in its
constructor.

rdar://104635319
2023-01-28 10:23:22 -08:00
Nate Chandler
10e86d6653 [CanonicalizeBorrowScope] Look through moves.
When encountering inside a borrow scope a non-lexical move_value or a
move_value [lexical] where the borrowed value is itself already lexical,
delete the move_value and regard its uses as uses of the moved-from
value.
2023-01-25 16:32:09 -08:00
Andrew Trick
7990dda02b Cleanup PrunedLiveness interface.
In preparation for adding OwnershipLiveness.

Rename Simple LiveRangeSummary to LiveRangeSummary.

Add initializeDefNode helpers to avoid confusion about the argument
type.

Add defBegin/defEnd iterators in MultiDefPrunedLiveness.
2023-01-24 23:26:40 -08:00
Nate Chandler
d563f9fa56 [Test] Reenable a test.
rdar://104021173
2023-01-23 14:36:50 -08:00
Andrew Trick
33a32e7af2 Replace OSSALifetimeAnalysis pass with unit tests. 2023-01-13 08:55:16 -08:00
Andrew Trick
a2dbd498b9 UnitTestRunner: Add a newline between tests
To make the output human-parsable.
2023-01-13 08:55:16 -08:00
Andrew Trick
e9f7c79b55 Organize UnitTestRunner.cpp before making it bigger.
Create a few sections for unit test. Ideally these would be in
separate files using a static global registry. For now, at least make
it possible to survey the available tests without reading them all
every time.
2023-01-11 16:44:58 -08:00
Meghana Gupta
dac6c0303f Add tests for simple jump threading 2023-01-08 00:15:17 -08:00
Meghana Gupta
5d2967ca75 Fix SimplifyCFG::simplifySwitchEnumOnObjcClassOptional for OSSA 2023-01-08 00:15:17 -08:00
Meghana Gupta
cdbd0f4743 Fix SimplifyCFG::simplifyArgs for OSSA 2023-01-08 00:15:12 -08:00
Meghana Gupta
900d8c3f63 Add ossa unit tests for SimplifyCFG::simplifyTermWithIdenticalDestBlocks 2023-01-06 23:50:07 -08:00
Meghana Gupta
73cd7a9dc1 Add ossa unit tests for SimplifyCFG::simplifySwitchEnumUnreachableBlocks 2023-01-06 23:50:07 -08:00
Meghana Gupta
94f8841374 Fix SimplifyCFG::simplifySwitchEnumBlock for OSSA 2023-01-06 23:50:07 -08:00
Andrew Trick
b85aea185d Unit tests for findEnclosingDefs and findBorrowIntroducers. 2023-01-03 09:33:39 -08:00
Andrew Trick
090f049acf Add an error message to unit test runner 2023-01-03 09:33:39 -08:00
Nate Chandler
a730387d55 [Test] Sorted alphabetically. 2022-10-24 12:23:42 -07:00
Meghana Gupta
ff4ab7de11 Enable SimplifyCFG::canonicalizeSwitchEnums and add unit tests 2022-10-21 23:08:43 -07:00
Meghana Gupta
2a908e3231 [NFC] Move UnitTestRunner::withTest definition out of the class 2022-10-21 16:48:28 -07:00
nate-chandler
a0207916cb Merge pull request #61655 from nate-chandler/shrink_borrow_scope/dont_hoist_over_only_rewritten_copies
[ShrinkBorrowScope] Leave under rewritten copies.
2022-10-21 16:34:46 -07:00
Nate Chandler
2f18af8979 [Test] Allowed referring to block arguments. 2022-10-21 13:58:42 -07:00
Nate Chandler
1ceee8dd30 [Gardening] Tweaked comment. 2022-10-20 18:09:56 -07:00
Nate Chandler
a4d31a468b [ShrinkBorrowScope] Leave under rewritten copies.
When shrinking a borrow scope like

    %borrow = begin_borrow %value
    barrier
    %copy = copy_value %borrow
    end_borrow %borrow

the copy will be rewritten to be a copy of the borrowee:

    %borrow = begin_borrow %value
    barrier
    %copy = copy_value %value
                       ^^^^^^
    end_borrow %borrow

If, as here, shrinking next encounters a barrier, then the insertion
point will be that rewritten copy_value instruction.

In such a case, when rather than creating a new end_borrow there and
deleting the old, just reuse the old one.  The lifetime of the value
being copied will be canonicalized by CopyPropagation regardless.
2022-10-20 18:09:54 -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
d5f1908918 [Test] Verified some non-deinit-barrier applies.
Checked that applies of empty functions, or their callees, or their
callees' callees, are not deinit barriers.  Checked that applies of
unknown functions, or their callees, or their callees' calles, are
deinit barriers.
2022-10-18 21:23:22 -07:00
Nate Chandler
c2f354eefd [PrunedLiveness] Addressed boundary TODO.
With guaranteed phis, we'll be able to encounter cases where the last
users are BranchInsts which use but don't consume a value.  But even
without them, we can still test the API.
2022-10-17 16:50:04 -07:00
Nate Chandler
ca43d71769 [OpaqueValues] Fixed index of self argument.
Previously, SILFunction_getSelfArgumentIndex was directly using the
function type rather than interacting with the function convention.
Here, it is made to interact with the convention.
2022-10-14 17:11:01 -07:00
Nate Chandler
94c2f3117b [Test] Fixed whitespace printing. 2022-10-14 17:10:27 -07:00
Nate Chandler
2898875fd3 [SILUnitTests] Added function dumper.
Being able to dump the function with a separate test allows other
unit-tests to skip that step and for FileChecking to focus only on the
specific things dumped between the begin and end of the unit test in
question.
2022-10-14 07:47:52 -07:00
Nate Chandler
57bc67032d [SILOpt] Add tester for visit adjacent reborrows. 2022-10-11 17:30:42 -07:00
Nate Chandler
eee857320b [SILOpt] Add tester for CanonicalizeOSSALifetime. 2022-10-11 17:30:42 -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