Commit 3ada8da3 authored by zhengxing.li's avatar zhengxing.li Committed by Commit bot

X87: [es6] Further fixing of tail Calls.

  port e519e6fa(r33886)

  original commit message:
  1) Update profiling counters in Full codegen.
  2) Call Runtime::kTraceTailCall when tracing is on

  test/mjsunit/es6/tail-call-simple.js is disabled for now, because Turbofan does not fully support TCO yet.

BUG=

Review URL: https://codereview.chromium.org/1706673002

Cr-Commit-Position: refs/heads/master@{#34054}
parent 8ba651aa
......@@ -383,6 +383,30 @@ void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt,
PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS);
}
void FullCodeGenerator::EmitProfilingCounterHandlingForReturnSequence(
bool is_tail_call) {
// Pretend that the exit is a backwards jump to the entry.
int weight = 1;
if (info_->ShouldSelfOptimize()) {
weight = FLAG_interrupt_budget / FLAG_self_opt_count;
} else {
int distance = masm_->pc_offset();
weight = Min(kMaxBackEdgeWeight, Max(1, distance / kCodeSizeMultiplier));
}
EmitProfilingCounterDecrement(weight);
Label ok;
__ j(positive, &ok, Label::kNear);
// Don't need to save result register if we are going to do a tail call.
if (!is_tail_call) {
__ push(eax);
}
__ call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET);
if (!is_tail_call) {
__ pop(eax);
}
EmitProfilingCounterReset();
__ bind(&ok);
}
void FullCodeGenerator::EmitReturnSequence() {
Comment cmnt(masm_, "[ Return sequence");
......@@ -395,24 +419,7 @@ void FullCodeGenerator::EmitReturnSequence() {
__ push(eax);
__ CallRuntime(Runtime::kTraceExit);
}
// Pretend that the exit is a backwards jump to the entry.
int weight = 1;
if (info_->ShouldSelfOptimize()) {
weight = FLAG_interrupt_budget / FLAG_self_opt_count;
} else {
int distance = masm_->pc_offset();
weight = Min(kMaxBackEdgeWeight,
Max(1, distance / kCodeSizeMultiplier));
}
EmitProfilingCounterDecrement(weight);
Label ok;
__ j(positive, &ok, Label::kNear);
__ push(eax);
__ call(isolate()->builtins()->InterruptCheck(),
RelocInfo::CODE_TARGET);
__ pop(eax);
EmitProfilingCounterReset();
__ bind(&ok);
EmitProfilingCounterHandlingForReturnSequence(false);
SetReturnPosition(literal());
__ leave();
......@@ -2629,6 +2636,14 @@ void FullCodeGenerator::EmitCall(Call* expr, ConvertReceiverMode mode) {
PrepareForBailoutForId(expr->CallId(), NO_REGISTERS);
SetCallPosition(expr);
if (expr->tail_call_mode() == TailCallMode::kAllow) {
if (FLAG_trace) {
__ CallRuntime(Runtime::kTraceTailCall);
}
// Update profiling counters before the tail call since we will
// not return to this function.
EmitProfilingCounterHandlingForReturnSequence(true);
}
Handle<Code> ic =
CodeFactory::CallIC(isolate(), arg_count, mode, expr->tail_call_mode())
.code();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment