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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/js-builtin-reducer.cc
diff --git a/src/compiler/js-builtin-reducer.cc b/src/compiler/js-builtin-reducer.cc
index 868ae7b0b3cb0411e35084c6bad2f9325dc39c90..15b6d174687157544ab8c1a7c3d058d6aff3bfa4 100644
--- a/src/compiler/js-builtin-reducer.cc
+++ b/src/compiler/js-builtin-reducer.cc
@@ -529,6 +529,56 @@ Reduction JSBuiltinReducer::ReduceNumberParseInt(Node* node) {
return NoChange();
}
+namespace {
+
+Node* GetNumberWitness(Node* node) {
+ Node* receiver = NodeProperties::GetValueInput(node, 1);
+ Type* receiver_type = NodeProperties::GetType(receiver);
+ Node* effect = NodeProperties::GetEffectInput(node);
+ if (receiver_type->Is(Type::Number())) return receiver;
+ // Check if the {node} is dominated by a CheckNumber renaming for
+ // it's {receiver}, and if so use that renaming as {receiver} for
+ // the lowering below.
+ for (Node* dominator = effect;;) {
+ if (dominator->opcode() == IrOpcode::kCheckNumber &&
+ dominator->InputAt(0) == receiver) {
+ return dominator;
+ }
+ if (dominator->op()->EffectInputCount() != 1) {
+ // Didn't find any appropriate CheckNumber node.
+ return nullptr;
+ }
+ dominator = NodeProperties::GetEffectInput(dominator);
+ }
+}
+
+} // namespace
+
+// 20.1.3.6 Number.prototype.toString ( [ radix ] )
+Reduction JSBuiltinReducer::ReduceNumberToString(Node* node) {
+ if (Node* receiver = GetNumberWitness(node)) {
+ // Determine the optional {radix} parameter.
+ Node* radix = node->op()->ValueInputCount() > 2
+ ? NodeProperties::GetValueInput(node, 2)
+ : jsgraph()->Constant(10);
+ Type* radix_type = NodeProperties::GetType(radix);
+ if (radix_type->Is(Type::Undefined())) {
+ radix = jsgraph()->Constant(10.0);
+ radix_type = type_cache_.kSingletonTen;
+ }
+ if (radix_type->Is(Type::Unsigned32())) {
+ if (radix_type->Min() >= 2.0 && radix_type->Max() <= 36.0) {
+ // Return the String representation of the Number {receiver}
+ // according to the given {radix}.
+ Node* value =
+ graph()->NewNode(simplified()->NumberToString(), receiver, radix);
+ return Replace(value);
+ }
+ }
+ }
+ return NoChange();
+}
+
// ES6 section 21.1.2.1 String.fromCharCode ( ...codeUnits )
Reduction JSBuiltinReducer::ReduceStringFromCharCode(Node* node) {
JSCallReduction r(node);
@@ -851,6 +901,9 @@ Reduction JSBuiltinReducer::Reduce(Node* node) {
case kNumberParseInt:
reduction = ReduceNumberParseInt(node);
break;
+ case kNumberToString:
+ reduction = ReduceNumberToString(node);
+ break;
case kStringFromCharCode:
reduction = ReduceStringFromCharCode(node);
break;
« 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