1 //===- ABIInfoImpl.h --------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFOIMPL_H
10 #define LLVM_CLANG_LIB_CODEGEN_ABIINFOIMPL_H
15 namespace clang::CodeGen
{
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
{
23 DefaultABIInfo(CodeGen::CodeGenTypes
&CGT
) : ABIInfo(CGT
) {}
25 virtual ~DefaultABIInfo();
27 ABIArgInfo
classifyReturnType(QualType RetTy
) const;
28 ABIArgInfo
classifyArgumentType(QualType RetTy
) const;
30 void computeInfo(CGFunctionInfo
&FI
) const override
;
32 RValue
EmitVAArg(CodeGenFunction
&CGF
, Address VAListAddr
, QualType Ty
,
33 AggValueSlot Slot
) const override
;
36 void AssignToArrayRange(CodeGen::CGBuilderTy
&Builder
, llvm::Value
*Array
,
37 llvm::Value
*Value
, unsigned FirstIndex
,
40 bool isAggregateTypeForABI(QualType T
);
42 llvm::Type
*getVAListElementType(CodeGenFunction
&CGF
);
44 CGCXXABI::RecordArgABI
getRecordArgABI(const RecordType
*RT
, CGCXXABI
&CXXABI
);
46 CGCXXABI::RecordArgABI
getRecordArgABI(QualType T
, CGCXXABI
&CXXABI
);
48 bool classifyReturnType(const CGCXXABI
&CXXABI
, CGFunctionInfo
&FI
,
51 /// Pass transparent unions as if they were the type of the first element. Sema
52 /// should ensure that all elements of the union have the same "machine type".
53 QualType
useFirstFieldIfTransparentUnion(QualType Ty
);
55 // Dynamically round a pointer up to a multiple of the given alignment.
56 llvm::Value
*emitRoundPointerUpToAlignment(CodeGenFunction
&CGF
,
57 llvm::Value
*Ptr
, CharUnits Align
);
59 /// Emit va_arg for a platform using the common void* representation,
60 /// where arguments are simply emitted in an array of slots on the stack.
62 /// This version implements the core direct-value passing rules.
64 /// \param SlotSize - The size and alignment of a stack slot.
65 /// Each argument will be allocated to a multiple of this number of
66 /// slots, and all the slots will be aligned to this value.
67 /// \param AllowHigherAlign - The slot alignment is not a cap;
68 /// an argument type with an alignment greater than the slot size
69 /// will be emitted on a higher-alignment address, potentially
70 /// leaving one or more empty slots behind as padding. If this
71 /// is false, the returned address might be less-aligned than
73 /// \param ForceRightAdjust - Default is false. On big-endian platform and
74 /// if the argument is smaller than a slot, set this flag will force
75 /// right-adjust the argument in its slot irrespective of the type.
76 Address
emitVoidPtrDirectVAArg(CodeGenFunction
&CGF
, Address VAListAddr
,
77 llvm::Type
*DirectTy
, CharUnits DirectSize
,
78 CharUnits DirectAlign
, CharUnits SlotSize
,
79 bool AllowHigherAlign
,
80 bool ForceRightAdjust
= false);
82 /// Emit va_arg for a platform using the common void* representation,
83 /// where arguments are simply emitted in an array of slots on the stack.
85 /// \param IsIndirect - Values of this type are passed indirectly.
86 /// \param ValueInfo - The size and alignment of this type, generally
87 /// computed with getContext().getTypeInfoInChars(ValueTy).
88 /// \param SlotSizeAndAlign - The size and alignment of a stack slot.
89 /// Each argument will be allocated to a multiple of this number of
90 /// slots, and all the slots will be aligned to this value.
91 /// \param AllowHigherAlign - The slot alignment is not a cap;
92 /// an argument type with an alignment greater than the slot size
93 /// will be emitted on a higher-alignment address, potentially
94 /// leaving one or more empty slots behind as padding.
95 /// \param ForceRightAdjust - Default is false. On big-endian platform and
96 /// if the argument is smaller than a slot, set this flag will force
97 /// right-adjust the argument in its slot irrespective of the type.
98 RValue
emitVoidPtrVAArg(CodeGenFunction
&CGF
, Address VAListAddr
,
99 QualType ValueTy
, bool IsIndirect
,
100 TypeInfoChars ValueInfo
, CharUnits SlotSizeAndAlign
,
101 bool AllowHigherAlign
, AggValueSlot Slot
,
102 bool ForceRightAdjust
= false);
104 Address
emitMergePHI(CodeGenFunction
&CGF
, Address Addr1
,
105 llvm::BasicBlock
*Block1
, Address Addr2
,
106 llvm::BasicBlock
*Block2
, const llvm::Twine
&Name
= "");
108 /// isEmptyField - Return true iff a the field is "empty", that is it
109 /// is an unnamed bit-field or an (array of) empty record(s). If
110 /// AsIfNoUniqueAddr is true, then C++ record fields are considered empty if
111 /// the [[no_unique_address]] attribute would have made them empty.
112 bool isEmptyField(ASTContext
&Context
, const FieldDecl
*FD
, bool AllowArrays
,
113 bool AsIfNoUniqueAddr
= false);
115 /// isEmptyRecord - Return true iff a structure contains only empty
116 /// fields. Note that a structure with a flexible array member is not
117 /// considered empty. If AsIfNoUniqueAddr is true, then C++ record fields are
118 /// considered empty if the [[no_unique_address]] attribute would have made
120 bool isEmptyRecord(ASTContext
&Context
, QualType T
, bool AllowArrays
,
121 bool AsIfNoUniqueAddr
= false);
123 /// isEmptyFieldForLayout - Return true iff the field is "empty", that is,
124 /// either a zero-width bit-field or an \ref isEmptyRecordForLayout.
125 bool isEmptyFieldForLayout(const ASTContext
&Context
, const FieldDecl
*FD
);
127 /// isEmptyRecordForLayout - Return true iff a structure contains only empty
128 /// base classes (per \ref isEmptyRecordForLayout) and fields (per
129 /// \ref isEmptyFieldForLayout). Note, C++ record fields are considered empty
130 /// if the [[no_unique_address]] attribute would have made them empty.
131 bool isEmptyRecordForLayout(const ASTContext
&Context
, QualType T
);
133 /// isSingleElementStruct - Determine if a structure is a "single
134 /// element struct", i.e. it has exactly one non-empty field or
135 /// exactly one field which is itself a single element
136 /// struct. Structures with flexible array members are never
137 /// considered single element structs.
139 /// \return The field declaration for the single non-empty field, if
141 const Type
*isSingleElementStruct(QualType T
, ASTContext
&Context
);
143 Address
EmitVAArgInstr(CodeGenFunction
&CGF
, Address VAListAddr
, QualType Ty
,
144 const ABIArgInfo
&AI
);
146 bool isSIMDVectorType(ASTContext
&Context
, QualType Ty
);
148 bool isRecordWithSIMDVectorType(ASTContext
&Context
, QualType Ty
);
150 } // namespace clang::CodeGen
152 #endif // LLVM_CLANG_LIB_CODEGEN_ABIINFOIMPL_H