1//===----- ABIInfo.h - ABI information access & encapsulation ---*- C++ -*-===//
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#ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
10#define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
11
12#include "clang/AST/Attr.h"
13#include "clang/AST/CharUnits.h"
14#include "clang/AST/Type.h"
15#include "llvm/IR/CallingConv.h"
16#include "llvm/IR/Type.h"
17
18namespace llvm {
19class Value;
20class LLVMContext;
21class DataLayout;
22class Type;
23} // namespace llvm
24
25namespace clang {
26class ASTContext;
27class CodeGenOptions;
28class TargetInfo;
29
30namespace CodeGen {
31class ABIArgInfo;
32class Address;
33class CGCXXABI;
34class CGFunctionInfo;
35class CodeGenFunction;
36class CodeGenTypes;
37
38// FIXME: All of this stuff should be part of the target interface
39// somehow. It is currently here because it is not clear how to factor
40// the targets to support this, since the Targets currently live in a
41// layer below types n'stuff.
42
43/// ABIInfo - Target specific hooks for defining how a type should be
44/// passed or returned from functions.
45class ABIInfo {
46protected:
47 CodeGen::CodeGenTypes &CGT;
48 llvm::CallingConv::ID RuntimeCC;
49
50public:
51 ABIInfo(CodeGen::CodeGenTypes &cgt)
52 : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {}
53
54 virtual ~ABIInfo();
55
56 virtual bool allowBFloatArgsAndRet() const { return false; }
57
58 CodeGen::CGCXXABI &getCXXABI() const;
59 ASTContext &getContext() const;
60 llvm::LLVMContext &getVMContext() const;
61 const llvm::DataLayout &getDataLayout() const;
62 const TargetInfo &getTarget() const;
63 const CodeGenOptions &getCodeGenOpts() const;
64
65 /// Return the calling convention to use for system runtime
66 /// functions.
67 llvm::CallingConv::ID getRuntimeCC() const { return RuntimeCC; }
68
69 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
70
71 /// EmitVAArg - Emit the target dependent code to load a value of
72 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
73
74 // FIXME: This is a gaping layering violation if we wanted to drop
75 // the ABI information any lower than CodeGen. Of course, for
76 // VAArg handling it has to be at this level; there is no way to
77 // abstract this out.
78 virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
79 CodeGen::Address VAListAddr,
80 QualType Ty) const = 0;
81
82 bool isAndroid() const;
83 bool isOHOSFamily() const;
84
85 /// Emit the target dependent code to load a value of
86 /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
87 virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
88 CodeGen::Address VAListAddr,
89 QualType Ty) const;
90
91 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
92
93 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
94 uint64_t Members) const;
95 virtual bool isZeroLengthBitfieldPermittedInHomogeneousAggregate() const;
96
97 /// isHomogeneousAggregate - Return true if a type is an ELFv2 homogeneous
98 /// aggregate. Base is set to the base element type, and Members is set
99 /// to the number of base elements.
100 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
101 uint64_t &Members) const;
102
103 // Implement the Type::IsPromotableIntegerType for ABI specific needs. The
104 // only difference is that this considers bit-precise integer types as well.
105 bool isPromotableIntegerTypeForABI(QualType Ty) const;
106
107 /// A convenience method to return an indirect ABIArgInfo with an
108 /// expected alignment equal to the ABI alignment of the given type.
109 CodeGen::ABIArgInfo
110 getNaturalAlignIndirect(QualType Ty, bool ByVal = true, bool Realign = false,
111 llvm::Type *Padding = nullptr) const;
112
113 CodeGen::ABIArgInfo getNaturalAlignIndirectInReg(QualType Ty,
114 bool Realign = false) const;
115
116 virtual void appendAttributeMangling(TargetAttr *Attr,
117 raw_ostream &Out) const;
118 virtual void appendAttributeMangling(TargetVersionAttr *Attr,
119 raw_ostream &Out) const;
120 virtual void appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
121 raw_ostream &Out) const;
122 virtual void appendAttributeMangling(StringRef AttrStr,
123 raw_ostream &Out) const;
124};
125
126/// Target specific hooks for defining how a type should be passed or returned
127/// from functions with one of the Swift calling conventions.
128class SwiftABIInfo {
129protected:
130 CodeGenTypes &CGT;
131 bool SwiftErrorInRegister;
132
133 bool occupiesMoreThan(ArrayRef<llvm::Type *> scalarTypes,
134 unsigned maxAllRegisters) const;
135
136public:
137 SwiftABIInfo(CodeGen::CodeGenTypes &CGT, bool SwiftErrorInRegister)
138 : CGT(CGT), SwiftErrorInRegister(SwiftErrorInRegister) {}
139
140 virtual ~SwiftABIInfo();
141
142 /// Returns true if an aggregate which expands to the given type sequence
143 /// should be passed / returned indirectly.
144 virtual bool shouldPassIndirectly(ArrayRef<llvm::Type *> ComponentTys,
145 bool AsReturnValue) const;
146
147 /// Returns true if the given vector type is legal from Swift's calling
148 /// convention perspective.
149 virtual bool isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,
150 unsigned NumElts) const;
151
152 /// Returns true if swifterror is lowered to a register by the target ABI.
153 bool isSwiftErrorInRegister() const { return SwiftErrorInRegister; };
154};
155} // end namespace CodeGen
156} // end namespace clang
157
158#endif
159

source code of clang/lib/CodeGen/ABIInfo.h