Skip to content
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

Basic block predecessors in mir textual representation #90868

Closed
wants to merge 2 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ where

// Basic block label at the top.
let cleanup_text = if data.is_cleanup { " (cleanup)" } else { "" };
writeln!(w, "{}{:?}{}: {{", INDENT, block, cleanup_text)?;
let indented_body = format!("{}{:?}{}: {{", INDENT, block, cleanup_text);
let predecessors = &body.predecessors()[block];
writeln!(w, "{:A$} // preds: {:?}", indented_body, predecessors, A = ALIGN)?;

// List of statements in the middle.
let mut current_location = Location { block, statement_index: 0 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
let mut _0: Type; // return place in scope 0 at $DIR/76803_regression.rs:10:27: 10:31
let mut _2: isize; // in scope 0 at $DIR/76803_regression.rs:12:9: 12:16

bb0: {
bb0: { // preds: []
_2 = discriminant(_1); // scope 0 at $DIR/76803_regression.rs:11:11: 11:12
switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/76803_regression.rs:11:5: 11:12
}

bb1: {
bb1: { // preds: [bb0]
_0 = move _1; // scope 0 at $DIR/76803_regression.rs:13:14: 13:15
goto -> bb3; // scope 0 at $DIR/76803_regression.rs:13:14: 13:15
}

bb2: {
bb2: { // preds: [bb0]
discriminant(_0) = 1; // scope 0 at $DIR/76803_regression.rs:12:20: 12:27
goto -> bb3; // scope 0 at $DIR/76803_regression.rs:12:20: 12:27
}

bb3: {
bb3: { // preds: [bb1, bb2]
return; // scope 0 at $DIR/76803_regression.rs:15:2: 15:2
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn address_of_reborrow() -> () {
}
}

bb0: {
bb0: { // preds: []
StorageLive(_1); // scope 0 at $DIR/address-of.rs:4:9: 4:10
StorageLive(_2); // scope 0 at $DIR/address-of.rs:4:14: 4:21
_2 = [const 0_i32; 10]; // scope 0 at $DIR/address-of.rs:4:14: 4:21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn borrow_and_cast(_1: i32) -> () {
}
}

bb0: {
bb0: { // preds: []
StorageLive(_2); // scope 0 at $DIR/address-of.rs:42:9: 42:10
StorageLive(_3); // scope 0 at $DIR/address-of.rs:42:13: 42:15
_3 = &_1; // scope 0 at $DIR/address-of.rs:42:13: 42:15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() -> () {
}
}

bb0: {
bb0: { // preds: []
StorageLive(_1); // scope 0 at $DIR/array-index-is-temporary.rs:13:9: 13:14
_1 = [const 42_u32, const 43_u32, const 44_u32]; // scope 0 at $DIR/array-index-is-temporary.rs:13:17: 13:29
StorageLive(_2); // scope 1 at $DIR/array-index-is-temporary.rs:14:9: 14:14
Expand All @@ -42,7 +42,7 @@ fn main() -> () {
// + literal: Const { ty: unsafe fn(*mut usize) -> u32 {foo}, val: Value(Scalar(<ZST>)) }
}

bb1: {
bb1: { // preds: [bb0]
StorageDead(_6); // scope 4 at $DIR/array-index-is-temporary.rs:16:26: 16:27
StorageLive(_7); // scope 3 at $DIR/array-index-is-temporary.rs:16:7: 16:8
_7 = _2; // scope 3 at $DIR/array-index-is-temporary.rs:16:7: 16:8
Expand All @@ -51,7 +51,7 @@ fn main() -> () {
assert(move _9, "index out of bounds: the length is {} but the index is {}", move _8, _7) -> bb2; // scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:9
}

bb2: {
bb2: { // preds: [bb1]
_1[_7] = move _5; // scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:29
StorageDead(_5); // scope 3 at $DIR/array-index-is-temporary.rs:16:28: 16:29
StorageDead(_7); // scope 3 at $DIR/array-index-is-temporary.rs:16:29: 16:30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() -> () {
}
}

bb0: {
bb0: { // preds: []
StorageLive(_1); // scope 0 at $DIR/array-index-is-temporary.rs:13:9: 13:14
_1 = [const 42_u32, const 43_u32, const 44_u32]; // scope 0 at $DIR/array-index-is-temporary.rs:13:17: 13:29
StorageLive(_2); // scope 1 at $DIR/array-index-is-temporary.rs:14:9: 14:14
Expand All @@ -42,7 +42,7 @@ fn main() -> () {
// + literal: Const { ty: unsafe fn(*mut usize) -> u32 {foo}, val: Value(Scalar(<ZST>)) }
}

bb1: {
bb1: { // preds: [bb0]
StorageDead(_6); // scope 4 at $DIR/array-index-is-temporary.rs:16:26: 16:27
StorageLive(_7); // scope 3 at $DIR/array-index-is-temporary.rs:16:7: 16:8
_7 = _2; // scope 3 at $DIR/array-index-is-temporary.rs:16:7: 16:8
Expand All @@ -51,7 +51,7 @@ fn main() -> () {
assert(move _9, "index out of bounds: the length is {} but the index is {}", move _8, _7) -> bb2; // scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:9
}

bb2: {
bb2: { // preds: [bb1]
_1[_7] = move _5; // scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:29
StorageDead(_5); // scope 3 at $DIR/array-index-is-temporary.rs:16:28: 16:29
StorageDead(_7); // scope 3 at $DIR/array-index-is-temporary.rs:16:29: 16:30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() -> () {
}
}

bb0: {
bb0: { // preds: []
StorageLive(_1); // scope 0 at $DIR/basic_assignment.rs:11:9: 11:17
_1 = const false; // scope 0 at $DIR/basic_assignment.rs:11:20: 11:25
FakeRead(ForLet(None), _1); // scope 0 at $DIR/basic_assignment.rs:11:9: 11:17
Expand All @@ -44,41 +44,41 @@ fn main() -> () {
replace(_5 <- move _6) -> [return: bb1, unwind: bb5]; // scope 4 at $DIR/basic_assignment.rs:23:5: 23:11
}

bb1: {
bb1: { // preds: [bb0]
drop(_6) -> [return: bb2, unwind: bb6]; // scope 4 at $DIR/basic_assignment.rs:23:19: 23:20
}

bb2: {
bb2: { // preds: [bb1]
StorageDead(_6); // scope 4 at $DIR/basic_assignment.rs:23:19: 23:20
_0 = const (); // scope 0 at $DIR/basic_assignment.rs:10:11: 24:2
drop(_5) -> [return: bb3, unwind: bb7]; // scope 3 at $DIR/basic_assignment.rs:24:1: 24:2
}

bb3: {
bb3: { // preds: [bb2]
StorageDead(_5); // scope 3 at $DIR/basic_assignment.rs:24:1: 24:2
drop(_4) -> [return: bb4, unwind: bb8]; // scope 2 at $DIR/basic_assignment.rs:24:1: 24:2
}

bb4: {
bb4: { // preds: [bb3]
StorageDead(_4); // scope 2 at $DIR/basic_assignment.rs:24:1: 24:2
StorageDead(_2); // scope 1 at $DIR/basic_assignment.rs:24:1: 24:2
StorageDead(_1); // scope 0 at $DIR/basic_assignment.rs:24:1: 24:2
return; // scope 0 at $DIR/basic_assignment.rs:24:2: 24:2
}

bb5 (cleanup): {
bb5 (cleanup): { // preds: [bb0]
drop(_6) -> bb6; // scope 4 at $DIR/basic_assignment.rs:23:19: 23:20
}

bb6 (cleanup): {
bb6 (cleanup): { // preds: [bb1, bb5]
drop(_5) -> bb7; // scope 3 at $DIR/basic_assignment.rs:24:1: 24:2
}

bb7 (cleanup): {
bb7 (cleanup): { // preds: [bb2, bb6]
drop(_4) -> bb8; // scope 2 at $DIR/basic_assignment.rs:24:1: 24:2
}

bb8 (cleanup): {
bb8 (cleanup): { // preds: [bb3, bb7]
resume; // scope 0 at $DIR/basic_assignment.rs:10:1: 24:2
}
}
8 changes: 4 additions & 4 deletions src/test/mir-opt/bool_compare.opt1.InstCombine.diff
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let mut _2: bool; // in scope 0 at $DIR/bool_compare.rs:3:8: 3:17
let mut _3: bool; // in scope 0 at $DIR/bool_compare.rs:3:8: 3:9

bb0: {
bb0: { // preds: []
StorageLive(_2); // scope 0 at $DIR/bool_compare.rs:3:8: 3:17
StorageLive(_3); // scope 0 at $DIR/bool_compare.rs:3:8: 3:9
_3 = _1; // scope 0 at $DIR/bool_compare.rs:3:8: 3:9
Expand All @@ -17,17 +17,17 @@
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/bool_compare.rs:3:8: 3:17
}

bb1: {
bb1: { // preds: [bb0]
_0 = const 0_u32; // scope 0 at $DIR/bool_compare.rs:3:20: 3:21
goto -> bb3; // scope 0 at $DIR/bool_compare.rs:3:5: 3:34
}

bb2: {
bb2: { // preds: [bb0]
_0 = const 1_u32; // scope 0 at $DIR/bool_compare.rs:3:31: 3:32
goto -> bb3; // scope 0 at $DIR/bool_compare.rs:3:5: 3:34
}

bb3: {
bb3: { // preds: [bb1, bb2]
StorageDead(_2); // scope 0 at $DIR/bool_compare.rs:3:33: 3:34
return; // scope 0 at $DIR/bool_compare.rs:4:2: 4:2
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/mir-opt/bool_compare.opt2.InstCombine.diff
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let mut _2: bool; // in scope 0 at $DIR/bool_compare.rs:8:8: 8:17
let mut _3: bool; // in scope 0 at $DIR/bool_compare.rs:8:16: 8:17

bb0: {
bb0: { // preds: []
StorageLive(_2); // scope 0 at $DIR/bool_compare.rs:8:8: 8:17
StorageLive(_3); // scope 0 at $DIR/bool_compare.rs:8:16: 8:17
_3 = _1; // scope 0 at $DIR/bool_compare.rs:8:16: 8:17
Expand All @@ -17,17 +17,17 @@
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/bool_compare.rs:8:8: 8:17
}

bb1: {
bb1: { // preds: [bb0]
_0 = const 0_u32; // scope 0 at $DIR/bool_compare.rs:8:20: 8:21
goto -> bb3; // scope 0 at $DIR/bool_compare.rs:8:5: 8:34
}

bb2: {
bb2: { // preds: [bb0]
_0 = const 1_u32; // scope 0 at $DIR/bool_compare.rs:8:31: 8:32
goto -> bb3; // scope 0 at $DIR/bool_compare.rs:8:5: 8:34
}

bb3: {
bb3: { // preds: [bb1, bb2]
StorageDead(_2); // scope 0 at $DIR/bool_compare.rs:8:33: 8:34
return; // scope 0 at $DIR/bool_compare.rs:9:2: 9:2
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/mir-opt/bool_compare.opt3.InstCombine.diff
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let mut _2: bool; // in scope 0 at $DIR/bool_compare.rs:13:8: 13:18
let mut _3: bool; // in scope 0 at $DIR/bool_compare.rs:13:8: 13:9

bb0: {
bb0: { // preds: []
StorageLive(_2); // scope 0 at $DIR/bool_compare.rs:13:8: 13:18
StorageLive(_3); // scope 0 at $DIR/bool_compare.rs:13:8: 13:9
_3 = _1; // scope 0 at $DIR/bool_compare.rs:13:8: 13:9
Expand All @@ -17,17 +17,17 @@
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/bool_compare.rs:13:8: 13:18
}

bb1: {
bb1: { // preds: [bb0]
_0 = const 0_u32; // scope 0 at $DIR/bool_compare.rs:13:21: 13:22
goto -> bb3; // scope 0 at $DIR/bool_compare.rs:13:5: 13:35
}

bb2: {
bb2: { // preds: [bb0]
_0 = const 1_u32; // scope 0 at $DIR/bool_compare.rs:13:32: 13:33
goto -> bb3; // scope 0 at $DIR/bool_compare.rs:13:5: 13:35
}

bb3: {
bb3: { // preds: [bb1, bb2]
StorageDead(_2); // scope 0 at $DIR/bool_compare.rs:13:34: 13:35
return; // scope 0 at $DIR/bool_compare.rs:14:2: 14:2
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/mir-opt/bool_compare.opt4.InstCombine.diff
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let mut _2: bool; // in scope 0 at $DIR/bool_compare.rs:18:8: 18:18
let mut _3: bool; // in scope 0 at $DIR/bool_compare.rs:18:17: 18:18

bb0: {
bb0: { // preds: []
StorageLive(_2); // scope 0 at $DIR/bool_compare.rs:18:8: 18:18
StorageLive(_3); // scope 0 at $DIR/bool_compare.rs:18:17: 18:18
_3 = _1; // scope 0 at $DIR/bool_compare.rs:18:17: 18:18
Expand All @@ -17,17 +17,17 @@
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/bool_compare.rs:18:8: 18:18
}

bb1: {
bb1: { // preds: [bb0]
_0 = const 0_u32; // scope 0 at $DIR/bool_compare.rs:18:21: 18:22
goto -> bb3; // scope 0 at $DIR/bool_compare.rs:18:5: 18:35
}

bb2: {
bb2: { // preds: [bb0]
_0 = const 1_u32; // scope 0 at $DIR/bool_compare.rs:18:32: 18:33
goto -> bb3; // scope 0 at $DIR/bool_compare.rs:18:5: 18:35
}

bb3: {
bb3: { // preds: [bb1, bb2]
StorageDead(_2); // scope 0 at $DIR/bool_compare.rs:18:34: 18:35
return; // scope 0 at $DIR/bool_compare.rs:19:2: 19:2
}
Expand Down
20 changes: 10 additions & 10 deletions src/test/mir-opt/box_expr.main.ElaborateDrops.before.mir
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() -> () {
scope 2 {
}

bb0: {
bb0: { // preds: []
StorageLive(_1); // scope 0 at $DIR/box_expr.rs:7:9: 7:10
_2 = SizeOf(S); // scope 2 at $DIR/box_expr.rs:7:13: 7:25
_3 = AlignOf(S); // scope 2 at $DIR/box_expr.rs:7:13: 7:25
Expand All @@ -25,7 +25,7 @@ fn main() -> () {
// + literal: Const { ty: unsafe fn(usize, usize) -> *mut u8 {alloc::alloc::exchange_malloc}, val: Value(Scalar(<ZST>)) }
}

bb1: {
bb1: { // preds: [bb0]
StorageLive(_5); // scope 0 at $DIR/box_expr.rs:7:13: 7:25
_5 = ShallowInitBox(move _4, S); // scope 0 at $DIR/box_expr.rs:7:13: 7:25
(*_5) = S::new() -> [return: bb2, unwind: bb8]; // scope 0 at $DIR/box_expr.rs:7:17: 7:25
Expand All @@ -34,12 +34,12 @@ fn main() -> () {
// + literal: Const { ty: fn() -> S {S::new}, val: Value(Scalar(<ZST>)) }
}

bb2: {
bb2: { // preds: [bb1]
_1 = move _5; // scope 0 at $DIR/box_expr.rs:7:13: 7:25
drop(_5) -> bb3; // scope 0 at $DIR/box_expr.rs:7:24: 7:25
}

bb3: {
bb3: { // preds: [bb2]
StorageDead(_5); // scope 0 at $DIR/box_expr.rs:7:24: 7:25
StorageLive(_6); // scope 1 at $DIR/box_expr.rs:8:5: 8:12
StorageLive(_7); // scope 1 at $DIR/box_expr.rs:8:10: 8:11
Expand All @@ -50,31 +50,31 @@ fn main() -> () {
// + literal: Const { ty: fn(std::boxed::Box<S>) {std::mem::drop::<std::boxed::Box<S>>}, val: Value(Scalar(<ZST>)) }
}

bb4: {
bb4: { // preds: [bb3]
StorageDead(_7); // scope 1 at $DIR/box_expr.rs:8:11: 8:12
StorageDead(_6); // scope 1 at $DIR/box_expr.rs:8:12: 8:13
_0 = const (); // scope 0 at $DIR/box_expr.rs:6:11: 9:2
drop(_1) -> bb5; // scope 0 at $DIR/box_expr.rs:9:1: 9:2
}

bb5: {
bb5: { // preds: [bb4]
StorageDead(_1); // scope 0 at $DIR/box_expr.rs:9:1: 9:2
return; // scope 0 at $DIR/box_expr.rs:9:2: 9:2
}

bb6 (cleanup): {
bb6 (cleanup): { // preds: [bb3]
drop(_7) -> bb7; // scope 1 at $DIR/box_expr.rs:8:11: 8:12
}

bb7 (cleanup): {
bb7 (cleanup): { // preds: [bb6]
drop(_1) -> bb9; // scope 0 at $DIR/box_expr.rs:9:1: 9:2
}

bb8 (cleanup): {
bb8 (cleanup): { // preds: [bb1]
drop(_5) -> bb9; // scope 0 at $DIR/box_expr.rs:7:24: 7:25
}

bb9 (cleanup): {
bb9 (cleanup): { // preds: [bb7, bb8]
resume; // scope 0 at $DIR/box_expr.rs:6:1: 9:2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() -> () {
}
}

bb0: {
bb0: { // preds: []
StorageLive(_1); // scope 0 at $DIR/byte_slice.rs:5:9: 5:10
_1 = const b"foo"; // scope 0 at $DIR/byte_slice.rs:5:13: 5:19
// ty::Const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
}

bb0: {
bb0: { // preds: []
StorageLive(_2); // scope 0 at $DIR/combine_array_len.rs:5:9: 5:10
StorageLive(_3); // scope 0 at $DIR/combine_array_len.rs:5:15: 5:16
_3 = const 0_usize; // scope 0 at $DIR/combine_array_len.rs:5:15: 5:16
Expand All @@ -35,7 +35,7 @@
assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> bb1; // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
}

bb1: {
bb1: { // preds: [bb0]
_2 = _1[_3]; // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
StorageDead(_3); // scope 0 at $DIR/combine_array_len.rs:5:17: 5:18
StorageLive(_6); // scope 1 at $DIR/combine_array_len.rs:6:9: 6:10
Expand All @@ -47,7 +47,7 @@
assert(move _9, "index out of bounds: the length is {} but the index is {}", move _8, _7) -> bb2; // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
}

bb2: {
bb2: { // preds: [bb1]
_6 = _1[_7]; // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
StorageDead(_7); // scope 1 at $DIR/combine_array_len.rs:6:17: 6:18
StorageLive(_10); // scope 2 at $DIR/combine_array_len.rs:7:5: 7:8
Expand Down
Loading