Skip to content

Commit 549da06

Browse files
wdx727lifengxiang1025zcfh
committed
Adding Matching and Inference Functionality to Propeller-PR3: Read basic block hashes from propeller profile.
Co-authored-by: lifengxiang1025 <lifengxiang@kuaishou.com> Co-authored-by: zcfh <wuminghui03@kuaishou.com>
1 parent 46a866a commit 549da06

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct FunctionPathAndClusterInfo {
5454
DenseMap<UniqueBBID, uint64_t> NodeCounts;
5555
// Edge counts for each edge, stored as a nested map.
5656
DenseMap<UniqueBBID, DenseMap<UniqueBBID, uint64_t>> EdgeCounts;
57+
// Hash for each basic block.
58+
DenseMap<unsigned, uint64_t> BBHashes;
5759
};
5860

5961
class BasicBlockSectionsProfileReader {
@@ -86,6 +88,10 @@ class BasicBlockSectionsProfileReader {
8688
uint64_t getEdgeCount(StringRef FuncName, const UniqueBBID &SrcBBID,
8789
const UniqueBBID &SinkBBID) const;
8890

91+
// Return the complete function path and cluster info for the given function.
92+
std::pair<bool, FunctionPathAndClusterInfo>
93+
getFunctionPathAndClusterInfo(StringRef FuncName) const;
94+
8995
private:
9096
StringRef getAliasName(StringRef FuncName) const {
9197
auto R = FuncAliasMap.find(FuncName);
@@ -195,6 +201,9 @@ class BasicBlockSectionsProfileReaderWrapperPass : public ImmutablePass {
195201
uint64_t getEdgeCount(StringRef FuncName, const UniqueBBID &SrcBBID,
196202
const UniqueBBID &DestBBID) const;
197203

204+
std::pair<bool, FunctionPathAndClusterInfo>
205+
getFunctionPathAndClusterInfo(StringRef FuncName) const;
206+
198207
// Initializes the FunctionNameToDIFilename map for the current module and
199208
// then reads the profile for the matching functions.
200209
bool doInitialization(Module &M) override;

llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ uint64_t BasicBlockSectionsProfileReader::getEdgeCount(
9191
return EdgeIt->second;
9292
}
9393

94+
std::pair<bool, FunctionPathAndClusterInfo>
95+
BasicBlockSectionsProfileReader::getFunctionPathAndClusterInfo(
96+
StringRef FuncName) const {
97+
auto R = ProgramPathAndClusterInfo.find(getAliasName(FuncName));
98+
return R != ProgramPathAndClusterInfo.end()
99+
? std::pair(true, R->second)
100+
: std::pair(false, FunctionPathAndClusterInfo());
101+
}
102+
94103
// Reads the version 1 basic block sections profile. Profile for each function
95104
// is encoded as follows:
96105
// m <module_name>
@@ -287,6 +296,25 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
287296
}
288297
continue;
289298
}
299+
case 'h': { // Basic block hash secifier.
300+
// Skip the profile when we the profile iterator (FI) refers to the
301+
// past-the-end element.
302+
if (FI == ProgramPathAndClusterInfo.end())
303+
continue;
304+
for (auto BBIDHashStr : Values) {
305+
auto [BBIDStr, HashStr] = BBIDHashStr.split(':');
306+
unsigned long long BBID = 0, Hash = 0;
307+
if (getAsUnsignedInteger(BBIDStr, 10, BBID))
308+
return createProfileParseError(Twine("unsigned integer expected: '") +
309+
BBIDStr + "'");
310+
HashStr.consume_front("0x");
311+
if (getAsUnsignedInteger(HashStr, 16, Hash))
312+
return createProfileParseError(Twine("unsigned integer expected: '") +
313+
HashStr + "'");
314+
FI->second.BBHashes[BBID] = Hash;
315+
}
316+
continue;
317+
}
290318
default:
291319
return createProfileParseError(Twine("invalid specifier: '") +
292320
Twine(Specifier) + "'");
@@ -493,6 +521,12 @@ uint64_t BasicBlockSectionsProfileReaderWrapperPass::getEdgeCount(
493521
return BBSPR.getEdgeCount(FuncName, SrcBBID, SinkBBID);
494522
}
495523

524+
std::pair<bool, FunctionPathAndClusterInfo>
525+
BasicBlockSectionsProfileReaderWrapperPass::getFunctionPathAndClusterInfo(
526+
StringRef FuncName) const {
527+
return BBSPR.getFunctionPathAndClusterInfo(FuncName);
528+
}
529+
496530
BasicBlockSectionsProfileReader &
497531
BasicBlockSectionsProfileReaderWrapperPass::getBBSPR() {
498532
return BBSPR;

0 commit comments

Comments
 (0)