Commit c8a2d899 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[maglev] Move compilation info out of graph processor

Move the CompilationInfo out of the GraphProcessor and into the
individual NodeProcessors, allowing them to hold it as a field rather
than getting it passed in via the various process methods. This will
allow us to write graph processors that don't have/need access to the
compilation info.

Bug: v8:7700
Change-Id: I8b91cbeaf632f05ae8bbbe8783e5a7381b5c8e53
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3892698
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarJakob Linke <jgruber@chromium.org>
Commit-Queue: Jakob Linke <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83179}
parent 10756bea
......@@ -636,7 +636,7 @@ class MaglevCodeGeneratingNodeProcessor {
explicit MaglevCodeGeneratingNodeProcessor(MaglevAssembler* masm)
: masm_(masm) {}
void PreProcessGraph(MaglevCompilationInfo*, Graph* graph) {
void PreProcessGraph(Graph* graph) {
if (FLAG_maglev_break_on_entry) {
__ int3();
}
......@@ -748,7 +748,7 @@ class MaglevCodeGeneratingNodeProcessor {
}
}
void PostProcessGraph(MaglevCompilationInfo*, Graph*) {
void PostProcessGraph(Graph*) {
__ int3();
__ bind(&deferred_call_stack_guard_);
ASM_CODE_COMMENT_STRING(masm(), "Stack/interrupt call");
......@@ -763,7 +763,7 @@ class MaglevCodeGeneratingNodeProcessor {
__ jmp(&deferred_call_stack_guard_return_);
}
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block) {
void PreProcessBasicBlock(BasicBlock* block) {
if (FLAG_code_comments) {
std::stringstream ss;
ss << "-- Block b" << graph_labeller()->BlockId(block);
......@@ -955,7 +955,7 @@ class MaglevCodeGeneratorImpl final {
graph->untagged_stack_slots()),
code_gen_state_(compilation_info, safepoint_table_builder()),
masm_(&code_gen_state_),
processor_(compilation_info, &masm_),
processor_(&masm_),
graph_(graph) {}
MaybeHandle<Code> Generate() {
......
......@@ -26,6 +26,7 @@
#include "src/ic/handler-configuration.h"
#include "src/maglev/maglev-basic-block.h"
#include "src/maglev/maglev-code-generator.h"
#include "src/maglev/maglev-compilation-info.h"
#include "src/maglev/maglev-compilation-unit.h"
#include "src/maglev/maglev-graph-builder.h"
#include "src/maglev/maglev-graph-labeller.h"
......@@ -48,13 +49,12 @@ namespace maglev {
class UseMarkingProcessor {
public:
void PreProcessGraph(MaglevCompilationInfo*, Graph* graph) {
next_node_id_ = kFirstValidNodeId;
}
void PostProcessGraph(MaglevCompilationInfo*, Graph* graph) {
DCHECK(loop_used_nodes_.empty());
}
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block) {
explicit UseMarkingProcessor(MaglevCompilationInfo* compilation_info)
: compilation_info_(compilation_info) {}
void PreProcessGraph(Graph* graph) { next_node_id_ = kFirstValidNodeId; }
void PostProcessGraph(Graph* graph) { DCHECK(loop_used_nodes_.empty()); }
void PreProcessBasicBlock(BasicBlock* block) {
if (!block->has_state()) return;
if (block->state()->is_loop()) {
loop_used_nodes_.push_back(LoopUsedNodes{next_node_id_, {}});
......@@ -121,7 +121,7 @@ class UseMarkingProcessor {
// loop, allow nodes to be "moved" between lifetime extensions.
LoopUsedNodes* outer_loop_used_nodes = GetCurrentLoopUsedNodes();
base::Vector<Input> used_node_inputs =
state.compilation_info()->zone()->NewVector<Input>(
compilation_info_->zone()->NewVector<Input>(
loop_used_nodes.used_nodes.size());
int i = 0;
for (ValueNode* used_node : loop_used_nodes.used_nodes) {
......@@ -228,29 +228,31 @@ class UseMarkingProcessor {
});
}
MaglevCompilationInfo* compilation_info_;
uint32_t next_node_id_;
std::vector<LoopUsedNodes> loop_used_nodes_;
};
class TranslationArrayProcessor {
public:
explicit TranslationArrayProcessor(LocalIsolate* local_isolate)
: local_isolate_(local_isolate) {}
explicit TranslationArrayProcessor(LocalIsolate* local_isolate,
MaglevCompilationInfo* compilation_info)
: local_isolate_(local_isolate), compilation_info_(compilation_info) {}
void PreProcessGraph(MaglevCompilationInfo* compilation_info, Graph* graph) {
void PreProcessGraph(Graph* graph) {
translation_array_builder_.reset(
new TranslationArrayBuilder(compilation_info->zone()));
new TranslationArrayBuilder(compilation_info_->zone()));
deopt_literals_.reset(new IdentityMap<int, base::DefaultAllocationPolicy>(
local_isolate_->heap()->heap()));
tagged_slots_ = graph->tagged_stack_slots();
}
void PostProcessGraph(MaglevCompilationInfo* compilation_info, Graph* graph) {
compilation_info->set_translation_array_builder(
void PostProcessGraph(Graph* graph) {
compilation_info_->set_translation_array_builder(
std::move(translation_array_builder_), std::move(deopt_literals_));
}
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block) {}
void PreProcessBasicBlock(BasicBlock* block) {}
void Process(NodeBase* node, const ProcessingState& state) {
if (node->properties().can_eager_deopt()) {
......@@ -524,6 +526,7 @@ class TranslationArrayProcessor {
}
LocalIsolate* local_isolate_;
MaglevCompilationInfo* compilation_info_;
std::unique_ptr<TranslationArrayBuilder> translation_array_builder_;
std::unique_ptr<IdentityMap<int, base::DefaultAllocationPolicy>>
deopt_literals_;
......@@ -572,7 +575,7 @@ void MaglevCompiler::Compile(LocalIsolate* local_isolate,
{
GraphMultiProcessor<UseMarkingProcessor, MaglevVregAllocator> processor(
compilation_info);
UseMarkingProcessor{compilation_info});
processor.ProcessGraph(graph_builder.graph());
}
......@@ -590,7 +593,7 @@ void MaglevCompiler::Compile(LocalIsolate* local_isolate,
}
GraphProcessor<TranslationArrayProcessor> build_translation_array(
compilation_info, local_isolate);
local_isolate, compilation_info);
build_translation_array.ProcessGraph(graph_builder.graph());
// Stash the compiled graph on the compilation info.
......
......@@ -242,13 +242,14 @@ int MaglevPrintingVisitorOstream::overflow(int c) {
} // namespace
MaglevPrintingVisitor::MaglevPrintingVisitor(std::ostream& os)
: os_(os),
MaglevPrintingVisitor::MaglevPrintingVisitor(
MaglevGraphLabeller* graph_labeller, std::ostream& os)
: graph_labeller_(graph_labeller),
os_(os),
os_for_additional_info_(
new MaglevPrintingVisitorOstream(os_, &targets_)) {}
void MaglevPrintingVisitor::PreProcessGraph(
MaglevCompilationInfo* compilation_info, Graph* graph) {
void MaglevPrintingVisitor::PreProcessGraph(Graph* graph) {
os_ << "Graph\n\n";
for (BasicBlock* block : *graph) {
......@@ -303,10 +304,7 @@ void MaglevPrintingVisitor::PreProcessGraph(
[](BasicBlock* block) { return block == nullptr; }));
}
void MaglevPrintingVisitor::PreProcessBasicBlock(
MaglevCompilationInfo* compilation_info, BasicBlock* block) {
MaglevGraphLabeller* graph_labeller = compilation_info->graph_labeller();
void MaglevPrintingVisitor::PreProcessBasicBlock(BasicBlock* block) {
size_t loop_position = static_cast<size_t>(-1);
if (loop_headers_.erase(block) > 0) {
loop_position = AddTarget(targets_, block);
......@@ -355,7 +353,7 @@ void MaglevPrintingVisitor::PreProcessBasicBlock(
if (FLAG_log_colour) os_ << "\033[0m";
}
int block_id = graph_labeller->BlockId(block);
int block_id = graph_labeller_->BlockId(block);
os_ << "Block b" << block_id;
if (block->is_exception_handler_block()) {
os_ << " (exception handler)";
......@@ -369,10 +367,8 @@ namespace {
template <typename NodeT>
void PrintEagerDeopt(std::ostream& os, std::vector<BasicBlock*> targets,
NodeT* node, const ProcessingState& state,
NodeT* node, MaglevGraphLabeller* graph_labeller,
int max_node_id) {
MaglevGraphLabeller* graph_labeller = state.graph_labeller();
PrintVerticalArrows(os, targets);
PrintPadding(os, graph_labeller, max_node_id, 0);
......@@ -394,15 +390,15 @@ void PrintEagerDeopt(std::ostream& os, std::vector<BasicBlock*> targets,
os << "}\n";
}
void MaybePrintEagerDeopt(std::ostream& os, std::vector<BasicBlock*> targets,
NodeBase* node, const ProcessingState& state,
NodeBase* node, MaglevGraphLabeller* graph_labeller,
int max_node_id) {
switch (node->opcode()) {
#define CASE(Name) \
case Opcode::k##Name: \
if constexpr (Name::kProperties.can_eager_deopt()) { \
PrintEagerDeopt<Name>(os, targets, node->Cast<Name>(), state, \
max_node_id); \
} \
#define CASE(Name) \
case Opcode::k##Name: \
if constexpr (Name::kProperties.can_eager_deopt()) { \
PrintEagerDeopt<Name>(os, targets, node->Cast<Name>(), graph_labeller, \
max_node_id); \
} \
break;
NODE_BASE_LIST(CASE)
#undef CASE
......@@ -411,10 +407,8 @@ void MaybePrintEagerDeopt(std::ostream& os, std::vector<BasicBlock*> targets,
template <typename NodeT>
void PrintLazyDeopt(std::ostream& os, std::vector<BasicBlock*> targets,
NodeT* node, const ProcessingState& state,
NodeT* node, MaglevGraphLabeller* graph_labeller,
int max_node_id) {
MaglevGraphLabeller* graph_labeller = state.graph_labeller();
PrintVerticalArrows(os, targets);
PrintPadding(os, graph_labeller, max_node_id, 0);
......@@ -444,7 +438,8 @@ void PrintLazyDeopt(std::ostream& os, std::vector<BasicBlock*> targets,
template <typename NodeT>
void PrintExceptionHandlerPoint(std::ostream& os,
std::vector<BasicBlock*> targets, NodeT* node,
const ProcessingState& state, int max_node_id) {
MaglevGraphLabeller* graph_labeller,
int max_node_id) {
// If no handler info, then we cannot throw.
ExceptionHandlerInfo* info = node->exception_handler_info();
if (!info->HasExceptionHandler()) return;
......@@ -463,8 +458,6 @@ void PrintExceptionHandlerPoint(std::ostream& os,
auto* liveness = block->state()->frame_state().liveness();
LazyDeoptInfo* deopt_info = node->lazy_deopt_info();
MaglevGraphLabeller* graph_labeller = state.graph_labeller();
PrintVerticalArrows(os, targets);
PrintPadding(os, graph_labeller, max_node_id, 0);
......@@ -489,19 +482,19 @@ void PrintExceptionHandlerPoint(std::ostream& os,
void MaybePrintLazyDeoptOrExceptionHandler(std::ostream& os,
std::vector<BasicBlock*> targets,
NodeBase* node,
const ProcessingState& state,
MaglevGraphLabeller* graph_labeller,
int max_node_id) {
switch (node->opcode()) {
#define CASE(Name) \
case Opcode::k##Name: \
if constexpr (Name::kProperties.can_lazy_deopt()) { \
PrintLazyDeopt<Name>(os, targets, node->Cast<Name>(), state, \
max_node_id); \
} \
if constexpr (Name::kProperties.can_throw()) { \
PrintExceptionHandlerPoint<Name>(os, targets, node->Cast<Name>(), state, \
max_node_id); \
} \
#define CASE(Name) \
case Opcode::k##Name: \
if constexpr (Name::kProperties.can_lazy_deopt()) { \
PrintLazyDeopt<Name>(os, targets, node->Cast<Name>(), graph_labeller, \
max_node_id); \
} \
if constexpr (Name::kProperties.can_throw()) { \
PrintExceptionHandlerPoint<Name>(os, targets, node->Cast<Name>(), \
graph_labeller, max_node_id); \
} \
break;
NODE_BASE_LIST(CASE)
#undef CASE
......@@ -511,10 +504,8 @@ void MaybePrintLazyDeoptOrExceptionHandler(std::ostream& os,
} // namespace
void MaglevPrintingVisitor::Process(Phi* phi, const ProcessingState& state) {
MaglevGraphLabeller* graph_labeller = state.graph_labeller();
PrintVerticalArrows(os_, targets_);
PrintPaddedId(os_, graph_labeller, max_node_id_, phi);
PrintPaddedId(os_, graph_labeller_, max_node_id_, phi);
if (phi->input_count() == 0) {
os_ << "φₑ " << phi->owner().ToString();
} else {
......@@ -524,37 +515,34 @@ void MaglevPrintingVisitor::Process(Phi* phi, const ProcessingState& state) {
// moves).
for (int i = 0; i < phi->input_count(); ++i) {
if (i > 0) os_ << ", ";
os_ << PrintNodeLabel(graph_labeller, phi->input(i).node());
os_ << PrintNodeLabel(graph_labeller_, phi->input(i).node());
}
os_ << ")";
}
os_ << " → " << phi->result().operand() << "\n";
MaglevPrintingVisitorOstream::cast(os_for_additional_info_)
->set_padding(MaxIdWidth(graph_labeller, max_node_id_, 2));
->set_padding(MaxIdWidth(graph_labeller_, max_node_id_, 2));
}
void MaglevPrintingVisitor::Process(Node* node, const ProcessingState& state) {
MaglevGraphLabeller* graph_labeller = state.graph_labeller();
MaybePrintEagerDeopt(os_, targets_, node, state, max_node_id_);
MaybePrintEagerDeopt(os_, targets_, node, graph_labeller_, max_node_id_);
PrintVerticalArrows(os_, targets_);
PrintPaddedId(os_, graph_labeller, max_node_id_, node);
os_ << PrintNode(graph_labeller, node) << "\n";
PrintPaddedId(os_, graph_labeller_, max_node_id_, node);
os_ << PrintNode(graph_labeller_, node) << "\n";
MaglevPrintingVisitorOstream::cast(os_for_additional_info_)
->set_padding(MaxIdWidth(graph_labeller, max_node_id_, 2));
->set_padding(MaxIdWidth(graph_labeller_, max_node_id_, 2));
MaybePrintLazyDeoptOrExceptionHandler(os_, targets_, node, state,
MaybePrintLazyDeoptOrExceptionHandler(os_, targets_, node, graph_labeller_,
max_node_id_);
}
void MaglevPrintingVisitor::Process(ControlNode* control_node,
const ProcessingState& state) {
MaglevGraphLabeller* graph_labeller = state.graph_labeller();
MaybePrintEagerDeopt(os_, targets_, control_node, state, max_node_id_);
MaybePrintEagerDeopt(os_, targets_, control_node, graph_labeller_,
max_node_id_);
bool has_fallthrough = false;
......@@ -563,7 +551,7 @@ void MaglevPrintingVisitor::Process(ControlNode* control_node,
PrintVerticalArrows(os_, targets_, {}, {target}, true);
os_ << "◄─";
PrintPaddedId(os_, graph_labeller, max_node_id_, control_node, "─", -2);
PrintPaddedId(os_, graph_labeller_, max_node_id_, control_node, "─", -2);
std::replace(targets_.begin(), targets_.end(), target,
static_cast<BasicBlock*>(nullptr));
......@@ -575,7 +563,7 @@ void MaglevPrintingVisitor::Process(ControlNode* control_node,
has_fallthrough |= !AddTargetIfNotNext(targets_, target, state.next_block(),
&arrows_starting_here);
PrintVerticalArrows(os_, targets_, arrows_starting_here);
PrintPaddedId(os_, graph_labeller, max_node_id_, control_node,
PrintPaddedId(os_, graph_labeller_, max_node_id_, control_node,
has_fallthrough ? " " : "─");
} else if (control_node->Is<BranchControlNode>()) {
......@@ -590,7 +578,7 @@ void MaglevPrintingVisitor::Process(ControlNode* control_node,
has_fallthrough |= !AddTargetIfNotNext(
targets_, true_target, state.next_block(), &arrows_starting_here);
PrintVerticalArrows(os_, targets_, arrows_starting_here);
PrintPaddedId(os_, graph_labeller, max_node_id_, control_node, "─");
PrintPaddedId(os_, graph_labeller_, max_node_id_, control_node, "─");
} else if (control_node->Is<Switch>()) {
std::set<size_t> arrows_starting_here;
for (int i = 0; i < control_node->Cast<Switch>()->size(); i++) {
......@@ -609,14 +597,14 @@ void MaglevPrintingVisitor::Process(ControlNode* control_node,
}
PrintVerticalArrows(os_, targets_, arrows_starting_here);
PrintPaddedId(os_, graph_labeller, max_node_id_, control_node, "─");
PrintPaddedId(os_, graph_labeller_, max_node_id_, control_node, "─");
} else {
PrintVerticalArrows(os_, targets_);
PrintPaddedId(os_, graph_labeller, max_node_id_, control_node);
PrintPaddedId(os_, graph_labeller_, max_node_id_, control_node);
}
os_ << PrintNode(graph_labeller, control_node) << "\n";
os_ << PrintNode(graph_labeller_, control_node) << "\n";
bool printed_phis = false;
if (control_node->Is<UnconditionalControlNode>()) {
......@@ -625,22 +613,22 @@ void MaglevPrintingVisitor::Process(ControlNode* control_node,
if (target->has_phi()) {
printed_phis = true;
PrintVerticalArrows(os_, targets_);
PrintPadding(os_, graph_labeller, max_node_id_, -1);
PrintPadding(os_, graph_labeller_, max_node_id_, -1);
os_ << (has_fallthrough ? "│" : " ");
os_ << " with gap moves:\n";
int pid = state.block()->predecessor_id();
for (Phi* phi : *target->phis()) {
PrintVerticalArrows(os_, targets_);
PrintPadding(os_, graph_labeller, max_node_id_, -1);
PrintPadding(os_, graph_labeller_, max_node_id_, -1);
os_ << (has_fallthrough ? "│" : " ");
os_ << " - ";
graph_labeller->PrintInput(os_, phi->input(pid));
os_ << " → " << graph_labeller->NodeId(phi) << ": φ "
graph_labeller_->PrintInput(os_, phi->input(pid));
os_ << " → " << graph_labeller_->NodeId(phi) << ": φ "
<< phi->result().operand() << "\n";
}
if (target->state()->register_state().is_initialized()) {
PrintVerticalArrows(os_, targets_);
PrintPadding(os_, graph_labeller, max_node_id_, -1);
PrintPadding(os_, graph_labeller_, max_node_id_, -1);
os_ << (has_fallthrough ? "│" : " ");
os_ << " with register merges:\n";
auto print_register_merges = [&](auto reg, RegisterState& state) {
......@@ -649,7 +637,7 @@ void MaglevPrintingVisitor::Process(ControlNode* control_node,
if (LoadMergeState(state, &node, &merge)) {
compiler::InstructionOperand source = merge->operand(pid);
PrintVerticalArrows(os_, targets_);
PrintPadding(os_, graph_labeller, max_node_id_, -1);
PrintPadding(os_, graph_labeller_, max_node_id_, -1);
os_ << (has_fallthrough ? "│" : " ");
os_ << " - " << source << " → " << reg << "\n";
}
......@@ -664,7 +652,7 @@ void MaglevPrintingVisitor::Process(ControlNode* control_node,
PrintVerticalArrows(os_, targets_);
if (has_fallthrough) {
PrintPadding(os_, graph_labeller, max_node_id_, -1);
PrintPadding(os_, graph_labeller_, max_node_id_, -1);
if (printed_phis) {
os_ << "▼";
} else {
......@@ -676,12 +664,13 @@ void MaglevPrintingVisitor::Process(ControlNode* control_node,
// TODO(leszeks): Allow MaglevPrintingVisitorOstream to print the arrowhead
// so that it overlaps the fallthrough arrow.
MaglevPrintingVisitorOstream::cast(os_for_additional_info_)
->set_padding(MaxIdWidth(graph_labeller, max_node_id_, 2));
->set_padding(MaxIdWidth(graph_labeller_, max_node_id_, 2));
}
void PrintGraph(std::ostream& os, MaglevCompilationInfo* compilation_info,
Graph* const graph) {
GraphProcessor<MaglevPrintingVisitor> printer(compilation_info, os);
GraphProcessor<MaglevPrintingVisitor> printer(
compilation_info->graph_labeller(), os);
printer.ProcessGraph(graph);
}
......
......@@ -28,11 +28,12 @@ class ProcessingState;
class MaglevPrintingVisitor {
public:
explicit MaglevPrintingVisitor(std::ostream& os);
explicit MaglevPrintingVisitor(MaglevGraphLabeller* graph_labeller,
std::ostream& os);
void PreProcessGraph(MaglevCompilationInfo*, Graph* graph);
void PostProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block);
void PreProcessGraph(Graph* graph);
void PostProcessGraph(Graph* graph) {}
void PreProcessBasicBlock(BasicBlock* block);
void Process(Phi* phi, const ProcessingState& state);
void Process(Node* node, const ProcessingState& state);
void Process(ControlNode* node, const ProcessingState& state);
......@@ -40,6 +41,7 @@ class MaglevPrintingVisitor {
std::ostream& os() { return *os_for_additional_info_; }
private:
MaglevGraphLabeller* graph_labeller_;
std::ostream& os_;
std::unique_ptr<std::ostream> os_for_additional_info_;
std::set<BasicBlock*> loop_headers_;
......
......@@ -19,20 +19,19 @@ namespace maglev {
// The GraphProcessor takes a NodeProcessor, and applies it to each Node in the
// Graph by calling NodeProcessor::Process on each Node.
//
// The GraphProcessor also keeps track of the current ProcessingState, including
// the inferred corresponding InterpreterFrameState and (optionally) the state
// at the most recent Checkpoint, and passes this to the Process method.
// The GraphProcessor also keeps track of the current ProcessingState, and
// passes this to the Process method.
//
// It expects a NodeProcessor class with:
//
// // A function that processes the graph before the nodes are walked.
// void PreProcessGraph(MaglevCompilationInfo*, Graph* graph);
// void PreProcessGraph(Graph* graph);
//
// // A function that processes the graph after the nodes are walked.
// void PostProcessGraph(MaglevCompilationInfo*, Graph* graph);
// void PostProcessGraph(Graph* graph);
//
// // A function that processes each basic block before its nodes are walked.
// void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block);
// void PreProcessBasicBlock(BasicBlock* block);
//
// // Process methods for each Node type. The GraphProcessor switches over
// // the Node's opcode, casts it to the appropriate FooNode, and dispatches
......@@ -46,9 +45,7 @@ class GraphProcessor;
class ProcessingState {
public:
explicit ProcessingState(MaglevCompilationInfo* compilation_info,
BlockConstIterator block_it)
: compilation_info_(compilation_info), block_it_(block_it) {}
explicit ProcessingState(BlockConstIterator block_it) : block_it_(block_it) {}
// Disallow copies, since the underlying frame states stay mutable.
ProcessingState(const ProcessingState&) = delete;
......@@ -57,14 +54,7 @@ class ProcessingState {
BasicBlock* block() const { return *block_it_; }
BasicBlock* next_block() const { return *(block_it_ + 1); }
MaglevCompilationInfo* compilation_info() const { return compilation_info_; }
MaglevGraphLabeller* graph_labeller() const {
return compilation_info_->graph_labeller();
}
private:
MaglevCompilationInfo* compilation_info_;
BlockConstIterator block_it_;
};
......@@ -72,15 +62,13 @@ template <typename NodeProcessor>
class GraphProcessor {
public:
template <typename... Args>
explicit GraphProcessor(MaglevCompilationInfo* compilation_info,
Args&&... args)
: compilation_info_(compilation_info),
node_processor_(std::forward<Args>(args)...) {}
explicit GraphProcessor(Args&&... args)
: node_processor_(std::forward<Args>(args)...) {}
void ProcessGraph(Graph* graph) {
graph_ = graph;
node_processor_.PreProcessGraph(compilation_info_, graph);
node_processor_.PreProcessGraph(graph);
for (const auto& [ref, constant] : graph->constants()) {
node_processor_.Process(constant, GetCurrentState());
......@@ -106,7 +94,7 @@ class GraphProcessor {
for (block_it_ = graph->begin(); block_it_ != graph->end(); ++block_it_) {
BasicBlock* block = *block_it_;
node_processor_.PreProcessBasicBlock(compilation_info_, block);
node_processor_.PreProcessBasicBlock(block);
if (block->has_phi()) {
for (Phi* phi : *block->phis()) {
......@@ -123,16 +111,14 @@ class GraphProcessor {
ProcessNodeBase(block->control_node(), GetCurrentState());
}
node_processor_.PostProcessGraph(compilation_info_, graph);
node_processor_.PostProcessGraph(graph);
}
NodeProcessor& node_processor() { return node_processor_; }
const NodeProcessor& node_processor() const { return node_processor_; }
private:
ProcessingState GetCurrentState() {
return ProcessingState(compilation_info_, block_it_);
}
ProcessingState GetCurrentState() { return ProcessingState(block_it_); }
void ProcessNodeBase(NodeBase* node, const ProcessingState& state) {
switch (node->opcode()) {
......@@ -148,7 +134,6 @@ class GraphProcessor {
void PreProcess(NodeBase* node, const ProcessingState& state) {}
MaglevCompilationInfo* const compilation_info_;
NodeProcessor node_processor_;
Graph* graph_;
BlockConstIterator block_it_;
......@@ -163,9 +148,9 @@ class NodeMultiProcessor;
template <>
class NodeMultiProcessor<> {
public:
void PreProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
void PostProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block) {}
void PreProcessGraph(Graph* graph) {}
void PostProcessGraph(Graph* graph) {}
void PreProcessBasicBlock(BasicBlock* block) {}
void Process(NodeBase* node, const ProcessingState& state) {}
};
......@@ -175,23 +160,31 @@ class NodeMultiProcessor<Processor, Processors...>
using Base = NodeMultiProcessor<Processors...>;
public:
template <typename... Args>
explicit NodeMultiProcessor(Processor&& processor, Args&&... processors)
: Base(std::forward<Args>(processors)...),
processor_(std::forward<Processor>(processor)) {}
template <typename... Args>
explicit NodeMultiProcessor(Args&&... processors)
: Base(std::forward<Args>(processors)...) {}
template <typename Node>
void Process(Node* node, const ProcessingState& state) {
processor_.Process(node, state);
Base::Process(node, state);
}
void PreProcessGraph(MaglevCompilationInfo* info, Graph* graph) {
processor_.PreProcessGraph(info, graph);
Base::PreProcessGraph(info, graph);
void PreProcessGraph(Graph* graph) {
processor_.PreProcessGraph(graph);
Base::PreProcessGraph(graph);
}
void PostProcessGraph(MaglevCompilationInfo* info, Graph* graph) {
void PostProcessGraph(Graph* graph) {
// Post process in reverse order because that kind of makes sense.
Base::PostProcessGraph(info, graph);
processor_.PostProcessGraph(info, graph);
Base::PostProcessGraph(graph);
processor_.PostProcessGraph(graph);
}
void PreProcessBasicBlock(MaglevCompilationInfo* info, BasicBlock* block) {
processor_.PreProcessBasicBlock(info, block);
Base::PreProcessBasicBlock(info, block);
void PreProcessBasicBlock(BasicBlock* block) {
processor_.PreProcessBasicBlock(block);
Base::PreProcessBasicBlock(block);
}
private:
......
......@@ -49,14 +49,15 @@ class Graph;
// are expected to be tagged/untagged. Add more verification later.
class MaglevGraphVerifier {
public:
void PreProcessGraph(MaglevCompilationInfo* compilation_info, Graph* graph) {
explicit MaglevGraphVerifier(MaglevCompilationInfo* compilation_info) {
if (compilation_info->has_graph_labeller()) {
graph_labeller_ = compilation_info->graph_labeller();
}
}
void PostProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block) {}
void PreProcessGraph(Graph* graph) {}
void PostProcessGraph(Graph* graph) {}
void PreProcessBasicBlock(BasicBlock* block) {}
void CheckValueInputIs(NodeBase* node, int i, ValueRepresentation expected) {
ValueNode* input = node->input(i).node();
......
......@@ -284,8 +284,9 @@ void StraightForwardRegisterAllocator::PrintLiveRegs() const {
void StraightForwardRegisterAllocator::AllocateRegisters() {
if (FLAG_trace_maglev_regalloc) {
printing_visitor_.reset(new MaglevPrintingVisitor(std::cout));
printing_visitor_->PreProcessGraph(compilation_info_, graph_);
printing_visitor_.reset(new MaglevPrintingVisitor(
compilation_info_->graph_labeller(), std::cout));
printing_visitor_->PreProcessGraph(graph_);
}
for (const auto& [ref, constant] : graph_->constants()) {
......@@ -326,7 +327,7 @@ void StraightForwardRegisterAllocator::AllocateRegisters() {
}
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->PreProcessBasicBlock(compilation_info_, block);
printing_visitor_->PreProcessBasicBlock(block);
printing_visitor_->os() << "live regs: ";
PrintLiveRegs();
......@@ -390,8 +391,7 @@ void StraightForwardRegisterAllocator::AllocateRegisters() {
if (phi->owner() == interpreter::Register::virtual_accumulator()) {
phi->result().SetAllocated(ForceAllocate(kReturnRegister0, phi));
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(
phi, ProcessingState(compilation_info_, block_it_));
printing_visitor_->Process(phi, ProcessingState(block_it_));
printing_visitor_->os() << "phi (exception message object) "
<< phi->result().operand() << std::endl;
}
......@@ -411,8 +411,7 @@ void StraightForwardRegisterAllocator::AllocateRegisters() {
general_registers_.AllocateRegister(phi);
phi->result().SetAllocated(allocation);
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(
phi, ProcessingState(compilation_info_, block_it_));
printing_visitor_->Process(phi, ProcessingState(block_it_));
printing_visitor_->os()
<< "phi (new reg) " << phi->result().operand() << std::endl;
}
......@@ -429,8 +428,7 @@ void StraightForwardRegisterAllocator::AllocateRegisters() {
// TODO(verwaest): Will this be used at all?
phi->result().SetAllocated(phi->spill_slot());
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(
phi, ProcessingState(compilation_info_, block_it_));
printing_visitor_->Process(phi, ProcessingState(block_it_));
printing_visitor_->os()
<< "phi (stack) " << phi->result().operand() << std::endl;
}
......@@ -606,8 +604,7 @@ void StraightForwardRegisterAllocator::AllocateNode(Node* node) {
if (node->properties().needs_register_snapshot()) SaveRegisterSnapshot(node);
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(node,
ProcessingState(compilation_info_, block_it_));
printing_visitor_->Process(node, ProcessingState(block_it_));
printing_visitor_->os() << "live regs: ";
PrintLiveRegs();
printing_visitor_->os() << "\n";
......@@ -880,8 +877,7 @@ void StraightForwardRegisterAllocator::AllocateControlNode(ControlNode* node,
DCHECK_EQ(node->properties(), OpProperties(0));
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(node,
ProcessingState(compilation_info_, block_it_));
printing_visitor_->Process(node, ProcessingState(block_it_));
}
} else if (node->Is<Deopt>()) {
// No fixed temporaries.
......@@ -893,8 +889,7 @@ void StraightForwardRegisterAllocator::AllocateControlNode(ControlNode* node,
UpdateUse(*node->eager_deopt_info());
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(node,
ProcessingState(compilation_info_, block_it_));
printing_visitor_->Process(node, ProcessingState(block_it_));
}
} else if (auto unconditional = node->TryCast<UnconditionalControlNode>()) {
// No fixed temporaries.
......@@ -932,8 +927,7 @@ void StraightForwardRegisterAllocator::AllocateControlNode(ControlNode* node,
}
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(node,
ProcessingState(compilation_info_, block_it_));
printing_visitor_->Process(node, ProcessingState(block_it_));
}
} else {
DCHECK(node->Is<ConditionalControlNode>() || node->Is<Return>());
......@@ -956,8 +950,7 @@ void StraightForwardRegisterAllocator::AllocateControlNode(ControlNode* node,
VerifyRegisterState();
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(node,
ProcessingState(compilation_info_, block_it_));
printing_visitor_->Process(node, ProcessingState(block_it_));
}
// Finally, initialize the merge states of branch targets, including the
......@@ -991,8 +984,7 @@ void StraightForwardRegisterAllocator::TryAllocateToInput(Phi* phi) {
phi->result().SetAllocated(ForceAllocate(reg, phi));
DCHECK_EQ(general_registers_.GetValue(reg), phi);
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(
phi, ProcessingState(compilation_info_, block_it_));
printing_visitor_->Process(phi, ProcessingState(block_it_));
printing_visitor_->os()
<< "phi (reuse) " << input.operand() << std::endl;
}
......
......@@ -26,8 +26,8 @@ class MaglevVregAllocationState {
class MaglevVregAllocator {
public:
void PreProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
void PostProcessGraph(MaglevCompilationInfo*, Graph* graph) {
void PreProcessGraph(Graph* graph) {}
void PostProcessGraph(Graph* graph) {
for (BasicBlock* block : *graph) {
if (!block->has_phi()) continue;
for (Phi* phi : *block->phis()) {
......@@ -35,7 +35,7 @@ class MaglevVregAllocator {
}
}
}
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block) {}
void PreProcessBasicBlock(BasicBlock* block) {}
#define DEF_PROCESS_NODE(NAME) \
void Process(NAME* node, const ProcessingState& state) { \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment