File: cfg-restructure.sml

package info (click to toggle)
mlton 20210117%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,464 kB
  • sloc: ansic: 27,682; sh: 4,455; asm: 3,569; lisp: 2,879; makefile: 2,347; perl: 1,169; python: 191; pascal: 68; javascript: 7
file content (51 lines) | stat: -rw-r--r-- 1,724 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(*
 * This module inserts preheaders and other stuff.
 * This is probably no longer used.
 *
 * -- Allen
 *)

functor ControlFlowGraphRestructure
    (structure Loop : LOOP_STRUCTURE) : CONTROL_FLOW_GRAPH_RESTRUCTURE =
struct
   structure Loop = Loop
   structure G    = Graph

   fun restructure (G.GRAPH cfg,G.GRAPH loop) 
          { add_preheader, 
            add_landing_pad
          } =
   let val add_node = #add_node cfg
       fun preheader f =
           fn {header,backedges} =>
              let val in_edges = #in_edges cfg header
                  fun g([],entries) = entries
                    | g((e as (i,j,_))::es,entries) = 
                       if List.exists (fn (i',j',_) => i=i' andalso j=j') 
                            backedges then g(es,entries)
                                      else g(es,e::entries)
              in  f{header =(header,#node_info cfg header),
                    entries=g(in_edges,[])
                   }
              end

       fun landing_pads f = fn {exits} => app (fn e => f {exit=e}) exits

       fun nop _ = ()
       val insert_preheader    = case add_preheader of
                                   SOME f => preheader f
                                 | NONE   => nop
       val insert_landing_pads = case add_landing_pad of
                                   SOME f => landing_pads f
                                 | NONE   => nop
       fun process_loop(i,Loop.LOOP{header,backedges=[],exits,...}) = ()
         | process_loop(i,Loop.LOOP{header,backedges,exits,...}) =
          (insert_preheader{header=header,backedges=backedges};
           insert_landing_pads{exits=exits}
          )
   in 
       #forall_nodes loop process_loop
   end

end