Skip to content

[Coverage] Mark symtab entries as guaranteed after intrinsic lowering #16527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/swift/SIL/SILProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ class SILProfiler : public SILAllocated<SILProfiler> {
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();
Expand Down
13 changes: 12 additions & 1 deletion lib/IRGen/GenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 0 additions & 7 deletions lib/SIL/SILProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,10 +1078,3 @@ Optional<ASTNode> 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();
}
1 change: 0 additions & 1 deletion lib/SILGen/SILGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,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 {
Expand Down