Skip to content

Commit ab3430f

Browse files
authored
[Profile] Add binary profile correlation for code coverage. (#69493)
## Motivation Since we don't need the metadata sections at runtime, we can somehow offload them from memory at runtime. Initially, I explored [debug info correlation](https://discourse.llvm.org/t/instrprofiling-lightweight-instrumentation/59113), which is used for PGO with value profiling disabled. However, it currently only works with DWARF and it's be hard to add such artificial debug info for every function in to CodeView which is used on Windows. So, offloading profile metadata sections at runtime seems to be a platform independent option. ## Design The idea is to use new section names for profile name and data sections and mark them as metadata sections. Under this mode, the new sections are non-SHF_ALLOC in ELF. So, they are not loaded into memory at runtime and can be stripped away as a post-linking step. After the process exits, the generated raw profiles will contains only headers + counters. llvm-profdata can be used correlate raw profiles with the unstripped binary to generate indexed profile. ## Data For chromium base_unittests with code coverage on linux, the binary size overhead due to instrumentation reduced from 64M to 38.8M (39.4%) and the raw profile files size reduce from 128M to 68M (46.9%) ``` $ bloaty out/cov/base_unittests.stripped -- out/no-cov/base_unittests.stripped FILE SIZE VM SIZE -------------- -------------- +121% +30.4Mi +121% +30.4Mi .text [NEW] +14.6Mi [NEW] +14.6Mi __llvm_prf_data [NEW] +10.6Mi [NEW] +10.6Mi __llvm_prf_names [NEW] +5.86Mi [NEW] +5.86Mi __llvm_prf_cnts +95% +1.75Mi +95% +1.75Mi .eh_frame +108% +400Ki +108% +400Ki .eh_frame_hdr +9.5% +211Ki +9.5% +211Ki .rela.dyn +9.2% +95.0Ki +9.2% +95.0Ki .data.rel.ro +5.0% +87.3Ki +5.0% +87.3Ki .rodata [ = ] 0 +13% +47.0Ki .bss +40% +1.78Ki +40% +1.78Ki .got +12% +1.49Ki +12% +1.49Ki .gcc_except_table [ = ] 0 +65% +1.23Ki .relro_padding +62% +1.20Ki [ = ] 0 [Unmapped] +13% +448 +19% +448 .init_array +8.8% +192 [ = ] 0 [ELF Section Headers] +0.0% +136 +0.0% +80 [7 Others] +0.1% +96 +0.1% +96 .dynsym +1.2% +96 +1.2% +96 .rela.plt +1.5% +80 +1.2% +64 .plt [ = ] 0 -99.2% -3.68Ki [LOAD #5 [RW]] +195% +64.0Mi +194% +64.0Mi TOTAL $ bloaty out/cov-cor/base_unittests.stripped -- out/no-cov/base_unittests.stripped FILE SIZE VM SIZE -------------- -------------- +121% +30.4Mi +121% +30.4Mi .text [NEW] +5.86Mi [NEW] +5.86Mi __llvm_prf_cnts +95% +1.75Mi +95% +1.75Mi .eh_frame +108% +400Ki +108% +400Ki .eh_frame_hdr +9.5% +211Ki +9.5% +211Ki .rela.dyn +9.2% +95.0Ki +9.2% +95.0Ki .data.rel.ro +5.0% +87.3Ki +5.0% +87.3Ki .rodata [ = ] 0 +13% +47.0Ki .bss +40% +1.78Ki +40% +1.78Ki .got +12% +1.49Ki +12% +1.49Ki .gcc_except_table +13% +448 +19% +448 .init_array +0.1% +96 +0.1% +96 .dynsym +1.2% +96 +1.2% +96 .rela.plt +1.2% +64 +1.2% +64 .plt +2.9% +64 [ = ] 0 [ELF Section Headers] +0.0% +40 +0.0% +40 .data +1.2% +32 +1.2% +32 .got.plt +0.0% +24 +0.0% +8 [5 Others] [ = ] 0 -22.9% -872 [LOAD #5 [RW]] -74.5% -1.44Ki [ = ] 0 [Unmapped] [ = ] 0 -76.5% -1.45Ki .relro_padding +118% +38.8Mi +117% +38.8Mi TOTAL ``` A few things to note: 1. llvm-profdata doesn't support filter raw profiles by binary id yet, so when a raw profile doesn't belongs to the binary being digested by llvm-profdata, merging will fail. Once this is implemented, llvm-profdata should be able to only merge raw profiles with the same binary id as the binary and discard the rest (with mismatched/missing binary id). The workflow I have in mind is to have scripts invoke llvm-profdata to get all binary ids for all raw profiles, and selectively choose the raw pnrofiles with matching binary id and the binary to llvm-profdata for merging. 2. Note: In COFF, currently they are still loaded into memory but not used. I didn't do it in this patch because I noticed that `.lcovmap` and `.lcovfunc` are loaded into memory. A separate patch will address it. 3. This should works with PGO when value profiling is disabled as debug info correlation currently doing, though I haven't tested this yet.
1 parent 7e15fa9 commit ab3430f

File tree

19 files changed

+385
-113
lines changed

19 files changed

+385
-113
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "llvm/Passes/PassBuilder.h"
4646
#include "llvm/Passes/PassPlugin.h"
4747
#include "llvm/Passes/StandardInstrumentations.h"
48+
#include "llvm/ProfileData/InstrProfCorrelator.h"
4849
#include "llvm/Support/BuryPointer.h"
4950
#include "llvm/Support/CommandLine.h"
5051
#include "llvm/Support/MemoryBuffer.h"
@@ -102,17 +103,21 @@ static cl::opt<bool> ClSanitizeOnOptimizerEarlyEP(
102103
"sanitizer-early-opt-ep", cl::Optional,
103104
cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
104105

106+
extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate;
107+
105108
// Re-link builtin bitcodes after optimization
106109
cl::opt<bool> ClRelinkBuiltinBitcodePostop(
107110
"relink-builtin-bitcode-postop", cl::Optional,
108111
cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false));
109-
}
112+
} // namespace llvm
110113

