Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade from ConstantPrimitiveAnalyzer to ConstantPrimitiveAndBoxedAnalyzer #733

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion opt/constant-propagation/ConstantPropagationPass.cpp
Expand Up @@ -9,6 +9,7 @@

#include "ConstantPropagation.h"
#include "PassManager.h"
#include "Purity.h"
#include "ScopedMetrics.h"
#include "Trace.h"
#include "Walkers.h"
Expand All @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions service/constant-propagation/ConstantPropagation.cpp
Expand Up @@ -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,
Expand All @@ -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<Transform::Stats>(
scope,
[&](DexMethod* method) { return run(method, xstores, runtime_cache); });
Expand Down
11 changes: 10 additions & 1 deletion service/constant-propagation/ConstantPropagation.h
Expand Up @@ -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,
Expand All @@ -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