Skip to content

Commit aec727f

Browse files
committed
Stop using EmulateItemResult for LLVM intrinsics in miri
1 parent 8c2ed2f commit aec727f

22 files changed

Lines changed: 64 additions & 78 deletions

File tree

compiler/rustc_const_eval/src/const_eval/dummy_machine.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ impl<'tcx> interpret::Machine<'tcx> for DummyMachine {
111111
_args: &[interpret::OpTy<'tcx, Self::Provenance>],
112112
_destination: &interpret::PlaceTy<'tcx, Self::Provenance>,
113113
_target: Option<BasicBlock>,
114-
_unwind: UnwindAction,
115114
) -> interpret::InterpResult<'tcx> {
116115
unimplemented!()
117116
}

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,6 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
751751
_args: &[OpTy<'tcx>],
752752
_dest: &PlaceTy<'tcx, Self::Provenance>,
753753
_target: Option<mir::BasicBlock>,
754-
_unwind: mir::UnwindAction,
755754
) -> InterpResult<'tcx> {
756755
let intrinsic_name = ecx.tcx.codegen_fn_attrs(instance.def_id()).symbol_name.unwrap();
757756

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
660660
&Self::copy_fn_args(args),
661661
destination,
662662
target,
663-
unwind,
664663
)
665664
}
666665
ty::InstanceKind::Shim(ty::ShimKind::VTable(..))

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ pub trait Machine<'tcx>: Sized {
255255
args: &[OpTy<'tcx, Self::Provenance>],
256256
destination: &PlaceTy<'tcx, Self::Provenance>,
257257
target: Option<mir::BasicBlock>,
258-
unwind: mir::UnwindAction,
259258
) -> InterpResult<'tcx>;
260259

261260
/// Check whether the given function may be executed on the current machine, in terms of the

src/tools/miri/src/machine.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,9 +1307,8 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
13071307
args: &[OpTy<'tcx>],
13081308
dest: &PlaceTy<'tcx>,
13091309
ret: Option<mir::BasicBlock>,
1310-
unwind: mir::UnwindAction,
13111310
) -> InterpResult<'tcx, ()> {
1312-
ecx.call_llvm_intrinsic(instance, args, dest, ret, unwind)
1311+
ecx.call_llvm_intrinsic(instance, args, dest, ret)
13131312
}
13141313

13151314
#[inline(always)]

src/tools/miri/src/shims/aarch64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1313
link_name: Symbol,
1414
args: &[OpTy<'tcx>],
1515
dest: &MPlaceTy<'tcx>,
16-
) -> InterpResult<'tcx, EmulateItemResult> {
16+
) -> InterpResult<'tcx, bool> {
1717
let this = self.eval_context_mut();
1818
// Prefix should have already been checked.
1919
let unprefixed_name = link_name.as_str().strip_prefix("llvm.aarch64.").unwrap();
@@ -273,8 +273,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
273273
this.write_scalar(Scalar::from_u128(result), &dest)?;
274274
}
275275

276-
_ => return interp_ok(EmulateItemResult::NotSupported),
276+
_ => return interp_ok(false),
277277
}
278-
interp_ok(EmulateItemResult::NeedsReturn)
278+
interp_ok(true)
279279
}
280280
}

src/tools/miri/src/shims/foreign_items.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
249249
args: &[OpTy<'tcx>],
250250
dest: &PlaceTy<'tcx>,
251251
ret: Option<mir::BasicBlock>,
252-
unwind: mir::UnwindAction,
253252
) -> InterpResult<'tcx> {
254253
let this = self.eval_context_mut();
255254

@@ -258,7 +257,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
258257
// FIXME: avoid allocating memory
259258
let dest = this.force_allocation(dest)?;
260259

261-
let res = match link_name.as_str() {
260+
let handled = match link_name.as_str() {
262261
// LLVM intrinsics
263262
"llvm.prefetch.p0" => {
264263
let [p, rw, loc, ty] = this.check_shim_sig_unadjusted(link_name, args)?;
@@ -285,7 +284,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
285284
throw_unsup_format!("unsupported `llvm.prefetch` type argument: {}", ty);
286285
}
287286

288-
EmulateItemResult::NeedsReturn
287+
true
289288
}
290289
// Used to implement the x86 `_mm{,256,512}_popcnt_epi{8,16,32,64}` and wasm
291290
// `{i,u}8x16_popcnt` functions.
@@ -311,7 +310,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
311310
)?;
312311
}
313312

