Flutter Engine
The Flutter Engine
compiler_pass.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_PASS_H_
6#define RUNTIME_VM_COMPILER_COMPILER_PASS_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
12#include <initializer_list>
13
14#include "vm/growable_array.h"
15#include "vm/timer.h"
16#include "vm/token_position.h"
17#include "vm/zone.h"
18
19namespace dart {
20
21#define COMPILER_PASS_LIST(V) \
22 V(AllocateRegisters) \
23 V(AllocateRegistersForGraphIntrinsic) \
24 V(AllocationSinking_DetachMaterializations) \
25 V(AllocationSinking_Sink) \
26 V(ApplyClassIds) \
27 V(ApplyICData) \
28 V(BranchSimplify) \
29 V(CSE) \
30 V(Canonicalize) \
31 V(ComputeSSA) \
32 V(ConstantPropagation) \
33 V(DCE) \
34 V(DelayAllocations) \
35 V(DSE) \
36 V(EliminateDeadPhis) \
37 V(EliminateEnvironments) \
38 V(EliminateStackOverflowChecks) \
39 V(FinalizeGraph) \
40 V(IfConvert) \
41 V(Inlining) \
42 V(LICM) \
43 V(OptimisticallySpecializeSmiPhis) \
44 V(OptimizeBranches) \
45 V(OptimizeTypedDataAccesses) \
46 V(RangeAnalysis) \
47 V(ReorderBlocks) \
48 V(SelectRepresentations) \
49 V(SelectRepresentations_Final) \
50 V(SetOuterInliningId) \
51 V(TryCatchOptimization) \
52 V(TryOptimizePatterns) \
53 V(TypePropagation) \
54 V(UseTableDispatch) \
55 V(EliminateWriteBarriers) \
56 V(TestILSerialization) \
57 V(LoweringAfterCodeMotionDisabled) \
58 V(GenerateCode)
59
60class AllocationSinking;
61class BlockScheduler;
62class CallSpecializer;
63class FlowGraph;
64class FlowGraphCompiler;
65class Function;
66class Precompiler;
67class SpeculativeInliningPolicy;
68class TimelineStream;
69class Thread;
70
75 Precompiler* precompiler = nullptr);
76
77 FlowGraph* flow_graph() const { return flow_graph_; }
78
80
81 Thread* const thread;
85
86 // Maps inline_id_to_function[inline_id] -> function. Top scope
87 // function has inline_id 0. The map is populated by the inliner.
89 // Token position where inlining occurred.
91 // For a given inlining-id(index) specifies the caller's inlining-id.
93
95
97
98 intptr_t sticky_flags;
99
101
102 private:
103 FlowGraph* flow_graph_;
104};
105
107 public:
108 enum Id {
109#define DEF(name) k##name,
111#undef DEF
112 };
113
114#define ADD_ONE(name) +1
115 static constexpr intptr_t kNumPasses = 0 COMPILER_PASS_LIST(ADD_ONE);
116#undef ADD_ONE
117
118 CompilerPass(Id id, const char* name) : 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 }
129 virtual ~CompilerPass() {}
130
131 enum Flag {
132 kDisabled = 1 << 0,
133 kTraceBefore = 1 << 1,
134 kTraceAfter = 1 << 2,
135 kSticky = 1 << 3,
137 };
138
139 void Run(CompilerPassState* state) const;
140
141 uint8_t flags() const { return flags_[id()]; }
142 const char* name() const { return name_; }
143 Id id() const { return id_; }
144
145 static CompilerPass* Get(Id id) { return passes_[id]; }
146
147 static void ParseFiltersFromFlag(const char* filter);
148 static uint8_t* ParseFiltersFromPragma(const char* filter);
149 static void ParseFilters(const char* filter, uint8_t* flags);
150 static void ParseOneFilter(const char* start,
151 const char* end,
152 uint8_t* flags);
153
155
157 CompilerPass::Get(CompilerPass::kGenerateCode)->Run(state);
158 }
159
161
163
164 // RunPipeline(WithPasses) may have the side effect of changing the FlowGraph
165 // stored in the CompilerPassState. However, existing callers may depend on
166 // the old invariant that the FlowGraph stored in the CompilerPassState was
167 // always updated, never entirely replaced.
168 //
169 // By default pipeline assumes that input graph is not in SSA form yet and
170 // will invoke |ComputeSSA| pass on it. |ComputeSSA| is not idempotent and
171 // will crash if invoked on a graph which is already in SSA form. To avoid
172 // that you can set |compute_ssa| to |false|.
173 //
174 // To make sure callers are updated properly, these methods also return
175 // the final FlowGraph and we add a check that callers use this result.
179 bool compute_ssa = true);
183 std::initializer_list<CompilerPass::Id> passes);
184
185 protected:
186 // This function executes the pass. If it returns true then
187 // we will run Canonicalize on the graph and execute the pass
188 // again.
189 virtual bool DoBody(CompilerPassState* state) const = 0;
190
191 private:
192 static CompilerPass* FindPassByName(const char* name) {
193 for (intptr_t i = 0; i < kNumPasses; i++) {
194 if ((passes_[i] != nullptr) && (strcmp(passes_[i]->name_, name) == 0)) {
195 return passes_[i];
196 }
197 }
198 return nullptr;
199 }
200
201 void PrintGraph(CompilerPassState* state, Flag mask, intptr_t round) const;
202
203 static CompilerPass* passes_[];
204 static uint8_t flags_[];
205
206 Id id_;
207 const char* name_;
208};
209
210} // namespace dart
211
212#endif // RUNTIME_VM_COMPILER_COMPILER_PASS_H_
static void round(SkPoint *p)
void Run(CompilerPassState *state) const
static void ParseOneFilter(const char *start, const char *end, uint8_t *flags)
static CompilerPass * Get(Id id)
virtual ~CompilerPass()
virtual bool DoBody(CompilerPassState *state) const =0
static uint8_t * ParseFiltersFromPragma(const char *filter)
static void RunGraphIntrinsicPipeline(CompilerPassState *state)
static void ParseFilters(const char *filter, uint8_t *flags)
static void GenerateCode(CompilerPassState *state)
static void RunInliningPipeline(PipelineMode mode, CompilerPassState *state)
static constexpr intptr_t kNumPasses
static void ParseFiltersFromFlag(const char *filter)
static DART_WARN_UNUSED_RESULT FlowGraph * RunPipeline(PipelineMode mode, CompilerPassState *state, bool compute_ssa=true)
static DART_WARN_UNUSED_RESULT FlowGraph * RunPipelineWithPasses(CompilerPassState *state, std::initializer_list< CompilerPass::Id > passes)
uint8_t flags() const
CompilerPass(Id id, const char *name)
const char * name() const
#define DEF(name)
#define COMPILER_PASS_LIST(V)
Definition: compiler_pass.h:21
#define ADD_ONE(name)
#define DART_WARN_UNUSED_RESULT
Definition: dart_api.h:66
#define ASSERT(E)
AtkStateType state
Definition: dart_vm.cc:33
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
CompilerPassState(Thread *thread, FlowGraph *flow_graph, SpeculativeInliningPolicy *speculative_policy, Precompiler *precompiler=nullptr)
CallSpecializer * call_specializer
Definition: compiler_pass.h:94
AllocationSinking * sinking
Definition: compiler_pass.h:84
SpeculativeInliningPolicy * speculative_policy
Definition: compiler_pass.h:96
FlowGraph * flow_graph() const
Definition: compiler_pass.h:77
GrowableArray< TokenPosition > inline_id_to_token_pos
Definition: compiler_pass.h:90
GrowableArray< intptr_t > caller_inline_id
Definition: compiler_pass.h:92
Precompiler *const precompiler
Definition: compiler_pass.h:82
GrowableArray< const Function * > inline_id_to_function
Definition: compiler_pass.h:88
FlowGraphCompiler * graph_compiler
void set_flow_graph(FlowGraph *flow_graph)