Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | #include "base/macros.h" |
| 18 | #include "bb_optimizations.h" |
| 19 | #include "compiler_internals.h" |
| 20 | #include "dataflow_iterator.h" |
| 21 | #include "dataflow_iterator-inl.h" |
| 22 | #include "pass_driver_me_opts.h" |
Vladimir Marko | 7baa6f8 | 2014-10-09 18:01:24 +0100 | [diff] [blame] | 23 | #include "post_opt_passes.h" |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | /* |
| 28 | * Create the pass list. These passes are immutable and are shared across the threads. |
| 29 | * |
| 30 | * Advantage is that there will be no race conditions here. |
| 31 | * Disadvantage is the passes can't change their internal states depending on CompilationUnit: |
| 32 | * - This is not yet an issue: no current pass would require it. |
| 33 | */ |
| 34 | // The initial list of passes to be used by the PassDriveMEOpts. |
| 35 | template<> |
| 36 | const Pass* const PassDriver<PassDriverMEOpts>::g_passes[] = { |
| 37 | GetPassInstance<CacheFieldLoweringInfo>(), |
| 38 | GetPassInstance<CacheMethodLoweringInfo>(), |
Vladimir Marko | 7baa6f8 | 2014-10-09 18:01:24 +0100 | [diff] [blame] | 39 | GetPassInstance<CalculatePredecessors>(), |
| 40 | GetPassInstance<DFSOrders>(), |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 41 | GetPassInstance<ClassInitCheckElimination>(), |
Vladimir Marko | 7baa6f8 | 2014-10-09 18:01:24 +0100 | [diff] [blame] | 42 | GetPassInstance<SpecialMethodInliner>(), |
| 43 | GetPassInstance<NullCheckElimination>(), |
Vladimir Marko | 312eb25 | 2014-10-07 15:01:57 +0100 | [diff] [blame] | 44 | GetPassInstance<BBCombine>(), |
Vladimir Marko | 7baa6f8 | 2014-10-09 18:01:24 +0100 | [diff] [blame] | 45 | GetPassInstance<CodeLayout>(), |
| 46 | GetPassInstance<TypeInference>(), |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 47 | GetPassInstance<GlobalValueNumberingPass>(), |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 48 | GetPassInstance<BBOptimizations>(), |
| 49 | }; |
| 50 | |
| 51 | // The number of the passes in the initial list of Passes (g_passes). |
| 52 | template<> |
| 53 | uint16_t const PassDriver<PassDriverMEOpts>::g_passes_size = |
| 54 | arraysize(PassDriver<PassDriverMEOpts>::g_passes); |
| 55 | |
| 56 | // The default pass list is used by the PassDriverME instance of PassDriver |
| 57 | // to initialize pass_list_. |
| 58 | template<> |
| 59 | std::vector<const Pass*> PassDriver<PassDriverMEOpts>::g_default_pass_list( |
| 60 | PassDriver<PassDriverMEOpts>::g_passes, |
| 61 | PassDriver<PassDriverMEOpts>::g_passes + |
| 62 | PassDriver<PassDriverMEOpts>::g_passes_size); |
| 63 | |
| 64 | // By default, do not have a dump pass list. |
| 65 | template<> |
| 66 | std::string PassDriver<PassDriverMEOpts>::dump_pass_list_ = std::string(); |
| 67 | |
| 68 | // By default, do not have a print pass list. |
| 69 | template<> |
| 70 | std::string PassDriver<PassDriverMEOpts>::print_pass_list_ = std::string(); |
| 71 | |
| 72 | // By default, we do not print the pass' information. |
| 73 | template<> |
| 74 | bool PassDriver<PassDriverMEOpts>::default_print_passes_ = false; |
| 75 | |
Razvan A Lupusoru | bd25d4b | 2014-07-02 18:16:51 -0700 | [diff] [blame] | 76 | // By default, there are no overridden pass settings. |
| 77 | template<> |
| 78 | std::string PassDriver<PassDriverMEOpts>::overridden_pass_options_list_ = std::string(); |
| 79 | |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 80 | void PassDriverMEOpts::ApplyPass(PassDataHolder* data, const Pass* pass) { |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 81 | const PassME* pass_me = down_cast<const PassME*> (pass); |
| 82 | DCHECK(pass_me != nullptr); |
| 83 | |
| 84 | PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data); |
| 85 | |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 86 | // Set to dirty. |
| 87 | pass_me_data_holder->dirty = true; |
| 88 | |
| 89 | // First call the base class' version. |
| 90 | PassDriver::ApplyPass(data, pass); |
| 91 | |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 92 | // Now we care about flags. |
| 93 | if ((pass_me->GetFlag(kOptimizationBasicBlockChange) == true) || |
| 94 | (pass_me->GetFlag(kOptimizationDefUsesChange) == true)) { |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 95 | // Is it dirty at least? |
| 96 | if (pass_me_data_holder->dirty == true) { |
Jean Christophe Beyler | fbebc69 | 2014-09-02 14:22:17 -0700 | [diff] [blame] | 97 | CompilationUnit* c_unit = pass_me_data_holder->c_unit; |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 98 | c_unit->mir_graph.get()->CalculateBasicBlockInformation(); |
| 99 | } |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
| 103 | } // namespace art |