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

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

Issue 1158273011: [turbofan] Turn JSBuiltinReducer into an AdvancedReducer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased. Created 5 years, 6 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
OLDNEW
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/diamond.h" 5 #include "src/compiler/diamond.h"
6 #include "src/compiler/js-builtin-reducer.h" 6 #include "src/compiler/js-builtin-reducer.h"
7 #include "src/compiler/js-graph.h" 7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/node-matchers.h" 8 #include "src/compiler/node-matchers.h"
9 #include "src/compiler/node-properties.h" 9 #include "src/compiler/node-properties.h"
10 #include "src/types.h" 10 #include "src/types.h"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace internal { 13 namespace internal {
14 namespace compiler { 14 namespace compiler {
15 15
16 16
17 // Helper method that assumes replacement nodes are pure values that don't
18 // produce an effect. Replaces {node} with {reduction} and relaxes effects.
19 static Reduction ReplaceWithPureReduction(Node* node, Reduction reduction) {
20 if (reduction.Changed()) {
21 NodeProperties::ReplaceWithValue(node, reduction.replacement());
22 return reduction;
23 }
24 return Reducer::NoChange();
25 }
26
27
28 // Helper class to access JSCallFunction nodes that are potential candidates 17 // Helper class to access JSCallFunction nodes that are potential candidates
29 // for reduction when they have a BuiltinFunctionId associated with them. 18 // for reduction when they have a BuiltinFunctionId associated with them.
30 class JSCallReduction { 19 class JSCallReduction {
31 public: 20 public:
32 explicit JSCallReduction(Node* node) : node_(node) {} 21 explicit JSCallReduction(Node* node) : node_(node) {}
33 22
34 // Determines whether the node is a JSCallFunction operation that targets a 23 // Determines whether the node is a JSCallFunction operation that targets a
35 // constant callee being a well-known builtin with a BuiltinFunctionId. 24 // constant callee being a well-known builtin with a BuiltinFunctionId.
36 bool HasBuiltinFunctionId() { 25 bool HasBuiltinFunctionId() {
37 if (node_->opcode() != IrOpcode::kJSCallFunction) return false; 26 if (node_->opcode() != IrOpcode::kJSCallFunction) return false;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 DCHECK_LT(index, GetJSCallArity()); 78 DCHECK_LT(index, GetJSCallArity());
90 // Skip first (i.e. callee) and second (i.e. receiver) operand. 79 // Skip first (i.e. callee) and second (i.e. receiver) operand.
91 return NodeProperties::GetValueInput(node_, index + 2); 80 return NodeProperties::GetValueInput(node_, index + 2);
92 } 81 }
93 82
94 private: 83 private:
95 Node* node_; 84 Node* node_;
96 }; 85 };
97 86
98 87
99 JSBuiltinReducer::JSBuiltinReducer(JSGraph* jsgraph) 88 JSBuiltinReducer::JSBuiltinReducer(Editor* editor, JSGraph* jsgraph)
100 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} 89 : AdvancedReducer(editor),
90 jsgraph_(jsgraph),
91 simplified_(jsgraph->zone()) {}
101 92
102 93
103 // ECMA-262, section 15.8.2.11. 94 // ECMA-262, section 15.8.2.11.
104 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) { 95 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) {
105 JSCallReduction r(node); 96 JSCallReduction r(node);
106 if (r.InputsMatchZero()) { 97 if (r.InputsMatchZero()) {
107 // Math.max() -> -Infinity 98 // Math.max() -> -Infinity
108 return Replace(jsgraph()->Constant(-V8_INFINITY)); 99 return Replace(jsgraph()->Constant(-V8_INFINITY));
109 } 100 }
110 if (r.InputsMatchOne(Type::Number())) { 101 if (r.InputsMatchOne(Type::Number())) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // Math.fround(a:number) -> TruncateFloat64ToFloat32(a) 137 // Math.fround(a:number) -> TruncateFloat64ToFloat32(a)
147 Node* value = 138 Node* value =
148 graph()->NewNode(machine()->TruncateFloat64ToFloat32(), r.left()); 139 graph()->NewNode(machine()->TruncateFloat64ToFloat32(), r.left());
149 return Replace(value); 140 return Replace(value);
150 } 141 }
151 return NoChange(); 142 return NoChange();
152 } 143 }
153 144
154 145
155 Reduction JSBuiltinReducer::Reduce(Node* node) { 146 Reduction JSBuiltinReducer::Reduce(Node* node) {
147 Reduction reduction = NoChange();
156 JSCallReduction r(node); 148 JSCallReduction r(node);
157 149
158 // Dispatch according to the BuiltinFunctionId if present. 150 // Dispatch according to the BuiltinFunctionId if present.
159 if (!r.HasBuiltinFunctionId()) return NoChange(); 151 if (!r.HasBuiltinFunctionId()) return NoChange();
160 switch (r.GetBuiltinFunctionId()) { 152 switch (r.GetBuiltinFunctionId()) {
161 case kMathMax: 153 case kMathMax:
162 return ReplaceWithPureReduction(node, ReduceMathMax(node)); 154 reduction = ReduceMathMax(node);
155 break;
163 case kMathImul: 156 case kMathImul:
164 return ReplaceWithPureReduction(node, ReduceMathImul(node)); 157 reduction = ReduceMathImul(node);
158 break;
165 case kMathFround: 159 case kMathFround:
166 return ReplaceWithPureReduction(node, ReduceMathFround(node)); 160 reduction = ReduceMathFround(node);
161 break;
167 default: 162 default:
168 break; 163 break;
169 } 164 }
170 return NoChange(); 165
166 // Replace builtin call assuming replacement nodes are pure values that don't
167 // produce an effect. Replaces {node} with {reduction} and relaxes effects.
168 if (reduction.Changed()) ReplaceWithValue(node, reduction.replacement());
169
170 return reduction;
171 } 171 }
172 172
173 173
174 Graph* JSBuiltinReducer::graph() const { return jsgraph()->graph(); } 174 Graph* JSBuiltinReducer::graph() const { return jsgraph()->graph(); }
175 175
176 176
177 CommonOperatorBuilder* JSBuiltinReducer::common() const { 177 CommonOperatorBuilder* JSBuiltinReducer::common() const {
178 return jsgraph()->common(); 178 return jsgraph()->common();
179 } 179 }
180 180
181 181
182 MachineOperatorBuilder* JSBuiltinReducer::machine() const { 182 MachineOperatorBuilder* JSBuiltinReducer::machine() const {
183 return jsgraph()->machine(); 183 return jsgraph()->machine();
184 } 184 }
185 185
186 } // namespace compiler 186 } // namespace compiler
187 } // namespace internal 187 } // namespace internal
188 } // namespace v8 188 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698