Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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(WidenSmiToInt32) \
56 V(EliminateWriteBarriers) \
57 V(TestILSerialization) \
58 V(LoweringAfterCodeMotionDisabled) \
59 V(GenerateCode)
60
61class AllocationSinking;
62class BlockScheduler;
63class CallSpecializer;
64class FlowGraph;
65class FlowGraphCompiler;
66class Function;
67class Precompiler;
68class SpeculativeInliningPolicy;
69class TimelineStream;
70class Thread;
71
76 Precompiler* precompiler = nullptr);
77
78 FlowGraph* flow_graph() const { return flow_graph_; }
79
81
82 Thread* const thread;
86
87 // Maps inline_id_to_function[inline_id] -> function. Top scope
88 // function has inline_id 0. The map is populated by the inliner.
90 // Token position where inlining occurred.
92 // For a given inlining-id(index) specifies the caller's inlining-id.
94
96
98
99 intptr_t sticky_flags;
100
102
103 private:
104 FlowGraph* flow_graph_;
105};
106
108 public:
109 enum Id {
110#define DEF(name) k##name,
112#undef DEF
113 };
114
115#define ADD_ONE(name) +1
116 static constexpr intptr_t kNumPasses = 0 COMPILER_PASS_LIST(ADD_ONE);
117#undef ADD_ONE
118
119 CompilerPass(Id id, const char* name) : 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 }
130 virtual ~CompilerPass() {}
131
139
140 void Run(CompilerPassState* state) const;
141
142 uint8_t flags() const { return flags_[id()]; }
143 const char* name() const { return name_; }
144 Id id() const { return id_; }
145
146 static CompilerPass* Get(Id id) { return passes_[id]; }
147
148 static void ParseFiltersFromFlag(const char* filter);
149 static uint8_t* ParseFiltersFromPragma(const char* filter);
150 static void ParseFilters(const char* filter, uint8_t* flags);
151 static void ParseOneFilter(const char* start,
152 const char* end,
153 uint8_t* flags);
154
156
158 CompilerPass::Get(CompilerPass::kGenerateCode)->Run(state);
159 }
160
162
164
165 // RunPipeline(WithPasses) may have the side effect of changing the FlowGraph
166 // stored in the CompilerPassState. However, existing callers may depend on
167 // the old invariant that the FlowGraph stored in the CompilerPassState was
168 // always updated, never entirely replaced.
169 //
170 // To make sure callers are updated properly, these methods also return
171 // the final FlowGraph and we add a check that callers use this result.
177 std::initializer_list<CompilerPass::Id> passes);
178
179 protected:
180 // This function executes the pass. If it returns true then
181 // we will run Canonicalize on the graph and execute the pass
182 // again.
183 virtual bool DoBody(CompilerPassState* state) const = 0;
184
185 private:
186 static CompilerPass* FindPassByName(const char* name) {
187 for (intptr_t i = 0; i < kNumPasses; i++) {
188 if ((passes_[i] != nullptr) && (strcmp(passes_[i]->name_, name) == 0)) {
189 return passes_[i];
190 }
191 }
192 return nullptr;
193 }
194
195 void PrintGraph(CompilerPassState* state, Flag mask, intptr_t round) const;
196
197 static CompilerPass* passes_[];
198 static uint8_t flags_[];
199
200 Id id_;
201 const char* name_;
202};
203
204} // namespace dart
205
206#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 bool DoBody(CompilerPassState *state) const =0
static uint8_t * ParseFiltersFromPragma(const char *filter)
static void RunGraphIntrinsicPipeline(CompilerPassState *state)
static DART_WARN_UNUSED_RESULT FlowGraph * RunPipeline(PipelineMode mode, 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 * 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)
#define ADD_ONE(name)
#define DART_WARN_UNUSED_RESULT
Definition dart_api.h:66
#define ASSERT(E)
AtkStateType state
glong glong end
CallSpecializer * call_specializer
AllocationSinking * sinking
SpeculativeInliningPolicy * speculative_policy
FlowGraph * flow_graph() const
GrowableArray< TokenPosition > inline_id_to_token_pos
GrowableArray< intptr_t > caller_inline_id
Precompiler *const precompiler
GrowableArray< const Function * > inline_id_to_function
FlowGraphCompiler * graph_compiler
void set_flow_graph(FlowGraph *flow_graph)