Skip to content

Commit 569c8af

Browse files
authored
[Profiler] Separate profiler instances for property inits and constructors (#25247)
Assign separate SILProfiler instances to stored property initializers and constructors. Starting with rdar://39460313, coverage reporting for these constructs was bundled up into a single SILProfiler uniqued by the NominalTypeDecl. There are two problems with doing this. First, the shared SILProfiler is given a fake name that can't be demangled. That breaks Xcode's reports. Second, the relationship between SILProfiler and SILFunction is supposed to be 1:1. Having a shared SILProfiler muddies things a bit and requires extra bookkeeping. rdar://47467864
1 parent 27b56b1 commit 569c8af

14 files changed

+171
-207
lines changed

include/swift/SIL/SILFunction.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/Basic/ProfileCounter.h"
2323
#include "swift/SIL/SILBasicBlock.h"
2424
#include "swift/SIL/SILDebugScope.h"
25+
#include "swift/SIL/SILDeclRef.h"
2526
#include "swift/SIL/SILLinkage.h"
2627
#include "swift/SIL/SILPrintContext.h"
2728
#include "llvm/ADT/StringMap.h"
@@ -362,7 +363,8 @@ class SILFunction
362363
Profiler = InheritedProfiler;
363364
}
364365

365-
void createProfiler(ASTNode Root, ForDefinition_t forDefinition);
366+
void createProfiler(ASTNode Root, SILDeclRef forDecl,
367+
ForDefinition_t forDefinition);
366368

367369
void discardProfiler() { Profiler = nullptr; }
368370

include/swift/SIL/SILProfiler.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class SILProfiler : public SILAllocated<SILProfiler> {
4141

4242
ASTNode Root;
4343

44+
SILDeclRef forDecl;
45+
4446
bool EmitCoverageMapping;
4547

4648
SILCoverageMap *CovMap = nullptr;
@@ -61,12 +63,14 @@ class SILProfiler : public SILAllocated<SILProfiler> {
6163

6264
std::vector<std::tuple<std::string, uint64_t, std::string>> CoverageData;
6365

64-
SILProfiler(SILModule &M, ASTNode Root, bool EmitCoverageMapping)
65-
: M(M), Root(Root), EmitCoverageMapping(EmitCoverageMapping) {}
66+
SILProfiler(SILModule &M, ASTNode Root, SILDeclRef forDecl,
67+
bool EmitCoverageMapping)
68+
: M(M), Root(Root), forDecl(forDecl),
69+
EmitCoverageMapping(EmitCoverageMapping) {}
6670

6771
public:
6872
static SILProfiler *create(SILModule &M, ForDefinition_t forDefinition,
69-
ASTNode N);
73+
ASTNode N, SILDeclRef forDecl);
7074

7175
/// Check if the function is set up for profiling.
7276
bool hasRegionCounters() const { return NumRegionCounters != 0; }

lib/SIL/SILFunction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ SILFunction::~SILFunction() {
151151
"Function cannot be deleted while function_ref's still exist");
152152
}
153153

154-
void SILFunction::createProfiler(ASTNode Root, ForDefinition_t forDefinition) {
154+
void SILFunction::createProfiler(ASTNode Root, SILDeclRef forDecl,
155+
ForDefinition_t forDefinition) {
155156
assert(!Profiler && "Function already has a profiler");
156-
Profiler = SILProfiler::create(Module, forDefinition, Root);
157+
Profiler = SILProfiler::create(Module, forDefinition, Root, forDecl);
157158
}
158159

159160
bool SILFunction::hasForeignBody() const {

0 commit comments

Comments
 (0)