use of org.jikesrvm.compilers.opt.ir.GenericPhysicalRegisterSet in project JikesRVM by JikesRVM.
the class ActiveSet method findAvailableRegister.
/**
* @param symb symbolic register to allocate
* @return a free physical register to allocate to the symbolic
* register, {@code null} if no free physical register is found
*/
Register findAvailableRegister(Register symb) {
GenericRegisterRestrictions restrict = ir.stackManager.getRestrictions();
// first attempt to allocate to the preferred register
if (ir.options.REGALLOC_COALESCE_MOVES) {
Register p = getPhysicalPreference(symb);
if (p != null) {
if (LinearScan.DEBUG_COALESCE) {
System.out.println("REGISTER PREFERENCE " + symb + " " + p);
}
return p;
}
}
GenericPhysicalRegisterSet phys = ir.regpool.getPhysicalRegisterSet();
int type = GenericPhysicalRegisterSet.getPhysicalRegisterType(symb);
// next attempt to allocate to a volatile
if (!restrict.allVolatilesForbidden(symb)) {
for (Enumeration<Register> e = phys.enumerateVolatiles(type); e.hasMoreElements(); ) {
Register p = e.nextElement();
if (allocateNewSymbolicToPhysical(symb, p)) {
return p;
}
}
}
// novolatiles backwards.
for (Enumeration<Register> e = phys.enumerateNonvolatilesBackwards(type); e.hasMoreElements(); ) {
Register p = e.nextElement();
if (allocateNewSymbolicToPhysical(symb, p)) {
return p;
}
}
// no allocation succeeded.
return null;
}
use of org.jikesrvm.compilers.opt.ir.GenericPhysicalRegisterSet in project JikesRVM by JikesRVM.
the class ActiveSet method allocateNewSymbolicToPhysical.
/**
* NOTE: This routine assumes we're processing the first interval of
* register symb; so p.isAvailable() is the key information needed.
*
* @param symb the symbolic register
* @param p the physical register
* @return whether it's ok to allocate the symbolic register to the physical
* register
*/
private boolean allocateNewSymbolicToPhysical(Register symb, Register p) {
GenericRegisterRestrictions restrict = ir.stackManager.getRestrictions();
GenericPhysicalRegisterSet phys = ir.regpool.getPhysicalRegisterSet();
if (p != null && !phys.isAllocatable(p))
return false;
if (LinearScan.VERBOSE_DEBUG && p != null) {
if (!p.isAvailable())
System.out.println("unavailable " + symb + p);
if (restrict.isForbidden(symb, p))
System.out.println("forbidden" + symb + p);
}
return (p != null) && p.isAvailable() && !restrict.isForbidden(symb, p);
}
use of org.jikesrvm.compilers.opt.ir.GenericPhysicalRegisterSet in project JikesRVM by JikesRVM.
the class GenericStackManager method getFirstFPRNotUsedIn.
/**
* Returns a FPR that does not appear in instruction s, to be used as a
* scratch register to hold register r.
* Except, does NOT return any register that is a member of the reserved set.
* <p>
* @param r the register that needs a scratch register
* @param s the instruction for which the scratch register is needed
* @param reserved the registers that must not be used
* @return a free FPR
* @throws OptimizingCompilerException if no free FPR was found
*/
private Register getFirstFPRNotUsedIn(Register r, Instruction s, ArrayList<Register> reserved) {
GenericPhysicalRegisterSet phys = ir.regpool.getPhysicalRegisterSet();
// first try the volatiles
for (Enumeration<Register> e = phys.enumerateVolatileFPRs(); e.hasMoreElements(); ) {
Register p = e.nextElement();
if (!appearsIn(p, s) && !p.isPinned() && !reserved.contains(p) && isLegal(r, p, s)) {
return p;
}
}
OptimizingCompilerException.TODO("Could not find a free FPR in spill situation");
return null;
}
use of org.jikesrvm.compilers.opt.ir.GenericPhysicalRegisterSet in project JikesRVM by JikesRVM.
the class IntervalAnalysis method perform.
/**
* compute live intervals for this ir
* the result is a sorted (by beginning point) set of compound
* intervals, stored in the private 'intervals' field.
*
* @param ir the ir
*/
@Override
public void perform(IR ir) {
this.ir = ir;
this.regAllocState = ir.MIRInfo.regAllocState;
ControlFlowGraph cfg = ir.cfg;
GenericPhysicalRegisterSet phys = ir.regpool.getPhysicalRegisterSet();
LinearScanState state = new LinearScanState();
ir.MIRInfo.linearScanState = state;
// create topological list and a reverse topological list
// the results are on listOfBlocks and reverseTopFirst lists
createTopAndReverseList(cfg);
// give dfn values to each instruction
assignDepthFirstNumbers(cfg);
// initialize registers
initializeRegisters();
int lastBeginSeen = -1;
// visit each basic block in the listOfBlocks list
for (BasicBlock bb = listOfBlocks; bb != null; bb = (BasicBlock) bb.nextSorted) {
// visit each live interval for this basic block
LiveInterval liveIntervals = ir.getLivenessInformation();
for (LiveIntervalElement live = liveIntervals.getFirstLiveIntervalElement(bb); live != null; live = live.getNext()) {
// begin.
if (VM.VerifyAssertions) {
int begin = regAllocState.getDfnBegin(live, bb);
VM._assert(begin >= lastBeginSeen);
lastBeginSeen = begin;
}
// skip registers which are not allocated.
if (live.getRegister().isPhysical() && !phys.isAllocatable(live.getRegister())) {
continue;
}
CompoundInterval resultingInterval = processLiveInterval(live, bb);
if (!bb.getInfrequent() && resultingInterval != null) {
resultingInterval.setFrequent();
}
}
}
// debug support
if (LinearScan.VERBOSE_DEBUG) {
VM.sysWriteln("**** start of interval dump " + ir.method + " ****");
VM.sysWrite(ir.MIRInfo.linearScanState.intervals.toString());
VM.sysWriteln("**** end of interval dump ****");
}
}
use of org.jikesrvm.compilers.opt.ir.GenericPhysicalRegisterSet in project JikesRVM by JikesRVM.
the class SpillCode method rewriteFPStack.
/**
* Rewrites floating point registers to reflect changes in stack
* height induced by BURS.
* <p>
* Side effect: update the fpStackHeight in MIRInfo.
*
* @param ir the IR to process
*/
private void rewriteFPStack(IR ir) {
GenericPhysicalRegisterSet phys = ir.regpool.getPhysicalRegisterSet();
for (Enumeration<BasicBlock> b = ir.getBasicBlocks(); b.hasMoreElements(); ) {
BasicBlock bb = b.nextElement();
// The following holds the floating point stack offset from its
// 'normal' position.
int fpStackOffset = 0;
for (Enumeration<Instruction> inst = bb.forwardInstrEnumerator(); inst.hasMoreElements(); ) {
Instruction s = inst.nextElement();
for (Enumeration<Operand> ops = s.getOperands(); ops.hasMoreElements(); ) {
Operand op = ops.nextElement();
if (op.isRegister()) {
RegisterOperand rop = op.asRegister();
Register r = rop.getRegister();
// Update MIR state for every physical FPR we see
if (r.isPhysical() && r.isFloatingPoint() && s.operator() != org.jikesrvm.compilers.opt.ir.ia32.ArchOperators.DUMMY_DEF && s.operator() != org.jikesrvm.compilers.opt.ir.ia32.ArchOperators.DUMMY_USE) {
int n = org.jikesrvm.compilers.opt.ir.ia32.PhysicalRegisterSet.getFPRIndex(r);
if (fpStackOffset != 0) {
n += fpStackOffset;
rop.setRegister(phys.getFPR(n));
}
ir.MIRInfo.fpStackHeight = Math.max(ir.MIRInfo.fpStackHeight, n + 1);
}
} else if (op instanceof BURSManagedFPROperand) {
int regNum = ((BURSManagedFPROperand) op).regNum;
s.replaceOperand(op, new RegisterOperand(phys.getFPR(regNum), TypeReference.Double));
}
}
// position.
if (s.operator().isFpPop()) {
fpStackOffset--;
} else if (s.operator().isFpPush()) {
fpStackOffset++;
}
if (VM.VerifyAssertions)
VM._assert(fpStackOffset >= 0);
}
}
}
Aggregations