@@ -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>();
@@ -71,14 +72,19 @@ auto MiriGenMCShim::createHandle(const GenmcParams &config, bool estimation_mode
71
72
conf->randomScheduleSeed =
72
73
" 42" ; // TODO GENMC: only for random exploration/scheduling mode in GenMC
73
74
conf->printRandomScheduleSeed = config.print_random_schedule_seed ;
74
- if (config.quiet ) {
75
+ if (config.quiet )
76
+ {
75
77
// logLevel = VerbosityLevel::Quiet;
76
78
// TODO GENMC: error might be better (or new level for `BUG`)
77
79
// logLevel = VerbosityLevel::Quiet;
78
80
logLevel = VerbosityLevel::Error;
79
- } else if (config.log_level_trace ) {
81
+ }
82
+ else if (config.log_level_trace )
83
+ {
80
84
logLevel = VerbosityLevel::Trace;
81
- } else {
85
+ }
86
+ else
87
+ {
82
88
logLevel = VerbosityLevel::Tip;
83
89
}
84
90
@@ -97,10 +103,8 @@ auto MiriGenMCShim::createHandle(const GenmcParams &config, bool estimation_mode
97
103
// TODO GENMC: Should there be a way to change this option from Miri?
98
104
conf->schedulePolicy = SchedulePolicy::WF;
99
105
100
- conf->estimate = estimation_mode;
101
- conf->estimationMax = config.estimation_max ;
102
- const auto mode = conf->estimate ? GenMCDriver::Mode (GenMCDriver::EstimationMode{})
103
- : GenMCDriver::Mode (GenMCDriver::VerificationMode{});
106
+ conf->estimate = false ;
107
+ const auto mode = GenMCDriver::Mode (GenMCDriver::VerificationMode{});
104
108
105
109
// Running Miri-GenMC without race detection is not supported.
106
110
// Disabling this option also changes the behavior of the replay scheduler to only schedule
@@ -119,22 +123,25 @@ auto MiriGenMCShim::createHandle(const GenmcParams &config, bool estimation_mode
119
123
auto driver = std::make_unique<MiriGenMCShim>(std::move (conf), mode);
120
124
121
125
auto *driverPtr = driver.get ();
122
- auto initValGetter = [driverPtr](const AAccess &access) {
126
+ auto initValGetter = [driverPtr](const AAccess &access)
127
+ {
123
128
const auto addr = access.getAddr ();
124
- if (!driverPtr->initVals_ .contains (addr)) {
129
+ if (!driverPtr->initVals_ .contains (addr))
130
+ {
125
131
MIRI_LOG () << " WARNING: TODO GENMC: requested initial value for address "
126
- << addr << " , but there is none.\n " ;
132
+ << addr << " , but there is none.\n " ;
127
133
return SVal (0xCC00CC00 );
128
134
// BUG_ON(!driverPtr->initVals_.contains(addr));
129
135
}
130
136
auto result = driverPtr->initVals_ [addr];
131
- if (!result.is_init ) {
137
+ if (!result.is_init )
138
+ {
132
139
MIRI_LOG () << " WARNING: TODO GENMC: requested initial value for address "
133
- << addr << " , but the memory is uninitialized.\n " ;
140
+ << addr << " , but the memory is uninitialized.\n " ;
134
141
return SVal (0xFF00FF00 );
135
142
}
136
143
MIRI_LOG () << " MiriGenMCShim: requested initial value for address " << addr
137
- << " == " << addr.get () << " , returning: " << result << " \n " ;
144
+ << " == " << addr.get () << " , returning: " << result << " \n " ;
138
145
return result.toSVal ();
139
146
};
140
147
driver->getExec ().getGraph ().setInitValGetter (initValGetter);
@@ -144,10 +151,10 @@ auto MiriGenMCShim::createHandle(const GenmcParams &config, bool estimation_mode
144
151
145
152
// This needs to be available to Miri, but clang-tidy wants it static
146
153
// NOLINTNEXTLINE(misc-use-internal-linkage)
147
- auto createGenmcHandle (const GenmcParams &config, bool estimation_mode )
154
+ auto createGenmcHandle (const GenmcParams &config)
148
155
-> std::unique_ptr<MiriGenMCShim>
149
156
{
150
- return MiriGenMCShim::createHandle (config, estimation_mode );
157
+ return MiriGenMCShim::createHandle (config);
151
158
}
152
159
153
160
/* *** Execution start/end handling ****/
@@ -227,32 +234,33 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
227
234
/* *** Memory access handling ****/
228
235
229
236
[[nodiscard]] auto MiriGenMCShim::handleLoad (ThreadId thread_id, uint64_t address, uint64_t size,
230
- MemOrdering ord, GenmcScalar old_val) -> LoadResult
237
+ MemOrdering ord, GenmcScalar old_val) -> LoadResult
231
238
{
232
239
auto pos = incPos (thread_id);
233
240
MIRI_LOG () << " Received Load from Miri at address: " << address << " , size " << size
234
- << " with ordering " << ord << " , event: " << pos << " \n " ;
241
+ << " with ordering " << ord << " , event: " << pos << " \n " ;
235
242
236
243
auto loc = SAddr (address);
237
244
auto aSize = ASize (size);
238
245
auto type = AType::Unsigned; // TODO GENMC: get correct type from Miri
239
246
240
247
auto newLab = std::make_unique<ReadLabel>(pos, ord, loc, aSize, type);
241
248
242
- auto oldValSetter = [this , old_val](SAddr loc) { this ->handleOldVal (loc, old_val); };
249
+ auto oldValSetter = [this , old_val](SAddr loc)
250
+ { this ->handleOldVal (loc, old_val); };
243
251
auto result = GenMCDriver::handleLoad (std::move (newLab), oldValSetter);
244
252
return result;
245
253
}
246
254
247
255
[[nodiscard]] auto MiriGenMCShim::handleReadModifyWrite (ThreadId thread_id, uint64_t address,
248
- uint64_t size, MemOrdering loadOrd,
249
- MemOrdering store_ordering, RMWBinOp rmw_op,
250
- GenmcScalar rhs_value, GenmcScalar old_val)
256
+ uint64_t size, MemOrdering loadOrd,
257
+ MemOrdering store_ordering, RMWBinOp rmw_op,
258
+ GenmcScalar rhs_value, GenmcScalar old_val)
251
259
-> ReadModifyWriteResult
252
260
{
253
261
MIRI_LOG () << " Received Read-Modify-Write from Miri at address: " << address << " , size "
254
- << size << " with orderings (" << loadOrd << " , " << store_ordering
255
- << " ), rmw op: " << static_cast <uint64_t >(rmw_op) << " \n " ;
262
+ << size << " with orderings (" << loadOrd << " , " << store_ordering
263
+ << " ), rmw op: " << static_cast <uint64_t >(rmw_op) << " \n " ;
256
264
257
265
auto pos = incPos (thread_id);
258
266
@@ -264,17 +272,19 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
264
272
auto newLab =
265
273
std::make_unique<FaiReadLabel>(pos, loadOrd, loc, aSize, type, rmw_op, rhsVal);
266
274
267
- auto oldValSetter = [this , old_val](SAddr loc) { this ->handleOldVal (loc, old_val); };
275
+ auto oldValSetter = [this , old_val](SAddr loc)
276
+ { this ->handleOldVal (loc, old_val); };
268
277
auto result = GenMCDriver::handleLoad (std::move (newLab), oldValSetter);
269
- if (const auto *error = result.error .get ()) {
278
+ if (const auto *error = result.error .get ())
279
+ {
270
280
return ReadModifyWriteResult::fromError (*error);
271
281
}
272
282
273
283
auto oldVal = result.scalar .toSVal (); // TODO GENMC: u128 handling
274
284
auto newVal = executeRMWBinOp (oldVal, rhsVal, size, rmw_op);
275
285
276
286
auto store_result = handleStore (thread_id, address, size, GenmcScalar (newVal), old_val,
277
- store_ordering, StoreEventType::ReadModifyWrite);
287
+ store_ordering, StoreEventType::ReadModifyWrite);
278
288
279
289
if (store_result.is_error ())
280
290
return ReadModifyWriteResult::fromError (*store_result.error .get ());
@@ -289,11 +299,11 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
289
299
{
290
300
291
301
MIRI_LOG () << " Received Compare-Exchange from Miri (value: " << expected_value << " --> "
292
- << new_value << " , old value: " << old_val << " ) at address: " << address
293
- << " , size " << size << " with success orderings (" << success_load_ordering
294
- << " , " << success_store_ordering
295
- << " ), fail load ordering: " << fail_load_ordering
296
- << " , is weak (can fail spuriously): " << can_fail_spuriously << " \n " ;
302
+ << new_value << " , old value: " << old_val << " ) at address: " << address
303
+ << " , size " << size << " with success orderings (" << success_load_ordering
304
+ << " , " << success_store_ordering
305
+ << " ), fail load ordering: " << fail_load_ordering
306
+ << " , is weak (can fail spuriously): " << can_fail_spuriously << " \n " ;
297
307
298
308
auto pos = incPos (thread_id);
299
309
@@ -307,11 +317,13 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
307
317
// FIXME(GenMC): properly handle failure memory ordering.
308
318
309
319
auto newLab = std::make_unique<CasReadLabel>(pos, success_load_ordering, loc, aSize, type,
310
- expectedVal, newVal);
320
+ expectedVal, newVal);
311
321
312
- auto oldValSetter = [this , old_val](SAddr loc) { this ->handleOldVal (loc, old_val); };
322
+ auto oldValSetter = [this , old_val](SAddr loc)
323
+ { this ->handleOldVal (loc, old_val); };
313
324
auto result = GenMCDriver::handleLoad (std::move (newLab), oldValSetter);
314
- if (const auto *error = result.error .get ()) {
325
+ if (const auto *error = result.error .get ())
326
+ {
315
327
return CompareExchangeResult::fromError (*error);
316
328
}
317
329
@@ -320,21 +332,21 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
320
332
return CompareExchangeResult::failure (oldVal);
321
333
322
334
auto store_result = handleStore (thread_id, address, size, GenmcScalar (newVal), old_val,
323
- success_store_ordering, StoreEventType::CompareExchange);
335
+ success_store_ordering, StoreEventType::CompareExchange);
324
336
325
337
if (store_result.is_error ())
326
338
return CompareExchangeResult::fromError (*store_result.error );
327
339
return CompareExchangeResult::success (oldVal, store_result.isCoMaxWrite );
328
340
}
329
341
330
342
[[nodiscard]] auto MiriGenMCShim::handleStore (ThreadId thread_id, uint64_t address, uint64_t size,
331
- GenmcScalar value, GenmcScalar old_val,
332
- MemOrdering ord, StoreEventType store_event_type)
343
+ GenmcScalar value, GenmcScalar old_val,
344
+ MemOrdering ord, StoreEventType store_event_type)
333
345
-> StoreResult
334
346
{
335
347
MIRI_LOG () << " Received Store from Miri at address " << address << " , size " << size
336
- << " with ordering " << ord << " , is part of rmw: ("
337
- << static_cast <uint64_t >(store_event_type) << " )\n " ;
348
+ << " with ordering " << ord << " , is part of rmw: ("
349
+ << static_cast <uint64_t >(store_event_type) << " )\n " ;
338
350
339
351
auto pos = incPos (thread_id);
340
352
@@ -346,7 +358,8 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
346
358
auto val = value.toSVal ();
347
359
348
360
std::unique_ptr<WriteLabel> wLab;
349
- switch (store_event_type) {
361
+ switch (store_event_type)
362
+ {
350
363
case StoreEventType::Normal:
351
364
wLab = std::make_unique<WriteLabel>(pos, ord, loc, aSize, type, val);
352
365
break ;
@@ -360,9 +373,10 @@ void MiriGenMCShim::handleThreadFinish(ThreadId thread_id, uint64_t ret_val)
360
373
ERROR (" Unsupported Store Event Type" );
361
374
}
362
375
363
- auto oldValSetter = [this , old_val](SAddr loc) {
376
+ auto oldValSetter = [this , old_val](SAddr loc)
377
+ {
364
378
this ->handleOldVal (loc,
365
- old_val); // TODO GENMC(HACK): is this the correct way to do it?
379
+ old_val); // TODO GENMC(HACK): is this the correct way to do it?
366
380
};
367
381
368
382
return GenMCDriver::handleStore (std::move (wLab), oldValSetter);
@@ -386,7 +400,7 @@ auto MiriGenMCShim::handleMalloc(ThreadId thread_id, uint64_t size, uint64_t ali
386
400
387
401
auto sd = StorageDuration::SD_Heap; // TODO GENMC: get from Miri
388
402
auto stype = StorageType::ST_Durable; // TODO GENMC
389
- auto spc = AddressSpace::AS_User; // TODO GENMC
403
+ auto spc = AddressSpace::AS_User; // TODO GENMC
390
404
391
405
auto deps = EventDeps (); // TODO GENMC: without this, constructor is ambiguous
392
406
0 commit comments