Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "src/compiler/js-intrinsic-lowering.h" | 5 #include "src/compiler/js-intrinsic-lowering.h" |
| 6 | 6 |
| 7 #include "src/compiler/access-builder.h" | 7 #include "src/compiler/access-builder.h" |
| 8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
| 9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 namespace compiler { | 13 namespace compiler { |
| 14 | 14 |
| 15 JSIntrinsicLowering::JSIntrinsicLowering(JSGraph* jsgraph) | 15 JSIntrinsicLowering::JSIntrinsicLowering(JSGraph* jsgraph) |
| 16 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} | 16 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} |
| 17 | 17 |
| 18 | 18 |
| 19 Reduction JSIntrinsicLowering::Reduce(Node* node) { | 19 Reduction JSIntrinsicLowering::Reduce(Node* node) { |
| 20 if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange(); | 20 if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange(); |
| 21 const Runtime::Function* const f = | 21 const Runtime::Function* const f = |
| 22 Runtime::FunctionForId(CallRuntimeParametersOf(node->op()).id()); | 22 Runtime::FunctionForId(CallRuntimeParametersOf(node->op()).id()); |
| 23 if (f->intrinsic_type != Runtime::IntrinsicType::INLINE) return NoChange(); | |
| 24 switch (f->function_id) { | 23 switch (f->function_id) { |
| 24 case Runtime::kDeoptimizeNow: | |
| 25 return ReduceDeoptimizeNow(node); | |
| 25 case Runtime::kInlineIsSmi: | 26 case Runtime::kInlineIsSmi: |
| 26 return ReduceInlineIsSmi(node); | 27 return ReduceInlineIsSmi(node); |
| 27 case Runtime::kInlineIsNonNegativeSmi: | 28 case Runtime::kInlineIsNonNegativeSmi: |
| 28 return ReduceInlineIsNonNegativeSmi(node); | 29 return ReduceInlineIsNonNegativeSmi(node); |
| 29 case Runtime::kInlineIsArray: | 30 case Runtime::kInlineIsArray: |
| 30 return ReduceInlineIsInstanceType(node, JS_ARRAY_TYPE); | 31 return ReduceInlineIsInstanceType(node, JS_ARRAY_TYPE); |
| 31 case Runtime::kInlineIsFunction: | 32 case Runtime::kInlineIsFunction: |
| 32 return ReduceInlineIsInstanceType(node, JS_FUNCTION_TYPE); | 33 return ReduceInlineIsInstanceType(node, JS_FUNCTION_TYPE); |
| 33 case Runtime::kInlineIsRegExp: | 34 case Runtime::kInlineIsRegExp: |
| 34 return ReduceInlineIsInstanceType(node, JS_REGEXP_TYPE); | 35 return ReduceInlineIsInstanceType(node, JS_REGEXP_TYPE); |
| 35 case Runtime::kInlineValueOf: | 36 case Runtime::kInlineValueOf: |
| 36 return ReduceInlineValueOf(node); | 37 return ReduceInlineValueOf(node); |
| 37 default: | 38 default: |
| 38 break; | 39 break; |
| 39 } | 40 } |
| 40 return NoChange(); | 41 return NoChange(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 | 44 |
| 45 Reduction JSIntrinsicLowering::ReduceDeoptimizeNow(Node* node) { | |
| 46 if (!FLAG_turbo_deoptimization) return NoChange(); | |
| 47 | |
| 48 Node* frame_state = NodeProperties::GetFrameStateInput(node); | |
| 49 DCHECK_EQ(frame_state->opcode(), IrOpcode::kFrameState); | |
| 50 | |
| 51 Node* effect = NodeProperties::GetEffectInput(node); | |
| 52 Node* control = NodeProperties::GetControlInput(node); | |
| 53 | |
| 54 // We are making the continuation after the call dead. To | |
| 55 // model this, we generate if (true) statement with deopt | |
| 56 // in the true branch and continuation in the false branch. | |
| 57 Node* branch = | |
| 58 graph()->NewNode(common()->Branch(), jsgraph()->TrueConstant(), control); | |
| 59 | |
| 60 // False branch - the original continuation. | |
| 61 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | |
| 62 NodeProperties::ReplaceControlInput(node, if_false); | |
| 63 NodeProperties::ReplaceWithValue(node, jsgraph()->UndefinedConstant(), | |
|
Benedikt Meurer
2015/02/27 08:27:14
Please add control parameter to ReplaceWithValue()
Jarin
2015/02/27 09:14:39
Done.
| |
| 64 effect); | |
| 65 | |
| 66 // True branch: deopt. | |
| 67 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | |
| 68 Node* deopt = | |
| 69 graph()->NewNode(common()->Deoptimize(), frame_state, effect, if_true); | |
| 70 | |
| 71 // Connect the deopt to the merge exiting the graph. | |
| 72 Node* end_pred = NodeProperties::GetControlInput(graph()->end()); | |
| 73 if (end_pred->opcode() == IrOpcode::kMerge) { | |
| 74 int inputs = end_pred->op()->ControlInputCount() + 1; | |
| 75 end_pred->AppendInput(graph()->zone(), deopt); | |
| 76 end_pred->set_op(common()->Merge(inputs)); | |
| 77 } else { | |
| 78 Node* merge = graph()->NewNode(common()->Merge(2), end_pred, deopt); | |
| 79 NodeProperties::ReplaceControlInput(graph()->end(), merge); | |
| 80 } | |
| 81 | |
| 82 return Changed(deopt); | |
| 83 } | |
| 84 | |
| 85 | |
| 44 Reduction JSIntrinsicLowering::ReduceInlineIsSmi(Node* node) { | 86 Reduction JSIntrinsicLowering::ReduceInlineIsSmi(Node* node) { |
| 45 return Change(node, simplified()->ObjectIsSmi()); | 87 return Change(node, simplified()->ObjectIsSmi()); |
| 46 } | 88 } |
| 47 | 89 |
| 48 | 90 |
| 49 Reduction JSIntrinsicLowering::ReduceInlineIsNonNegativeSmi(Node* node) { | 91 Reduction JSIntrinsicLowering::ReduceInlineIsNonNegativeSmi(Node* node) { |
| 50 return Change(node, simplified()->ObjectIsNonNegativeSmi()); | 92 return Change(node, simplified()->ObjectIsNonNegativeSmi()); |
| 51 } | 93 } |
| 52 | 94 |
| 53 | 95 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 } | 226 } |
| 185 | 227 |
| 186 | 228 |
| 187 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { | 229 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { |
| 188 return jsgraph()->machine(); | 230 return jsgraph()->machine(); |
| 189 } | 231 } |
| 190 | 232 |
| 191 } // namespace compiler | 233 } // namespace compiler |
| 192 } // namespace internal | 234 } // namespace internal |
| 193 } // namespace v8 | 235 } // namespace v8 |
| OLD | NEW |