1//===- TargetInfo.cpp - Target ABI information ----------------------------===//
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/TargetInfo.h"
10
11using namespace llvm::abi;
12
13bool TargetInfo::isAggregateTypeForABI(const Type *Ty) const {
14 // Check for fundamental scalar types.
15 if (Ty->isInteger() || Ty->isFloat() || Ty->isPointer() || Ty->isVector())
16 return false;
17
18 // A matrix type is modeled as an array but lowers to a single flattened
19 // vector and has scalar evaluation kind in classic CodeGen, so it is not an
20 // aggregate for ABI purposes.
21 if (const auto *AT = dyn_cast<ArrayType>(Val: Ty))
22 if (AT->isMatrixType())
23 return false;
24
25 // Everything else is treated as aggregate.
26 return true;
27}
28
29bool TargetInfo::isPromotableInteger(const IntegerType *IT) const {
30 // TODO: The threshold should be the target's int size rather than a
31 // hardcoded 32.
32 unsigned BitWidth = IT->getSizeInBits().getFixedValue();
33 return BitWidth < 32;
34}
35
36ArgInfo TargetInfo::getNaturalAlignIndirect(const Type *Ty, bool ByVal) const {
37 return ArgInfo::getIndirect(Align: Ty->getAlignment(), ByVal);
38}
39
40RecordArgABI TargetInfo::getRecordArgABI(const RecordType *RT) const {
41 if (RT && !RT->canPassInRegisters())
42 return RAA_Indirect;
43 return RAA_Default;
44}
45
46RecordArgABI TargetInfo::getRecordArgABI(const Type *Ty) const {
47 // TODO: When Microsoft ABI is supported, CXX records may need different
48 // handling here (see MicrosoftCXXABI::getRecordArgABI in Clang).
49 const RecordType *RT = dyn_cast<RecordType>(Val: Ty);
50 if (!RT)
51 return RAA_Default;
52 return getRecordArgABI(RT);
53}
54