OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/interpreter-assembler.h" | 5 #include "src/compiler/interpreter-assembler.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/compiler/graph.h" | 10 #include "src/compiler/graph.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 kMachAnyTagged, RegisterFileRawPointer(), | 307 kMachAnyTagged, RegisterFileRawPointer(), |
308 IntPtrConstant(InterpreterFrameConstants::kFunctionFromRegisterPointer)); | 308 IntPtrConstant(InterpreterFrameConstants::kFunctionFromRegisterPointer)); |
309 Node* shared_info = | 309 Node* shared_info = |
310 LoadObjectField(function, JSFunction::kSharedFunctionInfoOffset); | 310 LoadObjectField(function, JSFunction::kSharedFunctionInfoOffset); |
311 Node* vector = | 311 Node* vector = |
312 LoadObjectField(shared_info, SharedFunctionInfo::kFeedbackVectorOffset); | 312 LoadObjectField(shared_info, SharedFunctionInfo::kFeedbackVectorOffset); |
313 return vector; | 313 return vector; |
314 } | 314 } |
315 | 315 |
316 | 316 |
317 Node* InterpreterAssembler::CallN(CallDescriptor* descriptor, | |
318 Node* code_target, | |
319 Node** args) { | |
320 Node* stack_pointer_before_call = nullptr; | |
321 if (FLAG_debug_code) { | |
322 stack_pointer_before_call = raw_assembler_->LoadStackPointer(); | |
323 } | |
324 Node* return_val = raw_assembler_->CallN(descriptor, code_target, args); | |
325 if (FLAG_debug_code) { | |
326 Node* stack_pointer_after_call = raw_assembler_->LoadStackPointer(); | |
327 AbortIfWordNotEqual(stack_pointer_before_call, stack_pointer_after_call, | |
328 kUnexpectedStackPointer); | |
329 } | |
330 return return_val; | |
331 } | |
332 | |
333 | |
334 Node* InterpreterAssembler::CallJS(Node* function, Node* first_arg, | 317 Node* InterpreterAssembler::CallJS(Node* function, Node* first_arg, |
335 Node* arg_count) { | 318 Node* arg_count) { |
336 Callable callable = CodeFactory::InterpreterPushArgsAndCall(isolate()); | 319 Callable builtin = CodeFactory::PushArgsAndCall(isolate()); |
337 CallDescriptor* descriptor = Linkage::GetStubCallDescriptor( | 320 CallDescriptor* descriptor = Linkage::GetStubCallDescriptor( |
338 isolate(), zone(), callable.descriptor(), 0, CallDescriptor::kNoFlags); | 321 isolate(), zone(), builtin.descriptor(), 0, CallDescriptor::kNoFlags); |
339 | 322 |
340 Node* code_target = HeapConstant(callable.code()); | 323 Node* code_target = HeapConstant(builtin.code()); |
341 | 324 |
342 Node** args = zone()->NewArray<Node*>(4); | 325 Node** args = zone()->NewArray<Node*>(4); |
343 args[0] = arg_count; | 326 args[0] = arg_count; |
344 args[1] = first_arg; | 327 args[1] = first_arg; |
345 args[2] = function; | 328 args[2] = function; |
346 args[3] = ContextTaggedPointer(); | 329 args[3] = ContextTaggedPointer(); |
347 | 330 |
348 return CallN(descriptor, code_target, args); | 331 return raw_assembler_->CallN(descriptor, code_target, args); |
349 } | 332 } |
350 | 333 |
351 | 334 |
352 Node* InterpreterAssembler::CallIC(CallInterfaceDescriptor descriptor, | 335 Node* InterpreterAssembler::CallIC(CallInterfaceDescriptor descriptor, |
353 Node* target, Node** args) { | 336 Node* target, Node** args) { |
354 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( | 337 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( |
355 isolate(), zone(), descriptor, 0, CallDescriptor::kNoFlags); | 338 isolate(), zone(), descriptor, 0, CallDescriptor::kNoFlags); |
356 return CallN(call_descriptor, target, args); | 339 return raw_assembler_->CallN(call_descriptor, target, args); |
357 } | 340 } |
358 | 341 |
359 | 342 |
360 Node* InterpreterAssembler::CallIC(CallInterfaceDescriptor descriptor, | 343 Node* InterpreterAssembler::CallIC(CallInterfaceDescriptor descriptor, |
361 Node* target, Node* arg1, Node* arg2, | 344 Node* target, Node* arg1, Node* arg2, |
362 Node* arg3, Node* arg4) { | 345 Node* arg3, Node* arg4) { |
363 Node** args = zone()->NewArray<Node*>(5); | 346 Node** args = zone()->NewArray<Node*>(5); |
364 args[0] = arg1; | 347 args[0] = arg1; |
365 args[1] = arg2; | 348 args[1] = arg2; |
366 args[2] = arg3; | 349 args[2] = arg3; |
(...skipping 10 matching lines...) Expand all Loading... |
377 args[0] = arg1; | 360 args[0] = arg1; |
378 args[1] = arg2; | 361 args[1] = arg2; |
379 args[2] = arg3; | 362 args[2] = arg3; |
380 args[3] = arg4; | 363 args[3] = arg4; |
381 args[4] = arg5; | 364 args[4] = arg5; |
382 args[5] = ContextTaggedPointer(); | 365 args[5] = ContextTaggedPointer(); |
383 return CallIC(descriptor, target, args); | 366 return CallIC(descriptor, target, args); |
384 } | 367 } |
385 | 368 |
386 | 369 |
387 Node* InterpreterAssembler::CallRuntime(Node* function_id, Node* first_arg, | |
388 Node* arg_count) { | |
389 Callable callable = CodeFactory::InterpreterCEntry(isolate()); | |
390 CallDescriptor* descriptor = Linkage::GetStubCallDescriptor( | |
391 isolate(), zone(), callable.descriptor(), 0, CallDescriptor::kNoFlags); | |
392 | |
393 Node* code_target = HeapConstant(callable.code()); | |
394 | |
395 // Get the function entry from the function id. | |
396 Node* function_table = raw_assembler_->ExternalConstant( | |
397 ExternalReference::runtime_function_table_address(isolate())); | |
398 Node* function_offset = raw_assembler_->Int32Mul( | |
399 function_id, Int32Constant(sizeof(Runtime::Function))); | |
400 Node* function = IntPtrAdd(function_table, function_offset); | |
401 Node* function_entry = raw_assembler_->Load( | |
402 kMachPtr, function, Int32Constant(offsetof(Runtime::Function, entry))); | |
403 | |
404 Node** args = zone()->NewArray<Node*>(4); | |
405 args[0] = arg_count; | |
406 args[1] = first_arg; | |
407 args[2] = function_entry; | |
408 args[3] = ContextTaggedPointer(); | |
409 | |
410 return CallN(descriptor, code_target, args); | |
411 } | |
412 | |
413 | |
414 Node* InterpreterAssembler::CallRuntime(Runtime::FunctionId function_id, | 370 Node* InterpreterAssembler::CallRuntime(Runtime::FunctionId function_id, |
415 Node* arg1) { | 371 Node* arg1) { |
416 return raw_assembler_->CallRuntime1(function_id, arg1, | 372 return raw_assembler_->CallRuntime1(function_id, arg1, |
417 ContextTaggedPointer()); | 373 ContextTaggedPointer()); |
418 } | 374 } |
419 | 375 |
420 | 376 |
421 Node* InterpreterAssembler::CallRuntime(Runtime::FunctionId function_id, | 377 Node* InterpreterAssembler::CallRuntime(Runtime::FunctionId function_id, |
422 Node* arg1, Node* arg2) { | 378 Node* arg1, Node* arg2) { |
423 return raw_assembler_->CallRuntime2(function_id, arg1, arg2, | 379 return raw_assembler_->CallRuntime2(function_id, arg1, arg2, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 BytecodeArrayTaggedPointer(), | 457 BytecodeArrayTaggedPointer(), |
502 DispatchTableRawPointer(), | 458 DispatchTableRawPointer(), |
503 ContextTaggedPointer() }; | 459 ContextTaggedPointer() }; |
504 Node* tail_call = | 460 Node* tail_call = |
505 raw_assembler_->TailCallN(call_descriptor(), target_code_object, args); | 461 raw_assembler_->TailCallN(call_descriptor(), target_code_object, args); |
506 // This should always be the end node. | 462 // This should always be the end node. |
507 AddEndInput(tail_call); | 463 AddEndInput(tail_call); |
508 } | 464 } |
509 | 465 |
510 | 466 |
511 void InterpreterAssembler::AbortIfWordNotEqual( | |
512 Node* lhs, Node* rhs, BailoutReason bailout_reason) { | |
513 RawMachineAssembler::Label match, no_match; | |
514 Node* condition = raw_assembler_->WordEqual(lhs, rhs); | |
515 raw_assembler_->Branch(condition, &match, &no_match); | |
516 raw_assembler_->Bind(&no_match); | |
517 Node* abort_id = SmiTag(Int32Constant(bailout_reason)); | |
518 CallRuntime(Runtime::kAbort, abort_id); | |
519 Return(); | |
520 raw_assembler_->Bind(&match); | |
521 } | |
522 | |
523 | |
524 void InterpreterAssembler::AddEndInput(Node* input) { | 467 void InterpreterAssembler::AddEndInput(Node* input) { |
525 DCHECK_NOT_NULL(input); | 468 DCHECK_NOT_NULL(input); |
526 end_nodes_.push_back(input); | 469 end_nodes_.push_back(input); |
527 } | 470 } |
528 | 471 |
529 | 472 |
530 void InterpreterAssembler::End() { | 473 void InterpreterAssembler::End() { |
531 DCHECK(!end_nodes_.empty()); | 474 DCHECK(!end_nodes_.empty()); |
532 int end_count = static_cast<int>(end_nodes_.size()); | 475 int end_count = static_cast<int>(end_nodes_.size()); |
533 Node* end = graph()->NewNode(raw_assembler_->common()->End(end_count), | 476 Node* end = graph()->NewNode(raw_assembler_->common()->End(end_count), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 return raw_assembler_->schedule(); | 509 return raw_assembler_->schedule(); |
567 } | 510 } |
568 | 511 |
569 | 512 |
570 Zone* InterpreterAssembler::zone() { return raw_assembler_->zone(); } | 513 Zone* InterpreterAssembler::zone() { return raw_assembler_->zone(); } |
571 | 514 |
572 | 515 |
573 } // namespace compiler | 516 } // namespace compiler |
574 } // namespace internal | 517 } // namespace internal |
575 } // namespace v8 | 518 } // namespace v8 |
OLD | NEW |