Changeset 1664 for Deliverables/D2.2/8051/src/clight/loopPeeling.ml
 Timestamp:
 Jan 27, 2012, 12:11:54 AM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Deliverables/D2.2/8051/src/clight/loopPeeling.ml
r1580 r1664 70 70 ClightFold.statement2 ClightFold.expr_fill_exprs f_stmt 71 71 72 let remove_cnt_brk cnt_lbl brk_lbl = 73 let f_stmt stmt exprs stmts = 74 match stmt with 75  Clight.Sbreak > Clight.Sgoto brk_lbl 76  Clight.Scontinue > Clight.Sgoto cnt_lbl 77  _ >ClightFold. statement_fill_subs stmt exprs stmts in 78 ClightFold.statement2 ClightFold.expr_fill_exprs f_stmt 79 72 80 let peel fresh info = 73 let f_stmt stmt exprs stmts = 81 let process_cnt_brk peeled_body has_brk has_cnt = 82 let (brk_lbl, add_tail) = if has_brk then 83 let new_lbl = fresh () in 84 (new_lbl, fun stmt > 85 Clight.Ssequence (stmt, Clight.Slabel (new_lbl, Clight.Sskip))) 86 else 87 (Label.dummy, fun stmt > stmt) in 88 let (cnt_lbl, add_head) = if has_cnt then 89 let new_lbl = fresh () in 90 (new_lbl, fun stmt > Clight.Slabel(new_lbl, stmt)) 91 else 92 (Label.dummy, fun stmt > stmt) in 93 (* we could avoid making a further pass, but sacrificing the use 94 of the fold machinery *) 95 let peeled_body = if has_brk  has_cnt then 96 remove_cnt_brk cnt_lbl brk_lbl peeled_body 97 else peeled_body in 98 (add_head, peeled_body, add_tail) in 99 100 let f_stmt stmt exprs stmts_w_flags = 74 101 if heuristics info stmt then 75 match stmt, exprs, stmts with76  Clight.Swhile (Some i, _, _), e :: _, s:: _ >102 match stmt, exprs, stmts_w_flags with 103  Clight.Swhile (Some i, _, _), e :: _, (s, (has_brk, has_cnt)) :: _ > 77 104 (* we can suppose no label in stmt is target of a goto outside of stmt, *) 78 105 (* as loop is indexed and thus single entry. So we can freely rename *) … … 88 115 (* rebuild the loop *) 89 116 let loop = Clight.Swhile(Some i, e_next, s_next) in 117 (* all break and continue statements, if any, must be replaced by 118 gotos in the peeled body *) 119 let (head, s_first, tail) = process_cnt_brk s_first has_brk has_cnt in 90 120 (* build the peeled loop *) 91 let peeled = Clight.Ssequence(s_first, loop) in 92 (* add the guard at the start *) 93 Clight.Sifthenelse(e_first, peeled, Clight.Sskip) 94  Clight.Sdowhile (Some i, _, _), e :: _, s :: _ > 95 (* we can suppose no label in stmt is target of a goto outside of stmt, *) 121 let peeled = Clight.Ssequence(s_first, head loop) in 122 (tail (Clight.Sifthenelse(e_first, peeled, Clight.Sskip)), 123 (false, false)) 124  Clight.Sdowhile (Some i, _, _), e :: _, 125 (s, (has_brk, has_cnt)) :: _ > 126 (* we can suppose no label in stmt is target of a goto outside, *) 96 127 (* as loop is indexed and thus single entry. So we can freely rename *) 97 128 (* labels in stmt. *) … … 106 137 (* rebuild the loop *) 107 138 let loop = Clight.Sdowhile(Some i, e_next, s_next) in 139 let (head, s_first, tail) = process_cnt_brk s_first has_brk has_cnt in 108 140 (* put a guard before the following iterations of the loop *) 109 let guarded_loop = Clight.Sifthenelse(e_first, loop, Clight.Sskip) in 141 let guarded_loop = 142 Clight.Sifthenelse(e_first, head loop, Clight.Sskip) in 110 143 (* build the peeled loop *) 111 Clight.Ssequence(s_first, guarded_loop) 112  Clight.Sfor (Some i, _, _, _, _), e :: _, s1 :: s2 :: s3 ::_ > 144 (tail (Clight.Ssequence(s_first, guarded_loop)), (false, false)) 145  Clight.Sfor (Some i, _, _, _, _), e :: _, 146 (s1, _) :: (s2, _) :: (s3, (has_brk, has_cnt)) ::_ > 113 147 (* we can suppose no label in s3 is target of a goto outside of stmt, *) 114 148 (* as loop is indexed and thus single entry. So we can freely rename *) … … 127 161 (* rebuild the loop *) 128 162 let loop = Clight.Sfor(Some i, s2_first, e_next, s2_next, s3_next) in 163 let (head, s3_first, tail) = 164 process_cnt_brk s3_first has_brk has_cnt in 129 165 (* build the peeled loop *) 130 let peeled = Clight.Ssequence(s3_first, loop) in 166 let peeled = Clight.Ssequence(s3_first, head loop) in 167 let guarded = Clight.Sifthenelse(e_first, peeled, Clight.Sskip) in 131 168 (* add the guard at the start *) 132 Clight.Ssequence(s1,Clight.Sifthenelse(e_first, peeled, Clight.Sskip))169 (tail (Clight.Ssequence(s1, guarded)), (false, false)) 133 170  _ > assert false (* heuristics should have crossed out other cases *) 134 else ClightFold.statement_fill_subs stmt exprs stmts in 171 else match stmt with 172  Clight.Sbreak > (Clight.Sbreak, (true, false)) 173  Clight.Scontinue > (Clight.Scontinue, (false, true)) 174  _ > 175 let stmts, flags = List.split stmts_w_flags in 176 let f (b1, b2) (c1, c2) = (b1  c1, b2  c2) in 177 (ClightFold.statement_fill_subs stmt exprs stmts, 178 List.fold_left f (false, false) flags) in 135 179 ClightFold.statement2 ClightFold.expr_fill_exprs f_stmt 136 180 137 181 let peel_funct fresh info = function 138 182  (id, Clight.Internal def) > 139 let body = peel fresh info def.Clight.fn_body in183 let body, _ = peel fresh info def.Clight.fn_body in 140 184 (id, Clight.Internal {def with Clight.fn_body = body}) 141 185  _ as p > p
Note: See TracChangeset
for help on using the changeset viewer.