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

Side by Side Diff: test/cctest/compiler/compiler/test-js-constant-cache.cc

Issue 426233002: Land the Fan (disabled) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback, rebase and "git cl format" 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
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/v8.h"
6
7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/node-properties-inl.h"
9 #include "src/compiler/typer.h"
10 #include "src/types.h"
11 #include "test/cctest/cctest.h"
12 #include "test/cctest/compiler/value-helper.h"
13
14 using namespace v8::internal;
15 using namespace v8::internal::compiler;
16
17 class JSCacheTesterHelper {
18 protected:
19 explicit JSCacheTesterHelper(Zone* zone)
20 : main_graph_(zone), main_common_(zone), main_typer_(zone) {}
21 Graph main_graph_;
22 CommonOperatorBuilder main_common_;
23 Typer main_typer_;
24 };
25
26
27 class JSConstantCacheTester : public HandleAndZoneScope,
28 public JSCacheTesterHelper,
29 public JSGraph {
30 public:
31 JSConstantCacheTester()
32 : JSCacheTesterHelper(main_zone()),
33 JSGraph(&main_graph_, &main_common_, &main_typer_) {}
34
35 Type* upper(Node* node) { return NodeProperties::GetBounds(node).upper; }
36
37 Handle<Object> handle(Node* node) {
38 CHECK_EQ(IrOpcode::kHeapConstant, node->opcode());
39 return ValueOf<Handle<Object> >(node->op());
40 }
41
42 Factory* factory() { return main_isolate()->factory(); }
43 };
44
45
46 TEST(ZeroConstant1) {
47 JSConstantCacheTester T;
48
49 Node* zero = T.ZeroConstant();
50
51 CHECK_EQ(IrOpcode::kNumberConstant, zero->opcode());
52 CHECK_EQ(zero, T.Constant(0));
53 CHECK_NE(zero, T.Constant(-0.0));
54 CHECK_NE(zero, T.Constant(1.0));
55 CHECK_NE(zero, T.Constant(v8::base::OS::nan_value()));
56 CHECK_NE(zero, T.Float64Constant(0));
57 CHECK_NE(zero, T.Int32Constant(0));
58
59 Type* t = T.upper(zero);
60
61 CHECK(t->Is(Type::Number()));
62 CHECK(t->Is(Type::Integral32()));
63 CHECK(t->Is(Type::Signed32()));
64 CHECK(t->Is(Type::Unsigned32()));
65 CHECK(t->Is(Type::SignedSmall()));
66 CHECK(t->Is(Type::UnsignedSmall()));
67 }
68
69
70 TEST(MinusZeroConstant) {
71 JSConstantCacheTester T;
72
73 Node* minus_zero = T.Constant(-0.0);
74 Node* zero = T.ZeroConstant();
75
76 CHECK_EQ(IrOpcode::kNumberConstant, minus_zero->opcode());
77 CHECK_EQ(minus_zero, T.Constant(-0.0));
78 CHECK_NE(zero, minus_zero);
79
80 Type* t = T.upper(minus_zero);
81
82 CHECK(t->Is(Type::Number()));
83 CHECK(t->Is(Type::MinusZero()));
84 CHECK(!t->Is(Type::Integral32()));
85 CHECK(!t->Is(Type::Signed32()));
86 CHECK(!t->Is(Type::Unsigned32()));
87 CHECK(!t->Is(Type::SignedSmall()));
88 CHECK(!t->Is(Type::UnsignedSmall()));
89
90 double zero_value = ValueOf<double>(zero->op());
91 double minus_zero_value = ValueOf<double>(minus_zero->op());
92
93 CHECK_EQ(0.0, zero_value);
94 CHECK_NE(-0.0, zero_value);
95 CHECK_EQ(-0.0, minus_zero_value);
96 CHECK_NE(0.0, minus_zero_value);
97 }
98
99
100 TEST(ZeroConstant2) {
101 JSConstantCacheTester T;
102
103 Node* zero = T.Constant(0);
104
105 CHECK_EQ(IrOpcode::kNumberConstant, zero->opcode());
106 CHECK_EQ(zero, T.ZeroConstant());
107 CHECK_NE(zero, T.Constant(-0.0));
108 CHECK_NE(zero, T.Constant(1.0));
109 CHECK_NE(zero, T.Constant(v8::base::OS::nan_value()));
110 CHECK_NE(zero, T.Float64Constant(0));
111 CHECK_NE(zero, T.Int32Constant(0));
112
113 Type* t = T.upper(zero);
114
115 CHECK(t->Is(Type::Number()));
116 CHECK(t->Is(Type::Integral32()));
117 CHECK(t->Is(Type::Signed32()));
118 CHECK(t->Is(Type::Unsigned32()));
119 CHECK(t->Is(Type::SignedSmall()));
120 CHECK(t->Is(Type::UnsignedSmall()));
121 }
122
123
124 TEST(OneConstant1) {
125 JSConstantCacheTester T;
126
127 Node* one = T.OneConstant();
128
129 CHECK_EQ(IrOpcode::kNumberConstant, one->opcode());
130 CHECK_EQ(one, T.Constant(1));
131 CHECK_EQ(one, T.Constant(1.0));
132 CHECK_NE(one, T.Constant(1.01));
133 CHECK_NE(one, T.Constant(-1.01));
134 CHECK_NE(one, T.Constant(v8::base::OS::nan_value()));
135 CHECK_NE(one, T.Float64Constant(1.0));
136 CHECK_NE(one, T.Int32Constant(1));
137
138 Type* t = T.upper(one);
139
140 CHECK(t->Is(Type::Number()));
141 CHECK(t->Is(Type::Integral32()));
142 CHECK(t->Is(Type::Signed32()));
143 CHECK(t->Is(Type::Unsigned32()));
144 CHECK(t->Is(Type::SignedSmall()));
145 CHECK(t->Is(Type::UnsignedSmall()));
146 }
147
148
149 TEST(OneConstant2) {
150 JSConstantCacheTester T;
151
152 Node* one = T.Constant(1);
153
154 CHECK_EQ(IrOpcode::kNumberConstant, one->opcode());
155 CHECK_EQ(one, T.OneConstant());
156 CHECK_EQ(one, T.Constant(1.0));
157 CHECK_NE(one, T.Constant(1.01));
158 CHECK_NE(one, T.Constant(-1.01));
159 CHECK_NE(one, T.Constant(v8::base::OS::nan_value()));
160 CHECK_NE(one, T.Float64Constant(1.0));
161 CHECK_NE(one, T.Int32Constant(1));
162
163 Type* t = T.upper(one);
164
165 CHECK(t->Is(Type::Number()));
166 CHECK(t->Is(Type::Integral32()));
167 CHECK(t->Is(Type::Signed32()));
168 CHECK(t->Is(Type::Unsigned32()));
169 CHECK(t->Is(Type::SignedSmall()));
170 CHECK(t->Is(Type::UnsignedSmall()));
171 }
172
173
174 TEST(Canonicalizations) {
175 JSConstantCacheTester T;
176
177 CHECK_EQ(T.ZeroConstant(), T.ZeroConstant());
178 CHECK_EQ(T.UndefinedConstant(), T.UndefinedConstant());
179 CHECK_EQ(T.TheHoleConstant(), T.TheHoleConstant());
180 CHECK_EQ(T.TrueConstant(), T.TrueConstant());
181 CHECK_EQ(T.FalseConstant(), T.FalseConstant());
182 CHECK_EQ(T.NullConstant(), T.NullConstant());
183 CHECK_EQ(T.ZeroConstant(), T.ZeroConstant());
184 CHECK_EQ(T.OneConstant(), T.OneConstant());
185 CHECK_EQ(T.NaNConstant(), T.NaNConstant());
186 }
187
188
189 TEST(NoAliasing) {
190 JSConstantCacheTester T;
191
192 Node* nodes[] = {T.UndefinedConstant(), T.TheHoleConstant(), T.TrueConstant(),
193 T.FalseConstant(), T.NullConstant(), T.ZeroConstant(),
194 T.OneConstant(), T.NaNConstant(), T.Constant(21),
195 T.Constant(22.2)};
196
197 for (size_t i = 0; i < ARRAY_SIZE(nodes); i++) {
198 for (size_t j = 0; j < ARRAY_SIZE(nodes); j++) {
199 if (i != j) CHECK_NE(nodes[i], nodes[j]);
200 }
201 }
202 }
203
204
205 TEST(CanonicalizingNumbers) {
206 JSConstantCacheTester T;
207
208 FOR_FLOAT64_INPUTS(i) {
209 Node* node = T.Constant(*i);
210 for (int j = 0; j < 5; j++) {
211 CHECK_EQ(node, T.Constant(*i));
212 }
213 }
214 }
215
216
217 TEST(NumberTypes) {
218 JSConstantCacheTester T;
219
220 FOR_FLOAT64_INPUTS(i) {
221 double value = *i;
222 Node* node = T.Constant(value);
223 CHECK(T.upper(node)->Equals(Type::Of(value, T.main_zone())));
224 }
225 }
226
227
228 TEST(HeapNumbers) {
229 JSConstantCacheTester T;
230
231 FOR_FLOAT64_INPUTS(i) {
232 double value = *i;
233 Handle<Object> num = T.factory()->NewNumber(value);
234 Handle<HeapNumber> heap = T.factory()->NewHeapNumber(value);
235 Node* node1 = T.Constant(value);
236 Node* node2 = T.Constant(num);
237 Node* node3 = T.Constant(heap);
238 CHECK_EQ(node1, node2);
239 CHECK_EQ(node1, node3);
240 }
241 }
242
243
244 TEST(OddballHandle) {
245 JSConstantCacheTester T;
246
247 CHECK_EQ(T.UndefinedConstant(), T.Constant(T.factory()->undefined_value()));
248 CHECK_EQ(T.TheHoleConstant(), T.Constant(T.factory()->the_hole_value()));
249 CHECK_EQ(T.TrueConstant(), T.Constant(T.factory()->true_value()));
250 CHECK_EQ(T.FalseConstant(), T.Constant(T.factory()->false_value()));
251 CHECK_EQ(T.NullConstant(), T.Constant(T.factory()->null_value()));
252 CHECK_EQ(T.NaNConstant(), T.Constant(T.factory()->nan_value()));
253 }
254
255
256 TEST(OddballValues) {
257 JSConstantCacheTester T;
258
259 CHECK_EQ(*T.factory()->undefined_value(), *T.handle(T.UndefinedConstant()));
260 CHECK_EQ(*T.factory()->the_hole_value(), *T.handle(T.TheHoleConstant()));
261 CHECK_EQ(*T.factory()->true_value(), *T.handle(T.TrueConstant()));
262 CHECK_EQ(*T.factory()->false_value(), *T.handle(T.FalseConstant()));
263 CHECK_EQ(*T.factory()->null_value(), *T.handle(T.NullConstant()));
264 }
265
266
267 TEST(OddballTypes) {
268 JSConstantCacheTester T;
269
270 CHECK(T.upper(T.UndefinedConstant())->Is(Type::Undefined()));
271 // TODO(dcarney): figure this out.
272 // CHECK(T.upper(T.TheHoleConstant())->Is(Type::Internal()));
273 CHECK(T.upper(T.TrueConstant())->Is(Type::Boolean()));
274 CHECK(T.upper(T.FalseConstant())->Is(Type::Boolean()));
275 CHECK(T.upper(T.NullConstant())->Is(Type::Null()));
276 CHECK(T.upper(T.ZeroConstant())->Is(Type::Number()));
277 CHECK(T.upper(T.OneConstant())->Is(Type::Number()));
278 CHECK(T.upper(T.NaNConstant())->Is(Type::NaN()));
279 }
280
281
282 TEST(ExternalReferences) {
283 // TODO(titzer): test canonicalization of external references.
284 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698