1//===- DefaultTargetInfo.cpp - Default ABI classification -----------------===//
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/DefaultTargetInfo.h"
10#include "llvm/Support/Casting.h"
11
12using namespace llvm::abi;
13using llvm::dyn_cast;
14
15ArgInfo DefaultTargetInfo::classifyArgumentType(const Type *Ty) const {
16 Ty = useFirstFieldIfTransparentUnion(Ty);
17
18 if (isAggregateTypeForABI(Ty)) {
19 // Records with non-trivial destructors/copy-constructors should not be
20 // passed by value.
21 if (RecordArgABI RAA = getRecordArgABI(Ty))
22 return getNaturalAlignIndirect(Ty, AddrSpace: getAllocaAddrSpace(),
23 /*ByVal=*/RAA == RAA_DirectInMemory);
24 return getNaturalAlignIndirect(Ty, AddrSpace: getAllocaAddrSpace());
25 }
26
27 if (const auto *IT = dyn_cast<IntegerType>(Val: Ty)) {
28 // A _BitInt too wide for the largest integer register goes indirect.
29 if (IT->isBitInt() &&
30 IT->getSizeInBits().getFixedValue() > getBitIntRegThreshold())
31 return getNaturalAlignIndirect(Ty, AddrSpace: getAllocaAddrSpace());
32 if (isPromotableInteger(IT))
33 return ArgInfo::getExtend(T: Ty);
34 }
35
36 return ArgInfo::getDirect();
37}
38
39ArgInfo DefaultTargetInfo::classifyReturnType(const Type *RetTy) const {
40 if (RetTy->isVoid())
41 return ArgInfo::getIgnore();
42
43 if (isAggregateTypeForABI(Ty: RetTy))
44 return getNaturalAlignIndirect(Ty: RetTy, AddrSpace: getAllocaAddrSpace());
45
46 if (const auto *IT = dyn_cast<IntegerType>(Val: RetTy)) {
47 // A _BitInt too wide for the largest integer register goes indirect.
48 if (IT->isBitInt() &&
49 IT->getSizeInBits().getFixedValue() > getBitIntRegThreshold())
50 return getNaturalAlignIndirect(Ty: RetTy, AddrSpace: getAllocaAddrSpace());
51 if (isPromotableInteger(IT))
52 return ArgInfo::getExtend(T: RetTy);
53 }
54
55 return ArgInfo::getDirect();
56}
57
58void DefaultTargetInfo::computeInfo(FunctionInfo &FI) const {
59 if (!maybeCommonClassifyReturnType(FI))
60 FI.getReturnInfo() = classifyReturnType(RetTy: FI.getReturnType());
61 for (auto &I : FI.arguments())
62 I.Info = classifyArgumentType(Ty: I.ABIType);
63}
64