111114
namespace {
112115

113116
// Default filename used for profile generation.
114117
std::string getDefaultProfileGenName() {
115-
return DebugInfoCorrelate ? "default_%m.proflite" : "default_%m.profraw";
118+
return DebugInfoCorrelate || ProfileCorrelate != InstrProfCorrelator::NONE
119+
? "default_%m.proflite"
120+
: "default_%m.profraw";
116121
}
117122

118123
class EmitAssemblyHelper {
@@ -204,7 +209,7 @@ class EmitAssemblyHelper {
204209
void EmitAssembly(BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS,
205210
BackendConsumer *BC);
206211
};
207-
}
212+
} // namespace
208213

209214
static SanitizerCoverageOptions
210215
getSancovOptsFromCGOpts(const CodeGenOptions &CGOpts) {

compiler-rt/include/profile/InstrProfData.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ INSTR_PROF_SECT_ENTRY(IPSK_covfun, \
295295
INSTR_PROF_SECT_ENTRY(IPSK_orderfile, \
296296
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COMMON), \
297297
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COFF), "__DATA,")
298+
INSTR_PROF_SECT_ENTRY(IPSK_covdata, \
299+
INSTR_PROF_QUOTE(INSTR_PROF_COVDATA_COMMON), \
300+
INSTR_PROF_COVDATA_COFF, "__LLVM_COV,")
301+
INSTR_PROF_SECT_ENTRY(IPSK_covname, \
302+
INSTR_PROF_QUOTE(INSTR_PROF_COVNAME_COMMON), \
303+
INSTR_PROF_COVNAME_COFF, "__LLVM_COV,")
298304

