Skip to content

Commit 89e4373

Browse files
committed
rustc_trans: remove primitive_align optimization.
1 parent 88e4d2c commit 89e4373

File tree

6 files changed

+14
-55
lines changed

6 files changed

+14
-55
lines changed

src/librustc/ty/layout.rs

+8-37
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,6 @@ pub struct LayoutDetails {
847847
pub fields: FieldPlacement,
848848
pub abi: Abi,
849849
pub align: Align,
850-
pub primitive_align: Align,
851850
pub size: Size
852851
}
853852

@@ -861,7 +860,6 @@ impl LayoutDetails {
861860
abi: Abi::Scalar(scalar),
862861
size,
863862
align,
864-
primitive_align: align
865863
}
866864
}
867865

@@ -872,7 +870,6 @@ impl LayoutDetails {
872870
fields: FieldPlacement::Union(field_count),
873871
abi: Abi::Uninhabited,
874872
align,
875-
primitive_align: align,
876873
size: Size::from_bytes(0)
877874
}
878875
}
@@ -935,7 +932,6 @@ impl<'a, 'tcx> LayoutDetails {
935932
},
936933
abi: Abi::ScalarPair(a, b),
937934
align,
938-
primitive_align: align,
939935
size
940936
}
941937
};
@@ -955,14 +951,12 @@ impl<'a, 'tcx> LayoutDetails {
955951
bug!("struct cannot be packed and aligned");
956952
}
957953

958-
let base_align = if packed {
954+
let mut align = if packed {
959955
dl.i8_align
960956
} else {
961957
dl.aggregate_align
962958
};
963959

964-
let mut align = base_align;
965-
let mut primitive_align = base_align;
966960
let mut sized = true;
967961
let mut offsets = vec![Size::from_bytes(0); fields.len()];
968962
let mut inverse_memory_index: Vec<u32> = (0..fields.len() as u32).collect();
@@ -1012,7 +1006,6 @@ impl<'a, 'tcx> LayoutDetails {
10121006
if !packed {
10131007
let discr_align = discr.align(dl);
10141008
align = align.max(discr_align);
1015-
primitive_align = primitive_align.max(discr_align);
10161009
}
10171010
}
10181011

@@ -1035,7 +1028,6 @@ impl<'a, 'tcx> LayoutDetails {
10351028
if !packed {
10361029
offset = offset.abi_align(field.align);
10371030
align = align.max(field.align);
1038-
primitive_align = primitive_align.max(field.primitive_align);
10391031
}
10401032

10411033
debug!("univariant offset: {:?} field: {:#?}", offset, field);
@@ -1134,7 +1126,6 @@ impl<'a, 'tcx> LayoutDetails {
11341126
if offsets[i] == pair_offsets[0] &&
11351127
offsets[j] == pair_offsets[1] &&
11361128
align == pair.align &&
1137-
primitive_align == pair.primitive_align &&
11381129
size == pair.size {
11391130
// We can use `ScalarPair` only when it matches our
11401131
// already computed layout (including `#[repr(C)]`).
@@ -1155,7 +1146,6 @@ impl<'a, 'tcx> LayoutDetails {
11551146
},
11561147
abi,
11571148
align,
1158-
primitive_align,
11591149
size
11601150
})
11611151
};
@@ -1255,7 +1245,6 @@ impl<'a, 'tcx> LayoutDetails {
12551245
packed: false
12561246
},
12571247
align: element.align,
1258-
primitive_align: element.primitive_align,
12591248
size
12601249
})
12611250
}
@@ -1272,7 +1261,6 @@ impl<'a, 'tcx> LayoutDetails {
12721261
packed: false
12731262
},
12741263
align: element.align,
1275-
primitive_align: element.primitive_align,
12761264
size: Size::from_bytes(0)
12771265
})
12781266
}
@@ -1288,7 +1276,6 @@ impl<'a, 'tcx> LayoutDetails {
12881276
packed: false
12891277
},
12901278
align: dl.i8_align,
1291-
primitive_align: dl.i8_align,
12921279
size: Size::from_bytes(0)
12931280
})
12941281
}
@@ -1359,7 +1346,6 @@ impl<'a, 'tcx> LayoutDetails {
13591346
abi: Abi::Vector,
13601347
size,
13611348
align,
1362-
primitive_align: align
13631349
})
13641350
}
13651351

