Path: blob/main/contrib/llvm-project/clang/lib/CodeGen/ABIInfoImpl.h
35233 views
//===- ABIInfoImpl.h --------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFOIMPL_H9#define LLVM_CLANG_LIB_CODEGEN_ABIINFOIMPL_H1011#include "ABIInfo.h"12#include "CGCXXABI.h"1314namespace clang::CodeGen {1516/// DefaultABIInfo - The default implementation for ABI specific17/// details. This implementation provides information which results in18/// self-consistent and sensible LLVM IR generation, but does not19/// conform to any particular ABI.20class DefaultABIInfo : public ABIInfo {21public:22DefaultABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {}2324virtual ~DefaultABIInfo();2526ABIArgInfo classifyReturnType(QualType RetTy) const;27ABIArgInfo classifyArgumentType(QualType RetTy) const;2829void computeInfo(CGFunctionInfo &FI) const override;3031RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,32AggValueSlot Slot) const override;33};3435// Helper for coercing an aggregate argument or return value into an integer36// array of the same size (including padding) and alignment. This alternate37// coercion happens only for the RenderScript ABI and can be removed after38// runtimes that rely on it are no longer supported.39//40// RenderScript assumes that the size of the argument / return value in the IR41// is the same as the size of the corresponding qualified type. This helper42// coerces the aggregate type into an array of the same size (including43// padding). This coercion is used in lieu of expansion of struct members or44// other canonical coercions that return a coerced-type of larger size.45//46// Ty - The argument / return value type47// Context - The associated ASTContext48// LLVMContext - The associated LLVMContext49ABIArgInfo coerceToIntArray(QualType Ty, ASTContext &Context,50llvm::LLVMContext &LLVMContext);5152void AssignToArrayRange(CodeGen::CGBuilderTy &Builder, llvm::Value *Array,53llvm::Value *Value, unsigned FirstIndex,54unsigned LastIndex);5556bool isAggregateTypeForABI(QualType T);5758llvm::Type *getVAListElementType(CodeGenFunction &CGF);5960CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI);6162CGCXXABI::RecordArgABI getRecordArgABI(QualType T, CGCXXABI &CXXABI);6364bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI,65const ABIInfo &Info);6667/// Pass transparent unions as if they were the type of the first element. Sema68/// should ensure that all elements of the union have the same "machine type".69QualType useFirstFieldIfTransparentUnion(QualType Ty);7071// Dynamically round a pointer up to a multiple of the given alignment.72llvm::Value *emitRoundPointerUpToAlignment(CodeGenFunction &CGF,73llvm::Value *Ptr, CharUnits Align);7475/// Emit va_arg for a platform using the common void* representation,76/// where arguments are simply emitted in an array of slots on the stack.77///78/// This version implements the core direct-value passing rules.79///80/// \param SlotSize - The size and alignment of a stack slot.81/// Each argument will be allocated to a multiple of this number of82/// slots, and all the slots will be aligned to this value.83/// \param AllowHigherAlign - The slot alignment is not a cap;84/// an argument type with an alignment greater than the slot size85/// will be emitted on a higher-alignment address, potentially86/// leaving one or more empty slots behind as padding. If this87/// is false, the returned address might be less-aligned than88/// DirectAlign.89/// \param ForceRightAdjust - Default is false. On big-endian platform and90/// if the argument is smaller than a slot, set this flag will force91/// right-adjust the argument in its slot irrespective of the type.92Address emitVoidPtrDirectVAArg(CodeGenFunction &CGF, Address VAListAddr,93llvm::Type *DirectTy, CharUnits DirectSize,94CharUnits DirectAlign, CharUnits SlotSize,95bool AllowHigherAlign,96bool ForceRightAdjust = false);9798/// Emit va_arg for a platform using the common void* representation,99/// where arguments are simply emitted in an array of slots on the stack.100///101/// \param IsIndirect - Values of this type are passed indirectly.102/// \param ValueInfo - The size and alignment of this type, generally103/// computed with getContext().getTypeInfoInChars(ValueTy).104/// \param SlotSizeAndAlign - The size and alignment of a stack slot.105/// Each argument will be allocated to a multiple of this number of106/// slots, and all the slots will be aligned to this value.107/// \param AllowHigherAlign - The slot alignment is not a cap;108/// an argument type with an alignment greater than the slot size109/// will be emitted on a higher-alignment address, potentially110/// leaving one or more empty slots behind as padding.111/// \param ForceRightAdjust - Default is false. On big-endian platform and112/// if the argument is smaller than a slot, set this flag will force113/// right-adjust the argument in its slot irrespective of the type.114RValue emitVoidPtrVAArg(CodeGenFunction &CGF, Address VAListAddr,115QualType ValueTy, bool IsIndirect,116TypeInfoChars ValueInfo, CharUnits SlotSizeAndAlign,117bool AllowHigherAlign, AggValueSlot Slot,118bool ForceRightAdjust = false);119120Address emitMergePHI(CodeGenFunction &CGF, Address Addr1,121llvm::BasicBlock *Block1, Address Addr2,122llvm::BasicBlock *Block2, const llvm::Twine &Name = "");123124/// isEmptyField - Return true iff a the field is "empty", that is it125/// is an unnamed bit-field or an (array of) empty record(s). If126/// AsIfNoUniqueAddr is true, then C++ record fields are considered empty if127/// the [[no_unique_address]] attribute would have made them empty.128bool isEmptyField(ASTContext &Context, const FieldDecl *FD, bool AllowArrays,129bool AsIfNoUniqueAddr = false);130131/// isEmptyRecord - Return true iff a structure contains only empty132/// fields. Note that a structure with a flexible array member is not133/// considered empty. If AsIfNoUniqueAddr is true, then C++ record fields are134/// considered empty if the [[no_unique_address]] attribute would have made135/// them empty.136bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays,137bool AsIfNoUniqueAddr = false);138139/// isEmptyFieldForLayout - Return true iff the field is "empty", that is,140/// either a zero-width bit-field or an \ref isEmptyRecordForLayout.141bool isEmptyFieldForLayout(const ASTContext &Context, const FieldDecl *FD);142143/// isEmptyRecordForLayout - Return true iff a structure contains only empty144/// base classes (per \ref isEmptyRecordForLayout) and fields (per145/// \ref isEmptyFieldForLayout). Note, C++ record fields are considered empty146/// if the [[no_unique_address]] attribute would have made them empty.147bool isEmptyRecordForLayout(const ASTContext &Context, QualType T);148149/// isSingleElementStruct - Determine if a structure is a "single150/// element struct", i.e. it has exactly one non-empty field or151/// exactly one field which is itself a single element152/// struct. Structures with flexible array members are never153/// considered single element structs.154///155/// \return The field declaration for the single non-empty field, if156/// it exists.157const Type *isSingleElementStruct(QualType T, ASTContext &Context);158159Address EmitVAArgInstr(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,160const ABIArgInfo &AI);161162bool isSIMDVectorType(ASTContext &Context, QualType Ty);163164bool isRecordWithSIMDVectorType(ASTContext &Context, QualType Ty);165166} // namespace clang::CodeGen167168#endif // LLVM_CLANG_LIB_CODEGEN_ABIINFOIMPL_H169170171