Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
dart::CompilerPass Class Referenceabstract

#include <compiler_pass.h>

Public Types

enum  Id
 
enum  Flag {
  kDisabled = 1 << 0 , kTraceBefore = 1 << 1 , kTraceAfter = 1 << 2 , kSticky = 1 << 3 ,
  kTraceBeforeOrAfter = kTraceBefore | kTraceAfter
}
 
enum  PipelineMode { kJIT , kAOT }
 

Public Member Functions

 CompilerPass (Id id, const char *name)
 
virtual ~CompilerPass ()
 
void Run (CompilerPassState *state) const
 
uint8_t flags () const
 
const char * name () const
 
Id id () const
 

Static Public Member Functions

static CompilerPassGet (Id id)
 
static void ParseFiltersFromFlag (const char *filter)
 
static uint8_t * ParseFiltersFromPragma (const char *filter)
 
static void ParseFilters (const char *filter, uint8_t *flags)
 
static void ParseOneFilter (const char *start, const char *end, uint8_t *flags)
 
static void GenerateCode (CompilerPassState *state)
 
static void RunGraphIntrinsicPipeline (CompilerPassState *state)
 
static void RunInliningPipeline (PipelineMode mode, CompilerPassState *state)
 
static DART_WARN_UNUSED_RESULT FlowGraphRunPipeline (PipelineMode mode, CompilerPassState *state, bool compute_ssa=true)
 
static DART_WARN_UNUSED_RESULT FlowGraphRunPipelineWithPasses (CompilerPassState *state, std::initializer_list< CompilerPass::Id > passes)
 

Static Public Attributes

static constexpr intptr_t kNumPasses = 0 COMPILER_PASS_LIST(ADD_ONE)
 

Protected Member Functions

virtual bool DoBody (CompilerPassState *state) const =0
 

Detailed Description

Definition at line 106 of file compiler_pass.h.

Member Enumeration Documentation

◆ Flag

Enumerator
kDisabled 
kTraceBefore 
kTraceAfter 
kSticky 
kTraceBeforeOrAfter 

Definition at line 131 of file compiler_pass.h.

◆ Id

Definition at line 108 of file compiler_pass.h.

108 {
109#define DEF(name) k##name,
111#undef DEF
112 };
#define DEF(name)
#define COMPILER_PASS_LIST(V)
Definition: compiler_pass.h:21

◆ PipelineMode

Enumerator
kJIT 
kAOT 

Definition at line 154 of file compiler_pass.h.

Constructor & Destructor Documentation

◆ CompilerPass()

dart::CompilerPass::CompilerPass ( Id  id,
const char *  name 
)
inline

Definition at line 118 of file compiler_pass.h.

118 : id_(id), name_(name) {
119 ASSERT(passes_[id] == nullptr);
120 passes_[id] = this;
121
122 // By default print the final flow-graph after the register allocation.
123 if (id == kAllocateRegisters) {
124 flags_[id] = kTraceAfter;
125 } else {
126 flags_[id] = 0;
127 }
128 }
const char * name() const
#define ASSERT(E)

◆ ~CompilerPass()

virtual dart::CompilerPass::~CompilerPass ( )
inlinevirtual

Definition at line 129 of file compiler_pass.h.

129{}

Member Function Documentation

◆ DoBody()

virtual bool dart::CompilerPass::DoBody ( CompilerPassState state) const
protectedpure virtual

◆ flags()

uint8_t dart::CompilerPass::flags ( ) const
inline

Definition at line 141 of file compiler_pass.h.

141{ return flags_[id()]; }

◆ GenerateCode()

static void dart::CompilerPass::GenerateCode ( CompilerPassState state)
inlinestatic

Definition at line 156 of file compiler_pass.h.

156 {
157 CompilerPass::Get(CompilerPass::kGenerateCode)->Run(state);
158 }
void Run(CompilerPassState *state) const
static CompilerPass * Get(Id id)
AtkStateType state

◆ Get()

static CompilerPass * dart::CompilerPass::Get ( Id  id)
inlinestatic

Definition at line 145 of file compiler_pass.h.

145{ return passes_[id]; }

◆ id()

Id dart::CompilerPass::id ( ) const
inline

Definition at line 143 of file compiler_pass.h.

143{ return id_; }

◆ name()

const char * dart::CompilerPass::name ( ) const
inline

Definition at line 142 of file compiler_pass.h.

142{ return name_; }

◆ ParseFilters()

void dart::CompilerPass::ParseFilters ( const char *  filter,
uint8_t *  flags 
)
static

Definition at line 127 of file compiler_pass.cc.

