public void Allocate(BasicBlock <IRInstrList> block) { var blockLiveness = liveness[block]; var instrLiveness = LivenessAnalysis.ComputeLiveness(block, blockLiveness); var pool = RegisterPool.Create(baseOffset, globalVars); for (var i = 0; i < block.Content.Count; i++) { var instr = block.Content[i]; pool.CheckLiveness(instrLiveness[instr]); // Allocates if (instr.Operand1 != null) { instr.Operand1 = AllocateOperand(instr.Operand1, pool); } if (instr.Operand2 != null) { instr.Operand2 = AllocateOperand(instr.Operand2, pool); } } if (pool.SpillOffset - 1 > LocalSize) { LocalSize = pool.SpillOffset - 1; } baseOffset = pool.SpillOffset; }
private IIROperand AllocateOperand(IIROperand operand, RegisterPool pool) { if (operand is IRVariable) { var variable = (IRVariable)operand; StackSlot?slot; var reg = AllocateVariable(pool, variable, out slot); if (reg != null) { return new IRRegister(reg.Value) { SourceVariable = variable, Type = variable.Type } } ; variable.Annotation = slot.Value; return(new IRPointer { Register = IRRegister.BP, Offset = slot.Value.Offset, SourceVariable = variable, Type = variable.Type }); } return(operand); }
public static RegisterPool Create(int baseOffset, Dictionary <IRVariable, StackSlot> globalVars) { var pool = new RegisterPool(); pool.regAlloc = new IRVariable[NumRegisters]; pool.spillVars = new Dictionary <IRVariable, StackSlot>(globalVars); pool.SpillOffset = baseOffset; return(pool); }
IIROperand AllocateOperand(IIROperand operand, RegisterPool pool) { if (operand is IRVariable) { var variable = (IRVariable)operand; StackSlot?slot; var reg = AllocateVariable(pool, variable, out slot); if (reg != null) { return new IRRegister(reg.Value) { SourceVariable = variable, Type = variable.Type } } ; variable.Annotation = slot.Value; return(new IRPointer { Register = IRRegister.BP, Offset = slot.Value.Offset, SourceVariable = variable, Type = variable.Type }); } return(operand); } VMRegisters?AllocateVariable(RegisterPool pool, IRVariable var, out StackSlot?stackSlot) { stackSlot = pool.CheckSpill(var); if (stackSlot == null) { var allocReg = var.Annotation == null ? (VMRegisters?)null : (VMRegisters)var.Annotation; if (allocReg == null) { allocReg = pool.Allocate(var); } if (allocReg != null) { if (var.Annotation == null) { var.Annotation = allocReg.Value; } return(allocReg); } // Spill variable stackSlot = pool.SpillVariable(var); } return(null); } }
private VMRegisters?AllocateVariable(RegisterPool pool, IRVariable var, out StackSlot?stackSlot) { stackSlot = pool.CheckSpill(var); if (stackSlot == null) { var allocReg = var.Annotation == null ? (VMRegisters?)null : (VMRegisters)var.Annotation; if (allocReg == null) { allocReg = pool.Allocate(var); } if (allocReg != null) { if (var.Annotation == null) { var.Annotation = allocReg.Value; } return(allocReg); } // Spill variable stackSlot = pool.SpillVariable(var); } return(null); }