Ignore:
Timestamp:
Dec 1, 2011, 2:50:27 PM (9 years ago)
Author:
tranquil
Message:

implemented constant propagation in LTL
cleaned up translations in optimizations, a new module for translations is available

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051/src/RTLabs/constPropagation.ml

    r1572 r1580  
    208208    (types : sig_type Register.Map.t)
    209209    (graph : statement Label.Map.t)
    210     (pred_table : Label.Set.t Label.Map.t)
     210    (pred_table : Label.t list Label.Map.t)
    211211    (lbl : Label.t)
    212212    (valu : F.valuation)
    213213    : F.property =
    214214  let pred_prop = (* the situation at the entry of the statement (in [valu]) *)
    215     let f pred prop =
     215    let f prop pred =
    216216      L.join (valu pred) prop in
    217     Label.Set.fold f (Label.Map.find lbl pred_table) L.bottom in
     217    List.fold_left f L.bottom (Label.Map.find lbl pred_table) in
    218218  let type_of r = Register.Map.find r types in
    219219  match Label.Map.find lbl graph with
     
    239239    : F.valuation =
    240240  (* extract types of registers from the definition *)
    241   let types = RTLabsUtilities.computes_type_map f_def in
     241  let types = RTLabsGraph.compute_type_map f_def in
    242242
    243243  let graph = f_def.f_graph in
    244 
    245   let pred_table = RTLabsUtilities.compute_predecessors graph in
     244  let pred_table =
     245    let module U = GraphUtilities.Util(RTLabsGraph) in
     246    U.compute_predecessor_lists graph in
    246247
    247248  F.lfp (semantics types graph pred_table)
     
    268269  | Reg i -> arg_from_reg prop types i
    269270  | _ as a -> a
     271
     272let args_from_args prop types =
     273  List.map (arg_from_arg prop types)
    270274
    271275let copy i a l = match a with
     
    304308(* we transform statements according to the valuation found out by analyze *)
    305309(* We also turn branchings into redirections if the guard is constant. *)
    306 let transform_statement
     310let transform
    307311    (valu : F.valuation)
    308312    (types: sig_type Register.Map.t)
    309313    (p    : Label.t)
    310     : statement -> statement = function
    311       | St_cst (i, (Cst_offset _ | Cst_sizeof _), next) ->
    312         (* we are sure valu has a binding for i, we change the abstract
    313            quantities into actual integers *)
    314         St_cst (i, cst_of_value (L.find_cst i (valu p)), next)
    315       | (St_op1 (_,i,_,next) | St_op2(_,i,_,_,next)) when L.is_cst i (valu p) ->
    316         St_cst (i, cst_of_value (L.find_cst i (valu p)), next)
    317       | St_op2 (op, i, a, b, l) ->
    318         simpl_imm_op2 op i a b types (valu p) l
    319       | St_load (q, a, j, l) ->
    320         St_load(q, arg_from_arg (valu p) types a, j, l)
    321       | St_store (q, a, b, l) ->
    322         St_store (q, arg_from_arg (valu p) types a,
    323                      arg_from_arg (valu p) types b, l)
    324       | St_cond (i, if_true, if_false) as s when L.is_cst i (valu p) ->
    325         let s = match L.find_cst i (valu p) with
    326           | L.V v when Mem.Value.is_false v -> St_skip if_false
    327           | L.V _ | L.A _ -> St_skip if_true
    328           | _ -> s in s
    329       | St_return (Some a) ->
    330         St_return (Some (arg_from_arg (valu p) types a))
    331       | St_call_id (f, args, ret, sg, l) ->
    332         St_call_id (f, List.map (arg_from_arg (valu p) types) args, ret, sg, l)
    333       | St_call_ptr (f, args, ret, sg, l) ->
    334         St_call_ptr (f, List.map (arg_from_arg (valu p) types) args, ret, sg, l)
    335       | St_tailcall_id (f, args, sg) ->
    336         St_tailcall_id (f, List.map (arg_from_arg (valu p) types) args, sg)
    337       | St_tailcall_ptr (f, args, sg) ->
    338         St_tailcall_ptr (f, List.map (arg_from_arg (valu p) types) args, sg)
    339       | stmt -> stmt
     314    (stmt : statement) : statement list * Label.t list option =
     315  match stmt with
     316    | St_cst (i, (Cst_offset _ | Cst_sizeof _), next) ->
     317      (* we are sure valu has a binding for i, we change the abstract
     318         quantities into actual integers *)
     319      ([St_cst (i, cst_of_value (L.find_cst i (valu p)), next)] , None)
     320    | (St_op1 (_,i,_,next) | St_op2(_,i,_,_,next)) when L.is_cst i (valu p) ->
     321      ([St_cst (i, cst_of_value (L.find_cst i (valu p)), next)], None)
     322    | St_op2 (op, i, a, b, l) ->
     323      ([simpl_imm_op2 op i a b types (valu p) l], None)
     324    | St_load (q, a, j, l) ->
     325      ([St_load(q, arg_from_arg (valu p) types a, j, l)], None)
     326    | St_store (q, a, b, l) ->
     327      ([St_store (q, arg_from_arg (valu p) types a,
     328                arg_from_arg (valu p) types b, l)], None)
     329    | St_cond (i, if_true, if_false) as s when L.is_cst i (valu p) ->
     330      (match L.find_cst i (valu p) with
     331        | L.V v when Mem.Value.is_false v -> ([], Some [if_false])
     332        | L.V _ | L.A _ -> ([], Some [if_true])
     333        | _ -> ([s], Some [if_true ; if_false]))
     334    | St_return (Some a) ->
     335      ([St_return (Some (arg_from_arg (valu p) types a))], None)
     336    | St_call_id (f, args, ret, sg, l) ->
     337      ([St_call_id (f, args_from_args (valu p) types args, ret, sg, l)], None)
     338    | St_call_ptr (f, args, ret, sg, l) ->
     339      ([St_call_ptr (f, args_from_args (valu p) types args, ret, sg, l)], None)
     340    | St_tailcall_id (f, args, sg) ->
     341      ([St_tailcall_id (f, args_from_args (valu p) types args, sg)], None)
     342    | St_tailcall_ptr (f, args, sg) ->
     343      ([St_tailcall_ptr (f, args_from_args (valu p) types args, sg)], None)
     344    | stmt -> ([stmt], None)
    340345
    341346let transform_int_function
     
    344349  let valu = analyze f_def in
    345350        (* we transform the graph according to the analysis *)
    346   let types = RTLabsUtilities.computes_type_map f_def in
    347   let graph = Label.Map.mapi (transform_statement valu types) f_def.f_graph in
    348         (* and we eliminate resulting dead code *)
    349   let graph = RTLabsUtilities.dead_code_elim graph f_def.f_entry in
     351  let types = RTLabsGraph.compute_type_map f_def in
     352  let module U = GraphUtilities.Util(RTLabsGraph) in
     353  let module T = GraphUtilities.Trans(RTLabsGraph)(RTLabsGraph) in
     354  let trans =  transform valu types in
     355  let fresh () = Label.Gen.fresh f_def.f_luniverse in
     356  let graph = T.translate_pure_with_redirects fresh trans f_def.f_graph in
     357  let graph = U.dead_code_elim graph f_def.f_entry in
    350358  {f_def with f_graph = graph}
    351359
Note: See TracChangeset for help on using the changeset viewer.