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