| 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/js-graph.h" | 5 #include "src/compiler/js-graph.h" |
| 6 #include "src/compiler/js-typed-lowering.h" | 6 #include "src/compiler/js-typed-lowering.h" |
| 7 #include "src/compiler/machine-operator.h" | 7 #include "src/compiler/machine-operator.h" |
| 8 #include "src/compiler/node-properties.h" | 8 #include "src/compiler/node-properties.h" |
| 9 #include "src/compiler/opcodes.h" | 9 #include "src/compiler/opcodes.h" |
| 10 #include "src/compiler/operator-properties.h" | 10 #include "src/compiler/operator-properties.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 binop(NULL), | 34 binop(NULL), |
| 35 unop(NULL), | 35 unop(NULL), |
| 36 javascript(main_zone()), | 36 javascript(main_zone()), |
| 37 machine(main_zone()), | 37 machine(main_zone()), |
| 38 simplified(main_zone()), | 38 simplified(main_zone()), |
| 39 common(main_zone()), | 39 common(main_zone()), |
| 40 graph(main_zone()), | 40 graph(main_zone()), |
| 41 typer(main_isolate(), &graph), | 41 typer(main_isolate(), &graph), |
| 42 context_node(NULL) { | 42 context_node(NULL) { |
| 43 graph.SetStart(graph.NewNode(common.Start(num_parameters))); | 43 graph.SetStart(graph.NewNode(common.Start(num_parameters))); |
| 44 graph.SetEnd(graph.NewNode(common.End(1))); | 44 graph.SetEnd(graph.NewNode(common.End(1), graph.start())); |
| 45 typer.Run(); | 45 typer.Run(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 Isolate* isolate; | 48 Isolate* isolate; |
| 49 const Operator* binop; | 49 const Operator* binop; |
| 50 const Operator* unop; | 50 const Operator* unop; |
| 51 JSOperatorBuilder javascript; | 51 JSOperatorBuilder javascript; |
| 52 MachineOperatorBuilder machine; | 52 MachineOperatorBuilder machine; |
| 53 SimplifiedOperatorBuilder simplified; | 53 SimplifiedOperatorBuilder simplified; |
| 54 CommonOperatorBuilder common; | 54 CommonOperatorBuilder common; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 72 } | 72 } |
| 73 | 73 |
| 74 Node* EmptyFrameState(Node* context) { | 74 Node* EmptyFrameState(Node* context) { |
| 75 Node* parameters = graph.NewNode(common.StateValues(0)); | 75 Node* parameters = graph.NewNode(common.StateValues(0)); |
| 76 Node* locals = graph.NewNode(common.StateValues(0)); | 76 Node* locals = graph.NewNode(common.StateValues(0)); |
| 77 Node* stack = graph.NewNode(common.StateValues(0)); | 77 Node* stack = graph.NewNode(common.StateValues(0)); |
| 78 | 78 |
| 79 Node* state_node = graph.NewNode( | 79 Node* state_node = graph.NewNode( |
| 80 common.FrameState(BailoutId::None(), OutputFrameStateCombine::Ignore(), | 80 common.FrameState(BailoutId::None(), OutputFrameStateCombine::Ignore(), |
| 81 nullptr), | 81 nullptr), |
| 82 parameters, locals, stack, context, UndefinedConstant()); | 82 parameters, locals, stack, context, UndefinedConstant(), graph.start()); |
| 83 | 83 |
| 84 return state_node; | 84 return state_node; |
| 85 } | 85 } |
| 86 | 86 |
| 87 Node* reduce(Node* node) { | 87 Node* reduce(Node* node) { |
| 88 JSGraph jsgraph(main_isolate(), &graph, &common, &javascript, &machine); | 88 JSGraph jsgraph(main_isolate(), &graph, &common, &javascript, &machine); |
| 89 // TODO(titzer): mock the GraphReducer here for better unit testing. | 89 // TODO(titzer): mock the GraphReducer here for better unit testing. |
| 90 GraphReducer graph_reducer(main_zone(), &graph); | 90 GraphReducer graph_reducer(main_zone(), &graph); |
| 91 JSTypedLowering reducer(&graph_reducer, &jsgraph, main_zone()); | 91 JSTypedLowering reducer(&graph_reducer, &jsgraph, main_zone()); |
| 92 Reduction reduction = reducer.Reduce(node); | 92 Reduction reduction = reducer.Reduce(node); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 118 Node* ReduceUnop(const Operator* op, Type* input_type) { | 118 Node* ReduceUnop(const Operator* op, Type* input_type) { |
| 119 return reduce(Unop(op, Parameter(input_type))); | 119 return reduce(Unop(op, Parameter(input_type))); |
| 120 } | 120 } |
| 121 | 121 |
| 122 Node* ReduceBinop(const Operator* op, Type* left_type, Type* right_type) { | 122 Node* ReduceBinop(const Operator* op, Type* left_type, Type* right_type) { |
| 123 return reduce(Binop(op, Parameter(left_type, 0), Parameter(right_type, 1))); | 123 return reduce(Binop(op, Parameter(left_type, 0), Parameter(right_type, 1))); |
| 124 } | 124 } |
| 125 | 125 |
| 126 Node* Binop(const Operator* op, Node* left, Node* right) { | 126 Node* Binop(const Operator* op, Node* left, Node* right) { |
| 127 // JS binops also require context, effect, and control | 127 // JS binops also require context, effect, and control |
| 128 if (OperatorProperties::GetFrameStateInputCount(op) == 1) { | 128 std::vector<Node*> inputs; |
| 129 return graph.NewNode(op, left, right, context(), | 129 inputs.push_back(left); |
| 130 EmptyFrameState(context()), start(), control()); | 130 inputs.push_back(right); |
| 131 } else if (OperatorProperties::GetFrameStateInputCount(op) == 2) { | 131 if (OperatorProperties::HasContextInput(op)) { |
| 132 return graph.NewNode(op, left, right, context(), | 132 inputs.push_back(context()); |
| 133 EmptyFrameState(context()), | |
| 134 EmptyFrameState(context()), start(), control()); | |
| 135 } else { | |
| 136 return graph.NewNode(op, left, right, context(), start(), control()); | |
| 137 } | 133 } |
| 134 for (int i = 0; i < OperatorProperties::GetFrameStateInputCount(op); i++) { |
| 135 inputs.push_back(EmptyFrameState(context())); |
| 136 } |
| 137 if (op->EffectInputCount() > 0) { |
| 138 inputs.push_back(start()); |
| 139 } |
| 140 if (op->ControlInputCount() > 0) { |
| 141 inputs.push_back(control()); |
| 142 } |
| 143 return graph.NewNode(op, static_cast<int>(inputs.size()), |
| 144 &(inputs.front())); |
| 138 } | 145 } |
| 139 | 146 |
| 140 Node* Unop(const Operator* op, Node* input) { | 147 Node* Unop(const Operator* op, Node* input) { |
| 141 // JS unops also require context, effect, and control | 148 // JS unops also require context, effect, and control |
| 142 if (OperatorProperties::GetFrameStateInputCount(op) > 0) { | 149 if (OperatorProperties::GetFrameStateInputCount(op) > 0) { |
| 143 DCHECK(OperatorProperties::GetFrameStateInputCount(op) == 1); | 150 DCHECK(OperatorProperties::GetFrameStateInputCount(op) == 1); |
| 144 return graph.NewNode(op, input, context(), EmptyFrameState(context()), | 151 return graph.NewNode(op, input, context(), EmptyFrameState(context()), |
| 145 start(), control()); | 152 start(), control()); |
| 146 } else { | 153 } else { |
| 147 return graph.NewNode(op, input, context(), start(), control()); | 154 return graph.NewNode(op, input, context(), start(), control()); |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 | 828 |
| 822 | 829 |
| 823 // Helper function for strict and non-strict equality reductions. | 830 // Helper function for strict and non-strict equality reductions. |
| 824 void CheckEqualityReduction(JSTypedLoweringTester* R, bool strict, Node* l, | 831 void CheckEqualityReduction(JSTypedLoweringTester* R, bool strict, Node* l, |
| 825 Node* r, IrOpcode::Value expected) { | 832 Node* r, IrOpcode::Value expected) { |
| 826 for (int j = 0; j < 2; j++) { | 833 for (int j = 0; j < 2; j++) { |
| 827 Node* p0 = j == 0 ? l : r; | 834 Node* p0 = j == 0 ? l : r; |
| 828 Node* p1 = j == 1 ? l : r; | 835 Node* p1 = j == 1 ? l : r; |
| 829 | 836 |
| 830 { | 837 { |
| 831 Node* eq = strict ? R->graph.NewNode(R->javascript.StrictEqual(), p0, p1) | 838 Node* eq = strict |
| 832 : R->Binop(R->javascript.Equal(), p0, p1); | 839 ? R->graph.NewNode(R->javascript.StrictEqual(), p0, p1, |
| 840 R->context()) |
| 841 : R->Binop(R->javascript.Equal(), p0, p1); |
| 833 Node* r = R->reduce(eq); | 842 Node* r = R->reduce(eq); |
| 834 R->CheckPureBinop(expected, r); | 843 R->CheckPureBinop(expected, r); |
| 835 } | 844 } |
| 836 | 845 |
| 837 { | 846 { |
| 838 Node* ne = strict | 847 Node* ne = strict |
| 839 ? R->graph.NewNode(R->javascript.StrictNotEqual(), p0, p1) | 848 ? R->graph.NewNode(R->javascript.StrictNotEqual(), p0, p1, |
| 849 R->context()) |
| 840 : R->Binop(R->javascript.NotEqual(), p0, p1); | 850 : R->Binop(R->javascript.NotEqual(), p0, p1); |
| 841 Node* n = R->reduce(ne); | 851 Node* n = R->reduce(ne); |
| 842 CHECK_EQ(IrOpcode::kBooleanNot, n->opcode()); | 852 CHECK_EQ(IrOpcode::kBooleanNot, n->opcode()); |
| 843 Node* r = n->InputAt(0); | 853 Node* r = n->InputAt(0); |
| 844 R->CheckPureBinop(expected, r); | 854 R->CheckPureBinop(expected, r); |
| 845 } | 855 } |
| 846 } | 856 } |
| 847 } | 857 } |
| 848 | 858 |
| 849 | 859 |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 CHECK_EQ(p1, r->InputAt(0)); | 1258 CHECK_EQ(p1, r->InputAt(0)); |
| 1249 CHECK_EQ(p0, r->InputAt(1)); | 1259 CHECK_EQ(p0, r->InputAt(1)); |
| 1250 } else { | 1260 } else { |
| 1251 CHECK_EQ(p0, r->InputAt(0)); | 1261 CHECK_EQ(p0, r->InputAt(0)); |
| 1252 CHECK_EQ(p1, r->InputAt(1)); | 1262 CHECK_EQ(p1, r->InputAt(1)); |
| 1253 } | 1263 } |
| 1254 } | 1264 } |
| 1255 } | 1265 } |
| 1256 } | 1266 } |
| 1257 } | 1267 } |
| OLD | NEW |