@@ -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
// TODO GENMC: could directly return std::optional if CXX ever supports this
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 ****/
@@ -218,32 +225,33 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
218
225
/* *** Memory access handling ****/
219
226
220
227
[[nodiscard]] auto MiriGenMCShim::handleLoad (ThreadId thread_id, uint64_t address, uint64_t size,
221
- MemOrdering ord, GenmcScalar old_val) -> LoadResult
228
+ MemOrdering ord, GenmcScalar old_val) -> LoadResult
222
229
{
223
230
auto pos = incPos (thread_id);
224
231
MIRI_LOG () << " Received Load from Miri at address: " << address << " , size " << size
225
- << " with ordering " << ord << " , event: " << pos << " \n " ;
232
+ << " with ordering " << ord << " , event: " << pos << " \n " ;
226
233
227
234
auto loc = SAddr (address);
228
235
auto aSize = ASize (size);
229
236
auto type = AType::Unsigned; // FIXME(genmc): get correct type from Miri(?)
230
237
231
238
auto newLab = std::make_unique<ReadLabel>(pos, ord, loc, aSize, type);
232
239
233
- auto oldValSetter = [this , old_val](SAddr loc) { this ->handleOldVal (loc, old_val); };
240
+ auto oldValSetter = [this , old_val](SAddr loc)
241
+ { this ->handleOldVal (loc, old_val); };
234
242
auto result = GenMCDriver::handleLoad (std::move (newLab), oldValSetter);
235
243
return result;
236
244
}
237
245
238
246
[[nodiscard]] auto MiriGenMCShim::handleReadModifyWrite (ThreadId thread_id, uint64_t address,
239
- uint64_t size, MemOrdering loadOrd,
240
- MemOrdering store_ordering, RMWBinOp rmw_op,
241
- GenmcScalar rhs_value, GenmcScalar old_val)
247
+ uint64_t size, MemOrdering loadOrd,
248
+ MemOrdering store_ordering, RMWBinOp rmw_op,
249
+ GenmcScalar rhs_value, GenmcScalar old_val)
242
250
-> ReadModifyWriteResult
243
251
{
244
252
MIRI_LOG () << " Received Read-Modify-Write from Miri at address: " << address << " , size "
245
- << size << " with orderings (" << loadOrd << " , " << store_ordering
246
- << " ), rmw op: " << static_cast <uint64_t >(rmw_op) << " \n " ;
253
+ << size << " with orderings (" << loadOrd << " , " << store_ordering
254
+ << " ), rmw op: " << static_cast <uint64_t >(rmw_op) << " \n " ;
247
255
248
256
auto pos = incPos (thread_id);
249
257
@@ -255,17 +263,19 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
255
263
auto newLab =
256
264
std::make_unique<FaiReadLabel>(pos, loadOrd, loc, aSize, type, rmw_op, rhsVal);
257
265
258
- auto oldValSetter = [this , old_val](SAddr loc) { this ->handleOldVal (loc, old_val); };
266
+ auto oldValSetter = [this , old_val](SAddr loc)
267
+ { this ->handleOldVal (loc, old_val); };
259
268
auto result = GenMCDriver::handleLoad (std::move (newLab), oldValSetter);
260
- if (const auto *error = result.error .get ()) {
269
+ if (const auto *error = result.error .get ())
270
+ {
261
271
return ReadModifyWriteResult::fromError (*error);
262
272
}
263
273
264
274
auto oldVal = result.scalar .toSVal (); // TODO GENMC: u128 handling
265
275
auto newVal = executeRMWBinOp (oldVal, rhsVal, size, rmw_op);
266
276
267
277
auto store_result = handleStore (thread_id, address, size, GenmcScalar (newVal), old_val,
268
- store_ordering, StoreEventType::ReadModifyWrite);
278
+ store_ordering, StoreEventType::ReadModifyWrite);
269
279
270
280
if (store_result.is_error ())
271
281
return ReadModifyWriteResult::fromError (*store_result.error .get ());
@@ -280,11 +290,11 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
280
290
{
281
291
282
292
MIRI_LOG () << " Received Compare-Exchange from Miri (value: " << expected_value << " --> "
283
- << new_value << " , old value: " << old_val << " ) at address: " << address
284
- << " , size " << size << " with success orderings (" << success_load_ordering
285
- << " , " << success_store_ordering
286
- << " ), fail load ordering: " << fail_load_ordering
287
- << " , is weak (can fail spuriously): " << can_fail_spuriously << " \n " ;
293
+ << new_value << " , old value: " << old_val << " ) at address: " << address
294
+ << " , size " << size << " with success orderings (" << success_load_ordering
295
+ << " , " << success_store_ordering
296
+ << " ), fail load ordering: " << fail_load_ordering
297
+ << " , is weak (can fail spuriously): " << can_fail_spuriously << " \n " ;
288
298
289
299
auto pos = incPos (thread_id);
290
300
@@ -298,11 +308,13 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
298
308
// FIXME(GenMC): properly handle failure memory ordering.
299
309
300
310
auto newLab = std::make_unique<CasReadLabel>(pos, success_load_ordering, loc, aSize, type,
301
- expectedVal, newVal);
311
+ expectedVal, newVal);
302
312
303
- auto oldValSetter = [this , old_val](SAddr loc) { this ->handleOldVal (loc, old_val); };
313
+ auto oldValSetter = [this , old_val](SAddr loc)
314
+ { this ->handleOldVal (loc, old_val); };
304
315
auto result = GenMCDriver::handleLoad (std::move (newLab), oldValSetter);
305
- if (const auto *error = result.error .get ()) {
316
+ if (const auto *error = result.error .get ())
317
+ {
306
318
return CompareExchangeResult::fromError (*error);
307
319
}
308
320
@@ -311,21 +323,21 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
311
323
return CompareExchangeResult::failure (oldVal);
312
324
313
325
auto store_result = handleStore (thread_id, address, size, GenmcScalar (newVal), old_val,
314
- success_store_ordering, StoreEventType::CompareExchange);
326
+ success_store_ordering, StoreEventType::CompareExchange);
315
327
316
328
if (store_result.is_error ())
317
329
return CompareExchangeResult::fromError (*store_result.error );
318
330
return CompareExchangeResult::success (oldVal, store_result.isCoMaxWrite );
319
331
}
320
332
321
333
[[nodiscard]] auto MiriGenMCShim::handleStore (ThreadId thread_id, uint64_t address, uint64_t size,
322
- GenmcScalar value, GenmcScalar old_val,
323
- MemOrdering ord, StoreEventType store_event_type)
334
+ GenmcScalar value, GenmcScalar old_val,
335
+ MemOrdering ord, StoreEventType store_event_type)
324
336
-> StoreResult
325
337
{
326
338
MIRI_LOG () << " Received Store from Miri at address " << address << " , size " << size
327
- << " with ordering " << ord << " , is part of rmw: ("
328
- << static_cast <uint64_t >(store_event_type) << " )\n " ;
339
+ << " with ordering " << ord << " , is part of rmw: ("
340
+ << static_cast <uint64_t >(store_event_type) << " )\n " ;
329
341
330
342
auto pos = incPos (thread_id);
331
343
@@ -337,7 +349,8 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
337
349
auto val = value.toSVal ();
338
350
339
351
std::unique_ptr<WriteLabel> wLab;
340
- switch (store_event_type) {
352
+ switch (store_event_type)
353
+ {
341
354
case StoreEventType::Normal:
342
355
wLab = std::make_unique<WriteLabel>(pos, ord, loc, aSize, type, val);
343
356
break ;
@@ -351,9 +364,10 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
351
364
ERROR (" Unsupported Store Event Type" );
352
365
}
353
366
354
- auto oldValSetter = [this , old_val](SAddr loc) {
367
+ auto oldValSetter = [this , old_val](SAddr loc)
368
+ {
355
369
this ->handleOldVal (loc,
356
- old_val); // TODO GENMC(HACK): is this the correct way to do it?
370
+ old_val); // TODO GENMC(HACK): is this the correct way to do it?
357
371
};
358
372
359
373
return GenMCDriver::handleStore (std::move (wLab), oldValSetter);
0 commit comments