Commit 2dbdd1f0 authored by Skylot's avatar Skylot

fix: support instructions removing in SimplifyVisitor

parent fc58022d
...@@ -50,24 +50,36 @@ public class SimplifyVisitor extends AbstractVisitor { ...@@ -50,24 +50,36 @@ public class SimplifyVisitor extends AbstractVisitor {
return; return;
} }
for (BlockNode block : mth.getBasicBlocks()) { for (BlockNode block : mth.getBasicBlocks()) {
List<InsnNode> list = block.getInstructions(); simplifyBlock(mth, block);
for (int i = 0; i < list.size(); i++) { }
InsnNode modInsn = simplifyInsn(mth, list.get(i)); }
if (modInsn != null) {
if (i != 0 && modInsn.contains(AFlag.ARITH_ONEARG)) { private static void simplifyBlock(MethodNode mth, BlockNode block) {
List<InsnNode> list = block.getInstructions();
InsnNode mergedNode = simplifyOneArgConsecutive( for (int i = 0; i < list.size(); i++) {
list.get(i - 1), list.get(i), (ArithNode) modInsn); InsnNode insn = list.get(i);
int insnCount = list.size();
if (mergedNode != null) { InsnNode modInsn = simplifyInsn(mth, insn);
list.remove(i - 1); if (modInsn != null) {
modInsn = mergedNode; if (i != 0 && modInsn.contains(AFlag.ARITH_ONEARG)) {
i--; InsnNode mergedNode = simplifyOneArgConsecutive(
} list.get(i - 1), list.get(i), (ArithNode) modInsn);
if (mergedNode != null) {
list.remove(i - 1);
modInsn = mergedNode;
i--;
} }
}
if (i < list.size() && list.get(i) == insn) {
list.set(i, modInsn); list.set(i, modInsn);
} }
} }
if (list.size() < insnCount) {
// some insns removed => restart block processing
simplifyBlock(mth, block);
return;
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment