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

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

Issue 694063005: Introduce Diamond, a helper for building diamond-shaped control patterns. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: newline Created 6 years, 1 month 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/diamond.h ('k') | src/compiler/js-intrinsic-builder.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/diamond.h"
5 #include "src/compiler/graph-inl.h" 6 #include "src/compiler/graph-inl.h"
6 #include "src/compiler/js-builtin-reducer.h" 7 #include "src/compiler/js-builtin-reducer.h"
7 #include "src/compiler/node-matchers.h" 8 #include "src/compiler/node-matchers.h"
8 #include "src/compiler/node-properties-inl.h" 9 #include "src/compiler/node-properties-inl.h"
9 #include "src/types.h" 10 #include "src/types.h"
10 11
11 namespace v8 { 12 namespace v8 {
12 namespace internal { 13 namespace internal {
13 namespace compiler { 14 namespace compiler {
14 15
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) { 100 Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) {
100 JSCallReduction r(node); 101 JSCallReduction r(node);
101 if (r.InputsMatchOne(Type::Unsigned32())) { 102 if (r.InputsMatchOne(Type::Unsigned32())) {
102 // Math.abs(a:uint32) -> a 103 // Math.abs(a:uint32) -> a
103 return Replace(r.left()); 104 return Replace(r.left());
104 } 105 }
105 if (r.InputsMatchOne(Type::Number())) { 106 if (r.InputsMatchOne(Type::Number())) {
106 // Math.abs(a:number) -> (a > 0 ? a : 0 - a) 107 // Math.abs(a:number) -> (a > 0 ? a : 0 - a)
107 Node* value = r.left(); 108 Node* value = r.left();
108 Node* zero = jsgraph()->ZeroConstant(); 109 Node* zero = jsgraph()->ZeroConstant();
109 Node* control = graph()->start(); 110 Node* cmp = graph()->NewNode(simplified()->NumberLessThan(), zero, value);
110 Node* tag = graph()->NewNode(simplified()->NumberLessThan(), zero, value); 111 Diamond d(graph(), common(), cmp);
111
112 Node* branch = graph()->NewNode(common()->Branch(), tag, control);
113 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
114 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
115 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
116
117 Node* neg = graph()->NewNode(simplified()->NumberSubtract(), zero, value); 112 Node* neg = graph()->NewNode(simplified()->NumberSubtract(), zero, value);
118 value = graph()->NewNode(common()->Phi(kMachNone, 2), value, neg, merge); 113 return Replace(d.Phi(kMachNone, value, neg));
119 return Replace(value);
120 } 114 }
121 return NoChange(); 115 return NoChange();
122 } 116 }
123 117
124 118
125 // ECMA-262, section 15.8.2.17. 119 // ECMA-262, section 15.8.2.17.
126 Reduction JSBuiltinReducer::ReduceMathSqrt(Node* node) { 120 Reduction JSBuiltinReducer::ReduceMathSqrt(Node* node) {
127 JSCallReduction r(node); 121 JSCallReduction r(node);
128 if (r.InputsMatchOne(Type::Number())) { 122 if (r.InputsMatchOne(Type::Number())) {
129 // Math.sqrt(a:number) -> Float64Sqrt(a) 123 // Math.sqrt(a:number) -> Float64Sqrt(a)
(...skipping 13 matching lines...) Expand all
143 } 137 }
144 if (r.InputsMatchOne(Type::Number())) { 138 if (r.InputsMatchOne(Type::Number())) {
145 // Math.max(a:number) -> a 139 // Math.max(a:number) -> a
146 return Replace(r.left()); 140 return Replace(r.left());
147 } 141 }
148 if (r.InputsMatchAll(Type::Integral32())) { 142 if (r.InputsMatchAll(Type::Integral32())) {
149 // Math.max(a:int32, b:int32, ...) 143 // Math.max(a:int32, b:int32, ...)
150 Node* value = r.GetJSCallInput(0); 144 Node* value = r.GetJSCallInput(0);
151 for (int i = 1; i < r.GetJSCallArity(); i++) { 145 for (int i = 1; i < r.GetJSCallArity(); i++) {
152 Node* p = r.GetJSCallInput(i); 146 Node* p = r.GetJSCallInput(i);
153 Node* control = graph()->start(); 147 Node* cmp = graph()->NewNode(simplified()->NumberLessThan(), value, p);
154 Node* tag = graph()->NewNode(simplified()->NumberLessThan(), value, p); 148 Diamond d(graph(), common(), cmp);
155 149 value = d.Phi(kMachNone, p, value);
156 Node* branch = graph()->NewNode(common()->Branch(), tag, control);
157 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
158 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
159 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
160
161 value = graph()->NewNode(common()->Phi(kMachNone, 2), p, value, merge);
162 } 150 }
163 return Replace(value); 151 return Replace(value);
164 } 152 }
165 return NoChange(); 153 return NoChange();
166 } 154 }
167 155
168 156
169 // ES6 draft 08-24-14, section 20.2.2.19. 157 // ES6 draft 08-24-14, section 20.2.2.19.
170 Reduction JSBuiltinReducer::ReduceMathImul(Node* node) { 158 Reduction JSBuiltinReducer::ReduceMathImul(Node* node) {
171 JSCallReduction r(node); 159 JSCallReduction r(node);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 return ReplaceWithPureReduction(node, ReduceMathCeil(node)); 227 return ReplaceWithPureReduction(node, ReduceMathCeil(node));
240 default: 228 default:
241 break; 229 break;
242 } 230 }
243 return NoChange(); 231 return NoChange();
244 } 232 }
245 233
246 } // namespace compiler 234 } // namespace compiler
247 } // namespace internal 235 } // namespace internal
248 } // namespace v8 236 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/diamond.h ('k') | src/compiler/js-intrinsic-builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698