Skip to content

TypeLayout: Use AlignedGroups instead of ScalarLayouts #39053

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

Merged
merged 4 commits into from
Sep 22, 2021

Conversation

gmittert
Copy link
Contributor

The goal of these changes is to reduce the uses of getOrCreateScalarEntry which is a passthrough to the typeinfo system rather than using the typelayout system. Removing these uses should increase the visibility that the typelayout system has in the types that it is lowering and allow it to generate better code.

However, simply changing the included getOrCreateScalarEntries to getOrCreateAligned groups causes a significant size increase. The two main contributors were enums not implementing pod/nullablerefcount/forwardtopayload optimizations and structs doing alignment computations for each field.

This PR teach typelayout how to do the above and then swaps to using aligned group entries instead of scalar group entries. In my testing it brought the size increase down to within 1%, but it might be good to test it against more samples.

@gmittert gmittert requested a review from aschwaighofer August 26, 2021 00:08
@gmittert

This comment has been minimized.

@gmittert gmittert changed the title Type layout enhancements upstream TypeLayout: Use AlignedGroups instead of ScalarLayouts Aug 26, 2021
@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@gmittert gmittert force-pushed the TypeLayoutEnhancementsUpstream branch from 5f63ca4 to 9cffbfb Compare August 26, 2021 04:17
@gmittert

This comment has been minimized.

@gmittert

This comment has been minimized.

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@gmittert gmittert force-pushed the TypeLayoutEnhancementsUpstream branch from 9cffbfb to 290c6dd Compare August 26, 2021 21:32
@gmittert
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 290c6ddd4d1ae03af9278498ded5c554e8f95630

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 290c6ddd4d1ae03af9278498ded5c554e8f95630

@gmittert gmittert marked this pull request as ready for review August 27, 2021 00:23
@gmittert gmittert force-pushed the TypeLayoutEnhancementsUpstream branch from 290c6dd to 1e9127a Compare September 11, 2021 00:08
@gmittert
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@aschwaighofer aschwaighofer left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

@gmittert gmittert force-pushed the TypeLayoutEnhancementsUpstream branch from 1e9127a to 332b4f7 Compare September 21, 2021 22:28
@gmittert
Copy link
Contributor Author

Rebasing and cleaning up a bit.

@gmittert
Copy link
Contributor Author

@swift-ci please smoke test

Gwen Mittertreiner added 4 commits September 21, 2021 22:21
Added ForceStructTypeLayouts. When enabled, IRGen will lower structs using the
aligned group of TypeLayout rather than using TypeInfos. This potentially leads
to a size increase as TypeInfos currently produce better code than the
TypeLayout route.
If the Aligned Group is fixed sized and alignment, rather than doing an
alignment computation at runtime, we compute the offset for each field
and emit a GEP.
When generating TypeLayouts, rather than using a Scalar Layout, use an
aligned struct so that we use the typelayout path rather than the
typeinfo path when doing irgen.
Teach TypeLayout about when it can omit checking the enum tag and
instead directly either ignore retaining/releasing the payload or
retain/release it regardless of the enum tag. This ports to
PO/NullableRefcounted/ForwardToPayload distinctions to TypeLayout.
@gmittert gmittert force-pushed the TypeLayoutEnhancementsUpstream branch from 332b4f7 to b3c9316 Compare September 22, 2021 05:29
@gmittert
Copy link
Contributor Author

@swift-ci please smoke test

@gmittert
Copy link
Contributor Author

@swift-ci please test windows platform

@gmittert
Copy link
Contributor Author

Windows build seems to be broken. Same test is failing in other PRs.

@gmittert gmittert merged commit 45b84b8 into swiftlang:main Sep 22, 2021
@gmittert gmittert deleted the TypeLayoutEnhancementsUpstream branch September 22, 2021 16:57
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.

3 participants