| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/compiler.h" | 5 #include "vm/compiler.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/ast_printer.h" | 8 #include "vm/ast_printer.h" |
| 9 #include "vm/code_generator.h" | 9 #include "vm/code_generator.h" |
| 10 #include "vm/code_index_table.h" | 10 #include "vm/code_index_table.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // Compile a function. Should call only if the function has not been compiled. | 32 // Compile a function. Should call only if the function has not been compiled. |
| 33 // Arg0: function object. | 33 // Arg0: function object. |
| 34 DEFINE_RUNTIME_ENTRY(CompileFunction, 1) { | 34 DEFINE_RUNTIME_ENTRY(CompileFunction, 1) { |
| 35 ASSERT(arguments.Count() == kCompileFunctionRuntimeEntry.argument_count()); | 35 ASSERT(arguments.Count() == kCompileFunctionRuntimeEntry.argument_count()); |
| 36 const Function& function = Function::CheckedHandle(arguments.At(0)); | 36 const Function& function = Function::CheckedHandle(arguments.At(0)); |
| 37 ASSERT(!function.HasCode()); | 37 ASSERT(!function.HasCode()); |
| 38 Compiler::CompileFunction(function); | 38 Compiler::CompileFunction(function); |
| 39 } | 39 } |
| 40 | 40 |
| 41 | 41 |
| 42 // Extracts all encountered classes of instance calls in the unoptimized code | 42 // Extracts IC data associated with a node id. |
| 43 // by analyzing the inline caches. | 43 // TODO(srdjan): Check performance impact of node id search loop. |
| 44 // Each instance call contains a token index which is matched with an AST | |
| 45 // node. The collected classes are assigned to the corresponding node. | |
| 46 static void ExtractTypeFeedback(const Code& code, | 44 static void ExtractTypeFeedback(const Code& code, |
| 47 SequenceNode* sequence_node) { | 45 SequenceNode* sequence_node) { |
| 48 ASSERT(!code.IsNull() && !code.is_optimized()); | 46 ASSERT(!code.IsNull() && !code.is_optimized()); |
| 49 GrowableArray<intptr_t> node_ids; | |
| 50 GrowableArray<ZoneGrowableArray<const Class*>*> type_arrays; | |
| 51 code.ExtractTypesAtIcCalls(&node_ids, &type_arrays); | |
| 52 GrowableArray<AstNode*> all_nodes; | 47 GrowableArray<AstNode*> all_nodes; |
| 53 sequence_node->CollectAllNodes(&all_nodes); | 48 sequence_node->CollectAllNodes(&all_nodes); |
| 49 GrowableArray<intptr_t> node_ids; |
| 50 GrowableArray<const Array*> arrays; |
| 51 code.ExtractIcDataArraysAtCalls(&node_ids, &arrays); |
| 54 for (intptr_t i = 0; i < node_ids.length(); i++) { | 52 for (intptr_t i = 0; i < node_ids.length(); i++) { |
| 55 ZoneGrowableArray<const Class*>* types = type_arrays[i]; | 53 intptr_t node_id = node_ids[i]; |
| 56 bool found_node = false; | 54 bool found_node = false; |
| 57 for (intptr_t n = 0; n < all_nodes.length(); n++) { | 55 for (intptr_t n = 0; n < all_nodes.length(); n++) { |
| 58 if (all_nodes[n]->HasId(node_ids[i])) { | 56 if (all_nodes[n]->HasId(node_id)) { |
| 59 ASSERT(all_nodes[n]->CollectedClassesAtId(node_ids[i]) == NULL); | |
| 60 all_nodes[n]->SetCollectedClassesAtId(node_ids[i], types); | |
| 61 found_node = true; | 57 found_node = true; |
| 62 break; | 58 // Make sure we assign ic data array only once. |
| 59 ASSERT(all_nodes[n]->ICDataAtId(node_id).NumberOfChecks() == 0); |
| 60 all_nodes[n]->SetIcDataArrayAtId(node_id, *arrays[i]); |
| 63 } | 61 } |
| 64 } | 62 } |
| 65 // There must be a node with the given token index. | |
| 66 ASSERT(found_node); | 63 ASSERT(found_node); |
| 67 } | 64 } |
| 68 } | 65 } |
| 69 | 66 |
| 70 | 67 |
| 71 void Compiler::Compile(const Library& library, const Script& script) { | 68 void Compiler::Compile(const Library& library, const Script& script) { |
| 72 if (FLAG_trace_compiler) { | 69 if (FLAG_trace_compiler) { |
| 73 HANDLESCOPE(); | 70 HANDLESCOPE(); |
| 74 const String& script_url = String::Handle(script.url()); | 71 const String& script_url = String::Handle(script.url()); |
| 75 // TODO(iposva): Extract script kind. | 72 // TODO(iposva): Extract script kind. |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 kNoArgumentNames)); | 264 kNoArgumentNames)); |
| 268 if (result.IsUnhandledException()) { | 265 if (result.IsUnhandledException()) { |
| 269 // TODO(srdjan): implement proper exit from compiler. | 266 // TODO(srdjan): implement proper exit from compiler. |
| 270 UNIMPLEMENTED(); | 267 UNIMPLEMENTED(); |
| 271 } | 268 } |
| 272 return result.raw(); | 269 return result.raw(); |
| 273 } | 270 } |
| 274 | 271 |
| 275 | 272 |
| 276 } // namespace dart | 273 } // namespace dart |
| OLD | NEW |