|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef jit_IonOptimizationLevels_h |
|
8 #define jit_IonOptimizationLevels_h |
|
9 |
|
10 #include "jsbytecode.h" |
|
11 #include "jstypes.h" |
|
12 |
|
13 #include "jit/JitOptions.h" |
|
14 #include "js/TypeDecls.h" |
|
15 |
|
16 namespace js { |
|
17 namespace jit { |
|
18 |
|
19 enum OptimizationLevel |
|
20 { |
|
21 Optimization_DontCompile, |
|
22 Optimization_Normal, |
|
23 Optimization_AsmJS, |
|
24 Optimization_Count |
|
25 }; |
|
26 |
|
27 #ifdef JS_ION |
|
28 |
|
29 #ifdef DEBUG |
|
30 inline const char * |
|
31 OptimizationLevelString(OptimizationLevel level) |
|
32 { |
|
33 switch (level) { |
|
34 case Optimization_DontCompile: |
|
35 return "Optimization_DontCompile"; |
|
36 case Optimization_Normal: |
|
37 return "Optimization_Normal"; |
|
38 case Optimization_AsmJS: |
|
39 return "Optimization_AsmJS"; |
|
40 default: |
|
41 MOZ_ASSUME_UNREACHABLE("Invalid OptimizationLevel"); |
|
42 } |
|
43 } |
|
44 #endif |
|
45 |
|
46 class OptimizationInfo |
|
47 { |
|
48 public: |
|
49 OptimizationLevel level_; |
|
50 |
|
51 // Toggles whether Effective Address Analysis is performed. |
|
52 bool eaa_; |
|
53 |
|
54 // Toggles whether Edge Case Analysis is used. |
|
55 bool edgeCaseAnalysis_; |
|
56 |
|
57 // Toggles whether redundant checks get removed. |
|
58 bool eliminateRedundantChecks_; |
|
59 |
|
60 // Toggles whether interpreted scripts get inlined. |
|
61 bool inlineInterpreted_; |
|
62 |
|
63 // Toggles whether native scripts get inlined. |
|
64 bool inlineNative_; |
|
65 |
|
66 // Toggles whether global value numbering is used. |
|
67 bool gvn_; |
|
68 |
|
69 // Toggles whether global value numbering is optimistic or pessimistic. |
|
70 IonGvnKind gvnKind_; |
|
71 |
|
72 // Toggles whether loop invariant code motion is performed. |
|
73 bool licm_; |
|
74 |
|
75 // Toggles whether Unreachable Code Elimination is performed. |
|
76 bool uce_; |
|
77 |
|
78 // Toggles whether Range Analysis is used. |
|
79 bool rangeAnalysis_; |
|
80 |
|
81 // Describes which register allocator to use. |
|
82 IonRegisterAllocator registerAllocator_; |
|
83 |
|
84 // The maximum total bytecode size of an inline call site. |
|
85 uint32_t inlineMaxTotalBytecodeLength_; |
|
86 |
|
87 // The maximum bytecode length the caller may have, |
|
88 // before we stop inlining large functions in that caller. |
|
89 uint32_t inliningMaxCallerBytecodeLength_; |
|
90 |
|
91 // The maximum inlining depth. |
|
92 uint32_t maxInlineDepth_; |
|
93 |
|
94 // The maximum inlining depth for functions. |
|
95 // |
|
96 // Inlining small functions has almost no compiling overhead |
|
97 // and removes the otherwise needed call overhead. |
|
98 // The value is currently very low. |
|
99 // Actually it is only needed to make sure we don't blow out the stack. |
|
100 uint32_t smallFunctionMaxInlineDepth_; |
|
101 |
|
102 // How many invocations or loop iterations are needed before functions |
|
103 // are compiled. |
|
104 uint32_t usesBeforeCompile_; |
|
105 |
|
106 // How many invocations or loop iterations are needed before calls |
|
107 // are inlined, as a fraction of usesBeforeCompile. |
|
108 double usesBeforeInliningFactor_; |
|
109 |
|
110 OptimizationInfo() |
|
111 { } |
|
112 |
|
113 void initNormalOptimizationInfo(); |
|
114 void initAsmjsOptimizationInfo(); |
|
115 |
|
116 OptimizationLevel level() const { |
|
117 return level_; |
|
118 } |
|
119 |
|
120 bool inlineInterpreted() const { |
|
121 return inlineInterpreted_ && !js_JitOptions.disableInlining; |
|
122 } |
|
123 |
|
124 bool inlineNative() const { |
|
125 return inlineNative_ && !js_JitOptions.disableInlining; |
|
126 } |
|
127 |
|
128 uint32_t usesBeforeCompile(JSScript *script, jsbytecode *pc = nullptr) const; |
|
129 |
|
130 bool gvnEnabled() const { |
|
131 return gvn_ && !js_JitOptions.disableGvn; |
|
132 } |
|
133 |
|
134 bool licmEnabled() const { |
|
135 return licm_ && !js_JitOptions.disableLicm; |
|
136 } |
|
137 |
|
138 bool uceEnabled() const { |
|
139 return uce_ && !js_JitOptions.disableUce; |
|
140 } |
|
141 |
|
142 bool rangeAnalysisEnabled() const { |
|
143 return rangeAnalysis_ && !js_JitOptions.disableRangeAnalysis; |
|
144 } |
|
145 |
|
146 bool eaaEnabled() const { |
|
147 return eaa_ && !js_JitOptions.disableEaa; |
|
148 } |
|
149 |
|
150 bool edgeCaseAnalysisEnabled() const { |
|
151 return edgeCaseAnalysis_ && !js_JitOptions.disableEdgeCaseAnalysis; |
|
152 } |
|
153 |
|
154 bool eliminateRedundantChecksEnabled() const { |
|
155 return eliminateRedundantChecks_; |
|
156 } |
|
157 |
|
158 IonGvnKind gvnKind() const { |
|
159 if (!js_JitOptions.forceGvnKind) |
|
160 return gvnKind_; |
|
161 return js_JitOptions.forcedGvnKind; |
|
162 } |
|
163 |
|
164 IonRegisterAllocator registerAllocator() const { |
|
165 if (!js_JitOptions.forceRegisterAllocator) |
|
166 return registerAllocator_; |
|
167 return js_JitOptions.forcedRegisterAllocator; |
|
168 } |
|
169 |
|
170 uint32_t smallFunctionMaxInlineDepth() const { |
|
171 return smallFunctionMaxInlineDepth_; |
|
172 } |
|
173 |
|
174 bool isSmallFunction(JSScript *script) const; |
|
175 |
|
176 uint32_t maxInlineDepth() const { |
|
177 return maxInlineDepth_; |
|
178 } |
|
179 |
|
180 uint32_t inlineMaxTotalBytecodeLength() const { |
|
181 return inlineMaxTotalBytecodeLength_; |
|
182 } |
|
183 |
|
184 uint32_t inliningMaxCallerBytecodeLength() const { |
|
185 return inlineMaxTotalBytecodeLength_; |
|
186 } |
|
187 |
|
188 uint32_t usesBeforeInlining() const { |
|
189 uint32_t usesBeforeCompile = usesBeforeCompile_; |
|
190 if (js_JitOptions.forceDefaultIonUsesBeforeCompile) |
|
191 usesBeforeCompile = js_JitOptions.forcedDefaultIonUsesBeforeCompile; |
|
192 return usesBeforeCompile * usesBeforeInliningFactor_; |
|
193 } |
|
194 }; |
|
195 |
|
196 class OptimizationInfos |
|
197 { |
|
198 private: |
|
199 OptimizationInfo infos_[Optimization_Count - 1]; |
|
200 |
|
201 public: |
|
202 OptimizationInfos(); |
|
203 |
|
204 const OptimizationInfo *get(OptimizationLevel level) const { |
|
205 JS_ASSERT(level < Optimization_Count); |
|
206 JS_ASSERT(level != Optimization_DontCompile); |
|
207 |
|
208 return &infos_[level - 1]; |
|
209 } |
|
210 |
|
211 OptimizationLevel nextLevel(OptimizationLevel level) const; |
|
212 OptimizationLevel firstLevel() const; |
|
213 bool isLastLevel(OptimizationLevel level) const; |
|
214 OptimizationLevel levelForScript(JSScript *script, jsbytecode *pc = nullptr) const; |
|
215 }; |
|
216 |
|
217 extern OptimizationInfos js_IonOptimizations; |
|
218 |
|
219 #endif // JS_ION |
|
220 |
|
221 } // namespace jit |
|
222 } // namespace js |
|
223 |
|
224 #endif /* jit_IonOptimizationLevels_h */ |