127 {
128 if (filter == nullptr || *filter == 0) {
129 return;
130 }
131
132 if (strcmp(filter, "help") == 0) {
134 for (intptr_t i = 0; i < kNumPasses; i++) {
135 if (passes_[i] != nullptr) {
136 OS::PrintErr(" %s\n", passes_[i]->name());
137 }
138 }
139 return;
140 }
141
142 // Clear all flags.
143 memset(pass_flags, 0, CompilerPass::kNumPasses);
144
145 for (const char *start = filter, *end = filter; *end != 0;
146 start = (end + 1)) {
147 // Search forward until the separator ',' or the end of filter is reached.
148 end = start;
149 while (*end != ',' && *end != '\0') {
150 end++;
151 }
152 if (start == end) {
153 OS::PrintErr("Ignoring empty compiler pass flag\n");
154 continue;
155 }
156
157 ParseOneFilter(start, end, pass_flags);
158 }
159}
static void ParseOneFilter(const char *start, const char *end, uint8_t *flags)
static constexpr intptr_t kNumPasses
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
glong glong end
static const char * kCompilerPassesUsage

◆ ParseFiltersFromFlag()

void dart::CompilerPass::ParseFiltersFromFlag ( const char *  filter)
static

Definition at line 116 of file compiler_pass.cc.

116 {
117 ParseFilters(filter, flags_);
118}
static void ParseFilters(const char *filter, uint8_t *flags)

◆ ParseFiltersFromPragma()

uint8_t * dart::CompilerPass::ParseFiltersFromPragma ( const char *  filter)
static

Definition at line 120 of file compiler_pass.cc.

120 {
121 auto flags =
123 ParseFilters(filter, flags);
124 return flags;
125}
uint8_t flags() const
Zone * zone() const
Definition: thread_state.h:37
static ThreadState * Current()
Definition: thread_state.h:27
ElementType * Alloc(intptr_t length)

◆ ParseOneFilter()

void dart::CompilerPass::ParseOneFilter ( const char *  start,
const char *  end,
uint8_t *  flags 
)
static

Definition at line 161 of file compiler_pass.cc.

163 {
164 uint8_t flags = 0;
165 if (*start == '-') {
167 } else if (*start == ']') {
169 } else if (*start == '[') {
171 } else if (*start == '*') {
173 }
174 if (flags == 0) {
176 } else {
177 start++; // Skip the modifier
178 }
179
180 size_t suffix = 0;
181 if (end[-1] == '+') {
182 if (start == (end - 1)) {
183 OS::PrintErr("Sticky modifier '+' should follow pass name\n");
184 return;
185 }
186 flags |= kSticky;
187 suffix = 1;
188 }
189
190 size_t length = (end - start) - suffix;
191 if (length != 0) {
192 char* pass_name = Utils::StrNDup(start, length);
193 CompilerPass* pass = FindPassByName(pass_name);
194 if (pass != nullptr) {
195 pass_flags[pass->id()] |= flags;
196 } else {
197 OS::PrintErr("Unknown compiler pass: %s\n", pass_name);
198 }
199 free(pass_name);
200 } else if (flags == kTraceBeforeOrAfter) {
201 for (intptr_t i = 0; i < kNumPasses; i++) {
202 pass_flags[i] = kTraceAfter;
203 }
204 }
205}
CompilerPass(Id id, const char *name)
static char * StrNDup(const char *s, intptr_t n)
size_t length

◆ Run()

void dart::CompilerPass::Run ( CompilerPassState state) const

Definition at line 207 of file compiler_pass.cc.

207 {
208 if ((flags() & kDisabled) != 0) {
209 return;
210 }
211
212 if ((flags() & kSticky) != 0) {
213 state->sticky_flags |= flags();
214 }
215
216 const intptr_t kMaxRounds = 2;
217 Thread* thread = state->thread;
218 bool repeat = true;
219 for (intptr_t round = 1; round <= kMaxRounds && repeat; round++) {
220 if (round > 1) {
221 Get(kCanonicalize)->Run(state);
222 }
223
225 PrintGraph(state, kTraceBefore, round);
226 {
227 TIMELINE_DURATION(thread, CompilerVerbose, name());
228 {
231 }
232 thread->CheckForSafepoint();
233 }
234 PrintGraph(state, kTraceAfter, round);
235#if defined(DEBUG)
236 if (CompilerState::Current().is_optimizing()) {
237 FlowGraphChecker(state->flow_graph(), state->inline_id_to_function)
238 .Check(name());
239 }
240#endif
241 CompilerState::Current().set_current_pass(nullptr, nullptr);
242 }
243}
static void round(SkPoint *p)
static unsigned repeat(SkFixed fx, int max)
virtual bool DoBody(CompilerPassState *state) const =0
void set_current_pass(const CompilerPass *pass, const CompilerPassState *pass_state)
static CompilerState & Current()
#define COMPILER_TIMINGS_PASS_TIMER_SCOPE(thread, pass_id)
#define TIMELINE_DURATION(thread, stream, name)
Definition: timeline.h:39

◆ RunGraphIntrinsicPipeline()

void dart::CompilerPass::RunGraphIntrinsicPipeline ( CompilerPassState state)
static

Definition at line 279 of file compiler_pass.cc.

279 {
280 INVOKE_PASS(AllocateRegistersForGraphIntrinsic);
281}
#define INVOKE_PASS(Name)

◆ RunInliningPipeline()

void dart::CompilerPass::RunInliningPipeline ( PipelineMode  mode,
CompilerPassState state 
)
static

Definition at line 283 of file compiler_pass.cc.