@@ -1389,27 +1375,24 @@ impl<'a, 'tcx> LayoutDetails {
13891375
bug!("Union cannot be packed and aligned");
13901376
}
13911377

1392-
let mut primitive_align = if def.repr.packed() {
1378+
let mut align = if def.repr.packed() {
13931379
dl.i8_align
13941380
} else {
13951381
dl.aggregate_align
13961382
};
13971383

1398-
let mut align = if def.repr.align > 0 {
1384+
if def.repr.align > 0 {
13991385
let repr_align = def.repr.align as u64;
1400-
primitive_align.max(
1401-
Align::from_bytes(repr_align, repr_align).unwrap())
1402-
} else {
1403-
primitive_align
1404-
};
1386+
align = align.max(
1387+
Align::from_bytes(repr_align, repr_align).unwrap());
1388+
}
14051389

14061390
let mut size = Size::from_bytes(0);
14071391
for field in &variants[0] {
14081392
assert!(!field.is_unsized());
14091393

14101394
if !packed {
14111395
align = align.max(field.align);
1412-
primitive_align = primitive_align.max(field.primitive_align);
14131396
}
14141397
size = cmp::max(size, field.size);
14151398
}
@@ -1422,7 +1405,6 @@ impl<'a, 'tcx> LayoutDetails {
14221405
packed
14231406
},
14241407
align,
1425-
primitive_align,
14261408
size: size.abi_align(align)
14271409
}));
14281410
}
@@ -1519,12 +1501,7 @@ impl<'a, 'tcx> LayoutDetails {
15191501
}).collect::<Result<Vec<_>, _>>()?;
15201502

15211503
let offset = st[i].fields.offset(field_index) + offset;
1522-
let LayoutDetails {
1523-
size,
1524-
mut align,
1525-
mut primitive_align,
1526-
..
1527-
} = st[i];
1504+
let LayoutDetails { size, mut align, .. } = st[i];
15281505

15291506
let mut niche_align = niche.value.align(dl);
15301507
let abi = if offset.bytes() == 0 && niche.value.size(dl) == size {
@@ -1541,7 +1518,6 @@ impl<'a, 'tcx> LayoutDetails {
15411518
}
15421519
};
15431520
align = align.max(niche_align);
1544-
primitive_align = primitive_align.max(niche_align);
15451521

15461522
return Ok(tcx.intern_layout(LayoutDetails {
15471523
variants: Variants::NicheFilling {
@@ -1558,7 +1534,6 @@ impl<'a, 'tcx> LayoutDetails {
15581534
abi,
15591535
size,
15601536
align,
1561-
primitive_align
15621537
}));
15631538
}
15641539
}
@@ -1577,7 +1552,6 @@ impl<'a, 'tcx> LayoutDetails {
15771552
let (min_ity, signed) = Integer::repr_discr(tcx, ty, &def.repr, min, max);
15781553

15791554
let mut align = dl.aggregate_align;
1580-
let mut primitive_align = dl.aggregate_align;
15811555
let mut size = Size::from_bytes(0);
15821556

15831557
// We're interested in the smallest alignment, so start large.
@@ -1599,7 +1573,6 @@ impl<'a, 'tcx> LayoutDetails {
15991573
}
16001574
size = cmp::max(size, st.size);
16011575
align = align.max(st.align);
1602-
primitive_align = primitive_align.max(st.primitive_align);
16031576
Ok(st)
16041577
}).collect::<Result<Vec<_>, _>>()?;
16051578

@@ -1692,7 +1665,6 @@ impl<'a, 'tcx> LayoutDetails {
16921665
fields: FieldPlacement::Union(1),
16931666
abi,
16941667
align,
1695-
primitive_align,
16961668
size
16971669
})
16981670
}
@@ -2465,8 +2437,7 @@ impl_stable_hash_for!(struct ::ty::layout::LayoutDetails {
24652437
fields,
24662438
abi,
24672439
size,
2468-
align,
2469-
primitive_align
2440+
align
24702441
});
24712442

