Skip to content

Commit 2e12ee0

Browse files
committed
Lower inling cost for a statement.
1 parent fd5c78b commit 2e12ee0

22 files changed

+6939
-623
lines changed

compiler/rustc_mir_transform/src/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::ops::{Range, RangeFrom};
2222

2323
pub(crate) mod cycle;
2424

25-
const INSTR_COST: usize = 5;
25+
const INSTR_COST: usize = 1;
2626
const CALL_PENALTY: usize = 25;
2727
const LANDINGPAD_PENALTY: usize = 50;
2828
const RESUME_PENALTY: usize = 45;

tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-abort.diff

+771-3
Large diffs are not rendered by default.

tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff

+11-267
Original file line numberDiff line numberDiff line change
@@ -10,155 +10,6 @@
1010
}
1111
+ scope 2 (inlined Vec::<u32>::new) {
1212
+ let mut _3: alloc::raw_vec::RawVec<u32>;
13-
+ }
14-
+ scope 3 (inlined Box::<Vec<u32>>::new) {
15-
+ debug x => _2;
16-
+ let mut _4: usize;
17-
+ let mut _5: usize;
18-
+ let mut _6: *mut u8;
19-
+ let mut _7: *const std::vec::Vec<u32>;
20-
+ scope 4 {
21-
+ scope 5 (inlined alloc::alloc::exchange_malloc) {
22-
+ debug size => _4;
23-
+ debug align => _5;
24-
+ let _8: std::alloc::Layout;
25-
+ let mut _9: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
26-
+ let mut _10: isize;
27-
+ let mut _12: !;
28-
+ scope 6 {
29-
+ debug layout => _8;
30-
+ let _11: std::ptr::NonNull<[u8]>;
31-
+ let mut _13: &std::alloc::Global;
32-
+ scope 8 {
33-
+ debug ptr => _11;
34-
+ scope 18 (inlined NonNull::<[u8]>::as_mut_ptr) {
35-
+ debug self => _11;
36-
+ let mut _15: std::ptr::NonNull<u8>;
37-
+ scope 19 (inlined NonNull::<[u8]>::as_non_null_ptr) {
38-
+ debug self => _11;
39-
+ let mut _16: *mut u8;
40-
+ let mut _17: *mut [u8];
41-
+ scope 20 {
42-
+ scope 21 (inlined NonNull::<[u8]>::as_ptr) {
43-
+ debug self => _11;
44-
+ let mut _18: bool;
45-
+ let mut _19: bool;
46-
+ let mut _20: *const [u8];
47-
+ let mut _21: *const [u8];
48-
+ scope 22 {
49-
+ scope 23 (inlined ptr::const_ptr::<impl *const [u8]>::is_null) {
50-
+ debug self => _20;
51-
+ let mut _22: *const u8;
52-
+ scope 24 {
53-
+ scope 25 (inlined ptr::const_ptr::<impl *const T>::is_null::runtime_impl) {
54-
+ debug ptr => _22;
55-
+ let mut _23: usize;
56-
+ scope 26 (inlined ptr::const_ptr::<impl *const u8>::addr) {
57-
+ debug self => _22;
58-
+ let mut _24: *const ();
59-
+ scope 27 {
60-
+ scope 28 (inlined ptr::const_ptr::<impl *const u8>::cast::<()>) {
61-
+ debug self => _22;
62-
+ }
63-
+ }
64-
+ }
65-
+ }
66-
+ }
67-
+ }
68-
+ }
69-
+ }
70-
+ scope 29 (inlined ptr::mut_ptr::<impl *mut [u8]>::as_mut_ptr) {
71-
+ debug self => _17;
72-
+ }
73-
+ scope 30 (inlined NonNull::<u8>::new_unchecked) {
74-
+ debug ptr => _16;
75-
+ let mut _25: *const u8;
76-
+ scope 31 {
77-
+ scope 32 (inlined NonNull::<T>::new_unchecked::runtime::<u8>) {
78-
+ debug ptr => _16;
79-
+ scope 33 (inlined ptr::mut_ptr::<impl *mut u8>::is_null) {
80-
+ debug self => _16;
81-
+ let mut _26: *mut u8;
82-
+ scope 34 {
83-
+ scope 35 (inlined ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
84-
+ debug ptr => _26;
85-
+ scope 36 (inlined ptr::mut_ptr::<impl *mut u8>::addr) {
86-
+ debug self => _26;
87-
+ scope 37 {
88-
+ scope 38 (inlined ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
89-
+ debug self => _26;
90-
+ }
91-
+ }
92-
+ }
93-
+ }
94-
+ }
95-
+ }
96-
+ }
97-
+ }
98-
+ }
99-
+ }
100-
+ }
101-
+ scope 39 (inlined NonNull::<u8>::as_ptr) {
102-
+ debug self => _15;
103-
+ let mut _27: bool;
104-
+ let mut _28: bool;
105-
+ let mut _29: *const u8;
106-
+ let mut _30: *const u8;
107-
+ scope 40 {
108-
+ scope 41 (inlined ptr::const_ptr::<impl *const u8>::is_null) {
109-
+ debug self => _29;
110-
+ scope 42 {
111-
+ scope 43 (inlined ptr::const_ptr::<impl *const T>::is_null::runtime_impl) {
112-
+ debug ptr => _29;
113-
+ let mut _31: usize;
114-
+ scope 44 (inlined ptr::const_ptr::<impl *const u8>::addr) {
115-
+ debug self => _29;
116-
+ let mut _32: *const ();
117-
+ scope 45 {
118-
+ scope 46 (inlined ptr::const_ptr::<impl *const u8>::cast::<()>) {
119-
+ debug self => _29;
120-
+ }
121-
+ }
122-
+ }
123-
+ }
124-
+ }
125-
+ }
126-
+ }
127-
+ }
128-
+ }
129-
+ }
130-
+ scope 17 (inlined <std::alloc::Global as Allocator>::allocate) {
131-
+ debug self => const _;
132-
+ debug layout => _8;
133-
+ }
134-
+ }
135-
+ scope 7 {
136-
+ scope 9 (inlined Layout::from_size_align_unchecked) {
137-
+ debug size => _4;
138-
+ debug align => _5;
139-
+ let mut _14: std::ptr::Alignment;
140-
+ scope 10 {
141-
+ scope 11 (inlined std::ptr::Alignment::new_unchecked) {
142-
+ debug align => _5;
143-
+ scope 12 {
144-
+ scope 14 (inlined std::ptr::Alignment::new_unchecked::runtime) {
145-
+ debug align => _5;
146-
+ scope 15 (inlined core::num::<impl usize>::is_power_of_two) {
147-
+ debug self => _5;
148-
+ scope 16 (inlined core::num::<impl usize>::count_ones) {
149-
+ debug self => _5;
150-
+ }
151-
+ }
152-
+ }
153-
+ }
154-
+ scope 13 {
155-
+ }
156-
+ }
157-
+ }
158-
+ }
159-
+ }
160-
+ }
161-
+ }
16213
+ }
16314

