34 #ifndef MC2LIB_MEMCONSISTENCY_CATS_HPP_ 35 #define MC2LIB_MEMCONSISTENCY_CATS_HPP_ 42 namespace memconsistency {
62 template <
class FilterFunc>
68 for (
const auto& rf_tuples :
rf.
get()) {
69 const auto co_reach =
co.
Reachable(rf_tuples.first);
70 for (
const auto& co_w : co_reach.get()) {
71 for (
const auto& rf_r : rf_tuples.second.get()) {
72 if (filter_func(std::make_pair(rf_tuples.first, rf_r),
73 std::make_pair(rf_tuples.first, co_w))) {
91 return t1.second.iiid.pid == t2.second.iiid.pid;
97 return t1.second.iiid.pid != t2.second.iiid.pid;
159 virtual std::unique_ptr<Checker> MakeChecker(
167 return ew.
rfe() | proxy_->ppo(ew) | proxy_->fences(ew);
181 assert(proxy !=
nullptr);
189 template <
class ConcreteArch>
194 memoized_ppo_(false),
195 memoized_fences_(false),
196 memoized_prop_(false),
197 memoized_hb_(false) {
198 arch_->set_proxy(
this);
205 memoized_ppo_ =
false;
206 memoized_fences_ =
false;
207 memoized_prop_ =
false;
208 memoized_hb_ =
false;
213 return arch_->MakeChecker(arch, exec);
217 return MakeChecker(
this, exec);
222 fences_ = arch_->fences(ew);
223 memoized_fences_ =
true;
225 ppo_ = arch_->ppo(ew);
226 memoized_ppo_ =
true;
231 prop_ = arch_->prop(ew);
232 memoized_prop_ =
true;
236 return memoized_ppo_ ? ppo_ : arch_->ppo(ew);
240 return memoized_fences_ ? fences_ : arch_->fences(ew);
244 return memoized_prop_ ? prop_ : arch_->prop(ew);
248 return memoized_hb_ ? hb_ : arch_->hb(ew);
254 return arch_->EventTypeWrite();
274 : arch_(arch), exec_(exec) {}
281 for (
const auto& tuples : exec_->rf.get()) {
282 if (!tuples.first.AnyType(arch_->EventTypeWrite())) {
283 throw Error(
"WF_RF_NOT_FROM_WRITE");
286 for (
const auto& e : tuples.second.get()) {
287 if (!e.AnyType(arch_->EventTypeRead()) || tuples.first.addr != e.addr) {
288 throw Error(
"WF_RF_NOT_SAME_LOC");
293 throw Error(
"WF_RF_MULTI_SOURCE");
301 std::unordered_set<types::Addr> addrs;
304 for (
const auto& tuples : exec_->co.get()) {
305 addrs.insert(tuples.first.addr);
307 for (
const auto& e : tuples.second.get()) {
308 if (tuples.first.addr != e.addr) {
309 throw Error(
"WF_CO_NOT_SAME_LOC");
314 auto writes = exec_->events.Filter(
315 [&](
const Event& e) {
return e.
AnyType(arch_->EventTypeWrite()); });
316 if (!exec_->co.StrictPartialOrder(writes)) {
317 throw Error(
"WF_CO_NOT_STRICT_PARTIAL_ORDER");
320 for (
const auto& addr : addrs) {
321 auto same_addr_writes =
322 writes.Filter([&](
const Event& e) {
return e.
addr == addr; });
323 if (!exec_->co.ConnexOn(same_addr_writes)) {
324 throw Error(
"WF_CO_NOT_CONNEX");
329 virtual void wf()
const {
335 return (exec_->com() | exec_->po_loc()).Acyclic(cyclic);
339 return arch_->hb(*exec_).Acyclic(cyclic);
343 const EventRel prop = arch_->prop(*exec_);
350 bool r =
EventRelSeq({exec_->fre(), prop, hbstar.
Eval()}).Irreflexive();
352 if (!r && cyclic !=
nullptr) {
355 EventRelSeq({exec_->fre(), prop, hbstar}).Irreflexive(cyclic);
362 return (exec_->co | arch_->prop(*exec_)).Acyclic(cyclic);
368 if (!sc_per_location(cyclic)) {
369 throw Error(
"SC_PER_LOCATION");
372 if (!no_thin_air(cyclic)) {
373 throw Error(
"NO_THIN_AIR");
376 if (!observation(cyclic)) {
377 throw Error(
"OBSERVATION");
380 if (!propagation(cyclic)) {
381 throw Error(
"PROPAGATION");
400 return std::unique_ptr<Checker>(
new Checker(arch, exec));
411 return proxy_->ppo(ew) | proxy_->fences(ew) | ew.
rf | ew.
fr();
421 void Clear()
override { mfence.Clear(); }
425 return std::unique_ptr<Checker>(
new Checker(arch, exec));
436 if (mfence.empty()) {
450 return EventRelSeq({postar, mfence, postar}).EvalClear();
454 return proxy_->ppo(ew) | proxy_->fences(ew) | ew.
rfe() | ew.
fr();
483 return std::unique_ptr<Checker>(
new Checker(arch, exec));
488 assert(dd_reg.SubsetEq(ew.
po));
494 [&addr, &data, &ctrl_part,
this](
const Event& e1,
const Event& e2) {
495 if (!e1.
AnyType(EventTypeRead())) {
510 ctrl_part.Insert(e1, e2);
520 const auto rfe = ew.
rfe();
535 std::size_t prev_total_size;
539 prev_total_size = total_size;
550 ic |= ii | cc |
EventRelSeq({ic, cc}).EvalClear() |
554 assert(prev_total_size <= total_size);
555 }
while (total_size != prev_total_size);
558 return e1.
AnyType(EventTypeRead()) && e2.
AnyType(EventTypeWrite());
561 return e1.
AnyType(EventTypeRead()) && e2.
AnyType(EventTypeRead());
570 const auto postar_WW = postar.
Filter([&](
const Event& e1,
const Event& e2) {
574 auto ff =
EventRelSeq({postar, (dmb | dsb), postar}).EvalClear();
575 ff |=
EventRelSeq({postar_WW, (dmb_st | dsb_st), postar_WW}).EvalClear();
585 EventRelSeq({(proxy_->fences(ew) | A_cumul), hbstar}).EvalClear();
590 return e1.
AnyType(EventTypeWrite()) && e2.
AnyType(EventTypeWrite());
595 EventRelSeq({comstar, propbase , proxy_->fences(ew), hbstar})
Definition: eventsets.hpp:227
EventRel ppo_
Definition: cats.hpp:265
void set_proxy(const Architecture *proxy)
Definition: cats.hpp:180
bool AllType(Type type_mask) const
Definition: eventsets.hpp:209
std::unique_ptr< Checker > MakeChecker(const Architecture *arch, const ExecWitness *exec) const override
Definition: cats.hpp:211
EventRel rfe() const
Definition: cats.hpp:107
EventRel ppo(const ExecWitness &ew) const override
Definition: cats.hpp:235
bool AnyType(Type type_mask) const
Definition: eventsets.hpp:213
bool Transitive() const
Definition: sets.hpp:693
EventRel fences(const ExecWitness &ew) const override
Definition: cats.hpp:239
Set< Ts > Reachable(const Element &e) const
Definition: sets.hpp:656
virtual void valid_exec(EventRel::Path *cyclic=nullptr) const
Definition: cats.hpp:365
Event::Type EventTypeRead() const override
Definition: cats.hpp:414
bool memoized_hb_
Definition: cats.hpp:263
~ArchProxy() override
Definition: cats.hpp:201
EventRel ppo(const ExecWitness &ew) const override
Definition: cats.hpp:486
void Clear() override
Definition: cats.hpp:203
EventRel dmb_st
Definition: cats.hpp:609
EventRel coe() const
Definition: cats.hpp:119
EventRel mfence
Definition: cats.hpp:462
EventRel prop(const ExecWitness &ew) const override
Definition: cats.hpp:579
Event::Type EventTypeRead() const override
Definition: cats.hpp:600
EventRel po_loc() const
Definition: cats.hpp:127
EventRel prop(const ExecWitness &ew) const override
Definition: cats.hpp:410
virtual ~Architecture()
Definition: cats.hpp:152
const Architecture * proxy_
Definition: cats.hpp:186
EventRel po
Definition: cats.hpp:141
EventRel fr() const
Definition: cats.hpp:83
EventRel fences(const ExecWitness &ew) const override
Definition: cats.hpp:435
const Element & Insert(const Element &e, bool assert_unique=false)
Definition: sets.hpp:112
Event::Type EventTypeWrite() const override
Definition: cats.hpp:416
std::uint32_t Type
Definition: eventsets.hpp:111
Iiid iiid
Definition: eventsets.hpp:220
std::vector< Element > Path
Definition: sets.hpp:327
virtual ~Checker()
Definition: cats.hpp:276
EventRel dsb_st
Definition: cats.hpp:608
std::pair< Element, Element > Tuple
Definition: sets.hpp:325
virtual bool sc_per_location(EventRel::Path *cyclic=nullptr) const
Definition: cats.hpp:334
const ExecWitness * exec_
Definition: cats.hpp:387
virtual bool propagation(EventRel::Path *cyclic=nullptr) const
Definition: cats.hpp:361
EventRel isb
Definition: cats.hpp:610
void Clear()
Definition: cats.hpp:132
EventRel fences(const ExecWitness &ew) const override
Definition: cats.hpp:408
Event::Type EventTypeWrite() const override
Definition: cats.hpp:602
Definition: eventsets.hpp:103
virtual void wf_rf() const
Definition: cats.hpp:278
sets::RelationSeq< sets::Types< Event > > EventRelSeq
Definition: eventsets.hpp:225
std::size_t size() const
Definition: sets.hpp:434
Func for_each(Func func) const
Definition: sets.hpp:457
Relation & EvalInplace()
Definition: sets.hpp:494
EventRel fri() const
Definition: cats.hpp:89
EventRel dmb
Definition: cats.hpp:607
static constexpr Properties kReflexiveClosure
Definition: sets.hpp:341
static constexpr Type kBranch
Definition: eventsets.hpp:128
void Clear()
Definition: sets.hpp:156
EventRel prop_
Definition: cats.hpp:267
bool Contains(const Element &e) const
Definition: sets.hpp:158
Relation Eval() const
Definition: sets.hpp:475
std::unique_ptr< Checker > MakeChecker(const ExecWitness *exec) const
Definition: cats.hpp:216
EventRel prop(const ExecWitness &ew) const override
Definition: cats.hpp:243
std::unique_ptr< Checker > MakeChecker(const Architecture *arch, const ExecWitness *exec) const override
Definition: cats.hpp:398
std::unique_ptr< Checker > MakeChecker(const Architecture *arch, const ExecWitness *exec) const override
Definition: cats.hpp:423
EventRel coi() const
Definition: cats.hpp:113
EventRel dsb
Definition: cats.hpp:606
EventSet events
Definition: cats.hpp:140
static constexpr Type kMemoryOperation
Definition: eventsets.hpp:122
virtual void wf_co() const
Definition: cats.hpp:300
const Container & get() const
Definition: sets.hpp:355
Arch_ARMv7()
Definition: cats.hpp:470
EventRel fences_
Definition: cats.hpp:266
Event::Type EventTypeRead() const override
Definition: cats.hpp:251
EventRel fre() const
Definition: cats.hpp:95
sets::Relation< sets::Types< Event > > EventRel
Definition: eventsets.hpp:224
static constexpr Type kRegInAddr
Definition: eventsets.hpp:125
EventRel rfi() const
Definition: cats.hpp:101
EventRel dd_reg
Definition: cats.hpp:605
Event::Type EventTypeRead() const override
Definition: cats.hpp:457
static constexpr Properties kReflexiveTransitiveClosure
Definition: sets.hpp:342
EventRel ppo(const ExecWitness &ew) const override
Definition: cats.hpp:428
bool memoized_ppo_
Definition: cats.hpp:260
EventRel prop(const ExecWitness &ew) const override
Definition: cats.hpp:453
types::Addr addr
Definition: eventsets.hpp:218
EventRel rf
Definition: cats.hpp:143
void Clear() override
Definition: cats.hpp:472
Relation Filter(FilterFunc filterFunc) const
Definition: sets.hpp:511
void Memoize(const ExecWitness &ew)
Definition: cats.hpp:220
void Insert(const Element &e1, const Element &e2, bool assert_unique=false)
Definition: sets.hpp:384
EventRel ppo(const ExecWitness &ew) const override
Definition: cats.hpp:403
static constexpr Type kRead
Definition: eventsets.hpp:118
ArchProxy(ConcreteArch *arch)
Definition: cats.hpp:192
bool memoized_fences_
Definition: cats.hpp:261
EventRel co
Definition: cats.hpp:142
void Clear() override
Definition: cats.hpp:421
static constexpr Type kWrite
Definition: eventsets.hpp:119
Architecture()
Definition: cats.hpp:150
bool memoized_prop_
Definition: cats.hpp:262
EventRel fences(const ExecWitness &ew) const override
Definition: cats.hpp:568
EventRel hb(const ExecWitness &ew) const override
Definition: cats.hpp:247
types::Pid pid
Definition: eventsets.hpp:99
EventRel hb_
Definition: cats.hpp:268
ConcreteArch * arch_
Definition: cats.hpp:258
static constexpr Properties kTransitiveClosure
Definition: sets.hpp:340
virtual void wf() const
Definition: cats.hpp:329
virtual EventRel hb(const ExecWitness &ew) const
Definition: cats.hpp:166
Checker(const Architecture *arch, const ExecWitness *exec)
Definition: cats.hpp:273
Event::Type EventTypeWrite() const override
Definition: cats.hpp:253
const Architecture * arch_
Definition: cats.hpp:386
EventRel fr(FilterFunc filter_func) const
Definition: cats.hpp:63
static constexpr Type kRegInData
Definition: eventsets.hpp:126
std::unique_ptr< Checker > MakeChecker(const Architecture *arch, const ExecWitness *exec) const override
Definition: cats.hpp:481
virtual bool no_thin_air(EventRel::Path *cyclic=nullptr) const
Definition: cats.hpp:338
EventRel com() const
Definition: cats.hpp:125
Event::Type EventTypeWrite() const override
Definition: cats.hpp:459
virtual void Clear()
Definition: cats.hpp:154
void Clear()
Definition: sets.hpp:596
virtual bool observation(EventRel::Path *cyclic=nullptr) const
Definition: cats.hpp:342
Relation & set_props(Properties props)
Definition: sets.hpp:359