Skip to content

Commit cfcc7e8

Browse files
committed
Use std::forward_list instead of std::map in irept by default
This reduces the size of an irept by 5 pointers (i.e., 40 bytes on 64-bit systems). On SV-COMP's ReachSafety-ECA with this change we can perform 3819.81 symex_step calls per second, compared to 2752.28 calls per second with the std::map configuration. The performance improvements are spread across various `irept`-related operations.
1 parent 16072c1 commit cfcc7e8

File tree

9 files changed

+22
-19
lines changed

9 files changed

+22
-19
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ jobs:
182182
- WITH_MEMORY_ANALYZER=1
183183
script: echo "Not running any tests for a debug build."
184184

185-
# cmake build using g++-7, enable NAMED_SUB_IS_FORWARD_LIST
185+
# cmake build using g++-7, disable NAMED_SUB_IS_FORWARD_LIST
186186
- stage: Test different OS/CXX/Flags
187187
os: linux
188188
sudo: false
@@ -205,7 +205,7 @@ jobs:
205205
install:
206206
- ccache -z
207207
- ccache --max-size=1G
208-
- cmake -H. -Bbuild '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_CXX_COMPILER=/usr/bin/g++-7' '-DCMAKE_CXX_FLAGS=-DNAMED_SUB_IS_FORWARD_LIST' '-DWITH_MEMORY_ANALYZER=On'
208+
- cmake -H. -Bbuild '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_CXX_COMPILER=/usr/bin/g++-7' '-DCMAKE_CXX_FLAGS=-DNAMED_SUB_IS_FORWARD_LIST=0' '-DWITH_MEMORY_ANALYZER=On'
209209
- git submodule update --init --recursive
210210
- cmake --build build -- -j4
211211
script: (cd build; bin/unit "[core][irept]")

src/util/irep.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void irept::set(const irep_namet &name, const long long value)
9292

