Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions compiler/rustc_public/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,21 @@ pub enum PassMode {
},
}

/// Attributes of a function argument that affect its ABI.
///
/// Not all internal compiler attributes are exposed here, as some are
/// LLVM-specific optimization hints. The internal representation is kept
/// private so it can be expanded in the future.
/// Attributes of a function argument or return value.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
pub struct ArgAttributes {
pub(crate) regular: ArgAttributeFlags,
pub(crate) arg_ext: ArgExtension,
pub(crate) pointee_size: Size,
pub(crate) pointee_align: Option<Align>,
}

impl ArgAttributes {
/// Return the calling convention and optimization flags for this argument.
pub fn regular(&self) -> ArgAttributeFlags {
self.regular
}

/// Return how this argument should be extended when passed in a register.
///
/// Relevant for integer arguments smaller than the register width.
Expand All @@ -128,12 +130,34 @@ impl ArgAttributes {
self.pointee_align
}

/// Return the minimum dereferenceable size of the pointee, if known.
/// Return the minimum dereferenceable size of the pointee, if it is non-null,
/// at function entry (for arguments) or return (for return values).
///
/// This alone does not guarantee dereferenceability for the duration of the call.
pub fn pointee_size(&self) -> Size {
self.pointee_size
}
}

/// Calling convention and optimization flags for a function argument or return value.
///
/// The capture flags overlap: `captures_none` implies `captures_address`, which
/// implies `captures_read_only`.
#[non_exhaustive]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize)]
pub struct ArgAttributeFlags {
pub captures_none: bool,
pub captures_address: bool,
pub captures_read_only: bool,
Comment thread
makai410 marked this conversation as resolved.
pub no_alias: bool,
pub non_null: bool,
pub read_only: bool,
pub in_reg: bool,
pub no_undef: bool,
pub writable: bool,
pub no_free: bool,
}

/// How a small integer argument should be extended to fill a register.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize)]
pub enum ArgExtension {
Expand Down
21 changes: 17 additions & 4 deletions compiler/rustc_public/src/unstable/convert/stable/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use rustc_target::callconv;

use crate::IndexedVal;
use crate::abi::{
AddressSpace, ArgAbi, ArgAttributes, ArgExtension, CallConvention, CastTarget, FieldsShape,
FloatLength, FnAbi, IndirectMode, IntegerLength, IntegerType, Layout, LayoutShape,
NumScalableVectors, PassMode, Primitive, Reg, RegKind, ReprFlags, ReprOptions, Scalar,
TagEncoding, TyAndLayout, Uniform, ValueRepr, VariantFields, VariantsShape, WrappingRange,
AddressSpace, ArgAbi, ArgAttributeFlags, ArgAttributes, ArgExtension, CallConvention,
CastTarget, FieldsShape, FloatLength, FnAbi, IndirectMode, IntegerLength, IntegerType, Layout,
LayoutShape, NumScalableVectors, PassMode, Primitive, Reg, RegKind, ReprFlags, ReprOptions,
Scalar, TagEncoding, TyAndLayout, Uniform, ValueRepr, VariantFields, VariantsShape,
WrappingRange,
};
use crate::compiler_interface::BridgeTys;
use crate::target::MachineSize as Size;
Expand Down Expand Up @@ -264,6 +265,18 @@ impl<'tcx> Stable<'tcx> for callconv::ArgAttributes {
_: &CompilerCtxt<'cx, BridgeTys>,
) -> Self::T {
ArgAttributes {
regular: ArgAttributeFlags {
captures_none: self.regular.contains(callconv::ArgAttribute::CapturesNone),
captures_address: self.regular.contains(callconv::ArgAttribute::CapturesAddress),
captures_read_only: self.regular.contains(callconv::ArgAttribute::CapturesReadOnly),
no_alias: self.regular.contains(callconv::ArgAttribute::NoAlias),
non_null: self.regular.contains(callconv::ArgAttribute::NonNull),
read_only: self.regular.contains(callconv::ArgAttribute::ReadOnly),
in_reg: self.regular.contains(callconv::ArgAttribute::InReg),
no_undef: self.regular.contains(callconv::ArgAttribute::NoUndef),
writable: self.regular.contains(callconv::ArgAttribute::Writable),
no_free: self.regular.contains(callconv::ArgAttribute::NoFree),
},
arg_ext: match self.arg_ext {
callconv::ArgExtension::None => ArgExtension::None,
callconv::ArgExtension::Zext => ArgExtension::Zext,
Expand Down
Loading
Loading