[turbofan] reduce allocations outside of pipeline

BUG=
R=bmeurer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#24904}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24904 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
dcarney@chromium.org 2014-10-27 12:39:20 +00:00
parent a133780e5b
commit 91f4962343
22 changed files with 91 additions and 85 deletions

View File

@ -682,7 +682,7 @@ void CodeGenerator::AssemblePrologue() {
__ stm(db_w, sp, saves);
}
} else if (descriptor->IsJSFunctionCall()) {
CompilationInfo* info = linkage()->info();
CompilationInfo* info = this->info();
__ Prologue(info->IsCodePreAgingActive());
frame()->SetRegisterSaveAreaSize(
StandardFrameConstants::kFixedFrameSizeFromFp);
@ -914,7 +914,7 @@ void CodeGenerator::AddNopForSmiCodeInlining() {
void CodeGenerator::EnsureSpaceForLazyDeopt() {
int space_needed = Deoptimizer::patch_size();
if (!linkage()->info()->IsStub()) {
if (!info()->IsStub()) {
// Ensure that we have enough space after the previous lazy-bailout
// instruction for patching the code here.
int current_pc = masm()->pc_offset();

View File

@ -752,7 +752,7 @@ void CodeGenerator::AssemblePrologue() {
__ PushCalleeSavedRegisters();
frame()->SetRegisterSaveAreaSize(20 * kPointerSize);
} else if (descriptor->IsJSFunctionCall()) {
CompilationInfo* info = linkage()->info();
CompilationInfo* info = this->info();
__ SetStackPointer(jssp);
__ Prologue(info->IsCodePreAgingActive());
frame()->SetRegisterSaveAreaSize(
@ -967,7 +967,7 @@ void CodeGenerator::AddNopForSmiCodeInlining() { __ movz(xzr, 0); }
void CodeGenerator::EnsureSpaceForLazyDeopt() {
int space_needed = Deoptimizer::patch_size();
if (!linkage()->info()->IsStub()) {
if (!info()->IsStub()) {
// Ensure that we have enough space after the previous lazy-bailout
// instruction for patching the code here.
intptr_t current_pc = masm()->pc_offset();

View File

@ -22,10 +22,10 @@ AstGraphBuilder::AstGraphBuilder(Zone* local_zone, CompilationInfo* info,
: StructuredGraphBuilder(local_zone, jsgraph->graph(), jsgraph->common()),
info_(info),
jsgraph_(jsgraph),
globals_(0, info->zone()),
globals_(0, local_zone),
breakable_(NULL),
execution_context_(NULL) {
InitializeAstVisitor(info->zone());
InitializeAstVisitor(local_zone);
}

View File

@ -13,10 +13,11 @@ namespace internal {
namespace compiler {
CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage,
InstructionSequence* code)
InstructionSequence* code, CompilationInfo* info)
: frame_(frame),
linkage_(linkage),
code_(code),
info_(info),
current_block_(BasicBlock::RpoNumber::Invalid()),
current_source_position_(SourcePosition::Invalid()),
masm_(code->zone()->isolate(), NULL, 0),
@ -29,7 +30,7 @@ CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage,
Handle<Code> CodeGenerator::GenerateCode() {
CompilationInfo* info = linkage()->info();
CompilationInfo* info = this->info();
// Emit a code line info recording start event.
PositionsRecorder* recorder = masm()->positions_recorder();
@ -166,7 +167,7 @@ void CodeGenerator::AssembleSourcePosition(SourcePositionInstruction* instr) {
masm()->positions_recorder()->WriteRecordedPositions();
if (FLAG_code_comments) {
Vector<char> buffer = Vector<char>::New(256);
CompilationInfo* info = linkage()->info();
CompilationInfo* info = this->info();
int ln = Script::GetLineNumber(info->script(), code_pos);
int cn = Script::GetColumnNumber(info->script(), code_pos);
if (info->script()->name()->IsString()) {
@ -196,7 +197,7 @@ void CodeGenerator::AssembleGap(GapInstruction* instr) {
void CodeGenerator::PopulateDeoptimizationData(Handle<Code> code_object) {
CompilationInfo* info = linkage()->info();
CompilationInfo* info = this->info();
int deopt_count = static_cast<int>(deoptimization_states_.size());
if (deopt_count == 0) return;
Handle<DeoptimizationInputData> data =

View File

@ -21,7 +21,7 @@ namespace compiler {
class CodeGenerator FINAL : public GapResolver::Assembler {
public:
explicit CodeGenerator(Frame* frame, Linkage* linkage,
InstructionSequence* code);
InstructionSequence* code, CompilationInfo* info);
// Generate native code.
Handle<Code> GenerateCode();
@ -36,6 +36,7 @@ class CodeGenerator FINAL : public GapResolver::Assembler {
GapResolver* resolver() { return &resolver_; }
SafepointTableBuilder* safepoints() { return &safepoints_; }
Zone* zone() const { return code()->zone(); }
CompilationInfo* info() const { return info_; }
// Checks if {block} will appear directly after {current_block_} when
// assembling code, in which case, a fall-through can be used.
@ -118,6 +119,7 @@ class CodeGenerator FINAL : public GapResolver::Assembler {
Frame* const frame_;
Linkage* const linkage_;
InstructionSequence* const code_;
CompilationInfo* const info_;
BasicBlock::RpoNumber current_block_;
SourcePosition current_source_position_;
MacroAssembler masm_;

View File

@ -793,7 +793,7 @@ void CodeGenerator::AssemblePrologue() {
frame->SetRegisterSaveAreaSize(register_save_area_size);
}
} else if (descriptor->IsJSFunctionCall()) {
CompilationInfo* info = linkage()->info();
CompilationInfo* info = this->info();
__ Prologue(info->IsCodePreAgingActive());
frame->SetRegisterSaveAreaSize(
StandardFrameConstants::kFixedFrameSizeFromFp);
@ -1023,7 +1023,7 @@ void CodeGenerator::AddNopForSmiCodeInlining() { __ nop(); }
void CodeGenerator::EnsureSpaceForLazyDeopt() {
int space_needed = Deoptimizer::patch_size();
if (!linkage()->info()->IsStub()) {
if (!info()->IsStub()) {
// Ensure that we have enough space after the previous lazy-bailout
// instruction for patching the code here.
int current_pc = masm()->pc_offset();

View File

@ -19,7 +19,7 @@ namespace compiler {
JSGenericLowering::JSGenericLowering(CompilationInfo* info, JSGraph* jsgraph)
: info_(info),
jsgraph_(jsgraph),
linkage_(new (jsgraph->zone()) Linkage(info)) {}
linkage_(new (jsgraph->zone()) Linkage(jsgraph->zone(), info)) {}
void JSGenericLowering::PatchOperator(Node* node, const Operator* op) {

View File

@ -39,28 +39,30 @@ std::ostream& operator<<(std::ostream& os, const CallDescriptor& d) {
}
Linkage::Linkage(CompilationInfo* info) : info_(info) {
CallDescriptor* Linkage::ComputeIncoming(Zone* zone, CompilationInfo* info) {
if (info->function() != NULL) {
// If we already have the function literal, use the number of parameters
// plus the receiver.
incoming_ = GetJSCallDescriptor(1 + info->function()->parameter_count());
} else if (!info->closure().is_null()) {
return GetJSCallDescriptor(1 + info->function()->parameter_count(), zone);
}
if (!info->closure().is_null()) {
// If we are compiling a JS function, use a JS call descriptor,
// plus the receiver.
SharedFunctionInfo* shared = info->closure()->shared();
incoming_ = GetJSCallDescriptor(1 + shared->formal_parameter_count());
} else if (info->code_stub() != NULL) {
return GetJSCallDescriptor(1 + shared->formal_parameter_count(), zone);
}
if (info->code_stub() != NULL) {
// Use the code stub interface descriptor.
CallInterfaceDescriptor descriptor =
info->code_stub()->GetCallInterfaceDescriptor();
incoming_ = GetStubCallDescriptor(descriptor);
} else {
incoming_ = NULL; // TODO(titzer): ?
return GetStubCallDescriptor(descriptor, 0, CallDescriptor::kNoFlags, zone);
}
return NULL; // TODO(titzer): ?
}
FrameOffset Linkage::GetFrameOffset(int spill_slot, Frame* frame, int extra) {
FrameOffset Linkage::GetFrameOffset(int spill_slot, Frame* frame,
int extra) const {
if (frame->GetSpillSlotCount() > 0 || incoming_->IsJSFunctionCall() ||
incoming_->kind() == CallDescriptor::kCallAddress) {
int offset;
@ -87,24 +89,22 @@ FrameOffset Linkage::GetFrameOffset(int spill_slot, Frame* frame, int extra) {
}
CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count) {
return GetJSCallDescriptor(parameter_count, this->info_->zone());
CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count) const {
return GetJSCallDescriptor(parameter_count, zone_);
}
CallDescriptor* Linkage::GetRuntimeCallDescriptor(
Runtime::FunctionId function, int parameter_count,
Operator::Properties properties) {
return GetRuntimeCallDescriptor(function, parameter_count, properties,
this->info_->zone());
Operator::Properties properties) const {
return GetRuntimeCallDescriptor(function, parameter_count, properties, zone_);
}
CallDescriptor* Linkage::GetStubCallDescriptor(
CallInterfaceDescriptor descriptor, int stack_parameter_count,
CallDescriptor::Flags flags) {
return GetStubCallDescriptor(descriptor, stack_parameter_count, flags,
this->info_->zone());
CallDescriptor::Flags flags) const {
return GetStubCallDescriptor(descriptor, stack_parameter_count, flags, zone_);
}

View File

@ -129,16 +129,18 @@ class CallDescriptor FINAL : public ZoneObject {
private:
friend class Linkage;
Kind kind_;
MachineType target_type_;
LinkageLocation target_loc_;
MachineSignature* machine_sig_;
LocationSignature* location_sig_;
size_t js_param_count_;
Operator::Properties properties_;
RegList callee_saved_registers_;
Flags flags_;
const char* debug_name_;
const Kind kind_;
const MachineType target_type_;
const LinkageLocation target_loc_;
const MachineSignature* const machine_sig_;
const LocationSignature* const location_sig_;
const size_t js_param_count_;
const Operator::Properties properties_;
const RegList callee_saved_registers_;
const Flags flags_;
const char* const debug_name_;
DISALLOW_COPY_AND_ASSIGN(CallDescriptor);
};
DEFINE_OPERATORS_FOR_FLAGS(CallDescriptor::Flags)
@ -161,25 +163,28 @@ std::ostream& operator<<(std::ostream& os, const CallDescriptor::Kind& k);
// Call[Runtime] CEntryStub, arg 1, arg 2, arg 3, [...], fun, #arg, context
class Linkage : public ZoneObject {
public:
explicit Linkage(CompilationInfo* info);
explicit Linkage(CompilationInfo* info, CallDescriptor* incoming)
: info_(info), incoming_(incoming) {}
Linkage(Zone* zone, CompilationInfo* info)
: zone_(zone), incoming_(ComputeIncoming(zone, info)) {}
Linkage(Zone* zone, CallDescriptor* incoming)
: zone_(zone), incoming_(incoming) {}
static CallDescriptor* ComputeIncoming(Zone* zone, CompilationInfo* info);
// The call descriptor for this compilation unit describes the locations
// of incoming parameters and the outgoing return value(s).
CallDescriptor* GetIncomingDescriptor() { return incoming_; }
CallDescriptor* GetJSCallDescriptor(int parameter_count);
CallDescriptor* GetIncomingDescriptor() const { return incoming_; }
CallDescriptor* GetJSCallDescriptor(int parameter_count) const;
static CallDescriptor* GetJSCallDescriptor(int parameter_count, Zone* zone);
CallDescriptor* GetRuntimeCallDescriptor(Runtime::FunctionId function,
int parameter_count,
Operator::Properties properties);
CallDescriptor* GetRuntimeCallDescriptor(
Runtime::FunctionId function, int parameter_count,
Operator::Properties properties) const;
static CallDescriptor* GetRuntimeCallDescriptor(
Runtime::FunctionId function, int parameter_count,
Operator::Properties properties, Zone* zone);
CallDescriptor* GetStubCallDescriptor(
CallInterfaceDescriptor descriptor, int stack_parameter_count = 0,
CallDescriptor::Flags flags = CallDescriptor::kNoFlags);
CallDescriptor::Flags flags = CallDescriptor::kNoFlags) const;
static CallDescriptor* GetStubCallDescriptor(
CallInterfaceDescriptor descriptor, int stack_parameter_count,
CallDescriptor::Flags flags, Zone* zone);
@ -192,37 +197,37 @@ class Linkage : public ZoneObject {
MachineSignature* sig);
// Get the location of an (incoming) parameter to this function.
LinkageLocation GetParameterLocation(int index) {
LinkageLocation GetParameterLocation(int index) const {
return incoming_->GetInputLocation(index + 1); // + 1 to skip target.
}
// Get the machine type of an (incoming) parameter to this function.
MachineType GetParameterType(int index) {
MachineType GetParameterType(int index) const {
return incoming_->GetInputType(index + 1); // + 1 to skip target.
}
// Get the location where this function should place its return value.
LinkageLocation GetReturnLocation() {
LinkageLocation GetReturnLocation() const {
return incoming_->GetReturnLocation(0);
}
// Get the machine type of this function's return value.
MachineType GetReturnType() { return incoming_->GetReturnType(0); }
MachineType GetReturnType() const { return incoming_->GetReturnType(0); }
// Get the frame offset for a given spill slot. The location depends on the
// calling convention and the specific frame layout, and may thus be
// architecture-specific. Negative spill slots indicate arguments on the
// caller's frame. The {extra} parameter indicates an additional offset from
// the frame offset, e.g. to index into part of a double slot.
FrameOffset GetFrameOffset(int spill_slot, Frame* frame, int extra = 0);
CompilationInfo* info() const { return info_; }
FrameOffset GetFrameOffset(int spill_slot, Frame* frame, int extra = 0) const;
static bool NeedsFrameState(Runtime::FunctionId function);
private:
CompilationInfo* info_;
CallDescriptor* incoming_;
Zone* const zone_;
CallDescriptor* const incoming_;
DISALLOW_COPY_AND_ASSIGN(Linkage);
};
} // namespace compiler

View File

@ -709,7 +709,7 @@ void CodeGenerator::AssemblePrologue() {
__ MultiPush(saves);
}
} else if (descriptor->IsJSFunctionCall()) {
CompilationInfo* info = linkage()->info();
CompilationInfo* info = this->info();
__ Prologue(info->IsCodePreAgingActive());
frame()->SetRegisterSaveAreaSize(
StandardFrameConstants::kFixedFrameSizeFromFp);
@ -942,7 +942,7 @@ void CodeGenerator::AddNopForSmiCodeInlining() {
void CodeGenerator::EnsureSpaceForLazyDeopt() {
int space_needed = Deoptimizer::patch_size();
if (!linkage()->info()->IsStub()) {
if (!info()->IsStub()) {
// Ensure that we have enough space after the previous lazy-bailout
// instruction for patching the code here.
int current_pc = masm()->pc_offset();

View File

@ -397,7 +397,7 @@ Handle<Code> Pipeline::GenerateCode() {
PhaseScope phase_scope(pipeline_statistics.get(), "change lowering");
SourcePositionTable::Scope pos(data.source_positions(),
SourcePosition::Unknown());
Linkage linkage(info());
Linkage linkage(data.graph_zone(), info());
ValueNumberingReducer vn_reducer(data.graph_zone());
SimplifiedOperatorReducer simple_reducer(data.jsgraph());
ChangeLowering lowering(data.jsgraph(), &linkage);
@ -452,7 +452,7 @@ Handle<Code> Pipeline::GenerateCode() {
Handle<Code> code = Handle<Code>::null();
{
// Generate optimized code.
Linkage linkage(info());
Linkage linkage(data.instruction_zone(), info());
code = GenerateCode(&linkage, &data);
info()->SetCode(code);
}
@ -552,14 +552,13 @@ Handle<Code> Pipeline::GenerateCode(Linkage* linkage, PipelineData* data) {
{
int node_count = sequence.VirtualRegisterCount();
if (node_count > UnallocatedOperand::kMaxVirtualRegisters) {
linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersForValues);
info()->AbortOptimization(kNotEnoughVirtualRegistersForValues);
return Handle<Code>::null();
}
ZonePool::Scope zone_scope(data->zone_pool());
RegisterAllocator allocator(zone_scope.zone(), &frame, linkage->info(),
&sequence);
RegisterAllocator allocator(zone_scope.zone(), &frame, info(), &sequence);
if (!allocator.Allocate(data->pipeline_statistics())) {
linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc);
info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc);
return Handle<Code>::null();
}
if (FLAG_trace_turbo) {
@ -582,7 +581,7 @@ Handle<Code> Pipeline::GenerateCode(Linkage* linkage, PipelineData* data) {
Handle<Code> code;
{
PhaseScope phase_scope(data->pipeline_statistics(), "generate code");
CodeGenerator generator(&frame, linkage, &sequence);
CodeGenerator generator(&frame, linkage, &sequence, info());
code = generator.GenerateCode();
}
if (profiler_data != NULL) {

View File

@ -766,7 +766,7 @@ void CodeGenerator::AssemblePrologue() {
frame()->SetRegisterSaveAreaSize(register_save_area_size);
}
} else if (descriptor->IsJSFunctionCall()) {
CompilationInfo* info = linkage()->info();
CompilationInfo* info = this->info();
__ Prologue(info->IsCodePreAgingActive());
frame()->SetRegisterSaveAreaSize(
StandardFrameConstants::kFixedFrameSizeFromFp);
@ -992,7 +992,7 @@ void CodeGenerator::AddNopForSmiCodeInlining() { __ nop(); }
void CodeGenerator::EnsureSpaceForLazyDeopt() {
int space_needed = Deoptimizer::patch_size();
if (!linkage()->info()->IsStub()) {
if (!info()->IsStub()) {
// Ensure that we have enough space after the previous lazy-bailout
// instruction for patching the code here.
int current_pc = masm()->pc_offset();

View File

@ -66,7 +66,7 @@ class MachineAssemblerTester : public HandleAndZoneScope,
CallDescriptor* call_descriptor = this->call_descriptor();
Graph* graph = this->graph();
CompilationInfo info(graph->zone()->isolate(), graph->zone());
Linkage linkage(&info, call_descriptor);
Linkage linkage(graph->zone(), call_descriptor);
Pipeline pipeline(&info);
code_ = pipeline.GenerateCodeForMachineGraph(&linkage, graph, schedule);
}

View File

@ -221,7 +221,7 @@ class FunctionTester : public InitializedHandleScope {
CHECK(Compiler::EnsureDeoptimizationSupport(&info));
Pipeline pipeline(&info);
Linkage linkage(&info);
Linkage linkage(info.zone(), &info);
Handle<Code> code = pipeline.GenerateCodeForMachineGraph(&linkage, graph);
CHECK(!code.is_null());
function->ReplaceCode(*code);

View File

@ -36,7 +36,7 @@ byte* MachineCallHelper::Generate() {
if (code_.is_null()) {
Zone* zone = graph_->zone();
CompilationInfo info(zone->isolate(), zone);
Linkage linkage(&info,
Linkage linkage(zone,
Linkage::GetSimplifiedCDescriptor(zone, machine_sig_));
Pipeline pipeline(&info);
code_ = pipeline.GenerateCodeForMachineGraph(&linkage, graph_);

View File

@ -125,7 +125,7 @@ class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
void LowerChange(Node* change) {
// Run the graph reducer with changes lowering on a single node.
CompilationInfo info(this->isolate(), this->zone());
Linkage linkage(&info);
Linkage linkage(this->zone(), &info);
ChangeLowering lowering(&jsgraph, &linkage);
GraphReducer reducer(this->graph());
reducer.AddReducer(&lowering);

View File

@ -66,7 +66,7 @@ class DeoptCodegenTester {
}
// Initialize the codegen and generate code.
Linkage* linkage = new (scope_->main_zone()) Linkage(&info);
Linkage* linkage = new (scope_->main_zone()) Linkage(info.zone(), &info);
code = new v8::internal::compiler::InstructionSequence(scope_->main_zone(),
graph, schedule);
SourcePositionTable source_positions(graph);
@ -88,7 +88,7 @@ class DeoptCodegenTester {
<< *code;
}
compiler::CodeGenerator generator(&frame, linkage, code);
compiler::CodeGenerator generator(&frame, linkage, code, &info);
result_code = generator.GenerateCode();
#ifdef OBJECT_PRINT

View File

@ -31,7 +31,7 @@ class InstructionTester : public HandleAndZoneScope {
graph(zone()),
schedule(zone()),
info(static_cast<HydrogenCodeStub*>(NULL), main_isolate()),
linkage(&info),
linkage(zone(), &info),
common(zone()),
code(NULL) {}

View File

@ -45,7 +45,7 @@ TEST(TestLinkageCreate) {
InitializedHandleScope handles;
Handle<JSFunction> function = Compile("a + b");
CompilationInfoWithZone info(function);
Linkage linkage(&info);
Linkage linkage(info.zone(), &info);
}
@ -60,7 +60,7 @@ TEST(TestLinkageJSFunctionIncoming) {
Handle<JSFunction> function = v8::Utils::OpenHandle(
*v8::Handle<v8::Function>::Cast(CompileRun(sources[i])));
CompilationInfoWithZone info(function);
Linkage linkage(&info);
Linkage linkage(info.zone(), &info);
CallDescriptor* descriptor = linkage.GetIncomingDescriptor();
CHECK_NE(NULL, descriptor);
@ -76,7 +76,7 @@ TEST(TestLinkageJSFunctionIncoming) {
TEST(TestLinkageCodeStubIncoming) {
Isolate* isolate = CcTest::InitIsolateOnce();
CompilationInfoWithZone info(static_cast<HydrogenCodeStub*>(NULL), isolate);
Linkage linkage(&info);
Linkage linkage(info.zone(), &info);
// TODO(titzer): test linkage creation with a bonafide code stub.
// this just checks current behavior.
CHECK_EQ(NULL, linkage.GetIncomingDescriptor());
@ -87,7 +87,7 @@ TEST(TestLinkageJSCall) {
HandleAndZoneScope handles;
Handle<JSFunction> function = Compile("a + c");
CompilationInfoWithZone info(function);
Linkage linkage(&info);
Linkage linkage(info.zone(), &info);
for (int i = 0; i < 32; i++) {
CallDescriptor* descriptor = linkage.GetJSCallDescriptor(i);

View File

@ -61,7 +61,7 @@ class SimplifiedLoweringTester : public GraphBuilderTester<ReturnType> {
Zone* zone = this->zone();
CompilationInfo info(zone->isolate(), zone);
Linkage linkage(
&info, Linkage::GetSimplifiedCDescriptor(zone, this->machine_sig_));
zone, Linkage::GetSimplifiedCDescriptor(zone, this->machine_sig_));
ChangeLowering lowering(&jsgraph, &linkage);
GraphReducer reducer(this->graph());
reducer.AddReducer(&lowering);

View File

@ -69,7 +69,7 @@ class ChangeLoweringTest : public GraphTest {
JSOperatorBuilder javascript(zone());
JSGraph jsgraph(graph(), common(), &javascript, &machine);
CompilationInfo info(isolate(), zone());
Linkage linkage(&info);
Linkage linkage(zone(), &info);
ChangeLowering reducer(&jsgraph, &linkage);
return reducer.Reduce(node);
}

View File

@ -36,8 +36,7 @@ InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build(
}
EXPECT_NE(0, graph()->NodeCount());
int initial_node_count = graph()->NodeCount();
CompilationInfo info(test_->isolate(), test_->zone());
Linkage linkage(&info, call_descriptor());
Linkage linkage(test_->zone(), call_descriptor());
InstructionSequence sequence(test_->zone(), graph(), schedule);
SourcePositionTable source_position_table(graph());
InstructionSelector selector(test_->zone(), &linkage, &sequence, schedule,