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/code-factory.h" | 5 #include "src/code-factory.h" |
6 #include "src/compilation-dependencies.h" | 6 #include "src/compilation-dependencies.h" |
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/js-typed-lowering.h" | 9 #include "src/compiler/js-typed-lowering.h" |
10 #include "src/compiler/linkage.h" | 10 #include "src/compiler/linkage.h" |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 } | 282 } |
283 | 283 |
284 Node* ConvertPlainPrimitiveToNumberOrUndefined(Node* node) { | 284 Node* ConvertPlainPrimitiveToNumberOrUndefined(Node* node) { |
285 DCHECK(NodeProperties::GetType(node)->Is(Type::PlainPrimitive())); | 285 DCHECK(NodeProperties::GetType(node)->Is(Type::PlainPrimitive())); |
286 // Avoid inserting too many eager ToNumber() operations. | 286 // Avoid inserting too many eager ToNumber() operations. |
287 Reduction const reduction = lowering_->ReduceJSToNumberInput(node); | 287 Reduction const reduction = lowering_->ReduceJSToNumberInput(node); |
288 if (reduction.Changed()) return reduction.replacement(); | 288 if (reduction.Changed()) return reduction.replacement(); |
289 if (NodeProperties::GetType(node)->Is(Type::NumberOrUndefined())) { | 289 if (NodeProperties::GetType(node)->Is(Type::NumberOrUndefined())) { |
290 return node; | 290 return node; |
291 } | 291 } |
292 // TODO(bmeurer): Introduce PlainPrimitiveToNumber here. | 292 return graph()->NewNode(simplified()->PlainPrimitiveToNumber(), node); |
293 return graph()->NewNode( | |
294 javascript()->ToNumber(), node, jsgraph()->NoContextConstant(), | |
295 lowering_->EmptyFrameState(), graph()->start(), graph()->start()); | |
296 } | 293 } |
297 | 294 |
298 Node* ConvertSingleInputToNumber(Node* node, Node* frame_state) { | 295 Node* ConvertSingleInputToNumber(Node* node, Node* frame_state) { |
299 DCHECK(!NodeProperties::GetType(node)->Is(Type::PlainPrimitive())); | 296 DCHECK(!NodeProperties::GetType(node)->Is(Type::PlainPrimitive())); |
300 Node* const n = graph()->NewNode(javascript()->ToNumber(), node, context(), | 297 Node* const n = graph()->NewNode(javascript()->ToNumber(), node, context(), |
301 frame_state, effect(), control()); | 298 frame_state, effect(), control()); |
302 Node* const if_success = graph()->NewNode(common()->IfSuccess(), n); | 299 Node* const if_success = graph()->NewNode(common()->IfSuccess(), n); |
303 NodeProperties::ReplaceControlInput(node_, if_success); | 300 NodeProperties::ReplaceControlInput(node_, if_success); |
304 NodeProperties::ReplaceUses(node_, node_, node_, node_, n); | 301 NodeProperties::ReplaceUses(node_, node_, node_, node_, n); |
305 update_effect(n); | 302 update_effect(n); |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 Reduction JSTypedLowering::ReduceJSToNumber(Node* node) { | 859 Reduction JSTypedLowering::ReduceJSToNumber(Node* node) { |
863 // Try to reduce the input first. | 860 // Try to reduce the input first. |
864 Node* const input = node->InputAt(0); | 861 Node* const input = node->InputAt(0); |
865 Reduction reduction = ReduceJSToNumberInput(input); | 862 Reduction reduction = ReduceJSToNumberInput(input); |
866 if (reduction.Changed()) { | 863 if (reduction.Changed()) { |
867 ReplaceWithValue(node, reduction.replacement()); | 864 ReplaceWithValue(node, reduction.replacement()); |
868 return reduction; | 865 return reduction; |
869 } | 866 } |
870 Type* const input_type = NodeProperties::GetType(input); | 867 Type* const input_type = NodeProperties::GetType(input); |
871 if (input_type->Is(Type::PlainPrimitive())) { | 868 if (input_type->Is(Type::PlainPrimitive())) { |
872 if (NodeProperties::GetContextInput(node) != | 869 RelaxEffectsAndControls(node); |
873 jsgraph()->NoContextConstant() || | 870 node->TrimInputCount(1); |
874 NodeProperties::GetEffectInput(node) != graph()->start() || | 871 NodeProperties::ChangeOp(node, simplified()->PlainPrimitiveToNumber()); |
875 NodeProperties::GetControlInput(node) != graph()->start()) { | 872 return Changed(node); |
876 // JSToNumber(x:plain-primitive,context,effect,control) | |
877 // => JSToNumber(x,no-context,start,start) | |
878 RelaxEffectsAndControls(node); | |
879 NodeProperties::ReplaceContextInput(node, jsgraph()->NoContextConstant()); | |
880 NodeProperties::ReplaceControlInput(node, graph()->start()); | |
881 NodeProperties::ReplaceEffectInput(node, graph()->start()); | |
882 DCHECK_EQ(1, OperatorProperties::GetFrameStateInputCount(node->op())); | |
883 NodeProperties::ReplaceFrameStateInput(node, 0, EmptyFrameState()); | |
884 return Changed(node); | |
885 } | |
886 } | 873 } |
887 return NoChange(); | 874 return NoChange(); |
888 } | 875 } |
889 | 876 |
890 | 877 |
891 Reduction JSTypedLowering::ReduceJSToStringInput(Node* input) { | 878 Reduction JSTypedLowering::ReduceJSToStringInput(Node* input) { |
892 if (input->opcode() == IrOpcode::kJSToString) { | 879 if (input->opcode() == IrOpcode::kJSToString) { |
893 // Recursively try to reduce the input first. | 880 // Recursively try to reduce the input first. |
894 Reduction result = ReduceJSToString(input); | 881 Reduction result = ReduceJSToString(input); |
895 if (result.Changed()) return result; | 882 if (result.Changed()) return result; |
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1975 } | 1962 } |
1976 | 1963 |
1977 | 1964 |
1978 CompilationDependencies* JSTypedLowering::dependencies() const { | 1965 CompilationDependencies* JSTypedLowering::dependencies() const { |
1979 return dependencies_; | 1966 return dependencies_; |
1980 } | 1967 } |
1981 | 1968 |
1982 } // namespace compiler | 1969 } // namespace compiler |
1983 } // namespace internal | 1970 } // namespace internal |
1984 } // namespace v8 | 1971 } // namespace v8 |
OLD | NEW |