Added pass framework
The patch adds a Middle-End pass system and normalizes the current
passes into the pass framework.
Passes have:
- A start, work, and end functions.
- A gate to determine to apply the pass.
- Can provide a CFG dump folder.
mir_dataflow.cc, mir_graph.cc, mir_optimization.cc, ssa_transformation.cc:
- Changed due to moving code into bb_optimizations.cc.
- Moved certain functions from private to public due to needed from the passes.
pass.cc, pass.h:
- Pass base class
pass_driver.cc, pass_driver.h:
- The pass driver implementation.
frontend.cc:
- Replace the function calls to the passes with the pass driver.
Change-Id: I88cd82efbf6499df9e6c7f135d7e294dd724a079
Signed-off-by: Jean Christophe Beyler <jean.christophe.beyler@intel.com>
diff --git a/compiler/dex/mir_optimization.cc b/compiler/dex/mir_optimization.cc
index 5d83991..ee9f28e 100644
--- a/compiler/dex/mir_optimization.cc
+++ b/compiler/dex/mir_optimization.cc
@@ -36,7 +36,7 @@
constant_values_[ssa_reg + 1] = High32Bits(value);
}
-void MIRGraph::DoConstantPropogation(BasicBlock* bb) {
+void MIRGraph::DoConstantPropagation(BasicBlock* bb) {
MIR* mir;
for (mir = bb->first_mir_insn; mir != NULL; mir = mir->next) {
@@ -92,16 +92,6 @@
/* TODO: implement code to handle arithmetic operations */
}
-void MIRGraph::PropagateConstants() {
- is_constant_v_ = new (arena_) ArenaBitVector(arena_, GetNumSSARegs(), false);
- constant_values_ = static_cast<int*>(arena_->Alloc(sizeof(int) * GetNumSSARegs(),
- ArenaAllocator::kAllocDFInfo));
- AllNodesIterator iter(this);
- for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) {
- DoConstantPropogation(bb);
- }
-}
-
/* Advance to next strictly dominated MIR node in an extended basic block */
MIR* MIRGraph::AdvanceMIR(BasicBlock** p_bb, MIR* mir) {
BasicBlock* bb = *p_bb;
@@ -557,7 +547,7 @@
}
/* Combine any basic blocks terminated by instructions that we now know can't throw */
-bool MIRGraph::CombineBlocks(struct BasicBlock* bb) {
+void MIRGraph::CombineBlocks(struct BasicBlock* bb) {
// Loop here to allow combining a sequence of blocks
while (true) {
// Check termination conditions
@@ -621,14 +611,13 @@
// Now, loop back and see if we can keep going
}
- return false;
}
/*
* Eliminate unnecessary null checks for a basic block. Also, while we're doing
* an iterative walk go ahead and perform type and size inference.
*/
-bool MIRGraph::EliminateNullChecksAndInferTypes(struct BasicBlock* bb) {
+bool MIRGraph::EliminateNullChecksAndInferTypes(BasicBlock* bb) {
if (bb->data_flow_info == NULL) return false;
bool infer_changed = false;
bool do_nce = ((cu_->disable_opt & (1 << kNullCheckElimination)) == 0);
@@ -810,49 +799,6 @@
return infer_changed | nce_changed;
}
-void MIRGraph::NullCheckEliminationAndTypeInference() {
- DCHECK(temp_ssa_register_v_ != NULL);
- if ((cu_->disable_opt & (1 << kNullCheckElimination)) == 0) {
- AllNodesIterator iter(this);
- for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) {
- NullCheckEliminationInit(bb);
- }
- }
- RepeatingPreOrderDfsIterator iter2(this);
- bool change = false;
- for (BasicBlock* bb = iter2.Next(change); bb != NULL; bb = iter2.Next(change)) {
- change = EliminateNullChecksAndInferTypes(bb);
- }
- if (cu_->enable_debug & (1 << kDebugDumpCFG)) {
- DumpCFG("/sdcard/4_post_nce_cfg/", false);
- }
-}
-
-void MIRGraph::BasicBlockCombine() {
- if ((cu_->disable_opt & (1 << kSuppressExceptionEdges)) != 0) {
- PreOrderDfsIterator iter(this);
- for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) {
- CombineBlocks(bb);
- }
- if (cu_->enable_debug & (1 << kDebugDumpCFG)) {
- DumpCFG("/sdcard/5_post_bbcombine_cfg/", false);
- }
- }
-}
-
-void MIRGraph::CodeLayout() {
- if (cu_->enable_debug & (1 << kDebugVerifyDataflow)) {
- VerifyDataflow();
- }
- AllNodesIterator iter(this);
- for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) {
- LayoutBlocks(bb);
- }
- if (cu_->enable_debug & (1 << kDebugDumpCFG)) {
- DumpCFG("/sdcard/2_post_layout_cfg/", true);
- }
-}
-
void MIRGraph::DumpCheckStats() {
Checkstats* stats =
static_cast<Checkstats*>(arena_->Alloc(sizeof(Checkstats), ArenaAllocator::kAllocDFInfo));
@@ -909,29 +855,22 @@
return false; // Not iterative - return value will be ignored
}
-
void MIRGraph::BasicBlockOptimization() {
- if (!(cu_->disable_opt & (1 << kBBOpt))) {
- DCHECK_EQ(cu_->num_compiler_temps, 0);
- if ((cu_->disable_opt & (1 << kSuppressExceptionEdges)) != 0) {
- ClearAllVisitedFlags();
- PreOrderDfsIterator iter2(this);
- for (BasicBlock* bb = iter2.Next(); bb != NULL; bb = iter2.Next()) {
- BuildExtendedBBList(bb);
- }
- // Perform extended basic block optimizations.
- for (unsigned int i = 0; i < extended_basic_blocks_.size(); i++) {
- BasicBlockOpt(GetBasicBlock(extended_basic_blocks_[i]));
- }
- } else {
- PreOrderDfsIterator iter(this);
- for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) {
- BasicBlockOpt(bb);
- }
+ if ((cu_->disable_opt & (1 << kSuppressExceptionEdges)) != 0) {
+ ClearAllVisitedFlags();
+ PreOrderDfsIterator iter2(this);
+ for (BasicBlock* bb = iter2.Next(); bb != NULL; bb = iter2.Next()) {
+ BuildExtendedBBList(bb);
}
- }
- if (cu_->enable_debug & (1 << kDebugDumpCFG)) {
- DumpCFG("/sdcard/6_post_bbo_cfg/", false);
+ // Perform extended basic block optimizations.
+ for (unsigned int i = 0; i < extended_basic_blocks_.size(); i++) {
+ BasicBlockOpt(GetBasicBlock(extended_basic_blocks_[i]));
+ }
+ } else {
+ PreOrderDfsIterator iter(this);
+ for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) {
+ BasicBlockOpt(bb);
+ }
}
}