From 65fcf0df77b030654dc4dc92be768ee96a8e2368 Mon Sep 17 00:00:00 2001 From: Ross McIlroy Date: Mon, 28 Oct 2019 15:58:13 +0000 Subject: [PATCH] [TurboProp] Verify schedule after each scheduled lowering pass. Add support to verify the update schedule after ScheduledEffectControlLinearization and ScheduledMachineLowering phases. To do so, we need to recompute the immediate dominator tree of the scheduled blocks. BUG=v8:9684 Change-Id: I849fb7e3e699ca56c5115d90a53006d517cf3fe5 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1881160 Commit-Queue: Ross McIlroy Reviewed-by: Tobias Tebbi Cr-Commit-Position: refs/heads/master@{#64596} --- src/compiler/pipeline.cc | 25 +++++++++++++------------ src/compiler/scheduler.cc | 15 ++++++++------- src/compiler/scheduler.h | 7 +++++-- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc index cd4a5c6560..7ae8e970ab 100644 --- a/src/compiler/pipeline.cc +++ b/src/compiler/pipeline.cc @@ -762,8 +762,8 @@ void PrintCode(Isolate* isolate, Handle code, #endif // ENABLE_DISASSEMBLER } -void TraceSchedule(OptimizedCompilationInfo* info, PipelineData* data, - Schedule* schedule, const char* phase_name) { +void TraceScheduleAndVerify(OptimizedCompilationInfo* info, PipelineData* data, + Schedule* schedule, const char* phase_name) { if (info->trace_turbo_json_enabled()) { AllowHandleDereference allow_deref; TurboJsonFile json_of(info, std::ios_base::app); @@ -783,8 +783,9 @@ void TraceSchedule(OptimizedCompilationInfo* info, PipelineData* data, OFStream os(tracing_scope.file()); os << "-- Schedule --------------------------------------\n" << *schedule; } -} + if (FLAG_turbo_verify) ScheduleVerifier::Run(schedule); +} class SourcePositionWrapper final : public Reducer { public: @@ -1630,9 +1631,8 @@ struct EffectControlLinearizationPhase { Schedule* schedule = Scheduler::ComputeSchedule( temp_zone, data->graph(), Scheduler::kTempSchedule, &data->info()->tick_counter()); - if (FLAG_turbo_verify) ScheduleVerifier::Run(schedule); - TraceSchedule(data->info(), data, schedule, - "effect linearization schedule"); + TraceScheduleAndVerify(data->info(), data, schedule, + "effect linearization schedule"); MaskArrayIndexEnable mask_array_index = (data->info()->GetPoisoningMitigationLevel() != @@ -1830,8 +1830,9 @@ struct ScheduledEffectControlLinearizationPhase { // TODO(rmcilroy) Avoid having to rebuild rpo_order on schedule each time. Scheduler::ComputeSpecialRPO(temp_zone, data->schedule()); - TraceSchedule(data->info(), data, data->schedule(), - "effect linearization schedule"); + if (FLAG_turbo_verify) Scheduler::GenerateDominatorTree(data->schedule()); + TraceScheduleAndVerify(data->info(), data, data->schedule(), + "effect linearization schedule"); } }; @@ -1848,8 +1849,9 @@ struct ScheduledMachineLoweringPhase { // TODO(rmcilroy) Avoid having to rebuild rpo_order on schedule each time. Scheduler::ComputeSpecialRPO(temp_zone, data->schedule()); - TraceSchedule(data->info(), data, data->schedule(), - "machine lowered schedule"); + if (FLAG_turbo_verify) Scheduler::GenerateDominatorTree(data->schedule()); + TraceScheduleAndVerify(data->info(), data, data->schedule(), + "machine lowered schedule"); } }; @@ -1943,7 +1945,6 @@ struct ComputeSchedulePhase { data->info()->is_splitting_enabled() ? Scheduler::kSplitNodes : Scheduler::kNoFlags, &data->info()->tick_counter()); - if (FLAG_turbo_verify) ScheduleVerifier::Run(schedule); data->set_schedule(schedule); } }; @@ -2968,7 +2969,7 @@ void PipelineImpl::ComputeScheduledGraph() { RunPrintAndVerify(LateGraphTrimmingPhase::phase_name(), true); Run(); - TraceSchedule(data->info(), data, data->schedule(), "schedule"); + TraceScheduleAndVerify(data->info(), data, data->schedule(), "schedule"); } bool PipelineImpl::SelectInstructions(Linkage* linkage) { diff --git a/src/compiler/scheduler.cc b/src/compiler/scheduler.cc index 2999cbfcd6..2c3da4c4d5 100644 --- a/src/compiler/scheduler.cc +++ b/src/compiler/scheduler.cc @@ -58,7 +58,7 @@ Schedule* Scheduler::ComputeSchedule(Zone* zone, Graph* graph, Flags flags, scheduler.BuildCFG(); scheduler.ComputeSpecialRPONumbering(); - scheduler.GenerateImmediateDominatorTree(); + scheduler.GenerateDominatorTree(); scheduler.PrepareUses(); scheduler.ScheduleEarly(); @@ -1165,17 +1165,18 @@ void Scheduler::PropagateImmediateDominators(BasicBlock* block) { } } - -void Scheduler::GenerateImmediateDominatorTree() { - TRACE("--- IMMEDIATE BLOCK DOMINATORS -----------------------------\n"); - +void Scheduler::GenerateDominatorTree(Schedule* schedule) { // Seed start block to be the first dominator. - schedule_->start()->set_dominator_depth(0); + schedule->start()->set_dominator_depth(0); // Build the block dominator tree resulting from the above seed. - PropagateImmediateDominators(schedule_->start()->rpo_next()); + PropagateImmediateDominators(schedule->start()->rpo_next()); } +void Scheduler::GenerateDominatorTree() { + TRACE("--- IMMEDIATE BLOCK DOMINATORS -----------------------------\n"); + GenerateDominatorTree(schedule_); +} // ----------------------------------------------------------------------------- // Phase 3: Prepare use counts for nodes. diff --git a/src/compiler/scheduler.h b/src/compiler/scheduler.h index 3d1fa40025..291b53db67 100644 --- a/src/compiler/scheduler.h +++ b/src/compiler/scheduler.h @@ -42,6 +42,9 @@ class V8_EXPORT_PRIVATE Scheduler { // Compute the RPO of blocks in an existing schedule. static BasicBlockVector* ComputeSpecialRPO(Zone* zone, Schedule* schedule); + // Computes the dominator tree on an existing schedule that has RPO computed. + static void GenerateDominatorTree(Schedule* schedule); + private: // Placement of a node changes during scheduling. The placement state // transitions over time while the scheduler is choosing a position: @@ -98,7 +101,7 @@ class V8_EXPORT_PRIVATE Scheduler { void IncrementUnscheduledUseCount(Node* node, int index, Node* from); void DecrementUnscheduledUseCount(Node* node, int index, Node* from); - void PropagateImmediateDominators(BasicBlock* block); + static void PropagateImmediateDominators(BasicBlock* block); // Phase 1: Build control-flow graph. friend class CFGBuilder; @@ -107,7 +110,7 @@ class V8_EXPORT_PRIVATE Scheduler { // Phase 2: Compute special RPO and dominator tree. friend class SpecialRPONumberer; void ComputeSpecialRPONumbering(); - void GenerateImmediateDominatorTree(); + void GenerateDominatorTree(); // Phase 3: Prepare use counts for nodes. friend class PrepareUsesVisitor;