1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2014 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker *
4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker *
8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker *
10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker */
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Worker #include "optimization.h"
18*795d594fSAndroid Build Coastguard Worker
19*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_arm
20*795d594fSAndroid Build Coastguard Worker #include "critical_native_abi_fixup_arm.h"
21*795d594fSAndroid Build Coastguard Worker #include "instruction_simplifier_arm.h"
22*795d594fSAndroid Build Coastguard Worker #endif
23*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_arm64
24*795d594fSAndroid Build Coastguard Worker #include "instruction_simplifier_arm64.h"
25*795d594fSAndroid Build Coastguard Worker #endif
26*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_riscv64
27*795d594fSAndroid Build Coastguard Worker #include "critical_native_abi_fixup_riscv64.h"
28*795d594fSAndroid Build Coastguard Worker #include "instruction_simplifier_riscv64.h"
29*795d594fSAndroid Build Coastguard Worker #endif
30*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_x86
31*795d594fSAndroid Build Coastguard Worker #include "pc_relative_fixups_x86.h"
32*795d594fSAndroid Build Coastguard Worker #include "instruction_simplifier_x86.h"
33*795d594fSAndroid Build Coastguard Worker #endif
34*795d594fSAndroid Build Coastguard Worker #if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64)
35*795d594fSAndroid Build Coastguard Worker #include "x86_memory_gen.h"
36*795d594fSAndroid Build Coastguard Worker #endif
37*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_x86_64
38*795d594fSAndroid Build Coastguard Worker #include "instruction_simplifier_x86_64.h"
39*795d594fSAndroid Build Coastguard Worker #endif
40*795d594fSAndroid Build Coastguard Worker
41*795d594fSAndroid Build Coastguard Worker #include "bounds_check_elimination.h"
42*795d594fSAndroid Build Coastguard Worker #include "cha_guard_optimization.h"
43*795d594fSAndroid Build Coastguard Worker #include "code_sinking.h"
44*795d594fSAndroid Build Coastguard Worker #include "constant_folding.h"
45*795d594fSAndroid Build Coastguard Worker #include "constructor_fence_redundancy_elimination.h"
46*795d594fSAndroid Build Coastguard Worker #include "dead_code_elimination.h"
47*795d594fSAndroid Build Coastguard Worker #include "dex/code_item_accessors-inl.h"
48*795d594fSAndroid Build Coastguard Worker #include "driver/compiler_options.h"
49*795d594fSAndroid Build Coastguard Worker #include "driver/dex_compilation_unit.h"
50*795d594fSAndroid Build Coastguard Worker #include "gvn.h"
51*795d594fSAndroid Build Coastguard Worker #include "induction_var_analysis.h"
52*795d594fSAndroid Build Coastguard Worker #include "inliner.h"
53*795d594fSAndroid Build Coastguard Worker #include "instruction_simplifier.h"
54*795d594fSAndroid Build Coastguard Worker #include "intrinsics.h"
55*795d594fSAndroid Build Coastguard Worker #include "licm.h"
56*795d594fSAndroid Build Coastguard Worker #include "load_store_elimination.h"
57*795d594fSAndroid Build Coastguard Worker #include "loop_optimization.h"
58*795d594fSAndroid Build Coastguard Worker #include "reference_type_propagation.h"
59*795d594fSAndroid Build Coastguard Worker #include "scheduler.h"
60*795d594fSAndroid Build Coastguard Worker #include "select_generator.h"
61*795d594fSAndroid Build Coastguard Worker #include "sharpening.h"
62*795d594fSAndroid Build Coastguard Worker #include "side_effects_analysis.h"
63*795d594fSAndroid Build Coastguard Worker #include "write_barrier_elimination.h"
64*795d594fSAndroid Build Coastguard Worker
65*795d594fSAndroid Build Coastguard Worker // Decide between default or alternative pass name.
66*795d594fSAndroid Build Coastguard Worker
67*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
68*795d594fSAndroid Build Coastguard Worker
OptimizationPassName(OptimizationPass pass)69*795d594fSAndroid Build Coastguard Worker const char* OptimizationPassName(OptimizationPass pass) {
70*795d594fSAndroid Build Coastguard Worker switch (pass) {
71*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kSideEffectsAnalysis:
72*795d594fSAndroid Build Coastguard Worker return SideEffectsAnalysis::kSideEffectsAnalysisPassName;
73*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInductionVarAnalysis:
74*795d594fSAndroid Build Coastguard Worker return HInductionVarAnalysis::kInductionPassName;
75*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kGlobalValueNumbering:
76*795d594fSAndroid Build Coastguard Worker return GVNOptimization::kGlobalValueNumberingPassName;
77*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInvariantCodeMotion:
78*795d594fSAndroid Build Coastguard Worker return LICM::kLoopInvariantCodeMotionPassName;
79*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kLoopOptimization:
80*795d594fSAndroid Build Coastguard Worker return HLoopOptimization::kLoopOptimizationPassName;
81*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kBoundsCheckElimination:
82*795d594fSAndroid Build Coastguard Worker return BoundsCheckElimination::kBoundsCheckEliminationPassName;
83*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kLoadStoreElimination:
84*795d594fSAndroid Build Coastguard Worker return LoadStoreElimination::kLoadStoreEliminationPassName;
85*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kConstantFolding:
86*795d594fSAndroid Build Coastguard Worker return HConstantFolding::kConstantFoldingPassName;
87*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kDeadCodeElimination:
88*795d594fSAndroid Build Coastguard Worker return HDeadCodeElimination::kDeadCodeEliminationPassName;
89*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInliner:
90*795d594fSAndroid Build Coastguard Worker return HInliner::kInlinerPassName;
91*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kSelectGenerator:
92*795d594fSAndroid Build Coastguard Worker return HSelectGenerator::kSelectGeneratorPassName;
93*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kAggressiveInstructionSimplifier:
94*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInstructionSimplifier:
95*795d594fSAndroid Build Coastguard Worker return InstructionSimplifier::kInstructionSimplifierPassName;
96*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kCHAGuardOptimization:
97*795d594fSAndroid Build Coastguard Worker return CHAGuardOptimization::kCHAGuardOptimizationPassName;
98*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kCodeSinking:
99*795d594fSAndroid Build Coastguard Worker return CodeSinking::kCodeSinkingPassName;
100*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kConstructorFenceRedundancyElimination:
101*795d594fSAndroid Build Coastguard Worker return ConstructorFenceRedundancyElimination::kCFREPassName;
102*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kReferenceTypePropagation:
103*795d594fSAndroid Build Coastguard Worker return ReferenceTypePropagation::kReferenceTypePropagationPassName;
104*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kScheduling:
105*795d594fSAndroid Build Coastguard Worker return HInstructionScheduling::kInstructionSchedulingPassName;
106*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kWriteBarrierElimination:
107*795d594fSAndroid Build Coastguard Worker return WriteBarrierElimination::kWBEPassName;
108*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_arm
109*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInstructionSimplifierArm:
110*795d594fSAndroid Build Coastguard Worker return arm::InstructionSimplifierArm::kInstructionSimplifierArmPassName;
111*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kCriticalNativeAbiFixupArm:
112*795d594fSAndroid Build Coastguard Worker return arm::CriticalNativeAbiFixupArm::kCriticalNativeAbiFixupArmPassName;
113*795d594fSAndroid Build Coastguard Worker #endif
114*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_arm64
115*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInstructionSimplifierArm64:
116*795d594fSAndroid Build Coastguard Worker return arm64::InstructionSimplifierArm64::kInstructionSimplifierArm64PassName;
117*795d594fSAndroid Build Coastguard Worker #endif
118*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_riscv64
119*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kCriticalNativeAbiFixupRiscv64:
120*795d594fSAndroid Build Coastguard Worker return riscv64::CriticalNativeAbiFixupRiscv64::kCriticalNativeAbiFixupRiscv64PassName;
121*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInstructionSimplifierRiscv64:
122*795d594fSAndroid Build Coastguard Worker return riscv64::InstructionSimplifierRiscv64::kInstructionSimplifierRiscv64PassName;
123*795d594fSAndroid Build Coastguard Worker #endif
124*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_x86
125*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kPcRelativeFixupsX86:
126*795d594fSAndroid Build Coastguard Worker return x86::PcRelativeFixups::kPcRelativeFixupsX86PassName;
127*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInstructionSimplifierX86:
128*795d594fSAndroid Build Coastguard Worker return x86::InstructionSimplifierX86::kInstructionSimplifierX86PassName;
129*795d594fSAndroid Build Coastguard Worker #endif
130*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_x86_64
131*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInstructionSimplifierX86_64:
132*795d594fSAndroid Build Coastguard Worker return x86_64::InstructionSimplifierX86_64::kInstructionSimplifierX86_64PassName;
133*795d594fSAndroid Build Coastguard Worker #endif
134*795d594fSAndroid Build Coastguard Worker #if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64)
135*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kX86MemoryOperandGeneration:
136*795d594fSAndroid Build Coastguard Worker return x86::X86MemoryOperandGeneration::kX86MemoryOperandGenerationPassName;
137*795d594fSAndroid Build Coastguard Worker #endif
138*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kNone:
139*795d594fSAndroid Build Coastguard Worker LOG(FATAL) << "kNone does not represent an actual pass";
140*795d594fSAndroid Build Coastguard Worker UNREACHABLE();
141*795d594fSAndroid Build Coastguard Worker }
142*795d594fSAndroid Build Coastguard Worker }
143*795d594fSAndroid Build Coastguard Worker
144*795d594fSAndroid Build Coastguard Worker #define X(x) if (pass_name == OptimizationPassName((x))) return (x)
145*795d594fSAndroid Build Coastguard Worker
OptimizationPassByName(const std::string & pass_name)146*795d594fSAndroid Build Coastguard Worker OptimizationPass OptimizationPassByName(const std::string& pass_name) {
147*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kBoundsCheckElimination);
148*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kCHAGuardOptimization);
149*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kCodeSinking);
150*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kConstantFolding);
151*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kConstructorFenceRedundancyElimination);
152*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kDeadCodeElimination);
153*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kGlobalValueNumbering);
154*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kInductionVarAnalysis);
155*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kInliner);
156*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kInstructionSimplifier);
157*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kInvariantCodeMotion);
158*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kLoadStoreElimination);
159*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kLoopOptimization);
160*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kReferenceTypePropagation);
161*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kScheduling);
162*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kSelectGenerator);
163*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kSideEffectsAnalysis);
164*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_arm
165*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kInstructionSimplifierArm);
166*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kCriticalNativeAbiFixupArm);
167*795d594fSAndroid Build Coastguard Worker #endif
168*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_arm64
169*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kInstructionSimplifierArm64);
170*795d594fSAndroid Build Coastguard Worker #endif
171*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_riscv64
172*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kCriticalNativeAbiFixupRiscv64);
173*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kInstructionSimplifierRiscv64);
174*795d594fSAndroid Build Coastguard Worker #endif
175*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_x86
176*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kPcRelativeFixupsX86);
177*795d594fSAndroid Build Coastguard Worker X(OptimizationPass::kX86MemoryOperandGeneration);
178*795d594fSAndroid Build Coastguard Worker #endif
179*795d594fSAndroid Build Coastguard Worker LOG(FATAL) << "Cannot find optimization " << pass_name;
180*795d594fSAndroid Build Coastguard Worker UNREACHABLE();
181*795d594fSAndroid Build Coastguard Worker }
182*795d594fSAndroid Build Coastguard Worker
183*795d594fSAndroid Build Coastguard Worker #undef X
184*795d594fSAndroid Build Coastguard Worker
ConstructOptimizations(const OptimizationDef definitions[],size_t length,ArenaAllocator * allocator,HGraph * graph,OptimizingCompilerStats * stats,CodeGenerator * codegen,const DexCompilationUnit & dex_compilation_unit)185*795d594fSAndroid Build Coastguard Worker ArenaVector<HOptimization*> ConstructOptimizations(
186*795d594fSAndroid Build Coastguard Worker const OptimizationDef definitions[],
187*795d594fSAndroid Build Coastguard Worker size_t length,
188*795d594fSAndroid Build Coastguard Worker ArenaAllocator* allocator,
189*795d594fSAndroid Build Coastguard Worker HGraph* graph,
190*795d594fSAndroid Build Coastguard Worker OptimizingCompilerStats* stats,
191*795d594fSAndroid Build Coastguard Worker CodeGenerator* codegen,
192*795d594fSAndroid Build Coastguard Worker const DexCompilationUnit& dex_compilation_unit) {
193*795d594fSAndroid Build Coastguard Worker ArenaVector<HOptimization*> optimizations(allocator->Adapter());
194*795d594fSAndroid Build Coastguard Worker
195*795d594fSAndroid Build Coastguard Worker // Some optimizations require SideEffectsAnalysis or HInductionVarAnalysis
196*795d594fSAndroid Build Coastguard Worker // instances. This method uses the nearest instance preceeding it in the pass
197*795d594fSAndroid Build Coastguard Worker // name list or fails fatally if no such analysis can be found.
198*795d594fSAndroid Build Coastguard Worker SideEffectsAnalysis* most_recent_side_effects = nullptr;
199*795d594fSAndroid Build Coastguard Worker HInductionVarAnalysis* most_recent_induction = nullptr;
200*795d594fSAndroid Build Coastguard Worker
201*795d594fSAndroid Build Coastguard Worker // Loop over the requested optimizations.
202*795d594fSAndroid Build Coastguard Worker for (size_t i = 0; i < length; i++) {
203*795d594fSAndroid Build Coastguard Worker OptimizationPass pass = definitions[i].pass;
204*795d594fSAndroid Build Coastguard Worker const char* alt_name = definitions[i].pass_name;
205*795d594fSAndroid Build Coastguard Worker const char* pass_name = alt_name != nullptr
206*795d594fSAndroid Build Coastguard Worker ? alt_name
207*795d594fSAndroid Build Coastguard Worker : OptimizationPassName(pass);
208*795d594fSAndroid Build Coastguard Worker HOptimization* opt = nullptr;
209*795d594fSAndroid Build Coastguard Worker
210*795d594fSAndroid Build Coastguard Worker switch (pass) {
211*795d594fSAndroid Build Coastguard Worker //
212*795d594fSAndroid Build Coastguard Worker // Analysis passes (kept in most recent for subsequent passes).
213*795d594fSAndroid Build Coastguard Worker //
214*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kSideEffectsAnalysis:
215*795d594fSAndroid Build Coastguard Worker opt = most_recent_side_effects = new (allocator) SideEffectsAnalysis(graph, pass_name);
216*795d594fSAndroid Build Coastguard Worker break;
217*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInductionVarAnalysis:
218*795d594fSAndroid Build Coastguard Worker opt = most_recent_induction =
219*795d594fSAndroid Build Coastguard Worker new (allocator) HInductionVarAnalysis(graph, stats, pass_name);
220*795d594fSAndroid Build Coastguard Worker break;
221*795d594fSAndroid Build Coastguard Worker //
222*795d594fSAndroid Build Coastguard Worker // Passes that need prior analysis.
223*795d594fSAndroid Build Coastguard Worker //
224*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kGlobalValueNumbering:
225*795d594fSAndroid Build Coastguard Worker CHECK(most_recent_side_effects != nullptr);
226*795d594fSAndroid Build Coastguard Worker opt = new (allocator) GVNOptimization(graph, *most_recent_side_effects, pass_name);
227*795d594fSAndroid Build Coastguard Worker break;
228*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInvariantCodeMotion:
229*795d594fSAndroid Build Coastguard Worker CHECK(most_recent_side_effects != nullptr);
230*795d594fSAndroid Build Coastguard Worker opt = new (allocator) LICM(graph, *most_recent_side_effects, stats, pass_name);
231*795d594fSAndroid Build Coastguard Worker break;
232*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kLoopOptimization:
233*795d594fSAndroid Build Coastguard Worker CHECK(most_recent_induction != nullptr);
234*795d594fSAndroid Build Coastguard Worker opt = new (allocator) HLoopOptimization(
235*795d594fSAndroid Build Coastguard Worker graph, *codegen, most_recent_induction, stats, pass_name);
236*795d594fSAndroid Build Coastguard Worker break;
237*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kBoundsCheckElimination:
238*795d594fSAndroid Build Coastguard Worker CHECK(most_recent_side_effects != nullptr && most_recent_induction != nullptr);
239*795d594fSAndroid Build Coastguard Worker opt = new (allocator) BoundsCheckElimination(
240*795d594fSAndroid Build Coastguard Worker graph, *most_recent_side_effects, most_recent_induction, pass_name);
241*795d594fSAndroid Build Coastguard Worker break;
242*795d594fSAndroid Build Coastguard Worker //
243*795d594fSAndroid Build Coastguard Worker // Regular passes.
244*795d594fSAndroid Build Coastguard Worker //
245*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kConstantFolding:
246*795d594fSAndroid Build Coastguard Worker opt = new (allocator) HConstantFolding(graph, stats, pass_name);
247*795d594fSAndroid Build Coastguard Worker break;
248*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kDeadCodeElimination:
249*795d594fSAndroid Build Coastguard Worker opt = new (allocator) HDeadCodeElimination(graph, stats, pass_name);
250*795d594fSAndroid Build Coastguard Worker break;
251*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInliner: {
252*795d594fSAndroid Build Coastguard Worker CodeItemDataAccessor accessor(*dex_compilation_unit.GetDexFile(),
253*795d594fSAndroid Build Coastguard Worker dex_compilation_unit.GetCodeItem());
254*795d594fSAndroid Build Coastguard Worker opt = new (allocator) HInliner(graph, // outer_graph
255*795d594fSAndroid Build Coastguard Worker graph, // outermost_graph
256*795d594fSAndroid Build Coastguard Worker codegen,
257*795d594fSAndroid Build Coastguard Worker dex_compilation_unit, // outer_compilation_unit
258*795d594fSAndroid Build Coastguard Worker dex_compilation_unit, // outermost_compilation_unit
259*795d594fSAndroid Build Coastguard Worker stats,
260*795d594fSAndroid Build Coastguard Worker accessor.RegistersSize(),
261*795d594fSAndroid Build Coastguard Worker /* total_number_of_instructions= */ 0,
262*795d594fSAndroid Build Coastguard Worker /* parent= */ nullptr,
263*795d594fSAndroid Build Coastguard Worker /* caller_environment= */ nullptr,
264*795d594fSAndroid Build Coastguard Worker /* depth= */ 0,
265*795d594fSAndroid Build Coastguard Worker /* try_catch_inlining_allowed= */ true,
266*795d594fSAndroid Build Coastguard Worker pass_name);
267*795d594fSAndroid Build Coastguard Worker break;
268*795d594fSAndroid Build Coastguard Worker }
269*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kSelectGenerator:
270*795d594fSAndroid Build Coastguard Worker opt = new (allocator) HSelectGenerator(graph, stats, pass_name);
271*795d594fSAndroid Build Coastguard Worker break;
272*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInstructionSimplifier:
273*795d594fSAndroid Build Coastguard Worker opt = new (allocator) InstructionSimplifier(graph, codegen, stats, pass_name);
274*795d594fSAndroid Build Coastguard Worker break;
275*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kAggressiveInstructionSimplifier:
276*795d594fSAndroid Build Coastguard Worker opt = new (allocator) InstructionSimplifier(graph,
277*795d594fSAndroid Build Coastguard Worker codegen,
278*795d594fSAndroid Build Coastguard Worker stats,
279*795d594fSAndroid Build Coastguard Worker pass_name,
280*795d594fSAndroid Build Coastguard Worker /* use_all_optimizations_ = */ true);
281*795d594fSAndroid Build Coastguard Worker break;
282*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kCHAGuardOptimization:
283*795d594fSAndroid Build Coastguard Worker opt = new (allocator) CHAGuardOptimization(graph, pass_name);
284*795d594fSAndroid Build Coastguard Worker break;
285*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kCodeSinking:
286*795d594fSAndroid Build Coastguard Worker opt = new (allocator) CodeSinking(graph, stats, pass_name);
287*795d594fSAndroid Build Coastguard Worker break;
288*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kConstructorFenceRedundancyElimination:
289*795d594fSAndroid Build Coastguard Worker opt = new (allocator) ConstructorFenceRedundancyElimination(graph, stats, pass_name);
290*795d594fSAndroid Build Coastguard Worker break;
291*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kLoadStoreElimination:
292*795d594fSAndroid Build Coastguard Worker opt = new (allocator) LoadStoreElimination(graph, stats, pass_name);
293*795d594fSAndroid Build Coastguard Worker break;
294*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kReferenceTypePropagation:
295*795d594fSAndroid Build Coastguard Worker opt = new (allocator) ReferenceTypePropagation(
296*795d594fSAndroid Build Coastguard Worker graph, dex_compilation_unit.GetDexCache(), /* is_first_run= */ false, pass_name);
297*795d594fSAndroid Build Coastguard Worker break;
298*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kWriteBarrierElimination:
299*795d594fSAndroid Build Coastguard Worker opt = new (allocator) WriteBarrierElimination(graph, stats, pass_name);
300*795d594fSAndroid Build Coastguard Worker break;
301*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kScheduling:
302*795d594fSAndroid Build Coastguard Worker opt = new (allocator) HInstructionScheduling(
303*795d594fSAndroid Build Coastguard Worker graph, codegen->GetCompilerOptions().GetInstructionSet(), codegen, pass_name);
304*795d594fSAndroid Build Coastguard Worker break;
305*795d594fSAndroid Build Coastguard Worker //
306*795d594fSAndroid Build Coastguard Worker // Arch-specific passes.
307*795d594fSAndroid Build Coastguard Worker //
308*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_arm
309*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInstructionSimplifierArm:
310*795d594fSAndroid Build Coastguard Worker DCHECK(alt_name == nullptr) << "arch-specific pass does not support alternative name";
311*795d594fSAndroid Build Coastguard Worker opt = new (allocator) arm::InstructionSimplifierArm(graph, codegen, stats);
312*795d594fSAndroid Build Coastguard Worker break;
313*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kCriticalNativeAbiFixupArm:
314*795d594fSAndroid Build Coastguard Worker DCHECK(alt_name == nullptr) << "arch-specific pass does not support alternative name";
315*795d594fSAndroid Build Coastguard Worker opt = new (allocator) arm::CriticalNativeAbiFixupArm(graph, stats);
316*795d594fSAndroid Build Coastguard Worker break;
317*795d594fSAndroid Build Coastguard Worker #endif
318*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_arm64
319*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInstructionSimplifierArm64:
320*795d594fSAndroid Build Coastguard Worker DCHECK(alt_name == nullptr) << "arch-specific pass does not support alternative name";
321*795d594fSAndroid Build Coastguard Worker opt = new (allocator) arm64::InstructionSimplifierArm64(graph, codegen, stats);
322*795d594fSAndroid Build Coastguard Worker break;
323*795d594fSAndroid Build Coastguard Worker #endif
324*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_riscv64
325*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kCriticalNativeAbiFixupRiscv64:
326*795d594fSAndroid Build Coastguard Worker DCHECK(alt_name == nullptr) << "arch-specific pass does not support alternative name";
327*795d594fSAndroid Build Coastguard Worker opt = new (allocator) riscv64::CriticalNativeAbiFixupRiscv64(graph, stats);
328*795d594fSAndroid Build Coastguard Worker break;
329*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInstructionSimplifierRiscv64:
330*795d594fSAndroid Build Coastguard Worker DCHECK(alt_name == nullptr) << "arch-specific pass does not support alternative name";
331*795d594fSAndroid Build Coastguard Worker opt = new (allocator) riscv64::InstructionSimplifierRiscv64(graph, stats);
332*795d594fSAndroid Build Coastguard Worker break;
333*795d594fSAndroid Build Coastguard Worker #endif
334*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_x86
335*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kPcRelativeFixupsX86:
336*795d594fSAndroid Build Coastguard Worker DCHECK(alt_name == nullptr) << "arch-specific pass does not support alternative name";
337*795d594fSAndroid Build Coastguard Worker opt = new (allocator) x86::PcRelativeFixups(graph, codegen, stats);
338*795d594fSAndroid Build Coastguard Worker break;
339*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kX86MemoryOperandGeneration:
340*795d594fSAndroid Build Coastguard Worker DCHECK(alt_name == nullptr) << "arch-specific pass does not support alternative name";
341*795d594fSAndroid Build Coastguard Worker opt = new (allocator) x86::X86MemoryOperandGeneration(graph, codegen, stats);
342*795d594fSAndroid Build Coastguard Worker break;
343*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInstructionSimplifierX86:
344*795d594fSAndroid Build Coastguard Worker opt = new (allocator) x86::InstructionSimplifierX86(graph, codegen, stats);
345*795d594fSAndroid Build Coastguard Worker break;
346*795d594fSAndroid Build Coastguard Worker #endif
347*795d594fSAndroid Build Coastguard Worker #ifdef ART_ENABLE_CODEGEN_x86_64
348*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kInstructionSimplifierX86_64:
349*795d594fSAndroid Build Coastguard Worker opt = new (allocator) x86_64::InstructionSimplifierX86_64(graph, codegen, stats);
350*795d594fSAndroid Build Coastguard Worker break;
351*795d594fSAndroid Build Coastguard Worker #endif
352*795d594fSAndroid Build Coastguard Worker case OptimizationPass::kNone:
353*795d594fSAndroid Build Coastguard Worker LOG(FATAL) << "kNone does not represent an actual pass";
354*795d594fSAndroid Build Coastguard Worker UNREACHABLE();
355*795d594fSAndroid Build Coastguard Worker } // switch
356*795d594fSAndroid Build Coastguard Worker
357*795d594fSAndroid Build Coastguard Worker // Add each next optimization to result vector.
358*795d594fSAndroid Build Coastguard Worker CHECK(opt != nullptr);
359*795d594fSAndroid Build Coastguard Worker DCHECK_STREQ(pass_name, opt->GetPassName()); // Consistency check.
360*795d594fSAndroid Build Coastguard Worker optimizations.push_back(opt);
361*795d594fSAndroid Build Coastguard Worker }
362*795d594fSAndroid Build Coastguard Worker
363*795d594fSAndroid Build Coastguard Worker return optimizations;
364*795d594fSAndroid Build Coastguard Worker }
365*795d594fSAndroid Build Coastguard Worker
366*795d594fSAndroid Build Coastguard Worker } // namespace art
367