[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;
|
using FirstReducer<ReducerStack<Assembler, Reducers...>>::FirstReducer;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Assembler>
|
template <class Reducers>
|
||||||
class ReducerStack<Assembler> {
|
class ReducerStack<Assembler<Reducers>> {
|
||||||
public:
|
public:
|
||||||
using AssemblerType = Assembler;
|
using AssemblerType = Assembler<Reducers>;
|
||||||
Assembler& Asm() { return *static_cast<Assembler*>(this); }
|
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>
|
template <typename Next>
|
||||||
class ReducerBase;
|
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
|
// LABEL_BLOCK is used in Reducers to have a single call forwarding to the next
|
||||||
// reducer without change. A typical use would be:
|
// reducer without change. A typical use would be:
|
||||||
//
|
//
|
||||||
@ -101,9 +117,9 @@ class ReducerBaseForwarder : public Next {
|
|||||||
template <class Next>
|
template <class Next>
|
||||||
class ReducerBase : public ReducerBaseForwarder<Next> {
|
class ReducerBase : public ReducerBaseForwarder<Next> {
|
||||||
public:
|
public:
|
||||||
using Next::Asm;
|
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||||
using Base = ReducerBaseForwarder<Next>;
|
|
||||||
|
|
||||||
|
using Base = ReducerBaseForwarder<Next>;
|
||||||
using ArgT = std::tuple<>;
|
using ArgT = std::tuple<>;
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
@ -1047,24 +1063,18 @@ class AssemblerOpInterface {
|
|||||||
Assembler& stack() { return *static_cast<Assembler*>(this); }
|
Assembler& stack() { return *static_cast<Assembler*>(this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <template <class> class... Reducers>
|
template <class Reducers>
|
||||||
class Assembler
|
class Assembler : public GraphVisitor<Assembler<Reducers>>,
|
||||||
: public GraphVisitor<Assembler<Reducers...>>,
|
public reducer_stack_type<Reducers>::type,
|
||||||
public ReducerStack<Assembler<Reducers...>, Reducers...,
|
public OperationMatching<Assembler<Reducers>>,
|
||||||
v8::internal::compiler::turboshaft::ReducerBase>,
|
public AssemblerOpInterface<Assembler<Reducers>> {
|
||||||
public OperationMatching<Assembler<Reducers...>>,
|
using Stack = typename reducer_stack_type<Reducers>::type;
|
||||||
public AssemblerOpInterface<Assembler<Reducers...>> {
|
|
||||||
using Stack = ReducerStack<Assembler<Reducers...>, Reducers...,
|
|
||||||
v8::internal::compiler::turboshaft::ReducerBase>;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <class... ReducerArgs>
|
template <class... ReducerArgs>
|
||||||
explicit Assembler(
|
explicit Assembler(Graph& input_graph, Graph& output_graph, Zone* phase_zone,
|
||||||
Graph& input_graph, Graph& output_graph, Zone* phase_zone,
|
compiler::NodeOriginTable* origins,
|
||||||
compiler::NodeOriginTable* origins,
|
const typename Stack::ArgT& reducer_args)
|
||||||
const typename ReducerStack<
|
|
||||||
Assembler<Reducers...>, Reducers...,
|
|
||||||
v8::internal::compiler::turboshaft::ReducerBase>::ArgT& reducer_args)
|
|
||||||
: GraphVisitor<Assembler>(input_graph, output_graph, phase_zone, origins),
|
: GraphVisitor<Assembler>(input_graph, output_graph, phase_zone, origins),
|
||||||
Stack(reducer_args) {
|
Stack(reducer_args) {
|
||||||
SupportedOperations::Initialize();
|
SupportedOperations::Initialize();
|
||||||
@ -1075,7 +1085,7 @@ class Assembler
|
|||||||
Block* NewLoopHeader() { return this->output_graph().NewLoopHeader(); }
|
Block* NewLoopHeader() { return this->output_graph().NewLoopHeader(); }
|
||||||
Block* NewBlock() { return this->output_graph().NewBlock(); }
|
Block* NewBlock() { return this->output_graph().NewBlock(); }
|
||||||
|
|
||||||
using OperationMatching<Assembler<Reducers...>>::Get;
|
using OperationMatching<Assembler<Reducers>>::Get;
|
||||||
using Stack::Get;
|
using Stack::Get;
|
||||||
|
|
||||||
V8_INLINE V8_WARN_UNUSED_RESULT bool Bind(Block* block,
|
V8_INLINE V8_WARN_UNUSED_RESULT bool Bind(Block* block,
|
||||||
|
@ -37,7 +37,8 @@ struct AssertTypesReducerArgs {
|
|||||||
template <class Next>
|
template <class Next>
|
||||||
class AssertTypesReducer : public Next {
|
class AssertTypesReducer : public Next {
|
||||||
public:
|
public:
|
||||||
using Next::Asm;
|
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||||
|
|
||||||
using ArgT =
|
using ArgT =
|
||||||
base::append_tuple_type<typename Next::ArgT, AssertTypesReducerArgs>;
|
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
|
// 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.
|
// optimization will replace its final Branch by a Goto when reaching it.
|
||||||
public:
|
public:
|
||||||
using Next::Asm;
|
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
explicit BranchEliminationReducer(const std::tuple<Args...>& args)
|
explicit BranchEliminationReducer(const std::tuple<Args...>& args)
|
||||||
: Next(args),
|
: Next(args),
|
||||||
|
@ -415,8 +415,9 @@ template <class Next>
|
|||||||
class DeadCodeEliminationReducer
|
class DeadCodeEliminationReducer
|
||||||
: public UniformReducerAdapter<DeadCodeEliminationReducer, Next> {
|
: public UniformReducerAdapter<DeadCodeEliminationReducer, Next> {
|
||||||
public:
|
public:
|
||||||
|
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||||
|
|
||||||
using Adapter = UniformReducerAdapter<DeadCodeEliminationReducer, Next>;
|
using Adapter = UniformReducerAdapter<DeadCodeEliminationReducer, Next>;
|
||||||
using Next::Asm;
|
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
explicit DeadCodeEliminationReducer(const std::tuple<Args...>& args)
|
explicit DeadCodeEliminationReducer(const std::tuple<Args...>& args)
|
||||||
|
@ -45,7 +45,7 @@ struct GraphBuilder {
|
|||||||
Zone* graph_zone;
|
Zone* graph_zone;
|
||||||
Zone* phase_zone;
|
Zone* phase_zone;
|
||||||
Schedule& schedule;
|
Schedule& schedule;
|
||||||
Assembler<> assembler;
|
Assembler<reducer_list<>> assembler;
|
||||||
Linkage* linkage;
|
Linkage* linkage;
|
||||||
SourcePositionTable* source_positions;
|
SourcePositionTable* source_positions;
|
||||||
NodeOriginTable* origins;
|
NodeOriginTable* origins;
|
||||||
@ -1121,15 +1121,15 @@ base::Optional<BailoutReason> BuildGraph(JSHeapBroker* broker,
|
|||||||
Graph* graph, Linkage* linkage,
|
Graph* graph, Linkage* linkage,
|
||||||
SourcePositionTable* source_positions,
|
SourcePositionTable* source_positions,
|
||||||
NodeOriginTable* origins) {
|
NodeOriginTable* origins) {
|
||||||
GraphBuilder builder{
|
GraphBuilder builder{broker,
|
||||||
broker,
|
graph_zone,
|
||||||
graph_zone,
|
phase_zone,
|
||||||
phase_zone,
|
*schedule,
|
||||||
*schedule,
|
Assembler<reducer_list<>>(*graph, *graph, phase_zone,
|
||||||
Assembler<>(*graph, *graph, phase_zone, nullptr, std::tuple<>{}),
|
nullptr, std::tuple<>{}),
|
||||||
linkage,
|
linkage,
|
||||||
source_positions,
|
source_positions,
|
||||||
origins};
|
origins};
|
||||||
return builder.Run();
|
return builder.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
namespace v8::internal::compiler::turboshaft {
|
namespace v8::internal::compiler::turboshaft {
|
||||||
|
|
||||||
template <template <class> class... Reducers>
|
template <class Reducers>
|
||||||
class Assembler;
|
class Assembler;
|
||||||
|
|
||||||
// `OperationBuffer` is a growable, Zone-allocated buffer to store Turboshaft
|
// `OperationBuffer` is a growable, Zone-allocated buffer to store Turboshaft
|
||||||
@ -405,7 +405,7 @@ class Block : public RandomAccessStackDominatorNode<Block> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
friend class Graph;
|
friend class Graph;
|
||||||
template <template <class> class... Reducers>
|
template <class Reducers>
|
||||||
friend class Assembler;
|
friend class Assembler;
|
||||||
|
|
||||||
Kind kind_;
|
Kind kind_;
|
||||||
|
@ -46,7 +46,7 @@ class LateEscapeAnalysisAnalyzer {
|
|||||||
template <class Next>
|
template <class Next>
|
||||||
class LateEscapeAnalysisReducer : public Next {
|
class LateEscapeAnalysisReducer : public Next {
|
||||||
public:
|
public:
|
||||||
using Next::Asm;
|
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
explicit LateEscapeAnalysisReducer(const std::tuple<Args...>& args)
|
explicit LateEscapeAnalysisReducer(const std::tuple<Args...>& args)
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
#include "src/compiler/access-builder.h"
|
#include "src/compiler/access-builder.h"
|
||||||
#include "src/compiler/globals.h"
|
#include "src/compiler/globals.h"
|
||||||
#include "src/compiler/simplified-operator.h"
|
#include "src/compiler/simplified-operator.h"
|
||||||
|
#include "src/compiler/turboshaft/assembler.h"
|
||||||
#include "src/compiler/turboshaft/index.h"
|
#include "src/compiler/turboshaft/index.h"
|
||||||
#include "src/compiler/turboshaft/optimization-phase.h"
|
|
||||||
#include "src/compiler/turboshaft/representations.h"
|
#include "src/compiler/turboshaft/representations.h"
|
||||||
#include "src/objects/bigint.h"
|
#include "src/objects/bigint.h"
|
||||||
|
|
||||||
@ -25,7 +25,8 @@ struct MachineLoweringReducerArgs {
|
|||||||
template <typename Next>
|
template <typename Next>
|
||||||
class MachineLoweringReducer : public Next {
|
class MachineLoweringReducer : public Next {
|
||||||
public:
|
public:
|
||||||
using Next::Asm;
|
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||||
|
|
||||||
using ArgT =
|
using ArgT =
|
||||||
base::append_tuple_type<typename Next::ArgT, MachineLoweringReducerArgs>;
|
base::append_tuple_type<typename Next::ArgT, MachineLoweringReducerArgs>;
|
||||||
|
|
||||||
|
@ -95,7 +95,8 @@ struct MemoryOptimizationReducerArgs {
|
|||||||
template <class Next>
|
template <class Next>
|
||||||
class MemoryOptimizationReducer : public Next {
|
class MemoryOptimizationReducer : public Next {
|
||||||
public:
|
public:
|
||||||
using Next::Asm;
|
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||||
|
|
||||||
using ArgT = base::append_tuple_type<typename Next::ArgT,
|
using ArgT = base::append_tuple_type<typename Next::ArgT,
|
||||||
MemoryOptimizationReducerArgs>;
|
MemoryOptimizationReducerArgs>;
|
||||||
|
|
||||||
|
@ -68,10 +68,11 @@ template <template <class> class... Reducers>
|
|||||||
class OptimizationPhaseImpl {
|
class OptimizationPhaseImpl {
|
||||||
public:
|
public:
|
||||||
static void Run(Graph* input, Zone* phase_zone, NodeOriginTable* origins,
|
static void Run(Graph* input, Zone* phase_zone, NodeOriginTable* origins,
|
||||||
const typename Assembler<Reducers...>::ArgT& reducer_args =
|
const typename Assembler<reducer_list<Reducers...>>::ArgT&
|
||||||
std::tuple<>{}) {
|
reducer_args = std::tuple<>{}) {
|
||||||
Assembler<Reducers...> phase(*input, input->GetOrCreateCompanion(),
|
Assembler<reducer_list<Reducers...>> phase(
|
||||||
phase_zone, origins, reducer_args);
|
*input, input->GetOrCreateCompanion(), phase_zone, origins,
|
||||||
|
reducer_args);
|
||||||
if (v8_flags.turboshaft_trace_reduction) {
|
if (v8_flags.turboshaft_trace_reduction) {
|
||||||
phase.template VisitGraph<true>();
|
phase.template VisitGraph<true>();
|
||||||
} else {
|
} else {
|
||||||
@ -120,8 +121,8 @@ class OptimizationPhase {
|
|||||||
public:
|
public:
|
||||||
static void Run(Isolate* isolate, Graph* input, Zone* phase_zone,
|
static void Run(Isolate* isolate, Graph* input, Zone* phase_zone,
|
||||||
NodeOriginTable* origins,
|
NodeOriginTable* origins,
|
||||||
const typename Assembler<Reducers...>::ArgT& reducer_args =
|
const typename Assembler<reducer_list<Reducers...>>::ArgT&
|
||||||
std::tuple<>{}) {
|
reducer_args = std::tuple<>{}) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (v8_flags.turboshaft_verify_reductions) {
|
if (v8_flags.turboshaft_verify_reductions) {
|
||||||
impl_with_verification_t::Run(
|
impl_with_verification_t::Run(
|
||||||
|
@ -33,7 +33,7 @@ namespace v8::internal::compiler::turboshaft {
|
|||||||
template <class Next>
|
template <class Next>
|
||||||
class SelectLoweringReducer : public Next {
|
class SelectLoweringReducer : public Next {
|
||||||
public:
|
public:
|
||||||
using Next::Asm;
|
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
explicit SelectLoweringReducer(const std::tuple<Args...>& args)
|
explicit SelectLoweringReducer(const std::tuple<Args...>& args)
|
||||||
|
@ -991,7 +991,8 @@ class TypeInferenceReducer : public Next {
|
|||||||
using table_t = SnapshotTable<Type>;
|
using table_t = SnapshotTable<Type>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using Next::Asm;
|
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||||
|
|
||||||
using ArgT =
|
using ArgT =
|
||||||
base::append_tuple_type<typename Next::ArgT, TypeInferenceReducerArgs>;
|
base::append_tuple_type<typename Next::ArgT, TypeInferenceReducerArgs>;
|
||||||
|
|
||||||
|
@ -16,8 +16,9 @@ template <typename Next>
|
|||||||
class TypedOptimizationsReducer
|
class TypedOptimizationsReducer
|
||||||
: public UniformReducerAdapter<TypedOptimizationsReducer, Next> {
|
: public UniformReducerAdapter<TypedOptimizationsReducer, Next> {
|
||||||
public:
|
public:
|
||||||
|
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||||
|
|
||||||
using Adapter = UniformReducerAdapter<TypedOptimizationsReducer, Next>;
|
using Adapter = UniformReducerAdapter<TypedOptimizationsReducer, Next>;
|
||||||
using Next::Asm;
|
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
explicit TypedOptimizationsReducer(const std::tuple<Args...>& args)
|
explicit TypedOptimizationsReducer(const std::tuple<Args...>& args)
|
||||||
|
@ -19,8 +19,8 @@ namespace v8::internal::compiler::turboshaft {
|
|||||||
// template <typename Next>
|
// template <typename Next>
|
||||||
// class MyReducer : public UniformReducerAdapter<MyReducer, Next> {
|
// class MyReducer : public UniformReducerAdapter<MyReducer, Next> {
|
||||||
// public:
|
// public:
|
||||||
|
// TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||||
// using Adapter = UniformReducerAdapter<MyReducer, Next>;
|
// using Adapter = UniformReducerAdapter<MyReducer, Next>;
|
||||||
// using Next::Asm;
|
|
||||||
//
|
//
|
||||||
// template <typename... Args>
|
// template <typename... Args>
|
||||||
// explicit MyReducer(const std::tuple<Args...>& args)
|
// explicit MyReducer(const std::tuple<Args...>& args)
|
||||||
|
@ -71,7 +71,8 @@ namespace turboshaft {
|
|||||||
template <class Next>
|
template <class Next>
|
||||||
class ValueNumberingReducer : public Next {
|
class ValueNumberingReducer : public Next {
|
||||||
public:
|
public:
|
||||||
using Next::Asm;
|
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
explicit ValueNumberingReducer(const std::tuple<Args...>& args)
|
explicit ValueNumberingReducer(const std::tuple<Args...>& args)
|
||||||
: Next(args),
|
: Next(args),
|
||||||
|
@ -55,7 +55,7 @@ class VariableReducer : public Next {
|
|||||||
SnapshotTable<OpIndex, base::Optional<RegisterRepresentation>>::Snapshot;
|
SnapshotTable<OpIndex, base::Optional<RegisterRepresentation>>::Snapshot;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using Next::Asm;
|
TURBOSHAFT_REDUCER_BOILERPLATE()
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
explicit VariableReducer(const std::tuple<Args...>& args)
|
explicit VariableReducer(const std::tuple<Args...>& args)
|
||||||
|
Loading…
Reference in New Issue
Block a user