Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
compiler_state.h
Go to the documentation of this file.
1// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
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.
4
5#ifndef RUNTIME_VM_COMPILER_COMPILER_STATE_H_
6#define RUNTIME_VM_COMPILER_COMPILER_STATE_H_
7
8#if defined(DART_PRECOMPILED_RUNTIME)
9#error "AOT runtime should not use compiler sources (including header files)"
10#endif // defined(DART_PRECOMPILED_RUNTIME)
11
13#include "vm/compiler/cha.h"
14#include "vm/heap/safepoint.h"
15#include "vm/thread.h"
16#include "vm/timer.h"
17
18namespace dart {
19
20class CompilerPass;
21struct CompilerPassState;
22class Function;
23class LocalScope;
24class LocalVariable;
25class SlotCache;
26class Slot;
27
28enum class CompilerTracing {
29 kOn,
30 kOff,
31};
32
33// Global compiler state attached to the thread.
35 public:
37 bool is_aot,
38 bool is_optimizing,
41 cha_(thread),
42 is_aot_(is_aot),
43 is_optimizing_(is_optimizing),
44 tracing_(tracing) {
45 previous_ = thread->SetCompilerState(this);
46 }
47
49 ASSERT(&thread()->compiler_state() == this);
50 thread()->SetCompilerState(previous_);
51 }
52
53 CHA& cha() { return cha_; }
54
55 intptr_t deopt_id() const { return deopt_id_; }
56 void set_deopt_id(int value) {
57 ASSERT(value >= 0);
58 deopt_id_ = value;
59 }
60
61 intptr_t GetNextDeoptId() {
62 ASSERT(deopt_id_ != DeoptId::kNone);
63 const intptr_t id = deopt_id_;
64 deopt_id_ = DeoptId::Next(deopt_id_);
65 return id;
66 }
67
70 }
71
72 SlotCache* slot_cache() const { return slot_cache_; }
73 void set_slot_cache(SlotCache* cache) { slot_cache_ = cache; }
74
75 bool is_aot() const { return is_aot_; }
76
77 bool is_optimizing() const { return is_optimizing_; }
79 return !is_aot() && (is_optimizing() || FLAG_force_clone_compiler_objects);
80 }
81
82 bool should_trace() const { return tracing_ == CompilerTracing::kOn; }
83
84 static bool ShouldTrace() { return Current().should_trace(); }
85
86 static CompilerTracing ShouldTrace(const Function& func);
87
88 // Returns class Comparable<T> from dart:core.
89 const Class& ComparableClass();
90
91 // Returns _StringBase._interpolate
93
94 // Returns _StringBase._interpolateSingle
96
107
113
116
117 const Function* function() const { return function_; }
118
119 void set_function(const Function& function) { function_ = &function; }
122 pass_ = pass;
123 pass_state_ = pass_state;
124 }
125
126 const CompilerPass* pass() const { return pass_; }
127 const CompilerPassState* pass_state() const { return pass_state_; }
128
129 void ReportCrash();
130
131 private:
132 const Class& TypedListClass();
133
134 CHA cha_;
135 intptr_t deopt_id_ = 0;
136
137 // Cache for Slot objects created during compilation (see slot.h).
138 SlotCache* slot_cache_ = nullptr;
139
140 // Caches for dummy LocalVariables and context Slots.
141 ZoneGrowableArray<ZoneGrowableArray<const Slot*>*>* dummy_slots_ = nullptr;
142 ZoneGrowableArray<LocalVariable*>* dummy_captured_vars_ = nullptr;
143
144 const bool is_aot_;
145 const bool is_optimizing_;
146
147 const CompilerTracing tracing_;
148
149 // Lookup cache for various classes (to avoid polluting object store with
150 // compiler specific classes).
151 const Class* comparable_class_ = nullptr;
152 const Function* interpolate_ = nullptr;
153 const Function* interpolate_single_ = nullptr;
154 const Class* typed_list_class_ = nullptr;
155 const Class* array_class_ = nullptr;
156 const Class* compound_class_ = nullptr;
157 const Class* struct_class_ = nullptr;
158 const Class* typed_data_class_ = nullptr;
159 const Class* union_class_ = nullptr;
160 const Field* compound_offset_in_bytes_field_ = nullptr;
161 const Field* compound_typed_data_base_field_ = nullptr;
162 const Function* typed_list_get_float32_ = nullptr;
163 const Function* typed_list_set_float32_ = nullptr;
164 const Function* typed_list_get_float64_ = nullptr;
165 const Function* typed_list_set_float64_ = nullptr;
166 const Function* typed_list_get_float32x4_ = nullptr;
167 const Function* typed_list_set_float32x4_ = nullptr;
168 const Function* typed_list_get_int32x4_ = nullptr;
169 const Function* typed_list_set_int32x4_ = nullptr;
170 const Function* typed_list_get_float64x2_ = nullptr;
171 const Function* typed_list_set_float64x2_ = nullptr;
172
173 const Function* function_ = nullptr;
174 const CompilerPass* pass_ = nullptr;
175 const CompilerPassState* pass_state_ = nullptr;
176
177 CompilerState* previous_;
178};
179
181 public:
182 DeoptIdScope(Thread* thread, intptr_t deopt_id)
184 prev_deopt_id_(thread->compiler_state().deopt_id()) {
186 }
187
189
190 private:
191 const intptr_t prev_deopt_id_;
192
194};
195
196/// Ensures that there were no deopt id allocations during the lifetime of this
197/// object.
199 public:
202 prev_deopt_id_(thread->compiler_state().deopt_id()) {}
203
205 ASSERT(thread()->compiler_state().deopt_id() == prev_deopt_id_);
206 }
207
208 private:
209 const intptr_t prev_deopt_id_;
210
212};
213
214} // namespace dart
215
216#endif // RUNTIME_VM_COMPILER_COMPILER_STATE_H_
const Class & CompoundClass()
void set_slot_cache(SlotCache *cache)
const Class & ComparableClass()
intptr_t deopt_id() const
const Function & TypedListSetFloat64()
const Class & ArrayClass()
intptr_t GetNextDeoptId()
bool is_optimizing() const
void set_current_pass(const CompilerPass *pass, const CompilerPassState *pass_state)
const Function & TypedListGetFloat32()
const Function & TypedListGetInt32x4()
const Function & TypedListGetFloat32x4()
const Function & TypedListSetFloat32x4()
const Function & StringBaseInterpolateSingle()
CompilerState(Thread *thread, bool is_aot, bool is_optimizing, CompilerTracing tracing=CompilerTracing::kOn)
void set_deopt_id(int value)
const Function & TypedListSetInt32x4()
const CompilerPass * pass() const
void set_function(const Function &function)
const Class & UnionClass()
bool should_trace() const
static bool ShouldTrace()
const Class & StructClass()
const Function & TypedListGetFloat64x2()
const Function & TypedListSetFloat64x2()
static CompilerState & Current()
const Class & TypedDataClass()
const Field & CompoundTypedDataBaseField()
const Function & TypedListGetFloat64()
const Function & StringBaseInterpolate()
const Field & CompoundOffsetInBytesField()
const CompilerPassState * pass_state() const
const Function & TypedListSetFloat32()
SlotCache * slot_cache() const
const Function * function() const
DeoptIdScope(Thread *thread, intptr_t deopt_id)
static constexpr intptr_t kNone
Definition deopt_id.h:27
static intptr_t Next(intptr_t deopt_id)
Definition deopt_id.h:29
static Thread * Current()
Definition thread.h:361
CompilerState & compiler_state()
Definition thread.h:583
#define ASSERT(E)
uint8_t value
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition globals.h:581
const uintptr_t id