1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENTYPES_H |
14 | #define LLVM_CLANG_LIB_CODEGEN_CODEGENTYPES_H |
15 | |
16 | #include "CGCall.h" |
17 | #include "clang/Basic/ABI.h" |
18 | #include "clang/CodeGen/CGFunctionInfo.h" |
19 | #include "llvm/ADT/DenseMap.h" |
20 | #include "llvm/IR/Module.h" |
21 | |
22 | namespace llvm { |
23 | class FunctionType; |
24 | class DataLayout; |
25 | class Type; |
26 | class LLVMContext; |
27 | class StructType; |
28 | } |
29 | |
30 | namespace clang { |
31 | class ASTContext; |
32 | template <typename> class CanQual; |
33 | class CXXConstructorDecl; |
34 | class CXXDestructorDecl; |
35 | class CXXMethodDecl; |
36 | class CodeGenOptions; |
37 | class FieldDecl; |
38 | class FunctionProtoType; |
39 | class ObjCInterfaceDecl; |
40 | class ObjCIvarDecl; |
41 | class PointerType; |
42 | class QualType; |
43 | class RecordDecl; |
44 | class TagDecl; |
45 | class TargetInfo; |
46 | class Type; |
47 | typedef CanQual<Type> CanQualType; |
48 | class GlobalDecl; |
49 | |
50 | namespace CodeGen { |
51 | class ABIInfo; |
52 | class CGCXXABI; |
53 | class CGRecordLayout; |
54 | class CodeGenModule; |
55 | class RequiredArgs; |
56 | |
57 | |
58 | |
59 | class CodeGenTypes { |
60 | CodeGenModule &CGM; |
61 | |
62 | ASTContext &Context; |
63 | llvm::Module &TheModule; |
64 | const TargetInfo &Target; |
65 | CGCXXABI &TheCXXABI; |
66 | |
67 | |
68 | |
69 | const ABIInfo &TheABIInfo; |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | llvm::DenseMap<const ObjCInterfaceType*, llvm::Type *> InterfaceTypes; |
76 | |
77 | |
78 | llvm::DenseMap<const Type*, CGRecordLayout *> CGRecordLayouts; |
79 | |
80 | |
81 | llvm::DenseMap<const Type*, llvm::StructType *> RecordDeclTypes; |
82 | |
83 | |
84 | llvm::FoldingSet<CGFunctionInfo> FunctionInfos; |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | llvm::SmallPtrSet<const Type*, 4> RecordsBeingLaidOut; |
91 | |
92 | llvm::SmallPtrSet<const CGFunctionInfo*, 4> FunctionsBeingProcessed; |
93 | |
94 | |
95 | |
96 | bool SkippedLayout; |
97 | |
98 | SmallVector<const RecordDecl *, 8> DeferredRecords; |
99 | |
100 | |
101 | |
102 | llvm::DenseMap<const Type *, llvm::Type *> TypeCache; |
103 | |
104 | llvm::SmallSet<const Type *, 8> RecordsWithOpaqueMemberPointers; |
105 | |
106 | |
107 | llvm::Type *ConvertFunctionTypeInternal(QualType FT); |
108 | |
109 | public: |
110 | CodeGenTypes(CodeGenModule &cgm); |
111 | ~CodeGenTypes(); |
112 | |
113 | const llvm::DataLayout &getDataLayout() const { |
114 | return TheModule.getDataLayout(); |
115 | } |
116 | ASTContext &getContext() const { return Context; } |
117 | const ABIInfo &getABIInfo() const { return TheABIInfo; } |
118 | const TargetInfo &getTarget() const { return Target; } |
119 | CGCXXABI &getCXXABI() const { return TheCXXABI; } |
120 | llvm::LLVMContext &getLLVMContext() { return TheModule.getContext(); } |
121 | const CodeGenOptions &getCodeGenOpts() const; |
122 | |
123 | |
124 | unsigned ClangCallConvToLLVMCallConv(CallingConv CC); |
125 | |
126 | |
127 | |
128 | CanQualType DeriveThisType(const CXXRecordDecl *RD, const CXXMethodDecl *MD); |
129 | |
130 | |
131 | llvm::Type *ConvertType(QualType T); |
132 | |
133 | |
134 | |
135 | |
136 | |
137 | llvm::Type *ConvertTypeForMem(QualType T); |
138 | |
139 | |
140 | llvm::FunctionType *GetFunctionType(const CGFunctionInfo &Info); |
141 | |
142 | llvm::FunctionType *GetFunctionType(GlobalDecl GD); |
143 | |
144 | |
145 | |
146 | |
147 | bool isFuncTypeConvertible(const FunctionType *FT); |
148 | bool isFuncParamTypeConvertible(QualType Ty); |
149 | |
150 | |
151 | |
152 | bool inheritingCtorHasParams(const InheritedConstructor &Inherited, |
153 | CXXCtorType Type); |
154 | |
155 | |
156 | |
157 | |
158 | llvm::Type *GetFunctionTypeForVTable(GlobalDecl GD); |
159 | |
160 | const CGRecordLayout &getCGRecordLayout(const RecordDecl*); |
161 | |
162 | |
163 | |
164 | void UpdateCompletedType(const TagDecl *TD); |
165 | |
166 | |
167 | |
168 | void RefreshTypeCacheForClass(const CXXRecordDecl *RD); |
169 | |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | |
177 | |
178 | |
179 | |
180 | |
181 | |
182 | |
183 | |
184 | |
185 | |
186 | |
187 | |
188 | |
189 | |
190 | const CGFunctionInfo &arrangeGlobalDeclaration(GlobalDecl GD); |
191 | |
192 | |
193 | |
194 | |
195 | |
196 | const CGFunctionInfo &arrangeCall(const CGFunctionInfo &declFI, |
197 | const CallArgList &args); |
198 | |
199 | |
200 | |
201 | const CGFunctionInfo &arrangeFunctionDeclaration(const FunctionDecl *FD); |
202 | const CGFunctionInfo &arrangeFreeFunctionCall(const CallArgList &Args, |
203 | const FunctionType *Ty, |
204 | bool ChainCall); |
205 | const CGFunctionInfo &arrangeFreeFunctionType(CanQual<FunctionProtoType> Ty); |
206 | const CGFunctionInfo &arrangeFreeFunctionType(CanQual<FunctionNoProtoType> Ty); |
207 | |
208 | |
209 | |
210 | const CGFunctionInfo &arrangeNullaryFunction(); |
211 | |
212 | |
213 | |
214 | const CGFunctionInfo & |
215 | arrangeBuiltinFunctionDeclaration(QualType resultType, |
216 | const FunctionArgList &args); |
217 | const CGFunctionInfo & |
218 | arrangeBuiltinFunctionDeclaration(CanQualType resultType, |
219 | ArrayRef<CanQualType> argTypes); |
220 | const CGFunctionInfo &arrangeBuiltinFunctionCall(QualType resultType, |
221 | const CallArgList &args); |
222 | |
223 | |
224 | const CGFunctionInfo &arrangeObjCMethodDeclaration(const ObjCMethodDecl *MD); |
225 | const CGFunctionInfo &arrangeObjCMessageSendSignature(const ObjCMethodDecl *MD, |
226 | QualType receiverType); |
227 | const CGFunctionInfo &arrangeUnprototypedObjCMessageSend( |
228 | QualType returnType, |
229 | const CallArgList &args); |
230 | |
231 | |
232 | const CGFunctionInfo &arrangeBlockFunctionDeclaration( |
233 | const FunctionProtoType *type, |
234 | const FunctionArgList &args); |
235 | const CGFunctionInfo &arrangeBlockFunctionCall(const CallArgList &args, |
236 | const FunctionType *type); |
237 | |
238 | |
239 | const CGFunctionInfo &arrangeCXXMethodDeclaration(const CXXMethodDecl *MD); |
240 | const CGFunctionInfo &arrangeCXXStructorDeclaration(GlobalDecl GD); |
241 | const CGFunctionInfo &arrangeCXXConstructorCall(const CallArgList &Args, |
242 | const CXXConstructorDecl *D, |
243 | CXXCtorType CtorKind, |
244 | unsigned , |
245 | unsigned , |
246 | bool PassProtoArgs = true); |
247 | |
248 | const CGFunctionInfo &arrangeCXXMethodCall(const CallArgList &args, |
249 | const FunctionProtoType *type, |
250 | RequiredArgs required, |
251 | unsigned numPrefixArgs); |
252 | const CGFunctionInfo & |
253 | arrangeUnprototypedMustTailThunk(const CXXMethodDecl *MD); |
254 | const CGFunctionInfo &arrangeMSCtorClosure(const CXXConstructorDecl *CD, |
255 | CXXCtorType CT); |
256 | const CGFunctionInfo &arrangeCXXMethodType(const CXXRecordDecl *RD, |
257 | const FunctionProtoType *FTP, |
258 | const CXXMethodDecl *MD); |
259 | |
260 | |
261 | |
262 | |
263 | |
264 | |
265 | |
266 | const CGFunctionInfo &arrangeLLVMFunctionInfo(CanQualType returnType, |
267 | bool instanceMethod, |
268 | bool chainCall, |
269 | ArrayRef<CanQualType> argTypes, |
270 | FunctionType::ExtInfo info, |
271 | ArrayRef<FunctionProtoType::ExtParameterInfo> paramInfos, |
272 | RequiredArgs args); |
273 | |
274 | |
275 | CGRecordLayout *ComputeRecordLayout(const RecordDecl *D, |
276 | llvm::StructType *Ty); |
277 | |
278 | |
279 | |
280 | void addRecordTypeName(const RecordDecl *RD, llvm::StructType *Ty, |
281 | StringRef suffix); |
282 | |
283 | |
284 | public: |
285 | |
286 | llvm::StructType *ConvertRecordDeclType(const RecordDecl *TD); |
287 | |
288 | |
289 | |
290 | void getExpandedTypes(QualType Ty, |
291 | SmallVectorImpl<llvm::Type *>::iterator &TI); |
292 | |
293 | |
294 | |
295 | bool isZeroInitializable(QualType T); |
296 | |
297 | |
298 | |
299 | bool isPointerZeroInitializable(QualType T); |
300 | |
301 | |
302 | |
303 | bool isZeroInitializable(const RecordDecl *RD); |
304 | |
305 | bool isRecordLayoutComplete(const Type *Ty) const; |
306 | bool noRecordsBeingLaidOut() const { |
307 | return RecordsBeingLaidOut.empty(); |
308 | } |
309 | bool isRecordBeingLaidOut(const Type *Ty) const { |
310 | return RecordsBeingLaidOut.count(Ty); |
311 | } |
312 | |
313 | }; |
314 | |
315 | } |
316 | } |
317 | |
318 | #endif |
319 | |