Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/llvm-project/clang/lib/CodeGen/ABIInfoImpl.h
35233 views
1
//===- ABIInfoImpl.h --------------------------------------------*- 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_ABIINFOIMPL_H
10
#define LLVM_CLANG_LIB_CODEGEN_ABIINFOIMPL_H
11
12
#include "ABIInfo.h"
13
#include "CGCXXABI.h"
14
15
namespace clang::CodeGen {
16
17
/// DefaultABIInfo - The default implementation for ABI specific
18
/// details. This implementation provides information which results in
19
/// self-consistent and sensible LLVM IR generation, but does not
20
/// conform to any particular ABI.
21
class DefaultABIInfo : public ABIInfo {
22
public:
23
DefaultABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {}
24
25
virtual ~DefaultABIInfo();
26
27
ABIArgInfo classifyReturnType(QualType RetTy) const;
28
ABIArgInfo classifyArgumentType(QualType RetTy) const;
29
30
void computeInfo(CGFunctionInfo &FI) const override;
31
32
RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
33
AggValueSlot Slot) const override;
34
};
35
36
// Helper for coercing an aggregate argument or return value into an integer
37
// array of the same size (including padding) and alignment. This alternate
38
// coercion happens only for the RenderScript ABI and can be removed after
39
// runtimes that rely on it are no longer supported.
40
//
41
// RenderScript assumes that the size of the argument / return value in the IR
42
// is the same as the size of the corresponding qualified type. This helper
43
// coerces the aggregate type into an array of the same size (including
44
// padding). This coercion is used in lieu of expansion of struct members or
45
// other canonical coercions that return a coerced-type of larger size.
46
//
47
// Ty - The argument / return value type
48
// Context - The associated ASTContext
49
// LLVMContext - The associated LLVMContext
50
ABIArgInfo coerceToIntArray(QualType Ty, ASTContext &Context,
51
llvm::LLVMContext &LLVMContext);
52
53
void AssignToArrayRange(CodeGen::CGBuilderTy &Builder, llvm::Value *Array,
54
llvm::Value *Value, unsigned FirstIndex,
55
unsigned LastIndex);
56
57
bool isAggregateTypeForABI(QualType T);
58
59
llvm::Type *getVAListElementType(CodeGenFunction &CGF);
60
61
CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI);
62
63
CGCXXABI::RecordArgABI getRecordArgABI(QualType T, CGCXXABI &CXXABI);
64
65
bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI,
66
const ABIInfo &Info);
67
68
/// Pass transparent unions as if they were the type of the first element. Sema
69
/// should ensure that all elements of the union have the same "machine type".
70
QualType useFirstFieldIfTransparentUnion(QualType Ty);
71
72
// Dynamically round a pointer up to a multiple of the given alignment.
73
llvm::Value *emitRoundPointerUpToAlignment(CodeGenFunction &CGF,
74
llvm::Value *Ptr, CharUnits Align);
75
76
/// Emit va_arg for a platform using the common void* representation,
77
/// where arguments are simply emitted in an array of slots on the stack.
78
///
79
/// This version implements the core direct-value passing rules.
80
///
81
/// \param SlotSize - The size and alignment of a stack slot.
82
/// Each argument will be allocated to a multiple of this number of
83
/// slots, and all the slots will be aligned to this value.
84
/// \param AllowHigherAlign - The slot alignment is not a cap;
85
/// an argument type with an alignment greater than the slot size
86
/// will be emitted on a higher-alignment address, potentially
87
/// leaving one or more empty slots behind as padding. If this
88
/// is false, the returned address might be less-aligned than
89
/// DirectAlign.
90
/// \param ForceRightAdjust - Default is false. On big-endian platform and
91
/// if the argument is smaller than a slot, set this flag will force
92
/// right-adjust the argument in its slot irrespective of the type.
93
Address emitVoidPtrDirectVAArg(CodeGenFunction &CGF, Address VAListAddr,
94
llvm::Type *DirectTy, CharUnits DirectSize,
95
CharUnits DirectAlign, CharUnits SlotSize,
96
bool AllowHigherAlign,
97
bool ForceRightAdjust = false);
98
99
/// Emit va_arg for a platform using the common void* representation,
100
/// where arguments are simply emitted in an array of slots on the stack.
101
///
102
/// \param IsIndirect - Values of this type are passed indirectly.
103
/// \param ValueInfo - The size and alignment of this type, generally
104
/// computed with getContext().getTypeInfoInChars(ValueTy).
105
/// \param SlotSizeAndAlign - The size and alignment of a stack slot.
106
/// Each argument will be allocated to a multiple of this number of
107
/// slots, and all the slots will be aligned to this value.
108
/// \param AllowHigherAlign - The slot alignment is not a cap;
109
/// an argument type with an alignment greater than the slot size
110
/// will be emitted on a higher-alignment address, potentially
111
/// leaving one or more empty slots behind as padding.
112
/// \param ForceRightAdjust - Default is false. On big-endian platform and
113
/// if the argument is smaller than a slot, set this flag will force
114
/// right-adjust the argument in its slot irrespective of the type.
115
RValue emitVoidPtrVAArg(CodeGenFunction &CGF, Address VAListAddr,
116
QualType ValueTy, bool IsIndirect,
117
TypeInfoChars ValueInfo, CharUnits SlotSizeAndAlign,
118
bool AllowHigherAlign, AggValueSlot Slot,
119
bool ForceRightAdjust = false);
120
121
Address emitMergePHI(CodeGenFunction &CGF, Address Addr1,
122
llvm::BasicBlock *Block1, Address Addr2,
123
llvm::BasicBlock *Block2, const llvm::Twine &Name = "");
124
125
/// isEmptyField - Return true iff a the field is "empty", that is it
126
/// is an unnamed bit-field or an (array of) empty record(s). If
127
/// AsIfNoUniqueAddr is true, then C++ record fields are considered empty if
128
/// the [[no_unique_address]] attribute would have made them empty.
129
bool isEmptyField(ASTContext &Context, const FieldDecl *FD, bool AllowArrays,
130
bool AsIfNoUniqueAddr = false);
131
132
/// isEmptyRecord - Return true iff a structure contains only empty
133
/// fields. Note that a structure with a flexible array member is not
134
/// considered empty. If AsIfNoUniqueAddr is true, then C++ record fields are
135
/// considered empty if the [[no_unique_address]] attribute would have made
136
/// them empty.
137
bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays,
138
bool AsIfNoUniqueAddr = false);
139
140
/// isEmptyFieldForLayout - Return true iff the field is "empty", that is,
141
/// either a zero-width bit-field or an \ref isEmptyRecordForLayout.
142
bool isEmptyFieldForLayout(const ASTContext &Context, const FieldDecl *FD);
143
144
/// isEmptyRecordForLayout - Return true iff a structure contains only empty
145
/// base classes (per \ref isEmptyRecordForLayout) and fields (per
146
/// \ref isEmptyFieldForLayout). Note, C++ record fields are considered empty
147
/// if the [[no_unique_address]] attribute would have made them empty.
148
bool isEmptyRecordForLayout(const ASTContext &Context, QualType T);
149
150
/// isSingleElementStruct - Determine if a structure is a "single
151
/// element struct", i.e. it has exactly one non-empty field or
152
/// exactly one field which is itself a single element
153
/// struct. Structures with flexible array members are never
154
/// considered single element structs.
155
///
156
/// \return The field declaration for the single non-empty field, if
157
/// it exists.
158
const Type *isSingleElementStruct(QualType T, ASTContext &Context);
159
160
Address EmitVAArgInstr(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
161
const ABIArgInfo &AI);
162
163
bool isSIMDVectorType(ASTContext &Context, QualType Ty);
164
165
bool isRecordWithSIMDVectorType(ASTContext &Context, QualType Ty);
166
167
} // namespace clang::CodeGen
168
169
#endif // LLVM_CLANG_LIB_CODEGEN_ABIINFOIMPL_H
170
171