1
1
/* ******************************************************************\
2
2
3
- Module: Constant Propagation
3
+ Module: Constant propagation
4
4
5
5
Author: Peter Schrammel
6
6
@@ -18,6 +18,7 @@ Author: Peter Schrammel
18
18
#include < util/find_symbols.h>
19
19
#include < util/arith_tools.h>
20
20
#include < util/simplify_expr.h>
21
+ #include < util/cprover_prefix.h>
21
22
22
23
void constant_propagator_domaint::assign_rec (
23
24
valuest &values,
@@ -32,7 +33,7 @@ void constant_propagator_domaint::assign_rec(
32
33
33
34
exprt tmp=rhs;
34
35
values.replace_const (tmp);
35
- tmp= simplify_expr (tmp, ns);
36
+ simplify (tmp, ns);
36
37
37
38
if (tmp.is_constant ())
38
39
values.set_to (s, tmp);
@@ -122,13 +123,13 @@ void constant_propagator_domaint::transform(
122
123
123
124
if (to==next)
124
125
{
125
- if (id==" __CPROVER_set_must " ||
126
- id==" __CPROVER_get_must " ||
127
- id==" __CPROVER_set_may " ||
128
- id==" __CPROVER_get_may " ||
129
- id==" __CPROVER_cleanup " ||
130
- id==" __CPROVER_clear_may " ||
131
- id==" __CPROVER_clear_must " )
126
+ if (id==CPROVER_PREFIX " set_must " ||
127
+ id==CPROVER_PREFIX " get_must " ||
128
+ id==CPROVER_PREFIX " set_may " ||
129
+ id==CPROVER_PREFIX " get_may " ||
130
+ id==CPROVER_PREFIX " cleanup " ||
131
+ id==CPROVER_PREFIX " clear_may " ||
132
+ id==CPROVER_PREFIX " clear_must " )
132
133
{
133
134
// no effect on constants
134
135
}
@@ -149,17 +150,19 @@ void constant_propagator_domaint::transform(
149
150
const code_typet &code_type=to_code_type (symbol.type );
150
151
const code_typet::parameterst ¶meters=code_type.parameters ();
151
152
152
- const code_function_callt::argumentst &arguments
153
- = function_call.arguments ();
153
+ const code_function_callt::argumentst &arguments=
154
+ function_call.arguments ();
154
155
155
- unsigned n=std::min (arguments.size (), parameters.size ());
156
-
157
- for (unsigned i=0 ; i<n; i++)
156
+ code_typet::parameterst::const_iterator p_it=parameters.begin ();
157
+ for (const auto &arg : arguments)
158
158
{
159
- const symbol_exprt ¶meter_expr
160
- =symbol_exprt (parameters[i].get_identifier (), arguments[i].type ());
159
+ if (p_it==parameters.end ())
160
+ break ;
161
+
162
+ const symbol_exprt parameter_expr (p_it->get_identifier (), arg.type ());
163
+ assign_rec (values, parameter_expr, arg, ns);
161
164
162
- assign_rec (values, parameter_expr, arguments[i], ns) ;
165
+ ++p_it ;
163
166
}
164
167
}
165
168
}
@@ -183,18 +186,8 @@ void constant_propagator_domaint::transform(
183
186
184
187
const code_typet &type=to_code_type (symbol.type );
185
188
186
- typedef code_typet::parameterst parameterst;
187
- const parameterst ¶meters=type.parameters ();
188
-
189
- for (parameterst::const_iterator it=parameters.begin ();
190
- it!=parameters.end (); it++)
191
- {
192
- // normal parameter
193
- const irep_idt par=it->get_identifier ();
194
-
195
- // this erases the parameter from the map
196
- values.set_to_top (par);
197
- }
189
+ for (const auto ¶m : type.parameters ())
190
+ values.set_to_top (param.get_identifier ());
198
191
}
199
192
200
193
INVARIANT (from->is_goto () || !values.is_bottom ,
@@ -218,6 +211,7 @@ bool constant_propagator_domaint::two_way_propagate_rec(
218
211
219
212
bool change=false ;
220
213
214
+ // this seems to be buggy at present
221
215
#if 0
222
216
if(expr.id()==ID_and)
223
217
{
@@ -318,25 +312,20 @@ bool constant_propagator_domaint::valuest::is_constant_address_of(
318
312
// / Do not call this when iterating over replace_const.expr_map!
319
313
bool constant_propagator_domaint::valuest::set_to_top (const irep_idt &id)
320
314
{
321
- replace_symbolt::expr_mapt::iterator r_it
322
- = replace_const.expr_map .find (id);
315
+ replace_symbolt::expr_mapt::size_type n_erased=
316
+ replace_const.expr_map .erase (id);
323
317
324
- if (r_it!=replace_const.expr_map .end ())
325
- {
326
- assert (!is_bottom);
327
- replace_const.expr_map .erase (r_it);
328
- return true ;
329
- }
318
+ INVARIANT (n_erased==0 || !is_bottom, " bottom => 0 erased" );
330
319
331
- return false ;
320
+ return n_erased> 0 ;
332
321
}
333
322
334
323
335
324
void constant_propagator_domaint::valuest::set_dirty_to_top (
336
325
const dirtyt &dirty,
337
326
const namespacet &ns)
338
327
{
339
- typedef replace_symbol_extt ::expr_mapt expr_mapt;
328
+ typedef replace_symbolt ::expr_mapt expr_mapt;
340
329
expr_mapt &expr_map=replace_const.expr_map ;
341
330
342
331
for (expr_mapt::iterator it=expr_map.begin ();
@@ -375,12 +364,9 @@ void constant_propagator_domaint::valuest::output(
375
364
return ;
376
365
}
377
366
378
- for (replace_symbolt::expr_mapt::const_iterator
379
- it=replace_const.expr_map .begin ();
380
- it!=replace_const.expr_map .end ();
381
- ++it)
367
+ for (const auto &p : replace_const.expr_map )
382
368
{
383
- out << ' ' << it-> first << " =" << from_expr (ns, " " , it-> second ) << ' \n ' ;
369
+ out << ' ' << p. first << " =" << from_expr (ns, " " , p. second ) << ' \n ' ;
384
370
}
385
371
}
386
372
@@ -396,10 +382,6 @@ void constant_propagator_domaint::output(
396
382
// / \return Return true if "this" has changed.
397
383
bool constant_propagator_domaint::valuest::merge (const valuest &src)
398
384
{
399
- // dummy
400
- const symbol_tablet symbol_table;
401
- const namespacet ns (symbol_table);
402
-
403
385
// nothing to do
404
386
if (src.is_bottom )
405
387
return false ;
@@ -417,8 +399,8 @@ bool constant_propagator_domaint::valuest::merge(const valuest &src)
417
399
418
400
bool changed=false ;
419
401
420
- replace_symbol_extt ::expr_mapt &expr_map=replace_const.expr_map ;
421
- const replace_symbol_extt ::expr_mapt &src_expr_map=src.replace_const .expr_map ;
402
+ replace_symbolt ::expr_mapt &expr_map=replace_const.expr_map ;
403
+ const replace_symbolt ::expr_mapt &src_expr_map=src.replace_const .expr_map ;
422
404
423
405
// handle top
424
406
if (src_expr_map.empty ())
@@ -427,8 +409,6 @@ bool constant_propagator_domaint::valuest::merge(const valuest &src)
427
409
changed=!expr_map.empty ();
428
410
429
411
set_to_top ();
430
- assert (expr_map.empty ());
431
- assert (!is_bottom);
432
412
433
413
return changed;
434
414
}
@@ -475,29 +455,26 @@ bool constant_propagator_domaint::valuest::meet(const valuest &src)
475
455
if (src.is_bottom || is_bottom)
476
456
return false ;
477
457
478
- bool changed = false ;
458
+ bool changed= false ;
479
459
480
- for (replace_symbolt::expr_mapt::const_iterator
481
- it=src.replace_const .expr_map .begin ();
482
- it!=src.replace_const .expr_map .end ();
483
- ++it)
460
+ for (const auto &m : src.replace_const .expr_map )
484
461
{
485
462
replace_symbolt::expr_mapt::iterator
486
- c_it = replace_const.expr_map .find (it-> first );
463
+ c_it= replace_const.expr_map .find (m. first );
487
464
488
465
if (c_it!=replace_const.expr_map .end ())
489
466
{
490
- if (c_it->second !=it-> second )
467
+ if (c_it->second !=m. second )
491
468
{
492
469
set_to_bottom ();
493
- changed = true ;
470
+ changed= true ;
494
471
break ;
495
472
}
496
473
}
497
474
else
498
475
{
499
- set_to (it-> first , it-> second );
500
- changed = true ;
476
+ set_to (m. first , m. second );
477
+ changed= true ;
501
478
}
502
479
}
503
480
@@ -510,31 +487,7 @@ bool constant_propagator_domaint::merge(
510
487
locationt from,
511
488
locationt to)
512
489
{
513
- const symbol_tablet symbol_table;
514
- const namespacet ns (symbol_table);
515
-
516
- #if 0
517
- if(to->is_skip())
518
- {
519
- std::cout << "This:\n";
520
- values.output(std::cout, ns);
521
- std::cout << "Other:\n";
522
- other.values.output(std::cout, ns);
523
- }
524
- #endif
525
-
526
- bool b;
527
- b=values.merge (other.values );
528
-
529
- #if 0
530
- if(to->is_skip())
531
- {
532
- std::cout << "Merge result:\n";
533
- values.output(std::cout, ns);
534
- }
535
- #endif
536
-
537
- return b;
490
+ return values.merge (other.values );
538
491
}
539
492
540
493
void constant_propagator_ait::replace (
@@ -563,21 +516,22 @@ void constant_propagator_ait::replace(
563
516
if (it->is_goto () || it->is_assume () || it->is_assert ())
564
517
{
565
518
s_it->second .values .replace_const (it->guard );
566
- it-> guard = simplify_expr (it->guard , ns);
519
+ simplify (it->guard , ns);
567
520
}
568
521
else if (it->is_assign ())
569
522
{
570
523
exprt &rhs=to_code_assign (it->code ).rhs ();
571
524
s_it->second .values .replace_const (rhs);
572
- rhs= simplify_expr (rhs, ns);
525
+ simplify (rhs, ns);
573
526
if (rhs.id ()==ID_constant)
574
527
rhs.add_source_location ()=it->code .op0 ().source_location ();
575
528
}
576
529
else if (it->is_function_call ())
577
530
{
578
531
s_it->second .values .replace_const (
579
532
to_code_function_call (it->code ).function ());
580
- simplify_expr (to_code_function_call (it->code ).function (), ns);
533
+
534
+ simplify (to_code_function_call (it->code ).function (), ns);
581
535
582
536
exprt::operandst &args=
583
537
to_code_function_call (it->code ).arguments ();
@@ -586,7 +540,7 @@ void constant_propagator_ait::replace(
586
540
o_it!=args.end (); ++o_it)
587
541
{
588
542
s_it->second .values .replace_const (*o_it);
589
- *o_it= simplify_expr (*o_it, ns);
543
+ simplify (*o_it, ns);
590
544
}
591
545
}
592
546
else if (it->is_other ())
0 commit comments