Skip to content

Commit 19513b0

Browse files
authored
Merge pull request #16527 from vedantk/cov-symtab-4.2
2 parents 7909e24 + b74abea commit 19513b0

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

include/swift/SIL/SILProfiler.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ class SILProfiler : public SILAllocated<SILProfiler> {
9494
return RegionCounterMap;
9595
}
9696

97-
/// Increment the number of counter updates associated with this profiler.
98-
void recordCounterUpdate();
99-
10097
private:
10198
/// Map counters to ASTNodes and set them up for profiling the function.
10299
void assignRegionCounters();

lib/IRGen/GenBuiltin.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
206206
if (IID == llvm::Intrinsic::instrprof_increment) {
207207
// If we import profiling intrinsics from a swift module but profiling is
208208
// not enabled, ignore the increment.
209-
if (!IGF.getSILModule().getOptions().GenerateProfile) {
209+
SILModule &SILMod = IGF.getSILModule();
210+
const auto &Opts = SILMod.getOptions();
211+
if (!Opts.GenerateProfile) {
210212
(void)args.claimAll();
211213
return;
212214
}
@@ -246,6 +248,15 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
246248
replacement.add(NameGEP);
247249
replacement.add(args.claimAll());
248250
args = std::move(replacement);
251+
252+
if (Opts.EmitProfileCoverageMapping) {
253+
// Update the associated coverage mapping: it's now safe to emit, because
254+
// a symtab entry for this function is guaranteed (r://39146527).
255+
auto &coverageMaps = SILMod.getCoverageMaps();
256+
auto CovMapIt = coverageMaps.find(PGOFuncName);
257+
if (CovMapIt != coverageMaps.end())
258+
CovMapIt->second->setSymtabEntryGuaranteed();
259+
}
249260
}
250261

251262
if (IID != llvm::Intrinsic::not_intrinsic) {

lib/IRGen/GenDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,6 @@ void IRGenerator::emitGlobalTopLevel(bool emitForParallelEmission) {
10651065
CurrentIGMPtr IGM = getGenModule(decl ? decl->getDeclContext() : nullptr);
10661066
IGM->emitSILGlobalVariable(&v);
10671067
}
1068-
PrimaryIGM->emitCoverageMapping();
10691068

10701069
// Emit SIL functions.
10711070
for (SILFunction &f : PrimaryIGM->getSILModule()) {
@@ -1099,6 +1098,9 @@ void IRGenerator::emitGlobalTopLevel(bool emitForParallelEmission) {
10991098
IGM->emitSILProperty(&prop);
11001099
}
11011100

1101+
// Emit code coverage mapping data.
1102+
PrimaryIGM->emitCoverageMapping();
1103+
11021104
for (auto Iter : *this) {
11031105
IRGenModule *IGM = Iter.second;
11041106
IGM->finishEmitAfterTopLevel();

lib/SIL/SILProfiler.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,10 +1078,3 @@ Optional<ASTNode> SILProfiler::getPGOParent(ASTNode Node) {
10781078
}
10791079
return it->getSecond();
10801080
}
1081-
1082-
void SILProfiler::recordCounterUpdate() {
1083-
// If a counter update is recorded, the profile symbol table is guaranteed
1084-
// to have name data needed by the coverage mapping.
1085-
if (CovMap)
1086-
CovMap->setSymtabEntryGuaranteed();
1087-
}

lib/SILGen/SILGenFunction.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,6 @@ void SILGenFunction::emitProfilerIncrement(ASTNode N) {
657657
B.createIntegerLiteral(Loc, Int32Ty, CounterIt->second)};
658658
B.createBuiltin(Loc, C.getIdentifier("int_instrprof_increment"),
659659
SGM.Types.getEmptyTupleType(), {}, Args);
660-
SP->recordCounterUpdate();
661660
}
662661

663662
ProfileCounter SILGenFunction::loadProfilerCount(ASTNode Node) const {

0 commit comments

Comments
 (0)