Skip to content

Commit 5039c1c

Browse files
committed
[Profiler] NFC: Remove unnecessary parameter
`SILProfiler::create` is only ever called when emitting a definition, so this check is redundant.
1 parent 435af14 commit 5039c1c

File tree

5 files changed

+17
-27
lines changed

5 files changed

+17
-27
lines changed

include/swift/SIL/SILFunction.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,7 @@ class SILFunction
562562
Profiler = InheritedProfiler;
563563
}
564564

565-
void createProfiler(ASTNode Root, SILDeclRef forDecl,
566-
ForDefinition_t forDefinition);
565+
void createProfiler(ASTNode Root, SILDeclRef Ref);
567566

568567
void discardProfiler() { Profiler = nullptr; }
569568

include/swift/SIL/SILProfiler.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ class SILProfiler : public SILAllocated<SILProfiler> {
6969
EmitCoverageMapping(EmitCoverageMapping) {}
7070

7171
public:
72-
static SILProfiler *create(SILModule &M, ForDefinition_t forDefinition,
73-
ASTNode N, SILDeclRef forDecl);
72+
static SILProfiler *create(SILModule &M, ASTNode N, SILDeclRef Ref);
7473

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

lib/SIL/IR/SILFunction.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,9 @@ void SILFunction::deleteSnapshot(int ID) {
322322
} while ((f = f->snapshots) != nullptr);
323323
}
324324

