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