feat: add method to update all blocks related info in method (#2335)
Some checks failed
Build Artifacts / build (push) Has been cancelled
Build Artifacts / build-win-bundle (push) Has been cancelled
Build Test / tests (ubuntu-latest) (push) Has been cancelled
Build Test / tests (windows-latest) (push) Has been cancelled
CodeQL / Analyze (java) (push) Has been cancelled

This commit is contained in:
Skylot 2024-11-02 22:05:20 +00:00
parent 4c74e8e300
commit 417bb7a7e9
No known key found for this signature in database
GPG Key ID: 47A4975761262B6A
2 changed files with 32 additions and 0 deletions

View File

@ -408,6 +408,10 @@ public class MethodNode extends NotificationAttrNode implements IMethodDetails,
return exitBlock.getPredecessors().contains(block);
}
public void resetLoops() {
this.loops = new ArrayList<>();
}
public void registerLoop(LoopInfo loop) {
if (loops.isEmpty()) {
loops = new ArrayList<>(5);

View File

@ -94,6 +94,33 @@ public class BlockProcessor extends AbstractVisitor {
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);
}
@ -245,6 +272,7 @@ public class BlockProcessor extends AbstractVisitor {
}
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);