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"
10#include "llvm/ADT/bit.h"
13#include <algorithm>
14
15using namespace llvm;
16using namespace llvm::abi;
17
19 switch (getKind()) {
21 if (cast<IntegerType>(this)->isBitInt())
22 return getTypeAllocSize().getFixedValue() * 8;
23 return getTypeStoreSizeInBits().getFixedValue();
24 case TypeKind::Float:
25 return getTypeAllocSize().getFixedValue() * 8;
27 return 2 * cast<ComplexType>(this)->getElementType()->getABISizeInBits();
28 case TypeKind::Vector: {
29 const auto *VT = cast<VectorType>(this);
30 if (VT->isScalable())
31 return 0;
32 const Type *EltTy = VT->getElementType();
33 const auto *IT = dyn_cast<IntegerType>(EltTy);
34 uint64_t EltWidth = IT && !IT->isBitInt() ? IT->getFixedSizeInBitsOrZero()
35 : EltTy->getABISizeInBits();
36 uint64_t Width = EltWidth * VT->getNumElements().getFixedValue();
37 return bit_ceil(std::max<uint64_t>(Width, 8));
38 }
39 case TypeKind::Void:
44 case TypeKind::Array:
45 case TypeKind::Tuple:
48 }
49 llvm_unreachable("unknown ABI type kind");
50}
51
53 if (getKind() == TypeKind::Vector) {
54 const VectorType *VT = static_cast<const VectorType *>(this);
55 return VT->isSVEType() && VT->isScalable();
56 }
57 if (getKind() == TypeKind::Tuple) {
58 const VectorType *VT =
59 static_cast<const TupleType *>(this)->getVectorType();
60 return VT->isSVEType() && VT->isScalable();
61 }
62 return false;
63}
64
66 const auto *RT = dyn_cast<RecordType>(this);
67 return RT && RT->isEmpty();
68}
69
70bool RecordType::isEmpty() const {
72 return false;
73
74 // We shouldn't need to check for emptiness if the record has virtual bases
75 // because it can't be passed in registers. This assertion is here to enforce
76 // that assumption.
78
80 return false;
81
82 for (const FieldInfo &Base : getBaseClasses()) {
83 if (!Base.FieldType->isEmptyRecord())
84 return false;
85 }
86
87 for (const FieldInfo &FI : getFields())
88 if (!FI.isEmpty())
89 return false;
90
91 return true;
92}
93
94const FieldInfo *
95RecordType::getElementContainingOffset(unsigned OffsetInBits) const {
96 auto Contains = [&](const FieldInfo &Element) {
97 unsigned Start = Element.OffsetInBits;
98 unsigned Size = Element.FieldType->getSizeInBits().getFixedValue();
99 return OffsetInBits >= Start && OffsetInBits < Start + Size;
100 };
101
102 for (const FieldInfo &Base : getBaseClasses())
103 if (!Base.FieldType->isEmptyRecord() && Contains(Base))
104 return &Base;
105
106 for (const FieldInfo &VBase : getVirtualBaseClasses())
107 if (!VBase.FieldType->isEmptyRecord() && Contains(VBase))
108 return &VBase;
109
110 for (const FieldInfo &Field : getFields()) {
111 if (Field.IsUnnamedBitfield)
112 continue;
113 if (Contains(Field))
114 return &Field;
115 }
116
117 return nullptr;
118}
119
120bool FieldInfo::isEmpty() const {
122 return true;
123
124 const Type *Ty = FieldType;
125 bool WasArray = false;
126 while (const auto *AT = dyn_cast<ArrayType>(Ty)) {
127 // Constant arrays of zero length always count as empty.
128 if (AT->getNumElements() == 0)
129 return true;
130 Ty = AT->getElementType();
131 WasArray = true;
132 }
133
134 const auto *RT = dyn_cast<RecordType>(Ty);
135 if (!RT)
136 return false;
137
138 // C++ record fields are never empty unless [[no_unique_address]] applies.
139 // That exception does not apply to arrays of C++ empty records.
140 if (RT->isCXXRecord() && (WasArray || !HasNoUniqueAddress))
141 return false;
142
143 return RT->isEmpty();
144}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
OptimizedStructLayoutField Field
This file implements the C++20 <bit> header.
bool canPassInRegisters() const
Definition Types.h:447
ArrayRef< FieldInfo > getBaseClasses() const
Definition Types.h:462
ArrayRef< FieldInfo > getFields() const
Definition Types.h:461
uint32_t getNumVirtualBaseClasses() const
Definition Types.h:455
bool hasFlexibleArrayMember() const
Definition Types.h:450
ArrayRef< FieldInfo > getVirtualBaseClasses() const
Definition Types.h:463
A homogeneous tuple of 2, 3, or 4 identical vectors, such as the AArch64 SVE types svint32x3_t and sv...
Definition Types.h:370
Represents the ABI-specific view of a type in LLVM.
Definition Types.h:48
TypeSize getTypeAllocSize() const
Definition Types.h:103
LLVM_ABI bool isSVESizelessType() const
Definition Types.cpp:52
LLVM_ABI bool isEmptyRecord() const
True if this type is a record that is empty for ABI purposes.
Definition Types.cpp:65
Type(TypeKind K, TypeSize SizeInBits, Align ABIAlign)
Definition Types.h:68
LLVM_ABI uint64_t getABISizeInBits() const
Returns the size in bits that the source language gives this type, including any padding.
Definition Types.cpp:18
uint64_t getFixedSizeInBitsOrZero() const
Returns the size in bits if it is fixed, otherwise 0.
Definition Types.h:79
TypeKind getKind() const
Definition Types.h:75
bool isSVEType() const
Returns true for any of the AArch64 SVE flavors.
Definition Types.h:357
bool isScalable() const
Definition Types.h:344
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:201
This file defines the type system for the LLVMABI library, which mirrors ABI-relevant aspects of fron...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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
T bit_ceil(T Value)
Returns the smallest integral power of two no smaller than Value if Value is nonzero.
Definition bit.h:362
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool HasNoUniqueAddress
Definition Types.h:393
const Type * FieldType
Definition Types.h:388
LLVM_ABI bool isEmpty() const
Definition Types.cpp:120