284 {
285 INVOKE_PASS(ApplyClassIds);
286 INVOKE_PASS(TypePropagation);
287 INVOKE_PASS(ApplyICData);
289 // Run constant propagation to make sure we specialize for
290 // (optional) constant arguments passed into the inlined method.
291 INVOKE_PASS(ConstantPropagation);
292 // Constant propagation removes unreachable basic blocks and
293 // may open more opportunities for call specialization.
294 // Call specialization during inlining may cause more call
295 // sites to be discovered and more functions inlined.
296 INVOKE_PASS_AOT(ApplyClassIds);
297 // Optimize (a << b) & c patterns, merge instructions. Must occur
298 // before 'SelectRepresentations' which inserts conversion nodes.
299 INVOKE_PASS(TryOptimizePatterns);
300}
#define INVOKE_PASS_AOT(Name)
unibrow::Mapping< unibrow::Ecma262Canonicalize > Canonicalize

◆ RunPipeline()

FlowGraph * dart::CompilerPass::RunPipeline ( PipelineMode  mode,
CompilerPassState state,
bool  compute_ssa = true 
)
static

Definition at line 302 of file compiler_pass.cc.

304 {
305 if (compute_ssa) {
306 INVOKE_PASS(ComputeSSA);
307 }
308 INVOKE_PASS_AOT(ApplyClassIds);
309 INVOKE_PASS_AOT(TypePropagation);
310 INVOKE_PASS(ApplyICData);
311 INVOKE_PASS(TryOptimizePatterns);
312 INVOKE_PASS(SetOuterInliningId);
313 INVOKE_PASS(TypePropagation);
314 INVOKE_PASS(ApplyClassIds);
315 INVOKE_PASS(Inlining);
316 INVOKE_PASS(TypePropagation);
317 INVOKE_PASS(ApplyClassIds);
318 INVOKE_PASS(TypePropagation);
319 INVOKE_PASS(ApplyICData);
321 INVOKE_PASS(BranchSimplify);
322 INVOKE_PASS(IfConvert);
324 INVOKE_PASS(ConstantPropagation);
325 INVOKE_PASS(OptimisticallySpecializeSmiPhis);
326 INVOKE_PASS(TypePropagation);
327 // The extra call specialization pass in AOT is able to specialize more
328 // calls after ConstantPropagation, which removes unreachable code, and
329 // TypePropagation, which can infer more accurate types after removing
330 // unreachable code.
331 INVOKE_PASS_AOT(ApplyICData);
332 INVOKE_PASS_AOT(OptimizeTypedDataAccesses);
333 INVOKE_PASS(SelectRepresentations);
334 INVOKE_PASS(CSE);
336 INVOKE_PASS(LICM);
337 INVOKE_PASS(TryOptimizePatterns);
338 INVOKE_PASS(DSE);
339 INVOKE_PASS(TypePropagation);
340 INVOKE_PASS(RangeAnalysis);
341 INVOKE_PASS(OptimizeBranches);
342 INVOKE_PASS(TypePropagation);
343 INVOKE_PASS(TryCatchOptimization);
344 INVOKE_PASS(EliminateEnvironments);
345 INVOKE_PASS(EliminateDeadPhis);
346 // Currently DCE assumes that EliminateEnvironments has already been run,
347 // so it should not be lifted earlier than that pass.
348 INVOKE_PASS(DCE);
350 INVOKE_PASS_AOT(DelayAllocations);
351 // Repeat branches optimization after DCE, as it could make more
352 // empty blocks.
353 INVOKE_PASS(OptimizeBranches);
354 INVOKE_PASS(AllocationSinking_Sink);
355 INVOKE_PASS(EliminateDeadPhis);
356 INVOKE_PASS(DCE);
358 INVOKE_PASS(TypePropagation);
359 INVOKE_PASS(SelectRepresentations_Final);
360 INVOKE_PASS(UseTableDispatch);
361 INVOKE_PASS(EliminateStackOverflowChecks);
363 INVOKE_PASS(AllocationSinking_DetachMaterializations);
365 // This must be done after all other possible intra-block code motion.
366 INVOKE_PASS(LoweringAfterCodeMotionDisabled);
367 INVOKE_PASS(FinalizeGraph);
369 INVOKE_PASS(ReorderBlocks);
370 INVOKE_PASS(AllocateRegisters);
371 INVOKE_PASS(TestILSerialization); // Must be last.
372 return pass_state->flow_graph();
373}
void EliminateWriteBarriers(FlowGraph *flow_graph)

◆ RunPipelineWithPasses()

FlowGraph * dart::CompilerPass::RunPipelineWithPasses ( CompilerPassState state,
std::initializer_list< CompilerPass::Id passes 
)
static

Definition at line 375 of file compiler_pass.cc.

377 {
378 for (auto pass_id : passes) {
379 passes_[pass_id]->Run(state);
380 }
381 return state->flow_graph();
382}

Member Data Documentation

◆ kNumPasses

constexpr intptr_t dart::CompilerPass::kNumPasses = 0 COMPILER_PASS_LIST(ADD_ONE)
staticconstexpr

Definition at line 115 of file compiler_pass.h.


The documentation for this class was generated from the following files: