Skip to content

Commit b28f668

Browse files
committed
rustc: move size, align & primitive_align from Abi::Aggregate to layout.
1 parent b723af2 commit b28f668

30 files changed

+299
-383
lines changed

src/librustc/ty/layout.rs

Lines changed: 125 additions & 186 deletions
Large diffs are not rendered by default.

src/librustc_const_eval/eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,12 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
320320
};
321321
match &tcx.item_name(def_id)[..] {
322322
"size_of" => {
323-
let size = layout_of(substs.type_at(0))?.size(tcx).bytes();
323+
let size = layout_of(substs.type_at(0))?.size.bytes();
324324
return Ok(mk_const(Integral(Usize(ConstUsize::new(size,
325325
tcx.sess.target.usize_ty).unwrap()))));
326326
}
327327
"min_align_of" => {
328-
let align = layout_of(substs.type_at(0))?.align(tcx).abi();
328+
let align = layout_of(substs.type_at(0))?.align.abi();
329329
return Ok(mk_const(Integral(Usize(ConstUsize::new(align,
330330
tcx.sess.target.usize_ty).unwrap()))));
331331
}

src/librustc_lint/types.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,15 +757,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
757757
let discr_size = discr.size(cx.tcx).bytes();
758758

759759
debug!("enum `{}` is {} bytes large with layout:\n{:#?}",
760-
t, layout.size(cx.tcx).bytes(), layout);
760+
t, layout.size.bytes(), layout);
761761

762762
let (largest, slargest, largest_index) = enum_definition.variants
763763
.iter()
764764
.zip(variants)
765765
.map(|(variant, variant_layout)| {
766766
// Subtract the size of the enum discriminant
767-
let bytes = variant_layout.abi.size(cx.tcx)
768-
.bytes()
767+
let bytes = variant_layout.size.bytes()
769768
.saturating_sub(discr_size);
770769

771770
debug!("- variant `{}` is {} bytes large", variant.node.name, bytes);

src/librustc_mir/transform/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
626626
fn type_size_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
627627
param_env: ty::ParamEnv<'tcx>,
628628
ty: Ty<'tcx>) -> Option<u64> {
629-
(tcx, param_env).layout_of(ty).ok().map(|layout| layout.size(tcx).bytes())
629+
(tcx, param_env).layout_of(ty).ok().map(|layout| layout.size.bytes())
630630
}
631631

632632
fn subst_and_normalize<'a, 'tcx: 'a>(

src/librustc_trans/abi.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,14 @@ impl<'tcx> LayoutExt<'tcx> for TyLayout<'tcx> {
296296
};
297297
Some(Reg {
298298
kind,
299-
size: self.size(ccx)
299+
size: self.size
300300
})
301301
}
302302

303303
layout::Abi::Vector { .. } => {
304304
Some(Reg {
305305
kind: RegKind::Vector,
306-
size: self.size(ccx)
306+
size: self.size
307307
})
308308
}
309309

@@ -345,7 +345,7 @@ impl<'tcx> LayoutExt<'tcx> for TyLayout<'tcx> {
345345
}
346346

347347
// Keep track of the offset (without padding).
348-
let size = field.size(ccx);
348+
let size = field.size;
349349
if is_union {
350350
total = cmp::max(total, size);
351351
} else {
@@ -354,7 +354,7 @@ impl<'tcx> LayoutExt<'tcx> for TyLayout<'tcx> {
354354
}
355355

356356
// There needs to be no padding.
357-
if total != self.size(ccx) {
357+
if total != self.size {
358358
None
359359
} else {
360360
result
@@ -446,7 +446,7 @@ impl<'a, 'tcx> ArgType<'tcx> {
446446
}
447447
}
448448

449-
pub fn make_indirect(&mut self, ccx: &CrateContext<'a, 'tcx>) {
449+
pub fn make_indirect(&mut self) {
450450
assert!(self.nested.is_empty());
451451
assert_eq!(self.kind, ArgKind::Direct);
452452

@@ -458,7 +458,7 @@ impl<'a, 'tcx> ArgType<'tcx> {
458458
// program-invisible so can't possibly capture
459459
self.attrs.set(ArgAttribute::NoAlias)
460460
.set(ArgAttribute::NoCapture)
461-
.set_dereferenceable(self.layout.size(ccx));
461+
.set_dereferenceable(self.layout.size);
462462

463463
self.kind = ArgKind::Indirect;
464464
}
@@ -520,15 +520,15 @@ impl<'a, 'tcx> ArgType<'tcx> {
520520
}
521521
let ccx = bcx.ccx;
522522
if self.is_indirect() {
523-
let llsz = C_usize(ccx, self.layout.size(ccx).bytes());
524-
base::call_memcpy(bcx, dst.llval, val, llsz, self.layout.align(ccx));
523+
let llsz = C_usize(ccx, self.layout.size.bytes());
524+
base::call_memcpy(bcx, dst.llval, val, llsz, self.layout.align);
525525
} else if let Some(ty) = self.cast {
526526
// FIXME(eddyb): Figure out when the simpler Store is safe, clang
527527
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
528528
let can_store_through_cast_ptr = false;
529529
if can_store_through_cast_ptr {
530530
let cast_dst = bcx.pointercast(dst.llval, ty.llvm_type(ccx).ptr_to());
531-
bcx.store(val, cast_dst, Some(self.layout.align(ccx)));
531+
bcx.store(val, cast_dst, Some(self.layout.align));
532532
} else {
533533
// The actual return type is a struct, but the ABI
534534
// adaptation code has cast it into some scalar type. The
@@ -556,8 +556,8 @@ impl<'a, 'tcx> ArgType<'tcx> {
556556
base::call_memcpy(bcx,
557557
bcx.pointercast(dst.llval, Type::i8p(ccx)),
558558
bcx.pointercast(llscratch, Type::i8p(ccx)),
559-
C_usize(ccx, self.layout.size(ccx).bytes()),
560-
self.layout.align(ccx).min(ty.align(ccx)));
559+
C_usize(ccx, self.layout.size.bytes()),
560+
self.layout.align.min(ty.align(ccx)));
561561

562562
bcx.lifetime_end(llscratch, scratch_size);
563563
}
@@ -828,7 +828,7 @@ impl<'a, 'tcx> FnType<'tcx> {
828828
_ => return
829829
}
830830

