diff --git a/opt/constant-propagation/ConstantPropagationPass.cpp b/opt/constant-propagation/ConstantPropagationPass.cpp index 56a8746cc80..6f33c31e98e 100644 --- a/opt/constant-propagation/ConstantPropagationPass.cpp +++ b/opt/constant-propagation/ConstantPropagationPass.cpp @@ -9,6 +9,7 @@ #include "ConstantPropagation.h" #include "PassManager.h" +#include "Purity.h" #include "ScopedMetrics.h" #include "Trace.h" #include "Walkers.h" @@ -21,7 +22,12 @@ void ConstantPropagationPass::run_pass(DexStoresVector& stores, auto scope = build_class_scope(stores); XStoreRefs xstores(stores); - ConstantPropagation impl(m_config); + const auto& pure_methods = ::get_pure_methods(); + auto config = m_config; + config.transform.pure_methods = &pure_methods; + auto min_sdk = mgr.get_redex_options().min_sdk; + constant_propagation::ImmutableAttributeAnalyzerState immut_analyzer_state; + ConstantPropagation impl(config, min_sdk, &immut_analyzer_state); auto stats = impl.run(scope, &xstores); ScopedMetrics sm(mgr); diff --git a/service/constant-propagation/ConstantPropagation.cpp b/service/constant-propagation/ConstantPropagation.cpp index c78a7e1e751..3f1625fb978 100644 --- a/service/constant-propagation/ConstantPropagation.cpp +++ b/service/constant-propagation/ConstantPropagation.cpp @@ -30,8 +30,14 @@ Transform::Stats ConstantPropagation::run( TRACE(CONSTP, 5, "CFG: %s", SHOW(*cfg)); Transform::Stats local_stats; { - intraprocedural::FixpointIterator fp_iter(*cfg, - ConstantPrimitiveAnalyzer()); + intraprocedural::FixpointIterator fp_iter( + *cfg, + ConstantPrimitiveAndBoxedAnalyzer( + m_immut_analyzer_state, m_immut_analyzer_state, + constant_propagation::EnumFieldAnalyzerState::get(), + constant_propagation::BoxedBooleanAnalyzerState::get(), nullptr, + constant_propagation::ApiLevelAnalyzerState::get(m_min_sdk), + nullptr)); fp_iter.run({}); constant_propagation::Transform tf(m_config.transform, &runtime_cache); tf.apply(fp_iter, WholeProgramState(), code->cfg(), xstores, @@ -49,6 +55,7 @@ Transform::Stats ConstantPropagation::run(DexMethod* method, Transform::Stats ConstantPropagation::run(const Scope& scope, XStoreRefs* xstores) { Transform::RuntimeCache runtime_cache{}; + constant_propagation::ImmutableAttributeAnalyzerState immut_analyzer_state; return walk::parallel::methods( scope, [&](DexMethod* method) { return run(method, xstores, runtime_cache); }); diff --git a/service/constant-propagation/ConstantPropagation.h b/service/constant-propagation/ConstantPropagation.h index 5df3f14dc2c..2b66bc6648b 100644 --- a/service/constant-propagation/ConstantPropagation.h +++ b/service/constant-propagation/ConstantPropagation.h @@ -18,7 +18,14 @@ struct Config { class ConstantPropagation final { public: - explicit ConstantPropagation(const Config& config) : m_config(config) {} + explicit ConstantPropagation( + const Config& config, + int min_sdk = 0, + constant_propagation::ImmutableAttributeAnalyzerState* + immut_analyzer_state = nullptr) + : m_config(config), + m_min_sdk(min_sdk), + m_immut_analyzer_state(immut_analyzer_state) {} Transform::Stats run(DexMethod* method, XStoreRefs* xstores); Transform::Stats run(DexMethod* method, @@ -28,5 +35,7 @@ class ConstantPropagation final { private: const Config& m_config; + int m_min_sdk; + constant_propagation::ImmutableAttributeAnalyzerState* m_immut_analyzer_state; }; } // namespace constant_propagation