/** Print the value numbers for each node in the value graph. */ void printValueNumbers() { for (Enumeration<GraphNode> e = valueGraph.enumerateVertices(); e.hasMoreElements(); ) { ValueGraphVertex v = (ValueGraphVertex) e.nextElement(); int valueNumber = v.getValueNumber(); GVCongruenceClass c = B.get(valueNumber); System.out.println(v.getName() + " " + valueNumber + " " + c.getLabel()); } }
/** * Due to PI nodes and Moves, the initial label for a register may be another register. Fix up the * value graph for cases where the initial register label was not removed. */ private void computeClosure() { for (Enumeration<GraphNode> e = enumerateVertices(); e.hasMoreElements(); ) { ValueGraphVertex v = (ValueGraphVertex) e.nextElement(); if (v.getName() instanceof Register) { if (v.getLabel() instanceof Register) { if (v.getName() != v.getLabel()) { ValueGraphVertex v2 = getVertex(v.getLabel()); if (VM.VerifyAssertions) { if (v2.getName() instanceof Register && v2.getLabel() instanceof Register && v2.getLabel() != v2.getName()) { VM._assert(VM.NOT_REACHED); } } v.copyVertex(v2); } } } } }
/** * Transform to eliminate redundant branches passed on GVNs and dominator information. * * @param ir The IR on which to apply the phase */ public void perform(IR ir) { // (1) Remove redundant conditional branches and locally fix the PHIs GlobalValueNumberState gvns = ir.HIRInfo.valueNumbers; DominatorTree dt = ir.HIRInfo.dominatorTree; for (BasicBlockEnumeration bbs = ir.getBasicBlocks(); bbs.hasMoreElements(); ) { BasicBlock candBB = bbs.next(); Instruction candTest = candBB.firstBranchInstruction(); if (candTest == null) continue; if (!(IfCmp.conforms(candTest) || InlineGuard.conforms(candTest))) continue; GVCongruenceClass cc = gvns.congruenceClass(candTest); if (cc.size() > 1) { for (ValueGraphVertex vertex : cc) { Instruction poss = (Instruction) vertex.getName(); if (poss != candTest) { BasicBlock notTaken = getNotTakenBlock(poss); BasicBlock taken = poss.getBranchTarget(); if (taken == notTaken) continue; // both go to same block, so we don't know anything! if (notTaken.hasOneIn() && dt.dominates(notTaken, candBB)) { if (DEBUG) VM.sysWrite(candTest + " is dominated by not-taken branch of " + poss + "\n"); removeCondBranch(candBB, candTest, ir, poss); cc.removeVertex(gvns.valueGraph.getVertex(candTest)); break; } if (taken.hasOneIn() && dt.dominates(taken, candBB)) { if (DEBUG) VM.sysWrite(candTest + " is dominated by taken branch of " + poss + "\n"); takeCondBranch(candBB, candTest, ir); cc.removeVertex(gvns.valueGraph.getVertex(candTest)); break; } } } } } // (2) perform a Depth-first search of the control flow graph, // and remove any nodes we have made unreachable removeUnreachableCode(ir); }