Skip to content

Commit 74b99b5

Browse files
committed
[CSSPGO] Do not import pseudo probe desc in thinLTO
Previously we reliedy on pseudo probe descriptors to look up precomputed GUID during probe emission for inlined probes. Since we are moving to always using unique linkage names, GUID for functions can be computed in place from dwarf names. This eliminates the need of importing pseudo probe descs in thinlto, since those descs should be emitted by the original modules. This significantly reduces thinlto memory footprint in some extreme case where the number of imported modules for a single module is massive. Test Plan: Reviewed By: wenlei Differential Revision: https://reviews.llvm.org/D105248
1 parent 0712038 commit 74b99b5

File tree

6 files changed

+52
-46
lines changed

6 files changed

+52
-46
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ bool AsmPrinter::doInitialization(Module &M) {
359359
}
360360

361361
if (M.getNamedMetadata(PseudoProbeDescMetadataName)) {
362-
PP = new PseudoProbeHandler(this, &M);
362+
PP = new PseudoProbeHandler(this);
363363
Handlers.emplace_back(std::unique_ptr<PseudoProbeHandler>(PP), PPTimerName,
364364
PPTimerDescription, PPGroupName, PPGroupDescription);
365365
}

llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.cpp

+1-37
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,6 @@
2020

2121
using namespace llvm;
2222

23-
#define DEBUG_TYPE "pseudoprobe"
24-
25-
PseudoProbeHandler::~PseudoProbeHandler() = default;
26-
27-
PseudoProbeHandler::PseudoProbeHandler(AsmPrinter *A, Module *M) : Asm(A) {
28-
NamedMDNode *FuncInfo = M->getNamedMetadata(PseudoProbeDescMetadataName);
29-
assert(FuncInfo && "Pseudo probe descriptors are missing");
30-
for (const auto *Operand : FuncInfo->operands()) {
31-
const auto *MD = cast<MDNode>(Operand);
32-
auto GUID =
33-
mdconst::dyn_extract<ConstantInt>(MD->getOperand(0))->getZExtValue();
34-
auto Name = cast<MDString>(MD->getOperand(2))->getString();
35-
// We may see pairs with same name but different GUIDs here in LTO mode, due
36-
// to static same-named functions inlined from other modules into this
37-
// module. Function profiles with the same name will be merged no matter
38-
// whether they are collected on the same function. Therefore we just pick
39-
// up the last <Name, GUID> pair here to represent the same-named function
40-
// collection and all probes from the collection will be merged into a
41-
// single profile eventually.
42-
Names[Name] = GUID;
43-
}
44-
45-
LLVM_DEBUG(dump());
46-
}
47-
4823
void PseudoProbeHandler::emitPseudoProbe(uint64_t Guid, uint64_t Index,
4924
uint64_t Type, uint64_t Attr,
5025
const DILocation *DebugLoc) {
@@ -60,8 +35,7 @@ void PseudoProbeHandler::emitPseudoProbe(uint64_t Guid, uint64_t Index,
6035
auto Name = SP->getLinkageName();
6136
if (Name.empty())
6237
Name = SP->getName();
63-
assert(Names.count(Name) && "Pseudo probe descriptor missing for function");
64-
uint64_t CallerGuid = Names[Name];
38+
uint64_t CallerGuid = Function::getGUID(Name);
6539
uint64_t CallerProbeId = PseudoProbeDwarfDiscriminator::extractProbeIndex(
6640
InlinedAt->getDiscriminator());
6741
ReversedInlineStack.emplace_back(CallerGuid, CallerProbeId);
@@ -72,13 +46,3 @@ void PseudoProbeHandler::emitPseudoProbe(uint64_t Guid, uint64_t Index,
7246
ReversedInlineStack.rend());
7347
Asm->OutStreamer->emitPseudoProbe(Guid, Index, Type, Attr, InlineStack);
7448
}
75-
76-
#ifndef NDEBUG
77-
void PseudoProbeHandler::dump() const {
78-
dbgs() << "\n=============================\n";
79-
dbgs() << "\nFunction Name to GUID map:\n";
80-
dbgs() << "\n=============================\n";
81-
for (const auto &Item : Names)
82-
dbgs() << "Func: " << Item.first << " GUID: " << Item.second << "\n";
83-
}
84-
#endif

llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ class DILocation;
2626
class PseudoProbeHandler : public AsmPrinterHandler {
2727
// Target of pseudo probe emission.
2828
AsmPrinter *Asm;
29-
// Name to GUID map
30-
DenseMap<StringRef, uint64_t> Names;
3129

3230
public:
33-
PseudoProbeHandler(AsmPrinter *A, Module *M);
34-
~PseudoProbeHandler() override;
31+
PseudoProbeHandler(AsmPrinter *A) : Asm(A){};
3532

3633
void emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type,
3734
uint64_t Attr, const DILocation *DebugLoc);
@@ -43,10 +40,6 @@ class PseudoProbeHandler : public AsmPrinterHandler {
4340
void endFunction(const MachineFunction *MF) override {}
4441
void beginInstruction(const MachineInstr *MI) override {}
4542
void endInstruction() override {}
46-
47-
#ifndef NDEBUG
48-
void dump() const;
49-
#endif
5043
};
5144

5245
} // namespace llvm

