Skip to content

Commit 3ce8d44

Browse files
committed
rustc_target: separate out an individual Align from AbiAndPrefAlign.
1 parent d56e892 commit 3ce8d44

File tree

29 files changed

+207
-197
lines changed

29 files changed

+207
-197
lines changed

src/librustc/mir/interpret/allocation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use super::{Pointer, EvalResult, AllocId};
1414

15-
use ty::layout::{Size, AbiAndPrefAlign};
15+
use ty::layout::{Size, Align, AbiAndPrefAlign};
1616
use syntax::ast::Mutability;
1717
use std::iter;
1818
use mir;
@@ -104,7 +104,7 @@ impl<Tag, Extra: Default> Allocation<Tag, Extra> {
104104
}
105105

106106
pub fn from_byte_aligned_bytes(slice: &[u8]) -> Self {
107-
Allocation::from_bytes(slice, AbiAndPrefAlign::from_bytes(1, 1).unwrap())
107+
Allocation::from_bytes(slice, AbiAndPrefAlign::new(Align::from_bytes(1).unwrap()))
108108
}
109109

110110
pub fn undef(size: Size, align: AbiAndPrefAlign) -> Self {

src/librustc/mir/interpret/error.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for EvalErrorKind<'tcx, O> {
527527
write!(f, "tried to interpret an invalid 32-bit value as a char: {}", c),
528528
AlignmentCheckFailed { required, has } =>
529529
write!(f, "tried to access memory with alignment {}, but alignment {} is required",
530-
has.abi(), required.abi()),
530+
has.abi.bytes(), required.abi.bytes()),
531531
TypeNotPrimitive(ty) =>
532532
write!(f, "expected primitive type, got {}", ty),
533533
Layout(ref err) =>
@@ -537,8 +537,9 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for EvalErrorKind<'tcx, O> {
537537
MachineError(ref inner) =>
538538
write!(f, "{}", inner),
539539
IncorrectAllocationInformation(size, size2, align, align2) =>
540-
write!(f, "incorrect alloc info: expected size {} and align {}, got size {} and \
541-
align {}", size.bytes(), align.abi(), size2.bytes(), align2.abi()),
540+
write!(f, "incorrect alloc info: expected size {} and align {}, \
541+
got size {} and align {}",
542+
size.bytes(), align.abi.bytes(), size2.bytes(), align2.abi.bytes()),
542543
Panic { ref msg, line, col, ref file } =>
543544
write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col),
544545
InvalidDiscriminant(val) =>

