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/RTLabsToRTL.ml

    r1572 r1580  
    705705    add_graph lbl (RTL.St_return (find_local_env r lenv)) def
    706706
    707 (* let remove_non_int_immediates def = *)
    708 (*   let load_arg a lbl g rs = match a with *)
    709 (*     | RTLabs.Reg r -> (lbl, g, rs, r) *)
    710 (*     | RTLabs.Imm ((AST.Cst_stack _ | AST.Cst_addrsymbol _) as c, t) -> *)
    711 (*       let new_l = Label.Gen.fresh def.RTLabs.f_luniverse in *)
    712 (*       let new_r = Register.fresh def.RTLabs.f_runiverse in *)
    713 (*       let g = Label.Map.add lbl (RTLabs.St_cst (new_r, c, new_l)) g in *)
    714 (*       (new_l, g, (new_r, t) :: rs, new_r) in  *)
    715 (*   let f lbl stmt (g, rs) = *)
    716 (*     match stmt with *)
    717 (*       | RTLabs.St_op2(op, r, a1, a2, l) -> *)
    718 (*      let (lbl', g, rs, r1) = load_arg a1 lbl g rs in *)
    719 (*         let (lbl', g, rs, r2) = load_arg a2 lbl' g rs in *)
    720 (*         let s = RTLabs.St_op2 (op, r, RTLabs.Reg r1, RTLabs.Reg r2, l) in *)
    721 (*      let g = Label.Map.add lbl' s g in *)
    722 (*      (g, rs) *)
    723 (*       | RTLabs.St_store(q, a1, a2, l) -> *)
    724 (*         let (lbl', g, rs, r1) = load_arg a1 lbl g rs in *)
    725 (*         let (lbl', g, rs, r2) = load_arg a2 lbl' g rs in *)
    726 (*         let s = RTLabs.St_store (q, RTLabs.Reg r1, RTLabs.Reg r2, l) in *)
    727 (*         let g = Label.Map.add lbl' s g in *)
    728 (*         (g, rs) *)
    729 (*       | RTLabs.St_load (q, a, r, l) -> *)
    730 (*         let (lbl', g, rs, r1) = load_arg a lbl g rs in *)
    731 (*         let s = RTLabs.St_load (q, RTLabs.Reg r1, r, l) in *)
    732 (*         let g = Label.Map.add lbl' s g in *)
    733 (*         (g, rs) *)
    734 (*       | _ -> (g, rs) in *)
    735 (*   let g = def.RTLabs.f_graph in *)
    736 (*   let (g, rs) = Label.Map.fold f g (g, []) in *)
    737 (*   let locals = List.rev_append rs def.RTLabs.f_locals in *)
    738 (*   { def with RTLabs.f_graph = g; RTLabs.f_locals = locals } *)
     707let remove_non_int_immediates def =
     708  let load_arg a lbl g rs = match a with
     709    | RTLabs.Imm ((AST.Cst_stack _ | AST.Cst_addrsymbol _) as c, t) ->
     710      let new_l = Label.Gen.fresh def.RTLabs.f_luniverse in
     711      let new_r = Register.fresh def.RTLabs.f_runiverse in
     712      let g = Label.Map.add lbl (RTLabs.St_cst (new_r, c, new_l)) g in
     713      (new_l, g, (new_r, t) :: rs, RTLabs.Reg new_r)
     714    | _ -> (lbl, g, rs, a) in
     715  let load_args args lbl g rs =
     716    let f a (lbl', g', rs', args') =
     717      let (lbl'', g'', rs'', a') = load_arg a lbl' g' rs' in
     718      (lbl'', g'', rs'', a' :: args') in
     719    List.fold_right f args (lbl, g, rs, []) in
     720  let f lbl stmt (g, rs) =
     721    match stmt with
     722      | RTLabs.St_op2(op, r, a1, a2, l) ->
     723        let (lbl', g, rs, a1) = load_arg a1 lbl g rs in
     724        let (lbl', g, rs, a2) = load_arg a2 lbl' g rs in
     725        let s = RTLabs.St_op2 (op, r, a1, a2, l) in
     726        let g = Label.Map.add lbl' s g in
     727        (g, rs)
     728      | RTLabs.St_store(q, a1, a2, l) ->
     729        let (lbl', g, rs, a1) = load_arg a1 lbl g rs in
     730        let (lbl', g, rs, a2) = load_arg a2 lbl' g rs in
     731        let s = RTLabs.St_store (q, a1, a2, l) in
     732        let g = Label.Map.add lbl' s g in
     733        (g, rs)
     734      | RTLabs.St_load (q, a, r, l) ->
     735        let (lbl', g, rs, a) = load_arg a lbl g rs in
     736        let s = RTLabs.St_load (q, a, r, l) in
     737        let g = Label.Map.add lbl' s g in
     738        (g, rs)
     739      | RTLabs.St_call_id (f, args, ret, s, l) ->
     740        let (lbl', g, rs, args) = load_args args lbl g rs in
     741        let s = RTLabs.St_call_id (f, args, ret, s, l) in
     742        let g = Label.Map.add lbl' s g in
     743        (g, rs)
     744      | RTLabs.St_tailcall_id (f, args, s) ->
     745        let (lbl', g, rs, args) = load_args args lbl g rs in
     746        let s = RTLabs.St_tailcall_id (f, args, s) in
     747        let g = Label.Map.add lbl' s g in
     748        (g, rs)
     749      | RTLabs.St_call_ptr (f, args, ret, s, l) ->
     750        let (lbl', g, rs, args) = load_args args lbl g rs in
     751        let s = RTLabs.St_call_ptr (f, args, ret, s, l) in
     752        let g = Label.Map.add lbl' s g in
     753        (g, rs)
     754      | RTLabs.St_tailcall_ptr (f, args, s) ->
     755        let (lbl', g, rs, args) = load_args args lbl g rs in
     756        let s = RTLabs.St_tailcall_ptr (f, args, s) in
     757        let g = Label.Map.add lbl' s g in
     758        (g, rs)
     759      | RTLabs.St_return (Some a) ->
     760        let (lbl', g, rs, a) = load_arg a lbl g rs in
     761        let s = RTLabs.St_return (Some a) in
     762        let g = Label.Map.add lbl' s g in
     763        (g, rs)
     764      | _ -> (g, rs) in
     765  let g = def.RTLabs.f_graph in
     766  let (g, rs) = Label.Map.fold f g (g, []) in
     767  let locals = List.rev_append rs def.RTLabs.f_locals in
     768  { def with RTLabs.f_graph = g; RTLabs.f_locals = locals }
    739769 
    740770let translate_internal def =
     771  let def = remove_non_int_immediates def in
    741772  let runiverse = def.RTLabs.f_runiverse in
    742773  let lenv =
Note: See TracChangeset for help on using the changeset viewer.