| 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-builtin-reducer.h" | 5 #include "src/compiler/js-builtin-reducer.h" |
| 6 | 6 |
| 7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
| 8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
| 9 #include "src/compilation-dependencies.h" | 9 #include "src/compilation-dependencies.h" |
| 10 #include "src/compiler/access-builder.h" | 10 #include "src/compiler/access-builder.h" |
| 11 #include "src/compiler/js-graph.h" | 11 #include "src/compiler/js-graph.h" |
| 12 #include "src/compiler/linkage.h" | 12 #include "src/compiler/linkage.h" |
| 13 #include "src/compiler/node-matchers.h" | 13 #include "src/compiler/node-matchers.h" |
| 14 #include "src/compiler/node-properties.h" | 14 #include "src/compiler/node-properties.h" |
| 15 #include "src/compiler/simplified-operator.h" | 15 #include "src/compiler/simplified-operator.h" |
| 16 #include "src/compiler/type-cache.h" | 16 #include "src/compiler/type-cache.h" |
| 17 #include "src/compiler/types.h" | 17 #include "src/compiler/types.h" |
| 18 #include "src/objects-inl.h" | 18 #include "src/objects-inl.h" |
| 19 | 19 |
| 20 namespace v8 { | 20 namespace v8 { |
| 21 namespace internal { | 21 namespace internal { |
| 22 namespace compiler { | 22 namespace compiler { |
| 23 | 23 |
| 24 | 24 // Helper class to access JSCall nodes that are potential candidates |
| 25 // Helper class to access JSCallFunction nodes that are potential candidates | |
| 26 // for reduction when they have a BuiltinFunctionId associated with them. | 25 // for reduction when they have a BuiltinFunctionId associated with them. |
| 27 class JSCallReduction { | 26 class JSCallReduction { |
| 28 public: | 27 public: |
| 29 explicit JSCallReduction(Node* node) : node_(node) {} | 28 explicit JSCallReduction(Node* node) : node_(node) {} |
| 30 | 29 |
| 31 // Determines whether the node is a JSCallFunction operation that targets a | 30 // Determines whether the node is a JSCall operation that targets a |
| 32 // constant callee being a well-known builtin with a BuiltinFunctionId. | 31 // constant callee being a well-known builtin with a BuiltinFunctionId. |
| 33 bool HasBuiltinFunctionId() { | 32 bool HasBuiltinFunctionId() { |
| 34 if (node_->opcode() != IrOpcode::kJSCallFunction) return false; | 33 if (node_->opcode() != IrOpcode::kJSCall) return false; |
| 35 HeapObjectMatcher m(NodeProperties::GetValueInput(node_, 0)); | 34 HeapObjectMatcher m(NodeProperties::GetValueInput(node_, 0)); |
| 36 if (!m.HasValue() || !m.Value()->IsJSFunction()) return false; | 35 if (!m.HasValue() || !m.Value()->IsJSFunction()) return false; |
| 37 Handle<JSFunction> function = Handle<JSFunction>::cast(m.Value()); | 36 Handle<JSFunction> function = Handle<JSFunction>::cast(m.Value()); |
| 38 return function->shared()->HasBuiltinFunctionId(); | 37 return function->shared()->HasBuiltinFunctionId(); |
| 39 } | 38 } |
| 40 | 39 |
| 41 // Retrieves the BuiltinFunctionId as described above. | 40 // Retrieves the BuiltinFunctionId as described above. |
| 42 BuiltinFunctionId GetBuiltinFunctionId() { | 41 BuiltinFunctionId GetBuiltinFunctionId() { |
| 43 DCHECK_EQ(IrOpcode::kJSCallFunction, node_->opcode()); | 42 DCHECK_EQ(IrOpcode::kJSCall, node_->opcode()); |
| 44 HeapObjectMatcher m(NodeProperties::GetValueInput(node_, 0)); | 43 HeapObjectMatcher m(NodeProperties::GetValueInput(node_, 0)); |
| 45 Handle<JSFunction> function = Handle<JSFunction>::cast(m.Value()); | 44 Handle<JSFunction> function = Handle<JSFunction>::cast(m.Value()); |
| 46 return function->shared()->builtin_function_id(); | 45 return function->shared()->builtin_function_id(); |
| 47 } | 46 } |
| 48 | 47 |
| 49 bool ReceiverMatches(Type* type) { | 48 bool ReceiverMatches(Type* type) { |
| 50 return NodeProperties::GetType(receiver())->Is(type); | 49 return NodeProperties::GetType(receiver())->Is(type); |
| 51 } | 50 } |
| 52 | 51 |
| 53 // Determines whether the call takes zero inputs. | 52 // Determines whether the call takes zero inputs. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 74 } | 73 } |
| 75 } | 74 } |
| 76 return true; | 75 return true; |
| 77 } | 76 } |
| 78 | 77 |
| 79 Node* receiver() { return NodeProperties::GetValueInput(node_, 1); } | 78 Node* receiver() { return NodeProperties::GetValueInput(node_, 1); } |
| 80 Node* left() { return GetJSCallInput(0); } | 79 Node* left() { return GetJSCallInput(0); } |
| 81 Node* right() { return GetJSCallInput(1); } | 80 Node* right() { return GetJSCallInput(1); } |
| 82 | 81 |
| 83 int GetJSCallArity() { | 82 int GetJSCallArity() { |
| 84 DCHECK_EQ(IrOpcode::kJSCallFunction, node_->opcode()); | 83 DCHECK_EQ(IrOpcode::kJSCall, node_->opcode()); |
| 85 // Skip first (i.e. callee) and second (i.e. receiver) operand. | 84 // Skip first (i.e. callee) and second (i.e. receiver) operand. |
| 86 return node_->op()->ValueInputCount() - 2; | 85 return node_->op()->ValueInputCount() - 2; |
| 87 } | 86 } |
| 88 | 87 |
| 89 Node* GetJSCallInput(int index) { | 88 Node* GetJSCallInput(int index) { |
| 90 DCHECK_EQ(IrOpcode::kJSCallFunction, node_->opcode()); | 89 DCHECK_EQ(IrOpcode::kJSCall, node_->opcode()); |
| 91 DCHECK_LT(index, GetJSCallArity()); | 90 DCHECK_LT(index, GetJSCallArity()); |
| 92 // Skip first (i.e. callee) and second (i.e. receiver) operand. | 91 // Skip first (i.e. callee) and second (i.e. receiver) operand. |
| 93 return NodeProperties::GetValueInput(node_, index + 2); | 92 return NodeProperties::GetValueInput(node_, index + 2); |
| 94 } | 93 } |
| 95 | 94 |
| 96 private: | 95 private: |
| 97 Node* node_; | 96 Node* node_; |
| 98 }; | 97 }; |
| 99 | 98 |
| 100 JSBuiltinReducer::JSBuiltinReducer(Editor* editor, JSGraph* jsgraph, | 99 JSBuiltinReducer::JSBuiltinReducer(Editor* editor, JSGraph* jsgraph, |
| (...skipping 2091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2192 return jsgraph()->simplified(); | 2191 return jsgraph()->simplified(); |
| 2193 } | 2192 } |
| 2194 | 2193 |
| 2195 JSOperatorBuilder* JSBuiltinReducer::javascript() const { | 2194 JSOperatorBuilder* JSBuiltinReducer::javascript() const { |
| 2196 return jsgraph()->javascript(); | 2195 return jsgraph()->javascript(); |
| 2197 } | 2196 } |
| 2198 | 2197 |
| 2199 } // namespace compiler | 2198 } // namespace compiler |
| 2200 } // namespace internal | 2199 } // namespace internal |
| 2201 } // namespace v8 | 2200 } // namespace v8 |
| OLD | NEW |