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

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

Issue 1004083002: [turbofan] Use builtin inlining mechanism for Math.abs and Math.sqrt. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « src/compiler/js-builtin-reducer.h ('k') | src/compiler/js-intrinsic-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
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"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 private: 94 private:
95 Node* node_; 95 Node* node_;
96 }; 96 };
97 97
98 98
99 JSBuiltinReducer::JSBuiltinReducer(JSGraph* jsgraph) 99 JSBuiltinReducer::JSBuiltinReducer(JSGraph* jsgraph)
100 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} 100 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {}
101 101
102 102
103 // ECMA-262, section 15.8.2.1.
104 Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) {
105 JSCallReduction r(node);
106 if (r.InputsMatchOne(Type::Unsigned32())) {
107 // Math.abs(a:uint32) -> a
108 return Replace(r.left());
109 }
110 if (r.InputsMatchOne(Type::Number())) {
111 // Math.abs(a:number) -> (a > 0 ? a : 0 - a)
112 Node* const value = r.left();
113 Node* const zero = jsgraph()->ZeroConstant();
114 return Replace(graph()->NewNode(
115 common()->Select(kMachNone),
116 graph()->NewNode(simplified()->NumberLessThan(), zero, value), value,
117 graph()->NewNode(simplified()->NumberSubtract(), zero, value)));
118 }
119 return NoChange();
120 }
121
122
123 // ECMA-262, section 15.8.2.17.
124 Reduction JSBuiltinReducer::ReduceMathSqrt(Node* node) {
125 JSCallReduction r(node);
126 if (r.InputsMatchOne(Type::Number())) {
127 // Math.sqrt(a:number) -> Float64Sqrt(a)
128 Node* value = graph()->NewNode(machine()->Float64Sqrt(), r.left());
129 return Replace(value);
130 }
131 return NoChange();
132 }
133
134
135 // ECMA-262, section 15.8.2.11. 103 // ECMA-262, section 15.8.2.11.
136 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) { 104 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) {
137 JSCallReduction r(node); 105 JSCallReduction r(node);
138 if (r.InputsMatchZero()) { 106 if (r.InputsMatchZero()) {
139 // Math.max() -> -Infinity 107 // Math.max() -> -Infinity
140 return Replace(jsgraph()->Constant(-V8_INFINITY)); 108 return Replace(jsgraph()->Constant(-V8_INFINITY));
141 } 109 }
142 if (r.InputsMatchOne(Type::Number())) { 110 if (r.InputsMatchOne(Type::Number())) {
143 // Math.max(a:number) -> a 111 // Math.max(a:number) -> a
144 return Replace(r.left()); 112 return Replace(r.left());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return NoChange(); 151 return NoChange();
184 } 152 }
185 153
186 154
187 Reduction JSBuiltinReducer::Reduce(Node* node) { 155 Reduction JSBuiltinReducer::Reduce(Node* node) {
188 JSCallReduction r(node); 156 JSCallReduction r(node);
189 157
190 // Dispatch according to the BuiltinFunctionId if present. 158 // Dispatch according to the BuiltinFunctionId if present.
191 if (!r.HasBuiltinFunctionId()) return NoChange(); 159 if (!r.HasBuiltinFunctionId()) return NoChange();
192 switch (r.GetBuiltinFunctionId()) { 160 switch (r.GetBuiltinFunctionId()) {
193 case kMathAbs:
194 return ReplaceWithPureReduction(node, ReduceMathAbs(node));
195 case kMathSqrt:
196 return ReplaceWithPureReduction(node, ReduceMathSqrt(node));
197 case kMathMax: 161 case kMathMax:
198 return ReplaceWithPureReduction(node, ReduceMathMax(node)); 162 return ReplaceWithPureReduction(node, ReduceMathMax(node));
199 case kMathImul: 163 case kMathImul:
200 return ReplaceWithPureReduction(node, ReduceMathImul(node)); 164 return ReplaceWithPureReduction(node, ReduceMathImul(node));
201 case kMathFround: 165 case kMathFround:
202 return ReplaceWithPureReduction(node, ReduceMathFround(node)); 166 return ReplaceWithPureReduction(node, ReduceMathFround(node));
203 default: 167 default:
204 break; 168 break;
205 } 169 }
206 return NoChange(); 170 return NoChange();
207 } 171 }
208 172
209 173
210 Graph* JSBuiltinReducer::graph() const { return jsgraph()->graph(); } 174 Graph* JSBuiltinReducer::graph() const { return jsgraph()->graph(); }
211 175
212 176
213 CommonOperatorBuilder* JSBuiltinReducer::common() const { 177 CommonOperatorBuilder* JSBuiltinReducer::common() const {
214 return jsgraph()->common(); 178 return jsgraph()->common();
215 } 179 }
216 180
217 181
218 MachineOperatorBuilder* JSBuiltinReducer::machine() const { 182 MachineOperatorBuilder* JSBuiltinReducer::machine() const {
219 return jsgraph()->machine(); 183 return jsgraph()->machine();
220 } 184 }
221 185
222 } // namespace compiler 186 } // namespace compiler
223 } // namespace internal 187 } // namespace internal
224 } // namespace v8 188 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-builtin-reducer.h ('k') | src/compiler/js-intrinsic-lowering.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698