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 ResultAndEffect JSIntrinsicBuilder::BuildGraphFor(Runtime::FunctionId id, |
| 18 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 ResultAndEffect(); |
| 36 } |
| 37 |
| 38 ResultAndEffect 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 ResultAndEffect(condition, arguments[2]); |
| 45 } |
| 46 |
| 47 |
| 48 ResultAndEffect 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 ResultAndEffect(condition, arguments[2]); |
| 55 } |
| 56 |
| 57 |
| 58 /* |
| 59 * if (_isSmi(object)) { |
| 60 * return false |
| 61 * } else { |
| 62 * return %_GetMapInstanceType(object) == map_type |
| 63 * } |
| 64 */ |
| 65 ResultAndEffect JSIntrinsicBuilder::BuildMapCheck(Node* object, Node* effect, |
| 66 InstanceType map_type) { |
| 67 SimplifiedOperatorBuilder simplified(jsgraph_->zone()); |
| 68 |
| 69 Node* is_smi = graph()->NewNode(simplified.IsSmi(), object); |
| 70 Node* branch = graph()->NewNode(common()->Branch(), is_smi, graph()->start()); |
| 71 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 72 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 73 |
| 74 Node* map = graph()->NewNode(simplified.LoadField(AccessBuilder::ForMap()), |
| 75 object, effect, if_false); |
| 76 |
| 77 Node* instance_type = graph()->NewNode( |
| 78 simplified.LoadField(AccessBuilder::ForMapInstanceType()), map, map, |
| 79 if_false); |
| 80 |
| 81 Node* has_map_type = |
| 82 graph()->NewNode(jsgraph_->machine()->Word32Equal(), instance_type, |
| 83 jsgraph_->Int32Constant(map_type)); |
| 84 |
| 85 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 86 |
| 87 Node* phi = |
| 88 graph()->NewNode(common()->Phi((MachineType)(kTypeBool | kRepTagged), 2), |
| 89 jsgraph_->FalseConstant(), has_map_type, merge); |
| 90 |
| 91 Node* ephi = |
| 92 graph()->NewNode(common()->EffectPhi(2), effect, instance_type, merge); |
| 93 |
| 94 return ResultAndEffect(phi, ephi); |
| 95 } |
| 96 |
| 97 |
| 98 /* |
| 99 * if (%_isSmi(object)) { |
| 100 * return object; |
| 101 * } else if (%_GetMapInstanceType(object) == JS_VALUE_TYPE) { |
| 102 * return %_LoadValueField(object); |
| 103 * } else { |
| 104 * return object; |
| 105 * } |
| 106 */ |
| 107 ResultAndEffect JSIntrinsicBuilder::BuildGraphFor_ValueOf( |
| 108 const NodeVector& arguments) { |
| 109 Node* object = arguments[0]; |
| 110 Node* effect = arguments[2]; |
| 111 SimplifiedOperatorBuilder simplified(jsgraph_->zone()); |
| 112 |
| 113 Node* is_smi = graph()->NewNode(simplified.IsSmi(), object); |
| 114 Node* branch = graph()->NewNode(common()->Branch(), is_smi, graph()->start()); |
| 115 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 116 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 117 |
| 118 Node* map = graph()->NewNode(simplified.LoadField(AccessBuilder::ForMap()), |
| 119 object, effect, if_false); |
| 120 |
| 121 Node* instance_type = graph()->NewNode( |
| 122 simplified.LoadField(AccessBuilder::ForMapInstanceType()), map, map, |
| 123 if_false); |
| 124 |
| 125 Node* is_value = |
| 126 graph()->NewNode(jsgraph_->machine()->Word32Equal(), instance_type, |
| 127 jsgraph_->Constant(JS_VALUE_TYPE)); |
| 128 |
| 129 Node* branch_is_value = |
| 130 graph()->NewNode(common()->Branch(), is_value, if_false); |
| 131 Node* is_value_true = graph()->NewNode(common()->IfTrue(), branch_is_value); |
| 132 Node* is_value_false = graph()->NewNode(common()->IfFalse(), branch_is_value); |
| 133 |
| 134 Node* value = |
| 135 graph()->NewNode(simplified.LoadField(AccessBuilder::ForValue()), object, |
| 136 instance_type, is_value_true); |
| 137 |
| 138 Node* merge_is_value = |
| 139 graph()->NewNode(common()->Merge(2), is_value_true, is_value_false); |
| 140 |
| 141 Node* phi_is_value = graph()->NewNode(common()->Phi((MachineType)kTypeAny, 2), |
| 142 value, object, merge_is_value); |
| 143 |
| 144 |
| 145 Node* merge = graph()->NewNode(common()->Merge(2), if_true, merge_is_value); |
| 146 |
| 147 Node* phi = graph()->NewNode(common()->Phi((MachineType)kTypeAny, 2), object, |
| 148 phi_is_value, merge); |
| 149 |
| 150 Node* ephi = |
| 151 graph()->NewNode(common()->EffectPhi(2), effect, instance_type, merge); |
| 152 |
| 153 return ResultAndEffect(phi, ephi); |
| 154 } |
| 155 } |
| 156 } |
| 157 } // namespace v8::internal::compiler |
OLD | NEW |