X-Git-Url: http://git.joshuawise.com/snipe.git/blobdiff_plain/6ade8b0a3251e44b34c6bdbbd9403e36d6fd6231..5c79bb689ab446551bc7ec4497e6c9b75582837e:/codegen/liveness.sml diff --git a/codegen/liveness.sml b/codegen/liveness.sml index 24123b9..b030f94 100644 --- a/codegen/liveness.sml +++ b/codegen/liveness.sml @@ -7,22 +7,22 @@ signature LIVENESS = sig structure OperSet : ORD_SET - where type Key.ord_key = x86.oper; + where type Key.ord_key = x86.basicop; structure LiveMap : ORD_MAP where type Key.ord_key = int; - + type live = int * OperSet.set type pseudoasm = x86.insn list type livenesses = OperSet.set LiveMap.map type ident = int - datatype pred = DEF of x86.oper | USE of x86.oper | SUCC of ident | ISMOVE + datatype pred = DEF of x86.basicop | USE of x86.basicop | SUCC of ident | ISMOVE type predicates = pred list LiveMap.map - val uses : pred list -> x86.oper list + val uses : pred list -> x86.basicop list val succs : pred list -> ident list - val defs : pred list -> x86.oper list + val defs : pred list -> x86.basicop list val ismove : pred list -> bool val liveness : pseudoasm -> predicates * livenesses @@ -37,6 +37,10 @@ struct structure OperSet = x86.OperSet structure LiveMap = x86.LiveMap + structure LabelMap = SplayMapFn(struct + type ord_key = Label.label + val compare = Label.compare + end) type live = int * OperSet.set type pseudoasm = X.insn list @@ -44,8 +48,8 @@ struct type livenesses = OperSet.set LiveMap.map type ident = int - datatype pred = DEF of X.oper | USE of X.oper | SUCC of ident | ISMOVE - + datatype pred = DEF of X.basicop | USE of X.basicop | SUCC of ident | ISMOVE + type predicates = pred list LiveMap.map (* val number : pseudoasm -> numasm @@ -65,22 +69,25 @@ struct (* val defusesucc : numasm -> (ident * pred list) list * generates def/use/succ predicates according to rules *) - fun defusesucc l = let - fun findlabel (lb) = - Option.valOf - (LiveMap.foldri (fn (n, X.LABEL lb', NONE) => if (Label.compare (lb, lb') = EQUAL) then SOME n else NONE - | (_, _, old) => old) NONE l) - + val labelmap = LiveMap.foldri + (fn (n, a, b) => LabelMap.insert(b, a, n)) + (LabelMap.empty) + (LiveMap.mapPartial (fn (X.LABEL lb) => SOME(lb) | _ => NONE) l) + + fun findlabel (lb) = valOf (LabelMap.find (labelmap, lb)) + (* val defhit/usehit : X.oper -> pred list * helper functions to discard constant operands *) - fun defhit (X.REG a) = [DEF(X.REG a)] - | defhit (X.TEMP a) = [DEF(X.TEMP a)] + fun defhit (X.REG a,_) = [DEF(X.REG a)] + | defhit (X.TEMP a,_) = [DEF(X.TEMP a)] + | defhit (X.REL(o1, o2, _),_) = usehit o1 @ usehit o2 | defhit (_) = nil - fun usehit (X.REG a) = [USE(X.REG a)] - | usehit (X.TEMP a) = [USE(X.TEMP a)] + and usehit (X.REG a,_) = [USE(X.REG a)] + | usehit (X.TEMP a,_) = [USE(X.TEMP a)] + | usehit (X.REL(o1, o2, _),_) = usehit o1 @ usehit o2 | usehit (_) = nil fun callhit 0 = nil @@ -98,8 +105,9 @@ struct fun gendef (n, X.DIRECTIVE(_)) = (nil) | gendef (n, X.COMMENT(_)) = (nil) | gendef (n, X.LIVEIGN (_)) = ([SUCC (n+1)]) - | gendef (n, X.SIZE(_, i)) = gendef (n,i) | gendef (n, X.MOV(dest, src)) = (defhit dest @ usehit src @ [SUCC(n+1), ISMOVE]) + | gendef (n, X.MOVSC(dest, src)) = (defhit dest @ usehit src @ [SUCC(n+1)]) + | gendef (n, X.LEA(dest, src)) = (defhit dest @ usehit src @ [SUCC(n+1)]) | gendef (n, X.SUB(dest, src)) = (defhit dest @ usehit dest @ usehit src @ [SUCC(n+1)]) | gendef (n, X.IMUL(dest, src)) = (defhit dest @ usehit dest @ usehit src @ [SUCC(n+1)]) | gendef (n, X.IMUL3(dest, src, _)) = (defhit dest @ usehit src @ [SUCC(n+1)]) @@ -118,9 +126,10 @@ struct | gendef (n, X.CMP(dest, src)) = (usehit dest @ usehit src @ [SUCC(n+1)]) | gendef (n, X.TEST(dest, src)) = (usehit dest @ usehit src @ [SUCC(n+1)]) | gendef (n, X.SETcc(_,dest)) = (defhit dest @ [SUCC(n+1)]) + | gendef (n, X.CMOVcc(_,src, dest)) = (defhit dest @ usehit src @ [SUCC(n+1)]) | gendef (n, X.CALL(_, a)) = (callhit a @ [DEF(X.REG(X.EAX)), DEF(X.REG(X.ECX)), DEF(X.REG(X.EDX)), - DEF(X.REG(X.EDI)), DEF(X.REG(X.ESI)), DEF(X.REG(X.R8D)), - DEF(X.REG(X.R9D)), DEF(X.REG(X.R10D)), DEF(X.REG(X.R11D)), SUCC(n+1)]) + DEF(X.REG(X.EDI)), DEF(X.REG(X.ESI)), DEF(X.REG(X.R8D)), + DEF(X.REG(X.R9D)), DEF(X.REG(X.R10D)), DEF(X.REG(X.R11D)), SUCC(n+1)]) | gendef (n, X.MOVZB(dest, src)) = (defhit dest @ usehit src @ [SUCC(n+1)]) | gendef (n, X.RET) = ([USE (X.REG X.EAX)]) | gendef (n, X.LABEL l) = ([SUCC (n+1)]) @@ -207,7 +216,7 @@ struct (* val isndef : X.oper -> pred list -> bool * checks to see if x is defined in a predicate list *) fun isndef (X.STACKARG(_)) _ = false - | isndef x (DEF(y)::l') = not (X.opereq (x,y)) andalso isndef x l' + | isndef x (DEF(y)::l') = not (X.basiceq (x,y)) andalso isndef x l' | isndef x (a::l') = isndef x l' | isndef x nil = true @@ -237,8 +246,8 @@ struct else liveiter newl preds end - fun dustostring (DEF(a)) = "DEF(" ^ X.prettyprint_oper X.Long a ^ ")" - | dustostring (USE(a)) = "USE(" ^ X.prettyprint_oper X.Long a ^ ")" + fun dustostring (DEF(a)) = "DEF(" ^ X.pp_oper (a,Temp.Quad) ^ ")" + | dustostring (USE(a)) = "USE(" ^ X.pp_oper (a,Temp.Quad) ^ ")" | dustostring (SUCC(a)) = "SUCC(" ^ Int.toString a ^ ")" | dustostring ISMOVE = "ISMOVE" @@ -265,7 +274,7 @@ struct fun prettyprint (set) = OperSet.foldr - (fn (oper, s) => (X.prettyprint_oper X.Long oper) ^ ", " ^ s) + (fn (oper, s) => (X.pp_oper (oper,Temp.Quad)) ^ ", " ^ s) "-\n" set