Skip to content

Commit 6c59aca

Browse files
committed
Weak-memory-model instrumentation: do not use instructiont::function
We are working towards removing the "function" field from goto_programt::instructionst::instructiont, and thus need to pass the identifier of the function whenever it actually is required. Consistently use "function_id" as that identifier.
1 parent c327572 commit 6c59aca

File tree

4 files changed

+96
-66
lines changed

4 files changed

+96
-66
lines changed

src/goto-instrument/wmm/goto2graph.cpp

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -145,31 +145,32 @@ unsigned instrumentert::goto2graph_cfg(
145145
}
146146

147147
void instrumentert::cfg_visitort::visit_cfg_function(
148-
value_setst &value_sets,
149-
memory_modelt model,
150-
bool no_dependencies,
151-
loop_strategyt replicate_body,
152-
const irep_idt &function,
153-
std::set<instrumentert::cfg_visitort::nodet> &ending_vertex)
148+
value_setst &value_sets,
149+
memory_modelt model,
150+
bool no_dependencies,
151+
loop_strategyt replicate_body,
152+
const irep_idt &function_id,
153+
std::set<instrumentert::cfg_visitort::nodet> &ending_vertex)
154154
{
155155
/* flow: egraph */
156156

157-
instrumenter.message.debug() << "visit function "
158-
<< function << messaget::eom;
157+
instrumenter.message.debug()
158+
<< "visit function " << function_id << messaget::eom;
159159

160-
if(function == INITIALIZE_FUNCTION)
160+
if(function_id == INITIALIZE_FUNCTION)
161161
{
162162
return;
163163
}
164164

165165
#ifdef LOCAL_MAY
166166
local_may_aliast local_may(
167-
instrumenter.goto_functions.function_map[function]);
167+
instrumenter.goto_functions.function_map[function_id]);
168168
#endif
169169

