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 <stack> | 7 #include <stack> |
8 | 8 |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/compiler/access-builder.h" | 10 #include "src/compiler/access-builder.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 case Runtime::kInlineIsTypedArray: | 56 case Runtime::kInlineIsTypedArray: |
57 return ReduceIsInstanceType(node, JS_TYPED_ARRAY_TYPE); | 57 return ReduceIsInstanceType(node, JS_TYPED_ARRAY_TYPE); |
58 case Runtime::kInlineIsFunction: | 58 case Runtime::kInlineIsFunction: |
59 return ReduceIsInstanceType(node, JS_FUNCTION_TYPE); | 59 return ReduceIsInstanceType(node, JS_FUNCTION_TYPE); |
60 case Runtime::kInlineIsRegExp: | 60 case Runtime::kInlineIsRegExp: |
61 return ReduceIsInstanceType(node, JS_REGEXP_TYPE); | 61 return ReduceIsInstanceType(node, JS_REGEXP_TYPE); |
62 case Runtime::kInlineIsSmi: | 62 case Runtime::kInlineIsSmi: |
63 return ReduceIsSmi(node); | 63 return ReduceIsSmi(node); |
64 case Runtime::kInlineJSValueGetValue: | 64 case Runtime::kInlineJSValueGetValue: |
65 return ReduceJSValueGetValue(node); | 65 return ReduceJSValueGetValue(node); |
66 case Runtime::kInlineLikely: | |
67 return ReduceUnLikely(node, BranchHint::kTrue); | |
68 case Runtime::kInlineMapGetInstanceType: | 66 case Runtime::kInlineMapGetInstanceType: |
69 return ReduceMapGetInstanceType(node); | 67 return ReduceMapGetInstanceType(node); |
70 case Runtime::kInlineMathClz32: | 68 case Runtime::kInlineMathClz32: |
71 return ReduceMathClz32(node); | 69 return ReduceMathClz32(node); |
72 case Runtime::kInlineMathFloor: | 70 case Runtime::kInlineMathFloor: |
73 return ReduceMathFloor(node); | 71 return ReduceMathFloor(node); |
74 case Runtime::kInlineMathSqrt: | 72 case Runtime::kInlineMathSqrt: |
75 return ReduceMathSqrt(node); | 73 return ReduceMathSqrt(node); |
76 case Runtime::kInlineOneByteSeqStringGetChar: | 74 case Runtime::kInlineOneByteSeqStringGetChar: |
77 return ReduceSeqStringGetChar(node, String::ONE_BYTE_ENCODING); | 75 return ReduceSeqStringGetChar(node, String::ONE_BYTE_ENCODING); |
78 case Runtime::kInlineOneByteSeqStringSetChar: | 76 case Runtime::kInlineOneByteSeqStringSetChar: |
79 return ReduceSeqStringSetChar(node, String::ONE_BYTE_ENCODING); | 77 return ReduceSeqStringSetChar(node, String::ONE_BYTE_ENCODING); |
80 case Runtime::kInlineStringGetLength: | 78 case Runtime::kInlineStringGetLength: |
81 return ReduceStringGetLength(node); | 79 return ReduceStringGetLength(node); |
82 case Runtime::kInlineTwoByteSeqStringGetChar: | 80 case Runtime::kInlineTwoByteSeqStringGetChar: |
83 return ReduceSeqStringGetChar(node, String::TWO_BYTE_ENCODING); | 81 return ReduceSeqStringGetChar(node, String::TWO_BYTE_ENCODING); |
84 case Runtime::kInlineTwoByteSeqStringSetChar: | 82 case Runtime::kInlineTwoByteSeqStringSetChar: |
85 return ReduceSeqStringSetChar(node, String::TWO_BYTE_ENCODING); | 83 return ReduceSeqStringSetChar(node, String::TWO_BYTE_ENCODING); |
86 case Runtime::kInlineUnlikely: | |
87 return ReduceUnLikely(node, BranchHint::kFalse); | |
88 case Runtime::kInlineValueOf: | 84 case Runtime::kInlineValueOf: |
89 return ReduceValueOf(node); | 85 return ReduceValueOf(node); |
90 case Runtime::kInlineIsMinusZero: | 86 case Runtime::kInlineIsMinusZero: |
91 return ReduceIsMinusZero(node); | 87 return ReduceIsMinusZero(node); |
92 case Runtime::kInlineFixedArrayGet: | 88 case Runtime::kInlineFixedArrayGet: |
93 return ReduceFixedArrayGet(node); | 89 return ReduceFixedArrayGet(node); |
94 case Runtime::kInlineFixedArraySet: | 90 case Runtime::kInlineFixedArraySet: |
95 return ReduceFixedArraySet(node); | 91 return ReduceFixedArraySet(node); |
96 case Runtime::kInlineGetTypeFeedbackVector: | 92 case Runtime::kInlineGetTypeFeedbackVector: |
97 return ReduceGetTypeFeedbackVector(node); | 93 return ReduceGetTypeFeedbackVector(node); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 | 330 |
335 Reduction JSIntrinsicLowering::ReduceStringGetLength(Node* node) { | 331 Reduction JSIntrinsicLowering::ReduceStringGetLength(Node* node) { |
336 Node* value = NodeProperties::GetValueInput(node, 0); | 332 Node* value = NodeProperties::GetValueInput(node, 0); |
337 Node* effect = NodeProperties::GetEffectInput(node); | 333 Node* effect = NodeProperties::GetEffectInput(node); |
338 Node* control = NodeProperties::GetControlInput(node); | 334 Node* control = NodeProperties::GetControlInput(node); |
339 return Change(node, simplified()->LoadField(AccessBuilder::ForStringLength()), | 335 return Change(node, simplified()->LoadField(AccessBuilder::ForStringLength()), |
340 value, effect, control); | 336 value, effect, control); |
341 } | 337 } |
342 | 338 |
343 | 339 |
344 Reduction JSIntrinsicLowering::ReduceUnLikely(Node* node, BranchHint hint) { | |
345 std::stack<Node*> nodes_to_visit; | |
346 nodes_to_visit.push(node); | |
347 while (!nodes_to_visit.empty()) { | |
348 Node* current = nodes_to_visit.top(); | |
349 nodes_to_visit.pop(); | |
350 for (Node* use : current->uses()) { | |
351 if (use->opcode() == IrOpcode::kJSToBoolean) { | |
352 // We have to "look through" ToBoolean calls. | |
353 nodes_to_visit.push(use); | |
354 } else if (use->opcode() == IrOpcode::kBranch) { | |
355 // Actually set the hint on any branch using the intrinsic node. | |
356 NodeProperties::ChangeOp(use, common()->Branch(hint)); | |
357 } | |
358 } | |
359 } | |
360 // Apart from adding hints to branchs nodes, this is the identity function. | |
361 Node* value = NodeProperties::GetValueInput(node, 0); | |
362 ReplaceWithValue(node, value); | |
363 return Changed(value); | |
364 } | |
365 | |
366 | |
367 Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { | 340 Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { |
368 // if (%_IsSmi(value)) { | 341 // if (%_IsSmi(value)) { |
369 // return value; | 342 // return value; |
370 // } else if (%_GetInstanceType(%_GetMap(value)) == JS_VALUE_TYPE) { | 343 // } else if (%_GetInstanceType(%_GetMap(value)) == JS_VALUE_TYPE) { |
371 // return %_GetValue(value); | 344 // return %_GetValue(value); |
372 // } else { | 345 // } else { |
373 // return value; | 346 // return value; |
374 // } | 347 // } |
375 const Operator* const merge_op = common()->Merge(2); | 348 const Operator* const merge_op = common()->Merge(2); |
376 const Operator* const ephi_op = common()->EffectPhi(2); | 349 const Operator* const ephi_op = common()->EffectPhi(2); |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 } | 675 } |
703 | 676 |
704 | 677 |
705 SimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const { | 678 SimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const { |
706 return jsgraph()->simplified(); | 679 return jsgraph()->simplified(); |
707 } | 680 } |
708 | 681 |
709 } // namespace compiler | 682 } // namespace compiler |
710 } // namespace internal | 683 } // namespace internal |
711 } // namespace v8 | 684 } // namespace v8 |
OLD | NEW |