@@ -654,35 +654,6 @@ static SILFunction *getFunctionToInsertAfter(SILGenModule &SGM,
654
654
return nullptr ;
655
655
}
656
656
657
- static bool haveProfiledAssociatedFunction (SILDeclRef constant) {
658
- return constant.isDefaultArgGenerator () || constant.isForeign ;
659
- }
660
-
661
- // / Set up the function for profiling instrumentation.
662
- static void setUpForProfiling (SILDeclRef constant, SILFunction *F,
663
- ForDefinition_t forDefinition) {
664
- if (!forDefinition || F->getProfiler ())
665
- return ;
666
-
667
- ASTNode profiledNode;
668
- if (!haveProfiledAssociatedFunction (constant)) {
669
- if (constant.hasDecl ()) {
670
- if (auto *fd = constant.getFuncDecl ()) {
671
- if (fd->hasBody ()) {
672
- F->createProfiler (fd, constant);
673
- profiledNode = fd->getBody (/* canSynthesize=*/ false );
674
- }
675
- }
676
- } else if (auto *ace = constant.getAbstractClosureExpr ()) {
677
- F->createProfiler (ace, constant);
678
- profiledNode = ace;
679
- }
680
- // Set the function entry count for PGO.
681
- if (SILProfiler *SP = F->getProfiler ())
682
- F->setEntryCount (SP->getExecutionCount (profiledNode));
683
- }
684
- }
685
-
686
657
static bool isEmittedOnDemand (SILModule &M, SILDeclRef constant) {
687
658
if (!constant.hasDecl ())
688
659
return false ;
@@ -730,12 +701,9 @@ static bool isEmittedOnDemand(SILModule &M, SILDeclRef constant) {
730
701
731
702
SILFunction *SILGenModule::getFunction (SILDeclRef constant,
732
703
ForDefinition_t forDefinition) {
733
- // If we already emitted the function, return it (potentially preparing it
734
- // for definition).
735
- if (auto emitted = getEmittedFunction (constant, forDefinition)) {
736
- setUpForProfiling (constant, emitted, forDefinition);
704
+ // If we already emitted the function, return it.
705
+ if (auto emitted = getEmittedFunction (constant, forDefinition))
737
706
return emitted;
738
- }
739
707
740
708
auto getBestLocation = [](SILDeclRef ref) -> SILLocation {
741
709
if (ref.hasDecl ())
@@ -755,7 +723,6 @@ SILFunction *SILGenModule::getFunction(SILDeclRef constant,
755
723
[&IGM](SILLocation loc, SILDeclRef constant) -> SILFunction * {
756
724
return IGM.getFunction (constant, NotForDefinition);
757
725
});
758
- setUpForProfiling (constant, F, forDefinition);
759
726
760
727
assert (F && " SILFunction should have been defined" );
761
728
@@ -889,6 +856,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
889
856
if (auto *ce = constant.getAbstractClosureExpr ()) {
890
857
preEmitFunction (constant, f, ce);
891
858
PrettyStackTraceSILFunction X (" silgen closureexpr" , f);
859
+ f->createProfiler (ce, constant);
892
860
SILGenFunction (*this , *f, ce).emitClosure (ce);
893
861
postEmitFunction (constant, f);
894
862
break ;
@@ -898,6 +866,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
898
866
899
867
preEmitFunction (constant, f, fd);
900
868
PrettyStackTraceSILFunction X (" silgen emitFunction" , f);
869
+ f->createProfiler (fd, constant);
901
870
SILGenFunction (*this , *f, fd).emitFunction (fd);
902
871
postEmitFunction (constant, f);
903
872
break ;
0 commit comments