325-
void SILFunction::createProfiler(ASTNode Root, SILDeclRef forDecl,
326-
ForDefinition_t forDefinition) {
325+
void SILFunction::createProfiler(ASTNode Root, SILDeclRef Ref) {
327326
assert(!Profiler && "Function already has a profiler");
328-
Profiler = SILProfiler::create(Module, forDefinition, Root, forDecl);
327+
Profiler = SILProfiler::create(Module, Root, Ref);
329328
}
330329

331330
bool SILFunction::hasForeignBody() const {

lib/SIL/IR/SILProfiler.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,19 @@ static bool canCreateProfilerForAST(ASTNode N, SILDeclRef forDecl) {
147147
return false;
148148
}
149149

150-
SILProfiler *SILProfiler::create(SILModule &M, ForDefinition_t forDefinition,
151-
ASTNode N, SILDeclRef forDecl) {
152-
// Avoid generating profiling state for declarations.
153-
if (!forDefinition)
154-
return nullptr;
155-
150+
SILProfiler *SILProfiler::create(SILModule &M, ASTNode N, SILDeclRef Ref) {
156151
const auto &Opts = M.getOptions();
157152
if (!doesASTRequireProfiling(M, N) && Opts.UseProfile.empty())
158153
return nullptr;
159154

160-
if (!canCreateProfilerForAST(N, forDecl)) {
155+
if (!canCreateProfilerForAST(N, Ref)) {
161156
N.dump(llvm::errs());
162157
llvm_unreachable("Invalid AST node for profiling");
163158
}
164159

165160
auto *Buf = M.allocate<SILProfiler>(1);
166161
auto *SP =
167-
::new (Buf) SILProfiler(M, N, forDecl, Opts.EmitProfileCoverageMapping);
162+
::new (Buf) SILProfiler(M, N, Ref, Opts.EmitProfileCoverageMapping);
168163
SP->assignRegionCounters();
169164
return SP;
170165
}

lib/SILGen/SILGen.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -667,12 +667,12 @@ static void setUpForProfiling(SILDeclRef constant, SILFunction *F,
667667
if (constant.hasDecl()) {
668668
if (auto *fd = constant.getFuncDecl()) {
669669
if (fd->hasBody()) {
670-
F->createProfiler(fd, constant, forDefinition);
670+
F->createProfiler(fd, constant);
671671
profiledNode = fd->getBody(/*canSynthesize=*/false);
672672
}
673673
}
674674
} else if (auto *ace = constant.getAbstractClosureExpr()) {
675-
F->createProfiler(ace, constant, forDefinition);
675+
F->createProfiler(ace, constant);
676676
profiledNode = ace;
677677
}
678678
// Set the function entry count for PGO.
@@ -914,7 +914,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
914914
} else {
915915
preEmitFunction(constant, f, decl);
916916
PrettyStackTraceSILFunction X("silgen emitConstructor", f);
917-
f->createProfiler(decl, constant, ForDefinition);
917+
f->createProfiler(decl, constant);
918918
SILGenFunction(*this, *f, decl).emitValueConstructor(decl);
919919
postEmitFunction(constant, f);
920920
}
@@ -927,7 +927,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
927927

928928
preEmitFunction(constant, f, decl);
929929
PrettyStackTraceSILFunction X("silgen constructor initializer", f);
930-
f->createProfiler(decl, constant, ForDefinition);
930+
f->createProfiler(decl, constant);
931931
SILGenFunction(*this, *f, decl).emitClassConstructorInitializer(decl);
932932
postEmitFunction(constant, f);
933933
break;
@@ -993,7 +993,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
993993
auto loc = RegularLocation::getAutoGeneratedLocation(init);
994994
preEmitFunction(constant, f, loc);
995995
PrettyStackTraceSILFunction X("silgen emitStoredPropertyInitialization", f);
996-
f->createProfiler(init, constant, ForDefinition);
996+
f->createProfiler(init, constant);
997997
SILGenFunction SGF(*this, *f, initDC);
998998

999999
// If this is a stored property initializer inside a type at global scope,
@@ -1020,8 +1020,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
10201020
"silgen emitPropertyWrapperBackingInitializer", f);
10211021
auto wrapperInfo = var->getPropertyWrapperInitializerInfo();
10221022
assert(wrapperInfo.hasInitFromWrappedValue());
1023-
f->createProfiler(wrapperInfo.getInitFromWrappedValue(), constant,
1024-
ForDefinition);
1023+
f->createProfiler(wrapperInfo.getInitFromWrappedValue(), constant);
10251024
auto varDC = var->getInnermostDeclContext();
10261025
SILGenFunction SGF(*this, *f, varDC);
10271026
SGF.emitGeneratorFunction(constant, wrapperInfo.getInitFromWrappedValue());
@@ -1038,8 +1037,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
10381037
"silgen emitPropertyWrapperInitFromProjectedValue", f);
10391038
auto initInfo = var->getPropertyWrapperInitializerInfo();
10401039
assert(initInfo.hasInitFromProjectedValue());
1041-
f->createProfiler(initInfo.getInitFromProjectedValue(), constant,
1042-
ForDefinition);
1040+
f->createProfiler(initInfo.getInitFromProjectedValue(), constant);
10431041
auto varDC = var->getInnermostDeclContext();
10441042
SILGenFunction SGF(*this, *f, varDC);
10451043
SGF.emitGeneratorFunction(constant, initInfo.getInitFromProjectedValue());
@@ -1079,7 +1077,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
10791077
auto *dd = cast<DestructorDecl>(constant.getDecl());
10801078
preEmitFunction(constant, f, dd);
10811079
PrettyStackTraceSILFunction X("silgen emitDestroyingDestructor", f);
1082-
f->createProfiler(dd, constant, ForDefinition);
1080+
f->createProfiler(dd, constant);
10831081
SILGenFunction(*this, *f, dd).emitDestroyingDestructor(dd);
10841082
postEmitFunction(constant, f);
10851083
return;
@@ -1092,7 +1090,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
10921090
if (usesObjCAllocator(cd)) {
10931091
preEmitFunction(constant, f, dd);
10941092
PrettyStackTraceSILFunction X("silgen emitDestructor -dealloc", f);
1095-
f->createProfiler(dd, constant, ForDefinition);
1093+
f->createProfiler(dd, constant);
10961094
SILGenFunction(*this, *f, dd).emitObjCDestructor(constant);
10971095
postEmitFunction(constant, f);
10981096
return;
@@ -1954,7 +1952,7 @@ void SILGenModule::visitTopLevelCodeDecl(TopLevelCodeDecl *td) {
19541952
// A single SILFunction may be used to lower multiple top-level decls. When
19551953
// this happens, fresh profile counters must be assigned to the new decl.
19561954
TopLevelSGF->F.discardProfiler();
1957-
TopLevelSGF->F.createProfiler(td, SILDeclRef(), ForDefinition);
1955+
TopLevelSGF->F.createProfiler(td, SILDeclRef());
19581956

19591957
TopLevelSGF->emitProfilerIncrement(td->getBody());
19601958

0 commit comments

Comments
 (0)