blob: 8b5eba0f67802117fa89f78b058fe454bf49f438 [file] [log] [blame]
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -08001/*
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
21namespace art {
22
23/*
24 * Code Layout pass implementation start.
25 */
James C Scott4f596682014-05-01 05:52:04 -070026bool 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 Beyler4e97c532014-01-07 10:07:18 -080033 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 */
Vladimir Markoa5b8fde2014-05-23 15:16:44 +010041void SSATransformation::Start(const PassDataHolder* data) const {
42 DCHECK(data != nullptr);
43 CompilationUnit* cUnit = down_cast<const PassMEDataHolder*>(data)->c_unit;
44 DCHECK(cUnit != nullptr);
45 cUnit->mir_graph->SSATransformationStart();
46}
47
James C Scott4f596682014-05-01 05:52:04 -070048bool SSATransformation::Worker(const PassDataHolder* data) const {
49 DCHECK(data != nullptr);
50 const PassMEDataHolder* pass_me_data_holder = down_cast<const PassMEDataHolder*>(data);
51 CompilationUnit* cUnit = pass_me_data_holder->c_unit;
52 DCHECK(cUnit != nullptr);
53 BasicBlock* bb = pass_me_data_holder->bb;
54 DCHECK(bb != nullptr);
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080055 cUnit->mir_graph->InsertPhiNodeOperands(bb);
56 // No need of repeating, so just return false.
57 return false;
58}
59
James C Scott4f596682014-05-01 05:52:04 -070060void SSATransformation::End(const PassDataHolder* data) const {
61 DCHECK(data != nullptr);
62 CompilationUnit* cUnit = down_cast<const PassMEDataHolder*>(data)->c_unit;
63 DCHECK(cUnit != nullptr);
Vladimir Markoa5b8fde2014-05-23 15:16:44 +010064 cUnit->mir_graph->SSATransformationEnd();
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080065}
66
67/*
68 * ConstantPropagation pass implementation start
69 */
James C Scott4f596682014-05-01 05:52:04 -070070bool ConstantPropagation::Worker(const PassDataHolder* data) const {
71 DCHECK(data != nullptr);
72 const PassMEDataHolder* pass_me_data_holder = down_cast<const PassMEDataHolder*>(data);
73 CompilationUnit* cUnit = pass_me_data_holder->c_unit;
74 DCHECK(cUnit != nullptr);
75 BasicBlock* bb = pass_me_data_holder->bb;
76 DCHECK(bb != nullptr);
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080077 cUnit->mir_graph->DoConstantPropagation(bb);
78 // No need of repeating, so just return false.
79 return false;
80}
81
82/*
83 * MethodUseCount pass implementation start.
84 */
James C Scott4f596682014-05-01 05:52:04 -070085bool MethodUseCount::Gate(const PassDataHolder* data) const {
86 DCHECK(data != nullptr);
87 CompilationUnit* cUnit = down_cast<const PassMEDataHolder*>(data)->c_unit;
88 DCHECK(cUnit != nullptr);
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080089 // First initialize the data.
90 cUnit->mir_graph->InitializeMethodUses();
91
92 // Now check if the pass is to be ignored.
93 bool res = ((cUnit->disable_opt & (1 << kPromoteRegs)) == 0);
94
95 return res;
96}
97
James C Scott4f596682014-05-01 05:52:04 -070098bool MethodUseCount::Worker(const PassDataHolder* data) const {
99 DCHECK(data != nullptr);
100 const PassMEDataHolder* pass_me_data_holder = down_cast<const PassMEDataHolder*>(data);
101 CompilationUnit* cUnit = pass_me_data_holder->c_unit;
102 DCHECK(cUnit != nullptr);
103 BasicBlock* bb = pass_me_data_holder->bb;
104 DCHECK(bb != nullptr);
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800105 cUnit->mir_graph->CountUses(bb);
106 // No need of repeating, so just return false.
107 return false;
108}
109
110/*
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800111 * BasicBlock Combine pass implementation start.
112 */
James C Scott4f596682014-05-01 05:52:04 -0700113bool BBCombine::Worker(const PassDataHolder* data) const {
114 DCHECK(data != nullptr);
115 const PassMEDataHolder* pass_me_data_holder = down_cast<const PassMEDataHolder*>(data);
116 CompilationUnit* cUnit = pass_me_data_holder->c_unit;
117 DCHECK(cUnit != nullptr);
118 BasicBlock* bb = pass_me_data_holder->bb;
119 DCHECK(bb != nullptr);
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800120 cUnit->mir_graph->CombineBlocks(bb);
121
122 // No need of repeating, so just return false.
123 return false;
124}
125
126/*
127 * BasicBlock Optimization pass implementation start.
128 */
James C Scott4f596682014-05-01 05:52:04 -0700129void BBOptimizations::Start(const PassDataHolder* data) const {
130 DCHECK(data != nullptr);
131 CompilationUnit* cUnit = down_cast<const PassMEDataHolder*>(data)->c_unit;
132 DCHECK(cUnit != nullptr);
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800133 /*
134 * This pass has a different ordering depEnding on the suppress exception,
135 * so do the pass here for now:
136 * - Later, the Start should just change the ordering and we can move the extended
137 * creation into the pass driver's main job with a new iterator
138 */
139 cUnit->mir_graph->BasicBlockOptimization();
140}
141
142} // namespace art