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
;
37 // FIXME: All of this stuff should be part of the target interface
38 // somehow. It is currently here because it is not clear how to factor
39 // the targets to support this, since the Targets currently live in a
40 // layer below types n'stuff.
43 /// ABIInfo - Target specific hooks for defining how a type should be
44 /// passed or returned from functions.
47 CodeGen::CodeGenTypes
&CGT
;
48 llvm::CallingConv::ID RuntimeCC
;
50 ABIInfo(CodeGen::CodeGenTypes
&cgt
)
51 : CGT(cgt
), RuntimeCC(llvm::CallingConv::C
) {}
55 virtual bool allowBFloatArgsAndRet() const { return false; }
57 CodeGen::CGCXXABI
&getCXXABI() const;
58 ASTContext
&getContext() const;
59 llvm::LLVMContext
&getVMContext() const;
60 const llvm::DataLayout
&getDataLayout() const;
61 const TargetInfo
&getTarget() const;
62 const CodeGenOptions
&getCodeGenOpts() const;
64 /// Return the calling convention to use for system runtime
66 llvm::CallingConv::ID
getRuntimeCC() const {
70 virtual void computeInfo(CodeGen::CGFunctionInfo
&FI
) const = 0;
72 /// EmitVAArg - Emit the target dependent code to load a value of
73 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
75 // FIXME: This is a gaping layering violation if we wanted to drop
76 // the ABI information any lower than CodeGen. Of course, for
77 // VAArg handling it has to be at this level; there is no way to
79 virtual CodeGen::Address
EmitVAArg(CodeGen::CodeGenFunction
&CGF
,
80 CodeGen::Address VAListAddr
,
81 QualType Ty
) const = 0;
83 bool isAndroid() const;
85 /// Emit the target dependent code to load a value of
86 /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
87 virtual CodeGen::Address
EmitMSVAArg(CodeGen::CodeGenFunction
&CGF
,
88 CodeGen::Address VAListAddr
,
91 virtual bool isHomogeneousAggregateBaseType(QualType Ty
) const;
93 virtual bool isHomogeneousAggregateSmallEnough(const Type
*Base
,
94 uint64_t Members
) const;
95 virtual bool isZeroLengthBitfieldPermittedInHomogeneousAggregate() const;
97 bool isHomogeneousAggregate(QualType Ty
, const Type
*&Base
,
98 uint64_t &Members
) const;
100 // Implement the Type::IsPromotableIntegerType for ABI specific needs. The
101 // only difference is that this considers bit-precise integer types as well.
102 bool isPromotableIntegerTypeForABI(QualType Ty
) const;
104 /// A convenience method to return an indirect ABIArgInfo with an
105 /// expected alignment equal to the ABI alignment of the given type.
107 getNaturalAlignIndirect(QualType Ty
, bool ByVal
= true,
108 bool Realign
= false,
109 llvm::Type
*Padding
= nullptr) const;
112 getNaturalAlignIndirectInReg(QualType Ty
, bool Realign
= false) const;
115 /// Target specific hooks for defining how a type should be passed or returned
116 /// from functions with one of the Swift calling conventions.
120 bool SwiftErrorInRegister
;
123 SwiftABIInfo(CodeGen::CodeGenTypes
&CGT
, bool SwiftErrorInRegister
)
124 : CGT(CGT
), SwiftErrorInRegister(SwiftErrorInRegister
) {}
126 virtual ~SwiftABIInfo();
128 /// Returns true if an aggregate which expands to the given type sequence
129 /// should be passed / returned indirectly.
130 virtual bool shouldPassIndirectly(ArrayRef
<llvm::Type
*> ComponentTys
,
131 bool AsReturnValue
) const;
133 /// Returns true if the given vector type is legal from Swift's calling
134 /// convention perspective.
135 virtual bool isLegalVectorType(CharUnits VectorSize
, llvm::Type
*EltTy
,
136 unsigned NumElts
) const;
138 /// Returns true if swifterror is lowered to a register by the target ABI.
139 bool isSwiftErrorInRegister() const { return SwiftErrorInRegister
; };
141 } // end namespace CodeGen
142 } // end namespace clang