Commit Graph

446 Commits

Author SHA1 Message Date
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
John McCall
27142e42f6 Add SIL instructions to get and set pack elements 2023-02-07 01:10:15 -05:00
Allan Shortlidge
d2524a6de8 AST: Implement parsing support for the accepted spelling of @backDeployed for SE-0376.
For source compatibility `@_backDeploy` continues to be accepted as a spelling.

rdar://102792909
2023-02-01 22:04:33 -08:00
John McCall
6bf9ac858b Add instructions to allocate and deallocate packs.
Having added these, I'm not entirely sure we couldn't just use
alloc_stack and dealloc_stack.  Well, if we find ourselves adding
a lot of redundancy with those instructions (e.g. around DI), we
can always go back and rip these out.
2023-01-31 22:39:34 -05: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
Nate Chandler
03eb567d74 [Test] Print helpful info on bad unit tests.
If a unit test is miswritten in the sense that the test expects an
instance of one type by an instance of some other type is specified,
print that out.
2023-01-23 13:26:13 -08:00
John McCall
374c202b99 Add SIL instructions to generate pack indices 2023-01-19 23:57:22 -05: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
c9e533e606 Merge pull request #62987 from atrick/org-unittest
Organize UnitTestRunner.cpp before making it bigger.
2023-01-12 09:15:17 -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
John McCall
37baf9b2dc Add a SIL instruction to open a pack as an element archetype
IRGen not yet done.
2023-01-11 03:11:30 -05: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
Erik Eckstein
75aace0f40 Remove the old EscapeAnalysis 2022-12-21 17:41:47 +01:00
Erik Eckstein
c130273859 Remove the old SideEffectAnalysis 2022-12-21 17:41:47 +01:00
Pavel Yaskevich
3fb69b3c3c [SIL] SILFunction: Add runtime accessible function attribute
This attribute indicates that the given SILFunction has to be
added to "accessible functions" section and could be looked up
at runtime using a special API.
2022-12-20 09:33:44 -08:00
Michael Gottesman
9e44011e4d [sil] Add a new attribute called @closureCaptured to SILFunctionArguments that are closure capture arguments.
I am adding this to make it easy to determine if a SILFunction that is not inout
aliasable is captured. This is useful when emitting certain types of
diagnostics like I need to emit with move only.
2022-12-14 15:16:43 -08: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
Allan Shortlidge
e0cce4a45d Serialization: Update -experimental-skip-non-inlinable-function-bodies SIL verification for @_backDeploy.
SIL verification was failing for modules containing functions with `@_backDeploy` because `SILSkippingChecker` expected the `SILFunction` corresponding to the resilient copy of back deployed function to be empty. Since the overall function declaration for a back deployed function is considered inlinable, the body will be typechecked and SILGen emits both the fallback copy of the function and the resilient copy of the function. The checker should therefore expect to see back deployed functions that are not marked as serialized.
2022-12-06 17:15:17 -08: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
Allan Shortlidge
0a24042cdd SIL: Introduce the has_symbol SIL instruction. 2022-11-16 16:07:26 -08:00
Erik Eckstein
520a893146 ParseTestSpecification: remove an unused private member variable
To fix a warning
2022-11-14 20:37:33 +01: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
6dc4dee43e [Test] Improved inst/block offset subscripting. 2022-10-21 13:58:29 -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
8397a215d9 [Test] Allow specifying blocks by offset. 2022-10-20 13:34:13 -07:00
Nate Chandler
0d7d8911a4 [Test] Allow specifying instructions by offset.
Make @instruction[+1] refer to the instruction after the "current"
instruction, @instruction[-1] the one before, and so on.
2022-10-20 13:34:13 -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
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
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
faa75bd02f [LifetimeAnalysis] Only collect trace values.
Previously, every value for which there was a debug_value instruction
was added to liveness.  Only add those with the [trace] flag set.
2022-10-11 17:30:43 -07:00