Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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/code-factory.h" |
| 6 | #include "src/code-stubs.h" |
| 7 | #include "src/compiler/common-operator.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/compiler/js-generic-lowering.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9 | #include "src/compiler/js-graph.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10 | #include "src/compiler/machine-operator.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 11 | #include "src/compiler/node-matchers.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 12 | #include "src/compiler/node-properties.h" |
| 13 | #include "src/compiler/operator-properties.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 14 | |
| 15 | namespace v8 { |
| 16 | namespace internal { |
| 17 | namespace compiler { |
| 18 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 19 | static CallDescriptor::Flags AdjustFrameStatesForCall(Node* node) { |
| 20 | int count = OperatorProperties::GetFrameStateInputCount(node->op()); |
| 21 | if (count > 1) { |
| 22 | int index = NodeProperties::FirstFrameStateIndex(node) + 1; |
| 23 | do { |
| 24 | node->RemoveInput(index); |
| 25 | } while (--count > 1); |
| 26 | } |
| 27 | return count > 0 ? CallDescriptor::kNeedsFrameState |
| 28 | : CallDescriptor::kNoFlags; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 32 | JSGenericLowering::JSGenericLowering(bool is_typing_enabled, JSGraph* jsgraph) |
| 33 | : is_typing_enabled_(is_typing_enabled), jsgraph_(jsgraph) {} |
| 34 | |
| 35 | |
| 36 | JSGenericLowering::~JSGenericLowering() {} |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 37 | |
| 38 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 39 | Reduction JSGenericLowering::Reduce(Node* node) { |
| 40 | switch (node->opcode()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 41 | #define DECLARE_CASE(x) \ |
| 42 | case IrOpcode::k##x: \ |
| 43 | Lower##x(node); \ |
| 44 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 45 | JS_OP_LIST(DECLARE_CASE) |
| 46 | #undef DECLARE_CASE |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 47 | case IrOpcode::kBranch: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 48 | case IrOpcode::kDeoptimizeIf: |
| 49 | case IrOpcode::kDeoptimizeUnless: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 50 | // TODO(mstarzinger): If typing is enabled then simplified lowering will |
| 51 | // have inserted the correct ChangeBoolToBit, otherwise we need to perform |
| 52 | // poor-man's representation inference here and insert manual change. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 53 | if (!is_typing_enabled_) { |
| 54 | Node* condition = node->InputAt(0); |
| 55 | Node* test = graph()->NewNode(machine()->WordEqual(), condition, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 56 | jsgraph()->TrueConstant()); |
| 57 | node->ReplaceInput(0, test); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 58 | } |
| 59 | // Fall-through. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 60 | default: |
| 61 | // Nothing to see. |
| 62 | return NoChange(); |
| 63 | } |
| 64 | return Changed(node); |
| 65 | } |
| 66 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 67 | #define REPLACE_BINARY_OP_IC_CALL(Op, token) \ |
| 68 | void JSGenericLowering::Lower##Op(Node* node) { \ |
| 69 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); \ |
| 70 | ReplaceWithStubCall(node, CodeFactory::BinaryOpIC(isolate(), token), \ |
| 71 | CallDescriptor::kPatchableCallSiteWithNop | flags); \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 72 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 73 | REPLACE_BINARY_OP_IC_CALL(JSShiftLeft, Token::SHL) |
| 74 | REPLACE_BINARY_OP_IC_CALL(JSShiftRight, Token::SAR) |
| 75 | REPLACE_BINARY_OP_IC_CALL(JSShiftRightLogical, Token::SHR) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 76 | REPLACE_BINARY_OP_IC_CALL(JSMultiply, Token::MUL) |
| 77 | REPLACE_BINARY_OP_IC_CALL(JSDivide, Token::DIV) |
| 78 | REPLACE_BINARY_OP_IC_CALL(JSModulus, Token::MOD) |
| 79 | #undef REPLACE_BINARY_OP_IC_CALL |
| 80 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 81 | #define REPLACE_RUNTIME_CALL(op, fun) \ |
| 82 | void JSGenericLowering::Lower##op(Node* node) { \ |
| 83 | ReplaceWithRuntimeCall(node, fun); \ |
| 84 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 85 | REPLACE_RUNTIME_CALL(JSCreateWithContext, Runtime::kPushWithContext) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 86 | REPLACE_RUNTIME_CALL(JSCreateModuleContext, Runtime::kPushModuleContext) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 87 | REPLACE_RUNTIME_CALL(JSConvertReceiver, Runtime::kConvertReceiver) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 88 | #undef REPLACE_RUNTIME_CALL |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 89 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 90 | #define REPLACE_STUB_CALL(Name) \ |
| 91 | void JSGenericLowering::LowerJS##Name(Node* node) { \ |
| 92 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); \ |
| 93 | Callable callable = CodeFactory::Name(isolate()); \ |
| 94 | ReplaceWithStubCall(node, callable, flags); \ |
| 95 | } |
| 96 | REPLACE_STUB_CALL(Add) |
| 97 | REPLACE_STUB_CALL(Subtract) |
| 98 | REPLACE_STUB_CALL(BitwiseAnd) |
| 99 | REPLACE_STUB_CALL(BitwiseOr) |
| 100 | REPLACE_STUB_CALL(BitwiseXor) |
| 101 | REPLACE_STUB_CALL(LessThan) |
| 102 | REPLACE_STUB_CALL(LessThanOrEqual) |
| 103 | REPLACE_STUB_CALL(GreaterThan) |
| 104 | REPLACE_STUB_CALL(GreaterThanOrEqual) |
| 105 | REPLACE_STUB_CALL(Equal) |
| 106 | REPLACE_STUB_CALL(NotEqual) |
| 107 | REPLACE_STUB_CALL(StrictEqual) |
| 108 | REPLACE_STUB_CALL(StrictNotEqual) |
| 109 | REPLACE_STUB_CALL(ToBoolean) |
| 110 | REPLACE_STUB_CALL(ToInteger) |
| 111 | REPLACE_STUB_CALL(ToLength) |
| 112 | REPLACE_STUB_CALL(ToNumber) |
| 113 | REPLACE_STUB_CALL(ToName) |
| 114 | REPLACE_STUB_CALL(ToObject) |
| 115 | REPLACE_STUB_CALL(ToString) |
| 116 | #undef REPLACE_STUB_CALL |
| 117 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 118 | void JSGenericLowering::ReplaceWithStubCall(Node* node, Callable callable, |
| 119 | CallDescriptor::Flags flags) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 120 | Operator::Properties properties = node->op()->properties(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 121 | CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| 122 | isolate(), zone(), callable.descriptor(), 0, flags, properties); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 123 | Node* stub_code = jsgraph()->HeapConstant(callable.code()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 124 | node->InsertInput(zone(), 0, stub_code); |
| 125 | NodeProperties::ChangeOp(node, common()->Call(desc)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | |
| 129 | void JSGenericLowering::ReplaceWithRuntimeCall(Node* node, |
| 130 | Runtime::FunctionId f, |
| 131 | int nargs_override) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 132 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 133 | Operator::Properties properties = node->op()->properties(); |
| 134 | const Runtime::Function* fun = Runtime::FunctionForId(f); |
| 135 | int nargs = (nargs_override < 0) ? fun->nargs : nargs_override; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 136 | CallDescriptor* desc = |
| 137 | Linkage::GetRuntimeCallDescriptor(zone(), f, nargs, properties, flags); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 138 | Node* ref = jsgraph()->ExternalConstant(ExternalReference(f, isolate())); |
| 139 | Node* arity = jsgraph()->Int32Constant(nargs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 140 | node->InsertInput(zone(), 0, jsgraph()->CEntryStubConstant(fun->result_size)); |
| 141 | node->InsertInput(zone(), nargs + 1, ref); |
| 142 | node->InsertInput(zone(), nargs + 2, arity); |
| 143 | NodeProperties::ChangeOp(node, common()->Call(desc)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 147 | void JSGenericLowering::LowerJSTypeOf(Node* node) { |
| 148 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 149 | Callable callable = CodeFactory::Typeof(isolate()); |
| 150 | ReplaceWithStubCall(node, callable, flags); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 154 | void JSGenericLowering::LowerJSLoadProperty(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 155 | Node* closure = NodeProperties::GetValueInput(node, 2); |
| 156 | Node* effect = NodeProperties::GetEffectInput(node); |
| 157 | Node* control = NodeProperties::GetControlInput(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 158 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 159 | const PropertyAccess& p = PropertyAccessOf(node->op()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 160 | Callable callable = |
| 161 | CodeFactory::KeyedLoadICInOptimizedCode(isolate(), UNINITIALIZED); |
| 162 | // Load the type feedback vector from the closure. |
| 163 | Node* shared_info = effect = graph()->NewNode( |
| 164 | machine()->Load(MachineType::AnyTagged()), closure, |
| 165 | jsgraph()->IntPtrConstant(JSFunction::kSharedFunctionInfoOffset - |
| 166 | kHeapObjectTag), |
| 167 | effect, control); |
| 168 | Node* vector = effect = graph()->NewNode( |
| 169 | machine()->Load(MachineType::AnyTagged()), shared_info, |
| 170 | jsgraph()->IntPtrConstant(SharedFunctionInfo::kFeedbackVectorOffset - |
| 171 | kHeapObjectTag), |
| 172 | effect, control); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 173 | node->InsertInput(zone(), 2, jsgraph()->SmiConstant(p.feedback().index())); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 174 | node->ReplaceInput(3, vector); |
| 175 | node->ReplaceInput(6, effect); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 176 | ReplaceWithStubCall(node, callable, flags); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | |
| 180 | void JSGenericLowering::LowerJSLoadNamed(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 181 | Node* closure = NodeProperties::GetValueInput(node, 1); |
| 182 | Node* effect = NodeProperties::GetEffectInput(node); |
| 183 | Node* control = NodeProperties::GetControlInput(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 184 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 185 | NamedAccess const& p = NamedAccessOf(node->op()); |
| 186 | Callable callable = CodeFactory::LoadICInOptimizedCode( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 187 | isolate(), NOT_INSIDE_TYPEOF, UNINITIALIZED); |
| 188 | // Load the type feedback vector from the closure. |
| 189 | Node* shared_info = effect = graph()->NewNode( |
| 190 | machine()->Load(MachineType::AnyTagged()), closure, |
| 191 | jsgraph()->IntPtrConstant(JSFunction::kSharedFunctionInfoOffset - |
| 192 | kHeapObjectTag), |
| 193 | effect, control); |
| 194 | Node* vector = effect = graph()->NewNode( |
| 195 | machine()->Load(MachineType::AnyTagged()), shared_info, |
| 196 | jsgraph()->IntPtrConstant(SharedFunctionInfo::kFeedbackVectorOffset - |
| 197 | kHeapObjectTag), |
| 198 | effect, control); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 199 | node->InsertInput(zone(), 1, jsgraph()->HeapConstant(p.name())); |
| 200 | node->InsertInput(zone(), 2, jsgraph()->SmiConstant(p.feedback().index())); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 201 | node->ReplaceInput(3, vector); |
| 202 | node->ReplaceInput(6, effect); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 203 | ReplaceWithStubCall(node, callable, flags); |
| 204 | } |
| 205 | |
| 206 | |
| 207 | void JSGenericLowering::LowerJSLoadGlobal(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 208 | Node* closure = NodeProperties::GetValueInput(node, 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 209 | Node* context = NodeProperties::GetContextInput(node); |
| 210 | Node* effect = NodeProperties::GetEffectInput(node); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 211 | Node* control = NodeProperties::GetControlInput(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 212 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 213 | const LoadGlobalParameters& p = LoadGlobalParametersOf(node->op()); |
| 214 | Callable callable = CodeFactory::LoadICInOptimizedCode( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 215 | isolate(), p.typeof_mode(), UNINITIALIZED); |
| 216 | // Load the type feedback vector from the closure. |
| 217 | Node* shared_info = effect = graph()->NewNode( |
| 218 | machine()->Load(MachineType::AnyTagged()), closure, |
| 219 | jsgraph()->IntPtrConstant(JSFunction::kSharedFunctionInfoOffset - |
| 220 | kHeapObjectTag), |
| 221 | effect, control); |
| 222 | Node* vector = effect = graph()->NewNode( |
| 223 | machine()->Load(MachineType::AnyTagged()), shared_info, |
| 224 | jsgraph()->IntPtrConstant(SharedFunctionInfo::kFeedbackVectorOffset - |
| 225 | kHeapObjectTag), |
| 226 | effect, control); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 227 | // Load global object from the context. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 228 | Node* native_context = effect = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 229 | graph()->NewNode(machine()->Load(MachineType::AnyTagged()), context, |
| 230 | jsgraph()->IntPtrConstant( |
| 231 | Context::SlotOffset(Context::NATIVE_CONTEXT_INDEX)), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 232 | effect, control); |
| 233 | Node* global = effect = graph()->NewNode( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 234 | machine()->Load(MachineType::AnyTagged()), native_context, |
| 235 | jsgraph()->IntPtrConstant(Context::SlotOffset(Context::EXTENSION_INDEX)), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 236 | effect, control); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 237 | node->InsertInput(zone(), 0, global); |
| 238 | node->InsertInput(zone(), 1, jsgraph()->HeapConstant(p.name())); |
| 239 | node->InsertInput(zone(), 2, jsgraph()->SmiConstant(p.feedback().index())); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 240 | node->ReplaceInput(3, vector); |
| 241 | node->ReplaceInput(6, effect); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 242 | ReplaceWithStubCall(node, callable, flags); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | |
| 246 | void JSGenericLowering::LowerJSStoreProperty(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 247 | Node* closure = NodeProperties::GetValueInput(node, 3); |
| 248 | Node* effect = NodeProperties::GetEffectInput(node); |
| 249 | Node* control = NodeProperties::GetControlInput(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 250 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 251 | PropertyAccess const& p = PropertyAccessOf(node->op()); |
| 252 | LanguageMode language_mode = p.language_mode(); |
| 253 | Callable callable = CodeFactory::KeyedStoreICInOptimizedCode( |
| 254 | isolate(), language_mode, UNINITIALIZED); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 255 | // Load the type feedback vector from the closure. |
| 256 | Node* shared_info = effect = graph()->NewNode( |
| 257 | machine()->Load(MachineType::AnyTagged()), closure, |
| 258 | jsgraph()->IntPtrConstant(JSFunction::kSharedFunctionInfoOffset - |
| 259 | kHeapObjectTag), |
| 260 | effect, control); |
| 261 | Node* vector = effect = graph()->NewNode( |
| 262 | machine()->Load(MachineType::AnyTagged()), shared_info, |
| 263 | jsgraph()->IntPtrConstant(SharedFunctionInfo::kFeedbackVectorOffset - |
| 264 | kHeapObjectTag), |
| 265 | effect, control); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 266 | node->InsertInput(zone(), 3, jsgraph()->SmiConstant(p.feedback().index())); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 267 | node->ReplaceInput(4, vector); |
| 268 | node->ReplaceInput(7, effect); |
| 269 | ReplaceWithStubCall(node, callable, flags); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | |
| 273 | void JSGenericLowering::LowerJSStoreNamed(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 274 | Node* closure = NodeProperties::GetValueInput(node, 2); |
| 275 | Node* effect = NodeProperties::GetEffectInput(node); |
| 276 | Node* control = NodeProperties::GetControlInput(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 277 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 278 | NamedAccess const& p = NamedAccessOf(node->op()); |
| 279 | Callable callable = CodeFactory::StoreICInOptimizedCode( |
| 280 | isolate(), p.language_mode(), UNINITIALIZED); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 281 | // Load the type feedback vector from the closure. |
| 282 | Node* shared_info = effect = graph()->NewNode( |
| 283 | machine()->Load(MachineType::AnyTagged()), closure, |
| 284 | jsgraph()->IntPtrConstant(JSFunction::kSharedFunctionInfoOffset - |
| 285 | kHeapObjectTag), |
| 286 | effect, control); |
| 287 | Node* vector = effect = graph()->NewNode( |
| 288 | machine()->Load(MachineType::AnyTagged()), shared_info, |
| 289 | jsgraph()->IntPtrConstant(SharedFunctionInfo::kFeedbackVectorOffset - |
| 290 | kHeapObjectTag), |
| 291 | effect, control); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 292 | node->InsertInput(zone(), 1, jsgraph()->HeapConstant(p.name())); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 293 | node->InsertInput(zone(), 3, jsgraph()->SmiConstant(p.feedback().index())); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 294 | node->ReplaceInput(4, vector); |
| 295 | node->ReplaceInput(7, effect); |
| 296 | ReplaceWithStubCall(node, callable, flags); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | |
| 300 | void JSGenericLowering::LowerJSStoreGlobal(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 301 | Node* closure = NodeProperties::GetValueInput(node, 1); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 302 | Node* context = NodeProperties::GetContextInput(node); |
| 303 | Node* effect = NodeProperties::GetEffectInput(node); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 304 | Node* control = NodeProperties::GetControlInput(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 305 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 306 | const StoreGlobalParameters& p = StoreGlobalParametersOf(node->op()); |
| 307 | Callable callable = CodeFactory::StoreICInOptimizedCode( |
| 308 | isolate(), p.language_mode(), UNINITIALIZED); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 309 | // Load the type feedback vector from the closure. |
| 310 | Node* shared_info = effect = graph()->NewNode( |
| 311 | machine()->Load(MachineType::AnyTagged()), closure, |
| 312 | jsgraph()->IntPtrConstant(JSFunction::kSharedFunctionInfoOffset - |
| 313 | kHeapObjectTag), |
| 314 | effect, control); |
| 315 | Node* vector = effect = graph()->NewNode( |
| 316 | machine()->Load(MachineType::AnyTagged()), shared_info, |
| 317 | jsgraph()->IntPtrConstant(SharedFunctionInfo::kFeedbackVectorOffset - |
| 318 | kHeapObjectTag), |
| 319 | effect, control); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 320 | // Load global object from the context. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 321 | Node* native_context = effect = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 322 | graph()->NewNode(machine()->Load(MachineType::AnyTagged()), context, |
| 323 | jsgraph()->IntPtrConstant( |
| 324 | Context::SlotOffset(Context::NATIVE_CONTEXT_INDEX)), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 325 | effect, control); |
| 326 | Node* global = effect = graph()->NewNode( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 327 | machine()->Load(MachineType::AnyTagged()), native_context, |
| 328 | jsgraph()->IntPtrConstant(Context::SlotOffset(Context::EXTENSION_INDEX)), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 329 | effect, control); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 330 | node->InsertInput(zone(), 0, global); |
| 331 | node->InsertInput(zone(), 1, jsgraph()->HeapConstant(p.name())); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 332 | node->InsertInput(zone(), 3, jsgraph()->SmiConstant(p.feedback().index())); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 333 | node->ReplaceInput(4, vector); |
| 334 | node->ReplaceInput(7, effect); |
| 335 | ReplaceWithStubCall(node, callable, flags); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | |
| 339 | void JSGenericLowering::LowerJSDeleteProperty(Node* node) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 340 | LanguageMode language_mode = OpParameter<LanguageMode>(node); |
| 341 | ReplaceWithRuntimeCall(node, is_strict(language_mode) |
| 342 | ? Runtime::kDeleteProperty_Strict |
| 343 | : Runtime::kDeleteProperty_Sloppy); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | |
| 347 | void JSGenericLowering::LowerJSHasProperty(Node* node) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 348 | ReplaceWithRuntimeCall(node, Runtime::kHasProperty); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | |
| 352 | void JSGenericLowering::LowerJSInstanceOf(Node* node) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 353 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 354 | Callable callable = CodeFactory::InstanceOf(isolate()); |
| 355 | ReplaceWithStubCall(node, callable, flags); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | |
| 359 | void JSGenericLowering::LowerJSLoadContext(Node* node) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 360 | const ContextAccess& access = ContextAccessOf(node->op()); |
| 361 | for (size_t i = 0; i < access.depth(); ++i) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 362 | node->ReplaceInput( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 363 | 0, graph()->NewNode(machine()->Load(MachineType::AnyTagged()), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 364 | NodeProperties::GetValueInput(node, 0), |
| 365 | jsgraph()->Int32Constant( |
| 366 | Context::SlotOffset(Context::PREVIOUS_INDEX)), |
| 367 | NodeProperties::GetEffectInput(node), |
| 368 | graph()->start())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 369 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 370 | node->ReplaceInput(1, jsgraph()->Int32Constant(Context::SlotOffset( |
| 371 | static_cast<int>(access.index())))); |
| 372 | node->AppendInput(zone(), graph()->start()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 373 | NodeProperties::ChangeOp(node, machine()->Load(MachineType::AnyTagged())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | |
| 377 | void JSGenericLowering::LowerJSStoreContext(Node* node) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 378 | const ContextAccess& access = ContextAccessOf(node->op()); |
| 379 | for (size_t i = 0; i < access.depth(); ++i) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 380 | node->ReplaceInput( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 381 | 0, graph()->NewNode(machine()->Load(MachineType::AnyTagged()), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 382 | NodeProperties::GetValueInput(node, 0), |
| 383 | jsgraph()->Int32Constant( |
| 384 | Context::SlotOffset(Context::PREVIOUS_INDEX)), |
| 385 | NodeProperties::GetEffectInput(node), |
| 386 | graph()->start())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 387 | } |
| 388 | node->ReplaceInput(2, NodeProperties::GetValueInput(node, 1)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 389 | node->ReplaceInput(1, jsgraph()->Int32Constant(Context::SlotOffset( |
| 390 | static_cast<int>(access.index())))); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 391 | NodeProperties::ChangeOp( |
| 392 | node, machine()->Store(StoreRepresentation(MachineRepresentation::kTagged, |
| 393 | kFullWriteBarrier))); |
| 394 | } |
| 395 | |
| 396 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 397 | void JSGenericLowering::LowerJSCreate(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 398 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 399 | Callable callable = CodeFactory::FastNewObject(isolate()); |
| 400 | ReplaceWithStubCall(node, callable, flags); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | |
| 404 | void JSGenericLowering::LowerJSCreateArguments(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 405 | CreateArgumentsType const type = CreateArgumentsTypeOf(node->op()); |
| 406 | switch (type) { |
| 407 | case CreateArgumentsType::kMappedArguments: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 408 | ReplaceWithRuntimeCall(node, Runtime::kNewSloppyArguments_Generic); |
| 409 | break; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 410 | case CreateArgumentsType::kUnmappedArguments: |
| 411 | ReplaceWithRuntimeCall(node, Runtime::kNewStrictArguments); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 412 | break; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 413 | case CreateArgumentsType::kRestParameter: |
| 414 | ReplaceWithRuntimeCall(node, Runtime::kNewRestParameter); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 415 | break; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | |
| 420 | void JSGenericLowering::LowerJSCreateArray(Node* node) { |
| 421 | CreateArrayParameters const& p = CreateArrayParametersOf(node->op()); |
| 422 | int const arity = static_cast<int>(p.arity()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 423 | Handle<AllocationSite> const site = p.site(); |
| 424 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 425 | // TODO(turbofan): We embed the AllocationSite from the Operator at this |
| 426 | // point, which we should not do once we want to both consume the feedback |
| 427 | // but at the same time shared the optimized code across native contexts, |
| 428 | // as the AllocationSite is associated with a single native context (it's |
| 429 | // stored in the type feedback vector after all). Once we go for cross |
| 430 | // context code generation, we should somehow find a way to get to the |
| 431 | // allocation site for the actual native context at runtime. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 432 | if (!site.is_null()) { |
| 433 | // Reduce {node} to the appropriate ArrayConstructorStub backend. |
| 434 | // Note that these stubs "behave" like JSFunctions, which means they |
| 435 | // expect a receiver on the stack, which they remove. We just push |
| 436 | // undefined for the receiver. |
| 437 | ElementsKind elements_kind = site->GetElementsKind(); |
| 438 | AllocationSiteOverrideMode override_mode = |
| 439 | (AllocationSite::GetMode(elements_kind) == TRACK_ALLOCATION_SITE) |
| 440 | ? DISABLE_ALLOCATION_SITES |
| 441 | : DONT_OVERRIDE; |
| 442 | if (arity == 0) { |
| 443 | ArrayNoArgumentConstructorStub stub(isolate(), elements_kind, |
| 444 | override_mode); |
| 445 | CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| 446 | isolate(), graph()->zone(), stub.GetCallInterfaceDescriptor(), 1, |
| 447 | CallDescriptor::kNeedsFrameState); |
| 448 | node->ReplaceInput(0, jsgraph()->HeapConstant(stub.GetCode())); |
| 449 | node->InsertInput(graph()->zone(), 2, jsgraph()->HeapConstant(site)); |
| 450 | node->InsertInput(graph()->zone(), 3, jsgraph()->UndefinedConstant()); |
| 451 | NodeProperties::ChangeOp(node, common()->Call(desc)); |
| 452 | } else if (arity == 1) { |
| 453 | // TODO(bmeurer): Optimize for the 0 length non-holey case? |
| 454 | ArraySingleArgumentConstructorStub stub( |
| 455 | isolate(), GetHoleyElementsKind(elements_kind), override_mode); |
| 456 | CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| 457 | isolate(), graph()->zone(), stub.GetCallInterfaceDescriptor(), 2, |
| 458 | CallDescriptor::kNeedsFrameState); |
| 459 | node->ReplaceInput(0, jsgraph()->HeapConstant(stub.GetCode())); |
| 460 | node->InsertInput(graph()->zone(), 2, jsgraph()->HeapConstant(site)); |
| 461 | node->InsertInput(graph()->zone(), 3, jsgraph()->Int32Constant(1)); |
| 462 | node->InsertInput(graph()->zone(), 4, jsgraph()->UndefinedConstant()); |
| 463 | NodeProperties::ChangeOp(node, common()->Call(desc)); |
| 464 | } else { |
| 465 | ArrayNArgumentsConstructorStub stub(isolate(), elements_kind, |
| 466 | override_mode); |
| 467 | CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| 468 | isolate(), graph()->zone(), stub.GetCallInterfaceDescriptor(), |
| 469 | arity + 1, CallDescriptor::kNeedsFrameState); |
| 470 | node->ReplaceInput(0, jsgraph()->HeapConstant(stub.GetCode())); |
| 471 | node->InsertInput(graph()->zone(), 2, jsgraph()->HeapConstant(site)); |
| 472 | node->InsertInput(graph()->zone(), 3, jsgraph()->Int32Constant(arity)); |
| 473 | node->InsertInput(graph()->zone(), 4, jsgraph()->UndefinedConstant()); |
| 474 | NodeProperties::ChangeOp(node, common()->Call(desc)); |
| 475 | } |
| 476 | } else { |
| 477 | Node* new_target = node->InputAt(1); |
| 478 | Node* type_info = site.is_null() ? jsgraph()->UndefinedConstant() |
| 479 | : jsgraph()->HeapConstant(site); |
| 480 | node->RemoveInput(1); |
| 481 | node->InsertInput(zone(), 1 + arity, new_target); |
| 482 | node->InsertInput(zone(), 2 + arity, type_info); |
| 483 | ReplaceWithRuntimeCall(node, Runtime::kNewArray, arity + 3); |
| 484 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | |
| 488 | void JSGenericLowering::LowerJSCreateClosure(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 489 | CreateClosureParameters const& p = CreateClosureParametersOf(node->op()); |
| 490 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 491 | Handle<SharedFunctionInfo> const shared_info = p.shared_info(); |
| 492 | node->InsertInput(zone(), 0, jsgraph()->HeapConstant(shared_info)); |
| 493 | |
| 494 | // Use the FastNewClosureStub that allocates in new space only for nested |
| 495 | // functions that don't need literals cloning. |
| 496 | if (p.pretenure() == NOT_TENURED && shared_info->num_literals() == 0) { |
| 497 | Callable callable = CodeFactory::FastNewClosure( |
| 498 | isolate(), shared_info->language_mode(), shared_info->kind()); |
| 499 | ReplaceWithStubCall(node, callable, flags); |
| 500 | } else { |
| 501 | ReplaceWithRuntimeCall(node, (p.pretenure() == TENURED) |
| 502 | ? Runtime::kNewClosure_Tenured |
| 503 | : Runtime::kNewClosure); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | |
| 508 | void JSGenericLowering::LowerJSCreateFunctionContext(Node* node) { |
| 509 | int const slot_count = OpParameter<int>(node->op()); |
| 510 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 511 | |
| 512 | // Use the FastNewContextStub only for function contexts up maximum size. |
| 513 | if (slot_count <= FastNewContextStub::kMaximumSlots) { |
| 514 | Callable callable = CodeFactory::FastNewContext(isolate(), slot_count); |
| 515 | ReplaceWithStubCall(node, callable, flags); |
| 516 | } else { |
| 517 | ReplaceWithRuntimeCall(node, Runtime::kNewFunctionContext); |
| 518 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | |
| 522 | void JSGenericLowering::LowerJSCreateIterResultObject(Node* node) { |
| 523 | ReplaceWithRuntimeCall(node, Runtime::kCreateIterResultObject); |
| 524 | } |
| 525 | |
| 526 | |
| 527 | void JSGenericLowering::LowerJSCreateLiteralArray(Node* node) { |
| 528 | CreateLiteralParameters const& p = CreateLiteralParametersOf(node->op()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 529 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 530 | node->InsertInput(zone(), 1, jsgraph()->SmiConstant(p.index())); |
| 531 | node->InsertInput(zone(), 2, jsgraph()->HeapConstant(p.constant())); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 532 | |
| 533 | // Use the FastCloneShallowArrayStub only for shallow boilerplates up to the |
| 534 | // initial length limit for arrays with "fast" elements kind. |
| 535 | if ((p.flags() & ArrayLiteral::kShallowElements) != 0 && |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 536 | p.length() < JSArray::kInitialMaxFastElementArray) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 537 | Callable callable = CodeFactory::FastCloneShallowArray(isolate()); |
| 538 | ReplaceWithStubCall(node, callable, flags); |
| 539 | } else { |
| 540 | node->InsertInput(zone(), 3, jsgraph()->SmiConstant(p.flags())); |
| 541 | ReplaceWithRuntimeCall(node, Runtime::kCreateArrayLiteral); |
| 542 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | |
| 546 | void JSGenericLowering::LowerJSCreateLiteralObject(Node* node) { |
| 547 | CreateLiteralParameters const& p = CreateLiteralParametersOf(node->op()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 548 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 549 | node->InsertInput(zone(), 1, jsgraph()->SmiConstant(p.index())); |
| 550 | node->InsertInput(zone(), 2, jsgraph()->HeapConstant(p.constant())); |
| 551 | node->InsertInput(zone(), 3, jsgraph()->SmiConstant(p.flags())); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 552 | |
| 553 | // Use the FastCloneShallowObjectStub only for shallow boilerplates without |
| 554 | // elements up to the number of properties that the stubs can handle. |
| 555 | if ((p.flags() & ObjectLiteral::kShallowProperties) != 0 && |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 556 | p.length() <= FastCloneShallowObjectStub::kMaximumClonedProperties) { |
| 557 | Callable callable = |
| 558 | CodeFactory::FastCloneShallowObject(isolate(), p.length()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 559 | ReplaceWithStubCall(node, callable, flags); |
| 560 | } else { |
| 561 | ReplaceWithRuntimeCall(node, Runtime::kCreateObjectLiteral); |
| 562 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | |
| 566 | void JSGenericLowering::LowerJSCreateLiteralRegExp(Node* node) { |
| 567 | CreateLiteralParameters const& p = CreateLiteralParametersOf(node->op()); |
| 568 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 569 | Callable callable = CodeFactory::FastCloneRegExp(isolate()); |
| 570 | Node* literal_index = jsgraph()->SmiConstant(p.index()); |
| 571 | Node* literal_flags = jsgraph()->SmiConstant(p.flags()); |
| 572 | Node* pattern = jsgraph()->HeapConstant(p.constant()); |
| 573 | node->InsertInput(graph()->zone(), 1, literal_index); |
| 574 | node->InsertInput(graph()->zone(), 2, pattern); |
| 575 | node->InsertInput(graph()->zone(), 3, literal_flags); |
| 576 | ReplaceWithStubCall(node, callable, flags); |
| 577 | } |
| 578 | |
| 579 | |
| 580 | void JSGenericLowering::LowerJSCreateCatchContext(Node* node) { |
| 581 | Handle<String> name = OpParameter<Handle<String>>(node); |
| 582 | node->InsertInput(zone(), 0, jsgraph()->HeapConstant(name)); |
| 583 | ReplaceWithRuntimeCall(node, Runtime::kPushCatchContext); |
| 584 | } |
| 585 | |
| 586 | |
| 587 | void JSGenericLowering::LowerJSCreateBlockContext(Node* node) { |
| 588 | Handle<ScopeInfo> scope_info = OpParameter<Handle<ScopeInfo>>(node); |
| 589 | node->InsertInput(zone(), 0, jsgraph()->HeapConstant(scope_info)); |
| 590 | ReplaceWithRuntimeCall(node, Runtime::kPushBlockContext); |
| 591 | } |
| 592 | |
| 593 | |
| 594 | void JSGenericLowering::LowerJSCreateScriptContext(Node* node) { |
| 595 | Handle<ScopeInfo> scope_info = OpParameter<Handle<ScopeInfo>>(node); |
| 596 | node->InsertInput(zone(), 1, jsgraph()->HeapConstant(scope_info)); |
| 597 | ReplaceWithRuntimeCall(node, Runtime::kNewScriptContext); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | |
| 601 | void JSGenericLowering::LowerJSCallConstruct(Node* node) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 602 | CallConstructParameters const& p = CallConstructParametersOf(node->op()); |
| 603 | int const arg_count = static_cast<int>(p.arity() - 2); |
| 604 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 605 | Callable callable = CodeFactory::Construct(isolate()); |
| 606 | CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| 607 | isolate(), zone(), callable.descriptor(), arg_count + 1, flags); |
| 608 | Node* stub_code = jsgraph()->HeapConstant(callable.code()); |
| 609 | Node* stub_arity = jsgraph()->Int32Constant(arg_count); |
| 610 | Node* new_target = node->InputAt(arg_count + 1); |
| 611 | Node* receiver = jsgraph()->UndefinedConstant(); |
| 612 | node->RemoveInput(arg_count + 1); // Drop new target. |
| 613 | node->InsertInput(zone(), 0, stub_code); |
| 614 | node->InsertInput(zone(), 2, new_target); |
| 615 | node->InsertInput(zone(), 3, stub_arity); |
| 616 | node->InsertInput(zone(), 4, receiver); |
| 617 | NodeProperties::ChangeOp(node, common()->Call(desc)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 621 | void JSGenericLowering::LowerJSCallFunction(Node* node) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 622 | CallFunctionParameters const& p = CallFunctionParametersOf(node->op()); |
| 623 | int const arg_count = static_cast<int>(p.arity() - 2); |
| 624 | ConvertReceiverMode const mode = p.convert_mode(); |
| 625 | Callable callable = CodeFactory::Call(isolate(), mode); |
| 626 | CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 627 | if (p.tail_call_mode() == TailCallMode::kAllow) { |
| 628 | flags |= CallDescriptor::kSupportsTailCalls; |
| 629 | } |
| 630 | CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| 631 | isolate(), zone(), callable.descriptor(), arg_count + 1, flags); |
| 632 | Node* stub_code = jsgraph()->HeapConstant(callable.code()); |
| 633 | Node* stub_arity = jsgraph()->Int32Constant(arg_count); |
| 634 | node->InsertInput(zone(), 0, stub_code); |
| 635 | node->InsertInput(zone(), 2, stub_arity); |
| 636 | NodeProperties::ChangeOp(node, common()->Call(desc)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | |
| 640 | void JSGenericLowering::LowerJSCallRuntime(Node* node) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 641 | const CallRuntimeParameters& p = CallRuntimeParametersOf(node->op()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 642 | AdjustFrameStatesForCall(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 643 | ReplaceWithRuntimeCall(node, p.id(), static_cast<int>(p.arity())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 644 | } |
| 645 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 646 | |
| 647 | void JSGenericLowering::LowerJSForInDone(Node* node) { |
| 648 | ReplaceWithRuntimeCall(node, Runtime::kForInDone); |
| 649 | } |
| 650 | |
| 651 | |
| 652 | void JSGenericLowering::LowerJSForInNext(Node* node) { |
| 653 | ReplaceWithRuntimeCall(node, Runtime::kForInNext); |
| 654 | } |
| 655 | |
| 656 | |
| 657 | void JSGenericLowering::LowerJSForInPrepare(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 658 | ReplaceWithRuntimeCall(node, Runtime::kForInPrepare); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | |
| 662 | void JSGenericLowering::LowerJSForInStep(Node* node) { |
| 663 | ReplaceWithRuntimeCall(node, Runtime::kForInStep); |
| 664 | } |
| 665 | |
| 666 | |
| 667 | void JSGenericLowering::LowerJSLoadMessage(Node* node) { |
| 668 | ExternalReference message_address = |
| 669 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 670 | node->RemoveInput(NodeProperties::FirstContextIndex(node)); |
| 671 | node->InsertInput(zone(), 0, jsgraph()->ExternalConstant(message_address)); |
| 672 | node->InsertInput(zone(), 1, jsgraph()->IntPtrConstant(0)); |
| 673 | NodeProperties::ChangeOp(node, machine()->Load(MachineType::AnyTagged())); |
| 674 | } |
| 675 | |
| 676 | |
| 677 | void JSGenericLowering::LowerJSStoreMessage(Node* node) { |
| 678 | ExternalReference message_address = |
| 679 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 680 | node->RemoveInput(NodeProperties::FirstContextIndex(node)); |
| 681 | node->InsertInput(zone(), 0, jsgraph()->ExternalConstant(message_address)); |
| 682 | node->InsertInput(zone(), 1, jsgraph()->IntPtrConstant(0)); |
| 683 | StoreRepresentation representation(MachineRepresentation::kTagged, |
| 684 | kNoWriteBarrier); |
| 685 | NodeProperties::ChangeOp(node, machine()->Store(representation)); |
| 686 | } |
| 687 | |
| 688 | |
| 689 | void JSGenericLowering::LowerJSYield(Node* node) { UNIMPLEMENTED(); } |
| 690 | |
| 691 | |
| 692 | void JSGenericLowering::LowerJSStackCheck(Node* node) { |
| 693 | Node* effect = NodeProperties::GetEffectInput(node); |
| 694 | Node* control = NodeProperties::GetControlInput(node); |
| 695 | |
| 696 | Node* limit = graph()->NewNode( |
| 697 | machine()->Load(MachineType::Pointer()), |
| 698 | jsgraph()->ExternalConstant( |
| 699 | ExternalReference::address_of_stack_limit(isolate())), |
| 700 | jsgraph()->IntPtrConstant(0), effect, control); |
| 701 | Node* pointer = graph()->NewNode(machine()->LoadStackPointer()); |
| 702 | |
| 703 | Node* check = graph()->NewNode(machine()->UintLessThan(), limit, pointer); |
| 704 | Node* branch = |
| 705 | graph()->NewNode(common()->Branch(BranchHint::kTrue), check, control); |
| 706 | |
| 707 | Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 708 | Node* etrue = effect; |
| 709 | |
| 710 | Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 711 | NodeProperties::ReplaceControlInput(node, if_false); |
| 712 | Node* efalse = node; |
| 713 | |
| 714 | Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 715 | Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge); |
| 716 | |
| 717 | // Wire the new diamond into the graph, {node} can still throw. |
| 718 | NodeProperties::ReplaceUses(node, node, ephi, node, node); |
| 719 | NodeProperties::ReplaceEffectInput(ephi, efalse, 1); |
| 720 | |
| 721 | // TODO(mstarzinger): This iteration cuts out the IfSuccess projection from |
| 722 | // the node and places it inside the diamond. Come up with a helper method! |
| 723 | for (Node* use : node->uses()) { |
| 724 | if (use->opcode() == IrOpcode::kIfSuccess) { |
| 725 | use->ReplaceUses(merge); |
| 726 | merge->ReplaceInput(1, use); |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | // Turn the stack check into a runtime call. |
| 731 | ReplaceWithRuntimeCall(node, Runtime::kStackGuard); |
| 732 | } |
| 733 | |
| 734 | |
| 735 | Zone* JSGenericLowering::zone() const { return graph()->zone(); } |
| 736 | |
| 737 | |
| 738 | Isolate* JSGenericLowering::isolate() const { return jsgraph()->isolate(); } |
| 739 | |
| 740 | |
| 741 | Graph* JSGenericLowering::graph() const { return jsgraph()->graph(); } |
| 742 | |
| 743 | |
| 744 | CommonOperatorBuilder* JSGenericLowering::common() const { |
| 745 | return jsgraph()->common(); |
| 746 | } |
| 747 | |
| 748 | |
| 749 | MachineOperatorBuilder* JSGenericLowering::machine() const { |
| 750 | return jsgraph()->machine(); |
| 751 | } |
| 752 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 753 | } // namespace compiler |
| 754 | } // namespace internal |
| 755 | } // namespace v8 |