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