Skip to content

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Nov 8, 2017

This is the last missing piece that will allow me to land my patch updating pred mem opt for ownership.

rdar://31521023

This rename makes since since:

1. This is SILGen specific functionality.
2. In the next commit I am going to be adding a SIL SavedInsertionPoint class. I
want to make sure the two can not be confused.
… typealias to std::pair.

For pred-memopt to work with ownership, we need to insert instructions in two
different places:

1. When loading not-available values, we must insert the load at the site of the
load we are trying to promote.
2. When propagating an available value, we must destructure and or copy before
each one of the stores that provide our value.

By changing AvailableValue to be a struct, I am providing a cleaner API, but
more importantly the ability to start tracking that information.

rdar://31521023
… at the store site.

Previously in PredMemOpts, we would insert any extracts at the load site, i.e.:

  store %foo to %0
  ...
  %1 = struct_element_addr %0, $Type, $Type.field
  %2 = load %1
  ...
  apply %use(%2)

would transform to:

  store %foo to %0
  ...
  %2 = struct_extract %foo
  apply %use(%2)

This framework will not work with Ownership enabled since the value stored is
considered consumed by the store. This change fixes the issue by moving such
non-destructive extracts to occur while %foo is considered live, i.e. before the
store:

  %2 = struct_extract %foo
  store %foo to %0
  ...
  apply %use(%2)

This means that we have to store insertion points for each store that provides
us with available values and insert the extracts at those points. This creates
some complications in the case where we have multiple stores since we need to
deal with phi nodes. Rather than dealing with it by hand, we just insert the
extracts at each point and then use the SSA updater to insert the relevant phi
nodes.

rdar://31521023
@gottesmm
Copy link
Contributor Author

gottesmm commented Nov 8, 2017

@swift-ci test

@gottesmm
Copy link
Contributor Author

gottesmm commented Nov 8, 2017

@swift-ci test source compatibility

@gottesmm gottesmm merged commit c8c7d2b into swiftlang:master Nov 8, 2017
@gottesmm gottesmm deleted the predmemopt_extract_at_store_not_load branch November 8, 2017 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant