[llvm] db7a1ed - Revert "[Profile] Refactor profile correlation. (#70712)"
Zequan Wu via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 31 07:54:13 PDT 2023
Author: Zequan Wu
Date: 2023-10-31T10:53:45-04:00
New Revision: db7a1ed9a22fadacfa651e88d0f75f365d44af9a
URL: https://github.com/llvm/llvm-project/commit/db7a1ed9a22fadacfa651e88d0f75f365d44af9a
DIFF: https://github.com/llvm/llvm-project/commit/db7a1ed9a22fadacfa651e88d0f75f365d44af9a.diff
LOG: Revert "[Profile] Refactor profile correlation. (#70712)"
This reverts commit 4b383d0af93136b80841fc140da0823dfc441dd4.
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
compiler-rt/lib/profile/InstrProfiling.c
compiler-rt/lib/profile/InstrProfiling.h
compiler-rt/lib/profile/InstrProfilingBuffer.c
compiler-rt/lib/profile/InstrProfilingMerge.c
compiler-rt/lib/profile/InstrProfilingWriter.c
compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
compiler-rt/test/profile/Linux/instrprof-debug-info-correlate-warnings.c
compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c
llvm/docs/CommandGuide/llvm-profdata.rst
llvm/include/llvm/ProfileData/InstrProfCorrelator.h
llvm/include/llvm/ProfileData/InstrProfReader.h
llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/ProfileData/InstrProfCorrelator.cpp
llvm/lib/ProfileData/InstrProfReader.cpp
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll
llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll
llvm/tools/llvm-profdata/llvm-profdata.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 83b81a38a768523..70accce456d3c07 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -42,7 +42,6 @@
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Passes/StandardInstrumentations.h"
-#include "llvm/ProfileData/InstrProfCorrelator.h"
#include "llvm/Support/BuryPointer.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -56,7 +55,6 @@
#include "llvm/Target/TargetOptions.h"
#include "llvm/TargetParser/SubtargetFeature.h"
#include "llvm/TargetParser/Triple.h"
-#include "llvm/Transforms/HipStdPar/HipStdPar.h"
#include "llvm/Transforms/IPO/EmbedBitcodePass.h"
#include "llvm/Transforms/IPO/LowerTypeTests.h"
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
@@ -80,6 +78,7 @@
#include "llvm/Transforms/Scalar/EarlyCSE.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "llvm/Transforms/Scalar/JumpThreading.h"
+#include "llvm/Transforms/HipStdPar/HipStdPar.h"
#include "llvm/Transforms/Utils/Debugify.h"
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -99,18 +98,13 @@ extern cl::opt<bool> PrintPipelinePasses;
static cl::opt<bool> ClSanitizeOnOptimizerEarlyEP(
"sanitizer-early-opt-ep", cl::Optional,
cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
-
-extern cl::opt<bool> DebugInfoCorrelate;
-extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate;
-} // namespace llvm
+}
namespace {
// Default filename used for profile generation.
std::string getDefaultProfileGenName() {
- return DebugInfoCorrelate || ProfileCorrelate != InstrProfCorrelator::NONE
- ? "default_%m.proflite"
- : "default_%m.profraw";
+ return DebugInfoCorrelate ? "default_%m.proflite" : "default_%m.profraw";
}
class EmitAssemblyHelper {
@@ -203,7 +197,7 @@ class EmitAssemblyHelper {
void EmitAssembly(BackendAction Action,
std::unique_ptr<raw_pwrite_stream> OS);
};
-} // namespace
+}
static SanitizerCoverageOptions
getSancovOptsFromCGOpts(const CodeGenOptions &CGOpts) {
diff --git a/compiler-rt/lib/profile/InstrProfiling.c b/compiler-rt/lib/profile/InstrProfiling.c
index 7d69e37815c948f..da04d8ebdec95bb 100644
--- a/compiler-rt/lib/profile/InstrProfiling.c
+++ b/compiler-rt/lib/profile/InstrProfiling.c
@@ -89,7 +89,3 @@ COMPILER_RT_VISIBILITY void __llvm_profile_reset_counters(void) {
}
lprofSetProfileDumped(0);
}
-
-inline int hasCorrelation() {
- return (__llvm_profile_get_version() & VARIANT_MASK_DBG_CORRELATE) != 0ULL;
-}
diff --git a/compiler-rt/lib/profile/InstrProfiling.h b/compiler-rt/lib/profile/InstrProfiling.h
index b8104af5f12b910..e143149fca82707 100644
--- a/compiler-rt/lib/profile/InstrProfiling.h
+++ b/compiler-rt/lib/profile/InstrProfiling.h
@@ -261,9 +261,6 @@ uint64_t __llvm_profile_get_magic(void);
/*! \brief Get the version of the file format. */
uint64_t __llvm_profile_get_version(void);
-/*! \brief If the binary is compiled with profile correlation. */
-int hasCorrelation();
-
/*! \brief Get the number of entries in the profile data section. */
uint64_t __llvm_profile_get_num_data(const __llvm_profile_data *Begin,
const __llvm_profile_data *End);
@@ -285,9 +282,6 @@ uint64_t __llvm_profile_get_counters_size(const char *Begin, const char *End);
uint64_t __llvm_profile_get_num_bitmap_bytes(const char *Begin,
const char *End);
-/*! \brief Get the size of the profile name section in bytes. */
-uint64_t __llvm_profile_get_name_size(const char *Begin, const char *End);
-
/* ! \brief Given the sizes of the data and counter information, return the
* number of padding bytes before and after the counters, and after the names,
* in the raw profile.
diff --git a/compiler-rt/lib/profile/InstrProfilingBuffer.c b/compiler-rt/lib/profile/InstrProfilingBuffer.c
index 69965142d978746..c7217b2dfef8a97 100644
--- a/compiler-rt/lib/profile/InstrProfilingBuffer.c
+++ b/compiler-rt/lib/profile/InstrProfilingBuffer.c
@@ -56,8 +56,6 @@ uint64_t __llvm_profile_get_size_for_buffer(void) {
COMPILER_RT_VISIBILITY
uint64_t __llvm_profile_get_num_data(const __llvm_profile_data *Begin,
const __llvm_profile_data *End) {
- if (hasCorrelation())
- return 0;
intptr_t BeginI = (intptr_t)Begin, EndI = (intptr_t)End;
return ((EndI + sizeof(__llvm_profile_data) - 1) - BeginI) /
sizeof(__llvm_profile_data);
@@ -66,8 +64,6 @@ uint64_t __llvm_profile_get_num_data(const __llvm_profile_data *Begin,
COMPILER_RT_VISIBILITY
uint64_t __llvm_profile_get_data_size(const __llvm_profile_data *Begin,
const __llvm_profile_data *End) {
- if (hasCorrelation())
- return 0;
return __llvm_profile_get_num_data(Begin, End) * sizeof(__llvm_profile_data);
}
@@ -96,13 +92,6 @@ uint64_t __llvm_profile_get_num_bitmap_bytes(const char *Begin,
return (End - Begin);
}
-COMPILER_RT_VISIBILITY
-uint64_t __llvm_profile_get_name_size(const char *Begin, const char *End) {
- if (hasCorrelation())
- return 0;
- return End - Begin;
-}
-
/// Calculate the number of padding bytes needed to add to \p Offset in order
/// for (\p Offset + Padding) to be page-aligned.
static uint64_t calculateBytesNeededToPageAlign(uint64_t Offset) {
diff --git a/compiler-rt/lib/profile/InstrProfilingMerge.c b/compiler-rt/lib/profile/InstrProfilingMerge.c
index b08973debda94f3..c5f168bf7517718 100644
--- a/compiler-rt/lib/profile/InstrProfilingMerge.c
+++ b/compiler-rt/lib/profile/InstrProfilingMerge.c
@@ -69,9 +69,8 @@ int __llvm_profile_check_compatibility(const char *ProfileData,
Header->NumBitmapBytes !=
__llvm_profile_get_num_bitmap_bytes(__llvm_profile_begin_bitmap(),
__llvm_profile_end_bitmap()) ||
- Header->NamesSize !=
- __llvm_profile_get_name_size(__llvm_profile_begin_names(),
- __llvm_profile_end_names()) ||
+ Header->NamesSize != (uint64_t)(__llvm_profile_end_names() -
+ __llvm_profile_begin_names()) ||
Header->ValueKindLast != IPVK_Last)
return 1;
@@ -139,9 +138,9 @@ int __llvm_profile_merge_from_buffer(const char *ProfileData,
if (SrcNameStart < SrcCountersStart || SrcNameStart < SrcBitmapStart)
return 1;
- // Merge counters by iterating the entire counter section when correlation is
- // enabled.
- if (hasCorrelation()) {
+ // Merge counters by iterating the entire counter section when debug info
+ // correlation is enabled.
+ if (__llvm_profile_get_version() & VARIANT_MASK_DBG_CORRELATE) {
for (SrcCounter = SrcCountersStart,
DstCounter = __llvm_profile_begin_counters();
SrcCounter < SrcCountersEnd;) {
diff --git a/compiler-rt/lib/profile/InstrProfilingWriter.c b/compiler-rt/lib/profile/InstrProfilingWriter.c
index d35ee6b20504f3e..3b61f3def9f6ef0 100644
--- a/compiler-rt/lib/profile/InstrProfilingWriter.c
+++ b/compiler-rt/lib/profile/InstrProfilingWriter.c
@@ -262,19 +262,21 @@ lprofWriteDataImpl(ProfDataWriter *Writer, const __llvm_profile_data *DataBegin,
const char *BitmapBegin, const char *BitmapEnd,
VPDataReaderType *VPDataReader, const char *NamesBegin,
const char *NamesEnd, int SkipNameDataWrite) {
- int ProfileCorrelation = hasCorrelation();
+ int DebugInfoCorrelate =
+ (__llvm_profile_get_version() & VARIANT_MASK_DBG_CORRELATE) != 0ULL;
/* Calculate size of sections. */
const uint64_t DataSectionSize =
- __llvm_profile_get_data_size(DataBegin, DataEnd);
- const uint64_t NumData = __llvm_profile_get_num_data(DataBegin, DataEnd);
+ DebugInfoCorrelate ? 0 : __llvm_profile_get_data_size(DataBegin, DataEnd);
+ const uint64_t NumData =
+ DebugInfoCorrelate ? 0 : __llvm_profile_get_num_data(DataBegin, DataEnd);
const uint64_t CountersSectionSize =
__llvm_profile_get_counters_size(CountersBegin, CountersEnd);
const uint64_t NumCounters =
__llvm_profile_get_num_counters(CountersBegin, CountersEnd);
const uint64_t NumBitmapBytes =
__llvm_profile_get_num_bitmap_bytes(BitmapBegin, BitmapEnd);
- const uint64_t NamesSize = __llvm_profile_get_name_size(NamesBegin, NamesEnd);
+ const uint64_t NamesSize = DebugInfoCorrelate ? 0 : NamesEnd - NamesBegin;
/* Create the header. */
__llvm_profile_header Header;
@@ -302,7 +304,7 @@ lprofWriteDataImpl(ProfDataWriter *Writer, const __llvm_profile_data *DataBegin,
#endif
/* The data and names sections are omitted in lightweight mode. */
- if (ProfileCorrelation) {
+ if (DebugInfoCorrelate) {
Header.CountersDelta = 0;
Header.NamesDelta = 0;
}
@@ -318,22 +320,21 @@ lprofWriteDataImpl(ProfDataWriter *Writer, const __llvm_profile_data *DataBegin,
/* Write the profile data. */
ProfDataIOVec IOVecData[] = {
- {ProfileCorrelation ? NULL : DataBegin, sizeof(uint8_t), DataSectionSize,
+ {DebugInfoCorrelate ? NULL : DataBegin, sizeof(uint8_t), DataSectionSize,
0},
{NULL, sizeof(uint8_t), PaddingBytesBeforeCounters, 1},
{CountersBegin, sizeof(uint8_t), CountersSectionSize, 0},
{NULL, sizeof(uint8_t), PaddingBytesAfterCounters, 1},
{BitmapBegin, sizeof(uint8_t), NumBitmapBytes, 0},
{NULL, sizeof(uint8_t), PaddingBytesAfterBitmapBytes, 1},
- {(SkipNameDataWrite || ProfileCorrelation) ? NULL : NamesBegin,
+ {(SkipNameDataWrite || DebugInfoCorrelate) ? NULL : NamesBegin,
sizeof(uint8_t), NamesSize, 0},
{NULL, sizeof(uint8_t), PaddingBytesAfterNames, 1}};
if (Writer->Write(Writer, IOVecData, sizeof(IOVecData) / sizeof(*IOVecData)))
return -1;
- /* Value profiling is not yet supported in continuous mode and profile
- * correlation mode. */
- if (__llvm_profile_is_continuous_mode_enabled() || ProfileCorrelation)
+ /* Value profiling is not yet supported in continuous mode. */
+ if (__llvm_profile_is_continuous_mode_enabled())
return 0;
return writeValueProfData(Writer, VPDataReader, DataBegin, DataEnd);
diff --git a/compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c b/compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
index 46d25a4e386dc3a..f347d439e2e0671 100644
--- a/compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
+++ b/compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
@@ -1,5 +1,5 @@
// Value profiling is currently not supported in lightweight mode.
-// RUN: %clang_pgogen -o %t -g -mllvm --profile-correlate=debug-info -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
// RUN: env LLVM_PROFILE_FILE=%t.proflite %run %t
// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t.dSYM %t.proflite
@@ -9,7 +9,7 @@
// RUN:
diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) <(llvm-profdata show --all-functions --counts %t.profdata)
-// RUN: %clang_pgogen -o %t.cov -g -mllvm --profile-correlate=debug-info -mllvm -pgo-function-entry-coverage -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: %clang_pgogen -o %t.cov -g -mllvm --debug-info-correlate -mllvm -pgo-function-entry-coverage -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
// RUN: env LLVM_PROFILE_FILE=%t.cov.proflite %run %t.cov
// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov.dSYM %t.cov.proflite
diff --git a/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate-warnings.c b/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate-warnings.c
index 25022f241a6d281..5069c6340b64fd2 100644
--- a/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate-warnings.c
+++ b/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate-warnings.c
@@ -1,6 +1,6 @@
// Disable full debug info and verify that we get warnings during merging
-// RUN: %clang_pgogen -o %t -gline-tables-only -mllvm --profile-correlate=debug-info -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: %clang_pgogen -o %t -gline-tables-only -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
// RUN: env LLVM_PROFILE_FILE=%t.proflite %run %t
// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.proflite --max-debug-info-correlation-warnings=2 2>&1 >/dev/null | FileCheck %s --check-prefixes=CHECK,LIMIT --implicit-check-not=warning
// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.proflite --max-debug-info-correlation-warnings=0 2>&1 >/dev/null | FileCheck %s --check-prefixes=CHECK,NOLIMIT --implicit-check-not=warning
diff --git a/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c b/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
index ccfd65b6f4c4b16..a918d7b6299005e 100644
--- a/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
+++ b/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
@@ -3,19 +3,19 @@
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.normal
// RUN: llvm-profdata merge -o %t.normal.profdata %t.profraw
-// RUN: %clang_pgogen -o %t.d4 -g -gdwarf-4 -mllvm --profile-correlate=debug-info -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: %clang_pgogen -o %t.d4 -g -gdwarf-4 -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
// RUN: env LLVM_PROFILE_FILE=%t.d4.proflite %run %t.d4
// RUN: llvm-profdata merge -o %t.d4.profdata --debug-info=%t.d4 %t.d4.proflite
// RUN:
diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) <(llvm-profdata show --all-functions --counts %t.d4.profdata)
-// RUN: %clang_pgogen -o %t -g -mllvm --profile-correlate=debug-info -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
// RUN: env LLVM_PROFILE_FILE=%t.proflite %run %t
// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.proflite
// RUN:
diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) <(llvm-profdata show --all-functions --counts %t.profdata)
-// RUN: %clang_pgogen -o %t.cov -g -mllvm --profile-correlate=debug-info -mllvm -pgo-function-entry-coverage -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: %clang_pgogen -o %t.cov -g -mllvm --debug-info-correlate -mllvm -pgo-function-entry-coverage -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
// RUN: env LLVM_PROFILE_FILE=%t.cov.proflite %run %t.cov
// RUN: llvm-profdata merge -o %t.cov.profdata --debug-info=%t.cov %t.cov.proflite
diff --git a/compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c b/compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c
index 93bf40f98d3ab62..226d678aca347a4 100644
--- a/compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c
+++ b/compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c
@@ -1,10 +1,10 @@
-// RUN: %clang_pgogen -o %t -g -mllvm --profile-correlate=debug-info -mllvm --disable-vp=true %s
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %s
// RUN: llvm-profdata show --debug-info=%t --detailed-summary --show-prof-sym-list | FileCheck %s
// RUN: llvm-profdata show --debug-info=%t --show-format=yaml | FileCheck %s --match-full-lines --check-prefix YAML
-// RUN: %clang_pgogen -o %t.no.dbg -mllvm --profile-correlate=debug-info -mllvm --disable-vp=true %s
+// RUN: %clang_pgogen -o %t.no.dbg -mllvm --debug-info-correlate -mllvm --disable-vp=true %s
// RUN: not llvm-profdata show --debug-info=%t.no.dbg 2>&1 | FileCheck %s --check-prefix NO-DBG
-// NO-DBG: unable to correlate profile: could not find any profile data metadata in correlated file
+// NO-DBG: unable to correlate profile: could not find any profile metadata in debug info
// YAML: Probes:
// YAML: - Function Name: a
diff --git a/llvm/docs/CommandGuide/llvm-profdata.rst b/llvm/docs/CommandGuide/llvm-profdata.rst
index 73759f14b49a9d8..be42733ca140567 100644
--- a/llvm/docs/CommandGuide/llvm-profdata.rst
+++ b/llvm/docs/CommandGuide/llvm-profdata.rst
@@ -195,7 +195,7 @@ OPTIONS
.. option:: --debug-info=<path>
Specify the executable or ``.dSYM`` that contains debug info for the raw profile.
- When ``-profile-correlate=debug-info`` was used for instrumentation, use this option
+ When ``-debug-info-correlate`` was used for instrumentation, use this option
to correlate the raw profile.
.. option:: --temporal-profile-trace-reservoir-size
@@ -346,7 +346,7 @@ OPTIONS
.. option:: --debug-info=<path>
Specify the executable or ``.dSYM`` that contains debug info for the raw profile.
- When ``-profile-correlate=debug-info`` was used for instrumentation, use this option
+ When ``-debug-info-correlate`` was used for instrumentation, use this option
to show the correlated functions from the raw profile.
.. option:: --covered
diff --git a/llvm/include/llvm/ProfileData/InstrProfCorrelator.h b/llvm/include/llvm/ProfileData/InstrProfCorrelator.h
index a3a0805a294a20c..dd062951f277c1c 100644
--- a/llvm/include/llvm/ProfileData/InstrProfCorrelator.h
+++ b/llvm/include/llvm/ProfileData/InstrProfCorrelator.h
@@ -31,11 +31,8 @@ class ObjectFile;
/// to their functions.
class InstrProfCorrelator {
public:
- /// Indicate which kind correlator to use.
- enum ProfCorrelatorKind { NONE, DEBUG_INFO };
-
static llvm::Expected<std::unique_ptr<InstrProfCorrelator>>
- get(StringRef Filename, ProfCorrelatorKind FileKind);
+ get(StringRef DebugInfoFilename);
/// Construct a ProfileData vector used to correlate raw instrumentation data
/// to their functions.
@@ -107,7 +104,7 @@ class InstrProfCorrelator {
private:
static llvm::Expected<std::unique_ptr<InstrProfCorrelator>>
- get(std::unique_ptr<MemoryBuffer> Buffer, ProfCorrelatorKind FileKind);
+ get(std::unique_ptr<MemoryBuffer> Buffer);
const InstrProfCorrelatorKind Kind;
};
@@ -131,7 +128,7 @@ class InstrProfCorrelatorImpl : public InstrProfCorrelator {
static llvm::Expected<std::unique_ptr<InstrProfCorrelatorImpl<IntPtrT>>>
get(std::unique_ptr<InstrProfCorrelator::Context> Ctx,
- const object::ObjectFile &Obj, ProfCorrelatorKind FileKind);
+ const object::ObjectFile &Obj);
protected:
std::vector<RawInstrProf::ProfileData<IntPtrT>> Data;
@@ -141,8 +138,6 @@ class InstrProfCorrelatorImpl : public InstrProfCorrelator {
int MaxWarnings,
InstrProfCorrelator::CorrelationData *Data = nullptr) = 0;
- virtual Error correlateProfileNameImpl() = 0;
-
Error dumpYaml(int MaxWarnings, raw_ostream &OS) override;
void addProbe(StringRef FunctionName, uint64_t CFGHash, IntPtrT CounterOffset,
@@ -210,8 +205,6 @@ class DwarfInstrProfCorrelator : public InstrProfCorrelatorImpl<IntPtrT> {
void correlateProfileDataImpl(
int MaxWarnings,
InstrProfCorrelator::CorrelationData *Data = nullptr) override;
-
- Error correlateProfileNameImpl() override;
};
} // end namespace llvm
diff --git a/llvm/include/llvm/ProfileData/InstrProfReader.h b/llvm/include/llvm/ProfileData/InstrProfReader.h
index 1084a58eb098d12..cf6429a324d36b3 100644
--- a/llvm/include/llvm/ProfileData/InstrProfReader.h
+++ b/llvm/include/llvm/ProfileData/InstrProfReader.h
@@ -377,8 +377,6 @@ class RawInstrProfReader : public InstrProfReader {
return (Version & VARIANT_MASK_DBG_CORRELATE) != 0;
}
- bool useCorrelate() const { return useDebugInfoCorrelate(); }
-
bool hasSingleByteCoverage() const override {
return (Version & VARIANT_MASK_BYTE_COVERAGE) != 0;
}
diff --git a/llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h b/llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
index 3d8f3bd9235451f..5b1977b7de9a2ae 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
@@ -24,6 +24,8 @@
namespace llvm {
+extern cl::opt<bool> DebugInfoCorrelate;
+
class Function;
class Instruction;
class Module;
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index cf4983a6d0531f3..f3ba380818901ca 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -57,7 +57,6 @@
#include "llvm/MC/MCValue.h"
#include "llvm/MC/SectionKind.h"
#include "llvm/ProfileData/InstrProf.h"
-#include "llvm/ProfileData/InstrProfCorrelator.h"
#include "llvm/Support/Base64.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CodeGen.h"
@@ -72,24 +71,6 @@
using namespace llvm;
using namespace dwarf;
-namespace llvm {
-// Deprecated. Use -profile-correlate=debug-info.
-cl::opt<bool> DebugInfoCorrelate(
- "debug-info-correlate",
- cl::desc("Use debug info to correlate profiles (Deprecated). Use "
- "-profile-correlate=debug-info instead."),
- cl::init(false));
-
-cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate(
- "profile-correlate",
- cl::desc("Use debug info or binary file to correlate profiles."),
- cl::init(InstrProfCorrelator::NONE),
- cl::values(clEnumValN(InstrProfCorrelator::NONE, "",
- "No profile correlation"),
- clEnumValN(InstrProfCorrelator::DEBUG_INFO, "debug-info",
- "Use debug info to correlate")));
-} // namespace llvm
-
static cl::opt<bool> JumpTableInFunctionSection(
"jumptable-in-function-section", cl::Hidden, cl::init(false),
cl::desc("Putting Jump Table in function section"));
diff --git a/llvm/lib/ProfileData/InstrProfCorrelator.cpp b/llvm/lib/ProfileData/InstrProfCorrelator.cpp
index e429b9f1da54cba..2138368500bed09 100644
--- a/llvm/lib/ProfileData/InstrProfCorrelator.cpp
+++ b/llvm/lib/ProfileData/InstrProfCorrelator.cpp
@@ -24,20 +24,15 @@
using namespace llvm;
-/// Get profile section.
-Expected<object::SectionRef> getInstrProfSection(const object::ObjectFile &Obj,
- InstrProfSectKind IPSK) {
- Triple::ObjectFormatType ObjFormat = Obj.getTripleObjectFormat();
- std::string ExpectedSectionName =
- getInstrProfSectionName(IPSK, ObjFormat,
- /*AddSegmentInfo=*/false);
+/// Get the __llvm_prf_cnts section.
+Expected<object::SectionRef> getCountersSection(const object::ObjectFile &Obj) {
for (auto &Section : Obj.sections())
if (auto SectionName = Section.getName())
- if (SectionName.get() == ExpectedSectionName)
+ if (SectionName.get() == INSTR_PROF_CNTS_SECT_NAME)
return Section;
return make_error<InstrProfError>(
instrprof_error::unable_to_correlate_profile,
- "could not find section (" + Twine(ExpectedSectionName) + ")");
+ "could not find counter section (" INSTR_PROF_CNTS_SECT_NAME ")");
}
const char *InstrProfCorrelator::FunctionNameAttributeName = "Function Name";
@@ -47,7 +42,7 @@ const char *InstrProfCorrelator::NumCountersAttributeName = "Num Counters";
llvm::Expected<std::unique_ptr<InstrProfCorrelator::Context>>
InstrProfCorrelator::Context::get(std::unique_ptr<MemoryBuffer> Buffer,
const object::ObjectFile &Obj) {
- auto CountersSection = getInstrProfSection(Obj, IPSK_cnts);
+ auto CountersSection = getCountersSection(Obj);
if (auto Err = CountersSection.takeError())
return std::move(Err);
auto C = std::make_unique<Context>();
@@ -59,32 +54,30 @@ InstrProfCorrelator::Context::get(std::unique_ptr<MemoryBuffer> Buffer,
}
llvm::Expected<std::unique_ptr<InstrProfCorrelator>>
-InstrProfCorrelator::get(StringRef Filename, ProfCorrelatorKind FileKind) {
- if (FileKind == DEBUG_INFO) {
- auto DsymObjectsOrErr =
- object::MachOObjectFile::findDsymObjectMembers(Filename);
- if (auto Err = DsymObjectsOrErr.takeError())
- return std::move(Err);
- if (!DsymObjectsOrErr->empty()) {
- // TODO: Enable profile correlation when there are multiple objects in a
- // dSYM bundle.
- if (DsymObjectsOrErr->size() > 1)
- return make_error<InstrProfError>(
- instrprof_error::unable_to_correlate_profile,
- "using multiple objects is not yet supported");
- Filename = *DsymObjectsOrErr->begin();
- }
+InstrProfCorrelator::get(StringRef DebugInfoFilename) {
+ auto DsymObjectsOrErr =
+ object::MachOObjectFile::findDsymObjectMembers(DebugInfoFilename);
+ if (auto Err = DsymObjectsOrErr.takeError())
+ return std::move(Err);
+ if (!DsymObjectsOrErr->empty()) {
+ // TODO: Enable profile correlation when there are multiple objects in a
+ // dSYM bundle.
+ if (DsymObjectsOrErr->size() > 1)
+ return make_error<InstrProfError>(
+ instrprof_error::unable_to_correlate_profile,
+ "using multiple objects is not yet supported");
+ DebugInfoFilename = *DsymObjectsOrErr->begin();
}
- auto BufferOrErr = errorOrToExpected(MemoryBuffer::getFile(Filename));
+ auto BufferOrErr =
+ errorOrToExpected(MemoryBuffer::getFile(DebugInfoFilename));
if (auto Err = BufferOrErr.takeError())
return std::move(Err);
- return get(std::move(*BufferOrErr), FileKind);
+ return get(std::move(*BufferOrErr));
}
llvm::Expected<std::unique_ptr<InstrProfCorrelator>>
-InstrProfCorrelator::get(std::unique_ptr<MemoryBuffer> Buffer,
- ProfCorrelatorKind FileKind) {
+InstrProfCorrelator::get(std::unique_ptr<MemoryBuffer> Buffer) {
auto BinOrErr = object::createBinary(*Buffer);
if (auto Err = BinOrErr.takeError())
return std::move(Err);
@@ -95,11 +88,9 @@ InstrProfCorrelator::get(std::unique_ptr<MemoryBuffer> Buffer,
return std::move(Err);
auto T = Obj->makeTriple();
if (T.isArch64Bit())
- return InstrProfCorrelatorImpl<uint64_t>::get(std::move(*CtxOrErr), *Obj,
- FileKind);
+ return InstrProfCorrelatorImpl<uint64_t>::get(std::move(*CtxOrErr), *Obj);
if (T.isArch32Bit())
- return InstrProfCorrelatorImpl<uint32_t>::get(std::move(*CtxOrErr), *Obj,
- FileKind);
+ return InstrProfCorrelatorImpl<uint32_t>::get(std::move(*CtxOrErr), *Obj);
}
return make_error<InstrProfError>(
instrprof_error::unable_to_correlate_profile, "not an object file");
@@ -141,33 +132,29 @@ template <class IntPtrT>
llvm::Expected<std::unique_ptr<InstrProfCorrelatorImpl<IntPtrT>>>
InstrProfCorrelatorImpl<IntPtrT>::get(
std::unique_ptr<InstrProfCorrelator::Context> Ctx,
- const object::ObjectFile &Obj, ProfCorrelatorKind FileKind) {
- if (FileKind == DEBUG_INFO) {
- if (Obj.isELF() || Obj.isMachO()) {
- auto DICtx = DWARFContext::create(Obj);
- return std::make_unique<DwarfInstrProfCorrelator<IntPtrT>>(
- std::move(DICtx), std::move(Ctx));
- }
- return make_error<InstrProfError>(
- instrprof_error::unable_to_correlate_profile,
- "unsupported debug info format (only DWARF is supported)");
+ const object::ObjectFile &Obj) {
+ if (Obj.isELF() || Obj.isMachO()) {
+ auto DICtx = DWARFContext::create(Obj);
+ return std::make_unique<DwarfInstrProfCorrelator<IntPtrT>>(std::move(DICtx),
+ std::move(Ctx));
}
return make_error<InstrProfError>(
instrprof_error::unable_to_correlate_profile,
- "unsupported correlation file type (only DWARF is supported)");
+ "unsupported debug info format (only DWARF is supported)");
}
template <class IntPtrT>
Error InstrProfCorrelatorImpl<IntPtrT>::correlateProfileData(int MaxWarnings) {
assert(Data.empty() && Names.empty() && NamesVec.empty());
correlateProfileDataImpl(MaxWarnings);
- if (this->Data.empty())
+ if (Data.empty() || NamesVec.empty())
return make_error<InstrProfError>(
instrprof_error::unable_to_correlate_profile,
- "could not find any profile data metadata in correlated file");
- Error Result = correlateProfileNameImpl();
- this->CounterOffsets.clear();
- this->NamesVec.clear();
+ "could not find any profile metadata in debug info");
+ auto Result =
+ collectGlobalObjectNameStrings(NamesVec, /*doCompression=*/false, Names);
+ CounterOffsets.clear();
+ NamesVec.clear();
return Result;
}
@@ -202,7 +189,7 @@ Error InstrProfCorrelatorImpl<IntPtrT>::dumpYaml(int MaxWarnings,
if (Data.Probes.empty())
return make_error<InstrProfError>(
instrprof_error::unable_to_correlate_profile,
- "could not find any profile data metadata in debug info");
+ "could not find any profile metadata in debug info");
yaml::Output YamlOS(OS);
YamlOS << Data;
return Error::success();
@@ -378,16 +365,3 @@ void DwarfInstrProfCorrelator<IntPtrT>::correlateProfileDataImpl(
WithColor::warning() << format("Suppressed %d additional warnings\n",
NumSuppressedWarnings);
}
-
-template <class IntPtrT>
-Error DwarfInstrProfCorrelator<IntPtrT>::correlateProfileNameImpl() {
- if (this->NamesVec.empty()) {
- return make_error<InstrProfError>(
- instrprof_error::unable_to_correlate_profile,
- "could not find any profile name metadata in debug info");
- }
- auto Result =
- collectGlobalObjectNameStrings(this->NamesVec,
- /*doCompression=*/false, this->Names);
- return Result;
-}
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index dd66f4247ec73ea..31d3ff2bcbf6ca7 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -563,9 +563,9 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
"\nPLEASE update this tool to version in the raw profile, or "
"regenerate raw profile with expected version.")
.str());
- if (useCorrelate() && !Correlator)
+ if (useDebugInfoCorrelate() && !Correlator)
return error(instrprof_error::missing_debug_info_for_correlation);
- if (!useCorrelate() && Correlator)
+ if (!useDebugInfoCorrelate() && Correlator)
return error(instrprof_error::unexpected_debug_info_for_correlation);
BinaryIdsSize = swap(Header.BinaryIdsSize);
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index 0ca04d1f71df8c8..55eef2b76e9be28 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -60,8 +60,10 @@ using namespace llvm;
#define DEBUG_TYPE "instrprof"
namespace llvm {
-extern cl::opt<bool> DebugInfoCorrelate;
-extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate;
+cl::opt<bool>
+ DebugInfoCorrelate("debug-info-correlate",
+ cl::desc("Use debug info to correlate profiles."),
+ cl::init(false));
} // namespace llvm
namespace {
@@ -648,7 +650,7 @@ void InstrProfiling::lowerValueProfileInst(InstrProfValueProfileInst *Ind) {
// in lightweight mode. We need to move the value profile pointer to the
// Counter struct to get this working.
assert(
- (!DebugInfoCorrelate || ProfileCorrelate != InstrProfCorrelator::NONE) &&
+ !DebugInfoCorrelate &&
"Value profiling is not yet supported with lightweight instrumentation");
GlobalVariable *Name = Ind->getName();
auto It = ProfileDataMap.find(Name);
@@ -1076,11 +1078,10 @@ GlobalVariable *InstrProfiling::setupProfileSection(InstrProfInstBase *Inc,
Function *Fn = Inc->getParent()->getParent();
GlobalValue::LinkageTypes Linkage = NamePtr->getLinkage();
GlobalValue::VisibilityTypes Visibility = NamePtr->getVisibility();
- bool EnableDebugCorrelate =
- DebugInfoCorrelate || ProfileCorrelate == InstrProfCorrelator::DEBUG_INFO;
+
// Use internal rather than private linkage so the counter variable shows up
// in the symbol table when using debug info for correlation.
- if (EnableDebugCorrelate && TT.isOSBinFormatMachO() &&
+ if (DebugInfoCorrelate && TT.isOSBinFormatMachO() &&
Linkage == GlobalValue::PrivateLinkage)
Linkage = GlobalValue::InternalLinkage;
@@ -1201,8 +1202,7 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfCntrInstBase *Inc) {
auto *CounterPtr = setupProfileSection(Inc, IPSK_cnts);
PD.RegionCounters = CounterPtr;
- if (DebugInfoCorrelate ||
- ProfileCorrelate == InstrProfCorrelator::DEBUG_INFO) {
+ if (DebugInfoCorrelate) {
LLVMContext &Ctx = M->getContext();
Function *Fn = Inc->getParent()->getParent();
if (auto *SP = Fn->getSubprogram()) {
@@ -1245,7 +1245,7 @@ void InstrProfiling::createDataVariable(InstrProfCntrInstBase *Inc,
InstrProfMCDCBitmapParameters *Params) {
// When debug information is correlated to profile data, a data variable
// is not needed.
- if (DebugInfoCorrelate || ProfileCorrelate == InstrProfCorrelator::DEBUG_INFO)
+ if (DebugInfoCorrelate)
return;
GlobalVariable *NamePtr = Inc->getName();
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index 1e6f2470dedb707..7ad1c9bc54f3780 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -94,7 +94,6 @@
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/ProfileData/InstrProf.h"
-#include "llvm/ProfileData/InstrProfCorrelator.h"
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/CRC.h"
@@ -220,9 +219,6 @@ cl::opt<bool> NoPGOWarnMismatchComdatWeak(
cl::desc("The option is used to turn on/off "
"warnings about hash mismatch for comdat "
"or weak functions."));
-
-extern cl::opt<bool> DebugInfoCorrelate;
-extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate;
} // namespace llvm
// Command line option to enable/disable select instruction instrumentation.
@@ -385,7 +381,7 @@ static GlobalVariable *createIRLevelProfileFlagVar(Module &M, bool IsCS) {
ProfileVersion |= VARIANT_MASK_CSIR_PROF;
if (PGOInstrumentEntry)
ProfileVersion |= VARIANT_MASK_INSTR_ENTRY;
- if (DebugInfoCorrelate || ProfileCorrelate == InstrProfCorrelator::DEBUG_INFO)
+ if (DebugInfoCorrelate)
ProfileVersion |= VARIANT_MASK_DBG_CORRELATE;
if (PGOFunctionEntryCoverage)
ProfileVersion |=
diff --git a/llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll b/llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll
index dd6461533817050..192bac6e503a07b 100644
--- a/llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll
+++ b/llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -passes=instrprof -profile-correlate=debug-info -S | opt -O2 -S | FileCheck %s
+; RUN: opt < %s -passes=instrprof -debug-info-correlate -S | opt -O2 -S | FileCheck %s
@__profn_foo = private constant [3 x i8] c"foo"
; CHECK: @__profc_foo
diff --git a/llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll b/llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll
index 84eaab33701a487..fd868ead5b78d21 100644
--- a/llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll
+++ b/llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -passes=instrprof -profile-correlate=debug-info -S > %t.ll
+; RUN: opt < %s -passes=instrprof -debug-info-correlate -S > %t.ll
; RUN: FileCheck < %t.ll --implicit-check-not "{{__llvm_prf_data|__llvm_prf_names}}" %s
; RUN: %llc_dwarf -O0 -filetype=obj < %t.ll | llvm-dwarfdump - | FileCheck --implicit-check-not "{{DW_TAG|NULL}}" %s --check-prefix CHECK-DWARF
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index f05029e10e9bce9..7d665a8005b0d62 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -426,9 +426,8 @@ mergeInstrProfile(const WeightedFileVector &Inputs, StringRef DebugInfoFilename,
std::unique_ptr<InstrProfCorrelator> Correlator;
if (!DebugInfoFilename.empty()) {
- if (auto Err = InstrProfCorrelator::get(DebugInfoFilename,
- InstrProfCorrelator::DEBUG_INFO)
- .moveInto(Correlator))
+ if (auto Err =
+ InstrProfCorrelator::get(DebugInfoFilename).moveInto(Correlator))
exitWithError(std::move(Err), DebugInfoFilename);
if (auto Err = Correlator->correlateProfileData(MaxDbgCorrelationWarnings))
exitWithError(std::move(Err), DebugInfoFilename);
@@ -2894,9 +2893,7 @@ static int showDebugInfoCorrelation(const std::string &Filename,
if (SFormat == ShowFormat::Json)
exitWithError("JSON output is not supported for debug info correlation");
std::unique_ptr<InstrProfCorrelator> Correlator;
- if (auto Err =
- InstrProfCorrelator::get(Filename, InstrProfCorrelator::DEBUG_INFO)
- .moveInto(Correlator))
+ if (auto Err = InstrProfCorrelator::get(Filename).moveInto(Correlator))
exitWithError(std::move(Err), Filename);
if (SFormat == ShowFormat::Yaml) {
if (auto Err = Correlator->dumpYaml(MaxDbgCorrelationWarnings, OS))
More information about the llvm-commits
mailing list