831-
let size = arg.layout.size(ccx);
831+
let size = arg.layout.size;
832832

833833
if let Some(unit) = arg.layout.homogeneous_aggregate(ccx) {
834834
// Replace newtypes with their inner-most type.
@@ -851,7 +851,7 @@ impl<'a, 'tcx> FnType<'tcx> {
851851
}
852852

853853
if size > layout::Pointer.size(ccx) {
854-
arg.make_indirect(ccx);
854+
arg.make_indirect();
855855
} else {
856856
// We want to pass small aggregates as immediates, but using
857857
// a LLVM aggregate type for this leads to bad optimizations,
@@ -897,7 +897,7 @@ impl<'a, 'tcx> FnType<'tcx> {
897897
"x86_64" => if abi == Abi::SysV64 {
898898
cabi_x86_64::compute_abi_info(ccx, self);
899899
} else if abi == Abi::Win64 || ccx.sess().target.target.options.is_like_windows {
900-
cabi_x86_win64::compute_abi_info(ccx, self);
900+
cabi_x86_win64::compute_abi_info(self);
901901
} else {
902902
cabi_x86_64::compute_abi_info(ccx, self);
903903
},
@@ -910,12 +910,12 @@ impl<'a, 'tcx> FnType<'tcx> {
910910
"s390x" => cabi_s390x::compute_abi_info(ccx, self),
911911
"asmjs" => cabi_asmjs::compute_abi_info(ccx, self),
912912
"wasm32" => cabi_asmjs::compute_abi_info(ccx, self),
913-
"msp430" => cabi_msp430::compute_abi_info(ccx, self),
913+
"msp430" => cabi_msp430::compute_abi_info(self),
914914
"sparc" => cabi_sparc::compute_abi_info(ccx, self),
915915
"sparc64" => cabi_sparc64::compute_abi_info(ccx, self),
916-
"nvptx" => cabi_nvptx::compute_abi_info(ccx, self),
917-
"nvptx64" => cabi_nvptx64::compute_abi_info(ccx, self),
918-
"hexagon" => cabi_hexagon::compute_abi_info(ccx, self),
916+
"nvptx" => cabi_nvptx::compute_abi_info(self),
917+
"nvptx64" => cabi_nvptx64::compute_abi_info(self),
918+
"hexagon" => cabi_hexagon::compute_abi_info(self),
919919
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a))
920920
}
921921

src/librustc_trans/base.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,13 @@ pub fn memcpy_ty<'a, 'tcx>(
406406
layout: TyLayout<'tcx>,
407407
align: Option<Align>,
408408
) {
409-
let ccx = bcx.ccx;
410-
411-
let size = layout.size(ccx).bytes();
409+
let size = layout.size.bytes();
412410
if size == 0 {
413411
return;
414412
}
415413

416-
let align = align.unwrap_or_else(|| layout.align(ccx));
417-
call_memcpy(bcx, dst, src, C_usize(ccx, size), align);
414+
let align = align.unwrap_or(layout.align);
415+
call_memcpy(bcx, dst, src, C_usize(bcx.ccx, size), align);
418416
}
419417

