cprover
Loading...
Searching...
No Matches
goto2graph.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Turns a goto-program into an abstract event graph
4
5Author: Vincent Nimal
6
7Date: 2012
8
9\*******************************************************************/
10
13
14#include "goto2graph.h"
15
16#include <vector>
17#include <string>
18#include <fstream>
19
20#include <util/options.h>
21#include <util/prefix.h>
22
24
26
27#include "fence.h"
28
29// #define PRINT_UNSAFES
30
31
33bool inline instrumentert::local(const irep_idt &id)
34{
35 std::string identifier=id2string(id);
36
37 if(has_prefix(identifier, "symex_invalid") ||
38 has_prefix(identifier, "symex::invalid"))
39 {
40 /* symex_invalid and symex::invalid_object generated when pointer analysis
41 fails */
42 return true;
43 }
44
45 if(identifier==CPROVER_PREFIX "alloc" ||
46 identifier==CPROVER_PREFIX "alloc_size" ||
47 identifier=="stdin" ||
48 identifier=="stdout" ||
49 identifier=="stderr" ||
50 identifier=="sys_nerr" ||
51 has_prefix(identifier, "__unbuffered_"))
52 return true;
53
54 const size_t pos=identifier.find("[]");
55
56 if(pos!=std::string::npos)
57 {
58 /* we don't distinguish the members of an array for the moment */
59 identifier.erase(pos);
60 }
61
62 try
63 {
64 const symbolt &symbol=ns.lookup(identifier);
65
66 if(!symbol.is_static_lifetime)
67 return true; /* these are local */
68
69 if(symbol.is_thread_local)
70 return true; /* these are local */
71
72 return false;
73 }
74 catch(const std::string &exception)
75 {
76 message.debug()<<"Exception: "<<exception << messaget::eom;
77 return false;
78 }
79}
80
82{
83 return instrumenter.local(i);
84}
85
89 value_setst &value_sets,
90 memory_modelt model,
91 bool no_dependencies,
93{
95 message.status() << "Dependencies analysis enabled" << messaget::eom;
96
97 /* builds the graph following the CFG */
98 cfg_visitort visitor(ns, *this);
99 visitor.visit_cfg(value_sets, model, no_dependencies, duplicate_body,
101
102 std::vector<std::size_t> subgraph_index;
104 CHECK_RETURN(egraph_SCCs.empty());
105 egraph_SCCs.resize(num_sccs, std::set<event_idt>());
106 for(std::map<event_idt, event_idt>::const_iterator
107 it=map_vertex_gnode.begin();
108 it!=map_vertex_gnode.end();
109 it++)
110 {
111 const std::size_t sg=subgraph_index[it->second];
112 egraph_SCCs[sg].insert(it->first);
113 }
114
115 message.status() << "Number of threads detected: "
116 << visitor.max_thread << messaget::eom;
117
118 /* SCCs which could host critical cycles */
119 unsigned interesting_sccs=0;
120 for(unsigned i=0; i<num_sccs; i++)
121 if(egraph_SCCs[i].size()>3)
123
124 message.statistics() << "Graph with " << egraph_alt.size() << " nodes has "
125 << interesting_sccs << " interesting SCCs"
126 << messaget::eom;
127
128 message.statistics() << "Number of reads: " << visitor.read_counter
129 << messaget::eom;
130 message.statistics() << "Number of writes: " << visitor.write_counter
131 << messaget::eom;
132 message.statistics() << "Number of wse: " << visitor.ws_counter
133 << messaget::eom;
134 message.statistics() << "Number of rfe/fre: " << visitor.fr_rf_counter
135 << messaget::eom;
136 std::size_t instr_counter=0;
137 for(goto_functionst::function_mapt::const_iterator
138 it=goto_functions.function_map.begin();
140 ++it)
141 instr_counter+=it->second.body.instructions.size();
142 message.statistics() << "Number of goto-instructions: "
144
145 return visitor.max_thread;
146}
147
149 value_setst &value_sets,
150 memory_modelt model,
151 bool no_dependencies,
153 const irep_idt &function_id,
154 std::set<instrumentert::cfg_visitort::nodet> &ending_vertex)
155{
156 /* flow: egraph */
157
158 instrumenter.message.debug()
159 << "visit function " << function_id << messaget::eom;
160
161 if(function_id == INITIALIZE_FUNCTION)
162 {
163 return;
164 }
165
166#ifdef LOCAL_MAY
168 instrumenter.goto_functions.function_map[function_id]);
169#endif
170
171 /* goes through the function */
172 goto_programt &goto_program =
173 instrumenter.goto_functions.function_map[function_id].body;
175 {
176 goto_programt::instructiont &instruction=*i_it;
177
178 /* thread marking */
179 if(instruction.is_start_thread())
180 {
181 max_thread=max_thread+1;
182 coming_from=current_thread;
183 current_thread=max_thread;
184 }
185 else if(instruction.is_end_thread())
186 current_thread=coming_from;
187 thread=current_thread;
188
189 instrumenter.message.debug()
190 << "visit instruction " << instruction.type() << messaget::eom;
191
192 if(instruction.is_start_thread() || instruction.is_end_thread())
193 {
194 /* break the flow */
195 visit_cfg_thread();
196 }
197 else if(instruction.is_atomic_begin() || instruction.is_atomic_end())
198 {
199 /* break the flow (def 1) or add full barrier (def 2) */
200 #ifdef ATOMIC_BREAK
201 visit_cfg_thread();
202 #elif defined ATOMIC_FENCE
203 visit_cfg_fence(i_it, function_id);
204#else
205 /* propagates */
206 visit_cfg_propagate(i_it);
207#endif
208 }
209 /* a:=b -o-> Rb -po-> Wa */
210 else if(instruction.is_assign())
211 {
212 visit_cfg_assign(
213 value_sets,
214 function_id,
215 i_it,
218 ,
220#endif
221 ); // NOLINT(whitespace/parens)
222 }
223 else if(is_fence(instruction, instrumenter.ns))
224 {
225 instrumenter.message.debug() << "Constructing a fence" << messaget::eom;
226 visit_cfg_fence(i_it, function_id);
227 }
228 else if(model!=TSO && is_lwfence(instruction, instrumenter.ns))
229 {
230 visit_cfg_lwfence(i_it, function_id);
231 }
232 else if(model==TSO && is_lwfence(instruction, instrumenter.ns))
233 {
234 /* propagation */
235 visit_cfg_skip(i_it);
236 }
237 else if(
238 instruction.is_other() && instruction.code().get_statement() == ID_fence)
239 {
240 visit_cfg_asm_fence(i_it, function_id);
241 }
242 else if(instruction.is_function_call())
243 {
244 visit_cfg_function_call(value_sets, i_it, model,
246 }
247 else if(instruction.is_goto())
248 {
249 visit_cfg_goto(
250 function_id,
251 goto_program,
252 i_it,
254 value_sets
256 ,
258#endif
259 ); // NOLINT(whitespace/parens)
260 }
261#ifdef CONTEXT_INSENSITIVE
262 else if(instruction.is_set_return_value())
263 {
264 visit_cfg_propagate(i_it);
265 add_all_pos(it, out_nodes[function_id], in_pos[i_it]);
266 }
267#endif
268 else
269 {
270 /* propagates */
271 visit_cfg_propagate(i_it);
272 }
273 }
274
275 std::pair<unsigned, data_dpt> new_dp(thread, data_dp);
276 egraph.map_data_dp.insert(new_dp);
277 data_dp.print(instrumenter.message);
278
279 if(instrumenter.goto_functions.function_map[function_id]
280 .body.instructions.empty())
281 {
282 /* empty set of ending edges */
283 }
284 else
285 {
286 goto_programt::instructionst::iterator it =
287 instrumenter.goto_functions.function_map[function_id]
288 .body.instructions.end();
289 --it;
290 ending_vertex=in_pos[it];
291 }
292}
293
295 goto_programt::instructionst::iterator i_it)
296{
297 const goto_programt::instructiont &instruction=*i_it;
298 /* propagation */
299 in_pos[i_it].clear();
300 for(const auto &in : instruction.incoming_edges)
301 if(in_pos.find(in)!=in_pos.end())
302 for(const auto &node : in_pos[in])
303 in_pos[i_it].insert(node);
304}
305
309
311/* OBSOLETE */
312/* Note: can be merged with visit_cfg_body */
313/* Warning: we iterate here over the successive instructions of the
314 regardless of the gotos. This function has to be called *AFTER*
315 an exploration of the function constructing the graph. */
318{
319 if(instrumenter.map_function_graph.find(id_function)!=
320 instrumenter.map_function_graph.end())
321 return;
322
323 /* gets the body of the function */
324 goto_programt::instructionst &body=instrumenter.goto_functions
325 .function_map[id_function].body.instructions;
326
327 if(body.empty())
328 return;
329
330 /* end of function */
331 /* TODO: ensure that all the returns point to the last statement if the
332 function, or alternatively make i_it point to each return location in
333 the function */
334 goto_programt::instructionst::iterator i_it=body.end();
335 --i_it;
336
337 /* beginning of the function */
338 goto_programt::instructionst::iterator targ=body.begin();
339
340 std::set<event_idt> in_nodes;
341 std::set<event_idt> out_nodes;
342
343 /* if the target has already been covered by fwd analysis */
344 if(in_pos.find(targ)!=in_pos.end())
345 {
346 /* if in_pos was updated at this program point */
347 if(updated.find(targ)!=updated.end())
348 {
349 /* connects the previous nodes to those ones */
350 for(std::set<nodet>::const_iterator to=in_pos[targ].begin();
351 to!=in_pos[targ].end(); ++to)
352 in_nodes.insert(to->first);
353 for(std::set<nodet>::const_iterator from=in_pos[i_it].begin();
354 from!=in_pos[i_it].end(); ++from)
355 out_nodes.insert(from->first);
356 }
357 else
358 {
359 instrumenter.message.debug() << "else case" << messaget::eom;
360 /* connects NEXT nodes following the targets -- bwd analysis */
361 for(goto_programt::instructionst::iterator cur=i_it;
362 cur!=targ; --cur)
363 {
364 instrumenter.message.debug() << "i" << messaget::eom;
365 for(const auto &in : cur->incoming_edges)
366 {
367 instrumenter.message.debug() << "t" << messaget::eom;
368 if(in_pos.find(in)!=in_pos.end() &&
369 updated.find(in)!=updated.end())
370 {
371 /* out_pos[in].insert(in_pos[in])*/
372 add_all_pos(it1, out_pos[in], in_pos[in]);
373 }
374 else if(in_pos.find(in)!=in_pos.end())
375 {
376 /* out_pos[in].insert(out_pos[cur])*/
377 add_all_pos(it2, out_pos[in], out_pos[cur]);
378 }
379 }
380 }
381
382 /* connects the previous nodes to those ones */
383 if(out_pos.find(targ)!=out_pos.end())
384 {
385 for(std::set<nodet>::const_iterator to=out_pos[targ].begin();
386 to!=out_pos[targ].end(); ++to)
387 in_nodes.insert(to->first);
388 for(std::set<nodet>::const_iterator from=in_pos[i_it].begin();
389 from!=in_pos[i_it].end(); ++from)
390 out_nodes.insert(from->first);
391 }
392 }
393 }
394
395 instrumenter.map_function_graph[id_function]=
396 std::make_pair(in_nodes, out_nodes);
397}
398
400 event_idt begin, event_idt end)
401{
402 /* no need to duplicate the loop nodes for the SCC-detection graph -- a
403 single back-edge will ensure the same connectivity */
404 alt_egraph.add_edge(end, begin);
405 return end;
406}
407
409 const irep_idt &function_id,
412 value_setst &value_sets
414 ,
416#endif
417 ) const // NOLINT(whitespace/parens)
418{
419 instrumenter.message.debug()
420 << "contains_shared_array called for " << targ->source_location().get_line()
421 << " and " << i_it->source_location().get_line() << messaget::eom;
422 for(goto_programt::const_targett cur=targ; cur!=i_it; ++cur)
423 {
424 instrumenter.message.debug()
425 << "Do we have an array at line " << cur->source_location().get_line()
426 << "?" << messaget::eom;
428 ns,
429 value_sets,
430 function_id,
431 cur
433 ,
435#endif
436 ); // NOLINT(whitespace/parens)
437 instrumenter.message.debug() << "Writes: "<<rw_set.w_entries.size()
438 <<"; Reads:"<<rw_set.r_entries.size() << messaget::eom;
439
440 for(const auto &r_entry : rw_set.r_entries)
441 {
442 const irep_idt var = r_entry.second.object;
443 instrumenter.message.debug() << "Is "<<var<<" an array?"
444 << messaget::eom;
445 if(id2string(var).find("[]")!=std::string::npos
446 && !instrumenter.local(var))
447 return true;
448 }
449
450 for(const auto &w_entry : rw_set.w_entries)
451 {
452 const irep_idt var = w_entry.second.object;
453 instrumenter.message.debug()<<"Is "<<var<<" an array?"<<messaget::eom;
454 if(id2string(var).find("[]")!=std::string::npos
455 && !instrumenter.local(var))
456 return true;
457 }
458 }
459
460 return false;
461}
462
463
466 const irep_idt &function_id,
467 const goto_programt &goto_program,
470 value_setst &value_sets
472 ,
474#endif
475)
476{
477 /* for each target of the goto */
478 for(const auto &target : i_it->targets)
479 {
480 /* if the target has already been covered by fwd analysis */
481 if(in_pos.find(target)!=in_pos.end())
482 {
483 if(in_pos[i_it].empty())
484 continue;
485
486 bool duplicate_this=false;
487
488 switch(replicate_body)
489 {
490 case arrays_only:
491 duplicate_this = contains_shared_array(
492 function_id,
493 target,
494 i_it,
495 value_sets
497 ,
499#endif
500 ); // NOLINT(whitespace/parens)
501 break;
502 case all_loops:
503 duplicate_this=true;
504 break;
505 case no_loop:
506 duplicate_this=false;
507 break;
508 }
509
511 visit_cfg_duplicate(goto_program, target, i_it);
512 else
513 visit_cfg_backedge(target, i_it);
514 }
515 }
516}
517
519 const goto_programt &goto_program,
522{
523 instrumenter.message.status() << "Duplication..." << messaget::eom;
524
525 bool found_pos=false;
527
528 if(in_pos[targ].empty())
529 {
530 /* tries to find the next node after the back edge */
531 for(; new_targ != goto_program.instructions.end(); ++new_targ)
532 {
533 if(in_pos.find(new_targ)!=in_pos.end() && !in_pos[new_targ].empty())
534 {
535 found_pos=true;
536 break;
537 }
538 }
539
540 // The code below uses heuristics to limit false positives: no cycles across
541 // inlined functions, which we would detect when file names or
542 // (user-provided) function names change _within a single goto_program_.
543 if(
544 !found_pos ||
545 new_targ->source_location().get_function() !=
546 targ->source_location().get_function() ||
547 new_targ->source_location().get_file() !=
548 targ->source_location().get_file())
549 return;
550 }
551
552 /* appends the body once more */
553 const std::set<nodet> &up_set=in_pos[(found_pos ? new_targ : targ)];
554 const std::set<nodet> &down_set=in_pos[i_it];
555
556 for(std::set<nodet>::const_iterator begin_it=up_set.begin();
557 begin_it!=up_set.end(); ++begin_it)
558 instrumenter.message.debug() << "Up " << begin_it->first << messaget::eom;
559
560 for(std::set<nodet>::const_iterator begin_it=down_set.begin();
561 begin_it!=down_set.end(); ++begin_it)
562 instrumenter.message.debug() << "Down " << begin_it->first <<messaget::eom;
563
564 for(std::set<nodet>::const_iterator begin_it=up_set.begin();
565 begin_it!=up_set.end(); ++begin_it)
566 {
567 for(std::set<nodet>::const_iterator end_it=down_set.begin();
568 end_it!=down_set.end(); ++end_it)
569 {
570 egraph.copy_segment(begin_it->first, end_it->first);
571 alt_copy_segment(egraph_alt, begin_it->second, end_it->second);
572#if 0
573 const event_idt end=egraph.copy_segment(begin_it->first, end_it->first);
574 const event_idt alt_end=
575 alt_copy_segment(egraph_alt, begin_it->second, end_it->second);
576 // copied; no need for back-edge!
577 // in_pos[i_it].insert(nodet(end, alt_end));
578#endif
579 }
580 }
581}
582
587{
588 /* if in_pos was updated at this program point */
589 if(updated.find(targ)!=updated.end())
590 {
591 /* connects the previous nodes to those ones */
592 for(std::set<nodet>::const_iterator to=in_pos[targ].begin();
593 to!=in_pos[targ].end(); ++to)
594 for(std::set<nodet>::const_iterator from=in_pos[i_it].begin();
595 from!=in_pos[i_it].end(); ++from)
596 if(from->first!=to->first)
597 {
598 if(egraph[from->first].thread!=egraph[to->first].thread)
599 continue;
600 instrumenter.message.debug() << from->first << "-po->"
601 << to->first << messaget::eom;
602 egraph.add_po_back_edge(from->first, to->first);
603 egraph_alt.add_edge(from->second, to->second);
604 }
605 }
606 else
607 {
608 instrumenter.message.debug() << "else case" << messaget::eom;
609
610 /* connects NEXT nodes following the targets -- bwd analysis */
612 cur!=targ; --cur)
613 {
614 for(const auto &in : cur->incoming_edges)
615 {
616 if(in_pos.find(in)!=in_pos.end()
617 && updated.find(in)!=updated.end())
618 {
619 /* out_pos[in].insert(in_pos[in])*/
620 add_all_pos(it1, out_pos[in], in_pos[in]);
621 }
622 else if(in_pos.find(in)!=in_pos.end())
623 {
624 /* out_pos[in].insert(in_pos[cur])*/
625 add_all_pos(it2, out_pos[in], out_pos[cur]);
626 }
627 }
628 }
629
630 /* connects the previous nodes to those ones */
631 if(out_pos.find(targ)!=out_pos.end())
632 {
633 for(std::set<nodet>::const_iterator to=out_pos[targ].begin();
634 to!=out_pos[targ].end(); ++to)
635 for(std::set<nodet>::const_iterator from=in_pos[i_it].begin();
636 from!=in_pos[i_it].end(); ++from)
637 if(from->first!=to->first)
638 {
639 if(egraph[from->first].thread!=egraph[to->first].thread)
640 continue;
641 instrumenter.message.debug() << from->first<<"-po->"
642 <<to->first << messaget::eom;
643 egraph.add_po_back_edge(from->first, to->first);
644 egraph_alt.add_edge(from->second, to->second);
645 }
646 }
647 }
648}
649
651 const irep_idt &function_id,
652 const goto_programt &goto_program,
653 goto_programt::instructionst::iterator i_it,
655 value_setst &value_sets
657 ,
659#endif
660)
661{
662 const goto_programt::instructiont &instruction=*i_it;
663
664 /* propagates */
665 visit_cfg_propagate(i_it);
666
667 /* if back-edges, constructs them too:
668 if goto to event, connects previously propagated events to it;
669 if not, we need to find which events AFTER the target are to
670 be connected. We do a backward analysis. */
671 if(instruction.is_backwards_goto())
672 {
673 instrumenter.message.debug() << "backward goto" << messaget::eom;
674 visit_cfg_body(
675 function_id,
676 goto_program,
677 i_it,
679 value_sets
681 ,
683#endif
684 ); // NOLINT(whitespace/parens)
685 }
686}
687
689 value_setst &value_sets,
690 goto_programt::instructionst::iterator i_it,
691 memory_modelt model,
692 bool no_dependencies,
694{
695 const goto_programt::instructiont &instruction=*i_it;
696
697 const exprt &fun = instruction.call_function();
698 const irep_idt &fun_id=to_symbol_expr(fun).get_identifier();
699 /* ignore recursive calls -- underapproximation */
700 try
701 {
702 enter_function(fun_id);
703 #ifdef CONTEXT_INSENSITIVE
704 stack_fun.push(cur_fun);
705 cur_fun=fun_id;
706 #endif
707
708 #if 0
709 if(!inline_function_cond(fun_id))
710 {
711 /* do not inline it, connect to an existing subgraph or create a new
712 one */
713 if(instrumenter.map_function_graph.find(fun_id)!=
714 instrumenter.map_function_graph.end())
715 {
716 /* connects to existing */
717 /* TODO */
718 }
719 else
720 {
721 /* just inlines */
722 /* TODO */
723 visit_cfg_function(value_sets, model, no_dependencies, fun_id,
724 in_pos[i_it]);
725 updated.insert(i_it);
726 }
727 }
728 else // NOLINT(readability/braces)
729 #endif
730 {
731 /* normal inlining strategy */
732 visit_cfg_function(value_sets, model, no_dependencies, replicate_body,
733 fun_id, in_pos[i_it]);
734 updated.insert(i_it);
735 }
736
737 leave_function(fun_id);
738 #ifdef CONTEXT_INSENSITIVE
739 cur_fun=stack_fun.pop();
740 #endif
741 }
742 catch(const std::string &s)
743 {
744 instrumenter.message.warning() << "sorry, doesn't handle recursion "
745 << "(function " << fun_id << "; .cpp) "
746 << s << messaget::eom;
747 }
748}
749
751 goto_programt::instructionst::iterator i_it,
752 const irep_idt &function_id)
753{
754 const goto_programt::instructiont &instruction=*i_it;
757 thread,
758 "f",
759 instrumenter.unique_id++,
760 instruction.source_location(),
761 function_id,
762 false);
767 instrumenter.map_vertex_gnode.insert(
768 std::make_pair(new_fence_node, new_fence_gnode));
769
770 for(const auto &in : instruction.incoming_edges)
771 if(in_pos.find(in)!=in_pos.end())
772 {
773 for(const auto &node : in_pos[in])
774 {
775 if(egraph[node.first].thread!=thread)
776 continue;
777 instrumenter.message.debug() << node.first<<"-po->"<<new_fence_node
778 << messaget::eom;
779 egraph.add_po_edge(node.first, new_fence_node);
780 egraph_alt.add_edge(node.second, new_fence_gnode);
781 }
782 }
783
784 in_pos[i_it].clear();
785 in_pos[i_it].insert(nodet(new_fence_node, new_fence_gnode));
786 updated.insert(i_it);
787}
788
790 goto_programt::instructionst::iterator i_it,
791 const irep_idt &function_id)
792{
793 const goto_programt::instructiont &instruction=*i_it;
794 bool WRfence = instruction.code().get_bool(ID_WRfence);
795 bool WWfence = instruction.code().get_bool(ID_WWfence);
796 bool RRfence = instruction.code().get_bool(ID_RRfence);
797 bool RWfence = instruction.code().get_bool(ID_RWfence);
798 bool WWcumul = instruction.code().get_bool(ID_WWcumul);
799 bool RRcumul = instruction.code().get_bool(ID_RRcumul);
800 bool RWcumul = instruction.code().get_bool(ID_RWcumul);
803 thread,
804 "asm",
805 instrumenter.unique_id++,
806 instruction.source_location(),
807 function_id,
808 false,
809 WRfence,
810 WWfence,
811 RRfence,
812 RWfence,
813 WWcumul,
814 RWcumul,
815 RRcumul);
820 instrumenter.map_vertex_gnode.insert(
821 std::make_pair(new_fence_node, new_fence_gnode));
822
823 for(const auto &in : instruction.incoming_edges)
824 if(in_pos.find(in)!=in_pos.end())
825 {
826 for(const auto &node : in_pos[in])
827 {
828 if(egraph[node.first].thread!=thread)
829 continue;
830 instrumenter.message.debug() << node.first<<"-po->"<<new_fence_node
831 << messaget::eom;
832 egraph.add_po_edge(node.first, new_fence_node);
833 egraph_alt.add_edge(node.second, new_fence_gnode);
834 }
835 }
836
837 in_pos[i_it].clear();
838 in_pos[i_it].insert(nodet(new_fence_node, new_fence_gnode));
839 updated.insert(i_it);
840}
841
843 value_setst &value_sets,
844 const irep_idt &function_id,
845 goto_programt::instructionst::iterator &i_it,
846 bool no_dependencies
848 ,
850#endif
851)
852{
853 goto_programt::instructiont &instruction=*i_it;
854
855 /* Read (Rb) */
857 ns,
858 value_sets,
859 function_id,
860 i_it
862 ,
864#endif
865 ); // NOLINT(whitespace/parens)
866
867 event_idt previous=std::numeric_limits<event_idt>::max();
868 event_idt previous_gnode=std::numeric_limits<event_idt>::max();
869
870#if 0
871 /* for the moment, use labels ASSERT in front of the assertions
872 to prevent them from being instrumented */
873 if(instruction.is_assert())
874 continue; // return;
875 if(!instruction.labels.empty() && instruction.labels.front()=="ASSERT")
876 continue; // return;
877#endif
878
879 for(const auto &r_entry : rw_set.r_entries)
880 {
881 /* creates Read:
882 read is the irep_id of the read in the code;
883 new_read_event is the corresponding abstract event;
884 new_read_node is the node in the graph */
885 const irep_idt &read = r_entry.second.object;
886
887 /* skip local variables */
888 if(local(read))
889 continue;
890
891 read_counter++;
892#if 0
894#endif
895
898 thread,
899 id2string(read),
900 instrumenter.unique_id++,
901 instruction.source_location(),
902 function_id,
903 local(read));
904
907 instrumenter.message.debug() << "new Read" << read << " @thread" << (thread)
908 << "(" << instruction.source_location() << ","
909 << (local(read) ? "local" : "shared") << ") #"
911
912 if(read==ID_unknown)
913 unknown_read_nodes.insert(new_read_node);
914
917 instrumenter.map_vertex_gnode.insert(
918 std::make_pair(new_read_node, new_read_gnode));
919
920 /* creates ... -po-> Read */
921 for(const auto &in : instruction.incoming_edges)
922 {
923 if(in_pos.find(in)!=in_pos.end())
924 {
925 for(const auto &node : in_pos[in])
926 {
927 if(egraph[node.first].thread!=thread)
928 continue;
929 instrumenter.message.debug() << node.first<<"-po->"
931 egraph.add_po_edge(node.first, new_read_node);
932 egraph_alt.add_edge(node.second, new_read_gnode);
933 }
934 }
935 }
936
937 map_reads.insert(id2node_pairt(read, new_read_node));
938 previous=new_read_node;
940
941 /* creates Read <-com-> Write ... */
942 const std::pair<id2nodet::iterator, id2nodet::iterator>
943 with_same_var=map_writes.equal_range(read);
944 for(id2nodet::iterator id_it=with_same_var.first;
945 id_it!=with_same_var.second; id_it++)
946 if(egraph[id_it->second].thread!=new_read_event.thread)
947 {
948 instrumenter.message.debug() << id_it->second<<"<-com->"
950 std::map<event_idt, event_idt>::const_iterator entry=
951 instrumenter.map_vertex_gnode.find(id_it->second);
952 CHECK_RETURN(entry != instrumenter.map_vertex_gnode.end());
954 egraph_alt.add_edge(new_read_gnode, entry->second);
956 egraph_alt.add_edge(entry->second, new_read_gnode);
957 ++fr_rf_counter;
958 }
959
960 /* for unknown writes */
961 for(std::set<event_idt>::const_iterator id_it=
962 unknown_write_nodes.begin();
963 id_it!=unknown_write_nodes.end();
964 ++id_it)
965 if(egraph[*id_it].thread!=new_read_event.thread)
966 {
967 instrumenter.message.debug() << *id_it<<"<-com->"
969 std::map<event_idt, event_idt>::const_iterator entry=
970 instrumenter.map_vertex_gnode.find(*id_it);
971 CHECK_RETURN(entry != instrumenter.map_vertex_gnode.end());
973 egraph_alt.add_edge(new_read_gnode, entry->second);
975 egraph_alt.add_edge(entry->second, new_read_gnode);
976 ++fr_rf_counter;
977 }
978 }
979
980 /* Write (Wa) */
981 for(const auto &w_entry : rw_set.w_entries)
982 {
983 /* creates Write:
984 write is the irep_id in the code;
985 new_write_event is the corresponding abstract event;
986 new_write_node is the node in the graph */
987 const irep_idt &write = w_entry.second.object;
988
989 instrumenter.message.debug() << "WRITE: " << write << messaget::eom;
990
991 /* skip local variables */
992 if(local(write))
993 continue;
994
995 ++write_counter;
996 // assert(write_expr);
997
998 /* creates Write */
1001 thread,
1002 id2string(write),
1003 instrumenter.unique_id++,
1004 instruction.source_location(),
1005 function_id,
1006 local(write));
1007
1010 instrumenter.message.debug()
1011 << "new Write " << write << " @thread" << (thread) << "("
1012 << instruction.source_location() << ","
1013 << (local(write) ? "local" : "shared") << ") #" << new_write_node
1014 << messaget::eom;
1015
1016 if(write==ID_unknown)
1017 unknown_read_nodes.insert(new_write_node);
1018
1021 instrumenter.map_vertex_gnode.insert(
1022 std::pair<event_idt, event_idt>(new_write_node, new_write_gnode));
1023
1024 /* creates Read -po-> Write */
1025 if(previous!=std::numeric_limits<event_idt>::max())
1026 {
1027 instrumenter.message.debug() << previous<<"-po->"<<new_write_node
1028 << messaget::eom;
1031 }
1032 else
1033 {
1034 for(const auto &in : instruction.incoming_edges)
1035 {
1036 if(in_pos.find(in)!=in_pos.end())
1037 {
1038 for(const auto &node : in_pos[in])
1039 {
1040 if(egraph[node.first].thread!=thread)
1041 continue;
1042 instrumenter.message.debug() << node.first<<"-po->"
1044 egraph.add_po_edge(node.first, new_write_node);
1045 egraph_alt.add_edge(node.second, new_write_gnode);
1046 }
1047 }
1048 }
1049 }
1050
1051 /* creates Write <-com-> Read */
1052 const std::pair<id2nodet::iterator, id2nodet::iterator>
1053 r_with_same_var=map_reads.equal_range(write);
1054 for(id2nodet::iterator idr_it=r_with_same_var.first;
1055 idr_it!=r_with_same_var.second; idr_it++)
1056 if(egraph[idr_it->second].thread!=new_write_event.thread)
1057 {
1058 instrumenter.message.debug() <<idr_it->second<<"<-com->"
1060 std::map<event_idt, event_idt>::const_iterator entry=
1061 instrumenter.map_vertex_gnode.find(idr_it->second);
1062 CHECK_RETURN(entry != instrumenter.map_vertex_gnode.end());
1064 egraph_alt.add_edge(new_write_gnode, entry->second);
1066 egraph_alt.add_edge(entry->second, new_write_gnode);
1067 ++fr_rf_counter;
1068 }
1069
1070 /* creates Write <-com-> Write */
1071 const std::pair<id2nodet::iterator, id2nodet::iterator>
1072 w_with_same_var=map_writes.equal_range(write);
1073 for(id2nodet::iterator idw_it=w_with_same_var.first;
1074 idw_it!=w_with_same_var.second; idw_it++)
1075 if(egraph[idw_it->second].thread!=new_write_event.thread)
1076 {
1077 instrumenter.message.debug() << idw_it->second<<"<-com->"
1079 std::map<event_idt, event_idt>::const_iterator entry=
1080 instrumenter.map_vertex_gnode.find(idw_it->second);
1081 CHECK_RETURN(entry != instrumenter.map_vertex_gnode.end());
1083 egraph_alt.add_edge(new_write_gnode, entry->second);
1085 egraph_alt.add_edge(entry->second, new_write_gnode);
1086 ++ws_counter;
1087 }
1088
1089 /* for unknown writes */
1090 for(std::set<event_idt>::const_iterator id_it=
1091 unknown_write_nodes.begin();
1092 id_it!=unknown_write_nodes.end();
1093 ++id_it)
1094 if(egraph[*id_it].thread!=new_write_event.thread)
1095 {
1096 instrumenter.message.debug() << *id_it<<"<-com->"
1098 std::map<event_idt, event_idt>::const_iterator entry=
1099 instrumenter.map_vertex_gnode.find(*id_it);
1100 CHECK_RETURN(entry != instrumenter.map_vertex_gnode.end());
1102 egraph_alt.add_edge(new_write_gnode, entry->second);
1104 egraph_alt.add_edge(entry->second, new_write_gnode);
1105 ++fr_rf_counter;
1106 }
1107
1108 /* for unknown reads */
1109 for(std::set<event_idt>::const_iterator id_it=
1110 unknown_read_nodes.begin();
1111 id_it!=unknown_read_nodes.end();
1112 ++id_it)
1113 if(egraph[*id_it].thread!=new_write_event.thread)
1114 {
1115 instrumenter.message.debug() << *id_it<<"<-com->"
1117 std::map<event_idt, event_idt>::const_iterator entry=
1118 instrumenter.map_vertex_gnode.find(*id_it);
1119 CHECK_RETURN(entry != instrumenter.map_vertex_gnode.end());
1121 egraph_alt.add_edge(new_write_gnode, entry->second);
1123 egraph_alt.add_edge(entry->second, new_write_gnode);
1124 ++fr_rf_counter;
1125 }
1126
1127
1128 map_writes.insert(id2node_pairt(write, new_write_node));
1129 previous=new_write_node;
1131 }
1132
1133 if(previous!=std::numeric_limits<event_idt>::max())
1134 {
1135 in_pos[i_it].clear();
1136 in_pos[i_it].insert(nodet(previous, previous_gnode));
1137 updated.insert(i_it);
1138 }
1139 else
1140 {
1141 /* propagation */
1142 visit_cfg_skip(i_it);
1143 }
1144
1145 /* data dependency analysis */
1146 if(!no_dependencies)
1147 {
1148 for(const auto &w_entry : rw_set.w_entries)
1149 {
1150 for(const auto &r_entry : rw_set.r_entries)
1151 {
1152 const irep_idt &write = w_entry.second.object;
1153 const irep_idt &read = r_entry.second.object;
1154 instrumenter.message.debug() << "dp: Write:"<<write<<"; Read:"<<read
1155 << messaget::eom;
1156 const datat read_p(read, instruction.source_location());
1157 const datat write_p(write, instruction.source_location());
1158 data_dp.dp_analysis(read_p, local(read), write_p, local(write));
1159 }
1160 }
1161 data_dp.dp_merge();
1162
1163 for(const auto &r_entry : rw_set.r_entries)
1164 {
1165 for(const auto &r_entry2 : rw_set.r_entries)
1166 {
1167 const irep_idt &read2 = r_entry2.second.object;
1168 const irep_idt &read = r_entry.second.object;
1169 if(read2==read)
1170 continue;
1171 const datat read_p(read, instruction.source_location());
1172 const datat read2_p(read2, instruction.source_location());
1173 data_dp.dp_analysis(read_p, local(read), read2_p, local(read2));
1174 }
1175 }
1176 data_dp.dp_merge();
1177 }
1178}
1179
1181 goto_programt::instructionst::iterator i_it,
1182 const irep_idt &function_id)
1183{
1184 const goto_programt::instructiont &instruction=*i_it;
1187 thread,
1188 "F",
1189 instrumenter.unique_id++,
1190 instruction.source_location(),
1191 function_id,
1192 false);
1197 instrumenter.map_vertex_gnode.insert(
1198 std::make_pair(new_fence_node, new_fence_gnode));
1199
1200 for(const auto &in : instruction.incoming_edges)
1201 if(in_pos.find(in)!=in_pos.end())
1202 {
1203 for(const auto &node : in_pos[in])
1204 {
1205 instrumenter.message.debug() << node.first<<"-po->"<<new_fence_node
1206 << messaget::eom;
1207 egraph.add_po_edge(node.first, new_fence_node);
1208 egraph_alt.add_edge(node.second, new_fence_gnode);
1209 }
1210 }
1211#if 0
1212 std::set<nodet> s;
1214 in_pos[i_it]=s;
1215 updated.insert(i_it);
1216#endif
1217 in_pos[i_it].clear();
1218 in_pos[i_it].insert(nodet(new_fence_node, new_fence_gnode));
1219 updated.insert(i_it);
1220}
1221
1223 goto_programt::instructionst::iterator i_it)
1224{
1225 visit_cfg_propagate(i_it);
1226}
1227
1229 goto_programt::instructionst::iterator it,
1231{
1232 if(
1233 it->is_set_return_value() || it->is_throw() || it->is_catch() ||
1234 it->is_skip() || it->is_dead() || it->is_start_thread() ||
1235 it->is_end_thread())
1236 return;
1237
1238 if(it->is_atomic_begin() ||
1239 it->is_atomic_end())
1240 {
1241 /* atomicity not checked here for the moment */
1242 return;
1243 }
1244
1245 if(it->is_function_call())
1246 {
1247 /* function call not supported for the moment */
1248 return;
1249 }
1250
1251 /* add this instruction to the interleaving */
1253}
1254
1256{
1257 message.debug() << "spurious by CFG? " << messaget::eom;
1259
1261 e_it!=cyc.end() && ++e_it!=cyc.end(); ++e_it)
1262 {
1263 --e_it;
1264
1266 const source_locationt &current_location=current_event.source_location;
1267
1268 /* select relevant thread (po) -- or function contained in this thread */
1269 goto_programt *current_po=nullptr;
1270 bool thread_found=false;
1271
1273 {
1274 for(const auto &instruction : gf_entry.second.body.instructions)
1275 {
1276 if(instruction.source_location() == current_location)
1277 {
1278 current_po = &gf_entry.second.body;
1279 thread_found=true;
1280 break;
1281 }
1282 }
1283
1284 if(thread_found)
1285 break;
1286 }
1287 INVARIANT(current_po, "thread found");
1288
1291 --e_it;
1292
1293 bool exists_n=false;
1294
1295 for(wmm_grapht::edgest::const_iterator edge_it=pos_cur.begin();
1296 edge_it!=pos_cur.end(); edge_it++)
1297 {
1298 if(pos_next.find(edge_it->first)!=pos_next.end())
1299 {
1300 exists_n=true;
1301 break;
1302 }
1303 }
1304
1305 /* !exists n, has_po_edge(*e_it,n) /\ has_po_edge(*(++it--),n) */
1306 if((++e_it)!=cyc.end() || !exists_n)
1307 {
1308 --e_it;
1309
1310 /* add this instruction to the interleaving */
1312 if(i_it->source_location() == current_location)
1313 {
1314 /* add all the instructions of this line */
1315 for(goto_programt::instructionst::iterator same_loc = i_it;
1316 same_loc != current_po->instructions.end() &&
1317 same_loc->source_location() == i_it->source_location();
1318 same_loc++)
1320 break;
1321 }
1322 }
1323 else
1324 {
1325 --e_it;
1326
1327 /* find the portion of the thread to add */
1328 const abstract_eventt &next_event=egraph[*(++e_it--)];
1329 const source_locationt &next_location=next_event.source_location;
1330
1331 bool in_cycle=false;
1333 {
1334 if(it->source_location() == current_location)
1335 in_cycle=true;
1336
1337 /* do not add the last instruction now -- will be done at
1338 the next iteration */
1339 if(it->source_location() == next_location)
1340 break;
1341
1342 if(in_cycle)
1344 }
1345 }
1346 }
1347
1348 /* if a goto points to a label outside from this interleaving, replace it
1349 by an assert 0 */
1350 for(auto &instruction : interleaving.instructions)
1351 {
1352 if(instruction.is_goto())
1353 {
1354 for(const auto &t : instruction.targets)
1355 {
1356 bool target_in_cycle=false;
1357
1359 {
1360 if(targ==t)
1361 {
1362 target_in_cycle=true;
1363 break;
1364 }
1365 }
1366
1367 if(!target_in_cycle)
1368 {
1369 instruction = goto_programt::make_assertion(
1370 false_exprt(), instruction.source_location());
1371 break;
1372 }
1373 }
1374 }
1375 }
1376
1377 /* now test whether this part of the code can exist */
1380 one_interleaving.body.copy_from(interleaving);
1381 map.insert(std::make_pair(
1383 std::move(one_interleaving)));
1384
1386 this_interleaving.function_map=std::move(map);
1388
1389 #if 0
1390 bmct bmc(no_option, symbol_table, no_message);
1391
1393
1394 message.debug() << "CFG:"<<is_spurious << messaget::eom;
1395 return is_spurious;
1396 #else
1397
1398 return false; // conservative for now
1399 #endif
1400}
1401
1403{
1404 if(!set_of_cycles.empty())
1405 {
1406 for(std::set<event_grapht::critical_cyclet>::iterator
1407 it=set_of_cycles.begin();
1408 it!=set_of_cycles.end();
1409 )
1410 {
1411 bool erased=false;
1412 std::set<event_grapht::critical_cyclet>::iterator next=it;
1413 ++next;
1414 if(is_cfg_spurious(*it))
1415 {
1416 erased=true;
1417 set_of_cycles.erase(it);
1418 }
1419 it=next;
1420 if(!erased)
1421 ++it;
1422 }
1423 }
1424 else if(num_sccs > 0)
1425 {
1426 for(unsigned i=0; i<num_sccs; i++)
1427 for(std::set<event_grapht::critical_cyclet>::iterator it=
1428 set_of_cycles_per_SCC[i].begin();
1429 it!=set_of_cycles_per_SCC[i].end();
1430 )
1431 {
1432 bool erased=false;
1433 std::set<event_grapht::critical_cyclet>::iterator next=it;
1434 ++next;
1435 if(is_cfg_spurious(*it))
1436 {
1437 erased=true;
1438 set_of_cycles_per_SCC[i].erase(it);
1439 }
1440 it=next;
1441 if(!erased)
1442 ++it;
1443 }
1444 }
1445 else
1446 message.status() << "No cycle to filter" << messaget::eom;
1447}
1448
1450 const std::set<event_grapht::critical_cyclet> &set,
1451 std::ofstream &dot,
1452 std::ofstream &ref,
1453 std::ofstream &output,
1454 std::ofstream &all,
1455 std::ofstream &table,
1456 memory_modelt model,
1457 bool hide_internals)
1458{
1459 /* to represent the po aligned in the dot */
1460 std::map<unsigned, std::set<event_idt> > same_po;
1461 unsigned max_thread=0;
1462 unsigned colour=0;
1463
1464 /* to represent the files as clusters */
1465 std::map<irep_idt, std::set<event_idt> > same_file;
1466
1467 /* to summarise in a table all the variables */
1468 std::map<std::string, std::string> map_id2var;
1469 std::map<std::string, std::string> map_var2id;
1470
1471 for(std::set<event_grapht::critical_cyclet>::const_iterator it =
1472 set.begin(); it!=set.end(); it++)
1473 {
1474#ifdef PRINT_UNSAFES
1475 message.debug() << it->print_unsafes() << messaget::eom;
1476#endif
1477 it->print_dot(dot, colour++, model);
1478 ref << it->print_name(model, hide_internals) << '\n';
1479 output << it->print_output() << '\n';
1480 all << it->print_all(model, map_id2var, map_var2id, hide_internals)
1481 << '\n';
1482
1483 /* emphasises instrumented events */
1484 for(std::list<event_idt>::const_iterator it_e=it->begin();
1485 it_e!=it->end(); it_e++)
1486 {
1487 const abstract_eventt &ev=egraph[*it_e];
1488
1490 same_po[ev.thread].insert(*it_e);
1492 same_file[ev.function_id].insert(*it_e);
1493 else if(render_by_file)
1494 same_file[ev.source_location.get_file()].insert(*it_e);
1495 if(ev.thread>max_thread)
1496 max_thread=ev.thread;
1497
1498 if(var_to_instr.find(ev.variable)!=var_to_instr.end()
1499 && id2loc.find(ev.variable)!=id2loc.end())
1500 {
1501 dot << ev.id << "[label=\"\\\\lb {" << ev.id << "}";
1502 dot << ev.get_operation() << "{" << ev.variable << "} {} @thread";
1503 dot << ev.thread << "\",color=red,shape=box];\n";
1504 }
1505 }
1506 }
1507
1508 /* aligns events by po */
1510 {
1511 for(unsigned i=0; i<=max_thread; i++)
1512 if(!same_po[i].empty())
1513 {
1514 dot << "{rank=same; thread_" << i
1515 << "[shape=plaintext, label=\"thread " << i << "\"];";
1516 for(std::set<event_idt>::iterator it=same_po[i].begin();
1517 it!=same_po[i].end(); it++)
1518 dot << egraph[*it].id << ";";
1519 dot << "};\n";
1520 }
1521 }
1522
1523 /* clusters events by file/function */
1525 {
1526 for(std::map<irep_idt, std::set<event_idt> >::const_iterator it=
1527 same_file.begin();
1528 it!=same_file.end(); it++)
1529 {
1530 dot << "subgraph cluster_" << irep_id_hash()(it->first) << "{\n";
1531 dot << " label=\"" << it->first << "\";\n";
1532 for(std::set<event_idt>::const_iterator ev_it=it->second.begin();
1533 ev_it!=it->second.end(); ev_it++)
1534 {
1535 dot << " " << egraph[*ev_it].id << ";\n";
1536 }
1537 dot << "};\n";
1538 }
1539 }
1540
1541 /* variable table for "all" */
1542 table << std::string(80, '-');
1543 for(std::map<std::string, std::string>::const_iterator
1544 m_it=map_id2var.begin();
1545 m_it!=map_id2var.end();
1546 ++m_it)
1547 {
1548 table << "\n| " << m_it->first << " : " << m_it->second;
1549 }
1550 table << '\n';
1551 table << std::string(80, '-');
1552 table << '\n';
1553}
1554
1555void instrumentert::print_outputs(memory_modelt model, bool hide_internals)
1556{
1557 std::ofstream dot;
1558 std::ofstream ref;
1559 std::ofstream output;
1560 std::ofstream all;
1561 std::ofstream table;
1562
1563 dot.open("cycles.dot");
1564 ref.open("ref.txt");
1565 output.open("output.txt");
1566 all.open("all.txt");
1567 table.open("table.txt");
1568
1569 dot << "digraph G {\n";
1570 dot << "nodesep=1; ranksep=1;\n";
1571
1572 /* prints cycles in the different outputs */
1573 if(!set_of_cycles.empty())
1575 model, hide_internals);
1576 else if(num_sccs!=0)
1577 {
1578 for(unsigned i=0; i<num_sccs; i++)
1579 {
1580 std::ofstream local_dot;
1581 std::string name="scc_" + std::to_string(i) + ".dot";
1582 local_dot.open(name.c_str());
1583
1584 local_dot << "digraph G {\n";
1585 local_dot << "nodesep=1; ranksep=1;\n";
1587 table, model, hide_internals);
1588 local_dot << "}\n";
1589 local_dot.close();
1590
1591 dot << i << "[label=\"SCC " << i << "\",link=\"" << "scc_" << i;
1592 dot << ".svg\"]\n";
1593 }
1594 }
1595 else
1596 message.debug() << "no cycles to output" << messaget::eom;
1597
1598 dot << "}\n";
1599
1600 dot.close();
1601 ref.close();
1602 output.close();
1603 all.close();
1604 table.close();
1605}
1606
1608#if 1
1609// #ifdef _WIN32
1611{
1612 unsigned scc=0;
1614 std::set<event_grapht::critical_cyclet>());
1615 for(std::vector<std::set<event_idt> >::const_iterator it=egraph_SCCs.begin();
1616 it!=egraph_SCCs.end(); it++)
1617 if(it->size()>=4)
1619}
1620#else
1622{
1623public:
1626 const std::set<event_idt> &filter;
1627 std::set<event_grapht::critical_cyclet> &cycles;
1628
1631 const std::set<event_idt> &_filter,
1632 std::set<event_grapht::critical_cyclet> &_cycles)
1633 :instr(_instr), mem(_mem), filter(_filter), cycles(_cycles)
1634 {
1635 }
1636};
1637
1638/* wraper */
1639void *collect_cycles_in_thread(void *arg)
1640{
1641 /* arguments */
1642 pthread_argumentt *p_arg=reinterpret_cast<pthread_argumentt*>(arg);
1644 memory_modelt model=p_arg->mem;
1645 const std::set<event_idt> &filter=p_arg->filter;
1646 std::set<event_grapht::critical_cyclet> &cycles=p_arg->cycles;
1647
1648 this_instrumenter.egraph.collect_cycles(cycles, model, filter);
1649
1650 return NULL;
1651}
1652
1654{
1655 const unsigned number_of_sccs=num_sccs;
1656 std::set<unsigned> interesting_SCCs;
1657
1658 unsigned scc=0;
1659 pthread_t *threads=new pthread_t[num_sccs+1];
1660
1662 std::set<event_grapht::critical_cyclet>());
1663
1664 for(std::vector<std::set<unsigned> >::const_iterator it=egraph_SCCs.begin();
1665 it!=egraph_SCCs.end(); it++)
1666 if(it->size()>=4)
1667 {
1668 interesting_SCCs.insert(scc);
1669 pthread_argumentt arg(*this, model, *it, set_of_cycles_per_SCC[scc]);
1670
1671 int rc=pthread_create(&threads[scc++], NULL,
1673
1674 message.status()<<(rc!=0?"Failure ":"Success ")
1675 <<"in creating thread for SCC #"<<scc-1<<messaget::eom;
1676 }
1677
1678 for(unsigned i=0; i<number_of_sccs; i++)
1679 if(interesting_SCCs.find(i)!=interesting_SCCs.end())
1680 {
1681 int rc=pthread_join(threads[i], NULL);
1682 message.status()<<(rc!=0?"Failure ":"Success ")
1683 <<"in joining thread for SCC #"<<i<<messaget::eom;
1684 }
1685
1686 delete[] threads;
1687}
1688#endif
virtual void clear()
Reset the abstract state.
Definition ai.h:266
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:563
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:39
data_typet::const_iterator const_iterator
Definition event_graph.h:70
event_idt copy_segment(event_idt begin, event_idt end)
const wmm_grapht::edgest & po_out(event_idt n) const
void collect_cycles(std::set< critical_cyclet > &set_of_cycles, memory_modelt model, const std::set< event_idt > &filter)
std::map< unsigned, data_dpt > map_data_dp
void add_com_edge(event_idt a, event_idt b)
messaget & message
void add_po_edge(event_idt a, event_idt b)
void add_po_back_edge(event_idt a, event_idt b)
event_idt add_node()
Base class for all expressions.
Definition expr.h:56
const source_locationt & source_location() const
Definition expr.h:223
The Boolean constant false.
Definition std_expr.h:3017
A collection of goto functions.
std::map< irep_idt, goto_functiont > function_mapt
function_mapt function_map
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
This class represents an instruction in the GOTO intermediate representation.
const goto_instruction_codet & code() const
Get the code represented by this instruction.
bool is_backwards_goto() const
Returns true if the instruction is a backwards branch.
const exprt & call_function() const
Get the function that is called for FUNCTION_CALL.
std::set< targett, target_less_than > incoming_edges
const source_locationt & source_location() const
goto_program_instruction_typet type() const
What kind of instruction?
A generic container class for the GOTO intermediate representation of one function.
instructionst instructions
The list of instructions in the goto program.
instructionst::const_iterator const_targett
std::list< instructiont > instructionst
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
std::size_t SCCs(std::vector< node_indext > &subgraph_nr) const
Computes strongly-connected components of a graph and yields a vector expressing a mapping from nodes...
Definition graph.h:832
nodet::edgest edgest
Definition graph.h:170
node_indext add_node(arguments &&... values)
Definition graph.h:180
void add_edge(node_indext a, node_indext b)
Definition graph.h:232
std::size_t size() const
Definition graph.h:212
void visit_cfg_backedge(goto_programt::const_targett targ, goto_programt::const_targett i_it)
strategy: fwd/bwd alternation
void visit_cfg_reference_function(irep_idt id_function)
references the first and last edges of the function
bool contains_shared_array(const irep_idt &function_id, goto_programt::const_targett targ, goto_programt::const_targett i_it, value_setst &value_sets) const
instrumentert & instrumenter
Definition goto2graph.h:90
virtual void visit_cfg_function(value_setst &value_sets, memory_modelt model, bool no_dependencies, loop_strategyt duplicate_body, const irep_idt &function_id, std::set< nodet > &ending_vertex)
TODO: move the visitor outside, and inherit.
std::pair< irep_idt, event_idt > id2node_pairt
Definition goto2graph.h:181
bool local(const irep_idt &i)
void visit_cfg_fence(goto_programt::instructionst::iterator i_it, const irep_idt &function_id)
void visit_cfg_goto(const irep_idt &function_id, const goto_programt &goto_program, goto_programt::instructionst::iterator i_it, loop_strategyt replicate_body, value_setst &value_sets)
void visit_cfg_function_call(value_setst &value_sets, goto_programt::instructionst::iterator i_it, memory_modelt model, bool no_dependenciess, loop_strategyt duplicate_body)
void visit_cfg_lwfence(goto_programt::instructionst::iterator i_it, const irep_idt &function_id)
void visit_cfg_propagate(goto_programt::instructionst::iterator i_it)
void visit_cfg_assign(value_setst &value_sets, const irep_idt &function_id, goto_programt::instructionst::iterator &i_it, bool no_dependencies)
void visit_cfg_duplicate(const goto_programt &goto_program, goto_programt::const_targett targ, goto_programt::const_targett i_it)
void visit_cfg_body(const irep_idt &function_id, const goto_programt &goto_program, goto_programt::const_targett i_it, loop_strategyt replicate_body, value_setst &value_sets)
strategy: fwd/bwd alternation
std::pair< event_idt, event_idt > nodet
Definition goto2graph.h:190
void visit_cfg_skip(goto_programt::instructionst::iterator i_it)
void visit_cfg_asm_fence(goto_programt::instructionst::iterator i_it, const irep_idt &function_id)
void print_outputs(memory_modelt model, bool hide_internals)
unsigned num_sccs
Definition goto2graph.h:319
void collect_cycles_by_SCCs(memory_modelt model)
Note: can be distributed (#define DISTRIBUTED)
event_grapht egraph
Definition goto2graph.h:309
std::set< event_grapht::critical_cyclet > set_of_cycles
Definition goto2graph.h:315
bool render_po_aligned
Definition goto2graph.h:45
std::set< irep_idt > var_to_instr
Definition goto2graph.h:353
std::vector< std::set< event_idt > > egraph_SCCs
Definition goto2graph.h:312
std::multimap< irep_idt, source_locationt > id2loc
Definition goto2graph.h:354
bool is_cfg_spurious(const event_grapht::critical_cyclet &cyc)
bool render_by_function
Definition goto2graph.h:47
goto_functionst & goto_functions
Definition goto2graph.h:36
bool render_by_file
Definition goto2graph.h:46
std::map< event_idt, event_idt > map_vertex_gnode
Definition goto2graph.h:39
namespacet ns
Definition goto2graph.h:33
std::vector< std::set< event_grapht::critical_cyclet > > set_of_cycles_per_SCC
Definition goto2graph.h:318
wmm_grapht egraph_alt
Definition goto2graph.h:40
void add_instr_to_interleaving(goto_programt::instructionst::iterator it, goto_programt &interleaving)
messaget & message
Definition goto2graph.h:306
bool local(const irep_idt &id)
is local variable?
unsigned goto2graph_cfg(value_setst &value_sets, memory_modelt model, bool no_dependencies, loop_strategyt duplicate_body)
goes through CFG and build a static abstract event graph overapproximating the read/write relations f...
void cfg_cycles_filter()
void print_outputs_local(const std::set< event_grapht::critical_cyclet > &set, std::ofstream &dot, std::ofstream &ref, std::ofstream &output, std::ofstream &all, std::ofstream &table, memory_modelt model, bool hide_internals)
mstreamt & debug() const
Definition message.h:429
mstreamt & statistics() const
Definition message.h:419
static eomt eom
Definition message.h:297
mstreamt & status() const
Definition message.h:414
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
Symbol table entry.
Definition symbol.h:28
bool is_static_lifetime
Definition symbol.h:70
bool is_thread_local
Definition symbol.h:71
bool has_prefix(const std::string &s, const std::string &prefix)
Definition converter.cpp:13
#define CPROVER_PREFIX
void dot(const goto_modelt &src, std::ostream &out)
Definition dot.cpp:359
wmm_grapht::node_indext event_idt
Definition event_graph.h:32
bool is_fence(const goto_programt::instructiont &instruction, const namespacet &ns)
Definition fence.cpp:19
bool is_lwfence(const goto_programt::instructiont &instruction, const namespacet &ns)
Definition fence.cpp:35
Fences for instrumentation.
event_idt alt_copy_segment(wmm_grapht &alt_egraph, event_idt begin, event_idt end)
Instrumenter.
#define add_all_pos(it, target, source)
Definition goto2graph.h:204
#define forall_goto_program_instructions(it, program)
#define Forall_goto_program_instructions(it, program)
dstring_hash irep_id_hash
Definition irep.h:39
const std::string & id2string(const irep_idt &d)
Definition irep.h:47
literalt pos(literalt a)
Definition literal.h:194
Options.
Race Detection for Threaded Goto Programs.
#define CHECK_RETURN(CONDITION)
Definition invariant.h:495
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423
#define INITIALIZE_FUNCTION
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition std_expr.h:222
memory_modelt
Definition wmm.h:18
@ TSO
Definition wmm.h:20
loop_strategyt
Definition wmm.h:37
@ all_loops
Definition wmm.h:39
@ arrays_only
Definition wmm.h:38
@ no_loop
Definition wmm.h:40
@ all
Definition wmm.h:28