-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
Conversation
@swift-ci test. |
} | ||
|
||
SILFunction *swift::getCalleeOfOnceCall(BuiltinInst *BI) { | ||
assert(BI->getNumOperands() == 2 && "once call should have 2 operands."); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this 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 :)
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.
@swift-ci smoke test. |
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 ?