[llvm] [CGData][MachineOutliner] Global Outlining (PR #90074)
Kyungwoo Lee via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 28 10:38:13 PDT 2024
================
@@ -585,6 +644,111 @@ void MachineOutliner::emitOutlinedFunctionRemark(OutlinedFunction &OF) {
MORE.emit(R);
}
+struct MatchedEntry {
+ size_t StartIdx;
+ size_t Length;
+ size_t Count;
+};
+
+static const HashNode *followHashNode(stable_hash StableHash,
+ const HashNode *Current) {
+ auto I = Current->Successors.find(StableHash);
+ return (I == Current->Successors.end()) ? nullptr : I->second.get();
+}
+
+// Find all matches in the global outlined hash tree.
+// It's quadratic complexity in theory, but it's nearly linear in practice
+// since the length of outlined sequences are small within a block.
+static std::vector<MatchedEntry> getMatchedEntries(InstructionMapper &Mapper) {
+ auto &InstrList = Mapper.InstrList;
+ auto &UnsignedVec = Mapper.UnsignedVec;
+
+ std::vector<MatchedEntry> MatchedEntries;
+ std::vector<stable_hash> Sequence;
+ auto Size = UnsignedVec.size();
+
+ // Get the global outlined hash tree built from the previous run.
+ assert(cgdata::hasOutlinedHashTree());
+ const auto *RootNode = cgdata::getOutlinedHashTree()->getRoot();
+ for (size_t I = 0; I < Size; ++I) {
+ // skip the invalid mapping that represents a large negative value.
----------------
kyulee-com wrote:
Thanks for the catch! The large negative value (starting from `-3`) in the `InstructionMapper` indicates that an instruction mapping is not valid or legal -- https://github.com/kyulee-com/llvm-project/blob/master/llvm/lib/CodeGen/MachineOutliner.cpp#L216-L217, which I implicitly relied on. Instead, to clarify the code, I now check a valid mapping with `Mapper.LegalInstrNumber`.
https://github.com/llvm/llvm-project/pull/90074
More information about the llvm-commits
mailing list