| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/js-intrinsic-lowering.h" | 5 #include "src/compiler/js-intrinsic-lowering.h" |
| 6 | 6 |
| 7 #include "src/compiler/access-builder.h" | 7 #include "src/compiler/access-builder.h" |
| 8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
| 9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 namespace compiler { | 13 namespace compiler { |
| 14 | 14 |
| 15 JSIntrinsicLowering::JSIntrinsicLowering(JSGraph* jsgraph) | 15 JSIntrinsicLowering::JSIntrinsicLowering(JSGraph* jsgraph) |
| 16 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} | 16 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} |
| 17 | 17 |
| 18 | 18 |
| 19 Reduction JSIntrinsicLowering::Reduce(Node* node) { | 19 Reduction JSIntrinsicLowering::Reduce(Node* node) { |
| 20 if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange(); | 20 if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange(); |
| 21 const Runtime::Function* const f = | 21 const Runtime::Function* const f = |
| 22 Runtime::FunctionForId(CallRuntimeParametersOf(node->op()).id()); | 22 Runtime::FunctionForId(CallRuntimeParametersOf(node->op()).id()); |
| 23 if (f->intrinsic_type != Runtime::IntrinsicType::INLINE) return NoChange(); | 23 if (f->intrinsic_type != Runtime::IntrinsicType::INLINE) return NoChange(); |
| 24 switch (f->function_id) { | 24 switch (f->function_id) { |
| 25 case Runtime::kInlineConstructDouble: |
| 26 return ReduceInlineConstructDouble(node); |
| 25 case Runtime::kInlineDeoptimizeNow: | 27 case Runtime::kInlineDeoptimizeNow: |
| 26 return ReduceInlineDeoptimizeNow(node); | 28 return ReduceInlineDeoptimizeNow(node); |
| 27 case Runtime::kInlineIsSmi: | 29 case Runtime::kInlineDoubleHi: |
| 28 return ReduceInlineIsSmi(node); | 30 return ReduceInlineDoubleHi(node); |
| 29 case Runtime::kInlineIsNonNegativeSmi: | 31 case Runtime::kInlineDoubleLo: |
| 30 return ReduceInlineIsNonNegativeSmi(node); | 32 return ReduceInlineDoubleLo(node); |
| 33 case Runtime::kInlineHeapObjectGetMap: |
| 34 return ReduceHeapObjectGetMap(node); |
| 31 case Runtime::kInlineIsArray: | 35 case Runtime::kInlineIsArray: |
| 32 return ReduceInlineIsInstanceType(node, JS_ARRAY_TYPE); | 36 return ReduceInlineIsInstanceType(node, JS_ARRAY_TYPE); |
| 33 case Runtime::kInlineIsFunction: | 37 case Runtime::kInlineIsFunction: |
| 34 return ReduceInlineIsInstanceType(node, JS_FUNCTION_TYPE); | 38 return ReduceInlineIsInstanceType(node, JS_FUNCTION_TYPE); |
| 39 case Runtime::kInlineIsNonNegativeSmi: |
| 40 return ReduceInlineIsNonNegativeSmi(node); |
| 41 case Runtime::kInlineIsRegExp: |
| 42 return ReduceInlineIsInstanceType(node, JS_REGEXP_TYPE); |
| 43 case Runtime::kInlineIsSmi: |
| 44 return ReduceInlineIsSmi(node); |
| 35 case Runtime::kInlineJSValueGetValue: | 45 case Runtime::kInlineJSValueGetValue: |
| 36 return ReduceInlineJSValueGetValue(node); | 46 return ReduceInlineJSValueGetValue(node); |
| 37 case Runtime::kInlineConstructDouble: | 47 case Runtime::kInlineMapGetInstanceType: |
| 38 return ReduceInlineConstructDouble(node); | 48 return ReduceMapGetInstanceType(node); |
| 39 case Runtime::kInlineDoubleLo: | |
| 40 return ReduceInlineDoubleLo(node); | |
| 41 case Runtime::kInlineDoubleHi: | |
| 42 return ReduceInlineDoubleHi(node); | |
| 43 case Runtime::kInlineIsRegExp: | |
| 44 return ReduceInlineIsInstanceType(node, JS_REGEXP_TYPE); | |
| 45 case Runtime::kInlineMathClz32: | 49 case Runtime::kInlineMathClz32: |
| 46 return ReduceInlineMathClz32(node); | 50 return ReduceInlineMathClz32(node); |
| 47 case Runtime::kInlineMathFloor: | 51 case Runtime::kInlineMathFloor: |
| 48 return ReduceInlineMathFloor(node); | 52 return ReduceInlineMathFloor(node); |
| 49 case Runtime::kInlineMathSqrt: | 53 case Runtime::kInlineMathSqrt: |
| 50 return ReduceInlineMathSqrt(node); | 54 return ReduceInlineMathSqrt(node); |
| 51 case Runtime::kInlineStringGetLength: | 55 case Runtime::kInlineStringGetLength: |
| 52 return ReduceInlineStringGetLength(node); | 56 return ReduceInlineStringGetLength(node); |
| 53 case Runtime::kInlineValueOf: | 57 case Runtime::kInlineValueOf: |
| 54 return ReduceInlineValueOf(node); | 58 return ReduceInlineValueOf(node); |
| 55 default: | 59 default: |
| 56 break; | 60 break; |
| 57 } | 61 } |
| 58 return NoChange(); | 62 return NoChange(); |
| 59 } | 63 } |
| 60 | 64 |
| 61 | 65 |
| 66 Reduction JSIntrinsicLowering::ReduceInlineConstructDouble(Node* node) { |
| 67 Node* high = NodeProperties::GetValueInput(node, 0); |
| 68 Node* low = NodeProperties::GetValueInput(node, 1); |
| 69 Node* value = |
| 70 graph()->NewNode(machine()->Float64InsertHighWord32(), |
| 71 graph()->NewNode(machine()->Float64InsertLowWord32(), |
| 72 jsgraph()->Constant(0), low), |
| 73 high); |
| 74 NodeProperties::ReplaceWithValue(node, value); |
| 75 return Replace(value); |
| 76 } |
| 77 |
| 78 |
| 62 Reduction JSIntrinsicLowering::ReduceInlineDeoptimizeNow(Node* node) { | 79 Reduction JSIntrinsicLowering::ReduceInlineDeoptimizeNow(Node* node) { |
| 63 if (!FLAG_turbo_deoptimization) return NoChange(); | 80 if (!FLAG_turbo_deoptimization) return NoChange(); |
| 64 | 81 |
| 65 Node* frame_state = NodeProperties::GetFrameStateInput(node, 0); | 82 Node* frame_state = NodeProperties::GetFrameStateInput(node, 0); |
| 66 DCHECK_EQ(frame_state->opcode(), IrOpcode::kFrameState); | 83 DCHECK_EQ(frame_state->opcode(), IrOpcode::kFrameState); |
| 67 | 84 |
| 68 Node* effect = NodeProperties::GetEffectInput(node); | 85 Node* effect = NodeProperties::GetEffectInput(node); |
| 69 Node* control = NodeProperties::GetControlInput(node); | 86 Node* control = NodeProperties::GetControlInput(node); |
| 70 | 87 |
| 71 // We are making the continuation after the call dead. To | 88 // We are making the continuation after the call dead. To |
| (...skipping 20 matching lines...) Expand all Loading... |
| 92 end_pred->set_op(common()->Merge(inputs)); | 109 end_pred->set_op(common()->Merge(inputs)); |
| 93 } else { | 110 } else { |
| 94 Node* merge = graph()->NewNode(common()->Merge(2), end_pred, deopt); | 111 Node* merge = graph()->NewNode(common()->Merge(2), end_pred, deopt); |
| 95 NodeProperties::ReplaceControlInput(graph()->end(), merge); | 112 NodeProperties::ReplaceControlInput(graph()->end(), merge); |
| 96 } | 113 } |
| 97 | 114 |
| 98 return Changed(deopt); | 115 return Changed(deopt); |
| 99 } | 116 } |
| 100 | 117 |
| 101 | 118 |
| 102 Reduction JSIntrinsicLowering::ReduceInlineIsSmi(Node* node) { | 119 Reduction JSIntrinsicLowering::ReduceInlineDoubleHi(Node* node) { |
| 103 return Change(node, simplified()->ObjectIsSmi()); | 120 return Change(node, machine()->Float64ExtractHighWord32()); |
| 104 } | |
| 105 | |
| 106 | |
| 107 Reduction JSIntrinsicLowering::ReduceInlineIsNonNegativeSmi(Node* node) { | |
| 108 return Change(node, simplified()->ObjectIsNonNegativeSmi()); | |
| 109 } | |
| 110 | |
| 111 | |
| 112 Reduction JSIntrinsicLowering::ReduceInlineJSValueGetValue(Node* node) { | |
| 113 Node* value = NodeProperties::GetValueInput(node, 0); | |
| 114 Node* effect = NodeProperties::GetEffectInput(node); | |
| 115 Node* control = NodeProperties::GetControlInput(node); | |
| 116 return Change(node, simplified()->LoadField(AccessBuilder::ForValue()), value, | |
| 117 effect, control); | |
| 118 } | |
| 119 | |
| 120 | |
| 121 Reduction JSIntrinsicLowering::ReduceInlineConstructDouble(Node* node) { | |
| 122 Node* high = NodeProperties::GetValueInput(node, 0); | |
| 123 Node* low = NodeProperties::GetValueInput(node, 1); | |
| 124 Node* value = | |
| 125 graph()->NewNode(machine()->Float64InsertHighWord32(), | |
| 126 graph()->NewNode(machine()->Float64InsertLowWord32(), | |
| 127 jsgraph()->Constant(0), low), | |
| 128 high); | |
| 129 NodeProperties::ReplaceWithValue(node, value); | |
| 130 return Replace(value); | |
| 131 } | 121 } |
| 132 | 122 |
| 133 | 123 |
| 134 Reduction JSIntrinsicLowering::ReduceInlineDoubleLo(Node* node) { | 124 Reduction JSIntrinsicLowering::ReduceInlineDoubleLo(Node* node) { |
| 135 return Change(node, machine()->Float64ExtractLowWord32()); | 125 return Change(node, machine()->Float64ExtractLowWord32()); |
| 136 } | 126 } |
| 137 | 127 |
| 138 | 128 |
| 139 Reduction JSIntrinsicLowering::ReduceInlineDoubleHi(Node* node) { | 129 Reduction JSIntrinsicLowering::ReduceHeapObjectGetMap(Node* node) { |
| 140 return Change(node, machine()->Float64ExtractHighWord32()); | 130 Node* value = NodeProperties::GetValueInput(node, 0); |
| 131 Node* effect = NodeProperties::GetEffectInput(node); |
| 132 Node* control = NodeProperties::GetControlInput(node); |
| 133 return Change(node, simplified()->LoadField(AccessBuilder::ForMap()), value, |
| 134 effect, control); |
| 141 } | 135 } |
| 142 | 136 |
| 143 | 137 |
| 144 Reduction JSIntrinsicLowering::ReduceInlineIsInstanceType( | 138 Reduction JSIntrinsicLowering::ReduceInlineIsInstanceType( |
| 145 Node* node, InstanceType instance_type) { | 139 Node* node, InstanceType instance_type) { |
| 146 // if (%_IsSmi(value)) { | 140 // if (%_IsSmi(value)) { |
| 147 // return false; | 141 // return false; |
| 148 // } else { | 142 // } else { |
| 149 // return %_GetInstanceType(%_GetMap(value)) == instance_type; | 143 // return %_GetInstanceType(%_GetMap(value)) == instance_type; |
| 150 // } | 144 // } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 174 | 168 |
| 175 // Replace all effect uses of {node} with the {ephi}. | 169 // Replace all effect uses of {node} with the {ephi}. |
| 176 Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge); | 170 Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge); |
| 177 NodeProperties::ReplaceWithValue(node, node, ephi); | 171 NodeProperties::ReplaceWithValue(node, node, ephi); |
| 178 | 172 |
| 179 // Turn the {node} into a Phi. | 173 // Turn the {node} into a Phi. |
| 180 return Change(node, common()->Phi(type, 2), vtrue, vfalse, merge); | 174 return Change(node, common()->Phi(type, 2), vtrue, vfalse, merge); |
| 181 } | 175 } |
| 182 | 176 |
| 183 | 177 |
| 178 Reduction JSIntrinsicLowering::ReduceInlineIsNonNegativeSmi(Node* node) { |
| 179 return Change(node, simplified()->ObjectIsNonNegativeSmi()); |
| 180 } |
| 181 |
| 182 |
| 183 Reduction JSIntrinsicLowering::ReduceInlineIsSmi(Node* node) { |
| 184 return Change(node, simplified()->ObjectIsSmi()); |
| 185 } |
| 186 |
| 187 |
| 188 Reduction JSIntrinsicLowering::ReduceInlineJSValueGetValue(Node* node) { |
| 189 Node* value = NodeProperties::GetValueInput(node, 0); |
| 190 Node* effect = NodeProperties::GetEffectInput(node); |
| 191 Node* control = NodeProperties::GetControlInput(node); |
| 192 return Change(node, simplified()->LoadField(AccessBuilder::ForValue()), value, |
| 193 effect, control); |
| 194 } |
| 195 |
| 196 |
| 197 Reduction JSIntrinsicLowering::ReduceMapGetInstanceType(Node* node) { |
| 198 Node* value = NodeProperties::GetValueInput(node, 0); |
| 199 Node* effect = NodeProperties::GetEffectInput(node); |
| 200 Node* control = NodeProperties::GetControlInput(node); |
| 201 return Change(node, |
| 202 simplified()->LoadField(AccessBuilder::ForMapInstanceType()), |
| 203 value, effect, control); |
| 204 } |
| 205 |
| 206 |
| 184 Reduction JSIntrinsicLowering::ReduceInlineMathClz32(Node* node) { | 207 Reduction JSIntrinsicLowering::ReduceInlineMathClz32(Node* node) { |
| 185 return Change(node, machine()->Word32Clz()); | 208 return Change(node, machine()->Word32Clz()); |
| 186 } | 209 } |
| 187 | 210 |
| 188 | 211 |
| 189 Reduction JSIntrinsicLowering::ReduceInlineMathFloor(Node* node) { | 212 Reduction JSIntrinsicLowering::ReduceInlineMathFloor(Node* node) { |
| 190 if (!machine()->HasFloat64RoundDown()) return NoChange(); | 213 if (!machine()->HasFloat64RoundDown()) return NoChange(); |
| 191 return Change(node, machine()->Float64RoundDown()); | 214 return Change(node, machine()->Float64RoundDown()); |
| 192 } | 215 } |
| 193 | 216 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 } | 323 } |
| 301 | 324 |
| 302 | 325 |
| 303 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { | 326 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { |
| 304 return jsgraph()->machine(); | 327 return jsgraph()->machine(); |
| 305 } | 328 } |
| 306 | 329 |
| 307 } // namespace compiler | 330 } // namespace compiler |
| 308 } // namespace internal | 331 } // namespace internal |
| 309 } // namespace v8 | 332 } // namespace v8 |
| OLD | NEW |