use of org.jikesrvm.compilers.opt.ir.BasicBlock in project JikesRVM by JikesRVM.
the class LICM method upto.
/**
* Visits the blocks between the late and the early position along
* their path in the dominator tree.
*
* @param earlyPos the early position
* @param lateBlock the late position
* @param inst the instruction to schedule
* @return the block with the smallest execution costs
*/
BasicBlock upto(Instruction earlyPos, BasicBlock lateBlock, Instruction inst) {
BasicBlock _origBlock = getOrigBlock(inst);
BasicBlock actBlock = lateBlock;
BasicBlock bestBlock = lateBlock;
BasicBlock earlyBlock = getBlock(earlyPos);
if (VM.VerifyAssertions) {
if (!dominator.dominates(earlyBlock.getNumber(), _origBlock.getNumber()) || !dominator.dominates(earlyBlock.getNumber(), lateBlock.getNumber())) {
SSA.printInstructions(ir);
VM.sysWriteln("> " + earlyBlock.getNumber() + ", " + _origBlock.getNumber() + ", " + lateBlock.getNumber());
VM.sysWriteln(inst.toString());
}
VM._assert(dominator.dominates(earlyBlock.getNumber(), _origBlock.getNumber()));
VM._assert(dominator.dominates(earlyBlock.getNumber(), lateBlock.getNumber()));
}
for (; ; ) {
/* is the actual block better (less frequent)
than the so far best block? */
if (frequency(actBlock) < frequency(bestBlock)) {
if (DEBUG) {
VM.sysWriteln("going from " + frequency(_origBlock) + " to " + frequency(actBlock));
}
bestBlock = actBlock;
}
/* all candidates checked? */
if (actBlock == earlyBlock) {
break;
}
/* walk up the dominator tree for next candidate*/
actBlock = dominator.getParent(actBlock);
}
if (bestBlock == _origBlock)
return null;
if (DEBUG)
VM.sysWriteln("best Block: " + bestBlock);
return bestBlock;
}
use of org.jikesrvm.compilers.opt.ir.BasicBlock in project JikesRVM by JikesRVM.
the class LICM method move.
void move(Instruction inst, BasicBlock to) {
BasicBlock _origBlock = getOrigBlock(inst);
Instruction cand = null;
/* find a position within bestBlock */
if (dominator.dominates(_origBlock.getNumber(), to.getNumber())) {
// moved down, so insert in from
Instruction last = null;
Enumeration<Instruction> e = to.forwardInstrEnumerator();
while (e.hasMoreElements()) {
cand = e.nextElement();
if (DEBUG)
VM.sysWriteln(cand.toString());
;
// skip labels, phis, and yieldpoints
if (!Label.conforms(cand) && !cand.isYieldPoint() && !Phi.conforms(cand)) {
break;
}
last = cand;
}
cand = last;
} else {
// moved up, so insert at end of block
Enumeration<Instruction> e = to.reverseInstrEnumerator();
while (e.hasMoreElements()) {
cand = e.nextElement();
if (DEBUG)
VM.sysWriteln(cand.toString());
// skip branches and newly placed insts
if (!BBend.conforms(cand) && !cand.isBranch() && !relocated.contains(cand)) {
break;
}
}
if (DEBUG)
VM.sysWriteln("Adding to relocated: " + inst);
relocated.add(inst);
}
if (DEBUG && moved.add(inst.operator())) {
VM.sysWriteln("m(" + (ir.isLIR() ? "l" : "h") + ") " + inst.operator());
}
if (VERBOSE) {
VM.sysWrite(ir.isLIR() ? "%" : "#");
VM.sysWriteln(" moving " + inst + " from " + _origBlock + " to " + to + "\n" + "behind " + cand);
}
inst.remove();
cand.insertAfter(inst);
}
use of org.jikesrvm.compilers.opt.ir.BasicBlock in project JikesRVM by JikesRVM.
the class LICM method scheduleLate.
BasicBlock scheduleLate(Instruction inst) {
if (DEBUG)
VM.sysWriteln("Schedule Late: " + inst);
BasicBlock lateBlock = null;
int _state = getState(inst);
if (_state == late || _state == done)
return getBlock(inst);
setState(inst, late);
if (ir.options.FREQ_FOCUS_EFFORT) {
BasicBlock _origBlock = getOrigBlock(inst);
if (_origBlock.getInfrequent()) {
return _origBlock;
}
}
// explicitly INCLUDE instructions
if (!shouldMove(inst, ir)) {
return getOrigBlock(inst);
}
// dependencies via scalar operands
lateBlock = scheduleScalarUsesLate(inst, lateBlock);
if (DEBUG)
VM.sysWriteln("lateBlock1: " + lateBlock + " for " + inst);
// dependencies via heap operands
if (ir.isHIR()) {
lateBlock = scheduleHeapUsesLate(inst, lateBlock);
if (DEBUG)
VM.sysWriteln("lateBlock2: " + lateBlock + " for " + inst);
}
// if there are no uses, this instruction is dead.
if (lateBlock == null) {
if (VERBOSE)
VM.sysWriteln("deleting " + inst);
inst.remove();
} else {
if (DEBUG && lateBlock != getOrigBlock(inst)) {
VM.sysWriteln("new lateBlock: " + lateBlock + " for " + getOrigBlock(inst) + ": " + inst);
}
BasicBlock to = upto(getEarlyPos(inst), lateBlock, inst);
if (to == null) {
lateBlock = getOrigBlock(inst);
} else {
if (VM.VerifyAssertions)
VM._assert(getState(inst) != done);
lateBlock = to;
if (getOrigBlock(inst) != to)
move(inst, to);
}
}
setState(inst, done);
setBlock(inst, lateBlock);
return lateBlock;
}
use of org.jikesrvm.compilers.opt.ir.BasicBlock in project JikesRVM by JikesRVM.
the class LeaveSSA method translateFromSSA.
/**
* Main driver to translate an IR out of SSA form.
*
* @param ir the IR in SSA form
*/
public void translateFromSSA(IR ir) {
// 0. Deal with guards (validation registers)
unSSAGuards(ir);
// 1. re-compute dominator tree in case of control flow changes
LTDominators.perform(ir, true, true);
DominatorTree dom = new DominatorTree(ir, true);
// 1.5 Perform Sreedhar's naive translation from TSSA to CSSA
// if (ir.options.UNROLL_LOG == 0) normalizeSSA(ir);
// 2. compute liveness
LiveAnalysis live = new // don't create GC maps
LiveAnalysis(// don't create GC maps
false, // skip (final) local propagation step
true, // don't store information at handlers
false, // don't skip guards
false);
live.perform(ir);
// 3. initialization
VariableStacks s = new VariableStacks();
// 4. convert phi nodes into copies
BasicBlock b = ((DominatorTreeNode) dom.getRoot()).getBlock();
insertCopies(b, dom, live);
// 5. If necessary, recompute dominators to account for new control flow.
if (splitSomeBlock) {
LTDominators.perform(ir, true, true);
dom = new DominatorTree(ir, true);
}
// 6. compensate for copies required by simultaneous liveness
performRename(b, dom, s);
// 7. phis are now redundant
removeAllPhis(ir);
}
use of org.jikesrvm.compilers.opt.ir.BasicBlock in project JikesRVM by JikesRVM.
the class LeaveSSA method performRename.
// substitute variables renamed in control parents
private void performRename(BasicBlock bb, DominatorTree dom, VariableStacks s) {
if (DEBUG)
VM.sysWriteln("performRename: " + bb);
Enumeration<Instruction> e = bb.forwardRealInstrEnumerator();
while (e.hasMoreElements()) {
Instruction i = e.nextElement();
Enumeration<Operand> ee = i.getUses();
while (ee.hasMoreElements()) {
Operand o = ee.nextElement();
if (o instanceof RegisterOperand) {
Register r1 = ((RegisterOperand) o).getRegister();
if (r1.isValidation())
continue;
Operand r2 = s.peek(r1);
if (r2 != null) {
if (DEBUG) {
VM.sysWriteln("replace operand in " + i + "(" + r2 + " for " + o);
}
i.replaceOperand(o, r2.copy());
}
}
}
}
// record renamings required in children
e = bb.forwardRealInstrEnumerator();
while (e.hasMoreElements()) {
Instruction i = e.nextElement();
if (globalRenameTable.contains(i)) {
Register original = Move.getVal(i).asRegister().getRegister();
RegisterOperand rename = Move.getResult(i);
if (DEBUG)
VM.sysWriteln("record rename " + rename + " for " + original);
s.push(original, rename);
}
}
// insert copies in control children
Enumeration<TreeNode> children = dom.getChildren(bb);
while (children.hasMoreElements()) {
BasicBlock c = ((DominatorTreeNode) children.nextElement()).getBlock();
performRename(c, dom, s);
}
// pop renamings from this block off stack
e = bb.forwardRealInstrEnumerator();
while (e.hasMoreElements()) {
Instruction i = e.nextElement();
if (globalRenameTable.contains(i)) {
Register original = Move.getVal(i).asRegister().getRegister();
s.pop(original);
}
}
}
Aggregations