cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
cone_of_influence.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Loop Acceleration
4
5
Author: Matt Lewis
6
7
\*******************************************************************/
8
11
12
#include "
cone_of_influence.h
"
13
14
#ifdef DEBUG
15
# include <
util/format_expr.h
>
16
17
# include <iostream>
18
#endif
19
20
void
cone_of_influencet::cone_of_influence
(
21
const
expr_sett
&targets,
22
expr_sett
&cone)
23
{
24
if
(
program
.instructions.empty())
25
{
26
cone=targets;
27
return
;
28
}
29
30
for
(goto_programt::instructionst::const_reverse_iterator
31
rit=
program
.instructions.rbegin();
32
rit !=
program
.instructions.rend();
33
++rit)
34
{
35
expr_sett
curr;
// =targets;
36
expr_sett
next;
37
38
if
(rit ==
program
.instructions.rbegin())
39
{
40
curr=targets;
41
}
42
else
43
{
44
get_succs
(rit, curr);
45
}
46
47
cone_of_influence
(*rit, curr, next);
48
49
cone_map
[rit->location_number]=next;
50
51
#ifdef DEBUG
52
std::cout <<
"Previous cone: \n"
;
53
54
for
(
const
auto
&expr : curr)
55
std::cout <<
format
(expr) <<
" "
;
56
57
std::cout <<
"\nCurrent cone: \n"
;
58
59
for
(
const
auto
&expr : next)
60
std::cout <<
format
(expr) <<
" "
;
61
62
std::cout <<
'\n'
;
63
#endif
64
}
65
66
cone=
cone_map
[
program
.instructions.front().location_number];
67
}
68
69
void
cone_of_influencet::cone_of_influence
(
70
const
exprt
&target,
71
expr_sett
&cone)
72
{
73
expr_sett
s;
74
s.insert(target);
75
cone_of_influence
(s, cone);
76
}
77
78
void
cone_of_influencet::get_succs
(
79
goto_programt::instructionst::const_reverse_iterator rit,
80
expr_sett
&targets)
81
{
82
if
(rit ==
program
.instructions.rbegin())
83
{
84
return
;
85
}
86
87
goto_programt::instructionst::const_reverse_iterator next=rit;
88
--next;
89
90
if
(rit->is_goto())
91
{
92
if
(rit->condition() !=
false
)
93
{
94
// Branch can be taken.
95
for
(goto_programt::targetst::const_iterator t=rit->targets.begin();
96
t != rit->targets.end();
97
++t)
98
{
99
unsigned
int
loc=(*t)->location_number;
100
expr_sett
&s=
cone_map
[loc];
101
targets.insert(s.begin(), s.end());
102
}
103
}
104
105
if
(rit->condition() ==
true
)
106
{
107
return
;
108
}
109
}
110
else
if
(rit->is_assume() || rit->is_assert())
111
{
112
if
(rit->condition() ==
false
)
113
{
114
return
;
115
}
116
}
117
118
unsigned
int
loc=next->location_number;
119
expr_sett
&s=
cone_map
[loc];
120
targets.insert(s.begin(), s.end());
121
}
122
123
void
cone_of_influencet::cone_of_influence
(
124
const
goto_programt::instructiont
&i,
125
const
expr_sett
&curr,
126
expr_sett
&next)
127
{
128
next.insert(curr.begin(), curr.end());
129
130
if
(i.
is_assign
())
131
{
132
expr_sett
lhs_syms;
133
bool
care=
false
;
134
135
gather_rvalues
(i.
assign_lhs
(), lhs_syms);
136
137
for
(
const
auto
&expr : lhs_syms)
138
if
(curr.find(expr)!=curr.end())
139
{
140
care=
true
;
141
break
;
142
}
143
144
next.erase(i.
assign_lhs
());
145
146
if
(care)
147
{
148
gather_rvalues
(i.
assign_rhs
(), next);
149
}
150
}
151
}
152
153
void
cone_of_influencet::gather_rvalues
(
const
exprt
&expr,
expr_sett
&rvals)
154
{
155
if
(expr.
id
() == ID_symbol ||
156
expr.
id
() == ID_index ||
157
expr.
id
() == ID_member ||
158
expr.
id
() == ID_dereference)
159
{
160
rvals.insert(expr);
161
}
162
else
163
{
164
for
(
const
auto
&op : expr.
operands
())
165
{
166
gather_rvalues
(op, rvals);
167
}
168
}
169
}
cone_of_influencet::program
const goto_programt & program
Definition
cone_of_influence.h:53
cone_of_influencet::get_succs
void get_succs(goto_programt::instructionst::const_reverse_iterator rit, expr_sett &targets)
Definition
cone_of_influence.cpp:78
cone_of_influencet::cone_of_influence
void cone_of_influence(const expr_sett &targets, expr_sett &cone)
Definition
cone_of_influence.cpp:20
cone_of_influencet::cone_map
cone_mapt cone_map
Definition
cone_of_influence.h:51
cone_of_influencet::gather_rvalues
void gather_rvalues(const exprt &expr, expr_sett &rvals)
Definition
cone_of_influence.cpp:153
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::operands
operandst & operands()
Definition
expr.h:95
goto_programt::instructiont
This class represents an instruction in the GOTO intermediate representation.
Definition
goto_program.h:180
goto_programt::instructiont::assign_lhs
const exprt & assign_lhs() const
Get the lhs of the assignment for ASSIGN.
Definition
goto_program.h:199
goto_programt::instructiont::assign_rhs
const exprt & assign_rhs() const
Get the rhs of the assignment for ASSIGN.
Definition
goto_program.h:213
goto_programt::instructiont::is_assign
bool is_assign() const
Definition
goto_program.h:492
irept::id
const irep_idt & id() const
Definition
irep.h:388
cone_of_influence.h
Loop Acceleration.
expr_sett
std::unordered_set< exprt, irep_hash > expr_sett
Definition
cone_of_influence.h:21
format
static format_containert< T > format(const T &o)
Definition
format.h:37
format_expr.h
goto-instrument
accelerate
cone_of_influence.cpp
Generated by
1.17.0