299305
#undef INSTR_PROF_SECT_ENTRY
300306
#endif
@@ -701,6 +707,8 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
701707
#define INSTR_PROF_VNODES_COMMON __llvm_prf_vnds
702708
#define INSTR_PROF_COVMAP_COMMON __llvm_covmap
703709
#define INSTR_PROF_COVFUN_COMMON __llvm_covfun
710+
#define INSTR_PROF_COVDATA_COMMON __llvm_covdata
711+
#define INSTR_PROF_COVNAME_COMMON __llvm_covnames
704712
#define INSTR_PROF_ORDERFILE_COMMON __llvm_orderfile
705713
/* Windows section names. Because these section names contain dollar characters,
706714
* they must be quoted.
@@ -713,6 +721,11 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
713721
#define INSTR_PROF_VNODES_COFF ".lprfnd$M"
714722
#define INSTR_PROF_COVMAP_COFF ".lcovmap$M"
715723
#define INSTR_PROF_COVFUN_COFF ".lcovfun$M"
724+
/* Since cov data and cov names sections are not allocated, we don't need to
725+
* access them at runtime.
726+
*/
727+
#define INSTR_PROF_COVDATA_COFF ".lcovd"
728+
#define INSTR_PROF_COVNAME_COFF ".lcovn"
716729
#define INSTR_PROF_ORDERFILE_COFF ".lorderfile$M"
717730

718731
#ifdef _WIN32
@@ -729,6 +742,8 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
729742
#define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_VNODES_COFF
730743
#define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_COVMAP_COFF
731744
#define INSTR_PROF_COVFUN_SECT_NAME INSTR_PROF_COVFUN_COFF
745+
#define INSTR_PROF_COVDATA_SECT_NAME INSTR_PROF_COVDATA_COFF
746+
#define INSTR_PROF_COVNAME_SECT_NAME INSTR_PROF_COVNAME_COFF
732747
#define INSTR_PROF_ORDERFILE_SECT_NAME INSTR_PROF_ORDERFILE_COFF
733748
#else
734749
/* Runtime section names and name strings. */
@@ -744,6 +759,8 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
744759
#define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COMMON)
745760
#define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COMMON)
746761
#define INSTR_PROF_COVFUN_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVFUN_COMMON)
762+
#define INSTR_PROF_COVDATA_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVDATA_COMMON)
763+
#define INSTR_PROF_COVNAME_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVNAME_COMMON)
747764
/* Order file instrumentation. */
748765
#define INSTR_PROF_ORDERFILE_SECT_NAME \
749766
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COMMON)

compiler-rt/lib/profile/InstrProfilingPlatformWindows.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313

1414
#if defined(_MSC_VER)
1515
/* Merge read-write sections into .data. */
16-
#pragma comment(linker, "/MERGE:.lprfc=.data")
1716
#pragma comment(linker, "/MERGE:.lprfb=.data")
1817
#pragma comment(linker, "/MERGE:.lprfd=.data")
1918
#pragma comment(linker, "/MERGE:.lprfv=.data")
2019
#pragma comment(linker, "/MERGE:.lprfnd=.data")
2120
/* Do *NOT* merge .lprfn and .lcovmap into .rdata. llvm-cov must be able to find
2221
* after the fact.
22+
* Do *NOT* merge .lprfc .rdata. When binary profile correlation is enabled,
23+
* llvm-cov must be able to find after the fact.
2324
*/
2425

2526
/* Allocate read-only section bounds. */

