Skip to content

Commit

Permalink
Convert WrappedPrimitives logic to service, run within IPCP
Browse files Browse the repository at this point in the history
Summary:
This is a large diff, but what I'm trying to achieve here is a Pass that really, just sets up a few things based on its configuration, to allow the real work to happen from within IPCP with the intraprocedural analyzer/state of an individual method that already gets computed.

Because IPCP is already capable of modeling the creation and movement of ObjectWithImmutAttr instances, I feel like this work fits in here fairly well and is overall a cleaner/simpler to plug in new functionality, as opposed to the original WrappedPrimitives RFC diff which tries to make up a bunch of trees of usages, in a way that isn't even correct.

Overall, the flow of events in this version of the work is:
- `WrappedPrimitivesPass::eval_pass()` will read the Redex config to learn about the types/method refs involved, and will mark the unwrapped method refs as root to prevent removals.
- IPCP will call into the WrappedPrimitives service, per method to see if any work is configured or if the method has relevant transforms.
- `WrappedPrimitivesPass::run_pass()`, which ideally will run right after the first run of IPCP will then report metrics, and undo the marking of roots. It will also reset the state so that subsequent IPCP runs will call into the WrappedPrimitives service and have it be a noop.

Reviewed By: NTillmann

Differential Revision: D63414216

fbshipit-source-id: 9837a9b3a70858741728f637be1e24fb5906cc55
  • Loading branch information
wsanville authored and facebook-github-bot committed Sep 28, 2024
1 parent c71f51a commit 2c3e8d8
Show file tree
Hide file tree
Showing 13 changed files with 724 additions and 1,077 deletions.
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ libredex_la_SOURCES = \
service/type-analysis/TypeAnalysisRuntimeAssert.cpp \
service/type-analysis/ResolveMethodRefs.cpp \
service/type-string-rewriter/TypeStringRewriter.cpp \
service/wrapped-primitives/WrappedPrimitives.cpp \
shared/DexDefs.cpp \
shared/DexEncoding.cpp \
shared/file-utils.cpp \
Expand Down Expand Up @@ -526,7 +527,7 @@ libopt_la_SOURCES = \
opt/virtual_merging/DedupVirtualMethods.cpp \
opt/virtual_merging/VirtualMerging.cpp \
opt/virtual_scope/MethodDevirtualizationPass.cpp \
opt/wrapped-primitives/WrappedPrimitives.cpp
opt/wrapped-primitives/WrappedPrimitivesPass.cpp

libopt_la_LIBADD = \
libredex.la \
Expand Down
1 change: 1 addition & 0 deletions Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ COMMON_INCLUDES = \
-I$(top_srcdir)/service/switch-partitioning \
-I$(top_srcdir)/service/type-analysis \
-I$(top_srcdir)/service/type-string-rewriter \
-I$(top_srcdir)/service/wrapped-primitives \
-I$(top_srcdir)/shared \
-I$(top_srcdir)/sparta/include \
-I$(top_srcdir)/tools/common \
Expand Down
7 changes: 7 additions & 0 deletions opt/constant-propagation/IPConstantPropagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "Timer.h"
#include "Trace.h"
#include "Walkers.h"
#include "WrappedPrimitives.h"

namespace mog = method_override_graph;

Expand Down Expand Up @@ -260,6 +261,12 @@ void PassImpl::optimize(
code.cfg(),
&xstores,
method->get_class());
// If configured, plug in IPCP state to do additional transforms
// (API unwrapping to primitives for known ObjectWithImmutAttr
// instances).
wrapped_primitives::optimize_method(type_system, ipa->fp_iter,
fp_iter.get_whole_program_state(),
method, code.cfg());
return tf.get_stats();
}
});
Expand Down
Loading

0 comments on commit 2c3e8d8

Please sign in to comment.