Skip to content

Commit 5e72aee

Browse files
committed
Let intrinsics use the SSA operand path
1 parent 8474bb0 commit 5e72aee

3 files changed

Lines changed: 32 additions & 22 deletions

File tree

src/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_middle::ty::{self, ExistentialTraitRef, Instance, Ty, TyCtxt};
1919
use rustc_session::Session;
2020
#[cfg(feature = "master")]
2121
use rustc_session::config::DebugInfo;
22-
use rustc_span::{DUMMY_SP, Span, respan};
22+
use rustc_span::{DUMMY_SP, Span, Symbol, respan};
2323
use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, TlsModel, X86Abi};
2424

2525
#[cfg(feature = "master")]
@@ -497,6 +497,10 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
497497
None
498498
}
499499
}
500+
501+
fn intrinsic_call_expects_place_always(&self, _name: Symbol) -> bool {
502+
true
503+
}
500504
}
501505

502506
impl<'gcc, 'tcx> HasTyCtxt<'tcx> for CodegenCx<'gcc, 'tcx> {

src/intrinsic/mod.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_abi::{BackendRepr, HasDataLayout, WrappingRange};
99
use rustc_codegen_ssa::base::wants_msvc_seh;
1010
use rustc_codegen_ssa::common::IntPredicate;
1111
use rustc_codegen_ssa::errors::InvalidMonomorphization;
12+
use rustc_codegen_ssa::mir::IntrinsicResult;
1213
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1314
use rustc_codegen_ssa::mir::place::{PlaceRef, PlaceValue};
1415
#[cfg(feature = "master")]
@@ -194,11 +195,14 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
194195
&mut self,
195196
instance: Instance<'tcx>,
196197
args: &[OperandRef<'tcx, RValue<'gcc>>],
197-
result: PlaceRef<'tcx, RValue<'gcc>>,
198+
result_layout: ty::layout::TyAndLayout<'tcx>,
199+
result_place: Option<PlaceValue<RValue<'gcc>>>,
198200
span: Span,
199-
) -> Result<(), Instance<'tcx>> {
201+
) -> IntrinsicResult<'tcx, RValue<'gcc>> {
200202
let tcx = self.tcx;
201203

204+
let result = PlaceRef { val: result_place.unwrap(), layout: result_layout };
205+
202206
let name = tcx.item_name(instance.def_id());
203207
let name_str = name.as_str();
204208
let fn_args = instance.args;
@@ -353,7 +357,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
353357
args[2].immediate(),
354358
result,
355359
);
356-
return Ok(());
360+
return IntrinsicResult::WroteIntoPlace;
357361
}
358362
sym::breakpoint => {
359363
unimplemented!();
@@ -375,12 +379,12 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
375379
sym::volatile_store => {
376380
let dst = args[0].deref(self.cx());
377381
args[1].val.volatile_store(self, dst);
378-
return Ok(());
382+
return IntrinsicResult::WroteIntoPlace;
379383
}
380384
sym::unaligned_volatile_store => {
381385
let dst = args[0].deref(self.cx());
382386
args[1].val.unaligned_volatile_store(self, dst);
383-
return Ok(());
387+
return IntrinsicResult::WroteIntoPlace;
384388
}
385389
sym::prefetch_read_data
386390
| sym::prefetch_write_data
@@ -448,12 +452,12 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
448452
_ => bug!(),
449453
},
450454
None => {
451-
tcx.dcx().emit_err(InvalidMonomorphization::BasicIntegerType {
455+
let err = tcx.dcx().emit_err(InvalidMonomorphization::BasicIntegerType {
452456
span,
453457
name,
454458
ty: args[0].layout.ty,
455459
});
456-
return Ok(());
460+
return IntrinsicResult::Err(err);
457461
}
458462
}
459463
}
@@ -544,7 +548,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
544548
extended_asm.set_volatile_flag(true);
545549

546550
// We have copied the value to `result` already.
547-
return Ok(());
551+
return IntrinsicResult::WroteIntoPlace;
548552
}
549553

550554
sym::ptr_mask => {
@@ -569,12 +573,15 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
569573
span,
570574
) {
571575
Ok(value) => value,
572-
Err(()) => return Ok(()),
576+
Err(err) => return IntrinsicResult::Err(err),
573577
}
574578
}
575579

576580
// Fall back to default body
577-
_ => return Err(Instance::new_raw(instance.def_id(), instance.args)),
581+
_ => {
582+
let fallback = Instance::new_raw(instance.def_id(), instance.args);
583+
return IntrinsicResult::Fallback(fallback);
584+
}
578585
};
579586

580587
if result.layout.ty.is_bool() {
@@ -583,7 +590,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
583590
} else if !result.layout.ty.is_unit() {
584591
self.store_to_place(value, result.val);
585592
}
586-
Ok(())
593+
IntrinsicResult::WroteIntoPlace
587594
}
588595

589596
fn codegen_llvm_intrinsic_call(
@@ -694,13 +701,12 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
694701
self.context.new_rvalue_from_int(self.int_type, 0)
695702
}
696703

697-
fn va_start(&mut self, _va_list: RValue<'gcc>) -> RValue<'gcc> {
704+
fn va_start(&mut self, _va_list: RValue<'gcc>) {
698705
unimplemented!();
699706
}
700707

701-
fn va_end(&mut self, _va_list: RValue<'gcc>) -> RValue<'gcc> {
708+
fn va_end(&mut self, _va_list: RValue<'gcc>) {
702709
// FIXME(antoyo): implement.
703-
self.context.new_rvalue_from_int(self.int_type, 0)
704710
}
705711

706712
fn retag_reg(&mut self, _ptr: Self::Value, _info: &RetagInfo<Self::Value>) -> Self::Value {

src/intrinsic/simd.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_hir as hir;
1717
use rustc_middle::mir::BinOp;
1818
use rustc_middle::ty::layout::HasTyCtxt;
1919
use rustc_middle::ty::{self, Ty};
20-
use rustc_span::{Span, Symbol, sym};
20+
use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
2121

2222
use crate::builder::Builder;
2323
#[cfg(not(feature = "master"))]
@@ -32,12 +32,12 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
3232
ret_ty: Ty<'tcx>,
3333
llret_ty: Type<'gcc>,
3434
span: Span,
35-
) -> Result<RValue<'gcc>, ()> {
35+
) -> Result<RValue<'gcc>, ErrorGuaranteed> {
3636
// macros for error handling:
3737
macro_rules! return_error {
3838
($err:expr) => {{
39-
bx.tcx.dcx().emit_err($err);
40-
return Err(());
39+
let err = bx.tcx.dcx().emit_err($err);
40+
return Err(err);
4141
}};
4242
}
4343
macro_rules! require {
@@ -803,11 +803,11 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
803803
bx: &mut Builder<'_, 'gcc, 'tcx>,
804804
span: Span,
805805
args: &[OperandRef<'tcx, RValue<'gcc>>],
806-
) -> Result<RValue<'gcc>, ()> {
806+
) -> Result<RValue<'gcc>, ErrorGuaranteed> {
807807
macro_rules! return_error {
808808
($err:expr) => {{
809-
bx.tcx.dcx().emit_err($err);
810-
return Err(());
809+
let err = bx.tcx.dcx().emit_err($err);
810+
return Err(err);
811811
}};
812812
}
813813
let ty::Float(ref f) = *in_elem.kind() else {

0 commit comments

Comments
 (0)