use of org.jikesrvm.util.Pair in project JikesRVM by JikesRVM.
the class EnterSSA method patchPEIgeneratedValues.
/**
* Work around some problems with PEI-generated values and
* handlers. Namely, if a PEI has a return value, rename the
* result register before and after the PEI in order to reflect the fact
* that the PEI may not actually assign the result register.
*/
private void patchPEIgeneratedValues() {
// this only applies if there are exception handlers
if (!ir.hasReachableExceptionHandlers())
return;
HashSet<Pair<BasicBlock, RegisterOperand>> needed = new HashSet<Pair<BasicBlock, RegisterOperand>>(4);
Enumeration<BasicBlock> blocks = ir.getBasicBlocks();
while (blocks.hasMoreElements()) {
BasicBlock block = blocks.nextElement();
if (block.getExceptionalOut().hasMoreElements()) {
Instruction pei = block.lastRealInstruction();
if (pei != null && pei.isPEI() && ResultCarrier.conforms(pei)) {
boolean copyNeeded = false;
RegisterOperand v = ResultCarrier.getResult(pei);
// void calls and the like... :(
if (v != null) {
Register orig = v.getRegister();
{
Enumeration<BasicBlock> out = block.getApplicableExceptionalOut(pei);
while (out.hasMoreElements()) {
BasicBlock exp = out.nextElement();
LiveSet explive = live.getLiveInfo(exp).getIn();
if (explive.contains(orig)) {
copyNeeded = true;
break;
}
}
}
if (copyNeeded) {
Enumeration<BasicBlock> out = block.getApplicableExceptionalOut(pei);
while (out.hasMoreElements()) {
BasicBlock exp = out.nextElement();
needed.add(new Pair<BasicBlock, RegisterOperand>(exp, v));
}
}
}
}
}
}
// having determine where copies should be inserted, now insert them.
if (!needed.isEmpty()) {
for (Pair<BasicBlock, RegisterOperand> copy : needed) {
BasicBlock inBlock = copy.first;
RegisterOperand registerOp = copy.second;
TypeReference type = registerOp.getType();
Register register = registerOp.getRegister();
Register temp = ir.regpool.getReg(register);
inBlock.prependInstruction(SSA.makeMoveInstruction(ir, register, temp, type));
Enumeration<BasicBlock> outBlocks = inBlock.getIn();
while (outBlocks.hasMoreElements()) {
BasicBlock outBlock = outBlocks.nextElement();
Instruction x = SSA.makeMoveInstruction(ir, temp, register, type);
SSA.addAtEnd(ir, outBlock, x, true);
}
}
// Recompute liveness information. You might be tempted to incrementally
// update it, but it's tricky, so resist.....do the obvious, but easy thing!
prepare();
}
}
Aggregations