Commit d1083526 authored by mtrofin's avatar mtrofin Committed by Commit bot

Preparing the terrain for frame elision. This change is necessary to

avoid jump threading erasing the reconstruction of a frame, if the
frame was elided.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#33590}
parent dd64a6d8
......@@ -53,10 +53,10 @@ struct JumpThreadingState {
RpoNumber onstack() { return RpoNumber::FromInt(-2); }
};
bool JumpThreading::ComputeForwarding(Zone* local_zone,
ZoneVector<RpoNumber>& result,
InstructionSequence* code) {
InstructionSequence* code,
bool frame_at_start) {
ZoneStack<RpoNumber> stack(local_zone);
JumpThreadingState state = {false, result, stack};
state.Clear(code->InstructionBlockCount());
......@@ -91,7 +91,14 @@ bool JumpThreading::ComputeForwarding(Zone* local_zone,
} else if (instr->arch_opcode() == kArchJmp) {
// try to forward the jump instruction.
TRACE(" jmp\n");
fw = code->InputRpo(instr, 0);
// if this block deconstructs the frame, we can't forward it.
// TODO(mtrofin): we can still forward if we end up building
// the frame at start. So we should move the decision of whether
// to build a frame or not in the register allocator, and trickle it
// here and to the code generator.
if (frame_at_start || !block->must_deconstruct_frame()) {
fw = code->InputRpo(instr, 0);
}
fallthru = false;
} else {
// can't skip other instructions.
......
......@@ -18,7 +18,7 @@ class JumpThreading {
// Compute the forwarding map of basic blocks to their ultimate destination.
// Returns {true} if there is at least one block that is forwarded.
static bool ComputeForwarding(Zone* local_zone, ZoneVector<RpoNumber>& result,
InstructionSequence* code);
InstructionSequence* code, bool frame_at_start);
// Rewrite the instructions to forward jumps and branches.
// May also negate some branches.
......
......@@ -982,9 +982,10 @@ struct FrameElisionPhase {
struct JumpThreadingPhase {
static const char* phase_name() { return "jump threading"; }
void Run(PipelineData* data, Zone* temp_zone) {
void Run(PipelineData* data, Zone* temp_zone, bool frame_at_start) {
ZoneVector<RpoNumber> result(temp_zone);
if (JumpThreading::ComputeForwarding(temp_zone, result, data->sequence())) {
if (JumpThreading::ComputeForwarding(temp_zone, result, data->sequence(),
frame_at_start)) {
JumpThreading::ApplyForwarding(result, data->sequence());
}
}
......@@ -1334,10 +1335,16 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode(
}
BeginPhaseKind("code generation");
// TODO(mtrofin): move this off to the register allocator.
bool generate_frame_at_start =
!FLAG_turbo_frame_elision || !data_->info()->IsStub() ||
!data_->frame()->needs_frame() ||
data_->sequence()->instruction_blocks().front()->needs_frame() ||
linkage.GetIncomingDescriptor()->CalleeSavedFPRegisters() != 0 ||
linkage.GetIncomingDescriptor()->CalleeSavedRegisters() != 0;
// Optimimize jumps.
if (FLAG_turbo_jt) {
Run<JumpThreadingPhase>();
Run<JumpThreadingPhase>(generate_frame_at_start);
}
// Generate final machine code.
......
......@@ -65,6 +65,8 @@ class Pipeline {
void Run();
template <typename Phase, typename Arg0>
void Run(Arg0 arg_0);
template <typename Phase, typename Arg0, typename Arg1>
void Run(Arg0 arg_0, Arg1 arg_1);
CompilationInfo* info() const { return info_; }
Isolate* isolate() { return info_->isolate(); }
......
......@@ -108,7 +108,7 @@ class TestCode : public HandleAndZoneScope {
void VerifyForwarding(TestCode& code, int count, int* expected) {
Zone local_zone;
ZoneVector<RpoNumber> result(&local_zone);
JumpThreading::ComputeForwarding(&local_zone, result, &code.sequence_);
JumpThreading::ComputeForwarding(&local_zone, result, &code.sequence_, true);
CHECK(count == static_cast<int>(result.size()));
for (int i = 0; i < count; i++) {
......
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