Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
dart::compiler::ffi::NativeStructType Class Reference

#include <native_type.h>

Inheritance diagram for dart::compiler::ffi::NativeStructType:
dart::compiler::ffi::NativeCompoundType dart::compiler::ffi::NativeType dart::ZoneAllocated

Public Member Functions

const ZoneGrowableArray< intptr_t > & member_offsets () const
 
virtual bool IsStruct () const
 
virtual intptr_t AlignmentInBytesStack (bool is_vararg=false) const
 
virtual bool ContainsOnlyFloats (Range range) const
 
virtual bool ContainsUnalignedMembers (intptr_t offset=0) const
 
virtual intptr_t NumPrimitiveMembersRecursive () const
 
- Public Member Functions inherited from dart::compiler::ffi::NativeCompoundType
const NativeTypesmembers () const
 
virtual bool IsCompound () const
 
virtual intptr_t SizeInBytes () const
 
virtual intptr_t AlignmentInBytesField () const
 
virtual bool Equals (const NativeType &other) const
 
virtual void PrintTo (BaseTextBuffer *f, bool multi_line=false, bool verbose=true) const
 
intptr_t NumberOfWordSizeChunksOnlyFloat () const
 
intptr_t NumberOfWordSizeChunksNotOnlyFloat () const
 
bool ContainsHomogeneousFloats () const
 
virtual const NativePrimitiveTypeFirstPrimitiveMember () const
 
virtual intptr_t PrimitivePairMembers (const NativePrimitiveType **first, const NativePrimitiveType **second, intptr_t offset_in_members=0) const
 
- Public Member Functions inherited from dart::compiler::ffi::NativeType
virtual bool IsPrimitive () const
 
const NativePrimitiveTypeAsPrimitive () const
 
virtual bool IsArray () const
 
const NativeArrayTypeAsArray () const
 
const NativeCompoundTypeAsCompound () const
 
const NativeStructTypeAsStruct () const
 
virtual bool IsInt () const
 
virtual bool IsFloat () const
 
virtual bool IsVoid () const
 
virtual bool IsSigned () const
 
virtual bool IsExpressibleAsRepresentation () const
 
virtual Representation AsRepresentation () const
 
Representation AsRepresentationOverApprox (Zone *zone_) const
 
virtual NativeTypeSplit (Zone *zone, intptr_t index) const
 
const NativeTypeWidenTo4Bytes (Zone *zone) const
 
const NativeTypeWidenTo8Bytes (Zone *zone) const
 
const NativeTypeExtend (Zone *zone, ExtensionStrategy extension) const
 
const char * ToCString (Zone *zone, bool multi_line=false, bool verbose=true) const
 
const char * ToCString () const
 
virtual ~NativeType ()
 
- Public Member Functions inherited from dart::ZoneAllocated
 ZoneAllocated ()
 
void * operator new (size_t size)
 
void * operator new (size_t size, Zone *zone)
 
void operator delete (void *pointer)
 

Static Public Member Functions

static NativeStructTypeFromNativeTypes (Zone *zone, const NativeTypes &members, intptr_t member_packing=kMaxInt32)
 
- Static Public Member Functions inherited from dart::compiler::ffi::NativeType
static const NativeTypeFromAbstractType (Zone *zone, const AbstractType &type, const char **error)
 
static const NativeTypeFromTypedDataClassId (Zone *zone, classid_t class_id)
 
static NativePrimitiveTypeFromRepresentation (Zone *zone, Representation rep)
 

Protected Member Functions

virtual void PrintCompoundType (BaseTextBuffer *f) const
 
virtual void PrintMemberOffset (BaseTextBuffer *f, intptr_t member_index) const
 
- Protected Member Functions inherited from dart::compiler::ffi::NativeCompoundType
 NativeCompoundType (const NativeTypes &members, intptr_t size, intptr_t alignment_field, intptr_t alignment_stack)
 
- Protected Member Functions inherited from dart::compiler::ffi::NativeType
 NativeType ()
 

Additional Inherited Members

