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/flowgraph/cfg.sig
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/flowgraph/cfg.sig

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1125 - (view) (download) (as text)

1 : jhr 926 (* cfg.sig
2 :     *
3 :     * COPYRIGHT (c) 2001 Bell Labs, Lucent Technologies
4 :     *
5 : george 906 * Control flow graph data structure used by the MLRISC IR.
6 :     * All basic optimizations are based on this representation.
7 :     *
8 :     * -- Allen
9 :     *)
10 :    
11 :     signature CONTROL_FLOW_GRAPH =
12 :     sig
13 :    
14 :     structure P : PSEUDO_OPS
15 :     structure I : INSTRUCTIONS
16 :    
17 : jhr 1125 (* used to represent frequency of execution; we use reals because some
18 :     * static prediction methods produce such.
19 :     *)
20 :     type weight = real
21 : george 906
22 :     datatype block_kind =
23 :     START (* entry node *)
24 :     | STOP (* exit node *)
25 :     | NORMAL (* normal node *)
26 :    
27 :     (*
28 : george 984 * NOTE 1: the instructions are listed in reverse order.
29 : george 906 * This choice is for a few reasons:
30 :     *
31 :     * i) Clusters represent instructions in reverse order, so keeping this
32 :     * the same avoid having to do conversions.
33 :     *
34 :     * ii) This makes it easier to add instructions at the end of the block,
35 :     * which is more common than adding instructions to the front.
36 :     *
37 :     * iii) This also makes it easier to manipulate the branch/jump instruction
38 :     * at the end of the block.
39 : george 984 *
40 :     * NOTE 2:
41 :     * Alignment always appear before labels in a block.
42 : george 906 *)
43 :    
44 :     and block =
45 :     BLOCK of
46 :     { id : int, (* block id *)
47 :     kind : block_kind, (* block kind *)
48 :     freq : weight ref, (* execution frequency *)
49 :     labels : Label.label list ref, (* labels on blocks *)
50 :     insns : I.instruction list ref, (* in rev order *)
51 : george 984 align : P.pseudo_op option ref, (* alignment only *)
52 : george 906 annotations : Annotations.annotations ref (* annotations *)
53 :     }
54 :    
55 :    
56 : jhr 1084 (* We have the following invariant on blocks and out-edge kinds:
57 :     *
58 :     * If the last instruction of the block is an unconditional jump, then
59 :     * there is one out edge labeled with JUMP.
60 :     *
61 :     * If the last instruction of the block is a conditional jump, then
62 :     * there are two out edges. The one corresponding to the jump is
63 :     * labeled BRANCH(true) and the other is labeled BRANCH(false).
64 :     *
65 :     * If the last instruction of the block is not a jump, then there is
66 :     * one out edge labeled with FALLSTHRU.
67 :     *
68 :     * If the block ends with a switch, then the out edges are labeled with
69 :     * SWITCH.
70 :     *
71 :     * If the block ends with a call that has been wrapped with a FLOW_TO,
72 :     * then there will be one FALLSTHRU out edges and one or more FLOWSTO
73 :     * out edges.
74 : jhr 1107 *
75 :     * Control-flow to outside the CFG is represented by edges to the unique
76 :     * STOP node. When such edges are to labels that are defined outside
77 :     * the CFG, then JUMP, BRANCH, or SWITCH edges are used (as appropriate).
78 :     * When such edges are to unkonwn places (e.g., traps, returns, and
79 :     * indirect jumps), then an EXIT edge is used. There should never be
80 :     * a FALLSTHRU or ENTRY edge to the STOP node.
81 : jhr 1084 *)
82 :     and edge_kind (* edge kinds *)
83 : jhr 1107 = ENTRY (* edge from START node *)
84 :     | EXIT (* unlabeled edge to STOP node *)
85 : jhr 1084 | JUMP (* unconditional jump *)
86 :     | FALLSTHRU (* falls through to next block *)
87 :     | BRANCH of bool (* branch *)
88 :     | SWITCH of int (* computed goto *)
89 :     | FLOWSTO (* FLOW_TO edge *)
90 :    
91 :     and edge_info = EDGE of {
92 :     k : edge_kind, (* edge kind *)
93 :     w : weight ref, (* edge freq *)
94 :     a : Annotations.annotations ref (* annotations *)
95 :     }
96 : george 906
97 :     type edge = edge_info Graph.edge
98 :     type node = block Graph.node
99 :    
100 :     datatype info =
101 :     INFO of { annotations : Annotations.annotations ref,
102 :     firstBlock : int ref, (* id of first block *)
103 : george 984 reorder : bool ref, (* has the CFG been reordered? *)
104 :     data : P.pseudo_op list ref (* reverse order of generation *)
105 : george 906 }
106 :    
107 :     type cfg = (block,edge_info,info) Graph.graph
108 :    
109 :     (*========================================================================
110 :     *
111 :     * Various kinds of annotations on basic blocks
112 :     *
113 :     *========================================================================*)
114 :     val LIVEOUT : I.C.cellset Annotations.property
115 :     (* escaping live out information *)
116 :     val CHANGED : (string * (unit -> unit)) Annotations.property
117 :    
118 :     (*========================================================================
119 :     *
120 :     * Methods for manipulating basic blocks
121 :     *
122 :     *========================================================================*)
123 : jhr 1125 val newBlock : int * weight ref -> block (* empty *)
124 :     val newStart : int * weight ref -> block (* start node *)
125 :     val newStop : int * weight ref -> block (* stop node *)
126 :     val copyBlock : int * block -> block (* copy a block *)
127 :     val defineLabel : block -> Label.label (* define a label *)
128 : george 906 val insns : block -> I.instruction list ref
129 : jhr 1125 val freq : block -> weight ref
130 : george 906 val branchOf : edge_info -> bool option
131 :    
132 :     (* emit assembly *)
133 : jhr 926 val emit : Annotations.annotations -> block -> unit
134 : george 906
135 :     (*========================================================================
136 :     *
137 :     * Methods for manipulating CFG
138 :     *
139 :     *========================================================================*)
140 :     val cfg : info -> cfg (* create a new cfg *)
141 :     val new : unit -> cfg (* create a new cfg *)
142 :     val subgraph : cfg -> cfg (* mark as subgraph *)
143 :     val init : cfg -> unit (* add start/stop nodes *)
144 :     val changed : cfg -> unit (* mark cfg as changed *)
145 :    
146 :     val annotations : cfg -> Annotations.annotations ref
147 :     val liveOut : block -> I.C.cellset
148 :     val fallsThruFrom : cfg * Graph.node_id -> Graph.node_id option
149 :     val fallsThruTo : cfg * Graph.node_id -> Graph.node_id option
150 :     val removeEdge : cfg -> edge -> unit
151 :     val setBranch : cfg * Graph.node_id * bool -> I.instruction
152 :     val edgeDir : edge_info Graph.edge -> bool option
153 :    
154 :     (*========================================================================
155 :     *
156 :     * For viewing
157 :     *
158 :     *========================================================================*)
159 :     (*****
160 :     val viewStyle : cfg -> (block,edge_info,info) GraphLayout.style
161 :     val viewLayout : cfg -> GraphLayout.layout
162 :     val headerText : block -> string
163 :     val footerText : block -> string
164 :     val subgraphLayout : { cfg : cfg, subgraph : cfg } -> GraphLayout.layout
165 :     *****)
166 :    
167 :     (*========================================================================
168 :     *
169 :     * Miscellaneous stuff
170 :     *
171 :     *========================================================================*)
172 :     val cdgEdge : edge_info -> bool (* for building a CDG *)
173 :    
174 : jhr 926 (*========================================================================
175 :     *
176 :     * Methods for printing CFGs
177 :     *
178 :     *========================================================================*)
179 :     val show_block : Annotations.annotations -> block -> string
180 :     val show_edge : edge_info -> string
181 : jhr 1118 val dumpBlock : (TextIO.outstream * cfg) -> node -> unit
182 : jhr 1104 val dump : (TextIO.outstream * string * cfg) -> unit
183 : jhr 926
184 : george 906 end
185 :    

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