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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
| 7 #include "src/assembler.h" |
7 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/node-properties-inl.h" | 9 #include "src/compiler/node-properties-inl.h" |
9 #include "src/compiler/typer.h" | 10 #include "src/compiler/typer.h" |
10 #include "src/types.h" | 11 #include "src/types.h" |
11 #include "test/cctest/cctest.h" | 12 #include "test/cctest/cctest.h" |
12 #include "test/cctest/compiler/value-helper.h" | 13 #include "test/cctest/compiler/value-helper.h" |
13 | 14 |
14 using namespace v8::internal; | 15 using namespace v8::internal; |
15 using namespace v8::internal::compiler; | 16 using namespace v8::internal::compiler; |
16 | 17 |
17 class JSCacheTesterHelper { | 18 class JSCacheTesterHelper { |
18 protected: | 19 protected: |
19 explicit JSCacheTesterHelper(Zone* zone) | 20 explicit JSCacheTesterHelper(Zone* zone) |
20 : main_graph_(zone), | 21 : main_graph_(zone), |
21 main_common_(zone), | 22 main_common_(zone), |
22 main_javascript_(zone), | 23 main_javascript_(zone), |
23 main_typer_(zone), | 24 main_typer_(zone), |
24 main_machine_() {} | 25 main_machine_() {} |
25 Graph main_graph_; | 26 Graph main_graph_; |
26 CommonOperatorBuilder main_common_; | 27 CommonOperatorBuilder main_common_; |
27 JSOperatorBuilder main_javascript_; | 28 JSOperatorBuilder main_javascript_; |
28 Typer main_typer_; | 29 Typer main_typer_; |
29 MachineOperatorBuilder main_machine_; | 30 MachineOperatorBuilder main_machine_; |
30 }; | 31 }; |
31 | 32 |
32 | 33 |
| 34 // TODO(dcarney): JSConstantCacheTester inherits from JSGraph??? |
33 class JSConstantCacheTester : public HandleAndZoneScope, | 35 class JSConstantCacheTester : public HandleAndZoneScope, |
34 public JSCacheTesterHelper, | 36 public JSCacheTesterHelper, |
35 public JSGraph { | 37 public JSGraph { |
36 public: | 38 public: |
37 JSConstantCacheTester() | 39 JSConstantCacheTester() |
38 : JSCacheTesterHelper(main_zone()), | 40 : JSCacheTesterHelper(main_zone()), |
39 JSGraph(&main_graph_, &main_common_, &main_javascript_, &main_typer_, | 41 JSGraph(&main_graph_, &main_common_, &main_javascript_, &main_typer_, |
40 &main_machine_) {} | 42 &main_machine_) {} |
41 | 43 |
42 Type* upper(Node* node) { return NodeProperties::GetBounds(node).upper; } | 44 Type* upper(Node* node) { return NodeProperties::GetBounds(node).upper; } |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 CHECK(T.upper(T.NullConstant())->Is(Type::Null())); | 284 CHECK(T.upper(T.NullConstant())->Is(Type::Null())); |
283 CHECK(T.upper(T.ZeroConstant())->Is(Type::Number())); | 285 CHECK(T.upper(T.ZeroConstant())->Is(Type::Number())); |
284 CHECK(T.upper(T.OneConstant())->Is(Type::Number())); | 286 CHECK(T.upper(T.OneConstant())->Is(Type::Number())); |
285 CHECK(T.upper(T.NaNConstant())->Is(Type::NaN())); | 287 CHECK(T.upper(T.NaNConstant())->Is(Type::NaN())); |
286 } | 288 } |
287 | 289 |
288 | 290 |
289 TEST(ExternalReferences) { | 291 TEST(ExternalReferences) { |
290 // TODO(titzer): test canonicalization of external references. | 292 // TODO(titzer): test canonicalization of external references. |
291 } | 293 } |
| 294 |
| 295 |
| 296 static bool Contains(NodeVector* nodes, Node* n) { |
| 297 for (size_t i = 0; i < nodes->size(); i++) { |
| 298 if (nodes->at(i) == n) return true; |
| 299 } |
| 300 return false; |
| 301 } |
| 302 |
| 303 |
| 304 static void CheckGetCachedNodesContains(JSConstantCacheTester* T, Node* n) { |
| 305 NodeVector nodes(T->main_zone()); |
| 306 T->GetCachedNodes(&nodes); |
| 307 CHECK(Contains(&nodes, n)); |
| 308 } |
| 309 |
| 310 |
| 311 TEST(JSGraph_GetCachedNodes1) { |
| 312 JSConstantCacheTester T; |
| 313 CheckGetCachedNodesContains(&T, T.TrueConstant()); |
| 314 CheckGetCachedNodesContains(&T, T.UndefinedConstant()); |
| 315 CheckGetCachedNodesContains(&T, T.TheHoleConstant()); |
| 316 CheckGetCachedNodesContains(&T, T.TrueConstant()); |
| 317 CheckGetCachedNodesContains(&T, T.FalseConstant()); |
| 318 CheckGetCachedNodesContains(&T, T.NullConstant()); |
| 319 CheckGetCachedNodesContains(&T, T.ZeroConstant()); |
| 320 CheckGetCachedNodesContains(&T, T.OneConstant()); |
| 321 CheckGetCachedNodesContains(&T, T.NaNConstant()); |
| 322 } |
| 323 |
| 324 |
| 325 TEST(JSGraph_GetCachedNodes_int32) { |
| 326 JSConstantCacheTester T; |
| 327 |
| 328 int32_t constants[] = {0, 11, 12, 13, 14, 55, -55, -44, -33, -22, -11, |
| 329 0, 11, 11, 12, 12, 11, 11, -33, -33, -22, -11}; |
| 330 |
| 331 for (size_t i = 0; i < arraysize(constants); i++) { |
| 332 int count_before = T.graph()->NodeCount(); |
| 333 NodeVector nodes_before(T.main_zone()); |
| 334 T.GetCachedNodes(&nodes_before); |
| 335 Node* n = T.Int32Constant(constants[i]); |
| 336 if (n->id() < count_before) { |
| 337 // An old ID indicates a cached node. It should have been in the set. |
| 338 CHECK(Contains(&nodes_before, n)); |
| 339 } |
| 340 // Old or new, it should be in the cached set afterwards. |
| 341 CheckGetCachedNodesContains(&T, n); |
| 342 } |
| 343 } |
| 344 |
| 345 |
| 346 TEST(JSGraph_GetCachedNodes_float64) { |
| 347 JSConstantCacheTester T; |
| 348 |
| 349 double constants[] = {0, 11.1, 12.2, 13, 14, 55.5, -55.5, -44.4, |
| 350 -33, -22, -11, 0, 11.1, 11.1, 12.3, 12.3, |
| 351 11, 11, -33.3, -33.3, -22, -11}; |
| 352 |
| 353 for (size_t i = 0; i < arraysize(constants); i++) { |
| 354 int count_before = T.graph()->NodeCount(); |
| 355 NodeVector nodes_before(T.main_zone()); |
| 356 T.GetCachedNodes(&nodes_before); |
| 357 Node* n = T.Float64Constant(constants[i]); |
| 358 if (n->id() < count_before) { |
| 359 // An old ID indicates a cached node. It should have been in the set. |
| 360 CHECK(Contains(&nodes_before, n)); |
| 361 } |
| 362 // Old or new, it should be in the cached set afterwards. |
| 363 CheckGetCachedNodesContains(&T, n); |
| 364 } |
| 365 } |
| 366 |
| 367 |
| 368 TEST(JSGraph_GetCachedNodes_int64) { |
| 369 JSConstantCacheTester T; |
| 370 |
| 371 int32_t constants[] = {0, 11, 12, 13, 14, 55, -55, -44, -33, -22, -11, |
| 372 0, 11, 11, 12, 12, 11, 11, -33, -33, -22, -11}; |
| 373 |
| 374 for (size_t i = 0; i < arraysize(constants); i++) { |
| 375 int count_before = T.graph()->NodeCount(); |
| 376 NodeVector nodes_before(T.main_zone()); |
| 377 T.GetCachedNodes(&nodes_before); |
| 378 Node* n = T.Int64Constant(constants[i]); |
| 379 if (n->id() < count_before) { |
| 380 // An old ID indicates a cached node. It should have been in the set. |
| 381 CHECK(Contains(&nodes_before, n)); |
| 382 } |
| 383 // Old or new, it should be in the cached set afterwards. |
| 384 CheckGetCachedNodesContains(&T, n); |
| 385 } |
| 386 } |
| 387 |
| 388 |
| 389 TEST(JSGraph_GetCachedNodes_number) { |
| 390 JSConstantCacheTester T; |
| 391 |
| 392 double constants[] = {0, 11.1, 12.2, 13, 14, 55.5, -55.5, -44.4, |
| 393 -33, -22, -11, 0, 11.1, 11.1, 12.3, 12.3, |
| 394 11, 11, -33.3, -33.3, -22, -11}; |
| 395 |
| 396 for (size_t i = 0; i < arraysize(constants); i++) { |
| 397 int count_before = T.graph()->NodeCount(); |
| 398 NodeVector nodes_before(T.main_zone()); |
| 399 T.GetCachedNodes(&nodes_before); |
| 400 Node* n = T.Constant(constants[i]); |
| 401 if (n->id() < count_before) { |
| 402 // An old ID indicates a cached node. It should have been in the set. |
| 403 CHECK(Contains(&nodes_before, n)); |
| 404 } |
| 405 // Old or new, it should be in the cached set afterwards. |
| 406 CheckGetCachedNodesContains(&T, n); |
| 407 } |
| 408 } |
| 409 |
| 410 |
| 411 TEST(JSGraph_GetCachedNodes_external) { |
| 412 JSConstantCacheTester T; |
| 413 |
| 414 ExternalReference constants[] = {ExternalReference::address_of_min_int(), |
| 415 ExternalReference::address_of_min_int(), |
| 416 ExternalReference::address_of_min_int(), |
| 417 ExternalReference::address_of_one_half(), |
| 418 ExternalReference::address_of_one_half(), |
| 419 ExternalReference::address_of_min_int(), |
| 420 ExternalReference::address_of_the_hole_nan(), |
| 421 ExternalReference::address_of_one_half()}; |
| 422 |
| 423 for (size_t i = 0; i < arraysize(constants); i++) { |
| 424 int count_before = T.graph()->NodeCount(); |
| 425 NodeVector nodes_before(T.main_zone()); |
| 426 T.GetCachedNodes(&nodes_before); |
| 427 Node* n = T.ExternalConstant(constants[i]); |
| 428 if (n->id() < count_before) { |
| 429 // An old ID indicates a cached node. It should have been in the set. |
| 430 CHECK(Contains(&nodes_before, n)); |
| 431 } |
| 432 // Old or new, it should be in the cached set afterwards. |
| 433 CheckGetCachedNodesContains(&T, n); |
| 434 } |
| 435 } |
| 436 |
| 437 |
| 438 TEST(JSGraph_GetCachedNodes_together) { |
| 439 JSConstantCacheTester T; |
| 440 |
| 441 Node* constants[] = { |
| 442 T.TrueConstant(), |
| 443 T.UndefinedConstant(), |
| 444 T.TheHoleConstant(), |
| 445 T.TrueConstant(), |
| 446 T.FalseConstant(), |
| 447 T.NullConstant(), |
| 448 T.ZeroConstant(), |
| 449 T.OneConstant(), |
| 450 T.NaNConstant(), |
| 451 T.Int32Constant(0), |
| 452 T.Int32Constant(1), |
| 453 T.Int64Constant(-2), |
| 454 T.Int64Constant(-4), |
| 455 T.Float64Constant(0.9), |
| 456 T.Float64Constant(V8_INFINITY), |
| 457 T.Constant(0.99), |
| 458 T.Constant(1.11), |
| 459 T.ExternalConstant(ExternalReference::address_of_one_half())}; |
| 460 |
| 461 NodeVector nodes(T.main_zone()); |
| 462 T.GetCachedNodes(&nodes); |
| 463 |
| 464 for (size_t i = 0; i < arraysize(constants); i++) { |
| 465 CHECK(Contains(&nodes, constants[i])); |
| 466 } |
| 467 } |
OLD | NEW |