16415
bb0: {
@@ -169,136 +20,29 @@
16920
+ _3 = const _;
17021
+ _2 = Vec::<u32> { buf: move _3, len: const 0_usize };
17122
+ StorageDead(_3);
172-
+ StorageLive(_4);
173-
+ StorageLive(_5);
174-
+ StorageLive(_6);
175-
+ StorageLive(_7);
176-
+ _4 = SizeOf(std::vec::Vec<u32>);
177-
+ _5 = AlignOf(std::vec::Vec<u32>);
178-
+ StorageLive(_8);
179-
+ StorageLive(_10);
180-
+ StorageLive(_11);
181-
+ StorageLive(_12);
182-
+ StorageLive(_13);
183-
+ StorageLive(_29);
184-
+ StorageLive(_14);
185-
+ _14 = _5 as std::ptr::Alignment (Transmute);
186-
+ _8 = Layout { size: _4, align: move _14 };
187-
+ StorageDead(_14);
188-
+ StorageLive(_9);
189-
+ _13 = const _;
190-
+ _9 = std::alloc::Global::alloc_impl(move _13, _8, const false) -> [return: bb7, unwind: bb3];
23+
+ _1 = Box::<Vec<u32>>::new(move _2) -> [return: bb1, unwind: bb3];
19124
}
19225

