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

Side by Side Diff: src/compiler/representation-change.h

Issue 461653002: Assume signed for converting to word32/float64 unless use or output is explicitly unsigned. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 | « no previous file | test/cctest/compiler/test-representation-change.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 #ifndef V8_COMPILER_REPRESENTATION_CHANGE_H_ 5 #ifndef V8_COMPILER_REPRESENTATION_CHANGE_H_
6 #define V8_COMPILER_REPRESENTATION_CHANGE_H_ 6 #define V8_COMPILER_REPRESENTATION_CHANGE_H_
7 7
8 #include "src/compiler/js-graph.h" 8 #include "src/compiler/js-graph.h"
9 #include "src/compiler/machine-operator.h" 9 #include "src/compiler/machine-operator.h"
10 #include "src/compiler/node-properties-inl.h" 10 #include "src/compiler/node-properties-inl.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 if ((use_type & rMask) == (output_type & rMask)) { 82 if ((use_type & rMask) == (output_type & rMask)) {
83 // Representations are the same. That's a no-op. 83 // Representations are the same. That's a no-op.
84 return node; 84 return node;
85 } 85 }
86 if (use_type & rTagged) { 86 if (use_type & rTagged) {
87 return GetTaggedRepresentationFor(node, output_type); 87 return GetTaggedRepresentationFor(node, output_type);
88 } else if (use_type & rFloat64) { 88 } else if (use_type & rFloat64) {
89 return GetFloat64RepresentationFor(node, output_type); 89 return GetFloat64RepresentationFor(node, output_type);
90 } else if (use_type & rWord32) { 90 } else if (use_type & rWord32) {
91 return GetWord32RepresentationFor(node, output_type); 91 return GetWord32RepresentationFor(node, output_type, use_type & tUint32);
92 } else if (use_type & rBit) { 92 } else if (use_type & rBit) {
93 return GetBitRepresentationFor(node, output_type); 93 return GetBitRepresentationFor(node, output_type);
94 } else if (use_type & rWord64) { 94 } else if (use_type & rWord64) {
95 return GetWord64RepresentationFor(node, output_type); 95 return GetWord64RepresentationFor(node, output_type);
96 } else { 96 } else {
97 return node; 97 return node;
98 } 98 }
99 } 99 }
100 100
101 Node* GetTaggedRepresentationFor(Node* node, RepTypeUnion output_type) { 101 Node* GetTaggedRepresentationFor(Node* node, RepTypeUnion output_type) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 case IrOpcode::kFloat64Constant: 158 case IrOpcode::kFloat64Constant:
159 return node; // No change necessary. 159 return node; // No change necessary.
160 default: 160 default:
161 break; 161 break;
162 } 162 }
163 // Select the correct X -> Float64 operator. 163 // Select the correct X -> Float64 operator.
164 Operator* op; 164 Operator* op;
165 if (output_type & rWord32) { 165 if (output_type & rWord32) {
166 if (output_type & tUint32) { 166 if (output_type & tUint32) {
167 op = machine()->ChangeUint32ToFloat64(); 167 op = machine()->ChangeUint32ToFloat64();
168 } else if (output_type & tInt32) { 168 } else {
169 op = machine()->ChangeInt32ToFloat64(); 169 op = machine()->ChangeInt32ToFloat64();
170 } else {
171 return TypeError(node, output_type, rFloat64);
172 } 170 }
173 } else if (output_type & rTagged) { 171 } else if (output_type & rTagged) {
174 op = simplified()->ChangeTaggedToFloat64(); 172 op = simplified()->ChangeTaggedToFloat64();
175 } else { 173 } else {
176 return TypeError(node, output_type, rFloat64); 174 return TypeError(node, output_type, rFloat64);
177 } 175 }
178 return jsgraph()->graph()->NewNode(op, node); 176 return jsgraph()->graph()->NewNode(op, node);
179 } 177 }
180 178
181 Node* GetWord32RepresentationFor(Node* node, RepTypeUnion output_type) { 179 Node* GetWord32RepresentationFor(Node* node, RepTypeUnion output_type,
180 bool use_unsigned) {
182 // Eagerly fold representation changes for constants. 181 // Eagerly fold representation changes for constants.
183 switch (node->opcode()) { 182 switch (node->opcode()) {
184 case IrOpcode::kInt32Constant: 183 case IrOpcode::kInt32Constant:
185 return node; // No change necessary. 184 return node; // No change necessary.
186 case IrOpcode::kNumberConstant: 185 case IrOpcode::kNumberConstant:
187 case IrOpcode::kFloat64Constant: { 186 case IrOpcode::kFloat64Constant: {
188 if (output_type & tUint32) { 187 double value = ValueOf<double>(node->op());
Michael Starzinger 2014/08/11 16:10:19 Can we call DCHECK(Is[Uint|Int]32Double(value)) he
189 int32_t value = static_cast<int32_t>( 188 if (value < 0) {
190 static_cast<uint32_t>(ValueOf<double>(node->op()))); 189 DCHECK(value >= kMinInt && value <= kMaxInt);
191 return jsgraph()->Int32Constant(value); 190 int32_t iv = static_cast<int32_t>(value);
192 } else if (output_type & tInt32) { 191 return jsgraph()->Int32Constant(iv);
193 int32_t value = FastD2I(ValueOf<double>(node->op()));
194 return jsgraph()->Int32Constant(value);
195 } else { 192 } else {
196 return TypeError(node, output_type, rWord32); 193 DCHECK(value >= 0 && value <= kMaxUInt32);
194 int32_t iv = static_cast<int32_t>(static_cast<uint32_t>(value));
195 return jsgraph()->Int32Constant(iv);
197 } 196 }
198 } 197 }
199 default: 198 default:
200 break; 199 break;
201 } 200 }
202 // Select the correct X -> Word32 operator. 201 // Select the correct X -> Word32 operator.
203 Operator* op = NULL; 202 Operator* op = NULL;
204 if (output_type & rFloat64) { 203 if (output_type & rFloat64) {
205 if (output_type & tUint32) { 204 if (output_type & tUint32 || use_unsigned) {
206 op = machine()->ChangeFloat64ToUint32(); 205 op = machine()->ChangeFloat64ToUint32();
207 } else if (output_type & tInt32) { 206 } else {
208 op = machine()->ChangeFloat64ToInt32(); 207 op = machine()->ChangeFloat64ToInt32();
209 } else {
210 return TypeError(node, output_type, rWord32);
211 } 208 }
212 } else if (output_type & rTagged) { 209 } else if (output_type & rTagged) {
213 if (output_type & tUint32) { 210 if (output_type & tUint32 || use_unsigned) {
214 op = simplified()->ChangeTaggedToUint32(); 211 op = simplified()->ChangeTaggedToUint32();
215 } else if (output_type & tInt32) { 212 } else {
216 op = simplified()->ChangeTaggedToInt32(); 213 op = simplified()->ChangeTaggedToInt32();
217 } else {
218 return TypeError(node, output_type, rWord32);
219 } 214 }
220 } else if (output_type & rBit) { 215 } else if (output_type & rBit) {
221 return node; // Sloppy comparison -> word32. 216 return node; // Sloppy comparison -> word32.
222 } else { 217 } else {
223 return TypeError(node, output_type, rWord32); 218 return TypeError(node, output_type, rWord32);
224 } 219 }
225 return jsgraph()->graph()->NewNode(op, node); 220 return jsgraph()->graph()->NewNode(op, node);
226 } 221 }
227 222
228 Node* GetBitRepresentationFor(Node* node, RepTypeUnion output_type) { 223 Node* GetBitRepresentationFor(Node* node, RepTypeUnion output_type) {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 JSGraph* jsgraph() { return jsgraph_; } 402 JSGraph* jsgraph() { return jsgraph_; }
408 Isolate* isolate() { return isolate_; } 403 Isolate* isolate() { return isolate_; }
409 SimplifiedOperatorBuilder* simplified() { return simplified_; } 404 SimplifiedOperatorBuilder* simplified() { return simplified_; }
410 MachineOperatorBuilder* machine() { return machine_; } 405 MachineOperatorBuilder* machine() { return machine_; }
411 }; 406 };
412 } 407 }
413 } 408 }
414 } // namespace v8::internal::compiler 409 } // namespace v8::internal::compiler
415 410
416 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ 411 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_
OLDNEW
« no previous file with comments | « no previous file | test/cctest/compiler/test-representation-change.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698