| OLD | NEW |
| 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/change-lowering.h" | 5 #include "src/compiler/change-lowering.h" |
| 6 | 6 |
| 7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/linkage.h" | 8 #include "src/compiler/linkage.h" |
| 9 #include "src/compiler/machine-operator.h" | 9 #include "src/compiler/machine-operator.h" |
| 10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
| 11 #include "src/compiler/simplified-operator.h" | 11 #include "src/compiler/simplified-operator.h" |
| 12 #include "src/conversions-inl.h" | |
| 13 | 12 |
| 14 namespace v8 { | 13 namespace v8 { |
| 15 namespace internal { | 14 namespace internal { |
| 16 namespace compiler { | 15 namespace compiler { |
| 17 | 16 |
| 18 ChangeLowering::~ChangeLowering() {} | 17 ChangeLowering::~ChangeLowering() {} |
| 19 | 18 |
| 20 | 19 |
| 21 Reduction ChangeLowering::Reduce(Node* node) { | 20 Reduction ChangeLowering::Reduce(Node* node) { |
| 22 switch (node->opcode()) { | 21 switch (node->opcode()) { |
| 23 case IrOpcode::kLoadField: | 22 case IrOpcode::kLoadField: |
| 24 return ReduceLoadField(node); | 23 return ReduceLoadField(node); |
| 25 case IrOpcode::kStoreField: | 24 case IrOpcode::kStoreField: |
| 26 return ReduceStoreField(node); | 25 return ReduceStoreField(node); |
| 27 case IrOpcode::kLoadElement: | 26 case IrOpcode::kLoadElement: |
| 28 return ReduceLoadElement(node); | 27 return ReduceLoadElement(node); |
| 29 case IrOpcode::kStoreElement: | 28 case IrOpcode::kStoreElement: |
| 30 return ReduceStoreElement(node); | 29 return ReduceStoreElement(node); |
| 31 case IrOpcode::kAllocate: | 30 case IrOpcode::kAllocate: |
| 32 return ReduceAllocate(node); | 31 return ReduceAllocate(node); |
| 33 default: | 32 default: |
| 34 return NoChange(); | 33 return NoChange(); |
| 35 } | 34 } |
| 36 UNREACHABLE(); | 35 UNREACHABLE(); |
| 37 return NoChange(); | 36 return NoChange(); |
| 38 } | 37 } |
| 39 | 38 |
| 40 namespace { | |
| 41 | |
| 42 WriteBarrierKind ComputeWriteBarrierKind(BaseTaggedness base_is_tagged, | |
| 43 MachineRepresentation representation, | |
| 44 Node* value) { | |
| 45 // TODO(bmeurer): Optimize write barriers based on input. | |
| 46 if (base_is_tagged == kTaggedBase && | |
| 47 representation == MachineRepresentation::kTagged) { | |
| 48 if (value->opcode() == IrOpcode::kHeapConstant) { | |
| 49 return kPointerWriteBarrier; | |
| 50 } else if (value->opcode() == IrOpcode::kNumberConstant) { | |
| 51 double const number_value = OpParameter<double>(value); | |
| 52 if (IsSmiDouble(number_value)) return kNoWriteBarrier; | |
| 53 return kPointerWriteBarrier; | |
| 54 } | |
| 55 return kFullWriteBarrier; | |
| 56 } | |
| 57 return kNoWriteBarrier; | |
| 58 } | |
| 59 | |
| 60 WriteBarrierKind ComputeWriteBarrierKind(BaseTaggedness base_is_tagged, | |
| 61 MachineRepresentation representation, | |
| 62 int field_offset, Node* value) { | |
| 63 if (base_is_tagged == kTaggedBase && field_offset == HeapObject::kMapOffset) { | |
| 64 // Write barriers for storing maps are cheaper. | |
| 65 return kMapWriteBarrier; | |
| 66 } | |
| 67 return ComputeWriteBarrierKind(base_is_tagged, representation, value); | |
| 68 } | |
| 69 | |
| 70 } // namespace | |
| 71 | |
| 72 Reduction ChangeLowering::ReduceLoadField(Node* node) { | 39 Reduction ChangeLowering::ReduceLoadField(Node* node) { |
| 73 const FieldAccess& access = FieldAccessOf(node->op()); | 40 const FieldAccess& access = FieldAccessOf(node->op()); |
| 74 Node* offset = jsgraph()->IntPtrConstant(access.offset - access.tag()); | 41 Node* offset = jsgraph()->IntPtrConstant(access.offset - access.tag()); |
| 75 node->InsertInput(graph()->zone(), 1, offset); | 42 node->InsertInput(graph()->zone(), 1, offset); |
| 76 NodeProperties::ChangeOp(node, machine()->Load(access.machine_type)); | 43 NodeProperties::ChangeOp(node, machine()->Load(access.machine_type)); |
| 77 return Changed(node); | 44 return Changed(node); |
| 78 } | 45 } |
| 79 | 46 |
| 80 Reduction ChangeLowering::ReduceStoreField(Node* node) { | 47 Reduction ChangeLowering::ReduceStoreField(Node* node) { |
| 81 const FieldAccess& access = FieldAccessOf(node->op()); | 48 const FieldAccess& access = FieldAccessOf(node->op()); |
| 82 WriteBarrierKind kind = ComputeWriteBarrierKind( | |
| 83 access.base_is_tagged, access.machine_type.representation(), | |
| 84 access.offset, node->InputAt(1)); | |
| 85 Node* offset = jsgraph()->IntPtrConstant(access.offset - access.tag()); | 49 Node* offset = jsgraph()->IntPtrConstant(access.offset - access.tag()); |
| 86 node->InsertInput(graph()->zone(), 1, offset); | 50 node->InsertInput(graph()->zone(), 1, offset); |
| 87 NodeProperties::ChangeOp(node, | 51 NodeProperties::ChangeOp(node, machine()->Store(StoreRepresentation( |
| 88 machine()->Store(StoreRepresentation( | 52 access.machine_type.representation(), |
| 89 access.machine_type.representation(), kind))); | 53 access.write_barrier_kind))); |
| 90 return Changed(node); | 54 return Changed(node); |
| 91 } | 55 } |
| 92 | 56 |
| 93 | 57 |
| 94 Node* ChangeLowering::ComputeIndex(const ElementAccess& access, | 58 Node* ChangeLowering::ComputeIndex(const ElementAccess& access, |
| 95 Node* const key) { | 59 Node* const key) { |
| 96 Node* index = key; | 60 Node* index = key; |
| 97 const int element_size_shift = | 61 const int element_size_shift = |
| 98 ElementSizeLog2Of(access.machine_type.representation()); | 62 ElementSizeLog2Of(access.machine_type.representation()); |
| 99 if (element_size_shift) { | 63 if (element_size_shift) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 117 Reduction ChangeLowering::ReduceLoadElement(Node* node) { | 81 Reduction ChangeLowering::ReduceLoadElement(Node* node) { |
| 118 const ElementAccess& access = ElementAccessOf(node->op()); | 82 const ElementAccess& access = ElementAccessOf(node->op()); |
| 119 node->ReplaceInput(1, ComputeIndex(access, node->InputAt(1))); | 83 node->ReplaceInput(1, ComputeIndex(access, node->InputAt(1))); |
| 120 NodeProperties::ChangeOp(node, machine()->Load(access.machine_type)); | 84 NodeProperties::ChangeOp(node, machine()->Load(access.machine_type)); |
| 121 return Changed(node); | 85 return Changed(node); |
| 122 } | 86 } |
| 123 | 87 |
| 124 Reduction ChangeLowering::ReduceStoreElement(Node* node) { | 88 Reduction ChangeLowering::ReduceStoreElement(Node* node) { |
| 125 const ElementAccess& access = ElementAccessOf(node->op()); | 89 const ElementAccess& access = ElementAccessOf(node->op()); |
| 126 node->ReplaceInput(1, ComputeIndex(access, node->InputAt(1))); | 90 node->ReplaceInput(1, ComputeIndex(access, node->InputAt(1))); |
| 127 NodeProperties::ChangeOp( | 91 NodeProperties::ChangeOp(node, machine()->Store(StoreRepresentation( |
| 128 node, machine()->Store(StoreRepresentation( | 92 access.machine_type.representation(), |
| 129 access.machine_type.representation(), | 93 access.write_barrier_kind))); |
| 130 ComputeWriteBarrierKind(access.base_is_tagged, | |
| 131 access.machine_type.representation(), | |
| 132 node->InputAt(2))))); | |
| 133 return Changed(node); | 94 return Changed(node); |
| 134 } | 95 } |
| 135 | 96 |
| 136 Reduction ChangeLowering::ReduceAllocate(Node* node) { | 97 Reduction ChangeLowering::ReduceAllocate(Node* node) { |
| 137 PretenureFlag pretenure = OpParameter<PretenureFlag>(node->op()); | 98 PretenureFlag pretenure = OpParameter<PretenureFlag>(node->op()); |
| 138 Node* target = pretenure == NOT_TENURED | 99 Node* target = pretenure == NOT_TENURED |
| 139 ? jsgraph()->AllocateInNewSpaceStubConstant() | 100 ? jsgraph()->AllocateInNewSpaceStubConstant() |
| 140 : jsgraph()->AllocateInOldSpaceStubConstant(); | 101 : jsgraph()->AllocateInOldSpaceStubConstant(); |
| 141 node->InsertInput(graph()->zone(), 0, target); | 102 node->InsertInput(graph()->zone(), 0, target); |
| 142 if (!allocate_operator_.is_set()) { | 103 if (!allocate_operator_.is_set()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 159 } | 120 } |
| 160 | 121 |
| 161 | 122 |
| 162 MachineOperatorBuilder* ChangeLowering::machine() const { | 123 MachineOperatorBuilder* ChangeLowering::machine() const { |
| 163 return jsgraph()->machine(); | 124 return jsgraph()->machine(); |
| 164 } | 125 } |
| 165 | 126 |
| 166 } // namespace compiler | 127 } // namespace compiler |
| 167 } // namespace internal | 128 } // namespace internal |
| 168 } // namespace v8 | 129 } // namespace v8 |
| OLD | NEW |