Skip to content

[Coverage] Drop records for functions DCE'd after builtin lowering #26817

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
Aug 24, 2019
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
11 changes: 0 additions & 11 deletions include/swift/SIL/SILCoverageMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ class SILCoverageMap : public llvm::ilist_node<SILCoverageMap>,
// Tail-allocated expression list.
MutableArrayRef<llvm::coverage::CounterExpression> Expressions;

// Whether the coverage mapping's name data is in the profile symbol table.
bool HasSymtabEntry;

// Disallow copying into temporary objects.
SILCoverageMap(const SILCoverageMap &other) = delete;
SILCoverageMap &operator=(const SILCoverageMap &) = delete;
Expand Down Expand Up @@ -112,14 +109,6 @@ class SILCoverageMap : public llvm::ilist_node<SILCoverageMap>,
return Expressions;
}

/// Check whether this coverage mapping can reference its name data within
/// the profile symbol table.
bool hasSymtabEntry() const { return HasSymtabEntry; }

/// Guarantee that this coverage mapping can reference its name data within
/// the profile symbol table.
void setSymtabEntryGuaranteed() { HasSymtabEntry = true; }

void printCounter(llvm::raw_ostream &OS, llvm::coverage::Counter C) const;

/// Print the coverage map.
Expand Down
9 changes: 0 additions & 9 deletions lib/IRGen/GenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,6 @@ 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
15 changes: 12 additions & 3 deletions lib/IRGen/GenCoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ static std::string getCoverageSection(IRGenModule &IGM) {

void IRGenModule::emitCoverageMapping() {
std::vector<const SILCoverageMap *> Mappings;
for (const auto &M : getSILModule().getCoverageMaps())
if (M.second->hasSymtabEntry())
Mappings.push_back(M.second);
for (const auto &M : getSILModule().getCoverageMaps()) {
// Check whether this coverage mapping can reference its name data within
// the profile symbol table. If the name global is gone, this function has
// been optimized out.
StringRef PGOFuncName = M.second->getPGOFuncName();
std::string PGOFuncNameVar = llvm::getPGOFuncNameVarName(
PGOFuncName, llvm::GlobalValue::LinkOnceAnyLinkage);
if (!Module.getNamedGlobal(PGOFuncNameVar))
continue;
Mappings.push_back(M.second);
}

// If there aren't any coverage maps, there's nothing to emit.
if (Mappings.empty())
Expand Down Expand Up @@ -106,6 +114,7 @@ void IRGenModule::emitCoverageMapping() {
StringRef CoverageMapping(OS.str().c_str() + PrevSize, MappingLen);

StringRef NameValue = M->getPGOFuncName();
assert(!NameValue.empty() && "Expected a named record");
uint64_t FuncHash = M->getHash();

// Create a record for this function.
Expand Down
3 changes: 1 addition & 2 deletions lib/SIL/SILCoverageMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ SILCoverageMap::create(SILModule &M, StringRef Filename, StringRef Name,
return CM;
}

SILCoverageMap::SILCoverageMap(uint64_t Hash)
: Hash(Hash), HasSymtabEntry(false) {}
SILCoverageMap::SILCoverageMap(uint64_t Hash) : Hash(Hash) {}

SILCoverageMap::~SILCoverageMap() {}

Expand Down
3 changes: 3 additions & 0 deletions lib/SIL/SILProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,9 @@ void SILProfiler::assignRegionCounters() {
CurrentFuncName, getEquivalentPGOLinkage(CurrentFuncLinkage),
CurrentFileName);

assert((!CurrentFuncName.empty() && !PGOFuncName.empty()) &&
"Expected covered region to be named");

LLVM_DEBUG(llvm::dbgs() << "Assigning counters to: " << CurrentFuncName
<< "\n");
Root.walk(Mapper);
Expand Down
5 changes: 5 additions & 0 deletions test/Profiler/coverage_dead_code_elim.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: %target-swift-frontend %s -profile-generate -profile-coverage-mapping -O -whole-module-optimization -emit-ir -o - | %FileCheck %s

// CHECK-NOT: llvm_coverage_mapping = internal constant

func foo() {}