Skip to content

[NFC] SILGlobalVariable utilities. #16870

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
Jun 26, 2018
Merged

[NFC] SILGlobalVariable utilities. #16870

merged 4 commits into from
Jun 26, 2018

Conversation

atrick
Copy link
Contributor

@atrick atrick commented May 28, 2018

Ignore the first two commits, which are from #16834.

The third commit just moves some code to a place it belongs: Move the utilities that are required for recognizing SILGlobalVariable access into SILGlobalVariable.[h|cpp].

Should be a trivial review. I'm not making a serious attempt to rework the interfaces:
@eeckstein, @gottesmm, @shajrawi ?

@atrick
Copy link
Contributor Author

atrick commented May 28, 2018

@swift-ci test.

}

SILFunction *swift::getCalleeOfOnceCall(BuiltinInst *BI) {
assert(BI->getNumOperands() == 2 && "once call should have 2 operands.");

Choose a reason for hiding this comment

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

Can you please assert based on getBuiltinInfo().ID of the BuiltinInst ? cleaner and safer assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do. This is all super old code that I just move out of SILOptimizer so it can be used to verify well-formed SIL.

SingleValueInstruction *&InitVal) {
InitVal = nullptr;
SILGlobalVariable *GVar = nullptr;
// We only handle a single SILBasicBlock for now.

Choose a reason for hiding this comment

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

I see this comment and this check repeated here and in findInitializer, maybe we can outline it to a single static bool function?

Copy link

@shajrawi shajrawi left a comment

Choose a reason for hiding this comment

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

Overall LGTM! but see the couple of suggestions I made in comments :)

atrick added 4 commits June 25, 2018 13:30
This information was getting lost in SIL printing/parsing.
Some passes rely on it. Regardless of whether passes should rely on it,
it is totally unacceptable for the SIL passes to have subtle differences
in behavior depending on the frontend mode. So, if we don't want passes
to rely on global variable decls, that needs to be enforced by the API
independent of how the frontend is invoked or how SIL is serialized.
Move the utilities that are required for recognizing SILGlobalVariable access
into SILGlobalVariable.[h|cpp].

Structural SIL properties that are assumed by the optimizer, and thus required
for SIL verification, should never be embedded in SILOptimizer passes, or even
in SILOptimizer/Utils. Structural SIL properties need to be defined in
/SIL. They are as much part of the SIL language as the opcode list.

These particular utilities are required for working with SILGlobalVariables, and
will be used by a whole-module access enforcement optimization.

The primary API for recognizing SIL globals is `getVariableOfGlobalInit`. It is
required to find the association between the addressor SILFunction marked
[global_init], and the SILGlobalVariable being addressed.

Other helper APIs expose more details about the addressor's SIL patterns and are
useful for transforming the initializer itself into an optimized form.
@atrick
Copy link
Contributor Author

atrick commented Jun 26, 2018

@swift-ci smoke test.

@atrick atrick merged commit 025af31 into swiftlang:master Jun 26, 2018
@atrick atrick deleted the globalutil branch October 16, 2018 16:26
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