// with a temporary variable.
boolean parentScopeNeeded = false;
for (BasicBlock b: s.getCFG().getBasicBlocks()) {
ListIterator<Instr> instrs = b.getInstrs().listIterator();
while (instrs.hasNext()) {
Instr i = instrs.next();
if (i instanceof ResultInstr) {
Variable v = ((ResultInstr) i).getResult();
// %self is local to every scope and never crosses scope boundaries and need not be spilled/refilled
if (v instanceof LocalVariable && !v.isSelf()) {
LocalVariable lv = (LocalVariable)v;
if (lv.getScopeDepth() == 0) {
// Make sure there is a replacement tmp-var allocated for lv
setupLocalVarReplacement(lv, s, varRenameMap);
} else {
parentScopeNeeded = true;
decrementScopeDepth(lv, s, varRenameMap);
}
}
}
for (Variable v : i.getUsedVariables()) {
if (v instanceof LocalVariable && !v.isSelf()) {
LocalVariable lv = (LocalVariable)v;
if (lv.getScopeDepth() == 0) {
// SSS FIXME: Ugly/Dirty! Some abstraction is broken.
// If we hit a load/store instr for a local-var and we
// eliminated the dynscope for it, we no longer need the
// load/store instr for it.
if (i instanceof LoadLocalVarInstr) {
LoadLocalVarInstr llvi = (LoadLocalVarInstr)i;
if (llvi.getLocalVar() == lv) {
instrs.remove();
}
} else if (i instanceof StoreLocalVarInstr) {
StoreLocalVarInstr slvi = (StoreLocalVarInstr)i;
if (slvi.getLocalVar() == lv) {
instrs.remove();
}
}
// Make sure there is a replacement tmp-var allocated for lv
setupLocalVarReplacement(lv, s, varRenameMap);
} else {
// SSS FIXME: Ugly/Dirty! Some abstraction is broken.
if (i instanceof LoadLocalVarInstr) {
LoadLocalVarInstr llvi = (LoadLocalVarInstr)i;
if (llvi.getLocalVar() == lv) {
llvi.decrementLVarScopeDepth();
}
} else if (i instanceof StoreLocalVarInstr) {
StoreLocalVarInstr slvi = (StoreLocalVarInstr)i;
if (slvi.getLocalVar() == lv) {
slvi.decrementLVarScopeDepth();
}
}
parentScopeNeeded = true;
decrementScopeDepth(lv, s, varRenameMap);
}
}
}
}
}
if (parentScopeNeeded) {
s.getFlags().add(IRFlags.REUSE_PARENT_DYNSCOPE);
}
// Rename all local var uses with their tmp-var stand-ins
for (BasicBlock b: s.getCFG().getBasicBlocks()) {
for (Instr i: b.getInstrs()) i.renameVars(varRenameMap);
}
// LVA information is no longer valid after this pass
// FIXME: Grrr ... this seems broken to have to create a new object to invalidate
(new LiveVariableAnalysis()).invalidate(s);