Skip to content

Commit 8affad0

Browse files
committed
Enable HASH_CODE by default to avoid repeated hash computation
On some SV-COMP benchmark categories, hashing accounts for >20% of CPU time (with profiling enabled) - top five: * ReachSafety-BitVectors: 29.29% (470.54 seconds, which reduces to 4.39 seconds; for benchmarks not timing out we save 170 seconds (25%) in non-profiling mode) * Systems_BusyBox_NoOverflows: 27.98% (284.15 seconds, which reduces to 1.74 seconds; for the 1 benchmark not timing out we save 23 seconds (6%) in non-profiling mode) * Systems_BusyBox_MemSafety: 24.24% (194.74 seconds, which reduces to 0.93 seconds; no measurable difference on the 2 benchmarks not failing/timing out) * NoOverflows-Other: 18.84% (1127.61 seconds, which reduces to 23.57 seconds; for benchmarks not timing out we save 5 seconds (7%) in non-profiling mode) * ReachSafety-ControlFlow: 17.75% (1194.04 seconds, which reduces to 29.17 seconds; for benchmarks not timing out we save 200 seconds (25%) in non-profiling mode) For ReachSafety-ECA it's only 4.7%, which still amounts to 3006.7 seconds. With this change this reduces to 323.07 seconds. On ReachSafety-ECA, this enables 3055.35 symex_step calls per second over 2752.28 calls per second without this change.
1 parent 3b384ed commit 8affad0

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

src/solvers/smt2/letify.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class letifyt
3333
symbol_exprt let_symbol;
3434
};
3535

36-
#ifdef HASH_CODE
36+
#if HASH_CODE
3737
using seen_expressionst = std::unordered_map<exprt, let_count_idt, irep_hash>;
3838
#else
3939
using seen_expressionst = irep_hash_mapt<exprt, let_count_idt>;

src/solvers/smt2/smt2_conv.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/std_expr.h>
1717
#include <util/byte_operators.h>
1818

19-
#ifndef HASH_CODE
20-
#include <util/irep_hash_container.h>
19+
#if !HASH_CODE
20+
# include <util/irep_hash_container.h>
2121
#endif
2222

2323
#include <solvers/prop/prop_conv.h>

src/util/irep.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ std::size_t irept::number_of_non_comments(const named_subt &named_sub)
519519

520520
std::size_t irept::hash() const
521521
{
522-
#ifdef HASH_CODE
522+
#if HASH_CODE
523523
if(read().hash_code!=0)
524524
return read().hash_code;
525525
#endif
@@ -543,7 +543,7 @@ std::size_t irept::hash() const
543543

544544
result = hash_finalize(result, sub.size() + number_of_named_ireps);
545545

546-
#ifdef HASH_CODE
546+
#if HASH_CODE
547547
read().hash_code=result;
548548
#endif
549549
#ifdef IREP_HASH_STATS

src/util/irep.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ Author: Daniel Kroening, [email protected]
1717
#include "irep_ids.h"
1818

1919
#define SHARING
20-
// #define HASH_CODE
20+
#ifndef HASH_CODE
21+
# define HASH_CODE 1
22+
#endif
2123
// #define NAMED_SUB_IS_FORWARD_LIST
2224

2325
#ifdef NAMED_SUB_IS_FORWARD_LIST
@@ -138,7 +140,7 @@ class tree_nodet : public ref_count_ift<sharing>
138140
named_subt named_sub;
139141
subt sub;
140142

141-
#ifdef HASH_CODE
143+
#if HASH_CODE
142144
mutable std::size_t hash_code = 0;
143145
#endif
144146

@@ -147,7 +149,7 @@ class tree_nodet : public ref_count_ift<sharing>
147149
data.clear();
148150
sub.clear();
149151
named_sub.clear();
150-
#ifdef HASH_CODE
152+
#if HASH_CODE
151153
hash_code = 0;
152154
#endif
153155
}
@@ -157,7 +159,7 @@ class tree_nodet : public ref_count_ift<sharing>
157159
d.data.swap(data);
158160
d.sub.swap(sub);
159161
d.named_sub.swap(named_sub);
160-
#ifdef HASH_CODE
162+
#if HASH_CODE
161163
std::swap(d.hash_code, hash_code);
162164
#endif
163165
}
@@ -278,7 +280,7 @@ class sharing_treet
278280
dt &write()
279281
{
280282
detach();
281-
#ifdef HASH_CODE
283+
#if HASH_CODE
282284
data->hash_code = 0;
283285
#endif
284286
return *data;
@@ -319,7 +321,7 @@ class non_sharing_treet
319321

320322
dt &write()
321323
{
322-
#ifdef HASH_CODE
324+
#if HASH_CODE
323325
data.hash_code = 0;
324326
#endif
325327
return data;

unit/util/irep.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ SCENARIO("irept_memory", "[core][utils][irept]")
5353
# endif
5454
#endif
5555

56-
#ifdef HASH_CODE
56+
#if HASH_CODE
5757
const std::size_t hash_code_size = sizeof(std::size_t);
5858
#else
5959
const std::size_t hash_code_size = 0;

0 commit comments

Comments
 (0)