Ignore:
Timestamp:
Dec 2, 2011, 7:49:19 PM (8 years ago)
Author:
tranquil
Message:

fighting with a bug of the translation from RTL to ERTL

File:
1 edited

Legend:

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

    r1584 r1585  
    3838  val bind_2
    3939    : Register.t -> Register.t -> t option * t option -> property -> property
    40   val find : Register.t -> property -> t option
     40  val find_in : Register.t -> property -> t option
     41  val find_out : Register.t -> property -> t option
    4142  val find_carry_in : property -> t option
    4243  val equal : property -> property -> bool
    4344  val is_maximal : property -> bool
    44   val is_cst : Register.t -> property -> bool
    45   val find_cst : Register.t -> property -> int
    46   val find_cst_opt : Register.t -> property -> int option
     45  val is_cst_in : Register.t -> property -> bool
     46  val find_cst_in : Register.t -> property -> int
     47  val find_cst_opt_in : Register.t -> property -> int option
     48  val is_cst_out : Register.t -> property -> bool
     49  val find_cst_out : Register.t -> property -> int
     50  val find_cst_opt_out : Register.t -> property -> int option
    4751  val find_cst_carry_in : property -> int option
    4852
     
    5660
    5761  type property = {
    58     regs : t Register.FlexMap.t ; (* no need to have out and in *)
     62    in_regs : t Register.FlexMap.t ;
     63    out_regs : t Register.FlexMap.t ;
    5964    in_c : t option ;
    6065    out_c : t option
     
    6267
    6368  let bottom : property =
    64     { regs = Register.FlexMap.empty; in_c = None; out_c = None }
     69    { in_regs = Register.FlexMap.empty;
     70      out_regs = Register.FlexMap.empty;
     71      in_c = None; out_c = None }
    6572
    6673  let join_t x y = match x, y with
     
    7279    let choose _ = join_t in
    7380    let carry = join_t p.out_c q.out_c in
    74     { regs = Register.FlexMap.merge choose p.regs q.regs;
     81    let regs = Register.FlexMap.merge choose p.out_regs q.out_regs in
     82    {
     83      in_regs = regs;
     84      out_regs = regs;
    7585      in_c = carry;
    7686      out_c = carry
     
    7989  let bind r t p =
    8090    let regs = match t with
    81       | Some v -> Register.FlexMap.add r v p.regs
    82       | None -> Register.FlexMap.remove r p.regs in
    83     { p with regs = regs }
     91      | Some v -> Register.FlexMap.add r v p.out_regs
     92      | None -> Register.FlexMap.remove r p.out_regs in
     93    { p with out_regs = regs }
    8494
    8595  let bind_carry t p = { p with out_c = t }
     
    94104    bind s u (bind r v p)
    95105
    96   let find r p = to_opt_2 Register.FlexMap.find r p.regs
     106  let find_in r p = to_opt_2 Register.FlexMap.find r p.in_regs
     107  let find_out r p = to_opt_2 Register.FlexMap.find r p.out_regs
    97108  let find_carry_in p = p.in_c
    98109
     
    112123    equal_t_opt_as_bool p.in_c q.in_c &&
    113124      equal_t_opt_as_bool p.out_c q.out_c &&
    114       Register.FlexMap.equal equal_t p.regs q.regs
     125      Register.FlexMap.equal equal_t p.in_regs q.in_regs &&
     126      Register.FlexMap.equal equal_t p.out_regs q.out_regs
     127
    115128
    116129  let is_maximal _ = false
    117130
    118   let is_cst r p =
     131  let is_cst_in r p =
    119132    try
    120       match Register.FlexMap.find r p.regs with
     133      match Register.FlexMap.find r p.in_regs with
    121134        | V _ -> true
    122135        | T -> false
     
    124137      | Not_found -> false
    125138
    126   let find_cst r p =
    127     match find r p with
     139  let is_cst_out r p =
     140    try
     141      match Register.FlexMap.find r p.out_regs with
     142        | V _ -> true
     143        | T -> false
     144    with
     145      | Not_found -> false
     146
     147  let find_cst_in r p =
     148    match find_in r p with
    128149      | Some (V v) -> Val.to_int v
    129150      | _ -> raise Not_found
    130151
    131   let find_cst_opt r p =
    132     try Some (find_cst r p) with
     152  let find_cst_out r p =
     153    match find_out r p with
     154      | Some (V v) -> Val.to_int v
     155      | _ -> raise Not_found
     156
     157  let find_cst_opt_in r p =
     158    try Some (find_cst_in r p) with
     159      | Not_found -> None
     160
     161  let find_cst_opt_out r p =
     162    try Some (find_cst_in r p) with
    133163      | Not_found -> None
    134164
     
    150180let cst i =  L.V (Val.of_int i)
    151181
    152 let find_arg a prop = match a with
    153   | Reg r -> L.find r prop
     182let find_arg_in a prop = match a with
     183  | Reg r -> L.find_in r prop
    154184  | Imm k -> Some (cst k)
    155185
     
    159189    (j : Register.t)
    160190    : L.t option =
    161   let x = L.find j prop in
     191  let x = L.find_in j prop in
    162192  match x with
    163193    | Some (L.V v) -> Some (L.V (Eval.op1 op v))
     
    173203    (b : argument)
    174204    : L.t option * L.t option =
    175   let x = find_arg a prop in
    176   let y = find_arg b prop in
     205  let x = find_arg_in a prop in
     206  let y = find_arg_in b prop in
    177207  let c = L.find_carry_in prop in
    178208  match x, y, c, op with
     
    243273    (b : argument)
    244274    : L.t option * L.t option =
    245   let x = find_arg a prop in
    246   let y = find_arg b prop in
     275  let x = find_arg_in a prop in
     276  let y = find_arg_in b prop in
    247277  match x, y, op with
    248278    | _, Some (L.V v2), I8051.DivuModu when Val.is_false v2 ->
     
    285315  match Label.Map.find lbl graph with
    286316
    287     | St_move (r, a, _) -> L.bind r (find_arg a pred_prop) pred_prop
     317    | St_move (r, a, _) -> L.bind r (find_arg_in a pred_prop) pred_prop
    288318    | St_op1 (op, r, s, _) -> L.bind r (do_the_op1 op pred_prop s) pred_prop
    289319    | St_op2 (op, r, a, b, _) ->
     
    317347(* now that the info for constants can be gathered, let's put that to use *)
    318348
    319 let find_cst_arg prop = function
     349let find_cst_arg_in prop = function
    320350  | Imm k -> Some k
    321   | Reg r -> L.find_cst_opt r prop
     351  | Reg r -> L.find_cst_opt_in r prop
    322352
    323353let arg_from_arg prop a =
    324   match find_cst_arg prop a with
     354  match find_cst_arg_in prop a with
    325355    | Some k -> Imm k
    326356    | None -> a
    327357
     358let move i a prop =
     359  match arg_from_arg prop a with
     360    | Reg j when i = j -> []
     361    | Imm k when L.find_cst_opt_in i prop = Some k -> []
     362    | a' -> [St_move (i, a', Label.dummy)]
     363
    328364let simpl_imm_op2 op i a b prop l =
    329   match find_cst_arg prop a, find_cst_arg prop b,
     365  match find_cst_arg_in prop a, find_cst_arg_in prop b,
    330366    L.find_cst_carry_in prop, op with
    331367    | Some 0, _, _, (I8051.Or | I8051.Xor)
     
    336372    | Some 255, _, Some 1, I8051.Addc
    337373    | Some 255, _, _, I8051.And ->
    338       St_move (i, b, l)
     374      move i b prop
    339375    | _, Some 0, _, (I8051.Or | I8051.Xor)
    340376    | _, Some 0, Some 0, (I8051.Addc | I8051.Sub | I8051.Add)
    341377    | _, Some 255, Some 1, I8051.Addc
    342378    | _, Some 255, _, I8051.And ->
    343       St_move (i, a, l)
     379      move i a prop
    344380    | _, _, Some 0, I8051.Addc ->
    345381      (* does not change time, but maybe helps getting better results
    346382         with liveness analysis *)
    347       St_op2 (I8051.Add, i, arg_from_arg prop a, arg_from_arg prop b, l)
     383      [St_op2 (I8051.Add, i, arg_from_arg prop a, arg_from_arg prop b, l)]
    348384    | _ ->
    349       St_op2 (op, i, arg_from_arg prop a, arg_from_arg prop b, l)
     385      [St_op2 (op, i, arg_from_arg prop a, arg_from_arg prop b, l)]
    350386
    351387let simpl_imm_opaccs op i j a b prop l =
    352   match find_cst_arg prop a, find_cst_arg prop b, op with
     388  match find_cst_arg_in prop a, find_cst_arg_in prop b, op with
    353389    | Some 1, _, I8051.Mul ->
    354       [St_move (i, b, l) ; St_move (j, Imm 0, l)]
     390      move i b prop @ move j (Imm 0) prop
    355391    |  _, Some 1, (I8051.Mul | I8051.DivuModu) ->
    356       [St_move (i, a, l) ; St_move (j, Imm 0, l)]
     392      move i a prop @ move j (Imm 0) prop
    357393    | _ ->
    358394      [St_opaccs (op, i, j, arg_from_arg prop a, arg_from_arg prop b, l)]
     395
    359396
    360397(* we transform statements according to the valuation found out by analyze *)
     
    369406    (stmt : statement) : statement list * Label.t list option =
    370407  match stmt with
    371     | (St_op1 (_,i,_,l) | St_op2(_,i,_,_,l) | St_move (i, _, l))
    372         when L.is_cst i (valu p) ->
    373       ([St_move (i, Imm (L.find_cst i (valu p)), p)], None)
     408    | St_move (i, a, l) ->
     409      (move i a (valu p), None)
     410    | (St_op1 (_,i,_,l) | St_op2(_,i,_,_,l))
     411        when L.is_cst_out i (valu p) ->
     412      (move i (Imm (L.find_cst_out i (valu p))) (valu p), None)
    374413    | St_op2 (op, i, a, b, l) ->
    375       ([simpl_imm_op2 op i a b (valu p) l], None)
     414      (simpl_imm_op2 op i a b (valu p) l, None)
    376415    | St_opaccs (op, i, j, a, b, l) ->
    377416      (simpl_imm_opaccs op i j a b (valu p) l, None)
     
    383422                 arg_from_arg (valu p) c, l)], None)
    384423    | St_cond (i, if_true, if_false) as s ->
    385       (match L.find_cst_opt i (valu p) with
     424      (match L.find_cst_opt_in i (valu p) with
    386425        | Some 0 -> ([], Some [if_false])
    387426        | Some _ -> ([], Some [if_true])
Note: See TracChangeset for help on using the changeset viewer.