LLVM 24.0.0git
TargetInfo.cpp
Go to the documentation of this file.
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
10
11using namespace llvm::abi;
12
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>(Ty))
22 if (AT->isMatrixType())
23 return false;
24
25 // Everything else is treated as aggregate.
26 return true;
27}
28
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(Ty->getAlignment(), ByVal);
38}
39
41 if (RT && !RT->canPassInRegisters())
42 return RAA_Indirect;
43 return RAA_Default;
44}
45
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>(Ty);
50 if (!RT)
51 return RAA_Default;
52 return getRecordArgABI(RT);
53}
54
56 if (const auto *RT = dyn_cast<RecordType>(Ty)) {
57 if (RT->isUnion() && RT->isTransparentUnion()) {
58 auto Fields = RT->getFields();
59 assert(!Fields.empty() && "transparent union cannot be empty");
60 return Fields.front().FieldType;
61 }
62 }
63 return Ty;
64}
65
67 const abi::Type *Ty = FI.getReturnType();
68
69 // TODO: When Microsoft ABI is supported, CXX records may need different
70 // handling here (see MicrosoftCXXABI::classifyReturnType in Clang).
71 if (const auto *RT = llvm::dyn_cast<abi::RecordType>(Ty)) {
72 if (!RT->canPassInRegisters()) {
73 // A record that cannot pass in registers (e.g. a non-trivial copy/dtor)
74 // is returned indirectly with ByVal=false. This is the RAA path and is
75 // distinct from getIndirectReturnResult (plain aggregates), which uses
76 // ByVal=true.
77 FI.getReturnInfo() =
78 ArgInfo::getIndirect(RT->getAlignment(), /*ByVal=*/false);
79 return true;
80 }
81 }
82
83 return false;
84}
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")))
Target-specific ABI information and factory functions.
Helper class to encapsulate information about how a specific type should be passed to or returned fro...
static ArgInfo getIndirect(Align Align, bool ByVal, unsigned AddrSpace=0, bool Realign=false)
Realign: the caller couldn't guarantee sufficient alignment - the callee must copy the argument to a ...
const Type * getReturnType() const
bool canPassInRegisters() const
Definition Types.h:293
LLVM_ABI ArgInfo getNaturalAlignIndirect(const Type *Ty, bool ByVal=true) const
LLVM_ABI bool isPromotableInteger(const IntegerType *IT) const
LLVM_ABI bool maybeCommonClassifyReturnType(FunctionInfo &FI) const
Apply rules for classifying return types that are common to all targets.
LLVM_ABI bool isAggregateTypeForABI(const Type *Ty) const
LLVM_ABI const Type * useFirstFieldIfTransparentUnion(const Type *Ty) const
If Ty is a transparent union, return its first field type; otherwise return Ty unchanged.
LLVM_ABI RecordArgABI getRecordArgABI(const RecordType *RT) const
Represents the ABI-specific view of a type in LLVM.
Definition Types.h:44
@ RAA_Indirect
Pass it as a pointer to temporary memory.
Definition TargetInfo.h:37
@ RAA_Default
Pass it using the normal C aggregate rules for the ABI, potentially introducing extra copies and pass...
Definition TargetInfo.h:29
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
constexpr unsigned BitWidth