Commit e396f538 authored by svenpanne's avatar svenpanne Committed by Commit bot

Some CompilationInfo-related cleanup.

Use a delegating constructor for CompilationInfo, reducing duplicated
code. Simplified handling of InlinedFunctionInfos on the way: When we
start compiling, we have bigger things to worry about than a default
vector.

Reduced the usage of a SharedFunctionInfo for compiling, this is a
slighty strange concept.

Review URL: https://codereview.chromium.org/1018853004

Cr-Commit-Position: refs/heads/master@{#27299}
parent 5d8e3bfa
......@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/v8.h"
#include "src/compiler.h"
#include <algorithm>
#include "src/ast-numbering.h"
#include "src/bootstrapper.h"
#include "src/codegen.h"
......@@ -81,57 +81,8 @@ bool CompilationInfo::has_shared_info() const {
CompilationInfo::CompilationInfo(ParseInfo* parse_info)
: parse_info_(parse_info),
flags_(0),
osr_ast_id_(BailoutId::None()),
parameter_count_(0),
optimization_id_(-1),
aborted_due_to_dependency_change_(false),
osr_expr_stack_height_(0) {
Initialize(parse_info->isolate(), BASE, parse_info->zone());
}
CompilationInfo::CompilationInfo(CodeStub* stub, Isolate* isolate, Zone* zone)
: parse_info_(nullptr),
flags_(0),
osr_ast_id_(BailoutId::None()),
parameter_count_(0),
optimization_id_(-1),
aborted_due_to_dependency_change_(false),
osr_expr_stack_height_(0) {
Initialize(isolate, STUB, zone);
code_stub_ = stub;
}
void CompilationInfo::Initialize(Isolate* isolate,
Mode mode,
Zone* zone) {
isolate_ = isolate;
zone_ = zone;
deferred_handles_ = NULL;
code_stub_ = NULL;
prologue_offset_ = Code::kPrologueOffsetNotSet;
opt_count_ = has_shared_info() ? shared_info()->opt_count() : 0;
no_frame_ranges_ = isolate->cpu_profiler()->is_profiling()
? new List<OffsetRange>(2) : NULL;
if (FLAG_hydrogen_track_positions) {
inlined_function_infos_ = new std::vector<InlinedFunctionInfo>();
track_positions_ = true;
} else {
inlined_function_infos_ = NULL;
track_positions_ = false;
}
for (int i = 0; i < DependentCode::kGroupCount; i++) {
dependencies_[i] = NULL;
}
if (mode == STUB) {
mode_ = STUB;
return;
}
mode_ = mode;
: CompilationInfo(parse_info, nullptr, BASE, parse_info->isolate(),
parse_info->zone()) {
// Compiling for the snapshot typically results in different code than
// compiling later on. This means that code recompiled with deoptimization
// support won't be "equivalent" (as defined by SharedFunctionInfo::
......@@ -147,22 +98,48 @@ void CompilationInfo::Initialize(Isolate* isolate,
if (FLAG_turbo_splitting) MarkAsSplittingEnabled();
if (FLAG_turbo_types) MarkAsTypingEnabled();
bailout_reason_ = kNoReason;
if (has_shared_info() && shared_info()->is_compiled()) {
// We should initialize the CompilationInfo feedback vector from the
// passed in shared info, rather than creating a new one.
feedback_vector_ =
Handle<TypeFeedbackVector>(shared_info()->feedback_vector(), isolate);
feedback_vector_ = Handle<TypeFeedbackVector>(
shared_info()->feedback_vector(), parse_info->isolate());
}
}
CompilationInfo::CompilationInfo(CodeStub* stub, Isolate* isolate, Zone* zone)
: CompilationInfo(nullptr, stub, STUB, isolate, zone) {}
CompilationInfo::CompilationInfo(ParseInfo* parse_info, CodeStub* code_stub,
Mode mode, Isolate* isolate, Zone* zone)
: parse_info_(parse_info),
isolate_(isolate),
flags_(0),
code_stub_(code_stub),
mode_(mode),
osr_ast_id_(BailoutId::None()),
zone_(zone),
deferred_handles_(nullptr),
bailout_reason_(kNoReason),
prologue_offset_(Code::kPrologueOffsetNotSet),
no_frame_ranges_(isolate->cpu_profiler()->is_profiling()
? new List<OffsetRange>(2)
: nullptr),
track_positions_(FLAG_hydrogen_track_positions),
opt_count_(has_shared_info() ? shared_info()->opt_count() : 0),
parameter_count_(0),
optimization_id_(-1),
aborted_due_to_dependency_change_(false),
osr_expr_stack_height_(0) {
std::fill_n(dependencies_, DependentCode::kGroupCount, nullptr);
}
CompilationInfo::~CompilationInfo() {
DisableFutureOptimization();
delete deferred_handles_;
delete no_frame_ranges_;
delete inlined_function_infos_;
#ifdef DEBUG
// Check that no dependent maps have been added or added dependent maps have
// been rolled back or committed.
......@@ -267,9 +244,8 @@ int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
SourcePosition position,
int parent_id) {
DCHECK(track_positions_);
DCHECK(inlined_function_infos_);
int inline_id = static_cast<int>(inlined_function_infos_->size());
int inline_id = static_cast<int>(inlined_function_infos_.size());
InlinedFunctionInfo info(parent_id, position, UnboundScript::kNoScriptId,
shared->start_position());
if (!shared->script()->IsUndefined()) {
......@@ -296,7 +272,7 @@ int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
}
}
inlined_function_infos_->push_back(info);
inlined_function_infos_.push_back(info);
if (FLAG_hydrogen_track_positions && inline_id != 0) {
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
......@@ -312,9 +288,8 @@ int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
void CompilationInfo::LogDeoptCallPosition(int pc_offset, int inlining_id) {
if (!track_positions_ || IsStub()) return;
DCHECK_LT(static_cast<size_t>(inlining_id), inlined_function_infos_->size());
inlined_function_infos_->at(inlining_id)
.deopt_pc_offsets.push_back(pc_offset);
DCHECK_LT(static_cast<size_t>(inlining_id), inlined_function_infos_.size());
inlined_function_infos_.at(inlining_id).deopt_pc_offsets.push_back(pc_offset);
}
......@@ -926,7 +901,9 @@ MaybeHandle<Code> Compiler::GetUnoptimizedCode(
DCHECK(!shared->GetIsolate()->has_pending_exception());
DCHECK(!shared->is_compiled());
CompilationInfoWithZone info(shared);
Zone zone;
ParseInfo parse_info(&zone, shared);
CompilationInfo info(&parse_info);
return GetUnoptimizedCodeCommon(&info);
}
......@@ -953,10 +930,10 @@ bool Compiler::EnsureCompiled(Handle<JSFunction> function,
bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) {
DCHECK(info->function() != NULL);
DCHECK(info->scope() != NULL);
if (!info->shared_info()->has_deoptimization_support()) {
Handle<SharedFunctionInfo> shared = info->shared_info();
if (!shared->has_deoptimization_support()) {
// TODO(titzer): just reuse the ParseInfo for the unoptimized compile.
Handle<SharedFunctionInfo> shared = info->shared_info();
CompilationInfoWithZone unoptimized(shared);
CompilationInfoWithZone unoptimized(info->closure());
// Note that we use the same AST that we will use for generating the
// optimized code.
ParseInfo* parse_info = unoptimized.parse_info();
......@@ -1581,11 +1558,6 @@ CompilationInfoWithZone::CompilationInfoWithZone(Handle<JSFunction> function)
: CompilationInfo(new ParseInfo(&zone_, function)) {}
CompilationInfoWithZone::CompilationInfoWithZone(
Handle<SharedFunctionInfo> shared_info)
: CompilationInfo(new ParseInfo(&zone_, shared_info)) {}
CompilationInfoWithZone::~CompilationInfoWithZone() {
DisableFutureOptimization();
RollbackDependencies();
......
......@@ -346,13 +346,8 @@ class CompilationInfo {
return result;
}
std::vector<InlinedFunctionInfo>* inlined_function_infos() {
return inlined_function_infos_;
}
std::vector<InlinedFunctionInfo>* ReleaseInlinedFunctionInfos() {
std::vector<InlinedFunctionInfo>* tmp = inlined_function_infos_;
inlined_function_infos_ = NULL;
return tmp;
int start_position_for(uint32_t inlining_id) {
return inlined_function_infos_.at(inlining_id).start_position;
}
void LogDeoptCallPosition(int pc_offset, int inlining_id);
......@@ -405,8 +400,6 @@ class CompilationInfo {
}
private:
Isolate* isolate_;
// Compilation mode.
// BASE is generated by the full codegen, optionally prepared for bailouts.
// OPTIMIZE is optimized code generated by the Hydrogen-based backend.
......@@ -419,7 +412,10 @@ class CompilationInfo {
STUB
};
void Initialize(Isolate* isolate, Mode mode, Zone* zone);
CompilationInfo(ParseInfo* parse_info, CodeStub* code_stub, Mode mode,
Isolate* isolate, Zone* zone);
Isolate* isolate_;
void SetMode(Mode mode) {
mode_ = mode;
......@@ -464,7 +460,7 @@ class CompilationInfo {
int prologue_offset_;
List<OffsetRange>* no_frame_ranges_;
std::vector<InlinedFunctionInfo>* inlined_function_infos_;
std::vector<InlinedFunctionInfo> inlined_function_infos_;
bool track_positions_;
// A copy of shared_info()->opt_count() to avoid handle deref
......@@ -493,7 +489,6 @@ class CompilationInfo {
class CompilationInfoWithZone: public CompilationInfo {
public:
explicit CompilationInfoWithZone(Handle<Script> script);
explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info);
explicit CompilationInfoWithZone(Handle<JSFunction> closure);
CompilationInfoWithZone(CodeStub* stub, Isolate* isolate)
: CompilationInfo(stub, isolate, &zone_) {}
......
......@@ -3482,12 +3482,9 @@ void HGraph::FinalizeUniqueness() {
int HGraph::SourcePositionToScriptPosition(SourcePosition pos) {
if (!FLAG_hydrogen_track_positions || pos.IsUnknown()) {
return pos.raw();
}
return info()->inlined_function_infos()->at(pos.inlining_id())
.start_position + pos.position();
return (info()->is_tracking_positions() && !pos.IsUnknown())
? info()->start_position_for(pos.inlining_id()) + pos.position()
: pos.raw();
}
......
......@@ -27,8 +27,9 @@ class ParseInfo {
public:
explicit ParseInfo(Zone* zone);
ParseInfo(Zone* zone, Handle<JSFunction> function);
ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared);
ParseInfo(Zone* zone, Handle<Script> script);
// TODO(all) Only used via Debug::FindSharedFunctionInfoInScript, remove?
ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared);
~ParseInfo() {
if (ast_value_factory_owned()) {
......
......@@ -1218,7 +1218,7 @@ class ScopeIterator {
RetrieveScopeChain(scope, shared_info);
} else {
// Function code
ParseInfo info(&zone, shared_info);
ParseInfo info(&zone, function_);
if (Parser::ParseStatic(&info) && Scope::Analyze(&info)) {
scope = info.function()->scope();
}
......
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