OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/simplified-operator.h" | 5 #include "src/compiler/simplified-operator.h" |
6 | 6 |
7 #include "src/base/lazy-instance.h" | 7 #include "src/base/lazy-instance.h" |
8 #include "src/compiler/opcodes.h" | 8 #include "src/compiler/opcodes.h" |
9 #include "src/compiler/operator.h" | 9 #include "src/compiler/operator.h" |
10 #include "src/types.h" | 10 #include "src/types.h" |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 return OpParameter<BinaryOperationHints::Hint>(op); | 271 return OpParameter<BinaryOperationHints::Hint>(op); |
272 } | 272 } |
273 | 273 |
274 CompareOperationHints::Hint CompareOperationHintOf(const Operator* op) { | 274 CompareOperationHints::Hint CompareOperationHintOf(const Operator* op) { |
275 DCHECK(op->opcode() == IrOpcode::kSpeculativeNumberEqual || | 275 DCHECK(op->opcode() == IrOpcode::kSpeculativeNumberEqual || |
276 op->opcode() == IrOpcode::kSpeculativeNumberLessThan || | 276 op->opcode() == IrOpcode::kSpeculativeNumberLessThan || |
277 op->opcode() == IrOpcode::kSpeculativeNumberLessThanOrEqual); | 277 op->opcode() == IrOpcode::kSpeculativeNumberLessThanOrEqual); |
278 return OpParameter<CompareOperationHints::Hint>(op); | 278 return OpParameter<CompareOperationHints::Hint>(op); |
279 } | 279 } |
280 | 280 |
281 #define PURE_OP_LIST(V) \ | 281 #define PURE_OP_LIST(V) \ |
282 V(BooleanNot, Operator::kNoProperties, 1) \ | 282 V(BooleanNot, Operator::kNoProperties, 1, 0) \ |
283 V(NumberEqual, Operator::kCommutative, 2) \ | 283 V(NumberEqual, Operator::kCommutative, 2, 0) \ |
284 V(NumberLessThan, Operator::kNoProperties, 2) \ | 284 V(NumberLessThan, Operator::kNoProperties, 2, 0) \ |
285 V(NumberLessThanOrEqual, Operator::kNoProperties, 2) \ | 285 V(NumberLessThanOrEqual, Operator::kNoProperties, 2, 0) \ |
286 V(NumberAdd, Operator::kCommutative, 2) \ | 286 V(NumberAdd, Operator::kCommutative, 2, 0) \ |
287 V(NumberSubtract, Operator::kNoProperties, 2) \ | 287 V(NumberSubtract, Operator::kNoProperties, 2, 0) \ |
288 V(NumberMultiply, Operator::kCommutative, 2) \ | 288 V(NumberMultiply, Operator::kCommutative, 2, 0) \ |
289 V(NumberDivide, Operator::kNoProperties, 2) \ | 289 V(NumberDivide, Operator::kNoProperties, 2, 0) \ |
290 V(NumberModulus, Operator::kNoProperties, 2) \ | 290 V(NumberModulus, Operator::kNoProperties, 2, 0) \ |
291 V(NumberBitwiseOr, Operator::kCommutative, 2) \ | 291 V(NumberBitwiseOr, Operator::kCommutative, 2, 0) \ |
292 V(NumberBitwiseXor, Operator::kCommutative, 2) \ | 292 V(NumberBitwiseXor, Operator::kCommutative, 2, 0) \ |
293 V(NumberBitwiseAnd, Operator::kCommutative, 2) \ | 293 V(NumberBitwiseAnd, Operator::kCommutative, 2, 0) \ |
294 V(NumberShiftLeft, Operator::kNoProperties, 2) \ | 294 V(NumberShiftLeft, Operator::kNoProperties, 2, 0) \ |
295 V(NumberShiftRight, Operator::kNoProperties, 2) \ | 295 V(NumberShiftRight, Operator::kNoProperties, 2, 0) \ |
296 V(NumberShiftRightLogical, Operator::kNoProperties, 2) \ | 296 V(NumberShiftRightLogical, Operator::kNoProperties, 2, 0) \ |
297 V(NumberImul, Operator::kCommutative, 2) \ | 297 V(NumberImul, Operator::kCommutative, 2, 0) \ |
298 V(NumberAbs, Operator::kNoProperties, 1) \ | 298 V(NumberAbs, Operator::kNoProperties, 1, 0) \ |
299 V(NumberClz32, Operator::kNoProperties, 1) \ | 299 V(NumberClz32, Operator::kNoProperties, 1, 0) \ |
300 V(NumberCeil, Operator::kNoProperties, 1) \ | 300 V(NumberCeil, Operator::kNoProperties, 1, 0) \ |
301 V(NumberFloor, Operator::kNoProperties, 1) \ | 301 V(NumberFloor, Operator::kNoProperties, 1, 0) \ |
302 V(NumberFround, Operator::kNoProperties, 1) \ | 302 V(NumberFround, Operator::kNoProperties, 1, 0) \ |
303 V(NumberAcos, Operator::kNoProperties, 1) \ | 303 V(NumberAcos, Operator::kNoProperties, 1, 0) \ |
304 V(NumberAcosh, Operator::kNoProperties, 1) \ | 304 V(NumberAcosh, Operator::kNoProperties, 1, 0) \ |
305 V(NumberAsin, Operator::kNoProperties, 1) \ | 305 V(NumberAsin, Operator::kNoProperties, 1, 0) \ |
306 V(NumberAsinh, Operator::kNoProperties, 1) \ | 306 V(NumberAsinh, Operator::kNoProperties, 1, 0) \ |
307 V(NumberAtan, Operator::kNoProperties, 1) \ | 307 V(NumberAtan, Operator::kNoProperties, 1, 0) \ |
308 V(NumberAtan2, Operator::kNoProperties, 2) \ | 308 V(NumberAtan2, Operator::kNoProperties, 2, 0) \ |
309 V(NumberAtanh, Operator::kNoProperties, 1) \ | 309 V(NumberAtanh, Operator::kNoProperties, 1, 0) \ |
310 V(NumberCbrt, Operator::kNoProperties, 1) \ | 310 V(NumberCbrt, Operator::kNoProperties, 1, 0) \ |
311 V(NumberCos, Operator::kNoProperties, 1) \ | 311 V(NumberCos, Operator::kNoProperties, 1, 0) \ |
312 V(NumberCosh, Operator::kNoProperties, 1) \ | 312 V(NumberCosh, Operator::kNoProperties, 1, 0) \ |
313 V(NumberExp, Operator::kNoProperties, 1) \ | 313 V(NumberExp, Operator::kNoProperties, 1, 0) \ |
314 V(NumberExpm1, Operator::kNoProperties, 1) \ | 314 V(NumberExpm1, Operator::kNoProperties, 1, 0) \ |
315 V(NumberLog, Operator::kNoProperties, 1) \ | 315 V(NumberLog, Operator::kNoProperties, 1, 0) \ |
316 V(NumberLog1p, Operator::kNoProperties, 1) \ | 316 V(NumberLog1p, Operator::kNoProperties, 1, 0) \ |
317 V(NumberLog10, Operator::kNoProperties, 1) \ | 317 V(NumberLog10, Operator::kNoProperties, 1, 0) \ |
318 V(NumberLog2, Operator::kNoProperties, 1) \ | 318 V(NumberLog2, Operator::kNoProperties, 1, 0) \ |
319 V(NumberMax, Operator::kNoProperties, 2) \ | 319 V(NumberMax, Operator::kNoProperties, 2, 0) \ |
320 V(NumberMin, Operator::kNoProperties, 2) \ | 320 V(NumberMin, Operator::kNoProperties, 2, 0) \ |
321 V(NumberPow, Operator::kNoProperties, 2) \ | 321 V(NumberPow, Operator::kNoProperties, 2, 0) \ |
322 V(NumberRound, Operator::kNoProperties, 1) \ | 322 V(NumberRound, Operator::kNoProperties, 1, 0) \ |
323 V(NumberSign, Operator::kNoProperties, 1) \ | 323 V(NumberSign, Operator::kNoProperties, 1, 0) \ |
324 V(NumberSin, Operator::kNoProperties, 1) \ | 324 V(NumberSin, Operator::kNoProperties, 1, 0) \ |
325 V(NumberSinh, Operator::kNoProperties, 1) \ | 325 V(NumberSinh, Operator::kNoProperties, 1, 0) \ |
326 V(NumberSqrt, Operator::kNoProperties, 1) \ | 326 V(NumberSqrt, Operator::kNoProperties, 1, 0) \ |
327 V(NumberTan, Operator::kNoProperties, 1) \ | 327 V(NumberTan, Operator::kNoProperties, 1, 0) \ |
328 V(NumberTanh, Operator::kNoProperties, 1) \ | 328 V(NumberTanh, Operator::kNoProperties, 1, 0) \ |
329 V(NumberTrunc, Operator::kNoProperties, 1) \ | 329 V(NumberTrunc, Operator::kNoProperties, 1, 0) \ |
330 V(NumberToInt32, Operator::kNoProperties, 1) \ | 330 V(NumberToInt32, Operator::kNoProperties, 1, 0) \ |
331 V(NumberToUint32, Operator::kNoProperties, 1) \ | 331 V(NumberToUint32, Operator::kNoProperties, 1, 0) \ |
332 V(NumberSilenceNaN, Operator::kNoProperties, 1) \ | 332 V(NumberSilenceNaN, Operator::kNoProperties, 1, 0) \ |
333 V(StringFromCharCode, Operator::kNoProperties, 1) \ | 333 V(StringCharCodeAt, Operator::kNoProperties, 2, 1) \ |
334 V(PlainPrimitiveToNumber, Operator::kNoProperties, 1) \ | 334 V(StringFromCharCode, Operator::kNoProperties, 1, 0) \ |
335 V(PlainPrimitiveToWord32, Operator::kNoProperties, 1) \ | 335 V(PlainPrimitiveToNumber, Operator::kNoProperties, 1, 0) \ |
336 V(PlainPrimitiveToFloat64, Operator::kNoProperties, 1) \ | 336 V(PlainPrimitiveToWord32, Operator::kNoProperties, 1, 0) \ |
337 V(ChangeTaggedSignedToInt32, Operator::kNoProperties, 1) \ | 337 V(PlainPrimitiveToFloat64, Operator::kNoProperties, 1, 0) \ |
338 V(ChangeTaggedToInt32, Operator::kNoProperties, 1) \ | 338 V(ChangeTaggedSignedToInt32, Operator::kNoProperties, 1, 0) \ |
339 V(ChangeTaggedToUint32, Operator::kNoProperties, 1) \ | 339 V(ChangeTaggedToInt32, Operator::kNoProperties, 1, 0) \ |
340 V(ChangeTaggedToFloat64, Operator::kNoProperties, 1) \ | 340 V(ChangeTaggedToUint32, Operator::kNoProperties, 1, 0) \ |
341 V(ChangeInt31ToTaggedSigned, Operator::kNoProperties, 1) \ | 341 V(ChangeTaggedToFloat64, Operator::kNoProperties, 1, 0) \ |
342 V(ChangeInt32ToTagged, Operator::kNoProperties, 1) \ | 342 V(ChangeInt31ToTaggedSigned, Operator::kNoProperties, 1, 0) \ |
343 V(ChangeUint32ToTagged, Operator::kNoProperties, 1) \ | 343 V(ChangeInt32ToTagged, Operator::kNoProperties, 1, 0) \ |
344 V(ChangeFloat64ToTagged, Operator::kNoProperties, 1) \ | 344 V(ChangeUint32ToTagged, Operator::kNoProperties, 1, 0) \ |
345 V(ChangeTaggedToBit, Operator::kNoProperties, 1) \ | 345 V(ChangeFloat64ToTagged, Operator::kNoProperties, 1, 0) \ |
346 V(ChangeBitToTagged, Operator::kNoProperties, 1) \ | 346 V(ChangeTaggedToBit, Operator::kNoProperties, 1, 0) \ |
347 V(TruncateTaggedToWord32, Operator::kNoProperties, 1) \ | 347 V(ChangeBitToTagged, Operator::kNoProperties, 1, 0) \ |
348 V(TruncateTaggedToFloat64, Operator::kNoProperties, 1) \ | 348 V(TruncateTaggedToWord32, Operator::kNoProperties, 1, 0) \ |
349 V(ObjectIsCallable, Operator::kNoProperties, 1) \ | 349 V(TruncateTaggedToFloat64, Operator::kNoProperties, 1, 0) \ |
350 V(ObjectIsNumber, Operator::kNoProperties, 1) \ | 350 V(ObjectIsCallable, Operator::kNoProperties, 1, 0) \ |
351 V(ObjectIsReceiver, Operator::kNoProperties, 1) \ | 351 V(ObjectIsNumber, Operator::kNoProperties, 1, 0) \ |
352 V(ObjectIsSmi, Operator::kNoProperties, 1) \ | 352 V(ObjectIsReceiver, Operator::kNoProperties, 1, 0) \ |
353 V(ObjectIsString, Operator::kNoProperties, 1) \ | 353 V(ObjectIsSmi, Operator::kNoProperties, 1, 0) \ |
354 V(ObjectIsUndetectable, Operator::kNoProperties, 1) \ | 354 V(ObjectIsString, Operator::kNoProperties, 1, 0) \ |
355 V(StringEqual, Operator::kCommutative, 2) \ | 355 V(ObjectIsUndetectable, Operator::kNoProperties, 1, 0) \ |
356 V(StringLessThan, Operator::kNoProperties, 2) \ | 356 V(StringEqual, Operator::kCommutative, 2, 0) \ |
357 V(StringLessThanOrEqual, Operator::kNoProperties, 2) | 357 V(StringLessThan, Operator::kNoProperties, 2, 0) \ |
| 358 V(StringLessThanOrEqual, Operator::kNoProperties, 2, 0) |
358 | 359 |
359 #define SPECULATIVE_BINOP_LIST(V) \ | 360 #define SPECULATIVE_BINOP_LIST(V) \ |
360 V(SpeculativeNumberAdd) \ | 361 V(SpeculativeNumberAdd) \ |
361 V(SpeculativeNumberSubtract) \ | 362 V(SpeculativeNumberSubtract) \ |
362 V(SpeculativeNumberDivide) \ | 363 V(SpeculativeNumberDivide) \ |
363 V(SpeculativeNumberMultiply) \ | 364 V(SpeculativeNumberMultiply) \ |
364 V(SpeculativeNumberModulus) \ | 365 V(SpeculativeNumberModulus) \ |
365 V(SpeculativeNumberShiftLeft) | 366 V(SpeculativeNumberShiftLeft) |
366 | 367 |
367 #define CHECKED_OP_LIST(V) \ | 368 #define CHECKED_OP_LIST(V) \ |
368 V(CheckBounds, 2, 1) \ | 369 V(CheckBounds, 2, 1) \ |
369 V(CheckIf, 1, 0) \ | 370 V(CheckIf, 1, 0) \ |
370 V(CheckNumber, 1, 1) \ | 371 V(CheckNumber, 1, 1) \ |
371 V(CheckString, 1, 1) \ | 372 V(CheckString, 1, 1) \ |
372 V(CheckTaggedPointer, 1, 1) \ | 373 V(CheckTaggedPointer, 1, 1) \ |
373 V(CheckTaggedSigned, 1, 1) \ | 374 V(CheckTaggedSigned, 1, 1) \ |
374 V(CheckedInt32Add, 2, 1) \ | 375 V(CheckedInt32Add, 2, 1) \ |
375 V(CheckedInt32Sub, 2, 1) \ | 376 V(CheckedInt32Sub, 2, 1) \ |
376 V(CheckedInt32Div, 2, 1) \ | 377 V(CheckedInt32Div, 2, 1) \ |
377 V(CheckedInt32Mod, 2, 1) \ | 378 V(CheckedInt32Mod, 2, 1) \ |
378 V(CheckedUint32Div, 2, 1) \ | 379 V(CheckedUint32Div, 2, 1) \ |
379 V(CheckedUint32Mod, 2, 1) \ | 380 V(CheckedUint32Mod, 2, 1) \ |
380 V(CheckedUint32ToInt32, 1, 1) \ | 381 V(CheckedUint32ToInt32, 1, 1) \ |
381 V(CheckedFloat64ToInt32, 1, 1) \ | 382 V(CheckedFloat64ToInt32, 1, 1) \ |
382 V(CheckedTaggedToInt32, 1, 1) \ | 383 V(CheckedTaggedToInt32, 1, 1) \ |
383 V(CheckedTaggedToFloat64, 1, 1) | 384 V(CheckedTaggedToFloat64, 1, 1) |
384 | 385 |
385 struct SimplifiedOperatorGlobalCache final { | 386 struct SimplifiedOperatorGlobalCache final { |
386 #define PURE(Name, properties, input_count) \ | 387 #define PURE(Name, properties, value_input_count, control_input_count) \ |
387 struct Name##Operator final : public Operator { \ | 388 struct Name##Operator final : public Operator { \ |
388 Name##Operator() \ | 389 Name##Operator() \ |
389 : Operator(IrOpcode::k##Name, Operator::kPure | properties, #Name, \ | 390 : Operator(IrOpcode::k##Name, Operator::kPure | properties, #Name, \ |
390 input_count, 0, 0, 1, 0, 0) {} \ | 391 value_input_count, 0, control_input_count, 1, 0, 0) {} \ |
391 }; \ | 392 }; \ |
392 Name##Operator k##Name; | 393 Name##Operator k##Name; |
393 PURE_OP_LIST(PURE) | 394 PURE_OP_LIST(PURE) |
394 #undef PURE | 395 #undef PURE |
395 | 396 |
396 #define CHECKED(Name, value_input_count, value_output_count) \ | 397 #define CHECKED(Name, value_input_count, value_output_count) \ |
397 struct Name##Operator final : public Operator { \ | 398 struct Name##Operator final : public Operator { \ |
398 Name##Operator() \ | 399 Name##Operator() \ |
399 : Operator(IrOpcode::k##Name, \ | 400 : Operator(IrOpcode::k##Name, \ |
400 Operator::kFoldable | Operator::kNoThrow, #Name, \ | 401 Operator::kFoldable | Operator::kNoThrow, #Name, \ |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 }; | 481 }; |
481 | 482 |
482 | 483 |
483 static base::LazyInstance<SimplifiedOperatorGlobalCache>::type kCache = | 484 static base::LazyInstance<SimplifiedOperatorGlobalCache>::type kCache = |
484 LAZY_INSTANCE_INITIALIZER; | 485 LAZY_INSTANCE_INITIALIZER; |
485 | 486 |
486 | 487 |
487 SimplifiedOperatorBuilder::SimplifiedOperatorBuilder(Zone* zone) | 488 SimplifiedOperatorBuilder::SimplifiedOperatorBuilder(Zone* zone) |
488 : cache_(kCache.Get()), zone_(zone) {} | 489 : cache_(kCache.Get()), zone_(zone) {} |
489 | 490 |
490 #define GET_FROM_CACHE(Name, properties, input_count) \ | 491 #define GET_FROM_CACHE(Name, ...) \ |
491 const Operator* SimplifiedOperatorBuilder::Name() { return &cache_.k##Name; } | 492 const Operator* SimplifiedOperatorBuilder::Name() { return &cache_.k##Name; } |
492 PURE_OP_LIST(GET_FROM_CACHE) | 493 PURE_OP_LIST(GET_FROM_CACHE) |
493 #undef GET_FROM_CACHE | |
494 | |
495 #define GET_FROM_CACHE(Name, value_input_count, value_output_count) \ | |
496 const Operator* SimplifiedOperatorBuilder::Name() { return &cache_.k##Name; } | |
497 CHECKED_OP_LIST(GET_FROM_CACHE) | 494 CHECKED_OP_LIST(GET_FROM_CACHE) |
498 #undef GET_FROM_CACHE | 495 #undef GET_FROM_CACHE |
499 | 496 |
500 const Operator* SimplifiedOperatorBuilder::CheckedInt32Mul( | 497 const Operator* SimplifiedOperatorBuilder::CheckedInt32Mul( |
501 CheckForMinusZeroMode mode) { | 498 CheckForMinusZeroMode mode) { |
502 switch (mode) { | 499 switch (mode) { |
503 case CheckForMinusZeroMode::kCheckForMinusZero: | 500 case CheckForMinusZeroMode::kCheckForMinusZero: |
504 return &cache_.kCheckedInt32MulCheckForMinusZeroOperator; | 501 return &cache_.kCheckedInt32MulCheckForMinusZeroOperator; |
505 case CheckForMinusZeroMode::kDontCheckForMinusZero: | 502 case CheckForMinusZeroMode::kDontCheckForMinusZero: |
506 return &cache_.kCheckedInt32MulDontCheckForMinusZeroOperator; | 503 return &cache_.kCheckedInt32MulDontCheckForMinusZeroOperator; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 Operator::kNoDeopt | Operator::kNoThrow | properties, \ | 631 Operator::kNoDeopt | Operator::kNoThrow | properties, \ |
635 #Name, value_input_count, 1, control_input_count, \ | 632 #Name, value_input_count, 1, control_input_count, \ |
636 output_count, 1, 0, access); \ | 633 output_count, 1, 0, access); \ |
637 } | 634 } |
638 ACCESS_OP_LIST(ACCESS) | 635 ACCESS_OP_LIST(ACCESS) |
639 #undef ACCESS | 636 #undef ACCESS |
640 | 637 |
641 } // namespace compiler | 638 } // namespace compiler |
642 } // namespace internal | 639 } // namespace internal |
643 } // namespace v8 | 640 } // namespace v8 |
OLD | NEW |