Skip to content

Commit 01e527d

Browse files
authored
Merge pull request #26817 from vedantk/r42564768
2 parents 3fe9333 + 9606717 commit 01e527d

File tree

6 files changed

+21
-25
lines changed

6 files changed

+21
-25
lines changed

include/swift/SIL/SILCoverageMap.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ class SILCoverageMap : public llvm::ilist_node<SILCoverageMap>,
7373
// Tail-allocated expression list.
7474
MutableArrayRef<llvm::coverage::CounterExpression> Expressions;
7575

76-
// Whether the coverage mapping's name data is in the profile symbol table.
77-
bool HasSymtabEntry;
78-
7976
// Disallow copying into temporary objects.
8077
SILCoverageMap(const SILCoverageMap &other) = delete;
8178
SILCoverageMap &operator=(const SILCoverageMap &) = delete;
@@ -112,14 +109,6 @@ class SILCoverageMap : public llvm::ilist_node<SILCoverageMap>,
112109
return Expressions;
113110
}
114111

115-
/// Check whether this coverage mapping can reference its name data within
116-
/// the profile symbol table.
117-
bool hasSymtabEntry() const { return HasSymtabEntry; }
118-
119-
/// Guarantee that this coverage mapping can reference its name data within
120-
/// the profile symbol table.
121-
void setSymtabEntryGuaranteed() { HasSymtabEntry = true; }
122-
123112
void printCounter(llvm::raw_ostream &OS, llvm::coverage::Counter C) const;
124113

125114
/// Print the coverage map.

lib/IRGen/GenBuiltin.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,6 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
256256
replacement.add(NameGEP);
257257
replacement.add(args.claimAll());
258258
args = std::move(replacement);
259-
260-
if (Opts.EmitProfileCoverageMapping) {
261-
// Update the associated coverage mapping: it's now safe to emit, because
262-
// a symtab entry for this function is guaranteed (r://39146527).
263-
auto &coverageMaps = SILMod.getCoverageMaps();
264-
auto CovMapIt = coverageMaps.find(PGOFuncName);
265-
if (CovMapIt != coverageMaps.end())
266-
CovMapIt->second->setSymtabEntryGuaranteed();
267-
}
268259
}
269260

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

lib/IRGen/GenCoverage.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@ static std::string getCoverageSection(IRGenModule &IGM) {
3939

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

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

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

111120
// Create a record for this function.

lib/SIL/SILCoverageMap.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ SILCoverageMap::create(SILModule &M, StringRef Filename, StringRef Name,
5050
return CM;
5151
}
5252

53-
SILCoverageMap::SILCoverageMap(uint64_t Hash)
54-
: Hash(Hash), HasSymtabEntry(false) {}
53+
SILCoverageMap::SILCoverageMap(uint64_t Hash) : Hash(Hash) {}
5554

5655
SILCoverageMap::~SILCoverageMap() {}
5756

lib/SIL/SILProfiler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,9 @@ void SILProfiler::assignRegionCounters() {
10791079
CurrentFuncName, getEquivalentPGOLinkage(CurrentFuncLinkage),
10801080
CurrentFileName);
10811081

1082+
assert((!CurrentFuncName.empty() && !PGOFuncName.empty()) &&
1083+
"Expected covered region to be named");
1084+
10821085
LLVM_DEBUG(llvm::dbgs() << "Assigning counters to: " << CurrentFuncName
10831086
<< "\n");
10841087
Root.walk(Mapper);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-swift-frontend %s -profile-generate -profile-coverage-mapping -O -whole-module-optimization -emit-ir -o - | %FileCheck %s
2+
3+
// CHECK-NOT: llvm_coverage_mapping = internal constant
4+
5+
func foo() {}

0 commit comments

Comments
 (0)