[llvm] 954af75 - [PGO] Skip optimizing probes that don't fit. (#70875)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 31 21:30:39 PDT 2023
Author: Davide Italiano
Date: 2023-10-31T21:30:36-07:00
New Revision: 954af75cebbdad6de747b1491bd83a204c8b0d6f
URL: https://github.com/llvm/llvm-project/commit/954af75cebbdad6de747b1491bd83a204c8b0d6f
DIFF: https://github.com/llvm/llvm-project/commit/954af75cebbdad6de747b1491bd83a204c8b0d6f.diff
LOG: [PGO] Skip optimizing probes that don't fit. (#70875)
The discriminator can only pack 16 bits, so anything exceeding that
value will cause the packing code to crash. Emit a diagnostic and skip
the optimization instead.
Added:
Modified:
llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
index 56d711c588b0755..b786685d0943ada 100644
--- a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
@@ -18,6 +18,7 @@
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/IntrinsicInst.h"
@@ -221,12 +222,25 @@ void SampleProfileProber::computeProbeIdForBlocks() {
}
void SampleProfileProber::computeProbeIdForCallsites() {
+ LLVMContext &Ctx = F->getContext();
+ Module *M = F->getParent();
+
for (auto &BB : *F) {
for (auto &I : BB) {
if (!isa<CallBase>(I))
continue;
if (isa<IntrinsicInst>(&I))
continue;
+
+ // The current implementation uses the lower 16 bits of the discriminator
+ // so anything larger than 0xFFFF will be ignored.
+ if (LastProbeId >= 0xFFFF) {
+ std::string Msg = "Pseudo instrumentation incomplete for " +
+ std::string(F->getName()) + " because it's too large";
+ Ctx.diagnose(DiagnosticInfoSampleProfile(M->getName().data(), Msg));
+ return;
+ }
+
CallProbeIds[&I] = ++LastProbeId;
}
}
More information about the llvm-commits
mailing list