Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(895)

Unified Diff: runtime/vm/flow_graph_compiler_x64.cc

Issue 10447133: FlowGraphCompiler is not a visitor any longer. Start consolidating shared code between the x64 and … (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/flow_graph_compiler_x64.cc
===================================================================
--- runtime/vm/flow_graph_compiler_x64.cc (revision 8180)
+++ runtime/vm/flow_graph_compiler_x64.cc (working copy)
@@ -87,48 +87,24 @@
const ParsedFunction& parsed_function,
const GrowableArray<BlockEntryInstr*>& block_order,
bool is_optimizing)
- : FlowGraphVisitor(block_order),
+ : FlowGraphCompilerShared(parsed_function, block_order.length()),
assembler_(assembler),
- parsed_function_(parsed_function),
- block_info_(block_order.length()),
+ block_order_(block_order),
current_block_(NULL),
- pc_descriptors_list_(NULL),
- stackmap_builder_(NULL),
- exception_handlers_list_(NULL),
deopt_stubs_(),
is_optimizing_(is_optimizing) {
}
-void FlowGraphCompiler::InitCompiler() {
- pc_descriptors_list_ = new DescriptorList();
- exception_handlers_list_ = new ExceptionHandlerList();
- block_info_.Clear();
- for (int i = 0; i < block_order_.length(); ++i) {
- block_info_.Add(new BlockInfo());
- }
-}
-
-
-FlowGraphCompiler::~FlowGraphCompiler() {
- // BlockInfos are zone-allocated, so their destructors are not called.
- // Verify the labels explicitly here.
- for (int i = 0; i < block_info_.length(); ++i) {
- ASSERT(!block_info_[i]->label.IsLinked());
- ASSERT(!block_info_[i]->label.HasNear());
- }
-}
-
-
intptr_t FlowGraphCompiler::StackSize() const {
- return parsed_function_.stack_local_count() +
- parsed_function_.copied_parameter_count();
+ return parsed_function().stack_local_count() +
+ parsed_function().copied_parameter_count();
}
void FlowGraphCompiler::Bailout(const char* reason) {
const char* kFormat = "FlowGraphCompiler Bailout: %s %s.";
- const char* function_name = parsed_function_.function().ToCString();
+ const char* function_name = parsed_function().function().ToCString();
intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1;
char* chars = reinterpret_cast<char*>(
Isolate::Current()->current_zone()->Allocate(len));
@@ -622,30 +598,6 @@
}
-void FlowGraphCompiler::VisitUse(UseVal* val) {
- // UseVal is never visited during code generation.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitConstant(ConstantVal* val) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitAssertAssignable(AssertAssignableComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitAssertBoolean(AssertBooleanComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
void FlowGraphCompiler::EmitInstanceCall(intptr_t cid,
intptr_t token_index,
intptr_t try_index,
@@ -654,7 +606,7 @@
const Array& argument_names,
intptr_t checked_argument_count) {
ICData& ic_data =
- ICData::ZoneHandle(ICData::New(parsed_function_.function(),
+ ICData::ZoneHandle(ICData::New(parsed_function().function(),
function_name,
cid,
checked_argument_count));
@@ -699,115 +651,6 @@
}
-void FlowGraphCompiler::VisitCurrentContext(CurrentContextComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitStoreContext(StoreContextComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitClosureCall(ClosureCallComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitInstanceCall(InstanceCallComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitStrictCompare(StrictCompareComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitEqualityCompare(EqualityCompareComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitStaticCall(StaticCallComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitLoadLocal(LoadLocalComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitStoreLocal(StoreLocalComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitNativeCall(NativeCallComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitLoadInstanceField(LoadInstanceFieldComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitStoreInstanceField(StoreInstanceFieldComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-
-void FlowGraphCompiler::VisitLoadStaticField(LoadStaticFieldComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitStoreStaticField(StoreStaticFieldComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitStoreIndexed(StoreIndexedComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitInstanceSetter(InstanceSetterComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitStaticSetter(StaticSetterComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitBooleanNegate(BooleanNegateComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
// Optimize instanceof type test by adding inlined tests for:
// - NULL -> return false.
// - Smi -> compile time subtype check (only if dst class is not parameterized).
@@ -892,109 +735,6 @@
}
-void FlowGraphCompiler::VisitInstanceOf(InstanceOfComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitAllocateObject(AllocateObjectComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitAllocateObjectWithBoundsCheck(
- AllocateObjectWithBoundsCheckComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitCreateArray(CreateArrayComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitCreateClosure(CreateClosureComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitLoadVMField(LoadVMFieldComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitStoreVMField(StoreVMFieldComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitInstantiateTypeArguments(
- InstantiateTypeArgumentsComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitExtractConstructorTypeArguments(
- ExtractConstructorTypeArgumentsComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitExtractConstructorInstantiator(
- ExtractConstructorInstantiatorComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitAllocateContext(AllocateContextComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitChainContext(ChainContextComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitCloneContext(CloneContextComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitCatchEntry(CatchEntryComp* comp) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitBinaryOp(BinaryOpComp* comp) {
- UNIMPLEMENTED();
-}
-
-
-void FlowGraphCompiler::VisitUnarySmiOp(UnarySmiOpComp* comp) {
- UNIMPLEMENTED();
-}
-
-
-void FlowGraphCompiler::VisitNumberNegate(NumberNegateComp* comp) {
- UNIMPLEMENTED();
-}
-
-
void FlowGraphCompiler::EmitInstructionPrologue(Instruction* instr) {
LocationSummary* locs = instr->locs();
ASSERT(locs != NULL);
@@ -1015,17 +755,15 @@
__ Comment("B%d", i);
// Compile the block entry.
current_block_ = block_order_[i];
- Instruction* instr = current_block()->Accept(this);
+ current_block_->EmitNativeCode(this);
Vyacheslav Egorov (Google) 2012/06/01 10:55:24 This is extremely confusing to read, if I did not
srdjan 2012/06/01 17:44:47 Agreed with readability problem, needs at least a
+ Instruction* instr = current_block_->StraightLineSuccessor();
// Compile all successors until an exit, branch, or a block entry.
while ((instr != NULL) && !instr->IsBlockEntry()) {
if (FLAG_code_comments) EmitComment(instr);
- if (instr->locs() != NULL) {
- EmitInstructionPrologue(instr);
- instr->EmitNativeCode(this);
- instr = instr->StraightLineSuccessor();
- } else {
- instr = instr->Accept(this);
- }
+ ASSERT(instr->locs() != NULL);
+ EmitInstructionPrologue(instr);
+ instr->EmitNativeCode(this);
+ instr = instr->StraightLineSuccessor();
}
BlockEntryInstr* successor =
@@ -1035,7 +773,7 @@
// next block in the list. Otherwise, we need a jump.
if ((i == block_order_.length() - 1) ||
(block_order_[i + 1] != successor)) {
- __ jmp(&block_info_[successor->postorder_number()]->label);
+ __ jmp(&block_info()[successor->postorder_number()]->label);
Vyacheslav Egorov (Google) 2012/06/01 10:55:24 use GetLabelFor?
srdjan 2012/06/01 17:44:47 Done.
}
}
}
@@ -1050,68 +788,13 @@
}
-void FlowGraphCompiler::VisitGraphEntry(GraphEntryInstr* instr) {
- // Nothing to do.
-}
-
-
-void FlowGraphCompiler::VisitJoinEntry(JoinEntryInstr* instr) {
- __ Bind(&block_info_[instr->postorder_number()]->label);
-}
-
-
-void FlowGraphCompiler::VisitTargetEntry(TargetEntryInstr* instr) {
- __ Bind(&block_info_[instr->postorder_number()]->label);
- if (instr->HasTryIndex()) {
- exception_handlers_list_->AddHandler(instr->try_index(),
- assembler_->CodeSize());
- }
-}
-
-
-void FlowGraphCompiler::VisitDo(DoInstr* instr) {
- instr->computation()->Accept(this);
-}
-
-
-void FlowGraphCompiler::VisitBind(BindInstr* instr) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitReturn(ReturnInstr* instr) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitThrow(ThrowInstr* instr) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-void FlowGraphCompiler::VisitReThrow(ReThrowInstr* instr) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
-
-void FlowGraphCompiler::VisitBranch(BranchInstr* instr) {
- // Moved to intermediate_language_x64.cc.
- UNREACHABLE();
-}
-
-
// Copied from CodeGenerator::CopyParameters (CodeGenerator will be deprecated).
void FlowGraphCompiler::CopyParameters() {
- const Function& function = parsed_function_.function();
- LocalScope* scope = parsed_function_.node_sequence()->scope();
+ const Function& function = parsed_function().function();
+ LocalScope* scope = parsed_function().node_sequence()->scope();
const int num_fixed_params = function.num_fixed_parameters();
const int num_opt_params = function.num_optional_parameters();
- ASSERT(parsed_function_.first_parameter_index() ==
+ ASSERT(parsed_function().first_parameter_index() ==
ParsedFunction::kFirstLocalSlotIndex);
// Copy positional arguments.
// Check that no fewer than num_fixed_params positional arguments are passed
@@ -1212,7 +895,7 @@
__ Bind(&load_default_value);
// Load RAX with default argument at pos.
const Object& value = Object::ZoneHandle(
- parsed_function_.default_parameter_values().At(
+ parsed_function().default_parameter_values().At(
param_pos - num_fixed_params));
__ LoadObject(RAX, value);
__ Bind(&assign_optional_parameter);
@@ -1250,7 +933,7 @@
// Invoke noSuchMethod function.
const int kNumArgsChecked = 1;
ICData& ic_data = ICData::ZoneHandle();
- ic_data = ICData::New(parsed_function_.function(),
+ ic_data = ICData::New(parsed_function().function(),
String::Handle(function.name()),
AstNode::kNoId,
kNumArgsChecked);
@@ -1312,7 +995,7 @@
// TOS: return address.
// +1 : receiver.
// Sequence node has one return node, its input is load field node.
- const SequenceNode& sequence_node = *parsed_function_.node_sequence();
+ const SequenceNode& sequence_node = *parsed_function().node_sequence();
ASSERT(sequence_node.length() == 1);
ASSERT(sequence_node.NodeAt(0)->IsReturnNode());
const ReturnNode& return_node = *sequence_node.NodeAt(0)->AsReturnNode();
@@ -1330,7 +1013,7 @@
// +1 : value
// +2 : receiver.
// Sequence node has one store node and one return NULL node.
- const SequenceNode& sequence_node = *parsed_function_.node_sequence();
+ const SequenceNode& sequence_node = *parsed_function().node_sequence();
ASSERT(sequence_node.length() == 2);
ASSERT(sequence_node.NodeAt(0)->IsStoreInstanceFieldNode());
ASSERT(sequence_node.NodeAt(1)->IsReturnNode());
@@ -1353,11 +1036,11 @@
// Intrinsification skips arguments checks, therefore disable if in checked
// mode.
if (FLAG_intrinsify && !FLAG_trace_functions && !FLAG_enable_type_checks) {
- if ((parsed_function_.function().kind() == RawFunction::kImplicitGetter)) {
+ if ((parsed_function().function().kind() == RawFunction::kImplicitGetter)) {
IntrinsifyGetter();
return true;
}
- if ((parsed_function_.function().kind() == RawFunction::kImplicitSetter)) {
+ if ((parsed_function().function().kind() == RawFunction::kImplicitSetter)) {
IntrinsifySetter();
return true;
}
@@ -1365,7 +1048,7 @@
// Even if an intrinsified version of the function was successfully
// generated, it may fall through to the non-intrinsified method body.
if (!FLAG_trace_functions) {
- return Intrinsifier::Intrinsify(parsed_function_.function(), assembler_);
+ return Intrinsifier::Intrinsify(parsed_function().function(), assembler_);
}
return false;
}
@@ -1382,11 +1065,11 @@
return;
}
// Specialized version of entry code from CodeGenerator::GenerateEntryCode.
- const Function& function = parsed_function_.function();
+ const Function& function = parsed_function().function();
const int parameter_count = function.num_fixed_parameters();
- const int num_copied_params = parsed_function_.copied_parameter_count();
- const int local_count = parsed_function_.stack_local_count();
+ const int num_copied_params = parsed_function().copied_parameter_count();
+ const int local_count = parsed_function().stack_local_count();
AssemblerMacros::EnterDartFrame(assembler_, (StackSize() * kWordSize));
// We check the number of passed arguments when we have to copy them due to
@@ -1423,7 +1106,7 @@
// Initialize locals to null.
if (local_count > 0) {
__ movq(RAX, Immediate(reinterpret_cast<intptr_t>(Object::null())));
- const int base = parsed_function_.first_stack_local_index();
+ const int base = parsed_function().first_stack_local_index();
for (int i = 0; i < local_count; ++i) {
// Subtract index i (locals lie at lower addresses than RBP).
__ movq(Address(RBP, (base - i) * kWordSize), RAX);
@@ -1448,7 +1131,7 @@
// Second printing.
OS::Print("Annotated ");
}
- AstPrinter::PrintFunctionScope(parsed_function_);
+ AstPrinter::PrintFunctionScope(parsed_function());
}
VisitBlocks();
@@ -1457,11 +1140,11 @@
GenerateDeferredCode();
// Emit function patching code. This will be swapped with the first 13 bytes
// at entry point.
- pc_descriptors_list_->AddDescriptor(PcDescriptors::kPatchCode,
- assembler_->CodeSize(),
- AstNode::kNoId,
- 0,
- -1);
+ pc_descriptors_list()->AddDescriptor(PcDescriptors::kPatchCode,
+ assembler_->CodeSize(),
+ AstNode::kNoId,
+ 0,
+ -1);
__ jmp(&StubCode::FixCallersTargetLabel());
}
@@ -1497,11 +1180,11 @@
intptr_t cid,
intptr_t token_index,
intptr_t try_index) {
- pc_descriptors_list_->AddDescriptor(kind,
- assembler_->CodeSize(),
- cid,
- token_index,
- try_index);
+ pc_descriptors_list()->AddDescriptor(kind,
+ assembler_->CodeSize(),
+ cid,
+ token_index,
+ try_index);
}
@@ -1520,42 +1203,6 @@
}
-void FlowGraphCompiler::FinalizePcDescriptors(const Code& code) {
- ASSERT(pc_descriptors_list_ != NULL);
- const PcDescriptors& descriptors = PcDescriptors::Handle(
- pc_descriptors_list_->FinalizePcDescriptors(code.EntryPoint()));
- descriptors.Verify(parsed_function_.function().is_optimizable());
- code.set_pc_descriptors(descriptors);
-}
-
-
-void FlowGraphCompiler::FinalizeStackmaps(const Code& code) {
- if (stackmap_builder_ == NULL) {
- // The unoptimizing compiler has no stack maps.
- code.set_stackmaps(Array::Handle());
- } else {
- // Finalize the stack map array and add it to the code object.
- code.set_stackmaps(
- Array::Handle(stackmap_builder_->FinalizeStackmaps(code)));
- }
-}
-
-
-void FlowGraphCompiler::FinalizeVarDescriptors(const Code& code) {
- const LocalVarDescriptors& var_descs = LocalVarDescriptors::Handle(
- parsed_function_.node_sequence()->scope()->GetVarDescriptors());
- code.set_var_descriptors(var_descs);
-}
-
-
-void FlowGraphCompiler::FinalizeExceptionHandlers(const Code& code) {
- ASSERT(exception_handlers_list_ != NULL);
- const ExceptionHandlers& handlers = ExceptionHandlers::Handle(
- exception_handlers_list_->FinalizeExceptionHandlers(code.EntryPoint()));
- code.set_exception_handlers(handlers);
-}
-
-
void FlowGraphCompiler::FinalizeComments(const Code& code) {
code.set_comments(assembler_->GetCodeComments());
}

Powered by Google App Engine
This is Rietveld 408576698