| 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/address-map.h" |
| 8 #include "src/code-factory.h" |
| 7 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/linkage.h" | 10 #include "src/compiler/linkage.h" |
| 9 #include "src/compiler/machine-operator.h" | 11 #include "src/compiler/machine-operator.h" |
| 10 #include "src/compiler/node-properties.h" | 12 #include "src/compiler/node-properties.h" |
| 13 #include "src/compiler/operator-properties.h" |
| 11 #include "src/compiler/simplified-operator.h" | 14 #include "src/compiler/simplified-operator.h" |
| 12 #include "src/conversions-inl.h" | |
| 13 | 15 |
| 14 namespace v8 { | 16 namespace v8 { |
| 15 namespace internal { | 17 namespace internal { |
| 16 namespace compiler { | 18 namespace compiler { |
| 17 | 19 |
| 18 ChangeLowering::~ChangeLowering() {} | 20 ChangeLowering::~ChangeLowering() {} |
| 19 | 21 |
| 20 | 22 |
| 21 Reduction ChangeLowering::Reduce(Node* node) { | 23 Reduction ChangeLowering::Reduce(Node* node) { |
| 24 Node* control = graph()->start(); |
| 22 switch (node->opcode()) { | 25 switch (node->opcode()) { |
| 26 case IrOpcode::kChangeBitToBool: |
| 27 return ReduceChangeBitToBool(node->InputAt(0), control); |
| 28 case IrOpcode::kChangeBoolToBit: |
| 29 return ReduceChangeBoolToBit(node->InputAt(0)); |
| 30 case IrOpcode::kChangeInt31ToTagged: |
| 31 return ReduceChangeInt31ToTagged(node->InputAt(0), control); |
| 32 case IrOpcode::kChangeTaggedSignedToInt32: |
| 33 return ReduceChangeTaggedSignedToInt32(node->InputAt(0)); |
| 23 case IrOpcode::kLoadField: | 34 case IrOpcode::kLoadField: |
| 24 return ReduceLoadField(node); | 35 return ReduceLoadField(node); |
| 25 case IrOpcode::kStoreField: | 36 case IrOpcode::kStoreField: |
| 26 return ReduceStoreField(node); | 37 return ReduceStoreField(node); |
| 27 case IrOpcode::kLoadElement: | 38 case IrOpcode::kLoadElement: |
| 28 return ReduceLoadElement(node); | 39 return ReduceLoadElement(node); |
| 29 case IrOpcode::kStoreElement: | 40 case IrOpcode::kStoreElement: |
| 30 return ReduceStoreElement(node); | 41 return ReduceStoreElement(node); |
| 31 case IrOpcode::kAllocate: | 42 case IrOpcode::kAllocate: |
| 32 return ReduceAllocate(node); | 43 return ReduceAllocate(node); |
| 44 case IrOpcode::kObjectIsSmi: |
| 45 return ReduceObjectIsSmi(node); |
| 33 default: | 46 default: |
| 34 return NoChange(); | 47 return NoChange(); |
| 35 } | 48 } |
| 36 UNREACHABLE(); | 49 UNREACHABLE(); |
| 37 return NoChange(); | 50 return NoChange(); |
| 38 } | 51 } |
| 39 | 52 |
| 53 Node* ChangeLowering::SmiShiftBitsConstant() { |
| 54 return jsgraph()->IntPtrConstant(kSmiShiftSize + kSmiTagSize); |
| 55 } |
| 56 |
| 57 Node* ChangeLowering::ChangeInt32ToSmi(Node* value) { |
| 58 if (machine()->Is64()) { |
| 59 value = graph()->NewNode(machine()->ChangeInt32ToInt64(), value); |
| 60 } |
| 61 return graph()->NewNode(machine()->WordShl(), value, SmiShiftBitsConstant()); |
| 62 } |
| 63 |
| 64 Node* ChangeLowering::ChangeSmiToWord32(Node* value) { |
| 65 value = graph()->NewNode(machine()->WordSar(), value, SmiShiftBitsConstant()); |
| 66 if (machine()->Is64()) { |
| 67 value = graph()->NewNode(machine()->TruncateInt64ToInt32(), value); |
| 68 } |
| 69 return value; |
| 70 } |
| 71 |
| 72 |
| 73 Node* ChangeLowering::ChangeUint32ToFloat64(Node* value) { |
| 74 return graph()->NewNode(machine()->ChangeUint32ToFloat64(), value); |
| 75 } |
| 76 |
| 77 Reduction ChangeLowering::ReduceChangeBitToBool(Node* value, Node* control) { |
| 78 return Replace( |
| 79 graph()->NewNode(common()->Select(MachineRepresentation::kTagged), value, |
| 80 jsgraph()->TrueConstant(), jsgraph()->FalseConstant())); |
| 81 } |
| 82 |
| 83 Reduction ChangeLowering::ReduceChangeBoolToBit(Node* value) { |
| 84 return Replace(graph()->NewNode(machine()->WordEqual(), value, |
| 85 jsgraph()->TrueConstant())); |
| 86 } |
| 87 |
| 88 Reduction ChangeLowering::ReduceChangeInt31ToTagged(Node* value, |
| 89 Node* control) { |
| 90 return Replace(ChangeInt32ToSmi(value)); |
| 91 } |
| 92 |
| 93 Reduction ChangeLowering::ReduceChangeTaggedSignedToInt32(Node* value) { |
| 94 return Replace(ChangeSmiToWord32(value)); |
| 95 } |
| 96 |
| 40 namespace { | 97 namespace { |
| 41 | 98 |
| 42 WriteBarrierKind ComputeWriteBarrierKind(BaseTaggedness base_is_tagged, | 99 WriteBarrierKind ComputeWriteBarrierKind(BaseTaggedness base_is_tagged, |
| 43 MachineRepresentation representation, | 100 MachineRepresentation representation, |
| 44 Node* value) { | 101 Node* value) { |
| 45 // TODO(bmeurer): Optimize write barriers based on input. | 102 // TODO(bmeurer): Optimize write barriers based on input. |
| 46 if (base_is_tagged == kTaggedBase && | 103 if (base_is_tagged == kTaggedBase && |
| 47 representation == MachineRepresentation::kTagged) { | 104 representation == MachineRepresentation::kTagged) { |
| 48 if (value->opcode() == IrOpcode::kHeapConstant) { | 105 if (value->opcode() == IrOpcode::kHeapConstant) { |
| 49 return kPointerWriteBarrier; | 106 return kPointerWriteBarrier; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 node->InsertInput(graph()->zone(), 0, target); | 198 node->InsertInput(graph()->zone(), 0, target); |
| 142 if (!allocate_operator_.is_set()) { | 199 if (!allocate_operator_.is_set()) { |
| 143 CallDescriptor* descriptor = | 200 CallDescriptor* descriptor = |
| 144 Linkage::GetAllocateCallDescriptor(graph()->zone()); | 201 Linkage::GetAllocateCallDescriptor(graph()->zone()); |
| 145 allocate_operator_.set(common()->Call(descriptor)); | 202 allocate_operator_.set(common()->Call(descriptor)); |
| 146 } | 203 } |
| 147 NodeProperties::ChangeOp(node, allocate_operator_.get()); | 204 NodeProperties::ChangeOp(node, allocate_operator_.get()); |
| 148 return Changed(node); | 205 return Changed(node); |
| 149 } | 206 } |
| 150 | 207 |
| 208 Reduction ChangeLowering::ReduceObjectIsSmi(Node* node) { |
| 209 node->ReplaceInput(0, |
| 210 graph()->NewNode(machine()->WordAnd(), node->InputAt(0), |
| 211 jsgraph()->IntPtrConstant(kSmiTagMask))); |
| 212 node->AppendInput(graph()->zone(), jsgraph()->IntPtrConstant(kSmiTag)); |
| 213 NodeProperties::ChangeOp(node, machine()->WordEqual()); |
| 214 return Changed(node); |
| 215 } |
| 216 |
| 151 Isolate* ChangeLowering::isolate() const { return jsgraph()->isolate(); } | 217 Isolate* ChangeLowering::isolate() const { return jsgraph()->isolate(); } |
| 152 | 218 |
| 153 | 219 |
| 154 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); } | 220 Graph* ChangeLowering::graph() const { return jsgraph()->graph(); } |
| 155 | 221 |
| 156 | 222 |
| 157 CommonOperatorBuilder* ChangeLowering::common() const { | 223 CommonOperatorBuilder* ChangeLowering::common() const { |
| 158 return jsgraph()->common(); | 224 return jsgraph()->common(); |
| 159 } | 225 } |
| 160 | 226 |
| 161 | 227 |
| 162 MachineOperatorBuilder* ChangeLowering::machine() const { | 228 MachineOperatorBuilder* ChangeLowering::machine() const { |
| 163 return jsgraph()->machine(); | 229 return jsgraph()->machine(); |
| 164 } | 230 } |
| 165 | 231 |
| 166 } // namespace compiler | 232 } // namespace compiler |
| 167 } // namespace internal | 233 } // namespace internal |
| 168 } // namespace v8 | 234 } // namespace v8 |
| OLD | NEW |