Skip to content

Commit bc9c428

Browse files
committed
Simplify next instruction type determination
1 parent 2a97d2c commit bc9c428

File tree

2 files changed

+6
-62
lines changed

2 files changed

+6
-62
lines changed

src/concurrency/genmc/helper.rs

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
use rustc_abi::Size;
2-
use rustc_const_eval::interpret::{InterpCx, InterpResult, interp_ok};
3-
use rustc_middle::mir::{Terminator, TerminatorKind};
4-
use rustc_middle::ty::{self, ScalarInt, Ty};
2+
use rustc_const_eval::interpret::{InterpResult, interp_ok};
3+
use rustc_middle::ty::ScalarInt;
54
use tracing::info;
65

76
use super::GenmcScalar;
87
use crate::alloc_addresses::EvalContextExt as _;
9-
use crate::{
10-
BorTag, MiriInterpCx, MiriMachine, Pointer, Provenance, Scalar, ThreadId, throw_unsup_format,
11-
};
8+
use crate::{BorTag, MiriInterpCx, Pointer, Provenance, Scalar, throw_unsup_format};
129

1310
pub fn split_access(address: Size, size: Size) -> impl Iterator<Item = (u64, u64)> {
1411
/// Maximum size memory access in bytes that GenMC supports.
@@ -139,53 +136,3 @@ pub fn genmc_scalar_to_scalar<'tcx>(
139136
let (value_scalar_int, _got_truncated) = ScalarInt::truncate_from_uint(scalar.value, size);
140137
interp_ok(Scalar::Int(value_scalar_int))
141138
}
142-
143-
pub fn is_terminator_atomic<'tcx>(
144-
ecx: &InterpCx<'tcx, MiriMachine<'tcx>>,
145-
terminator: &Terminator<'tcx>,
146-
thread_id: ThreadId,
147-
) -> InterpResult<'tcx, bool> {
148-
match &terminator.kind {
149-
// All atomics are modeled as function calls to intrinsic functions.
150-
// The one exception is thread joining, but those are also calls.
151-
TerminatorKind::Call { func, .. } | TerminatorKind::TailCall { func, .. } => {
152-
let frame = ecx.machine.threads.get_thread_stack(thread_id).last().unwrap();
153-
let func_ty = func.ty(&frame.body().local_decls, *ecx.tcx);
154-
info!("GenMC: terminator is a call with operand: {func:?}, ty of operand: {func_ty:?}");
155-
156-
is_function_atomic(ecx, func_ty)
157-
}
158-
_ => interp_ok(false),
159-
}
160-
}
161-
162-
fn is_function_atomic<'tcx>(
163-
ecx: &InterpCx<'tcx, MiriMachine<'tcx>>,
164-
func_ty: Ty<'tcx>,
165-
// func: &Operand<'tcx>,
166-
) -> InterpResult<'tcx, bool> {
167-
let callee_def_id = match func_ty.kind() {
168-
ty::FnDef(def_id, _args) => def_id,
169-
_ => return interp_ok(true), // we don't know the callee, might be an intrinsic or pthread_join
170-
};
171-
if ecx.tcx.is_foreign_item(*callee_def_id) {
172-
// Some shims, like pthread_join, must be considered loads. So just consider them all loads,
173-
// these calls are not *that* common.
174-
return interp_ok(true);
175-
}
176-
177-
let Some(intrinsic_def) = ecx.tcx.intrinsic(callee_def_id) else {
178-
// TODO GENMC: Make this work for other platforms?
179-
let item_name = ecx.tcx.item_name(*callee_def_id);
180-
info!("GenMC: function DefId: {callee_def_id:?}, item name: {item_name:?}");
181-
if matches!(item_name.as_str(), "pthread_join" | "WaitForSingleObject") {
182-
info!("GenMC: found a 'join' terminator: '{}'", item_name.as_str(),);
183-
return interp_ok(true);
184-
}
185-
return interp_ok(false);
186-
};
187-
let intrinsice_name = intrinsic_def.name.as_str();
188-
info!("GenMC: intrinsic name: '{intrinsice_name}'");
189-
// TODO GENMC(ENHANCEMENT): make this more precise (only loads). How can we make this maintainable?
190-
interp_ok(intrinsice_name.starts_with("atomic_"))
191-
}

src/concurrency/genmc/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use self::helper::{
1717
};
1818
use self::mapping::{min_max_to_genmc_rmw_op, to_genmc_rmw_op};
1919
use self::thread_info_manager::ThreadInfoManager;
20-
use crate::concurrency::genmc::helper::{is_terminator_atomic, split_access};
20+
use crate::concurrency::genmc::helper::split_access;
2121
use crate::{
2222
AtomicFenceOrd, AtomicReadOrd, AtomicRwOrd, AtomicWriteOrd, MemoryKind, MiriConfig,
2323
MiriMachine, MiriMemoryKind, Scalar, TerminationInfo, ThreadId, ThreadManager, VisitProvenance,
@@ -864,11 +864,8 @@ impl GenmcCtx {
864864
return interp_ok(active_thread_id);
865865
}
866866

867-
if is_terminator_atomic(ecx, basic_block.terminator(), active_thread_id)? {
868-
ActionKind::Load
869-
} else {
870-
ActionKind::NonLoad
871-
}
867+
// FIXME(genmc): determine terminator kind.
868+
ActionKind::Load
872869
};
873870

874871
info!(

0 commit comments

Comments
 (0)