Skip to content

Commit 3b4e3f4

Browse files
committed
Update with #107137 changes
Created using spr 1.3.4
2 parents 2ba5591 + 75d6229 commit 3b4e3f4

File tree

6 files changed

+62
-75
lines changed

6 files changed

+62
-75
lines changed

bolt/include/bolt/Profile/ProfileYAMLMapping.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ template <> struct MappingTraits<bolt::SuccessorInfo> {
9696
namespace bolt {
9797
struct PseudoProbeInfo {
9898
uint32_t InlineTreeIndex = 0;
99-
uint64_t BlockMask = 0; // bitset with probe indices
100-
// Assume BlockMask == 1 if no other probes are set
101-
std::vector<uint64_t> BlockProbes;
99+
uint64_t BlockMask = 0; // bitset with probe indices from 1 to 64
100+
std::vector<uint64_t> BlockProbes; // block probes with indices above 64
102101
std::vector<uint64_t> CallProbes;
103102
std::vector<uint64_t> IndCallProbes;
104103
std::vector<uint32_t> InlineTreeNodes;
@@ -113,10 +112,10 @@ struct PseudoProbeInfo {
113112

114113
template <> struct MappingTraits<bolt::PseudoProbeInfo> {
115114
static void mapping(IO &YamlIO, bolt::PseudoProbeInfo &PI) {
116-
YamlIO.mapOptional("blk", PI.BlockMask, 0);
117-
YamlIO.mapOptional("blks", PI.BlockProbes, std::vector<uint64_t>());
118-
YamlIO.mapOptional("calls", PI.CallProbes, std::vector<uint64_t>());
119-
YamlIO.mapOptional("indcalls", PI.IndCallProbes, std::vector<uint64_t>());
115+
YamlIO.mapOptional("blx", PI.BlockMask, 0);
116+
YamlIO.mapOptional("blk", PI.BlockProbes, std::vector<uint64_t>());
117+
YamlIO.mapOptional("call", PI.CallProbes, std::vector<uint64_t>());
118+
YamlIO.mapOptional("icall", PI.IndCallProbes, std::vector<uint64_t>());
120119
YamlIO.mapOptional("id", PI.InlineTreeIndex, 0);
121120
YamlIO.mapOptional("ids", PI.InlineTreeNodes, std::vector<uint32_t>());
122121
}
@@ -170,18 +169,18 @@ template <> struct MappingTraits<bolt::BinaryBasicBlockProfile> {
170169
};
171170

172171
namespace bolt {
173-
struct InlineTreeInfo {
172+
struct InlineTreeNode {
174173
uint32_t ParentIndexDelta;
175174
uint32_t CallSiteProbe;
176-
// Index in PseudoProbeDesc.GUID + 1, 0 for same as previous
175+
// Index in PseudoProbeDesc.GUID, UINT32_MAX for same as previous (omitted)
177176
uint32_t GUIDIndex;
178-
bool operator==(const InlineTreeInfo &) const { return false; }
177+
bool operator==(const InlineTreeNode &) const { return false; }
179178
};
180179
} // end namespace bolt
181180

182-
template <> struct MappingTraits<bolt::InlineTreeInfo> {
183-
static void mapping(IO &YamlIO, bolt::InlineTreeInfo &ITI) {
184-
YamlIO.mapOptional("g", ITI.GUIDIndex, 0);
181+
template <> struct MappingTraits<bolt::InlineTreeNode> {
182+
static void mapping(IO &YamlIO, bolt::InlineTreeNode &ITI) {
183+
YamlIO.mapOptional("g", ITI.GUIDIndex, UINT32_MAX);
185184
YamlIO.mapOptional("p", ITI.ParentIndexDelta, 0);
186185
YamlIO.mapOptional("cs", ITI.CallSiteProbe, 0);
187186
}
@@ -192,7 +191,7 @@ template <> struct MappingTraits<bolt::InlineTreeInfo> {
192191
} // end namespace llvm
193192

194193
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::bolt::BinaryBasicBlockProfile)
195-
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::bolt::InlineTreeInfo)
194+
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::bolt::InlineTreeNode)
196195

197196
namespace llvm {
198197
namespace yaml {
@@ -205,7 +204,7 @@ struct BinaryFunctionProfile {
205204
llvm::yaml::Hex64 Hash{0};
206205
uint64_t ExecCount{0};
207206
std::vector<BinaryBasicBlockProfile> Blocks;
208-
std::vector<InlineTreeInfo> InlineTree;
207+
std::vector<InlineTreeNode> InlineTree;
209208
bool Used{false};
210209
};
211210
} // end namespace bolt
@@ -220,7 +219,7 @@ template <> struct MappingTraits<bolt::BinaryFunctionProfile> {
220219
YamlIO.mapOptional("blocks", BFP.Blocks,
221220
std::vector<bolt::BinaryBasicBlockProfile>());
222221
YamlIO.mapOptional("inline_tree", BFP.InlineTree,
223-
std::vector<bolt::InlineTreeInfo>());
222+
std::vector<bolt::InlineTreeNode>());
224223
}
225224
};
226225

@@ -274,20 +273,21 @@ namespace bolt {
274273
struct PseudoProbeDesc {
275274
std::vector<Hex64> GUID;
276275
std::vector<Hex64> Hash;
277-
std::vector<uint32_t> GUIDHash; // Index of hash for that GUID in Hash
276+
std::vector<uint32_t> GUIDHashIdx; // Index of hash for that GUID in Hash
278277

279278
bool operator==(const PseudoProbeDesc &Other) const {
280279
// Only treat empty Desc as equal
281280
return GUID.empty() && Other.GUID.empty() && Hash.empty() &&
282-
Other.Hash.empty() && GUIDHash.empty() && Other.GUIDHash.empty();
281+
Other.Hash.empty() && GUIDHashIdx.empty() &&
282+
Other.GUIDHashIdx.empty();
283283
}
284284
};
285285
} // end namespace bolt
286286

287287
template <> struct MappingTraits<bolt::PseudoProbeDesc> {
288288
static void mapping(IO &YamlIO, bolt::PseudoProbeDesc &PD) {
289289
YamlIO.mapRequired("gs", PD.GUID);
290-
YamlIO.mapRequired("gh", PD.GUIDHash);
290+
YamlIO.mapRequired("gh", PD.GUIDHashIdx);
291291
YamlIO.mapRequired("hs", PD.Hash);
292292
}
293293
};

bolt/include/bolt/Profile/YAMLProfileWriter.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ class YAMLProfileWriter {
4343
GUIDNumMap HashIdxMap;
4444
};
4545

46-
static std::tuple<std::vector<yaml::bolt::InlineTreeInfo>, InlineTreeMapTy>
46+
static std::tuple<std::vector<yaml::bolt::InlineTreeNode>, InlineTreeMapTy>
4747
convertBFInlineTree(const MCPseudoProbeDecoder &Decoder,
4848
const InlineTreeDesc &InlineTree, uint64_t GUID);
4949

50+
static std::tuple<yaml::bolt::PseudoProbeDesc, InlineTreeDesc>
51+
convertPseudoProbeDesc(const MCPseudoProbeDecoder &PseudoProbeDecoder);
52+
5053
static yaml::bolt::BinaryFunctionProfile
5154
convert(const BinaryFunction &BF, bool UseDFS,
5255
const InlineTreeDesc &InlineTree,
5356
const BoltAddressTranslation *BAT = nullptr);
5457

55-
static std::tuple<yaml::bolt::PseudoProbeDesc, InlineTreeDesc>
56-
convertPseudoProbeDesc(const MCPseudoProbeDecoder &PseudoProbeDecoder);
57-
5858
/// Set CallSiteInfo destination fields from \p Symbol and return a target
5959
/// BinaryFunction for that symbol.
6060
static const BinaryFunction *
@@ -71,8 +71,8 @@ class YAMLProfileWriter {
7171
uint32_t InlineSite;
7272
};
7373
static std::vector<InlineTreeNode>
74-
getInlineTree(const MCPseudoProbeDecoder &Decoder,
75-
const MCDecodedPseudoProbeInlineTree *Root);
74+
collectInlineTree(const MCPseudoProbeDecoder &Decoder,
75+
const MCDecodedPseudoProbeInlineTree &Root);
7676

7777
// 0 - block probe, 1 - indirect call, 2 - direct call
7878
using ProbeList = std::array<SmallVector<uint64_t, 0>, 3>;

bolt/lib/Profile/StaleProfileMatching.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class StaleMatcher {
233233
std::pair<const FlowBlock *, MatchMethod>
234234
matchBlock(BlendedBlockHash BlendedHash, uint64_t CallHash,
235235
const ArrayRef<yaml::bolt::PseudoProbeInfo> PseudoProbes,
236-
const ArrayRef<yaml::bolt::InlineTreeInfo> InlineTree) {
236+
const ArrayRef<yaml::bolt::InlineTreeNode> InlineTree) {
237237
const auto &[Block, ExactHash] = matchWithOpcodes(BlendedHash);
238238
if (Block && ExactHash)
239239
return {Block, MATCH_EXACT};
@@ -327,7 +327,7 @@ class StaleMatcher {
327327
/// unambiguous.
328328
std::pair<const FlowBlock *, bool> matchWithPseudoProbes(
329329
const ArrayRef<yaml::bolt::PseudoProbeInfo> BlockPseudoProbes,
330-
const ArrayRef<yaml::bolt::InlineTreeInfo> InlineTree) const {
330+
const ArrayRef<yaml::bolt::InlineTreeNode> InlineTree) const {
331331
if (!opts::StaleMatchingWithPseudoProbes)
332332
return {nullptr, false};
333333

@@ -353,11 +353,7 @@ class StaleMatcher {
353353
};
354354

355355
auto matchProbe = [&](const yaml::bolt::PseudoProbeInfo &Probe,
356-
uint32_t NodeId, bool IsBlock1) {
357-
if (IsBlock1) {
358-
++FlowBlockMatchCount[match(NodeId, 1)];
359-
return;
360-
}
356+
uint32_t NodeId) {
361357
for (uint64_t Index = 0; Index < 64; ++Index)
362358
if (Probe.BlockMask & 1ull << Index)
363359
++FlowBlockMatchCount[match(NodeId, Index + 1)];
@@ -368,13 +364,11 @@ class StaleMatcher {
368364
};
369365

370366
for (const yaml::bolt::PseudoProbeInfo &Probe : BlockPseudoProbes) {
371-
bool IsBlock1 = Probe.BlockMask == 0 && Probe.BlockProbes.empty() &&
372-
Probe.IndCallProbes.empty() && Probe.CallProbes.empty();
373367
if (!Probe.InlineTreeNodes.empty())
374368
for (uint32_t Node : Probe.InlineTreeNodes)
375-
matchProbe(Probe, Node, IsBlock1);
369+
matchProbe(Probe, Node);
376370
else
377-
matchProbe(Probe, Probe.InlineTreeIndex, IsBlock1);
371+
matchProbe(Probe, Probe.InlineTreeIndex);
378372
}
379373
uint32_t BestMatchCount = 0;
380374
uint32_t TotalMatchCount = 0;
@@ -622,16 +616,16 @@ size_t matchWeightsByHashes(
622616
uint32_t ParentId = 0;
623617
uint32_t PrevGUIDIdx = 0;
624618
uint32_t Index = 0;
625-
for (const yaml::bolt::InlineTreeInfo &InlineTreeNode : YamlBF.InlineTree) {
619+
for (const yaml::bolt::InlineTreeNode &InlineTreeNode : YamlBF.InlineTree) {
626620
uint64_t GUIDIdx = InlineTreeNode.GUIDIndex;
627-
if (GUIDIdx)
621+
if (GUIDIdx != UINT32_MAX)
628622
PrevGUIDIdx = GUIDIdx;
629623
else
630624
GUIDIdx = PrevGUIDIdx;
631-
assert(GUIDIdx - 1 < YamlPD.GUID.size());
632-
assert(GUIDIdx - 1 < YamlPD.GUIDHash.size());
633-
uint64_t GUID = YamlPD.GUID[GUIDIdx - 1];
634-
uint32_t HashIdx = YamlPD.GUIDHash[GUIDIdx - 1];
625+
assert(GUIDIdx < YamlPD.GUID.size());
626+
assert(GUIDIdx < YamlPD.GUIDHashIdx.size());
627+
uint64_t GUID = YamlPD.GUID[GUIDIdx];
628+
uint32_t HashIdx = YamlPD.GUIDHashIdx[GUIDIdx];
635629
assert(HashIdx < YamlPD.Hash.size());
636630
uint64_t Hash = YamlPD.Hash[HashIdx];
637631
uint32_t InlineTreeNodeId = Index++;

bolt/lib/Profile/YAMLProfileWriter.cpp

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/Support/CommandLine.h"
1919
#include "llvm/Support/FileSystem.h"
2020
#include "llvm/Support/raw_ostream.h"
21-
#include <queue>
2221

2322
#undef DEBUG_TYPE
2423
#define DEBUG_TYPE "bolt-prof"
@@ -61,23 +60,21 @@ const BinaryFunction *YAMLProfileWriter::setCSIDestination(
6160
}
6261

6362
std::vector<YAMLProfileWriter::InlineTreeNode>
64-
YAMLProfileWriter::getInlineTree(const MCPseudoProbeDecoder &Decoder,
65-
const MCDecodedPseudoProbeInlineTree *Root) {
63+
YAMLProfileWriter::collectInlineTree(
64+
const MCPseudoProbeDecoder &Decoder,
65+
const MCDecodedPseudoProbeInlineTree &Root) {
6666
auto getHash = [&](const MCDecodedPseudoProbeInlineTree &Node) {
6767
return Decoder.getFuncDescForGUID(Node.Guid)->FuncHash;
6868
};
69-
assert(Root);
70-
std::vector<InlineTreeNode> InlineTree;
71-
InlineTreeNode Node{Root, Root->Guid, getHash(*Root), 0, 0};
72-
InlineTree.emplace_back(Node);
69+
std::vector<InlineTreeNode> InlineTree(
70+
{InlineTreeNode{&Root, Root.Guid, getHash(Root), 0, 0}});
7371
uint32_t ParentId = 0;
7472
while (ParentId != InlineTree.size()) {
7573
const MCDecodedPseudoProbeInlineTree *Cur = InlineTree[ParentId].InlineTree;
76-
for (const MCDecodedPseudoProbeInlineTree &Child : Cur->getChildren()) {
77-
InlineTreeNode Node{&Child, Child.Guid, getHash(Child), ParentId,
78-
std::get<1>(Child.getInlineSite())};
79-
InlineTree.emplace_back(Node);
80-
}
74+
for (const MCDecodedPseudoProbeInlineTree &Child : Cur->getChildren())
75+
InlineTree.emplace_back(
76+
InlineTreeNode{&Child, Child.Guid, getHash(Child), ParentId,
77+
std::get<1>(Child.getInlineSite())});
8178
++ParentId;
8279
}
8380

@@ -125,7 +122,7 @@ YAMLProfileWriter::convertPseudoProbeDesc(const MCPseudoProbeDecoder &Decoder) {
125122
Desc.GUID.emplace_back(GUID);
126123
InlineTree.GUIDIdxMap[GUID] = Index++;
127124
uint64_t Hash = Decoder.getFuncDescForGUID(GUID)->FuncHash;
128-
Desc.GUIDHash.emplace_back(InlineTree.HashIdxMap[Hash]);
125+
Desc.GUIDHashIdx.emplace_back(InlineTree.HashIdxMap[Hash]);
129126
}
130127

131128
return {Desc, InlineTree};
@@ -176,39 +173,35 @@ YAMLProfileWriter::convertNodeProbes(NodeIdToProbes &NodeProbes) {
176173
else
177174
YamlBPI.InlineTreeNodes = Nodes;
178175
handleMask(BPI.BlockProbes, YamlBPI.BlockProbes, YamlBPI.BlockMask);
179-
// Assume BlockMask == 1 if no other probes are set
180-
if (YamlBPI.BlockMask == 1 && YamlBPI.CallProbes.empty() &&
181-
YamlBPI.IndCallProbes.empty())
182-
YamlBPI.BlockMask = 0;
183176
}
184177
return YamlProbes;
185178
}
186179

187-
std::tuple<std::vector<yaml::bolt::InlineTreeInfo>,
180+
std::tuple<std::vector<yaml::bolt::InlineTreeNode>,
188181
YAMLProfileWriter::InlineTreeMapTy>
189182
YAMLProfileWriter::convertBFInlineTree(const MCPseudoProbeDecoder &Decoder,
190183
const InlineTreeDesc &InlineTree,
191184
uint64_t GUID) {
192185
DenseMap<const MCDecodedPseudoProbeInlineTree *, uint32_t> InlineTreeNodeId;
193-
std::vector<yaml::bolt::InlineTreeInfo> YamlInlineTree;
186+
std::vector<yaml::bolt::InlineTreeNode> YamlInlineTree;
194187
auto It = InlineTree.TopLevelGUIDToInlineTree.find(GUID);
195188
if (It == InlineTree.TopLevelGUIDToInlineTree.end())
196189
return {YamlInlineTree, InlineTreeNodeId};
197190
const MCDecodedPseudoProbeInlineTree *Root = It->second;
198-
assert(Root);
191+
assert(Root && "Malformed TopLevelGUIDToInlineTree");
199192
uint32_t Index = 0;
200193
uint32_t PrevParent = 0;
201194
uint32_t PrevGUIDIdx = 0;
202-
for (const auto &Node : getInlineTree(Decoder, Root)) {
195+
for (const auto &Node : collectInlineTree(Decoder, *Root)) {
203196
InlineTreeNodeId[Node.InlineTree] = Index++;
204197
auto GUIDIdxIt = InlineTree.GUIDIdxMap.find(Node.GUID);
205-
assert(GUIDIdxIt != InlineTree.GUIDIdxMap.end());
206-
uint32_t GUIDIdx = GUIDIdxIt->second + 1;
198+
assert(GUIDIdxIt != InlineTree.GUIDIdxMap.end() && "Malformed GUIDIdxMap");
199+
uint32_t GUIDIdx = GUIDIdxIt->second;
207200
if (GUIDIdx == PrevGUIDIdx)
208-
GUIDIdx = 0;
201+
GUIDIdx = UINT32_MAX;
209202
else
210203
PrevGUIDIdx = GUIDIdx;
211-
YamlInlineTree.emplace_back(yaml::bolt::InlineTreeInfo{
204+
YamlInlineTree.emplace_back(yaml::bolt::InlineTreeNode{
212205
Node.ParentId - PrevParent, Node.InlineSite, GUIDIdx});
213206
PrevParent = Node.ParentId;
214207
}

bolt/test/X86/match-blocks-with-pseudo-probes.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ functions:
5555
hash: 0xFFFFFFFFFFFFFFF1
5656
insns: 1
5757
succ: [ { bid: 3, cnt: 1} ]
58-
probes: [ { } ]
59-
inline_tree: [ { g: 1 } ]
58+
probes: [ { blx: 1 } ]
59+
inline_tree: [ { g: 0 } ]
6060
pseudo_probe_desc:
6161
gs: [ 0xDB956436E78DD5FA ]
6262
gh: [ 0 ]

bolt/test/X86/pseudoprobe-decoding-inline.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
# RUN: FileCheck --input-file %t.yaml2 %s --check-prefix CHECK-YAML
1515
# CHECK-YAML: name: bar
1616
# CHECK-YAML: - bid: 0
17-
# CHECK-YAML: probes: [ { blk: 9 } ]
18-
# CHECK-YAML: inline_tree: [ { g: 1 } ]
17+
# CHECK-YAML: probes: [ { blx: 9 } ]
18+
# CHECK-YAML: inline_tree: [ { } ]
1919
#
2020
# CHECK-YAML: name: foo
2121
# CHECK-YAML: - bid: 0
22-
# CHECK-YAML: probes: [ { blk: 3 } ]
23-
# CHECK-YAML: inline_tree: [ { g: 2 }, { g: 1, cs: 8 } ]
22+
# CHECK-YAML: probes: [ { blx: 3 } ]
23+
# CHECK-YAML: inline_tree: [ { g: 1 }, { g: 0, cs: 8 } ]
2424
#
2525
# CHECK-YAML: name: main
2626
# CHECK-YAML: - bid: 0
27-
# CHECK-YAML: probes: [ { blk: 3, id: 1 }, { } ]
28-
# CHECK-YAML: inline_tree: [ { g: 3 }, { g: 2, cs: 2 }, { g: 1, p: 1, cs: 8 } ]
27+
# CHECK-YAML: probes: [ { blx: 3, id: 1 }, { blx: 1 } ]
28+
# CHECK-YAML: inline_tree: [ { g: 2 }, { g: 1, cs: 2 }, { g: 0, p: 1, cs: 8 } ]
2929
#
3030
# CHECK-YAML: pseudo_probe_desc:
3131
# CHECK-YAML-NEXT: gs: [ 0xE413754A191DB537, 0x5CF8C24CDB18BDAC, 0xDB956436E78DD5FA ]

0 commit comments

Comments
 (0)