@@ -31,14 +31,15 @@ using AnnotT = SExpr<AnnotID>;
31
31
// NOTE: this is safe because ThreadId is 32 bit, and we return a 64 bit integer
32
32
// FIXME(genmc,cxx): could directly return std::optional if CXX ever supports sharing it (see https://github.com/dtolnay/cxx/issues/87).
33
33
auto MiriGenMCShim::scheduleNext (const int curr_thread_id,
34
- const ActionKind curr_thread_next_instr_kind) -> int64_t
34
+ const ActionKind curr_thread_next_instr_kind) -> int64_t
35
35
{
36
36
// The current thread is the only one where the `kind` could have changed since we last made
37
37
// a scheduling decision.
38
38
globalInstructions[curr_thread_id].kind = curr_thread_next_instr_kind;
39
39
40
40
auto result = GenMCDriver::scheduleNext (globalInstructions);
41
- if (result.has_value ()) {
41
+ if (result.has_value ())
42
+ {
42
43
return static_cast <int64_t >(result.value ());
43
44
}
44
45
return -1 ;
@@ -47,7 +48,7 @@ auto MiriGenMCShim::scheduleNext(const int curr_thread_id,
47
48
/* *** Functions available to Miri ****/
48
49
49
50
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
50
- auto MiriGenMCShim::createHandle (const GenmcParams &config, bool estimation_mode )
51
+ auto MiriGenMCShim::createHandle (const GenmcParams &config)
51
52
-> std::unique_ptr<MiriGenMCShim>
52
53
{
53
54
auto conf = std::make_shared<Config>();
@@ -70,14 +71,19 @@ auto MiriGenMCShim::createHandle(const GenmcParams &config, bool estimation_mode
70
71
// FIXME(genmc): expose this setting to Miri
71
72
conf->randomScheduleSeed = " 42" ;
72
73
conf->printRandomScheduleSeed = config.print_random_schedule_seed ;
73
- if (config.quiet ) {
74
+ if (config.quiet )
75
+ {
74
76
// logLevel = VerbosityLevel::Quiet;
75
77
// TODO GENMC: error might be better (or new level for `BUG`)
76
78
// logLevel = VerbosityLevel::Quiet;
77
79
logLevel = VerbosityLevel::Error;
78
- } else if (config.log_level_trace ) {
80
+ }
81
+ else if (config.log_level_trace )
82
+ {
79
83
logLevel = VerbosityLevel::Trace;
80
- } else {
84
+ }
85
+ else
86
+ {
81
87
logLevel = VerbosityLevel::Tip;
82
88
}
83
89
@@ -96,10 +102,8 @@ auto MiriGenMCShim::createHandle(const GenmcParams &config, bool estimation_mode
96
102
// FIXME(genmc): expose this setting to Miri (useful for testing Miri-GenMC).
97
103
conf->schedulePolicy = SchedulePolicy::WF;
98
104
99
- conf->estimate = estimation_mode;
100
- conf->estimationMax = config.estimation_max ;
101
- const auto mode = conf->estimate ? GenMCDriver::Mode (GenMCDriver::EstimationMode{})
102
- : GenMCDriver::Mode (GenMCDriver::VerificationMode{});
105
+ conf->estimate = false ;
106
+ const auto mode = GenMCDriver::Mode (GenMCDriver::VerificationMode{});
103
107
104
108
// Running Miri-GenMC without race detection is not supported.
105
109
// Disabling this option also changes the behavior of the replay scheduler to only schedule
@@ -118,22 +122,25 @@ auto MiriGenMCShim::createHandle(const GenmcParams &config, bool estimation_mode
118
122
auto driver = std::make_unique<MiriGenMCShim>(std::move (conf), mode);
119
123
120
124
auto *driverPtr = driver.get ();
121
- auto initValGetter = [driverPtr](const AAccess &access) {
125
+ auto initValGetter = [driverPtr](const AAccess &access)
126
+ {
122
127
const auto addr = access.getAddr ();
123
- if (!driverPtr->initVals_ .contains (addr)) {
128
+ if (!driverPtr->initVals_ .contains (addr))
129
+ {
124
130
MIRI_LOG () << " WARNING: TODO GENMC: requested initial value for address "
125
- << addr << " , but there is none.\n " ;
131
+ << addr << " , but there is none.\n " ;
126
132
return SVal (0xCC00CC00 );
127
133
// BUG_ON(!driverPtr->initVals_.contains(addr));
128
134
}
129
135
auto result = driverPtr->initVals_ [addr];
130
- if (!result.is_init ) {
136
+ if (!result.is_init )
137
+ {
131
138
MIRI_LOG () << " WARNING: TODO GENMC: requested initial value for address "
132
- << addr << " , but the memory is uninitialized.\n " ;
139
+ << addr << " , but the memory is uninitialized.\n " ;
133
140
return SVal (0xFF00FF00 );
134
141
}
135
142
MIRI_LOG () << " MiriGenMCShim: requested initial value for address " << addr
136
- << " == " << addr.get () << " , returning: " << result << " \n " ;
143
+ << " == " << addr.get () << " , returning: " << result << " \n " ;
137
144
return result.toSVal ();
138
145
};
139
146
driver->getExec ().getGraph ().setInitValGetter (initValGetter);
@@ -143,10 +150,10 @@ auto MiriGenMCShim::createHandle(const GenmcParams &config, bool estimation_mode
143
150
144
151
// This needs to be available to Miri, but clang-tidy wants it static
145
152
// NOLINTNEXTLINE(misc-use-internal-linkage)
146
- auto createGenmcHandle (const GenmcParams &config, bool estimation_mode )
153
+ auto createGenmcHandle (const GenmcParams &config)
147
154
-> std::unique_ptr<MiriGenMCShim>
148
155
{
149
- return MiriGenMCShim::createHandle (config, estimation_mode );
156
+ return MiriGenMCShim::createHandle (config);
150
157
}
151
158
152
159
/* *** Execution start/end handling ****/
@@ -222,11 +229,11 @@ void MiriGenMCShim::handleThreadKill(ThreadId thread_id) {
222
229
/* *** Memory access handling ****/
223
230
224
231
[[nodiscard]] auto MiriGenMCShim::handleLoad (ThreadId thread_id, uint64_t address, uint64_t size,
225
- MemOrdering ord, GenmcScalar old_val) -> LoadResult
232
+ MemOrdering ord, GenmcScalar old_val) -> LoadResult
226
233
{
227
234
auto pos = incPos (thread_id);
228
235
MIRI_LOG () << " Received Load from Miri at address: " << address << " , size " << size
229
- << " with ordering " << ord << " , event: " << pos << " \n " ;
236
+ << " with ordering " << ord << " , event: " << pos << " \n " ;
230
237
231
238
auto loc = SAddr (address);
232
239
auto aSize = ASize (size);
@@ -235,20 +242,21 @@ void MiriGenMCShim::handleThreadKill(ThreadId thread_id) {
235
242
236
243
auto newLab = std::make_unique<ReadLabel>(pos, ord, loc, aSize, type);
237
244
238
- auto oldValSetter = [this , old_val](SAddr loc) { this ->handleOldVal (loc, old_val); };
245
+ auto oldValSetter = [this , old_val](SAddr loc)
246
+ { this ->handleOldVal (loc, old_val); };
239
247
auto result = GenMCDriver::handleLoad (std::move (newLab), oldValSetter);
240
248
return result;
241
249
}
242
250
243
251
[[nodiscard]] auto MiriGenMCShim::handleReadModifyWrite (ThreadId thread_id, uint64_t address,
244
- uint64_t size, MemOrdering loadOrd,
245
- MemOrdering store_ordering, RMWBinOp rmw_op,
246
- GenmcScalar rhs_value, GenmcScalar old_val)
252
+ uint64_t size, MemOrdering loadOrd,
253
+ MemOrdering store_ordering, RMWBinOp rmw_op,
254
+ GenmcScalar rhs_value, GenmcScalar old_val)
247
255
-> ReadModifyWriteResult
248
256
{
249
257
MIRI_LOG () << " Received Read-Modify-Write from Miri at address: " << address << " , size "
250
- << size << " with orderings (" << loadOrd << " , " << store_ordering
251
- << " ), rmw op: " << static_cast <uint64_t >(rmw_op) << " \n " ;
258
+ << size << " with orderings (" << loadOrd << " , " << store_ordering
259
+ << " ), rmw op: " << static_cast <uint64_t >(rmw_op) << " \n " ;
252
260
253
261
auto pos = incPos (thread_id);
254
262
@@ -261,17 +269,19 @@ void MiriGenMCShim::handleThreadKill(ThreadId thread_id) {
261
269
auto newLab =
262
270
std::make_unique<FaiReadLabel>(pos, loadOrd, loc, aSize, type, rmw_op, rhsVal);
263
271
264
- auto oldValSetter = [this , old_val](SAddr loc) { this ->handleOldVal (loc, old_val); };
272
+ auto oldValSetter = [this , old_val](SAddr loc)
273
+ { this ->handleOldVal (loc, old_val); };
265
274
auto result = GenMCDriver::handleLoad (std::move (newLab), oldValSetter);
266
- if (const auto *error = result.error .get ()) {
275
+ if (const auto *error = result.error .get ())
276
+ {
267
277
return ReadModifyWriteResult::fromError (*error);
268
278
}
269
279
270
280
auto oldVal = result.scalar .toSVal (); // TODO GENMC: u128 handling
271
281
auto newVal = executeRMWBinOp (oldVal, rhsVal, size, rmw_op);
272
282
273
283
auto store_result = handleStore (thread_id, address, size, GenmcScalar (newVal), old_val,
274
- store_ordering, StoreEventType::ReadModifyWrite);
284
+ store_ordering, StoreEventType::ReadModifyWrite);
275
285
276
286
if (store_result.is_error ())
277
287
return ReadModifyWriteResult::fromError (*store_result.error .get ());
@@ -286,11 +296,11 @@ void MiriGenMCShim::handleThreadKill(ThreadId thread_id) {
286
296
{
287
297
288
298
MIRI_LOG () << " Received Compare-Exchange from Miri (value: " << expected_value << " --> "
289
- << new_value << " , old value: " << old_val << " ) at address: " << address
290
- << " , size " << size << " with success orderings (" << success_load_ordering
291
- << " , " << success_store_ordering
292
- << " ), fail load ordering: " << fail_load_ordering
293
- << " , is weak (can fail spuriously): " << can_fail_spuriously << " \n " ;
299
+ << new_value << " , old value: " << old_val << " ) at address: " << address
300
+ << " , size " << size << " with success orderings (" << success_load_ordering
301
+ << " , " << success_store_ordering
302
+ << " ), fail load ordering: " << fail_load_ordering
303
+ << " , is weak (can fail spuriously): " << can_fail_spuriously << " \n " ;
294
304
295
305
auto pos = incPos (thread_id);
296
306
@@ -305,11 +315,13 @@ void MiriGenMCShim::handleThreadKill(ThreadId thread_id) {
305
315
// FIXME(GenMC): properly handle failure memory ordering.
306
316
307
317
auto newLab = std::make_unique<CasReadLabel>(pos, success_load_ordering, loc, aSize, type,
308
- expectedVal, newVal);
318
+ expectedVal, newVal);
309
319
310
- auto oldValSetter = [this , old_val](SAddr loc) { this ->handleOldVal (loc, old_val); };
320
+ auto oldValSetter = [this , old_val](SAddr loc)
321
+ { this ->handleOldVal (loc, old_val); };
311
322
auto result = GenMCDriver::handleLoad (std::move (newLab), oldValSetter);
312
- if (const auto *error = result.error .get ()) {
323
+ if (const auto *error = result.error .get ())
324
+ {
313
325
return CompareExchangeResult::fromError (*error);
314
326
}
315
327
@@ -318,21 +330,21 @@ void MiriGenMCShim::handleThreadKill(ThreadId thread_id) {
318
330
return CompareExchangeResult::failure (oldVal);
319
331
320
332
auto store_result = handleStore (thread_id, address, size, GenmcScalar (newVal), old_val,
321
- success_store_ordering, StoreEventType::CompareExchange);
333
+ success_store_ordering, StoreEventType::CompareExchange);
322
334
323
335
if (store_result.is_error ())
324
336
return CompareExchangeResult::fromError (*store_result.error );
325
337
return CompareExchangeResult::success (oldVal, store_result.isCoMaxWrite );
326
338
}
327
339
328
340
[[nodiscard]] auto MiriGenMCShim::handleStore (ThreadId thread_id, uint64_t address, uint64_t size,
329
- GenmcScalar value, GenmcScalar old_val,
330
- MemOrdering ord, StoreEventType store_event_type)
341
+ GenmcScalar value, GenmcScalar old_val,
342
+ MemOrdering ord, StoreEventType store_event_type)
331
343
-> StoreResult
332
344
{
333
345
MIRI_LOG () << " Received Store from Miri at address " << address << " , size " << size
334
- << " with ordering " << ord << " , is part of rmw: ("
335
- << static_cast <uint64_t >(store_event_type) << " )\n " ;
346
+ << " with ordering " << ord << " , is part of rmw: ("
347
+ << static_cast <uint64_t >(store_event_type) << " )\n " ;
336
348
337
349
auto pos = incPos (thread_id);
338
350
@@ -344,7 +356,8 @@ void MiriGenMCShim::handleThreadKill(ThreadId thread_id) {
344
356
auto val = value.toSVal ();
345
357
346
358
std::unique_ptr<WriteLabel> wLab;
347
- switch (store_event_type) {
359
+ switch (store_event_type)
360
+ {
348
361
case StoreEventType::Normal:
349
362
wLab = std::make_unique<WriteLabel>(pos, ord, loc, aSize, type, val);
350
363
break ;
@@ -358,9 +371,10 @@ void MiriGenMCShim::handleThreadKill(ThreadId thread_id) {
358
371
ERROR (" Unsupported Store Event Type" );
359
372
}
360
373
361
- auto oldValSetter = [this , old_val](SAddr loc) {
374
+ auto oldValSetter = [this , old_val](SAddr loc)
375
+ {
362
376
this ->handleOldVal (loc,
363
- old_val); // TODO GENMC(HACK): is this the correct way to do it?
377
+ old_val); // TODO GENMC(HACK): is this the correct way to do it?
364
378
};
365
379
366
380
return GenMCDriver::handleStore (std::move (wLab), oldValSetter);
0 commit comments