Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: src/compiler/js-builtin-reducer.cc

Issue 584573003: Add JSBuiltinReducer for inlining well-known builtins. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Ben Titzer. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/js-builtin-reducer.h ('k') | src/compiler/js-typed-lowering.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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-inl.h"
6 #include "src/compiler/js-builtin-reducer.h"
7 #include "src/compiler/node-matchers.h"
8 #include "src/compiler/node-properties-inl.h"
9 #include "src/types.h"
10
11 namespace v8 {
12 namespace internal {
13 namespace compiler {
14
15
16 // Helper method that assumes replacement nodes are pure values that don't
17 // produce an effect. Replaces {node} with {reduction} and relaxes effects.
18 static Reduction ReplaceWithPureReduction(Node* node, Reduction reduction) {
19 if (reduction.Changed()) {
20 NodeProperties::ReplaceWithValue(node, reduction.replacement());
21 return reduction;
22 }
23 return Reducer::NoChange();
24 }
25
26
27 // Helper class to access JSCallFunction nodes that are potential candidates
28 // for reduction when they have a BuiltinFunctionId associated with them.
29 class JSCallReduction {
30 public:
31 explicit JSCallReduction(Node* node) : node_(node) {}
32
33 // Determines whether the node is a JSCallFunction operation that targets a
34 // constant callee being a well-known builtin with a BuiltinFunctionId.
35 bool HasBuiltinFunctionId() {
36 if (node_->opcode() != IrOpcode::kJSCallFunction) return false;
37 HeapObjectMatcher<JSFunction> m(NodeProperties::GetValueInput(node_, 0));
38 return m.HasValue() && m.Value().handle()->shared()->HasBuiltinFunctionId();
39 }
40
41 // Retrieves the BuiltinFunctionId as described above.
42 BuiltinFunctionId GetBuiltinFunctionId() {
43 DCHECK_EQ(IrOpcode::kJSCallFunction, node_->opcode());
44 HeapObjectMatcher<JSFunction> m(NodeProperties::GetValueInput(node_, 0));
45 return m.Value().handle()->shared()->builtin_function_id();
46 }
47
48 // Determines whether the call takes one input of the given type.
49 bool InputsMatch(Type* t1) {
50 return GetJSCallArity() == 1 &&
51 NodeProperties::GetBounds(GetJSCallInput(0)).upper->Is(t1);
52 }
53
54 // Determines whether the call takes two inputs of the given types.
55 bool InputsMatch(Type* t1, Type* t2) {
56 return GetJSCallArity() == 2 &&
57 NodeProperties::GetBounds(GetJSCallInput(0)).upper->Is(t1) &&
58 NodeProperties::GetBounds(GetJSCallInput(1)).upper->Is(t2);
59 }
60
61 Node* left() { return GetJSCallInput(0); }
62 Node* right() { return GetJSCallInput(1); }
63
64 protected:
65 int GetJSCallArity() {
66 DCHECK_EQ(IrOpcode::kJSCallFunction, node_->opcode());
67 // Skip first (i.e. callee) and second (i.e. receiver) operand.
68 return OperatorProperties::GetValueInputCount(node_->op()) - 2;
69 }
70
71 Node* GetJSCallInput(int index) {
72 DCHECK_EQ(IrOpcode::kJSCallFunction, node_->opcode());
73 DCHECK_LT(index, GetJSCallArity());
74 // Skip first (i.e. callee) and second (i.e. receiver) operand.
75 return NodeProperties::GetValueInput(node_, index + 2);
76 }
77
78 private:
79 Node* node_;
80 };
81
82
83 // ES6 draft 08-24-14, section 20.2.2.19.
84 Reduction JSBuiltinReducer::ReduceMathImul(Node* node) {
85 JSCallReduction r(node);
86 if (r.InputsMatch(Type::Integral32(), Type::Integral32())) {
87 // Math.imul(a:int32, b:int32) -> Int32Mul(a, b)
88 Node* value = graph()->NewNode(machine()->Int32Mul(), r.left(), r.right());
89 return Replace(value);
90 }
91 return NoChange();
92 }
93
94
95 Reduction JSBuiltinReducer::Reduce(Node* node) {
96 JSCallReduction r(node);
97
98 // Dispatch according to the BuiltinFunctionId if present.
99 if (!r.HasBuiltinFunctionId()) return NoChange();
100 switch (r.GetBuiltinFunctionId()) {
101 case kMathImul:
102 return ReplaceWithPureReduction(node, ReduceMathImul(node));
103 default:
104 break;
105 }
106 return NoChange();
107 }
108
109 } // namespace compiler
110 } // namespace internal
111 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-builtin-reducer.h ('k') | src/compiler/js-typed-lowering.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698