Path: blob/main/contrib/llvm-project/clang/lib/CodeGen/ABIInfo.h
35233 views
//===----- ABIInfo.h - ABI information access & encapsulation ---*- 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_ABIINFO_H9#define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H1011#include "clang/AST/Attr.h"12#include "clang/AST/CharUnits.h"13#include "clang/AST/Type.h"14#include "llvm/IR/CallingConv.h"15#include "llvm/IR/Type.h"1617namespace llvm {18class Value;19class LLVMContext;20class DataLayout;21class Type;22} // namespace llvm2324namespace clang {25class ASTContext;26class CodeGenOptions;27class TargetInfo;2829namespace CodeGen {30class ABIArgInfo;31class Address;32class CGCXXABI;33class CGFunctionInfo;34class CodeGenFunction;35class CodeGenTypes;36class RValue;37class AggValueSlot;3839// FIXME: All of this stuff should be part of the target interface40// somehow. It is currently here because it is not clear how to factor41// the targets to support this, since the Targets currently live in a42// layer below types n'stuff.4344/// ABIInfo - Target specific hooks for defining how a type should be45/// passed or returned from functions.46class ABIInfo {47protected:48CodeGen::CodeGenTypes &CGT;49llvm::CallingConv::ID RuntimeCC;5051public:52ABIInfo(CodeGen::CodeGenTypes &cgt)53: CGT(cgt), RuntimeCC(llvm::CallingConv::C) {}5455virtual ~ABIInfo();5657virtual bool allowBFloatArgsAndRet() const { return false; }5859CodeGen::CGCXXABI &getCXXABI() const;60ASTContext &getContext() const;61llvm::LLVMContext &getVMContext() const;62const llvm::DataLayout &getDataLayout() const;63const TargetInfo &getTarget() const;64const CodeGenOptions &getCodeGenOpts() const;6566/// Return the calling convention to use for system runtime67/// functions.68llvm::CallingConv::ID getRuntimeCC() const { return RuntimeCC; }6970virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;7172/// EmitVAArg - Emit the target dependent code to load a value of73/// \arg Ty from the va_list pointed to by \arg VAListAddr.7475// FIXME: This is a gaping layering violation if we wanted to drop76// the ABI information any lower than CodeGen. Of course, for77// VAArg handling it has to be at this level; there is no way to78// abstract this out.79virtual RValue EmitVAArg(CodeGen::CodeGenFunction &CGF,80CodeGen::Address VAListAddr, QualType Ty,81AggValueSlot Slot) const = 0;8283bool isAndroid() const;84bool isOHOSFamily() const;8586/// Emit the target dependent code to load a value of87/// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.88virtual RValue EmitMSVAArg(CodeGen::CodeGenFunction &CGF,89CodeGen::Address VAListAddr, QualType Ty,90AggValueSlot Slot) const;9192virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;9394virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,95uint64_t Members) const;96virtual bool isZeroLengthBitfieldPermittedInHomogeneousAggregate() const;9798/// isHomogeneousAggregate - Return true if a type is an ELFv2 homogeneous99/// aggregate. Base is set to the base element type, and Members is set100/// to the number of base elements.101bool isHomogeneousAggregate(QualType Ty, const Type *&Base,102uint64_t &Members) const;103104// Implement the Type::IsPromotableIntegerType for ABI specific needs. The105// only difference is that this considers bit-precise integer types as well.106bool isPromotableIntegerTypeForABI(QualType Ty) const;107108/// A convenience method to return an indirect ABIArgInfo with an109/// expected alignment equal to the ABI alignment of the given type.110CodeGen::ABIArgInfo111getNaturalAlignIndirect(QualType Ty, bool ByVal = true, bool Realign = false,112llvm::Type *Padding = nullptr) const;113114CodeGen::ABIArgInfo getNaturalAlignIndirectInReg(QualType Ty,115bool Realign = false) const;116117virtual void appendAttributeMangling(TargetAttr *Attr,118raw_ostream &Out) const;119virtual void appendAttributeMangling(TargetVersionAttr *Attr,120raw_ostream &Out) const;121virtual void appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,122raw_ostream &Out) const;123virtual void appendAttributeMangling(StringRef AttrStr,124raw_ostream &Out) const;125};126127/// Target specific hooks for defining how a type should be passed or returned128/// from functions with one of the Swift calling conventions.129class SwiftABIInfo {130protected:131CodeGenTypes &CGT;132bool SwiftErrorInRegister;133134bool occupiesMoreThan(ArrayRef<llvm::Type *> scalarTypes,135unsigned maxAllRegisters) const;136137public:138SwiftABIInfo(CodeGen::CodeGenTypes &CGT, bool SwiftErrorInRegister)139: CGT(CGT), SwiftErrorInRegister(SwiftErrorInRegister) {}140141virtual ~SwiftABIInfo();142143/// Returns true if an aggregate which expands to the given type sequence144/// should be passed / returned indirectly.145virtual bool shouldPassIndirectly(ArrayRef<llvm::Type *> ComponentTys,146bool AsReturnValue) const;147148/// Returns true if the given vector type is legal from Swift's calling149/// convention perspective.150virtual bool isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,151unsigned NumElts) const;152153/// Returns true if swifterror is lowered to a register by the target ABI.154bool isSwiftErrorInRegister() const { return SwiftErrorInRegister; };155};156} // end namespace CodeGen157} // end namespace clang158159#endif160161162