From ca3d55e32d762ca0acb0676aac70848c559c7f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Thu, 19 Jan 2023 00:00:00 +0000 Subject: [PATCH] Custom MIR: Support storage statements --- .../src/build/custom/parse/instruction.rs | 6 ++++++ library/core/src/intrinsics/mir.rs | 2 ++ tests/mir-opt/building/custom/simple_assign.rs | 2 ++ .../custom/simple_assign.simple.built.after.mir | 12 +++++++----- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs index dca4906c07d..0bca02589bc 100644 --- a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs +++ b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs @@ -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> { 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])?))) }, diff --git a/library/core/src/intrinsics/mir.rs b/library/core/src/intrinsics/mir.rs index 399d54f18c5..e3157b66902 100644 --- a/library/core/src/intrinsics/mir.rs +++ b/library/core/src/intrinsics/mir.rs @@ -259,6 +259,8 @@ define!("mir_unreachable", fn Unreachable() -> BasicBlock); define!("mir_drop", fn Drop(place: T, goto: BasicBlock)); define!("mir_drop_and_replace", fn DropAndReplace(place: T, value: T, goto: BasicBlock)); define!("mir_call", fn Call(place: T, goto: BasicBlock, call: T)); +define!("mir_storage_live", fn StorageLive(local: T)); +define!("mir_storage_dead", fn StorageDead(local: T)); define!("mir_retag", fn Retag(place: T)); define!("mir_move", fn Move(place: T) -> T); define!("mir_static", fn Static(s: T) -> &'static T); diff --git a/tests/mir-opt/building/custom/simple_assign.rs b/tests/mir-opt/building/custom/simple_assign.rs index ec6dbe1d052..db041aab239 100644 --- a/tests/mir-opt/building/custom/simple_assign.rs +++ b/tests/mir-opt/building/custom/simple_assign.rs @@ -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() } diff --git a/tests/mir-opt/building/custom/simple_assign.simple.built.after.mir b/tests/mir-opt/building/custom/simple_assign.simple.built.after.mir index d7560fde69c..743016708c5 100644 --- a/tests/mir-opt/building/custom/simple_assign.simple.built.after.mir +++ b/tests/mir-opt/building/custom/simple_assign.simple.built.after.mir @@ -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 } }