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

Side by Side Diff: src/compiler/js-typed-lowering.cc

Issue 2259613003: [turbofan] Reduce code duplication in JSTypedLowering somewhat. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
« no previous file with comments | « src/compiler/js-typed-lowering.h ('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 "src/compiler/js-typed-lowering.h" 5 #include "src/compiler/js-typed-lowering.h"
6 6
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/compilation-dependencies.h" 8 #include "src/compilation-dependencies.h"
9 #include "src/compiler/access-builder.h" 9 #include "src/compiler/access-builder.h"
10 #include "src/compiler/js-graph.h" 10 #include "src/compiler/js-graph.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 208 }
209 209
210 Reduction ChangeToPureOperator(const Operator* op, Type* type) { 210 Reduction ChangeToPureOperator(const Operator* op, Type* type) {
211 return ChangeToPureOperator(op, false, type); 211 return ChangeToPureOperator(op, false, type);
212 } 212 }
213 213
214 Reduction ChangeToSpeculativeOperator(const Operator* op, Type* type) { 214 Reduction ChangeToSpeculativeOperator(const Operator* op, Type* type) {
215 return ChangeToSpeculativeOperator(op, false, type); 215 return ChangeToSpeculativeOperator(op, false, type);
216 } 216 }
217 217
218 const Operator* NumberOp() {
219 switch (node_->opcode()) {
220 case IrOpcode::kJSAdd:
221 return simplified()->NumberAdd();
222 case IrOpcode::kJSSubtract:
223 return simplified()->NumberSubtract();
224 case IrOpcode::kJSMultiply:
225 return simplified()->NumberMultiply();
226 case IrOpcode::kJSDivide:
227 return simplified()->NumberDivide();
228 case IrOpcode::kJSModulus:
229 return simplified()->NumberModulus();
230 case IrOpcode::kJSBitwiseAnd:
231 return simplified()->NumberBitwiseAnd();
232 case IrOpcode::kJSBitwiseOr:
233 return simplified()->NumberBitwiseOr();
234 case IrOpcode::kJSBitwiseXor:
235 return simplified()->NumberBitwiseXor();
236 case IrOpcode::kJSShiftLeft:
237 return simplified()->NumberShiftLeft();
238 case IrOpcode::kJSShiftRight:
239 return simplified()->NumberShiftRight();
240 case IrOpcode::kJSShiftRightLogical:
241 return simplified()->NumberShiftRightLogical();
242 default:
243 break;
244 }
245 UNREACHABLE();
246 return nullptr;
247 }
248
249 const Operator* SpeculativeNumberOp(NumberOperationHint hint) {
250 switch (node_->opcode()) {
251 case IrOpcode::kJSAdd:
252 return simplified()->SpeculativeNumberAdd(hint);
253 case IrOpcode::kJSSubtract:
254 return simplified()->SpeculativeNumberSubtract(hint);
255 case IrOpcode::kJSMultiply:
256 return simplified()->SpeculativeNumberMultiply(hint);
257 case IrOpcode::kJSDivide:
258 return simplified()->SpeculativeNumberDivide(hint);
259 case IrOpcode::kJSModulus:
260 return simplified()->SpeculativeNumberModulus(hint);
261 case IrOpcode::kJSBitwiseAnd:
262 return simplified()->SpeculativeNumberBitwiseAnd(hint);
263 case IrOpcode::kJSBitwiseOr:
264 return simplified()->SpeculativeNumberBitwiseOr(hint);
265 case IrOpcode::kJSBitwiseXor:
266 return simplified()->SpeculativeNumberBitwiseXor(hint);
267 case IrOpcode::kJSShiftLeft:
268 return simplified()->SpeculativeNumberShiftLeft(hint);
269 case IrOpcode::kJSShiftRight:
270 return simplified()->SpeculativeNumberShiftRight(hint);
271 case IrOpcode::kJSShiftRightLogical:
272 return simplified()->SpeculativeNumberShiftRightLogical(hint);
273 default:
274 break;
275 }
276 UNREACHABLE();
277 return nullptr;
278 }
279
218 bool LeftInputIs(Type* t) { return left_type()->Is(t); } 280 bool LeftInputIs(Type* t) { return left_type()->Is(t); }
219 281
220 bool RightInputIs(Type* t) { return right_type()->Is(t); } 282 bool RightInputIs(Type* t) { return right_type()->Is(t); }
221 283
222 bool OneInputIs(Type* t) { return LeftInputIs(t) || RightInputIs(t); } 284 bool OneInputIs(Type* t) { return LeftInputIs(t) || RightInputIs(t); }
223 285
224 bool BothInputsAre(Type* t) { return LeftInputIs(t) && RightInputIs(t); } 286 bool BothInputsAre(Type* t) { return LeftInputIs(t) && RightInputIs(t); }
225 287
226 bool OneInputCannotBe(Type* t) { 288 bool OneInputCannotBe(Type* t) {
227 return !left_type()->Maybe(t) || !right_type()->Maybe(t); 289 return !left_type()->Maybe(t) || !right_type()->Maybe(t);
228 } 290 }
229 291
230 bool NeitherInputCanBe(Type* t) { 292 bool NeitherInputCanBe(Type* t) {
231 return !left_type()->Maybe(t) && !right_type()->Maybe(t); 293 return !left_type()->Maybe(t) && !right_type()->Maybe(t);
232 } 294 }
233 295
234 Node* effect() { return NodeProperties::GetEffectInput(node_); } 296 Node* effect() { return NodeProperties::GetEffectInput(node_); }
235 Node* control() { return NodeProperties::GetControlInput(node_); } 297 Node* control() { return NodeProperties::GetControlInput(node_); }
236 Node* context() { return NodeProperties::GetContextInput(node_); } 298 Node* context() { return NodeProperties::GetContextInput(node_); }
237 Node* left() { return NodeProperties::GetValueInput(node_, 0); } 299 Node* left() { return NodeProperties::GetValueInput(node_, 0); }
238 Node* right() { return NodeProperties::GetValueInput(node_, 1); } 300 Node* right() { return NodeProperties::GetValueInput(node_, 1); }
239 Type* left_type() { return NodeProperties::GetType(node_->InputAt(0)); } 301 Type* left_type() { return NodeProperties::GetType(node_->InputAt(0)); }
240 Type* right_type() { return NodeProperties::GetType(node_->InputAt(1)); } 302 Type* right_type() { return NodeProperties::GetType(node_->InputAt(1)); }
303 Type* type() { return NodeProperties::GetType(node_); }
241 304
242 SimplifiedOperatorBuilder* simplified() { return lowering_->simplified(); } 305 SimplifiedOperatorBuilder* simplified() { return lowering_->simplified(); }
243 Graph* graph() const { return lowering_->graph(); } 306 Graph* graph() const { return lowering_->graph(); }
244 JSGraph* jsgraph() { return lowering_->jsgraph(); } 307 JSGraph* jsgraph() { return lowering_->jsgraph(); }
245 JSOperatorBuilder* javascript() { return lowering_->javascript(); } 308 JSOperatorBuilder* javascript() { return lowering_->javascript(); }
246 CommonOperatorBuilder* common() { return jsgraph()->common(); } 309 CommonOperatorBuilder* common() { return jsgraph()->common(); }
247 Zone* zone() const { return graph()->zone(); } 310 Zone* zone() const { return graph()->zone(); }
248 311
249 private: 312 private:
250 JSTypedLowering* lowering_; // The containing lowering instance. 313 JSTypedLowering* lowering_; // The containing lowering instance.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 CallDescriptor::kNeedsFrameState, node->op()->properties()); 483 CallDescriptor::kNeedsFrameState, node->op()->properties());
421 DCHECK_EQ(1, OperatorProperties::GetFrameStateInputCount(node->op())); 484 DCHECK_EQ(1, OperatorProperties::GetFrameStateInputCount(node->op()));
422 node->InsertInput(graph()->zone(), 0, 485 node->InsertInput(graph()->zone(), 0,
423 jsgraph()->HeapConstant(callable.code())); 486 jsgraph()->HeapConstant(callable.code()));
424 NodeProperties::ChangeOp(node, common()->Call(desc)); 487 NodeProperties::ChangeOp(node, common()->Call(desc));
425 return Changed(node); 488 return Changed(node);
426 } 489 }
427 return NoChange(); 490 return NoChange();
428 } 491 }
429 492
430 Reduction JSTypedLowering::ReduceJSSubtract(Node* node) { 493 Reduction JSTypedLowering::ReduceNumberBinop(Node* node) {
431 JSBinopReduction r(this, node); 494 JSBinopReduction r(this, node);
432 NumberOperationHint hint; 495 NumberOperationHint hint;
433 if (r.GetBinaryNumberOperationHint(&hint)) { 496 if (r.GetBinaryNumberOperationHint(&hint)) {
434 if (hint == NumberOperationHint::kNumberOrOddball && 497 if (hint == NumberOperationHint::kNumberOrOddball &&
435 r.BothInputsAre(Type::PlainPrimitive())) { 498 r.BothInputsAre(Type::PlainPrimitive())) {
436 // JSSubtract(x:plain-primitive, y:plain-primitive)
437 // => NumberSubtract(ToNumber(x), ToNumber(y))
438 r.ConvertInputsToNumber(); 499 r.ConvertInputsToNumber();
439 return r.ChangeToPureOperator(simplified()->NumberSubtract(), 500 return r.ChangeToPureOperator(r.NumberOp(), Type::Number());
440 Type::Number());
441 } 501 }
442 return r.ChangeToSpeculativeOperator( 502 return r.ChangeToSpeculativeOperator(r.SpeculativeNumberOp(hint),
443 simplified()->SpeculativeNumberSubtract(hint), Type::Number()); 503 Type::Number());
444 } 504 }
445 if (r.BothInputsAre(Type::PlainPrimitive()) || 505 if (r.BothInputsAre(Type::PlainPrimitive()) ||
446 !(flags() & kDeoptimizationEnabled)) { 506 !(flags() & kDeoptimizationEnabled)) {
447 r.ConvertInputsToNumber(); 507 r.ConvertInputsToNumber();
448 return r.ChangeToPureOperator(simplified()->NumberSubtract(), 508 return r.ChangeToPureOperator(r.NumberOp(), Type::Number());
449 Type::Number());
450 } 509 }
451 return NoChange(); 510 return NoChange();
452 } 511 }
453 512
454 Reduction JSTypedLowering::ReduceJSMultiply(Node* node) { 513 Reduction JSTypedLowering::ReduceInt32Binop(Node* node) {
455 JSBinopReduction r(this, node); 514 JSBinopReduction r(this, node);
456 NumberOperationHint hint; 515 NumberOperationHint hint;
457 if (r.GetBinaryNumberOperationHint(&hint)) { 516 if (r.GetBinaryNumberOperationHint(&hint)) {
458 if (hint == NumberOperationHint::kNumberOrOddball && 517 return r.ChangeToSpeculativeOperator(r.SpeculativeNumberOp(hint),
459 r.BothInputsAre(Type::PlainPrimitive())) { 518 Type::Signed32());
460 // JSMultiply(x:plain-primitive,
461 // y:plain-primitive) => NumberMultiply(ToNumber(x),
462 // ToNumber(y))
463 r.ConvertInputsToNumber();
464 return r.ChangeToPureOperator(simplified()->NumberMultiply(),
465 Type::Number());
466 }
467 return r.ChangeToSpeculativeOperator(
468 simplified()->SpeculativeNumberMultiply(hint), Type::Number());
469 }
470 if (r.BothInputsAre(Type::PlainPrimitive()) ||
471 !(flags() & kDeoptimizationEnabled)) {
472 r.ConvertInputsToNumber();
473 return r.ChangeToPureOperator(simplified()->NumberMultiply(),
474 Type::Number());
475 }
476 return NoChange();
477 }
478
479 Reduction JSTypedLowering::ReduceJSDivide(Node* node) {
480 JSBinopReduction r(this, node);
481 NumberOperationHint hint;
482 if (r.GetBinaryNumberOperationHint(&hint)) {
483 if (hint == NumberOperationHint::kNumberOrOddball &&
484 r.BothInputsAre(Type::PlainPrimitive())) {
485 // JSDivide(x:plain-primitive,
486 // y:plain-primitive) => NumberDivide(ToNumber(x), ToNumber(y))
487 r.ConvertInputsToNumber();
488 return r.ChangeToPureOperator(simplified()->NumberDivide(),
489 Type::Number());
490 }
491 return r.ChangeToSpeculativeOperator(
492 simplified()->SpeculativeNumberDivide(hint), Type::Number());
493 }
494 if (r.BothInputsAre(Type::PlainPrimitive())) {
495 // JSDivide(x:plain-primitive,
496 // y:plain-primitive) => NumberDivide(ToNumber(x), ToNumber(y))
497 r.ConvertInputsToNumber();
498 return r.ChangeToPureOperator(simplified()->NumberDivide(), Type::Number());
499 }
500 return NoChange();
501 }
502
503 Reduction JSTypedLowering::ReduceJSModulus(Node* node) {
504 JSBinopReduction r(this, node);
505 NumberOperationHint hint;
506 if (r.GetBinaryNumberOperationHint(&hint)) {
507 if (hint == NumberOperationHint::kNumberOrOddball &&
508 r.BothInputsAre(Type::PlainPrimitive())) {
509 // JSModulus(x:plain-primitive,
510 // y:plain-primitive) => NumberModulus(ToNumber(x), ToNumber(y))
511 r.ConvertInputsToNumber();
512 return r.ChangeToPureOperator(simplified()->NumberModulus(),
513 Type::Number());
514 }
515 return r.ChangeToSpeculativeOperator(
516 simplified()->SpeculativeNumberModulus(hint), Type::Number());
517 }
518 if (r.BothInputsAre(Type::PlainPrimitive())) {
519 // JSModulus(x:plain-primitive,
520 // y:plain-primitive) => NumberModulus(ToNumber(x), ToNumber(y))
521 r.ConvertInputsToNumber();
522 return r.ChangeToPureOperator(simplified()->NumberModulus(),
523 Type::Number());
524 }
525 return NoChange();
526 }
527
528 Reduction JSTypedLowering::ReduceInt32Binop(Node* node,
529 const Operator* int_op) {
530 JSBinopReduction r(this, node);
531 NumberOperationHint hint;
532 if (r.GetBinaryNumberOperationHint(&hint)) {
533 Operator const* speculative_op;
534 if (int_op->opcode() == IrOpcode::kNumberBitwiseAnd) {
535 speculative_op = simplified()->SpeculativeNumberBitwiseAnd(hint);
536 } else if (int_op->opcode() == IrOpcode::kNumberBitwiseOr) {
537 speculative_op = simplified()->SpeculativeNumberBitwiseOr(hint);
538 } else {
539 DCHECK_EQ(IrOpcode::kNumberBitwiseXor, int_op->opcode());
540 speculative_op = simplified()->SpeculativeNumberBitwiseXor(hint);
541 }
542 return r.ChangeToSpeculativeOperator(speculative_op, Type::Signed32());
543 } 519 }
544 if (r.BothInputsAre(Type::PlainPrimitive()) || 520 if (r.BothInputsAre(Type::PlainPrimitive()) ||
545 !(flags() & kDeoptimizationEnabled)) { 521 !(flags() & kDeoptimizationEnabled)) {
546 r.ConvertInputsToNumber(); 522 r.ConvertInputsToNumber();
547 r.ConvertInputsToUI32(kSigned, kSigned); 523 r.ConvertInputsToUI32(kSigned, kSigned);
548 return r.ChangeToPureOperator(int_op, Type::Signed32()); 524 return r.ChangeToPureOperator(r.NumberOp(), Type::Signed32());
549 } 525 }
550 return NoChange(); 526 return NoChange();
551 } 527 }
552 528
553 Reduction JSTypedLowering::ReduceUI32Shift(Node* node, Signedness signedness, 529 Reduction JSTypedLowering::ReduceUI32Shift(Node* node, Signedness signedness) {
554 const Operator* shift_op) {
555 JSBinopReduction r(this, node); 530 JSBinopReduction r(this, node);
556 NumberOperationHint hint; 531 NumberOperationHint hint;
557 if (r.GetBinaryNumberOperationHint(&hint)) { 532 if (r.GetBinaryNumberOperationHint(&hint)) {
558 Operator const* speculative_op;
559 if (shift_op->opcode() == IrOpcode::kNumberShiftLeft) {
560 speculative_op = simplified()->SpeculativeNumberShiftLeft(hint);
561 } else if (shift_op->opcode() == IrOpcode::kNumberShiftRightLogical) {
562 speculative_op = simplified()->SpeculativeNumberShiftRightLogical(hint);
563 } else {
564 DCHECK_EQ(IrOpcode::kNumberShiftRight, shift_op->opcode());
565 speculative_op = simplified()->SpeculativeNumberShiftRight(hint);
566 }
567 return r.ChangeToSpeculativeOperator( 533 return r.ChangeToSpeculativeOperator(
568 speculative_op, 534 r.SpeculativeNumberOp(hint),
569 signedness == kUnsigned ? Type::Unsigned32() : Type::Signed32()); 535 signedness == kUnsigned ? Type::Unsigned32() : Type::Signed32());
570 } 536 }
571 if (r.BothInputsAre(Type::PlainPrimitive()) || 537 if (r.BothInputsAre(Type::PlainPrimitive()) ||
572 !(flags() & kDeoptimizationEnabled)) { 538 !(flags() & kDeoptimizationEnabled)) {
573 r.ConvertInputsToNumber(); 539 r.ConvertInputsToNumber();
574 r.ConvertInputsToUI32(signedness, kUnsigned); 540 r.ConvertInputsToUI32(signedness, kUnsigned);
575 return r.ChangeToPureOperator(shift_op); 541 return r.ChangeToPureOperator(r.NumberOp(), signedness == kUnsigned
542 ? Type::Unsigned32()
543 : Type::Signed32());
576 } 544 }
577 return NoChange(); 545 return NoChange();
578 } 546 }
579 547
580 Reduction JSTypedLowering::ReduceJSComparison(Node* node) { 548 Reduction JSTypedLowering::ReduceJSComparison(Node* node) {
581 JSBinopReduction r(this, node); 549 JSBinopReduction r(this, node);
582 if (r.BothInputsAre(Type::String())) { 550 if (r.BothInputsAre(Type::String())) {
583 // If both inputs are definitely strings, perform a string comparison. 551 // If both inputs are definitely strings, perform a string comparison.
584 const Operator* stringOp; 552 const Operator* stringOp;
585 switch (node->opcode()) { 553 switch (node->opcode()) {
(...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after
2040 case IrOpcode::kJSStrictEqual: 2008 case IrOpcode::kJSStrictEqual:
2041 return ReduceJSStrictEqual(node, false); 2009 return ReduceJSStrictEqual(node, false);
2042 case IrOpcode::kJSStrictNotEqual: 2010 case IrOpcode::kJSStrictNotEqual:
2043 return ReduceJSStrictEqual(node, true); 2011 return ReduceJSStrictEqual(node, true);
2044 case IrOpcode::kJSLessThan: // fall through 2012 case IrOpcode::kJSLessThan: // fall through
2045 case IrOpcode::kJSGreaterThan: // fall through 2013 case IrOpcode::kJSGreaterThan: // fall through
2046 case IrOpcode::kJSLessThanOrEqual: // fall through 2014 case IrOpcode::kJSLessThanOrEqual: // fall through
2047 case IrOpcode::kJSGreaterThanOrEqual: 2015 case IrOpcode::kJSGreaterThanOrEqual:
2048 return ReduceJSComparison(node); 2016 return ReduceJSComparison(node);
2049 case IrOpcode::kJSBitwiseOr: 2017 case IrOpcode::kJSBitwiseOr:
2050 return ReduceInt32Binop(node, simplified()->NumberBitwiseOr());
2051 case IrOpcode::kJSBitwiseXor: 2018 case IrOpcode::kJSBitwiseXor:
2052 return ReduceInt32Binop(node, simplified()->NumberBitwiseXor());
2053 case IrOpcode::kJSBitwiseAnd: 2019 case IrOpcode::kJSBitwiseAnd:
2054 return ReduceInt32Binop(node, simplified()->NumberBitwiseAnd()); 2020 return ReduceInt32Binop(node);
2055 case IrOpcode::kJSShiftLeft: 2021 case IrOpcode::kJSShiftLeft:
2056 return ReduceUI32Shift(node, kSigned, simplified()->NumberShiftLeft());
2057 case IrOpcode::kJSShiftRight: 2022 case IrOpcode::kJSShiftRight:
2058 return ReduceUI32Shift(node, kSigned, simplified()->NumberShiftRight()); 2023 return ReduceUI32Shift(node, kSigned);
2059 case IrOpcode::kJSShiftRightLogical: 2024 case IrOpcode::kJSShiftRightLogical:
2060 return ReduceUI32Shift(node, kUnsigned, 2025 return ReduceUI32Shift(node, kUnsigned);
2061 simplified()->NumberShiftRightLogical());
2062 case IrOpcode::kJSAdd: 2026 case IrOpcode::kJSAdd:
2063 return ReduceJSAdd(node); 2027 return ReduceJSAdd(node);
2064 case IrOpcode::kJSSubtract: 2028 case IrOpcode::kJSSubtract:
2065 return ReduceJSSubtract(node);
2066 case IrOpcode::kJSMultiply: 2029 case IrOpcode::kJSMultiply:
2067 return ReduceJSMultiply(node);
2068 case IrOpcode::kJSDivide: 2030 case IrOpcode::kJSDivide:
2069 return ReduceJSDivide(node);
2070 case IrOpcode::kJSModulus: 2031 case IrOpcode::kJSModulus:
2071 return ReduceJSModulus(node); 2032 return ReduceNumberBinop(node);
2072 case IrOpcode::kJSToBoolean: 2033 case IrOpcode::kJSToBoolean:
2073 return ReduceJSToBoolean(node); 2034 return ReduceJSToBoolean(node);
2074 case IrOpcode::kJSToInteger: 2035 case IrOpcode::kJSToInteger:
2075 return ReduceJSToInteger(node); 2036 return ReduceJSToInteger(node);
2076 case IrOpcode::kJSToLength: 2037 case IrOpcode::kJSToLength:
2077 return ReduceJSToLength(node); 2038 return ReduceJSToLength(node);
2078 case IrOpcode::kJSToNumber: 2039 case IrOpcode::kJSToNumber:
2079 return ReduceJSToNumber(node); 2040 return ReduceJSToNumber(node);
2080 case IrOpcode::kJSToString: 2041 case IrOpcode::kJSToString:
2081 return ReduceJSToString(node); 2042 return ReduceJSToString(node);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2158 } 2119 }
2159 2120
2160 2121
2161 CompilationDependencies* JSTypedLowering::dependencies() const { 2122 CompilationDependencies* JSTypedLowering::dependencies() const {
2162 return dependencies_; 2123 return dependencies_;
2163 } 2124 }
2164 2125
2165 } // namespace compiler 2126 } // namespace compiler
2166 } // namespace internal 2127 } // namespace internal
2167 } // namespace v8 2128 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-typed-lowering.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698