예제 #1
0
 public static ProgramBlock<MilocInstruction> DoOpt(ProgramBlock<MilocInstruction> prog)
 {
     var defs = new ReachingDef<MilocInstruction>(prog);
     var conv = prog.Convert(new MilocConverter<MilocInstruction>(new PowerReductionTranslator(defs)));
     return (ProgramBlock<MilocInstruction>)conv;
 }
예제 #2
0
        public ProgramBlock<SparcInstruction> DoAllocation(ProgramBlock<SparcInstruction> start)
        {
            numRegs = getMaxRegValue(start) + 1;
            spilleds = new BitArray(numRegs);

            while (true)
            {
                setupVars(start);
                doGenAndKill(start);
                doLiveoutSets(start);
                doGraph(start);
                var uncoloredRegs = colorGraph(start);

                if (uncoloredRegs.Select(r => r.Value.Count).Sum() == 0)
                    break;

                var regsToSpill = new BitArray(numRegs);

                foreach (var kvp in uncoloredRegs)
                {
                    if (kvp.Value.Count != 0)
                    {
                        var rToSpill = kvp.Value.Where(r => !spilleds[r]).Where(r => getSparcRegister(r) == null).First();
                        regsToSpill.Set(rToSpill, true);
                    }
                }

                spilleds.Or(regsToSpill);

                start = (ProgramBlock<SparcInstruction>)start.Convert(new SpillConverter(regsToSpill));

                //Console.WriteLine("spilled {0} regs, trying again", regsToSpill.TrueIndexs().Count());
            }

            //print(start);

            return (ProgramBlock<SparcInstruction>)start.Convert(new SparcRegisterConverter(colorMapping));
        }