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 | */ |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 26 | bool CodeLayout::WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 27 | cUnit->mir_graph->LayoutBlocks(bb); |
| 28 | // No need of repeating, so just return false. |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | /* |
| 33 | * SSATransformation pass implementation start. |
| 34 | */ |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 35 | bool SSATransformation::WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 36 | cUnit->mir_graph->InsertPhiNodeOperands(bb); |
| 37 | // No need of repeating, so just return false. |
| 38 | return false; |
| 39 | } |
| 40 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 41 | void SSATransformation::End(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 42 | // Verify the dataflow information after the pass. |
| 43 | if (cUnit->enable_debug & (1 << kDebugVerifyDataflow)) { |
| 44 | cUnit->mir_graph->VerifyDataflow(); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /* |
| 49 | * ConstantPropagation pass implementation start |
| 50 | */ |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 51 | bool ConstantPropagation::WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 52 | cUnit->mir_graph->DoConstantPropagation(bb); |
| 53 | // No need of repeating, so just return false. |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * MethodUseCount pass implementation start. |
| 59 | */ |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 60 | bool MethodUseCount::Gate(const CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 61 | // First initialize the data. |
| 62 | cUnit->mir_graph->InitializeMethodUses(); |
| 63 | |
| 64 | // Now check if the pass is to be ignored. |
| 65 | bool res = ((cUnit->disable_opt & (1 << kPromoteRegs)) == 0); |
| 66 | |
| 67 | return res; |
| 68 | } |
| 69 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 70 | bool MethodUseCount::WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 71 | cUnit->mir_graph->CountUses(bb); |
| 72 | // No need of repeating, so just return false. |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * Null Check Elimination and Type Inference Initialization pass implementation start. |
| 78 | */ |
| 79 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 80 | bool NullCheckEliminationAndTypeInferenceInit::Gate(const CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 81 | // First check the ssa register vector |
| 82 | cUnit->mir_graph->CheckSSARegisterVector(); |
| 83 | |
| 84 | // Did we disable the pass? |
| 85 | bool performInit = ((cUnit->disable_opt & (1 << kNullCheckElimination)) == 0); |
| 86 | |
| 87 | return performInit; |
| 88 | } |
| 89 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 90 | bool NullCheckEliminationAndTypeInferenceInit::WalkBasicBlocks(CompilationUnit* cUnit, |
| 91 | BasicBlock* bb) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 92 | cUnit->mir_graph->NullCheckEliminationInit(bb); |
| 93 | // No need of repeating, so just return false. |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * BasicBlock Combine pass implementation start. |
| 99 | */ |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 100 | bool BBCombine::WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 101 | cUnit->mir_graph->CombineBlocks(bb); |
| 102 | |
| 103 | // No need of repeating, so just return false. |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * BasicBlock Optimization pass implementation start. |
| 109 | */ |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 110 | void BBOptimizations::Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 111 | /* |
| 112 | * This pass has a different ordering depEnding on the suppress exception, |
| 113 | * so do the pass here for now: |
| 114 | * - Later, the Start should just change the ordering and we can move the extended |
| 115 | * creation into the pass driver's main job with a new iterator |
| 116 | */ |
| 117 | cUnit->mir_graph->BasicBlockOptimization(); |
| 118 | } |
| 119 | |
| 120 | } // namespace art |