CBMC
Loading...
Searching...
No Matches
cone_of_influence.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Loop Acceleration
4
5Author: 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
21 const expr_sett &targets,
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 {
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
70 const exprt &target,
72{
73 expr_sett s;
74 s.insert(target);
76}
77
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().is_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().is_true())
106 {
107 return;
108 }
109 }
110 else if(rit->is_assume() || rit->is_assert())
111 {
112 if(rit->condition().is_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
125 const expr_sett &curr,
126 expr_sett &next)
127{
128 next.insert(curr.begin(), curr.end());
129
130 if(i.is_assign())
131 {
133 bool care=false;
134
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
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 {
167 }
168 }
169}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
const goto_programt & program
void get_succs(goto_programt::instructionst::const_reverse_iterator rit, expr_sett &targets)
void cone_of_influence(const expr_sett &targets, expr_sett &cone)
void gather_rvalues(const exprt &expr, expr_sett &rvals)
Base class for all expressions.
Definition expr.h:56
operandst & operands()
Definition expr.h:94
This class represents an instruction in the GOTO intermediate representation.
const exprt & assign_lhs() const
Get the lhs of the assignment for ASSIGN.
const exprt & assign_rhs() const
Get the rhs of the assignment for ASSIGN.
const irep_idt & id() const
Definition irep.h:388
Loop Acceleration.
std::unordered_set< exprt, irep_hash > expr_sett
static format_containert< T > format(const T &o)
Definition format.h:37