llvm/lib/Linker/IRMover.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/IR/DiagnosticPrinter.h"
1717
#include "llvm/IR/GVMaterializer.h"
1818
#include "llvm/IR/Intrinsics.h"
19+
#include "llvm/IR/PseudoProbe.h"
1920
#include "llvm/IR/TypeFinder.h"
2021
#include "llvm/Object/ModuleSymbolTable.h"
2122
#include "llvm/Support/Error.h"
@@ -1207,6 +1208,10 @@ void IRLinker::linkNamedMDNodes() {
12071208
// Don't link module flags here. Do them separately.
12081209
if (&NMD == SrcModFlags)
12091210
continue;
1211+
// Don't import pseudo probe descriptors here for thinLTO. They will be
1212+
// emitted by the originating module.
1213+
if (IsPerformingImport && NMD.getName() == PseudoProbeDescMetadataName)
1214+
continue;
12101215
NamedMDNode *DestNMD = DstM.getOrInsertNamedMetadata(NMD.getName());
12111216
// Add Src elements into Dest node.
12121217
for (const MDNode *Op : NMD.operands())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
2+
target triple = "x86_64-unknown-linux-gnu"
3+
4+
define void @foo() {
5+
entry:
6+
call void @llvm.pseudoprobe(i64 6699318081062747564, i64 1, i32 0, i64 -1)
7+
ret void
8+
}
9+
10+
declare void @llvm.pseudoprobe(i64, i64, i32, i64) #0
11+
12+
attributes #0 = { inaccessiblememonly nounwind willreturn }
13+
14+
!llvm.pseudo_probe_desc = !{!0}
15+
16+
!0 = !{i64 6699318081062747564, i64 4294967295, !"foo", null}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; RUN: opt -module-summary %s -o %t1.bc
2+
; RUN: opt -module-summary %p/Inputs/pseudo-probe-desc-import.ll -o %t2.bc
3+
; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc %t2.bc
4+
5+
; Don't import pseudo probe desc.
6+
; RUN: llvm-lto -thinlto-action=import %t1.bc -thinlto-index=%t.index.bc -o - | llvm-dis -o - | FileCheck %s
7+
; CHECK-NOT: {i64 6699318081062747564, i64 4294967295, !"foo"
8+
; CHECK: !{i64 -2624081020897602054, i64 281479271677951, !"main"
9+
10+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
11+
target triple = "x86_64-unknown-linux-gnu"
12+
13+
define i32 @main() {
14+
entry:
15+
call void (...) @foo()
16+
call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 1, i32 0, i64 -1)
17+
ret i32 0
18+
}
19+
20+
declare void @foo(...)
21+
22+
declare void @llvm.pseudoprobe(i64, i64, i32, i64) #0
23+
24+
attributes #0 = { inaccessiblememonly nounwind willreturn }
25+
26+
!llvm.pseudo_probe_desc = !{!0}
27+
28+
!0 = !{i64 -2624081020897602054, i64 281479271677951, !"main", null}

0 commit comments

Comments
 (0)