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

Side by Side Diff: test/unittests/compiler/typer-unittest.cc

Issue 2754003007: [compiler] Add even more tests for monotonicity of typing. (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 <functional> 5 #include <functional>
6 6
7 #include "src/codegen.h" 7 #include "src/codegen.h"
8 #include "src/compiler/js-operator.h" 8 #include "src/compiler/js-operator.h"
9 #include "src/compiler/node-properties.h" 9 #include "src/compiler/node-properties.h"
10 #include "src/compiler/operator-properties.h" 10 #include "src/compiler/operator-properties.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 OperationTyper operation_typer_; 58 OperationTyper operation_typer_;
59 Types types_; 59 Types types_;
60 JSOperatorBuilder javascript_; 60 JSOperatorBuilder javascript_;
61 SimplifiedOperatorBuilder simplified_; 61 SimplifiedOperatorBuilder simplified_;
62 BinaryOperationHint const hints_ = BinaryOperationHint::kAny; 62 BinaryOperationHint const hints_ = BinaryOperationHint::kAny;
63 Node* context_node_; 63 Node* context_node_;
64 v8::base::RandomNumberGenerator* rng_; 64 v8::base::RandomNumberGenerator* rng_;
65 std::vector<double> integers; 65 std::vector<double> integers;
66 std::vector<double> int32s; 66 std::vector<double> int32s;
67 67
68 Type* TypeUnaryOp(const Operator* op, Type* type0) {
69 Node* p0 = Parameter(0);
70 NodeProperties::SetType(p0, type0);
71 std::vector<Node*> inputs;
72 inputs.push_back(p0);
73 if (OperatorProperties::HasContextInput(op)) {
74 inputs.push_back(context_node_);
75 }
76 for (int i = 0; i < OperatorProperties::GetFrameStateInputCount(op); i++) {
77 inputs.push_back(EmptyFrameState());
78 }
79 for (int i = 0; i < op->EffectInputCount(); i++) {
80 inputs.push_back(graph()->start());
81 }
82 for (int i = 0; i < op->ControlInputCount(); i++) {
83 inputs.push_back(graph()->start());
84 }
85 Node* n = graph()->NewNode(op, static_cast<int>(inputs.size()),
86 &(inputs.front()));
87 return NodeProperties::GetType(n);
88 }
89
68 Type* TypeBinaryOp(const Operator* op, Type* lhs, Type* rhs) { 90 Type* TypeBinaryOp(const Operator* op, Type* lhs, Type* rhs) {
69 Node* p0 = Parameter(0); 91 Node* p0 = Parameter(0);
70 Node* p1 = Parameter(1); 92 Node* p1 = Parameter(1);
71 NodeProperties::SetType(p0, lhs); 93 NodeProperties::SetType(p0, lhs);
72 NodeProperties::SetType(p1, rhs); 94 NodeProperties::SetType(p1, rhs);
73 std::vector<Node*> inputs; 95 std::vector<Node*> inputs;
74 inputs.push_back(p0); 96 inputs.push_back(p0);
75 inputs.push_back(p1); 97 inputs.push_back(p1);
76 if (OperatorProperties::HasContextInput(op)) { 98 if (OperatorProperties::HasContextInput(op)) {
77 inputs.push_back(context_node_); 99 inputs.push_back(context_node_);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 DCHECK(type2->Is(upper2)); 269 DCHECK(type2->Is(upper2));
248 Type* type = typer(type1, type2); 270 Type* type = typer(type1, type2);
249 271
250 Type* subtype1 = RandomSubtype(type1); 272 Type* subtype1 = RandomSubtype(type1);
251 Type* subtype2 = RandomSubtype(type2); 273 Type* subtype2 = RandomSubtype(type2);
252 Type* subtype = typer(subtype1, subtype2); 274 Type* subtype = typer(subtype1, subtype2);
253 275
254 EXPECT_TRUE(subtype->Is(type)); 276 EXPECT_TRUE(subtype->Is(type));
255 } 277 }
256 278
279 void TestUnaryMonotonicity(const Operator* op, Type* upper1 = Type::Any()) {
280 UnaryTyper typer = [&](Type* type1) { return TypeUnaryOp(op, type1); };
281 for (int i = 0; i < kRepetitions; ++i) {
282 TestUnaryMonotonicity(typer, upper1);
283 }
284 }
285
257 void TestBinaryMonotonicity(const Operator* op, Type* upper1 = Type::Any(), 286 void TestBinaryMonotonicity(const Operator* op, Type* upper1 = Type::Any(),
258 Type* upper2 = Type::Any()) { 287 Type* upper2 = Type::Any()) {
259 BinaryTyper typer = [&](Type* type1, Type* type2) { 288 BinaryTyper typer = [&](Type* type1, Type* type2) {
260 return TypeBinaryOp(op, type1, type2); 289 return TypeBinaryOp(op, type1, type2);
261 }; 290 };
262 for (int i = 0; i < kRepetitions; ++i) { 291 for (int i = 0; i < kRepetitions; ++i) {
263 TestBinaryMonotonicity(typer, upper1, upper2); 292 TestBinaryMonotonicity(typer, upper1, upper2);
264 } 293 }
265 } 294 }
266 }; 295 };
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 412
384 // For numbers there's no difference between strict and non-strict equality. 413 // For numbers there's no difference between strict and non-strict equality.
385 TEST_F(TyperTest, TypeJSStrictEqual) { 414 TEST_F(TyperTest, TypeJSStrictEqual) {
386 TestBinaryCompareOp(javascript_.StrictEqual(CompareOperationHint::kAny), 415 TestBinaryCompareOp(javascript_.StrictEqual(CompareOperationHint::kAny),
387 std::equal_to<double>()); 416 std::equal_to<double>());
388 } 417 }
389 418
390 //------------------------------------------------------------------------------ 419 //------------------------------------------------------------------------------
391 // Typer Monotonicity 420 // Typer Monotonicity
392 421
422 // JS UNOPs without hint
423 #define TEST_MONOTONICITY(name) \
424 TEST_F(TyperTest, Monotonicity_##name) { \
425 TestUnaryMonotonicity(javascript_.name()); \
426 }
427 TEST_MONOTONICITY(ToInteger)
428 TEST_MONOTONICITY(ToLength)
429 TEST_MONOTONICITY(ToName)
430 TEST_MONOTONICITY(ToNumber)
431 TEST_MONOTONICITY(ToObject)
432 TEST_MONOTONICITY(ToString)
433 TEST_MONOTONICITY(ClassOf)
434 TEST_MONOTONICITY(TypeOf)
435 #undef TEST_MONOTONICITY
436
437 // JS UNOPs with ToBooleanHint
438 #define TEST_MONOTONICITY(name) \
439 TEST_F(TyperTest, Monotonicity_##name) { \
440 TestUnaryMonotonicity(javascript_.name(ToBooleanHint())); \
441 }
442 TEST_MONOTONICITY(ToBoolean)
443 #undef TEST_MONOTONICITY
444
393 // JS BINOPs with CompareOperationHint 445 // JS BINOPs with CompareOperationHint
394 #define TEST_MONOTONICITY(name) \ 446 #define TEST_MONOTONICITY(name) \
395 TEST_F(TyperTest, Monotonicity_##name) { \ 447 TEST_F(TyperTest, Monotonicity_##name) { \
396 TestBinaryMonotonicity(javascript_.name(CompareOperationHint::kAny)); \ 448 TestBinaryMonotonicity(javascript_.name(CompareOperationHint::kAny)); \
397 } 449 }
398 TEST_MONOTONICITY(Equal) 450 TEST_MONOTONICITY(Equal)
399 TEST_MONOTONICITY(StrictEqual) 451 TEST_MONOTONICITY(StrictEqual)
400 TEST_MONOTONICITY(LessThan) 452 TEST_MONOTONICITY(LessThan)
401 TEST_MONOTONICITY(GreaterThan) 453 TEST_MONOTONICITY(GreaterThan)
402 TEST_MONOTONICITY(LessThanOrEqual) 454 TEST_MONOTONICITY(LessThanOrEqual)
(...skipping 16 matching lines...) Expand all
419 TEST_MONOTONICITY(BitwiseOr) 471 TEST_MONOTONICITY(BitwiseOr)
420 TEST_MONOTONICITY(BitwiseXor) 472 TEST_MONOTONICITY(BitwiseXor)
421 TEST_MONOTONICITY(BitwiseAnd) 473 TEST_MONOTONICITY(BitwiseAnd)
422 TEST_MONOTONICITY(ShiftLeft) 474 TEST_MONOTONICITY(ShiftLeft)
423 TEST_MONOTONICITY(ShiftRight) 475 TEST_MONOTONICITY(ShiftRight)
424 TEST_MONOTONICITY(ShiftRightLogical) 476 TEST_MONOTONICITY(ShiftRightLogical)
425 TEST_MONOTONICITY(Subtract) 477 TEST_MONOTONICITY(Subtract)
426 TEST_MONOTONICITY(Multiply) 478 TEST_MONOTONICITY(Multiply)
427 TEST_MONOTONICITY(Divide) 479 TEST_MONOTONICITY(Divide)
428 TEST_MONOTONICITY(Modulus) 480 TEST_MONOTONICITY(Modulus)
481 TEST_MONOTONICITY(InstanceOf)
482 TEST_MONOTONICITY(OrdinaryHasInstance)
429 #undef TEST_MONOTONICITY 483 #undef TEST_MONOTONICITY
430 484
431 // SIMPLIFIED BINOPs without hint, with Number input restriction 485 // SIMPLIFIED BINOPs without hint, with Number input restriction
432 #define TEST_MONOTONICITY(name) \ 486 #define TEST_MONOTONICITY(name) \
433 TEST_F(TyperTest, Monotonicity_##name) { \ 487 TEST_F(TyperTest, Monotonicity_##name) { \
434 TestBinaryMonotonicity(simplified_.name(), Type::Number(), \ 488 TestBinaryMonotonicity(simplified_.name(), Type::Number(), \
435 Type::Number()); \ 489 Type::Number()); \
436 } 490 }
437 SIMPLIFIED_NUMBER_BINOP_LIST(TEST_MONOTONICITY); 491 SIMPLIFIED_NUMBER_BINOP_LIST(TEST_MONOTONICITY);
438 #undef TEST_MONOTONICITY 492 #undef TEST_MONOTONICITY
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 for (int i = 0; i < kRepetitions; ++i) { \ 557 for (int i = 0; i < kRepetitions; ++i) { \
504 TestBinaryMonotonicity(typer); \ 558 TestBinaryMonotonicity(typer); \
505 } \ 559 } \
506 } 560 }
507 SIMPLIFIED_SPECULATIVE_NUMBER_BINOP_LIST(TEST_MONOTONICITY) 561 SIMPLIFIED_SPECULATIVE_NUMBER_BINOP_LIST(TEST_MONOTONICITY)
508 #undef TEST_MONOTONICITY 562 #undef TEST_MONOTONICITY
509 563
510 } // namespace compiler 564 } // namespace compiler
511 } // namespace internal 565 } // namespace internal
512 } // namespace v8 566 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698