/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/CodeGen/ABIInfo.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===----- ABIInfo.h - ABI information access & encapsulation ---*- C++ -*-===// |
2 | | // |
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 |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H |
10 | | #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H |
11 | | |
12 | | #include "clang/AST/CharUnits.h" |
13 | | #include "clang/AST/Type.h" |
14 | | #include "llvm/IR/CallingConv.h" |
15 | | #include "llvm/IR/Type.h" |
16 | | |
17 | | namespace llvm { |
18 | | class Value; |
19 | | class LLVMContext; |
20 | | class DataLayout; |
21 | | class Type; |
22 | | } |
23 | | |
24 | | namespace clang { |
25 | | class ASTContext; |
26 | | class CodeGenOptions; |
27 | | class TargetInfo; |
28 | | |
29 | | namespace CodeGen { |
30 | | class ABIArgInfo; |
31 | | class Address; |
32 | | class CGCXXABI; |
33 | | class CGFunctionInfo; |
34 | | class CodeGenFunction; |
35 | | class CodeGenTypes; |
36 | | class SwiftABIInfo; |
37 | | |
38 | | namespace swiftcall { |
39 | | class SwiftAggLowering; |
40 | | } |
41 | | |
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. |
46 | | |
47 | | |
48 | | /// ABIInfo - Target specific hooks for defining how a type should be |
49 | | /// passed or returned from functions. |
50 | | class ABIInfo { |
51 | | public: |
52 | | CodeGen::CodeGenTypes &CGT; |
53 | | protected: |
54 | | llvm::CallingConv::ID RuntimeCC; |
55 | | public: |
56 | | ABIInfo(CodeGen::CodeGenTypes &cgt) |
57 | 36.6k | : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {} |
58 | | |
59 | | virtual ~ABIInfo(); |
60 | | |
61 | 0 | virtual bool supportsSwift() const { return false; } |
62 | | |
63 | 0 | virtual bool allowBFloatArgsAndRet() const { return false; } |
64 | | |
65 | | CodeGen::CGCXXABI &getCXXABI() const; |
66 | | ASTContext &getContext() const; |
67 | | llvm::LLVMContext &getVMContext() const; |
68 | | const llvm::DataLayout &getDataLayout() const; |
69 | | const TargetInfo &getTarget() const; |
70 | | const CodeGenOptions &getCodeGenOpts() const; |
71 | | |
72 | | /// Return the calling convention to use for system runtime |
73 | | /// functions. |
74 | 44.6k | llvm::CallingConv::ID getRuntimeCC() const { |
75 | 44.6k | return RuntimeCC; |
76 | 44.6k | } |
77 | | |
78 | | virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0; |
79 | | |
80 | | /// EmitVAArg - Emit the target dependent code to load a value of |
81 | | /// \arg Ty from the va_list pointed to by \arg VAListAddr. |
82 | | |
83 | | // FIXME: This is a gaping layering violation if we wanted to drop |
84 | | // the ABI information any lower than CodeGen. Of course, for |
85 | | // VAArg handling it has to be at this level; there is no way to |
86 | | // abstract this out. |
87 | | virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF, |
88 | | CodeGen::Address VAListAddr, |
89 | | QualType Ty) const = 0; |
90 | | |
91 | | bool isAndroid() const; |
92 | | |
93 | | /// Emit the target dependent code to load a value of |
94 | | /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr. |
95 | | virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF, |
96 | | CodeGen::Address VAListAddr, |
97 | | QualType Ty) const; |
98 | | |
99 | | virtual bool isHomogeneousAggregateBaseType(QualType Ty) const; |
100 | | |
101 | | virtual bool isHomogeneousAggregateSmallEnough(const Type *Base, |
102 | | uint64_t Members) const; |
103 | | virtual bool isZeroLengthBitfieldPermittedInHomogeneousAggregate() const; |
104 | | |
105 | | bool isHomogeneousAggregate(QualType Ty, const Type *&Base, |
106 | | uint64_t &Members) const; |
107 | | |
108 | | // Implement the Type::IsPromotableIntegerType for ABI specific needs. The |
109 | | // only difference is that this considers bit-precise integer types as well. |
110 | | bool isPromotableIntegerTypeForABI(QualType Ty) const; |
111 | | |
112 | | /// A convenience method to return an indirect ABIArgInfo with an |
113 | | /// expected alignment equal to the ABI alignment of the given type. |
114 | | CodeGen::ABIArgInfo |
115 | | getNaturalAlignIndirect(QualType Ty, bool ByVal = true, |
116 | | bool Realign = false, |
117 | | llvm::Type *Padding = nullptr) const; |
118 | | |
119 | | CodeGen::ABIArgInfo |
120 | | getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const; |
121 | | |
122 | | |
123 | | }; |
124 | | |
125 | | /// A refining implementation of ABIInfo for targets that support swiftcall. |
126 | | /// |
127 | | /// If we find ourselves wanting multiple such refinements, they'll probably |
128 | | /// be independent refinements, and we should probably find another way |
129 | | /// to do it than simple inheritance. |
130 | | class SwiftABIInfo : public ABIInfo { |
131 | | public: |
132 | 35.2k | SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {} |
133 | | |
134 | 2.54k | bool supportsSwift() const final override { return true; } |
135 | | |
136 | | virtual bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type*> types, |
137 | | bool asReturnValue) const = 0; |
138 | | |
139 | | virtual bool isLegalVectorTypeForSwift(CharUnits totalSize, |
140 | | llvm::Type *eltTy, |
141 | | unsigned elts) const; |
142 | | |
143 | | virtual bool isSwiftErrorInRegister() const = 0; |
144 | | |
145 | 2.54k | static bool classof(const ABIInfo *info) { |
146 | 2.54k | return info->supportsSwift(); |
147 | 2.54k | } |
148 | | }; |
149 | | } // end namespace CodeGen |
150 | | } // end namespace clang |
151 | | |
152 | | #endif |