Skip to content

Commit

Permalink
Address feedback #2 from ellishg + clean-up header inclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
kyulee-com authored and Kyungwoo Lee committed Jul 6, 2024
1 parent 40eaed6 commit c6fa20b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
1 change: 1 addition & 0 deletions llvm/include/llvm/CodeGenData/OutlinedHashTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef LLVM_CODEGENDATA_OUTLINEDHASHTREE_H
#define LLVM_CODEGENDATA_OUTLINEDHASHTREE_H

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StableHashing.h"
#include "llvm/ObjectYAML/YAML.h"
#include "llvm/Support/raw_ostream.h"
Expand Down
1 change: 0 additions & 1 deletion llvm/include/llvm/CodeGenData/OutlinedHashTreeRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#ifndef LLVM_CODEGENDATA_OUTLINEDHASHTREERECORD_H
#define LLVM_CODEGENDATA_OUTLINEDHASHTREERECORD_H

#include "llvm/ADT/DenseMap.h"
#include "llvm/CodeGenData/OutlinedHashTree.h"

namespace llvm {
Expand Down
12 changes: 5 additions & 7 deletions llvm/lib/CodeGenData/OutlinedHashTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

#include "llvm/CodeGenData/OutlinedHashTree.h"

#include <stack>
#include <tuple>

#define DEBUG_TYPE "outlined-hash-tree"

using namespace llvm;
Expand All @@ -38,9 +35,10 @@ void OutlinedHashTree::walkGraph(NodeCallbackFn CallbackNode,
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();
SmallVector<std::pair<stable_hash, const HashNode *>> SortedSuccessors;
for (const auto &[Hash, Successor] : Current->Successors)
SortedSuccessors.emplace_back(Hash, Successor.get());
llvm::sort(SortedSuccessors);
for (const auto &P : SortedSuccessors)
HandleNext(P.second);
} else {
Expand All @@ -60,7 +58,7 @@ size_t OutlinedHashTree::size(bool GetTerminalCountOnly) const {

size_t OutlinedHashTree::depth() const {
size_t Size = 0;
std::unordered_map<const HashNode *, size_t> DepthMap;
DenseMap<const HashNode *, size_t> DepthMap;
walkGraph([&Size, &DepthMap](
const HashNode *N) { Size = std::max(Size, DepthMap[N]); },
[&DepthMap](const HashNode *Src, const HashNode *Dst) {
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/CodeGenData/OutlinedHashTreeRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
//===----------------------------------------------------------------------===//

#include "llvm/CodeGenData/OutlinedHashTreeRecord.h"
#include "llvm/CodeGenData/OutlinedHashTree.h"
#include "llvm/ObjectYAML/YAML.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/EndianStream.h"
Expand Down
24 changes: 12 additions & 12 deletions llvm/unittests/CodeGenData/OutlinedHashTreeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ namespace {

TEST(OutlinedHashTreeTest, Empty) {
OutlinedHashTree HashTree;
ASSERT_TRUE(HashTree.empty());
EXPECT_TRUE(HashTree.empty());
// The header node is always present.
ASSERT_TRUE(HashTree.size() == 1);
ASSERT_TRUE(HashTree.depth() == 0);
EXPECT_EQ(HashTree.size(), 1);
EXPECT_EQ(HashTree.depth(), 0);
}

TEST(OutlinedHashTreeTest, Insert) {
OutlinedHashTree HashTree;
HashTree.insert({{1, 2, 3}, 1});
// The node count is 4 (including the root node).
ASSERT_TRUE(HashTree.size() == 4);
EXPECT_EQ(HashTree.size(), 4);
// The terminal count is 1.
ASSERT_TRUE(HashTree.size(/*GetTerminalCountOnly=*/true) == 1);
EXPECT_EQ(HashTree.size(/*GetTerminalCountOnly=*/true), 1);
// The depth is 3.
ASSERT_TRUE(HashTree.depth() == 3);
EXPECT_EQ(HashTree.depth(), 3);

HashTree.clear();
ASSERT_TRUE(HashTree.empty());
EXPECT_TRUE(HashTree.empty());

HashTree.insert({{1, 2, 3}, 1});
HashTree.insert({{1, 2, 4}, 2});
// The nodes of 1 and 2 are shared with the same prefix.
// The nodes are root, 1, 2, 3 and 4, whose counts are 5.
ASSERT_TRUE(HashTree.size() == 5);
EXPECT_EQ(HashTree.size(), 5);
}

TEST(OutlinedHashTreeTest, Find) {
Expand All @@ -48,11 +48,11 @@ TEST(OutlinedHashTreeTest, Find) {
HashTree.insert({{1, 2, 3}, 2});

// The node count does not change as the same sequences are added.
ASSERT_TRUE(HashTree.size() == 4);
EXPECT_EQ(HashTree.size(), 4);
// The terminal counts are accumulated from two same sequences.
ASSERT_TRUE(HashTree.find({1, 2, 3}));
ASSERT_TRUE(HashTree.find({1, 2, 3}).value() == 3);
ASSERT_FALSE(HashTree.find({1, 2}));
EXPECT_TRUE(HashTree.find({1, 2, 3}));
EXPECT_EQ(HashTree.find({1, 2, 3}).value(), 3);
EXPECT_FALSE(HashTree.find({1, 2}));
}

TEST(OutlinedHashTreeTest, Merge) {
Expand Down

0 comments on commit c6fa20b

Please sign in to comment.