| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/raw-machine-assembler.h" | 5 #include "src/compiler/raw-machine-assembler.h" |
| 6 | 6 |
| 7 #include "src/code-factory.h" | |
| 8 #include "src/compiler/node-properties.h" | 7 #include "src/compiler/node-properties.h" |
| 9 #include "src/compiler/pipeline.h" | 8 #include "src/compiler/pipeline.h" |
| 10 #include "src/compiler/scheduler.h" | 9 #include "src/compiler/scheduler.h" |
| 10 #include "src/objects-inl.h" |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 namespace compiler { | 14 namespace compiler { |
| 15 | 15 |
| 16 RawMachineAssembler::RawMachineAssembler( | 16 RawMachineAssembler::RawMachineAssembler( |
| 17 Isolate* isolate, Graph* graph, CallDescriptor* call_descriptor, | 17 Isolate* isolate, Graph* graph, CallDescriptor* call_descriptor, |
| 18 MachineRepresentation word, MachineOperatorBuilder::Flags flags, | 18 MachineRepresentation word, MachineOperatorBuilder::Flags flags, |
| 19 MachineOperatorBuilder::AlignmentRequirements alignment_requirements) | 19 MachineOperatorBuilder::AlignmentRequirements alignment_requirements) |
| 20 : isolate_(isolate), | 20 : isolate_(isolate), |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function, | 203 Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function, |
| 204 Node** args) { | 204 Node** args) { |
| 205 int param_count = static_cast<int>(desc->ParameterCount()); | 205 int param_count = static_cast<int>(desc->ParameterCount()); |
| 206 int input_count = param_count + 1; | 206 int input_count = param_count + 1; |
| 207 Node** buffer = zone()->NewArray<Node*>(input_count); | 207 Node** buffer = zone()->NewArray<Node*>(input_count); |
| 208 int index = 0; | 208 int index = 0; |
| 209 buffer[index++] = function; | 209 buffer[index++] = function; |
| 210 for (int i = 0; i < param_count; i++) { | 210 for (int i = 0; i < param_count; i++) { |
| 211 buffer[index++] = args[i]; | 211 buffer[index++] = args[i]; |
| 212 } | 212 } |
| 213 Node* tail_call = MakeNode(common()->TailCall(desc), input_count, buffer); | 213 return TailCallN(desc, input_count, buffer); |
| 214 } |
| 215 |
| 216 Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, int input_count, |
| 217 Node* const* inputs) { |
| 218 DCHECK_EQ(input_count, desc->ParameterCount() + 1); |
| 219 Node* tail_call = MakeNode(common()->TailCall(desc), input_count, inputs); |
| 214 schedule()->AddTailCall(CurrentBlock(), tail_call); | 220 schedule()->AddTailCall(CurrentBlock(), tail_call); |
| 215 current_block_ = nullptr; | 221 current_block_ = nullptr; |
| 216 return tail_call; | 222 return tail_call; |
| 217 } | |
| 218 | |
| 219 Node* RawMachineAssembler::TailCallRuntime0(Runtime::FunctionId function, | |
| 220 Node* context) { | |
| 221 const int kArity = 0; | |
| 222 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
| 223 zone(), function, kArity, Operator::kNoProperties, | |
| 224 CallDescriptor::kSupportsTailCalls); | |
| 225 int return_count = static_cast<int>(desc->ReturnCount()); | |
| 226 | |
| 227 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
| 228 Node* ref = AddNode( | |
| 229 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
| 230 Node* arity = Int32Constant(kArity); | |
| 231 | |
| 232 Node* nodes[] = {centry, ref, arity, context}; | |
| 233 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
| 234 | |
| 235 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
| 236 current_block_ = nullptr; | |
| 237 return tail_call; | |
| 238 } | |
| 239 | |
| 240 Node* RawMachineAssembler::TailCallRuntime1(Runtime::FunctionId function, | |
| 241 Node* arg1, Node* context) { | |
| 242 const int kArity = 1; | |
| 243 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
| 244 zone(), function, kArity, Operator::kNoProperties, | |
| 245 CallDescriptor::kSupportsTailCalls); | |
| 246 int return_count = static_cast<int>(desc->ReturnCount()); | |
| 247 | |
| 248 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
| 249 Node* ref = AddNode( | |
| 250 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
| 251 Node* arity = Int32Constant(kArity); | |
| 252 | |
| 253 Node* nodes[] = {centry, arg1, ref, arity, context}; | |
| 254 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
| 255 | |
| 256 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
| 257 current_block_ = nullptr; | |
| 258 return tail_call; | |
| 259 } | |
| 260 | |
| 261 | |
| 262 Node* RawMachineAssembler::TailCallRuntime2(Runtime::FunctionId function, | |
| 263 Node* arg1, Node* arg2, | |
| 264 Node* context) { | |
| 265 const int kArity = 2; | |
| 266 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
| 267 zone(), function, kArity, Operator::kNoProperties, | |
| 268 CallDescriptor::kSupportsTailCalls); | |
| 269 int return_count = static_cast<int>(desc->ReturnCount()); | |
| 270 | |
| 271 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
| 272 Node* ref = AddNode( | |
| 273 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
| 274 Node* arity = Int32Constant(kArity); | |
| 275 | |
| 276 Node* nodes[] = {centry, arg1, arg2, ref, arity, context}; | |
| 277 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
| 278 | |
| 279 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
| 280 current_block_ = nullptr; | |
| 281 return tail_call; | |
| 282 } | |
| 283 | |
| 284 Node* RawMachineAssembler::TailCallRuntime3(Runtime::FunctionId function, | |
| 285 Node* arg1, Node* arg2, Node* arg3, | |
| 286 Node* context) { | |
| 287 const int kArity = 3; | |
| 288 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
| 289 zone(), function, kArity, Operator::kNoProperties, | |
| 290 CallDescriptor::kSupportsTailCalls); | |
| 291 int return_count = static_cast<int>(desc->ReturnCount()); | |
| 292 | |
| 293 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
| 294 Node* ref = AddNode( | |
| 295 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
| 296 Node* arity = Int32Constant(kArity); | |
| 297 | |
| 298 Node* nodes[] = {centry, arg1, arg2, arg3, ref, arity, context}; | |
| 299 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
| 300 | |
| 301 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
| 302 current_block_ = nullptr; | |
| 303 return tail_call; | |
| 304 } | |
| 305 | |
| 306 Node* RawMachineAssembler::TailCallRuntime4(Runtime::FunctionId function, | |
| 307 Node* arg1, Node* arg2, Node* arg3, | |
| 308 Node* arg4, Node* context) { | |
| 309 const int kArity = 4; | |
| 310 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
| 311 zone(), function, kArity, Operator::kNoProperties, | |
| 312 CallDescriptor::kSupportsTailCalls); | |
| 313 int return_count = static_cast<int>(desc->ReturnCount()); | |
| 314 | |
| 315 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
| 316 Node* ref = AddNode( | |
| 317 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
| 318 Node* arity = Int32Constant(kArity); | |
| 319 | |
| 320 Node* nodes[] = {centry, arg1, arg2, arg3, arg4, ref, arity, context}; | |
| 321 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
| 322 | |
| 323 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
| 324 current_block_ = nullptr; | |
| 325 return tail_call; | |
| 326 } | |
| 327 | |
| 328 Node* RawMachineAssembler::TailCallRuntime5(Runtime::FunctionId function, | |
| 329 Node* arg1, Node* arg2, Node* arg3, | |
| 330 Node* arg4, Node* arg5, | |
| 331 Node* context) { | |
| 332 const int kArity = 5; | |
| 333 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
| 334 zone(), function, kArity, Operator::kNoProperties, | |
| 335 CallDescriptor::kSupportsTailCalls); | |
| 336 int return_count = static_cast<int>(desc->ReturnCount()); | |
| 337 | |
| 338 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
| 339 Node* ref = AddNode( | |
| 340 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
| 341 Node* arity = Int32Constant(kArity); | |
| 342 | |
| 343 Node* nodes[] = {centry, arg1, arg2, arg3, arg4, arg5, ref, arity, context}; | |
| 344 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
| 345 | |
| 346 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
| 347 current_block_ = nullptr; | |
| 348 return tail_call; | |
| 349 } | |
| 350 | |
| 351 Node* RawMachineAssembler::TailCallRuntime6(Runtime::FunctionId function, | |
| 352 Node* arg1, Node* arg2, Node* arg3, | |
| 353 Node* arg4, Node* arg5, Node* arg6, | |
| 354 Node* context) { | |
| 355 const int kArity = 6; | |
| 356 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
| 357 zone(), function, kArity, Operator::kNoProperties, | |
| 358 CallDescriptor::kSupportsTailCalls); | |
| 359 int return_count = static_cast<int>(desc->ReturnCount()); | |
| 360 | |
| 361 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); | |
| 362 Node* ref = AddNode( | |
| 363 common()->ExternalConstant(ExternalReference(function, isolate()))); | |
| 364 Node* arity = Int32Constant(kArity); | |
| 365 | |
| 366 Node* nodes[] = {centry, arg1, arg2, arg3, arg4, | |
| 367 arg5, arg6, ref, arity, context}; | |
| 368 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | |
| 369 | |
| 370 schedule()->AddTailCall(CurrentBlock(), tail_call); | |
| 371 current_block_ = nullptr; | |
| 372 return tail_call; | |
| 373 } | 223 } |
| 374 | 224 |
| 375 Node* RawMachineAssembler::CallCFunction0(MachineType return_type, | 225 Node* RawMachineAssembler::CallCFunction0(MachineType return_type, |
| 376 Node* function) { | 226 Node* function) { |
| 377 MachineSignature::Builder builder(zone(), 1, 0); | 227 MachineSignature::Builder builder(zone(), 1, 0); |
| 378 builder.AddReturn(return_type); | 228 builder.AddReturn(return_type); |
| 379 const CallDescriptor* descriptor = | 229 const CallDescriptor* descriptor = |
| 380 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); | 230 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); |
| 381 | 231 |
| 382 return AddNode(common()->Call(descriptor), function); | 232 return AddNode(common()->Call(descriptor), function); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 // The raw machine assembler nodes do not have effect and control inputs, | 340 // The raw machine assembler nodes do not have effect and control inputs, |
| 491 // so we disable checking input counts here. | 341 // so we disable checking input counts here. |
| 492 return graph()->NewNodeUnchecked(op, input_count, inputs); | 342 return graph()->NewNodeUnchecked(op, input_count, inputs); |
| 493 } | 343 } |
| 494 | 344 |
| 495 RawMachineLabel::~RawMachineLabel() { DCHECK(bound_ || !used_); } | 345 RawMachineLabel::~RawMachineLabel() { DCHECK(bound_ || !used_); } |
| 496 | 346 |
| 497 } // namespace compiler | 347 } // namespace compiler |
| 498 } // namespace internal | 348 } // namespace internal |
| 499 } // namespace v8 | 349 } // namespace v8 |
| OLD | NEW |