1 //===----- ABIInfo.h - ABI information access & encapsulation ---*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
10 #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_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"
34 class CodeGenFunction;
38 // FIXME: All of this stuff should be part of the target interface
39 // somehow. It is currently here because it is not clear how to factor
40 // the targets to support this, since the Targets currently live in a
41 // layer below types n'stuff.
44 /// ABIInfo - Target specific hooks for defining how a type should be
45 /// passed or returned from functions.
48 CodeGen::CodeGenTypes &CGT;
50 llvm::CallingConv::ID RuntimeCC;
52 ABIInfo(CodeGen::CodeGenTypes &cgt)
53 : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {}
57 virtual bool supportsSwift() const { return false; }
59 virtual bool allowBFloatArgsAndRet() const { return false; }
61 CodeGen::CGCXXABI &getCXXABI() const;
62 ASTContext &getContext() const;
63 llvm::LLVMContext &getVMContext() const;
64 const llvm::DataLayout &getDataLayout() const;
65 const TargetInfo &getTarget() const;
66 const CodeGenOptions &getCodeGenOpts() const;
68 /// Return the calling convention to use for system runtime
70 llvm::CallingConv::ID getRuntimeCC() const {
74 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
76 /// EmitVAArg - Emit the target dependent code to load a value of
77 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
79 // FIXME: This is a gaping layering violation if we wanted to drop
80 // the ABI information any lower than CodeGen. Of course, for
81 // VAArg handling it has to be at this level; there is no way to
83 virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
84 CodeGen::Address VAListAddr,
85 QualType Ty) const = 0;
87 bool isAndroid() const;
89 /// Emit the target dependent code to load a value of
90 /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
91 virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
92 CodeGen::Address VAListAddr,
95 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
97 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
98 uint64_t Members) const;
99 virtual bool isZeroLengthBitfieldPermittedInHomogeneousAggregate() const;
101 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
102 uint64_t &Members) const;
104 // Implement the Type::IsPromotableIntegerType for ABI specific needs. The
105 // only difference is that this considers bit-precise integer types as well.
106 bool isPromotableIntegerTypeForABI(QualType Ty) const;
108 /// A convenience method to return an indirect ABIArgInfo with an
109 /// expected alignment equal to the ABI alignment of the given type.
111 getNaturalAlignIndirect(QualType Ty, bool ByVal = true,
112 bool Realign = false,
113 llvm::Type *Padding = nullptr) const;
116 getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
121 /// A refining implementation of ABIInfo for targets that support swiftcall.
123 /// If we find ourselves wanting multiple such refinements, they'll probably
124 /// be independent refinements, and we should probably find another way
125 /// to do it than simple inheritance.
126 class SwiftABIInfo : public ABIInfo {
128 SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {}
130 bool supportsSwift() const final override { return true; }
132 virtual bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type*> types,
133 bool asReturnValue) const = 0;
135 virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
137 unsigned elts) const;
139 virtual bool isSwiftErrorInRegister() const = 0;
141 static bool classof(const ABIInfo *info) {
142 return info->supportsSwift();
145 } // end namespace CodeGen
146 } // end namespace clang