Changeset 1585 for Deliverables/D2.2/8051/src/RTL/RTLConstPropagation.ml
 Timestamp:
 Dec 2, 2011, 7:49:19 PM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Deliverables/D2.2/8051/src/RTL/RTLConstPropagation.ml
r1584 r1585 38 38 val bind_2 39 39 : 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 41 42 val find_carry_in : property > t option 42 43 val equal : property > property > bool 43 44 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 47 51 val find_cst_carry_in : property > int option 48 52 … … 56 60 57 61 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 ; 59 64 in_c : t option ; 60 65 out_c : t option … … 62 67 63 68 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 } 65 72 66 73 let join_t x y = match x, y with … … 72 79 let choose _ = join_t in 73 80 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; 75 85 in_c = carry; 76 86 out_c = carry … … 79 89 let bind r t p = 80 90 let regs = match t with 81  Some v > Register.FlexMap.add r v p. regs82  None > Register.FlexMap.remove r p. regs in83 { 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 } 84 94 85 95 let bind_carry t p = { p with out_c = t } … … 94 104 bind s u (bind r v p) 95 105 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 97 108 let find_carry_in p = p.in_c 98 109 … … 112 123 equal_t_opt_as_bool p.in_c q.in_c && 113 124 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 115 128 116 129 let is_maximal _ = false 117 130 118 let is_cst r p =131 let is_cst_in r p = 119 132 try 120 match Register.FlexMap.find r p. regs with133 match Register.FlexMap.find r p.in_regs with 121 134  V _ > true 122 135  T > false … … 124 137  Not_found > false 125 138 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 128 149  Some (V v) > Val.to_int v 129 150  _ > raise Not_found 130 151 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 133 163  Not_found > None 134 164 … … 150 180 let cst i = L.V (Val.of_int i) 151 181 152 let find_arg a prop = match a with153  Reg r > L.find r prop182 let find_arg_in a prop = match a with 183  Reg r > L.find_in r prop 154 184  Imm k > Some (cst k) 155 185 … … 159 189 (j : Register.t) 160 190 : L.t option = 161 let x = L.find j prop in191 let x = L.find_in j prop in 162 192 match x with 163 193  Some (L.V v) > Some (L.V (Eval.op1 op v)) … … 173 203 (b : argument) 174 204 : L.t option * L.t option = 175 let x = find_arg a prop in176 let y = find_arg b prop in205 let x = find_arg_in a prop in 206 let y = find_arg_in b prop in 177 207 let c = L.find_carry_in prop in 178 208 match x, y, c, op with … … 243 273 (b : argument) 244 274 : L.t option * L.t option = 245 let x = find_arg a prop in246 let y = find_arg b prop in275 let x = find_arg_in a prop in 276 let y = find_arg_in b prop in 247 277 match x, y, op with 248 278  _, Some (L.V v2), I8051.DivuModu when Val.is_false v2 > … … 285 315 match Label.Map.find lbl graph with 286 316 287  St_move (r, a, _) > L.bind r (find_arg a pred_prop) pred_prop317  St_move (r, a, _) > L.bind r (find_arg_in a pred_prop) pred_prop 288 318  St_op1 (op, r, s, _) > L.bind r (do_the_op1 op pred_prop s) pred_prop 289 319  St_op2 (op, r, a, b, _) > … … 317 347 (* now that the info for constants can be gathered, let's put that to use *) 318 348 319 let find_cst_arg prop = function349 let find_cst_arg_in prop = function 320 350  Imm k > Some k 321  Reg r > L.find_cst_opt r prop351  Reg r > L.find_cst_opt_in r prop 322 352 323 353 let arg_from_arg prop a = 324 match find_cst_arg prop a with354 match find_cst_arg_in prop a with 325 355  Some k > Imm k 326 356  None > a 327 357 358 let 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 328 364 let simpl_imm_op2 op i a b prop l = 329 match find_cst_arg prop a, find_cst_argprop b,365 match find_cst_arg_in prop a, find_cst_arg_in prop b, 330 366 L.find_cst_carry_in prop, op with 331 367  Some 0, _, _, (I8051.Or  I8051.Xor) … … 336 372  Some 255, _, Some 1, I8051.Addc 337 373  Some 255, _, _, I8051.And > 338 St_move (i, b, l)374 move i b prop 339 375  _, Some 0, _, (I8051.Or  I8051.Xor) 340 376  _, Some 0, Some 0, (I8051.Addc  I8051.Sub  I8051.Add) 341 377  _, Some 255, Some 1, I8051.Addc 342 378  _, Some 255, _, I8051.And > 343 St_move (i, a, l)379 move i a prop 344 380  _, _, Some 0, I8051.Addc > 345 381 (* does not change time, but maybe helps getting better results 346 382 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)] 348 384  _ > 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)] 350 386 351 387 let simpl_imm_opaccs op i j a b prop l = 352 match find_cst_arg prop a, find_cst_argprop b, op with388 match find_cst_arg_in prop a, find_cst_arg_in prop b, op with 353 389  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 355 391  _, 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 357 393  _ > 358 394 [St_opaccs (op, i, j, arg_from_arg prop a, arg_from_arg prop b, l)] 395 359 396 360 397 (* we transform statements according to the valuation found out by analyze *) … … 369 406 (stmt : statement) : statement list * Label.t list option = 370 407 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) 374 413  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) 376 415  St_opaccs (op, i, j, a, b, l) > 377 416 (simpl_imm_opaccs op i j a b (valu p) l, None) … … 383 422 arg_from_arg (valu p) c, l)], None) 384 423  St_cond (i, if_true, if_false) as s > 385 (match L.find_cst_opt i (valu p) with424 (match L.find_cst_opt_in i (valu p) with 386 425  Some 0 > ([], Some [if_false]) 387 426  Some _ > ([], Some [if_true])
Note: See TracChangeset
for help on using the changeset viewer.