|
1 | 1 | use super::*;
|
| 2 | +use std::fmt::Write; |
2 | 3 | use std::{borrow::Borrow, cmp, iter, ops::Bound};
|
3 | 4 |
|
4 | 5 | #[cfg(feature = "randomize")]
|
@@ -72,12 +73,30 @@ pub trait LayoutCalculator {
|
72 | 73 | .expect("alt layout should have a niche like the regular one");
|
73 | 74 | let alt_head_space = niche.offset.bytes();
|
74 | 75 | let alt_niche_len = niche.value.size(dl).bytes();
|
| 76 | + let alt_tail_space = alt_layout.size.bytes() - alt_head_space - alt_niche_len; |
75 | 77 |
|
76 | 78 | debug_assert_eq!(layout.size.bytes(), alt_layout.size.bytes());
|
77 | 79 |
|
78 | 80 | let prefer_alt_layout =
|
79 | 81 | alt_head_space > head_space && alt_head_space > tail_space;
|
80 | 82 |
|
| 83 | + debug!( |
| 84 | + "sz: {}, default_niche_at: {}+{}, default_tail_space: {}, alt_niche_at/head_space: {}+{}, alt_tail: {}, num_fields: {}, better: {}\n\ |
| 85 | + layout: {}\n\ |
| 86 | + alt_layout: {}\n", |
| 87 | + layout.size.bytes(), |
| 88 | + head_space, |
| 89 | + niche_length, |
| 90 | + tail_space, |
| 91 | + alt_head_space, |
| 92 | + alt_niche_len, |
| 93 | + alt_tail_space, |
| 94 | + layout.fields.count(), |
| 95 | + prefer_alt_layout, |
| 96 | + format_field_niches(&layout, &fields, &dl), |
| 97 | + format_field_niches(&alt_layout, &fields, &dl), |
| 98 | + ); |
| 99 | + |
81 | 100 | if prefer_alt_layout {
|
82 | 101 | return Some(alt_layout);
|
83 | 102 | }
|
@@ -1015,3 +1034,28 @@ fn univariant(
|
1015 | 1034 | size,
|
1016 | 1035 | })
|
1017 | 1036 | }
|
| 1037 | + |
| 1038 | +fn format_field_niches( |
| 1039 | + layout: &LayoutS, |
| 1040 | + fields: &IndexSlice<FieldIdx, Layout<'_>>, |
| 1041 | + dl: &TargetDataLayout, |
| 1042 | +) -> String { |
| 1043 | + let mut s = String::new(); |
| 1044 | + for i in layout.fields.index_by_increasing_offset() { |
| 1045 | + let offset = layout.fields.offset(i); |
| 1046 | + let f = fields[i.into()]; |
| 1047 | + write!(s, "[o{}a{}s{}", offset.bytes(), f.align().abi.bytes(), f.size().bytes()).unwrap(); |
| 1048 | + if let Some(n) = f.largest_niche() { |
| 1049 | + write!( |
| 1050 | + s, |
| 1051 | + " n{}b{}s{}", |
| 1052 | + n.offset.bytes(), |
| 1053 | + n.available(dl).ilog2(), |
| 1054 | + n.value.size(dl).bytes() |
| 1055 | + ) |
| 1056 | + .unwrap(); |
| 1057 | + } |
| 1058 | + write!(s, "] ").unwrap(); |
| 1059 | + } |
| 1060 | + s |
| 1061 | +} |
0 commit comments