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

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

Issue 595963002: Extend JSBuiltinReducer to cover Math.sqrt as well. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comment by Benedikt. Created 6 years, 2 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-builtin-reducer-unittest.cc » ('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/graph-inl.h" 5 #include "src/compiler/graph-inl.h"
6 #include "src/compiler/js-builtin-reducer.h" 6 #include "src/compiler/js-builtin-reducer.h"
7 #include "src/compiler/node-matchers.h" 7 #include "src/compiler/node-matchers.h"
8 #include "src/compiler/node-properties-inl.h" 8 #include "src/compiler/node-properties-inl.h"
9 #include "src/types.h" 9 #include "src/types.h"
10 10
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 DCHECK_LT(index, GetJSCallArity()); 88 DCHECK_LT(index, GetJSCallArity());
89 // Skip first (i.e. callee) and second (i.e. receiver) operand. 89 // Skip first (i.e. callee) and second (i.e. receiver) operand.
90 return NodeProperties::GetValueInput(node_, index + 2); 90 return NodeProperties::GetValueInput(node_, index + 2);
91 } 91 }
92 92
93 private: 93 private:
94 Node* node_; 94 Node* node_;
95 }; 95 };
96 96
97 97
98 // ECMA-262, section 15.8.2.17.
99 Reduction JSBuiltinReducer::ReduceMathSqrt(Node* node) {
100 JSCallReduction r(node);
101 if (r.InputsMatchOne(Type::Number())) {
102 // Math.sqrt(a:number) -> Float64Sqrt(a)
103 Node* value = graph()->NewNode(machine()->Float64Sqrt(), r.left());
104 return Replace(value);
105 }
106 return NoChange();
107 }
108
109
98 // ECMA-262, section 15.8.2.11. 110 // ECMA-262, section 15.8.2.11.
99 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) { 111 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) {
100 JSCallReduction r(node); 112 JSCallReduction r(node);
101 if (r.InputsMatchZero()) { 113 if (r.InputsMatchZero()) {
102 // Math.max() -> -Infinity 114 // Math.max() -> -Infinity
103 return Replace(jsgraph()->Constant(-V8_INFINITY)); 115 return Replace(jsgraph()->Constant(-V8_INFINITY));
104 } 116 }
105 if (r.InputsMatchOne(Type::Number())) { 117 if (r.InputsMatchOne(Type::Number())) {
106 // Math.max(a:number) -> a 118 // Math.max(a:number) -> a
107 return Replace(r.left()); 119 return Replace(r.left());
(...skipping 30 matching lines...) Expand all
138 return NoChange(); 150 return NoChange();
139 } 151 }
140 152
141 153
142 Reduction JSBuiltinReducer::Reduce(Node* node) { 154 Reduction JSBuiltinReducer::Reduce(Node* node) {
143 JSCallReduction r(node); 155 JSCallReduction r(node);
144 156
145 // Dispatch according to the BuiltinFunctionId if present. 157 // Dispatch according to the BuiltinFunctionId if present.
146 if (!r.HasBuiltinFunctionId()) return NoChange(); 158 if (!r.HasBuiltinFunctionId()) return NoChange();
147 switch (r.GetBuiltinFunctionId()) { 159 switch (r.GetBuiltinFunctionId()) {
160 case kMathSqrt:
161 return ReplaceWithPureReduction(node, ReduceMathSqrt(node));
148 case kMathMax: 162 case kMathMax:
149 return ReplaceWithPureReduction(node, ReduceMathMax(node)); 163 return ReplaceWithPureReduction(node, ReduceMathMax(node));
150 case kMathImul: 164 case kMathImul:
151 return ReplaceWithPureReduction(node, ReduceMathImul(node)); 165 return ReplaceWithPureReduction(node, ReduceMathImul(node));
152 default: 166 default:
153 break; 167 break;
154 } 168 }
155 return NoChange(); 169 return NoChange();
156 } 170 }
157 171
158 } // namespace compiler 172 } // namespace compiler
159 } // namespace internal 173 } // namespace internal
160 } // namespace v8 174 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-builtin-reducer.h ('k') | src/compiler/js-builtin-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698