Commit Graph

116 Commits

Author SHA1 Message Date
Andrew Trick
b272dc5e1a Cache 'isLet' within AccessedStorage.
Compute 'isLet' from the VarDecl that is available when constructing
AccessedStorage so we don't need to recover the VarDecl for the base
later.

This generally makes more sense and is more efficient, but it will be
necessary when we look past class casts when finding the reference root.
2020-10-16 15:00:10 -07:00
Andrew Trick
1e9c4d13ad Update LoadCopyToLoadBorrow for MemAccessUtils API. 2020-10-16 15:00:10 -07:00
Robert Widmann
6125d25cb4 [NFC] Silence Non-Exhaustive Switch Warnings on Windows 2020-10-14 13:26:09 -07:00
Michael Gottesman
0e05b51988 When converting load [copy] -> load_borrow, do not insert end_borrow if the block insert point is a dead end block.
This is important to do since otherwise, we may be implicitly reducing the
lifetime of a value which we can not do yet since we do not require all interior
pointer instructions to be guarded by borrows (yet). Once that constraint is in
place, we will not have this problem.

Consider a situation where one has a @owned switch_enum on an
indirect box case which is post-dominated by an unreachable that we want
to convert to @guaranteed:

  enum MyEnum {
    indirect case FirstCase(Int)
    ...
  }

  bb0(%in_guaranteed_addr : $*MyEnum):
    ...
    %0 = load [copy] %in_guaranteed_addr : $*MyEnum
    switch_enum %0 : $MyEnum, case #MyEnum.FirstCase: bb1, ...

  bb1(%1 : @owned ${ var Int }):
    %2 = project_box %1 : ${ var Int }, 0
    %3 = load [trivial] %2 : $*Int
    apply %log(%3) : $@convention(thin) (Int) -> ()
    unreachable

In this case, we will not have a destroy_value on the box, but we may
have a project_box on the box. This is ok since we are going to leak the
value. But since we are using all consuming uses to determine the
lifetime, we will want to insert an end_borrow at the head of the
switch_enum dest block like follows:

  bb0(%in_guaranteed_addr : $*MyEnum):
    ...
    %0 = load_borrow %in_guaranteed_addr : $*MyEnum
    switch_enum %0 : $MyEnum, case #MyEnum.FirstCase: bb1, ...

  bb1(%1 : @guaranteed ${ var Int }):
    end_borrow %1 : ${ var Int }
    %2 = project_box %1 : ${ var Int }, 0
    %3 = load [trivial] %2 : $*Int
    apply %log(%3) : $@convention(thin) (Int) -> ()
    unreachable

which would violate ownership invariants. Instead, we need to realize
that %1 is dominated by a dead end block so we may not have a
destroy_value upon it meaning we should just not insert the end_borrow
here. If we have a destroy_value upon it (since we did not get rid of a
destroy_value), then we will still get rid of the destroy_value if we are
going to optimize this, so we are still correct.

rdar://68096662
2020-10-12 13:11:46 -07:00
Michael Gottesman
22ef39a872 [semantic-arc] Fix an initialization thinko.
Just doing this quickly to prevent the bots from breaking. We still were using
the default instModCallbacks that do remove/RAUW/etc, but do not update data
structures.
2020-09-17 17:39:14 -05:00
Michael Gottesman
58508783b0 [semantic-arc] Add the ability to at the command line run a subset of semantic-arc optimizations.
SemanticARCOpts for maintainance reasons is becoming a series of small
optimization passes with a little pass manager that runs them. Given that, I
want to be able to be able to run subsets of these transforms for testing
reasons while normally running them in series.

This is in preparation for landing the coroutine lifetime extender and the
auto-coroutinizer.
2020-09-17 00:18:27 -05:00
Michael Gottesman
fa8c9d055a [semantic-arc] Move main optimize loop of SemanticARCOptVisitor into its own file. 2020-09-17 00:18:27 -05:00
Michael Gottesman
8d898e5180 [semantic-arc] Extract owned phi to guaranteed phi conversion from the visitor to its own function that works on the SemanticARCContext. 2020-09-17 00:18:26 -05:00
Michael Gottesman
915ccc0854 [semantic-arc] Extract out from the main visitor a context object for individual sub optimizations.
This patch moves state from the main SemanticARCOptVisitor struct to instead be
on a context object. Sub-transformations should not need to know about the
visitor since how it processes things is orthogonal from the transformations
themselves.
2020-09-16 19:11:07 -05:00
Michael Gottesman
04da864090 [semantic-arc] Split out owned -> guaranteed phi opt into its own file. 2020-09-01 12:25:46 -07:00
Michael Gottesman
d26f336b0b [semantic-arc] Split out copy_value optimizations (except phi elimination) into its own file. 2020-08-31 17:57:02 -07:00
Michael Gottesman
7c12c7f466 [semantic-arc] Extract out borrow scope optimizations into its own file. 2020-08-31 14:12:23 -07:00
Michael Gottesman
ba6dc1724b [semantic-arc] Split load [copy] -> load_borrow opt into its own file. 2020-08-31 10:07:59 -07:00
Michael Gottesman
96feb2dedd [ownership] Extract out the main visitor SemanticARCOptVisitor from SemanticARCOpts.h into its own header.
This is so I can move individual sub-optimizations on SemanticARCOptVisitor into
their own files. So for instance, there will be one file containing the load
[copy] optimization and another containing the phi optimization, etc.
2020-08-30 01:05:53 -07:00
Michael Gottesman
364b7c742c [ownership] Refactor OwnershipLiveRange and OwnershipPhiOperand into separate files from SemanticARCOpts.cpp 2020-08-29 21:39:34 -07:00
Michael Gottesman
1132cda811 [ownership] Move SemanticARCOpts into a separate folder in preparation for splitting into multiple small pseudo-passes.
SemanticARCOpts keeps on growing with various optimizations attached to a single
"optimization" manager. Move it to its own folder in prepation for splitting it
into multiple different optimizations and utility files.
2020-08-27 23:58:14 -07:00