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

[maglev] Pass MaglevCompilationInfo to more passes

MaglevCompilationInfo stores the overall compilation information (zone,
graph, labeller, etc.), while MaglevCompilationUnit stores per-function
information (function, bytecode analysis, register count, etc.).

Without inlining, these are 1:1 and we've been pretty sloppy in deciding
which to pass around. Once we implement inlining though, we want to be
careful to pass MaglevCompilationInfo where we're processing the whole
graph, and MaglevCompilationUnit where we're processing something
function-specific.

This does the pre-work of cleaning this up in preparation for inlining.

Bug: v8:7700
Change-Id: Ic50fdd97e56f6c963ab490bd419eb65fe0873688
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3596162
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80051}
parent 58fb7d8f
......@@ -13,7 +13,7 @@
#include "src/common/globals.h"
#include "src/compiler/backend/instruction.h"
#include "src/compiler/js-heap-broker.h"
#include "src/maglev/maglev-compilation-unit.h"
#include "src/maglev/maglev-compilation-info.h"
#include "src/maglev/maglev-ir.h"
namespace v8 {
......@@ -32,9 +32,9 @@ class DeferredCodeInfo {
class MaglevCodeGenState {
public:
MaglevCodeGenState(MaglevCompilationUnit* compilation_unit,
MaglevCodeGenState(MaglevCompilationInfo* compilation_info,
SafepointTableBuilder* safepoint_table_builder)
: compilation_unit_(compilation_unit),
: compilation_info_(compilation_info),
safepoint_table_builder_(safepoint_table_builder),
masm_(isolate(), CodeObjectRequired::kNo) {}
......@@ -61,25 +61,17 @@ class MaglevCodeGenState {
compiler::NativeContextRef native_context() const {
return broker()->target_native_context();
}
Isolate* isolate() const { return compilation_unit_->isolate(); }
int parameter_count() const { return compilation_unit_->parameter_count(); }
int register_count() const { return compilation_unit_->register_count(); }
const compiler::BytecodeAnalysis& bytecode_analysis() const {
return compilation_unit_->bytecode_analysis();
}
compiler::JSHeapBroker* broker() const { return compilation_unit_->broker(); }
const compiler::BytecodeArrayRef& bytecode() const {
return compilation_unit_->bytecode();
}
Isolate* isolate() const { return compilation_info_->isolate(); }
compiler::JSHeapBroker* broker() const { return compilation_info_->broker(); }
MaglevGraphLabeller* graph_labeller() const {
return compilation_unit_->graph_labeller();
return compilation_info_->graph_labeller();
}
MacroAssembler* masm() { return &masm_; }
int stack_slots() const { return untagged_slots_ + tagged_slots_; }
SafepointTableBuilder* safepoint_table_builder() const {
return safepoint_table_builder_;
}
MaglevCompilationUnit* compilation_unit() const { return compilation_unit_; }
MaglevCompilationInfo* compilation_info() const { return compilation_info_; }
// TODO(v8:7700): Clean up after all code paths are supported.
void set_found_unsupported_code_paths(bool val) {
......@@ -121,7 +113,7 @@ class MaglevCodeGenState {
index * kSystemPointerSize;
}
MaglevCompilationUnit* const compilation_unit_;
MaglevCompilationInfo* const compilation_info_;
SafepointTableBuilder* const safepoint_table_builder_;
MacroAssembler masm_;
......
......@@ -47,7 +47,7 @@ class MaglevCodeGeneratingNodeProcessor {
explicit MaglevCodeGeneratingNodeProcessor(MaglevCodeGenState* code_gen_state)
: code_gen_state_(code_gen_state) {}
void PreProcessGraph(MaglevCompilationUnit*, Graph* graph) {
void PreProcessGraph(MaglevCompilationInfo*, Graph* graph) {
if (FLAG_maglev_break_on_entry) {
__ int3();
}
......@@ -87,9 +87,9 @@ class MaglevCodeGeneratingNodeProcessor {
code_gen_state_->DefineSafepointStackSlots(safepoint);
}
void PostProcessGraph(MaglevCompilationUnit*, Graph*) {}
void PostProcessGraph(MaglevCompilationInfo*, Graph*) {}
void PreProcessBasicBlock(MaglevCompilationUnit*, BasicBlock* block) {
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block) {
if (FLAG_code_comments) {
std::stringstream ss;
ss << "-- Block b" << graph_labeller()->BlockId(block);
......@@ -312,20 +312,20 @@ class MaglevCodeGeneratingNodeProcessor {
class MaglevCodeGeneratorImpl final {
public:
static MaybeHandle<Code> Generate(MaglevCompilationUnit* compilation_unit,
static MaybeHandle<Code> Generate(MaglevCompilationInfo* compilation_info,
Graph* graph) {
return MaglevCodeGeneratorImpl(compilation_unit, graph).Generate();
return MaglevCodeGeneratorImpl(compilation_info, graph).Generate();
}
private:
static constexpr int kFunctionLiteralIndex = 0;
static constexpr int kOptimizedOutConstantIndex = 1;
MaglevCodeGeneratorImpl(MaglevCompilationUnit* compilation_unit, Graph* graph)
: safepoint_table_builder_(compilation_unit->zone()),
translation_array_builder_(compilation_unit->zone()),
code_gen_state_(compilation_unit, safepoint_table_builder()),
processor_(compilation_unit, &code_gen_state_),
MaglevCodeGeneratorImpl(MaglevCompilationInfo* compilation_info, Graph* graph)
: safepoint_table_builder_(compilation_info->zone()),
translation_array_builder_(compilation_info->zone()),
code_gen_state_(compilation_info, safepoint_table_builder()),
processor_(compilation_info, &code_gen_state_),
graph_(graph) {}
MaybeHandle<Code> Generate() {
......@@ -388,17 +388,20 @@ class MaglevCodeGeneratorImpl final {
deopt_info->deopt_index = translation_array_builder_.BeginTranslation(
frame_count, jsframe_count, update_feedback_count);
const MaglevCompilationUnit& compilation_unit =
*code_gen_state_.compilation_info()->toplevel_compilation_unit();
// Returns are used for updating an accumulator or register after a lazy
// deopt.
const int return_offset = 0;
const int return_count = 0;
translation_array_builder_.BeginInterpretedFrame(
deopt_info->state.bytecode_position, kFunctionLiteralIndex,
code_gen_state_.register_count(), return_offset, return_count);
compilation_unit.register_count(), return_offset, return_count);
EmitDeoptFrameValues(
*code_gen_state_.compilation_unit(), deopt_info->state.register_frame,
deopt_info->input_locations, interpreter::Register::invalid_value());
EmitDeoptFrameValues(compilation_unit, deopt_info->state.register_frame,
deopt_info->input_locations,
interpreter::Register::invalid_value());
}
void EmitLazyDeopt(LazyDeoptInfo* deopt_info) {
......@@ -408,6 +411,9 @@ class MaglevCodeGeneratorImpl final {
deopt_info->deopt_index = translation_array_builder_.BeginTranslation(
frame_count, jsframe_count, update_feedback_count);
const MaglevCompilationUnit& compilation_unit =
*code_gen_state_.compilation_info()->toplevel_compilation_unit();
// Return offsets are counted from the end of the translation frame, which
// is the array [parameters..., locals..., accumulator].
int return_offset;
......@@ -423,22 +429,22 @@ class MaglevCodeGeneratorImpl final {
// ^
// and this calculation gives, correctly:
// 2 + 2 - 1 = 3
return_offset = code_gen_state_.register_count() +
code_gen_state_.parameter_count() -
return_offset = compilation_unit.register_count() +
compilation_unit.parameter_count() -
deopt_info->result_location.ToParameterIndex();
} else {
return_offset = code_gen_state_.register_count() -
return_offset = compilation_unit.register_count() -
deopt_info->result_location.index();
}
// TODO(leszeks): Support lazy deopts with multiple return values.
int return_count = 1;
translation_array_builder_.BeginInterpretedFrame(
deopt_info->state.bytecode_position, kFunctionLiteralIndex,
code_gen_state_.register_count(), return_offset, return_count);
compilation_unit.register_count(), return_offset, return_count);
EmitDeoptFrameValues(
*code_gen_state_.compilation_unit(), deopt_info->state.register_frame,
deopt_info->input_locations, deopt_info->result_location);
EmitDeoptFrameValues(compilation_unit, deopt_info->state.register_frame,
deopt_info->input_locations,
deopt_info->result_location);
}
void EmitDeoptStoreRegister(const compiler::AllocatedOperand& operand,
......@@ -551,7 +557,7 @@ class MaglevCodeGeneratorImpl final {
i++;
input_location++;
});
while (i < code_gen_state_.register_count()) {
while (i < compilation_unit.register_count()) {
translation_array_builder_.StoreLiteral(kOptimizedOutConstantIndex);
i++;
}
......@@ -613,15 +619,18 @@ class MaglevCodeGeneratorImpl final {
data->SetEagerDeoptCount(Smi::FromInt(eager_deopt_count));
data->SetLazyDeoptCount(Smi::FromInt(lazy_deopt_count));
data->SetSharedFunctionInfo(
*code_gen_state_.compilation_unit()->shared_function_info().object());
data->SetSharedFunctionInfo(*code_gen_state_.compilation_info()
->toplevel_compilation_unit()
->shared_function_info()
.object());
// TODO(leszeks): Proper literals array.
Handle<DeoptimizationLiteralArray> literals =
isolate()->factory()->NewDeoptimizationLiteralArray(2);
literals->set(
kFunctionLiteralIndex,
*code_gen_state_.compilation_unit()->shared_function_info().object());
literals->set(kFunctionLiteralIndex, *code_gen_state_.compilation_info()
->toplevel_compilation_unit()
->shared_function_info()
.object());
literals->set(kOptimizedOutConstantIndex,
ReadOnlyRoots(isolate()).optimized_out());
data->SetLiteralArray(*literals);
......@@ -668,7 +677,7 @@ class MaglevCodeGeneratorImpl final {
}
Isolate* isolate() const {
return code_gen_state_.compilation_unit()->isolate();
return code_gen_state_.compilation_info()->isolate();
}
MacroAssembler* masm() { return code_gen_state_.masm(); }
SafepointTableBuilder* safepoint_table_builder() {
......@@ -689,8 +698,8 @@ class MaglevCodeGeneratorImpl final {
// static
MaybeHandle<Code> MaglevCodeGenerator::Generate(
MaglevCompilationUnit* compilation_unit, Graph* graph) {
return MaglevCodeGeneratorImpl::Generate(compilation_unit, graph);
MaglevCompilationInfo* compilation_info, Graph* graph) {
return MaglevCodeGeneratorImpl::Generate(compilation_info, graph);
}
} // namespace maglev
......
......@@ -12,11 +12,11 @@ namespace internal {
namespace maglev {
class Graph;
class MaglevCompilationUnit;
class MaglevCompilationInfo;
class MaglevCodeGenerator : public AllStatic {
public:
static MaybeHandle<Code> Generate(MaglevCompilationUnit* compilation_unit,
static MaybeHandle<Code> Generate(MaglevCompilationInfo* compilation_info,
Graph* graph);
};
......
......@@ -54,9 +54,7 @@ MaglevCompilationInfo::MaglevCompilationInfo(Isolate* isolate,
: zone_(isolate->allocator(), kMaglevZoneName),
isolate_(isolate),
broker_(new compiler::JSHeapBroker(
isolate, zone(), FLAG_trace_heap_broker, CodeKind::MAGLEV)),
shared_(function->shared(), isolate),
function_(function)
isolate, zone(), FLAG_trace_heap_broker, CodeKind::MAGLEV))
#define V(Name) , Name##_(FLAG_##Name)
MAGLEV_COMPILATION_FLAG_LIST(V)
#undef V
......@@ -91,12 +89,7 @@ void MaglevCompilationInfo::set_graph_labeller(
graph_labeller_.reset(graph_labeller);
}
void MaglevCompilationInfo::ReopenHandlesInNewHandleScope(Isolate* isolate) {
DCHECK(!shared_.is_null());
shared_ = handle(*shared_, isolate);
DCHECK(!function_.is_null());
function_ = handle(*function_, isolate);
}
void MaglevCompilationInfo::ReopenHandlesInNewHandleScope(Isolate* isolate) {}
void MaglevCompilationInfo::set_persistent_handles(
std::unique_ptr<PersistentHandles>&& persistent_handles) {
......
......@@ -51,7 +51,6 @@ class MaglevCompilationInfo final {
MaglevCompilationUnit* toplevel_compilation_unit() const {
return toplevel_compilation_unit_;
}
Handle<JSFunction> function() const { return function_; }
bool has_graph_labeller() const { return !!graph_labeller_; }
void set_graph_labeller(MaglevGraphLabeller* graph_labeller);
......@@ -92,9 +91,6 @@ class MaglevCompilationInfo final {
// Must be initialized late since it requires an initialized heap broker.
MaglevCompilationUnit* toplevel_compilation_unit_ = nullptr;
Handle<SharedFunctionInfo> shared_;
Handle<JSFunction> function_;
std::unique_ptr<MaglevGraphLabeller> graph_labeller_;
// Produced off-thread during ExecuteJobImpl.
......
......@@ -16,9 +16,11 @@ namespace maglev {
MaglevCompilationUnit::MaglevCompilationUnit(MaglevCompilationInfo* info,
Handle<JSFunction> function)
: info_(info),
shared_function_info_(MakeRef(broker(), function->shared())),
function_(MakeRef(broker(), function)),
shared_function_info_(function_.shared()),
bytecode_(shared_function_info_.GetBytecodeArray()),
feedback_(MakeRef(broker(), function->feedback_vector())),
feedback_(
function_.feedback_vector(info_->broker()->dependencies()).value()),
bytecode_analysis_(bytecode_.object(), zone(), BytecodeOffset::None(),
true),
register_count_(bytecode_.register_count()),
......
......@@ -22,11 +22,11 @@ class Node;
// function.
class MaglevCompilationUnit : public ZoneObject {
public:
static MaglevCompilationUnit* New(Zone* zone, MaglevCompilationInfo* data,
static MaglevCompilationUnit* New(Zone* zone, MaglevCompilationInfo* info,
Handle<JSFunction> function) {
return zone->New<MaglevCompilationUnit>(data, function);
return zone->New<MaglevCompilationUnit>(info, function);
}
MaglevCompilationUnit(MaglevCompilationInfo* data,
MaglevCompilationUnit(MaglevCompilationInfo* info,
Handle<JSFunction> function);
MaglevCompilationInfo* info() const { return info_; }
......@@ -41,6 +41,7 @@ class MaglevCompilationUnit : public ZoneObject {
const compiler::SharedFunctionInfoRef& shared_function_info() const {
return shared_function_info_;
}
const compiler::JSFunctionRef& function() const { return function_; }
const compiler::BytecodeArrayRef& bytecode() const { return bytecode_; }
const compiler::FeedbackVectorRef& feedback() const { return feedback_; }
const compiler::BytecodeAnalysis& bytecode_analysis() const {
......@@ -51,6 +52,7 @@ class MaglevCompilationUnit : public ZoneObject {
private:
MaglevCompilationInfo* const info_;
const compiler::JSFunctionRef function_;
const compiler::SharedFunctionInfoRef shared_function_info_;
const compiler::BytecodeArrayRef bytecode_;
const compiler::FeedbackVectorRef feedback_;
......
......@@ -47,9 +47,9 @@ namespace maglev {
class NumberingProcessor {
public:
void PreProcessGraph(MaglevCompilationUnit*, Graph* graph) { node_id_ = 1; }
void PostProcessGraph(MaglevCompilationUnit*, Graph* graph) {}
void PreProcessBasicBlock(MaglevCompilationUnit*, BasicBlock* block) {}
void PreProcessGraph(MaglevCompilationInfo*, Graph* graph) { node_id_ = 1; }
void PostProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block) {}
void Process(NodeBase* node, const ProcessingState& state) {
node->set_id(node_id_++);
......@@ -61,9 +61,9 @@ class NumberingProcessor {
class UseMarkingProcessor {
public:
void PreProcessGraph(MaglevCompilationUnit*, Graph* graph) {}
void PostProcessGraph(MaglevCompilationUnit*, Graph* graph) {}
void PreProcessBasicBlock(MaglevCompilationUnit*, BasicBlock* block) {}
void PreProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
void PostProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block) {}
template <typename NodeT>
void Process(NodeT* node, const ProcessingState& state) {
......@@ -110,27 +110,29 @@ class UseMarkingProcessor {
private:
void MarkCheckpointNodes(NodeBase* node, const EagerDeoptInfo* deopt_info,
const ProcessingState& state) {
const MaglevCompilationUnit& compilation_unit =
*state.compilation_info()->toplevel_compilation_unit();
const CompactInterpreterFrameState* register_frame =
deopt_info->state.register_frame;
int use_id = node->id();
int index = 0;
register_frame->ForEachValue(
*state.compilation_unit(),
[&](ValueNode* node, interpreter::Register reg) {
compilation_unit, [&](ValueNode* node, interpreter::Register reg) {
node->mark_use(use_id, &deopt_info->input_locations[index++]);
});
}
void MarkCheckpointNodes(NodeBase* node, const LazyDeoptInfo* deopt_info,
const ProcessingState& state) {
const MaglevCompilationUnit& compilation_unit =
*state.compilation_info()->toplevel_compilation_unit();
const CompactInterpreterFrameState* register_frame =
deopt_info->state.register_frame;
int use_id = node->id();
int index = 0;
register_frame->ForEachValue(
*state.compilation_unit(),
[&](ValueNode* node, interpreter::Register reg) {
compilation_unit, [&](ValueNode* node, interpreter::Register reg) {
// Skip over the result location.
if (reg == deopt_info->result_location) return;
node->mark_use(use_id, &deopt_info->input_locations[index++]);
......@@ -140,27 +142,27 @@ class UseMarkingProcessor {
// static
void MaglevCompiler::Compile(LocalIsolate* local_isolate,
MaglevCompilationUnit* toplevel_compilation_unit) {
compiler::UnparkedScopeIfNeeded unparked_scope(
toplevel_compilation_unit->broker());
MaglevCompilationInfo* compilation_info) {
compiler::UnparkedScopeIfNeeded unparked_scope(compilation_info->broker());
// Build graph.
if (FLAG_print_maglev_code || FLAG_code_comments || FLAG_print_maglev_graph ||
FLAG_trace_maglev_regalloc) {
toplevel_compilation_unit->info()->set_graph_labeller(
new MaglevGraphLabeller());
compilation_info->set_graph_labeller(new MaglevGraphLabeller());
}
// TODO(v8:7700): Support exceptions in maglev. We currently bail if exception
// handler table is non-empty.
if (toplevel_compilation_unit->bytecode().handler_table_size() > 0) {
if (compilation_info->toplevel_compilation_unit()
->bytecode()
.handler_table_size() > 0) {
return;
}
Graph* graph = Graph::New(toplevel_compilation_unit->zone());
Graph* graph = Graph::New(compilation_info->zone());
MaglevGraphBuilder graph_builder(local_isolate, toplevel_compilation_unit,
graph);
MaglevGraphBuilder graph_builder(
local_isolate, compilation_info->toplevel_compilation_unit(), graph);
graph_builder.Build();
......@@ -171,12 +173,12 @@ void MaglevCompiler::Compile(LocalIsolate* local_isolate,
if (FLAG_print_maglev_graph) {
std::cout << "After graph buiding" << std::endl;
PrintGraph(std::cout, toplevel_compilation_unit, graph_builder.graph());
PrintGraph(std::cout, compilation_info, graph_builder.graph());
}
#ifdef DEBUG
{
GraphProcessor<MaglevGraphVerifier> verifier(toplevel_compilation_unit);
GraphProcessor<MaglevGraphVerifier> verifier(compilation_info);
verifier.ProcessGraph(graph_builder.graph());
}
#endif
......@@ -184,49 +186,50 @@ void MaglevCompiler::Compile(LocalIsolate* local_isolate,
{
GraphMultiProcessor<NumberingProcessor, UseMarkingProcessor,
MaglevVregAllocator>
processor(toplevel_compilation_unit);
processor(compilation_info);
processor.ProcessGraph(graph_builder.graph());
}
if (FLAG_print_maglev_graph) {
std::cout << "After node processor" << std::endl;
PrintGraph(std::cout, toplevel_compilation_unit, graph_builder.graph());
PrintGraph(std::cout, compilation_info, graph_builder.graph());
}
StraightForwardRegisterAllocator allocator(toplevel_compilation_unit,
StraightForwardRegisterAllocator allocator(compilation_info,
graph_builder.graph());
if (FLAG_print_maglev_graph) {
std::cout << "After register allocation" << std::endl;
PrintGraph(std::cout, toplevel_compilation_unit, graph_builder.graph());
PrintGraph(std::cout, compilation_info, graph_builder.graph());
}
// Stash the compiled graph on the compilation info.
toplevel_compilation_unit->info()->set_graph(graph_builder.graph());
compilation_info->set_graph(graph_builder.graph());
}
// static
MaybeHandle<CodeT> MaglevCompiler::GenerateCode(
MaglevCompilationUnit* toplevel_compilation_unit) {
Graph* const graph = toplevel_compilation_unit->info()->graph();
MaglevCompilationInfo* compilation_info) {
Graph* const graph = compilation_info->graph();
if (graph == nullptr) {
// Compilation failed.
toplevel_compilation_unit->shared_function_info()
compilation_info->toplevel_compilation_unit()
->shared_function_info()
.object()
->set_maglev_compilation_failed(true);
return {};
}
Handle<Code> code;
if (!MaglevCodeGenerator::Generate(toplevel_compilation_unit, graph)
.ToHandle(&code)) {
toplevel_compilation_unit->shared_function_info()
if (!MaglevCodeGenerator::Generate(compilation_info, graph).ToHandle(&code)) {
compilation_info->toplevel_compilation_unit()
->shared_function_info()
.object()
->set_maglev_compilation_failed(true);
return {};
}
compiler::JSHeapBroker* const broker = toplevel_compilation_unit->broker();
compiler::JSHeapBroker* const broker = compilation_info->broker();
const bool deps_committed_successfully = broker->dependencies()->Commit(code);
CHECK(deps_committed_successfully);
......@@ -234,7 +237,7 @@ MaybeHandle<CodeT> MaglevCompiler::GenerateCode(
code->Print();
}
Isolate* const isolate = toplevel_compilation_unit->isolate();
Isolate* const isolate = compilation_info->isolate();
isolate->native_context()->AddOptimizedCode(ToCodeT(*code));
return ToCodeT(code, isolate);
}
......
......@@ -25,12 +25,12 @@ class MaglevCompiler : public AllStatic {
public:
// May be called from any thread.
static void Compile(LocalIsolate* local_isolate,
MaglevCompilationUnit* toplevel_compilation_unit);
MaglevCompilationInfo* compilation_info);
// Called on the main thread after Compile has completed.
// TODO(v8:7700): Move this to a different class?
static MaybeHandle<CodeT> GenerateCode(
MaglevCompilationUnit* toplevel_compilation_unit);
MaglevCompilationInfo* compilation_info);
};
} // namespace maglev
......
......@@ -101,24 +101,22 @@ CompilationJob::Status MaglevCompilationJob::PrepareJobImpl(Isolate* isolate) {
CompilationJob::Status MaglevCompilationJob::ExecuteJobImpl(
RuntimeCallStats* stats, LocalIsolate* local_isolate) {
LocalIsolateScope scope{info(), local_isolate};
maglev::MaglevCompiler::Compile(local_isolate,
info()->toplevel_compilation_unit());
maglev::MaglevCompiler::Compile(local_isolate, info());
// TODO(v8:7700): Actual return codes.
return CompilationJob::SUCCEEDED;
}
CompilationJob::Status MaglevCompilationJob::FinalizeJobImpl(Isolate* isolate) {
Handle<CodeT> codet;
if (!maglev::MaglevCompiler::GenerateCode(info()->toplevel_compilation_unit())
.ToHandle(&codet)) {
if (!maglev::MaglevCompiler::GenerateCode(info()).ToHandle(&codet)) {
return CompilationJob::FAILED;
}
info()->function()->set_code(*codet);
info()->toplevel_compilation_unit()->function().object()->set_code(*codet);
return CompilationJob::SUCCEEDED;
}
Handle<JSFunction> MaglevCompilationJob::function() const {
return info_->function();
return info_->toplevel_compilation_unit()->function().object();
}
// The JobTask is posted to V8::GetCurrentPlatform(). It's responsible for
......
......@@ -4,12 +4,15 @@
#include "src/maglev/maglev-graph-builder.h"
#include "src/common/globals.h"
#include "src/compiler/compilation-dependencies.h"
#include "src/compiler/feedback-source.h"
#include "src/compiler/heap-refs.h"
#include "src/compiler/processed-feedback.h"
#include "src/handles/maybe-handles-inl.h"
#include "src/ic/handler-configuration-inl.h"
#include "src/maglev/maglev-compilation-unit.h"
#include "src/maglev/maglev-interpreter-frame-state.h"
#include "src/maglev/maglev-ir.h"
#include "src/objects/feedback-vector.h"
#include "src/objects/name-inl.h"
......
......@@ -215,9 +215,8 @@ MaglevPrintingVisitor::MaglevPrintingVisitor(std::ostream& os)
new MaglevPrintingVisitorOstream(os_, &targets_)) {}
void MaglevPrintingVisitor::PreProcessGraph(
MaglevCompilationUnit* compilation_unit, Graph* graph) {
os_ << "Graph (param count: " << compilation_unit->parameter_count()
<< ", frame size: " << compilation_unit->register_count() << ")\n\n";
MaglevCompilationInfo* compilation_info, Graph* graph) {
os_ << "Graph\n\n";
for (BasicBlock* block : *graph) {
if (block->control_node()->Is<JumpLoop>()) {
......@@ -258,8 +257,8 @@ void MaglevPrintingVisitor::PreProcessGraph(
}
void MaglevPrintingVisitor::PreProcessBasicBlock(
MaglevCompilationUnit* compilation_unit, BasicBlock* block) {
MaglevGraphLabeller* graph_labeller = compilation_unit->graph_labeller();
MaglevCompilationInfo* compilation_info, BasicBlock* block) {
MaglevGraphLabeller* graph_labeller = compilation_info->graph_labeller();
size_t loop_position = static_cast<size_t>(-1);
if (loop_headers_.erase(block) > 0) {
......@@ -315,9 +314,10 @@ void PrintEagerDeopt(std::ostream& os, std::vector<BasicBlock*> targets,
os << " ↱ eager @" << deopt_info->state.bytecode_position << " : {";
bool first = true;
int index = 0;
const MaglevCompilationUnit& compilation_unit =
*state.compilation_info()->toplevel_compilation_unit();
deopt_info->state.register_frame->ForEachValue(
*state.compilation_unit(),
[&](ValueNode* node, interpreter::Register reg) {
compilation_unit, [&](ValueNode* node, interpreter::Register reg) {
if (first) {
first = false;
} else {
......@@ -355,9 +355,10 @@ void PrintLazyDeopt(std::ostream& os, std::vector<BasicBlock*> targets,
os << " ↳ lazy @" << deopt_info->state.bytecode_position << " : {";
bool first = true;
int index = 0;
const MaglevCompilationUnit& compilation_unit =
*state.compilation_info()->toplevel_compilation_unit();
deopt_info->state.register_frame->ForEachValue(
*state.compilation_unit(),
[&](ValueNode* node, interpreter::Register reg) {
compilation_unit, [&](ValueNode* node, interpreter::Register reg) {
if (first) {
first = false;
} else {
......@@ -517,9 +518,9 @@ void MaglevPrintingVisitor::Process(ControlNode* control_node,
->set_padding(graph_labeller->max_node_id_width() + 4);
}
void PrintGraph(std::ostream& os, MaglevCompilationUnit* compilation_unit,
void PrintGraph(std::ostream& os, MaglevCompilationInfo* compilation_info,
Graph* const graph) {
GraphProcessor<MaglevPrintingVisitor> printer(compilation_unit, os);
GraphProcessor<MaglevPrintingVisitor> printer(compilation_info, os);
printer.ProcessGraph(graph);
}
......
......@@ -17,7 +17,7 @@ namespace maglev {
class BasicBlock;
class ControlNode;
class Graph;
class MaglevCompilationUnit;
class MaglevCompilationInfo;
class MaglevGraphLabeller;
class Node;
class NodeBase;
......@@ -28,9 +28,9 @@ class MaglevPrintingVisitor {
public:
explicit MaglevPrintingVisitor(std::ostream& os);
void PreProcessGraph(MaglevCompilationUnit*, Graph* graph);
void PostProcessGraph(MaglevCompilationUnit*, Graph* graph) {}
void PreProcessBasicBlock(MaglevCompilationUnit*, BasicBlock* block);
void PreProcessGraph(MaglevCompilationInfo*, Graph* graph);
void PostProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block);
void Process(Phi* phi, const ProcessingState& state);
void Process(Node* node, const ProcessingState& state);
void Process(ControlNode* node, const ProcessingState& state);
......@@ -44,7 +44,7 @@ class MaglevPrintingVisitor {
std::vector<BasicBlock*> targets_;
};
void PrintGraph(std::ostream& os, MaglevCompilationUnit* compilation_unit,
void PrintGraph(std::ostream& os, MaglevCompilationInfo* compilation_info,
Graph* const graph);
class PrintNode {
......
......@@ -7,6 +7,7 @@
#include "src/compiler/bytecode-analysis.h"
#include "src/maglev/maglev-basic-block.h"
#include "src/maglev/maglev-compilation-info.h"
#include "src/maglev/maglev-graph.h"
#include "src/maglev/maglev-interpreter-frame-state.h"
#include "src/maglev/maglev-ir.h"
......@@ -25,13 +26,13 @@ namespace maglev {
// It expects a NodeProcessor class with:
//
// // A function that processes the graph before the nodes are walked.
// void PreProcessGraph(MaglevCompilationUnit*, Graph* graph);
// void PreProcessGraph(MaglevCompilationInfo*, Graph* graph);
//
// // A function that processes the graph after the nodes are walked.
// void PostProcessGraph(MaglevCompilationUnit*, Graph* graph);
// void PostProcessGraph(MaglevCompilationInfo*, Graph* graph);
//
// // A function that processes each basic block before its nodes are walked.
// void PreProcessBasicBlock(MaglevCompilationUnit*, BasicBlock* block);
// void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block);
//
// // Process methods for each Node type. The GraphProcessor switches over
// // the Node's opcode, casts it to the appropriate FooNode, and dispatches
......@@ -45,9 +46,9 @@ class GraphProcessor;
class ProcessingState {
public:
explicit ProcessingState(MaglevCompilationUnit* compilation_unit,
explicit ProcessingState(MaglevCompilationInfo* compilation_info,
BlockConstIterator block_it)
: compilation_unit_(compilation_unit), block_it_(block_it) {}
: compilation_info_(compilation_info), block_it_(block_it) {}
// Disallow copies, since the underlying frame states stay mutable.
ProcessingState(const ProcessingState&) = delete;
......@@ -56,17 +57,14 @@ class ProcessingState {
BasicBlock* block() const { return *block_it_; }
BasicBlock* next_block() const { return *(block_it_ + 1); }
MaglevCompilationUnit* compilation_unit() const { return compilation_unit_; }
int register_count() const { return compilation_unit_->register_count(); }
int parameter_count() const { return compilation_unit_->parameter_count(); }
MaglevCompilationInfo* compilation_info() const { return compilation_info_; }
MaglevGraphLabeller* graph_labeller() const {
return compilation_unit_->graph_labeller();
return compilation_info_->graph_labeller();
}
private:
MaglevCompilationUnit* compilation_unit_;
MaglevCompilationInfo* compilation_info_;
BlockConstIterator block_it_;
};
......@@ -74,20 +72,20 @@ template <typename NodeProcessor>
class GraphProcessor {
public:
template <typename... Args>
explicit GraphProcessor(MaglevCompilationUnit* compilation_unit,
explicit GraphProcessor(MaglevCompilationInfo* compilation_info,
Args&&... args)
: compilation_unit_(compilation_unit),
: compilation_info_(compilation_info),
node_processor_(std::forward<Args>(args)...) {}
void ProcessGraph(Graph* graph) {
graph_ = graph;
node_processor_.PreProcessGraph(compilation_unit_, graph);
node_processor_.PreProcessGraph(compilation_info_, graph);
for (block_it_ = graph->begin(); block_it_ != graph->end(); ++block_it_) {
BasicBlock* block = *block_it_;
node_processor_.PreProcessBasicBlock(compilation_unit_, block);
node_processor_.PreProcessBasicBlock(compilation_info_, block);
if (block->has_phi()) {
for (Phi* phi : *block->phis()) {
......@@ -104,7 +102,7 @@ class GraphProcessor {
ProcessNodeBase(block->control_node(), GetCurrentState());
}
node_processor_.PostProcessGraph(compilation_unit_, graph);
node_processor_.PostProcessGraph(compilation_info_, graph);
}
NodeProcessor& node_processor() { return node_processor_; }
......@@ -112,7 +110,7 @@ class GraphProcessor {
private:
ProcessingState GetCurrentState() {
return ProcessingState(compilation_unit_, block_it_);
return ProcessingState(compilation_info_, block_it_);
}
void ProcessNodeBase(NodeBase* node, const ProcessingState& state) {
......@@ -129,12 +127,7 @@ class GraphProcessor {
void PreProcess(NodeBase* node, const ProcessingState& state) {}
int register_count() const { return compilation_unit_->register_count(); }
const compiler::BytecodeAnalysis& bytecode_analysis() const {
return compilation_unit_->bytecode_analysis();
}
MaglevCompilationUnit* const compilation_unit_;
MaglevCompilationInfo* const compilation_info_;
NodeProcessor node_processor_;
Graph* graph_;
BlockConstIterator block_it_;
......@@ -149,9 +142,9 @@ class NodeMultiProcessor;
template <>
class NodeMultiProcessor<> {
public:
void PreProcessGraph(MaglevCompilationUnit*, Graph* graph) {}
void PostProcessGraph(MaglevCompilationUnit*, Graph* graph) {}
void PreProcessBasicBlock(MaglevCompilationUnit*, BasicBlock* block) {}
void PreProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
void PostProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block) {}
void Process(NodeBase* node, const ProcessingState& state) {}
};
......@@ -166,18 +159,18 @@ class NodeMultiProcessor<Processor, Processors...>
processor_.Process(node, state);
Base::Process(node, state);
}
void PreProcessGraph(MaglevCompilationUnit* unit, Graph* graph) {
processor_.PreProcessGraph(unit, graph);
Base::PreProcessGraph(unit, graph);
void PreProcessGraph(MaglevCompilationInfo* info, Graph* graph) {
processor_.PreProcessGraph(info, graph);
Base::PreProcessGraph(info, graph);
}
void PostProcessGraph(MaglevCompilationUnit* unit, Graph* graph) {
void PostProcessGraph(MaglevCompilationInfo* info, Graph* graph) {
// Post process in reverse order because that kind of makes sense.
Base::PostProcessGraph(unit, graph);
processor_.PostProcessGraph(unit, graph);
Base::PostProcessGraph(info, graph);
processor_.PostProcessGraph(info, graph);
}
void PreProcessBasicBlock(MaglevCompilationUnit* unit, BasicBlock* block) {
processor_.PreProcessBasicBlock(unit, block);
Base::PreProcessBasicBlock(unit, block);
void PreProcessBasicBlock(MaglevCompilationInfo* info, BasicBlock* block) {
processor_.PreProcessBasicBlock(info, block);
Base::PreProcessBasicBlock(info, block);
}
private:
......
......@@ -5,6 +5,7 @@
#ifndef V8_MAGLEV_MAGLEV_GRAPH_VERIFIER_H_
#define V8_MAGLEV_MAGLEV_GRAPH_VERIFIER_H_
#include "src/maglev/maglev-compilation-info.h"
#include "src/maglev/maglev-graph-labeller.h"
#include "src/maglev/maglev-ir.h"
......@@ -33,14 +34,14 @@ class Graph;
// are expected to be tagged/untagged. Add more verification later.
class MaglevGraphVerifier {
public:
void PreProcessGraph(MaglevCompilationUnit* compilation_unit, Graph* graph) {
if (compilation_unit->has_graph_labeller()) {
graph_labeller_ = compilation_unit->graph_labeller();
void PreProcessGraph(MaglevCompilationInfo* compilation_info, Graph* graph) {
if (compilation_info->has_graph_labeller()) {
graph_labeller_ = compilation_info->graph_labeller();
}
}
void PostProcessGraph(MaglevCompilationUnit*, Graph* graph) {}
void PreProcessBasicBlock(MaglevCompilationUnit*, BasicBlock* block) {}
void PostProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block) {}
void CheckValueInputIs(NodeBase* node, int i, ValueRepresentation expected) {
ValueNode* input = node->input(i).node();
......
......@@ -113,14 +113,14 @@ template <typename T, typename Enable = void>
struct CopyForDeferredHelper {
template <typename U>
struct No_Copy_Helper_Implemented_For_Type;
static void Copy(MaglevCompilationUnit* compilation_unit,
static void Copy(MaglevCompilationInfo* compilation_info,
No_Copy_Helper_Implemented_For_Type<T>);
};
// Helper for copies by value.
template <typename T, typename Enable = void>
struct CopyForDeferredByValue {
static T Copy(MaglevCompilationUnit* compilation_unit, T node) {
static T Copy(MaglevCompilationInfo* compilation_info, T node) {
return node;
}
};
......@@ -139,10 +139,10 @@ template <typename T>
struct CopyForDeferredHelper<
T, typename std::enable_if<std::is_enum<T>::value>::type>
: public CopyForDeferredByValue<T> {};
// MaglevCompilationUnits are copied by value.
// MaglevCompilationInfos are copied by value.
template <>
struct CopyForDeferredHelper<MaglevCompilationUnit*>
: public CopyForDeferredByValue<MaglevCompilationUnit*> {};
struct CopyForDeferredHelper<MaglevCompilationInfo*>
: public CopyForDeferredByValue<MaglevCompilationInfo*> {};
// Machine registers are copied by value.
template <>
struct CopyForDeferredHelper<Register>
......@@ -151,36 +151,25 @@ struct CopyForDeferredHelper<Register>
template <>
struct CopyForDeferredHelper<BytecodeOffset>
: public CopyForDeferredByValue<BytecodeOffset> {};
// InterpreterFrameState is cloned.
template <>
struct CopyForDeferredHelper<const InterpreterFrameState*> {
static const InterpreterFrameState* Copy(
MaglevCompilationUnit* compilation_unit,
const InterpreterFrameState* frame_state) {
return compilation_unit->zone()->New<InterpreterFrameState>(
*compilation_unit, *frame_state);
}
};
// EagerDeoptInfo pointers are copied by value.
template <>
struct CopyForDeferredHelper<EagerDeoptInfo*>
: public CopyForDeferredByValue<EagerDeoptInfo*> {};
template <typename T>
T CopyForDeferred(MaglevCompilationUnit* compilation_unit, T&& value) {
return CopyForDeferredHelper<T>::Copy(compilation_unit,
T CopyForDeferred(MaglevCompilationInfo* compilation_info, T&& value) {
return CopyForDeferredHelper<T>::Copy(compilation_info,
std::forward<T>(value));
}
template <typename T>
T CopyForDeferred(MaglevCompilationUnit* compilation_unit, T& value) {
return CopyForDeferredHelper<T>::Copy(compilation_unit, value);
T CopyForDeferred(MaglevCompilationInfo* compilation_info, T& value) {
return CopyForDeferredHelper<T>::Copy(compilation_info, value);
}
template <typename T>
T CopyForDeferred(MaglevCompilationUnit* compilation_unit, const T& value) {
return CopyForDeferredHelper<T>::Copy(compilation_unit, value);
T CopyForDeferred(MaglevCompilationInfo* compilation_info, const T& value) {
return CopyForDeferredHelper<T>::Copy(compilation_info, value);
}
template <typename Function, typename FunctionPointer = Function>
......@@ -213,10 +202,10 @@ class DeferredCodeInfoImpl final : public DeferredCodeInfo {
static constexpr size_t kSize = FunctionArgumentsTupleHelper<Function>::kSize;
template <typename... InArgs>
explicit DeferredCodeInfoImpl(MaglevCompilationUnit* compilation_unit,
explicit DeferredCodeInfoImpl(MaglevCompilationInfo* compilation_info,
FunctionPointer function, InArgs&&... args)
: function(function),
args(CopyForDeferred(compilation_unit, std::forward<InArgs>(args))...) {
args(CopyForDeferred(compilation_info, std::forward<InArgs>(args))...) {
}
DeferredCodeInfoImpl(DeferredCodeInfoImpl&&) = delete;
......@@ -244,8 +233,8 @@ void JumpToDeferredIf(Condition cond, MaglevCodeGenState* code_gen_state,
Function&& deferred_code_gen, Args&&... args) {
using DeferredCodeInfoT = DeferredCodeInfoImpl<Function>;
DeferredCodeInfoT* deferred_code =
code_gen_state->compilation_unit()->zone()->New<DeferredCodeInfoT>(
code_gen_state->compilation_unit(), deferred_code_gen,
code_gen_state->compilation_info()->zone()->New<DeferredCodeInfoT>(
code_gen_state->compilation_info(), deferred_code_gen,
std::forward<Args>(args)...);
code_gen_state->PushDeferredCode(deferred_code);
......@@ -852,6 +841,12 @@ void Return::GenerateCode(MaglevCodeGenState* code_gen_state,
const ProcessingState& state) {
DCHECK_EQ(ToRegister(value_input()), kReturnRegister0);
// Read the formal number of parameters from the top level compilation unit
// (i.e. the outermost, non inlined function).
int formal_params_size = code_gen_state->compilation_info()
->toplevel_compilation_unit()
->parameter_count();
// We're not going to continue execution, so we can use an arbitrary register
// here instead of relying on temporaries from the register allocator.
Register actual_params_size = r8;
......@@ -869,12 +864,11 @@ void Return::GenerateCode(MaglevCodeGenState* code_gen_state,
// If actual is bigger than formal, then we should use it to free up the stack
// arguments.
Label drop_dynamic_arg_size;
__ cmpq(actual_params_size, Immediate(code_gen_state->parameter_count()));
__ cmpq(actual_params_size, Immediate(formal_params_size));
__ j(greater, &drop_dynamic_arg_size);
// Drop receiver + arguments according to static formal arguments size.
__ Ret(code_gen_state->parameter_count() * kSystemPointerSize,
kScratchRegister);
__ Ret(formal_params_size * kSystemPointerSize, kScratchRegister);
__ bind(&drop_dynamic_arg_size);
// Drop receiver + arguments according to dynamic arguments size.
......
......@@ -10,6 +10,7 @@
#include "src/codegen/register.h"
#include "src/codegen/reglist.h"
#include "src/compiler/backend/instruction.h"
#include "src/maglev/maglev-compilation-info.h"
#include "src/maglev/maglev-compilation-unit.h"
#include "src/maglev/maglev-graph-labeller.h"
#include "src/maglev/maglev-graph-printer.h"
......@@ -79,8 +80,8 @@ bool IsLiveAtTarget(ValueNode* node, ControlNode* source, BasicBlock* target) {
} // namespace
StraightForwardRegisterAllocator::StraightForwardRegisterAllocator(
MaglevCompilationUnit* compilation_unit, Graph* graph)
: compilation_unit_(compilation_unit) {
MaglevCompilationInfo* compilation_info, Graph* graph)
: compilation_info_(compilation_info) {
ComputePostDominatingHoles(graph);
AllocateRegisters(graph);
graph->set_tagged_stack_slots(tagged_.top);
......@@ -213,7 +214,7 @@ void StraightForwardRegisterAllocator::PrintLiveRegs() const {
void StraightForwardRegisterAllocator::AllocateRegisters(Graph* graph) {
if (FLAG_trace_maglev_regalloc) {
printing_visitor_.reset(new MaglevPrintingVisitor(std::cout));
printing_visitor_->PreProcessGraph(compilation_unit_, graph);
printing_visitor_->PreProcessGraph(compilation_info_, graph);
}
for (block_it_ = graph->begin(); block_it_ != graph->end(); ++block_it_) {
......@@ -225,7 +226,7 @@ void StraightForwardRegisterAllocator::AllocateRegisters(Graph* graph) {
}
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->PreProcessBasicBlock(compilation_unit_, block);
printing_visitor_->PreProcessBasicBlock(compilation_info_, block);
printing_visitor_->os() << "live regs: ";
PrintLiveRegs();
......@@ -274,7 +275,7 @@ void StraightForwardRegisterAllocator::AllocateRegisters(Graph* graph) {
compiler::AllocatedOperand::cast(allocation));
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(
phi, ProcessingState(compilation_unit_, block_it_));
phi, ProcessingState(compilation_info_, block_it_));
printing_visitor_->os()
<< "phi (new reg) " << phi->result().operand() << std::endl;
}
......@@ -288,7 +289,7 @@ void StraightForwardRegisterAllocator::AllocateRegisters(Graph* graph) {
phi->result().SetAllocated(phi->spill_slot());
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(
phi, ProcessingState(compilation_unit_, block_it_));
phi, ProcessingState(compilation_info_, block_it_));
printing_visitor_->os()
<< "phi (stack) " << phi->result().operand() << std::endl;
}
......@@ -340,9 +341,11 @@ void StraightForwardRegisterAllocator::UpdateUse(
const EagerDeoptInfo& deopt_info) {
const CompactInterpreterFrameState* checkpoint_state =
deopt_info.state.register_frame;
const MaglevCompilationUnit& compilation_unit =
*compilation_info_->toplevel_compilation_unit();
int index = 0;
checkpoint_state->ForEachValue(
*compilation_unit_, [&](ValueNode* node, interpreter::Register reg) {
compilation_unit, [&](ValueNode* node, interpreter::Register reg) {
InputLocation* input = &deopt_info.input_locations[index++];
input->InjectAllocated(node->allocation());
UpdateUse(node, input);
......@@ -353,9 +356,11 @@ void StraightForwardRegisterAllocator::UpdateUse(
const LazyDeoptInfo& deopt_info) {
const CompactInterpreterFrameState* checkpoint_state =
deopt_info.state.register_frame;
const MaglevCompilationUnit& compilation_unit =
*compilation_info_->toplevel_compilation_unit();
int index = 0;
checkpoint_state->ForEachValue(
*compilation_unit_, [&](ValueNode* node, interpreter::Register reg) {
compilation_unit, [&](ValueNode* node, interpreter::Register reg) {
// Skip over the result location.
if (reg == deopt_info.result_location) return;
InputLocation* input = &deopt_info.input_locations[index++];
......@@ -384,7 +389,7 @@ void StraightForwardRegisterAllocator::AllocateNode(Node* node) {
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(node,
ProcessingState(compilation_unit_, block_it_));
ProcessingState(compilation_info_, block_it_));
printing_visitor_->os() << "live regs: ";
PrintLiveRegs();
printing_visitor_->os() << "\n";
......@@ -554,7 +559,7 @@ void StraightForwardRegisterAllocator::AllocateControlNode(ControlNode* node,
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(node,
ProcessingState(compilation_unit_, block_it_));
ProcessingState(compilation_info_, block_it_));
}
}
......@@ -567,7 +572,7 @@ void StraightForwardRegisterAllocator::TryAllocateToInput(Phi* phi) {
phi->result().SetAllocated(ForceAllocate(reg, phi));
if (FLAG_trace_maglev_regalloc) {
printing_visitor_->Process(
phi, ProcessingState(compilation_unit_, block_it_));
phi, ProcessingState(compilation_info_, block_it_));
printing_visitor_->os()
<< "phi (reuse) " << input.operand() << std::endl;
}
......@@ -580,8 +585,8 @@ void StraightForwardRegisterAllocator::TryAllocateToInput(Phi* phi) {
void StraightForwardRegisterAllocator::AddMoveBeforeCurrentNode(
compiler::AllocatedOperand source, compiler::AllocatedOperand target) {
GapMove* gap_move =
Node::New<GapMove>(compilation_unit_->zone(), {}, source, target);
if (compilation_unit_->has_graph_labeller()) {
Node::New<GapMove>(compilation_info_->zone(), {}, source, target);
if (compilation_info_->has_graph_labeller()) {
graph_labeller()->RegisterNode(gap_move);
}
if (*node_it_ == nullptr) {
......@@ -894,7 +899,7 @@ void StraightForwardRegisterAllocator::MergeRegisterValues(ControlNode* control,
const size_t size = sizeof(RegisterMerge) +
predecessor_count * sizeof(compiler::AllocatedOperand);
void* buffer = compilation_unit_->zone()->Allocate<void*>(size);
void* buffer = compilation_info_->zone()->Allocate<void*>(size);
merge = new (buffer) RegisterMerge();
merge->node = node == nullptr ? incoming : node;
......
......@@ -7,6 +7,7 @@
#include "src/codegen/reglist.h"
#include "src/compiler/backend/instruction.h"
#include "src/maglev/maglev-compilation-info.h"
#include "src/maglev/maglev-graph.h"
#include "src/maglev/maglev-ir.h"
#include "src/maglev/maglev-regalloc-data.h"
......@@ -15,13 +16,13 @@ namespace v8 {
namespace internal {
namespace maglev {
class MaglevCompilationUnit;
class MaglevCompilationInfo;
class MaglevPrintingVisitor;
class MergePointRegisterState;
class StraightForwardRegisterAllocator {
public:
StraightForwardRegisterAllocator(MaglevCompilationUnit* compilation_unit,
StraightForwardRegisterAllocator(MaglevCompilationInfo* compilation_info,
Graph* graph);
~StraightForwardRegisterAllocator();
......@@ -110,10 +111,10 @@ class StraightForwardRegisterAllocator {
int predecessor_id);
MaglevGraphLabeller* graph_labeller() const {
return compilation_unit_->graph_labeller();
return compilation_info_->graph_labeller();
}
MaglevCompilationUnit* compilation_unit_;
MaglevCompilationInfo* compilation_info_;
std::unique_ptr<MaglevPrintingVisitor> printing_visitor_;
BlockConstIterator block_it_;
NodeIterator node_it_;
......
......@@ -26,8 +26,8 @@ class MaglevVregAllocationState {
class MaglevVregAllocator {
public:
void PreProcessGraph(MaglevCompilationUnit*, Graph* graph) {}
void PostProcessGraph(MaglevCompilationUnit*, Graph* graph) {
void PreProcessGraph(MaglevCompilationInfo*, Graph* graph) {}
void PostProcessGraph(MaglevCompilationInfo*, Graph* graph) {
for (BasicBlock* block : *graph) {
if (!block->has_phi()) continue;
for (Phi* phi : *block->phis()) {
......@@ -35,7 +35,7 @@ class MaglevVregAllocator {
}
}
}
void PreProcessBasicBlock(MaglevCompilationUnit*, BasicBlock* block) {}
void PreProcessBasicBlock(MaglevCompilationInfo*, BasicBlock* block) {}
#define DEF_PROCESS_NODE(NAME) \
void Process(NAME* node, const ProcessingState& state) { \
......
......@@ -14,10 +14,11 @@ namespace internal {
MaybeHandle<CodeT> Maglev::Compile(Isolate* isolate,
Handle<JSFunction> function) {
DCHECK(FLAG_maglev);
auto info = maglev::MaglevCompilationInfo::New(isolate, function);
maglev::MaglevCompilationUnit* const unit = info->toplevel_compilation_unit();
maglev::MaglevCompiler::Compile(isolate->main_thread_local_isolate(), unit);
return maglev::MaglevCompiler::GenerateCode(unit);
std::unique_ptr<maglev::MaglevCompilationInfo> info =
maglev::MaglevCompilationInfo::New(isolate, function);
maglev::MaglevCompiler::Compile(isolate->main_thread_local_isolate(),
info.get());
return maglev::MaglevCompiler::GenerateCode(info.get());
}
} // namespace internal
......
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