compiler-rt/test/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ if(NOT ANDROID)
3737
if(NOT COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD)
3838
# Use LLVM utils and Clang from the same build tree.
3939
list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS
40-
clang clang-resource-headers FileCheck count not llvm-config llvm-nm llvm-objdump
41-
llvm-readelf llvm-readobj llvm-size llvm-symbolizer compiler-rt-headers sancov split-file)
40+
clang clang-resource-headers FileCheck count not llvm-config llvm-nm
41+
llvm-objdump llvm-readelf llvm-readobj llvm-size llvm-symbolizer
42+
compiler-rt-headers sancov split-file llvm-strip)
4243
if (WIN32)
4344
list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS KillTheDoctor)
4445
endif()
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// REQUIRES: linux || windows
2+
// Default
3+
// RUN: %clang -o %t.normal -fprofile-instr-generate -fcoverage-mapping %S/Inputs/instrprof-debug-info-correlate-main.cpp %S/Inputs/instrprof-debug-info-correlate-foo.cpp
4+
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.normal
5+
// RUN: llvm-profdata merge -o %t.normal.profdata %t.profraw
6+
// RUN: llvm-cov report --instr-profile=%t.normal.profdata %t.normal > %t.normal.report
7+
// RUN: llvm-cov show --instr-profile=%t.normal.profdata %t.normal > %t.normal.show
8+
9+
// With -profile-correlate=binary flag
10+
// RUN: %clang -o %t-1.exe -fprofile-instr-generate -fcoverage-mapping -mllvm -profile-correlate=binary %S/Inputs/instrprof-debug-info-correlate-main.cpp %S/Inputs/instrprof-debug-info-correlate-foo.cpp
11+
// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t-1.exe
12+
// RUN: llvm-profdata merge -o %t-1.profdata --binary-file=%t-1.exe %t-1.profraw
13+
// RUN: llvm-cov report --instr-profile=%t-1.profdata %t-1.exe > %t-1.report
14+
// RUN: llvm-cov show --instr-profile=%t-1.profdata %t-1.exe > %t-1.show
15+
// RUN: diff %t.normal.profdata %t-1.profdata
16+
// RUN: diff %t.normal.report %t-1.report
17+
// RUN: diff %t.normal.show %t-1.show
18+
19+
// Strip above binary and run
20+
// RUN: llvm-strip %t-1.exe -o %t-2.exe
21+
// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t-2.exe
22+
// RUN: llvm-profdata merge -o %t-2.profdata --binary-file=%t-1.exe %t-2.profraw
23+
// RUN: llvm-cov report --instr-profile=%t-2.profdata %t-1.exe > %t-2.report
24+
// RUN: llvm-cov show --instr-profile=%t-2.profdata %t-1.exe > %t-2.show
25+
// RUN: diff %t.normal.profdata %t-2.profdata
26+
// RUN: diff %t.normal.report %t-2.report
27+
// RUN: diff %t.normal.show %t-2.show
28+
29+
// Online merging.
30+
// RUN: env LLVM_PROFILE_FILE=%t-3.profraw %run %t.normal
31+
// RUN: env LLVM_PROFILE_FILE=%t-4.profraw %run %t.normal
32+
// RUN: llvm-profdata merge -o %t.normal.merged.profdata %t-3.profraw %t-4.profraw
33+
// RUN: llvm-cov report --instr-profile=%t.normal.merged.profdata %t.normal > %t.normal.merged.report
34+
// RUN: llvm-cov show --instr-profile=%t.normal.merged.profdata %t.normal > %t.normal.merged.show
35+
36+
// RUN: rm -rf %t.profdir && mkdir %t.profdir
37+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m-4.profraw %run %t-2.exe
38+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m-4.profraw %run %t-2.exe
39+
// RUN: llvm-profdata merge -o %t-4.profdata --binary-file=%t-1.exe %t.profdir
40+
// RUN: llvm-cov report --instr-profile=%t-4.profdata %t-1.exe > %t-4.report
41+
// RUN: llvm-cov show --instr-profile=%t-4.profdata %t-1.exe > %t-4.show
42+
// RUN: diff %t.normal.merged.profdata %t-4.profdata
43+
// RUN: diff %t.normal.merged.report %t-4.report
44+
// RUN: diff %t.normal.merged.show %t-4.show
45+
46+
// TODO: After adding support for binary ID, test binaries with different binary IDs.

