1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #ifndef LLVM_CLANG_CODEGEN_SWIFTCALLINGCONV_H |
14 | #define LLVM_CLANG_CODEGEN_SWIFTCALLINGCONV_H |
15 | |
16 | #include "clang/AST/CanonicalType.h" |
17 | #include "clang/AST/CharUnits.h" |
18 | #include "clang/AST/Type.h" |
19 | #include "llvm/Support/TrailingObjects.h" |
20 | #include <cassert> |
21 | |
22 | namespace llvm { |
23 | class IntegerType; |
24 | class Type; |
25 | class StructType; |
26 | class VectorType; |
27 | } |
28 | |
29 | namespace clang { |
30 | class Decl; |
31 | class FieldDecl; |
32 | class ASTRecordLayout; |
33 | |
34 | namespace CodeGen { |
35 | class ABIArgInfo; |
36 | class CodeGenModule; |
37 | class CGFunctionInfo; |
38 | |
39 | namespace swiftcall { |
40 | |
41 | class SwiftAggLowering { |
42 | CodeGenModule &CGM; |
43 | |
44 | struct StorageEntry { |
45 | CharUnits Begin; |
46 | CharUnits End; |
47 | llvm::Type *Type; |
48 | |
49 | CharUnits getWidth() const { |
50 | return End - Begin; |
51 | } |
52 | }; |
53 | SmallVector<StorageEntry, 4> Entries; |
54 | bool Finished = false; |
55 | |
56 | public: |
57 | SwiftAggLowering(CodeGenModule &CGM) : CGM(CGM) {} |
58 | |
59 | void addOpaqueData(CharUnits begin, CharUnits end) { |
60 | addEntry(nullptr, begin, end); |
61 | } |
62 | |
63 | void addTypedData(QualType type, CharUnits begin); |
64 | void addTypedData(const RecordDecl *record, CharUnits begin); |
65 | void addTypedData(const RecordDecl *record, CharUnits begin, |
66 | const ASTRecordLayout &layout); |
67 | void addTypedData(llvm::Type *type, CharUnits begin); |
68 | void addTypedData(llvm::Type *type, CharUnits begin, CharUnits end); |
69 | |
70 | void finish(); |
71 | |
72 | |
73 | bool empty() const { |
74 | (0) . __assert_fail ("Finished && \"didn't finish lowering before calling empty()\"", "/home/seafit/code_projects/clang_source/clang/include/clang/CodeGen/SwiftCallingConv.h", 74, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Finished && "didn't finish lowering before calling empty()"); |
75 | return Entries.empty(); |
76 | } |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | bool shouldPassIndirectly(bool asReturnValue) const; |
90 | |
91 | using EnumerationCallback = |
92 | llvm::function_ref<void(CharUnits offset, CharUnits end, llvm::Type *type)>; |
93 | |
94 | |
95 | |
96 | |
97 | |
98 | void enumerateComponents(EnumerationCallback callback) const; |
99 | |
100 | |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | std::pair<llvm::StructType*, llvm::Type*> getCoerceAndExpandTypes() const; |
109 | |
110 | private: |
111 | void addBitFieldData(const FieldDecl *field, CharUnits begin, |
112 | uint64_t bitOffset); |
113 | void addLegalTypedData(llvm::Type *type, CharUnits begin, CharUnits end); |
114 | void addEntry(llvm::Type *type, CharUnits begin, CharUnits end); |
115 | void splitVectorEntry(unsigned index); |
116 | static bool shouldMergeEntries(const StorageEntry &first, |
117 | const StorageEntry &second, |
118 | CharUnits chunkSize); |
119 | }; |
120 | |
121 | |
122 | |
123 | bool shouldPassIndirectly(CodeGenModule &CGM, |
124 | ArrayRef<llvm::Type*> types, |
125 | bool asReturnValue); |
126 | |
127 | |
128 | CharUnits getMaximumVoluntaryIntegerSize(CodeGenModule &CGM); |
129 | |
130 | |
131 | CharUnits getNaturalAlignment(CodeGenModule &CGM, llvm::Type *type); |
132 | |
133 | |
134 | |
135 | bool isLegalIntegerType(CodeGenModule &CGM, llvm::IntegerType *type); |
136 | |
137 | |
138 | |
139 | bool isLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize, |
140 | llvm::VectorType *vectorTy); |
141 | bool isLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize, |
142 | llvm::Type *eltTy, unsigned numElts); |
143 | |
144 | |
145 | std::pair<llvm::Type*, unsigned> |
146 | splitLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize, |
147 | llvm::VectorType *vectorTy); |
148 | |
149 | |
150 | |
151 | |
152 | |
153 | void legalizeVectorType(CodeGenModule &CGM, CharUnits vectorSize, |
154 | llvm::VectorType *vectorTy, |
155 | llvm::SmallVectorImpl<llvm::Type*> &types); |
156 | |
157 | |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | |
165 | bool mustPassRecordIndirectly(CodeGenModule &CGM, const RecordDecl *record); |
166 | |
167 | |
168 | ABIArgInfo classifyReturnType(CodeGenModule &CGM, CanQualType type); |
169 | |
170 | |
171 | ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type); |
172 | |
173 | |
174 | |
175 | void computeABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI); |
176 | |
177 | |
178 | bool isSwiftErrorLoweredInRegister(CodeGenModule &CGM); |
179 | |
180 | } |
181 | } |
182 | } |
183 | |
184 | #endif |
185 | |