Skip to content

Conversation

@eeckstein
Copy link
Contributor

@eeckstein eeckstein commented May 25, 2023

The main change in this PR is in IRGen which needs to be able to emit constant enum values.
Use emitValueInjection to create the enum constant. Usually this method creates code in the current function. But if all arguments to the enum are constant, the builder never has to emit an instruction. Instead it can constant fold everything and just returns the final constant.

This PR also contains a few other statically-initialized-global related improvements:

  • create statically initialized let-globals as constant global (constant instead of global)
  • simplification for the init_enum_data_addr instruction
  • simplification for the value_to_bridge_object instruction

For details see the commit messages.

rdar://26521135

@eeckstein eeckstein requested a review from aschwaighofer May 25, 2023 07:27
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

eeckstein added 6 commits May 25, 2023 16:28
…ction

This comes up in the code for constructing an empty string literal.
With this optimization it's possible to statically initialize empty string global variables.
Optimize the sequence
```
  %1 = init_enum_data_addr %enum_addr, #someCaseWithPayload
  store %payload to %1
  inject_enum_addr %enum_addr, #someCaseWithPayload
```
to
```
  %1 = enum  $E, #someCaseWithPayload, %payload
  store %1 to %enum_addr
```
This sequence of three instructions must appear in consecutive order.
But usually this is the case, because it's generated this way by SILGen.
… in static initializers

Instead of passing `IRGenFunction`, pass the `IRGenModule` and the `IRBuilder`.
This makes enum creation not dependent on the presence of a function.

NFC, just refactoring.
The main change here is in IRGen which needs to be able to emit constant enum values.
Use `emitValueInjection` to create the enum constant.
Usually this method creates code in the current function.
But if all arguments to the enum are constant, the builder never has to emit an instruction.
Instead it can constant fold everything and just returns the final constant.

Also, create statically initialized let-globals as constant global (`constant` instead of `global`).
@eeckstein
Copy link
Contributor Author

@swift-ci 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.

The IRGen part looks good to me.

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.

2 participants