private static FatBlock newFatBlock(int startNodeIndex, int endNodeIndex) { FatBlock fb = new FatBlock(); fb.realBlock = new Block(startNodeIndex, endNodeIndex); return fb; }
private void markAnyTypeVariables(int[] varTypes) { for (int i = 0; i != varTypes.length; i++) { if (itsLiveOnEntrySet.get(i)) { assignType(varTypes, i, Optimizer.AnyType); } } }
theBlocks[i].initLiveOnEntrySets(fn, statementNodes); doneOnce[vIndex] = true; visit[vIndex] = false; if (theBlocks[vIndex].doReachedUseDataFlow()) { Block pred[] = theBlocks[vIndex].itsPredecessors; if (pred != null) { theBlocks[0].markAnyTypeVariables(varTypes);
private static boolean findDefPoints(OptFunctionNode fn, Node n, int[] varTypes) { boolean result = false; Node first = n.getFirstChild(); for (Node next = first; next != null; next = next.getNext()) { result |= findDefPoints(fn, next, varTypes); } switch (n.getType()) { case Token.DEC : case Token.INC : if (first.getType() == Token.GETVAR) { // theVar is a Number now int i = fn.getVarIndex(first); result |= assignType(varTypes, i, Optimizer.NumberType); } break; case Token.SETVAR : { Node rValue = first.getNext(); int theType = findExpressionType(fn, rValue, varTypes); int i = fn.getVarIndex(n); result |= assignType(varTypes, i, theType); break; } } return result; }
Block[] theBlocks = buildBlocks(statementNodes); reachingDefDataFlow(fn, statementNodes, theBlocks, varTypes); typeFlow(fn, statementNodes, theBlocks, varTypes);
private void initLiveOnEntrySets(OptFunctionNode fn, Node[] statementNodes) { int listLength = fn.getVarCount(); itsUseBeforeDefSet = new BitSet(listLength); itsNotDefSet = new BitSet(listLength); itsLiveOnEntrySet = new BitSet(listLength); itsLiveOnExitSet = new BitSet(listLength); for (int i = itsStartNodeIndex; i <= itsEndNodeIndex; i++) { Node n = statementNodes[i]; lookForVariableAccess(fn, n); } itsNotDefSet.flip(0, listLength); // truth in advertising }
private boolean doTypeFlow(OptFunctionNode fn, Node[] statementNodes, int[] varTypes) { boolean changed = false; for (int i = itsStartNodeIndex; i <= itsEndNodeIndex; i++) { Node n = statementNodes[i]; if (n != null) { changed |= findDefPoints(fn, n, varTypes); } } return changed; }
doneOnce[vIndex] = true; visit[vIndex] = false; if (theBlocks[vIndex].doTypeFlow(fn, statementNodes, varTypes))
int lType = findExpressionType(fn, child, varTypes); int rType = findExpressionType(fn, child.getNext(), varTypes); return lType | rType; // we're not distinguishing strings yet Node ifTrue = n.getFirstChild().getNext(); Node ifFalse = ifTrue.getNext(); int ifTrueType = findExpressionType(fn, ifTrue, varTypes); int ifFalseType = findExpressionType(fn, ifFalse, varTypes); return ifTrueType | ifFalseType; case Token.SETPROP: case Token.SETELEM: return findExpressionType(fn, n.getLastChild(), varTypes); int lType = findExpressionType(fn, child, varTypes); int rType = findExpressionType(fn, child.getNext(), varTypes); return lType | rType;
private static boolean findDefPoints(OptFunctionNode fn, Node n, int[] varTypes) { boolean result = false; Node first = n.getFirstChild(); for (Node next = first; next != null; next = next.getNext()) { result |= findDefPoints(fn, next, varTypes); } switch (n.getType()) { case Token.DEC : case Token.INC : if (first.getType() == Token.GETVAR) { // theVar is a Number now int i = fn.getVarIndex(first); result |= assignType(varTypes, i, Optimizer.NumberType); } break; case Token.SETVAR : { Node rValue = first.getNext(); int theType = findExpressionType(fn, rValue, varTypes); int i = fn.getVarIndex(n); result |= assignType(varTypes, i, theType); break; } } return result; }
Block[] theBlocks = buildBlocks(statementNodes); reachingDefDataFlow(fn, statementNodes, theBlocks, varTypes); typeFlow(fn, statementNodes, theBlocks, varTypes);
private void initLiveOnEntrySets(OptFunctionNode fn, Node[] statementNodes) { int listLength = fn.getVarCount(); itsUseBeforeDefSet = new BitSet(listLength); itsNotDefSet = new BitSet(listLength); itsLiveOnEntrySet = new BitSet(listLength); itsLiveOnExitSet = new BitSet(listLength); for (int i = itsStartNodeIndex; i <= itsEndNodeIndex; i++) { Node n = statementNodes[i]; lookForVariableAccess(fn, n); } itsNotDefSet.flip(0, listLength); // truth in advertising }
private boolean doTypeFlow(OptFunctionNode fn, Node[] statementNodes, int[] varTypes) { boolean changed = false; for (int i = itsStartNodeIndex; i <= itsEndNodeIndex; i++) { Node n = statementNodes[i]; if (n != null) changed |= findDefPoints(fn, n, varTypes); } return changed; }
doneOnce[vIndex] = true; visit[vIndex] = false; if (theBlocks[vIndex].doTypeFlow(fn, statementNodes, varTypes))
int lType = findExpressionType(fn, child, varTypes); int rType = findExpressionType(fn, child.getNext(), varTypes); return lType | rType; // we're not distinguishing strings yet Node ifTrue = n.getFirstChild().getNext(); Node ifFalse = ifTrue.getNext(); int ifTrueType = findExpressionType(fn, ifTrue, varTypes); int ifFalseType = findExpressionType(fn, ifFalse, varTypes); return ifTrueType | ifFalseType; case Token.SETPROP: case Token.SETELEM: return findExpressionType(fn, n.getLastChild(), varTypes); int lType = findExpressionType(fn, child, varTypes); int rType = findExpressionType(fn, child.getNext(), varTypes); return lType | rType;
default : while (child != null) { result |= findDefPoints(fn, child, varTypes); child = child.getNext(); result |= assignType(varTypes, i, Optimizer.NumberType); if (child.getType() == Token.GETVAR) { int i = fn.getVarIndex(child); assignType(varTypes, i, Optimizer.AnyType); result |= findDefPoints(fn, child, varTypes); child = child.getNext(); case Token.SETVAR : { Node rValue = child.getNext(); int theType = findExpressionType(fn, rValue, varTypes); int i = fn.getVarIndex(n); result |= assignType(varTypes, i, theType); break;
Block[] theBlocks = buildBlocks(statementNodes); reachingDefDataFlow(fn, statementNodes, theBlocks, varTypes); typeFlow(fn, statementNodes, theBlocks, varTypes);
theBlocks[i].initLiveOnEntrySets(fn, statementNodes); doneOnce[vIndex] = true; visit[vIndex] = false; if (theBlocks[vIndex].doReachedUseDataFlow()) { Block pred[] = theBlocks[vIndex].itsPredecessors; if (pred != null) { theBlocks[0].markAnyTypeVariables(varTypes);
private void initLiveOnEntrySets(OptFunctionNode fn, Node[] statementNodes) { int listLength = fn.getVarCount(); itsUseBeforeDefSet = new BitSet(listLength); itsNotDefSet = new BitSet(listLength); itsLiveOnEntrySet = new BitSet(listLength); itsLiveOnExitSet = new BitSet(listLength); for (int i = itsStartNodeIndex; i <= itsEndNodeIndex; i++) { Node n = statementNodes[i]; lookForVariableAccess(fn, n); } itsNotDefSet.flip(0, listLength); // truth in advertising }
private void markAnyTypeVariables(int[] varTypes) { for (int i = 0; i != varTypes.length; i++) { if (itsLiveOnEntrySet.get(i)) { assignType(varTypes, i, Optimizer.AnyType); } } }