Skip to content

Commit

Permalink
Several methods to retrieve info about nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
perezzini committed Nov 18, 2017
1 parent 6d1d314 commit 4e3b619
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
14 changes: 13 additions & 1 deletion tigerliveness.sig
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@ signature tigerliveness =
sig
type node

val getInstrFromNode : node -> tigerassem.instr

val getNumFromNode : node -> int

val compareNodes : node * node -> order

(* [calculateUseSet instr] returns a set of temporaries the instruction uses *)
val calculateUseSet : tigerassem.instr -> tigertemp.temp Splayset.set

(* [calculateDefSet instr] returns a set of temporaries the instruction defines *)
val calculateDefSet : tigerassem.instr -> tigertemp.temp Splayset.set

(* [calculateLiveOut instrList] returns a live-out set of registers for each instruction in the list
along with the instruction graph correspoding to the input *)
val calculateLiveOut : tigerassem.instr list -> tigertemp.temp Splayset.set list * node Splayset.set

(* [liveOutInfoToString instrList] returns a list of several strings of info, corresponding to each element
in the input list: assembly, node number, node successors, node live-out set of registers *)
in the input list: node's assembly, node's number, node's successors, and node's live-out set of registers *)
val liveOutInfoToString : tigerassem.instr list -> (string * string * string * string) list
end
54 changes: 29 additions & 25 deletions tigerliveness.sml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ struct
end
*)

fun getInstrFromNode (instr, _) = instr

fun getNumFromNode (_, n) = n

(* createLabelsTableFromGraph : node Splayset.set -> (string * int) Splaymap.dict *)
fun createLabelsTableFromGraph iGraph =
let
Expand Down Expand Up @@ -88,6 +92,28 @@ struct
utils.setMap toNode intSet compareNodes
end

(* calculateUseSet : tigerassem.instr -> tigertemp.temp Splayset.set *)
fun calculateUseSet instr =
let
val emptySet = Splayset.empty(String.compare)
in
case instr of
OPER {src, ...} => Splayset.addList(emptySet, src)
| MOVE {src ,...} => Splayset.add(emptySet, src)
| _ => emptySet
end

(* calculateDefSet : tigerassem.instr -> tigertemp.temp Splayset.set *)
fun calculateDefSet instr =
let
val emptySet = Splayset.empty(String.compare)
in
case instr of
OPER {dst, ...} => Splayset.addList(emptySet, dst)
| MOVE {dst ,...} => Splayset.add(emptySet, dst)
| _ => emptySet
end

(* calculateLiveOut : tigerassem.instr list -> tigertemp.temp Splayset.set list *)
fun calculateLiveOut instrList =
let
Expand All @@ -108,31 +134,9 @@ struct
val (liveInArray, liveOutArray) = (Array.array (List.length instrList, emptyStringSet),
Array.array (List.length instrList, emptyStringSet)) (* Init live-in and live-out arrays with empty temp-sets *)


(* calculateUseSet : node -> tigertemp.temp Splayset.set *)
fun calculateUseSet node =
let
val emptySet = Splayset.empty(String.compare)
in
case node of
(OPER {src, ...}, _) => Splayset.addList(emptySet, src)
| (MOVE {src ,...}, _) => Splayset.add(emptySet, src)
| _ => emptySet
end

(* calculateDefSet : node -> tigertemp.temp Splayset.set *)
fun calculateDefSet node =
let
val emptySet = Splayset.empty(String.compare)
in
case node of
(OPER {dst, ...}, _) => Splayset.addList(emptySet, dst)
| (MOVE {dst ,...}, _) => Splayset.add(emptySet, dst)
| _ => emptySet
end

(* computationByIteration : node list -> bool -> unit *)
fun computationByIteration (((node as (_, n)) :: nodes) : node list) flag =
fun computationByIteration (((node as (instr, n)) :: nodes) : node list) flag =
let
(* insertSetFromArray : node -> tigertemp.temp Splayset.set *)
fun insertSetFromArray (_, n) = Array.sub (liveInArray, n)
Expand All @@ -155,8 +159,8 @@ struct

val _ = Array.update (liveOutArray, n, List.foldl Splayset.union emptySet succNodes')

val diff = Splayset.difference(Array.sub (liveOutArray, n), calculateDefSet node)
val union = Splayset.union(calculateUseSet node, diff)
val diff = Splayset.difference(Array.sub (liveOutArray, n), calculateDefSet instr)
val union = Splayset.union(calculateUseSet instr, diff)

val _ = Array.update(liveInArray, n, union)

Expand Down

0 comments on commit 4e3b619

Please sign in to comment.