Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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)
 
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 107 of file compiler_pass.h.

Member Enumeration Documentation

◆ Flag

Enumerator
kDisabled 
kTraceBefore 
kTraceAfter 
kSticky 
kTraceBeforeOrAfter 

Definition at line 132 of file compiler_pass.h.

◆ Id

Definition at line 109 of file compiler_pass.h.

109 {
110#define DEF(name) k##name,
112#undef DEF
113 };
#define DEF(name)
#define COMPILER_PASS_LIST(V)

◆ PipelineMode

Enumerator
kJIT 
kAOT 

Definition at line 155 of file compiler_pass.h.

Constructor & Destructor Documentation

◆ CompilerPass()

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

Definition at line 119 of file compiler_pass.h.

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

◆ ~CompilerPass()

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

Definition at line 130 of file compiler_pass.h.

130{}

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 142 of file compiler_pass.h.

142{ return flags_[id()]; }

◆ GenerateCode()

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

Definition at line 157 of file compiler_pass.h.

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

◆ Get()

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

Definition at line 146 of file compiler_pass.h.

146{ return passes_[id]; }

◆ id()

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

Definition at line 144 of file compiler_pass.h.

144{ return id_; }

◆ name()

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

Definition at line 143 of file compiler_pass.h.

143{ 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
static ThreadState * Current()
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 
)
static

Definition at line 302 of file compiler_pass.cc.

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

◆ RunPipelineWithPasses()

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

Definition at line 373 of file compiler_pass.cc.

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

Member Data Documentation

◆ kNumPasses

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

Definition at line 116 of file compiler_pass.h.


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