Skip to content

Commit 74f3916

Browse files
committed
Sync from rust be16c61
2 parents d628444 + b867d41 commit 74f3916

File tree

7 files changed

+99
-95
lines changed

7 files changed

+99
-95
lines changed

src/abi/mod.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fn clif_sig_from_fn_abi<'tcx>(
2323
) -> Signature {
2424
let call_conv = match fn_abi.conv {
2525
Conv::Rust | Conv::C => default_call_conv,
26+
Conv::RustCold => CallConv::Cold,
2627
Conv::X86_64SysV => CallConv::SystemV,
2728
Conv::X86_64Win64 => CallConv::WindowsFastcall,
2829
Conv::ArmAapcs
@@ -312,13 +313,14 @@ pub(crate) fn codegen_terminator_call<'tcx>(
312313
source_info: mir::SourceInfo,
313314
func: &Operand<'tcx>,
314315
args: &[Operand<'tcx>],
315-
mir_dest: Option<(Place<'tcx>, BasicBlock)>,
316+
destination: Place<'tcx>,
317+
target: Option<BasicBlock>,
316318
) {
317319
let fn_ty = fx.monomorphize(func.ty(fx.mir, fx.tcx));
318320
let fn_sig =
319321
fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), fn_ty.fn_sig(fx.tcx));
320322

321-
let destination = mir_dest.map(|(place, bb)| (codegen_place(fx, place), bb));
323+
let ret_place = codegen_place(fx, destination);
322324

323325
// Handle special calls like instrinsics and empty drop glue.
324326
let instance = if let ty::FnDef(def_id, substs) = *fn_ty.kind() {
@@ -333,7 +335,8 @@ pub(crate) fn codegen_terminator_call<'tcx>(
333335
&fx.tcx.symbol_name(instance).name,
334336
substs,
335337
args,
336-
destination,
338+
ret_place,
339+
target,
337340
);
338341
return;
339342
}
@@ -344,14 +347,15 @@ pub(crate) fn codegen_terminator_call<'tcx>(
344347
fx,
345348
instance,
346349
args,
347-
destination,
350+
ret_place,
351+
target,
348352
source_info,
349353
);
350354
return;
351355
}
352356
InstanceDef::DropGlue(_, None) => {
353357
// empty drop glue - a nop.
354-
let (_, dest) = destination.expect("Non terminating drop_in_place_real???");
358+
let dest = target.expect("Non terminating drop_in_place_real???");
355359
let ret_block = fx.get_block(dest);
356360
fx.bcx.ins().jump(ret_block, &[]);
357361
return;
@@ -377,7 +381,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
377381
.unwrap_or(false);
378382
if is_cold {
379383
fx.bcx.set_cold_block(fx.bcx.current_block().unwrap());
380-
if let Some((_place, destination_block)) = destination {
384+
if let Some(destination_block) = target {
381385
fx.bcx.set_cold_block(fx.get_block(destination_block));
382386
}
383387
}
@@ -459,7 +463,6 @@ pub(crate) fn codegen_terminator_call<'tcx>(
459463
}
460464
};
461465

462-
let ret_place = destination.map(|(place, _)| place);
463466
self::returning::codegen_with_call_return_arg(fx, &fn_abi.ret, ret_place, |fx, return_ptr| {
464467
let call_args = return_ptr
465468
.into_iter()
@@ -511,7 +514,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
511514
call_inst
512515
});
513516

