From c11ab6f7e51c38f1aebae783bdf6bff801389f91 Mon Sep 17 00:00:00 2001 From: mtrofin Date: Tue, 4 Aug 2015 07:49:44 -0700 Subject: [PATCH] Setting up the stage for heuristics that preprocess live ranges before register allocation, and are independent of register allocation - e.g. the deferred blocks heuristic, or the split at call sites heuristic. Added a separate flag for this, since we intend to enable it for the linear allocator as well. Currently, the option is "on" for greedy, as a point in time to enable its testing (through the greedy allocator bots). BUG= Review URL: https://codereview.chromium.org/1256313003 Cr-Commit-Position: refs/heads/master@{#30005} --- BUILD.gn | 2 ++ src/compiler/pipeline.cc | 17 +++++++++++++ src/compiler/preprocess-live-ranges.cc | 29 +++++++++++++++++++++ src/compiler/preprocess-live-ranges.h | 35 ++++++++++++++++++++++++++ src/flag-definitions.h | 3 +++ tools/gyp/v8.gyp | 2 ++ 6 files changed, 88 insertions(+) create mode 100644 src/compiler/preprocess-live-ranges.cc create mode 100644 src/compiler/preprocess-live-ranges.h diff --git a/BUILD.gn b/BUILD.gn index 20878cda52..95feb0a86b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -782,6 +782,8 @@ source_set("v8_base") { "src/compiler/pipeline.h", "src/compiler/pipeline-statistics.cc", "src/compiler/pipeline-statistics.h", + "src/compiler/preprocess-live-ranges.cc", + "src/compiler/preprocess-live-ranges.h", "src/compiler/raw-machine-assembler.cc", "src/compiler/raw-machine-assembler.h", "src/compiler/register-allocator.cc", diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc index d2c5fa6f35..f55b4d3512 100644 --- a/src/compiler/pipeline.cc +++ b/src/compiler/pipeline.cc @@ -42,6 +42,7 @@ #include "src/compiler/move-optimizer.h" #include "src/compiler/osr.h" #include "src/compiler/pipeline-statistics.h" +#include "src/compiler/preprocess-live-ranges.h" #include "src/compiler/register-allocator.h" #include "src/compiler/register-allocator-verifier.h" #include "src/compiler/schedule.h" @@ -785,6 +786,17 @@ struct BuildLiveRangesPhase { }; +struct PreprocessLiveRangesPhase { + static const char* phase_name() { return "preprocess live ranges"; } + + void Run(PipelineData* data, Zone* temp_zone) { + PreprocessLiveRanges live_range_preprocessor( + data->register_allocation_data(), temp_zone); + live_range_preprocessor.PreprocessRanges(); + } +}; + + template struct AllocateGeneralRegistersPhase { static const char* phase_name() { return "allocate general registers"; } @@ -1320,6 +1332,11 @@ void Pipeline::AllocateRegisters(const RegisterConfiguration* config, if (verifier != nullptr) { CHECK(!data->register_allocation_data()->ExistsUseWithoutDefinition()); } + + if (FLAG_turbo_preprocess_ranges) { + Run(); + } + if (FLAG_turbo_greedy_regalloc) { Run>(); Run>(); diff --git a/src/compiler/preprocess-live-ranges.cc b/src/compiler/preprocess-live-ranges.cc new file mode 100644 index 0000000000..81283a898a --- /dev/null +++ b/src/compiler/preprocess-live-ranges.cc @@ -0,0 +1,29 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/compiler/preprocess-live-ranges.h" +#include "src/compiler/register-allocator.h" + +namespace v8 { +namespace internal { +namespace compiler { + + +#define TRACE(...) \ + do { \ + if (FLAG_trace_alloc) PrintF(__VA_ARGS__); \ + } while (false) + + +void PreprocessLiveRanges::PreprocessRanges() { + SplitRangesAroundDeferredBlocks(); +} + + +void PreprocessLiveRanges::SplitRangesAroundDeferredBlocks() {} + + +} // namespace compiler +} // namespace internal +} // namespace v8 diff --git a/src/compiler/preprocess-live-ranges.h b/src/compiler/preprocess-live-ranges.h new file mode 100644 index 0000000000..aa852fc7ca --- /dev/null +++ b/src/compiler/preprocess-live-ranges.h @@ -0,0 +1,35 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_PREPROCESS_LIVE_RANGES_H_ +#define V8_PREPROCESS_LIVE_RANGES_H_ + +#include "src/compiler/register-allocator.h" + +namespace v8 { +namespace internal { +namespace compiler { + + +class PreprocessLiveRanges final { + public: + PreprocessLiveRanges(RegisterAllocationData* data, Zone* zone) + : data_(data), zone_(zone) {} + void PreprocessRanges(); + + private: + void SplitRangesAroundDeferredBlocks(); + + RegisterAllocationData* data() { return data_; } + Zone* zone() { return zone_; } + + RegisterAllocationData* data_; + Zone* zone_; +}; + + +} // namespace compiler +} // namespace internal +} // namespace v8 +#endif // V8_PREPROCESS_LIVE_RANGES_H_ diff --git a/src/flag-definitions.h b/src/flag-definitions.h index acc7edaa6e..1e59f00de1 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -397,6 +397,9 @@ DEFINE_BOOL(omit_map_checks_for_leaf_maps, true, DEFINE_BOOL(turbo, false, "enable TurboFan compiler") DEFINE_BOOL(turbo_shipping, true, "enable TurboFan compiler on subset") DEFINE_BOOL(turbo_greedy_regalloc, false, "use the greedy register allocator") +DEFINE_BOOL(turbo_preprocess_ranges, false, + "run pre-register allocation heuristics") +DEFINE_IMPLICATION(turbo_greedy_regalloc, turbo_preprocess_ranges) DEFINE_IMPLICATION(turbo, turbo_asm_deoptimization) DEFINE_STRING(turbo_filter, "~~", "optimization filter for TurboFan compiler") DEFINE_BOOL(trace_turbo, false, "trace generated TurboFan IR") diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index 913f95aa7e..31645fa61a 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -575,6 +575,8 @@ '../../src/compiler/pipeline.h', '../../src/compiler/pipeline-statistics.cc', '../../src/compiler/pipeline-statistics.h', + '../../src/compiler/preprocess-live-ranges.cc', + '../../src/compiler/preprocess-live-ranges.h', '../../src/compiler/raw-machine-assembler.cc', '../../src/compiler/raw-machine-assembler.h', '../../src/compiler/register-allocator.cc',