Skip to content

Commit

Permalink
rustc_trans: remove primitive_align optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Nov 19, 2017
1 parent 88e4d2c commit 89e4373
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 55 deletions.
45 changes: 8 additions & 37 deletions src/librustc/ty/layout.rs
Expand Up @@ -847,7 +847,6 @@ pub struct LayoutDetails {
pub fields: FieldPlacement,
pub abi: Abi,
pub align: Align,
pub primitive_align: Align,
pub size: Size
}

Expand All @@ -861,7 +860,6 @@ impl LayoutDetails {
abi: Abi::Scalar(scalar),
size,
align,
primitive_align: align
}
}

Expand All @@ -872,7 +870,6 @@ impl LayoutDetails {
fields: FieldPlacement::Union(field_count),
abi: Abi::Uninhabited,
align,
primitive_align: align,
size: Size::from_bytes(0)
}
}
Expand Down Expand Up @@ -935,7 +932,6 @@ impl<'a, 'tcx> LayoutDetails {
},
abi: Abi::ScalarPair(a, b),
align,
primitive_align: align,
size
}
};
Expand All @@ -955,14 +951,12 @@ impl<'a, 'tcx> LayoutDetails {
bug!("struct cannot be packed and aligned");
}

let base_align = if packed {
let mut align = if packed {
dl.i8_align
} else {
dl.aggregate_align
};

let mut align = base_align;
let mut primitive_align = base_align;
let mut sized = true;
let mut offsets = vec![Size::from_bytes(0); fields.len()];
let mut inverse_memory_index: Vec<u32> = (0..fields.len() as u32).collect();
Expand Down Expand Up @@ -1012,7 +1006,6 @@ impl<'a, 'tcx> LayoutDetails {
if !packed {
let discr_align = discr.align(dl);
align = align.max(discr_align);
primitive_align = primitive_align.max(discr_align);
}
}

Expand All @@ -1035,7 +1028,6 @@ impl<'a, 'tcx> LayoutDetails {
if !packed {
offset = offset.abi_align(field.align);
align = align.max(field.align);
primitive_align = primitive_align.max(field.primitive_align);
}

debug!("univariant offset: {:?} field: {:#?}", offset, field);
Expand Down Expand Up @@ -1134,7 +1126,6 @@ impl<'a, 'tcx> LayoutDetails {
if offsets[i] == pair_offsets[0] &&
offsets[j] == pair_offsets[1] &&
align == pair.align &&
primitive_align == pair.primitive_align &&
size == pair.size {
// We can use `ScalarPair` only when it matches our
// already computed layout (including `#[repr(C)]`).
Expand All @@ -1155,7 +1146,6 @@ impl<'a, 'tcx> LayoutDetails {
},
abi,
align,
primitive_align,
size
})
};
Expand Down Expand Up @@ -1255,7 +1245,6 @@ impl<'a, 'tcx> LayoutDetails {
packed: false
},
align: element.align,
primitive_align: element.primitive_align,
size
})
}
Expand All @@ -1272,7 +1261,6 @@ impl<'a, 'tcx> LayoutDetails {
packed: false
},
align: element.align,
primitive_align: element.primitive_align,
size: Size::from_bytes(0)
})
}
Expand All @@ -1288,7 +1276,6 @@ impl<'a, 'tcx> LayoutDetails {
packed: false
},
align: dl.i8_align,
primitive_align: dl.i8_align,
size: Size::from_bytes(0)
})
}
Expand Down Expand Up @@ -1359,7 +1346,6 @@ impl<'a, 'tcx> LayoutDetails {
abi: Abi::Vector,
size,
align,
primitive_align: align
})
}

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

let mut primitive_align = if def.repr.packed() {
let mut align = if def.repr.packed() {
dl.i8_align
} else {
dl.aggregate_align
};

let mut align = if def.repr.align > 0 {
if def.repr.align > 0 {
let repr_align = def.repr.align as u64;
primitive_align.max(
Align::from_bytes(repr_align, repr_align).unwrap())
} else {
primitive_align
};
align = align.max(
Align::from_bytes(repr_align, repr_align).unwrap());
}

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

if !packed {
align = align.max(field.align);
primitive_align = primitive_align.max(field.primitive_align);
}
size = cmp::max(size, field.size);
}
Expand All @@ -1422,7 +1405,6 @@ impl<'a, 'tcx> LayoutDetails {
packed
},
align,
primitive_align,
size: size.abi_align(align)
}));
}
Expand Down Expand Up @@ -1519,12 +1501,7 @@ impl<'a, 'tcx> LayoutDetails {
}).collect::<Result<Vec<_>, _>>()?;

