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

Side by Side Diff: runtime/vm/flow_graph_compiler_x64.cc

Issue 10431006: First step toward an optimizing compiler: (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64.
6 #if defined(TARGET_ARCH_X64) 6 #if defined(TARGET_ARCH_X64)
7 7
8 #include "vm/flow_graph_compiler.h" 8 #include "vm/flow_graph_compiler.h"
9 9
10 #include "lib/error.h" 10 #include "lib/error.h"
(...skipping 14 matching lines...) Expand all
25 25
26 DEFINE_FLAG(bool, print_scopes, false, "Print scopes of local variables."); 26 DEFINE_FLAG(bool, print_scopes, false, "Print scopes of local variables.");
27 DEFINE_FLAG(bool, trace_functions, false, "Trace entry of each function."); 27 DEFINE_FLAG(bool, trace_functions, false, "Trace entry of each function.");
28 DECLARE_FLAG(bool, enable_type_checks); 28 DECLARE_FLAG(bool, enable_type_checks);
29 DECLARE_FLAG(bool, intrinsify); 29 DECLARE_FLAG(bool, intrinsify);
30 DECLARE_FLAG(bool, optimization_counter_threshold); 30 DECLARE_FLAG(bool, optimization_counter_threshold);
31 DECLARE_FLAG(bool, print_ast); 31 DECLARE_FLAG(bool, print_ast);
32 DECLARE_FLAG(bool, report_usage_count); 32 DECLARE_FLAG(bool, report_usage_count);
33 DECLARE_FLAG(bool, code_comments); 33 DECLARE_FLAG(bool, code_comments);
34 34
35 class DeoptimizationStub : public ZoneAllocated {
36 public:
37 DeoptimizationStub(intptr_t deopt_id,
38 intptr_t deopt_token_index,
39 intptr_t try_index,
40 DeoptReasonId reason)
41 : deopt_id_(deopt_id),
42 deopt_token_index_(deopt_token_index),
43 try_index_(try_index),
44 reason_(reason),
45 registers_(2),
46 entry_label_() {}
47
48 void Push(Register reg) { registers_.Add(reg); }
49 Label* entry_label() { return &entry_label_; }
50
51 void GenerateCode(FlowGraphCompiler* compiler);
52
53 private:
54 const intptr_t deopt_id_;
55 const intptr_t deopt_token_index_;
56 const intptr_t try_index_;
57 const DeoptReasonId reason_;
58 GrowableArray<Register> registers_;
59 Label entry_label_;
60
61 DISALLOW_COPY_AND_ASSIGN(DeoptimizationStub);
62 };
63
64
65 void DeoptimizationStub::GenerateCode(FlowGraphCompiler* compiler) {
66 Assembler* assem = compiler->assembler();
67 assem->Comment("Deopt stub for id %d", deopt_id_);
68 assem->Bind(entry_label());
Florian Schneider 2012/05/24 00:20:39 Maybe make a temporary definition of the __ macro
srdjan 2012/05/24 01:36:26 Done
69 for (intptr_t i = 0; i < registers_.length(); i++) {
70 assem->pushq(registers_[i]);
71 }
72 assem->movq(RAX, Immediate(Smi::RawValue(reason_)));
73 assem->call(&StubCode::DeoptimizeLabel());
74 compiler->AddCurrentDescriptor(PcDescriptors::kOther,
75 deopt_id_,
76 deopt_token_index_,
77 try_index_);
78 }
79
35 80
36 FlowGraphCompiler::FlowGraphCompiler( 81 FlowGraphCompiler::FlowGraphCompiler(
37 Assembler* assembler, 82 Assembler* assembler,
38 const ParsedFunction& parsed_function, 83 const ParsedFunction& parsed_function,
39 const GrowableArray<BlockEntryInstr*>& block_order, 84 const GrowableArray<BlockEntryInstr*>& block_order,
40 bool is_optimizing) 85 bool is_optimizing)
41 : FlowGraphVisitor(block_order), 86 : FlowGraphVisitor(block_order),
42 assembler_(assembler), 87 assembler_(assembler),
43 parsed_function_(parsed_function), 88 parsed_function_(parsed_function),
44 block_info_(block_order.length()), 89 block_info_(block_order.length()),
45 current_block_(NULL), 90 current_block_(NULL),
46 pc_descriptors_list_(NULL), 91 pc_descriptors_list_(NULL),
47 exception_handlers_list_(NULL), 92 exception_handlers_list_(NULL),
93 deopt_stubs_(),
48 is_optimizing_(is_optimizing) { 94 is_optimizing_(is_optimizing) {
49 } 95 }
50 96
51 97
52 void FlowGraphCompiler::InitCompiler() { 98 void FlowGraphCompiler::InitCompiler() {
53 pc_descriptors_list_ = new DescriptorList(); 99 pc_descriptors_list_ = new DescriptorList();
54 exception_handlers_list_ = new ExceptionHandlerList(); 100 exception_handlers_list_ = new ExceptionHandlerList();
55 block_info_.Clear(); 101 block_info_.Clear();
56 for (int i = 0; i < block_order_.length(); ++i) { 102 for (int i = 0; i < block_order_.length(); ++i) {
57 block_info_.Add(new BlockInfo()); 103 block_info_.Add(new BlockInfo());
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 1356
1311 ASSERT(!comp->exception_var().is_captured()); 1357 ASSERT(!comp->exception_var().is_captured());
1312 ASSERT(!comp->stacktrace_var().is_captured()); 1358 ASSERT(!comp->stacktrace_var().is_captured());
1313 __ movq(Address(RBP, comp->exception_var().index() * kWordSize), 1359 __ movq(Address(RBP, comp->exception_var().index() * kWordSize),
1314 kExceptionObjectReg); 1360 kExceptionObjectReg);
1315 __ movq(Address(RBP, comp->stacktrace_var().index() * kWordSize), 1361 __ movq(Address(RBP, comp->stacktrace_var().index() * kWordSize),
1316 kStackTraceObjectReg); 1362 kStackTraceObjectReg);
1317 } 1363 }
1318 1364
1319 1365
1366 void FlowGraphCompiler::VisitBinaryOp(BinaryOpComp* comp) {
1367 UNIMPLEMENTED();
1368 }
1369
1370
1320 void FlowGraphCompiler::EmitInstructionPrologue(Instruction* instr) { 1371 void FlowGraphCompiler::EmitInstructionPrologue(Instruction* instr) {
1321 LocationSummary* locs = instr->locs(); 1372 LocationSummary* locs = instr->locs();
1322 ASSERT(locs != NULL); 1373 ASSERT(locs != NULL);
1323 1374
1324 locs->AllocateRegisters(); 1375 locs->AllocateRegisters();
1325 1376
1326 // Load instruction inputs into allocated registers. 1377 // Load instruction inputs into allocated registers.
1327 for (intptr_t i = locs->count() - 1; i >= 0; i--) { 1378 for (intptr_t i = locs->count() - 1; i >= 0; i--) {
1328 Location loc = locs->in(i); 1379 Location loc = locs->in(i);
1329 ASSERT(loc.kind() == Location::kRegister); 1380 ASSERT(loc.kind() == Location::kRegister);
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 if (FLAG_print_ast) { 1901 if (FLAG_print_ast) {
1851 // Second printing. 1902 // Second printing.
1852 OS::Print("Annotated "); 1903 OS::Print("Annotated ");
1853 } 1904 }
1854 AstPrinter::PrintFunctionScope(parsed_function_); 1905 AstPrinter::PrintFunctionScope(parsed_function_);
1855 } 1906 }
1856 1907
1857 VisitBlocks(); 1908 VisitBlocks();
1858 1909
1859 __ int3(); 1910 __ int3();
1911 GenerateDeferredCode();
1860 // Emit function patching code. This will be swapped with the first 13 bytes 1912 // Emit function patching code. This will be swapped with the first 13 bytes
1861 // at entry point. 1913 // at entry point.
1862 pc_descriptors_list_->AddDescriptor(PcDescriptors::kPatchCode, 1914 pc_descriptors_list_->AddDescriptor(PcDescriptors::kPatchCode,
1863 assembler_->CodeSize(), 1915 assembler_->CodeSize(),
1864 AstNode::kNoId, 1916 AstNode::kNoId,
1865 0, 1917 0,
1866 -1); 1918 -1);
1867 __ jmp(&StubCode::FixCallersTargetLabel()); 1919 __ jmp(&StubCode::FixCallersTargetLabel());
1868 } 1920 }
1869 1921
1870 1922
1923 void FlowGraphCompiler::GenerateDeferredCode() {
1924 for (intptr_t i = 0; i < deopt_stubs_.length(); i++) {
1925 deopt_stubs_[i]->GenerateCode(this);
1926 }
1927 }
1928
1929
1871 // Infrastructure copied from class CodeGenerator. 1930 // Infrastructure copied from class CodeGenerator.
1872 void FlowGraphCompiler::GenerateCall(intptr_t token_index, 1931 void FlowGraphCompiler::GenerateCall(intptr_t token_index,
1873 intptr_t try_index, 1932 intptr_t try_index,
1874 const ExternalLabel* label, 1933 const ExternalLabel* label,
1875 PcDescriptors::Kind kind) { 1934 PcDescriptors::Kind kind) {
1876 __ call(label); 1935 __ call(label);
1877 AddCurrentDescriptor(kind, AstNode::kNoId, token_index, try_index); 1936 AddCurrentDescriptor(kind, AstNode::kNoId, token_index, try_index);
1878 } 1937 }
1879 1938
1880 1939
(...skipping 12 matching lines...) Expand all
1893 intptr_t token_index, 1952 intptr_t token_index,
1894 intptr_t try_index) { 1953 intptr_t try_index) {
1895 pc_descriptors_list_->AddDescriptor(kind, 1954 pc_descriptors_list_->AddDescriptor(kind,
1896 assembler_->CodeSize(), 1955 assembler_->CodeSize(),
1897 cid, 1956 cid,
1898 token_index, 1957 token_index,
1899 try_index); 1958 try_index);
1900 } 1959 }
1901 1960
1902 1961
1962 Label* FlowGraphCompiler::AddDeoptStub(intptr_t deopt_id,
1963 intptr_t deopt_token_index,
1964 intptr_t try_index,
1965 DeoptReasonId reason,
1966 Register reg1,
1967 Register reg2) {
1968 DeoptimizationStub* stub =
1969 new DeoptimizationStub(deopt_id, deopt_token_index, try_index, reason);
1970 stub->Push(reg1);
1971 stub->Push(reg2);
1972 deopt_stubs_.Add(stub);
1973 return stub->entry_label();
1974 }
1975
1976
1903 void FlowGraphCompiler::FinalizePcDescriptors(const Code& code) { 1977 void FlowGraphCompiler::FinalizePcDescriptors(const Code& code) {
1904 ASSERT(pc_descriptors_list_ != NULL); 1978 ASSERT(pc_descriptors_list_ != NULL);
1905 const PcDescriptors& descriptors = PcDescriptors::Handle( 1979 const PcDescriptors& descriptors = PcDescriptors::Handle(
1906 pc_descriptors_list_->FinalizePcDescriptors(code.EntryPoint())); 1980 pc_descriptors_list_->FinalizePcDescriptors(code.EntryPoint()));
1907 descriptors.Verify(parsed_function_.function().is_optimizable()); 1981 descriptors.Verify(parsed_function_.function().is_optimizable());
1908 code.set_pc_descriptors(descriptors); 1982 code.set_pc_descriptors(descriptors);
1909 } 1983 }
1910 1984
1911 1985
1912 void FlowGraphCompiler::FinalizeStackmaps(const Code& code) { 1986 void FlowGraphCompiler::FinalizeStackmaps(const Code& code) {
(...skipping 18 matching lines...) Expand all
1931 2005
1932 2006
1933 void FlowGraphCompiler::FinalizeComments(const Code& code) { 2007 void FlowGraphCompiler::FinalizeComments(const Code& code) {
1934 code.set_comments(assembler_->GetCodeComments()); 2008 code.set_comments(assembler_->GetCodeComments());
1935 } 2009 }
1936 2010
1937 2011
1938 } // namespace dart 2012 } // namespace dart
1939 2013
1940 #endif // defined TARGET_ARCH_X64 2014 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698