9393
void irept::remove(const irep_namet &name)
9494
{
95-
#ifdef NAMED_SUB_IS_FORWARD_LIST
95+
#if NAMED_SUB_IS_FORWARD_LIST
9696
return get_named_sub().remove(name);
9797
#else
9898
named_subt &s = get_named_sub();
@@ -120,7 +120,7 @@ irept &irept::add(const irep_namet &name, irept irep)
120120
{
121121
named_subt &s = get_named_sub();
122122

123-
#ifdef NAMED_SUB_IS_FORWARD_LIST
123+
#if NAMED_SUB_IS_FORWARD_LIST
124124
return s.add(name, std::move(irep));
125125
#else
126126
std::pair<named_subt::iterator, bool> entry = s.emplace(

src/util/irep.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ Author: Daniel Kroening, [email protected]
2020
#ifndef HASH_CODE
2121
# define HASH_CODE 1
2222
#endif
23-
// #define NAMED_SUB_IS_FORWARD_LIST
23+
#ifndef NAMED_SUB_IS_FORWARD_LIST
24+
# define NAMED_SUB_IS_FORWARD_LIST 1
25+
#endif
2426

25-
#ifdef NAMED_SUB_IS_FORWARD_LIST
27+
#if NAMED_SUB_IS_FORWARD_LIST
2628
# include "forward_list_as_map.h"
2729
#else
2830
#include <map>
@@ -386,7 +388,7 @@ class irept
386388
: public non_sharing_treet<
387389
irept,
388390
#endif
389-
#ifdef NAMED_SUB_IS_FORWARD_LIST
391+
#if NAMED_SUB_IS_FORWARD_LIST
390392
forward_list_as_mapt<irep_namet, irept>>
391393
#else
392394
std::map<irep_namet, irept>>

src/util/irep_hash_container.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void irep_hash_container_baset::pack(
5555
{
5656
// we pack: the irep id, the sub size, the subs, the named-sub size, and
5757
// each of the named subs with their ids
58-
#ifdef NAMED_SUB_IS_FORWARD_LIST
58+
#if NAMED_SUB_IS_FORWARD_LIST
5959
const std::size_t named_sub_size =
6060
std::distance(named_sub.begin(), named_sub.end());
6161
#else

src/util/irep_serialization.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ irept irep_serializationt::read_irep(std::istream &in)
7676
sub.push_back(reference_convert(in));
7777
}
7878

79-
#ifdef NAMED_SUB_IS_FORWARD_LIST
79+
#if NAMED_SUB_IS_FORWARD_LIST
8080
irept::named_subt::iterator before = named_sub.before_begin();
8181
#endif
8282
while(in.peek()=='N')
8383
{
8484
in.get();
8585
irep_idt id = read_string_ref(in);
86-
#ifdef NAMED_SUB_IS_FORWARD_LIST
86+
#if NAMED_SUB_IS_FORWARD_LIST
8787
named_sub.emplace_after(before, id, reference_convert(in));
8888
++before;
8989
#else
@@ -95,7 +95,7 @@ irept irep_serializationt::read_irep(std::istream &in)
9595
{
9696
in.get();
9797
irep_idt id = read_string_ref(in);
98-
#ifdef NAMED_SUB_IS_FORWARD_LIST
98+
#if NAMED_SUB_IS_FORWARD_LIST
9999
named_sub.emplace_after(before, id, reference_convert(in));
100100
++before;
101101
#else

src/util/lispirep.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void irep2lisp(const irept &src, lispexprt &dest)
4646
dest.value.clear();
4747
dest.type=lispexprt::List;
4848

49-
#ifdef NAMED_SUB_IS_FORWARD_LIST
49+
#if NAMED_SUB_IS_FORWARD_LIST
5050
const std::size_t named_sub_size =
5151
std::distance(src.get_named_sub().begin(), src.get_named_sub().end());
5252
#else

src/util/merge_irep.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bool to_be_merged_irept::operator == (const to_be_merged_irept &other) const
4646

4747
if(sub.size()!=o_sub.size())
4848
return false;
49-
#ifdef NAMED_SUB_IS_FORWARD_LIST
49+
#if NAMED_SUB_IS_FORWARD_LIST
5050
if(
5151
std::distance(named_sub.begin(), named_sub.end()) !=
5252
std::distance(o_named_sub.begin(), o_named_sub.end()))
@@ -105,12 +105,12 @@ const merged_irept &merged_irepst::merged(const irept &irep)
105105
const irept::named_subt &src_named_sub=irep.get_named_sub();
106106
irept::named_subt &dest_named_sub=new_irep.get_named_sub();
107107

108-
#ifdef NAMED_SUB_IS_FORWARD_LIST
108+
#if NAMED_SUB_IS_FORWARD_LIST
109109
irept::named_subt::iterator before = dest_named_sub.before_begin();
110110
#endif
111111
forall_named_irep(it, src_named_sub)
112112
{
113-
#ifdef NAMED_SUB_IS_FORWARD_LIST
113+
#if NAMED_SUB_IS_FORWARD_LIST
114114
dest_named_sub.emplace_after(
115115
before, it->first, merged(it->second)); // recursive call
116116
++before;
@@ -209,12 +209,12 @@ const irept &merge_full_irept::merged(const irept &irep)
209209
const irept::named_subt &src_named_sub=irep.get_named_sub();
210210
irept::named_subt &dest_named_sub=new_irep.get_named_sub();
211211

212-
#ifdef NAMED_SUB_IS_FORWARD_LIST
212+
#if NAMED_SUB_IS_FORWARD_LIST
213213
irept::named_subt::iterator before = dest_named_sub.before_begin();
214214
#endif
215215
forall_named_irep(it, src_named_sub)
216216
{
217-
#ifdef NAMED_SUB_IS_FORWARD_LIST
217+
#if NAMED_SUB_IS_FORWARD_LIST
218218
dest_named_sub.emplace_after(
219219
before, it->first, merged(it->second)); // recursive call
220220
++before;

src/util/type.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class typet:public irept
3232

3333
explicit typet(const irep_idt &_id):irept(_id) { }
3434

35-
#if defined(__clang__) || !defined(__GNUC__) || __GNUC__ >= 6
35+
// the STL implementation shipped with GCC 5 is broken
36+
#if !defined(__GLIBCXX__) || __GLIBCXX__ >= 20181026
3637
typet(irep_idt _id, typet _subtype)
3738
: irept(std::move(_id), {}, {std::move(_subtype)})
3839
{

unit/util/irep.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ SCENARIO("irept_memory", "[core][utils][irept]")
3535
REQUIRE(sizeof(std::vector<int>) == 3 * sizeof(void *));
3636
#endif
3737

38-
#ifndef NAMED_SUB_IS_FORWARD_LIST
38+
#if !NAMED_SUB_IS_FORWARD_LIST
3939
const std::size_t named_size = sizeof(std::map<int, int>);
4040
# ifndef _GLIBCXX_DEBUG
4141
# ifdef __APPLE__

0 commit comments

Comments
 (0)