Commit 3f7e96df authored by mtrofin's avatar mtrofin Committed by Commit bot

[turbofan] move optimizer - CompressBlock cleanup.

I believe the code reads easier after this change. The original code
probably dates back to when we had 4 gap positions. Now that there
are only 2, the logic can be simpler by avoiding a loop and instead
treating each case explicitly: no gaps; gaps just at end; gaps at start and
maybe end. That way, it is also  easier to understand how the moves get
pushed downwards. This is what got me to make this change in the first
place: trying to work out a finer grained move optimization.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#33016}
parent f7364222
......@@ -118,6 +118,8 @@ void MoveOptimizer::Run() {
void MoveOptimizer::CompressMoves(ParallelMove* left, ParallelMove* right) {
if (right == nullptr) return;
MoveOpVector& eliminated = local_vector();
DCHECK(eliminated.empty());
......@@ -153,26 +155,37 @@ void MoveOptimizer::CompressBlock(InstructionBlock* block) {
for (int index = block->code_start(); index < block->code_end(); ++index) {
Instruction* instr = code()->instructions()[index];
int i = FindFirstNonEmptySlot(instr);
if (i <= Instruction::LAST_GAP_POSITION) {
// Move the first non-empty gap to position 0.
std::swap(instr->parallel_moves()[0], instr->parallel_moves()[i]);
ParallelMove* left = instr->parallel_moves()[0];
// Compress everything into position 0.
for (++i; i <= Instruction::LAST_GAP_POSITION; ++i) {
ParallelMove* move = instr->parallel_moves()[i];
if (move == nullptr) continue;
CompressMoves(left, move);
}
if (prev_instr != nullptr) {
// Smash left into prev_instr, killing left.
ParallelMove* pred_moves = prev_instr->parallel_moves()[0];
CompressMoves(pred_moves, left);
}
bool has_moves = i <= Instruction::LAST_GAP_POSITION;
if (i == Instruction::LAST_GAP_POSITION) {
std::swap(instr->parallel_moves()[Instruction::FIRST_GAP_POSITION],
instr->parallel_moves()[Instruction::LAST_GAP_POSITION]);
} else if (i == Instruction::FIRST_GAP_POSITION) {
CompressMoves(instr->parallel_moves()[Instruction::FIRST_GAP_POSITION],
instr->parallel_moves()[Instruction::LAST_GAP_POSITION]);
}
// We either have no moves, or, after swapping or compressing, we have
// all the moves in the first gap position, and none in the second/end gap
// position.
ParallelMove* first =
instr->parallel_moves()[Instruction::FIRST_GAP_POSITION];
ParallelMove* last =
instr->parallel_moves()[Instruction::LAST_GAP_POSITION];
USE(last);
DCHECK(!has_moves ||
(first != nullptr && (last == nullptr || last->empty())));
if (prev_instr != nullptr) {
if (has_moves) {
// Smash first into prev_instr, killing left.
ParallelMove* pred_moves = prev_instr->parallel_moves()[0];
CompressMoves(pred_moves, first);
}
// Slide prev_instr down so we always know where to look for it.
std::swap(prev_instr->parallel_moves()[0], instr->parallel_moves()[0]);
}
prev_instr = instr->parallel_moves()[0] == nullptr ? nullptr : instr;
if (GapsCanMoveOver(instr, local_zone())) continue;
if (prev_instr != nullptr) {
......
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