[llvm] [CGData][MachineOutliner] Global Outlining (PR #90074)
Kyungwoo Lee via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 28 10:46:47 PDT 2024
================
@@ -695,6 +859,39 @@ void MachineOutliner::findCandidates(
}
}
+void MachineOutliner::computeAndPublishHashSequence(MachineFunction &MF,
+ unsigned CandSize) {
+ // Compute the hash sequence for the outlined function.
+ SmallVector<stable_hash> OutlinedHashSequence;
+ for (auto &MBB : MF) {
+ for (auto &NewMI : MBB) {
+ stable_hash Hash = stableHashValue(NewMI);
+ if (!Hash) {
+ OutlinedHashSequence.clear();
+ break;
+ }
+ OutlinedHashSequence.push_back(Hash);
+ }
+ }
+
+ // Append a unique name based on the non-empty hash sequence.
+ if (AppendContentHashToOutlinedName && !OutlinedHashSequence.empty()) {
+ auto CombinedHash = stable_hash_combine(OutlinedHashSequence);
+ auto NewName =
+ MF.getName().str() + ".content." + std::to_string(CombinedHash);
+ MF.getFunction().setName(NewName);
+ }
+
+ // Publish the non-empty hash sequence to the local hash tree.
+ if (OutlinerMode == CGDataMode::Write) {
+ StableHashAttempts++;
+ if (!OutlinedHashSequence.empty())
+ LocalHashTree->insert({OutlinedHashSequence, CandSize});
----------------
kyulee-com wrote:
We track the frequency of each outlined hash sequence in the LocalHashTree (in write mode), which helps us understand how often each sequence appears in a specific module. This frequency is represented as `Terminals` -- https://github.com/llvm/llvm-project/blob/main/llvm/lib/CGData/OutlinedHashTree.cpp#L87.
When combining data from all modules, this terminal count shows the total occurrences of each sequence across all modules.
In this PR, when we create a `GlobalOutlinedFunction` using CGData from previous runs (in read mode), we initialize a `GlobalOccurrenceCount` from the `Terminals` in the global hash tree, which has been merged. This count helps us decide which candidates are most important to outline based on their frequency across all modules.
https://github.com/llvm/llvm-project/pull/90074
More information about the llvm-commits
mailing list