Skip to content

Custom MIR: Support storage statements #107067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ use super::{parse_by_kind, PResult, ParseCtxt};
impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
pub fn parse_statement(&self, expr_id: ExprId) -> PResult<StatementKind<'tcx>> {
parse_by_kind!(self, expr_id, _, "statement",
@call("mir_storage_live", args) => {
Ok(StatementKind::StorageLive(self.parse_local(args[0])?))
},
@call("mir_storage_dead", args) => {
Ok(StatementKind::StorageDead(self.parse_local(args[0])?))
},
@call("mir_retag", args) => {
Ok(StatementKind::Retag(RetagKind::Default, Box::new(self.parse_place(args[0])?)))
},
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/intrinsics/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ define!("mir_unreachable", fn Unreachable() -> BasicBlock);
define!("mir_drop", fn Drop<T>(place: T, goto: BasicBlock));
define!("mir_drop_and_replace", fn DropAndReplace<T>(place: T, value: T, goto: BasicBlock));
define!("mir_call", fn Call<T>(place: T, goto: BasicBlock, call: T));
define!("mir_storage_live", fn StorageLive<T>(local: T));
define!("mir_storage_dead", fn StorageDead<T>(local: T));
define!("mir_retag", fn Retag<T>(place: T));
define!("mir_move", fn Move<T>(place: T) -> T);
define!("mir_static", fn Static<T>(s: T) -> &'static T);
Expand Down
2 changes: 2 additions & 0 deletions tests/mir-opt/building/custom/simple_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ pub fn simple(x: i32) -> i32 {
let temp2: _;

{
StorageLive(temp1);
temp1 = x;
Goto(exit)
}

exit = {
temp2 = Move(temp1);
StorageDead(temp1);
RET = temp2;
Return()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ fn simple(_1: i32) -> i32 {
let mut _3: i32; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL

bb0: {
_2 = _1; // scope 0 at $DIR/simple_assign.rs:+6:13: +6:22
goto -> bb1; // scope 0 at $DIR/simple_assign.rs:+7:13: +7:23
StorageLive(_2); // scope 0 at $DIR/simple_assign.rs:+6:13: +6:31
_2 = _1; // scope 0 at $DIR/simple_assign.rs:+7:13: +7:22
goto -> bb1; // scope 0 at $DIR/simple_assign.rs:+8:13: +8:23
}

bb1: {
_3 = move _2; // scope 0 at $DIR/simple_assign.rs:+11:13: +11:32
_0 = _3; // scope 0 at $DIR/simple_assign.rs:+12:13: +12:24
return; // scope 0 at $DIR/simple_assign.rs:+13:13: +13:21
_3 = move _2; // scope 0 at $DIR/simple_assign.rs:+12:13: +12:32
StorageDead(_2); // scope 0 at $DIR/simple_assign.rs:+13:13: +13:31
_0 = _3; // scope 0 at $DIR/simple_assign.rs:+14:13: +14:24
return; // scope 0 at $DIR/simple_assign.rs:+15:13: +15:21
}
}