- Protected Attributes inherited from dart::compiler::ffi::NativeCompoundType
const NativeTypesmembers_
 
const intptr_t size_
 
const intptr_t alignment_field_
 
const intptr_t alignment_stack_
 

Detailed Description

Definition at line 386 of file native_type.h.

Member Function Documentation

◆ AlignmentInBytesStack()

virtual intptr_t dart::compiler::ffi::NativeStructType::AlignmentInBytesStack ( bool  is_vararg = false) const
inlinevirtual

Reimplemented from dart::compiler::ffi::NativeCompoundType.

Definition at line 398 of file native_type.h.

398 {
399 if (is_vararg) {
400 return alignment_stack_vararg_;
401 }
402 return alignment_stack_;
403 }

◆ ContainsOnlyFloats()

bool dart::compiler::ffi::NativeStructType::ContainsOnlyFloats ( Range  range) const
virtual

Implements dart::compiler::ffi::NativeCompoundType.

Definition at line 937 of file native_type.cc.

937 {
938 const auto this_range = Range::StartAndEnd(0, SizeInBytes());
939 ASSERT(this_range.Contains(range));
940
941 for (intptr_t i = 0; i < members_.length(); i++) {
942 const auto& member = *members_[i];
943 const intptr_t member_offset = member_offsets_[i];
944 const intptr_t member_size = member.SizeInBytes();
945 const auto member_range = Range::StartAndLength(member_offset, member_size);
946 if (range.Overlaps(member_range)) {
947 const auto member_range_clipped = member_range.Intersect(range);
948 const auto range_in_member =
949 member_range_clipped.Translate(-member_offset);
950 if (!member.ContainsOnlyFloats(range_in_member)) {
951 // Member contains not only floats in specified range.
952 return false;
953 }
954 }
955 if (member_range.After(range)) {
956 // None of the remaining members fits the range.
957 break;
958 }
959 }
960 return true;
961}
intptr_t length() const
virtual intptr_t SizeInBytes() const
static Range StartAndLength(intptr_t start_inclusive, intptr_t length)
Definition range.h:28
static Range StartAndEnd(intptr_t start_inclusive, intptr_t end_exclusive)
Definition range.h:35
#define ASSERT(E)

◆ ContainsUnalignedMembers()

bool dart::compiler::ffi::NativeStructType::ContainsUnalignedMembers ( intptr_t  offset = 0) const
virtual

Implements dart::compiler::ffi::NativeCompoundType.

Definition at line 1024 of file native_type.cc.

1024 {
1025 for (intptr_t i = 0; i < members_.length(); i++) {
1026 const auto& member = *members_.At(i);
1027 const intptr_t member_offset = member_offsets_.At(i);
1028 if (member.ContainsUnalignedMembers(offset + member_offset)) {
1029 return true;
1030 }
1031 }
1032 return false;
1033}
const T & At(intptr_t index) const
Point offset

◆ FromNativeTypes()

NativeStructType & dart::compiler::ffi::NativeStructType::FromNativeTypes ( Zone zone,
const NativeTypes members,
intptr_t  member_packing = kMaxInt32 
)
static

Definition at line 196 of file native_type.cc.

