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

Side by Side Diff: test/cctest/compiler/test-representation-change.cc

Issue 1571263004: [turbofan] Replace MachineSemantic with Type in simplified lowering. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rename upper -> type Created 4 years, 11 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/simplified-lowering.cc ('k') | no next file » | 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 <limits> 5 #include <limits>
6 6
7 #include "test/cctest/cctest.h" 7 #include "test/cctest/cctest.h"
8 #include "test/cctest/compiler/codegen-tester.h" 8 #include "test/cctest/compiler/codegen-tester.h"
9 #include "test/cctest/compiler/graph-builder-tester.h" 9 #include "test/cctest/compiler/graph-builder-tester.h"
10 #include "test/cctest/compiler/value-helper.h" 10 #include "test/cctest/compiler/value-helper.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 CHECK(m.HasValue()); 76 CHECK(m.HasValue());
77 CheckDoubleEq(expected, m.Value()); 77 CheckDoubleEq(expected, m.Value());
78 } 78 }
79 79
80 Node* Parameter(int index = 0) { 80 Node* Parameter(int index = 0) {
81 Node* n = graph()->NewNode(common()->Parameter(index), graph()->start()); 81 Node* n = graph()->NewNode(common()->Parameter(index), graph()->start());
82 NodeProperties::SetType(n, Type::Any()); 82 NodeProperties::SetType(n, Type::Any());
83 return n; 83 return n;
84 } 84 }
85 85
86 void CheckTypeError(MachineType from, MachineRepresentation to) { 86 void CheckTypeError(MachineRepresentation from, Type* from_type,
87 MachineRepresentation to) {
87 changer()->testing_type_errors_ = true; 88 changer()->testing_type_errors_ = true;
88 changer()->type_error_ = false; 89 changer()->type_error_ = false;
89 Node* n = Parameter(0); 90 Node* n = Parameter(0);
90 Node* c = changer()->GetRepresentationFor(n, from, to); 91 Node* c = changer()->GetRepresentationFor(n, from, from_type, to);
91 CHECK(changer()->type_error_); 92 CHECK(changer()->type_error_);
92 CHECK_EQ(n, c); 93 CHECK_EQ(n, c);
93 } 94 }
94 95
95 void CheckNop(MachineType from, MachineRepresentation to) { 96 void CheckNop(MachineRepresentation from, Type* from_type,
97 MachineRepresentation to) {
96 Node* n = Parameter(0); 98 Node* n = Parameter(0);
97 Node* c = changer()->GetRepresentationFor(n, from, to); 99 Node* c = changer()->GetRepresentationFor(n, from, from_type, to);
98 CHECK_EQ(n, c); 100 CHECK_EQ(n, c);
99 } 101 }
100 }; 102 };
101 103
102 104
103 const MachineType kMachineTypes[] = { 105 const MachineType kMachineTypes[] = {
104 MachineType::Float32(), MachineType::Float64(), MachineType::Int8(), 106 MachineType::Float32(), MachineType::Float64(), MachineType::Int8(),
105 MachineType::Uint8(), MachineType::Int16(), MachineType::Uint16(), 107 MachineType::Uint8(), MachineType::Int16(), MachineType::Uint16(),
106 MachineType::Int32(), MachineType::Uint32(), MachineType::Int64(), 108 MachineType::Int32(), MachineType::Uint32(), MachineType::Int64(),
107 MachineType::Uint64(), MachineType::AnyTagged()}; 109 MachineType::Uint64(), MachineType::AnyTagged()};
108 110
109 111
110 TEST(BoolToBit_constant) { 112 TEST(BoolToBit_constant) {
111 RepresentationChangerTester r; 113 RepresentationChangerTester r;
112 114
113 Node* true_node = r.jsgraph()->TrueConstant(); 115 Node* true_node = r.jsgraph()->TrueConstant();
114 Node* true_bit = r.changer()->GetRepresentationFor( 116 Node* true_bit = r.changer()->GetRepresentationFor(
115 true_node, MachineType::RepTagged(), MachineRepresentation::kBit); 117 true_node, MachineRepresentation::kTagged, Type::None(),
118 MachineRepresentation::kBit);
116 r.CheckInt32Constant(true_bit, 1); 119 r.CheckInt32Constant(true_bit, 1);
117 120
118 Node* false_node = r.jsgraph()->FalseConstant(); 121 Node* false_node = r.jsgraph()->FalseConstant();
119 Node* false_bit = r.changer()->GetRepresentationFor( 122 Node* false_bit = r.changer()->GetRepresentationFor(
120 false_node, MachineType::RepTagged(), MachineRepresentation::kBit); 123 false_node, MachineRepresentation::kTagged, Type::None(),
124 MachineRepresentation::kBit);
121 r.CheckInt32Constant(false_bit, 0); 125 r.CheckInt32Constant(false_bit, 0);
122 } 126 }
123 127
124 128
125 TEST(BitToBool_constant) { 129 TEST(BitToBool_constant) {
126 RepresentationChangerTester r; 130 RepresentationChangerTester r;
127 131
128 for (int i = -5; i < 5; i++) { 132 for (int i = -5; i < 5; i++) {
129 Node* node = r.jsgraph()->Int32Constant(i); 133 Node* node = r.jsgraph()->Int32Constant(i);
130 Node* val = r.changer()->GetRepresentationFor( 134 Node* val = r.changer()->GetRepresentationFor(
131 node, MachineType::RepBit(), MachineRepresentation::kTagged); 135 node, MachineRepresentation::kBit, Type::Boolean(),
136 MachineRepresentation::kTagged);
132 r.CheckHeapConstant(val, i == 0 ? r.isolate()->heap()->false_value() 137 r.CheckHeapConstant(val, i == 0 ? r.isolate()->heap()->false_value()
133 : r.isolate()->heap()->true_value()); 138 : r.isolate()->heap()->true_value());
134 } 139 }
135 } 140 }
136 141
137 142
138 TEST(ToTagged_constant) { 143 TEST(ToTagged_constant) {
139 RepresentationChangerTester r; 144 RepresentationChangerTester r;
140 145
141 { 146 {
142 FOR_FLOAT64_INPUTS(i) { 147 FOR_FLOAT64_INPUTS(i) {
143 Node* n = r.jsgraph()->Float64Constant(*i); 148 Node* n = r.jsgraph()->Float64Constant(*i);
144 Node* c = r.changer()->GetRepresentationFor( 149 Node* c = r.changer()->GetRepresentationFor(
145 n, MachineType::RepFloat64(), MachineRepresentation::kTagged); 150 n, MachineRepresentation::kFloat64, Type::None(),
151 MachineRepresentation::kTagged);
146 r.CheckNumberConstant(c, *i); 152 r.CheckNumberConstant(c, *i);
147 } 153 }
148 } 154 }
149 155
150 { 156 {
151 FOR_FLOAT64_INPUTS(i) { 157 FOR_FLOAT64_INPUTS(i) {
152 Node* n = r.jsgraph()->Constant(*i); 158 Node* n = r.jsgraph()->Constant(*i);
153 Node* c = r.changer()->GetRepresentationFor( 159 Node* c = r.changer()->GetRepresentationFor(
154 n, MachineType::RepFloat64(), MachineRepresentation::kTagged); 160 n, MachineRepresentation::kFloat64, Type::None(),
161 MachineRepresentation::kTagged);
155 r.CheckNumberConstant(c, *i); 162 r.CheckNumberConstant(c, *i);
156 } 163 }
157 } 164 }
158 165
159 { 166 {
160 FOR_FLOAT32_INPUTS(i) { 167 FOR_FLOAT32_INPUTS(i) {
161 Node* n = r.jsgraph()->Float32Constant(*i); 168 Node* n = r.jsgraph()->Float32Constant(*i);
162 Node* c = r.changer()->GetRepresentationFor( 169 Node* c = r.changer()->GetRepresentationFor(
163 n, MachineType::RepFloat32(), MachineRepresentation::kTagged); 170 n, MachineRepresentation::kFloat32, Type::None(),
171 MachineRepresentation::kTagged);
164 r.CheckNumberConstant(c, *i); 172 r.CheckNumberConstant(c, *i);
165 } 173 }
166 } 174 }
167 175
168 { 176 {
169 FOR_INT32_INPUTS(i) { 177 FOR_INT32_INPUTS(i) {
170 Node* n = r.jsgraph()->Int32Constant(*i); 178 Node* n = r.jsgraph()->Int32Constant(*i);
171 Node* c = r.changer()->GetRepresentationFor( 179 Node* c = r.changer()->GetRepresentationFor(
172 n, MachineType::Int32(), MachineRepresentation::kTagged); 180 n, MachineRepresentation::kWord32, Type::Signed32(),
181 MachineRepresentation::kTagged);
173 r.CheckNumberConstant(c, *i); 182 r.CheckNumberConstant(c, *i);
174 } 183 }
175 } 184 }
176 185
177 { 186 {
178 FOR_UINT32_INPUTS(i) { 187 FOR_UINT32_INPUTS(i) {
179 Node* n = r.jsgraph()->Int32Constant(*i); 188 Node* n = r.jsgraph()->Int32Constant(*i);
180 Node* c = r.changer()->GetRepresentationFor( 189 Node* c = r.changer()->GetRepresentationFor(
181 n, MachineType::Uint32(), MachineRepresentation::kTagged); 190 n, MachineRepresentation::kWord32, Type::Unsigned32(),
191 MachineRepresentation::kTagged);
182 r.CheckNumberConstant(c, *i); 192 r.CheckNumberConstant(c, *i);
183 } 193 }
184 } 194 }
185 } 195 }
186 196
187 197
188 TEST(ToFloat64_constant) { 198 TEST(ToFloat64_constant) {
189 RepresentationChangerTester r; 199 RepresentationChangerTester r;
190 200
191 { 201 {
192 FOR_FLOAT64_INPUTS(i) { 202 FOR_FLOAT64_INPUTS(i) {
193 Node* n = r.jsgraph()->Float64Constant(*i); 203 Node* n = r.jsgraph()->Float64Constant(*i);
194 Node* c = r.changer()->GetRepresentationFor( 204 Node* c = r.changer()->GetRepresentationFor(
195 n, MachineType::RepFloat64(), MachineRepresentation::kFloat64); 205 n, MachineRepresentation::kFloat64, Type::None(),
206 MachineRepresentation::kFloat64);
196 CHECK_EQ(n, c); 207 CHECK_EQ(n, c);
197 } 208 }
198 } 209 }
199 210
200 { 211 {
201 FOR_FLOAT64_INPUTS(i) { 212 FOR_FLOAT64_INPUTS(i) {
202 Node* n = r.jsgraph()->Constant(*i); 213 Node* n = r.jsgraph()->Constant(*i);
203 Node* c = r.changer()->GetRepresentationFor( 214 Node* c = r.changer()->GetRepresentationFor(
204 n, MachineType::RepTagged(), MachineRepresentation::kFloat64); 215 n, MachineRepresentation::kTagged, Type::None(),
216 MachineRepresentation::kFloat64);
205 r.CheckFloat64Constant(c, *i); 217 r.CheckFloat64Constant(c, *i);
206 } 218 }
207 } 219 }
208 220
209 { 221 {
210 FOR_FLOAT32_INPUTS(i) { 222 FOR_FLOAT32_INPUTS(i) {
211 Node* n = r.jsgraph()->Float32Constant(*i); 223 Node* n = r.jsgraph()->Float32Constant(*i);
212 Node* c = r.changer()->GetRepresentationFor( 224 Node* c = r.changer()->GetRepresentationFor(
213 n, MachineType::RepFloat32(), MachineRepresentation::kFloat64); 225 n, MachineRepresentation::kFloat32, Type::None(),
226 MachineRepresentation::kFloat64);
214 r.CheckFloat64Constant(c, *i); 227 r.CheckFloat64Constant(c, *i);
215 } 228 }
216 } 229 }
217 230
218 { 231 {
219 FOR_INT32_INPUTS(i) { 232 FOR_INT32_INPUTS(i) {
220 Node* n = r.jsgraph()->Int32Constant(*i); 233 Node* n = r.jsgraph()->Int32Constant(*i);
221 Node* c = r.changer()->GetRepresentationFor( 234 Node* c = r.changer()->GetRepresentationFor(
222 n, MachineType::Int32(), MachineRepresentation::kFloat64); 235 n, MachineRepresentation::kWord32, Type::Signed32(),
236 MachineRepresentation::kFloat64);
223 r.CheckFloat64Constant(c, *i); 237 r.CheckFloat64Constant(c, *i);
224 } 238 }
225 } 239 }
226 240
227 { 241 {
228 FOR_UINT32_INPUTS(i) { 242 FOR_UINT32_INPUTS(i) {
229 Node* n = r.jsgraph()->Int32Constant(*i); 243 Node* n = r.jsgraph()->Int32Constant(*i);
230 Node* c = r.changer()->GetRepresentationFor( 244 Node* c = r.changer()->GetRepresentationFor(
231 n, MachineType::Uint32(), MachineRepresentation::kFloat64); 245 n, MachineRepresentation::kWord32, Type::Unsigned32(),
246 MachineRepresentation::kFloat64);
232 r.CheckFloat64Constant(c, *i); 247 r.CheckFloat64Constant(c, *i);
233 } 248 }
234 } 249 }
235 } 250 }
236 251
237 252
238 static bool IsFloat32Int32(int32_t val) { 253 static bool IsFloat32Int32(int32_t val) {
239 return val >= -(1 << 23) && val <= (1 << 23); 254 return val >= -(1 << 23) && val <= (1 << 23);
240 } 255 }
241 256
242 257
243 static bool IsFloat32Uint32(uint32_t val) { return val <= (1 << 23); } 258 static bool IsFloat32Uint32(uint32_t val) { return val <= (1 << 23); }
244 259
245 260
246 TEST(ToFloat32_constant) { 261 TEST(ToFloat32_constant) {
247 RepresentationChangerTester r; 262 RepresentationChangerTester r;
248 263
249 { 264 {
250 FOR_FLOAT32_INPUTS(i) { 265 FOR_FLOAT32_INPUTS(i) {
251 Node* n = r.jsgraph()->Float32Constant(*i); 266 Node* n = r.jsgraph()->Float32Constant(*i);
252 Node* c = r.changer()->GetRepresentationFor( 267 Node* c = r.changer()->GetRepresentationFor(
253 n, MachineType::RepFloat32(), MachineRepresentation::kFloat32); 268 n, MachineRepresentation::kFloat32, Type::None(),
269 MachineRepresentation::kFloat32);
254 CHECK_EQ(n, c); 270 CHECK_EQ(n, c);
255 } 271 }
256 } 272 }
257 273
258 { 274 {
259 FOR_FLOAT32_INPUTS(i) { 275 FOR_FLOAT32_INPUTS(i) {
260 Node* n = r.jsgraph()->Constant(*i); 276 Node* n = r.jsgraph()->Constant(*i);
261 Node* c = r.changer()->GetRepresentationFor( 277 Node* c = r.changer()->GetRepresentationFor(
262 n, MachineType::RepTagged(), MachineRepresentation::kFloat32); 278 n, MachineRepresentation::kTagged, Type::None(),
279 MachineRepresentation::kFloat32);
263 r.CheckFloat32Constant(c, *i); 280 r.CheckFloat32Constant(c, *i);
264 } 281 }
265 } 282 }
266 283
267 { 284 {
268 FOR_FLOAT32_INPUTS(i) { 285 FOR_FLOAT32_INPUTS(i) {
269 Node* n = r.jsgraph()->Float64Constant(*i); 286 Node* n = r.jsgraph()->Float64Constant(*i);
270 Node* c = r.changer()->GetRepresentationFor( 287 Node* c = r.changer()->GetRepresentationFor(
271 n, MachineType::RepFloat64(), MachineRepresentation::kFloat32); 288 n, MachineRepresentation::kFloat64, Type::None(),
289 MachineRepresentation::kFloat32);
272 r.CheckFloat32Constant(c, *i); 290 r.CheckFloat32Constant(c, *i);
273 } 291 }
274 } 292 }
275 293
276 { 294 {
277 FOR_INT32_INPUTS(i) { 295 FOR_INT32_INPUTS(i) {
278 if (!IsFloat32Int32(*i)) continue; 296 if (!IsFloat32Int32(*i)) continue;
279 Node* n = r.jsgraph()->Int32Constant(*i); 297 Node* n = r.jsgraph()->Int32Constant(*i);
280 Node* c = r.changer()->GetRepresentationFor( 298 Node* c = r.changer()->GetRepresentationFor(
281 n, MachineType::Int32(), MachineRepresentation::kFloat32); 299 n, MachineRepresentation::kWord32, Type::Signed32(),
300 MachineRepresentation::kFloat32);
282 r.CheckFloat32Constant(c, static_cast<float>(*i)); 301 r.CheckFloat32Constant(c, static_cast<float>(*i));
283 } 302 }
284 } 303 }
285 304
286 { 305 {
287 FOR_UINT32_INPUTS(i) { 306 FOR_UINT32_INPUTS(i) {
288 if (!IsFloat32Uint32(*i)) continue; 307 if (!IsFloat32Uint32(*i)) continue;
289 Node* n = r.jsgraph()->Int32Constant(*i); 308 Node* n = r.jsgraph()->Int32Constant(*i);
290 Node* c = r.changer()->GetRepresentationFor( 309 Node* c = r.changer()->GetRepresentationFor(
291 n, MachineType::Uint32(), MachineRepresentation::kFloat32); 310 n, MachineRepresentation::kWord32, Type::Unsigned32(),
311 MachineRepresentation::kFloat32);
292 r.CheckFloat32Constant(c, static_cast<float>(*i)); 312 r.CheckFloat32Constant(c, static_cast<float>(*i));
293 } 313 }
294 } 314 }
295 } 315 }
296 316
297 317
298 TEST(ToInt32_constant) { 318 TEST(ToInt32_constant) {
299 RepresentationChangerTester r; 319 RepresentationChangerTester r;
300 320
301 { 321 {
302 FOR_INT32_INPUTS(i) { 322 FOR_INT32_INPUTS(i) {
303 Node* n = r.jsgraph()->Int32Constant(*i); 323 Node* n = r.jsgraph()->Int32Constant(*i);
304 Node* c = r.changer()->GetRepresentationFor( 324 Node* c = r.changer()->GetRepresentationFor(
305 n, MachineType::Int32(), MachineRepresentation::kWord32); 325 n, MachineRepresentation::kWord32, Type::Signed32(),
326 MachineRepresentation::kWord32);
306 r.CheckInt32Constant(c, *i); 327 r.CheckInt32Constant(c, *i);
307 } 328 }
308 } 329 }
309 330
310 { 331 {
311 FOR_INT32_INPUTS(i) { 332 FOR_INT32_INPUTS(i) {
312 if (!IsFloat32Int32(*i)) continue; 333 if (!IsFloat32Int32(*i)) continue;
313 Node* n = r.jsgraph()->Float32Constant(static_cast<float>(*i)); 334 Node* n = r.jsgraph()->Float32Constant(static_cast<float>(*i));
314 Node* c = r.changer()->GetRepresentationFor( 335 Node* c = r.changer()->GetRepresentationFor(
315 n, 336 n, MachineRepresentation::kFloat32, Type::Signed32(),
316 MachineType(MachineRepresentation::kFloat32, MachineSemantic::kInt32),
317 MachineRepresentation::kWord32); 337 MachineRepresentation::kWord32);
318 r.CheckInt32Constant(c, *i); 338 r.CheckInt32Constant(c, *i);
319 } 339 }
320 } 340 }
321 341
322 { 342 {
323 FOR_INT32_INPUTS(i) { 343 FOR_INT32_INPUTS(i) {
324 Node* n = r.jsgraph()->Float64Constant(*i); 344 Node* n = r.jsgraph()->Float64Constant(*i);
325 Node* c = r.changer()->GetRepresentationFor( 345 Node* c = r.changer()->GetRepresentationFor(
326 n, 346 n, MachineRepresentation::kFloat64, Type::Signed32(),
327 MachineType(MachineRepresentation::kFloat64, MachineSemantic::kInt32),
328 MachineRepresentation::kWord32); 347 MachineRepresentation::kWord32);
329 r.CheckInt32Constant(c, *i); 348 r.CheckInt32Constant(c, *i);
330 } 349 }
331 } 350 }
332 351
333 { 352 {
334 FOR_INT32_INPUTS(i) { 353 FOR_INT32_INPUTS(i) {
335 Node* n = r.jsgraph()->Constant(*i); 354 Node* n = r.jsgraph()->Constant(*i);
336 Node* c = r.changer()->GetRepresentationFor( 355 Node* c = r.changer()->GetRepresentationFor(
337 n, 356 n, MachineRepresentation::kTagged, Type::Signed32(),
338 MachineType(MachineRepresentation::kTagged, MachineSemantic::kInt32),
339 MachineRepresentation::kWord32); 357 MachineRepresentation::kWord32);
340 r.CheckInt32Constant(c, *i); 358 r.CheckInt32Constant(c, *i);
341 } 359 }
342 } 360 }
343 } 361 }
344 362
345 363
346 TEST(ToUint32_constant) { 364 TEST(ToUint32_constant) {
347 RepresentationChangerTester r; 365 RepresentationChangerTester r;
348 366
349 { 367 {
350 FOR_UINT32_INPUTS(i) { 368 FOR_UINT32_INPUTS(i) {
351 Node* n = r.jsgraph()->Int32Constant(*i); 369 Node* n = r.jsgraph()->Int32Constant(*i);
352 Node* c = r.changer()->GetRepresentationFor( 370 Node* c = r.changer()->GetRepresentationFor(
353 n, MachineType::Uint32(), MachineRepresentation::kWord32); 371 n, MachineRepresentation::kWord32, Type::Unsigned32(),
372 MachineRepresentation::kWord32);
354 r.CheckUint32Constant(c, *i); 373 r.CheckUint32Constant(c, *i);
355 } 374 }
356 } 375 }
357 376
358 { 377 {
359 FOR_UINT32_INPUTS(i) { 378 FOR_UINT32_INPUTS(i) {
360 if (!IsFloat32Uint32(*i)) continue; 379 if (!IsFloat32Uint32(*i)) continue;
361 Node* n = r.jsgraph()->Float32Constant(static_cast<float>(*i)); 380 Node* n = r.jsgraph()->Float32Constant(static_cast<float>(*i));
362 Node* c = r.changer()->GetRepresentationFor( 381 Node* c = r.changer()->GetRepresentationFor(
363 n, MachineType(MachineRepresentation::kFloat32, 382 n, MachineRepresentation::kFloat32, Type::Unsigned32(),
364 MachineSemantic::kUint32),
365 MachineRepresentation::kWord32); 383 MachineRepresentation::kWord32);
366 r.CheckUint32Constant(c, *i); 384 r.CheckUint32Constant(c, *i);
367 } 385 }
368 } 386 }
369 387
370 { 388 {
371 FOR_UINT32_INPUTS(i) { 389 FOR_UINT32_INPUTS(i) {
372 Node* n = r.jsgraph()->Float64Constant(*i); 390 Node* n = r.jsgraph()->Float64Constant(*i);
373 Node* c = r.changer()->GetRepresentationFor( 391 Node* c = r.changer()->GetRepresentationFor(
374 n, MachineType(MachineRepresentation::kFloat64, 392 n, MachineRepresentation::kFloat64, Type::Unsigned32(),
375 MachineSemantic::kUint32),
376 MachineRepresentation::kWord32); 393 MachineRepresentation::kWord32);
377 r.CheckUint32Constant(c, *i); 394 r.CheckUint32Constant(c, *i);
378 } 395 }
379 } 396 }
380 397
381 { 398 {
382 FOR_UINT32_INPUTS(i) { 399 FOR_UINT32_INPUTS(i) {
383 Node* n = r.jsgraph()->Constant(static_cast<double>(*i)); 400 Node* n = r.jsgraph()->Constant(static_cast<double>(*i));
384 Node* c = r.changer()->GetRepresentationFor( 401 Node* c = r.changer()->GetRepresentationFor(
385 n, 402 n, MachineRepresentation::kTagged, Type::Unsigned32(),
386 MachineType(MachineRepresentation::kTagged, MachineSemantic::kUint32),
387 MachineRepresentation::kWord32); 403 MachineRepresentation::kWord32);
388 r.CheckUint32Constant(c, *i); 404 r.CheckUint32Constant(c, *i);
389 } 405 }
390 } 406 }
391 } 407 }
392 408
393 409
394 static void CheckChange(IrOpcode::Value expected, MachineType from, 410 static void CheckChange(IrOpcode::Value expected, MachineRepresentation from,
395 MachineRepresentation to) { 411 Type* from_type, MachineRepresentation to) {
396 RepresentationChangerTester r; 412 RepresentationChangerTester r;
397 413
398 Node* n = r.Parameter(); 414 Node* n = r.Parameter();
399 Node* c = r.changer()->GetRepresentationFor(n, from, to); 415 Node* c = r.changer()->GetRepresentationFor(n, from, from_type, to);
400 416
401 CHECK_NE(c, n); 417 CHECK_NE(c, n);
402 CHECK_EQ(expected, c->opcode()); 418 CHECK_EQ(expected, c->opcode());
403 CHECK_EQ(n, c->InputAt(0)); 419 CHECK_EQ(n, c->InputAt(0));
404 } 420 }
405 421
406 422
407 static void CheckTwoChanges(IrOpcode::Value expected2, 423 static void CheckTwoChanges(IrOpcode::Value expected2,
408 IrOpcode::Value expected1, MachineType from, 424 IrOpcode::Value expected1,
425 MachineRepresentation from, Type* from_type,
409 MachineRepresentation to) { 426 MachineRepresentation to) {
410 RepresentationChangerTester r; 427 RepresentationChangerTester r;
411 428
412 Node* n = r.Parameter(); 429 Node* n = r.Parameter();
413 Node* c1 = r.changer()->GetRepresentationFor(n, from, to); 430 Node* c1 = r.changer()->GetRepresentationFor(n, from, from_type, to);
414 431
415 CHECK_NE(c1, n); 432 CHECK_NE(c1, n);
416 CHECK_EQ(expected1, c1->opcode()); 433 CHECK_EQ(expected1, c1->opcode());
417 Node* c2 = c1->InputAt(0); 434 Node* c2 = c1->InputAt(0);
418 CHECK_NE(c2, n); 435 CHECK_NE(c2, n);
419 CHECK_EQ(expected2, c2->opcode()); 436 CHECK_EQ(expected2, c2->opcode());
420 CHECK_EQ(n, c2->InputAt(0)); 437 CHECK_EQ(n, c2->InputAt(0));
421 } 438 }
422 439
423 440
424 TEST(SingleChanges) { 441 TEST(SingleChanges) {
425 CheckChange(IrOpcode::kChangeBoolToBit, MachineType::RepTagged(), 442 CheckChange(IrOpcode::kChangeBoolToBit, MachineRepresentation::kTagged,
426 MachineRepresentation::kBit); 443 Type::None(), MachineRepresentation::kBit);
427 CheckChange(IrOpcode::kChangeBitToBool, MachineType::RepBit(), 444 CheckChange(IrOpcode::kChangeBitToBool, MachineRepresentation::kBit,
428 MachineRepresentation::kTagged); 445 Type::None(), MachineRepresentation::kTagged);
429 446
430 CheckChange(IrOpcode::kChangeInt32ToTagged, MachineType::Int32(), 447 CheckChange(IrOpcode::kChangeInt32ToTagged, MachineRepresentation::kWord32,
431 MachineRepresentation::kTagged); 448 Type::Signed32(), MachineRepresentation::kTagged);
432 CheckChange(IrOpcode::kChangeUint32ToTagged, MachineType::Uint32(), 449 CheckChange(IrOpcode::kChangeUint32ToTagged, MachineRepresentation::kWord32,
433 MachineRepresentation::kTagged); 450 Type::Unsigned32(), MachineRepresentation::kTagged);
434 CheckChange(IrOpcode::kChangeFloat64ToTagged, MachineType::RepFloat64(), 451 CheckChange(IrOpcode::kChangeFloat64ToTagged, MachineRepresentation::kFloat64,
435 MachineRepresentation::kTagged); 452 Type::None(), MachineRepresentation::kTagged);
436 453
437 CheckChange( 454 CheckChange(IrOpcode::kChangeTaggedToInt32, MachineRepresentation::kTagged,
438 IrOpcode::kChangeTaggedToInt32, 455 Type::Signed32(), MachineRepresentation::kWord32);
439 MachineType(MachineRepresentation::kTagged, MachineSemantic::kInt32), 456 CheckChange(IrOpcode::kChangeTaggedToUint32, MachineRepresentation::kTagged,
440 MachineRepresentation::kWord32); 457 Type::Unsigned32(), MachineRepresentation::kWord32);
441 CheckChange( 458 CheckChange(IrOpcode::kChangeTaggedToFloat64, MachineRepresentation::kTagged,
442 IrOpcode::kChangeTaggedToUint32, 459 Type::None(), MachineRepresentation::kFloat64);
443 MachineType(MachineRepresentation::kTagged, MachineSemantic::kUint32),
444 MachineRepresentation::kWord32);
445 CheckChange(IrOpcode::kChangeTaggedToFloat64, MachineType::RepTagged(),
446 MachineRepresentation::kFloat64);
447 460
448 // Int32,Uint32 <-> Float64 are actually machine conversions. 461 // Int32,Uint32 <-> Float64 are actually machine conversions.
449 CheckChange(IrOpcode::kChangeInt32ToFloat64, MachineType::Int32(), 462 CheckChange(IrOpcode::kChangeInt32ToFloat64, MachineRepresentation::kWord32,
450 MachineRepresentation::kFloat64); 463 Type::Signed32(), MachineRepresentation::kFloat64);
451 CheckChange(IrOpcode::kChangeUint32ToFloat64, MachineType::Uint32(), 464 CheckChange(IrOpcode::kChangeUint32ToFloat64, MachineRepresentation::kWord32,
452 MachineRepresentation::kFloat64); 465 Type::Unsigned32(), MachineRepresentation::kFloat64);
453 CheckChange( 466 CheckChange(IrOpcode::kChangeFloat64ToInt32, MachineRepresentation::kFloat64,
454 IrOpcode::kChangeFloat64ToInt32, 467 Type::Signed32(), MachineRepresentation::kWord32);
455 MachineType(MachineRepresentation::kFloat64, MachineSemantic::kInt32), 468 CheckChange(IrOpcode::kChangeFloat64ToUint32, MachineRepresentation::kFloat64,
456 MachineRepresentation::kWord32); 469 Type::Unsigned32(), MachineRepresentation::kWord32);
457 CheckChange(
458 IrOpcode::kChangeFloat64ToUint32,
459 MachineType(MachineRepresentation::kFloat64, MachineSemantic::kUint32),
460 MachineRepresentation::kWord32);
461 470
462 CheckChange(IrOpcode::kTruncateFloat64ToFloat32, MachineType::RepFloat64(), 471 CheckChange(IrOpcode::kTruncateFloat64ToFloat32,
472 MachineRepresentation::kFloat64, Type::None(),
463 MachineRepresentation::kFloat32); 473 MachineRepresentation::kFloat32);
464 474
465 // Int32,Uint32 <-> Float32 require two changes. 475 // Int32,Uint32 <-> Float32 require two changes.
466 CheckTwoChanges(IrOpcode::kChangeInt32ToFloat64, 476 CheckTwoChanges(IrOpcode::kChangeInt32ToFloat64,
467 IrOpcode::kTruncateFloat64ToFloat32, MachineType::Int32(), 477 IrOpcode::kTruncateFloat64ToFloat32,
478 MachineRepresentation::kWord32, Type::Signed32(),
468 MachineRepresentation::kFloat32); 479 MachineRepresentation::kFloat32);
469 CheckTwoChanges(IrOpcode::kChangeUint32ToFloat64, 480 CheckTwoChanges(IrOpcode::kChangeUint32ToFloat64,
470 IrOpcode::kTruncateFloat64ToFloat32, MachineType::Uint32(), 481 IrOpcode::kTruncateFloat64ToFloat32,
482 MachineRepresentation::kWord32, Type::Unsigned32(),
471 MachineRepresentation::kFloat32); 483 MachineRepresentation::kFloat32);
472 CheckTwoChanges( 484 CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64,
473 IrOpcode::kChangeFloat32ToFloat64, IrOpcode::kChangeFloat64ToInt32, 485 IrOpcode::kChangeFloat64ToInt32,
474 MachineType(MachineRepresentation::kFloat32, MachineSemantic::kInt32), 486 MachineRepresentation::kFloat32, Type::Signed32(),
475 MachineRepresentation::kWord32); 487 MachineRepresentation::kWord32);
476 CheckTwoChanges( 488 CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64,
477 IrOpcode::kChangeFloat32ToFloat64, IrOpcode::kChangeFloat64ToUint32, 489 IrOpcode::kChangeFloat64ToUint32,
478 MachineType(MachineRepresentation::kFloat32, MachineSemantic::kUint32), 490 MachineRepresentation::kFloat32, Type::Unsigned32(),
479 MachineRepresentation::kWord32); 491 MachineRepresentation::kWord32);
480 492
481 // Float32 <-> Tagged require two changes. 493 // Float32 <-> Tagged require two changes.
482 CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64, 494 CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64,
483 IrOpcode::kChangeFloat64ToTagged, MachineType::RepFloat32(), 495 IrOpcode::kChangeFloat64ToTagged,
496 MachineRepresentation::kFloat32, Type::None(),
484 MachineRepresentation::kTagged); 497 MachineRepresentation::kTagged);
485 CheckTwoChanges(IrOpcode::kChangeTaggedToFloat64, 498 CheckTwoChanges(IrOpcode::kChangeTaggedToFloat64,
486 IrOpcode::kTruncateFloat64ToFloat32, MachineType::RepTagged(), 499 IrOpcode::kTruncateFloat64ToFloat32,
500 MachineRepresentation::kTagged, Type::None(),
487 MachineRepresentation::kFloat32); 501 MachineRepresentation::kFloat32);
488 } 502 }
489 503
490 504
491 TEST(SignednessInWord32) { 505 TEST(SignednessInWord32) {
492 RepresentationChangerTester r; 506 RepresentationChangerTester r;
493 507
494 CheckChange( 508 CheckChange(IrOpcode::kChangeTaggedToInt32, MachineRepresentation::kTagged,
495 IrOpcode::kChangeTaggedToInt32, 509 Type::Signed32(), MachineRepresentation::kWord32);
496 MachineType(MachineRepresentation::kTagged, MachineSemantic::kInt32), 510 CheckChange(IrOpcode::kChangeTaggedToUint32, MachineRepresentation::kTagged,
497 MachineRepresentation::kWord32); 511 Type::Unsigned32(), MachineRepresentation::kWord32);
498 CheckChange( 512 CheckChange(IrOpcode::kChangeInt32ToFloat64, MachineRepresentation::kWord32,
499 IrOpcode::kChangeTaggedToUint32, 513 Type::None(), MachineRepresentation::kFloat64);
500 MachineType(MachineRepresentation::kTagged, MachineSemantic::kUint32), 514 CheckChange(IrOpcode::kChangeFloat64ToInt32, MachineRepresentation::kFloat64,
501 MachineRepresentation::kWord32); 515 Type::Signed32(), MachineRepresentation::kWord32);
502 CheckChange(IrOpcode::kChangeInt32ToFloat64, MachineType::RepWord32(), 516 CheckChange(IrOpcode::kTruncateFloat64ToInt32,
503 MachineRepresentation::kFloat64); 517 MachineRepresentation::kFloat64, Type::Number(),
504 CheckChange(
505 IrOpcode::kChangeFloat64ToInt32,
506 MachineType(MachineRepresentation::kFloat64, MachineSemantic::kInt32),
507 MachineRepresentation::kWord32);
508 CheckChange(IrOpcode::kTruncateFloat64ToInt32, MachineType::RepFloat64(),
509 MachineRepresentation::kWord32); 518 MachineRepresentation::kWord32);
510 519
511 CheckTwoChanges(IrOpcode::kChangeInt32ToFloat64, 520 CheckTwoChanges(IrOpcode::kChangeInt32ToFloat64,
512 IrOpcode::kTruncateFloat64ToFloat32, MachineType::RepWord32(), 521 IrOpcode::kTruncateFloat64ToFloat32,
522 MachineRepresentation::kWord32, Type::None(),
513 MachineRepresentation::kFloat32); 523 MachineRepresentation::kFloat32);
514 CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64, 524 CheckTwoChanges(IrOpcode::kChangeFloat32ToFloat64,
515 IrOpcode::kTruncateFloat64ToInt32, MachineType::RepFloat32(), 525 IrOpcode::kTruncateFloat64ToInt32,
526 MachineRepresentation::kFloat32, Type::Number(),
516 MachineRepresentation::kWord32); 527 MachineRepresentation::kWord32);
517 } 528 }
518 529
519 530
520 TEST(Nops) { 531 TEST(Nops) {
521 RepresentationChangerTester r; 532 RepresentationChangerTester r;
522 533
523 // X -> X is always a nop for any single representation X. 534 // X -> X is always a nop for any single representation X.
524 for (size_t i = 0; i < arraysize(kMachineTypes); i++) { 535 for (size_t i = 0; i < arraysize(kMachineTypes); i++) {
525 r.CheckNop(kMachineTypes[i], kMachineTypes[i].representation()); 536 r.CheckNop(kMachineTypes[i].representation(), Type::None(),
537 kMachineTypes[i].representation());
526 } 538 }
527 539
528 // 32-bit floats. 540 // 32-bit floats.
529 r.CheckNop(MachineType::RepFloat32(), MachineRepresentation::kFloat32); 541 r.CheckNop(MachineRepresentation::kFloat32, Type::None(),
530 r.CheckNop(MachineType::Float32(), MachineRepresentation::kFloat32); 542 MachineRepresentation::kFloat32);
543 r.CheckNop(MachineRepresentation::kFloat32, Type::Number(),
544 MachineRepresentation::kFloat32);
531 545
532 // 32-bit words can be used as smaller word sizes and vice versa, because 546 // 32-bit words can be used as smaller word sizes and vice versa, because
533 // loads from memory implicitly sign or zero extend the value to the 547 // loads from memory implicitly sign or zero extend the value to the
534 // full machine word size, and stores implicitly truncate. 548 // full machine word size, and stores implicitly truncate.
535 r.CheckNop(MachineType::Int32(), MachineRepresentation::kWord8); 549 r.CheckNop(MachineRepresentation::kWord32, Type::Signed32(),
536 r.CheckNop(MachineType::Int32(), MachineRepresentation::kWord16); 550 MachineRepresentation::kWord8);
537 r.CheckNop(MachineType::Int32(), MachineRepresentation::kWord32); 551 r.CheckNop(MachineRepresentation::kWord32, Type::Signed32(),
538 r.CheckNop(MachineType::Int8(), MachineRepresentation::kWord32); 552 MachineRepresentation::kWord16);
539 r.CheckNop(MachineType::Int16(), MachineRepresentation::kWord32); 553 r.CheckNop(MachineRepresentation::kWord32, Type::Signed32(),
554 MachineRepresentation::kWord32);
555 r.CheckNop(MachineRepresentation::kWord8, Type::Signed32(),
556 MachineRepresentation::kWord32);
557 r.CheckNop(MachineRepresentation::kWord16, Type::Signed32(),
558 MachineRepresentation::kWord32);
540 559
541 // kRepBit (result of comparison) is implicitly a wordish thing. 560 // kRepBit (result of comparison) is implicitly a wordish thing.
542 r.CheckNop(MachineType::RepBit(), MachineRepresentation::kWord8); 561 r.CheckNop(MachineRepresentation::kBit, Type::None(),
543 r.CheckNop(MachineType::RepBit(), MachineRepresentation::kWord16); 562 MachineRepresentation::kWord8);
544 r.CheckNop(MachineType::RepBit(), MachineRepresentation::kWord32); 563 r.CheckNop(MachineRepresentation::kBit, Type::None(),
545 r.CheckNop(MachineType::RepBit(), MachineRepresentation::kWord64); 564 MachineRepresentation::kWord16);
546 r.CheckNop(MachineType::Bool(), MachineRepresentation::kWord8); 565 r.CheckNop(MachineRepresentation::kBit, Type::None(),
547 r.CheckNop(MachineType::Bool(), MachineRepresentation::kWord16); 566 MachineRepresentation::kWord32);
548 r.CheckNop(MachineType::Bool(), MachineRepresentation::kWord32); 567 r.CheckNop(MachineRepresentation::kBit, Type::None(),
549 r.CheckNop(MachineType::Bool(), MachineRepresentation::kWord64); 568 MachineRepresentation::kWord64);
569 r.CheckNop(MachineRepresentation::kBit, Type::Boolean(),
570 MachineRepresentation::kWord8);
571 r.CheckNop(MachineRepresentation::kBit, Type::Boolean(),
572 MachineRepresentation::kWord16);
573 r.CheckNop(MachineRepresentation::kBit, Type::Boolean(),
574 MachineRepresentation::kWord32);
575 r.CheckNop(MachineRepresentation::kBit, Type::Boolean(),
576 MachineRepresentation::kWord64);
550 } 577 }
551 578
552 579
553 TEST(TypeErrors) { 580 TEST(TypeErrors) {
554 RepresentationChangerTester r; 581 RepresentationChangerTester r;
555 582
556 // Wordish cannot be implicitly converted to/from comparison conditions. 583 // Wordish cannot be implicitly converted to/from comparison conditions.
557 r.CheckTypeError(MachineType::RepWord8(), MachineRepresentation::kBit); 584 r.CheckTypeError(MachineRepresentation::kWord8, Type::None(),
558 r.CheckTypeError(MachineType::RepWord16(), MachineRepresentation::kBit); 585 MachineRepresentation::kBit);
559 r.CheckTypeError(MachineType::RepWord32(), MachineRepresentation::kBit); 586 r.CheckTypeError(MachineRepresentation::kWord16, Type::None(),
560 r.CheckTypeError(MachineType::RepWord64(), MachineRepresentation::kBit); 587 MachineRepresentation::kBit);
588 r.CheckTypeError(MachineRepresentation::kWord32, Type::None(),
589 MachineRepresentation::kBit);
590 r.CheckTypeError(MachineRepresentation::kWord64, Type::None(),
591 MachineRepresentation::kBit);
561 592
562 // Floats cannot be implicitly converted to/from comparison conditions. 593 // Floats cannot be implicitly converted to/from comparison conditions.
563 r.CheckTypeError(MachineType::RepFloat64(), MachineRepresentation::kBit); 594 r.CheckTypeError(MachineRepresentation::kFloat64, Type::None(),
564 r.CheckTypeError(MachineType::RepBit(), MachineRepresentation::kFloat64); 595 MachineRepresentation::kBit);
565 r.CheckTypeError(MachineType::Bool(), MachineRepresentation::kFloat64); 596 r.CheckTypeError(MachineRepresentation::kBit, Type::None(),
597 MachineRepresentation::kFloat64);
598 r.CheckTypeError(MachineRepresentation::kBit, Type::Boolean(),
599 MachineRepresentation::kFloat64);
566 600
567 // Floats cannot be implicitly converted to/from comparison conditions. 601 // Floats cannot be implicitly converted to/from comparison conditions.
568 r.CheckTypeError(MachineType::RepFloat32(), MachineRepresentation::kBit); 602 r.CheckTypeError(MachineRepresentation::kFloat32, Type::None(),
569 r.CheckTypeError(MachineType::RepBit(), MachineRepresentation::kFloat32); 603 MachineRepresentation::kBit);
570 r.CheckTypeError(MachineType::Bool(), MachineRepresentation::kFloat32); 604 r.CheckTypeError(MachineRepresentation::kBit, Type::None(),
605 MachineRepresentation::kFloat32);
606 r.CheckTypeError(MachineRepresentation::kBit, Type::Boolean(),
607 MachineRepresentation::kFloat32);
571 608
572 // Word64 is internal and shouldn't be implicitly converted. 609 // Word64 is internal and shouldn't be implicitly converted.
573 r.CheckTypeError(MachineType::RepWord64(), MachineRepresentation::kTagged); 610 r.CheckTypeError(MachineRepresentation::kWord64, Type::None(),
574 r.CheckTypeError(MachineType::RepTagged(), MachineRepresentation::kWord64); 611 MachineRepresentation::kTagged);
575 r.CheckTypeError(MachineType::TaggedBool(), MachineRepresentation::kWord64); 612 r.CheckTypeError(MachineRepresentation::kTagged, Type::None(),
613 MachineRepresentation::kWord64);
614 r.CheckTypeError(MachineRepresentation::kTagged, Type::Boolean(),
615 MachineRepresentation::kWord64);
576 616
577 // Word64 / Word32 shouldn't be implicitly converted. 617 // Word64 / Word32 shouldn't be implicitly converted.
578 r.CheckTypeError(MachineType::RepWord64(), MachineRepresentation::kWord32); 618 r.CheckTypeError(MachineRepresentation::kWord64, Type::None(),
579 r.CheckTypeError(MachineType::RepWord32(), MachineRepresentation::kWord64); 619 MachineRepresentation::kWord32);
580 r.CheckTypeError(MachineType::Int32(), MachineRepresentation::kWord64); 620 r.CheckTypeError(MachineRepresentation::kWord32, Type::None(),
581 r.CheckTypeError(MachineType::Uint32(), MachineRepresentation::kWord64); 621 MachineRepresentation::kWord64);
622 r.CheckTypeError(MachineRepresentation::kWord32, Type::Signed32(),
623 MachineRepresentation::kWord64);
624 r.CheckTypeError(MachineRepresentation::kWord32, Type::Unsigned32(),
625 MachineRepresentation::kWord64);
582 } 626 }
583 627
584 } // namespace compiler 628 } // namespace compiler
585 } // namespace internal 629 } // namespace internal
586 } // namespace v8 630 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/simplified-lowering.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698