A64: Improve the deoptimization helpers to generate fewer instructions.

R=jochen@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19516 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 01cf2f8e
...@@ -960,22 +960,26 @@ void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { ...@@ -960,22 +960,26 @@ void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() {
} }
Deoptimizer::BailoutType LCodeGen::DeoptimizeHeader( void LCodeGen::DeoptimizeBranch(
LEnvironment* environment, LEnvironment* environment,
BranchType branch_type, Register reg, int bit,
Deoptimizer::BailoutType* override_bailout_type) { Deoptimizer::BailoutType* override_bailout_type) {
RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt);
Deoptimizer::BailoutType bailout_type =
info()->IsStub() ? Deoptimizer::LAZY : Deoptimizer::EAGER;
if (override_bailout_type != NULL) {
bailout_type = *override_bailout_type;
}
ASSERT(environment->HasBeenRegistered()); ASSERT(environment->HasBeenRegistered());
ASSERT(info()->IsOptimizing() || info()->IsStub()); ASSERT(info()->IsOptimizing() || info()->IsStub());
int id = environment->deoptimization_index(); int id = environment->deoptimization_index();
Deoptimizer::BailoutType bailout_type =
info()->IsStub() ? Deoptimizer::LAZY : Deoptimizer::EAGER;
if (override_bailout_type) bailout_type = *override_bailout_type;
Address entry = Address entry =
Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type);
if (entry == NULL) { if (entry == NULL) {
Abort(kBailoutWasNotPrepared); Abort(kBailoutWasNotPrepared);
return bailout_type;
} }
if (FLAG_deopt_every_n_times != 0 && !info()->IsStub()) { if (FLAG_deopt_every_n_times != 0 && !info()->IsStub()) {
...@@ -1001,26 +1005,20 @@ Deoptimizer::BailoutType LCodeGen::DeoptimizeHeader( ...@@ -1001,26 +1005,20 @@ Deoptimizer::BailoutType LCodeGen::DeoptimizeHeader(
__ Pop(x0, x1, x2); __ Pop(x0, x1, x2);
} }
return bailout_type;
}
void LCodeGen::Deoptimize(LEnvironment* environment,
Deoptimizer::BailoutType bailout_type) {
ASSERT(environment->HasBeenRegistered());
ASSERT(info()->IsOptimizing() || info()->IsStub());
int id = environment->deoptimization_index();
Address entry =
Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type);
if (info()->ShouldTrapOnDeopt()) { if (info()->ShouldTrapOnDeopt()) {
Label dont_trap;
__ B(&dont_trap, InvertBranchType(branch_type), reg, bit);
__ Debug("trap_on_deopt", __LINE__, BREAK); __ Debug("trap_on_deopt", __LINE__, BREAK);
__ Bind(&dont_trap);
} }
ASSERT(info()->IsStub() || frame_is_built_); ASSERT(info()->IsStub() || frame_is_built_);
// Go through jump table if we need to build frame, or restore caller doubles. // Go through jump table if we need to build frame, or restore caller doubles.
if (frame_is_built_ && !info()->saves_caller_doubles()) { if (frame_is_built_ && !info()->saves_caller_doubles()) {
Label dont_deopt;
__ B(&dont_deopt, InvertBranchType(branch_type), reg, bit);
__ Call(entry, RelocInfo::RUNTIME_ENTRY); __ Call(entry, RelocInfo::RUNTIME_ENTRY);
__ Bind(&dont_deopt);
} else { } else {
// We often have several deopts to the same entry, reuse the last // We often have several deopts to the same entry, reuse the last
// jump entry if this is the case. // jump entry if this is the case.
...@@ -1033,82 +1031,58 @@ void LCodeGen::Deoptimize(LEnvironment* environment, ...@@ -1033,82 +1031,58 @@ void LCodeGen::Deoptimize(LEnvironment* environment,
!frame_is_built_); !frame_is_built_);
deopt_jump_table_.Add(table_entry, zone()); deopt_jump_table_.Add(table_entry, zone());
} }
__ B(&deopt_jump_table_.last().label); __ B(&deopt_jump_table_.last().label,
branch_type, reg, bit);
} }
} }
void LCodeGen::Deoptimize(LEnvironment* environment) { void LCodeGen::Deoptimize(LEnvironment* environment,
Deoptimizer::BailoutType bailout_type = DeoptimizeHeader(environment, NULL); Deoptimizer::BailoutType* override_bailout_type) {
Deoptimize(environment, bailout_type); DeoptimizeBranch(environment, always, NoReg, -1, override_bailout_type);
} }
void LCodeGen::DeoptimizeIf(Condition cond, LEnvironment* environment) { void LCodeGen::DeoptimizeIf(Condition cond, LEnvironment* environment) {
Label dont_deopt; DeoptimizeBranch(environment, static_cast<BranchType>(cond));
Deoptimizer::BailoutType bailout_type = DeoptimizeHeader(environment, NULL);
__ B(InvertCondition(cond), &dont_deopt);
Deoptimize(environment, bailout_type);
__ Bind(&dont_deopt);
} }
void LCodeGen::DeoptimizeIfZero(Register rt, LEnvironment* environment) { void LCodeGen::DeoptimizeIfZero(Register rt, LEnvironment* environment) {
Label dont_deopt; DeoptimizeBranch(environment, reg_zero, rt);
Deoptimizer::BailoutType bailout_type = DeoptimizeHeader(environment, NULL);
__ Cbnz(rt, &dont_deopt);
Deoptimize(environment, bailout_type);
__ Bind(&dont_deopt);
} }
void LCodeGen::DeoptimizeIfNegative(Register rt, LEnvironment* environment) { void LCodeGen::DeoptimizeIfNegative(Register rt, LEnvironment* environment) {
Label dont_deopt; int sign_bit = rt.Is64Bits() ? kXSignBit : kWSignBit;
Deoptimizer::BailoutType bailout_type = DeoptimizeHeader(environment, NULL); DeoptimizeBranch(environment, reg_bit_set, rt, sign_bit);
__ Tbz(rt, rt.Is64Bits() ? kXSignBit : kWSignBit, &dont_deopt);
Deoptimize(environment, bailout_type);
__ Bind(&dont_deopt);
} }
void LCodeGen::DeoptimizeIfSmi(Register rt, void LCodeGen::DeoptimizeIfSmi(Register rt,
LEnvironment* environment) { LEnvironment* environment) {
Label dont_deopt; DeoptimizeBranch(environment, reg_bit_clear, rt, MaskToBit(kSmiTagMask));
Deoptimizer::BailoutType bailout_type = DeoptimizeHeader(environment, NULL);
__ JumpIfNotSmi(rt, &dont_deopt);
Deoptimize(environment, bailout_type);
__ Bind(&dont_deopt);
} }
void LCodeGen::DeoptimizeIfNotSmi(Register rt, LEnvironment* environment) { void LCodeGen::DeoptimizeIfNotSmi(Register rt, LEnvironment* environment) {
Label dont_deopt; DeoptimizeBranch(environment, reg_bit_set, rt, MaskToBit(kSmiTagMask));
Deoptimizer::BailoutType bailout_type = DeoptimizeHeader(environment, NULL);
__ JumpIfSmi(rt, &dont_deopt);
Deoptimize(environment, bailout_type);
__ Bind(&dont_deopt);
} }
void LCodeGen::DeoptimizeIfRoot(Register rt, void LCodeGen::DeoptimizeIfRoot(Register rt,
Heap::RootListIndex index, Heap::RootListIndex index,
LEnvironment* environment) { LEnvironment* environment) {
Label dont_deopt; __ CompareRoot(rt, index);
Deoptimizer::BailoutType bailout_type = DeoptimizeHeader(environment, NULL); DeoptimizeIf(eq, environment);
__ JumpIfNotRoot(rt, index, &dont_deopt);
Deoptimize(environment, bailout_type);
__ Bind(&dont_deopt);
} }
void LCodeGen::DeoptimizeIfNotRoot(Register rt, void LCodeGen::DeoptimizeIfNotRoot(Register rt,
Heap::RootListIndex index, Heap::RootListIndex index,
LEnvironment* environment) { LEnvironment* environment) {
Label dont_deopt; __ CompareRoot(rt, index);
Deoptimizer::BailoutType bailout_type = DeoptimizeHeader(environment, NULL); DeoptimizeIf(ne, environment);
__ JumpIfRoot(rt, index, &dont_deopt);
Deoptimize(environment, bailout_type);
__ Bind(&dont_deopt);
} }
...@@ -2135,9 +2109,6 @@ void LCodeGen::DoCheckMaps(LCheckMaps* instr) { ...@@ -2135,9 +2109,6 @@ void LCodeGen::DoCheckMaps(LCheckMaps* instr) {
void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) {
if (!instr->hydrogen()->value()->IsHeapObject()) { if (!instr->hydrogen()->value()->IsHeapObject()) {
// TODO(all): Depending of how we chose to implement the deopt, if we could
// guarantee that we have a deopt handler reachable by a tbz instruction,
// we could use tbz here and produce less code to support this instruction.
DeoptimizeIfSmi(ToRegister(instr->value()), instr->environment()); DeoptimizeIfSmi(ToRegister(instr->value()), instr->environment());
} }
} }
...@@ -2146,7 +2117,6 @@ void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { ...@@ -2146,7 +2117,6 @@ void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) {
void LCodeGen::DoCheckSmi(LCheckSmi* instr) { void LCodeGen::DoCheckSmi(LCheckSmi* instr) {
Register value = ToRegister(instr->value()); Register value = ToRegister(instr->value());
ASSERT(!instr->result() || ToRegister(instr->result()).Is(value)); ASSERT(!instr->result() || ToRegister(instr->result()).Is(value));
// TODO(all): See DoCheckNonSmi for comments on use of tbz.
DeoptimizeIfNotSmi(value, instr->environment()); DeoptimizeIfNotSmi(value, instr->environment());
} }
...@@ -2586,8 +2556,7 @@ void LCodeGen::DoDeoptimize(LDeoptimize* instr) { ...@@ -2586,8 +2556,7 @@ void LCodeGen::DoDeoptimize(LDeoptimize* instr) {
} }
Comment(";;; deoptimize: %s", instr->hydrogen()->reason()); Comment(";;; deoptimize: %s", instr->hydrogen()->reason());
DeoptimizeHeader(instr->environment(), &type); Deoptimize(instr->environment(), &type);
Deoptimize(instr->environment(), type);
} }
......
...@@ -218,12 +218,12 @@ class LCodeGen: public LCodeGenBase { ...@@ -218,12 +218,12 @@ class LCodeGen: public LCodeGenBase {
Register temp, Register temp,
LOperand* index, LOperand* index,
String::Encoding encoding); String::Encoding encoding);
Deoptimizer::BailoutType DeoptimizeHeader( void DeoptimizeBranch(
LEnvironment* environment, LEnvironment* environment,
Deoptimizer::BailoutType* override_bailout_type); BranchType branch_type, Register reg = NoReg, int bit = -1,
void Deoptimize(LEnvironment* environment); Deoptimizer::BailoutType* override_bailout_type = NULL);
void Deoptimize(LEnvironment* environment, void Deoptimize(LEnvironment* environment,
Deoptimizer::BailoutType bailout_type); Deoptimizer::BailoutType* override_bailout_type = NULL);
void DeoptimizeIf(Condition cc, LEnvironment* environment); void DeoptimizeIf(Condition cc, LEnvironment* environment);
void DeoptimizeIfZero(Register rt, LEnvironment* environment); void DeoptimizeIfZero(Register rt, LEnvironment* environment);
void DeoptimizeIfNegative(Register rt, LEnvironment* environment); void DeoptimizeIfNegative(Register rt, LEnvironment* environment);
......
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