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(); | 145 static void DisassembleCode(const Function& function, bool optimized); |
97 }; | 146 }; |
98 | 147 |
99 | 148 |
100 // Class to run optimizing compilation in a background thread. | 149 // Class to run optimizing compilation in a background thread. |
101 // Current implementation: one task per isolate, it dies with the owning | 150 // Current implementation: one task per isolate, it dies with the owning |
102 // isolate. | 151 // isolate. |
103 // No OSR compilation in the background compiler. | 152 // No OSR compilation in the background compiler. |
104 class BackgroundCompiler : public ThreadPool::Task { | 153 class BackgroundCompiler : public ThreadPool::Task { |
105 public: | 154 public: |
106 static void EnsureInit(Thread* thread); | 155 static void EnsureInit(Thread* thread); |
(...skipping 20 matching lines...) Expand all Loading... |
127 Monitor* done_monitor_; // Notify/wait that the thread is done. | 176 Monitor* done_monitor_; // Notify/wait that the thread is done. |
128 | 177 |
129 BackgroundCompilationQueue* function_queue_; | 178 BackgroundCompilationQueue* function_queue_; |
130 | 179 |
131 DISALLOW_IMPLICIT_CONSTRUCTORS(BackgroundCompiler); | 180 DISALLOW_IMPLICIT_CONSTRUCTORS(BackgroundCompiler); |
132 }; | 181 }; |
133 | 182 |
134 } // namespace dart | 183 } // namespace dart |
135 | 184 |
136 #endif // VM_COMPILER_H_ | 185 #endif // VM_COMPILER_H_ |
OLD | NEW |