Skip to content

Commit 7d52e27

Browse files
committed
Simplify mutex lock annotation id.
1 parent 8e1eb4a commit 7d52e27

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

genmc-sys/cpp/include/MiriInterface.hpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
// GenMC headers:
1414
#include "ExecutionGraph/EventLabel.hpp"
15-
#include "Static/ModuleID.hpp"
1615
#include "Support/MemOrdering.hpp"
1716
#include "Support/RMWOps.hpp"
1817
#include "Verification/Config.hpp"
@@ -41,10 +40,6 @@ struct MutexLockResult;
4140
// GenMC uses `int` for its thread IDs.
4241
using ThreadId = int;
4342

44-
// Types used for GenMC annotations, e.g., in `handle_mutex_lock`.
45-
using AnnotID = ModuleID::ID;
46-
using AnnotT = SExpr<AnnotID>;
47-
4843
/// Set the log level for GenMC.
4944
///
5045
/// # Safety
@@ -245,14 +240,6 @@ struct MiriGenmcShim : private GenMCDriver {
245240
* indices, since GenMC expects us to do that.
246241
*/
247242
std::vector<Action> threads_action_;
248-
249-
/**
250-
* Map of already used annotation ids (e.g., for mutexes).
251-
* FIXME(GenMC): Ensure that these are consistent with how GenMC expects them once Miri supports
252-
* multithreading in GenMC mode.
253-
*/
254-
std::unordered_map<uint64_t, ModuleID::ID> annotation_id {};
255-
ModuleID::ID annotation_id_counter = 0;
256243
};
257244

258245
/// Get the bit mask that GenMC expects for global memory allocations.

genmc-sys/cpp/src/MiriInterface/Mutex.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
#include "MiriInterface.hpp"
44

5+
// GenMC headers:
6+
#include "Static/ModuleID.hpp"
7+
58
// CXX.rs generated headers:
69
#include "genmc-sys/src/lib.rs.h"
710

@@ -10,24 +13,20 @@
1013

1114
auto MiriGenmcShim::handle_mutex_lock(ThreadId thread_id, uint64_t address, uint64_t size)
1215
-> MutexLockResult {
13-
// FIXME(genmc,multithreading): ensure this annotation id is unique even if Miri runs GenMC mode
14-
// multithreaded. We cannot use the address directly, since it is 64 bits, and `ID` is an
15-
// `unsigned int`.
16-
ModuleID::ID annot_id;
17-
auto [it, inserted] = annotation_id.try_emplace(address, annotation_id_counter);
18-
if (inserted) {
19-
annot_id = annotation_id_counter++;
20-
} else {
21-
annot_id = it->second;
22-
}
16+
// This annotation informs GenMC about the condition required to make this lock call succeed.
17+
// It stands for `value_read_by_load != MUTEX_LOCKED`.
2318
const auto size_bits = size * 8;
2419
const auto annot = std::move(Annotation(
2520
AssumeType::Spinloop,
26-
Annotation::ExprVP(NeExpr<AnnotID>::create(
27-
RegisterExpr<AnnotID>::create(size_bits, annot_id),
28-
ConcreteExpr<AnnotID>::create(size_bits, MUTEX_LOCKED)
21+
Annotation::ExprVP(
22+
NeExpr<ModuleID::ID>::create(
23+
// `RegisterExpr` marks the value of the current expression, i.e., the loaded value.
24+
// The id is zero, since this annotation only uses one input variable.
25+
RegisterExpr<ModuleID::ID>::create(size_bits, /* id */ 0),
26+
ConcreteExpr<ModuleID::ID>::create(size_bits, MUTEX_LOCKED)
27+
)
28+
.release()
2929
)
30-
.release())
3130
));
3231

3332
// Mutex starts out unlocked, so we always say the previous value is "unlocked".

0 commit comments

Comments
 (0)