[turboshaft] refactor assemblers/reducers to enable IDE autocomplete
Bug: v8:12783 Change-Id: I237f470cea6be265475fec6c4301f3bf60bcb118 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4208931 Auto-Submit: Tobias Tebbi <tebbi@chromium.org> Reviewed-by: Nico Hartmann <nicohartmann@chromium.org> Commit-Queue: Nico Hartmann <nicohartmann@chromium.org> Cr-Commit-Position: refs/heads/main@{#85586}
This commit is contained in:
parent
7d8ca951ec
commit
993c2b45be
@ -52,16 +52,32 @@ class ReducerStack<Assembler, FirstReducer, Reducers...>
|
||||
using FirstReducer<ReducerStack<Assembler, Reducers...>>::FirstReducer;
|
||||
};
|
||||
|
||||
template <class Assembler>
|
||||
class ReducerStack<Assembler> {
|
||||
template <class Reducers>
|
||||
class ReducerStack<Assembler<Reducers>> {
|
||||
public:
|
||||
using AssemblerType = Assembler;
|
||||
Assembler& Asm() { return *static_cast<Assembler*>(this); }
|
||||
using AssemblerType = Assembler<Reducers>;
|
||||
using ReducerList = Reducers;
|
||||
Assembler<ReducerList>& Asm() {
|
||||
return *static_cast<Assembler<ReducerList>*>(this);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Reducers>
|
||||
struct reducer_stack_type {};
|
||||
template <template <class> class... Reducers>
|
||||
struct reducer_stack_type<reducer_list<Reducers...>> {
|
||||
using type = ReducerStack<Assembler<reducer_list<Reducers...>>, Reducers...,
|
||||
v8::internal::compiler::turboshaft::ReducerBase>;
|
||||
};
|
||||
|
||||
template <typename Next>
|
||||
class ReducerBase;
|
||||
|
||||
#define TURBOSHAFT_REDUCER_BOILERPLATE() \
|
||||
Assembler<typename Next::ReducerList>& Asm() { \
|
||||
return *static_cast<Assembler<typename Next::ReducerList>*>(this); \
|
||||
}
|
||||
|
||||
// LABEL_BLOCK is used in Reducers to have a single call forwarding to the next
|
||||
// reducer without change. A typical use would be:
|
||||
//
|
||||
@ -101,9 +117,9 @@ class ReducerBaseForwarder : public Next {
|
||||
template <class Next>
|
||||
class ReducerBase : public ReducerBaseForwarder<Next> {
|
||||
public:
|
||||
using Next::Asm;
|
||||
using Base = ReducerBaseForwarder<Next>;
|
||||
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||
|
||||
using Base = ReducerBaseForwarder<Next>;
|
||||
using ArgT = std::tuple<>;
|
||||
|
||||
template <class... Args>
|
||||
@ -1047,24 +1063,18 @@ class AssemblerOpInterface {
|
||||
Assembler& stack() { return *static_cast<Assembler*>(this); }
|
||||
};
|
||||
|
||||
template <template <class> class... Reducers>
|
||||
class Assembler
|
||||
: public GraphVisitor<Assembler<Reducers...>>,
|
||||
public ReducerStack<Assembler<Reducers...>, Reducers...,
|
||||
v8::internal::compiler::turboshaft::ReducerBase>,
|
||||
public OperationMatching<Assembler<Reducers...>>,
|
||||
public AssemblerOpInterface<Assembler<Reducers...>> {
|
||||
using Stack = ReducerStack<Assembler<Reducers...>, Reducers...,
|
||||
v8::internal::compiler::turboshaft::ReducerBase>;
|
||||
template <class Reducers>
|
||||
class Assembler : public GraphVisitor<Assembler<Reducers>>,
|
||||
public reducer_stack_type<Reducers>::type,
|
||||
public OperationMatching<Assembler<Reducers>>,
|
||||
public AssemblerOpInterface<Assembler<Reducers>> {
|
||||
using Stack = typename reducer_stack_type<Reducers>::type;
|
||||
|
||||
public:
|
||||
template <class... ReducerArgs>
|
||||
explicit Assembler(
|
||||
Graph& input_graph, Graph& output_graph, Zone* phase_zone,
|
||||
compiler::NodeOriginTable* origins,
|
||||
const typename ReducerStack<
|
||||
Assembler<Reducers...>, Reducers...,
|
||||
v8::internal::compiler::turboshaft::ReducerBase>::ArgT& reducer_args)
|
||||
explicit Assembler(Graph& input_graph, Graph& output_graph, Zone* phase_zone,
|
||||
compiler::NodeOriginTable* origins,
|
||||
const typename Stack::ArgT& reducer_args)
|
||||
: GraphVisitor<Assembler>(input_graph, output_graph, phase_zone, origins),
|
||||
Stack(reducer_args) {
|
||||
SupportedOperations::Initialize();
|
||||
@ -1075,7 +1085,7 @@ class Assembler
|
||||
Block* NewLoopHeader() { return this->output_graph().NewLoopHeader(); }
|
||||
Block* NewBlock() { return this->output_graph().NewBlock(); }
|
||||
|
||||
using OperationMatching<Assembler<Reducers...>>::Get;
|
||||
using OperationMatching<Assembler<Reducers>>::Get;
|
||||
using Stack::Get;
|
||||
|
||||
V8_INLINE V8_WARN_UNUSED_RESULT bool Bind(Block* block,
|
||||
|
@ -37,7 +37,8 @@ struct AssertTypesReducerArgs {
|
||||
template <class Next>
|
||||
class AssertTypesReducer : public Next {
|
||||
public:
|
||||
using Next::Asm;
|
||||
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||
|
||||
using ArgT =
|
||||
base::append_tuple_type<typename Next::ArgT, AssertTypesReducerArgs>;
|
||||
|
||||
|
@ -168,7 +168,8 @@ class BranchEliminationReducer : public Next {
|
||||
// that's the case, then we copy the destination block, and the 1st
|
||||
// optimization will replace its final Branch by a Goto when reaching it.
|
||||
public:
|
||||
using Next::Asm;
|
||||
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||
|
||||
template <class... Args>
|
||||
explicit BranchEliminationReducer(const std::tuple<Args...>& args)
|
||||
: Next(args),
|
||||
|
@ -415,8 +415,9 @@ template <class Next>
|
||||
class DeadCodeEliminationReducer
|
||||
: public UniformReducerAdapter<DeadCodeEliminationReducer, Next> {
|
||||
public:
|
||||
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||
|
||||
using Adapter = UniformReducerAdapter<DeadCodeEliminationReducer, Next>;
|
||||
using Next::Asm;
|
||||
|
||||
template <class... Args>
|
||||
explicit DeadCodeEliminationReducer(const std::tuple<Args...>& args)
|
||||
|
@ -45,7 +45,7 @@ struct GraphBuilder {
|
||||
Zone* graph_zone;
|
||||
Zone* phase_zone;
|
||||
Schedule& schedule;
|
||||
Assembler<> assembler;
|
||||
Assembler<reducer_list<>> assembler;
|
||||
Linkage* linkage;
|
||||
SourcePositionTable* source_positions;
|
||||
NodeOriginTable* origins;
|
||||
@ -1121,15 +1121,15 @@ base::Optional<BailoutReason> BuildGraph(JSHeapBroker* broker,
|
||||
Graph* graph, Linkage* linkage,
|
||||
SourcePositionTable* source_positions,
|
||||
NodeOriginTable* origins) {
|
||||
GraphBuilder builder{
|
||||
broker,
|
||||
graph_zone,
|
||||
phase_zone,
|
||||
*schedule,
|
||||
Assembler<>(*graph, *graph, phase_zone, nullptr, std::tuple<>{}),
|
||||
linkage,
|
||||
source_positions,
|
||||
origins};
|
||||
GraphBuilder builder{broker,
|
||||
graph_zone,
|
||||
phase_zone,
|
||||
*schedule,
|
||||
Assembler<reducer_list<>>(*graph, *graph, phase_zone,
|
||||
nullptr, std::tuple<>{}),
|
||||
linkage,
|
||||
source_positions,
|
||||
origins};
|
||||
return builder.Run();
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
namespace v8::internal::compiler::turboshaft {
|
||||
|
||||
template <template <class> class... Reducers>
|
||||
template <class Reducers>
|
||||
class Assembler;
|
||||
|
||||
// `OperationBuffer` is a growable, Zone-allocated buffer to store Turboshaft
|
||||
@ -405,7 +405,7 @@ class Block : public RandomAccessStackDominatorNode<Block> {
|
||||
}
|
||||
|
||||
friend class Graph;
|
||||
template <template <class> class... Reducers>
|
||||
template <class Reducers>
|
||||
friend class Assembler;
|
||||
|
||||
Kind kind_;
|
||||
|
@ -46,7 +46,7 @@ class LateEscapeAnalysisAnalyzer {
|
||||
template <class Next>
|
||||
class LateEscapeAnalysisReducer : public Next {
|
||||
public:
|
||||
using Next::Asm;
|
||||
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||
|
||||
template <class... Args>
|
||||
explicit LateEscapeAnalysisReducer(const std::tuple<Args...>& args)
|
||||
|
@ -9,8 +9,8 @@
|
||||
#include "src/compiler/access-builder.h"
|
||||
#include "src/compiler/globals.h"
|
||||
#include "src/compiler/simplified-operator.h"
|
||||
#include "src/compiler/turboshaft/assembler.h"
|
||||
#include "src/compiler/turboshaft/index.h"
|
||||
#include "src/compiler/turboshaft/optimization-phase.h"
|
||||
#include "src/compiler/turboshaft/representations.h"
|
||||
#include "src/objects/bigint.h"
|
||||
|
||||
@ -25,7 +25,8 @@ struct MachineLoweringReducerArgs {
|
||||
template <typename Next>
|
||||
class MachineLoweringReducer : public Next {
|
||||
public:
|
||||
using Next::Asm;
|
||||
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||
|
||||
using ArgT =
|
||||
base::append_tuple_type<typename Next::ArgT, MachineLoweringReducerArgs>;
|
||||
|
||||
|
@ -95,7 +95,8 @@ struct MemoryOptimizationReducerArgs {
|
||||
template <class Next>
|
||||
class MemoryOptimizationReducer : public Next {
|
||||
public:
|
||||
using Next::Asm;
|
||||
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||
|
||||
using ArgT = base::append_tuple_type<typename Next::ArgT,
|
||||
MemoryOptimizationReducerArgs>;
|
||||
|
||||
|
@ -68,10 +68,11 @@ template <template <class> class... Reducers>
|
||||
class OptimizationPhaseImpl {
|
||||
public:
|
||||
static void Run(Graph* input, Zone* phase_zone, NodeOriginTable* origins,
|
||||
const typename Assembler<Reducers...>::ArgT& reducer_args =
|
||||
std::tuple<>{}) {
|
||||
Assembler<Reducers...> phase(*input, input->GetOrCreateCompanion(),
|
||||
phase_zone, origins, reducer_args);
|
||||
const typename Assembler<reducer_list<Reducers...>>::ArgT&
|
||||
reducer_args = std::tuple<>{}) {
|
||||
Assembler<reducer_list<Reducers...>> phase(
|
||||
*input, input->GetOrCreateCompanion(), phase_zone, origins,
|
||||
reducer_args);
|
||||
if (v8_flags.turboshaft_trace_reduction) {
|
||||
phase.template VisitGraph<true>();
|
||||
} else {
|
||||
@ -120,8 +121,8 @@ class OptimizationPhase {
|
||||
public:
|
||||
static void Run(Isolate* isolate, Graph* input, Zone* phase_zone,
|
||||
NodeOriginTable* origins,
|
||||
const typename Assembler<Reducers...>::ArgT& reducer_args =
|
||||
std::tuple<>{}) {
|
||||
const typename Assembler<reducer_list<Reducers...>>::ArgT&
|
||||
reducer_args = std::tuple<>{}) {
|
||||
#ifdef DEBUG
|
||||
if (v8_flags.turboshaft_verify_reductions) {
|
||||
impl_with_verification_t::Run(
|
||||
|
@ -33,7 +33,7 @@ namespace v8::internal::compiler::turboshaft {
|
||||
template <class Next>
|
||||
class SelectLoweringReducer : public Next {
|
||||
public:
|
||||
using Next::Asm;
|
||||
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||
|
||||
template <class... Args>
|
||||
explicit SelectLoweringReducer(const std::tuple<Args...>& args)
|
||||
|
@ -991,7 +991,8 @@ class TypeInferenceReducer : public Next {
|
||||
using table_t = SnapshotTable<Type>;
|
||||
|
||||
public:
|
||||
using Next::Asm;
|
||||
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||
|
||||
using ArgT =
|
||||
base::append_tuple_type<typename Next::ArgT, TypeInferenceReducerArgs>;
|
||||
|
||||
|
@ -16,8 +16,9 @@ template <typename Next>
|
||||
class TypedOptimizationsReducer
|
||||
: public UniformReducerAdapter<TypedOptimizationsReducer, Next> {
|
||||
public:
|
||||
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||
|
||||
using Adapter = UniformReducerAdapter<TypedOptimizationsReducer, Next>;
|
||||
using Next::Asm;
|
||||
|
||||
template <typename... Args>
|
||||
explicit TypedOptimizationsReducer(const std::tuple<Args...>& args)
|
||||
|
@ -19,8 +19,8 @@ namespace v8::internal::compiler::turboshaft {
|
||||
// template <typename Next>
|
||||
// class MyReducer : public UniformReducerAdapter<MyReducer, Next> {
|
||||
// public:
|
||||
// TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||
// using Adapter = UniformReducerAdapter<MyReducer, Next>;
|
||||
// using Next::Asm;
|
||||
//
|
||||
// template <typename... Args>
|
||||
// explicit MyReducer(const std::tuple<Args...>& args)
|
||||
|
@ -71,7 +71,8 @@ namespace turboshaft {
|
||||
template <class Next>
|
||||
class ValueNumberingReducer : public Next {
|
||||
public:
|
||||
using Next::Asm;
|
||||
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||
|
||||
template <class... Args>
|
||||
explicit ValueNumberingReducer(const std::tuple<Args...>& args)
|
||||
: Next(args),
|
||||
|
@ -55,7 +55,7 @@ class VariableReducer : public Next {
|
||||
SnapshotTable<OpIndex, base::Optional<RegisterRepresentation>>::Snapshot;
|
||||
|
||||
public:
|
||||
using Next::Asm;
|
||||
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||
|
||||
template <class... Args>
|
||||
explicit VariableReducer(const std::tuple<Args...>& args)
|
||||
|
Loading…
Reference in New Issue
Block a user