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/src/MLRISC/ra/ra-deadCodeE.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/ra/ra-deadCodeE.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 958 - (view) (download)

1 : monnier 496 (*
2 :     * This is a hack module for removing dead code that are discovered by
3 :     * the register allocator. This module acts as a wrapper
4 :     * for the generic RA flowgraph module.
5 :     *
6 :     * -- Allen
7 :     *)
8 :    
9 :     functor RADeadCodeElim
10 :     (Flowgraph : RA_FLOWGRAPH)
11 : leunga 744 ( (* check for dead code on these cellkinds only *)
12 : george 889 val cellkind : CellsBasis.cellkind -> bool
13 : leunga 744 (* Dead registers are stored here. *)
14 :     val deadRegs : bool IntHashTable.hash_table
15 :     (* Affected blocks *)
16 :     val affectedBlocks : bool IntHashTable.hash_table
17 : george 889 val spillInit : Flowgraph.G.interferenceGraph * CellsBasis.cellkind
18 : george 545 -> unit
19 : monnier 496 ) : RA_FLOWGRAPH =
20 :     struct
21 :     structure F = Flowgraph
22 :    
23 :     open F
24 :    
25 : george 545 (* We must save all the copy temporaries for this to work *)
26 : monnier 496 val mode = RACore.SAVE_COPY_TEMPS
27 :    
28 : george 545 fun isOn(flag,mask) = Word.andb(flag,mask) <> 0w0
29 :    
30 : monnier 496 (*
31 :     * New services that also removes dead code
32 :     *)
33 :     fun services f =
34 :     let val {build, spill, blockNum, instrNum, programPoint} = F.services f
35 :     (*
36 :     * The following build method marks all pseudo registers
37 :     * that are dead, and record their definition points.
38 :     *)
39 : george 545 fun findDeadCode(G.GRAPH{nodes, copyTmps, mode, ...}) =
40 : blume 733 let val dead = IntHashTable.insert deadRegs
41 :     val affected = IntHashTable.insert affectedBlocks
42 : monnier 496 val affectedList = app (fn d => affected(blockNum d, true))
43 :    
44 :     (* Mark all copy temporaries *)
45 : george 958 val marker = [{block=0,insn=0}]
46 : monnier 496 fun markCopyTmps [] = ()
47 :     | markCopyTmps(G.NODE{uses, ...}::tmps) =
48 :     (uses := marker; markCopyTmps tmps)
49 :     fun unmarkCopyTmps [] = ()
50 :     | unmarkCopyTmps(G.NODE{uses, ...}::tmps) =
51 :     (uses := []; unmarkCopyTmps tmps)
52 :    
53 :     fun enter(_, G.NODE{uses=ref [], defs, number=reg, ...}) =
54 :     (* This is dead, but make sure it is not a copy temporary.
55 :     * Those cannot be eliminated.
56 :     *)
57 :     (affectedList (!defs); dead(reg, true))
58 :     | enter _ = ()
59 :    
60 :     in markCopyTmps(!copyTmps);
61 : blume 733 IntHashTable.appi enter nodes;
62 : monnier 496 unmarkCopyTmps(!copyTmps);
63 : george 545 if isOn(mode, RACore.HAS_PARALLEL_COPIES) then ()
64 :     else copyTmps := [] (* clean up now *)
65 : monnier 496 end
66 :    
67 :     (*
68 :     * Build the graph, then remove dead code.
69 :     *)
70 :     fun buildIt(graph, kind) =
71 :     let val moves = build(graph, kind)
72 :     in if cellkind kind then findDeadCode(graph) else ();
73 :     moves
74 :     end
75 : george 545
76 :     fun spillIt(arg as {graph, cellkind, ...}) =
77 :     (spillInit(graph, cellkind); spill arg)
78 :    
79 :     in {build=buildIt, spill=spillIt, programPoint=programPoint,
80 : monnier 496 blockNum=blockNum, instrNum=instrNum}
81 :     end
82 :    
83 :     end

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