src/librustc/session/code_stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl CodeStats {
7171
let info = TypeSizeInfo {
7272
kind,
7373
type_description: type_desc.to_string(),
74-
align: align.abi(),
74+
align: align.abi.bytes(),
7575
overall_size: overall_size.bytes(),
7676
packed: packed,
7777
opt_discr_size: opt_discr_size.map(|s| s.bytes()),

src/librustc/ty/layout.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
259259

260260
let pack = {
261261
let pack = repr.pack as u64;
262-
AbiAndPrefAlign::from_bytes(pack, pack).unwrap()
262+
AbiAndPrefAlign::new(Align::from_bytes(pack).unwrap())
263263
};
264264

265265
let mut align = if packed {
@@ -274,7 +274,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
274274

275275
let mut optimize = !repr.inhibit_struct_field_reordering_opt();
276276
if let StructKind::Prefixed(_, align) = kind {
277-
optimize &= align.abi() == 1;
277+
optimize &= align.abi.bytes() == 1;
278278
}
279279

280280
if optimize {
@@ -285,7 +285,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
285285
};
286286
let optimizing = &mut inverse_memory_index[..end];
287287
let field_align = |f: &TyLayout<'_>| {
288-
if packed { f.align.min(pack).abi() } else { f.align.abi() }
288+
if packed { f.align.min(pack).abi } else { f.align.abi }
289289
};
290290
match kind {
291291
StructKind::AlwaysSized |
@@ -352,7 +352,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
352352

353353
if repr.align > 0 {
354354
let repr_align = repr.align as u64;
355-
align = align.max(AbiAndPrefAlign::from_bytes(repr_align, repr_align).unwrap());
355+
align = align.max(AbiAndPrefAlign::new(Align::from_bytes(repr_align).unwrap()));
356356
debug!("univariant repr_align: {:?}", repr_align);
357357
}
358358

@@ -394,7 +394,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
394394
(Some((i, field)), None, None) => {
395395
// Field fills the struct and it has a scalar or scalar pair ABI.
396396
if offsets[i].bytes() == 0 &&
397-
align.abi() == field.align.abi() &&
397+
align.abi == field.align.abi &&
398398
size == field.size {
399399
match field.abi {
400400
// For plain scalars, or vectors of them, we can't unpack
@@ -682,7 +682,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
682682

683683
let pack = {
684684
let pack = def.repr.pack as u64;
685-
AbiAndPrefAlign::from_bytes(pack, pack).unwrap()
685+
AbiAndPrefAlign::new(Align::from_bytes(pack).unwrap())
686686
};
687687

688688
let mut align = if packed {
@@ -694,7 +694,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
694694
if def.repr.align > 0 {
695695
let repr_align = def.repr.align as u64;
696696
align = align.max(
697-
AbiAndPrefAlign::from_bytes(repr_align, repr_align).unwrap());
697+
AbiAndPrefAlign::new(Align::from_bytes(repr_align).unwrap()));
698698
}
699699

700700
let optimize = !def.repr.inhibit_union_abi_opt();
@@ -964,7 +964,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
964964
let mut size = Size::ZERO;
965965

966966
// We're interested in the smallest alignment, so start large.
967-
let mut start_align = AbiAndPrefAlign::from_bytes(256, 256).unwrap();
967+
let mut start_align = AbiAndPrefAlign::new(Align::from_bytes(256).unwrap());
968968
assert_eq!(Integer::for_abi_align(dl, start_align), None);
969969

970970
// repr(C) on an enum tells us to make a (tag, union) layout,
@@ -989,7 +989,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
989989
// Find the first field we can't move later
990990
// to make room for a larger discriminant.
991991
for field in st.fields.index_by_increasing_offset().map(|j| field_layouts[j]) {
992-
if !field.is_zst() || field.align.abi() != 1 {
992+
if !field.is_zst() || field.align.abi.bytes() != 1 {
993993
start_align = start_align.min(field.align);
994994
break;
995995
}
@@ -1251,7 +1251,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
12511251
name: name.to_string(),
12521252
offset: offset.bytes(),
12531253
size: field_layout.size.bytes(),
1254-
align: field_layout.align.abi(),
1254+
align: field_layout.align.abi.bytes(),
12551255
}
12561256
}
12571257
}
@@ -1264,7 +1264,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
12641264
} else {
12651265
session::SizeKind::Exact
12661266
},
1267-
align: layout.align.abi(),
1267+
align: layout.align.abi.bytes(),
12681268
size: if min_size.bytes() == 0 {
12691269
layout.size.bytes()
12701270
} else {
@@ -1994,12 +1994,16 @@ impl_stable_hash_for!(enum ::ty::layout::Primitive {
19941994
Pointer
19951995
});
19961996

1997-
impl<'gcx> HashStable<StableHashingContext<'gcx>> for AbiAndPrefAlign {
1997+
impl_stable_hash_for!(struct ::ty::layout::AbiAndPrefAlign {
1998+
abi,
1999+
pref
2000+
});
2001+
2002+
impl<'gcx> HashStable<StableHashingContext<'gcx>> for Align {
19982003
fn hash_stable<W: StableHasherResult>(&self,
19992004
hcx: &mut StableHashingContext<'gcx>,
20002005
hasher: &mut StableHasher<W>) {
2001-
self.abi().hash_stable(hcx, hasher);
2002-
self.pref().hash_stable(hcx, hasher);
2006+
self.bytes().hash_stable(hcx, hasher);
20032007
}
20042008
}
20052009

src/librustc_codegen_llvm/abi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl ArgAttributesExt for ArgAttributes {
7373
if let Some(align) = self.pointee_align {
7474
llvm::LLVMRustAddAlignmentAttr(llfn,
7575
idx.as_uint(),
76-
align.abi() as u32);
76+
align.abi.bytes() as u32);
7777
}
7878
regular.for_each_kind(|attr| attr.apply_llfn(idx, llfn));
7979
}
@@ -98,7 +98,7 @@ impl ArgAttributesExt for ArgAttributes {
9898
if let Some(align) = self.pointee_align {
9999
llvm::LLVMRustAddAlignmentCallSiteAttr(callsite,
100100
idx.as_uint(),
101-
align.abi() as u32);
101+
align.abi.bytes() as u32);
102102
}
103103
regular.for_each_kind(|attr| attr.apply_callsite(idx, callsite));
104104
}

src/librustc_codegen_llvm/builder.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
475475
llvm::LLVMBuildAlloca(self.llbuilder, ty,
476476
name.as_ptr())
477477
};
478-
llvm::LLVMSetAlignment(alloca, align.abi() as c_uint);
478+
llvm::LLVMSetAlignment(alloca, align.abi.bytes() as c_uint);
479479
alloca
480480
}
481481
}
@@ -494,7 +494,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
494494
llvm::LLVMBuildArrayAlloca(self.llbuilder, ty, len,
495495
name.as_ptr())
496496
};
497-
llvm::LLVMSetAlignment(alloca, align.abi() as c_uint);
497+
llvm::LLVMSetAlignment(alloca, align.abi.bytes() as c_uint);
498498
alloca
499499
}
500500
}
@@ -503,7 +503,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
503503
self.count_insn("load");
504504
unsafe {
505505
let load = llvm::LLVMBuildLoad(self.llbuilder, ptr, noname());
506-
llvm::LLVMSetAlignment(load, align.abi() as c_uint);
506+
llvm::LLVMSetAlignment(load, align.abi.bytes() as c_uint);
507507
load
508508
}
509509
}
@@ -658,7 +658,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
658658
let align = if flags.contains(MemFlags::UNALIGNED) {
659659
1
660660
} else {
661-
align.abi() as c_uint
661+
align.abi.bytes() as c_uint
662662
};
663663
llvm::LLVMSetAlignment(store, align);
664664
if flags.contains(MemFlags::VOLATILE) {
@@ -893,8 +893,8 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
893893
let dst = self.pointercast(dst, self.cx().type_i8p());
894894
let src = self.pointercast(src, self.cx().type_i8p());
895895
unsafe {
896-
llvm::LLVMRustBuildMemCpy(self.llbuilder, dst, dst_align.abi() as c_uint,
897-
src, src_align.abi() as c_uint, size, is_volatile);
896+
llvm::LLVMRustBuildMemCpy(self.llbuilder, dst, dst_align.abi.bytes() as c_uint,
897+
src, src_align.abi.bytes() as c_uint, size, is_volatile);
898898
}
899899
}
900900

