Commit 21acaa8d authored by Skylot's avatar Skylot

fix: resolve mix up in SKIP and DONT_GENERATE flags

parent c705f8cb
...@@ -98,7 +98,7 @@ public class RegionGen extends InsnGen { ...@@ -98,7 +98,7 @@ public class RegionGen extends InsnGen {
private void makeSimpleBlock(IBlock block, CodeWriter code) throws CodegenException { private void makeSimpleBlock(IBlock block, CodeWriter code) throws CodegenException {
for (InsnNode insn : block.getInstructions()) { for (InsnNode insn : block.getInstructions()) {
if (!insn.contains(AFlag.SKIP)) { if (!insn.contains(AFlag.DONT_GENERATE)) {
makeInsn(insn, code); makeInsn(insn, code);
} }
} }
......
...@@ -16,11 +16,10 @@ public enum AFlag { ...@@ -16,11 +16,10 @@ public enum AFlag {
DECLARE_VAR, DECLARE_VAR,
DONT_WRAP, DONT_WRAP,
DONT_SHRINK,
DONT_INLINE, DONT_INLINE,
DONT_GENERATE, DONT_GENERATE, // process as usual, but don't output to generated code
SKIP, REMOVE, // can be completely removed
REMOVE, ADDED_TO_REGION,
SKIP_FIRST_ARG, SKIP_FIRST_ARG,
SKIP_ARG, // skip argument in invoke call SKIP_ARG, // skip argument in invoke call
......
...@@ -70,7 +70,7 @@ public class TryCatchBlock { ...@@ -70,7 +70,7 @@ public class TryCatchBlock {
for (BlockNode block : handler.getBlocks()) { for (BlockNode block : handler.getBlocks()) {
// skip synthetic loop exit blocks // skip synthetic loop exit blocks
BlockUtils.skipPredSyntheticPaths(block); BlockUtils.skipPredSyntheticPaths(block);
block.add(AFlag.SKIP); block.add(AFlag.REMOVE);
ExcHandlerAttr excHandlerAttr = block.get(AType.EXC_HANDLER); ExcHandlerAttr excHandlerAttr = block.get(AType.EXC_HANDLER);
if (excHandlerAttr != null if (excHandlerAttr != null
&& excHandlerAttr.getHandler().equals(handler)) { && excHandlerAttr.getHandler().equals(handler)) {
......
...@@ -31,7 +31,7 @@ public class CodeShrinker extends AbstractVisitor { ...@@ -31,7 +31,7 @@ public class CodeShrinker extends AbstractVisitor {
} }
public static void shrinkMethod(MethodNode mth) { public static void shrinkMethod(MethodNode mth) {
if (mth.isNoCode() || mth.contains(AFlag.DONT_SHRINK)) { if (mth.isNoCode()) {
return; return;
} }
for (BlockNode block : mth.getBasicBlocks()) { for (BlockNode block : mth.getBasicBlocks()) {
......
...@@ -236,7 +236,7 @@ public class BlockFinallyExtract extends AbstractVisitor { ...@@ -236,7 +236,7 @@ public class BlockFinallyExtract extends AbstractVisitor {
} }
if (!replaced) { if (!replaced) {
insnsList.remove(insnsList.size() - 1); insnsList.remove(insnsList.size() - 1);
handlerBlock.add(AFlag.SKIP); handlerBlock.add(AFlag.REMOVE);
} }
} }
...@@ -650,18 +650,18 @@ public class BlockFinallyExtract extends AbstractVisitor { ...@@ -650,18 +650,18 @@ public class BlockFinallyExtract extends AbstractVisitor {
int size = insns.size(); int size = insns.size();
for (int i = splitIndex; i < size; i++) { for (int i = splitIndex; i < size; i++) {
InsnNode insnNode = insns.get(i); InsnNode insnNode = insns.get(i);
insnNode.add(AFlag.SKIP); insnNode.add(AFlag.DONT_GENERATE);
newBlock.getInstructions().add(insnNode); newBlock.getInstructions().add(insnNode);
} }
Iterator<InsnNode> it = insns.iterator(); Iterator<InsnNode> it = insns.iterator();
while (it.hasNext()) { while (it.hasNext()) {
InsnNode insnNode = it.next(); InsnNode insnNode = it.next();
if (insnNode.contains(AFlag.SKIP)) { if (insnNode.contains(AFlag.DONT_GENERATE)) {
it.remove(); it.remove();
} }
} }
for (InsnNode insnNode : newBlock.getInstructions()) { for (InsnNode insnNode : newBlock.getInstructions()) {
insnNode.remove(AFlag.SKIP); insnNode.remove(AFlag.DONT_GENERATE);
} }
return newBlock; return newBlock;
} }
...@@ -680,13 +680,13 @@ public class BlockFinallyExtract extends AbstractVisitor { ...@@ -680,13 +680,13 @@ public class BlockFinallyExtract extends AbstractVisitor {
block.getPredecessors().clear(); block.getPredecessors().clear();
block.getSuccessors().clear(); block.getSuccessors().clear();
block.add(AFlag.REMOVE); block.add(AFlag.REMOVE);
block.remove(AFlag.SKIP); block.remove(AFlag.DONT_GENERATE);
CatchAttr catchAttr = block.get(AType.CATCH_BLOCK); CatchAttr catchAttr = block.get(AType.CATCH_BLOCK);
if (catchAttr != null) { if (catchAttr != null) {
catchAttr.getTryBlock().removeBlock(mth, block); catchAttr.getTryBlock().removeBlock(mth, block);
for (BlockNode skipBlock : mth.getBasicBlocks()) { for (BlockNode skipBlock : mth.getBasicBlocks()) {
if (skipBlock.contains(AFlag.SKIP)) { if (skipBlock.contains(AFlag.REMOVE)) {
markForRemove(mth, skipBlock); markForRemove(mth, skipBlock);
} }
} }
......
...@@ -47,7 +47,7 @@ public class CheckRegions extends AbstractVisitor { ...@@ -47,7 +47,7 @@ public class CheckRegions extends AbstractVisitor {
} }
if (LOG.isDebugEnabled() if (LOG.isDebugEnabled()
&& !block.contains(AFlag.RETURN) && !block.contains(AFlag.RETURN)
&& !block.contains(AFlag.SKIP) && !block.contains(AFlag.REMOVE)
&& !block.contains(AFlag.SYNTHETIC) && !block.contains(AFlag.SYNTHETIC)
&& !block.getInstructions().isEmpty()) { && !block.getInstructions().isEmpty()) {
LOG.debug("Duplicated block: {} - {}", mth, block); LOG.debug("Duplicated block: {} - {}", mth, block);
...@@ -58,7 +58,8 @@ public class CheckRegions extends AbstractVisitor { ...@@ -58,7 +58,8 @@ public class CheckRegions extends AbstractVisitor {
for (BlockNode block : mth.getBasicBlocks()) { for (BlockNode block : mth.getBasicBlocks()) {
if (!blocksInRegions.contains(block) if (!blocksInRegions.contains(block)
&& !block.getInstructions().isEmpty() && !block.getInstructions().isEmpty()
&& !block.contains(AFlag.SKIP)) { && !block.contains(AFlag.ADDED_TO_REGION)
&& !block.contains(AFlag.REMOVE)) {
String blockCode = getBlockInsnStr(mth, block); String blockCode = getBlockInsnStr(mth, block);
mth.addWarn("Missing block: " + block + ", code skipped:" + CodeWriter.NL + blockCode); mth.addWarn("Missing block: " + block + ", code skipped:" + CodeWriter.NL + blockCode);
} }
......
...@@ -291,13 +291,13 @@ public class IfMakerHelper { ...@@ -291,13 +291,13 @@ public class IfMakerHelper {
if (info.getMergedBlocks().size() > 1) { if (info.getMergedBlocks().size() > 1) {
for (BlockNode block : info.getMergedBlocks()) { for (BlockNode block : info.getMergedBlocks()) {
if (block != info.getIfBlock()) { if (block != info.getIfBlock()) {
block.add(AFlag.SKIP); block.add(AFlag.ADDED_TO_REGION);
} }
} }
} }
if (!info.getSkipBlocks().isEmpty()) { if (!info.getSkipBlocks().isEmpty()) {
for (BlockNode block : info.getSkipBlocks()) { for (BlockNode block : info.getSkipBlocks()) {
block.add(AFlag.SKIP); block.add(AFlag.ADDED_TO_REGION);
} }
info.getSkipBlocks().clear(); info.getSkipBlocks().clear();
} }
...@@ -325,7 +325,7 @@ public class IfMakerHelper { ...@@ -325,7 +325,7 @@ public class IfMakerHelper {
} }
private static BlockNode getNextIfNode(BlockNode block) { private static BlockNode getNextIfNode(BlockNode block) {
if (block == null || block.contains(AType.LOOP) || block.contains(AFlag.SKIP)) { if (block == null || block.contains(AType.LOOP) || block.contains(AFlag.ADDED_TO_REGION)) {
return null; return null;
} }
List<InsnNode> insns = block.getInstructions(); List<InsnNode> insns = block.getInstructions();
......
...@@ -114,8 +114,8 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor ...@@ -114,8 +114,8 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
} }
// all checks passed // all checks passed
initInsn.add(AFlag.SKIP); initInsn.add(AFlag.DONT_GENERATE);
incrInsn.add(AFlag.SKIP); incrInsn.add(AFlag.DONT_GENERATE);
LoopType arrForEach = checkArrayForEach(mth, initInsn, incrInsn, condition); LoopType arrForEach = checkArrayForEach(mth, initInsn, incrInsn, condition);
if (arrForEach != null) { if (arrForEach != null) {
loopRegion.setType(arrForEach); loopRegion.setType(arrForEach);
...@@ -188,8 +188,8 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor ...@@ -188,8 +188,8 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
} }
// array for each loop confirmed // array for each loop confirmed
len.add(AFlag.SKIP); len.add(AFlag.DONT_GENERATE);
arrGetInsn.add(AFlag.SKIP); arrGetInsn.add(AFlag.DONT_GENERATE);
InstructionRemover.unbindInsn(mth, len); InstructionRemover.unbindInsn(mth, len);
// inline array variable // inline array variable
...@@ -265,9 +265,9 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor ...@@ -265,9 +265,9 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
toSkip.add(nextCall); toSkip.add(nextCall);
} }
assignInsn.add(AFlag.SKIP); assignInsn.add(AFlag.DONT_GENERATE);
for (InsnNode insnNode : toSkip) { for (InsnNode insnNode : toSkip) {
insnNode.add(AFlag.SKIP); insnNode.add(AFlag.DONT_GENERATE);
} }
loopRegion.setType(new ForEachLoop(iterVar, iterableArg)); loopRegion.setType(new ForEachLoop(iterVar, iterableArg));
return true; return true;
......
...@@ -122,7 +122,7 @@ public class ProcessVariables extends AbstractVisitor { ...@@ -122,7 +122,7 @@ public class ProcessVariables extends AbstractVisitor {
int len = container.getInstructions().size(); int len = container.getInstructions().size();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
InsnNode insn = container.getInstructions().get(i); InsnNode insn = container.getInstructions().get(i);
if (insn.contains(AFlag.SKIP)) { if (insn.contains(AFlag.DONT_GENERATE)) {
continue; continue;
} }
args.clear(); args.clear();
......
...@@ -203,13 +203,13 @@ public class RegionMaker { ...@@ -203,13 +203,13 @@ public class RegionMaker {
BlockNode thenBlock = condInfo.getThenBlock(); BlockNode thenBlock = condInfo.getThenBlock();
out = thenBlock == loopStart ? condInfo.getElseBlock() : thenBlock; out = thenBlock == loopStart ? condInfo.getElseBlock() : thenBlock;
loopStart.remove(AType.LOOP); loopStart.remove(AType.LOOP);
loop.getEnd().add(AFlag.SKIP); loop.getEnd().add(AFlag.ADDED_TO_REGION);
stack.addExit(loop.getEnd()); stack.addExit(loop.getEnd());
processedBlocks.clear(loopStart.getId()); processedBlocks.clear(loopStart.getId());
Region body = makeRegion(loopStart, stack); Region body = makeRegion(loopStart, stack);
loopRegion.setBody(body); loopRegion.setBody(body);
loopStart.addAttr(AType.LOOP, loop); loopStart.addAttr(AType.LOOP, loop);
loop.getEnd().remove(AFlag.SKIP); loop.getEnd().remove(AFlag.ADDED_TO_REGION);
} else { } else {
out = condInfo.getElseBlock(); out = condInfo.getElseBlock();
if (outerRegion != null if (outerRegion != null
...@@ -229,7 +229,7 @@ public class RegionMaker { ...@@ -229,7 +229,7 @@ public class RegionMaker {
blocks.remove(conditionBlock); blocks.remove(conditionBlock);
for (BlockNode block : blocks) { for (BlockNode block : blocks) {
if (block.getInstructions().isEmpty() if (block.getInstructions().isEmpty()
&& !block.contains(AFlag.SKIP) && !block.contains(AFlag.ADDED_TO_REGION)
&& !RegionUtils.isRegionContainsBlock(body, block)) { && !RegionUtils.isRegionContainsBlock(body, block)) {
body.add(block); body.add(block);
} }
...@@ -489,7 +489,7 @@ public class RegionMaker { ...@@ -489,7 +489,7 @@ public class RegionMaker {
return false; return false;
} }
BlockNode codePred = preds.get(0); BlockNode codePred = preds.get(0);
if (codePred.contains(AFlag.SKIP)) { if (codePred.contains(AFlag.ADDED_TO_REGION)) {
return false; return false;
} }
if (loopEnd.isDominator(codePred) if (loopEnd.isDominator(codePred)
...@@ -530,9 +530,9 @@ public class RegionMaker { ...@@ -530,9 +530,9 @@ public class RegionMaker {
for (InsnNode exitInsn : synchRegion.getExitInsns()) { for (InsnNode exitInsn : synchRegion.getExitInsns()) {
BlockNode insnBlock = BlockUtils.getBlockByInsn(mth, exitInsn); BlockNode insnBlock = BlockUtils.getBlockByInsn(mth, exitInsn);
if (insnBlock != null) { if (insnBlock != null) {
insnBlock.add(AFlag.SKIP); insnBlock.add(AFlag.DONT_GENERATE);
} }
exitInsn.add(AFlag.SKIP); exitInsn.add(AFlag.DONT_GENERATE);
InstructionRemover.unbindInsn(mth, exitInsn); InstructionRemover.unbindInsn(mth, exitInsn);
} }
...@@ -615,7 +615,7 @@ public class RegionMaker { ...@@ -615,7 +615,7 @@ public class RegionMaker {
} }
private BlockNode processIf(IRegion currentRegion, BlockNode block, IfNode ifnode, RegionStack stack) { private BlockNode processIf(IRegion currentRegion, BlockNode block, IfNode ifnode, RegionStack stack) {
if (block.contains(AFlag.SKIP)) { if (block.contains(AFlag.ADDED_TO_REGION)) {
// block already included in other 'if' region // block already included in other 'if' region
return ifnode.getThenBlock(); return ifnode.getThenBlock();
} }
...@@ -681,7 +681,7 @@ public class RegionMaker { ...@@ -681,7 +681,7 @@ public class RegionMaker {
private void addEdgeInsn(IfInfo ifInfo, Region region, EdgeInsnAttr edgeInsnAttr) { private void addEdgeInsn(IfInfo ifInfo, Region region, EdgeInsnAttr edgeInsnAttr) {
BlockNode start = edgeInsnAttr.getStart(); BlockNode start = edgeInsnAttr.getStart();
if (start.contains(AFlag.SKIP)) { if (start.contains(AFlag.ADDED_TO_REGION)) {
return; return;
} }
boolean fromThisIf = false; boolean fromThisIf = false;
......
...@@ -126,7 +126,7 @@ public class RegionMakerVisitor extends AbstractVisitor { ...@@ -126,7 +126,7 @@ public class RegionMakerVisitor extends AbstractVisitor {
BlockNode bn = (BlockNode) block; BlockNode bn = (BlockNode) block;
for (BlockNode s : bn.getCleanSuccessors()) { for (BlockNode s : bn.getCleanSuccessors()) {
if (!blocks.contains(s) if (!blocks.contains(s)
&& !bn.contains(AFlag.SKIP) && !bn.contains(AFlag.ADDED_TO_REGION)
&& !s.contains(AFlag.FALL_THROUGH)) { && !s.contains(AFlag.FALL_THROUGH)) {
addBreak(mth, c, bn); addBreak(mth, c, bn);
break; break;
......
...@@ -429,7 +429,7 @@ public class SSATransform extends AbstractVisitor { ...@@ -429,7 +429,7 @@ public class SSATransform extends AbstractVisitor {
if (resArg.getRegNum() != arg.getRegNum() if (resArg.getRegNum() != arg.getRegNum()
&& !resArg.getSVar().isUsedInPhi()) { && !resArg.getSVar().isUsedInPhi()) {
markThisArgs(resArg); markThisArgs(resArg);
parentInsn.add(AFlag.SKIP); parentInsn.add(AFlag.DONT_GENERATE);
} }
} }
} }
......
...@@ -74,7 +74,7 @@ public class BlockUtils { ...@@ -74,7 +74,7 @@ public class BlockUtils {
} }
public static boolean isBlockMustBeCleared(BlockNode b) { public static boolean isBlockMustBeCleared(BlockNode b) {
if (b.contains(AType.EXC_HANDLER) || b.contains(AFlag.SKIP)) { if (b.contains(AType.EXC_HANDLER) || b.contains(AFlag.REMOVE)) {
return true; return true;
} }
if (b.contains(AFlag.SYNTHETIC)) { if (b.contains(AFlag.SYNTHETIC)) {
...@@ -495,7 +495,7 @@ public class BlockUtils { ...@@ -495,7 +495,7 @@ public class BlockUtils {
if (pred.contains(AFlag.SYNTHETIC) if (pred.contains(AFlag.SYNTHETIC)
&& !pred.contains(AType.SPLITTER_BLOCK) && !pred.contains(AType.SPLITTER_BLOCK)
&& pred.getInstructions().isEmpty()) { && pred.getInstructions().isEmpty()) {
pred.add(AFlag.SKIP); pred.add(AFlag.DONT_GENERATE);
skipPredSyntheticPaths(pred); skipPredSyntheticPaths(pred);
} }
} }
......
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