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

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

Issue 2227463003: [WIP] NumberToString operator in TF. Base URL: https://chromium.googlesource.com/v8/v8.git@TurboFan_BuiltinTypingRules
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-builtin-reducer.h ('k') | src/compiler/js-typed-lowering.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/js-builtin-reducer.h" 5 #include "src/compiler/js-builtin-reducer.h"
6 6
7 #include "src/compiler/access-builder.h" 7 #include "src/compiler/access-builder.h"
8 #include "src/compiler/js-graph.h" 8 #include "src/compiler/js-graph.h"
9 #include "src/compiler/node-matchers.h" 9 #include "src/compiler/node-matchers.h"
10 #include "src/compiler/node-properties.h" 10 #include "src/compiler/node-properties.h"
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 // Number.parseInt(a:safe-integer) -> NumberToInt32(a) 522 // Number.parseInt(a:safe-integer) -> NumberToInt32(a)
523 // Number.parseInt(a:safe-integer,b:#0\/undefined) -> NumberToInt32(a) 523 // Number.parseInt(a:safe-integer,b:#0\/undefined) -> NumberToInt32(a)
524 // Number.parseInt(a:safe-integer,b:#10\/undefined) -> NumberToInt32(a) 524 // Number.parseInt(a:safe-integer,b:#10\/undefined) -> NumberToInt32(a)
525 Node* input = r.GetJSCallInput(0); 525 Node* input = r.GetJSCallInput(0);
526 Node* value = graph()->NewNode(simplified()->NumberToInt32(), input); 526 Node* value = graph()->NewNode(simplified()->NumberToInt32(), input);
527 return Replace(value); 527 return Replace(value);
528 } 528 }
529 return NoChange(); 529 return NoChange();
530 } 530 }
531 531
532 namespace {
533
534 Node* GetNumberWitness(Node* node) {
535 Node* receiver = NodeProperties::GetValueInput(node, 1);
536 Type* receiver_type = NodeProperties::GetType(receiver);
537 Node* effect = NodeProperties::GetEffectInput(node);
538 if (receiver_type->Is(Type::Number())) return receiver;
539 // Check if the {node} is dominated by a CheckNumber renaming for
540 // it's {receiver}, and if so use that renaming as {receiver} for
541 // the lowering below.
542 for (Node* dominator = effect;;) {
543 if (dominator->opcode() == IrOpcode::kCheckNumber &&
544 dominator->InputAt(0) == receiver) {
545 return dominator;
546 }
547 if (dominator->op()->EffectInputCount() != 1) {
548 // Didn't find any appropriate CheckNumber node.
549 return nullptr;
550 }
551 dominator = NodeProperties::GetEffectInput(dominator);
552 }
553 }
554
555 } // namespace
556
557 // 20.1.3.6 Number.prototype.toString ( [ radix ] )
558 Reduction JSBuiltinReducer::ReduceNumberToString(Node* node) {
559 if (Node* receiver = GetNumberWitness(node)) {
560 // Determine the optional {radix} parameter.
561 Node* radix = node->op()->ValueInputCount() > 2
562 ? NodeProperties::GetValueInput(node, 2)
563 : jsgraph()->Constant(10);
564 Type* radix_type = NodeProperties::GetType(radix);
565 if (radix_type->Is(Type::Undefined())) {
566 radix = jsgraph()->Constant(10.0);
567 radix_type = type_cache_.kSingletonTen;
568 }
569 if (radix_type->Is(Type::Unsigned32())) {
570 if (radix_type->Min() >= 2.0 && radix_type->Max() <= 36.0) {
571 // Return the String representation of the Number {receiver}
572 // according to the given {radix}.
573 Node* value =
574 graph()->NewNode(simplified()->NumberToString(), receiver, radix);
575 return Replace(value);
576 }
577 }
578 }
579 return NoChange();
580 }
581
532 // ES6 section 21.1.2.1 String.fromCharCode ( ...codeUnits ) 582 // ES6 section 21.1.2.1 String.fromCharCode ( ...codeUnits )
533 Reduction JSBuiltinReducer::ReduceStringFromCharCode(Node* node) { 583 Reduction JSBuiltinReducer::ReduceStringFromCharCode(Node* node) {
534 JSCallReduction r(node); 584 JSCallReduction r(node);
535 if (r.InputsMatchOne(Type::PlainPrimitive())) { 585 if (r.InputsMatchOne(Type::PlainPrimitive())) {
536 // String.fromCharCode(a:plain-primitive) -> StringFromCharCode(a) 586 // String.fromCharCode(a:plain-primitive) -> StringFromCharCode(a)
537 Node* input = ToNumber(r.GetJSCallInput(0)); 587 Node* input = ToNumber(r.GetJSCallInput(0));
538 Node* value = graph()->NewNode(simplified()->StringFromCharCode(), input); 588 Node* value = graph()->NewNode(simplified()->StringFromCharCode(), input);
539 return Replace(value); 589 return Replace(value);
540 } 590 }
541 return NoChange(); 591 return NoChange();
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 break; 894 break;
845 case kMathTanh: 895 case kMathTanh:
846 reduction = ReduceMathTanh(node); 896 reduction = ReduceMathTanh(node);
847 break; 897 break;
848 case kMathTrunc: 898 case kMathTrunc:
849 reduction = ReduceMathTrunc(node); 899 reduction = ReduceMathTrunc(node);
850 break; 900 break;
851 case kNumberParseInt: 901 case kNumberParseInt:
852 reduction = ReduceNumberParseInt(node); 902 reduction = ReduceNumberParseInt(node);
853 break; 903 break;
904 case kNumberToString:
905 reduction = ReduceNumberToString(node);
906 break;
854 case kStringFromCharCode: 907 case kStringFromCharCode:
855 reduction = ReduceStringFromCharCode(node); 908 reduction = ReduceStringFromCharCode(node);
856 break; 909 break;
857 case kStringCharAt: 910 case kStringCharAt:
858 return ReduceStringCharAt(node); 911 return ReduceStringCharAt(node);
859 case kStringCharCodeAt: 912 case kStringCharCodeAt:
860 return ReduceStringCharCodeAt(node); 913 return ReduceStringCharCodeAt(node);
861 case kDataViewByteLength: 914 case kDataViewByteLength:
862 return ReduceArrayBufferViewAccessor( 915 return ReduceArrayBufferViewAccessor(
863 node, JS_DATA_VIEW_TYPE, 916 node, JS_DATA_VIEW_TYPE,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 } 965 }
913 966
914 967
915 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { 968 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const {
916 return jsgraph()->simplified(); 969 return jsgraph()->simplified();
917 } 970 }
918 971
919 } // namespace compiler 972 } // namespace compiler
920 } // namespace internal 973 } // namespace internal
921 } // namespace v8 974 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-builtin-reducer.h ('k') | src/compiler/js-typed-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698