2222
2323#include " loop_utils.h"
2424
25- void parse_unwindset (const std::string &us, unwind_sett &unwind_set)
26- {
27- assert (unwind_set.empty ());
28-
29- std::vector<std::string> result;
30- split_string (us, ' ,' , result, true , true );
31- assert (!result.empty ());
32-
33- if (result.front ().empty ()) // allow empty string as unwindset
34- return ;
35-
36- for (std::vector<std::string>::const_iterator it=result.begin ();
37- it!=result.end (); it++)
38- {
39- std::string loop;
40- std::string bound;
41-
42- split_string (*it, ' :' , loop, bound, true );
43-
44- std::string func;
45- std::string id;
46-
47- split_string (loop, ' .' , func, id, true );
48-
49- unsigned loop_id=std::stoi (id);
50- int loop_bound=std::stoi (bound);
51-
52- if (loop_bound<-1 )
53- throw " given unwind bound < -1" ;
54-
55- unwind_set[func][loop_id]=loop_bound;
56- }
57- }
58-
5925void goto_unwindt::copy_segment (
6026 const goto_programt::const_targett start,
6127 const goto_programt::const_targett end, // exclusive
@@ -290,37 +256,11 @@ void goto_unwindt::unwind(
290256 goto_program.destructive_insert (loop_exit, copies);
291257}
292258
293- int goto_unwindt::get_k (
294- const irep_idt func,
295- const unsigned loop_id,
296- const int global_k,
297- const unwind_sett &unwind_set) const
298- {
299- assert (global_k>=-1 );
300-
301- unwind_sett::const_iterator f_it=unwind_set.find (func);
302- if (f_it==unwind_set.end ())
303- return global_k;
304-
305- const std::map<unsigned , int > &m=f_it->second ;
306- std::map<unsigned , int >::const_iterator l_it=m.find (loop_id);
307- if (l_it==m.end ())
308- return global_k;
309-
310- int k=l_it->second ;
311- assert (k>=-1 );
312-
313- return k;
314- }
315-
316259void goto_unwindt::unwind (
317260 goto_programt &goto_program,
318- const unwind_sett &unwind_set,
319- const int k,
261+ const unwindsett &unwindset,
320262 const unwind_strategyt unwind_strategy)
321263{
322- assert (k>=-1 );
323-
324264 for (goto_programt::const_targett i_it=goto_program.instructions .begin ();
325265 i_it!=goto_program.instructions .end ();)
326266 {
@@ -340,12 +280,14 @@ void goto_unwindt::unwind(
340280 const irep_idt func=i_it->function ;
341281 assert (!func.empty ());
342282
343- unsigned loop_number=i_it->loop_number ;
283+ const irep_idt loop_id=
284+ id2string (func) + " ." + std::to_string (i_it->loop_number );
344285
345- int final_k= get_k (func, loop_number, k, unwind_set );
286+ auto limit=unwindset. get_limit (loop_id, 0 );
346287
347- if (final_k==- 1 )
288+ if (!limit. has_value () )
348289 {
290+ // no unwinding given
349291 i_it++;
350292 continue ;
351293 }
@@ -355,7 +297,7 @@ void goto_unwindt::unwind(
355297 loop_exit++;
356298 assert (loop_exit!=goto_program.instructions .end ());
357299
358- unwind (goto_program, loop_head, loop_exit, final_k , unwind_strategy);
300+ unwind (goto_program, loop_head, loop_exit, *limit , unwind_strategy);
359301
360302 // necessary as we change the goto program in the previous line
361303 i_it=loop_exit;
@@ -364,12 +306,9 @@ void goto_unwindt::unwind(
364306
365307void goto_unwindt::operator ()(
366308 goto_functionst &goto_functions,
367- const unwind_sett &unwind_set,
368- const int k,
309+ const unwindsett &unwindset,
369310 const unwind_strategyt unwind_strategy)
370311{
371- assert (k>=-1 );
372-
373312 Forall_goto_functions (it, goto_functions)
374313 {
375314 goto_functionst::goto_functiont &goto_function=it->second ;
@@ -383,7 +322,7 @@ void goto_unwindt::operator()(
383322
384323 goto_programt &goto_program=goto_function.body ;
385324
386- unwind (goto_program, unwind_set, k , unwind_strategy);
325+ unwind (goto_program, unwindset , unwind_strategy);
387326 }
388327}
389328
0 commit comments