Skip to main content

rustc_codegen_ssa/traits/
intrinsic.rs

1use rustc_middle::ty;
2use rustc_span::Span;
3
4use super::BackendTypes;
5use crate::RetagInfo;
6use crate::mir::IntrinsicResult;
7use crate::mir::operand::OperandRef;
8use crate::mir::place::PlaceValue;
9
10pub trait IntrinsicCallBuilderMethods<'tcx>: BackendTypes {
11    /// Higher-level interface to emitting calls to intrinsics
12    ///
13    /// Remember to add all intrinsics here, in `compiler/rustc_hir_analysis/src/check/mod.rs`,
14    /// and in `library/core/src/intrinsics.rs`; if you need access to any LLVM intrinsics,
15    /// add them to `compiler/rustc_codegen_llvm/src/context.rs`.
16    /// Returns `Fallback` if another instance should be called instead. This is used to invoke
17    /// intrinsic default bodies in case an intrinsic is not implemented by the backend.
18    ///
19    /// The `result_place` will be provided for things that weren't `LocalKind::SSA`.
20    /// If you need it for more things, see `intrinsic_call_expects_place_always`.
21    ///
22    /// NOTE: allowed to call [`BuilderMethods::call`]
23    ///
24    /// [`BuilderMethods::call`]: super::builder::BuilderMethods::call
25    fn codegen_intrinsic_call(
26        &mut self,
27        instance: ty::Instance<'tcx>,
28        args: &[OperandRef<'tcx, Self::Value>],
29        result_layout: ty::layout::TyAndLayout<'tcx>,
30        result_place: Option<PlaceValue<Self::Value>>,
31        span: Span,
32    ) -> IntrinsicResult<'tcx, Self::Value>;
33
34    fn codegen_llvm_intrinsic_call(
35        &mut self,
36        instance: ty::Instance<'tcx>,
37        args: &[OperandRef<'tcx, Self::Value>],
38        is_cleanup: bool,
39    ) -> Self::Value;
40
41    fn abort(&mut self);
42    fn assume(&mut self, val: Self::Value);
43    fn expect(&mut self, cond: Self::Value, expected: bool) -> Self::Value;
44    /// Trait method used to load a function while testing if it is associated with a type
45    /// identifier.
46    fn type_checked_load(
47        &mut self,
48        llvtable: Self::Value,
49        vtable_byte_offset: u64,
50        typeid: &[u8],
51    ) -> Self::Value;
52    /// Trait method used to inject `va_start` on the "spoofed" `VaList` in
53    /// Rust defined C-variadic functions.
54    fn va_start(&mut self, val: Self::Value);
55    /// Trait method used to inject `va_end` on the "spoofed" `VaList` before
56    /// Rust defined C-variadic functions return.
57    fn va_end(&mut self, val: Self::Value);
58    /// Trait method used to retag a pointer stored within a place.
59    fn retag_mem(&mut self, place: Self::Value, info: &RetagInfo<Self::Value>);
60    /// Trait method used to retag a pointer that has been loaded into a register.
61    fn retag_reg(&mut self, ptr: Self::Value, info: &RetagInfo<Self::Value>) -> Self::Value;
62}