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 namespace { |
| 47 |
| 48 // TODO(mstarzinger): Find a common place and unify with test-js-typed-lowering. |
| 49 Type* const kNumberTypes[] = { |
| 50 Type::UnsignedSmall(), Type::OtherSignedSmall(), Type::OtherUnsigned31(), |
| 51 Type::OtherUnsigned32(), Type::OtherSigned32(), Type::SignedSmall(), |
| 52 Type::Signed32(), Type::Unsigned32(), Type::Integral32(), |
| 53 Type::MinusZero(), Type::NaN(), Type::OtherNumber(), |
| 54 Type::OrderedNumber(), Type::Number()}; |
| 55 |
| 56 } // namespace |
| 57 |
| 58 |
| 59 // ----------------------------------------------------------------------------- |
| 60 // Math.imul |
| 61 |
| 62 |
| 63 TEST_F(JSBuiltinReducerTest, MathImul) { |
| 64 Handle<JSFunction> f(isolate()->context()->math_imul_fun()); |
| 65 |
| 66 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
| 67 TRACED_FOREACH(Type*, t1, kNumberTypes) { |
| 68 Node* p0 = Parameter(t0, 0); |
| 69 Node* p1 = Parameter(t1, 1); |
| 70 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
| 71 Node* call = |
| 72 graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun, |
| 73 UndefinedConstant(), p0, p1); |
| 74 Reduction r = Reduce(call); |
| 75 |
| 76 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) { |
| 77 EXPECT_TRUE(r.Changed()); |
| 78 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1)); |
| 79 } else { |
| 80 EXPECT_FALSE(r.Changed()); |
| 81 EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode()); |
| 82 } |
| 83 } |
| 84 } |
| 85 } |
| 86 |
| 87 } // namespace compiler |
| 88 } // namespace internal |
| 89 } // namespace v8 |
OLD | NEW |