# Path: vis/irvis.py
# def showFunction(f):
# def renderFunctionToFile(f):
# 
# Path: vis/dagvis.py
# def showSelDAG(dg):
# 
# Path: vis/interferencevis.py
# def showInterferenceGraph(ig):


import target
import selectiondag
import instructionselector
import interference
import registerallocator
import ir
import function
from vis import irvis
from vis import dagvis
from vis import interferencevis
from passes import jumpfix
from passes import blockmerge
from passes import unused
from passes import branchreplace
from passes import constantfold
from passes import copypropagation
from passes import mem2reg
    
    def doInstructionSelection(self,func):
        for b in func:
            assigned = set()
            liveout = set()
            #XXX ugly code,move method somewhere?,  find vars that are used
            #outside the current block that need an edge to liveout
            for instr in b:
                assigned.update(instr.assigned)
                
            for other in func:
                if b != other:
                    for otherinstr in other:
                        for read in otherinstr.read:
                            if read in assigned:
                                liveout.add(read)
                                
            sd = selectiondag.SelectionDag(b,liveout)
            
            isel = instructionselector.InstructionSelector()
            if self.args.show_all or self.args.show_selection_dag:
                dagvis.showSelDAG(sd)
            
            self.dagFixups(sd)
            
            if self.args.show_all or self.args.show_selection_dag:
                dagvis.showSelDAG(sd)
            
            isel.select(self,sd)
            if self.args.show_all or self.args.show_md_selection_dag:

# Path: vis/irvis.py
# def showFunction(f):
# def renderFunctionToFile(f):
# 
# Path: vis/dagvis.py
# def showSelDAG(dg):
# 
# Path: vis/interferencevis.py
# def showInterferenceGraph(ig):


# Path: backend/standardmachine.py
import target
import selectiondag
import instructionselector
import interference
import registerallocator
import ir
import function
from vis import irvis
from vis import dagvis
from vis import interferencevis
from passes import jumpfix
from passes import blockmerge
from passes import unused
from passes import branchreplace
from passes import constantfold
from passes import copypropagation
from passes import mem2reg

    
    def doInstructionSelection(self,func):
        for b in func:
            assigned = set()
            liveout = set()
            #XXX ugly code,move method somewhere?,  find vars that are used
            #outside the current block that need an edge to liveout
            for instr in b:
                assigned.update(instr.assigned)
                
            for other in func:
                if b != other:
                    for otherinstr in other:
                        for read in otherinstr.read:
                            if read in assigned:
                                liveout.add(read)
                                
            sd = selectiondag.SelectionDag(b,liveout)
            
            isel = instructionselector.InstructionSelector()
            if self.args.show_all or self.args.show_selection_dag:
                dagvis.showSelDAG(sd)
            
            self.dagFixups(sd)
            
            if self.args.show_all or self.args.show_selection_dag:
                dagvis.showSelDAG(sd)
            
            isel.select(self,sd)
            if self.args.show_all or self.args.show_md_selection_dag:

                dagvis.showSelDAG(sd)