blob: 9262440ae2e3efd9a8d1e74bac3cdc261254a2f2 [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
17#include "post_opt_passes.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080018
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070019#include "dataflow_iterator-inl.h"
20
21namespace art {
22
Jean Christophe Beyler09321df2014-07-18 15:33:57 -070023bool ClearPhiInstructions::Worker(PassDataHolder* data) const {
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070024 DCHECK(data != nullptr);
Jean Christophe Beyler09321df2014-07-18 15:33:57 -070025 PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data);
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070026 CompilationUnit* c_unit = pass_me_data_holder->c_unit;
27 DCHECK(c_unit != nullptr);
28 BasicBlock* bb = pass_me_data_holder->bb;
29 DCHECK(bb != nullptr);
30 MIR* mir = bb->first_mir_insn;
31
32 while (mir != nullptr) {
33 MIR* next = mir->next;
34
35 Instruction::Code opcode = mir->dalvikInsn.opcode;
36
37 if (opcode == static_cast<Instruction::Code> (kMirOpPhi)) {
38 bb->RemoveMIR(mir);
39 }
40
41 mir = next;
42 }
43
44 // We do not care in reporting a change or not in the MIR.
45 return false;
46}
47
Jean Christophe Beylere1f65bc2014-06-09 10:18:26 -070048void CalculatePredecessors::Start(PassDataHolder* data) const {
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070049 DCHECK(data != nullptr);
Jean Christophe Beylere1f65bc2014-06-09 10:18:26 -070050 CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit;
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070051 DCHECK(c_unit != nullptr);
52 // First get the MIRGraph here to factorize a bit the code.
53 MIRGraph *mir_graph = c_unit->mir_graph.get();
54
55 // First clear all predecessors.
56 AllNodesIterator first(mir_graph);
57 for (BasicBlock* bb = first.Next(); bb != nullptr; bb = first.Next()) {
Vladimir Markoe39c54e2014-09-22 14:50:02 +010058 bb->predecessors.clear();
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070059 }
60
61 // Now calculate all predecessors.
62 AllNodesIterator second(mir_graph);
63 for (BasicBlock* bb = second.Next(); bb != nullptr; bb = second.Next()) {
64 // We only care about non hidden blocks.
65 if (bb->hidden == true) {
66 continue;
67 }
68
69 // Create iterator for visiting children.
70 ChildBlockIterator child_iter(bb, mir_graph);
71
72 // Now iterate through the children to set the predecessor bits.
73 for (BasicBlock* child = child_iter.Next(); child != nullptr; child = child_iter.Next()) {
Vladimir Markoe39c54e2014-09-22 14:50:02 +010074 child->predecessors.push_back(bb->id);
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070075 }
76 }
77}
78
79} // namespace art