Skip to content

Commit

Permalink
feat: add method to update all blocks related info in method (#2335)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Nov 2, 2024
1 parent 4c74e8e commit 417bb7a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ public boolean isPreExitBlock(BlockNode block) {
return exitBlock.getPredecessors().contains(block);
}

public void resetLoops() {
this.loops = new ArrayList<>();
}

public void registerLoop(LoopInfo loop) {
if (loops.isEmpty()) {
loops = new ArrayList<>(5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,33 @@ private static void processBlocksTree(MethodNode mth) {
updateCleanSuccessors(mth);
}

/**
* Recalculate all additional info attached to blocks:
*
* <pre>
* - dominators
* - dominance frontier
* - post dominators (only if {@link AFlag#COMPUTE_POST_DOM} added to method)
* - loops and nested loop info
* </pre>
*
* This method should be called after changing a block tree in custom passes added before
* {@link BlockFinisher}.
*/
public static void updateBlocksData(MethodNode mth) {
clearBlocksState(mth);
DominatorTree.compute(mth);
markLoops(mth);

DominatorTree.computeDominanceFrontier(mth);
registerLoops(mth);
processNestedLoops(mth);

PostDominatorTree.compute(mth);

updateCleanSuccessors(mth);
}

static void updateCleanSuccessors(MethodNode mth) {
mth.getBasicBlocks().forEach(BlockNode::updateCleanSuccessors);
}
Expand Down Expand Up @@ -245,6 +272,7 @@ private static void markLoops(MethodNode mth) {
}

private static void registerLoops(MethodNode mth) {
mth.resetLoops();
mth.getBasicBlocks().forEach(block -> {
if (block.contains(AFlag.LOOP_START)) {
block.getAll(AType.LOOP).forEach(mth::registerLoop);
Expand Down

0 comments on commit 417bb7a

Please sign in to comment.