mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Coverage] Refactor SIL generation for profiling
This patch moves the ownership of profiling state from SILGenProfiling to SILFunction, where it always belonged. Similarly, it moves ownership of the profile reader from SILGenModule to SILModule. The refactor sets us up to fix a few outstanding code coverage bugs and does away with sad hacks like ProfilerRAII. It also allows us to locally guarantee that a profile counter increment actually corresponds to the SILFunction at hand. That local guarantee causes a bugfix to accidentally fall out of this refactor: we now set up the profiling state for delayed functions correctly. Previously, we would set up a ProfilerRAII for the delayed function, but its counter increment would never be emitted :(. This fix constitutes the only functional change in this patch -- the rest is NFC. As a follow-up, I plan on removing some dead code in the profiling logic and fixing a few naming inconsistencies. I've left that for later to keep this patch simple.
This commit is contained in:
committed by
Vedant Kumar
parent
3fd5675235
commit
dd560d2aa6
@@ -23,6 +23,7 @@
|
||||
#include "swift/SIL/SILDebugScope.h"
|
||||
#include "swift/SIL/SILLinkage.h"
|
||||
#include "swift/SIL/SILPrintContext.h"
|
||||
#include "swift/SIL/SILProfiler.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
|
||||
/// The symbol name used for the program entry point function.
|
||||
@@ -132,6 +133,10 @@ private:
|
||||
/// The source location and scope of the function.
|
||||
const SILDebugScope *DebugScope;
|
||||
|
||||
/// The profiler for instrumentation based profiling, or null if profiling is
|
||||
/// disabled.
|
||||
SILProfiler *Profiler = nullptr;
|
||||
|
||||
/// The function's bare attribute. Bare means that the function is SIL-only
|
||||
/// and does not require debug info.
|
||||
unsigned Bare : 1;
|
||||
@@ -251,8 +256,24 @@ public:
|
||||
return SILFunctionConventions(LoweredType, getModule());
|
||||
}
|
||||
|
||||
SILProfiler *getProfiler() const { return Profiler; }
|
||||
|
||||
void setProfiler(SILProfiler *InheritedProfiler) {
|
||||
assert(!Profiler && "Function already has a profiler");
|
||||
Profiler = InheritedProfiler;
|
||||
}
|
||||
|
||||
void createProfiler(Decl *D) {
|
||||
assert(!Profiler && "Function already has a profiler");
|
||||
Profiler = SILProfiler::create(Module, D);
|
||||
}
|
||||
|
||||
void discardProfiler() { Profiler = nullptr; }
|
||||
|
||||
ProfileCounter getEntryCount() const { return EntryCount; }
|
||||
|
||||
void setEntryCount(ProfileCounter Count) { EntryCount = Count; }
|
||||
|
||||
bool isNoReturnFunction() const;
|
||||
|
||||
/// Unsafely rewrite the lowered type of this function.
|
||||
|
||||
Reference in New Issue
Block a user