@@ -1726,12 +1726,48 @@ void taint_summarise_all_functions(
1726
1726
{
1727
1727
size_t processed = 0UL ;
1728
1728
size_t modelled = 0UL ;
1729
- size_t skipped = 0UL ;
1729
+ std::unordered_set<irep_idt> skipped;
1730
1730
1731
1731
const std::size_t topological_order_size =
1732
1732
program->get_inverted_functions_topological_order ().size ();
1733
1733
1734
1734
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
+
1735
1771
for (const auto &fn_name :
1736
1772
program->get_inverted_functions_topological_order ())
1737
1773
{
@@ -1743,7 +1779,7 @@ void taint_summarise_all_functions(
1743
1779
<< " ["
1744
1780
<< std::fixed << std::setprecision (1 ) << std::setw (5 )
1745
1781
<< (topological_order_size==0UL ?100.0 :
1746
- 100.0 *(double )(processed+skipped)/
1782
+ 100.0 *(double )(processed+skipped. size () )/
1747
1783
(double )topological_order_size)
1748
1784
<< " %] "
1749
1785
<< " TIMEOUT! ("
@@ -1765,7 +1801,7 @@ void taint_summarise_all_functions(
1765
1801
<< " ["
1766
1802
<< std::fixed << std::setprecision (1 ) << std::setw (5 )
1767
1803
<< (topological_order_size==0UL ?100.0 :
1768
- 100.0 *(double )(processed+skipped)/
1804
+ 100.0 *(double )(processed+skipped. size () )/
1769
1805
(double )topological_order_size)
1770
1806
<< " %] "
1771
1807
<< fn_name
@@ -1790,22 +1826,40 @@ void taint_summarise_all_functions(
1790
1826
<< " ["
1791
1827
<< std::fixed << std::setprecision (1 ) << std::setw (5 )
1792
1828
<< (topological_order_size==0UL ?100.0 :
1793
- 100.0 *(double )(processed+skipped)/
1829
+ 100.0 *(double )(processed+skipped. size () )/
1794
1830
(double )topological_order_size)
1795
1831
<< " %] Skipping"
1796
1832
<< (fn_it!=functions_map.cend () && !fn_it->second .body_available ()
1797
1833
? " [function without a body]" : " " )
1798
1834
<< " : "
1799
1835
<< fn_name
1800
1836
<< 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
+ }
1802
1856
}
1803
1857
}
1804
1858
log ->status ()
1805
1859
<< " [100.0%] Summarisation of functions has finished successfully ("
1806
1860
<< processed << " processed, "
1807
1861
<< modelled << " modelled, "
1808
- << skipped << " skipped)."
1862
+ << skipped. size () << " skipped)."
1809
1863
<< messaget::eom;
1810
1864
}
1811
1865
0 commit comments