Commit f626d5df authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[compiler] Make OsrHelper a member of PipelineData.

... in order to avoid creating an OsrHelper during code assembly,
because its constructor accesses the heap.

Bug: v8:6048
Change-Id: I3bf592a5a0f91752a9f5ec35982f962445512bb7
Reviewed-on: https://chromium-review.googlesource.com/530370
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45990}
parent 53b6f276
...@@ -267,10 +267,14 @@ class V8_EXPORT_PRIVATE CompilationInfo final { ...@@ -267,10 +267,14 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
int optimization_id() const { return optimization_id_; } int optimization_id() const { return optimization_id_; }
int osr_expr_stack_height() { return osr_expr_stack_height_; } int osr_expr_stack_height() {
DCHECK_GE(osr_expr_stack_height_, 0);
return osr_expr_stack_height_;
}
void set_osr_expr_stack_height(int height) { void set_osr_expr_stack_height(int height) {
DCHECK(height >= 0); DCHECK_EQ(osr_expr_stack_height_, -1);
osr_expr_stack_height_ = height; osr_expr_stack_height_ = height;
DCHECK_GE(osr_expr_stack_height_, 0);
} }
bool has_simple_parameters(); bool has_simple_parameters();
......
...@@ -2785,7 +2785,7 @@ void CodeGenerator::AssembleConstructFrame() { ...@@ -2785,7 +2785,7 @@ void CodeGenerator::AssembleConstructFrame() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); shrink_slots -= osr_helper()->UnoptimizedFrameSlots();
} }
const RegList saves_fp = descriptor->CalleeSavedFPRegisters(); const RegList saves_fp = descriptor->CalleeSavedFPRegisters();
......
...@@ -1993,7 +1993,7 @@ void CodeGenerator::AssembleConstructFrame() { ...@@ -1993,7 +1993,7 @@ void CodeGenerator::AssembleConstructFrame() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); shrink_slots -= osr_helper()->UnoptimizedFrameSlots();
} }
if (info()->IsWasm() && shrink_slots > 128) { if (info()->IsWasm() && shrink_slots > 128) {
......
...@@ -2705,7 +2705,6 @@ Node* AstGraphBuilder::TryFastToBoolean(Node* input) { ...@@ -2705,7 +2705,6 @@ Node* AstGraphBuilder::TryFastToBoolean(Node* input) {
bool AstGraphBuilder::CheckOsrEntry(IterationStatement* stmt) { bool AstGraphBuilder::CheckOsrEntry(IterationStatement* stmt) {
if (info()->osr_ast_id() == stmt->OsrEntryId()) { if (info()->osr_ast_id() == stmt->OsrEntryId()) {
DCHECK_EQ(-1, info()->osr_expr_stack_height());
info()->set_osr_expr_stack_height(environment()->stack_height()); info()->set_osr_expr_stack_height(environment()->stack_height());
return true; return true;
} }
......
...@@ -36,7 +36,8 @@ class CodeGenerator::JumpTable final : public ZoneObject { ...@@ -36,7 +36,8 @@ class CodeGenerator::JumpTable final : public ZoneObject {
}; };
CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage, CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage,
InstructionSequence* code, CompilationInfo* info) InstructionSequence* code, CompilationInfo* info,
base::Optional<OsrHelper> osr_helper)
: frame_access_state_(nullptr), : frame_access_state_(nullptr),
linkage_(linkage), linkage_(linkage),
code_(code), code_(code),
...@@ -57,6 +58,7 @@ CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage, ...@@ -57,6 +58,7 @@ CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage,
last_lazy_deopt_pc_(0), last_lazy_deopt_pc_(0),
jump_tables_(nullptr), jump_tables_(nullptr),
ools_(nullptr), ools_(nullptr),
osr_helper_(osr_helper),
osr_pc_offset_(-1), osr_pc_offset_(-1),
optimized_out_literal_id_(-1), optimized_out_literal_id_(-1),
source_position_table_builder_(code->zone(), source_position_table_builder_(code->zone(),
...@@ -66,6 +68,7 @@ CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage, ...@@ -66,6 +68,7 @@ CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage,
new (&labels_[i]) Label; new (&labels_[i]) Label;
} }
CreateFrameAccessState(frame); CreateFrameAccessState(frame);
CHECK_EQ(info->is_osr(), osr_helper_.has_value());
} }
Isolate* CodeGenerator::isolate() const { return info_->isolate(); } Isolate* CodeGenerator::isolate() const { return info_->isolate(); }
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
#ifndef V8_COMPILER_CODE_GENERATOR_H_ #ifndef V8_COMPILER_CODE_GENERATOR_H_
#define V8_COMPILER_CODE_GENERATOR_H_ #define V8_COMPILER_CODE_GENERATOR_H_
#include "src/base/optional.h"
#include "src/compiler/gap-resolver.h" #include "src/compiler/gap-resolver.h"
#include "src/compiler/instruction.h" #include "src/compiler/instruction.h"
#include "src/compiler/osr.h"
#include "src/compiler/unwinding-info-writer.h" #include "src/compiler/unwinding-info-writer.h"
#include "src/deoptimizer.h" #include "src/deoptimizer.h"
#include "src/macro-assembler.h" #include "src/macro-assembler.h"
...@@ -78,7 +80,8 @@ class DeoptimizationLiteral { ...@@ -78,7 +80,8 @@ class DeoptimizationLiteral {
class CodeGenerator final : public GapResolver::Assembler { class CodeGenerator final : public GapResolver::Assembler {
public: public:
explicit CodeGenerator(Frame* frame, Linkage* linkage, explicit CodeGenerator(Frame* frame, Linkage* linkage,
InstructionSequence* code, CompilationInfo* info); InstructionSequence* code, CompilationInfo* info,
base::Optional<OsrHelper> osr_helper);
// Generate native code. After calling AssembleCode, call FinalizeCode to // Generate native code. After calling AssembleCode, call FinalizeCode to
// produce the actual code object. If an error occurs during either phase, // produce the actual code object. If an error occurs during either phase,
...@@ -108,6 +111,7 @@ class CodeGenerator final : public GapResolver::Assembler { ...@@ -108,6 +111,7 @@ class CodeGenerator final : public GapResolver::Assembler {
SafepointTableBuilder* safepoints() { return &safepoints_; } SafepointTableBuilder* safepoints() { return &safepoints_; }
Zone* zone() const { return code()->zone(); } Zone* zone() const { return code()->zone(); }
CompilationInfo* info() const { return info_; } CompilationInfo* info() const { return info_; }
OsrHelper* osr_helper() { return &(*osr_helper_); }
// Create the FrameAccessState object. The Frame is immutable from here on. // Create the FrameAccessState object. The Frame is immutable from here on.
void CreateFrameAccessState(Frame* frame); void CreateFrameAccessState(Frame* frame);
...@@ -317,6 +321,7 @@ class CodeGenerator final : public GapResolver::Assembler { ...@@ -317,6 +321,7 @@ class CodeGenerator final : public GapResolver::Assembler {
int last_lazy_deopt_pc_; int last_lazy_deopt_pc_;
JumpTable* jump_tables_; JumpTable* jump_tables_;
OutOfLineCode* ools_; OutOfLineCode* ools_;
base::Optional<OsrHelper> osr_helper_;
int osr_pc_offset_; int osr_pc_offset_;
int optimized_out_literal_id_; int optimized_out_literal_id_;
SourcePositionTableBuilder source_position_table_builder_; SourcePositionTableBuilder source_position_table_builder_;
......
...@@ -2465,7 +2465,7 @@ void CodeGenerator::AssembleConstructFrame() { ...@@ -2465,7 +2465,7 @@ void CodeGenerator::AssembleConstructFrame() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); shrink_slots -= osr_helper()->UnoptimizedFrameSlots();
} }
const RegList saves = descriptor->CalleeSavedRegisters(); const RegList saves = descriptor->CalleeSavedRegisters();
......
...@@ -2746,7 +2746,7 @@ void CodeGenerator::AssembleConstructFrame() { ...@@ -2746,7 +2746,7 @@ void CodeGenerator::AssembleConstructFrame() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); shrink_slots -= osr_helper()->UnoptimizedFrameSlots();
} }
const RegList saves_fpu = descriptor->CalleeSavedFPRegisters(); const RegList saves_fpu = descriptor->CalleeSavedFPRegisters();
......
...@@ -3076,7 +3076,7 @@ void CodeGenerator::AssembleConstructFrame() { ...@@ -3076,7 +3076,7 @@ void CodeGenerator::AssembleConstructFrame() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); shrink_slots -= osr_helper()->UnoptimizedFrameSlots();
} }
if (shrink_slots > 0) { if (shrink_slots > 0) {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <sstream> #include <sstream>
#include "src/base/adapters.h" #include "src/base/adapters.h"
#include "src/base/optional.h"
#include "src/base/platform/elapsed-timer.h" #include "src/base/platform/elapsed-timer.h"
#include "src/compilation-info.h" #include "src/compilation-info.h"
#include "src/compiler.h" #include "src/compiler.h"
...@@ -185,6 +186,7 @@ class PipelineData { ...@@ -185,6 +186,7 @@ class PipelineData {
CompilationInfo* info() const { return info_; } CompilationInfo* info() const { return info_; }
ZoneStats* zone_stats() const { return zone_stats_; } ZoneStats* zone_stats() const { return zone_stats_; }
PipelineStatistics* pipeline_statistics() { return pipeline_statistics_; } PipelineStatistics* pipeline_statistics() { return pipeline_statistics_; }
OsrHelper* osr_helper() { return &(*osr_helper_); }
bool compilation_failed() const { return compilation_failed_; } bool compilation_failed() const { return compilation_failed_; }
void set_compilation_failed() { compilation_failed_ = true; } void set_compilation_failed() { compilation_failed_ = true; }
...@@ -318,9 +320,15 @@ class PipelineData { ...@@ -318,9 +320,15 @@ class PipelineData {
sequence(), debug_name()); sequence(), debug_name());
} }
void InitializeOsrHelper() {
DCHECK(!osr_helper_.has_value());
osr_helper_.emplace(info());
}
void InitializeCodeGenerator(Linkage* linkage) { void InitializeCodeGenerator(Linkage* linkage) {
DCHECK_NULL(code_generator_); DCHECK_NULL(code_generator_);
code_generator_ = new CodeGenerator(frame(), linkage, sequence(), info()); code_generator_ =
new CodeGenerator(frame(), linkage, sequence(), info(), osr_helper_);
} }
void BeginPhaseKind(const char* phase_kind_name) { void BeginPhaseKind(const char* phase_kind_name) {
...@@ -347,6 +355,7 @@ class PipelineData { ...@@ -347,6 +355,7 @@ class PipelineData {
bool compilation_failed_ = false; bool compilation_failed_ = false;
bool verify_graph_ = false; bool verify_graph_ = false;
bool is_asm_ = false; bool is_asm_ = false;
base::Optional<OsrHelper> osr_helper_;
Handle<Code> code_ = Handle<Code>::null(); Handle<Code> code_ = Handle<Code>::null();
CodeGenerator* code_generator_ = nullptr; CodeGenerator* code_generator_ = nullptr;
...@@ -626,6 +635,8 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl() { ...@@ -626,6 +635,8 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl() {
return AbortOptimization(kGraphBuildingFailed); return AbortOptimization(kGraphBuildingFailed);
} }
if (info()->is_osr()) data_.InitializeOsrHelper();
// Make sure that we have generated the maximal number of deopt entries. // Make sure that we have generated the maximal number of deopt entries.
// This is in order to avoid triggering the generation of deopt entries later // This is in order to avoid triggering the generation of deopt entries later
// during code assembly. // during code assembly.
...@@ -934,6 +945,7 @@ struct OsrDeconstructionPhase { ...@@ -934,6 +945,7 @@ struct OsrDeconstructionPhase {
data->jsgraph()->GetCachedNodes(&roots); data->jsgraph()->GetCachedNodes(&roots);
trimmer.TrimGraph(roots.begin(), roots.end()); trimmer.TrimGraph(roots.begin(), roots.end());
// TODO(neis): Use data->osr_helper() here once AST graph builder is gone.
OsrHelper osr_helper(data->info()); OsrHelper osr_helper(data->info());
osr_helper.Deconstruct(data->jsgraph(), data->common(), temp_zone); osr_helper.Deconstruct(data->jsgraph(), data->common(), temp_zone);
} }
...@@ -2003,11 +2015,7 @@ void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config, ...@@ -2003,11 +2015,7 @@ void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config,
#endif #endif
data->InitializeRegisterAllocationData(config, descriptor); data->InitializeRegisterAllocationData(config, descriptor);
if (info()->is_osr()) { if (info()->is_osr()) data->osr_helper()->SetupFrame(data->frame());
AllowHandleDereference allow_deref;
OsrHelper osr_helper(info());
osr_helper.SetupFrame(data->frame());
}
Run<MeetRegisterConstraintsPhase>(); Run<MeetRegisterConstraintsPhase>();
Run<ResolvePhisPhase>(); Run<ResolvePhisPhase>();
......
...@@ -2291,7 +2291,7 @@ void CodeGenerator::AssembleConstructFrame() { ...@@ -2291,7 +2291,7 @@ void CodeGenerator::AssembleConstructFrame() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); shrink_slots -= osr_helper()->UnoptimizedFrameSlots();
} }
const RegList double_saves = descriptor->CalleeSavedFPRegisters(); const RegList double_saves = descriptor->CalleeSavedFPRegisters();
......
...@@ -2668,7 +2668,7 @@ void CodeGenerator::AssembleConstructFrame() { ...@@ -2668,7 +2668,7 @@ void CodeGenerator::AssembleConstructFrame() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); shrink_slots -= osr_helper()->UnoptimizedFrameSlots();
} }
const RegList double_saves = descriptor->CalleeSavedFPRegisters(); const RegList double_saves = descriptor->CalleeSavedFPRegisters();
......
...@@ -2859,7 +2859,7 @@ void CodeGenerator::AssembleConstructFrame() { ...@@ -2859,7 +2859,7 @@ void CodeGenerator::AssembleConstructFrame() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
shrink_slots -= static_cast<int>(OsrHelper(info()).UnoptimizedFrameSlots()); shrink_slots -= static_cast<int>(osr_helper()->UnoptimizedFrameSlots());
} }
const RegList saves_fp = descriptor->CalleeSavedFPRegisters(); const RegList saves_fp = descriptor->CalleeSavedFPRegisters();
......
...@@ -2449,7 +2449,7 @@ void CodeGenerator::AssembleConstructFrame() { ...@@ -2449,7 +2449,7 @@ void CodeGenerator::AssembleConstructFrame() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); shrink_slots -= osr_helper()->UnoptimizedFrameSlots();
// Initailize FPU state. // Initailize FPU state.
__ fninit(); __ fninit();
......
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