Add Assume custom MIR.

This commit is contained in:
Camille GILLOT 2024-01-20 19:01:57 +00:00
parent ef71f1047e
commit 161c674ef0
7 changed files with 81 additions and 0 deletions

View File

@ -20,6 +20,10 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
@call(mir_storage_dead, args) => {
Ok(StatementKind::StorageDead(self.parse_local(args[0])?))
},
@call(mir_assume, args) => {
let op = self.parse_operand(args[0])?;
Ok(StatementKind::Intrinsic(Box::new(NonDivergingIntrinsic::Assume(op))))
},
@call(mir_deinit, args) => {
Ok(StatementKind::Deinit(Box::new(self.parse_place(args[0])?)))
},

View File

@ -1027,6 +1027,7 @@ symbols! {
minnumf32,
minnumf64,
mips_target_feature,
mir_assume,
mir_basic_block,
mir_call,
mir_cast_transmute,

View File

@ -357,6 +357,8 @@ define!("mir_unwind_resume",
define!("mir_storage_live", fn StorageLive<T>(local: T));
define!("mir_storage_dead", fn StorageDead<T>(local: T));
#[cfg(not(bootstrap))]
define!("mir_assume", fn Assume(operand: bool));
define!("mir_deinit", fn Deinit<T>(place: T));
define!("mir_checked", fn Checked<T>(binop: T) -> (T, bool));
define!("mir_len", fn Len<T>(place: T) -> usize);

View File

@ -0,0 +1,10 @@
// MIR for `assume_constant` after built
fn assume_constant() -> () {
let mut _0: ();
bb0: {
assume(const true);
return;
}
}

View File

@ -0,0 +1,10 @@
// MIR for `assume_local` after built
fn assume_local(_1: bool) -> () {
let mut _0: ();
bb0: {
assume(_1);
return;
}
}

View File

@ -0,0 +1,10 @@
// MIR for `assume_place` after built
fn assume_place(_1: (bool, u8)) -> () {
let mut _0: ();
bb0: {
assume((_1.0: bool));
return;
}
}

View File

@ -0,0 +1,44 @@
// skip-filecheck
#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;
// EMIT_MIR assume.assume_local.built.after.mir
#[custom_mir(dialect = "built")]
fn assume_local(x: bool) {
mir!(
{
Assume(x);
Return()
}
)
}
// EMIT_MIR assume.assume_place.built.after.mir
#[custom_mir(dialect = "built")]
fn assume_place(p: (bool, u8)) {
mir!(
{
Assume(p.0);
Return()
}
)
}
// EMIT_MIR assume.assume_constant.built.after.mir
#[custom_mir(dialect = "built")]
fn assume_constant() {
mir!(
{
Assume(true);
Return()
}
)
}
fn main() {
assume_local(true);
assume_place((true, 50));
assume_constant();
}