|
1 | 1 | #![cfg_attr(feature = "nightly", feature(step_trait, rustc_attrs, min_specialization))]
|
2 | 2 |
|
3 |
| -use std::fmt; |
4 | 3 | #[cfg(feature = "nightly")]
|
5 | 4 | use std::iter::Step;
|
6 | 5 | use std::num::{NonZeroUsize, ParseIntError};
|
7 | 6 | use std::ops::{Add, AddAssign, Mul, RangeInclusive, Sub};
|
8 | 7 | use std::str::FromStr;
|
| 8 | +use std::{cmp, fmt}; |
9 | 9 |
|
10 | 10 | use bitflags::bitflags;
|
11 | 11 | use rustc_data_structures::intern::Interned;
|
@@ -1272,6 +1272,31 @@ impl Abi {
|
1272 | 1272 | pub fn is_scalar(&self) -> bool {
|
1273 | 1273 | matches!(*self, Abi::Scalar(_))
|
1274 | 1274 | }
|
| 1275 | + |
| 1276 | + /// Returns the fixed alignment of this ABI, if any |
| 1277 | + pub fn inherent_align<C: HasDataLayout>(&self, cx: &C) -> Option<AbiAndPrefAlign> { |
| 1278 | + Some(match *self { |
| 1279 | + Abi::Scalar(s) => s.align(cx), |
| 1280 | + Abi::ScalarPair(s1, s2) => { |
| 1281 | + AbiAndPrefAlign::new(cmp::max(s1.align(cx).abi, s2.align(cx).abi)) |
| 1282 | + } |
| 1283 | + Abi::Vector { element, count } => { |
| 1284 | + cx.data_layout().vector_align(element.size(cx) * count) |
| 1285 | + } |
| 1286 | + Abi::Uninhabited | Abi::Aggregate { .. } => return None, |
| 1287 | + }) |
| 1288 | + } |
| 1289 | + |
| 1290 | + /// Discard valid range information and allow undef |
| 1291 | + pub fn to_union(&self) -> Self { |
| 1292 | + assert!(self.is_sized()); |
| 1293 | + match *self { |
| 1294 | + Abi::Scalar(s) => Abi::Scalar(s.to_union()), |
| 1295 | + Abi::ScalarPair(s1, s2) => Abi::ScalarPair(s1.to_union(), s2.to_union()), |
| 1296 | + Abi::Vector { element, count } => Abi::Vector { element: element.to_union(), count }, |
| 1297 | + Abi::Uninhabited | Abi::Aggregate { .. } => Abi::Aggregate { sized: true }, |
| 1298 | + } |
| 1299 | + } |
1275 | 1300 | }
|
1276 | 1301 |
|
1277 | 1302 | #[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
|
0 commit comments