Skip to content

Commit

Permalink
Back out "add MergeabilityAwareInterDexReshufflePass"
Browse files Browse the repository at this point in the history
Summary:
Original commit changeset: 989888169622

Original Phabricator Diff: D56172431

Reviewed By: wsanville

Differential Revision: D56262093

fbshipit-source-id: 6a4a4f8fbc1a48ba35aab66b91960ce9d1cffc31
  • Loading branch information
beicy authored and facebook-github-bot committed Apr 17, 2024
1 parent a7b3f2e commit ae67d7a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 176 deletions.
1 change: 0 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ libopt_la_SOURCES = \
opt/interdex/InterDexPass.cpp \
opt/interdex/InterDexReshuffleImpl.cpp \
opt/interdex/InterDexReshufflePass.cpp \
opt/interdex/MAInterDexReshufflePass.cpp \
opt/interdex/SortRemainingClassesPass.cpp \
opt/kotlin-lambda/RewriteKotlinSingletonInstance.cpp \
opt/kotlin-lambda/KotlinObjectInliner.cpp \
Expand Down
2 changes: 1 addition & 1 deletion opt/class-merging/IntraDexClassMergingPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class IntraDexClassMergingPass : public Pass {
using namespace redex_properties::interactions;
using namespace redex_properties::names;
return {
{DexLimitsObeyed, Establishes},
{DexLimitsObeyed, Preserves},
{NoResolvablePureRefs, Preserves},
{InitialRenameClass, Preserves},
};
Expand Down
30 changes: 27 additions & 3 deletions opt/interdex/InterDexReshufflePass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
*/

#include "InterDexReshufflePass.h"
#include "ClassMerging.h"
#include "ConfigFiles.h"
#include "DedupStrings.h"
#include "DexClass.h"
#include "DexStructure.h"
#include "DexUtil.h"
#include "InterDexPass.h"
#include "ModelSpecGenerator.h"
#include "PassManager.h"
#include "Show.h"
#include "StlUtil.h"
Expand Down Expand Up @@ -49,9 +51,29 @@ void InterDexReshufflePass::run_pass(DexStoresVector& stores,
return;
}

InterDexReshuffleImpl impl(conf, mgr, m_config, original_scope, root_dexen);
impl.compute_plan();
impl.apply_plan();
auto has_IDCM_pass = mgr.find_pass("IntraDexClassMergingPass");
// The mergeability_aware reshuffle algorithm is only enabled when 1) there
// will be a IDCM pass; 2) m_allow_mergeability_aware is set true; and 3) This
// is the first run of InterDexReshufflePass.
bool enable_mergeability_aware_reshuffle =
has_IDCM_pass && m_allow_mergeability_aware && m_run == 0;
if (enable_mergeability_aware_reshuffle) {
TRACE(PM, 1, "Run regular mergeability-aware InterDexReshuffle");
mgr.incr_metric("Mergeability_aware", 1);
class_merging::Model merging_model = class_merging::construct_global_model(
original_scope, mgr, conf, stores);

InterDexReshuffleImpl impl(conf, mgr, m_config, original_scope, root_dexen,
merging_model);
impl.compute_plan();
impl.apply_plan();
} else {
TRACE(PM, 1, "Run regular InterDexReshuffle");
mgr.incr_metric("Mergeability_aware", 0);
InterDexReshuffleImpl impl(conf, mgr, m_config, original_scope, root_dexen);
impl.compute_plan();
impl.apply_plan();
}

// Sanity check
std::unordered_set<DexClass*> original_scope_set(original_scope.begin(),
Expand All @@ -63,6 +85,8 @@ void InterDexReshufflePass::run_pass(DexStoresVector& stores,
for (auto cls : original_scope_set) {
always_assert(new_scope_set.count(cls));
}

++m_run;
}

static InterDexReshufflePass s_pass;
16 changes: 16 additions & 0 deletions opt/interdex/InterDexReshufflePass.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,30 @@ class InterDexReshufflePass : public Pass {
m_config.max_batch_size,
"How many class to move per batch. More might yield better results, "
"but might take longer.");
bind("other_weight",
m_config.other_weight,
m_config.other_weight,
"Weight for non-deduped method in mergeability-aware reshuffle cost "
"function.");
bind("deduped_weight",
m_config.deduped_weight,
m_config.deduped_weight,
"Weight for deduped method in mergeability-aware reshuffle cost "
"function.");
bind("exclude_below20pct_coldstart_classes",
false,
m_config.exclude_below20pct_coldstart_classes,
"Whether to exclude coldstart classes in between 1pctColdStart and "
"20pctColdStart marker"
"from the reshuffle.");
bind("allow_mergeability_aware", true, m_allow_mergeability_aware);
}

private:
ReshuffleConfig m_config;

// Which iteration of `run_pass`.
size_t m_run{0};

bool m_allow_mergeability_aware;
};
82 changes: 0 additions & 82 deletions opt/interdex/MAInterDexReshufflePass.cpp

This file was deleted.

89 changes: 0 additions & 89 deletions opt/interdex/MAInterDexReshufflePass.h

This file was deleted.

0 comments on commit ae67d7a

Please sign in to comment.