Skip to content

Performance improvement and cleanup of local bitvector analysis #6528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/analyses/local_bitvector_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ bool local_bitvector_analysist::merge(points_tot &a, points_tot &b)
std::max(a.size(), b.size());

for(std::size_t i=0; i<max_index; i++)
{
if(a[i].merge(b[i]))
result=true;
}
result |= a[i].merge(b[i]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a comment that the bitwise or is used instead of the logical or to prevent the short-circuit semantics.


return result;
}
Expand All @@ -73,7 +70,7 @@ void local_bitvector_analysist::assign_lhs(

if(is_tracked(identifier))
{
unsigned dest_pointer=pointers.number(identifier);
const auto dest_pointer = pointers.number(identifier);
flagst rhs_flags=get_rec(rhs, loc_info_src);
loc_info_dest[dest_pointer]=rhs_flags;
}
Expand Down Expand Up @@ -128,7 +125,7 @@ local_bitvector_analysist::flagst local_bitvector_analysist::get_rec(
const irep_idt &identifier=to_symbol_expr(rhs).get_identifier();
if(is_tracked(identifier))
{
unsigned src_pointer=pointers.number(identifier);
const auto src_pointer = pointers.number(identifier);
return loc_info_src[src_pointer];
}
else
Expand Down Expand Up @@ -242,8 +239,8 @@ void local_bitvector_analysist::build()
if(cfg.nodes.empty())
return;

work_queuet work_queue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one has a friend who would also like to become a set:

typedef std::stack<local_cfgt::node_nrt> work_queuet;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I'll do so in a follow-up PR.

work_queue.push(0);
std::set<local_cfgt::node_nrt> work_queue;
work_queue.insert(0);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Queues are usually ordered (especially in the UK). Is the set really helping performance, and if so, I'd rename it to "work_set".

loc_infos.resize(cfg.nodes.size());

Expand All @@ -258,10 +255,10 @@ void local_bitvector_analysist::build()

while(!work_queue.empty())
{
unsigned loc_nr=work_queue.top();
const auto loc_nr = *work_queue.begin();
const local_cfgt::nodet &node=cfg.nodes[loc_nr];
const goto_programt::instructiont &instruction=*node.t;
work_queue.pop();
work_queue.erase(work_queue.begin());

auto &loc_info_src=loc_infos[loc_nr];
auto loc_info_dest=loc_infos[loc_nr];
Expand Down Expand Up @@ -338,7 +335,7 @@ void local_bitvector_analysist::build()
{
assert(succ<loc_infos.size());
if(merge(loc_infos[succ], (loc_info_dest)))
work_queue.push(succ);
work_queue.insert(succ);
}
}
}
Expand All @@ -348,7 +345,7 @@ void local_bitvector_analysist::output(
const goto_functiont &goto_function,
const namespacet &ns) const
{
unsigned l=0;
std::size_t l = 0;

for(const auto &instruction : goto_function.body.instructions)
{
Expand Down
4 changes: 0 additions & 4 deletions src/analyses/local_bitvector_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Author: Daniel Kroening, [email protected]
#ifndef CPROVER_ANALYSES_LOCAL_BITVECTOR_ANALYSIS_H
#define CPROVER_ANALYSES_LOCAL_BITVECTOR_ANALYSIS_H

#include <stack>

#include <util/expanding_vector.h>
#include <util/numbering.h>

Expand Down Expand Up @@ -182,8 +180,6 @@ class local_bitvector_analysist
const namespacet &ns;
void build();

typedef std::stack<unsigned> work_queuet;

numberingt<irep_idt> pointers;

// pointers -> flagst
Expand Down