LLVM 24.0.0git
AArch64.cpp
Go to the documentation of this file.
1//===- AArch64.cpp - AArch64 ABI Implementation ---------------------------===//
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#include "llvm/ABI/TargetInfo.h"
11#include "llvm/ABI/Types.h"
14
15namespace llvm {
16namespace abi {
17
19public:
21 : TB(TB), Kind(Kind) {}
22
23 void computeInfo(FunctionInfo &FI) const override {
25 FI.getReturnInfo() =
26 classifyReturnType(FI.getReturnType(), FI.isVariadic());
27
28 unsigned ArgNo = 0;
29 unsigned NSRN = 0, NPRN = 0;
30 for (auto &I : FI.arguments()) {
31 const bool IsNamedArg =
32 !FI.isVariadic() || ArgNo < FI.getNumRequiredArgs();
33 ++ArgNo;
34 I.Info = classifyArgumentType(I.ABIType, FI.isVariadic(), IsNamedArg,
35 FI.getCallingConvention(), NSRN, NPRN);
36 }
37 }
38
39private:
40 [[maybe_unused]] TypeBuilder &TB;
41 AArch64ABIKind Kind;
42
43 ArgInfo classifyReturnType(const Type *RetTy, bool IsVariadicFn) const;
44 ArgInfo classifyArgumentType(const Type *Ty, bool IsVariadicFn,
45 bool IsNamedArg, unsigned CallingConvention,
46 unsigned &NSRN, unsigned &NPRN) const;
47
48 bool isDarwinPCS() const { return Kind == AArch64ABIKind::DarwinPCS; }
49 bool passAsAggregateType(const Type *Ty) const;
50};
51
52std::unique_ptr<TargetInfo> createAArch64TargetInfo(TypeBuilder &TB,
53 AArch64ABIKind Kind) {
54 return std::make_unique<AArch64TargetInfo>(TB, Kind);
55}
56
57static void reportNYI(StringRef Feature) {
59 << Feature
60 << " is not yet implemented for AArch64 in the LLVM ABI library.\n";
61}
62
63ArgInfo AArch64TargetInfo::classifyReturnType(const Type *RetTy,
64 bool IsVariadicFn) const {
65 if (RetTy->isVoid())
66 return ArgInfo::getIgnore();
67
68 if (RetTy->isVector()) {
69 reportNYI("Vector return type handling");
70 return ArgInfo::getDirect();
71 }
72
73 if (!passAsAggregateType(RetTy)) {
74 if (const auto *IntTy = dyn_cast<IntegerType>(RetTy)) {
75 if (IntTy->isBitInt()) {
76 reportNYI("BitInt return type handling");
77 return ArgInfo::getDirect();
78 }
79 if (isPromotableInteger(IntTy) && isDarwinPCS()) {
80 return ArgInfo::getExtend(IntTy);
81 }
82 }
83
84 // Everything not handled above is returned directly.
85 return ArgInfo::getDirect();
86 }
87
88 reportNYI("Aggregate return type handling");
89 return ArgInfo::getDirect();
90}
91
92ArgInfo AArch64TargetInfo::classifyArgumentType(
93 const Type *Ty, bool IsVariadicFn, bool IsNamedArg,
94 unsigned CallingConvention, unsigned &NSRN, unsigned &NPRN) const {
96
97 // TODO: Handle variadic functins here when Windows Arm64 EC is supported.
98
99 if (Ty->isVector()) {
100 reportNYI("Vector argument type handling");
101 return ArgInfo::getDirect();
102 }
103
104 if (!passAsAggregateType(Ty)) {
105 if (const auto *IntTy = dyn_cast<IntegerType>(Ty)) {
106 if (IntTy->isBitInt()) {
107 reportNYI("BitInt argument type handling");
108 return ArgInfo::getDirect();
109 }
110 if (isPromotableInteger(IntTy) && isDarwinPCS()) {
111 return ArgInfo::getExtend(IntTy);
112 }
113 }
114
115 // TODO: Legal vector types will update NSRN or NPRN.
116
117 if (Ty->isFloat())
118 NSRN = std::min(NSRN + 1, 8u);
119
120 // Everything not handled above is returned directly.
121 return ArgInfo::getDirect();
122 }
123
124 reportNYI("Aggregate argument type handling");
125 return ArgInfo::getDirect();
126}
127
128bool AArch64TargetInfo::passAsAggregateType(const Type *Ty) const {
129 // TODO: Handle SVE types. For now, they don't get through the type mapper.
130 return isAggregateTypeForABI(Ty);
131}
132
133} // namespace abi
134} // namespace llvm
#define I(x, y, z)
Definition MD5.cpp:57
Target-specific ABI information and factory functions.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
Definition WithColor.cpp:86
AArch64TargetInfo(TypeBuilder &TB, AArch64ABIKind Kind)
Definition AArch64.cpp:20
void computeInfo(FunctionInfo &FI) const override
Populate FI with the target's ABI-lowering decisions for each argument and return value.
Definition AArch64.cpp:23
Helper class to encapsulate information about how a specific type should be passed to or returned fro...
static ArgInfo getDirect(const Type *T=nullptr, unsigned Offset=0, MaybeAlign Align=std::nullopt)
static ArgInfo getIgnore()
static ArgInfo getExtend(const Type *T)
ArrayRef< ArgEntry > arguments() const
unsigned getNumRequiredArgs() const
CallingConv::ID getCallingConvention() const
const Type * getReturnType() 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.
TypeBuilder manages the lifecycle of ABI types using bump pointer allocation.
Definition Types.h:335
Represents the ABI-specific view of a type in LLVM.
Definition Types.h:44
This file defines the type system for the LLVMABI library, which mirrors ABI-relevant aspects of fron...
static void reportNYI(StringRef Feature)
Definition AArch64.cpp:57
LLVM_ABI std::unique_ptr< TargetInfo > createAArch64TargetInfo(TypeBuilder &TB, AArch64ABIKind Kind)
Definition AArch64.cpp:52
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
Helper struct shared between Function Specialization and SCCP Solver.
Definition SCCPSolver.h:42