19326
bb1: {
19427
- _1 = Box::<Vec<u32>>::new(move _2) -> [return: bb2, unwind: bb4];
195-
+ StorageDead(_1);
196-
+ return;
197-
}
198-
28+
- }
29+
-
19930
- bb2: {
200-
- StorageDead(_2);
201-
- _0 = const ();
31+
StorageDead(_2);
32+
_0 = const ();
20233
- drop(_1) -> [return: bb3, unwind: bb4];
203-
+ bb2 (cleanup): {
204-
+ resume;
34+
+ drop(_1) -> [return: bb2, unwind: bb3];
20535
}
20636

20737
- bb3: {
208-
- StorageDead(_1);
209-
- return;
210-
+ bb3 (cleanup): {
211-
+ drop(_2) -> [return: bb2, unwind terminate(cleanup)];
38+
+ bb2: {
39+
StorageDead(_1);
40+
return;
21241
}
21342

21443
- bb4 (cleanup): {
215-
- resume;
216-
+ bb4: {
217-
+ _12 = handle_alloc_error(move _8) -> bb3;
218-
+ }
219-
+
220-
+ bb5: {
221-
+ unreachable;
222-
+ }
223-
+
224-
+ bb6: {
225-
+ _11 = ((_9 as Ok).0: std::ptr::NonNull<[u8]>);
226-
+ StorageLive(_15);
227-
+ StorageLive(_16);
228-
+ StorageLive(_17);
229-
+ StorageLive(_18);
230-
+ StorageLive(_19);
231-
+ StorageLive(_20);
232-
+ _20 = (_11.0: *const [u8]);
233-
+ StorageLive(_22);
234-
+ _22 = _20 as *const u8 (PtrToPtr);
235-
+ StorageLive(_23);
236-
+ StorageLive(_24);
237-
+ _24 = _22 as *const () (PtrToPtr);
238-
+ _23 = move _24 as usize (Transmute);
239-
+ StorageDead(_24);
240-
+ _19 = Eq(move _23, const 0_usize);
241-
+ StorageDead(_23);
242-
+ StorageDead(_22);
243-
+ StorageDead(_20);
244-
+ _18 = Not(move _19);
245-
+ StorageDead(_19);
246-
+ assume(move _18);
247-
+ StorageDead(_18);
248-
+ StorageLive(_21);
249-
+ _21 = (_11.0: *const [u8]);
250-
+ _17 = move _21 as *mut [u8] (PtrToPtr);
251-
+ StorageDead(_21);
252-
+ _16 = _17 as *mut u8 (PtrToPtr);
253-
+ StorageDead(_17);
254-
+ StorageLive(_25);
255-
+ StorageLive(_26);
256-
+ _25 = _16 as *const u8 (PointerCoercion(MutToConstPointer));
257-
+ _15 = NonNull::<u8> { pointer: _25 };
258-
+ StorageDead(_26);
259-
+ StorageDead(_25);
260-
+ StorageDead(_16);
261-
+ StorageLive(_27);
262-
+ StorageLive(_28);
263-
+ _29 = (_15.0: *const u8);
264-
+ StorageLive(_31);
265-
+ StorageLive(_32);
266-
+ _32 = _29 as *const () (PtrToPtr);
267-
+ _31 = move _32 as usize (Transmute);
268-
+ StorageDead(_32);
269-
+ _28 = Eq(move _31, const 0_usize);
270-
+ StorageDead(_31);
271-
+ _27 = Not(move _28);
272-
+ StorageDead(_28);
273-
+ assume(move _27);
274-
+ StorageDead(_27);
275-
+ StorageLive(_30);
276-
+ _30 = (_15.0: *const u8);
277-
+ _6 = move _30 as *mut u8 (PtrToPtr);
278-
+ StorageDead(_30);
279-
+ StorageDead(_15);
280-
+ StorageDead(_9);
281-
+ StorageDead(_29);
282-
+ StorageDead(_13);
283-
+ StorageDead(_12);
284-
+ StorageDead(_11);
285-
+ StorageDead(_10);
286-
+ StorageDead(_8);
287-
+ _1 = ShallowInitBox(move _6, std::vec::Vec<u32>);
288-
+ _7 = (((_1.0: std::ptr::Unique<std::vec::Vec<u32>>).0: std::ptr::NonNull<std::vec::Vec<u32>>).0: *const std::vec::Vec<u32>);
289-
+ (*_7) = move _2;
290-
+ StorageDead(_7);
291-
+ StorageDead(_6);
292-
+ StorageDead(_5);
293-
+ StorageDead(_4);
294-
+ StorageDead(_2);
295-
+ _0 = const ();
296-
+ drop(_1) -> [return: bb1, unwind: bb2];
297-
+ }
298-
+
299-
+ bb7: {
300-
+ _10 = discriminant(_9);
301-
+ switchInt(move _10) -> [0: bb6, 1: bb4, otherwise: bb5];
44+
+ bb3 (cleanup): {
45+
resume;
30246
}
30347
}
30448

0 commit comments

Comments
 (0)