Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/graph-unittest.h" | |
| 6 #include "src/compiler/js-builtin-reducer.h" | |
| 7 #include "src/compiler/js-graph.h" | |
| 8 #include "src/compiler/node-properties-inl.h" | |
| 9 #include "src/compiler/typer.h" | |
| 10 | |
| 11 namespace v8 { | |
| 12 namespace internal { | |
| 13 namespace compiler { | |
| 14 | |
| 15 class JSBuiltinReducerTest : public GraphTest { | |
| 16 public: | |
| 17 JSBuiltinReducerTest() : javascript_(zone()) {} | |
| 18 | |
| 19 protected: | |
| 20 Reduction Reduce(Node* node) { | |
| 21 Typer typer(zone()); | |
| 22 MachineOperatorBuilder machine; | |
| 23 JSGraph jsgraph(graph(), common(), javascript(), &typer, &machine); | |
| 24 JSBuiltinReducer reducer(&jsgraph); | |
| 25 return reducer.Reduce(node); | |
| 26 } | |
| 27 | |
| 28 Node* Parameter(Type* t, int32_t index = 0) { | |
| 29 Node* n = graph()->NewNode(common()->Parameter(index), graph()->start()); | |
| 30 NodeProperties::SetBounds(n, Bounds(Type::None(), t)); | |
| 31 return n; | |
| 32 } | |
| 33 | |
| 34 Node* UndefinedConstant() { | |
| 35 return HeapConstant( | |
| 36 Unique<HeapObject>::CreateImmovable(factory()->undefined_value())); | |
| 37 } | |
| 38 | |
| 39 JSOperatorBuilder* javascript() { return &javascript_; } | |
| 40 | |
| 41 private: | |
| 42 JSOperatorBuilder javascript_; | |
| 43 }; | |
| 44 | |
| 45 | |
| 46 // TODO(mstarzinger): Find a common place and unify with test-js-typed-lowering. | |
| 47 static Type* kNumberTypes[] = { | |
|
Benedikt Meurer
2014/09/23 10:25:58
Nit: Please use const and move to anonymous namesp
Michael Starzinger
2014/09/23 10:31:30
Done.
| |
| 48 Type::UnsignedSmall(), Type::OtherSignedSmall(), Type::OtherUnsigned31(), | |
| 49 Type::OtherUnsigned32(), Type::OtherSigned32(), Type::SignedSmall(), | |
| 50 Type::Signed32(), Type::Unsigned32(), Type::Integral32(), | |
| 51 Type::MinusZero(), Type::NaN(), Type::OtherNumber(), | |
| 52 Type::OrderedNumber(), Type::Number()}; | |
| 53 | |
| 54 | |
| 55 // ----------------------------------------------------------------------------- | |
| 56 // Math.imul | |
| 57 | |
| 58 | |
| 59 TEST_F(JSBuiltinReducerTest, MathImul) { | |
| 60 Handle<JSFunction> f(isolate()->context()->math_imul_fun()); | |
| 61 | |
| 62 TRACED_FOREACH(Type*, t0, kNumberTypes) { | |
| 63 TRACED_FOREACH(Type*, t1, kNumberTypes) { | |
| 64 Node* p0 = Parameter(t0, 0); | |
| 65 Node* p1 = Parameter(t1, 1); | |
| 66 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); | |
| 67 Node* call = | |
| 68 graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun, | |
| 69 UndefinedConstant(), p0, p1); | |
| 70 Reduction r = Reduce(call); | |
| 71 | |
| 72 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) { | |
| 73 EXPECT_TRUE(r.Changed()); | |
| 74 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1)); | |
| 75 } else { | |
| 76 EXPECT_FALSE(r.Changed()); | |
| 77 EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode()); | |
| 78 } | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 } // namespace compiler | |
| 84 } // namespace internal | |
| 85 } // namespace v8 | |
| OLD | NEW |