Skip to content

Commit 9df4a26

Browse files
Set a limit size for array cell propagation
The use of field_sensitivity for arrays can be expensive for big arrays so we have to set a limit on the size of constant arrays which get processed. The value 64 was determined by changing the size of the array in the test regression/cbmc/variable-access-to-constant-array and reducing it until there was no significant difference in execution time between the versions of CBMC with and without array cell propagation. For the chosen value the execution time was around 0.05 second in both cases (for comparison with size 1024 the time with propagation was 0.5 sec, against 0.1 without).
1 parent 6e02c69 commit 9df4a26

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/goto-symex/field_sensitivity.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ exprt field_sensitivityt::apply(
9898
bool was_l2 = !tmp.get_level_2().empty();
9999
if(
100100
to_array_type(l2_array.get().type()).size().id() == ID_constant &&
101+
numeric_cast_v<mp_integer>(to_constant_expr(to_array_type(
102+
l2_array.get().type()).size()))
103+
<= max_field_sensitive_array_size &&
101104
l2_index.get().id() == ID_constant)
102105
{
103106
// place the entire index expression, not just the array operand, in an
@@ -154,7 +157,9 @@ exprt field_sensitivityt::get_fields(
154157
#ifdef ENABLE_ARRAY_FIELD_SENSITIVITY
155158
else if(
156159
ssa_expr.type().id() == ID_array &&
157-
to_array_type(ssa_expr.type()).size().id() == ID_constant)
160+
to_array_type(ssa_expr.type()).size().id() == ID_constant &&
161+
numeric_cast_v<mp_integer>(to_constant_expr(
162+
to_array_type(ssa_expr.type()).size())) <= max_field_sensitive_array_size)
158163
{
159164
const array_typet &type = to_array_type(ssa_expr.type());
160165
const std::size_t array_size =
@@ -276,6 +281,9 @@ void field_sensitivityt::field_assignments_rec(
276281
numeric_cast_v<std::size_t>(to_constant_expr(type->size()));
277282
PRECONDITION(lhs_fs.operands().size() == array_size);
278283

284+
if(array_size > max_field_sensitive_array_size)
285+
return;
286+
279287
exprt::operandst::const_iterator fs_it = lhs_fs.operands().begin();
280288
for(std::size_t i = 0; i < array_size; ++i)
281289
{
@@ -315,7 +323,9 @@ bool field_sensitivityt::is_divisible(const ssa_exprt &expr)
315323
#ifdef ENABLE_ARRAY_FIELD_SENSITIVITY
316324
if(
317325
expr.type().id() == ID_array &&
318-
to_array_type(expr.type()).size().id() == ID_constant)
326+
to_array_type(expr.type()).size().id() == ID_constant &&
327+
numeric_cast_v<mp_integer>(to_constant_expr(to_array_type(expr.type()).size()))
328+
<= max_field_sensitive_array_size)
319329
{
320330
return true;
321331
}

src/goto-symex/field_sensitivity.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Author: Michael Tautschnig
99
#ifndef CPROVER_GOTO_SYMEX_FIELD_SENSITIVITY_H
1010
#define CPROVER_GOTO_SYMEX_FIELD_SENSITIVITY_H
1111

12+
/// Limit the size of arrays for which field_sensitivity gets applied.
13+
/// Necessary because large constant arrays slow-down the process.
14+
static constexpr unsigned max_field_sensitive_array_size = 64;
15+
1216
class exprt;
1317
class ssa_exprt;
1418
class namespacet;

0 commit comments

Comments
 (0)