24722443
impl_stable_hash_for!(enum ::ty::layout::Integer {

src/librustc_trans/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ impl<'a, 'tcx> ArgType<'tcx> {
585585
// bitcasting to the struct type yields invalid cast errors.
586586

587587
// We instead thus allocate some scratch space...
588-
let llscratch = bcx.alloca(cast.llvm_type(ccx), "abi_cast", None);
588+
let llscratch = bcx.alloca(cast.llvm_type(ccx), "abi_cast", cast.align(ccx));
589589
let scratch_size = cast.size(ccx);
590590
bcx.lifetime_start(llscratch, scratch_size);
591591

src/librustc_trans/builder.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -488,15 +488,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
488488
}
489489
}
490490

491-
pub fn alloca(&self, ty: Type, name: &str, align: Option<Align>) -> ValueRef {
491+
pub fn alloca(&self, ty: Type, name: &str, align: Align) -> ValueRef {
492492
let builder = Builder::with_ccx(self.ccx);
493493
builder.position_at_start(unsafe {
494494
llvm::LLVMGetFirstBasicBlock(self.llfn())
495495
});
496496
builder.dynamic_alloca(ty, name, align)
497497
}
498498

499-
pub fn dynamic_alloca(&self, ty: Type, name: &str, align: Option<Align>) -> ValueRef {
499+
pub fn dynamic_alloca(&self, ty: Type, name: &str, align: Align) -> ValueRef {
500500
self.count_insn("alloca");
501501
unsafe {
502502
let alloca = if name.is_empty() {
@@ -506,9 +506,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
506506
llvm::LLVMBuildAlloca(self.llbuilder, ty.to_ref(),
507507
name.as_ptr())
508508
};
509-
if let Some(align) = align {
510-
llvm::LLVMSetAlignment(alloca, align.abi() as c_uint);
511-
}
509+
llvm::LLVMSetAlignment(alloca, align.abi() as c_uint);
512510
alloca
513511
}
514512
}

src/librustc_trans/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ fn trans_msvc_try<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
817817
//
818818
// More information can be found in libstd's seh.rs implementation.
819819
let i64p = Type::i64(ccx).ptr_to();
820-
let slot = bcx.alloca(i64p, "slot", None);
820+
let slot = bcx.alloca(i64p, "slot", ccx.data_layout().pointer_align);
821821
bcx.invoke(func, &[data], normal.llbb(), catchswitch.llbb(),
822822
None);
823823

src/librustc_trans/mir/lvalue.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
103103
pub fn alloca(bcx: &Builder<'a, 'tcx>, layout: TyLayout<'tcx>, name: &str)
104104
-> LvalueRef<'tcx> {
105105
debug!("alloca({:?}: {:?})", name, layout);
106-
let tmp = bcx.alloca(
107-
layout.llvm_type(bcx.ccx), name, layout.over_align());
106+
let tmp = bcx.alloca(layout.llvm_type(bcx.ccx), name, layout.align);
108107
Self::new_sized(tmp, layout, Alignment::AbiAligned)
109108
}
110109

src/librustc_trans/type_of.rs

-9
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ pub trait LayoutLlvmExt<'tcx> {
185185
fn immediate_llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> Type;
186186
fn scalar_pair_element_llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>,
187187
index: usize) -> Type;
188-
fn over_align(&self) -> Option<Align>;
189188
fn llvm_field_index(&self, index: usize) -> u64;
190189
fn pointee_info_at<'a>(&self, ccx: &CrateContext<'a, 'tcx>, offset: Size)
191190
-> Option<PointeeInfo>;
@@ -365,14 +364,6 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
365364
}
366365
}
367366

368-
fn over_align(&self) -> Option<Align> {
369-
if self.align != self.primitive_align {
370-
Some(self.align)
371-
} else {
372-
None
373-
}
374-
}
375-
376367
fn llvm_field_index(&self, index: usize) -> u64 {
377368
match self.abi {
378369
layout::Abi::Scalar(_) |

0 commit comments

Comments
 (0)