170170
/* goes through the function */
171-
Forall_goto_program_instructions(i_it,
172-
instrumenter.goto_functions.function_map[function].body)
171+
goto_programt &goto_program =
172+
instrumenter.goto_functions.function_map[function_id].body;
173+
Forall_goto_program_instructions(i_it, goto_program)
173174
{
174175
goto_programt::instructiont &instruction=*i_it;
175176

@@ -243,17 +244,22 @@ void instrumentert::cfg_visitort::visit_cfg_function(
243244
}
244245
else if(instruction.is_goto())
245246
{
246-
visit_cfg_goto(i_it, replicate_body, value_sets
247+
visit_cfg_goto(
248+
goto_program,
249+
i_it,
250+
replicate_body,
251+
value_sets
247252
#ifdef LOCAL_MAY
248-
, local_may
253+
,
254+
local_may
249255
#endif
250256
); // NOLINT(whitespace/parens)
251257
}
252258
#ifdef CONTEXT_INSENSITIVE
253259
else if(instruction.is_return())
254260
{
255261
visit_cfg_propagate(i_it);
256-
add_all_pos(it, out_nodes[function], in_pos[i_it]);
262+
add_all_pos(it, out_nodes[function_id], in_pos[i_it]);
257263
}
258264
#endif
259265
else
@@ -267,15 +273,16 @@ void instrumentert::cfg_visitort::visit_cfg_function(
267273
egraph.map_data_dp.insert(new_dp);
268274
data_dp.print(instrumenter.message);
269275

270-
if(instrumenter.goto_functions.function_map[function]
271-
.body.instructions.empty())
276+
if(instrumenter.goto_functions.function_map[function_id]
277+
.body.instructions.empty())
272278
{
273279
/* empty set of ending edges */
274280
}
275281
else
276282
{
277-
goto_programt::instructionst::iterator it=instrumenter
278-
.goto_functions.function_map[function].body.instructions.end();
283+
goto_programt::instructionst::iterator it =
284+
instrumenter.goto_functions.function_map[function_id]
285+
.body.instructions.end();
279286
--it;
280287
ending_vertex=in_pos[it];
281288
}
@@ -445,11 +452,13 @@ bool instrumentert::cfg_visitort::contains_shared_array(
445452

446453
/// strategy: fwd/bwd alternation
447454
void inline instrumentert::cfg_visitort::visit_cfg_body(
455+
const goto_programt &goto_program,
448456
goto_programt::const_targett i_it,
449457
loop_strategyt replicate_body,
450458
value_setst &value_sets
451459
#ifdef LOCAL_MAY
452-
, local_may_aliast &local_may
460+
,
461+
local_may_aliast &local_may
453462
#endif
454463
)
455464
{
@@ -482,29 +491,27 @@ void inline instrumentert::cfg_visitort::visit_cfg_body(
482491
}
483492

484493
if(duplicate_this)
485-
visit_cfg_duplicate(target, i_it);
494+
visit_cfg_duplicate(goto_program, target, i_it);
486495
else
487496
visit_cfg_backedge(target, i_it);
488497
}
489498
}
490499
}
491500

492501
void inline instrumentert::cfg_visitort::visit_cfg_duplicate(
502+
const goto_programt &goto_program,
493503
goto_programt::const_targett targ,
494504
goto_programt::const_targett i_it)
495505
{
496506
instrumenter.message.status() << "Duplication..." << messaget::eom;
497-
const goto_functionst::goto_functiont &fun=
498-
instrumenter.goto_functions.function_map[i_it->function];
499507

500508
bool found_pos=false;
501509
goto_programt::const_targett new_targ=targ;
502510

503511
if(in_pos[targ].empty())
504512
{
505513
/* tries to find the next node after the back edge */
506-
for(; new_targ!=fun.body.instructions.end();
507-
++new_targ)
514+
for(; new_targ != goto_program.instructions.end(); ++new_targ)
508515
{
509516
if(in_pos.find(new_targ)!=in_pos.end() && !in_pos[new_targ].empty())
510517
{
@@ -620,11 +627,13 @@ void inline instrumentert::cfg_visitort::visit_cfg_backedge(
620627
}
621628

622629
void instrumentert::cfg_visitort::visit_cfg_goto(
630+
const goto_programt &goto_program,
623631
goto_programt::instructionst::iterator i_it,
624632
loop_strategyt replicate_body,
625633
value_setst &value_sets
626634
#ifdef LOCAL_MAY
627-
, local_may_aliast &local_may
635+
,
636+
local_may_aliast &local_may
628637
#endif
629638
)
630639
{
@@ -640,9 +649,14 @@ void instrumentert::cfg_visitort::visit_cfg_goto(
640649
if(instruction.is_backwards_goto())
641650
{
642651
instrumenter.message.debug() << "backward goto" << messaget::eom;
643-
visit_cfg_body(i_it, replicate_body, value_sets
652+
visit_cfg_body(
653+
goto_program,
654+
i_it,
655+
replicate_body,
656+
value_sets
644657
#ifdef LOCAL_MAY
645-
, local_may
658+
,
659+
local_may
646660
#endif
647661
); // NOLINT(whitespace/parens)
648662
}

src/goto-instrument/wmm/goto2graph.h

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,20 @@ class instrumentert
114114
void visit_cfg_thread() const;
115115
void visit_cfg_propagate(goto_programt::instructionst::iterator i_it);
116116
void visit_cfg_body(
117+
const goto_programt &goto_program,
117118
goto_programt::const_targett i_it,
118119
loop_strategyt replicate_body,
119120
value_setst &value_sets
120-
#ifdef LOCAL_MAY
121-
, local_may_aliast &local_may
122-
#endif
121+
#ifdef LOCAL_MAY
122+
,
123+
local_may_aliast &local_may
124+
#endif
123125
); // deprecated NOLINT(whitespace/parens)
124126
void inline visit_cfg_backedge(goto_programt::const_targett targ,
125127
goto_programt::const_targett i_it);
126-
void inline visit_cfg_duplicate(goto_programt::const_targett targ,
128+
void inline visit_cfg_duplicate(
129+
const goto_programt &goto_program,
130+
goto_programt::const_targett targ,
127131
goto_programt::const_targett i_it);
128132
void visit_cfg_assign(
129133
value_setst &value_sets,
@@ -144,14 +148,16 @@ class instrumentert
144148
bool no_dependenciess,
145149
loop_strategyt duplicate_body);
146150
void visit_cfg_goto(
151+
const goto_programt &goto_program,
147152
goto_programt::instructionst::iterator i_it,
148153
/* forces the duplication of all the loops, with array or not
149154
otherwise, duplication of loops with array accesses only */
150155
loop_strategyt replicate_body,
151156
value_setst &value_sets
152-
#ifdef LOCAL_MAY
153-
, local_may_aliast &local_may
154-
#endif
157+
#ifdef LOCAL_MAY
158+
,
159+
local_may_aliast &local_may
160+
#endif
155161
); // NOLINT(whitespace/parens)
156162
void visit_cfg_reference_function(irep_idt id_function);
157163

@@ -224,34 +230,39 @@ class instrumentert
224230
coming_from = 0;
225231
}
226232

227-
void inline enter_function(const irep_idt &function)
233+
void inline enter_function(const irep_idt &function_id)
228234
{
229-
if(functions_met.find(function)!=functions_met.end())
235+
if(functions_met.find(function_id) != functions_met.end())
230236
throw "sorry, doesn't handle recursive function for the moment";
231-
functions_met.insert(function);
237+
functions_met.insert(function_id);
232238
}
233239

234-
void inline leave_function(const irep_idt &function)
240+
void inline leave_function(const irep_idt &function_id)
235241
{
236-
functions_met.erase(function);
242+
functions_met.erase(function_id);
237243
}
238244

239245
void inline visit_cfg(
240246
value_setst &value_sets,
241247
memory_modelt model,
242248
bool no_dependencies,
243249
loop_strategyt duplicate_body,
244-
const irep_idt &function)
250+
const irep_idt &function_id)
245251
{
246252
/* ignore recursive calls -- underapproximation */
247253
try
248254
{
249255
/* forbids recursive function */
250-
enter_function(function);
256+
enter_function(function_id);
251257
std::set<nodet> end_out;
252-
visit_cfg_function(value_sets, model, no_dependencies, duplicate_body,
253-
function, end_out);
254-
leave_function(function);
258+
visit_cfg_function(
259+
value_sets,
260+
model,
261+
no_dependencies,
262+
duplicate_body,
263+
function_id,
264+
end_out);
265+
leave_function(function_id);
255266
}
256267
catch(const std::string &s)
257268
{
@@ -265,14 +276,14 @@ class instrumentert
265276
/// \param no_dependencies: Option to disable dependency analysis
266277
/// \param duplicate_body: Control which loop body segments should
267278
/// be duplicated
268-
/// \param function: Function to analyse
279+
/// \param function_id: Function to analyse
269280
/// \param ending_vertex: Outcoming edges
270281
virtual void visit_cfg_function(
271282
value_setst &value_sets,
272283
memory_modelt model,
273284
bool no_dependencies,
274285
loop_strategyt duplicate_body,
275-
const irep_idt &function,
286+
const irep_idt &function_id,
276287
std::set<nodet> &ending_vertex);
277288

278289
bool inline local(const irep_idt &i);

src/goto-instrument/wmm/shared_buffers.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ void shared_bufferst::det_flush(
447447

448448
/// instruments read
449449
void shared_bufferst::nondet_flush(
450+
const irep_idt &function_id,
450451
goto_programt &goto_program,
451452
goto_programt::targett &target,
452453
const source_locationt &source_location,
@@ -463,8 +464,8 @@ void shared_bufferst::nondet_flush(
463464
const varst &vars=(*this)(object);
464465

465466
// Non deterministic choice
466-
irep_idt choice0=choice(target->function, "0");
467-
irep_idt choice2=choice(target->function, "2"); // delays the write flush
467+
irep_idt choice0 = choice(function_id, "0");
468+
irep_idt choice2 = choice(function_id, "2"); // delays the write flush
468469

469470
const symbol_exprt choice0_expr=symbol_exprt(choice0, bool_typet());
470471
const symbol_exprt delay_expr=symbol_exprt(choice2, bool_typet());
@@ -690,7 +691,7 @@ void shared_bufferst::nondet_flush(
690691
// a thread can read the other threads' buffers
691692

692693
// One extra non-deterministic choice needed
693-
irep_idt choice1=choice(target->function, "1");
694+
irep_idt choice1 = choice(function_id, "1");
694695
const symbol_exprt choice1_expr=symbol_exprt(choice1, bool_typet());
695696

696697
// throw Boolean dice
@@ -1056,19 +1057,19 @@ void shared_bufferst::affected_by_delay(
10561057
/// instruments the program for the pairs detected through the CFG
10571058
void shared_bufferst::cfg_visitort::weak_memory(
10581059
value_setst &value_sets,
1059-
const irep_idt &function,
1060+
const irep_idt &function_id,
10601061
memory_modelt model)
10611062
{
1062-
shared_buffers.message.debug() << "visit function "<< function
1063-
<< messaget::eom;
1064-
if(function == INITIALIZE_FUNCTION)
1063+
shared_buffers.message.debug()
1064+
<< "visit function " << function_id << messaget::eom;
1065+
if(function_id == INITIALIZE_FUNCTION)
10651066
return;
10661067

10671068
namespacet ns(symbol_table);
1068-
goto_programt &goto_program=goto_functions.function_map[function].body;
1069+
goto_programt &goto_program = goto_functions.function_map[function_id].body;
10691070

10701071
#ifdef LOCAL_MAY
1071-
local_may_aliast local_may(goto_functions.function_map[function]);
1072+
local_may_aliast local_may(goto_functions.function_map[function_id]);
10721073
#endif
10731074

10741075
Forall_goto_program_instructions(i_it, goto_program)
@@ -1127,9 +1128,13 @@ void shared_bufferst::cfg_visitort::weak_memory(
11271128

11281129
if(shared_buffers.is_buffered(ns, e_it->second.symbol_expr, false))
11291130
shared_buffers.nondet_flush(
1130-
goto_program, i_it, source_location, e_it->second.object,
1131+
function_id,
1132+
goto_program,
1133+
i_it,
1134+
source_location,
1135+
e_it->second.object,
11311136
current_thread,
1132-
(model==TSO || model==PSO || model==RMO));
1137+
(model == TSO || model == PSO || model == RMO));
11331138
}
11341139

11351140
// Now perform the write(s).
@@ -1184,8 +1189,7 @@ void shared_bufferst::cfg_visitort::weak_memory(
11841189
vars.read_delayed, bool_typet());
11851190

11861191
// One extra non-deterministic choice needed
1187-
irep_idt choice1=shared_buffers.choice(
1188-
instruction.function, "1");
1192+
irep_idt choice1 = shared_buffers.choice(function_id, "1");
11891193
const symbol_exprt choice1_expr=symbol_exprt(choice1,
11901194
bool_typet());
11911195
const exprt nondet_bool_expr =

src/goto-instrument/wmm/shared_buffers.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class shared_bufferst
117117
const unsigned current_thread);
118118

119119
void nondet_flush(
120+
const irep_idt &function_id,
120121
goto_programt &goto_program,
121122
goto_programt::targett &t,
122123
const source_locationt &source_location,
@@ -156,9 +157,9 @@ class shared_bufferst
156157
return true;
157158
}
158159

159-
irep_idt choice(const irep_idt &function, const std::string &suffix)
160+
irep_idt choice(const irep_idt &function_id, const std::string &suffix)
160161
{
161-
const auto maybe_symbol=symbol_table.lookup(function);
162+
const auto maybe_symbol = symbol_table.lookup(function_id);
162163
const std::string function_base_name =
163164
maybe_symbol
164165
? id2string(maybe_symbol->base_name)
@@ -213,10 +214,10 @@ class shared_bufferst
213214
max_thread = 0;
214215
}
215216

216-
void weak_memory(
217-
value_setst &value_sets,
218-
const irep_idt &function,
219-
memory_modelt model);
217+
void weak_memory(
218+
value_setst &value_sets,
219+
const irep_idt &function_id,
220+
memory_modelt model);
220221
};
221222

222223
protected:

0 commit comments

Comments
 (0)