Skip to content

Commit 84a7784

Browse files
committed
Simplify next instruction type determination
1 parent 6a2873c commit 84a7784

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

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,
@@ -854,11 +854,8 @@ impl GenmcCtx {
854854
return interp_ok(active_thread_id);
855855
}
856856

857-
if is_terminator_atomic(ecx, basic_block.terminator(), active_thread_id)? {
858-
ActionKind::Load
859-
} else {
860-
ActionKind::NonLoad
861-
}
857+
// FIXME(genmc): determine terminator kind.
858+
ActionKind::Load
862859
};
863860

864861
info!(

0 commit comments

Comments
 (0)