OLD | NEW |
1 | 1 |
2 // Copyright 2015 the V8 project authors. All rights reserved. | 2 // Copyright 2015 the V8 project authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 | 5 |
6 #include "src/compiler/js-intrinsic-lowering.h" | 6 #include "src/compiler/js-intrinsic-lowering.h" |
7 | 7 |
| 8 #include <stack> |
| 9 |
8 #include "src/compiler/access-builder.h" | 10 #include "src/compiler/access-builder.h" |
9 #include "src/compiler/js-graph.h" | 11 #include "src/compiler/js-graph.h" |
10 #include "src/compiler/node-matchers.h" | 12 #include "src/compiler/node-matchers.h" |
11 #include "src/compiler/node-properties.h" | 13 #include "src/compiler/node-properties.h" |
12 | 14 |
13 namespace v8 { | 15 namespace v8 { |
14 namespace internal { | 16 namespace internal { |
15 namespace compiler { | 17 namespace compiler { |
16 | 18 |
17 JSIntrinsicLowering::JSIntrinsicLowering(JSGraph* jsgraph) | 19 JSIntrinsicLowering::JSIntrinsicLowering(JSGraph* jsgraph) |
(...skipping 23 matching lines...) Expand all Loading... |
41 case Runtime::kInlineIsFunction: | 43 case Runtime::kInlineIsFunction: |
42 return ReduceIsInstanceType(node, JS_FUNCTION_TYPE); | 44 return ReduceIsInstanceType(node, JS_FUNCTION_TYPE); |
43 case Runtime::kInlineIsNonNegativeSmi: | 45 case Runtime::kInlineIsNonNegativeSmi: |
44 return ReduceIsNonNegativeSmi(node); | 46 return ReduceIsNonNegativeSmi(node); |
45 case Runtime::kInlineIsRegExp: | 47 case Runtime::kInlineIsRegExp: |
46 return ReduceIsInstanceType(node, JS_REGEXP_TYPE); | 48 return ReduceIsInstanceType(node, JS_REGEXP_TYPE); |
47 case Runtime::kInlineIsSmi: | 49 case Runtime::kInlineIsSmi: |
48 return ReduceIsSmi(node); | 50 return ReduceIsSmi(node); |
49 case Runtime::kInlineJSValueGetValue: | 51 case Runtime::kInlineJSValueGetValue: |
50 return ReduceJSValueGetValue(node); | 52 return ReduceJSValueGetValue(node); |
| 53 case Runtime::kInlineLikely: |
| 54 return ReduceUnLikely(node, BranchHint::kTrue); |
51 case Runtime::kInlineMapGetInstanceType: | 55 case Runtime::kInlineMapGetInstanceType: |
52 return ReduceMapGetInstanceType(node); | 56 return ReduceMapGetInstanceType(node); |
53 case Runtime::kInlineMathClz32: | 57 case Runtime::kInlineMathClz32: |
54 return ReduceMathClz32(node); | 58 return ReduceMathClz32(node); |
55 case Runtime::kInlineMathFloor: | 59 case Runtime::kInlineMathFloor: |
56 return ReduceMathFloor(node); | 60 return ReduceMathFloor(node); |
57 case Runtime::kInlineMathSqrt: | 61 case Runtime::kInlineMathSqrt: |
58 return ReduceMathSqrt(node); | 62 return ReduceMathSqrt(node); |
59 case Runtime::kInlineOneByteSeqStringGetChar: | 63 case Runtime::kInlineOneByteSeqStringGetChar: |
60 return ReduceSeqStringGetChar(node, String::ONE_BYTE_ENCODING); | 64 return ReduceSeqStringGetChar(node, String::ONE_BYTE_ENCODING); |
61 case Runtime::kInlineOneByteSeqStringSetChar: | 65 case Runtime::kInlineOneByteSeqStringSetChar: |
62 return ReduceSeqStringSetChar(node, String::ONE_BYTE_ENCODING); | 66 return ReduceSeqStringSetChar(node, String::ONE_BYTE_ENCODING); |
63 case Runtime::kInlineStringGetLength: | 67 case Runtime::kInlineStringGetLength: |
64 return ReduceStringGetLength(node); | 68 return ReduceStringGetLength(node); |
65 case Runtime::kInlineTwoByteSeqStringGetChar: | 69 case Runtime::kInlineTwoByteSeqStringGetChar: |
66 return ReduceSeqStringGetChar(node, String::TWO_BYTE_ENCODING); | 70 return ReduceSeqStringGetChar(node, String::TWO_BYTE_ENCODING); |
67 case Runtime::kInlineTwoByteSeqStringSetChar: | 71 case Runtime::kInlineTwoByteSeqStringSetChar: |
68 return ReduceSeqStringSetChar(node, String::TWO_BYTE_ENCODING); | 72 return ReduceSeqStringSetChar(node, String::TWO_BYTE_ENCODING); |
| 73 case Runtime::kInlineUnlikely: |
| 74 return ReduceUnLikely(node, BranchHint::kFalse); |
69 case Runtime::kInlineValueOf: | 75 case Runtime::kInlineValueOf: |
70 return ReduceValueOf(node); | 76 return ReduceValueOf(node); |
71 default: | 77 default: |
72 break; | 78 break; |
73 } | 79 } |
74 return NoChange(); | 80 return NoChange(); |
75 } | 81 } |
76 | 82 |
77 | 83 |
78 Reduction JSIntrinsicLowering::ReduceConstructDouble(Node* node) { | 84 Reduction JSIntrinsicLowering::ReduceConstructDouble(Node* node) { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 292 |
287 Reduction JSIntrinsicLowering::ReduceStringGetLength(Node* node) { | 293 Reduction JSIntrinsicLowering::ReduceStringGetLength(Node* node) { |
288 Node* value = NodeProperties::GetValueInput(node, 0); | 294 Node* value = NodeProperties::GetValueInput(node, 0); |
289 Node* effect = NodeProperties::GetEffectInput(node); | 295 Node* effect = NodeProperties::GetEffectInput(node); |
290 Node* control = NodeProperties::GetControlInput(node); | 296 Node* control = NodeProperties::GetControlInput(node); |
291 return Change(node, simplified()->LoadField(AccessBuilder::ForStringLength()), | 297 return Change(node, simplified()->LoadField(AccessBuilder::ForStringLength()), |
292 value, effect, control); | 298 value, effect, control); |
293 } | 299 } |
294 | 300 |
295 | 301 |
| 302 Reduction JSIntrinsicLowering::ReduceUnLikely(Node* node, BranchHint hint) { |
| 303 std::stack<Node*> nodes_to_visit; |
| 304 nodes_to_visit.push(node); |
| 305 while (!nodes_to_visit.empty()) { |
| 306 Node* current = nodes_to_visit.top(); |
| 307 nodes_to_visit.pop(); |
| 308 for (Node* use : current->uses()) { |
| 309 if (use->opcode() == IrOpcode::kJSToBoolean) { |
| 310 // We have to "look through" ToBoolean calls. |
| 311 nodes_to_visit.push(use); |
| 312 } else if (use->opcode() == IrOpcode::kBranch) { |
| 313 // Actually set the hint on any branch using the intrinsic node. |
| 314 use->set_op(common()->Branch(hint)); |
| 315 } |
| 316 } |
| 317 } |
| 318 // Apart from adding hints to branchs nodes, this is the identity function. |
| 319 Node* value = NodeProperties::GetValueInput(node, 0); |
| 320 NodeProperties::ReplaceWithValue(node, value); |
| 321 return Changed(value); |
| 322 } |
| 323 |
| 324 |
296 Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { | 325 Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { |
297 // if (%_IsSmi(value)) { | 326 // if (%_IsSmi(value)) { |
298 // return value; | 327 // return value; |
299 // } else if (%_GetInstanceType(%_GetMap(value)) == JS_VALUE_TYPE) { | 328 // } else if (%_GetInstanceType(%_GetMap(value)) == JS_VALUE_TYPE) { |
300 // return %_GetValue(value); | 329 // return %_GetValue(value); |
301 // } else { | 330 // } else { |
302 // return value; | 331 // return value; |
303 // } | 332 // } |
304 const Operator* const merge_op = common()->Merge(2); | 333 const Operator* const merge_op = common()->Merge(2); |
305 const Operator* const ephi_op = common()->EffectPhi(2); | 334 const Operator* const ephi_op = common()->EffectPhi(2); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 } | 423 } |
395 | 424 |
396 | 425 |
397 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { | 426 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { |
398 return jsgraph()->machine(); | 427 return jsgraph()->machine(); |
399 } | 428 } |
400 | 429 |
401 } // namespace compiler | 430 } // namespace compiler |
402 } // namespace internal | 431 } // namespace internal |
403 } // namespace v8 | 432 } // namespace v8 |
OLD | NEW |