198 {
199 intptr_t offset = 0;
200
201 const intptr_t kAtLeast1ByteAligned = 1;
202 // If this struct is nested in another struct, it should be aligned to the
203 // largest alignment of its members.
204 intptr_t alignment_field = kAtLeast1ByteAligned;
205 // If this struct is passed on the stack, it should be aligned to the largest
206 // alignment of its members when passing those members on the stack.
207 intptr_t alignment_stack = kAtLeast1ByteAligned;
208 intptr_t alignment_stack_vararg = kAtLeast1ByteAligned;
209#if (defined(DART_TARGET_OS_MACOS_IOS) || defined(DART_TARGET_OS_MACOS)) && \
210 defined(TARGET_ARCH_ARM64)
211 // On iOS64 and MacOS arm64 stack values can be less aligned than wordSize,
212 // which deviates from the arm64 ABI.
214 // Because the arm64 ABI aligns primitives to word size on the stack, every
215 // struct will be automatically aligned to word size. iOS64 does not align
216 // the primitives to word size, so we set structs to align to word size for
217 // iOS64.
218 // However, homogenous structs are treated differently. They are aligned to
219 // their member alignment. (Which is 4 in case of a homogenous float).
220 // Source: manual testing.
222 alignment_stack = compiler::target::kWordSize;
223 }
224 alignment_stack_vararg = compiler::target::kWordSize;
225#endif
226
227 auto& member_offsets =
228 *new (zone) ZoneGrowableArray<intptr_t>(zone, members.length());
229 for (intptr_t i = 0; i < members.length(); i++) {
230 const NativeType& member = *members[i];
231 const intptr_t member_size = member.SizeInBytes();
232 const intptr_t member_align_field =
233 Utils::Minimum(member.AlignmentInBytesField(), member_packing);
234 intptr_t member_align_stack = member.AlignmentInBytesStack();
235 if (member_align_stack > member_packing &&
236 member_packing < compiler::target::kWordSize) {
237 member_align_stack = compiler::target::kWordSize;
238 }
239 offset = Utils::RoundUp(offset, member_align_field);
241 offset += member_size;
242 alignment_field = Utils::Maximum(alignment_field, member_align_field);
243 alignment_stack = Utils::Maximum(alignment_stack, member_align_stack);
244 alignment_stack_vararg =
245 Utils::Maximum(alignment_stack_vararg, member_align_stack);
246 }
247 const intptr_t size = Utils::RoundUp(offset, alignment_field);
248
249 return *new (zone)
250 NativeStructType(members, member_offsets, size, alignment_field,
251 alignment_stack, alignment_stack_vararg);
252}
void Add(const T &value)
static constexpr AlignmentStrategy kArgumentStackAlignment
static constexpr T Maximum(T x, T y)
Definition utils.h:26
static T Minimum(T x, T y)
Definition utils.h:21
static constexpr T RoundUp(T x, uintptr_t alignment, uintptr_t offset=0)
Definition utils.h:105
const NativeTypes & members() const
const ZoneGrowableArray< intptr_t > & member_offsets() const
static bool ContainsHomogeneousFloatsInternal(const NativeTypes &types)
@ kAlignedToValueSize
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259

◆ IsStruct()

virtual bool dart::compiler::ffi::NativeStructType::IsStruct ( ) const
inlinevirtual

Reimplemented from dart::compiler::ffi::NativeType.

Definition at line 396 of file native_type.h.

396{ return true; }

◆ member_offsets()

const ZoneGrowableArray< intptr_t > & dart::compiler::ffi::NativeStructType::member_offsets ( ) const
inline

Definition at line 392 of file native_type.h.

392 {
393 return member_offsets_;
394 }

◆ NumPrimitiveMembersRecursive()

intptr_t dart::compiler::ffi::NativeStructType::NumPrimitiveMembersRecursive ( ) const
virtual

Implements dart::compiler::ffi::NativeCompoundType.

Definition at line 820 of file native_type.cc.

820 {
821 intptr_t count = 0;
822 for (intptr_t i = 0; i < members_.length(); i++) {
823 count += members_[i]->NumPrimitiveMembersRecursive();
824 }
825 return count;
826}
int count

◆ PrintCompoundType()

void dart::compiler::ffi::NativeStructType::PrintCompoundType ( BaseTextBuffer f) const
protectedvirtual

Implements dart::compiler::ffi::NativeCompoundType.

Definition at line 778 of file native_type.cc.

778 {
779 f->AddString("Struct");
780}

◆ PrintMemberOffset()

void dart::compiler::ffi::NativeStructType::PrintMemberOffset ( BaseTextBuffer f,
intptr_t  member_index 
) const
protectedvirtual

Reimplemented from dart::compiler::ffi::NativeCompoundType.

Definition at line 786 of file native_type.cc.

787 {
788 f->Printf("%" Pd ": ", member_offsets_[member_index]);
789}
#define Pd
Definition globals.h:408

The documentation for this class was generated from the following files: