[llvm] [CGData] Outlined Hash Tree (PR #89792)
Ellis Hoag via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 18 10:17:50 PDT 2024
================
@@ -0,0 +1,131 @@
+//===-- OutlinedHashTree.cpp ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// An OutlinedHashTree is a Trie that contains sequences of stable hash values
+// of instructions that have been outlined. This OutlinedHashTree can be used
+// to understand the outlined instruction sequences collected across modules.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGenData/OutlinedHashTree.h"
+
+#include <stack>
+#include <tuple>
+
+#define DEBUG_TYPE "outlined-hash-tree"
+
+using namespace llvm;
+
+void OutlinedHashTree::walkGraph(NodeCallbackFn CallbackNode,
+ EdgeCallbackFn CallbackEdge,
+ bool SortedWalk) const {
+ SmallVector<const HashNode *> Stack;
+ Stack.emplace_back(getRoot());
+
+ while (!Stack.empty()) {
+ const auto *Current = Stack.pop_back_val();
+ if (CallbackNode)
+ CallbackNode(Current);
+
+ auto HandleNext = [&](const HashNode *Next) {
+ if (CallbackEdge)
+ CallbackEdge(Current, Next);
+ Stack.emplace_back(Next);
+ };
+ if (SortedWalk) {
+ std::map<stable_hash, const HashNode *> SortedSuccessors;
+ for (const auto &P : Current->Successors)
+ SortedSuccessors[P.first] = P.second.get();
----------------
ellishg wrote:
```suggestion
SmallVector<std::pair<stable_hash, const HashNode *>> SortedSuccessors;
for (const auto &P : Current->Successors)
SortedSuccessors.emplace_back(P.first, P.second.get());
llvm::stable_sort(SortedSuccessors);
// ...
```
I think you'll need to write your own comparator in the sort, but this might be slightly faster since you don't expect any duplicates.
Also, I think you can use `for (auto &[a, b] : Current->Successors)`
https://github.com/llvm/llvm-project/pull/89792
More information about the llvm-commits
mailing list