[PATCH] D156006: [InstrProf] Emit warnings when correlating lightweight profiles
Ellis Hoag via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 21 17:13:15 PDT 2023
ellis created this revision.
Herald added subscribers: Enna1, hiraditya.
Herald added a project: All.
ellis edited the summary of this revision.
ellis added reviewers: kyulee, phosek, wenlei.
ellis published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Emit warnings when `InstrProfCorrelator` finds problems with debug info for lightweight instrumentation profile correlation. To prevent excessive printing, only emit the first 5 warnings.
In addition, remove a diagnostic about missing debug info in `InstrProfiling.cpp`. Some compiler-generated functions, e.g., `__clang_call_terminate`, does not emit debug info and will fail a build if `-Werror` is used. This warning is not actionable by the user and I have not seen non-compiler-generated functions fail this test.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156006
Files:
llvm/lib/ProfileData/InstrProfCorrelator.cpp
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -1056,12 +1056,6 @@
Annotations);
CounterPtr->addDebugInfo(DICounter);
DB.finalize();
- } else {
- std::string Msg = ("Missing debug info for function " + Fn->getName() +
- "; required for profile correlation.")
- .str();
- Ctx.diagnose(
- DiagnosticInfoPGOProfile(M->getName().data(), Msg, DS_Warning));
}
}
Index: llvm/lib/ProfileData/InstrProfCorrelator.cpp
===================================================================
--- llvm/lib/ProfileData/InstrProfCorrelator.cpp
+++ llvm/lib/ProfileData/InstrProfCorrelator.cpp
@@ -16,6 +16,8 @@
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
#include "llvm/Object/MachO.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/WithColor.h"
#include <optional>
#define DEBUG_TYPE "correlator"
@@ -261,6 +263,8 @@
template <class IntPtrT>
void DwarfInstrProfCorrelator<IntPtrT>::correlateProfileDataImpl(
InstrProfCorrelator::CorrelationData *Data) {
+ // The negation of the maximum number of warnings we would like to emit
+ int NumSuppressedWarnings = -5;
auto maybeAddProbe = [&](DWARFDie Die) {
if (!isDIEOfProbe(Die))
return;
@@ -297,28 +301,30 @@
}
}
if (!FunctionName || !CFGHash || !CounterPtr || !NumCounters) {
- LLVM_DEBUG(dbgs() << "Incomplete DIE for probe\n\tFunctionName: "
- << FunctionName << "\n\tCFGHash: " << CFGHash
- << "\n\tCounterPtr: " << CounterPtr
- << "\n\tNumCounters: " << NumCounters);
- LLVM_DEBUG(Die.dump(dbgs()));
+ if (++NumSuppressedWarnings < 1) {
+ WithColor::warning()
+ << "Incomplete DIE for function " << FunctionName
+ << ": CFGHash=" << CFGHash << " CounterPtr=" << CounterPtr
+ << " NumCounters=" << NumCounters << "\n";
+ LLVM_DEBUG(Die.dump(dbgs()));
+ }
return;
}
uint64_t CountersStart = this->Ctx->CountersSectionStart;
uint64_t CountersEnd = this->Ctx->CountersSectionEnd;
if (*CounterPtr < CountersStart || *CounterPtr >= CountersEnd) {
- LLVM_DEBUG(
- dbgs() << "CounterPtr out of range for probe\n\tFunction Name: "
- << FunctionName << "\n\tExpected: [0x"
- << Twine::utohexstr(CountersStart) << ", 0x"
- << Twine::utohexstr(CountersEnd) << ")\n\tActual: 0x"
- << Twine::utohexstr(*CounterPtr));
- LLVM_DEBUG(Die.dump(dbgs()));
+ if (++NumSuppressedWarnings < 1) {
+ WithColor::warning()
+ << format("CounterPtr out of range for function %s: Actual=0x%x "
+ "Expected=[0x%x, 0x%x)\n",
+ *FunctionName, *CounterPtr, CountersStart, CountersEnd);
+ LLVM_DEBUG(Die.dump(dbgs()));
+ }
return;
}
- if (!FunctionPtr) {
- LLVM_DEBUG(dbgs() << "Could not find address of " << *FunctionName
- << "\n");
+ if (!FunctionPtr && ++NumSuppressedWarnings < 1) {
+ WithColor::warning() << format("Could not find address of function %s\n",
+ *FunctionName);
LLVM_DEBUG(Die.dump(dbgs()));
}
IntPtrT CounterOffset = *CounterPtr - CountersStart;
@@ -348,4 +354,8 @@
for (auto &CU : DICtx->dwo_units())
for (const auto &Entry : CU->dies())
maybeAddProbe(DWARFDie(CU.get(), &Entry));
+
+ if (NumSuppressedWarnings > 0)
+ WithColor::warning() << format("Suppressed %d additional warnings\n",
+ NumSuppressedWarnings);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156006.543120.patch
Type: text/x-patch
Size: 3924 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230722/952ae3fc/attachment.bin>
More information about the llvm-commits
mailing list