Commit 06c69f88 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Introduce tgba::release_iter().

Instead of "delete iter;" we now do "aut->release_iter(iter);" to
give the iterator back to the automaton.  The TGBA classes now
reuse a previously returned tgba_succ_iterator to answer a succ_iter()
call, therefore avoiding (1) memory allocation, as well as (2) vtable
and other constant member initialization.

* src/tgba/tgba.hh, src/tgba/tgba.cc (release_iter, iter_cache_):
Implement a release_iter() that stores the released iterator
in iter_cache_.
* src/tgba/succiter.hh (internal::succ_iterable): Move...
* src/tgba/tgba.hh (tgba::succ_iterable): ... here. And use
release_iter().

* iface/dve2/dve2.cc, src/kripke/kripke.cc, src/kripke/kripke.hh,
src/tgba/succiterconcrete.cc, src/tgba/succiterconcrete.hh,
src/tgba/taatgba.hh, src/tgba/tgbabddconcrete.cc,
src/tgba/tgbaexplicit.hh, src/tgba/tgbamask.cc, src/tgba/tgbaproduct.cc,
src/tgba/tgbaproxy.cc, src/tgba/tgbascc.cc, src/tgba/tgbatba.cc,
src/tgba/tgbaunion.cc, src/tgba/tgbaunion.hh, src/tgba/wdbacomp.cc,
src/tgbaalgos/bfssteps.cc, src/tgbaalgos/compsusp.cc,
src/tgbaalgos/cycles.cc, src/tgbaalgos/dtbasat.cc,
src/tgbaalgos/dtgbasat.cc, src/tgbaalgos/gtec/gtec.cc,
src/tgbaalgos/gv04.cc, src/tgbaalgos/isweakscc.cc,
src/tgbaalgos/lbtt.cc, src/tgbaalgos/ltl2tgba_fm.cc,
src/tgbaalgos/magic.cc, src/tgbaalgos/ndfs_result.hxx,
src/tgbaalgos/neverclaim.cc, src/tgbaalgos/reachiter.cc,
src/tgbaalgos/replayrun.cc, src/tgbaalgos/safety.cc,
src/tgbaalgos/scc.cc, src/tgbaalgos/se05.cc,
src/tgbaalgos/simulation.cc, src/tgbaalgos/tau03.cc,
src/tgbaalgos/tau03opt.cc: Use release_iter() instead of deleting
iterators, and used recycle iter_cache_ in implementations of
tgba::succ_iter().
parent 487cd01d
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2012 Laboratoire de Recherche et Développement
// Copyright (C) 2011, 2012, 2014 Laboratoire de Recherche et Développement
// de l'Epita (LRDE)
//
// This file is part of Spot, a model checking library.
......@@ -214,9 +214,8 @@ namespace spot
~callback_context()
{
callback_context::transitions_t::const_iterator it;
for (it = transitions.begin(); it != transitions.end(); ++it)
(*it)->destroy();
for (auto t: transitions)
t->destroy();
}
};
......@@ -260,6 +259,13 @@ namespace spot
{
}
void recycle(const callback_context* cc, bdd cond)
{
delete cc_;
cc_ = cc;
kripke_succ_iterator::recycle(cond);
}
~dve2_succ_iterator()
{
delete cc_;
......@@ -661,6 +667,11 @@ namespace spot
~dve2_kripke()
{
if (iter_cache_)
{
delete iter_cache_;
iter_cache_ = nullptr;
}
delete[] format_filter_;
delete[] vname_;
if (compress_)
......@@ -857,6 +868,14 @@ namespace spot
cc->transitions.push_back(local_state->clone());
}
if (iter_cache_)
{
dve2_succ_iterator* it =
down_cast<dve2_succ_iterator*>(iter_cache_);
it->recycle(cc, scond);
iter_cache_ = nullptr;
return it;
}
return new dve2_succ_iterator(cc, scond);
}
......
// Copyright (C) 2009, 2010 Laboratoire de Recherche et Developpement de l'Epita
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2010, 2014 Laboratoire de Recherche et
// Developpement de l'Epita
//
// This file is part of Spot, a model checking library.
//
......@@ -20,11 +22,6 @@
namespace spot
{
kripke_succ_iterator::kripke_succ_iterator(const bdd& cond)
: cond_(cond)
{
}
kripke_succ_iterator::~kripke_succ_iterator()
{
}
......
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2010, 2013 Laboratoire de Recherche et
// Copyright (C) 2009, 2010, 2013, 2014 Laboratoire de Recherche et
// Developpement de l'Epita
//
// This file is part of Spot, a model checking library.
......@@ -48,7 +48,16 @@ namespace spot
///
/// The \a cond argument will be the one returned
/// by kripke_succ_iterator::current_condition().
kripke_succ_iterator(const bdd& cond);
kripke_succ_iterator(const bdd& cond)
: cond_(cond)
{
}
void recycle(const bdd& cond)
{
cond_ = cond;
}
virtual ~kripke_succ_iterator();
virtual bdd current_condition() const;
......
......@@ -27,6 +27,8 @@
namespace spot
{
class tgba;
/// \ingroup tgba_essentials
/// \brief Iterate over the successors of a state.
///
......@@ -100,8 +102,6 @@ namespace spot
//@}
};
class tgba;
namespace internal
{
struct SPOT_API succ_iterator
......@@ -137,34 +137,6 @@ namespace spot
it_ = nullptr;
}
};
class SPOT_API succ_iterable
{
protected:
const tgba* aut_;
tgba_succ_iterator* it_;
public:
succ_iterable(const tgba* aut, tgba_succ_iterator* it)
: aut_(aut), it_(it)
{
}
~succ_iterable()
{
delete it_;
}
succ_iterator begin()
{
it_->first();
return it_->done() ? nullptr : it_;
}
succ_iterator end()
{
return nullptr;
}
};
}
}
......
// Copyright (C) 2009 Laboratoire de Recherche et Développement
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2014 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
......@@ -24,15 +25,6 @@
namespace spot
{
tgba_succ_iterator_concrete::tgba_succ_iterator_concrete
(const tgba_bdd_core_data& d, bdd successors)
: data_(d),
succ_set_(successors),
succ_set_left_(successors),
current_(bddfalse)
{
}
tgba_succ_iterator_concrete::~tgba_succ_iterator_concrete()
{
}
......
// -*- coding: utf-8 -*-
// Copyright (C) 2013 Laboratoire de Recherche et Developpement de
// Copyright (C) 2013, 2014 Laboratoire de Recherche et Developpement de
// l'Epita (LRDE).
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
......@@ -45,7 +45,19 @@ namespace spot
/// \param d The core data of the automata.
/// These contains sets of variables useful to split a BDD, and
/// compute acceptance conditions.
tgba_succ_iterator_concrete(const tgba_bdd_core_data& d, bdd successors);
tgba_succ_iterator_concrete(const tgba_bdd_core_data& d, bdd successors)
: data_(d)
{
recycle(successors);
}
void recycle(bdd successors)
{
succ_set_ = successors;
succ_set_left_ = successors;
current_ = bddfalse;
}
virtual ~tgba_succ_iterator_concrete();
// iteration
......
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2011, 2012, 2013 Laboratoire de Recherche et
// Copyright (C) 2009, 2011, 2012, 2013, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......
// Copyright (C) 2011 Laboratoire de Recherche et Developpement de
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2014 Laboratoire de Recherche et Developpement de
// l'EPITA (LRDE).
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
......@@ -24,7 +25,8 @@
namespace spot
{
tgba::tgba()
: last_support_conditions_input_(0),
: iter_cache_(nullptr),
last_support_conditions_input_(0),
last_support_variables_input_(0),
num_acc_(-1)
{
......@@ -36,6 +38,7 @@ namespace spot
last_support_conditions_input_->destroy();
if (last_support_variables_input_)
last_support_variables_input_->destroy();
delete iter_cache_;
}
bdd
......
......@@ -71,8 +71,48 @@ namespace spot
{
protected:
tgba();
// Any iterator returned via release_iter.
mutable tgba_succ_iterator* iter_cache_;
public:
#ifndef SWIG
class succ_iterable
{
protected:
const tgba* aut_;
tgba_succ_iterator* it_;
public:
succ_iterable(const tgba* aut, tgba_succ_iterator* it)
: aut_(aut), it_(it)
{
}
succ_iterable(succ_iterable&& other)
: aut_(other.aut_), it_(other.it_)
{
other.it_ = nullptr;
}
~succ_iterable()
{
if (it_)
aut_->release_iter(it_);
}
internal::succ_iterator begin()
{
it_->first();
return it_->done() ? nullptr : it_;
}
internal::succ_iterator end()
{
return nullptr;
}
};
#endif
virtual ~tgba();
/// \brief Get the initial state of the automaton.
......@@ -111,15 +151,29 @@ namespace spot
const state* global_state = nullptr,
const tgba* global_automaton = nullptr) const = 0;
#ifndef SWIG
/// \brief Build an iterable over the successors of \a s.
///
/// This is meant to be used as
/// <code>for (auto i: aut->out(s)) { /* i->current_state() */ }</code>.
internal::succ_iterable
succ_iterable
succ(const state* s) const
{
return {this, succ_iter(s)};
}
#endif
/// \brief Release an iterator after usage.
///
/// This iterator can then be reused by succ_iter() to avoid
/// memory allocation.
void release_iter(tgba_succ_iterator* i) const
{
if (iter_cache_)
delete i;
else
iter_cache_ = i;
}
/// \brief Get a formula that must hold whatever successor is taken.
///
......
// Copyright (C) 2011 Laboratoire de Recherche et Développement de
// l'Epita (LRDE).
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2014 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
......@@ -107,6 +108,15 @@ namespace spot
bdd global_conds = global_automaton->support_conditions(global_state);
succ_set = bdd_appexcomp(succ_set, global_conds, bddop_and, varused);
}
// Do not allocate an iterator if we can reuse one.
if (iter_cache_)
{
tgba_succ_iterator_concrete* res =
down_cast<tgba_succ_iterator_concrete*>(iter_cache_);
iter_cache_ = nullptr;
res->recycle(succ_set);
return res;
}
return new tgba_succ_iterator_concrete(data_, succ_set);
}
......
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2010, 2011, 2012, 2013 Laboratoire de Recherche
// et Développement de l'Epita.
// Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Laboratoire de
// Recherche et Développement de l'Epita.
// Copyright (C) 2003, 2004, 2006 Laboratoire d'Informatique de Paris
// 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie.
......@@ -202,6 +202,12 @@ namespace spot
{
}
void recycle(const State* start, bdd all_acc)
{
start_ = start;
all_acceptance_conditions_ = all_acc;
}
virtual void first()
{
it_ = start_->successors.begin();
......@@ -508,6 +514,14 @@ namespace spot
(void) global_state;
(void) global_automaton;
if (this->iter_cache_)
{
tgba_explicit_succ_iterator<State>* it =
down_cast<tgba_explicit_succ_iterator<State>*>(this->iter_cache_);
it->recycle(s, this->all_acceptance_conditions());
this->iter_cache_ = nullptr;
return it;
}
return
new tgba_explicit_succ_iterator<State>(s,
this
......
......@@ -141,7 +141,16 @@ namespace spot
const state*,
const tgba*) const
{
succ_iter_filtered* res = new succ_iter_filtered;
succ_iter_filtered* res;
if (iter_cache_)
{
res = down_cast<succ_iter_filtered*>(iter_cache_);
iter_cache_ = nullptr;
}
else
{
res = new succ_iter_filtered;
}
for (auto it: original_->succ(local_state))
{
const state* s = it->current_state();
......
// Copyright (C) 2009, 2011, 2012 Laboratoire de Recherche et
// Dveloppement de l'Epita (LRDE).
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2011, 2012, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
// Copyright (C) 2003, 2004, 2006 Laboratoire d'Informatique de
// Paris 6 (LIP6), dpartement Systmes Rpartis Coopratifs (SRC),
// Universit Pierre et Marie Curie.
// Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
......@@ -88,6 +89,15 @@ namespace spot
{
}
void recycle(const tgba* l, tgba_succ_iterator* left,
const tgba* r, tgba_succ_iterator* right)
{
l->release_iter(left_);
left_ = left;
r->release_iter(right_);
right_ = right;
}
virtual ~tgba_succ_iterator_product_common()
{
delete left_;
......@@ -390,6 +400,15 @@ namespace spot
tgba_succ_iterator* ri = right_->succ_iter(s->right(),
global_state, global_automaton);
if (iter_cache_)
{
tgba_succ_iterator_product_common* it =
down_cast<tgba_succ_iterator_product_common*>(iter_cache_);
it->recycle(left_, li, right_, ri);
iter_cache_ = nullptr;
return it;
}
fixed_size_pool* p = const_cast<fixed_size_pool*>(&pool_);
if (left_kripke_)
return new tgba_succ_iterator_product_kripke(li, ri, p);
......
// Copyright (C) 2013 Laboratoire de Recherche et
// -*- coding: utf-8 -*-
// Copyright (C) 2013, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -41,6 +42,11 @@ namespace spot
const state* global_state,
const tgba* global_automaton) const
{
if (iter_cache_)
{
original_->release_iter(iter_cache_);
iter_cache_ = nullptr;
}
return original_->succ_iter(local_state, global_state, global_automaton);
}
......
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2012, 2013 Laboratoire de recherche et
// Copyright (C) 2009, 2012, 2013, 2014 Laboratoire de recherche et
// développement de l'Epita.
//
// This file is part of Spot, a model checking library.
......@@ -50,6 +50,11 @@ namespace spot
const state* global_state,
const tgba* global_automaton) const
{
if (iter_cache_)
{
aut_->release_iter(iter_cache_);
iter_cache_ = nullptr;
}
return aut_->succ_iter(local_state, global_state, global_automaton);
}
......
......@@ -170,14 +170,29 @@ namespace spot
typedef tgba_tba_proxy::cycle_list::const_iterator iterator;
public:
tgba_tba_proxy_succ_iterator(const state* rs,
tgba_succ_iterator* it,
tgba::succ_iterable&& iterable,
iterator expected,
const list& cycle,
bdd the_acceptance_cond,
const tgba_tba_proxy* aut)
: the_acceptance_cond_(the_acceptance_cond)
{
for (it->first(); !it->done(); it->next())
recycle(rs, std::move(iterable), expected, cycle, aut);
}
void recycle(const state* rs,
tgba::succ_iterable&& iterable,
iterator expected,
const list& cycle,
const tgba_tba_proxy* aut)
{
if (!transmap_.empty())
{
translist_.clear();
transmap_.clear();
}
for (auto it: iterable)
{
bool accepting;
bdd acc = it->current_acceptance_conditions();
......@@ -324,20 +339,11 @@ namespace spot
dest->destroy();
}
}
delete it;
}
virtual
~tgba_tba_proxy_succ_iterator()
{
for (transmap_t::const_iterator i = transmap_.begin();
i != transmap_.end();)
{
const state* d = i->first.first;
// Advance i before deleting d.
++i;
d->destroy();
}
}
// iteration
......@@ -492,17 +498,23 @@ namespace spot
tgba_succ_iterator*
tgba_tba_proxy::succ_iter(const state* local_state,
const state* global_state,
const tgba* global_automaton) const
const state*, const tgba*) const
{
const state_tba_proxy* s =
down_cast<const state_tba_proxy*>(local_state);
assert(s);
const state* rs = s->real_state();
tgba_succ_iterator* it = a_->succ_iter(rs, global_state, global_automaton);
return new tgba_tba_proxy_succ_iterator(rs, it,
if (iter_cache_)
{
tgba_tba_proxy_succ_iterator* res =
down_cast<tgba_tba_proxy_succ_iterator*>(iter_cache_);
res->recycle(rs, a_->succ(rs),
s->acceptance_iterator(), acc_cycle_, this);
iter_cache_ = nullptr;
return res;
}
return new tgba_tba_proxy_succ_iterator(rs, a_->succ(rs),
s->acceptance_iterator(),
acc_cycle_, the_acceptance_cond_,
this);
......
// Copyright (C) 2009, 2011 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2011, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
......@@ -94,6 +95,16 @@ namespace spot
{
}
void
tgba_succ_iterator_union::recycle(const tgba* l, tgba_succ_iterator* left,
const tgba* r, tgba_succ_iterator* right)
{
l->release_iter(left_);
left_ = left;
r->release_iter(right_);
right_ = right;
}
tgba_succ_iterator_union::~tgba_succ_iterator_union()
{
delete left_;
......@@ -278,44 +289,45 @@ namespace spot
(void) global_automaton;
const state_union* s = down_cast<const state_union*>(local_state);
assert(s);
tgba_succ_iterator_union* res = 0;
// Is it the initial state ?
tgba_succ_iterator* li;
tgba_succ_iterator* ri;
if (!s->left() && !s->right())
{
// Yes, create an iterator with both initial states.
state* left_init = left_->get_init_state();
state* right_init = right_->get_init_state();
tgba_succ_iterator* li = left_->succ_iter(left_init);
tgba_succ_iterator* ri = right_->succ_iter(right_init);
res = new tgba_succ_iterator_union(li, ri, left_acc_missing_,
right_acc_missing_,
left_var_missing_,
right_var_missing_);
left_init->destroy();
right_init->destroy();
}
{
// Yes, create an iterator with both initial states.
state* left_init = left_->get_init_state();
state* right_init = right_->get_init_state();
li = left_->succ_iter(left_init);
ri = right_->succ_iter(right_init);
left_init->destroy();