Skip to content

Commit 746cf0d

Browse files
committed
Unload of LVSA summaries on demand using refcounting.
1 parent b26dded commit 746cf0d

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

src/taint-analysis/taint_summary.cpp

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,12 +1726,48 @@ void taint_summarise_all_functions(
17261726
{
17271727
size_t processed = 0UL;
17281728
size_t modelled = 0UL;
1729-
size_t skipped = 0UL;
1729+
std::unordered_set<irep_idt> skipped;
17301730

17311731
const std::size_t topological_order_size =
17321732
program->get_inverted_functions_topological_order().size();
17331733

17341734
auto start_time=std::chrono::high_resolution_clock::now();
1735+
1736+
typedef std::pair<std::size_t, std::unordered_set<irep_idt>>
1737+
refcount_and_calleest;
1738+
std::unordered_map<irep_idt, refcount_and_calleest> lvsadb_flush_ref_counts;
1739+
for(const auto &fn_name :
1740+
program->get_inverted_functions_topological_order())
1741+
{
1742+
const auto self_it =
1743+
lvsadb_flush_ref_counts.insert({fn_name, {0UL, {}}}).first;
1744+
const auto node =
1745+
*program->get_directed_call_graph().get_node_index(fn_name);
1746+
for(const auto &succ_node :
1747+
program->get_directed_call_graph().get_successors(node))
1748+
{
1749+
const auto &callee_name =
1750+
program->get_directed_call_graph()[succ_node].function;
1751+
if(callee_name != fn_name) // Skip direct recursion.
1752+
{
1753+
auto it = lvsadb_flush_ref_counts.find(callee_name);
1754+
if(it != lvsadb_flush_ref_counts.end()) // Skip indirect recursion.
1755+
{
1756+
it->second.first += 1UL;
1757+
self_it->second.second.insert(callee_name);
1758+
}
1759+
}
1760+
}
1761+
}
1762+
for(auto &elem : lvsadb_flush_ref_counts)
1763+
{
1764+
if(elem.second.first == 0UL) // No caller -> unload yourself
1765+
{
1766+
elem.second.first = 1UL;
1767+
elem.second.second.insert(elem.first);
1768+
}
1769+
}
1770+
17351771
for(const auto &fn_name :
17361772
program->get_inverted_functions_topological_order())
17371773
{
@@ -1743,7 +1779,7 @@ void taint_summarise_all_functions(
17431779
<< "["
17441780
<< std::fixed << std::setprecision(1) << std::setw(5)
17451781
<< (topological_order_size==0UL?100.0:
1746-
100.0*(double)(processed+skipped)/
1782+
100.0*(double)(processed+skipped.size())/
17471783
(double)topological_order_size)
17481784
<< "%] "
17491785
<< " TIMEOUT! ("
@@ -1765,7 +1801,7 @@ void taint_summarise_all_functions(
17651801
<< "["
17661802
<< std::fixed << std::setprecision(1) << std::setw(5)
17671803
<< (topological_order_size==0UL?100.0:
1768-
100.0*(double)(processed+skipped)/
1804+
100.0*(double)(processed+skipped.size())/
17691805
(double)topological_order_size)
17701806
<< "%] "
17711807
<< fn_name
@@ -1790,22 +1826,40 @@ void taint_summarise_all_functions(
17901826
<< "["
17911827
<< std::fixed << std::setprecision(1) << std::setw(5)
17921828
<< (topological_order_size==0UL?100.0:
1793-
100.0*(double)(processed+skipped)/
1829+
100.0*(double)(processed+skipped.size())/
17941830
(double)topological_order_size)
17951831
<< "%] Skipping"
17961832
<< (fn_it!=functions_map.cend() && !fn_it->second.body_available()
17971833
? " [function without a body]" : "")
17981834
<< ": "
17991835
<< fn_name
18001836
<< messaget::eom;
1801-
++skipped;
1837+
skipped.insert(fn_name);
1838+
}
1839+
1840+
for(auto &succ : lvsadb_flush_ref_counts.at(fn_name).second)
1841+
{
1842+
auto &elem = lvsadb_flush_ref_counts.at(succ);
1843+
if(elem.first > 0UL)
1844+
{
1845+
--elem.first;
1846+
if(elem.first == 0UL)
1847+
{
1848+
std::cout << "@@@ Trying to flush: " << succ << std::endl;
1849+
const bool unloaded = lvsa_db.unload(succ);
1850+
INVARIANT(unloaded || skipped.count(succ) != 0UL,
1851+
"Either the LVSA summary was unloaded or there was "
1852+
"nothing to unload (the summary computation was "
1853+
"skipped).");
1854+
}
1855+
}
18021856
}
18031857
}
18041858
log->status()
18051859
<< "[100.0%] Summarisation of functions has finished successfully ("
18061860
<< processed << " processed, "
18071861
<< modelled << " modelled, "
1808-
<< skipped << " skipped)."
1862+
<< skipped.size() << " skipped)."
18091863
<< messaget::eom;
18101864
}
18111865

0 commit comments

Comments
 (0)