1193326Sed//===----- ABIInfo.h - ABI information access & encapsulation ---*- C++ -*-===// 2193326Sed// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6193326Sed// 7193326Sed//===----------------------------------------------------------------------===// 8193326Sed 9280031Sdim#ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H 10280031Sdim#define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H 11193326Sed 12321369Sdim#include "clang/AST/CharUnits.h" 13193576Sed#include "clang/AST/Type.h" 14276479Sdim#include "llvm/IR/CallingConv.h" 15249423Sdim#include "llvm/IR/Type.h" 16193576Sed 17193326Sednamespace llvm { 18193576Sed class Value; 19198092Srdivacky class LLVMContext; 20243830Sdim class DataLayout; 21309124Sdim class Type; 22193326Sed} 23193326Sed 24193326Sednamespace clang { 25193326Sed class ASTContext; 26323112Sdim class CodeGenOptions; 27251662Sdim class TargetInfo; 28193326Sed 29309124Sdimnamespace CodeGen { 30309124Sdim class ABIArgInfo; 31309124Sdim class Address; 32309124Sdim class CGCXXABI; 33309124Sdim class CGFunctionInfo; 34309124Sdim class CodeGenFunction; 35309124Sdim class CodeGenTypes; 36309124Sdim class SwiftABIInfo; 37193326Sed 38309124Sdimnamespace swiftcall { 39309124Sdim class SwiftAggLowering; 40309124Sdim} 41309124Sdim 42212904Sdim // FIXME: All of this stuff should be part of the target interface 43212904Sdim // somehow. It is currently here because it is not clear how to factor 44212904Sdim // the targets to support this, since the Targets currently live in a 45212904Sdim // layer below types n'stuff. 46193326Sed 47193576Sed 48193326Sed /// ABIInfo - Target specific hooks for defining how a type should be 49193326Sed /// passed or returned from functions. 50193326Sed class ABIInfo { 51193326Sed public: 52212904Sdim CodeGen::CodeGenTypes &CGT; 53249423Sdim protected: 54249423Sdim llvm::CallingConv::ID RuntimeCC; 55249423Sdim public: 56249423Sdim ABIInfo(CodeGen::CodeGenTypes &cgt) 57341825Sdim : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {} 58218893Sdim 59193326Sed virtual ~ABIInfo(); 60218893Sdim 61309124Sdim virtual bool supportsSwift() const { return false; } 62309124Sdim 63261991Sdim CodeGen::CGCXXABI &getCXXABI() const; 64212904Sdim ASTContext &getContext() const; 65212904Sdim llvm::LLVMContext &getVMContext() const; 66243830Sdim const llvm::DataLayout &getDataLayout() const; 67251662Sdim const TargetInfo &getTarget() const; 68323112Sdim const CodeGenOptions &getCodeGenOpts() const; 69193326Sed 70249423Sdim /// Return the calling convention to use for system runtime 71249423Sdim /// functions. 72249423Sdim llvm::CallingConv::ID getRuntimeCC() const { 73249423Sdim return RuntimeCC; 74249423Sdim } 75249423Sdim 76212904Sdim virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0; 77193326Sed 78193326Sed /// EmitVAArg - Emit the target dependent code to load a value of 79193326Sed /// \arg Ty from the va_list pointed to by \arg VAListAddr. 80193576Sed 81193326Sed // FIXME: This is a gaping layering violation if we wanted to drop 82193326Sed // the ABI information any lower than CodeGen. Of course, for 83193326Sed // VAArg handling it has to be at this level; there is no way to 84193326Sed // abstract this out. 85296417Sdim virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF, 86296417Sdim CodeGen::Address VAListAddr, 87296417Sdim QualType Ty) const = 0; 88280031Sdim 89309124Sdim bool isAndroid() const; 90309124Sdim 91296417Sdim /// Emit the target dependent code to load a value of 92296417Sdim /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr. 93296417Sdim virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF, 94296417Sdim CodeGen::Address VAListAddr, 95296417Sdim QualType Ty) const; 96296417Sdim 97280031Sdim virtual bool isHomogeneousAggregateBaseType(QualType Ty) const; 98280031Sdim 99280031Sdim virtual bool isHomogeneousAggregateSmallEnough(const Type *Base, 100280031Sdim uint64_t Members) const; 101280031Sdim 102280031Sdim bool isHomogeneousAggregate(QualType Ty, const Type *&Base, 103280031Sdim uint64_t &Members) const; 104280031Sdim 105296417Sdim /// A convenience method to return an indirect ABIArgInfo with an 106296417Sdim /// expected alignment equal to the ABI alignment of the given type. 107296417Sdim CodeGen::ABIArgInfo 108296417Sdim getNaturalAlignIndirect(QualType Ty, bool ByRef = true, 109296417Sdim bool Realign = false, 110296417Sdim llvm::Type *Padding = nullptr) const; 111296417Sdim 112296417Sdim CodeGen::ABIArgInfo 113296417Sdim getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const; 114309124Sdim 115309124Sdim 116193326Sed }; 117309124Sdim 118309124Sdim /// A refining implementation of ABIInfo for targets that support swiftcall. 119309124Sdim /// 120309124Sdim /// If we find ourselves wanting multiple such refinements, they'll probably 121309124Sdim /// be independent refinements, and we should probably find another way 122309124Sdim /// to do it than simple inheritance. 123309124Sdim class SwiftABIInfo : public ABIInfo { 124309124Sdim public: 125309124Sdim SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {} 126309124Sdim 127309124Sdim bool supportsSwift() const final override { return true; } 128309124Sdim 129341825Sdim virtual bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type*> types, 130309124Sdim bool asReturnValue) const = 0; 131309124Sdim 132309124Sdim virtual bool isLegalVectorTypeForSwift(CharUnits totalSize, 133309124Sdim llvm::Type *eltTy, 134309124Sdim unsigned elts) const; 135309124Sdim 136314564Sdim virtual bool isSwiftErrorInRegister() const = 0; 137314564Sdim 138309124Sdim static bool classof(const ABIInfo *info) { 139309124Sdim return info->supportsSwift(); 140309124Sdim } 141309124Sdim }; 142309124Sdim} // end namespace CodeGen 143193326Sed} // end namespace clang 144193326Sed 145193326Sed#endif 146