Skip to content

Commit

Permalink
Construct InterDexGrouping at Model level
Browse files Browse the repository at this point in the history
Summary:
We don't need to repeatedly building the same interdex groups for each `MergerType` within the same `Model`.
This change does away with the repetition. It speeds up the passes.

Reviewed By: ssj933

Differential Revision: D49117965

fbshipit-source-id: 674f5b994f211b45d40ddc353beeacc1b7f5023c
  • Loading branch information
Wei Zhang (Devinfra) authored and facebook-github-bot committed Sep 13, 2023
1 parent 6c04ff1 commit 9fb72da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions service/class-merging/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ void Model::shape_model() {
return compare_dextypes(first->type, second->type);
});

InterDexGrouping interdex_grouping(m_scope, m_conf, m_spec.interdex_config,
m_spec.merging_targets);
for (auto merger : mergers) {
TRACE(CLMG, 6, "Build shapes from %s", SHOW(merger->type));
MergerType::ShapeCollector shapes;
Expand All @@ -436,7 +438,7 @@ void Model::shape_model() {
break_by_interface(*merger, shape_it.first, shape_it.second);
}

flatten_shapes(*merger, shapes);
flatten_shapes(interdex_grouping, *merger, shapes);
}

// Update excluded metrics
Expand Down Expand Up @@ -589,12 +591,12 @@ TypeGroupByDex Model::group_per_dex(const TypeSet& types,
return result;
}

void Model::flatten_shapes(const MergerType& merger,
void Model::flatten_shapes(const InterDexGrouping& interdex_grouping,
const MergerType& merger,
MergerType::ShapeCollector& shapes) {
size_t num_trimmed_types = trim_groups(shapes, m_spec.min_count);
m_stats.m_dropped += num_trimmed_types;
InterDexGrouping interdex_grouping(m_scope, m_conf, m_spec.interdex_config,
m_spec.merging_targets);

// Shape based grouping layer
// sort shapes by mergeables count
std::vector<const MergerType::Shape*> keys;
Expand Down
3 changes: 2 additions & 1 deletion service/class-merging/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ class Model {
void break_by_interface(const MergerType& merger,
const MergerType::Shape& shape,
MergerType::ShapeHierarchy& hier);
void flatten_shapes(const MergerType& merger,
void flatten_shapes(const InterDexGrouping& interdex_grouping,
const MergerType& merger,
MergerType::ShapeCollector& shapes);
TypeGroupByDex group_per_dex(const TypeSet& types, const ModelSpec& spec);

Expand Down

0 comments on commit 9fb72da

Please sign in to comment.