llvm/docs/CommandGuide/llvm-profdata.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,14 @@ OPTIONS
195195
.. option:: --debug-info=<path>
196196

197197
Specify the executable or ``.dSYM`` that contains debug info for the raw profile.
198-
When ``-debug-info-correlate`` was used for instrumentation, use this option
199-
to correlate the raw profile.
198+
When ``--debug-info-correlate`` or ``--profile-correlate=debug-info`` was used
199+
for instrumentation, use this option to correlate the raw profile.
200+
201+
.. option:: --binary-file=<path>
202+
203+
Specify the executable that contains profile data and profile name sections for
204+
the raw profile. When ``-profile-correlate=binary`` was used for
205+
instrumentation, use this option to correlate the raw profile.
200206

201207
.. option:: --temporal-profile-trace-reservoir-size
202208

@@ -346,8 +352,9 @@ OPTIONS
346352
.. option:: --debug-info=<path>
347353

348354
Specify the executable or ``.dSYM`` that contains debug info for the raw profile.
349-
When ``-debug-info-correlate`` was used for instrumentation, use this option
350-
to show the correlated functions from the raw profile.
355+
When ``--debug-info-correlate`` or ``--profile-correlate=debug-info`` was used
356+
for instrumentation, use this option to show the correlated functions from the
357+
raw profile.
351358

