Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(801)

Side by Side Diff: test/compiler-unittests/common-node-cache-unittest.cc

Issue 456843004: Revert 23077 - "Use CommonNodeCache for heap constants in ChangeLowering." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/compiler/test-node-cache.cc ('k') | test/compiler-unittests/compiler-unittests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/compiler/common-node-cache.h"
6 #include "src/compiler/common-operator.h"
7 #include "src/compiler/graph.h"
8 #include "test/compiler-unittests/compiler-unittests.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10
11 using testing::AllOf;
12 using testing::IsNull;
13 using testing::NotNull;
14 using testing::Pointee;
15
16 namespace v8 {
17 namespace internal {
18 namespace compiler {
19
20 class CommonNodeCacheTest : public CompilerTest {
21 public:
22 CommonNodeCacheTest() : cache_(zone()), common_(zone()), graph_(zone()) {}
23 virtual ~CommonNodeCacheTest() {}
24
25 protected:
26 Factory* factory() const { return isolate()->factory(); }
27 CommonNodeCache* cache() { return &cache_; }
28 CommonOperatorBuilder* common() { return &common_; }
29 Graph* graph() { return &graph_; }
30
31 private:
32 CommonNodeCache cache_;
33 CommonOperatorBuilder common_;
34 Graph graph_;
35 };
36
37
38 TEST_F(CommonNodeCacheTest, FindInt32Constant) {
39 Node** l42 = cache()->FindInt32Constant(42);
40 ASSERT_THAT(l42, AllOf(NotNull(), Pointee(IsNull())));
41 Node* n42 = *l42 = graph()->NewNode(common()->Int32Constant(42));
42
43 Node** l0 = cache()->FindInt32Constant(0);
44 ASSERT_THAT(l0, AllOf(NotNull(), Pointee(IsNull())));
45 Node* n0 = *l0 = graph()->NewNode(common()->Int32Constant(0));
46
47 EXPECT_THAT(cache()->FindInt32Constant(42), AllOf(l42, Pointee(n42)));
48 EXPECT_THAT(cache()->FindInt32Constant(0), AllOf(l0, Pointee(n0)));
49 EXPECT_THAT(cache()->FindInt32Constant(42), AllOf(l42, Pointee(n42)));
50 EXPECT_THAT(cache()->FindInt32Constant(0), AllOf(l0, Pointee(n0)));
51 }
52
53
54 TEST_F(CommonNodeCacheTest, FindFloat64Constant) {
55 Node** l42 = cache()->FindFloat64Constant(42.0);
56 ASSERT_THAT(l42, AllOf(NotNull(), Pointee(IsNull())));
57 Node* n42 = *l42 = graph()->NewNode(common()->Float64Constant(42.0));
58
59 Node** l0 = cache()->FindFloat64Constant(0.0);
60 ASSERT_THAT(l0, AllOf(NotNull(), Pointee(IsNull())));
61 Node* n0 = *l0 = graph()->NewNode(common()->Float64Constant(0.0));
62
63 EXPECT_THAT(cache()->FindFloat64Constant(42.0), AllOf(l42, Pointee(n42)));
64 EXPECT_THAT(cache()->FindFloat64Constant(0.0), AllOf(l0, Pointee(n0)));
65 EXPECT_THAT(cache()->FindFloat64Constant(42.0), AllOf(l42, Pointee(n42)));
66 EXPECT_THAT(cache()->FindFloat64Constant(0.0), AllOf(l0, Pointee(n0)));
67 }
68
69
70 TEST_F(CommonNodeCacheTest, FindExternalConstant) {
71 ExternalReference i = ExternalReference::isolate_address(isolate());
72 Node** li = cache()->FindExternalConstant(i);
73 ASSERT_THAT(li, AllOf(NotNull(), Pointee(IsNull())));
74 Node* ni = *li = graph()->NewNode(common()->ExternalConstant(i));
75
76 ExternalReference m = ExternalReference::address_of_min_int();
77 Node** lm = cache()->FindExternalConstant(m);
78 ASSERT_THAT(lm, AllOf(NotNull(), Pointee(IsNull())));
79 Node* nm = *lm = graph()->NewNode(common()->ExternalConstant(m));
80
81 EXPECT_THAT(cache()->FindExternalConstant(i), AllOf(li, Pointee(ni)));
82 EXPECT_THAT(cache()->FindExternalConstant(m), AllOf(lm, Pointee(nm)));
83 EXPECT_THAT(cache()->FindExternalConstant(i), AllOf(li, Pointee(ni)));
84 EXPECT_THAT(cache()->FindExternalConstant(m), AllOf(lm, Pointee(nm)));
85 }
86
87
88 TEST_F(CommonNodeCacheTest, FindNumberConstant) {
89 Node** l42 = cache()->FindNumberConstant(42.0);
90 ASSERT_THAT(l42, AllOf(NotNull(), Pointee(IsNull())));
91 Node* n42 = *l42 = graph()->NewNode(common()->NumberConstant(42.0));
92
93 Node** l0 = cache()->FindNumberConstant(0.0);
94 ASSERT_THAT(l0, AllOf(NotNull(), Pointee(IsNull())));
95 Node* n0 = *l0 = graph()->NewNode(common()->NumberConstant(0.0));
96
97 EXPECT_THAT(cache()->FindNumberConstant(42.0), AllOf(l42, Pointee(n42)));
98 EXPECT_THAT(cache()->FindNumberConstant(0.0), AllOf(l0, Pointee(n0)));
99 EXPECT_THAT(cache()->FindNumberConstant(42.0), AllOf(l42, Pointee(n42)));
100 EXPECT_THAT(cache()->FindNumberConstant(0.0), AllOf(l0, Pointee(n0)));
101 }
102
103
104 TEST_F(CommonNodeCacheTest, FindHeapConstant) {
105 PrintableUnique<HeapObject> n = PrintableUnique<HeapObject>::CreateImmovable(
106 zone(), factory()->null_value());
107 Node** ln = cache()->FindHeapConstant(n);
108 ASSERT_THAT(ln, AllOf(NotNull(), Pointee(IsNull())));
109 Node* nn = *ln = graph()->NewNode(common()->HeapConstant(n));
110
111 PrintableUnique<HeapObject> t = PrintableUnique<HeapObject>::CreateImmovable(
112 zone(), factory()->true_value());
113 Node** lt = cache()->FindHeapConstant(t);
114 ASSERT_THAT(lt, AllOf(NotNull(), Pointee(IsNull())));
115 Node* nt = *lt = graph()->NewNode(common()->HeapConstant(t));
116
117 EXPECT_THAT(cache()->FindHeapConstant(n), AllOf(ln, Pointee(nn)));
118 EXPECT_THAT(cache()->FindHeapConstant(t), AllOf(lt, Pointee(nt)));
119 EXPECT_THAT(cache()->FindHeapConstant(n), AllOf(ln, Pointee(nn)));
120 EXPECT_THAT(cache()->FindHeapConstant(t), AllOf(lt, Pointee(nt)));
121 }
122
123 } // namespace compiler
124 } // namespace internal
125 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-node-cache.cc ('k') | test/compiler-unittests/compiler-unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698