Lazily Associated a SILRemarkStreamer with an LLVMContext at IRGen time

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 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.
This commit is contained in:
Robert Widmann
2020-04-20 17:43:45 -07:00
parent 477af9f90d
commit 90d05c10fa
5 changed files with 41 additions and 16 deletions

View File

@@ -523,6 +523,9 @@ public:
swift::SILRemarkStreamer *getSILRemarkStreamer() {
return silRemarkStreamer.get();
}
std::unique_ptr<swift::SILRemarkStreamer> takeSILRemarkStreamer() {
return std::move(silRemarkStreamer);
}
void installSILRemarkStreamer();
// This is currently limited to VarDecl because the visibility of global