420418
pub fn call_memset<'a, 'tcx>(b: &Builder<'a, 'tcx>,

src/librustc_trans/cabi_aarch64.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use context::CrateContext;
1414
fn is_homogeneous_aggregate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>)
1515
-> Option<Uniform> {
1616
arg.layout.homogeneous_aggregate(ccx).and_then(|unit| {
17-
let size = arg.layout.size(ccx);
17+
let size = arg.layout.size;
1818

1919
// Ensure we have at most four uniquely addressable members.
2020
if size > unit.size.checked_mul(4, ccx).unwrap() {
@@ -47,7 +47,7 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tc
4747
ret.cast_to(uniform);
4848
return;
4949
}
50-
let size = ret.layout.size(ccx);
50+
let size = ret.layout.size;
5151
let bits = size.bits();
5252
if bits <= 128 {
5353
let unit = if bits <= 8 {
@@ -66,7 +66,7 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tc
6666
});
6767
return;
6868
}
69-
ret.make_indirect(ccx);
69+
ret.make_indirect();
7070
}
7171

7272
fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
@@ -78,7 +78,7 @@ fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tc
7878
arg.cast_to(uniform);
7979
return;
8080
}
81-
let size = arg.layout.size(ccx);
81+
let size = arg.layout.size;
8282
let bits = size.bits();
8383
if bits <= 128 {
8484
let unit = if bits <= 8 {
@@ -97,7 +97,7 @@ fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tc
9797
});
9898
return;
9999
}
100-
arg.make_indirect(ccx);
100+
arg.make_indirect();
101101
}
102102

103103
pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {

src/librustc_trans/cabi_arm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use llvm::CallConv;
1515
fn is_homogeneous_aggregate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>)
1616
-> Option<Uniform> {
1717
arg.layout.homogeneous_aggregate(ccx).and_then(|unit| {
18-
let size = arg.layout.size(ccx);
18+
let size = arg.layout.size;
1919

2020
// Ensure we have at most four uniquely addressable members.
2121
if size > unit.size.checked_mul(4, ccx).unwrap() {
@@ -52,7 +52,7 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tc
5252
}
5353
}
5454

55-
let size = ret.layout.size(ccx);
55+
let size = ret.layout.size;
5656
let bits = size.bits();
5757
if bits <= 32 {
5858
let unit = if bits <= 8 {
@@ -68,7 +68,7 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tc
6868
});
6969
return;
7070
}
71-
ret.make_indirect(ccx);
71+
ret.make_indirect();
7272
}
7373

7474
fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>, vfp: bool) {
@@ -84,8 +84,8 @@ fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tc
8484
}
8585
}
8686

87-
let align = arg.layout.align(ccx).abi();
88-
let total = arg.layout.size(ccx);
87+
let align = arg.layout.align.abi();
88+
let total = arg.layout.size;
8989
arg.cast_to(Uniform {
9090
unit: if align <= 4 { Reg::i32() } else { Reg::i64() },
9191
total

src/librustc_trans/cabi_asmjs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use context::CrateContext;
1919
fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
2020
if ret.layout.is_aggregate() {
2121
if let Some(unit) = ret.layout.homogeneous_aggregate(ccx) {
22-
let size = ret.layout.size(ccx);
22+
let size = ret.layout.size;
2323
if unit.size == size {
2424
ret.cast_to(Uniform {
2525
unit,
@@ -29,13 +29,13 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tc
2929
}
3030
}
3131

32-
ret.make_indirect(ccx);
32+
ret.make_indirect();
3333
}
3434
}
3535

36-
fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
36+
fn classify_arg_ty(arg: &mut ArgType) {
3737
if arg.layout.is_aggregate() {
38-
arg.make_indirect(ccx);
38+
arg.make_indirect();
3939
arg.attrs.set(ArgAttribute::ByVal);
4040
}
4141
}
@@ -47,6 +47,6 @@ pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType
4747

4848
for arg in &mut fty.args {
4949
if arg.is_ignore() { continue; }
50-
classify_arg_ty(ccx, arg);
50+
classify_arg_ty(arg);
5151
}
5252
}

src/librustc_trans/cabi_hexagon.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,32 @@
1111
#![allow(non_upper_case_globals)]
1212

1313
use abi::{FnType, ArgType, LayoutExt};
14-
use context::CrateContext;
1514

16-
fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
17-
if ret.layout.is_aggregate() && ret.layout.size(ccx).bits() > 64 {
18-
ret.make_indirect(ccx);
15+
fn classify_ret_ty(ret: &mut ArgType) {
16+
if ret.layout.is_aggregate() && ret.layout.size.bits() > 64 {
17+
ret.make_indirect();
1918
} else {
2019
ret.extend_integer_width_to(32);
2120
}
2221
}
2322

24-
fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
25-
if arg.layout.is_aggregate() && arg.layout.size(ccx).bits() > 64 {
26-
arg.make_indirect(ccx);
23+
fn classify_arg_ty(arg: &mut ArgType) {
24+
if arg.layout.is_aggregate() && arg.layout.size.bits() > 64 {
25+
arg.make_indirect();
2726
} else {
2827
arg.extend_integer_width_to(32);
2928
}
3029
}
3130

32-
pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
31+
pub fn compute_abi_info(fty: &mut FnType) {
3332
if !fty.ret.is_ignore() {
34-
classify_ret_ty(ccx, &mut fty.ret);
33+
classify_ret_ty(&mut fty.ret);
3534
}
3635

3736
for arg in &mut fty.args {
3837
if arg.is_ignore() {
3938
continue;
4039
}
41-
classify_arg_ty(ccx, arg);
40+
classify_arg_ty(arg);
4241
}
4342
}

0 commit comments

Comments
 (0)