@@ -913,8 +913,8 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
913913
let dst = self.pointercast(dst, self.cx().type_i8p());
914914
let src = self.pointercast(src, self.cx().type_i8p());
915915
unsafe {
916-
llvm::LLVMRustBuildMemMove(self.llbuilder, dst, dst_align.abi() as c_uint,
917-
src, src_align.abi() as c_uint, size, is_volatile);
916+
llvm::LLVMRustBuildMemMove(self.llbuilder, dst, dst_align.abi.bytes() as c_uint,
917+
src, src_align.abi.bytes() as c_uint, size, is_volatile);
918918
}
919919
}
920920

@@ -930,7 +930,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
930930
let intrinsic_key = format!("llvm.memset.p0i8.i{}", ptr_width);
931931
let llintrinsicfn = self.cx().get_intrinsic(&intrinsic_key);
932932
let ptr = self.pointercast(ptr, self.cx().type_i8p());
933-
let align = self.cx().const_u32(align.abi() as u32);
933+
let align = self.cx().const_u32(align.abi.bytes() as u32);
934934
let volatile = self.cx().const_bool(flags.contains(MemFlags::VOLATILE));
935935
self.call(llintrinsicfn, &[ptr, fill_byte, size, align, volatile], None);
936936
}

src/librustc_codegen_llvm/consts.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use value::Value;
2828
use rustc::ty::{self, Ty};
2929
use rustc_codegen_ssa::traits::*;
3030

31-
use rustc::ty::layout::{self, Size, AbiAndPrefAlign, LayoutOf};
31+
use rustc::ty::layout::{self, Size, Align, AbiAndPrefAlign, LayoutOf};
3232

3333
use rustc::hir::{self, CodegenFnAttrs, CodegenFnAttrFlags};
3434

@@ -94,15 +94,15 @@ fn set_global_alignment(cx: &CodegenCx<'ll, '_>,
9494
// Note: GCC and Clang also allow `__attribute__((aligned))` on variables,
9595
// which can force it to be smaller. Rust doesn't support this yet.
9696
if let Some(min) = cx.sess().target.target.options.min_global_align {
97-
match ty::layout::AbiAndPrefAlign::from_bits(min, min) {
98-
Ok(min) => align = align.max(min),
97+
match Align::from_bits(min) {
98+
Ok(min) => align = align.max(AbiAndPrefAlign::new(min)),
9999
Err(err) => {
100100
cx.sess().err(&format!("invalid minimum global alignment: {}", err));
101101
}
102102
}
103103
}
104104
unsafe {
105-
llvm::LLVMSetAlignment(gv, align.abi() as u32);
105+
llvm::LLVMSetAlignment(gv, align.abi.bytes() as u32);
106106
}
107107
}
108108

@@ -219,7 +219,7 @@ impl StaticMethods<'tcx> for CodegenCx<'ll, 'tcx> {
219219
unsafe {
220220
// Upgrade the alignment in cases where the same constant is used with different
221221
// alignment requirements
222-
let llalign = align.abi() as u32;
222+
let llalign = align.abi.bytes() as u32;
223223
if llalign > llvm::LLVMGetAlignment(gv) {
224224
llvm::LLVMSetAlignment(gv, llalign);
225225
}

0 commit comments

Comments
 (0)