clang 20.0.0git
ABIInfoImpl.h
Go to the documentation of this file.
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
15namespace 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.
21class DefaultABIInfo : public ABIInfo {
22public:
24
25 virtual ~DefaultABIInfo();
26
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
51 llvm::LLVMContext &LLVMContext);
52
53void AssignToArrayRange(CodeGen::CGBuilderTy &Builder, llvm::Value *Array,
54 llvm::Value *Value, unsigned FirstIndex,
55 unsigned LastIndex);
56
58
60
62
64
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".
71
72// Dynamically round a pointer up to a multiple of the given alignment.
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.
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.
116 QualType ValueTy, bool IsIndirect,
117 TypeInfoChars ValueInfo, CharUnits SlotSizeAndAlign,
118 bool AllowHigherAlign, AggValueSlot Slot,
119 bool ForceRightAdjust = false);
120
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.
129bool 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.
137bool 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.
142bool 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.
148bool 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.
159
161 const ABIArgInfo &AI);
162
163bool isSIMDVectorType(ASTContext &Context, QualType Ty);
164
166
167} // namespace clang::CodeGen
168
169#endif // LLVM_CLANG_LIB_CODEGEN_ABIINFOIMPL_H
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
Implements C++ ABI-specific semantic analysis functions.
Definition: CXXABI.h:29
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
ABIInfo - Target specific hooks for defining how a type should be passed or returned from functions.
Definition: ABIInfo.h:47
CodeGen::CodeGenTypes & CGT
Definition: ABIInfo.h:49
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
Definition: Address.h:128
An aggregate value slot.
Definition: CGValue.h:504
Implements C++ ABI-specific code generation functions.
Definition: CGCXXABI.h:43
RecordArgABI
Specify how one should pass an argument of a record type.
Definition: CGCXXABI.h:150
CGFunctionInfo - Class to encapsulate the information about a function definition.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
Definition: CodeGenTypes.h:54
DefaultABIInfo - The default implementation for ABI specific details.
Definition: ABIInfoImpl.h:21
DefaultABIInfo(CodeGen::CodeGenTypes &CGT)
Definition: ABIInfoImpl.h:23
ABIArgInfo classifyArgumentType(QualType RetTy) const
Definition: ABIInfoImpl.cpp:17
RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, AggValueSlot Slot) const override
EmitVAArg - Emit the target dependent code to load a value of.
Definition: ABIInfoImpl.cpp:75
ABIArgInfo classifyReturnType(QualType RetTy) const
Definition: ABIInfoImpl.cpp:46
void computeInfo(CGFunctionInfo &FI) const override
Definition: ABIInfoImpl.cpp:68
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:42
Represents a member of a struct/union/class.
Definition: Decl.h:3030
A (possibly-)qualified type.
Definition: Type.h:941
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5965
The base class of the type hierarchy.
Definition: Type.h:1829
bool isEmptyRecordForLayout(const ASTContext &Context, QualType T)
isEmptyRecordForLayout - Return true iff a structure contains only empty base classes (per isEmptyRec...
CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI)
bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI, const ABIInfo &Info)
Address EmitVAArgInstr(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, const ABIArgInfo &AI)
bool isEmptyFieldForLayout(const ASTContext &Context, const FieldDecl *FD)
isEmptyFieldForLayout - Return true iff the field is "empty", that is, either a zero-width bit-field ...
Address emitVoidPtrDirectVAArg(CodeGenFunction &CGF, Address VAListAddr, llvm::Type *DirectTy, CharUnits DirectSize, CharUnits DirectAlign, CharUnits SlotSize, bool AllowHigherAlign, bool ForceRightAdjust=false)
Emit va_arg for a platform using the common void* representation, where arguments are simply emitted ...
bool isRecordWithSIMDVectorType(ASTContext &Context, QualType Ty)
RValue emitVoidPtrVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType ValueTy, bool IsIndirect, TypeInfoChars ValueInfo, CharUnits SlotSizeAndAlign, bool AllowHigherAlign, AggValueSlot Slot, bool ForceRightAdjust=false)
Emit va_arg for a platform using the common void* representation, where arguments are simply emitted ...
Address emitMergePHI(CodeGenFunction &CGF, Address Addr1, llvm::BasicBlock *Block1, Address Addr2, llvm::BasicBlock *Block2, const llvm::Twine &Name="")
bool isEmptyField(ASTContext &Context, const FieldDecl *FD, bool AllowArrays, bool AsIfNoUniqueAddr=false)
isEmptyField - Return true iff a the field is "empty", that is it is an unnamed bit-field or an (arra...
ABIArgInfo coerceToIntArray(QualType Ty, ASTContext &Context, llvm::LLVMContext &LLVMContext)
Definition: ABIInfoImpl.cpp:83
llvm::Value * emitRoundPointerUpToAlignment(CodeGenFunction &CGF, llvm::Value *Ptr, CharUnits Align)
bool isAggregateTypeForABI(QualType T)
const Type * isSingleElementStruct(QualType T, ASTContext &Context)
isSingleElementStruct - Determine if a structure is a "single element struct", i.e.
llvm::Type * getVAListElementType(CodeGenFunction &CGF)
void AssignToArrayRange(CodeGen::CGBuilderTy &Builder, llvm::Value *Array, llvm::Value *Value, unsigned FirstIndex, unsigned LastIndex)
Definition: ABIInfoImpl.cpp:93
QualType useFirstFieldIfTransparentUnion(QualType Ty)
Pass transparent unions as if they were the type of the first element.
bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays, bool AsIfNoUniqueAddr=false)
isEmptyRecord - Return true iff a structure contains only empty fields.
bool isSIMDVectorType(ASTContext &Context, QualType Ty)
const FunctionProtoType * T