[compiler] Only run ScheduleEarly if graph contains loops.

The ScheduleEarly phase of the scheduler initializes the minimum_block
values which are only required for loop hoisting. If there are no loops,
running this step is unecessary overhead.

BUG=v8:9684

Change-Id: Iba181fd55ecd634c05d3f8eb4282bd0be3141c21
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2880538
Reviewed-by: Nico Hartmann <nicohartmann@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74445}
This commit is contained in:
Ross McIlroy 2021-05-07 16:34:25 +01:00 committed by V8 LUCI CQ
parent 350b0c38ad
commit be09ba1f12

View File

@ -727,6 +727,8 @@ class SpecialRPONumberer : public ZoneObject {
return empty_; return empty_;
} }
bool HasLoopBlocks() const { return loops_.size() != 0; }
private: private:
using Backedge = std::pair<BasicBlock*, size_t>; using Backedge = std::pair<BasicBlock*, size_t>;
@ -1382,6 +1384,11 @@ class ScheduleEarlyNodeVisitor {
void Scheduler::ScheduleEarly() { void Scheduler::ScheduleEarly() {
if (!special_rpo_->HasLoopBlocks()) {
TRACE("--- NO LOOPS SO SKIPPING SCHEDULE EARLY --------------------\n");
return;
}
TRACE("--- SCHEDULE EARLY -----------------------------------------\n"); TRACE("--- SCHEDULE EARLY -----------------------------------------\n");
if (FLAG_trace_turbo_scheduler) { if (FLAG_trace_turbo_scheduler) {
TRACE("roots: "); TRACE("roots: ");
@ -1459,6 +1466,7 @@ class ScheduleLateNodeVisitor {
// The schedule early block dominates the schedule late block. // The schedule early block dominates the schedule late block.
BasicBlock* min_block = scheduler_->GetData(node)->minimum_block_; BasicBlock* min_block = scheduler_->GetData(node)->minimum_block_;
DCHECK_EQ(min_block, BasicBlock::GetCommonDominator(block, min_block)); DCHECK_EQ(min_block, BasicBlock::GetCommonDominator(block, min_block));
TRACE( TRACE(
"Schedule late of #%d:%s is id:%d at loop depth %d, minimum = id:%d\n", "Schedule late of #%d:%s is id:%d at loop depth %d, minimum = id:%d\n",
node->id(), node->op()->mnemonic(), block->id().ToInt(), node->id(), node->op()->mnemonic(), block->id().ToInt(),
@ -1470,6 +1478,7 @@ class ScheduleLateNodeVisitor {
BasicBlock* hoist_block = GetHoistBlock(block); BasicBlock* hoist_block = GetHoistBlock(block);
if (hoist_block && if (hoist_block &&
hoist_block->dominator_depth() >= min_block->dominator_depth()) { hoist_block->dominator_depth() >= min_block->dominator_depth()) {
DCHECK(scheduler_->special_rpo_->HasLoopBlocks());
do { do {
TRACE(" hoisting #%d:%s to block id:%d\n", node->id(), TRACE(" hoisting #%d:%s to block id:%d\n", node->id(),
node->op()->mnemonic(), hoist_block->id().ToInt()); node->op()->mnemonic(), hoist_block->id().ToInt());
@ -1599,6 +1608,7 @@ class ScheduleLateNodeVisitor {
} }
BasicBlock* GetHoistBlock(BasicBlock* block) { BasicBlock* GetHoistBlock(BasicBlock* block) {
if (!scheduler_->special_rpo_->HasLoopBlocks()) return nullptr;
if (block->IsLoopHeader()) return block->dominator(); if (block->IsLoopHeader()) return block->dominator();
// We have to check to make sure that the {block} dominates all // We have to check to make sure that the {block} dominates all
// of the outgoing blocks. If it doesn't, then there is a path // of the outgoing blocks. If it doesn't, then there is a path