From a56af88942f1b52fb6c31967aeeb63411d13fbc2 Mon Sep 17 00:00:00 2001 From: jarin Date: Thu, 18 Feb 2016 23:18:42 -0800 Subject: [PATCH] [turbofan] Move lowering of ObjectIs* nodes to ChangeLowering. Review URL: https://codereview.chromium.org/1712563002 Cr-Commit-Position: refs/heads/master@{#34137} --- src/compiler/change-lowering.cc | 76 ++++++++++++++++++++++++++++ src/compiler/change-lowering.h | 8 +++ src/compiler/simplified-lowering.cc | 77 ----------------------------- src/compiler/simplified-lowering.h | 6 --- 4 files changed, 84 insertions(+), 83 deletions(-) diff --git a/src/compiler/change-lowering.cc b/src/compiler/change-lowering.cc index f791db1fdc..e217f3786b 100644 --- a/src/compiler/change-lowering.cc +++ b/src/compiler/change-lowering.cc @@ -49,6 +49,12 @@ Reduction ChangeLowering::Reduce(Node* node) { return StoreElement(node); case IrOpcode::kAllocate: return Allocate(node); + case IrOpcode::kObjectIsReceiver: + return ObjectIsReceiver(node); + case IrOpcode::kObjectIsSmi: + return ObjectIsSmi(node); + case IrOpcode::kObjectIsNumber: + return ObjectIsNumber(node); default: return NoChange(); } @@ -582,6 +588,76 @@ Reduction ChangeLowering::Allocate(Node* node) { return Changed(node); } +Node* ChangeLowering::IsSmi(Node* value) { + return graph()->NewNode( + machine()->WordEqual(), + graph()->NewNode(machine()->WordAnd(), value, + jsgraph()->IntPtrConstant(kSmiTagMask)), + jsgraph()->IntPtrConstant(kSmiTag)); +} + +Node* ChangeLowering::LoadHeapObjectMap(Node* object, Node* control) { + return graph()->NewNode( + machine()->Load(MachineType::AnyTagged()), object, + jsgraph()->IntPtrConstant(HeapObject::kMapOffset - kHeapObjectTag), + graph()->start(), control); +} + +Node* ChangeLowering::LoadMapInstanceType(Node* map) { + return graph()->NewNode( + machine()->Load(MachineType::Uint8()), map, + jsgraph()->IntPtrConstant(Map::kInstanceTypeOffset - kHeapObjectTag), + graph()->start(), graph()->start()); +} + +Reduction ChangeLowering::ObjectIsNumber(Node* node) { + Node* input = NodeProperties::GetValueInput(node, 0); + // TODO(bmeurer): Optimize somewhat based on input type. + Node* check = IsSmi(input); + Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); + Node* if_true = graph()->NewNode(common()->IfTrue(), branch); + Node* vtrue = jsgraph()->Int32Constant(1); + Node* if_false = graph()->NewNode(common()->IfFalse(), branch); + Node* vfalse = graph()->NewNode( + machine()->WordEqual(), LoadHeapObjectMap(input, if_false), + jsgraph()->HeapConstant(isolate()->factory()->heap_number_map())); + Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); + node->ReplaceInput(0, vtrue); + node->AppendInput(graph()->zone(), vfalse); + node->AppendInput(graph()->zone(), control); + NodeProperties::ChangeOp(node, common()->Phi(MachineRepresentation::kBit, 2)); + return Changed(node); +} + +Reduction ChangeLowering::ObjectIsReceiver(Node* node) { + Node* input = NodeProperties::GetValueInput(node, 0); + // TODO(bmeurer): Optimize somewhat based on input type. + STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); + Node* check = IsSmi(input); + Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); + Node* if_true = graph()->NewNode(common()->IfTrue(), branch); + Node* vtrue = jsgraph()->Int32Constant(0); + Node* if_false = graph()->NewNode(common()->IfFalse(), branch); + Node* vfalse = + graph()->NewNode(machine()->Uint32LessThanOrEqual(), + jsgraph()->Uint32Constant(FIRST_JS_RECEIVER_TYPE), + LoadMapInstanceType(LoadHeapObjectMap(input, if_false))); + Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); + node->ReplaceInput(0, vtrue); + node->AppendInput(graph()->zone(), vfalse); + node->AppendInput(graph()->zone(), control); + NodeProperties::ChangeOp(node, common()->Phi(MachineRepresentation::kBit, 2)); + return Changed(node); +} + +Reduction ChangeLowering::ObjectIsSmi(Node* node) { + node->ReplaceInput(0, + graph()->NewNode(machine()->WordAnd(), node->InputAt(0), + jsgraph()->IntPtrConstant(kSmiTagMask))); + node->AppendInput(graph()->zone(), jsgraph()->IntPtrConstant(kSmiTag)); + NodeProperties::ChangeOp(node, machine()->WordEqual()); + return Changed(node); +} Isolate* ChangeLowering::isolate() const { return jsgraph()->isolate(); } diff --git a/src/compiler/change-lowering.h b/src/compiler/change-lowering.h index 6d607768d9..defadd95fd 100644 --- a/src/compiler/change-lowering.h +++ b/src/compiler/change-lowering.h @@ -56,6 +56,14 @@ class ChangeLowering final : public Reducer { Reduction StoreElement(Node* node); Reduction Allocate(Node* node); + Node* IsSmi(Node* value); + Node* LoadHeapObjectMap(Node* object, Node* control); + Node* LoadMapInstanceType(Node* map); + + Reduction ObjectIsNumber(Node* node); + Reduction ObjectIsReceiver(Node* node); + Reduction ObjectIsSmi(Node* node); + Node* ComputeIndex(const ElementAccess& access, Node* const key); Graph* graph() const; Isolate* isolate() const; diff --git a/src/compiler/simplified-lowering.cc b/src/compiler/simplified-lowering.cc index dedcfe6bce..38df48e18e 100644 --- a/src/compiler/simplified-lowering.cc +++ b/src/compiler/simplified-lowering.cc @@ -1241,19 +1241,16 @@ class RepresentationSelector { case IrOpcode::kObjectIsNumber: { ProcessInput(node, 0, UseInfo::AnyTagged()); SetOutput(node, NodeOutputInfo::Bool()); - if (lower()) lowering->DoObjectIsNumber(node); break; } case IrOpcode::kObjectIsReceiver: { ProcessInput(node, 0, UseInfo::AnyTagged()); SetOutput(node, NodeOutputInfo::Bool()); - if (lower()) lowering->DoObjectIsReceiver(node); break; } case IrOpcode::kObjectIsSmi: { ProcessInput(node, 0, UseInfo::AnyTagged()); SetOutput(node, NodeOutputInfo::Bool()); - if (lower()) lowering->DoObjectIsSmi(node); break; } @@ -1591,80 +1588,6 @@ void SimplifiedLowering::DoStoreBuffer(Node* node) { } -void SimplifiedLowering::DoObjectIsNumber(Node* node) { - Node* input = NodeProperties::GetValueInput(node, 0); - // TODO(bmeurer): Optimize somewhat based on input type. - Node* check = IsSmi(input); - Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); - Node* if_true = graph()->NewNode(common()->IfTrue(), branch); - Node* vtrue = jsgraph()->Int32Constant(1); - Node* if_false = graph()->NewNode(common()->IfFalse(), branch); - Node* vfalse = graph()->NewNode( - machine()->WordEqual(), LoadHeapObjectMap(input, if_false), - jsgraph()->HeapConstant(isolate()->factory()->heap_number_map())); - Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); - node->ReplaceInput(0, vtrue); - node->AppendInput(graph()->zone(), vfalse); - node->AppendInput(graph()->zone(), control); - NodeProperties::ChangeOp(node, common()->Phi(MachineRepresentation::kBit, 2)); -} - - -void SimplifiedLowering::DoObjectIsReceiver(Node* node) { - Node* input = NodeProperties::GetValueInput(node, 0); - // TODO(bmeurer): Optimize somewhat based on input type. - STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); - Node* check = IsSmi(input); - Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); - Node* if_true = graph()->NewNode(common()->IfTrue(), branch); - Node* vtrue = jsgraph()->Int32Constant(0); - Node* if_false = graph()->NewNode(common()->IfFalse(), branch); - Node* vfalse = - graph()->NewNode(machine()->Uint32LessThanOrEqual(), - jsgraph()->Uint32Constant(FIRST_JS_RECEIVER_TYPE), - LoadMapInstanceType(LoadHeapObjectMap(input, if_false))); - Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); - node->ReplaceInput(0, vtrue); - node->AppendInput(graph()->zone(), vfalse); - node->AppendInput(graph()->zone(), control); - NodeProperties::ChangeOp(node, common()->Phi(MachineRepresentation::kBit, 2)); -} - - -void SimplifiedLowering::DoObjectIsSmi(Node* node) { - node->ReplaceInput(0, - graph()->NewNode(machine()->WordAnd(), node->InputAt(0), - jsgraph()->IntPtrConstant(kSmiTagMask))); - node->AppendInput(graph()->zone(), jsgraph()->IntPtrConstant(kSmiTag)); - NodeProperties::ChangeOp(node, machine()->WordEqual()); -} - - -Node* SimplifiedLowering::IsSmi(Node* value) { - return graph()->NewNode( - machine()->WordEqual(), - graph()->NewNode(machine()->WordAnd(), value, - jsgraph()->IntPtrConstant(kSmiTagMask)), - jsgraph()->IntPtrConstant(kSmiTag)); -} - - -Node* SimplifiedLowering::LoadHeapObjectMap(Node* object, Node* control) { - return graph()->NewNode( - machine()->Load(MachineType::AnyTagged()), object, - jsgraph()->IntPtrConstant(HeapObject::kMapOffset - kHeapObjectTag), - graph()->start(), control); -} - - -Node* SimplifiedLowering::LoadMapInstanceType(Node* map) { - return graph()->NewNode( - machine()->Load(MachineType::Uint8()), map, - jsgraph()->IntPtrConstant(Map::kInstanceTypeOffset - kHeapObjectTag), - graph()->start(), graph()->start()); -} - - Node* SimplifiedLowering::StringComparison(Node* node) { Operator::Properties properties = node->op()->properties(); Callable callable = CodeFactory::StringCompare(isolate()); diff --git a/src/compiler/simplified-lowering.h b/src/compiler/simplified-lowering.h index 0fb079d38c..6792045d7b 100644 --- a/src/compiler/simplified-lowering.h +++ b/src/compiler/simplified-lowering.h @@ -36,9 +36,6 @@ class SimplifiedLowering final { void DoLoadBuffer(Node* node, MachineRepresentation rep, RepresentationChanger* changer); void DoStoreBuffer(Node* node); - void DoObjectIsNumber(Node* node); - void DoObjectIsReceiver(Node* node); - void DoObjectIsSmi(Node* node); void DoShift(Node* node, Operator const* op, Type* rhs_type); void DoStringEqual(Node* node); void DoStringLessThan(Node* node); @@ -56,9 +53,6 @@ class SimplifiedLowering final { // position information via the SourcePositionWrapper like all other reducers. SourcePositionTable* source_positions_; - Node* IsSmi(Node* value); - Node* LoadHeapObjectMap(Node* object, Node* control); - Node* LoadMapInstanceType(Node* map); Node* StringComparison(Node* node); Node* Int32Div(Node* const node); Node* Int32Mod(Node* const node);