OLD | NEW |
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 #ifndef VM_COMPILER_H_ | 5 #ifndef VM_COMPILER_H_ |
6 #define VM_COMPILER_H_ | 6 #define VM_COMPILER_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/growable_array.h" | 9 #include "vm/growable_array.h" |
10 #include "vm/runtime_entry.h" | 10 #include "vm/runtime_entry.h" |
11 #include "vm/thread_pool.h" | 11 #include "vm/thread_pool.h" |
12 | 12 |
13 namespace dart { | 13 namespace dart { |
14 | 14 |
15 // Forward declarations. | 15 // Forward declarations. |
16 class BackgroundCompilationQueue; | 16 class BackgroundCompilationQueue; |
17 class Class; | 17 class Class; |
18 class Code; | 18 class Code; |
19 class CompilationWorkQueue; | 19 class CompilationWorkQueue; |
| 20 class FlowGraph; |
20 class Function; | 21 class Function; |
| 22 class IndirectGotoInstr; |
21 class Library; | 23 class Library; |
22 class ParsedFunction; | 24 class ParsedFunction; |
23 class QueueElement; | 25 class QueueElement; |
24 class RawInstance; | 26 class RawInstance; |
25 class Script; | 27 class Script; |
26 class SequenceNode; | 28 class SequenceNode; |
27 | 29 |
28 | 30 |
| 31 class CompilationPipeline : public ZoneAllocated { |
| 32 public: |
| 33 static CompilationPipeline* New(Zone* zone, const Function& function); |
| 34 |
| 35 virtual void ParseFunction(ParsedFunction* parsed_function) = 0; |
| 36 virtual FlowGraph* BuildFlowGraph( |
| 37 Zone* zone, |
| 38 ParsedFunction* parsed_function, |
| 39 const ZoneGrowableArray<const ICData*>& ic_data_array, |
| 40 intptr_t osr_id) = 0; |
| 41 virtual void FinalizeCompilation() = 0; |
| 42 virtual ~CompilationPipeline() { } |
| 43 }; |
| 44 |
| 45 |
| 46 class DartCompilationPipeline : public CompilationPipeline { |
| 47 public: |
| 48 virtual void ParseFunction(ParsedFunction* parsed_function); |
| 49 |
| 50 virtual FlowGraph* BuildFlowGraph( |
| 51 Zone* zone, |
| 52 ParsedFunction* parsed_function, |
| 53 const ZoneGrowableArray<const ICData*>& ic_data_array, |
| 54 intptr_t osr_id); |
| 55 |
| 56 virtual void FinalizeCompilation(); |
| 57 }; |
| 58 |
| 59 |
| 60 class IrregexpCompilationPipeline : public CompilationPipeline { |
| 61 public: |
| 62 IrregexpCompilationPipeline() : backtrack_goto_(NULL) { } |
| 63 |
| 64 virtual void ParseFunction(ParsedFunction* parsed_function); |
| 65 |
| 66 virtual FlowGraph* BuildFlowGraph( |
| 67 Zone* zone, |
| 68 ParsedFunction* parsed_function, |
| 69 const ZoneGrowableArray<const ICData*>& ic_data_array, |
| 70 intptr_t osr_id); |
| 71 |
| 72 virtual void FinalizeCompilation(); |
| 73 |
| 74 private: |
| 75 IndirectGotoInstr* backtrack_goto_; |
| 76 }; |
| 77 |
| 78 |
29 class Compiler : public AllStatic { | 79 class Compiler : public AllStatic { |
30 public: | 80 public: |
31 static const intptr_t kNoOSRDeoptId = Thread::kNoDeoptId; | 81 static const intptr_t kNoOSRDeoptId = Thread::kNoDeoptId; |
32 | 82 |
33 static bool IsBackgroundCompilation(); | 83 static bool IsBackgroundCompilation(); |
34 | 84 |
35 // Extracts top level entities from the script and populates | 85 // Extracts top level entities from the script and populates |
36 // the class dictionary of the library. | 86 // the class dictionary of the library. |
37 // | 87 // |
38 // Returns Error::null() if there is no compilation error. | 88 // Returns Error::null() if there is no compilation error. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // | 125 // |
76 // The return value is either a RawInstance on success or a RawError | 126 // The return value is either a RawInstance on success or a RawError |
77 // on compilation failure. | 127 // on compilation failure. |
78 static RawObject* ExecuteOnce(SequenceNode* fragment); | 128 static RawObject* ExecuteOnce(SequenceNode* fragment); |
79 | 129 |
80 // Evaluates the initializer expression of the given static field. | 130 // Evaluates the initializer expression of the given static field. |
81 // | 131 // |
82 // The return value is either a RawInstance on success or a RawError | 132 // The return value is either a RawInstance on success or a RawError |
83 // on compilation failure. | 133 // on compilation failure. |
84 static RawObject* EvaluateStaticInitializer(const Field& field); | 134 static RawObject* EvaluateStaticInitializer(const Field& field); |
85 static void CompileStaticInitializer(const Field& field); | |
86 | 135 |
87 // Generates local var descriptors and sets it in 'code'. Do not call if the | 136 // Generates local var descriptors and sets it in 'code'. Do not call if the |
88 // local var descriptor already exists. | 137 // local var descriptor already exists. |
89 static void ComputeLocalVarDescriptors(const Code& code); | 138 static void ComputeLocalVarDescriptors(const Code& code); |
90 | 139 |
91 // Eagerly compiles all functions in a class. | 140 // Eagerly compiles all functions in a class. |
92 // | 141 // |
93 // Returns Error::null() if there is no compilation error. | 142 // Returns Error::null() if there is no compilation error. |
94 static RawError* CompileAllFunctions(const Class& cls); | 143 static RawError* CompileAllFunctions(const Class& cls); |
95 | 144 |
96 static bool always_optimize(); | |
97 | |
98 // Notify the compiler that background (optimized) compilation has failed | 145 // Notify the compiler that background (optimized) compilation has failed |
99 // because the mutator thread changed the state (e.g., deoptimization, | 146 // because the mutator thread changed the state (e.g., deoptimization, |
100 // deferred loading). The background compilation may retry to compile | 147 // deferred loading). The background compilation may retry to compile |
101 // the same function later. | 148 // the same function later. |
102 static void AbortBackgroundCompilation(intptr_t deopt_id); | 149 static void AbortBackgroundCompilation(intptr_t deopt_id); |
103 }; | 150 }; |
104 | 151 |
105 | 152 |
106 // Class to run optimizing compilation in a background thread. | 153 // Class to run optimizing compilation in a background thread. |
107 // Current implementation: one task per isolate, it dies with the owning | 154 // Current implementation: one task per isolate, it dies with the owning |
(...skipping 25 matching lines...) Expand all Loading... |
133 Monitor* done_monitor_; // Notify/wait that the thread is done. | 180 Monitor* done_monitor_; // Notify/wait that the thread is done. |
134 | 181 |
135 BackgroundCompilationQueue* function_queue_; | 182 BackgroundCompilationQueue* function_queue_; |
136 | 183 |
137 DISALLOW_IMPLICIT_CONSTRUCTORS(BackgroundCompiler); | 184 DISALLOW_IMPLICIT_CONSTRUCTORS(BackgroundCompiler); |
138 }; | 185 }; |
139 | 186 |
140 } // namespace dart | 187 } // namespace dart |
141 | 188 |
142 #endif // VM_COMPILER_H_ | 189 #endif // VM_COMPILER_H_ |
OLD | NEW |