Skip to content

Commit 6a0ce7f

Browse files
committed
Sync from rust 04ae501
2 parents e86b954 + 21a0c8e commit 6a0ce7f

File tree

5 files changed

+50
-22
lines changed

5 files changed

+50
-22
lines changed

src/abi/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,11 @@ pub(crate) fn codegen_terminator_call<'tcx>(
469469

470470
// FIXME find a cleaner way to support varargs
471471
if fn_sig.c_variadic {
472-
if fn_sig.abi != Abi::C {
473-
fx.tcx.sess.span_fatal(span, &format!("Variadic call for non-C abi {:?}", fn_sig.abi));
472+
if !matches!(fn_sig.abi, Abi::C { .. }) {
473+
fx.tcx.sess.span_fatal(
474+
span,
475+
&format!("Variadic call for non-C abi {:?}", fn_sig.abi),
476+
);
474477
}
475478
let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap();
476479
let abi_params = call_args

src/base.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,27 @@ fn codegen_stmt<'tcx>(
835835
}
836836
}
837837
StatementKind::Coverage { .. } => fx.tcx.sess.fatal("-Zcoverage is unimplemented"),
838+
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
839+
src,
840+
dst,
841+
count,
842+
}) => {
843+
let dst = codegen_operand(fx, dst);
844+
let pointee = dst
845+
.layout()
846+
.pointee_info_at(fx, rustc_target::abi::Size::ZERO)
847+
.expect("Expected pointer");
848+
let dst = dst.load_scalar(fx);
849+
let src = codegen_operand(fx, src).load_scalar(fx);
850+
let count = codegen_operand(fx, count).load_scalar(fx);
851+
let elem_size: u64 = pointee.size.bytes();
852+
let bytes = if elem_size != 1 {
853+
fx.bcx.ins().imul_imm(count, elem_size as i64)
854+
} else {
855+
count
856+
};
857+
fx.bcx.call_memcpy(fx.cx.module.target_config(), dst, src, bytes);
858+
}
838859
}
839860
}
840861

src/constant.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
88
use rustc_middle::mir::interpret::{
99
read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Pointer, Scalar,
1010
};
11-
use rustc_middle::ty::{Const, ConstKind};
11+
use rustc_middle::ty::ConstKind;
1212

1313
use cranelift_codegen::ir::GlobalValueData;
1414
use cranelift_module::*;
@@ -39,7 +39,10 @@ impl ConstantCx {
3939
pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
4040
let mut all_constants_ok = true;
4141
for constant in &fx.mir.required_consts {
42-
let const_ = fx.monomorphize(constant.literal);
42+
let const_ = match fx.monomorphize(constant.literal) {
43+
ConstantKind::Ty(ct) => ct,
44+
ConstantKind::Val(..) => continue,
45+
};
4346
match const_.val {
4447
ConstKind::Value(_) => {}
4548
ConstKind::Unevaluated(def, ref substs, promoted) => {
@@ -115,19 +118,17 @@ pub(crate) fn codegen_constant<'tcx>(
115118
fx: &mut FunctionCx<'_, '_, 'tcx>,
116119
constant: &Constant<'tcx>,
117120
) -> CValue<'tcx> {
118-
let const_ = fx.monomorphize(constant.literal);
121+
let const_ = match fx.monomorphize(constant.literal) {
122+
ConstantKind::Ty(ct) => ct,
123+
ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty),
124+
};
119125
let const_val = match const_.val {
120126
ConstKind::Value(const_val) => const_val,
121127
ConstKind::Unevaluated(def, ref substs, promoted) if fx.tcx.is_static(def.did) => {
122128
assert!(substs.is_empty());
123129
assert!(promoted.is_none());
124130

125-
return codegen_static_ref(
126-
fx,
127-
def.did,
128-
fx.layout_of(fx.monomorphize(&constant.literal.ty)),
129-
)
130-
.to_cvalue(fx);
131+
return codegen_static_ref(fx, def.did, fx.layout_of(const_.ty)).to_cvalue(fx);
131132
}
132133
ConstKind::Unevaluated(def, ref substs, promoted) => {
133134
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None) {
@@ -427,11 +428,14 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
427428
pub(crate) fn mir_operand_get_const_val<'tcx>(
428429
fx: &FunctionCx<'_, '_, 'tcx>,
429430
operand: &Operand<'tcx>,
430-
) -> Option<&'tcx Const<'tcx>> {
431+
) -> Option<ConstValue<'tcx>> {
431432
match operand {
432433
Operand::Copy(_) | Operand::Move(_) => None,
433-
Operand::Constant(const_) => {
434-
Some(fx.monomorphize(const_.literal).eval(fx.tcx, ParamEnv::reveal_all()))
435-
}
434+
Operand::Constant(const_) => match const_.literal {
435+
ConstantKind::Ty(const_) => {
436+
fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).val.try_to_value()
437+
}
438+
ConstantKind::Val(val, _) => Some(val),
439+
},
436440
}
437441
}

src/intrinsics/llvm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
5353
};
5454
llvm.x86.sse2.cmp.ps | llvm.x86.sse2.cmp.pd, (c x, c y, o kind) {
5555
let kind_const = crate::constant::mir_operand_get_const_val(fx, kind).expect("llvm.x86.sse2.cmp.* kind not const");
56-
let flt_cc = match kind_const.val.try_to_bits(Size::from_bytes(1)).unwrap_or_else(|| panic!("kind not scalar: {:?}", kind_const)) {
56+
let flt_cc = match kind_const.try_to_bits(Size::from_bytes(1)).unwrap_or_else(|| panic!("kind not scalar: {:?}", kind_const)) {
5757
0 => FloatCC::Equal,
5858
1 => FloatCC::LessThan,
5959
2 => FloatCC::LessThanOrEqual,
@@ -84,7 +84,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
8484
llvm.x86.sse2.psrli.d, (c a, o imm8) {
8585
let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8).expect("llvm.x86.sse2.psrli.d imm8 not const");
8686
simd_for_each_lane(fx, a, ret, |fx, _lane_layout, res_lane_layout, lane| {
87-
let res_lane = match imm8.val.try_to_bits(Size::from_bytes(4)).unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) {
87+
let res_lane = match imm8.try_to_bits(Size::from_bytes(4)).unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) {
8888
imm8 if imm8 < 32 => fx.bcx.ins().ushr_imm(lane, i64::from(imm8 as u8)),
8989
_ => fx.bcx.ins().iconst(types::I32, 0),
9090
};
@@ -94,7 +94,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
9494
llvm.x86.sse2.pslli.d, (c a, o imm8) {
9595
let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8).expect("llvm.x86.sse2.psrli.d imm8 not const");
9696
simd_for_each_lane(fx, a, ret, |fx, _lane_layout, res_lane_layout, lane| {
97-
let res_lane = match imm8.val.try_to_bits(Size::from_bytes(4)).unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) {
97+
let res_lane = match imm8.try_to_bits(Size::from_bytes(4)).unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) {
9898
imm8 if imm8 < 32 => fx.bcx.ins().ishl_imm(lane, i64::from(imm8 as u8)),
9999
_ => fx.bcx.ins().iconst(types::I32, 0),
100100
};

src/intrinsics/simd.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
8585
use rustc_middle::mir::interpret::*;
8686
let idx_const = crate::constant::mir_operand_get_const_val(fx, idx).expect("simd_shuffle* idx not const");
8787

88-
let idx_bytes = match idx_const.val {
89-
ty::ConstKind::Value(ConstValue::ByRef { alloc, offset }) => {
88+
let idx_bytes = match idx_const {
89+
ConstValue::ByRef { alloc, offset } => {
9090
let ptr = Pointer::new(AllocId(0 /* dummy */), offset);
9191
let size = Size::from_bytes(4 * ret_lane_count /* size_of([u32; ret_lane_count]) */);
9292
alloc.get_bytes(fx, ptr, size).unwrap()
@@ -130,7 +130,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
130130
);
131131
};
132132

133-
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).unwrap_or_else(|| panic!("kind not scalar: {:?}", idx_const));
133+
let idx = idx_const.try_to_bits(Size::from_bytes(4 /* u32*/)).unwrap_or_else(|| panic!("kind not scalar: {:?}", idx_const));
134134
let (lane_count, _lane_ty) = base.layout().ty.simd_size_and_type(fx.tcx);
135135
if idx >= lane_count.into() {
136136
fx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_insert] idx {} >= lane_count {}", idx, lane_count));
@@ -159,7 +159,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
159159
return;
160160
};
161161

162-
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).unwrap_or_else(|| panic!("kind not scalar: {:?}", idx_const));
162+
let idx = idx_const.try_to_bits(Size::from_bytes(4 /* u32*/)).unwrap_or_else(|| panic!("kind not scalar: {:?}", idx_const));
163163
let (lane_count, _lane_ty) = v.layout().ty.simd_size_and_type(fx.tcx);
164164
if idx >= lane_count.into() {
165165
fx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_extract] idx {} >= lane_count {}", idx, lane_count));

0 commit comments

Comments
 (0)