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