blob: 375003bf1fde575464015451d0359a9d2b8d9967 [file] [log] [blame]
Jean Christophe Beyler2469e602014-05-06 20:36:55 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andreas Gampe0b9203e2015-01-22 20:39:27 -080017#include "pass_driver_me_opts.h"
18
19#include "base/logging.h"
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070020#include "base/macros.h"
21#include "bb_optimizations.h"
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070022#include "dataflow_iterator.h"
23#include "dataflow_iterator-inl.h"
Mathieu Chartier5bdab122015-01-26 18:30:19 -080024#include "pass_driver_me_opts.h"
25#include "pass_manager.h"
Vladimir Marko7baa6f82014-10-09 18:01:24 +010026#include "post_opt_passes.h"
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070027
28namespace art {
29
Mathieu Chartier5bdab122015-01-26 18:30:19 -080030void PassDriverMEOpts::SetupPasses(PassManager* pass_manager) {
31 /*
32 * Create the pass list. These passes are immutable and are shared across the threads.
33 *
34 * Advantage is that there will be no race conditions here.
35 * Disadvantage is the passes can't change their internal states depending on CompilationUnit:
36 * - This is not yet an issue: no current pass would require it.
37 */
Jeff Hao848f70a2014-01-15 13:49:50 -080038 pass_manager->AddPass(new StringChange);
Mathieu Chartier5bdab122015-01-26 18:30:19 -080039 pass_manager->AddPass(new CacheFieldLoweringInfo);
40 pass_manager->AddPass(new CacheMethodLoweringInfo);
41 pass_manager->AddPass(new CalculatePredecessors);
42 pass_manager->AddPass(new DFSOrders);
43 pass_manager->AddPass(new ClassInitCheckElimination);
44 pass_manager->AddPass(new SpecialMethodInliner);
45 pass_manager->AddPass(new NullCheckElimination);
46 pass_manager->AddPass(new BBCombine);
47 pass_manager->AddPass(new CodeLayout);
48 pass_manager->AddPass(new GlobalValueNumberingPass);
Vladimir Marko7a01dc22015-01-02 17:00:44 +000049 pass_manager->AddPass(new DeadCodeEliminationPass);
Vladimir Markoad677272015-04-20 10:48:13 +010050 pass_manager->AddPass(new GlobalValueNumberingCleanupPass);
Mathieu Chartier5bdab122015-01-26 18:30:19 -080051 pass_manager->AddPass(new ConstantPropagation);
52 pass_manager->AddPass(new MethodUseCount);
53 pass_manager->AddPass(new BBOptimizations);
54 pass_manager->AddPass(new SuspendCheckElimination);
55}
Razvan A Lupusorubd25d4b2014-07-02 18:16:51 -070056
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070057void PassDriverMEOpts::ApplyPass(PassDataHolder* data, const Pass* pass) {
Mathieu Chartier5bdab122015-01-26 18:30:19 -080058 const PassME* const pass_me = down_cast<const PassME*>(pass);
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070059 DCHECK(pass_me != nullptr);
Mathieu Chartier5bdab122015-01-26 18:30:19 -080060 PassMEDataHolder* const pass_me_data_holder = down_cast<PassMEDataHolder*>(data);
Jean Christophe Beyler09321df2014-07-18 15:33:57 -070061 // Set to dirty.
62 pass_me_data_holder->dirty = true;
Jean Christophe Beyler09321df2014-07-18 15:33:57 -070063 // First call the base class' version.
64 PassDriver::ApplyPass(data, pass);
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070065 // Now we care about flags.
66 if ((pass_me->GetFlag(kOptimizationBasicBlockChange) == true) ||
67 (pass_me->GetFlag(kOptimizationDefUsesChange) == true)) {
Jean Christophe Beyler09321df2014-07-18 15:33:57 -070068 // Is it dirty at least?
69 if (pass_me_data_holder->dirty == true) {
Jean Christophe Beylerfbebc692014-09-02 14:22:17 -070070 CompilationUnit* c_unit = pass_me_data_holder->c_unit;
Nicolas Geoffray216eaa22015-03-17 17:09:30 +000071 c_unit->mir_graph.get()->CalculateBasicBlockInformation(post_opt_pass_manager_);
Jean Christophe Beyler09321df2014-07-18 15:33:57 -070072 }
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070073 }
74}
75
76} // namespace art