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;
39 class SwiftAggLowering;
42 // FIXME: All of this stuff should be part of the target interface
43 // somehow. It is currently here because it is not clear how to factor
44 // the targets to support this, since the Targets currently live in a
45 // layer below types n'stuff.
48 /// ABIInfo - Target specific hooks for defining how a type should be
49 /// passed or returned from functions.
52 CodeGen::CodeGenTypes &CGT;
54 llvm::CallingConv::ID RuntimeCC;
56 ABIInfo(CodeGen::CodeGenTypes &cgt)
57 : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {}
61 virtual bool supportsSwift() const { return false; }
63 CodeGen::CGCXXABI &getCXXABI() const;
64 ASTContext &getContext() const;
65 llvm::LLVMContext &getVMContext() const;
66 const llvm::DataLayout &getDataLayout() const;
67 const TargetInfo &getTarget() const;
68 const CodeGenOptions &getCodeGenOpts() const;
70 /// Return the calling convention to use for system runtime
72 llvm::CallingConv::ID getRuntimeCC() const {
76 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
78 /// EmitVAArg - Emit the target dependent code to load a value of
79 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
81 // FIXME: This is a gaping layering violation if we wanted to drop
82 // the ABI information any lower than CodeGen. Of course, for
83 // VAArg handling it has to be at this level; there is no way to
85 virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
86 CodeGen::Address VAListAddr,
87 QualType Ty) const = 0;
89 bool isAndroid() const;
91 /// Emit the target dependent code to load a value of
92 /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
93 virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
94 CodeGen::Address VAListAddr,
97 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
99 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
100 uint64_t Members) const;
102 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
103 uint64_t &Members) const;
105 /// A convenience method to return an indirect ABIArgInfo with an
106 /// expected alignment equal to the ABI alignment of the given type.
108 getNaturalAlignIndirect(QualType Ty, bool ByRef = true,
109 bool Realign = false,
110 llvm::Type *Padding = nullptr) const;
113 getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;
118 /// A refining implementation of ABIInfo for targets that support swiftcall.
120 /// If we find ourselves wanting multiple such refinements, they'll probably
121 /// be independent refinements, and we should probably find another way
122 /// to do it than simple inheritance.
123 class SwiftABIInfo : public ABIInfo {
125 SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {}
127 bool supportsSwift() const final override { return true; }
129 virtual bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type*> types,
130 bool asReturnValue) const = 0;
132 virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,
134 unsigned elts) const;
136 virtual bool isSwiftErrorInRegister() const = 0;
138 static bool classof(const ABIInfo *info) {
139 return info->supportsSwift();
142 } // end namespace CodeGen
143 } // end namespace clang