352359
.. option:: --covered
353360

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ enum class instrprof_error {
328328
too_large,
329329
truncated,
330330
malformed,
331-
missing_debug_info_for_correlation,
332-
unexpected_debug_info_for_correlation,
331+
missing_correlation_info,
332+
unexpected_correlation_info,
333333
unable_to_correlate_profile,
334334
unknown_function,
335335
invalid_prof,

llvm/include/llvm/ProfileData/InstrProfCorrelator.h

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8-
// This file defines InstrProfCorrelator used to generate PGO profiles from
9-
// raw profile data and debug info.
8+
// This file defines InstrProfCorrelator used to generate PGO/coverage profiles
9+
// from raw profile data and debug info/binary file.
1010
//===----------------------------------------------------------------------===//
1111

1212
#ifndef LLVM_PROFILEDATA_INSTRPROFCORRELATOR_H
@@ -31,8 +31,9 @@ class ObjectFile;
3131
/// to their functions.
3232
class InstrProfCorrelator {
3333
public:
34-
/// Indicate which kind correlator to use.
35-
enum ProfCorrelatorKind { NONE, DEBUG_INFO };
34+
/// Indicate if we should use the debug info or profile metadata sections to
35+
/// correlate.
36+
enum ProfCorrelatorKind { NONE, DEBUG_INFO, BINARY };
3637

3738
static llvm::Expected<std::unique_ptr<InstrProfCorrelator>>
3839
get(StringRef Filename, ProfCorrelatorKind FileKind);
@@ -71,11 +72,18 @@ class InstrProfCorrelator {
7172
protected:
7273
struct Context {
7374
static llvm::Expected<std::unique_ptr<Context>>
74-
get(std::unique_ptr<MemoryBuffer> Buffer, const object::ObjectFile &Obj);
75+
get(std::unique_ptr<MemoryBuffer> Buffer, const object::ObjectFile &Obj,
76+
ProfCorrelatorKind FileKind);
7577
std::unique_ptr<MemoryBuffer> Buffer;
7678
/// The address range of the __llvm_prf_cnts section.
7779
uint64_t CountersSectionStart;
7880
uint64_t CountersSectionEnd;
81+
/// The pointer points to start/end of profile data/name sections if
82+
/// FileKind is Binary.
83+
const char *DataStart;
84+
const char *DataEnd;
85+
const char *NameStart;
86+
size_t NameSize;
7987
/// True if target and host have different endian orders.
8088
bool ShouldSwapBytes;
8189
};
@@ -145,19 +153,20 @@ class InstrProfCorrelatorImpl : public InstrProfCorrelator {
145153

146154
Error dumpYaml(int MaxWarnings, raw_ostream &OS) override;
147155

148-
void addProbe(StringRef FunctionName, uint64_t CFGHash, IntPtrT CounterOffset,
149-
IntPtrT FunctionPtr, uint32_t NumCounters);
156+
void addDataProbe(uint64_t FunctionName, uint64_t CFGHash,
157+
IntPtrT CounterOffset, IntPtrT FunctionPtr,
158+
uint32_t NumCounters);
159+
160+
// Byte-swap the value if necessary.
161+
template <class T> T maybeSwap(T Value) const {
162+
return Ctx->ShouldSwapBytes ? llvm::byteswap(Value) : Value;
163+
}
150164

151165
private:
152166
InstrProfCorrelatorImpl(InstrProfCorrelatorKind Kind,
153167
std::unique_ptr<InstrProfCorrelator::Context> Ctx)
154168
: InstrProfCorrelator(Kind, std::move(Ctx)){};
155169
llvm::DenseSet<IntPtrT> CounterOffsets;
156-
157-
// Byte-swap the value if necessary.
158-
template <class T> T maybeSwap(T Value) const {
159-
return Ctx->ShouldSwapBytes ? llvm::byteswap(Value) : Value;
160-
}
161170
};
162171

163172
/// DwarfInstrProfCorrelator - A child of InstrProfCorrelatorImpl that takes
@@ -214,6 +223,28 @@ class DwarfInstrProfCorrelator : public InstrProfCorrelatorImpl<IntPtrT> {
214223
Error correlateProfileNameImpl() override;
215224
};
216225

226+
/// BinaryInstrProfCorrelator - A child of InstrProfCorrelatorImpl that
227+
/// takes an object file as input to correlate profiles.
228+
template <class IntPtrT>
229+
class BinaryInstrProfCorrelator : public InstrProfCorrelatorImpl<IntPtrT> {
230+
public:
231+
BinaryInstrProfCorrelator(std::unique_ptr<InstrProfCorrelator::Context> Ctx)
232+
: InstrProfCorrelatorImpl<IntPtrT>(std::move(Ctx)) {}
233+
234+
/// Return a pointer to the names string that this class constructs.
235+
const char *getNamesPointer() const { return this->Ctx.NameStart; }
236+
237+
/// Return the number of bytes in the names string.
238+
size_t getNamesSize() const { return this->Ctx.NameSize; }
239+
240+
private:
241+
void correlateProfileDataImpl(
242+
int MaxWarnings,
243+
InstrProfCorrelator::CorrelationData *Data = nullptr) override;
244+
245+
Error correlateProfileNameImpl() override;
246+
};
247+
217248
} // end namespace llvm
218249

219250
#endif // LLVM_PROFILEDATA_INSTRPROFCORRELATOR_H

llvm/include/llvm/ProfileData/InstrProfData.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ INSTR_PROF_SECT_ENTRY(IPSK_covfun, \
295295
INSTR_PROF_SECT_ENTRY(IPSK_orderfile, \
296296
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COMMON), \
297297
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COFF), "__DATA,")
298+
INSTR_PROF_SECT_ENTRY(IPSK_covdata, \
299+
INSTR_PROF_QUOTE(INSTR_PROF_COVDATA_COMMON), \
300+
INSTR_PROF_COVDATA_COFF, "__LLVM_COV,")
301+
INSTR_PROF_SECT_ENTRY(IPSK_covname, \
302+
INSTR_PROF_QUOTE(INSTR_PROF_COVNAME_COMMON), \
303+
INSTR_PROF_COVNAME_COFF, "__LLVM_COV,")
298304

299305
#undef INSTR_PROF_SECT_ENTRY
300306
#endif
@@ -701,6 +707,8 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
701707
#define INSTR_PROF_VNODES_COMMON __llvm_prf_vnds
702708
#define INSTR_PROF_COVMAP_COMMON __llvm_covmap
703709
#define INSTR_PROF_COVFUN_COMMON __llvm_covfun
710+
#define INSTR_PROF_COVDATA_COMMON __llvm_covdata
711+
#define INSTR_PROF_COVNAME_COMMON __llvm_covnames
704712
#define INSTR_PROF_ORDERFILE_COMMON __llvm_orderfile
705713
/* Windows section names. Because these section names contain dollar characters,
706714
* they must be quoted.
@@ -713,6 +721,11 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
713721
#define INSTR_PROF_VNODES_COFF ".lprfnd$M"
714722
#define INSTR_PROF_COVMAP_COFF ".lcovmap$M"
715723
#define INSTR_PROF_COVFUN_COFF ".lcovfun$M"
724+
/* Since cov data and cov names sections are not allocated, we don't need to
725+
* access them at runtime.
726+
*/
727+
#define INSTR_PROF_COVDATA_COFF ".lcovd"
728+
#define INSTR_PROF_COVNAME_COFF ".lcovn"
716729
#define INSTR_PROF_ORDERFILE_COFF ".lorderfile$M"
717730

718731
#ifdef _WIN32
@@ -729,6 +742,8 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
729742
#define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_VNODES_COFF
730743
#define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_COVMAP_COFF
731744
#define INSTR_PROF_COVFUN_SECT_NAME INSTR_PROF_COVFUN_COFF
745+
#define INSTR_PROF_COVDATA_SECT_NAME INSTR_PROF_COVDATA_COFF
746+
#define INSTR_PROF_COVNAME_SECT_NAME INSTR_PROF_COVNAME_COFF
732747
#define INSTR_PROF_ORDERFILE_SECT_NAME INSTR_PROF_ORDERFILE_COFF
733748
#else
734749
/* Runtime section names and name strings. */
@@ -744,6 +759,8 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
744759
#define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COMMON)
745760
#define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COMMON)
746761
#define INSTR_PROF_COVFUN_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVFUN_COMMON)
762+
#define INSTR_PROF_COVDATA_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVDATA_COMMON)
763+
#define INSTR_PROF_COVNAME_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVNAME_COMMON)
747764
/* Order file instrumentation. */
748765
#define INSTR_PROF_ORDERFILE_SECT_NAME \
749766
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COMMON)

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ class InstrProfReader {
123123

124124
virtual bool instrEntryBBEnabled() const = 0;
125125

126-
/// Return true if we must provide debug info to create PGO profiles.
127-
virtual bool useDebugInfoCorrelate() const { return false; }
128-
129126
/// Return true if the profile has single byte counters representing coverage.
130127
virtual bool hasSingleByteCoverage() const = 0;
131128

@@ -378,12 +375,6 @@ class RawInstrProfReader : public InstrProfReader {
378375
return (Version & VARIANT_MASK_INSTR_ENTRY) != 0;
379376
}
380377

381-
bool useDebugInfoCorrelate() const override {
382-
return (Version & VARIANT_MASK_DBG_CORRELATE) != 0;
383-
}
384-
385-
bool useCorrelate() const { return useDebugInfoCorrelate(); }
386-
387378
bool hasSingleByteCoverage() const override {
388379
return (Version & VARIANT_MASK_BYTE_COVERAGE) != 0;
389380
}

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) {
472472
/*AddSegmentInfo=*/false) ||
473473
Name == getInstrProfSectionName(IPSK_covfun, Triple::ELF,
474474
/*AddSegmentInfo=*/false) ||
475+
Name == getInstrProfSectionName(IPSK_covdata, Triple::ELF,
476+
/*AddSegmentInfo=*/false) ||
477+
Name == getInstrProfSectionName(IPSK_covname, Triple::ELF,
478+
/*AddSegmentInfo=*/false) ||
475479
Name == ".llvmbc" || Name == ".llvmcmd")
476480
return SectionKind::getMetadata();
477481

0 commit comments

Comments
 (0)