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); }