Skip to content

Allow more complex InlineArray initializations to end up in a statically initialized global #81649

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 7 commits into from
May 21, 2025

Conversation

eeckstein
Copy link
Contributor

The main part of this PR is to rewrite the InitializeStaticGlobals pass. Instead of looking for a single store to the global in a global-init function, it builds a GlobalInitValue tree. This is a data structure representing the init value of the global. It can handle complex InlineArray initializations, like init(repeating:).

Some other changes were necessary to make this work:

  • In SILGen, use the new builtin prepareInitialization instead of zeroInitializer when generating SIL for Builtin.emplace
  • In the inliner tune the heuristic for constructors to be inlined into global initializer functions.

rdar://150859232

eeckstein added 7 commits May 20, 2025 20:46
…l initializer functions.

Inlining constructors into global initializers increase the changes that the global can be initialized statically.
It is like `zeroInitializer`, but does not actually initialize the memory.
It only indicates to mandatory passes that the memory is going to be initialized.
…er` when generating SIL for `Builtin.emplace`

`zeroInitializer` is blocking optimizations, but it is not needed because the closure of `Builtin.emplace` will initialize the memory anyway.
We only need to tell mandatory passes that this memory should be treated as initialized.
…rays

Instead of looking for a single store to the global in a global-init function, build a GlobalInitValue tree.
This is a data structure representing the init value of the global. It can handle complex InlineArray initializations,
like `init(repeating:)`.

rdar://150859232
…wift to SimplifyLoad.swift

Because it's not used anywhere else anymore
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein requested review from kubamracek, atrick, meg-gupta and nate-chandler and removed request for xedin, slavapestov, kavon, rjmccall and hborla May 20, 2025 18:51
@eeckstein
Copy link
Contributor Author

@swift-ci apple silicon benchmark

@eeckstein eeckstein merged commit 0ceb517 into swiftlang:main May 21, 2025
6 checks passed
@eeckstein eeckstein deleted the global-inlinearray-initialization branch May 21, 2025 04:24
hamishknight added a commit to hamishknight/swift that referenced this pull request May 22, 2025
…nearray-initialization"

This reverts commit 0ceb517.
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