Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opt] Re-work broadenSingleElementStores to use projections. #32318

Merged
merged 1 commit into from
Jun 12, 2020

Conversation

zoecarver
Copy link
Contributor

  • Fixes loadable edge case for address-only types.
  • Re-work, generalize, and simplify by using projections.
  • Support -enable-cxx-interop in sil-opt.

Refs #32291.

// loadable type, we can't create it as a struct later on.
// If our aggregate has unreferenced storage then we can never prove if it
// actually has a single field.
if (!baseAddrType.isLoadable(*f) ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atrick what do you think about supporting opaque types here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What cases are you trying to handle by doing that? Can you find out if it's possible to have
baseAddrType.isLoadable(*f) == true
AND
baseAddrType.aggregateHasUnreferenceableStorage() == false
??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean baseAddrType.isLoadable(*f) && baseAddrType.aggregateHasUnreferenceableStorage() == true? If not, I think that's most loadable types.

I think if we have a trivial struct with a bitfield that would do it: struct Foo { int x : 3; };. That struct will be loadable (even though, maybe it shouldn't be) but will also have un-referenceable storage (x).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so what case are you trying to handle? A struct with a single opaque property? So that "store" would need to actually be a copy_addr?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atrick my understanding is that has unreferencable storage is for things from c/c++ that have memory/other things that are not exposed to swift. To me it is sort of like an early, hacky resilience-esque sort of thing.

Copy link
Contributor Author

@zoecarver zoecarver Jun 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what case are you trying to handle?

I'm not trying to handle any particular case. Currently, we will bail on opaque types. I just wanted to make sure that's the correct behavior.

To me it is sort of like an early, hacky resilience-esque sort of thing.

I think this is true, yes. But most non-loadable types are non-loadable for ABI reasons, or to make sure calling conventions work with the C++ definitions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isLoadable seems like a sensible bailout considering we're dealing with storing values at its address

@atrick
Copy link
Contributor

atrick commented Jun 11, 2020

I don't want to say that I carefully reviewed this or thought about alternatives, but the implementation looks reasonable to me.

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some quick comments. I am fine with this landing after you fix the few nits and we finish answering Andy's questions.

include/swift/SIL/Projection.h Outdated Show resolved Hide resolved
lib/SIL/Utils/Projection.cpp Outdated Show resolved Hide resolved
// loadable type, we can't create it as a struct later on.
// If our aggregate has unreferenced storage then we can never prove if it
// actually has a single field.
if (!baseAddrType.isLoadable(*f) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atrick my understanding is that has unreferencable storage is for things from c/c++ that have memory/other things that are not exposed to swift. To me it is sort of like an early, hacky resilience-esque sort of thing.

lib/SILOptimizer/Utils/CanonicalizeInstruction.cpp Outdated Show resolved Hide resolved
* Fixes loadable edge case for address-only types.
* Re-work, generalize, and simplify by using projections.
* Support `-enable-cxx-interop` in sil-opt.
@zoecarver zoecarver force-pushed the opt/project-broaden branch from 5ad9ee4 to b695aee Compare June 11, 2020 22:52
@zoecarver
Copy link
Contributor Author

@gottesmm thanks for the review. I addressed all your comments.

@zoecarver
Copy link
Contributor Author

@swift-ci please smoke test

@zoecarver
Copy link
Contributor Author

@swift-ci please smoke test.

@zoecarver
Copy link
Contributor Author

@swift-ci please test windows platform.

@zoecarver zoecarver merged commit ee1d76e into swiftlang:master Jun 12, 2020
@@ -0,0 +1,18 @@
#ifndef VALIDATION_TEST_SILOPTIMIZER_FOO_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zoecarver Can you change the name of this file to something more meaningful? I didn't notice the name when I was reviewing.

@gribozavr gribozavr added the c++ interop Feature: Interoperability with C++ label Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants