public RegisterAllocationResult Allocate( InterferenceCopyGraphPair query, IReadOnlyCollection <HardwareRegister> allowedHardwareRegisters) { var allowedRegistersCount = allowedHardwareRegisters.Count; query = new InterferenceCopyGraphPair( query.InterferenceGraph, RemoveUnavailableHWRegisters(query.CopyGraph, allowedHardwareRegisters)); var allRegisters = query.GetAllRegisters(); var superVertices = allRegisters .ToDictionary( x => x, x => new HashSet <VirtualRegister> { x }); var interference = RegisterAllocatorUtils.GetGraph(allRegisters, superVertices, query.InterferenceGraph); interference.AddHardwareRegisterClique(superVertices); var copy = RegisterAllocatorUtils.GetGraph(allRegisters, superVertices, query.CopyGraph); var coalescingProcess = new CoalescingProcess(interference, copy, superVertices, allowedRegistersCount); var registerSorter = new RegisterSorter( interference, copy, superVertices, allRegisters, coalescingProcess, allowedHardwareRegisters.Count); var order = registerSorter.GetOrder().ToList(); var verticesEnumerable = allRegisters.Select(register => superVertices[register]); var vertices = new HashSet <HashSet <VirtualRegister> >(verticesEnumerable); var finalInterference = FinalGraph(allRegisters, superVertices, query.InterferenceGraph); var finalCopy = FinalGraph(allRegisters, superVertices, query.CopyGraph); var registerPainter = new RegisterPainter(finalInterference, finalCopy, superVertices); return(registerPainter.GetColoring(vertices, allowedHardwareRegisters, order, allRegisters)); }
public RegisterSorter( Graph interference, Graph copy, Dictionary <VirtualRegister, HashSet <VirtualRegister> > superVertices, IReadOnlyCollection <VirtualRegister> allRegisters, CoalescingProcess coalescingProcess, int allowedHardwareRegistersCount) { this.interference = interference; this.copy = copy; this.superVertices = superVertices; this.coalescingProcess = coalescingProcess; this.allowedHardwareRegistersCount = allowedHardwareRegistersCount; this.allRegisters = allRegisters; this.containHardware = new HashSet <HashSet <VirtualRegister> >(allRegisters .OfType <HardwareRegister>() .Select(x => superVertices[x])); this.resultStack = new Stack <HashSet <VirtualRegister> >(); this.coalescingProcess.ContainHardware = this.containHardware; }