diff options
Diffstat (limited to 'deps/v8/src/compiler/js-intrinsic-lowering.cc')
-rw-r--r-- | deps/v8/src/compiler/js-intrinsic-lowering.cc | 157 |
1 files changed, 114 insertions, 43 deletions
diff --git a/deps/v8/src/compiler/js-intrinsic-lowering.cc b/deps/v8/src/compiler/js-intrinsic-lowering.cc index 219a452a7d..379f8b7490 100644 --- a/deps/v8/src/compiler/js-intrinsic-lowering.cc +++ b/deps/v8/src/compiler/js-intrinsic-lowering.cc @@ -6,13 +6,16 @@ #include <stack> +#include "src/code-factory.h" #include "src/compiler/access-builder.h" #include "src/compiler/js-graph.h" +#include "src/compiler/linkage.h" #include "src/compiler/node-matchers.h" #include "src/compiler/node-properties.h" #include "src/compiler/operator-properties.h" #include "src/counters.h" #include "src/objects-inl.h" +#include "src/type-cache.h" namespace v8 { namespace internal { @@ -23,7 +26,7 @@ JSIntrinsicLowering::JSIntrinsicLowering(Editor* editor, JSGraph* jsgraph, : AdvancedReducer(editor), jsgraph_(jsgraph), mode_(mode), - simplified_(jsgraph->zone()) {} + type_cache_(TypeCache::Get()) {} Reduction JSIntrinsicLowering::Reduce(Node* node) { @@ -60,8 +63,6 @@ Reduction JSIntrinsicLowering::Reduce(Node* node) { return ReduceIsSmi(node); case Runtime::kInlineJSValueGetValue: return ReduceJSValueGetValue(node); - case Runtime::kInlineLikely: - return ReduceUnLikely(node, BranchHint::kTrue); case Runtime::kInlineMapGetInstanceType: return ReduceMapGetInstanceType(node); case Runtime::kInlineMathClz32: @@ -80,8 +81,6 @@ Reduction JSIntrinsicLowering::Reduce(Node* node) { return ReduceSeqStringGetChar(node, String::TWO_BYTE_ENCODING); case Runtime::kInlineTwoByteSeqStringSetChar: return ReduceSeqStringSetChar(node, String::TWO_BYTE_ENCODING); - case Runtime::kInlineUnlikely: - return ReduceUnLikely(node, BranchHint::kFalse); case Runtime::kInlineValueOf: return ReduceValueOf(node); case Runtime::kInlineIsMinusZero: @@ -94,12 +93,24 @@ Reduction JSIntrinsicLowering::Reduce(Node* node) { return ReduceGetTypeFeedbackVector(node); case Runtime::kInlineGetCallerJSFunction: return ReduceGetCallerJSFunction(node); + case Runtime::kInlineToInteger: + return ReduceToInteger(node); + case Runtime::kInlineToLength: + return ReduceToLength(node); + case Runtime::kInlineToName: + return ReduceToName(node); + case Runtime::kInlineToNumber: + return ReduceToNumber(node); case Runtime::kInlineToObject: return ReduceToObject(node); + case Runtime::kInlineToPrimitive: + return ReduceToPrimitive(node); + case Runtime::kInlineToString: + return ReduceToString(node); case Runtime::kInlineThrowNotDateError: return ReduceThrowNotDateError(node); - case Runtime::kInlineCallFunction: - return ReduceCallFunction(node); + case Runtime::kInlineCall: + return ReduceCall(node); default: break; } @@ -321,35 +332,11 @@ Reduction JSIntrinsicLowering::ReduceStringGetLength(Node* node) { Node* value = NodeProperties::GetValueInput(node, 0); Node* effect = NodeProperties::GetEffectInput(node); Node* control = NodeProperties::GetControlInput(node); - return Change(node, simplified()->LoadField( - AccessBuilder::ForStringLength(graph()->zone())), + return Change(node, simplified()->LoadField(AccessBuilder::ForStringLength()), value, effect, control); } -Reduction JSIntrinsicLowering::ReduceUnLikely(Node* node, BranchHint hint) { - std::stack<Node*> nodes_to_visit; - nodes_to_visit.push(node); - while (!nodes_to_visit.empty()) { - Node* current = nodes_to_visit.top(); - nodes_to_visit.pop(); - for (Node* use : current->uses()) { - if (use->opcode() == IrOpcode::kJSToBoolean) { - // We have to "look through" ToBoolean calls. - nodes_to_visit.push(use); - } else if (use->opcode() == IrOpcode::kBranch) { - // Actually set the hint on any branch using the intrinsic node. - NodeProperties::ChangeOp(use, common()->Branch(hint)); - } - } - } - // Apart from adding hints to branchs nodes, this is the identity function. - Node* value = NodeProperties::GetValueInput(node, 0); - ReplaceWithValue(node, value); - return Changed(value); -} - - Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { // if (%_IsSmi(value)) { // return value; @@ -527,25 +514,101 @@ Reduction JSIntrinsicLowering::ReduceThrowNotDateError(Node* node) { } +Reduction JSIntrinsicLowering::ReduceToInteger(Node* node) { + Node* value = NodeProperties::GetValueInput(node, 0); + Type* value_type = NodeProperties::GetType(value); + if (value_type->Is(type_cache().kIntegerOrMinusZero)) { + ReplaceWithValue(node, value); + return Replace(value); + } + return NoChange(); +} + + +Reduction JSIntrinsicLowering::ReduceToName(Node* node) { + NodeProperties::ChangeOp(node, javascript()->ToName()); + return Changed(node); +} + + +Reduction JSIntrinsicLowering::ReduceToNumber(Node* node) { + NodeProperties::ChangeOp(node, javascript()->ToNumber()); + return Changed(node); +} + + +Reduction JSIntrinsicLowering::ReduceToLength(Node* node) { + Node* value = NodeProperties::GetValueInput(node, 0); + Type* value_type = NodeProperties::GetType(value); + if (value_type->Is(type_cache().kIntegerOrMinusZero)) { + if (value_type->Max() <= 0.0) { + value = jsgraph()->ZeroConstant(); + } else if (value_type->Min() >= kMaxSafeInteger) { + value = jsgraph()->Constant(kMaxSafeInteger); + } else { + if (value_type->Min() <= 0.0) { + value = graph()->NewNode( + common()->Select(kMachAnyTagged), + graph()->NewNode(simplified()->NumberLessThanOrEqual(), value, + jsgraph()->ZeroConstant()), + jsgraph()->ZeroConstant(), value); + value_type = Type::Range(0.0, value_type->Max(), graph()->zone()); + NodeProperties::SetType(value, value_type); + } + if (value_type->Max() > kMaxSafeInteger) { + value = graph()->NewNode( + common()->Select(kMachAnyTagged), + graph()->NewNode(simplified()->NumberLessThanOrEqual(), + jsgraph()->Constant(kMaxSafeInteger), value), + jsgraph()->Constant(kMaxSafeInteger), value); + value_type = + Type::Range(value_type->Min(), kMaxSafeInteger, graph()->zone()); + NodeProperties::SetType(value, value_type); + } + } + ReplaceWithValue(node, value); + return Replace(value); + } + Callable callable = CodeFactory::ToLength(isolate()); + CallDescriptor const* const desc = Linkage::GetStubCallDescriptor( + isolate(), graph()->zone(), callable.descriptor(), 0, + CallDescriptor::kNeedsFrameState, node->op()->properties()); + node->InsertInput(graph()->zone(), 0, + jsgraph()->HeapConstant(callable.code())); + NodeProperties::ChangeOp(node, common()->Call(desc)); + return Changed(node); +} + + Reduction JSIntrinsicLowering::ReduceToObject(Node* node) { NodeProperties::ChangeOp(node, javascript()->ToObject()); return Changed(node); } -Reduction JSIntrinsicLowering::ReduceCallFunction(Node* node) { - CallRuntimeParameters params = OpParameter<CallRuntimeParameters>(node->op()); - size_t arity = params.arity(); - Node* function = node->InputAt(static_cast<int>(arity - 1)); - while (--arity != 0) { - node->ReplaceInput(static_cast<int>(arity), - node->InputAt(static_cast<int>(arity - 1))); +Reduction JSIntrinsicLowering::ReduceToPrimitive(Node* node) { + Node* value = NodeProperties::GetValueInput(node, 0); + Type* value_type = NodeProperties::GetType(value); + if (value_type->Is(Type::Primitive())) { + ReplaceWithValue(node, value); + return Replace(value); } - node->ReplaceInput(0, function); + return NoChange(); +} + + +Reduction JSIntrinsicLowering::ReduceToString(Node* node) { + NodeProperties::ChangeOp(node, javascript()->ToString()); + return Changed(node); +} + + +Reduction JSIntrinsicLowering::ReduceCall(Node* node) { + size_t const arity = CallRuntimeParametersOf(node->op()).arity(); NodeProperties::ChangeOp( - node, - javascript()->CallFunction(params.arity(), NO_CALL_FUNCTION_FLAGS, STRICT, - VectorSlotPair(), ALLOW_TAIL_CALLS)); + node, javascript()->CallFunction(arity, STRICT, VectorSlotPair(), + ConvertReceiverMode::kAny, + TailCallMode::kAllow)); return Changed(node); } @@ -595,6 +658,9 @@ Reduction JSIntrinsicLowering::ChangeToUndefined(Node* node, Node* effect) { Graph* JSIntrinsicLowering::graph() const { return jsgraph()->graph(); } +Isolate* JSIntrinsicLowering::isolate() const { return jsgraph()->isolate(); } + + CommonOperatorBuilder* JSIntrinsicLowering::common() const { return jsgraph()->common(); } @@ -608,6 +674,11 @@ MachineOperatorBuilder* JSIntrinsicLowering::machine() const { return jsgraph()->machine(); } + +SimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const { + return jsgraph()->simplified(); +} + } // namespace compiler } // namespace internal } // namespace v8 |