let offset = st[i].fields.offset(field_index) + offset;
let LayoutDetails {
size,
mut align,
mut primitive_align,
..
} = st[i];
let LayoutDetails { size, mut align, .. } = st[i];

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

return Ok(tcx.intern_layout(LayoutDetails {
variants: Variants::NicheFilling {
Expand All @@ -1558,7 +1534,6 @@ impl<'a, 'tcx> LayoutDetails {
abi,
size,
align,
primitive_align
}));
}
}
Expand All @@ -1577,7 +1552,6 @@ impl<'a, 'tcx> LayoutDetails {
let (min_ity, signed) = Integer::repr_discr(tcx, ty, &def.repr, min, max);

let mut align = dl.aggregate_align;
let mut primitive_align = dl.aggregate_align;
let mut size = Size::from_bytes(0);

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

Expand Down Expand Up @@ -1692,7 +1665,6 @@ impl<'a, 'tcx> LayoutDetails {
fields: FieldPlacement::Union(1),
abi,
align,
primitive_align,
size
})
}
Expand Down Expand Up @@ -2465,8 +2437,7 @@ impl_stable_hash_for!(struct ::ty::layout::LayoutDetails {
fields,
abi,
size,
align,
primitive_align
align
});

impl_stable_hash_for!(enum ::ty::layout::Integer {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/abi.rs
Expand Up @@ -585,7 +585,7 @@ impl<'a, 'tcx> ArgType<'tcx> {
// bitcasting to the struct type yields invalid cast errors.

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

Expand Down
8 changes: 3 additions & 5 deletions src/librustc_trans/builder.rs
Expand Up @@ -488,15 +488,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}

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

pub fn dynamic_alloca(&self, ty: Type, name: &str, align: Option<Align>) -> ValueRef {
pub fn dynamic_alloca(&self, ty: Type, name: &str, align: Align) -> ValueRef {
self.count_insn("alloca");
unsafe {
let alloca = if name.is_empty() {
Expand All @@ -506,9 +506,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
llvm::LLVMBuildAlloca(self.llbuilder, ty.to_ref(),
name.as_ptr())
};
if let Some(align) = align {
llvm::LLVMSetAlignment(alloca, align.abi() as c_uint);
}
llvm::LLVMSetAlignment(alloca, align.abi() as c_uint);
alloca
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/intrinsic.rs
Expand Up @@ -817,7 +817,7 @@ fn trans_msvc_try<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
//
// More information can be found in libstd's seh.rs implementation.
let i64p = Type::i64(ccx).ptr_to();
let slot = bcx.alloca(i64p, "slot", None);
let slot = bcx.alloca(i64p, "slot", ccx.data_layout().pointer_align);
bcx.invoke(func, &[data], normal.llbb(), catchswitch.llbb(),
None);

Expand Down
3 changes: 1 addition & 2 deletions src/librustc_trans/mir/lvalue.rs
Expand Up @@ -103,8 +103,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
pub fn alloca(bcx: &Builder<'a, 'tcx>, layout: TyLayout<'tcx>, name: &str)
-> LvalueRef<'tcx> {
debug!("alloca({:?}: {:?})", name, layout);
let tmp = bcx.alloca(
layout.llvm_type(bcx.ccx), name, layout.over_align());
let tmp = bcx.alloca(layout.llvm_type(bcx.ccx), name, layout.align);
Self::new_sized(tmp, layout, Alignment::AbiAligned)
}

Expand Down
9 changes: 0 additions & 9 deletions src/librustc_trans/type_of.rs
Expand Up @@ -185,7 +185,6 @@ pub trait LayoutLlvmExt<'tcx> {
fn immediate_llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> Type;
fn scalar_pair_element_llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>,
index: usize) -> Type;
fn over_align(&self) -> Option<Align>;
fn llvm_field_index(&self, index: usize) -> u64;
fn pointee_info_at<'a>(&self, ccx: &CrateContext<'a, 'tcx>, offset: Size)
-> Option<PointeeInfo>;
Expand Down Expand Up @@ -365,14 +364,6 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
}
}

fn over_align(&self) -> Option<Align> {
if self.align != self.primitive_align {
Some(self.align)
} else {
None
}
}

fn llvm_field_index(&self, index: usize) -> u64 {
match self.abi {
layout::Abi::Scalar(_) |
Expand Down

0 comments on commit 89e4373

Please sign in to comment.