314-
EmulateItemResult::NeedsReturn
313+
true
315314
}
316315

317316
// Target-specific shims
@@ -331,26 +330,18 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
331330
shims::loongarch::EvalContextExt::emulate_loongarch_intrinsic(
332331
this, link_name, args, &dest,
333332
)?,
334-
_ => EmulateItemResult::NotSupported,
333+
_ => false,
335334
};
336335

337336
// The rest either implements the logic, or falls back to `lookup_exported_symbol`.
338-
match res {
339-
EmulateItemResult::NeedsReturn => {
340-
trace!("{:?}", this.dump_place(&dest.clone().into()));
341-
this.return_to_block(ret)
342-
}
343-
EmulateItemResult::NeedsUnwind => {
344-
// Jump to the unwind block to begin unwinding.
345-
this.unwind_to_block(unwind)
346-
}
347-
EmulateItemResult::AlreadyJumped => interp_ok(()),
348-
EmulateItemResult::NotSupported => {
349-
throw_machine_stop!(TerminationInfo::UnsupportedForeignItem(format!(
350-
"can't call LLVM intrinsic `{link_name}` on architecture `{arch}`",
351-
arch = this.tcx.sess.target.arch,
352-
)));
353-
}
337+
if handled {
338+
trace!("{:?}", this.dump_place(&dest.clone().into()));
339+
this.return_to_block(ret)
340+
} else {
341+
throw_machine_stop!(TerminationInfo::UnsupportedForeignItem(format!(
342+
"can't call LLVM intrinsic `{link_name}` on architecture `{arch}`",
343+
arch = this.tcx.sess.target.arch,
344+
)));
354345
}
355346
}
356347
}

src/tools/miri/src/shims/loongarch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1111
link_name: Symbol,
1212
args: &[OpTy<'tcx>],
1313
dest: &MPlaceTy<'tcx>,
14-
) -> InterpResult<'tcx, EmulateItemResult> {
14+
) -> InterpResult<'tcx, bool> {
1515
let this = self.eval_context_mut();
1616
// Prefix should have already been checked.
1717
let unprefixed_name = link_name.as_str().strip_prefix("llvm.loongarch.").unwrap();
@@ -67,8 +67,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
6767
let result = compute_crc32(crc, data, bit_size, polynomial);
6868
this.write_scalar(Scalar::from_u32(result), dest)?;
6969
}
70-
_ => return interp_ok(EmulateItemResult::NotSupported),
70+
_ => return interp_ok(false),
7171
}
72-
interp_ok(EmulateItemResult::NeedsReturn)
72+
interp_ok(true)
7373
}
7474
}

src/tools/miri/src/shims/x86/aesni.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1010
link_name: Symbol,
1111
args: &[OpTy<'tcx>],
1212
dest: &MPlaceTy<'tcx>,
13-
) -> InterpResult<'tcx, EmulateItemResult> {
13+
) -> InterpResult<'tcx, bool> {
1414
let this = self.eval_context_mut();
1515
this.expect_target_feature_for_intrinsic(link_name, "aes")?;
1616
// Prefix should have already been checked.
@@ -112,9 +112,9 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
112112
}
113113
// TODO: Implement the `llvm.x86.aesni.aeskeygenassist` when possible
114114
// with an external crate.
115-
_ => return interp_ok(EmulateItemResult::NotSupported),
115+
_ => return interp_ok(false),
116116
}
117-
interp_ok(EmulateItemResult::NeedsReturn)
117+
interp_ok(true)
118118
}
119119
}
120120

src/tools/miri/src/shims/x86/avx.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1414
link_name: Symbol,
1515
args: &[OpTy<'tcx>],
1616
dest: &MPlaceTy<'tcx>,
17-
) -> InterpResult<'tcx, EmulateItemResult> {
17+
) -> InterpResult<'tcx, bool> {
1818
let this = self.eval_context_mut();
1919
this.expect_target_feature_for_intrinsic(link_name, "avx")?;
2020
// Prefix should have already been checked.
@@ -243,8 +243,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
243243
// The only thing that needs to be ensured is the correct calling convention.
244244
let [] = this.check_shim_sig_unadjusted(link_name, args)?;
245245
}
246-
_ => return interp_ok(EmulateItemResult::NotSupported),
246+
_ => return interp_ok(false),
247247
}
248-
interp_ok(EmulateItemResult::NeedsReturn)
248+
interp_ok(true)
249249
}
250250
}

0 commit comments

Comments
 (0)