514-
if let Some((_, dest)) = destination {
517+
if let Some(dest) = target {
515518
let ret_block = fx.get_block(dest);
516519
fx.bcx.ins().jump(ret_block, &[]);
517520
} else {

src/abi/returning.rs

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,22 @@ pub(super) fn codegen_return_param<'tcx>(
5656
pub(super) fn codegen_with_call_return_arg<'tcx>(
5757
fx: &mut FunctionCx<'_, '_, 'tcx>,
5858
ret_arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
59-
ret_place: Option<CPlace<'tcx>>,
59+
ret_place: CPlace<'tcx>,
6060
f: impl FnOnce(&mut FunctionCx<'_, '_, 'tcx>, Option<Value>) -> Inst,
6161
) {
6262
let (ret_temp_place, return_ptr) = match ret_arg_abi.mode {
6363
PassMode::Ignore => (None, None),
64-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => match ret_place {
65-
Some(ret_place) if matches!(ret_place.inner(), CPlaceInner::Addr(_, None)) => {
64+
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
65+
if matches!(ret_place.inner(), CPlaceInner::Addr(_, None)) {
6666
// This is an optimization to prevent unnecessary copies of the return value when
6767
// the return place is already a memory place as opposed to a register.
6868
// This match arm can be safely removed.
6969
(None, Some(ret_place.to_ptr().get_addr(fx)))
70-
}
71-
_ => {
70+
} else {
7271
let place = CPlace::new_stack_slot(fx, ret_arg_abi.layout);
7372
(Some(place), Some(place.to_ptr().get_addr(fx)))
7473
}
75-
},
74+
}
7675
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
7776
unreachable!("unsized return value")
7877
}
@@ -84,39 +83,25 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
8483
match ret_arg_abi.mode {
8584
PassMode::Ignore => {}
8685
PassMode::Direct(_) => {
87-
if let Some(ret_place) = ret_place {
88-
let ret_val = fx.bcx.inst_results(call_inst)[0];
89-
ret_place.write_cvalue(fx, CValue::by_val(ret_val, ret_arg_abi.layout));
90-
}
86+
let ret_val = fx.bcx.inst_results(call_inst)[0];
87+
ret_place.write_cvalue(fx, CValue::by_val(ret_val, ret_arg_abi.layout));
9188
}
9289
PassMode::Pair(_, _) => {
93-
if let Some(ret_place) = ret_place {
94-
let ret_val_a = fx.bcx.inst_results(call_inst)[0];
95-
let ret_val_b = fx.bcx.inst_results(call_inst)[1];
96-
ret_place.write_cvalue(
97-
fx,
98-
CValue::by_val_pair(ret_val_a, ret_val_b, ret_arg_abi.layout),
99-
);
100-
}
90+
let ret_val_a = fx.bcx.inst_results(call_inst)[0];
91+
let ret_val_b = fx.bcx.inst_results(call_inst)[1];
92+
ret_place
93+
.write_cvalue(fx, CValue::by_val_pair(ret_val_a, ret_val_b, ret_arg_abi.layout));
10194
}
10295
PassMode::Cast(cast) => {
103-
if let Some(ret_place) = ret_place {
104-
let results = fx
105-
.bcx
106-
.inst_results(call_inst)
107-
.iter()
108-
.copied()
109-
.collect::<SmallVec<[Value; 2]>>();
110-
let result =
111-
super::pass_mode::from_casted_value(fx, &results, ret_place.layout(), cast);
112-
ret_place.write_cvalue(fx, result);
113-
}
96+
let results =
97+
fx.bcx.inst_results(call_inst).iter().copied().collect::<SmallVec<[Value; 2]>>();
98+
let result =
99+
super::pass_mode::from_casted_value(fx, &results, ret_place.layout(), cast);
100+
ret_place.write_cvalue(fx, result);
114101
}
115102
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
116-
if let (Some(ret_place), Some(ret_temp_place)) = (ret_place, ret_temp_place) {
117-
// Both ret_place and ret_temp_place must be Some. If ret_place is None, this is
118-
// a non-returning call. If ret_temp_place is None, it is not necessary to copy the
119-
// return value.
103+
if let Some(ret_temp_place) = ret_temp_place {
104+
// If ret_temp_place is None, it is not necessary to copy the return value.
120105
let ret_temp_value = ret_temp_place.to_cvalue(fx);
121106
ret_place.write_cvalue(fx, ret_temp_value);
122107
}

src/base.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) {
393393
func,
394394
args,
395395
destination,
396+
target,
396397
fn_span,
397398
cleanup: _,
398399
from_hir_call: _,
@@ -404,6 +405,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) {
404405
func,
405406
args,
406407
*destination,
408+
*target,
407409
)
408410
});
409411
}
@@ -605,7 +607,13 @@ fn codegen_stmt<'tcx>(
605607
let operand = codegen_operand(fx, operand);
606608
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
607609
}
608-
Rvalue::Cast(CastKind::Misc, ref operand, to_ty) => {
610+
Rvalue::Cast(
611+
CastKind::Misc
612+
| CastKind::PointerExposeAddress
613+
| CastKind::PointerFromExposedAddress,
614+
ref operand,
615+
to_ty,
616+
) => {
609617
let operand = codegen_operand(fx, operand);
610618
let from_ty = operand.layout().ty;
611619
let to_ty = fx.monomorphize(to_ty);

src/constant.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
542542
| TerminatorKind::FalseEdge { .. }
543543
| TerminatorKind::FalseUnwind { .. } => unreachable!(),
544544
TerminatorKind::InlineAsm { .. } => return None,
545-
TerminatorKind::Call { destination: Some((call_place, _)), .. }
546-
if call_place == place =>
545+
TerminatorKind::Call { destination, target: Some(_), .. }
546+
if destination == place =>
547547
{
548548
return None;
549549
}

src/driver/aot.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ fn emit_module(
6666
let work_product = if backend_config.disable_incr_cache {
6767
None
6868
} else {
69-
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(
70-
tcx.sess,
71-
&name,
72-
&Some(tmp_file.clone()),
73-
)
69+
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(tcx.sess, &name, &tmp_file)
7470
};
7571

7672
ModuleCodegenResult(
@@ -84,29 +80,24 @@ fn reuse_workproduct_for_cgu(
8480
cgu: &CodegenUnit<'_>,
8581
work_products: &mut FxHashMap<WorkProductId, WorkProduct>,
8682
) -> CompiledModule {
87-
let mut object = None;
88-
let work_product = cgu.work_product(tcx);
89-
if let Some(saved_file) = &work_product.saved_file {
90-
let obj_out =
91-
tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str()));
92-
object = Some(obj_out.clone());
93-
let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &saved_file);
94-
if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) {
95-
tcx.sess.err(&format!(
96-
"unable to copy {} to {}: {}",
97-
source_file.display(),
98-
obj_out.display(),
99-
err
100-
));
101-
}
83+
let work_product = cgu.previous_work_product(tcx);
84+
let obj_out = tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str()));
85+
let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &work_product.saved_file);
86+
if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) {
87+
tcx.sess.err(&format!(
88+
"unable to copy {} to {}: {}",
89+
source_file.display(),
90+
obj_out.display(),
91+
err
92+
));
10293
}
10394

10495
work_products.insert(cgu.work_product_id(), work_product);
10596

10697
CompiledModule {
10798
name: cgu.name().to_string(),
10899
kind: ModuleKind::Regular,
109-
object,
100+
object: Some(obj_out),
110101
dwarf_object: None,
111102
bytecode: None,
112103
}

src/intrinsics/llvm.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
1010
intrinsic: &str,
1111
_substs: SubstsRef<'tcx>,
1212
args: &[mir::Operand<'tcx>],
13-
destination: Option<(CPlace<'tcx>, BasicBlock)>,
13+
ret: CPlace<'tcx>,
14+
target: Option<BasicBlock>,
1415
) {
15-
let ret = destination.unwrap().0;
16-
1716
intrinsic_match! {
1817
fx, intrinsic, args,
1918
_ => {
@@ -126,7 +125,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
126125
};
127126
}
128127

129-
let dest = destination.expect("all llvm intrinsics used by stdlib should return").1;
128+
let dest = target.expect("all llvm intrinsics used by stdlib should return");
130129
let ret_block = fx.get_block(dest);
131130
fx.bcx.ins().jump(ret_block, &[]);
132131
}

0 commit comments

Comments
 (0)