-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac66811
commit 5dafc5f
Showing
49 changed files
with
349 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Skeleton 5 | ||
d2f9d"Flow"d"List"d"Temp"d"Assem"Cd"Canon"d"Parse"d"TextIO"d"MIPSGen"d"MakeGraph"Nad"Main"h3aä¢F"gp1d"MIPSFrame"aä¢Tr"jgp1ÿgp1e"Translate"ad"S"jgp1ÿ1gp1e"Semant" | ||
d2f7d"Flow"d"List"Cd"Temp"d"Assem"d"Canon"d"Parse"d"TextIO"Cd"MIPSGen"d"Liveness"d"MakeGraph"d"Printtree"d"PrintAbsyn"Nad"Main"h3aä¢F"gp1d"MIPSFrame"aä¢Tr"jgp1ÿ‚gp1e"Translate"ad"S"jgp1ÿ‚gp1e"Semant" |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Skeleton 5 | ||
d2f2d"Int"d"Temp"ad"Flow"h2ad"G"jgp1d"NodeKey"gp1e"FuncGraph"ad"T"jh0gp1e"IntMapTable" | ||
d2f4d"Int"d"Char"d"Temp"d"String"ad"Flow"h2ad"G"jgp1d"NodeKey"gp1e"FuncGraph"ad"T"jh0gp1e"IntMapTable" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Skeleton 5 | ||
d3f2d"Flow"d"Temp"a�LIVENESS"h0ad"Liveness"jh1ad"G"jgp1d"NodeKey"gp1e"FuncGraph"gp1� | ||
d2f4d"Int"ä˘Flow"d"List"ä˘Temp"ad"Liveness"h3ad"TempSet"gp2˙d"Set"ad"TempMap"gp2˙d"Map"aä˘G"gp2˙ | ||
˙ |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,124 @@ | ||
signature LIVENESS = | ||
(* signature LIVENESS = | ||
sig | ||
type igraph | ||
type node | ||
type live | ||
type livegraph | ||
(* val interferenceGraph : Flow.flowgraph -> igraph * (node -> Temp.temp list) | ||
val show : outstream * igraph -> unit *) | ||
end | ||
val flowToLiveGraph : Flow.graph -> livegraph | ||
val showLiveGraph : livegraph -> unit | ||
structure Liveness : LIVENESS = | ||
end *) | ||
|
||
structure Liveness (*: LIVENESS*) = | ||
struct | ||
structure G = FuncGraph (NodeKey) | ||
type igraph = G.graph | ||
type node = Flow.node | ||
datatype igraph = IGRAPH of {graph: igraph, | ||
structure TempSet = Temp.Set | ||
structure TempMap = Temp.Map | ||
structure G = Flow.G | ||
|
||
type temp_set = TempSet.set | ||
|
||
type node = Temp.temp G.node | ||
datatype igraph = IGRAPH of {graph: Temp.temp G.graph, | ||
tnode: Temp.temp -> node, | ||
gtemp: node -> Temp.temp, | ||
moves: (node * node) list} | ||
|
||
|
||
type live = {def: Temp.set, | ||
use: Temp.set, | ||
move: (Temp.temp * Temp.temp) option, | ||
liveIn: Temp.set, | ||
liveOut: Temp.set} | ||
|
||
type livegraph = live G.graph | ||
|
||
(* Calculates liveness and adds that info to flow graph *) | ||
fun flowToLiveGraph (flow : Flow.node G.graph) : livegraph = | ||
let fun convertFlowToLive () = | ||
(* Copy original graph (only nodes) *) | ||
let fun init (flowNode : Flow.node Flow.G.node, liveGraph : livegraph) = | ||
let val nid = G.getNodeID (flowNode) | ||
val (assm, def, use, move, jump) = G.nodeInfo (flowNode) | ||
val newInfo = {def=TempSet.addList (TempSet.empty, def), | ||
use=TempSet.addList (TempSet.empty, use), | ||
move=move, | ||
liveIn=Temp.Set.empty, | ||
liveOut=Temp.Set.empty} | ||
in G.addNode (liveGraph, nid, newInfo) | ||
end | ||
|
||
(* Copy the edges *) | ||
fun copyEdges (oldNode, newGraph) = | ||
let val nid = G.getNodeID (oldNode) | ||
val oldInfo = G.nodeInfo (oldNode) | ||
val oldSuccs = G.succs (oldNode) | ||
val newNode = G.getNode (newGraph, nid) | ||
in List.foldl (fn (succ, graph) => G.addEdge (graph, {from=nid, to=succ})) newGraph oldSuccs | ||
end | ||
|
||
fun iterateLiveness (edgedGraph) = | ||
let fun iterGraph (nid, graph) = | ||
let val node = G.getNode (graph, nid) | ||
|
||
val info = G.nodeInfo node | ||
val {def=def, use=use, move=move, liveIn=oldLiveIn, liveOut=oldLiveOut} = info | ||
|
||
val succs = G.succs (node) | ||
val preds = G.preds (node) | ||
|
||
val newLiveIn = TempSet.union (use, (TempSet.difference (oldLiveOut, def))) | ||
val newLiveOut = foldl (fn (nid, set) => let val iterNode = G.getNode (graph, nid) | ||
val lIn = #liveIn (G.nodeInfo iterNode) | ||
in TempSet.union (set, lIn) | ||
end) TempSet.empty succs | ||
val unchanged : bool = ((TempSet.equal (oldLiveIn, newLiveIn)) andalso (TempSet.equal (oldLiveOut, newLiveOut))) | ||
val newInfo = {def=def, use=use, move=move, liveIn=newLiveIn, liveOut=newLiveOut} | ||
val newGraph = G.changeNodeData (graph, nid, newInfo) | ||
in (unchanged, newGraph) | ||
end | ||
|
||
fun untilUnchanged (true, graph) = graph | ||
| untilUnchanged (false, graph) = | ||
untilUnchanged (G.foldNodes (fn (node, (unchanged, graph)) => | ||
(let val nid = G.getNodeID(node) | ||
val (newUnchanged, newGraph) = iterGraph (nid, graph) | ||
in (unchanged andalso newUnchanged, newGraph) | ||
end )) (true, graph) graph) | ||
in untilUnchanged (false, edgedGraph) | ||
end | ||
|
||
val initializedGraph : livegraph = G.foldNodes init G.empty flow | ||
val edgedGraph : livegraph = G.foldNodes copyEdges initializedGraph flow | ||
val liveGraph : livegraph = iterateLiveness edgedGraph | ||
|
||
in liveGraph | ||
end | ||
in convertFlowToLive () | ||
end | ||
|
||
(* Uses a flow graph with liveness info to make an interference graph *) | ||
(* fun interferenceGraph (flow) = let val liveGraph = flowToLiveGraph flow | ||
in {graph=graph, | ||
tnode=tnode, | ||
gtemp=gtemp, | ||
moves=moves} | ||
end *) | ||
|
||
fun moveToString (SOME (t1, t2)) = (Temp.makestring t1 ^ " <- " ^ Temp.makestring t2) | ||
| moveToString (NONE) = "N/A" | ||
|
||
fun showLiveGraph (liveGraph : livegraph) = | ||
(print "\n--- Live Graph: --- \n"; | ||
G.printGraph (fn (nid, liveObj:live) => | ||
let val liveIn : Temp.set = #liveIn liveObj | ||
val liveOut : Temp.set = #liveOut liveObj | ||
val move = #move liveObj | ||
in ("nid = " ^ (Int.toString nid) ^ " \tliveIn: " ^ (Temp.tempSetToString liveIn) ^ | ||
" \tliveOut: " ^ (Temp.tempSetToString liveOut) ^ | ||
" \tmove: " ^ (moveToString move)) | ||
end) liveGraph false) | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.