@@ -606,20 +606,12 @@ SILGenModule::getOrCreateProfilerForConstructors(DeclContext *ctx,
606
606
return profiler;
607
607
}
608
608
609
- SILFunction *SILGenModule::getFunction (SILDeclRef constant,
610
- ForDefinition_t forDefinition) {
611
- // If we already emitted the function, return it (potentially preparing it
612
- // for definition).
613
- if (auto emitted = getEmittedFunction (constant, forDefinition))
614
- return emitted;
615
-
616
- // Note: Do not provide any SILLocation. You can set it afterwards.
617
- SILGenFunctionBuilder builder (*this );
618
- auto *F = builder.getOrCreateFunction (constant.hasDecl () ? constant.getDecl ()
619
- : (Decl *)nullptr ,
620
- constant, forDefinition);
609
+ // / Set up the function for profiling instrumentation.
610
+ static void setUpForProfiling (SILDeclRef constant, SILFunction *F,
611
+ ForDefinition_t forDefinition) {
612
+ if (!forDefinition)
613
+ return ;
621
614
622
- // Set up the function for profiling instrumentation.
623
615
ASTNode profiledNode;
624
616
if (!haveProfiledAssociatedFunction (constant)) {
625
617
if (constant.hasDecl ()) {
@@ -637,6 +629,23 @@ SILFunction *SILGenModule::getFunction(SILDeclRef constant,
637
629
if (SILProfiler *SP = F->getProfiler ())
638
630
F->setEntryCount (SP->getExecutionCount (profiledNode));
639
631
}
632
+ }
633
+
634
+ SILFunction *SILGenModule::getFunction (SILDeclRef constant,
635
+ ForDefinition_t forDefinition) {
636
+ // If we already emitted the function, return it (potentially preparing it
637
+ // for definition).
638
+ if (auto emitted = getEmittedFunction (constant, forDefinition)) {
639
+ setUpForProfiling (constant, emitted, forDefinition);
640
+ return emitted;
641
+ }
642
+
643
+ // Note: Do not provide any SILLocation. You can set it afterwards.
644
+ SILGenFunctionBuilder builder (*this );
645
+ auto *F = builder.getOrCreateFunction (constant.hasDecl () ? constant.getDecl ()
646
+ : (Decl *)nullptr ,
647
+ constant, forDefinition);
648
+ setUpForProfiling (constant, F, forDefinition);
640
649
641
650
assert (F && " SILFunction should have been defined" );
642
651
0 commit comments