diff --git a/include/swift/SIL/SILProfiler.h b/include/swift/SIL/SILProfiler.h index 45ab785cae1d6..c7cfb3b595860 100644 --- a/include/swift/SIL/SILProfiler.h +++ b/include/swift/SIL/SILProfiler.h @@ -93,9 +93,6 @@ class SILProfiler : public SILAllocated { return RegionCounterMap; } - /// Increment the number of counter updates associated with this profiler. - void recordCounterUpdate(); - private: /// Map counters to ASTNodes and set them up for profiling the function. void assignRegionCounters(); diff --git a/lib/IRGen/GenBuiltin.cpp b/lib/IRGen/GenBuiltin.cpp index 66b3d9b1f6f01..c176966981eb7 100644 --- a/lib/IRGen/GenBuiltin.cpp +++ b/lib/IRGen/GenBuiltin.cpp @@ -206,7 +206,9 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, if (IID == llvm::Intrinsic::instrprof_increment) { // If we import profiling intrinsics from a swift module but profiling is // not enabled, ignore the increment. - if (!IGF.getSILModule().getOptions().GenerateProfile) { + SILModule &SILMod = IGF.getSILModule(); + const auto &Opts = SILMod.getOptions(); + if (!Opts.GenerateProfile) { (void)args.claimAll(); return; } @@ -246,6 +248,15 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, replacement.add(NameGEP); replacement.add(args.claimAll()); args = std::move(replacement); + + if (Opts.EmitProfileCoverageMapping) { + // Update the associated coverage mapping: it's now safe to emit, because + // a symtab entry for this function is guaranteed (r://39146527). + auto &coverageMaps = SILMod.getCoverageMaps(); + auto CovMapIt = coverageMaps.find(PGOFuncName); + if (CovMapIt != coverageMaps.end()) + CovMapIt->second->setSymtabEntryGuaranteed(); + } } if (IID != llvm::Intrinsic::not_intrinsic) { diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index 653bfdcc935ff..856530b056e1e 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -1065,7 +1065,6 @@ void IRGenerator::emitGlobalTopLevel(bool emitForParallelEmission) { CurrentIGMPtr IGM = getGenModule(decl ? decl->getDeclContext() : nullptr); IGM->emitSILGlobalVariable(&v); } - PrimaryIGM->emitCoverageMapping(); // Emit SIL functions. for (SILFunction &f : PrimaryIGM->getSILModule()) { @@ -1099,6 +1098,9 @@ void IRGenerator::emitGlobalTopLevel(bool emitForParallelEmission) { IGM->emitSILProperty(&prop); } + // Emit code coverage mapping data. + PrimaryIGM->emitCoverageMapping(); + for (auto Iter : *this) { IRGenModule *IGM = Iter.second; IGM->finishEmitAfterTopLevel(); diff --git a/lib/SIL/SILProfiler.cpp b/lib/SIL/SILProfiler.cpp index ca8e18ed5d948..d00e16539c7d2 100644 --- a/lib/SIL/SILProfiler.cpp +++ b/lib/SIL/SILProfiler.cpp @@ -1081,10 +1081,3 @@ Optional SILProfiler::getPGOParent(ASTNode Node) { } return it->getSecond(); } - -void SILProfiler::recordCounterUpdate() { - // If a counter update is recorded, the profile symbol table is guaranteed - // to have name data needed by the coverage mapping. - if (CovMap) - CovMap->setSymtabEntryGuaranteed(); -} diff --git a/lib/SILGen/SILGenFunction.cpp b/lib/SILGen/SILGenFunction.cpp index 8f9885ded9490..022dea0b84863 100644 --- a/lib/SILGen/SILGenFunction.cpp +++ b/lib/SILGen/SILGenFunction.cpp @@ -658,7 +658,6 @@ void SILGenFunction::emitProfilerIncrement(ASTNode N) { B.createIntegerLiteral(Loc, Int32Ty, CounterIt->second)}; B.createBuiltin(Loc, C.getIdentifier("int_instrprof_increment"), SGM.Types.getEmptyTupleType(), {}, Args); - SP->recordCounterUpdate(); } ProfileCounter SILGenFunction::loadProfilerCount(ASTNode Node) const {