Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/compiler/CodeGen/main/machine-gen.sml
ViewVC logotype

Annotation of /sml/trunk/compiler/CodeGen/main/machine-gen.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2162 - (view) (download)

1 : monnier 427 (*
2 :     * This is a generic functor that hooks everything together
3 :     * into an MLRISC backend.
4 :     *)
5 :    
6 :     functor MachineGen
7 :     (structure MachSpec : MACH_SPEC (* machine specifications *)
8 : blume 773 structure Ext : SMLNJ_MLTREE_EXT
9 : george 909 structure InsnProps : INSN_PROPERTIES (* instruction properties *)
10 : monnier 427 structure CpsRegs : CPSREGS (* CPS registers *)
11 : george 909 where T.Region=CPSRegions
12 :     and T.Constant=SMLNJConstant
13 :     and T.Extension=Ext
14 : george 984 structure ClientPseudoOps : SMLNJ_PSEUDO_OPS
15 :     structure PseudoOps : PSEUDO_OPS (* pseudo ops *)
16 :     where T = CpsRegs.T
17 :     and Client = ClientPseudoOps
18 : monnier 427 structure MLTreeComp : MLTREECOMP (* instruction selection *)
19 : george 984 where I = InsnProps.I
20 :     and TS.T = CpsRegs.T
21 :     and TS.S.P = PseudoOps
22 : monnier 427 structure Asm : INSTRUCTION_EMITTER (* assembly *)
23 : george 984 where S.P = PseudoOps
24 : george 909 and I = MLTreeComp.I
25 : george 555 structure Shuffle : SHUFFLE (* shuffling copies *)
26 : george 909 where I = Asm.I
27 : monnier 427 structure BackPatch : BBSCHED (* machine code emitter *)
28 : george 909 where CFG = MLTreeComp.CFG
29 :     structure RA : CFG_OPTIMIZATION (* register allocator *)
30 :     where CFG = BackPatch.CFG
31 : blume 773 structure CCalls : C_CALLS (* native C call generator *)
32 : george 909 where T = CpsRegs.T
33 :     structure OmitFramePtr : OMIT_FRAME_POINTER
34 :     where CFG=RA.CFG
35 : mblume 1886
36 :     val abi_variant : string option
37 : monnier 427 ) : MACHINE_GEN =
38 :     struct
39 :    
40 : george 909 structure G = Graph
41 :     structure CFG = BackPatch.CFG
42 :     structure P = InsnProps
43 :     structure I = CFG.I
44 :     structure Cells = I.C
45 : george 984 structure T = MLTreeComp.TS.T
46 :     structure Stream = MLTreeComp.TS
47 : george 909 structure Asm = Asm
48 :     structure Shuffle = Shuffle
49 :     structure MachSpec = MachSpec
50 : mblume 1886 val abi_variant = abi_variant
51 : george 909 structure MLTreeComp = MLTreeComp
52 : monnier 427
53 : george 1168
54 :     structure CFGViewer =
55 :     CFGViewer
56 :     (structure CFG = CFG
57 :     structure GraphViewer = GraphViewer(AllDisplays)
58 :     structure Asm = Asm)
59 :    
60 : george 1009 (* expand copies into their primitive moves.
61 :     * Copies are no longer treated as span dependent, which was a hack.
62 :     *)
63 :     structure ExpandCpys =
64 : george 1016 CFGExpandCopies
65 :     (structure CFG = CFG
66 :     structure Shuffle = Shuffle)
67 : george 1009
68 : george 1168 structure LoopProbs =
69 :     EstimateLoopProbsFn(structure CFG=CFG)
70 :    
71 : george 1136 structure ComputeFreqs =
72 :     ComputeFreqsFn(structure CFG=CFG)
73 :    
74 : george 1133 structure BlockPlacement =
75 :     BlockPlacement
76 :     (structure CFG = CFG
77 :     structure Props = InsnProps)
78 :    
79 : george 1168 structure CheckPlacement =
80 :     CheckPlacementFn
81 :     (structure CFG = CFG
82 :     structure InsnProps = InsnProps)
83 :    
84 : george 1141 (* After experimentation, some architecture specific control
85 :     * may be needed for chainEscapes.
86 :     *)
87 : george 1133 structure JumpChaining =
88 :     JumpChainElimFn
89 :     (structure CFG = CFG
90 : george 1141 structure InsnProps = InsnProps
91 :     val chainEscapes = ref false
92 :     val reverseDirection = ref false)
93 : george 1133
94 :     structure InvokeGC =
95 :     InvokeGC
96 :     (structure C = CpsRegs
97 :     structure MS = MachSpec
98 :     structure CFG = CFG
99 :     structure TS = MLTreeComp.TS
100 :     )
101 :    
102 : allenleung 1785 (*
103 :     * This module is used to check for gc bugs.
104 :     * It is turned off by default. You can turn it on
105 :     * with the flag "check-gc", and turn on verbose debugging
106 :     * with "debug-check-gc".
107 :     *)
108 :     structure CheckGC =
109 :     CheckGCFn
110 :     (structure Asm = Asm
111 :     structure CFG = CFG
112 :     structure InsnProps = InsnProps
113 :     structure CpsRegs = CpsRegs
114 :     val gcParamRegs = InvokeGC.gcParamRegs
115 :     )
116 :    
117 : george 1168 val graphical_view =
118 :     MLRiscControl.mkFlag
119 :     ("cfg-graphical-view",
120 :     "graphical view of cfg after block placement")
121 :    
122 :     val graphical_view_size =
123 :     MLRiscControl.mkInt
124 : george 1173 ("cfg-graphical-view-size",
125 : george 1168 "minimium threshold for size of graphical view")
126 :    
127 : george 909 fun omitFramePointer(cfg as G.GRAPH graph) = let
128 :     val CFG.INFO{annotations, ...} = #graph_info graph
129 :     in
130 : george 823 if #contains MLRiscAnnotations.USES_VIRTUAL_FRAME_POINTER (!annotations) then
131 : blume 838 (OmitFramePtr.omitframeptr
132 : george 909 {vfp=CpsRegs.vfp, cfg=cfg, idelta=SOME 0:Int32.int option};
133 :     cfg)
134 :     else cfg
135 :     end
136 : george 823
137 : george 1168 fun computeFreqs cfg =
138 :     (LoopProbs.estimate cfg; ComputeFreqs.compute cfg; cfg)
139 : george 1136
140 : george 909 type mlriscPhase = string * (CFG.cfg -> CFG.cfg)
141 : monnier 427
142 :     fun phase x = Stats.doPhase (Stats.makePhase x)
143 : george 555 fun makePhase(name,f) = (name, phase name f)
144 : monnier 427
145 : george 1009 val mc = phase "MLRISC BackPatch.bbsched" BackPatch.bbsched
146 : george 1133 val placement = phase "MLRISC Block placement" BlockPlacement.blockPlacement
147 :     val chainJumps = phase "MLRISC Jump chaining" JumpChaining.run
148 :     val finish = phase "MLRISC BackPatch.finish" BackPatch.finish
149 : george 1136 val compFreqs = phase "MLRISC Compute frequencies" computeFreqs
150 : george 1009 val ra = phase "MLRISC ra" RA.run
151 :     val omitfp = phase "MLRISC omit frame pointer" omitFramePointer
152 :     val expandCpys = phase "MLRISC expand copies" ExpandCpys.run
153 : allenleung 1785 val checkGC = phase "MLRISC check GC" CheckGC.checkGC
154 : george 1133
155 : george 555 val raPhase = ("ra",ra)
156 :    
157 : george 823 val optimizerHook =
158 : allenleung 1785 ref [("checkgc", checkGC),
159 :     ("compFreqs", compFreqs),
160 : george 1136 ("ra", ra),
161 : george 1009 ("omitfp", omitfp),
162 : allenleung 1785 ("expand copies", expandCpys),
163 :     ("checkgc", checkGC)
164 : george 823 ]
165 :    
166 : george 1133 fun compile cluster = let
167 : george 1168 fun runPhases([],cluster) = cluster
168 :     | runPhases((_,f)::phases,cluster) = runPhases(phases,f cluster)
169 : monnier 427
170 : george 1168 fun dumpBlocks cfg = let
171 :     val cbp as (cfg, blks) = chainJumps (placement cfg)
172 :     fun view () =
173 :     if !graphical_view andalso length blks >= !graphical_view_size
174 :     then CFGViewer.view cfg
175 :     else ()
176 :     in
177 :     CheckPlacement.check cbp;
178 :     view ();
179 :     mc cbp
180 :     end
181 : george 1133 in
182 : george 1168 dumpBlocks (runPhases(!optimizerHook,cluster))
183 : george 823 end
184 : monnier 498
185 : monnier 427 (* compilation of CPS to MLRISC *)
186 :     structure MLTreeGen =
187 : george 1133 MLRiscGen
188 :     (structure MachineSpec=MachSpec
189 :     structure MLTreeComp=MLTreeComp
190 :     structure Ext = Ext
191 :     structure C=CpsRegs
192 :     structure ClientPseudoOps =ClientPseudoOps
193 :     structure PseudoOp=PseudoOps
194 :     structure InvokeGC=InvokeGC
195 :     structure Flowgen=
196 :     BuildFlowgraph
197 :     (structure CFG = CFG
198 :     structure Props = InsnProps
199 :     structure Stream = MLTreeComp.TS.S
200 :     )
201 :     structure CCalls = CCalls
202 :     structure Cells = Cells
203 :     val compile = compile
204 :     )
205 : george 823
206 : monnier 498
207 : monnier 427 val gen = phase "MLRISC MLTreeGen.codegen" MLTreeGen.codegen
208 :    
209 :     fun codegen x =
210 :     (* initialize all hidden states first *)
211 :     (Label.reset();
212 :     InvokeGC.init();
213 :     BackPatch.cleanUp();
214 :     gen x
215 :     )
216 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0