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.
......
This diff is collapsed.
......@@ -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