diff --git a/llvm/include/llvm/MC/MCPseudoProbe.h b/llvm/include/llvm/MC/MCPseudoProbe.h --- a/llvm/include/llvm/MC/MCPseudoProbe.h +++ b/llvm/include/llvm/MC/MCPseudoProbe.h @@ -36,7 +36,6 @@ // A list of NUM_INLINED_FUNCTIONS entries describing each of the inlined // callees. Each record contains: // INLINE SITE -// GUID of the inlinee (uint64) // ID of the callsite probe (ULEB128) // FUNCTION BODY // A FUNCTION BODY entry describing the inlined function. diff --git a/llvm/test/Transforms/SampleProfile/pseudo-probe-slotindex.s b/llvm/test/Transforms/SampleProfile/pseudo-probe-slotindex.s new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/SampleProfile/pseudo-probe-slotindex.s @@ -0,0 +1,67 @@ +--- | + ; ModuleID = '/home/hoy/src/llvm-project/llvm/test/Transforms/SampleProfile/pseudo-probe-slotindex.ll' + source_filename = "/home/hoy/src/llvm-project/llvm/test/Transforms/SampleProfile/pseudo-probe-slotindex.ll" + target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + target triple = "x86_64-unknown-unknown" + + define void @foo(i32* %p) { + call void @llvm.pseudoprobe(i64 5116412291814990879, i64 1, i32 0, i64 -1) + store i32 0, i32* %p, align 4 + store i32 0, i32* %p, align 4 + ret void + } + + ; Function Attrs: inaccessiblememonly nounwind willreturn + declare void @llvm.pseudoprobe(i64, i64, i32, i64) #0 + + attributes #0 = { inaccessiblememonly nounwind willreturn } + +... +--- +name: foo +alignment: 16 +exposesReturnsTwice: false +legalized: false +regBankSelected: false +selected: false +failedISel: false +tracksRegLiveness: true +hasWinCFI: false +registers: [] +liveins: + - { reg: '$rdi', virtual-reg: '' } +frameInfo: + isFrameAddressTaken: false + isReturnAddressTaken: false + hasStackMap: false + hasPatchPoint: false + stackSize: 0 + offsetAdjustment: 0 + maxAlignment: 1 + adjustsStack: false + hasCalls: false + stackProtector: '' + maxCallFrameSize: 0 + cvBytesOfCalleeSavedRegisters: 0 + hasOpaqueSPAdjustment: false + hasVAStart: false + hasMustTailInVarArgFunc: false + hasTailCall: false + localFrameSize: 0 + savePoint: '' + restorePoint: '' +fixedStack: [] +stack: [] +callSites: [] +debugValueSubstitutions: [] +constants: [] +machineFunctionInfo: {} +body: | + bb.0 (%ir-block.0): + liveins: $rdi + + PSEUDO_PROBE 5116412291814990879, 1, 0, 0 + MOV32mi killed renamable $rdi, 1, $noreg, 0, $noreg, 0 :: (store 4 into %ir.p) + RETQ + +... diff --git a/llvm/tools/llvm-profgen/PseudoProbe.h b/llvm/tools/llvm-profgen/PseudoProbe.h --- a/llvm/tools/llvm-profgen/PseudoProbe.h +++ b/llvm/tools/llvm-profgen/PseudoProbe.h @@ -71,6 +71,7 @@ return Ret.first->second.get(); } + auto &getChildren() { return Children; } void addProbes(PseudoProbe *Probe) { ProbeVector.push_back(Probe); } // Return false if it's a dummy inline site bool hasInlineSite() const { return std::get<0>(ISite) != 0; } @@ -91,7 +92,7 @@ // GUID to PseudoProbeFuncDesc map using GUIDProbeFunctionMap = std::unordered_map; // Address to pseudo probes map. -using AddressProbesMap = std::unordered_map>; +using AddressProbesMap = std::unordered_map>; /* A pseudo probe has the format like below: diff --git a/llvm/tools/llvm-profgen/PseudoProbe.cpp b/llvm/tools/llvm-profgen/PseudoProbe.cpp --- a/llvm/tools/llvm-profgen/PseudoProbe.cpp +++ b/llvm/tools/llvm-profgen/PseudoProbe.cpp @@ -198,7 +198,6 @@ // A list of NUM_INLINED_FUNCTIONS entries describing each of the // inlined callees. Each record contains: // INLINE SITE - // GUID of the inlinee (uint64) // Index of the callsite probe (ULEB128) // FUNCTION BODY // A FUNCTION BODY entry describing the inlined function. @@ -214,8 +213,11 @@ uint32_t Index = 0; // A DFS-based decoding while (Data < End) { - // Read inline site for inlinees - if (Root != Cur) { + if (Root == Cur) { + // Use a sequential id for outline functions. + Index = Root->getChildren().size(); + } else { + // Read inline site for inlinees Index = readUnsignedNumber(); } // Switch/add to a new tree node(inlinee) @@ -243,10 +245,10 @@ Addr = readUnencodedNumber(); } // Populate Address2ProbesMap - std::vector &ProbeVec = Address2ProbesMap[Addr]; - ProbeVec.emplace_back(Addr, Cur->GUID, Index, PseudoProbeType(Kind), Attr, - Cur); - Cur->addProbes(&ProbeVec.back()); + auto &Probes = Address2ProbesMap[Addr]; + Probes.emplace_back(Addr, Cur->GUID, Index, PseudoProbeType(Kind), Attr, + Cur); + Cur->addProbes(&Probes.back()); LastAddr = Addr; } @@ -298,7 +300,7 @@ auto It = Address2ProbesMap.find(Address); if (It == Address2ProbesMap.end()) return nullptr; - const std::vector &Probes = It->second; + const auto &Probes = It->second; const PseudoProbe *CallProbe = nullptr; for (const auto &Probe : Probes) {