cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
abstract_event.h
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: abstract events
4
5
Author: Vincent Nimal
6
7
Date: 2012
8
9
\*******************************************************************/
10
13
14
#ifndef CPROVER_GOTO_INSTRUMENT_WMM_ABSTRACT_EVENT_H
15
#define CPROVER_GOTO_INSTRUMENT_WMM_ABSTRACT_EVENT_H
16
17
#include <
util/source_location.h
>
18
#include <
util/graph.h
>
19
20
#include "
wmm.h
"
21
22
class
abstract_eventt
:
public
graph_nodet
<empty_edget>
23
{
24
protected
:
25
bool
unsafe_pair_lwfence_param
(
const
abstract_eventt
&next,
26
memory_modelt
model,
bool
lwsync_met)
const
;
27
28
public
:
29
/* for now, both fence functions and asm fences accepted */
30
enum class
operationt
{
Write
,
Read
,
Fence
,
Lwfence
,
ASMfence
};
31
32
operationt
operation
;
33
unsigned
thread
;
34
irep_idt
variable
;
35
unsigned
id
;
36
source_locationt
source_location
;
37
irep_idt
function_id
;
38
bool
local
;
39
40
// for ASMfence
41
bool
WRfence
;
42
bool
WWfence
;
43
bool
RRfence
;
44
bool
RWfence
;
45
bool
WWcumul
;
46
bool
RWcumul
;
47
bool
RRcumul
;
48
49
abstract_eventt
():
50
operation
(
operationt
::
Write
),
51
thread
(0),
52
id
(0),
53
local
(false),
54
WRfence
(false),
55
WWfence
(false),
56
RRfence
(false),
57
RWfence
(false),
58
WWcumul
(false),
59
RWcumul
(false),
60
RRcumul
(false)
61
{
62
}
63
64
abstract_eventt
(
65
operationt
_op,
66
unsigned
_th,
67
irep_idt
_var,
68
unsigned
_id,
69
source_locationt
_loc,
70
irep_idt
_function_id,
71
bool
_local)
72
:
operation
(_op),
73
thread
(_th),
74
variable
(_var),
75
id
(_id),
76
source_location
(_loc),
77
function_id
(_function_id),
78
local
(_local)
79
{
80
}
81
82
abstract_eventt
(
83
operationt
_op,
84
unsigned
_th,
85
irep_idt
_var,
86
unsigned
_id,
87
source_locationt
_loc,
88
irep_idt
_function_id,
89
bool
_local,
90
bool
WRf,
91
bool
WWf,
92
bool
RRf,
93
bool
RWf,
94
bool
WWc,
95
bool
RWc,
96
bool
RRc)
97
:
operation
(_op),
98
thread
(_th),
99
variable
(_var),
100
id
(_id),
101
source_location
(_loc),
102
function_id
(_function_id),
103
local
(_local),
104
WRfence
(RWf),
105
WWfence
(WWf),
106
RRfence
(RRf),
107
RWfence
(WRf),
108
WWcumul
(WWc),
109
RWcumul
(RWc),
110
RRcumul
(RRc)
111
{
112
}
113
114
/* post declaration (through graph) -- doesn't copy */
115
void
operator()
(
const
abstract_eventt
&other)
116
{
117
operation
=other.
operation
;
118
thread
=other.
thread
;
119
variable
=other.
variable
;
120
id
=other.
id
;
121
source_location
=other.
source_location
;
122
function_id
= other.
function_id
;
123
local
=other.
local
;
124
}
125
126
bool
operator==
(
const
abstract_eventt
&other)
const
127
{
128
return
(
id
== other.
id
);
129
}
130
131
bool
operator<
(
const
abstract_eventt
&other)
const
132
{
133
return
(
id
< other.
id
);
134
}
135
136
bool
is_fence
()
const
137
{
138
return
operation
==
operationt::Fence
||
139
operation
==
operationt::Lwfence
||
140
operation
==
operationt::ASMfence
;
141
}
142
143
/* checks the safety of the pair locally (i.e., w/o taking fences
144
or dependencies into account -- use is_unsafe on the whole
145
critical cycle for this) */
146
bool
unsafe_pair
(
const
abstract_eventt
&next,
memory_modelt
model)
const
147
{
148
return
unsafe_pair_lwfence_param
(next, model,
false
);
149
}
150
151
bool
unsafe_pair_lwfence
(
152
const
abstract_eventt
&next,
153
memory_modelt
model)
const
154
{
155
return
unsafe_pair_lwfence_param
(next, model,
true
);
156
}
157
158
bool
unsafe_pair_asm
(
159
const
abstract_eventt
&next,
160
memory_modelt
model,
161
unsigned
char
met)
const
;
162
163
std::string
get_operation
()
const
164
{
165
switch
(
operation
)
166
{
167
case
operationt::Write
:
return
"W"
;
168
case
operationt::Read
:
return
"R"
;
169
case
operationt::Fence
:
return
"F"
;
170
case
operationt::Lwfence
:
return
"f"
;
171
case
operationt::ASMfence
:
return
"asm:"
;
172
}
173
UNREACHABLE
;
174
return
"?"
;
175
}
176
177
bool
is_corresponding_fence
(
const
abstract_eventt
&first,
178
const
abstract_eventt
&second)
const
179
{
180
return
181
(
WRfence
&&
182
first.
operation
==
operationt::Write
&&
183
second.
operation
==
operationt::Read
) ||
184
((
WWfence
||
WWcumul
) &&
185
first.
operation
==
operationt::Write
&&
186
second.
operation
==
operationt::Write
) ||
187
((
RWfence
||
RWcumul
) &&
188
first.
operation
==
operationt::Read
&&
189
second.
operation
==
operationt::Write
) ||
190
((
RRfence
||
RRcumul
) &&
191
first.
operation
==
operationt::Read
&&
192
second.
operation
==
operationt::Read
);
193
}
194
195
bool
is_direct
()
const
{
return
WWfence
||
WRfence
||
RRfence
||
RWfence
; }
196
bool
is_cumul
()
const
{
return
WWcumul
||
RWcumul
||
RRcumul
; }
197
198
unsigned
char
fence_value
()
const
199
{
200
return
uc
(
WRfence
) + 2u *
uc
(
WWfence
) + 4u *
uc
(
RRfence
) +
201
8u *
uc
(
RWfence
) + 16u *
uc
(
WWcumul
) + 32u *
uc
(
RWcumul
) +
202
64u *
uc
(
RRcumul
);
203
}
204
205
private
:
206
static
unsigned
char
uc
(
bool
truth_value)
207
{
208
return
truth_value ? 1u : 0u;
209
}
210
};
211
212
inline
std::ostream &
operator<<
(
213
std::ostream &s,
214
const
abstract_eventt
&e)
215
{
216
return
s << e.
get_operation
() << e.
variable
;
217
}
218
219
#endif
// CPROVER_GOTO_INSTRUMENT_WMM_ABSTRACT_EVENT_H
operator<<
std::ostream & operator<<(std::ostream &s, const abstract_eventt &e)
Definition
abstract_event.h:212
abstract_eventt
Definition
abstract_event.h:23
abstract_eventt::is_cumul
bool is_cumul() const
Definition
abstract_event.h:196
abstract_eventt::operationt
operationt
Definition
abstract_event.h:30
abstract_eventt::operationt::Write
@ Write
Definition
abstract_event.h:30
abstract_eventt::operationt::Read
@ Read
Definition
abstract_event.h:30
abstract_eventt::operationt::Lwfence
@ Lwfence
Definition
abstract_event.h:30
abstract_eventt::operationt::ASMfence
@ ASMfence
Definition
abstract_event.h:30
abstract_eventt::operationt::Fence
@ Fence
Definition
abstract_event.h:30
abstract_eventt::unsafe_pair
bool unsafe_pair(const abstract_eventt &next, memory_modelt model) const
Definition
abstract_event.h:146
abstract_eventt::is_corresponding_fence
bool is_corresponding_fence(const abstract_eventt &first, const abstract_eventt &second) const
Definition
abstract_event.h:177
abstract_eventt::get_operation
std::string get_operation() const
Definition
abstract_event.h:163
abstract_eventt::operator()
void operator()(const abstract_eventt &other)
Definition
abstract_event.h:115
abstract_eventt::uc
static unsigned char uc(bool truth_value)
Definition
abstract_event.h:206
abstract_eventt::WRfence
bool WRfence
Definition
abstract_event.h:41
abstract_eventt::RWcumul
bool RWcumul
Definition
abstract_event.h:46
abstract_eventt::WWcumul
bool WWcumul
Definition
abstract_event.h:45
abstract_eventt::thread
unsigned thread
Definition
abstract_event.h:33
abstract_eventt::is_fence
bool is_fence() const
Definition
abstract_event.h:136
abstract_eventt::unsafe_pair_lwfence
bool unsafe_pair_lwfence(const abstract_eventt &next, memory_modelt model) const
Definition
abstract_event.h:151
abstract_eventt::source_location
source_locationt source_location
Definition
abstract_event.h:36
abstract_eventt::function_id
irep_idt function_id
Definition
abstract_event.h:37
abstract_eventt::id
unsigned id
Definition
abstract_event.h:35
abstract_eventt::RWfence
bool RWfence
Definition
abstract_event.h:44
abstract_eventt::unsafe_pair_asm
bool unsafe_pair_asm(const abstract_eventt &next, memory_modelt model, unsigned char met) const
Definition
abstract_event.cpp:101
abstract_eventt::unsafe_pair_lwfence_param
bool unsafe_pair_lwfence_param(const abstract_eventt &next, memory_modelt model, bool lwsync_met) const
Definition
abstract_event.cpp:16
abstract_eventt::RRcumul
bool RRcumul
Definition
abstract_event.h:47
abstract_eventt::is_direct
bool is_direct() const
Definition
abstract_event.h:195
abstract_eventt::variable
irep_idt variable
Definition
abstract_event.h:34
abstract_eventt::abstract_eventt
abstract_eventt(operationt _op, unsigned _th, irep_idt _var, unsigned _id, source_locationt _loc, irep_idt _function_id, bool _local, bool WRf, bool WWf, bool RRf, bool RWf, bool WWc, bool RWc, bool RRc)
Definition
abstract_event.h:82
abstract_eventt::operator<
bool operator<(const abstract_eventt &other) const
Definition
abstract_event.h:131
abstract_eventt::operation
operationt operation
Definition
abstract_event.h:32
abstract_eventt::abstract_eventt
abstract_eventt()
Definition
abstract_event.h:49
abstract_eventt::abstract_eventt
abstract_eventt(operationt _op, unsigned _th, irep_idt _var, unsigned _id, source_locationt _loc, irep_idt _function_id, bool _local)
Definition
abstract_event.h:64
abstract_eventt::local
bool local
Definition
abstract_event.h:38
abstract_eventt::fence_value
unsigned char fence_value() const
Definition
abstract_event.h:198
abstract_eventt::RRfence
bool RRfence
Definition
abstract_event.h:43
abstract_eventt::operator==
bool operator==(const abstract_eventt &other) const
Definition
abstract_event.h:126
abstract_eventt::WWfence
bool WWfence
Definition
abstract_event.h:42
graph_nodet
This class represents a node in a directed graph.
Definition
graph.h:35
source_locationt
Definition
source_location.h:20
graph.h
A Template Class for Graphs.
source_location.h
UNREACHABLE
#define UNREACHABLE
This should be used to mark dead code.
Definition
invariant.h:525
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
wmm.h
memory models
memory_modelt
memory_modelt
Definition
wmm.h:18
goto-instrument
wmm
abstract_event.h
Generated by
1.17.0