diff python/codegenarm.py @ 277:046017431c6a

Started register allocator
author Windel Bouwman
date Thu, 26 Sep 2013 21:14:25 +0200
parents 56d37ed4b4d2
children 2ccd57b1d78c
line wrap: on
line diff
--- a/python/codegenarm.py	Mon Sep 16 21:51:17 2013 +0200
+++ b/python/codegenarm.py	Thu Sep 26 21:14:25 2013 +0200
@@ -3,7 +3,6 @@
 from target import Label, Comment, Alignment, LabelRef, Imm32, DebugInfo
 import cortexm3 as arm
 from ppci import CompilerError
-import flowgraph
 import registerallocator
 from instructionselector import InstructionSelector
 import irmach
@@ -210,59 +209,26 @@
         # TODO: schedule traces in better order.
         # This is optional!
         self.ins_sel = ArmInstructionSelector()
+        self.ra = registerallocator.RegisterAllocator()
         self.outs = outs
         self.outs.getSection('code').address = 0x08000000
         self.outs.getSection('data').address = 0x20000000
 
-    def useUnused(self, inslist):
-        # Use unused temporaries at the end of the list
-        defTemps = []
-        useTemps = []
-        for i in inslist:
-            for d in iter(i.dst):
-                defTemps.append(d)
-            for s in iter(i.src):
-                useTemps.append(s)
-        defTemps = set(defTemps)
-        useTemps = set(useTemps)
-        unUsed = defTemps - useTemps
-        assert not unUsed
-        for uu in unUsed:
-            inslist.append(irmach.AbstractInstruction('use %s0', src=[uu]))
-        #print(useTemps)
-
-    def allocFrame(self, f):
-        """
-            Do register allocation for a single stack frame.
-        """
-        ilist = f.instructions
-        self.useUnused(ilist)
-        cfg = flowgraph.FlowGraph(ilist)
-        f.cfg = cfg
-        ig = registerallocator.InterferenceGraph(cfg)
-        f.ig = ig
-
-        ra = registerallocator.RegisterAllocator()
-        regMap = ra.registerAllocate(ig, f.regs, f.tempMap)
-        # Use allocated registers:
-        for i in ilist:
-            i.src = tuple(regMap[t] for t in i.src)
-            i.dst = tuple(regMap[t] for t in i.dst)
-
     def generateFunc(self, irfunc):
         # Create a frame for this function:
         frame = ArmFrame(irfunc.name)
+
         # Canonicalize the intermediate language:
         canon.make(irfunc, frame)
-        # print('after canonicalize:')
-        # irfunc.dump()
+        print('after canonicalize:')
+        irfunc.dump()
         self.ins_sel.munchFunction(irfunc, frame)
-        # print('Selected instructions:')
-        #for i in frame.instructions:
-        #    print(i)
+        print('Selected instructions:')
+        for i in frame.instructions:
+            print(i)
         
         # Do register allocation:
-        self.allocFrame(frame)
+        self.ra.allocFrame(frame)
         # TODO: Peep-hole here?
 
         # Add label and return and stack adjustment: