1 use rustc::ty::adjustment::PointerCast;
2 use rustc_index::vec::IndexVec;
6 pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
7 cx: &mut crate::CodegenCx<'clif, 'tcx, B>,
8 instance: Instance<'tcx>,
13 let mir = *tcx.instance_mir(instance.def);
16 let (name, sig) = get_function_name_and_sig(tcx, cx.module.isa().triple(), instance, false);
17 let func_id = cx.module.declare_function(&name, linkage, &sig).unwrap();
18 let mut debug_context = cx
21 .map(|debug_context| FunctionDebugContext::new(debug_context, instance, func_id, &name));
23 // Make FunctionBuilder
24 let context = &mut cx.cached_context;
26 context.func.name = ExternalName::user(0, func_id.as_u32());
27 context.func.signature = sig;
28 context.func.collect_debug_info();
29 let mut func_ctx = FunctionBuilderContext::new();
30 let mut bcx = FunctionBuilder::new(&mut context.func, &mut func_ctx);
33 let start_block = bcx.create_block();
34 let block_map: IndexVec<BasicBlock, Block> = (0..mir.basic_blocks().len()).map(|_| bcx.create_block()).collect();
37 let pointer_type = cx.module.target_config().pointer_type();
38 let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance);
40 let mut fx = FunctionCx {
50 local_map: HashMap::new(),
51 caller_location: None, // set by `codegen_fn_prelude`
52 cold_blocks: EntitySet::new(),
55 constants_cx: &mut cx.constants_cx,
56 vtables: &mut cx.vtables,
57 source_info_set: indexmap::IndexSet::new(),
60 let arg_uninhabited = fx.mir.args_iter().any(|arg| fx.layout_of(fx.monomorphize(&fx.mir.local_decls[arg].ty)).abi.is_uninhabited());
61 let is_call_once_for_box = name.starts_with("_ZN83_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$9call_once");
64 fx.bcx.append_block_params_for_function_params(fx.block_map[START_BLOCK]);
65 fx.bcx.switch_to_block(fx.block_map[START_BLOCK]);
66 crate::trap::trap_unreachable(&mut fx, "function has uninhabited argument");
67 } else if is_call_once_for_box {
68 // HACK implement `<Box<F> as FnOnce>::call_once` without `alloca`.
69 tcx.sess.time("codegen prelude", || crate::abi::codegen_fn_prelude(&mut fx, start_block, false));
70 fx.bcx.switch_to_block(fx.block_map[START_BLOCK]);
71 let bb_data = &fx.mir.basic_blocks()[START_BLOCK];
72 let destination = match &bb_data.terminator().kind {
73 TerminatorKind::Call {
80 assert_eq!(args.len(), 2);
82 let closure_arg = Local::new(1);
83 let closure_local = args[0].place().unwrap().as_local().unwrap();
84 assert_eq!(fx.mir.local_decls[closure_local].ty, fx.mir.local_decls[closure_arg].ty.builtin_deref(true).unwrap().ty);
85 let closure_deref = fx.local_map[&closure_arg].place_deref(&mut fx);
86 fx.local_map.insert(closure_local, closure_deref);
88 let args_arg = Local::new(2);
89 let args_local = args[1].place().unwrap().as_local().unwrap();
90 assert_eq!(fx.mir.local_decls[args_local].ty, fx.mir.local_decls[args_arg].ty);
91 fx.local_map.insert(args_local, fx.local_map[&args_arg]);
93 fx.tcx.sess.time("codegen call", || crate::abi::codegen_terminator_call(
95 bb_data.terminator().source_info.span,
100 destination.map(|(_ret_place, ret_block)| ret_block)
105 let destination = if let Some(destination) = destination {
106 fx.bcx.switch_to_block(fx.block_map[destination]);
107 let bb_data = &fx.mir.basic_blocks()[destination];
108 match &bb_data.terminator().kind {
109 TerminatorKind::Call {
117 Some((ret_place, _ret_block)) => {
118 fx.local_map.insert(ret_place.as_local().unwrap(), CPlace::no_place(fx.layout_of(fx.tcx.mk_unit())));
123 assert_eq!(args.len(), 1);
124 fx.tcx.sess.time("codegen call", || crate::abi::codegen_terminator_call(
126 bb_data.terminator().source_info.span,
131 destination.map(|(_ret_place, ret_block)| ret_block)
139 if let Some(destination) = destination {
140 fx.bcx.switch_to_block(fx.block_map[destination]);
141 let bb_data = &fx.mir.basic_blocks()[destination];
142 match &bb_data.terminator().kind {
143 TerminatorKind::Return => crate::abi::codegen_return(&mut fx),
148 tcx.sess.time("codegen clif ir", || {
149 tcx.sess.time("codegen prelude", || crate::abi::codegen_fn_prelude(&mut fx, start_block, true));
150 codegen_fn_content(&mut fx);
154 // Recover all necessary data from fx, before accessing func will prevent future access to it.
155 let instance = fx.instance;
156 let mut clif_comments = fx.clif_comments;
157 let source_info_set = fx.source_info_set;
158 let local_map = fx.local_map;
159 let cold_blocks = fx.cold_blocks;
161 #[cfg(debug_assertions)]
162 crate::pretty_clif::write_clif_file(cx.tcx, "unopt", instance, &context.func, &clif_comments, None);
165 verify_func(tcx, &clif_comments, &context.func);
167 // Perform rust specific optimizations
168 tcx.sess.time("optimize clif ir", || {
169 crate::optimize::optimize_function(tcx, instance, context, &cold_blocks, &mut clif_comments);
173 let module = &mut cx.module;
174 tcx.sess.time("define function", || module.define_function(func_id, context).unwrap());
176 // Write optimized function to file for debugging
177 #[cfg(debug_assertions)]
179 let value_ranges = context
180 .build_value_labels_ranges(cx.module.isa())
181 .expect("value location ranges");
183 crate::pretty_clif::write_clif_file(
193 // Define debuginfo for function
194 let isa = cx.module.isa();
195 tcx.sess.time("generate debug info", || {
198 .map(|x| x.define(context, isa, &source_info_set, local_map));
201 // Clear context to make it usable for the next function
205 pub fn verify_func(tcx: TyCtxt, writer: &crate::pretty_clif::CommentWriter, func: &Function) {
206 tcx.sess.time("verify clif ir", || {
207 let flags = settings::Flags::new(settings::builder());
208 match ::cranelift_codegen::verify_function(&func, &flags) {
211 tcx.sess.err(&format!("{:?}", err));
212 let pretty_error = ::cranelift_codegen::print_errors::pretty_verifier_error(
215 Some(Box::new(writer)),
219 .fatal(&format!("cranelift verify error:\n{}", pretty_error));
225 fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
226 for (bb, bb_data) in fx.mir.basic_blocks().iter_enumerated() {
227 let block = fx.get_block(bb);
228 fx.bcx.switch_to_block(block);
230 if bb_data.is_cleanup {
231 // Unwinding after panicking is not supported
234 // FIXME once unwinding is supported uncomment next lines
235 // // Unwinding is unlikely to happen, so mark cleanup block's as cold.
236 // fx.cold_blocks.insert(block);
240 for stmt in &bb_data.statements {
241 fx.set_debug_loc(stmt.source_info);
242 trans_stmt(fx, block, stmt);
245 #[cfg(debug_assertions)]
247 let mut terminator_head = "\n".to_string();
251 .fmt_head(&mut terminator_head)
253 let inst = fx.bcx.func.layout.last_inst(block).unwrap();
254 fx.add_comment(inst, terminator_head);
257 fx.set_debug_loc(bb_data.terminator().source_info);
259 match &bb_data.terminator().kind {
260 TerminatorKind::Goto { target } => {
261 let block = fx.get_block(*target);
262 fx.bcx.ins().jump(block, &[]);
264 TerminatorKind::Return => {
265 crate::abi::codegen_return(fx);
267 TerminatorKind::Assert {
274 if !fx.tcx.sess.overflow_checks() {
275 if let mir::AssertKind::OverflowNeg = *msg {
276 let target = fx.get_block(*target);
277 fx.bcx.ins().jump(target, &[]);
281 let cond = trans_operand(fx, cond).load_scalar(fx);
283 let target = fx.get_block(*target);
284 let failure = fx.bcx.create_block();
285 fx.cold_blocks.insert(failure);
288 fx.bcx.ins().brz(cond, failure, &[]);
290 fx.bcx.ins().brnz(cond, failure, &[]);
292 fx.bcx.ins().jump(target, &[]);
294 fx.bcx.switch_to_block(failure);
298 "[panic] Assert {:?} at {:?} failed.",
300 bb_data.terminator().source_info.span
305 TerminatorKind::SwitchInt {
311 let discr = trans_operand(fx, discr).load_scalar(fx);
312 let mut switch = ::cranelift_frontend::Switch::new();
313 for (i, value) in values.iter().enumerate() {
314 let block = fx.get_block(targets[i]);
315 switch.set_entry(*value as u64, block);
317 let otherwise_block = fx.get_block(targets[targets.len() - 1]);
318 switch.emit(&mut fx.bcx, discr, otherwise_block);
320 TerminatorKind::Call {
327 fx.tcx.sess.time("codegen call", || crate::abi::codegen_terminator_call(
329 bb_data.terminator().source_info.span,
335 TerminatorKind::Resume | TerminatorKind::Abort => {
336 trap_unreachable(fx, "[corruption] Unwinding bb reached.");
338 TerminatorKind::Unreachable => {
339 trap_unreachable(fx, "[corruption] Hit unreachable code.");
341 TerminatorKind::Yield { .. }
342 | TerminatorKind::FalseEdges { .. }
343 | TerminatorKind::FalseUnwind { .. }
344 | TerminatorKind::DropAndReplace { .. }
345 | TerminatorKind::GeneratorDrop => {
346 bug!("shouldn't exist at trans {:?}", bb_data.terminator());
348 TerminatorKind::Drop {
353 let drop_place = trans_place(fx, location);
354 crate::abi::codegen_drop(fx, bb_data.terminator().source_info.span, drop_place);
356 let target_block = fx.get_block(*target);
357 fx.bcx.ins().jump(target_block, &[]);
362 fx.bcx.seal_all_blocks();
367 fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
368 #[allow(unused_variables)]
370 stmt: &Statement<'tcx>,
372 let _print_guard = PrintOnPanic(|| format!("stmt {:?}", stmt));
374 fx.set_debug_loc(stmt.source_info);
376 #[cfg(false_debug_assertions)]
378 StatementKind::StorageLive(..) | StatementKind::StorageDead(..) => {} // Those are not very useful
380 let inst = fx.bcx.func.layout.last_inst(cur_block).unwrap();
381 fx.add_comment(inst, format!("{:?}", stmt));
386 StatementKind::SetDiscriminant {
390 let place = trans_place(fx, place);
391 crate::discriminant::codegen_set_discriminant(fx, place, *variant_index);
393 StatementKind::Assign(to_place_and_rval) => {
394 let lval = trans_place(fx, &to_place_and_rval.0);
395 let dest_layout = lval.layout();
396 match &to_place_and_rval.1 {
397 Rvalue::Use(operand) => {
398 let val = trans_operand(fx, operand);
399 lval.write_cvalue(fx, val);
401 Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
402 let place = trans_place(fx, place);
403 place.write_place_ref(fx, lval);
405 Rvalue::BinaryOp(bin_op, lhs, rhs) => {
406 let lhs = trans_operand(fx, lhs);
407 let rhs = trans_operand(fx, rhs);
409 let res = crate::num::codegen_binop(fx, *bin_op, lhs, rhs);
410 lval.write_cvalue(fx, res);
412 Rvalue::CheckedBinaryOp(bin_op, lhs, rhs) => {
413 let lhs = trans_operand(fx, lhs);
414 let rhs = trans_operand(fx, rhs);
416 let res = if !fx.tcx.sess.overflow_checks() {
418 crate::num::trans_int_binop(fx, *bin_op, lhs, rhs).load_scalar(fx);
419 let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
420 CValue::by_val_pair(val, is_overflow, lval.layout())
422 crate::num::trans_checked_int_binop(fx, *bin_op, lhs, rhs)
425 lval.write_cvalue(fx, res);
427 Rvalue::UnaryOp(un_op, operand) => {
428 let operand = trans_operand(fx, operand);
429 let layout = operand.layout();
430 let val = operand.load_scalar(fx);
431 let res = match un_op {
433 match layout.ty.kind {
435 let val = fx.bcx.ins().uextend(types::I32, val); // WORKAROUND for CraneStation/cranelift#466
436 let res = fx.bcx.ins().icmp_imm(IntCC::Equal, val, 0);
437 CValue::by_val(fx.bcx.ins().bint(types::I8, res), layout)
439 ty::Uint(_) | ty::Int(_) => {
440 CValue::by_val(fx.bcx.ins().bnot(val), layout)
442 _ => unreachable!("un op Not for {:?}", layout.ty),
445 UnOp::Neg => match layout.ty.kind {
446 ty::Int(IntTy::I128) => {
447 // FIXME remove this case once ineg.i128 works
448 let zero = CValue::const_val(fx, layout, 0);
449 crate::num::trans_int_binop(fx, BinOp::Sub, zero, operand)
452 CValue::by_val(fx.bcx.ins().ineg(val), layout)
455 CValue::by_val(fx.bcx.ins().fneg(val), layout)
457 _ => unreachable!("un op Neg for {:?}", layout.ty),
460 lval.write_cvalue(fx, res);
462 Rvalue::Cast(CastKind::Pointer(PointerCast::ReifyFnPointer), operand, to_ty) => {
463 let from_ty = fx.monomorphize(&operand.ty(&fx.mir.local_decls, fx.tcx));
464 let to_layout = fx.layout_of(fx.monomorphize(to_ty));
466 ty::FnDef(def_id, substs) => {
467 let func_ref = fx.get_function_ref(
468 Instance::resolve_for_fn_ptr(fx.tcx, ParamEnv::reveal_all(), def_id, substs)
471 let func_addr = fx.bcx.ins().func_addr(fx.pointer_type, func_ref);
472 lval.write_cvalue(fx, CValue::by_val(func_addr, to_layout));
474 _ => bug!("Trying to ReifyFnPointer on non FnDef {:?}", from_ty),
477 Rvalue::Cast(CastKind::Pointer(PointerCast::UnsafeFnPointer), operand, to_ty)
478 | Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), operand, to_ty)
479 | Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), operand, to_ty) => {
480 let to_layout = fx.layout_of(fx.monomorphize(to_ty));
481 let operand = trans_operand(fx, operand);
482 lval.write_cvalue(fx, operand.unchecked_cast_to(to_layout));
484 Rvalue::Cast(CastKind::Misc, operand, to_ty) => {
485 let operand = trans_operand(fx, operand);
486 let from_ty = operand.layout().ty;
487 let to_ty = fx.monomorphize(to_ty);
490 fx: &FunctionCx<'_, 'tcx, impl Backend>,
493 ty.builtin_deref(true)
498 }| has_ptr_meta(fx.tcx, pointee_ty),
503 if is_fat_ptr(fx, from_ty) {
504 if is_fat_ptr(fx, to_ty) {
505 // fat-ptr -> fat-ptr
506 lval.write_cvalue(fx, operand.unchecked_cast_to(dest_layout));
508 // fat-ptr -> thin-ptr
509 let (ptr, _extra) = operand.load_scalar_pair(fx);
510 lval.write_cvalue(fx, CValue::by_val(ptr, dest_layout))
512 } else if let ty::Adt(adt_def, _substs) = from_ty.kind {
513 // enum -> discriminant value
514 assert!(adt_def.is_enum());
516 ty::Uint(_) | ty::Int(_) => {}
517 _ => unreachable!("cast adt {} -> {}", from_ty, to_ty),
520 let discr = crate::discriminant::codegen_get_discriminant(
525 lval.write_cvalue(fx, discr);
527 let to_clif_ty = fx.clif_type(to_ty).unwrap();
528 let from = operand.load_scalar(fx);
530 let res = clif_int_or_float_cast(
537 lval.write_cvalue(fx, CValue::by_val(res, dest_layout));
540 Rvalue::Cast(CastKind::Pointer(PointerCast::ClosureFnPointer(_)), operand, _to_ty) => {
541 let operand = trans_operand(fx, operand);
542 match operand.layout().ty.kind {
543 ty::Closure(def_id, substs) => {
544 let instance = Instance::resolve_closure(
548 ty::ClosureKind::FnOnce,
550 let func_ref = fx.get_function_ref(instance);
551 let func_addr = fx.bcx.ins().func_addr(fx.pointer_type, func_ref);
552 lval.write_cvalue(fx, CValue::by_val(func_addr, lval.layout()));
554 _ => bug!("{} cannot be cast to a fn ptr", operand.layout().ty),
557 Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), operand, _to_ty) => {
558 let operand = trans_operand(fx, operand);
559 operand.unsize_value(fx, lval);
561 Rvalue::Discriminant(place) => {
562 let place = trans_place(fx, place);
563 let value = place.to_cvalue(fx);
565 crate::discriminant::codegen_get_discriminant(fx, value, dest_layout);
566 lval.write_cvalue(fx, discr);
568 Rvalue::Repeat(operand, times) => {
569 let operand = trans_operand(fx, operand);
571 let index = fx.bcx.ins().iconst(fx.pointer_type, i as i64);
572 let to = lval.place_index(fx, index);
573 to.write_cvalue(fx, operand);
576 Rvalue::Len(place) => {
577 let place = trans_place(fx, place);
578 let usize_layout = fx.layout_of(fx.tcx.types.usize);
579 let len = codegen_array_len(fx, place);
580 lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
582 Rvalue::NullaryOp(NullOp::Box, content_ty) => {
583 use rustc::middle::lang_items::ExchangeMallocFnLangItem;
585 let usize_type = fx.clif_type(fx.tcx.types.usize).unwrap();
586 let content_ty = fx.monomorphize(content_ty);
587 let layout = fx.layout_of(content_ty);
588 let llsize = fx.bcx.ins().iconst(usize_type, layout.size.bytes() as i64);
592 .iconst(usize_type, layout.align.abi.bytes() as i64);
593 let box_layout = fx.layout_of(fx.tcx.mk_box(content_ty));
596 let def_id = match fx.tcx.lang_items().require(ExchangeMallocFnLangItem) {
601 .fatal(&format!("allocation of `{}` {}", box_layout.ty, s));
604 let instance = ty::Instance::mono(fx.tcx, def_id);
605 let func_ref = fx.get_function_ref(instance);
606 let call = fx.bcx.ins().call(func_ref, &[llsize, llalign]);
607 let ptr = fx.bcx.inst_results(call)[0];
608 lval.write_cvalue(fx, CValue::by_val(ptr, box_layout));
610 Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
614 .is_sized(fx.tcx.at(stmt.source_info.span), ParamEnv::reveal_all()));
615 let ty_size = fx.layout_of(fx.monomorphize(ty)).size.bytes();
616 let val = CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), ty_size.into());
617 lval.write_cvalue(fx, val);
619 Rvalue::Aggregate(kind, operands) => match **kind {
620 AggregateKind::Array(_ty) => {
621 for (i, operand) in operands.into_iter().enumerate() {
622 let operand = trans_operand(fx, operand);
623 let index = fx.bcx.ins().iconst(fx.pointer_type, i as i64);
624 let to = lval.place_index(fx, index);
625 to.write_cvalue(fx, operand);
628 _ => unreachable!("shouldn't exist at trans {:?}", to_place_and_rval.1),
632 StatementKind::StorageLive(_)
633 | StatementKind::StorageDead(_)
635 | StatementKind::FakeRead(..)
636 | StatementKind::Retag { .. }
637 | StatementKind::AscribeUserType(..) => {}
639 StatementKind::InlineAsm(asm) => {
640 use rustc_ast::ast::Name;
646 let rustc_hir::InlineAsmInner {
647 asm: asm_code, // Name
648 outputs, // Vec<Name>
650 clobbers, // Vec<Name>
653 dialect: _, // rustc_ast::ast::AsmDialect
656 match &*asm_code.as_str() {
658 assert_eq!(inputs, &[Name::intern("r")]);
659 assert!(outputs.is_empty(), "{:?}", outputs);
663 "cpuid" | "cpuid\n" => {
664 assert_eq!(inputs, &[Name::intern("{eax}"), Name::intern("{ecx}")]);
666 assert_eq!(outputs.len(), 4);
667 for (i, c) in (&["={eax}", "={ebx}", "={ecx}", "={edx}"])
671 assert_eq!(&outputs[i].constraint.as_str(), c);
672 assert!(!outputs[i].is_rw);
673 assert!(!outputs[i].is_indirect);
676 assert_eq!(clobbers, &[Name::intern("rbx")]);
679 assert!(!alignstack);
681 crate::trap::trap_unimplemented(
683 "__cpuid_count arch intrinsic is not supported",
687 assert_eq!(inputs, &[Name::intern("{ecx}")]);
689 assert_eq!(outputs.len(), 2);
690 for (i, c) in (&["={eax}", "={edx}"]).iter().enumerate() {
691 assert_eq!(&outputs[i].constraint.as_str(), c);
692 assert!(!outputs[i].is_rw);
693 assert!(!outputs[i].is_indirect);
696 assert_eq!(clobbers, &[]);
699 assert!(!alignstack);
701 crate::trap::trap_unimplemented(fx, "_xgetbv arch intrinsic is not supported");
703 _ => unimpl!("Inline assembly is not supported"),
709 fn codegen_array_len<'tcx>(
710 fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
713 match place.layout().ty.kind {
714 ty::Array(_elem_ty, len) => {
715 let len = fx.monomorphize(&len)
716 .eval(fx.tcx, ParamEnv::reveal_all())
717 .eval_usize(fx.tcx, ParamEnv::reveal_all()) as i64;
718 fx.bcx.ins().iconst(fx.pointer_type, len)
720 ty::Slice(_elem_ty) => place
721 .to_ptr_maybe_unsized(fx)
723 .expect("Length metadata for slice place"),
724 _ => bug!("Rvalue::Len({:?})", place),
728 pub fn trans_place<'tcx>(
729 fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
732 let mut cplace = fx.get_local_place(place.local);
734 for elem in &*place.projection {
736 PlaceElem::Deref => {
737 cplace = cplace.place_deref(fx);
739 PlaceElem::Field(field, _ty) => {
740 cplace = cplace.place_field(fx, field);
742 PlaceElem::Index(local) => {
743 let index = fx.get_local_place(local).to_cvalue(fx).load_scalar(fx);
744 cplace = cplace.place_index(fx, index);
746 PlaceElem::ConstantIndex {
751 let index = if !from_end {
752 fx.bcx.ins().iconst(fx.pointer_type, offset as i64)
754 let len = codegen_array_len(fx, cplace);
755 fx.bcx.ins().iadd_imm(len, -(offset as i64))
757 cplace = cplace.place_index(fx, index);
759 PlaceElem::Subslice { from, to, from_end } => {
760 // These indices are generated by slice patterns.
761 // slice[from:-to] in Python terms.
763 match cplace.layout().ty.kind {
764 ty::Array(elem_ty, _len) => {
765 assert!(!from_end, "array subslices are never `from_end`");
766 let elem_layout = fx.layout_of(elem_ty);
767 let ptr = cplace.to_ptr(fx);
768 cplace = CPlace::for_ptr(
769 ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * from as i64),
770 fx.layout_of(fx.tcx.mk_array(elem_ty, to as u64 - from as u64)),
773 ty::Slice(elem_ty) => {
774 assert!(from_end, "slice subslices should be `from_end`");
775 let elem_layout = fx.layout_of(elem_ty);
776 let (ptr, len) = cplace.to_ptr_maybe_unsized(fx);
777 let len = len.unwrap();
778 cplace = CPlace::for_ptr_with_extra(
779 ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * from as i64),
780 fx.bcx.ins().iadd_imm(len, -(from as i64 + to as i64)),
787 PlaceElem::Downcast(_adt_def, variant) => {
788 cplace = cplace.downcast_variant(fx, variant);
796 pub fn trans_operand<'tcx>(
797 fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
798 operand: &Operand<'tcx>,
801 Operand::Move(place) | Operand::Copy(place) => {
802 let cplace = trans_place(fx, place);
805 Operand::Constant(const_) => crate::constant::trans_constant(fx, const_),