22
22
23
23
#include " loop_utils.h"
24
24
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
-
59
25
void goto_unwindt::copy_segment (
60
26
const goto_programt::const_targett start,
61
27
const goto_programt::const_targett end, // exclusive
@@ -290,37 +256,11 @@ void goto_unwindt::unwind(
290
256
goto_program.destructive_insert (loop_exit, copies);
291
257
}
292
258
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
-
316
259
void goto_unwindt::unwind (
317
260
goto_programt &goto_program,
318
- const unwind_sett &unwind_set,
319
- const int k,
261
+ const unwindsett &unwindset,
320
262
const unwind_strategyt unwind_strategy)
321
263
{
322
- assert (k>=-1 );
323
-
324
264
for (goto_programt::const_targett i_it=goto_program.instructions .begin ();
325
265
i_it!=goto_program.instructions .end ();)
326
266
{
@@ -340,12 +280,14 @@ void goto_unwindt::unwind(
340
280
const irep_idt func=i_it->function ;
341
281
assert (!func.empty ());
342
282
343
- unsigned loop_number=i_it->loop_number ;
283
+ const irep_idt loop_id=
284
+ id2string (func) + " ." + std::to_string (i_it->loop_number );
344
285
345
- int final_k= get_k (func, loop_number, k, unwind_set );
286
+ auto limit=unwindset. get_limit (loop_id, 0 );
346
287
347
- if (final_k==- 1 )
288
+ if (!limit. has_value () )
348
289
{
290
+ // no unwinding given
349
291
i_it++;
350
292
continue ;
351
293
}
@@ -355,7 +297,7 @@ void goto_unwindt::unwind(
355
297
loop_exit++;
356
298
assert (loop_exit!=goto_program.instructions .end ());
357
299
358
- unwind (goto_program, loop_head, loop_exit, final_k , unwind_strategy);
300
+ unwind (goto_program, loop_head, loop_exit, *limit , unwind_strategy);
359
301
360
302
// necessary as we change the goto program in the previous line
361
303
i_it=loop_exit;
@@ -364,12 +306,9 @@ void goto_unwindt::unwind(
364
306
365
307
void goto_unwindt::operator ()(
366
308
goto_functionst &goto_functions,
367
- const unwind_sett &unwind_set,
368
- const int k,
309
+ const unwindsett &unwindset,
369
310
const unwind_strategyt unwind_strategy)
370
311
{
371
- assert (k>=-1 );
372
-
373
312
Forall_goto_functions (it, goto_functions)
374
313
{
375
314
goto_functionst::goto_functiont &goto_function=it->second ;
@@ -383,7 +322,7 @@ void goto_unwindt::operator()(
383
322
384
323
goto_programt &goto_program=goto_function.body ;
385
324
386
- unwind (goto_program, unwind_set, k , unwind_strategy);
325
+ unwind (goto_program, unwindset , unwind_strategy);
387
326
}
388
327
}
389
328
0 commit comments