Ignore:
Timestamp:
Dec 6, 2011, 5:04:13 PM (8 years ago)
Author:
tranquil
Message:
  • turned to argument-less return statements for RTLabs and RTL (there was a hidden invariant, for which the arguments of return statements where equal to the f_result field of the function definition: they were useless and an optimization was breaking the compilation)
  • corrected a bug in liveness analysis I had introduced
Location:
Deliverables/D2.2/8051/src/RTL
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051/src/RTL/RTL.mli

    r1572 r1589  
    102102  | St_cond of Register.t * Label.t * Label.t
    103103
    104   (* Return the value of some registers (low bytes first). *)
    105   | St_return of argument list
     104  (* Return control. *)
     105  | St_return
    106106
    107107
  • Deliverables/D2.2/8051/src/RTL/RTLConstPropagation.ml

    r1585 r1589  
    415415    | St_opaccs (op, i, j, a, b, l) ->
    416416      (simpl_imm_opaccs op i j a b (valu p) l, None)
     417    | St_set_carry l when L.find_cst_carry_in (valu p) = Some 1 -> ([], None)
     418    | St_clear_carry l when L.find_cst_carry_in (valu p) = Some 0 -> ([], None)
    417419    | St_load (i, a, b, l) ->
    418420      ([St_load(i, arg_from_arg (valu p) a, arg_from_arg (valu p) b, l)], None)
     
    426428        | Some _ -> ([], Some [if_true])
    427429        | None -> ([s], Some [if_true ; if_false]))
    428     | St_return rets ->
    429       let rets' = List.map (arg_from_arg (valu p)) rets in
    430       ([St_return rets'], None)
    431430    | St_call_id (f, args, rets, l) ->
    432431      let args' = List.map (arg_from_arg (valu p)) args in
  • Deliverables/D2.2/8051/src/RTL/RTLGraph.ml

    r1580 r1589  
    6262  | St_tailcall_id (f, args), [] -> St_tailcall_id (f, args)
    6363  | St_tailcall_ptr (f1, f2, args), [] -> St_tailcall_ptr (f1, f2, args)
    64   | St_return regs, [] -> St_return regs
     64  | St_return, [] -> St_return
    6565  | _ -> invalid_arg "fill_succs: statement and successors do not match"
  • Deliverables/D2.2/8051/src/RTL/RTLInterpret.ml

    r1572 r1589  
    1919   being executed. *)
    2020
    21 type local_env = Val.t Register.Map.t
     21type local_env = {
     22  le_vals : Val.t Register.Map.t ;
     23  le_rets : Register.t list
     24}
    2225
    2326(* Call frames. The execution state has a call stack, each element of the stack
     
    2730
    2831type stack_frame =
    29     { ret_regs : Register.t list ;
     32    { result  : Register.t list ;
    3033      graph    : RTL.graph ;
    3134      pc       : Label.t ;
     
    5558      (if Val.eq v Val.undef then ""
    5659       else (Register.print x) ^ " = " ^ (Val.to_string v) ^ "  ") in
    57   Register.Map.fold f lenv ""
     60  Register.Map.fold f lenv.le_vals ""
    5861
    5962let string_of_args args =
     
    8790
    8891let get_local_value (lenv : local_env) (r : Register.t) : Val.t =
    89   if Register.Map.mem r lenv then Register.Map.find r lenv
    90   else error ("Unknown local register \"" ^ (Register.print r) ^ "\".")
     92  try
     93    Register.Map.find r lenv.le_vals
     94  with
     95    | Not_found ->
     96      error ("Unknown local register \"" ^ (Register.print r) ^ "\".")
     97
    9198
    9299let get_local_arg_value (lenv : local_env) : RTL.argument -> Val.t = function
     
    108115
    109116let assign_state sfrs graph lbl sp lenv carry mem inds trace destrs vs =
    110   let lenv = adds destrs vs lenv in
     117  let lenv = { lenv with le_vals = adds destrs vs lenv.le_vals } in
    111118  State (sfrs, graph, lbl, sp, lenv, carry, mem, inds, trace)
    112119
     
    210217        let args = get_arg_values lenv args in
    211218        let sf =
    212           { ret_regs = ret_regs ; graph = graph ; pc = lbl ;
     219          { result = ret_regs ; graph = graph ; pc = lbl ;
    213220            sp = sp ; lenv = lenv ; carry = carry }
    214221        in
     
    219226        let f_def = Mem.find_fun_def mem addr in
    220227        let args = get_arg_values lenv args in
    221         let sf = { ret_regs = ret_regs ; graph = graph ; pc = lbl ;
     228        let sf = { result = ret_regs ; graph = graph ; pc = lbl ;
    222229                   sp = sp ; lenv = lenv ; carry = carry } in
    223230        CallState (sf :: sfrs, f_def, args, mem, inds, trace)
     
    240247        branch_state sfrs graph lbl_true lbl_false sp lenv carry mem inds trace v
    241248
    242       | RTL.St_return rl ->
    243         let vl = List.map (get_local_arg_value lenv) rl in
     249      | RTL.St_return ->
     250        let vl = List.map (get_local_value lenv) lenv.le_rets in
    244251        let mem = Mem.free mem sp in
    245252        ReturnState (sfrs, vl, mem, inds, trace)
     
    255262    (locals : Register.Set.t)
    256263    (params : Register.t list)
     264    (rets   : Register.t list)
    257265    (args   : Val.t list) :
    258266    local_env =
    259   let f r lenv = Register.Map.add r Val.undef lenv in
    260   let lenv = Register.Set.fold f locals Register.Map.empty in
    261   let f lenv r v = Register.Map.add r v lenv in
    262   List.fold_left2 f lenv params args
     267  let f r lenv_vals = Register.Map.add r Val.undef lenv_vals in
     268  let lenv_vals = Register.Set.fold f locals Register.Map.empty in
     269  let f lenv_vals r v = Register.Map.add r v lenv_vals in
     270  { le_vals = List.fold_left2 f lenv_vals params args ; le_rets = rets }
    263271
    264272let state_after_call
     
    274282      let inds = new_ind inds in
    275283      let (mem', sp) = Mem.alloc mem def.RTL.f_stacksize in
     284      let lenv =
     285        init_locals def.RTL.f_locals def.RTL.f_params def.RTL.f_result args in
    276286      State (sfrs, def.RTL.f_graph, def.RTL.f_entry, sp,
    277              init_locals def.RTL.f_locals def.RTL.f_params args,
     287             lenv,
    278288             Val.undef, mem', inds, trace)
    279289    | RTL.F_ext def ->
     
    289299    (trace    : CostLabel.t list) :
    290300    state =
    291   let f i lenv r = Register.Map.add r (List.nth ret_vals i) lenv in
    292   let lenv = MiscPottier.foldi f sf.lenv sf.ret_regs in
     301  let f i lenv_vals r = Register.Map.add r (List.nth ret_vals i) lenv_vals in
     302  let lenv =
     303    {sf.lenv with
     304      le_vals = MiscPottier.foldi f sf.lenv.le_vals sf.result } in
    293305  let inds = forget_ind inds in
    294306  State (sfrs, sf.graph, sf.pc, sf.sp, lenv, sf.carry, mem, inds, trace)
  • Deliverables/D2.2/8051/src/RTL/RTLPrinter.ml

    r1580 r1589  
    125125    Printf.sprintf "branch %s <> 0 --> %s, %s"
    126126      (print_reg srcr) lbl_true lbl_false
    127   | RTL.St_return regs ->
    128     Printf.sprintf "return %s" (print_return regs)
     127  | RTL.St_return ->
     128    Printf.sprintf "return"
    129129
    130130
     
    143143
    144144  Printf.sprintf
    145     "%s\"%s\"%s\n%slocals: %s\n%sresult: %s\n%sstacksize: %d\n%sentry: %s\n%sexit: %s\n\n%s"
     145    "%s\"%s\"%s\n%slocals: %s\n%sstacksize: %d\n%sentry: %s\n%sexit: %s\n\n%s"
    146146    (n_spaces n)
    147147    f
     
    149149    (n_spaces (n+2))
    150150    (print_locals def.RTL.f_locals)
    151     (n_spaces (n+2))
    152     (print_result def.RTL.f_result)
     151    (* (n_spaces (n+2)) *)
     152    (* (print_result def.RTL.f_result) *)
    153153    (n_spaces (n+2))
    154154    def.RTL.f_stacksize
  • Deliverables/D2.2/8051/src/RTL/RTLToERTL.ml

    r1584 r1589  
    350350    add_graph lbl (ERTL.St_cond (srcr, lbl_true, lbl_false)) def
    351351
    352   | RTL.St_return ret_regs ->
    353     add_graph lbl (ERTL.St_return ret_regs) def
     352  | RTL.St_return ->
     353    add_graph lbl (ERTL.St_return) def
    354354
    355355  | RTL.St_tailcall_id _ | RTL.St_tailcall_ptr _ ->
Note: See TracChangeset for help on using the changeset viewer.