Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [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 "bb_optimizations.h" |
| 18 | #include "dataflow_iterator.h" |
| 19 | #include "dataflow_iterator-inl.h" |
| 20 | |
| 21 | namespace art { |
| 22 | |
| 23 | /* |
| 24 | * Code Layout pass implementation start. |
| 25 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame^] | 26 | bool CodeLayout::Worker(const PassDataHolder* data) const { |
| 27 | DCHECK(data != nullptr); |
| 28 | const PassMEDataHolder* pass_me_data_holder = down_cast<const PassMEDataHolder*>(data); |
| 29 | CompilationUnit* cUnit = pass_me_data_holder->c_unit; |
| 30 | DCHECK(cUnit != nullptr); |
| 31 | BasicBlock* bb = pass_me_data_holder->bb; |
| 32 | DCHECK(bb != nullptr); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 33 | cUnit->mir_graph->LayoutBlocks(bb); |
| 34 | // No need of repeating, so just return false. |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | /* |
| 39 | * SSATransformation pass implementation start. |
| 40 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame^] | 41 | bool SSATransformation::Worker(const PassDataHolder* data) const { |
| 42 | DCHECK(data != nullptr); |
| 43 | const PassMEDataHolder* pass_me_data_holder = down_cast<const PassMEDataHolder*>(data); |
| 44 | CompilationUnit* cUnit = pass_me_data_holder->c_unit; |
| 45 | DCHECK(cUnit != nullptr); |
| 46 | BasicBlock* bb = pass_me_data_holder->bb; |
| 47 | DCHECK(bb != nullptr); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 48 | cUnit->mir_graph->InsertPhiNodeOperands(bb); |
| 49 | // No need of repeating, so just return false. |
| 50 | return false; |
| 51 | } |
| 52 | |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame^] | 53 | void SSATransformation::End(const PassDataHolder* data) const { |
| 54 | DCHECK(data != nullptr); |
| 55 | CompilationUnit* cUnit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 56 | DCHECK(cUnit != nullptr); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 57 | // Verify the dataflow information after the pass. |
| 58 | if (cUnit->enable_debug & (1 << kDebugVerifyDataflow)) { |
| 59 | cUnit->mir_graph->VerifyDataflow(); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * ConstantPropagation pass implementation start |
| 65 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame^] | 66 | bool ConstantPropagation::Worker(const PassDataHolder* data) const { |
| 67 | DCHECK(data != nullptr); |
| 68 | const PassMEDataHolder* pass_me_data_holder = down_cast<const PassMEDataHolder*>(data); |
| 69 | CompilationUnit* cUnit = pass_me_data_holder->c_unit; |
| 70 | DCHECK(cUnit != nullptr); |
| 71 | BasicBlock* bb = pass_me_data_holder->bb; |
| 72 | DCHECK(bb != nullptr); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 73 | cUnit->mir_graph->DoConstantPropagation(bb); |
| 74 | // No need of repeating, so just return false. |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * MethodUseCount pass implementation start. |
| 80 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame^] | 81 | bool MethodUseCount::Gate(const PassDataHolder* data) const { |
| 82 | DCHECK(data != nullptr); |
| 83 | CompilationUnit* cUnit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 84 | DCHECK(cUnit != nullptr); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 85 | // First initialize the data. |
| 86 | cUnit->mir_graph->InitializeMethodUses(); |
| 87 | |
| 88 | // Now check if the pass is to be ignored. |
| 89 | bool res = ((cUnit->disable_opt & (1 << kPromoteRegs)) == 0); |
| 90 | |
| 91 | return res; |
| 92 | } |
| 93 | |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame^] | 94 | bool MethodUseCount::Worker(const PassDataHolder* data) const { |
| 95 | DCHECK(data != nullptr); |
| 96 | const PassMEDataHolder* pass_me_data_holder = down_cast<const PassMEDataHolder*>(data); |
| 97 | CompilationUnit* cUnit = pass_me_data_holder->c_unit; |
| 98 | DCHECK(cUnit != nullptr); |
| 99 | BasicBlock* bb = pass_me_data_holder->bb; |
| 100 | DCHECK(bb != nullptr); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 101 | cUnit->mir_graph->CountUses(bb); |
| 102 | // No need of repeating, so just return false. |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | /* |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 107 | * BasicBlock Combine pass implementation start. |
| 108 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame^] | 109 | bool BBCombine::Worker(const PassDataHolder* data) const { |
| 110 | DCHECK(data != nullptr); |
| 111 | const PassMEDataHolder* pass_me_data_holder = down_cast<const PassMEDataHolder*>(data); |
| 112 | CompilationUnit* cUnit = pass_me_data_holder->c_unit; |
| 113 | DCHECK(cUnit != nullptr); |
| 114 | BasicBlock* bb = pass_me_data_holder->bb; |
| 115 | DCHECK(bb != nullptr); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 116 | cUnit->mir_graph->CombineBlocks(bb); |
| 117 | |
| 118 | // No need of repeating, so just return false. |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * BasicBlock Optimization pass implementation start. |
| 124 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame^] | 125 | void BBOptimizations::Start(const PassDataHolder* data) const { |
| 126 | DCHECK(data != nullptr); |
| 127 | CompilationUnit* cUnit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 128 | DCHECK(cUnit != nullptr); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 129 | /* |
| 130 | * This pass has a different ordering depEnding on the suppress exception, |
| 131 | * so do the pass here for now: |
| 132 | * - Later, the Start should just change the ordering and we can move the extended |
| 133 | * creation into the pass driver's main job with a new iterator |
| 134 | */ |
| 135 | cUnit->mir_graph->BasicBlockOptimization(); |
| 136 | } |
| 137 | |
| 138 | } // namespace art |