OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/compiler/access-builder.h" |
| 6 #include "src/compiler/common-operator.h" |
| 7 #include "src/compiler/generic-node-inl.h" |
| 8 #include "src/compiler/js-intrinsic-builder.h" |
| 9 #include "src/compiler/js-operator.h" |
| 10 #include "src/compiler/simplified-operator.h" |
| 11 |
| 12 |
| 13 namespace v8 { |
| 14 namespace internal { |
| 15 namespace compiler { |
| 16 |
| 17 std::pair<Node*, Node*> JSIntrinsicBuilder::BuildGraphFor( |
| 18 Runtime::FunctionId id, const NodeVector& arguments) { |
| 19 switch (id) { |
| 20 case Runtime::kInlineIsSmi: |
| 21 return BuildGraphFor_IsSmi(arguments); |
| 22 case Runtime::kInlineIsNonNegativeSmi: |
| 23 return BuildGraphFor_IsNonNegativeSmi(arguments); |
| 24 case Runtime::kInlineIsArray: |
| 25 return BuildMapCheck(arguments[0], arguments[2], JS_ARRAY_TYPE); |
| 26 case Runtime::kInlineIsRegExp: |
| 27 return BuildMapCheck(arguments[0], arguments[2], JS_REGEXP_TYPE); |
| 28 case Runtime::kInlineIsFunction: |
| 29 return BuildMapCheck(arguments[0], arguments[2], JS_FUNCTION_TYPE); |
| 30 case Runtime::kInlineValueOf: |
| 31 return BuildGraphFor_ValueOf(arguments); |
| 32 default: |
| 33 break; |
| 34 } |
| 35 return std::pair<Node*, Node*>(); |
| 36 } |
| 37 |
| 38 std::pair<Node*, Node*> JSIntrinsicBuilder::BuildGraphFor_IsSmi( |
| 39 const NodeVector& arguments) { |
| 40 Node* object = arguments[0]; |
| 41 SimplifiedOperatorBuilder simplified(jsgraph_->zone()); |
| 42 Node* condition = graph()->NewNode(simplified.IsSmi(), object); |
| 43 |
| 44 return std::pair<Node*, Node*>(condition, arguments[2]); |
| 45 } |
| 46 |
| 47 |
| 48 std::pair<Node*, Node*> JSIntrinsicBuilder::BuildGraphFor_IsNonNegativeSmi( |
| 49 const NodeVector& arguments) { |
| 50 Node* object = arguments[0]; |
| 51 SimplifiedOperatorBuilder simplified(jsgraph_->zone()); |
| 52 Node* condition = graph()->NewNode(simplified.IsNonNegativeSmi(), object); |
| 53 |
| 54 return std::pair<Node*, Node*>(condition, arguments[2]); |
| 55 } |
| 56 |
| 57 |
| 58 std::pair<Node*, Node*> JSIntrinsicBuilder::BuildMapCheck( |
| 59 Node* object, Node* effect, InstanceType map_type) { |
| 60 SimplifiedOperatorBuilder simplified(jsgraph_->zone()); |
| 61 |
| 62 Node* is_smi = graph()->NewNode(simplified.IsSmi(), object); |
| 63 Node* branch = graph()->NewNode(common()->Branch(), is_smi, graph()->start()); |
| 64 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 65 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 66 |
| 67 Node* map = graph()->NewNode(simplified.LoadField(AccessBuilder::ForMap()), |
| 68 object, effect, if_false); |
| 69 |
| 70 Node* instance_type = graph()->NewNode( |
| 71 simplified.LoadField(AccessBuilder::ForMapInstanceType()), map, map, |
| 72 if_false); |
| 73 |
| 74 Node* has_map_type = |
| 75 graph()->NewNode(jsgraph_->machine()->Word32Equal(), instance_type, |
| 76 jsgraph_->Int32Constant(map_type)); |
| 77 |
| 78 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 79 |
| 80 Node* phi = |
| 81 graph()->NewNode(common()->Phi((MachineType)(kTypeBool | kRepTagged), 2), |
| 82 jsgraph_->FalseConstant(), has_map_type, merge); |
| 83 |
| 84 Node* ephi = |
| 85 graph()->NewNode(common()->EffectPhi(2), effect, instance_type, merge); |
| 86 |
| 87 return std::pair<Node*, Node*>(phi, ephi); |
| 88 } |
| 89 |
| 90 |
| 91 std::pair<Node*, Node*> JSIntrinsicBuilder::BuildGraphFor_ValueOf( |
| 92 const NodeVector& arguments) { |
| 93 Node* object = arguments[0]; |
| 94 Node* effect = arguments[2]; |
| 95 SimplifiedOperatorBuilder simplified(jsgraph_->zone()); |
| 96 |
| 97 Node* is_smi = graph()->NewNode(simplified.IsSmi(), object); |
| 98 Node* branch = graph()->NewNode(common()->Branch(), is_smi, graph()->start()); |
| 99 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 100 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 101 |
| 102 Node* map = graph()->NewNode(simplified.LoadField(AccessBuilder::ForMap()), |
| 103 object, effect, if_false); |
| 104 |
| 105 Node* instance_type = graph()->NewNode( |
| 106 simplified.LoadField(AccessBuilder::ForMapInstanceType()), map, map, |
| 107 if_false); |
| 108 |
| 109 Node* is_value = |
| 110 graph()->NewNode(jsgraph_->machine()->Word32Equal(), instance_type, |
| 111 jsgraph_->Constant(JS_VALUE_TYPE)); |
| 112 |
| 113 Node* branch_is_value = |
| 114 graph()->NewNode(common()->Branch(), is_value, if_false); |
| 115 Node* is_value_true = graph()->NewNode(common()->IfTrue(), branch_is_value); |
| 116 Node* is_value_false = graph()->NewNode(common()->IfFalse(), branch_is_value); |
| 117 |
| 118 Node* value = |
| 119 graph()->NewNode(simplified.LoadField(AccessBuilder::ForValue()), object, |
| 120 instance_type, is_value_true); |
| 121 |
| 122 Node* merge_is_value = |
| 123 graph()->NewNode(common()->Merge(2), is_value_true, is_value_false); |
| 124 |
| 125 Node* phi_is_value = graph()->NewNode(common()->Phi((MachineType)kTypeAny, 2), |
| 126 value, object, merge_is_value); |
| 127 |
| 128 |
| 129 Node* merge = graph()->NewNode(common()->Merge(2), if_true, merge_is_value); |
| 130 |
| 131 Node* phi = graph()->NewNode(common()->Phi((MachineType)kTypeAny, 2), object, |
| 132 phi_is_value, merge); |
| 133 |
| 134 Node* ephi = |
| 135 graph()->NewNode(common()->EffectPhi(2), effect, instance_type, merge); |
| 136 |
| 137 return std::pair<Node*, Node*>(phi, ephi); |
| 138 } |
| 139 } |
| 140 } |
| 141 } // namespace v8::internal::compiler |
OLD | NEW |