Skip to content

Commit 954af75

Browse files
authored
[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.
1 parent 0692784 commit 954af75

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

llvm/lib/Transforms/IPO/SampleProfileProbe.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/IR/BasicBlock.h"
1919
#include "llvm/IR/Constants.h"
2020
#include "llvm/IR/DebugInfoMetadata.h"
21+
#include "llvm/IR/DiagnosticInfo.h"
2122
#include "llvm/IR/IRBuilder.h"
2223
#include "llvm/IR/Instruction.h"
2324
#include "llvm/IR/IntrinsicInst.h"
@@ -221,12 +222,25 @@ void SampleProfileProber::computeProbeIdForBlocks() {
221222
}
222223

223224
void SampleProfileProber::computeProbeIdForCallsites() {
225+
LLVMContext &Ctx = F->getContext();
226+
Module *M = F->getParent();
227+
224228
for (auto &BB : *F) {
225229
for (auto &I : BB) {
226230
if (!isa<CallBase>(I))
227231
continue;
228232
if (isa<IntrinsicInst>(&I))
229233
continue;
234+
235+
// The current implementation uses the lower 16 bits of the discriminator
236+
// so anything larger than 0xFFFF will be ignored.
237+
if (LastProbeId >= 0xFFFF) {
238+
std::string Msg = "Pseudo instrumentation incomplete for " +
239+
std::string(F->getName()) + " because it's too large";
240+
Ctx.diagnose(DiagnosticInfoSampleProfile(M->getName().data(), Msg));
241+
return;
242+
}
243+
230244
CallProbeIds[&I] = ++LastProbeId;
231245
}
232246
}

0 commit comments

Comments
 (0)