OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/access-builder.h" | 5 #include "src/compiler/access-builder.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/js-operator.h" | 7 #include "src/compiler/js-operator.h" |
8 #include "src/compiler/js-typed-lowering.h" | 8 #include "src/compiler/js-typed-lowering.h" |
9 #include "src/compiler/machine-operator.h" | 9 #include "src/compiler/machine-operator.h" |
10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
11 #include "test/unittests/compiler/compiler-test-utils.h" | 11 #include "test/unittests/compiler/compiler-test-utils.h" |
12 #include "test/unittests/compiler/graph-unittest.h" | 12 #include "test/unittests/compiler/graph-unittest.h" |
13 #include "test/unittests/compiler/node-test-utils.h" | 13 #include "test/unittests/compiler/node-test-utils.h" |
14 #include "testing/gmock-support.h" | 14 #include "testing/gmock-support.h" |
15 | 15 |
16 using testing::BitEq; | 16 using testing::BitEq; |
| 17 using testing::IsNaN; |
17 | 18 |
18 | 19 |
19 namespace v8 { | 20 namespace v8 { |
20 namespace internal { | 21 namespace internal { |
21 namespace compiler { | 22 namespace compiler { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 const ExternalArrayType kExternalArrayTypes[] = { | 26 const ExternalArrayType kExternalArrayTypes[] = { |
26 kExternalUint8Array, kExternalInt8Array, kExternalUint16Array, | 27 kExternalUint8Array, kExternalInt8Array, kExternalUint16Array, |
27 kExternalInt16Array, kExternalUint32Array, kExternalInt32Array, | 28 kExternalInt16Array, kExternalUint32Array, kExternalInt32Array, |
28 kExternalFloat32Array, kExternalFloat64Array}; | 29 kExternalFloat32Array, kExternalFloat64Array}; |
29 | 30 |
30 | 31 |
| 32 const double kFloat64Values[] = { |
| 33 -V8_INFINITY, -4.23878e+275, -5.82632e+265, -6.60355e+220, -6.26172e+212, |
| 34 -2.56222e+211, -4.82408e+201, -1.84106e+157, -1.63662e+127, -1.55772e+100, |
| 35 -1.67813e+72, -2.3382e+55, -3.179e+30, -1.441e+09, -1.0647e+09, |
| 36 -7.99361e+08, -5.77375e+08, -2.20984e+08, -32757, -13171, -9970, -3984, |
| 37 -107, -105, -92, -77, -61, -0.000208163, -1.86685e-06, -1.17296e-10, |
| 38 -9.26358e-11, -5.08004e-60, -1.74753e-65, -1.06561e-71, -5.67879e-79, |
| 39 -5.78459e-130, -2.90989e-171, -7.15489e-243, -3.76242e-252, -1.05639e-263, |
| 40 -4.40497e-267, -2.19666e-273, -4.9998e-276, -5.59821e-278, -2.03855e-282, |
| 41 -5.99335e-283, -7.17554e-284, -3.11744e-309, -0.0, 0.0, 2.22507e-308, |
| 42 1.30127e-270, 7.62898e-260, 4.00313e-249, 3.16829e-233, 1.85244e-228, |
| 43 2.03544e-129, 1.35126e-110, 1.01182e-106, 5.26333e-94, 1.35292e-90, |
| 44 2.85394e-83, 1.78323e-77, 5.4967e-57, 1.03207e-25, 4.57401e-25, 1.58738e-05, |
| 45 2, 125, 2310, 9636, 14802, 17168, 28945, 29305, 4.81336e+07, 1.41207e+08, |
| 46 4.65962e+08, 1.40499e+09, 2.12648e+09, 8.80006e+30, 1.4446e+45, 1.12164e+54, |
| 47 2.48188e+89, 6.71121e+102, 3.074e+112, 4.9699e+152, 5.58383e+166, |
| 48 4.30654e+172, 7.08824e+185, 9.6586e+214, 2.028e+223, 6.63277e+243, |
| 49 1.56192e+261, 1.23202e+269, 5.72883e+289, 8.5798e+290, 1.40256e+294, |
| 50 1.79769e+308, V8_INFINITY}; |
| 51 |
| 52 |
31 const size_t kIndices[] = {0, 1, 42, 100, 1024}; | 53 const size_t kIndices[] = {0, 1, 42, 100, 1024}; |
32 | 54 |
33 | 55 |
| 56 const double kIntegerValues[] = {-V8_INFINITY, INT_MIN, -1000.0, -42.0, |
| 57 -1.0, 0.0, 1.0, 42.0, |
| 58 1000.0, INT_MAX, UINT_MAX, V8_INFINITY}; |
| 59 |
| 60 |
34 Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(), | 61 Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(), |
35 Type::Number(), Type::String(), Type::Object()}; | 62 Type::Number(), Type::String(), Type::Object()}; |
36 | 63 |
37 | 64 |
38 const StrictMode kStrictModes[] = {SLOPPY, STRICT}; | 65 const StrictMode kStrictModes[] = {SLOPPY, STRICT}; |
39 | 66 |
40 } // namespace | 67 } // namespace |
41 | 68 |
42 | 69 |
43 class JSTypedLoweringTest : public TypedGraphTest { | 70 class JSTypedLoweringTest : public TypedGraphTest { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 Node* input = Parameter(Type::Any(), 0); | 173 Node* input = Parameter(Type::Any(), 0); |
147 Node* context = Parameter(Type::Any(), 1); | 174 Node* context = Parameter(Type::Any(), 1); |
148 Reduction r = | 175 Reduction r = |
149 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); | 176 Reduce(graph()->NewNode(javascript()->UnaryNot(), input, context)); |
150 ASSERT_TRUE(r.Changed()); | 177 ASSERT_TRUE(r.Changed()); |
151 EXPECT_THAT(r.replacement(), IsBooleanNot(IsAnyToBoolean(input))); | 178 EXPECT_THAT(r.replacement(), IsBooleanNot(IsAnyToBoolean(input))); |
152 } | 179 } |
153 | 180 |
154 | 181 |
155 // ----------------------------------------------------------------------------- | 182 // ----------------------------------------------------------------------------- |
| 183 // Constant propagation |
| 184 |
| 185 |
| 186 TEST_F(JSTypedLoweringTest, ParameterWithMinusZero) { |
| 187 { |
| 188 Reduction r = Reduce( |
| 189 Parameter(Type::Constant(factory()->minus_zero_value(), zone()))); |
| 190 ASSERT_TRUE(r.Changed()); |
| 191 EXPECT_THAT(r.replacement(), IsNumberConstant(-0.0)); |
| 192 } |
| 193 { |
| 194 Reduction r = Reduce(Parameter(Type::MinusZero())); |
| 195 ASSERT_TRUE(r.Changed()); |
| 196 EXPECT_THAT(r.replacement(), IsNumberConstant(-0.0)); |
| 197 } |
| 198 { |
| 199 Reduction r = Reduce(Parameter( |
| 200 Type::Union(Type::MinusZero(), |
| 201 Type::Constant(factory()->NewNumber(0), zone()), zone()))); |
| 202 EXPECT_FALSE(r.Changed()); |
| 203 } |
| 204 } |
| 205 |
| 206 |
| 207 TEST_F(JSTypedLoweringTest, ParameterWithNull) { |
| 208 Handle<HeapObject> null = factory()->null_value(); |
| 209 { |
| 210 Reduction r = Reduce(Parameter(Type::Constant(null, zone()))); |
| 211 ASSERT_TRUE(r.Changed()); |
| 212 EXPECT_THAT(r.replacement(), |
| 213 IsHeapConstant(Unique<HeapObject>::CreateImmovable(null))); |
| 214 } |
| 215 { |
| 216 Reduction r = Reduce(Parameter(Type::Null())); |
| 217 ASSERT_TRUE(r.Changed()); |
| 218 EXPECT_THAT(r.replacement(), |
| 219 IsHeapConstant(Unique<HeapObject>::CreateImmovable(null))); |
| 220 } |
| 221 } |
| 222 |
| 223 |
| 224 TEST_F(JSTypedLoweringTest, ParameterWithNaN) { |
| 225 const double kNaNs[] = {base::OS::nan_value(), |
| 226 std::numeric_limits<double>::quiet_NaN(), |
| 227 std::numeric_limits<double>::signaling_NaN()}; |
| 228 TRACED_FOREACH(double, nan, kNaNs) { |
| 229 Handle<Object> constant = factory()->NewNumber(nan); |
| 230 Reduction r = Reduce(Parameter(Type::Constant(constant, zone()))); |
| 231 ASSERT_TRUE(r.Changed()); |
| 232 EXPECT_THAT(r.replacement(), IsNumberConstant(IsNaN())); |
| 233 } |
| 234 { |
| 235 Reduction r = |
| 236 Reduce(Parameter(Type::Constant(factory()->nan_value(), zone()))); |
| 237 ASSERT_TRUE(r.Changed()); |
| 238 EXPECT_THAT(r.replacement(), IsNumberConstant(IsNaN())); |
| 239 } |
| 240 { |
| 241 Reduction r = Reduce(Parameter(Type::NaN())); |
| 242 ASSERT_TRUE(r.Changed()); |
| 243 EXPECT_THAT(r.replacement(), IsNumberConstant(IsNaN())); |
| 244 } |
| 245 } |
| 246 |
| 247 |
| 248 TEST_F(JSTypedLoweringTest, ParameterWithPlainNumber) { |
| 249 TRACED_FOREACH(double, value, kFloat64Values) { |
| 250 Handle<Object> constant = factory()->NewNumber(value); |
| 251 Reduction r = Reduce(Parameter(Type::Constant(constant, zone()))); |
| 252 ASSERT_TRUE(r.Changed()); |
| 253 EXPECT_THAT(r.replacement(), IsNumberConstant(value)); |
| 254 } |
| 255 TRACED_FOREACH(double, value, kIntegerValues) { |
| 256 Handle<Object> constant = factory()->NewNumber(value); |
| 257 Reduction r = Reduce(Parameter(Type::Range(constant, constant, zone()))); |
| 258 ASSERT_TRUE(r.Changed()); |
| 259 EXPECT_THAT(r.replacement(), IsNumberConstant(value)); |
| 260 } |
| 261 } |
| 262 |
| 263 |
| 264 TEST_F(JSTypedLoweringTest, ParameterWithUndefined) { |
| 265 Handle<HeapObject> undefined = factory()->undefined_value(); |
| 266 { |
| 267 Reduction r = Reduce(Parameter(Type::Undefined())); |
| 268 ASSERT_TRUE(r.Changed()); |
| 269 EXPECT_THAT(r.replacement(), |
| 270 IsHeapConstant(Unique<HeapObject>::CreateImmovable(undefined))); |
| 271 } |
| 272 { |
| 273 Reduction r = Reduce(Parameter(Type::Constant(undefined, zone()))); |
| 274 ASSERT_TRUE(r.Changed()); |
| 275 EXPECT_THAT(r.replacement(), |
| 276 IsHeapConstant(Unique<HeapObject>::CreateImmovable(undefined))); |
| 277 } |
| 278 } |
| 279 |
| 280 |
| 281 // ----------------------------------------------------------------------------- |
156 // JSToBoolean | 282 // JSToBoolean |
157 | 283 |
158 | 284 |
159 TEST_F(JSTypedLoweringTest, JSToBooleanWithBoolean) { | 285 TEST_F(JSTypedLoweringTest, JSToBooleanWithBoolean) { |
160 Node* input = Parameter(Type::Boolean(), 0); | 286 Node* input = Parameter(Type::Boolean(), 0); |
161 Node* context = Parameter(Type::Any(), 1); | 287 Node* context = Parameter(Type::Any(), 1); |
162 Reduction r = | 288 Reduction r = |
163 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context)); | 289 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context)); |
164 ASSERT_TRUE(r.Changed()); | 290 ASSERT_TRUE(r.Changed()); |
165 EXPECT_EQ(input, r.replacement()); | 291 EXPECT_EQ(input, r.replacement()); |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 IsStoreElement( | 799 IsStoreElement( |
674 access, IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), | 800 access, IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), |
675 key, value, effect, control)); | 801 key, value, effect, control)); |
676 } | 802 } |
677 } | 803 } |
678 } | 804 } |
679 | 805 |
680 } // namespace compiler | 806 } // namespace compiler |
681 } // namespace internal | 807 } // namespace internal |
682 } // namespace v8 | 808 } // namespace v8 |
OLD | NEW |