-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Lazily Associate a SILRemarkStreamer with an LLVMContext at IRGen time #31167
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
Corrects a mistake introduced in swiftlang#31106 I was under the impression that the LLVMContext for an instance of llvm::remarks::RemarkStreamer was somehow just scratch-space. It turns out the ASMPrinters don't gather remarks data from modules, they gather it from the remark streamer associated with the module's context. Thus, we cannot have the module's context be distinct from whatever context the streamer is eventually associated with. In order to bring these two systems back into harmony, introduce a simple ownership contract to SILRemarkStreamer. That is, it starts owned by a SILModule, in which case the SILRemarkStreamer holds onto the underlying LLVM object as the optimizer emits remarks. When it comes time to IRGen the module, then and only then do we install the streamer on the module's context. This tranfers ownership of the underlying LLVM streamer to LLVM itself, so it acts as a consuming operation. When we are about to perform IR Generation, the SILModule will be expiring anyways, so the streamer was already about to be destroyed. We're just putting it to better use doing its job.
@swift-ci test |
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.
LGTM! Thanks!
Build failed |
Build failed |
@swift-ci test |
Build failed |
Build failed |
Destroying the SIL remark streamer after transferring ownership to LLVM is frought. For one, the streamer holds the remark file's stream open. Destroying it early doesn't accomodate sil-opt, which transfers control to LLVM before running passes that emit remarks. Instead, just take a reference to the context that the streamer gets parented onto. If the remarks streamer infrastructure could just hold the file stream open for us, we wouldn't have to do any of this.
Heh, taking the streamer won't work because it'll close the underlying file stream before sil-opt has a chance to run any passes. |
@swift-ci test |
1 similar comment
@swift-ci test |
@swift-ci test Windows |
Build failed |
Builder died @swift-ci test Linux |
⛵ Note to self: Cherry-pick to 5.3 |
Corrects a mistake introduced in #31106
I was under the impression that the LLVMContext for an instance of
llvm::remarks::RemarkStreamer was somehow just scratch-space. It turns
out the ASMPrinters don't gather remarks data from modules, they gather
it from the remarks streamer associated with the module's context.
So, we cannot have the module's context be distinct from whatever
context the streamer is eventually associated with.
In order to bring these two notions back in harmony, introduce a simple
ownership contract to SILRemarkStreamer. That is, it starts owned by
a SILModule, in which case the SILRemarkStreamer holds onto the
underlying LLVM object as the optimizer emits remarks. When it comes
time to IRGen the module, then and only then do we install the streamer
on the module's context. This tranfers ownership of the underlying LLVM
streamer to LLVM itself, so it acts as a consuming operation. When we
are about to perform IRGeneration, the SILModule will be expiring
anyways, so the streamer was already about to be destroyed.