diff options
author | 2015-01-16 16:04:43 +0000 | |
---|---|---|
committer | 2015-01-16 19:38:01 +0000 | |
commit | 066f9e4b87d875f02a10fd43d8a251b3c17a64a3 (patch) | |
tree | 357dbd03b2ff2893469bc2dc7a8d0b658a699245 | |
parent | d16d76ac64b1b9ed17e9cc17a6afb85f16ce4b51 (diff) |
Quick: Clean up optimization pass order.
Move the TypeInference pass to post-opt passes and make it
a PassMEMirSsaRep as we need to rerun the pass if the SSA
representation has changed. (Though we currently don't have
any pass that would require it.)
The results of MethodUseCount and ConstantPropagation passes
are used only in the BBOptimization and codegen and stay
valid across BBOptimization and SuspendCheckElimination, so
move them out of post-opt passes to just before the BBOpt
(and reverse the dependency between ConstantPropagation and
init reg locations passes).
Change-Id: If02c087107cef48d5f9f7c18b0a0ace370fe2647
-rw-r--r-- | compiler/dex/bb_optimizations.cc | 28 | ||||
-rw-r--r-- | compiler/dex/bb_optimizations.h | 63 | ||||
-rw-r--r-- | compiler/dex/mir_optimization.cc | 3 | ||||
-rw-r--r-- | compiler/dex/pass_driver_me_opts.cc | 3 | ||||
-rw-r--r-- | compiler/dex/pass_driver_me_post_opt.cc | 3 | ||||
-rw-r--r-- | compiler/dex/post_opt_passes.cc | 29 | ||||
-rw-r--r-- | compiler/dex/post_opt_passes.h | 38 | ||||
-rw-r--r-- | compiler/dex/vreg_analysis.cc | 2 |
8 files changed, 85 insertions, 84 deletions
diff --git a/compiler/dex/bb_optimizations.cc b/compiler/dex/bb_optimizations.cc index e5358139d8..11a7e44f98 100644 --- a/compiler/dex/bb_optimizations.cc +++ b/compiler/dex/bb_optimizations.cc @@ -51,4 +51,32 @@ bool BBCombine::Worker(PassDataHolder* data) const { return false; } +/* + * MethodUseCount pass implementation start. + */ +bool MethodUseCount::Gate(const PassDataHolder* data) const { + DCHECK(data != nullptr); + CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; + DCHECK(c_unit != nullptr); + // First initialize the data. + c_unit->mir_graph->InitializeMethodUses(); + + // Now check if the pass is to be ignored. + bool res = ((c_unit->disable_opt & (1 << kPromoteRegs)) == 0); + + return res; +} + +bool MethodUseCount::Worker(PassDataHolder* data) const { + DCHECK(data != nullptr); + PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data); + CompilationUnit* c_unit = pass_me_data_holder->c_unit; + DCHECK(c_unit != nullptr); + BasicBlock* bb = pass_me_data_holder->bb; + DCHECK(bb != nullptr); + c_unit->mir_graph->CountUses(bb); + // No need of repeating, so just return false. + return false; +} + } // namespace art diff --git a/compiler/dex/bb_optimizations.h b/compiler/dex/bb_optimizations.h index b07a415d4a..aac2644e9b 100644 --- a/compiler/dex/bb_optimizations.h +++ b/compiler/dex/bb_optimizations.h @@ -171,27 +171,6 @@ class NullCheckElimination : public PassME { } }; -/** - * @class TypeInference - * @brief Type inference pass. - */ -class TypeInference : public PassME { - public: - TypeInference() - : PassME("TypeInference", kRepeatingPreOrderDFSTraversal, "4_post_type_cfg") { - } - - bool Worker(PassDataHolder* data) const { - DCHECK(data != nullptr); - PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data); - CompilationUnit* c_unit = pass_me_data_holder->c_unit; - DCHECK(c_unit != nullptr); - BasicBlock* bb = pass_me_data_holder->bb; - DCHECK(bb != nullptr); - return c_unit->mir_graph->InferTypes(bb); - } -}; - class ClassInitCheckElimination : public PassME { public: ClassInitCheckElimination() @@ -279,6 +258,48 @@ class BBCombine : public PassME { }; /** + * @class ConstantPropagation + * @brief Perform a constant propagation pass. + */ +class ConstantPropagation : public PassME { + public: + ConstantPropagation() : PassME("ConstantPropagation") { + } + + void Start(PassDataHolder* data) const { + DCHECK(data != nullptr); + CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; + DCHECK(c_unit != nullptr); + c_unit->mir_graph->InitializeConstantPropagation(); + } + + bool Worker(PassDataHolder* data) const { + DCHECK(data != nullptr); + CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; + DCHECK(c_unit != nullptr); + BasicBlock* bb = down_cast<PassMEDataHolder*>(data)->bb; + DCHECK(bb != nullptr); + c_unit->mir_graph->DoConstantPropagation(bb); + // No need of repeating, so just return false. + return false; + } +}; + +/** + * @class MethodUseCount + * @brief Count the register uses of the method + */ +class MethodUseCount : public PassME { + public: + MethodUseCount() : PassME("UseCount") { + } + + bool Worker(PassDataHolder* data) const; + + bool Gate(const PassDataHolder* data) const; +}; + +/** * @class BasicBlock Optimizations * @brief Any simple BasicBlock optimization can be put here. */ diff --git a/compiler/dex/mir_optimization.cc b/compiler/dex/mir_optimization.cc index 15b83413b7..ebbd28f6c4 100644 --- a/compiler/dex/mir_optimization.cc +++ b/compiler/dex/mir_optimization.cc @@ -35,6 +35,7 @@ static unsigned int Predecessors(BasicBlock* bb) { void MIRGraph::SetConstant(int32_t ssa_reg, int32_t value) { is_constant_v_->SetBit(ssa_reg); constant_values_[ssa_reg] = value; + reg_location_[ssa_reg].is_const = true; } void MIRGraph::SetConstantWide(int32_t ssa_reg, int64_t value) { @@ -42,6 +43,8 @@ void MIRGraph::SetConstantWide(int32_t ssa_reg, int64_t value) { is_constant_v_->SetBit(ssa_reg + 1); constant_values_[ssa_reg] = Low32Bits(value); constant_values_[ssa_reg + 1] = High32Bits(value); + reg_location_[ssa_reg].is_const = true; + reg_location_[ssa_reg + 1].is_const = true; } void MIRGraph::DoConstantPropagation(BasicBlock* bb) { diff --git a/compiler/dex/pass_driver_me_opts.cc b/compiler/dex/pass_driver_me_opts.cc index c476b2aabc..6bb94c3c0e 100644 --- a/compiler/dex/pass_driver_me_opts.cc +++ b/compiler/dex/pass_driver_me_opts.cc @@ -43,8 +43,9 @@ const Pass* const PassDriver<PassDriverMEOpts>::g_passes[] = { GetPassInstance<NullCheckElimination>(), GetPassInstance<BBCombine>(), GetPassInstance<CodeLayout>(), - GetPassInstance<TypeInference>(), GetPassInstance<GlobalValueNumberingPass>(), + GetPassInstance<ConstantPropagation>(), + GetPassInstance<MethodUseCount>(), GetPassInstance<BBOptimizations>(), GetPassInstance<SuspendCheckElimination>(), }; diff --git a/compiler/dex/pass_driver_me_post_opt.cc b/compiler/dex/pass_driver_me_post_opt.cc index 9b56c0da87..5e2140d393 100644 --- a/compiler/dex/pass_driver_me_post_opt.cc +++ b/compiler/dex/pass_driver_me_post_opt.cc @@ -40,9 +40,8 @@ const Pass* const PassDriver<PassDriverMEPostOpt>::g_passes[] = { GetPassInstance<CreatePhiNodes>(), GetPassInstance<SSAConversion>(), GetPassInstance<PhiNodeOperands>(), - GetPassInstance<ConstantPropagation>(), GetPassInstance<PerformInitRegLocations>(), - GetPassInstance<MethodUseCount>(), + GetPassInstance<TypeInference>(), GetPassInstance<FinishSSATransformation>(), }; diff --git a/compiler/dex/post_opt_passes.cc b/compiler/dex/post_opt_passes.cc index 675dbcf91d..92078b471b 100644 --- a/compiler/dex/post_opt_passes.cc +++ b/compiler/dex/post_opt_passes.cc @@ -20,35 +20,6 @@ namespace art { -/* - * MethodUseCount pass implementation start. - */ -bool MethodUseCount::Gate(const PassDataHolder* data) const { - DCHECK(data != nullptr); - CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; - DCHECK(c_unit != nullptr); - // First initialize the data. - c_unit->mir_graph->InitializeMethodUses(); - - // Now check if the pass is to be ignored. - bool res = ((c_unit->disable_opt & (1 << kPromoteRegs)) == 0); - - return res; -} - -bool MethodUseCount::Worker(PassDataHolder* data) const { - DCHECK(data != nullptr); - PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data); - CompilationUnit* c_unit = pass_me_data_holder->c_unit; - DCHECK(c_unit != nullptr); - BasicBlock* bb = pass_me_data_holder->bb; - DCHECK(bb != nullptr); - c_unit->mir_graph->CountUses(bb); - // No need of repeating, so just return false. - return false; -} - - bool ClearPhiInstructions::Worker(PassDataHolder* data) const { DCHECK(data != nullptr); PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data); diff --git a/compiler/dex/post_opt_passes.h b/compiler/dex/post_opt_passes.h index 964355bb5d..55ae874451 100644 --- a/compiler/dex/post_opt_passes.h +++ b/compiler/dex/post_opt_passes.h @@ -63,20 +63,6 @@ class InitializeSSATransformation : public PassMEMirSsaRep { }; /** - * @class MethodUseCount - * @brief Count the register uses of the method - */ -class MethodUseCount : public PassME { - public: - MethodUseCount() : PassME("UseCount") { - } - - bool Worker(PassDataHolder* data) const; - - bool Gate(const PassDataHolder* data) const; -}; - -/** * @class ClearPhiInformation * @brief Clear the PHI nodes from the CFG. */ @@ -274,30 +260,22 @@ class PerformInitRegLocations : public PassMEMirSsaRep { }; /** - * @class ConstantPropagation - * @brief Perform a constant propagation pass. + * @class TypeInference + * @brief Type inference pass. */ -class ConstantPropagation : public PassMEMirSsaRep { +class TypeInference : public PassMEMirSsaRep { public: - ConstantPropagation() : PassMEMirSsaRep("ConstantPropagation") { + TypeInference() : PassMEMirSsaRep("TypeInference", kRepeatingPreOrderDFSTraversal) { } bool Worker(PassDataHolder* data) const { DCHECK(data != nullptr); - CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; + PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data); + CompilationUnit* c_unit = pass_me_data_holder->c_unit; DCHECK(c_unit != nullptr); - BasicBlock* bb = down_cast<PassMEDataHolder*>(data)->bb; + BasicBlock* bb = pass_me_data_holder->bb; DCHECK(bb != nullptr); - c_unit->mir_graph->DoConstantPropagation(bb); - // No need of repeating, so just return false. - return false; - } - - void Start(PassDataHolder* data) const { - DCHECK(data != nullptr); - CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; - DCHECK(c_unit != nullptr); - c_unit->mir_graph->InitializeConstantPropagation(); + return c_unit->mir_graph->InferTypes(bb); } }; diff --git a/compiler/dex/vreg_analysis.cc b/compiler/dex/vreg_analysis.cc index a541c7d7a7..62c40892cf 100644 --- a/compiler/dex/vreg_analysis.cc +++ b/compiler/dex/vreg_analysis.cc @@ -442,7 +442,7 @@ void MIRGraph::InitRegLocations() { for (int i = 0; i < GetNumSSARegs(); i++) { loc[i] = fresh_loc; loc[i].s_reg_low = i; - loc[i].is_const = is_constant_v_->IsBitSet(i); + loc[i].is_const = false; // Constants will be marked by constant propagation pass later. loc[i].wide = false; } |