Skip to content

Commit 37d2944

Browse files
kyulee-comKyungwoo Lee
authored and
Kyungwoo Lee
committed
Address feedback #2 from ellishg + clean-up header inclusion
1 parent 40eaed6 commit 37d2944

File tree

6 files changed

+4463
-22
lines changed

6 files changed

+4463
-22
lines changed

llvm/include/llvm/CodeGenData/OutlinedHashTree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef LLVM_CODEGENDATA_OUTLINEDHASHTREE_H
1616
#define LLVM_CODEGENDATA_OUTLINEDHASHTREE_H
1717

18+
#include "llvm/ADT/DenseMap.h"
1819
#include "llvm/ADT/StableHashing.h"
1920
#include "llvm/ObjectYAML/YAML.h"
2021
#include "llvm/Support/raw_ostream.h"

llvm/include/llvm/CodeGenData/OutlinedHashTreeRecord.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#ifndef LLVM_CODEGENDATA_OUTLINEDHASHTREERECORD_H
1717
#define LLVM_CODEGENDATA_OUTLINEDHASHTREERECORD_H
1818

19-
#include "llvm/ADT/DenseMap.h"
2019
#include "llvm/CodeGenData/OutlinedHashTree.h"
2120

2221
namespace llvm {
@@ -38,7 +37,7 @@ struct OutlinedHashTreeRecord {
3837

3938
OutlinedHashTreeRecord() { HashTree = std::make_unique<OutlinedHashTree>(); }
4039
OutlinedHashTreeRecord(std::unique_ptr<OutlinedHashTree> HashTree)
41-
: HashTree(std::move(HashTree)){};
40+
: HashTree(std::move(HashTree)) {};
4241

4342
/// Serialize the outlined hash tree to a raw_ostream.
4443
void serialize(raw_ostream &OS) const;

llvm/lib/CodeGenData/OutlinedHashTree.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
#include "llvm/CodeGenData/OutlinedHashTree.h"
1616

17-
#include <stack>
18-
#include <tuple>
19-
2017
#define DEBUG_TYPE "outlined-hash-tree"
2118

2219
using namespace llvm;
@@ -38,9 +35,10 @@ void OutlinedHashTree::walkGraph(NodeCallbackFn CallbackNode,
3835
Stack.emplace_back(Next);
3936
};
4037
if (SortedWalk) {
41-
std::map<stable_hash, const HashNode *> SortedSuccessors;
42-
for (const auto &P : Current->Successors)
43-
SortedSuccessors[P.first] = P.second.get();
38+
SmallVector<std::pair<stable_hash, const HashNode *>> SortedSuccessors;
39+
for (const auto &[Hash, Successor] : Current->Successors)
40+
SortedSuccessors.emplace_back(Hash, Successor.get());
41+
llvm::sort(SortedSuccessors);
4442
for (const auto &P : SortedSuccessors)
4543
HandleNext(P.second);
4644
} else {
@@ -60,7 +58,7 @@ size_t OutlinedHashTree::size(bool GetTerminalCountOnly) const {
6058

6159
size_t OutlinedHashTree::depth() const {
6260
size_t Size = 0;
63-
std::unordered_map<const HashNode *, size_t> DepthMap;
61+
DenseMap<const HashNode *, size_t> DepthMap;
6462
walkGraph([&Size, &DepthMap](
6563
const HashNode *N) { Size = std::max(Size, DepthMap[N]); },
6664
[&DepthMap](const HashNode *Src, const HashNode *Dst) {

llvm/lib/CodeGenData/OutlinedHashTreeRecord.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
//===----------------------------------------------------------------------===//
1515

1616
#include "llvm/CodeGenData/OutlinedHashTreeRecord.h"
17-
#include "llvm/CodeGenData/OutlinedHashTree.h"
1817
#include "llvm/ObjectYAML/YAML.h"
1918
#include "llvm/Support/Endian.h"
2019
#include "llvm/Support/EndianStream.h"

llvm/unittests/CodeGenData/OutlinedHashTreeTest.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,30 @@ namespace {
1616

1717
TEST(OutlinedHashTreeTest, Empty) {
1818
OutlinedHashTree HashTree;
19-
ASSERT_TRUE(HashTree.empty());
19+
EXPECT_TRUE(HashTree.empty());
2020
// The header node is always present.
21-
ASSERT_TRUE(HashTree.size() == 1);
22-
ASSERT_TRUE(HashTree.depth() == 0);
21+
EXPECT_EQ(HashTree.size(), 1);
22+
EXPECT_EQ(HashTree.depth(), 0);
2323
}
2424

2525
TEST(OutlinedHashTreeTest, Insert) {
2626
OutlinedHashTree HashTree;
2727
HashTree.insert({{1, 2, 3}, 1});
2828
// The node count is 4 (including the root node).
29-
ASSERT_TRUE(HashTree.size() == 4);
29+
EXPECT_EQ(HashTree.size(), 4);
3030
// The terminal count is 1.
31-
ASSERT_TRUE(HashTree.size(/*GetTerminalCountOnly=*/true) == 1);
31+
EXPECT_EQ(HashTree.size(/*GetTerminalCountOnly=*/true), 1);
3232
// The depth is 3.
33-
ASSERT_TRUE(HashTree.depth() == 3);
33+
EXPECT_EQ(HashTree.depth(), 3);
3434

3535
HashTree.clear();
36-
ASSERT_TRUE(HashTree.empty());
36+
EXPECT_TRUE(HashTree.empty());
3737

3838
HashTree.insert({{1, 2, 3}, 1});
3939
HashTree.insert({{1, 2, 4}, 2});
4040
// The nodes of 1 and 2 are shared with the same prefix.
4141
// The nodes are root, 1, 2, 3 and 4, whose counts are 5.
42-
ASSERT_TRUE(HashTree.size() == 5);
42+
EXPECT_EQ(HashTree.size(), 5);
4343
}
4444

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

5050
// The node count does not change as the same sequences are added.
51-
ASSERT_TRUE(HashTree.size() == 4);
51+
EXPECT_EQ(HashTree.size(), 4);
5252
// The terminal counts are accumulated from two same sequences.
53-
ASSERT_TRUE(HashTree.find({1, 2, 3}));
54-
ASSERT_TRUE(HashTree.find({1, 2, 3}).value() == 3);
55-
ASSERT_FALSE(HashTree.find({1, 2}));
53+
EXPECT_TRUE(HashTree.find({1, 2, 3}));
54+
EXPECT_EQ(HashTree.find({1, 2, 3}).value(), 3);
55+
EXPECT_FALSE(HashTree.find({1, 2}));
5656
}
5757

5858
TEST(OutlinedHashTreeTest, Merge) {

0 commit comments

Comments
 (0)