LLVM 24.0.0git
Types.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/ABI/Types.h"
11
12using namespace llvm;
13using namespace llvm::abi;
14
16 if (getKind() == TypeKind::Vector) {
17 const VectorType *VT = static_cast<const VectorType *>(this);
18 return VT->isSVEType() && VT->isScalable();
19 }
20 if (getKind() == TypeKind::Tuple) {
21 const VectorType *VT =
22 static_cast<const TupleType *>(this)->getVectorType();
23 return VT->isSVEType() && VT->isScalable();
24 }
25 return false;
26}
27
29 const auto *RT = dyn_cast<RecordType>(this);
30 return RT && RT->isEmpty();
31}
32
33bool RecordType::isEmpty() const {
35 return false;
36
37 // We shouldn't need to check for emptiness if the record has virtual bases
38 // because it can't be passed in registers. This assertion is here to enforce
39 // that assumption.
41
43 return false;
44
45 for (const FieldInfo &Base : getBaseClasses()) {
46 if (!Base.FieldType->isEmptyRecord())
47 return false;
48 }
49
50 for (const FieldInfo &FI : getFields())
51 if (!FI.isEmpty())
52 return false;
53
54 return true;
55}
56
57const FieldInfo *
58RecordType::getElementContainingOffset(unsigned OffsetInBits) const {
59 auto Contains = [&](const FieldInfo &Element) {
60 unsigned Start = Element.OffsetInBits;
61 unsigned Size = Element.FieldType->getSizeInBits().getFixedValue();
62 return OffsetInBits >= Start && OffsetInBits < Start + Size;
63 };
64
65 for (const FieldInfo &Base : getBaseClasses())
66 if (!Base.FieldType->isEmptyRecord() && Contains(Base))
67 return &Base;
68
69 for (const FieldInfo &VBase : getVirtualBaseClasses())
70 if (!VBase.FieldType->isEmptyRecord() && Contains(VBase))
71 return &VBase;
72
73 for (const FieldInfo &Field : getFields()) {
74 if (Field.IsUnnamedBitfield)
75 continue;
76 if (Contains(Field))
77 return &Field;
78 }
79
80 return nullptr;
81}
82
83bool FieldInfo::isEmpty() const {
85 return true;
86
87 const Type *Ty = FieldType;
88 bool WasArray = false;
89 while (const auto *AT = dyn_cast<ArrayType>(Ty)) {
90 // Constant arrays of zero length always count as empty.
91 if (AT->getNumElements() == 0)
92 return true;
93 Ty = AT->getElementType();
94 WasArray = true;
95 }
96
97 const auto *RT = dyn_cast<RecordType>(Ty);
98 if (!RT)
99 return false;
100
101 // C++ record fields are never empty unless [[no_unique_address]] applies.
102 // That exception does not apply to arrays of C++ empty records.
103 if (RT->isCXXRecord() && (WasArray || !HasNoUniqueAddress))
104 return false;
105
106 return RT->isEmpty();
107}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
OptimizedStructLayoutField Field
static bool Contains(directive::VersionRange V, int P)
Definition Spelling.cpp:18
bool canPassInRegisters() const
Definition Types.h:400
ArrayRef< FieldInfo > getBaseClasses() const
Definition Types.h:415
ArrayRef< FieldInfo > getFields() const
Definition Types.h:414
uint32_t getNumVirtualBaseClasses() const
Definition Types.h:408
bool hasFlexibleArrayMember() const
Definition Types.h:403
ArrayRef< FieldInfo > getVirtualBaseClasses() const
Definition Types.h:416
A homogeneous tuple of 2, 3, or 4 identical vectors, such as the AArch64 SVE types svint32x3_t and sv...
Definition Types.h:323
Represents the ABI-specific view of a type in LLVM.
Definition Types.h:46
LLVM_ABI bool isSVESizelessType() const
Definition Types.cpp:15
LLVM_ABI bool isEmptyRecord() const
True if this type is a record that is empty for ABI purposes.
Definition Types.cpp:28
TypeKind getKind() const
Definition Types.h:73
bool isSVEType() const
Returns true for any of the AArch64 SVE flavors.
Definition Types.h:310
bool isScalable() const
Definition Types.h:302
This file defines the type system for the LLVMABI library, which mirrors ABI-relevant aspects of fron...
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool HasNoUniqueAddress
Definition Types.h:346
const Type * FieldType
Definition Types.h:341
LLVM_ABI bool isEmpty() const
Definition Types.cpp:83