Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
inliner.h
Go to the documentation of this file.
1// Copyright (c) 2012, 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_BACKEND_INLINER_H_
6#define RUNTIME_VM_COMPILER_BACKEND_INLINER_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 "vm/allocation.h"
13#include "vm/growable_array.h"
14#include "vm/token_position.h"
15
16namespace dart {
17
18class Definition;
19class Field;
20class FlowGraph;
21class ForwardInstructionIterator;
22class Function;
23class FunctionEntryInstr;
24class GraphEntryInstr;
25class ICData;
26class InstanceCallInstr;
27class Instruction;
28struct InstructionSource;
29class Precompiler;
30class StaticCallInstr;
31class TargetEntryInstr;
32
34 public:
35 explicit SpeculativeInliningPolicy(bool enable_suppression,
36 intptr_t limit = -1)
37 : enable_suppression_(enable_suppression), remaining_(limit) {}
38
40 return !enable_suppression_ || remaining_ > 0;
41 }
42
43 bool IsAllowedForInlining(intptr_t call_deopt_id) const {
44 // If we are not suppressing, we always enable optimistic inlining.
45 if (!enable_suppression_) {
46 return true;
47 }
48
49 // If we have already suppressed the deopt-id we don't allow inlining it.
50 if (IsSuppressed(call_deopt_id)) {
51 return false;
52 }
53
54 // Allow it if we can bailout at least one more time.
55 return remaining_ > 0;
56 }
57
58 bool AddBlockedDeoptId(intptr_t id) {
59 ASSERT(enable_suppression_);
60#if defined(DEBUG)
61 ASSERT(!IsSuppressed(id));
62#endif
63
64 // If we exhausted the number of suppression entries there is no point
65 // in adding entries to the list.
66 if (remaining_ <= 0) return false;
67
68 inlining_suppressions_.Add(id);
69 remaining_ -= 1;
70 return true;
71 }
72
73 intptr_t length() const { return inlining_suppressions_.length(); }
74
75 private:
76 bool IsSuppressed(intptr_t id) const {
77 for (intptr_t i = 0; i < inlining_suppressions_.length(); ++i) {
78 if (inlining_suppressions_[i] == id) return true;
79 }
80 return false;
81 }
82
83 // Whether we enable suppressing inlining at specific deopt-ids.
84 const bool enable_suppression_;
85
86 // After we reach [remaining_] number of deopt-ids in [inlining_suppressions_]
87 // list, we'll disable speculative inlining entirely.
88 intptr_t remaining_;
89 GrowableArray<intptr_t> inlining_suppressions_;
90};
91
93 public:
95 GrowableArray<const Function*>* inline_id_to_function,
96 GrowableArray<TokenPosition>* inline_id_to_token_pos,
97 GrowableArray<intptr_t>* caller_inline_id,
99 Precompiler* precompiler);
100
101 // The flow graph is destructively updated upon inlining. Returns the max
102 // depth that we inlined.
103 int Inline();
104
105 // Computes graph information (instruction and call site count).
106 // For the non-specialized cases (num_constants_args == 0), the
107 // method uses a cache to avoid recomputing the counts (the cached
108 // value may still be approximate but close). The 'force' flag is
109 // used to update the cached value at the end of running the full pipeline
110 // on non-specialized cases. Specialized cases (num_constants_args > 0)
111 // always recompute the counts without caching.
112 //
113 // TODO(ajcbik): cache for specific constant argument combinations too?
115 intptr_t num_constant_args,
116 bool force,
117 intptr_t* instruction_count,
118 intptr_t* call_site_count);
119
120 static void SetInliningId(FlowGraph* flow_graph, intptr_t inlining_id);
121
122 bool AlwaysInline(const Function& function);
123
127
128 FlowGraph* flow_graph() const { return flow_graph_; }
129 intptr_t NextInlineId(const Function& function,
131
132 bool trace_inlining() const { return trace_inlining_; }
133
135 return speculative_policy_;
136 }
137
138 private:
139 friend class CallSiteInliner;
140
141 FlowGraph* flow_graph_;
142 GrowableArray<const Function*>* inline_id_to_function_;
143 GrowableArray<TokenPosition>* inline_id_to_token_pos_;
144 GrowableArray<intptr_t>* caller_inline_id_;
145 const bool trace_inlining_;
146 SpeculativeInliningPolicy* speculative_policy_;
147 Precompiler* precompiler_;
148
150};
151
152} // namespace dart
153
154#endif // RUNTIME_VM_COMPILER_BACKEND_INLINER_H_
void Add(const T &value)
intptr_t length() const
bool AlwaysInline(const Function &function)
Definition inliner.cc:2512
intptr_t NextInlineId(const Function &function, const InstructionSource &source)
Definition inliner.cc:2606
bool trace_inlining() const
Definition inliner.h:132
static bool FunctionHasAlwaysConsiderInliningPragma(const Function &function)
Definition inliner.cc:2499
static void SetInliningId(FlowGraph *flow_graph, intptr_t inlining_id)
Definition inliner.cc:2449
SpeculativeInliningPolicy * speculative_policy()
Definition inliner.h:134
static bool FunctionHasNeverInlinePragma(const Function &function)
Definition inliner.cc:2487
static void CollectGraphInfo(FlowGraph *flow_graph, intptr_t num_constant_args, bool force, intptr_t *instruction_count, intptr_t *call_site_count)
Definition inliner.cc:2415
FlowGraph * flow_graph() const
Definition inliner.h:128
static bool FunctionHasPreferInlinePragma(const Function &function)
Definition inliner.cc:2475
bool IsAllowedForInlining(intptr_t call_deopt_id) const
Definition inliner.h:43
intptr_t length() const
Definition inliner.h:73
bool AllowsSpeculativeInlining() const
Definition inliner.h:39
bool AddBlockedDeoptId(intptr_t id)
Definition inliner.h:58
SpeculativeInliningPolicy(bool enable_suppression, intptr_t limit=-1)
Definition inliner.h:35
#define ASSERT(E)
SkBitmap source
Definition examples.cpp:28
Dart_NativeFunction function
Definition fuchsia.cc:51
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition globals.h:581