Skip to content

[isolation-regions] Eliminate unnecessary heap allocations used for temporary values #68712

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

Conversation

gottesmm
Copy link
Contributor

I am splitting this off of a different commit that I decided to do in a slightly different manner. This PR just eliminates all of the temporary std::vectors being passed around in the hot loop of the pass in favor of a builder type that stores internally a SmallVector that should be large enough for handling the PartitionOps produced by any instruction.

…slation loop.

I did this by introducing a builder construct that has a SmallVector within it
that we append into instead of returning std::vector. I also used some passed in
SmallVectors in other places as well with large enough sizes that most times we
will not allocate.
Transfer is the terminology that we are using for something be transferred
across an isolation boundary, not consume. This also eliminates confusion with
consume which is a term being used around ownership.
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test


struct PartitionOpBuilder {
/// Parent translator that contains state.
PartitionOpTranslator *translater;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: translator not translater

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll fix this in a follow on.

return {};
void getApplyResults(const SILInstruction *inst,
SmallVectorImpl<SILValue> &foundResults) {
if (isa<ApplyInst, BeginApplyInst, BuiltinInst, PartialApplyInst>(inst)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Whoa I didn't know isa<> was variadic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I didn't know either)

// PartitionOpKind represents the different kinds of PartitionOps that
// SILInstructions can be translated to
/// PartitionOpKind represents the different kinds of PartitionOps that
/// SILInstructions can be translated to
Copy link
Contributor

Choose a reason for hiding this comment

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

It might help if the comments for each case gave an example of an actual instruction that lowers to this operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add that in a follow on.

@gottesmm gottesmm merged commit 631ad05 into swiftlang:main Sep 28, 2023
@gottesmm gottesmm deleted the pr-8f27a8f70da71ca09280019764955e3b64882190 branch September 28, 2023 15:43
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