Skip to main content

rustc_middle/ty/
offload_meta.rs

1use bitflags::bitflags;
2
3use crate::ty::{self, PseudoCanonicalInput, Ty, TyCtxt, TypingEnv};
4
5pub struct OffloadMetadata {
6    pub payload_size: u64,
7    pub mode: MappingFlags,
8}
9
10#[doc = r" Mirrors `OpenMPOffloadMappingFlags` from Clang/OpenMP."]
#[repr(transparent)]
pub struct MappingFlags(<MappingFlags as
    ::bitflags::__private::PublicFlags>::Internal);
#[automatically_derived]
impl ::core::fmt::Debug for MappingFlags {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_tuple_field1_finish(f, "MappingFlags",
            &&self.0)
    }
}
#[automatically_derived]
impl ::core::marker::Copy for MappingFlags { }
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for MappingFlags { }
#[automatically_derived]
impl ::core::clone::Clone for MappingFlags {
    #[inline]
    fn clone(&self) -> MappingFlags {
        let _:
                ::core::clone::AssertParamIsClone<<MappingFlags as
                ::bitflags::__private::PublicFlags>::Internal>;
        *self
    }
}
impl MappingFlags {
    #[doc = r" No flags."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const NONE: Self = Self::from_bits_retain(0x0);
    #[doc =
    r" Allocate memory on the device and move data from host to device."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const TO: Self = Self::from_bits_retain(0x01);
    #[doc =
    r" Allocate memory on the device and move data from device to host."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const FROM: Self = Self::from_bits_retain(0x02);
    #[doc =
    r" Always perform the requested mapping action, even if already mapped."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const ALWAYS: Self = Self::from_bits_retain(0x04);
    #[doc =
    r" Delete the element from the device environment, ignoring ref count."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const DELETE: Self = Self::from_bits_retain(0x08);
    #[doc = r" The element being mapped is a pointer-pointee pair."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const PTR_AND_OBJ: Self = Self::from_bits_retain(0x10);
    #[doc =
    r" The base address should be passed to the target kernel as argument."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const TARGET_PARAM: Self = Self::from_bits_retain(0x20);
    #[doc = r" The runtime must return the device pointer."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const RETURN_PARAM: Self = Self::from_bits_retain(0x40);
    #[doc = r" The reference being passed is a pointer to private data."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const PRIVATE: Self = Self::from_bits_retain(0x80);
    #[doc = r" Pass the element by value."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const LITERAL: Self = Self::from_bits_retain(0x100);
    #[doc = r" Implicit map (generated by compiler, not explicit in code)."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const IMPLICIT: Self = Self::from_bits_retain(0x200);
    #[doc = r" Hint to allocate memory close to the target device."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLOSE: Self = Self::from_bits_retain(0x400);
    #[doc = r" Reserved (0x800 in OpenMP for XLC compatibility)."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const RESERVED: Self = Self::from_bits_retain(0x800);
    #[doc = r" Require that the data is already allocated on the device."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const PRESENT: Self = Self::from_bits_retain(0x1000);
    #[doc =
    r" Increment/decrement a separate ref counter (OpenACC compatibility)."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const OMPX_HOLD: Self = Self::from_bits_retain(0x2000);
    #[doc = r" Used for non-contiguous list items in target update."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const NON_CONTIG: Self = Self::from_bits_retain(0x100000000000);
    #[doc = r" 16 MSBs indicate membership in a struct."]
    #[allow(deprecated, non_upper_case_globals,)]
    pub const MEMBER_OF: Self = Self::from_bits_retain(0xffff000000000000);
}
impl ::bitflags::Flags for MappingFlags {
    const FLAGS: &'static [::bitflags::Flag<MappingFlags>] =
        &[{

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("NONE", MappingFlags::NONE)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("TO", MappingFlags::TO)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("FROM", MappingFlags::FROM)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("ALWAYS", MappingFlags::ALWAYS)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("DELETE", MappingFlags::DELETE)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("PTR_AND_OBJ",
                            MappingFlags::PTR_AND_OBJ)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("TARGET_PARAM",
                            MappingFlags::TARGET_PARAM)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("RETURN_PARAM",
                            MappingFlags::RETURN_PARAM)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("PRIVATE", MappingFlags::PRIVATE)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("LITERAL", MappingFlags::LITERAL)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("IMPLICIT", MappingFlags::IMPLICIT)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLOSE", MappingFlags::CLOSE)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("RESERVED", MappingFlags::RESERVED)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("PRESENT", MappingFlags::PRESENT)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("OMPX_HOLD", MappingFlags::OMPX_HOLD)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("NON_CONTIG",
                            MappingFlags::NON_CONTIG)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("MEMBER_OF", MappingFlags::MEMBER_OF)
                    }];
    type Bits = u64;
    fn bits(&self) -> u64 { MappingFlags::bits(self) }
    fn from_bits_retain(bits: u64) -> MappingFlags {
        MappingFlags::from_bits_retain(bits)
    }
}
#[allow(dead_code, deprecated, unused_doc_comments, unused_attributes,
unused_mut, unused_imports, non_upper_case_globals, clippy ::
assign_op_pattern, clippy :: indexing_slicing, clippy :: same_name_method,
clippy :: iter_without_into_iter,)]
const _: () =
    {
        #[repr(transparent)]
        pub struct InternalBitFlags(u64);
        #[automatically_derived]
        #[doc(hidden)]
        unsafe impl ::core::clone::TrivialClone for InternalBitFlags { }
        #[automatically_derived]
        impl ::core::clone::Clone for InternalBitFlags {
            #[inline]
            fn clone(&self) -> InternalBitFlags {
                let _: ::core::clone::AssertParamIsClone<u64>;
                *self
            }
        }
        #[automatically_derived]
        impl ::core::marker::Copy for InternalBitFlags { }
        #[automatically_derived]
        impl ::core::marker::StructuralPartialEq for InternalBitFlags { }
        #[automatically_derived]
        impl ::core::cmp::PartialEq for InternalBitFlags {
            #[inline]
            fn eq(&self, other: &InternalBitFlags) -> bool {
                self.0 == other.0
            }
        }
        #[automatically_derived]
        impl ::core::cmp::Eq for InternalBitFlags {
            #[inline]
            #[doc(hidden)]
            #[coverage(off)]
            fn assert_receiver_is_total_eq(&self) {
                let _: ::core::cmp::AssertParamIsEq<u64>;
            }
        }
        #[automatically_derived]
        impl ::core::cmp::PartialOrd for InternalBitFlags {
            #[inline]
            fn partial_cmp(&self, other: &InternalBitFlags)
                -> ::core::option::Option<::core::cmp::Ordering> {
                ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
            }
        }
        #[automatically_derived]
        impl ::core::cmp::Ord for InternalBitFlags {
            #[inline]
            fn cmp(&self, other: &InternalBitFlags) -> ::core::cmp::Ordering {
                ::core::cmp::Ord::cmp(&self.0, &other.0)
            }
        }
        #[automatically_derived]
        impl ::core::hash::Hash for InternalBitFlags {
            #[inline]
            fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
                ::core::hash::Hash::hash(&self.0, state)
            }
        }
        impl ::bitflags::__private::PublicFlags for MappingFlags {
            type Primitive = u64;
            type Internal = InternalBitFlags;
        }
        impl ::bitflags::__private::core::default::Default for
            InternalBitFlags {
            #[inline]
            fn default() -> Self { InternalBitFlags::empty() }
        }
        impl ::bitflags::__private::core::fmt::Debug for InternalBitFlags {
            fn fmt(&self,
                f: &mut ::bitflags::__private::core::fmt::Formatter<'_>)
                -> ::bitflags::__private::core::fmt::Result {
                if self.is_empty() {
                    f.write_fmt(format_args!("{0:#x}",
                            <u64 as ::bitflags::Bits>::EMPTY))
                } else {
                    ::bitflags::__private::core::fmt::Display::fmt(self, f)
                }
            }
        }
        impl ::bitflags::__private::core::fmt::Display for InternalBitFlags {
            fn fmt(&self,
                f: &mut ::bitflags::__private::core::fmt::Formatter<'_>)
                -> ::bitflags::__private::core::fmt::Result {
                ::bitflags::parser::to_writer(&MappingFlags(*self), f)
            }
        }
        impl ::bitflags::__private::core::str::FromStr for InternalBitFlags {
            type Err = ::bitflags::parser::ParseError;
            fn from_str(s: &str)
                ->
                    ::bitflags::__private::core::result::Result<Self,
                    Self::Err> {
                ::bitflags::parser::from_str::<MappingFlags>(s).map(|flags|
                        flags.0)
            }
        }
        impl ::bitflags::__private::core::convert::AsRef<u64> for
            InternalBitFlags {
            fn as_ref(&self) -> &u64 { &self.0 }
        }
        impl ::bitflags::__private::core::convert::From<u64> for
            InternalBitFlags {
            fn from(bits: u64) -> Self { Self::from_bits_retain(bits) }
        }
        #[allow(dead_code, deprecated, unused_attributes)]
        impl InternalBitFlags {
            /// Get a flags value with all bits unset.
            #[inline]
            pub const fn empty() -> Self {
                Self(<u64 as ::bitflags::Bits>::EMPTY)
            }
            /// Get a flags value with all known bits set.
            #[inline]
            pub const fn all() -> Self {
                let mut truncated = <u64 as ::bitflags::Bits>::EMPTY;
                let mut i = 0;
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MappingFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                let _ = i;
                Self(truncated)
            }
            /// Get the underlying bits value.
            ///
            /// The returned value is exactly the bits set in this flags value.
            #[inline]
            pub const fn bits(&self) -> u64 { self.0 }
            /// Convert from a bits value.
            ///
            /// This method will return `None` if any unknown bits are set.
            #[inline]
            pub const fn from_bits(bits: u64)
                -> ::bitflags::__private::core::option::Option<Self> {
                let truncated = Self::from_bits_truncate(bits).0;
                if truncated == bits {
                    ::bitflags::__private::core::option::Option::Some(Self(bits))
                } else { ::bitflags::__private::core::option::Option::None }
            }
            /// Convert from a bits value, unsetting any unknown bits.
            #[inline]
            pub const fn from_bits_truncate(bits: u64) -> Self {
                Self(bits & Self::all().0)
            }
            /// Convert from a bits value exactly.
            #[inline]
            pub const fn from_bits_retain(bits: u64) -> Self { Self(bits) }
            /// Get a flags value with the bits of a flag with the given name set.
            ///
            /// This method will return `None` if `name` is empty or doesn't
            /// correspond to any named flag.
            #[inline]
            pub fn from_name(name: &str)
                -> ::bitflags::__private::core::option::Option<Self> {
                {
                    if name == "NONE" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::NONE.bits()));
                    }
                };
                ;
                {
                    if name == "TO" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::TO.bits()));
                    }
                };
                ;
                {
                    if name == "FROM" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::FROM.bits()));
                    }
                };
                ;
                {
                    if name == "ALWAYS" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::ALWAYS.bits()));
                    }
                };
                ;
                {
                    if name == "DELETE" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::DELETE.bits()));
                    }
                };
                ;
                {
                    if name == "PTR_AND_OBJ" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::PTR_AND_OBJ.bits()));
                    }
                };
                ;
                {
                    if name == "TARGET_PARAM" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::TARGET_PARAM.bits()));
                    }
                };
                ;
                {
                    if name == "RETURN_PARAM" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::RETURN_PARAM.bits()));
                    }
                };
                ;
                {
                    if name == "PRIVATE" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::PRIVATE.bits()));
                    }
                };
                ;
                {
                    if name == "LITERAL" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::LITERAL.bits()));
                    }
                };
                ;
                {
                    if name == "IMPLICIT" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::IMPLICIT.bits()));
                    }
                };
                ;
                {
                    if name == "CLOSE" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::CLOSE.bits()));
                    }
                };
                ;
                {
                    if name == "RESERVED" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::RESERVED.bits()));
                    }
                };
                ;
                {
                    if name == "PRESENT" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::PRESENT.bits()));
                    }
                };
                ;
                {
                    if name == "OMPX_HOLD" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::OMPX_HOLD.bits()));
                    }
                };
                ;
                {
                    if name == "NON_CONTIG" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::NON_CONTIG.bits()));
                    }
                };
                ;
                {
                    if name == "MEMBER_OF" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MappingFlags::MEMBER_OF.bits()));
                    }
                };
                ;
                let _ = name;
                ::bitflags::__private::core::option::Option::None
            }
            /// Whether all bits in this flags value are unset.
            #[inline]
            pub const fn is_empty(&self) -> bool {
                self.0 == <u64 as ::bitflags::Bits>::EMPTY
            }
            /// Whether all known bits in this flags value are set.
            #[inline]
            pub const fn is_all(&self) -> bool {
                Self::all().0 | self.0 == self.0
            }
            /// Whether any set bits in a source flags value are also set in a target flags value.
            #[inline]
            pub const fn intersects(&self, other: Self) -> bool {
                self.0 & other.0 != <u64 as ::bitflags::Bits>::EMPTY
            }
            /// Whether all set bits in a source flags value are also set in a target flags value.
            #[inline]
            pub const fn contains(&self, other: Self) -> bool {
                self.0 & other.0 == other.0
            }
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            pub fn insert(&mut self, other: Self) {
                *self = Self(self.0).union(other);
            }
            /// The intersection of a source flags value with the complement of a target flags
            /// value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `remove` won't truncate `other`, but the `!` operator will.
            #[inline]
            pub fn remove(&mut self, other: Self) {
                *self = Self(self.0).difference(other);
            }
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            pub fn toggle(&mut self, other: Self) {
                *self = Self(self.0).symmetric_difference(other);
            }
            /// Call `insert` when `value` is `true` or `remove` when `value` is `false`.
            #[inline]
            pub fn set(&mut self, other: Self, value: bool) {
                if value { self.insert(other); } else { self.remove(other); }
            }
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn intersection(self, other: Self) -> Self {
                Self(self.0 & other.0)
            }
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn union(self, other: Self) -> Self {
                Self(self.0 | other.0)
            }
            /// The intersection of a source flags value with the complement of a target flags
            /// value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            #[must_use]
            pub const fn difference(self, other: Self) -> Self {
                Self(self.0 & !other.0)
            }
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn symmetric_difference(self, other: Self) -> Self {
                Self(self.0 ^ other.0)
            }
            /// The bitwise negation (`!`) of the bits in a flags value, truncating the result.
            #[inline]
            #[must_use]
            pub const fn complement(self) -> Self {
                Self::from_bits_truncate(!self.0)
            }
        }
        impl ::bitflags::__private::core::fmt::Binary for InternalBitFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::Octal for InternalBitFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::LowerHex for InternalBitFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::UpperHex for InternalBitFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::ops::BitOr for InternalBitFlags {
            type Output = Self;
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            fn bitor(self, other: InternalBitFlags) -> Self {
                self.union(other)
            }
        }
        impl ::bitflags::__private::core::ops::BitOrAssign for
            InternalBitFlags {
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            fn bitor_assign(&mut self, other: Self) { self.insert(other); }
        }
        impl ::bitflags::__private::core::ops::BitXor for InternalBitFlags {
            type Output = Self;
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            fn bitxor(self, other: Self) -> Self {
                self.symmetric_difference(other)
            }
        }
        impl ::bitflags::__private::core::ops::BitXorAssign for
            InternalBitFlags {
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
        }
        impl ::bitflags::__private::core::ops::BitAnd for InternalBitFlags {
            type Output = Self;
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            fn bitand(self, other: Self) -> Self { self.intersection(other) }
        }
        impl ::bitflags::__private::core::ops::BitAndAssign for
            InternalBitFlags {
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            fn bitand_assign(&mut self, other: Self) {
                *self =
                    Self::from_bits_retain(self.bits()).intersection(other);
            }
        }
        impl ::bitflags::__private::core::ops::Sub for InternalBitFlags {
            type Output = Self;
            /// The intersection of a source flags value with the complement of a target flags value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            fn sub(self, other: Self) -> Self { self.difference(other) }
        }
        impl ::bitflags::__private::core::ops::SubAssign for InternalBitFlags
            {
            /// The intersection of a source flags value with the complement of a target flags value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            fn sub_assign(&mut self, other: Self) { self.remove(other); }
        }
        impl ::bitflags::__private::core::ops::Not for InternalBitFlags {
            type Output = Self;
            /// The bitwise negation (`!`) of the bits in a flags value, truncating the result.
            #[inline]
            fn not(self) -> Self { self.complement() }
        }
        impl ::bitflags::__private::core::iter::Extend<InternalBitFlags> for
            InternalBitFlags {
            /// The bitwise or (`|`) of the bits in each flags value.
            fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
                = Self>>(&mut self, iterator: T) {
                for item in iterator { self.insert(item) }
            }
        }
        impl ::bitflags::__private::core::iter::FromIterator<InternalBitFlags>
            for InternalBitFlags {
            /// The bitwise or (`|`) of the bits in each flags value.
            fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
                = Self>>(iterator: T) -> Self {
                use ::bitflags::__private::core::iter::Extend;
                let mut result = Self::empty();
                result.extend(iterator);
                result
            }
        }
        impl InternalBitFlags {
            /// Yield a set of contained flags values.
            ///
            /// Each yielded flags value will correspond to a defined named flag. Any unknown bits
            /// will be yielded together as a final flags value.
            #[inline]
            pub const fn iter(&self) -> ::bitflags::iter::Iter<MappingFlags> {
                ::bitflags::iter::Iter::__private_const_new(<MappingFlags as
                        ::bitflags::Flags>::FLAGS,
                    MappingFlags::from_bits_retain(self.bits()),
                    MappingFlags::from_bits_retain(self.bits()))
            }
            /// Yield a set of contained named flags values.
            ///
            /// This method is like [`iter`](#method.iter), except only yields bits in contained named flags.
            /// Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
            #[inline]
            pub const fn iter_names(&self)
                -> ::bitflags::iter::IterNames<MappingFlags> {
                ::bitflags::iter::IterNames::__private_const_new(<MappingFlags
                        as ::bitflags::Flags>::FLAGS,
                    MappingFlags::from_bits_retain(self.bits()),
                    MappingFlags::from_bits_retain(self.bits()))
            }
        }
        impl ::bitflags::__private::core::iter::IntoIterator for
            InternalBitFlags {
            type Item = MappingFlags;
            type IntoIter = ::bitflags::iter::Iter<MappingFlags>;
            fn into_iter(self) -> Self::IntoIter { self.iter() }
        }
        impl InternalBitFlags {
            /// Returns a mutable reference to the raw value of the flags currently stored.
            #[inline]
            pub fn bits_mut(&mut self) -> &mut u64 { &mut self.0 }
        }
        #[allow(dead_code, deprecated, unused_attributes)]
        impl MappingFlags {
            /// Get a flags value with all bits unset.
            #[inline]
            pub const fn empty() -> Self { Self(InternalBitFlags::empty()) }
            /// Get a flags value with all known bits set.
            #[inline]
            pub const fn all() -> Self { Self(InternalBitFlags::all()) }
            /// Get the underlying bits value.
            ///
            /// The returned value is exactly the bits set in this flags value.
            #[inline]
            pub const fn bits(&self) -> u64 { self.0.bits() }
            /// Convert from a bits value.
            ///
            /// This method will return `None` if any unknown bits are set.
            #[inline]
            pub const fn from_bits(bits: u64)
                -> ::bitflags::__private::core::option::Option<Self> {
                match InternalBitFlags::from_bits(bits) {
                    ::bitflags::__private::core::option::Option::Some(bits) =>
                        ::bitflags::__private::core::option::Option::Some(Self(bits)),
                    ::bitflags::__private::core::option::Option::None =>
                        ::bitflags::__private::core::option::Option::None,
                }
            }
            /// Convert from a bits value, unsetting any unknown bits.
            #[inline]
            pub const fn from_bits_truncate(bits: u64) -> Self {
                Self(InternalBitFlags::from_bits_truncate(bits))
            }
            /// Convert from a bits value exactly.
            #[inline]
            pub const fn from_bits_retain(bits: u64) -> Self {
                Self(InternalBitFlags::from_bits_retain(bits))
            }
            /// Get a flags value with the bits of a flag with the given name set.
            ///
            /// This method will return `None` if `name` is empty or doesn't
            /// correspond to any named flag.
            #[inline]
            pub fn from_name(name: &str)
                -> ::bitflags::__private::core::option::Option<Self> {
                match InternalBitFlags::from_name(name) {
                    ::bitflags::__private::core::option::Option::Some(bits) =>
                        ::bitflags::__private::core::option::Option::Some(Self(bits)),
                    ::bitflags::__private::core::option::Option::None =>
                        ::bitflags::__private::core::option::Option::None,
                }
            }
            /// Whether all bits in this flags value are unset.
            #[inline]
            pub const fn is_empty(&self) -> bool { self.0.is_empty() }
            /// Whether all known bits in this flags value are set.
            #[inline]
            pub const fn is_all(&self) -> bool { self.0.is_all() }
            /// Whether any set bits in a source flags value are also set in a target flags value.
            #[inline]
            pub const fn intersects(&self, other: Self) -> bool {
                self.0.intersects(other.0)
            }
            /// Whether all set bits in a source flags value are also set in a target flags value.
            #[inline]
            pub const fn contains(&self, other: Self) -> bool {
                self.0.contains(other.0)
            }
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            pub fn insert(&mut self, other: Self) { self.0.insert(other.0) }
            /// The intersection of a source flags value with the complement of a target flags
            /// value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `remove` won't truncate `other`, but the `!` operator will.
            #[inline]
            pub fn remove(&mut self, other: Self) { self.0.remove(other.0) }
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            pub fn toggle(&mut self, other: Self) { self.0.toggle(other.0) }
            /// Call `insert` when `value` is `true` or `remove` when `value` is `false`.
            #[inline]
            pub fn set(&mut self, other: Self, value: bool) {
                self.0.set(other.0, value)
            }
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn intersection(self, other: Self) -> Self {
                Self(self.0.intersection(other.0))
            }
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn union(self, other: Self) -> Self {
                Self(self.0.union(other.0))
            }
            /// The intersection of a source flags value with the complement of a target flags
            /// value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            #[must_use]
            pub const fn difference(self, other: Self) -> Self {
                Self(self.0.difference(other.0))
            }
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn symmetric_difference(self, other: Self) -> Self {
                Self(self.0.symmetric_difference(other.0))
            }
            /// The bitwise negation (`!`) of the bits in a flags value, truncating the result.
            #[inline]
            #[must_use]
            pub const fn complement(self) -> Self {
                Self(self.0.complement())
            }
        }
        impl ::bitflags::__private::core::fmt::Binary for MappingFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::Octal for MappingFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::LowerHex for MappingFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::UpperHex for MappingFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::ops::BitOr for MappingFlags {
            type Output = Self;
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            fn bitor(self, other: MappingFlags) -> Self { self.union(other) }
        }
        impl ::bitflags::__private::core::ops::BitOrAssign for MappingFlags {
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            fn bitor_assign(&mut self, other: Self) { self.insert(other); }
        }
        impl ::bitflags::__private::core::ops::BitXor for MappingFlags {
            type Output = Self;
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            fn bitxor(self, other: Self) -> Self {
                self.symmetric_difference(other)
            }
        }
        impl ::bitflags::__private::core::ops::BitXorAssign for MappingFlags {
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
        }
        impl ::bitflags::__private::core::ops::BitAnd for MappingFlags {
            type Output = Self;
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            fn bitand(self, other: Self) -> Self { self.intersection(other) }
        }
        impl ::bitflags::__private::core::ops::BitAndAssign for MappingFlags {
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            fn bitand_assign(&mut self, other: Self) {
                *self =
                    Self::from_bits_retain(self.bits()).intersection(other);
            }
        }
        impl ::bitflags::__private::core::ops::Sub for MappingFlags {
            type Output = Self;
            /// The intersection of a source flags value with the complement of a target flags value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            fn sub(self, other: Self) -> Self { self.difference(other) }
        }
        impl ::bitflags::__private::core::ops::SubAssign for MappingFlags {
            /// The intersection of a source flags value with the complement of a target flags value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            fn sub_assign(&mut self, other: Self) { self.remove(other); }
        }
        impl ::bitflags::__private::core::ops::Not for MappingFlags {
            type Output = Self;
            /// The bitwise negation (`!`) of the bits in a flags value, truncating the result.
            #[inline]
            fn not(self) -> Self { self.complement() }
        }
        impl ::bitflags::__private::core::iter::Extend<MappingFlags> for
            MappingFlags {
            /// The bitwise or (`|`) of the bits in each flags value.
            fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
                = Self>>(&mut self, iterator: T) {
                for item in iterator { self.insert(item) }
            }
        }
        impl ::bitflags::__private::core::iter::FromIterator<MappingFlags> for
            MappingFlags {
            /// The bitwise or (`|`) of the bits in each flags value.
            fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
                = Self>>(iterator: T) -> Self {
                use ::bitflags::__private::core::iter::Extend;
                let mut result = Self::empty();
                result.extend(iterator);
                result
            }
        }
        impl MappingFlags {
            /// Yield a set of contained flags values.
            ///
            /// Each yielded flags value will correspond to a defined named flag. Any unknown bits
            /// will be yielded together as a final flags value.
            #[inline]
            pub const fn iter(&self) -> ::bitflags::iter::Iter<MappingFlags> {
                ::bitflags::iter::Iter::__private_const_new(<MappingFlags as
                        ::bitflags::Flags>::FLAGS,
                    MappingFlags::from_bits_retain(self.bits()),
                    MappingFlags::from_bits_retain(self.bits()))
            }
            /// Yield a set of contained named flags values.
            ///
            /// This method is like [`iter`](#method.iter), except only yields bits in contained named flags.
            /// Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
            #[inline]
            pub const fn iter_names(&self)
                -> ::bitflags::iter::IterNames<MappingFlags> {
                ::bitflags::iter::IterNames::__private_const_new(<MappingFlags
                        as ::bitflags::Flags>::FLAGS,
                    MappingFlags::from_bits_retain(self.bits()),
                    MappingFlags::from_bits_retain(self.bits()))
            }
        }
        impl ::bitflags::__private::core::iter::IntoIterator for MappingFlags
            {
            type Item = MappingFlags;
            type IntoIter = ::bitflags::iter::Iter<MappingFlags>;
            fn into_iter(self) -> Self::IntoIter { self.iter() }
        }
    };bitflags! {
11    /// Mirrors `OpenMPOffloadMappingFlags` from Clang/OpenMP.
12    #[derive(Debug, Copy, Clone)]
13    #[repr(transparent)]
14    pub struct MappingFlags: u64 {
15        /// No flags.
16        const NONE           = 0x0;
17        /// Allocate memory on the device and move data from host to device.
18        const TO             = 0x01;
19        /// Allocate memory on the device and move data from device to host.
20        const FROM           = 0x02;
21        /// Always perform the requested mapping action, even if already mapped.
22        const ALWAYS         = 0x04;
23        /// Delete the element from the device environment, ignoring ref count.
24        const DELETE         = 0x08;
25        /// The element being mapped is a pointer-pointee pair.
26        const PTR_AND_OBJ    = 0x10;
27        /// The base address should be passed to the target kernel as argument.
28        const TARGET_PARAM   = 0x20;
29        /// The runtime must return the device pointer.
30        const RETURN_PARAM   = 0x40;
31        /// The reference being passed is a pointer to private data.
32        const PRIVATE        = 0x80;
33        /// Pass the element by value.
34        const LITERAL        = 0x100;
35        /// Implicit map (generated by compiler, not explicit in code).
36        const IMPLICIT       = 0x200;
37        /// Hint to allocate memory close to the target device.
38        const CLOSE          = 0x400;
39        /// Reserved (0x800 in OpenMP for XLC compatibility).
40        const RESERVED       = 0x800;
41        /// Require that the data is already allocated on the device.
42        const PRESENT        = 0x1000;
43        /// Increment/decrement a separate ref counter (OpenACC compatibility).
44        const OMPX_HOLD      = 0x2000;
45        /// Used for non-contiguous list items in target update.
46        const NON_CONTIG     = 0x100000000000;
47        /// 16 MSBs indicate membership in a struct.
48        const MEMBER_OF      = 0xffff000000000000;
49    }
50}
51
52impl OffloadMetadata {
53    pub fn from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
54        OffloadMetadata {
55            payload_size: get_payload_size(tcx, ty),
56            mode: MappingFlags::from_ty(tcx, ty),
57        }
58    }
59}
60
61// FIXME(Sa4dUs): implement a solid logic to determine the payload size
62fn get_payload_size<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> u64 {
63    match ty.kind() {
64        ty::RawPtr(inner, _) | ty::Ref(_, inner, _) => get_payload_size(tcx, *inner),
65        _ => tcx
66            .layout_of(PseudoCanonicalInput {
67                typing_env: TypingEnv::fully_monomorphized(),
68                value: ty,
69            })
70            .unwrap()
71            .size
72            .bytes(),
73    }
74}
75
76impl MappingFlags {
77    fn from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
78        use rustc_ast::Mutability::*;
79
80        match ty.kind() {
81            ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) => {
82                MappingFlags::LITERAL | MappingFlags::IMPLICIT
83            }
84
85            ty::Adt(_, _) | ty::Tuple(_) | ty::Array(_, _) | ty::Alias(_, _) | ty::Param(_) => {
86                MappingFlags::TO
87            }
88
89            ty::RawPtr(_, Not) | ty::Ref(_, _, Not) => MappingFlags::TO,
90
91            ty::RawPtr(_, Mut) | ty::Ref(_, _, Mut) => MappingFlags::TO | MappingFlags::FROM,
92
93            ty::Slice(_) | ty::Str | ty::Dynamic(_, _) => MappingFlags::TO | MappingFlags::FROM,
94
95            ty::Foreign(_) | ty::Pat(_, _) | ty::UnsafeBinder(_) => {
96                MappingFlags::TO | MappingFlags::FROM
97            }
98
99            ty::FnDef(_, _)
100            | ty::FnPtr(_, _)
101            | ty::Closure(_, _)
102            | ty::CoroutineClosure(_, _)
103            | ty::Coroutine(_, _)
104            | ty::CoroutineWitness(_, _)
105            | ty::Never
106            | ty::Bound(_, _)
107            | ty::Placeholder(_)
108            | ty::Infer(_)
109            | ty::Error(_) => {
110                tcx.dcx()
111                    .span_err(rustc_span::DUMMY_SP, ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("type `{0:?}` cannot be offloaded",
                ty))
    })format!("type `{ty:?}` cannot be offloaded"));
112                MappingFlags::empty()
113            }
114        }
115    }
116}