Auto merge of #88839 - nbdd0121:alignof, r=nagisa
Introduce NullOp::AlignOf This PR introduces `Rvalue::NullaryOp(NullOp::AlignOf, ty)`, which will be lowered from `align_of`, similar to `size_of` lowering to `Rvalue::NullaryOp(NullOp::SizeOf, ty)`. The changes are originally part of #88700 but since it's not dependent on other changes and could have performance impact on its own, it's separated into its own PR.
This commit is contained in:
commit
02d3c132ae
11
src/base.rs
11
src/base.rs
@ -726,15 +726,20 @@ fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
|
|||||||
let ptr = fx.bcx.inst_results(call)[0];
|
let ptr = fx.bcx.inst_results(call)[0];
|
||||||
lval.write_cvalue(fx, CValue::by_val(ptr, box_layout));
|
lval.write_cvalue(fx, CValue::by_val(ptr, box_layout));
|
||||||
}
|
}
|
||||||
Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
|
Rvalue::NullaryOp(null_op, ty) => {
|
||||||
assert!(
|
assert!(
|
||||||
lval.layout()
|
lval.layout()
|
||||||
.ty
|
.ty
|
||||||
.is_sized(fx.tcx.at(stmt.source_info.span), ParamEnv::reveal_all())
|
.is_sized(fx.tcx.at(stmt.source_info.span), ParamEnv::reveal_all())
|
||||||
);
|
);
|
||||||
let ty_size = fx.layout_of(fx.monomorphize(ty)).size.bytes();
|
let layout = fx.layout_of(fx.monomorphize(ty));
|
||||||
|
let val = match null_op {
|
||||||
|
NullOp::SizeOf => layout.size.bytes(),
|
||||||
|
NullOp::AlignOf => layout.align.abi.bytes(),
|
||||||
|
NullOp::Box => unreachable!(),
|
||||||
|
};
|
||||||
let val =
|
let val =
|
||||||
CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), ty_size.into());
|
CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), val.into());
|
||||||
lval.write_cvalue(fx, val);
|
lval.write_cvalue(fx, val);
|
||||||
}
|
}
|
||||||
Rvalue::Aggregate(ref kind, ref operands) => match kind.as_ref() {
|
Rvalue::Aggregate(ref kind, ref operands) => match kind.as_ref() {
|
||||||
|
@ -823,7 +823,7 @@ fn swap(bcx: &mut FunctionBuilder<'_>, v: Value) -> Value {
|
|||||||
dest.write_cvalue(fx, val);
|
dest.write_cvalue(fx, val);
|
||||||
};
|
};
|
||||||
|
|
||||||
pref_align_of | min_align_of | needs_drop | type_id | type_name | variant_count, () {
|
pref_align_of | needs_drop | type_id | type_name | variant_count, () {
|
||||||
let const_val =
|
let const_val =
|
||||||
fx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap();
|
fx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap();
|
||||||
let val = crate::constant::codegen_const_value(
|
let val = crate::constant::codegen_const_value(
|
||||||
|
Loading…
Reference in New Issue
Block a user