brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.1 KiB · d9d79c6 Raw
153 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFOIMPL_H10#define LLVM_CLANG_LIB_CODEGEN_ABIINFOIMPL_H11 12#include "ABIInfo.h"13#include "CGCXXABI.h"14 15namespace clang::CodeGen {16 17/// DefaultABIInfo - The default implementation for ABI specific18/// details. This implementation provides information which results in19/// self-consistent and sensible LLVM IR generation, but does not20/// conform to any particular ABI.21class DefaultABIInfo : public ABIInfo {22public: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 36void AssignToArrayRange(CodeGen::CGBuilderTy &Builder, llvm::Value *Array,37                        llvm::Value *Value, unsigned FirstIndex,38                        unsigned LastIndex);39 40bool isAggregateTypeForABI(QualType T);41 42llvm::Type *getVAListElementType(CodeGenFunction &CGF);43 44CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI);45 46CGCXXABI::RecordArgABI getRecordArgABI(QualType T, CGCXXABI &CXXABI);47 48bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI,49                        const ABIInfo &Info);50 51/// Pass transparent unions as if they were the type of the first element. Sema52/// should ensure that all elements of the union have the same "machine type".53QualType useFirstFieldIfTransparentUnion(QualType Ty);54 55// Dynamically round a pointer up to a multiple of the given alignment.56llvm::Value *emitRoundPointerUpToAlignment(CodeGenFunction &CGF,57                                           llvm::Value *Ptr, CharUnits Align);58 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.61///62/// This version implements the core direct-value passing rules.63///64/// \param SlotSize - The size and alignment of a stack slot.65///   Each argument will be allocated to a multiple of this number of66///   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 size69///   will be emitted on a higher-alignment address, potentially70///   leaving one or more empty slots behind as padding.  If this71///   is false, the returned address might be less-aligned than72///   DirectAlign.73/// \param ForceRightAdjust - Default is false. On big-endian platform and74///   if the argument is smaller than a slot, set this flag will force75///   right-adjust the argument in its slot irrespective of the type.76Address emitVoidPtrDirectVAArg(CodeGenFunction &CGF, Address VAListAddr,77                               llvm::Type *DirectTy, CharUnits DirectSize,78                               CharUnits DirectAlign, CharUnits SlotSize,79                               bool AllowHigherAlign,80                               bool ForceRightAdjust = false);81 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.84///85/// \param IsIndirect - Values of this type are passed indirectly.86/// \param ValueInfo - The size and alignment of this type, generally87///   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 of90///   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 size93///   will be emitted on a higher-alignment address, potentially94///   leaving one or more empty slots behind as padding.95/// \param ForceRightAdjust - Default is false. On big-endian platform and96///   if the argument is smaller than a slot, set this flag will force97///   right-adjust the argument in its slot irrespective of the type.98RValue emitVoidPtrVAArg(CodeGenFunction &CGF, Address VAListAddr,99                        QualType ValueTy, bool IsIndirect,100                        TypeInfoChars ValueInfo, CharUnits SlotSizeAndAlign,101                        bool AllowHigherAlign, AggValueSlot Slot,102                        bool ForceRightAdjust = false);103 104Address emitMergePHI(CodeGenFunction &CGF, Address Addr1,105                     llvm::BasicBlock *Block1, Address Addr2,106                     llvm::BasicBlock *Block2, const llvm::Twine &Name = "");107 108/// isEmptyField - Return true iff a the field is "empty", that is it109/// is an unnamed bit-field or an (array of) empty record(s). If110/// AsIfNoUniqueAddr is true, then C++ record fields are considered empty if111/// the [[no_unique_address]] attribute would have made them empty.112bool isEmptyField(ASTContext &Context, const FieldDecl *FD, bool AllowArrays,113                  bool AsIfNoUniqueAddr = false);114 115/// isEmptyRecord - Return true iff a structure contains only empty116/// fields. Note that a structure with a flexible array member is not117/// considered empty. If AsIfNoUniqueAddr is true, then C++ record fields are118/// considered empty if the [[no_unique_address]] attribute would have made119/// them empty.120bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays,121                   bool AsIfNoUniqueAddr = false);122 123/// isEmptyFieldForLayout - Return true iff the field is "empty", that is,124/// either a zero-width bit-field or an \ref isEmptyRecordForLayout.125bool isEmptyFieldForLayout(const ASTContext &Context, const FieldDecl *FD);126 127/// isEmptyRecordForLayout - Return true iff a structure contains only empty128/// base classes (per \ref isEmptyRecordForLayout) and fields (per129/// \ref isEmptyFieldForLayout). Note, C++ record fields are considered empty130/// if the [[no_unique_address]] attribute would have made them empty.131bool isEmptyRecordForLayout(const ASTContext &Context, QualType T);132 133/// isSingleElementStruct - Determine if a structure is a "single134/// element struct", i.e. it has exactly one non-empty field or135/// exactly one field which is itself a single element136/// struct. Structures with flexible array members are never137/// considered single element structs.138///139/// \return The field declaration for the single non-empty field, if140/// it exists.141const Type *isSingleElementStruct(QualType T, ASTContext &Context);142 143Address EmitVAArgInstr(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,144                       const ABIArgInfo &AI);145 146bool isSIMDVectorType(ASTContext &Context, QualType Ty);147 148bool isRecordWithSIMDVectorType(ASTContext &Context, QualType Ty);149 150} // namespace clang::CodeGen151 152#endif // LLVM_CLANG_LIB_CODEGEN_ABIINFOIMPL_H153