clang  16.0.0git
CodeGenTypes.cpp
Go to the documentation of this file.
1 //===--- CodeGenTypes.cpp - Type translation for LLVM CodeGen -------------===//
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 // This is the code that handles AST -> LLVM type lowering.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "CodeGenTypes.h"
14 #include "CGCXXABI.h"
15 #include "CGCall.h"
16 #include "CGOpenCLRuntime.h"
17 #include "CGRecordLayout.h"
18 #include "TargetInfo.h"
19 #include "clang/AST/ASTContext.h"
20 #include "clang/AST/DeclCXX.h"
21 #include "clang/AST/DeclObjC.h"
22 #include "clang/AST/Expr.h"
23 #include "clang/AST/RecordLayout.h"
25 #include "llvm/IR/DataLayout.h"
26 #include "llvm/IR/DerivedTypes.h"
27 #include "llvm/IR/Module.h"
28 
29 using namespace clang;
30 using namespace CodeGen;
31 
33  : CGM(cgm), Context(cgm.getContext()), TheModule(cgm.getModule()),
34  Target(cgm.getTarget()), TheCXXABI(cgm.getCXXABI()),
35  TheABIInfo(cgm.getTargetCodeGenInfo().getABIInfo()) {
36  SkippedLayout = false;
37 }
38 
40  for (llvm::FoldingSet<CGFunctionInfo>::iterator
41  I = FunctionInfos.begin(), E = FunctionInfos.end(); I != E; )
42  delete &*I++;
43 }
44 
46  return CGM.getCodeGenOpts();
47 }
48 
50  llvm::StructType *Ty,
51  StringRef suffix) {
53  llvm::raw_svector_ostream OS(TypeName);
54  OS << RD->getKindName() << '.';
55 
56  // FIXME: We probably want to make more tweaks to the printing policy. For
57  // example, we should probably enable PrintCanonicalTypes and
58  // FullyQualifiedNames.
60  Policy.SuppressInlineNamespace = false;
61 
62  // Name the codegen type after the typedef name
63  // if there is no tag type name available
64  if (RD->getIdentifier()) {
65  // FIXME: We should not have to check for a null decl context here.
66  // Right now we do it because the implicit Obj-C decls don't have one.
67  if (RD->getDeclContext())
68  RD->printQualifiedName(OS, Policy);
69  else
70  RD->printName(OS, Policy);
71  } else if (const TypedefNameDecl *TDD = RD->getTypedefNameForAnonDecl()) {
72  // FIXME: We should not have to check for a null decl context here.
73  // Right now we do it because the implicit Obj-C decls don't have one.
74  if (TDD->getDeclContext())
75  TDD->printQualifiedName(OS, Policy);
76  else
77  TDD->printName(OS);
78  } else
79  OS << "anon";
80 
81  if (!suffix.empty())
82  OS << suffix;
83 
84  Ty->setName(OS.str());
85 }
86 
87 /// ConvertTypeForMem - Convert type T into a llvm::Type. This differs from
88 /// ConvertType in that it is used to convert to the memory representation for
89 /// a type. For example, the scalar representation for _Bool is i1, but the
90 /// memory representation is usually i8 or i32, depending on the target.
91 llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T, bool ForBitField) {
92  if (T->isConstantMatrixType()) {
93  const Type *Ty = Context.getCanonicalType(T).getTypePtr();
94  const ConstantMatrixType *MT = cast<ConstantMatrixType>(Ty);
95  return llvm::ArrayType::get(ConvertType(MT->getElementType()),
96  MT->getNumRows() * MT->getNumColumns());
97  }
98 
99  llvm::Type *R = ConvertType(T);
100 
101  // Check for the boolean vector case.
102  if (T->isExtVectorBoolType()) {
103  auto *FixedVT = cast<llvm::FixedVectorType>(R);
104  // Pad to at least one byte.
105  uint64_t BytePadded = std::max<uint64_t>(FixedVT->getNumElements(), 8);
106  return llvm::IntegerType::get(FixedVT->getContext(), BytePadded);
107  }
108 
109  // If this is a bool type, or a bit-precise integer type in a bitfield
110  // representation, map this integer to the target-specified size.
111  if ((ForBitField && T->isBitIntType()) ||
112  (!T->isBitIntType() && R->isIntegerTy(1)))
113  return llvm::IntegerType::get(getLLVMContext(),
114  (unsigned)Context.getTypeSize(T));
115 
116  // Else, don't map it.
117  return R;
118 }
119 
120 /// isRecordLayoutComplete - Return true if the specified type is already
121 /// completely laid out.
123  llvm::DenseMap<const Type*, llvm::StructType *>::const_iterator I =
124  RecordDeclTypes.find(Ty);
125  return I != RecordDeclTypes.end() && !I->second->isOpaque();
126 }
127 
128 static bool
131 
132 
133 /// isSafeToConvert - Return true if it is safe to convert the specified record
134 /// decl to IR and lay it out, false if doing so would cause us to get into a
135 /// recursive compilation mess.
136 static bool
139  // If we have already checked this type (maybe the same type is used by-value
140  // multiple times in multiple structure fields, don't check again.
141  if (!AlreadyChecked.insert(RD).second)
142  return true;
143 
144  const Type *Key = CGT.getContext().getTagDeclType(RD).getTypePtr();
145 
146  // If this type is already laid out, converting it is a noop.
147  if (CGT.isRecordLayoutComplete(Key)) return true;
148 
149  // If this type is currently being laid out, we can't recursively compile it.
150  if (CGT.isRecordBeingLaidOut(Key))
151  return false;
152 
153  // If this type would require laying out bases that are currently being laid
154  // out, don't do it. This includes virtual base classes which get laid out
155  // when a class is translated, even though they aren't embedded by-value into
156  // the class.
157  if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(RD)) {
158  for (const auto &I : CRD->bases())
159  if (!isSafeToConvert(I.getType()->castAs<RecordType>()->getDecl(), CGT,
160  AlreadyChecked))
161  return false;
162  }
163 
164  // If this type would require laying out members that are currently being laid
165  // out, don't do it.
166  for (const auto *I : RD->fields())
167  if (!isSafeToConvert(I->getType(), CGT, AlreadyChecked))
168  return false;
169 
170  // If there are no problems, lets do it.
171  return true;
172 }
173 
174 /// isSafeToConvert - Return true if it is safe to convert this field type,
175 /// which requires the structure elements contained by-value to all be
176 /// recursively safe to convert.
177 static bool
180  // Strip off atomic type sugar.
181  if (const auto *AT = T->getAs<AtomicType>())
182  T = AT->getValueType();
183 
184  // If this is a record, check it.
185  if (const auto *RT = T->getAs<RecordType>())
186  return isSafeToConvert(RT->getDecl(), CGT, AlreadyChecked);
187 
188  // If this is an array, check the elements, which are embedded inline.
189  if (const auto *AT = CGT.getContext().getAsArrayType(T))
190  return isSafeToConvert(AT->getElementType(), CGT, AlreadyChecked);
191 
192  // Otherwise, there is no concern about transforming this. We only care about
193  // things that are contained by-value in a structure that can have another
194  // structure as a member.
195  return true;
196 }
197 
198 
199 /// isSafeToConvert - Return true if it is safe to convert the specified record
200 /// decl to IR and lay it out, false if doing so would cause us to get into a
201 /// recursive compilation mess.
202 static bool isSafeToConvert(const RecordDecl *RD, CodeGenTypes &CGT) {
203  // If no structs are being laid out, we can certainly do this one.
204  if (CGT.noRecordsBeingLaidOut()) return true;
205 
207  return isSafeToConvert(RD, CGT, AlreadyChecked);
208 }
209 
210 /// isFuncParamTypeConvertible - Return true if the specified type in a
211 /// function parameter or result position can be converted to an IR type at this
212 /// point. This boils down to being whether it is complete, as well as whether
213 /// we've temporarily deferred expanding the type because we're in a recursive
214 /// context.
216  // Some ABIs cannot have their member pointers represented in IR unless
217  // certain circumstances have been reached.
218  if (const auto *MPT = Ty->getAs<MemberPointerType>())
220 
221  // If this isn't a tagged type, we can convert it!
222  const TagType *TT = Ty->getAs<TagType>();
223  if (!TT) return true;
224 
225  // Incomplete types cannot be converted.
226  if (TT->isIncompleteType())
227  return false;
228 
229  // If this is an enum, then it is always safe to convert.
230  const RecordType *RT = dyn_cast<RecordType>(TT);
231  if (!RT) return true;
232 
233  // Otherwise, we have to be careful. If it is a struct that we're in the
234  // process of expanding, then we can't convert the function type. That's ok
235  // though because we must be in a pointer context under the struct, so we can
236  // just convert it to a dummy type.
237  //
238  // We decide this by checking whether ConvertRecordDeclType returns us an
239  // opaque type for a struct that we know is defined.
240  return isSafeToConvert(RT->getDecl(), *this);
241 }
242 
243 
244 /// Code to verify a given function type is complete, i.e. the return type
245 /// and all of the parameter types are complete. Also check to see if we are in
246 /// a RS_StructPointer context, and if so whether any struct types have been
247 /// pended. If so, we don't want to ask the ABI lowering code to handle a type
248 /// that cannot be converted to an IR type.
251  return false;
252 
253  if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT))
254  for (unsigned i = 0, e = FPT->getNumParams(); i != e; i++)
255  if (!isFuncParamTypeConvertible(FPT->getParamType(i)))
256  return false;
257 
258  return true;
259 }
260 
261 /// UpdateCompletedType - When we find the full definition for a TagDecl,
262 /// replace the 'opaque' type we previously made for it if applicable.
264  // If this is an enum being completed, then we flush all non-struct types from
265  // the cache. This allows function types and other things that may be derived
266  // from the enum to be recomputed.
267  if (const EnumDecl *ED = dyn_cast<EnumDecl>(TD)) {
268  // Only flush the cache if we've actually already converted this type.
269  if (TypeCache.count(ED->getTypeForDecl())) {
270  // Okay, we formed some types based on this. We speculated that the enum
271  // would be lowered to i32, so we only need to flush the cache if this
272  // didn't happen.
273  if (!ConvertType(ED->getIntegerType())->isIntegerTy(32))
274  TypeCache.clear();
275  }
276  // If necessary, provide the full definition of a type only used with a
277  // declaration so far.
278  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
279  DI->completeType(ED);
280  return;
281  }
282 
283  // If we completed a RecordDecl that we previously used and converted to an
284  // anonymous type, then go ahead and complete it now.
285  const RecordDecl *RD = cast<RecordDecl>(TD);
286  if (RD->isDependentType()) return;
287 
288  // Only complete it if we converted it already. If we haven't converted it
289  // yet, we'll just do it lazily.
290  if (RecordDeclTypes.count(Context.getTagDeclType(RD).getTypePtr()))
292 
293  // If necessary, provide the full definition of a type only used with a
294  // declaration so far.
295  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
296  DI->completeType(RD);
297 }
298 
300  QualType T = Context.getRecordType(RD);
301  T = Context.getCanonicalType(T);
302 
303  const Type *Ty = T.getTypePtr();
304  if (RecordsWithOpaqueMemberPointers.count(Ty)) {
305  TypeCache.clear();
306  RecordsWithOpaqueMemberPointers.clear();
307  }
308 }
309 
310 static llvm::Type *getTypeForFormat(llvm::LLVMContext &VMContext,
311  const llvm::fltSemantics &format,
312  bool UseNativeHalf = false) {
313  if (&format == &llvm::APFloat::IEEEhalf()) {
314  if (UseNativeHalf)
315  return llvm::Type::getHalfTy(VMContext);
316  else
317  return llvm::Type::getInt16Ty(VMContext);
318  }
319  if (&format == &llvm::APFloat::BFloat())
320  return llvm::Type::getBFloatTy(VMContext);
321  if (&format == &llvm::APFloat::IEEEsingle())
322  return llvm::Type::getFloatTy(VMContext);
323  if (&format == &llvm::APFloat::IEEEdouble())
324  return llvm::Type::getDoubleTy(VMContext);
325  if (&format == &llvm::APFloat::IEEEquad())
326  return llvm::Type::getFP128Ty(VMContext);
327  if (&format == &llvm::APFloat::PPCDoubleDouble())
328  return llvm::Type::getPPC_FP128Ty(VMContext);
329  if (&format == &llvm::APFloat::x87DoubleExtended())
330  return llvm::Type::getX86_FP80Ty(VMContext);
331  llvm_unreachable("Unknown float format!");
332 }
333 
334 llvm::Type *CodeGenTypes::ConvertFunctionTypeInternal(QualType QFT) {
335  assert(QFT.isCanonical());
336  const Type *Ty = QFT.getTypePtr();
337  const FunctionType *FT = cast<FunctionType>(QFT.getTypePtr());
338  // First, check whether we can build the full function type. If the
339  // function type depends on an incomplete type (e.g. a struct or enum), we
340  // cannot lower the function type.
341  if (!isFuncTypeConvertible(FT)) {
342  // This function's type depends on an incomplete tag type.
343 
344  // Force conversion of all the relevant record types, to make sure
345  // we re-convert the FunctionType when appropriate.
346  if (const RecordType *RT = FT->getReturnType()->getAs<RecordType>())
347  ConvertRecordDeclType(RT->getDecl());
348  if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT))
349  for (unsigned i = 0, e = FPT->getNumParams(); i != e; i++)
350  if (const RecordType *RT = FPT->getParamType(i)->getAs<RecordType>())
351  ConvertRecordDeclType(RT->getDecl());
352 
353  SkippedLayout = true;
354 
355  // Return a placeholder type.
356  return llvm::StructType::get(getLLVMContext());
357  }
358 
359  // While we're converting the parameter types for a function, we don't want
360  // to recursively convert any pointed-to structs. Converting directly-used
361  // structs is ok though.
362  if (!RecordsBeingLaidOut.insert(Ty).second) {
363  SkippedLayout = true;
364  return llvm::StructType::get(getLLVMContext());
365  }
366 
367  // The function type can be built; call the appropriate routines to
368  // build it.
369  const CGFunctionInfo *FI;
370  if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT)) {
373  } else {
374  const FunctionNoProtoType *FNPT = cast<FunctionNoProtoType>(FT);
377  }
378 
379  llvm::Type *ResultType = nullptr;
380  // If there is something higher level prodding our CGFunctionInfo, then
381  // don't recurse into it again.
382  if (FunctionsBeingProcessed.count(FI)) {
383 
384  ResultType = llvm::StructType::get(getLLVMContext());
385  SkippedLayout = true;
386  } else {
387 
388  // Otherwise, we're good to go, go ahead and convert it.
389  ResultType = GetFunctionType(*FI);
390  }
391 
392  RecordsBeingLaidOut.erase(Ty);
393 
394  if (RecordsBeingLaidOut.empty())
395  while (!DeferredRecords.empty())
396  ConvertRecordDeclType(DeferredRecords.pop_back_val());
397  return ResultType;
398 }
399 
400 /// ConvertType - Convert the specified type to its LLVM form.
402  T = Context.getCanonicalType(T);
403 
404  const Type *Ty = T.getTypePtr();
405 
406  // For the device-side compilation, CUDA device builtin surface/texture types
407  // may be represented in different types.
408  if (Context.getLangOpts().CUDAIsDevice) {
410  if (auto *Ty = CGM.getTargetCodeGenInfo()
412  return Ty;
413  } else if (T->isCUDADeviceBuiltinTextureType()) {
414  if (auto *Ty = CGM.getTargetCodeGenInfo()
416  return Ty;
417  }
418  }
419 
420  // RecordTypes are cached and processed specially.
421  if (const RecordType *RT = dyn_cast<RecordType>(Ty))
422  return ConvertRecordDeclType(RT->getDecl());
423 
424  // The LLVM type we return for a given Clang type may not always be the same,
425  // most notably when dealing with recursive structs. We mark these potential
426  // cases with ShouldUseCache below. Builtin types cannot be recursive.
427  // TODO: when clang uses LLVM opaque pointers we won't be able to represent
428  // recursive types with LLVM types, making this logic much simpler.
429  llvm::Type *CachedType = nullptr;
430  bool ShouldUseCache =
431  Ty->isBuiltinType() ||
432  (noRecordsBeingLaidOut() && FunctionsBeingProcessed.empty());
433  if (ShouldUseCache) {
434  llvm::DenseMap<const Type *, llvm::Type *>::iterator TCI =
435  TypeCache.find(Ty);
436  if (TCI != TypeCache.end())
437  CachedType = TCI->second;
438  // With expensive checks, check that the type we compute matches the
439  // cached type.
440 #ifndef EXPENSIVE_CHECKS
441  if (CachedType)
442  return CachedType;
443 #endif
444  }
445 
446  // If we don't have it in the cache, convert it now.
447  llvm::Type *ResultType = nullptr;
448  switch (Ty->getTypeClass()) {
449  case Type::Record: // Handled above.
450 #define TYPE(Class, Base)
451 #define ABSTRACT_TYPE(Class, Base)
452 #define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
453 #define DEPENDENT_TYPE(Class, Base) case Type::Class:
454 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
455 #include "clang/AST/TypeNodes.inc"
456  llvm_unreachable("Non-canonical or dependent types aren't possible.");
457 
458  case Type::Builtin: {
459  switch (cast<BuiltinType>(Ty)->getKind()) {
460  case BuiltinType::Void:
461  case BuiltinType::ObjCId:
462  case BuiltinType::ObjCClass:
463  case BuiltinType::ObjCSel:
464  // LLVM void type can only be used as the result of a function call. Just
465  // map to the same as char.
466  ResultType = llvm::Type::getInt8Ty(getLLVMContext());
467  break;
468 
469  case BuiltinType::Bool:
470  // Note that we always return bool as i1 for use as a scalar type.
471  ResultType = llvm::Type::getInt1Ty(getLLVMContext());
472  break;
473 
474  case BuiltinType::Char_S:
475  case BuiltinType::Char_U:
476  case BuiltinType::SChar:
477  case BuiltinType::UChar:
478  case BuiltinType::Short:
479  case BuiltinType::UShort:
480  case BuiltinType::Int:
481  case BuiltinType::UInt:
482  case BuiltinType::Long:
483  case BuiltinType::ULong:
484  case BuiltinType::LongLong:
485  case BuiltinType::ULongLong:
486  case BuiltinType::WChar_S:
487  case BuiltinType::WChar_U:
488  case BuiltinType::Char8:
489  case BuiltinType::Char16:
490  case BuiltinType::Char32:
491  case BuiltinType::ShortAccum:
492  case BuiltinType::Accum:
493  case BuiltinType::LongAccum:
494  case BuiltinType::UShortAccum:
495  case BuiltinType::UAccum:
496  case BuiltinType::ULongAccum:
497  case BuiltinType::ShortFract:
498  case BuiltinType::Fract:
499  case BuiltinType::LongFract:
500  case BuiltinType::UShortFract:
501  case BuiltinType::UFract:
502  case BuiltinType::ULongFract:
503  case BuiltinType::SatShortAccum:
504  case BuiltinType::SatAccum:
505  case BuiltinType::SatLongAccum:
506  case BuiltinType::SatUShortAccum:
507  case BuiltinType::SatUAccum:
508  case BuiltinType::SatULongAccum:
509  case BuiltinType::SatShortFract:
510  case BuiltinType::SatFract:
511  case BuiltinType::SatLongFract:
512  case BuiltinType::SatUShortFract:
513  case BuiltinType::SatUFract:
514  case BuiltinType::SatULongFract:
515  ResultType = llvm::IntegerType::get(getLLVMContext(),
516  static_cast<unsigned>(Context.getTypeSize(T)));
517  break;
518 
519  case BuiltinType::Float16:
520  ResultType =
522  /* UseNativeHalf = */ true);
523  break;
524 
525  case BuiltinType::Half:
526  // Half FP can either be storage-only (lowered to i16) or native.
527  ResultType = getTypeForFormat(
529  Context.getLangOpts().NativeHalfType ||
531  break;
532  case BuiltinType::BFloat16:
533  case BuiltinType::Float:
534  case BuiltinType::Double:
535  case BuiltinType::LongDouble:
536  case BuiltinType::Float128:
537  case BuiltinType::Ibm128:
538  ResultType = getTypeForFormat(getLLVMContext(),
539  Context.getFloatTypeSemantics(T),
540  /* UseNativeHalf = */ false);
541  break;
542 
543  case BuiltinType::NullPtr:
544  // Model std::nullptr_t as i8*
545  ResultType = llvm::Type::getInt8PtrTy(getLLVMContext());
546  break;
547 
548  case BuiltinType::UInt128:
549  case BuiltinType::Int128:
550  ResultType = llvm::IntegerType::get(getLLVMContext(), 128);
551  break;
552 
553 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
554  case BuiltinType::Id:
555 #include "clang/Basic/OpenCLImageTypes.def"
556 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
557  case BuiltinType::Id:
558 #include "clang/Basic/OpenCLExtensionTypes.def"
559  case BuiltinType::OCLSampler:
560  case BuiltinType::OCLEvent:
561  case BuiltinType::OCLClkEvent:
562  case BuiltinType::OCLQueue:
563  case BuiltinType::OCLReserveID:
564  ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty);
565  break;
566  case BuiltinType::SveInt8:
567  case BuiltinType::SveUint8:
568  case BuiltinType::SveInt8x2:
569  case BuiltinType::SveUint8x2:
570  case BuiltinType::SveInt8x3:
571  case BuiltinType::SveUint8x3:
572  case BuiltinType::SveInt8x4:
573  case BuiltinType::SveUint8x4:
574  case BuiltinType::SveInt16:
575  case BuiltinType::SveUint16:
576  case BuiltinType::SveInt16x2:
577  case BuiltinType::SveUint16x2:
578  case BuiltinType::SveInt16x3:
579  case BuiltinType::SveUint16x3:
580  case BuiltinType::SveInt16x4:
581  case BuiltinType::SveUint16x4:
582  case BuiltinType::SveInt32:
583  case BuiltinType::SveUint32:
584  case BuiltinType::SveInt32x2:
585  case BuiltinType::SveUint32x2:
586  case BuiltinType::SveInt32x3:
587  case BuiltinType::SveUint32x3:
588  case BuiltinType::SveInt32x4:
589  case BuiltinType::SveUint32x4:
590  case BuiltinType::SveInt64:
591  case BuiltinType::SveUint64:
592  case BuiltinType::SveInt64x2:
593  case BuiltinType::SveUint64x2:
594  case BuiltinType::SveInt64x3:
595  case BuiltinType::SveUint64x3:
596  case BuiltinType::SveInt64x4:
597  case BuiltinType::SveUint64x4:
598  case BuiltinType::SveBool:
599  case BuiltinType::SveFloat16:
600  case BuiltinType::SveFloat16x2:
601  case BuiltinType::SveFloat16x3:
602  case BuiltinType::SveFloat16x4:
603  case BuiltinType::SveFloat32:
604  case BuiltinType::SveFloat32x2:
605  case BuiltinType::SveFloat32x3:
606  case BuiltinType::SveFloat32x4:
607  case BuiltinType::SveFloat64:
608  case BuiltinType::SveFloat64x2:
609  case BuiltinType::SveFloat64x3:
610  case BuiltinType::SveFloat64x4:
611  case BuiltinType::SveBFloat16:
612  case BuiltinType::SveBFloat16x2:
613  case BuiltinType::SveBFloat16x3:
614  case BuiltinType::SveBFloat16x4: {
616  Context.getBuiltinVectorTypeInfo(cast<BuiltinType>(Ty));
617  return llvm::ScalableVectorType::get(ConvertType(Info.ElementType),
618  Info.EC.getKnownMinValue() *
619  Info.NumVectors);
620  }
621 #define PPC_VECTOR_TYPE(Name, Id, Size) \
622  case BuiltinType::Id: \
623  ResultType = \
624  llvm::FixedVectorType::get(ConvertType(Context.BoolTy), Size); \
625  break;
626 #include "clang/Basic/PPCTypes.def"
627 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
628 #include "clang/Basic/RISCVVTypes.def"
629  {
631  Context.getBuiltinVectorTypeInfo(cast<BuiltinType>(Ty));
632  return llvm::ScalableVectorType::get(ConvertType(Info.ElementType),
633  Info.EC.getKnownMinValue() *
634  Info.NumVectors);
635  }
636  case BuiltinType::Dependent:
637 #define BUILTIN_TYPE(Id, SingletonId)
638 #define PLACEHOLDER_TYPE(Id, SingletonId) \
639  case BuiltinType::Id:
640 #include "clang/AST/BuiltinTypes.def"
641  llvm_unreachable("Unexpected placeholder builtin type!");
642  }
643  break;
644  }
645  case Type::Auto:
646  case Type::DeducedTemplateSpecialization:
647  llvm_unreachable("Unexpected undeduced type!");
648  case Type::Complex: {
649  llvm::Type *EltTy = ConvertType(cast<ComplexType>(Ty)->getElementType());
650  ResultType = llvm::StructType::get(EltTy, EltTy);
651  break;
652  }
653  case Type::LValueReference:
654  case Type::RValueReference: {
655  const ReferenceType *RTy = cast<ReferenceType>(Ty);
656  QualType ETy = RTy->getPointeeType();
657  llvm::Type *PointeeType = ConvertTypeForMem(ETy);
658  unsigned AS = getTargetAddressSpace(ETy);
659  ResultType = llvm::PointerType::get(PointeeType, AS);
660  break;
661  }
662  case Type::Pointer: {
663  const PointerType *PTy = cast<PointerType>(Ty);
664  QualType ETy = PTy->getPointeeType();
665  llvm::Type *PointeeType = ConvertTypeForMem(ETy);
666  if (PointeeType->isVoidTy())
667  PointeeType = llvm::Type::getInt8Ty(getLLVMContext());
668  unsigned AS = getTargetAddressSpace(ETy);
669  ResultType = llvm::PointerType::get(PointeeType, AS);
670  break;
671  }
672 
673  case Type::VariableArray: {
674  const VariableArrayType *A = cast<VariableArrayType>(Ty);
675  assert(A->getIndexTypeCVRQualifiers() == 0 &&
676  "FIXME: We only handle trivial array types so far!");
677  // VLAs resolve to the innermost element type; this matches
678  // the return of alloca, and there isn't any obviously better choice.
679  ResultType = ConvertTypeForMem(A->getElementType());
680  break;
681  }
682  case Type::IncompleteArray: {
683  const IncompleteArrayType *A = cast<IncompleteArrayType>(Ty);
684  assert(A->getIndexTypeCVRQualifiers() == 0 &&
685  "FIXME: We only handle trivial array types so far!");
686  // int X[] -> [0 x int], unless the element type is not sized. If it is
687  // unsized (e.g. an incomplete struct) just use [0 x i8].
688  ResultType = ConvertTypeForMem(A->getElementType());
689  if (!ResultType->isSized()) {
690  SkippedLayout = true;
691  ResultType = llvm::Type::getInt8Ty(getLLVMContext());
692  }
693  ResultType = llvm::ArrayType::get(ResultType, 0);
694  break;
695  }
696  case Type::ConstantArray: {
697  const ConstantArrayType *A = cast<ConstantArrayType>(Ty);
698  llvm::Type *EltTy = ConvertTypeForMem(A->getElementType());
699 
700  // Lower arrays of undefined struct type to arrays of i8 just to have a
701  // concrete type.
702  if (!EltTy->isSized()) {
703  SkippedLayout = true;
704  EltTy = llvm::Type::getInt8Ty(getLLVMContext());
705  }
706 
707  ResultType = llvm::ArrayType::get(EltTy, A->getSize().getZExtValue());
708  break;
709  }
710  case Type::ExtVector:
711  case Type::Vector: {
712  const auto *VT = cast<VectorType>(Ty);
713  // An ext_vector_type of Bool is really a vector of bits.
714  llvm::Type *IRElemTy = VT->isExtVectorBoolType()
715  ? llvm::Type::getInt1Ty(getLLVMContext())
716  : ConvertType(VT->getElementType());
717  ResultType = llvm::FixedVectorType::get(IRElemTy, VT->getNumElements());
718  break;
719  }
720  case Type::ConstantMatrix: {
721  const ConstantMatrixType *MT = cast<ConstantMatrixType>(Ty);
722  ResultType =
723  llvm::FixedVectorType::get(ConvertType(MT->getElementType()),
724  MT->getNumRows() * MT->getNumColumns());
725  break;
726  }
727  case Type::FunctionNoProto:
728  case Type::FunctionProto:
729  ResultType = ConvertFunctionTypeInternal(T);
730  break;
731  case Type::ObjCObject:
732  ResultType = ConvertType(cast<ObjCObjectType>(Ty)->getBaseType());
733  break;
734 
735  case Type::ObjCInterface: {
736  // Objective-C interfaces are always opaque (outside of the
737  // runtime, which can do whatever it likes); we never refine
738  // these.
739  llvm::Type *&T = InterfaceTypes[cast<ObjCInterfaceType>(Ty)];
740  if (!T)
742  ResultType = T;
743  break;
744  }
745 
746  case Type::ObjCObjectPointer: {
747  // Protocol qualifications do not influence the LLVM type, we just return a
748  // pointer to the underlying interface type. We don't need to worry about
749  // recursive conversion.
750  llvm::Type *T =
751  ConvertTypeForMem(cast<ObjCObjectPointerType>(Ty)->getPointeeType());
752  ResultType = T->getPointerTo();
753  break;
754  }
755 
756  case Type::Enum: {
757  const EnumDecl *ED = cast<EnumType>(Ty)->getDecl();
758  if (ED->isCompleteDefinition() || ED->isFixed())
759  return ConvertType(ED->getIntegerType());
760  // Return a placeholder 'i32' type. This can be changed later when the
761  // type is defined (see UpdateCompletedType), but is likely to be the
762  // "right" answer.
763  ResultType = llvm::Type::getInt32Ty(getLLVMContext());
764  break;
765  }
766 
767  case Type::BlockPointer: {
768  const QualType FTy = cast<BlockPointerType>(Ty)->getPointeeType();
769  llvm::Type *PointeeType = CGM.getLangOpts().OpenCL
771  : ConvertTypeForMem(FTy);
772  // Block pointers lower to function type. For function type,
773  // getTargetAddressSpace() returns default address space for
774  // function pointer i.e. program address space. Therefore, for block
775  // pointers, it is important to pass the pointee AST address space when
776  // calling getTargetAddressSpace(), to ensure that we get the LLVM IR
777  // address space for data pointers and not function pointers.
778  unsigned AS = Context.getTargetAddressSpace(FTy.getAddressSpace());
779  ResultType = llvm::PointerType::get(PointeeType, AS);
780  break;
781  }
782 
783  case Type::MemberPointer: {
784  auto *MPTy = cast<MemberPointerType>(Ty);
785  if (!getCXXABI().isMemberPointerConvertible(MPTy)) {
786  auto *C = MPTy->getClass();
787  auto Insertion = RecordsWithOpaqueMemberPointers.insert({C, nullptr});
788  if (Insertion.second)
789  Insertion.first->second = llvm::StructType::create(getLLVMContext());
790  ResultType = Insertion.first->second;
791  } else {
792  ResultType = getCXXABI().ConvertMemberPointerType(MPTy);
793  }
794  break;
795  }
796 
797  case Type::Atomic: {
798  QualType valueType = cast<AtomicType>(Ty)->getValueType();
799  ResultType = ConvertTypeForMem(valueType);
800 
801  // Pad out to the inflated size if necessary.
802  uint64_t valueSize = Context.getTypeSize(valueType);
803  uint64_t atomicSize = Context.getTypeSize(Ty);
804  if (valueSize != atomicSize) {
805  assert(valueSize < atomicSize);
806  llvm::Type *elts[] = {
807  ResultType,
808  llvm::ArrayType::get(CGM.Int8Ty, (atomicSize - valueSize) / 8)
809  };
810  ResultType = llvm::StructType::get(getLLVMContext(),
811  llvm::makeArrayRef(elts));
812  }
813  break;
814  }
815  case Type::Pipe: {
816  ResultType = CGM.getOpenCLRuntime().getPipeType(cast<PipeType>(Ty));
817  break;
818  }
819  case Type::BitInt: {
820  const auto &EIT = cast<BitIntType>(Ty);
821  ResultType = llvm::Type::getIntNTy(getLLVMContext(), EIT->getNumBits());
822  break;
823  }
824  }
825 
826  assert(ResultType && "Didn't convert a type?");
827  assert((!CachedType || CachedType == ResultType) &&
828  "Cached type doesn't match computed type");
829 
830  if (ShouldUseCache)
831  TypeCache[Ty] = ResultType;
832  return ResultType;
833 }
834 
836  return isPaddedAtomicType(type->castAs<AtomicType>());
837 }
838 
840  return Context.getTypeSize(type) != Context.getTypeSize(type->getValueType());
841 }
842 
843 /// ConvertRecordDeclType - Lay out a tagged decl type like struct or union.
844 llvm::StructType *CodeGenTypes::ConvertRecordDeclType(const RecordDecl *RD) {
845  // TagDecl's are not necessarily unique, instead use the (clang)
846  // type connected to the decl.
847  const Type *Key = Context.getTagDeclType(RD).getTypePtr();
848 
849  llvm::StructType *&Entry = RecordDeclTypes[Key];
850 
851  // If we don't have a StructType at all yet, create the forward declaration.
852  if (!Entry) {
854  addRecordTypeName(RD, Entry, "");
855  }
856  llvm::StructType *Ty = Entry;
857 
858  // If this is still a forward declaration, or the LLVM type is already
859  // complete, there's nothing more to do.
860  RD = RD->getDefinition();
861  if (!RD || !RD->isCompleteDefinition() || !Ty->isOpaque())
862  return Ty;
863 
864  // If converting this type would cause us to infinitely loop, don't do it!
865  if (!isSafeToConvert(RD, *this)) {
866  DeferredRecords.push_back(RD);
867  return Ty;
868  }
869 
870  // Okay, this is a definition of a type. Compile the implementation now.
871  bool InsertResult = RecordsBeingLaidOut.insert(Key).second;
872  (void)InsertResult;
873  assert(InsertResult && "Recursively compiling a struct?");
874 
875  // Force conversion of non-virtual base classes recursively.
876  if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(RD)) {
877  for (const auto &I : CRD->bases()) {
878  if (I.isVirtual()) continue;
879  ConvertRecordDeclType(I.getType()->castAs<RecordType>()->getDecl());
880  }
881  }
882 
883  // Layout fields.
884  std::unique_ptr<CGRecordLayout> Layout = ComputeRecordLayout(RD, Ty);
885  CGRecordLayouts[Key] = std::move(Layout);
886 
887  // We're done laying out this struct.
888  bool EraseResult = RecordsBeingLaidOut.erase(Key); (void)EraseResult;
889  assert(EraseResult && "struct not in RecordsBeingLaidOut set?");
890 
891  // If this struct blocked a FunctionType conversion, then recompute whatever
892  // was derived from that.
893  // FIXME: This is hugely overconservative.
894  if (SkippedLayout)
895  TypeCache.clear();
896 
897  // If we're done converting the outer-most record, then convert any deferred
898  // structs as well.
899  if (RecordsBeingLaidOut.empty())
900  while (!DeferredRecords.empty())
901  ConvertRecordDeclType(DeferredRecords.pop_back_val());
902 
903  return Ty;
904 }
905 
906 /// getCGRecordLayout - Return record layout info for the given record decl.
907 const CGRecordLayout &
909  const Type *Key = Context.getTagDeclType(RD).getTypePtr();
910 
911  auto I = CGRecordLayouts.find(Key);
912  if (I != CGRecordLayouts.end())
913  return *I->second;
914  // Compute the type information.
916 
917  // Now try again.
918  I = CGRecordLayouts.find(Key);
919 
920  assert(I != CGRecordLayouts.end() &&
921  "Unable to find record layout information for type");
922  return *I->second;
923 }
924 
926  assert((T->isAnyPointerType() || T->isBlockPointerType()) && "Invalid type");
927  return isZeroInitializable(T);
928 }
929 
931  if (T->getAs<PointerType>())
932  return Context.getTargetNullPointerValue(T) == 0;
933 
934  if (const auto *AT = Context.getAsArrayType(T)) {
935  if (isa<IncompleteArrayType>(AT))
936  return true;
937  if (const auto *CAT = dyn_cast<ConstantArrayType>(AT))
938  if (Context.getConstantArrayElementCount(CAT) == 0)
939  return true;
940  T = Context.getBaseElementType(T);
941  }
942 
943  // Records are non-zero-initializable if they contain any
944  // non-zero-initializable subobjects.
945  if (const RecordType *RT = T->getAs<RecordType>()) {
946  const RecordDecl *RD = RT->getDecl();
947  return isZeroInitializable(RD);
948  }
949 
950  // We have to ask the ABI about member pointers.
951  if (const MemberPointerType *MPT = T->getAs<MemberPointerType>())
952  return getCXXABI().isZeroInitializable(MPT);
953 
954  // Everything else is okay.
955  return true;
956 }
957 
960 }
961 
963  // Return the address space for the type. If the type is a
964  // function type without an address space qualifier, the
965  // program address space is used. Otherwise, the target picks
966  // the best address space based on the type information
967  return T->isFunctionType() && !T.hasAddressSpace()
968  ? getDataLayout().getProgramAddressSpace()
970 }
clang::TagDecl::getKindName
StringRef getKindName() const
Definition: Decl.h:3616
clang::CodeGen::CodeGenTypes::getContext
ASTContext & getContext() const
Definition: CodeGenTypes.h:112
clang::Decl::getASTContext
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:428
clang::ASTContext::BuiltinVectorTypeInfo::NumVectors
unsigned NumVectors
Definition: ASTContext.h:1463
clang::Type::isConstantMatrixType
bool isConstantMatrixType() const
Definition: Type.h:7003
clang::Type::isBlockPointerType
bool isBlockPointerType() const
Definition: Type.h:6891
clang::CodeGen::CodeGenTypes::noRecordsBeingLaidOut
bool noRecordsBeingLaidOut() const
Definition: CodeGenTypes.h:302
clang::CodeGen::CodeGenTypes::getTargetAddressSpace
unsigned getTargetAddressSpace(QualType T) const
Definition: CodeGenTypes.cpp:962
clang::ConstantArrayType
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3058
clang::CodeGen::CodeGenModule::getOpenCLRuntime
CGOpenCLRuntime & getOpenCLRuntime()
Return a reference to the configured OpenCL runtime.
Definition: CodeGenModule.h:629
clang::ASTContext::BuiltinVectorTypeInfo::ElementType
QualType ElementType
Definition: ASTContext.h:1461
clang::ConstantArrayType::getSize
const llvm::APInt & getSize() const
Definition: Type.h:3081
clang::if
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
Definition: RecursiveASTVisitor.h:1081
clang::CodeGen::CodeGenTypes::RefreshTypeCacheForClass
void RefreshTypeCacheForClass(const CXXRecordDecl *RD)
Remove stale types from the type cache when an inheritance model gets assigned to a class.
Definition: CodeGenTypes.cpp:299
clang::MultiVersionKind::Target
@ Target
CGRecordLayout.h
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::EnumDecl::isFixed
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition: Decl.h:3919
clang::CodeGen::CodeGenTypes::getCodeGenOpts
const CodeGenOptions & getCodeGenOpts() const
Definition: CodeGenTypes.cpp:45
clang::ASTContext::getFloatTypeSemantics
const llvm::fltSemantics & getFloatTypeSemantics(QualType T) const
Return the APFloat 'semantics' for the specified scalar floating point type.
Definition: ASTContext.cpp:1710
clang::ASTContext::getBaseElementType
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
Definition: ASTContext.cpp:6985
clang::ast_matchers::type
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchersInternal.cpp:774
DeclCXX.h
TargetInfo.h
clang::CodeGen::CodeGenTypes::isFuncParamTypeConvertible
bool isFuncParamTypeConvertible(QualType Ty)
isFuncParamTypeConvertible - Return true if the specified type in a function parameter or result posi...
Definition: CodeGenTypes.cpp:215
clang::CodeGen::CodeGenTypes::getLLVMContext
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenTypes.h:116
clang::CodeGen::CodeGenModule::getGenericBlockLiteralType
llvm::Type * getGenericBlockLiteralType()
The type of a generic block literal.
Definition: CGBlocks.cpp:1144
clang::RecordDecl::getDefinition
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4194
llvm::SmallPtrSet
Definition: ASTContext.h:55
clang::TagType
Definition: Type.h:4792
clang::CodeGen::CodeGenModule::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenModule.h:729
clang::TagDecl::getTypedefNameForAnonDecl
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3651
clang::CodeGen::TargetCodeGenInfo::getCUDADeviceBuiltinTextureDeviceType
virtual llvm::Type * getCUDADeviceBuiltinTextureDeviceType() const
Return the device-side type for the CUDA device builtin texture type.
Definition: TargetInfo.h:360
clang::PrintingPolicy
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
clang::CodeGen::CodeGenModule::getTargetCodeGenInfo
const TargetCodeGenInfo & getTargetCodeGenInfo()
Definition: TargetInfo.cpp:12068
clang::FunctionType
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3675
clang::FunctionNoProtoType
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:3978
clang::CodeGen::CodeGenTypes::ConvertType
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
Definition: CodeGenTypes.cpp:401
clang::EnumDecl
Represents an enum.
Definition: Decl.h:3705
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1565
DeclObjC.h
clang::ReferenceType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2898
clang::CodeGen::TargetCodeGenInfo::getCUDADeviceBuiltinSurfaceDeviceType
virtual llvm::Type * getCUDADeviceBuiltinSurfaceDeviceType() const
Return the device-side type for the CUDA device builtin surface type.
Definition: TargetInfo.h:355
clang::CanQual::getTypePtr
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
Definition: CanonicalType.h:83
clang::Type::isCUDADeviceBuiltinTextureType
bool isCUDADeviceBuiltinTextureType() const
Check if the type is the CUDA device builtin texture type.
Definition: Type.cpp:4436
clang::CodeGen::CodeGenTypes::ConvertTypeForMem
llvm::Type * ConvertTypeForMem(QualType T, bool ForBitField=false)
ConvertTypeForMem - Convert type T into a llvm::Type.
Definition: CodeGenTypes.cpp:91
CGCall.h
clang::ArrayType::getIndexTypeCVRQualifiers
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:3043
clang::CodeGen::CGRecordLayout::isZeroInitializable
bool isZeroInitializable() const
Check whether this struct can be C++ zero-initialized with a zeroinitializer.
Definition: CGRecordLayout.h:185
clang::Type::isBitIntType
bool isBitIntType() const
Definition: Type.h:7107
clang::RecordType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4816
clang::QualType::getAddressSpace
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:6756
hlsl::uint64_t
unsigned long uint64_t
Definition: hlsl_basic_types.h:25
clang::CodeGen::CodeGenTypes::isRecordLayoutComplete
bool isRecordLayoutComplete(const Type *Ty) const
isRecordLayoutComplete - Return true if the specified type is already completely laid out.
Definition: CodeGenTypes.cpp:122
clang::CodeGen::CodeGenModule::isPaddedAtomicType
bool isPaddedAtomicType(QualType type)
Definition: CodeGenTypes.cpp:835
clang::ASTContext::getAsArrayType
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
Definition: ASTContext.cpp:6874
clang::ASTContext::getTargetNullPointerValue
uint64_t getTargetNullPointerValue(QualType QT) const
Get target-dependent integer value for null pointer which is used for constant folding.
Definition: ASTContext.cpp:12221
clang::CodeGen::CodeGenModule::getCodeGenOpts
const CodeGenOptions & getCodeGenOpts() const
Definition: CodeGenModule.h:737
CGFunctionInfo.h
clang::CodeGen::CGCXXABI::isMemberPointerConvertible
virtual bool isMemberPointerConvertible(const MemberPointerType *MPT) const
Return whether or not a member pointers type is convertible to an IR type.
Definition: CGCXXABI.h:217
clang::ConstantMatrixType
Represents a concrete matrix type with constant number of rows and columns.
Definition: Type.h:3584
clang::ASTContext::getConstantArrayElementCount
uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const
Return number of constant array elements.
Definition: ASTContext.cpp:7005
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7386
clang::ASTContext::BuiltinVectorTypeInfo::EC
llvm::ElementCount EC
Definition: ASTContext.h:1462
clang::RISCV::Policy
Policy
Definition: RISCVVIntrinsicUtils.h:96
clang::CodeGen::CGRecordLayout
CGRecordLayout - This class handles struct and union layout info while lowering AST types to LLVM typ...
Definition: CGRecordLayout.h:121
clang::ASTContext::getBuiltinVectorTypeInfo
BuiltinVectorTypeInfo getBuiltinVectorTypeInfo(const BuiltinType *VecTy) const
Returns the element type, element count and number of vectors (in case of tuple) for a builtin vector...
Definition: ASTContext.cpp:3906
clang::ASTContext::getTypeSize
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2275
clang::CodeGen::CGDebugInfo
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:55
clang::ConstantMatrixType::getNumColumns
unsigned getNumColumns() const
Returns the number of columns in the matrix.
Definition: Type.h:3605
clang::QualType::hasAddressSpace
bool hasAddressSpace() const
Check if this type has any address space qualifier.
Definition: Type.h:6751
clang::Type::isFunctionType
bool isFunctionType() const
Definition: Type.h:6879
Expr.h
llvm::SmallString
Definition: LLVM.h:37
clang::CodeGen::CodeGenTypes::~CodeGenTypes
~CodeGenTypes()
Definition: CodeGenTypes.cpp:39
ASTContext.h
clang::ASTContext::getRecordType
QualType getRecordType(const RecordDecl *Decl) const
Definition: ASTContext.cpp:4760
clang::Type::getPointeeType
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:625
clang::TagDecl
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3423
clang::Type::isExtVectorBoolType
bool isExtVectorBoolType() const
Definition: Type.h:6993
clang::ASTContext::getCanonicalType
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2501
clang::CanQual
Represents a canonical, potentially-qualified type.
Definition: CanonicalType.h:65
clang::TagDecl::isCompleteDefinition
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3528
clang::MatrixType::getElementType
QualType getElementType() const
Returns type of the elements being stored in the matrix.
Definition: Type.h:3562
clang::CodeGen::CodeGenTypes::UpdateCompletedType
void UpdateCompletedType(const TagDecl *TD)
UpdateCompletedType - When we find the full definition for a TagDecl, replace the 'opaque' type we pr...
Definition: CodeGenTypes.cpp:263
clang::CodeGenOptions
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
Definition: CodeGenOptions.h:49
getKind
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1025
clang::Type::getTypeClass
TypeClass getTypeClass() const
Definition: Type.h:1984
clang::CodeGen::CodeGenTypes::isPointerZeroInitializable
bool isPointerZeroInitializable(QualType T)
Check if the pointer type can be zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
Definition: CodeGenTypes.cpp:925
clang::IncompleteArrayType
Represents a C array with an unspecified size.
Definition: Type.h:3118
clang::CodeGen::CodeGenTypes::isFuncTypeConvertible
bool isFuncTypeConvertible(const FunctionType *FT)
isFuncTypeConvertible - Utility to check whether a function type can be converted to an LLVM type (i....
Definition: CodeGenTypes.cpp:249
clang::ASTContext::getTargetAddressSpace
unsigned getTargetAddressSpace(LangAS AS) const
Definition: ASTContext.cpp:12231
clang::CodeGen::CodeGenModule::getModuleDebugInfo
CGDebugInfo * getModuleDebugInfo()
Definition: CodeGenModule.h:719
clang::CodeGen::CodeGenTypes::getCGRecordLayout
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
Definition: CodeGenTypes.cpp:908
clang::CodeGen::CodeGenTypes::GetFunctionType
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
Definition: CGCall.cpp:1617
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
clang::Type::isBuiltinType
bool isBuiltinType() const
Helper methods to distinguish type categories.
Definition: Type.h:6969
clang::serialized_diags::create
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Definition: SerializedDiagnosticPrinter.cpp:301
clang::QualType::isCanonical
bool isCanonical() const
Definition: Type.h:6679
clang::VariableArrayType
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3162
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:268
clang::ASTContext::getTagDeclType
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
Definition: ASTContext.cpp:5924
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4016
clang::ASTContext::getPrintingPolicy
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:686
clang::CodeGen::CodeGenModule
This class organizes the cross-function state that is used while generating LLVM code.
Definition: CodeGenModule.h:279
clang::RecordDecl::fields
field_range fields() const
Definition: Decl.h:4209
clang::CodeGen::CodeGenTypes::CodeGenTypes
CodeGenTypes(CodeGenModule &cgm)
Definition: CodeGenTypes.cpp:32
clang::RISCV::Float
@ Float
Definition: RISCVVIntrinsicUtils.h:170
CodeGenTypes.h
clang::CodeGen::CodeGenTypes
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
Definition: CodeGenTypes.h:54
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:746
clang::MemberPointerType
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2960
clang::CodeGen::CGFunctionInfo
CGFunctionInfo - Class to encapsulate the information about a function definition.
Definition: CGFunctionInfo.h:546
CGCXXABI.h
clang::CodeGen::CGCXXABI::ConvertMemberPointerType
virtual llvm::Type * ConvertMemberPointerType(const MemberPointerType *MPT)
Find the LLVM type used to represent the given member pointer type.
Definition: CGCXXABI.cpp:37
clang::CodeGen::CGOpenCLRuntime::convertOpenCLSpecificType
virtual llvm::Type * convertOpenCLSpecificType(const Type *T)
Definition: CGOpenCLRuntime.cpp:33
clang::PointerType
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2769
isSafeToConvert
static bool isSafeToConvert(QualType T, CodeGenTypes &CGT, llvm::SmallPtrSet< const RecordDecl *, 16 > &AlreadyChecked)
isSafeToConvert - Return true if it is safe to convert this field type, which requires the structure ...
Definition: CodeGenTypes.cpp:178
clang::CodeGen::CGOpenCLRuntime::getPipeType
virtual llvm::Type * getPipeType(const PipeType *T, StringRef Name, llvm::Type *&PipeTy)
Definition: CGOpenCLRuntime.cpp:84
clang::DeclaratorContext::TypeName
@ TypeName
clang::CodeGen::CodeGenTypes::getCXXABI
CGCXXABI & getCXXABI() const
Definition: CodeGenTypes.h:115
clang::CodeGen::CodeGenTypes::isRecordBeingLaidOut
bool isRecordBeingLaidOut(const Type *Ty) const
Definition: CodeGenTypes.h:305
clang::ASTContext::BuiltinVectorTypeInfo
Definition: ASTContext.h:1460
getTypeForFormat
static llvm::Type * getTypeForFormat(llvm::LLVMContext &VMContext, const llvm::fltSemantics &format, bool UseNativeHalf=false)
Definition: CodeGenTypes.cpp:310
clang
Definition: CalledOnceCheck.h:17
clang::Type::isAnyPointerType
bool isAnyPointerType() const
Definition: Type.h:6887
CGOpenCLRuntime.h
clang::CodeGen::CodeGenTypes::addRecordTypeName
void addRecordTypeName(const RecordDecl *RD, llvm::StructType *Ty, StringRef suffix)
addRecordTypeName - Compute a name from the given record decl with an optional suffix and name the gi...
Definition: CodeGenTypes.cpp:49
clang::EnumDecl::getIntegerType
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:3865
clang::CodeGen::CodeGenTypes::ConvertRecordDeclType
llvm::StructType * ConvertRecordDeclType(const RecordDecl *TD)
ConvertRecordDeclType - Lay out a tagged decl type like struct or union.
Definition: CodeGenTypes.cpp:844
clang::FunctionType::getReturnType
QualType getReturnType() const
Definition: Type.h:3940
clang::CodeGen::CodeGenTypes::getDataLayout
const llvm::DataLayout & getDataLayout() const
Definition: CodeGenTypes.h:109
clang::TypedefNameDecl
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3275
clang::CodeGen::CodeGenTypes::arrangeFreeFunctionType
const CGFunctionInfo & arrangeFreeFunctionType(CanQual< FunctionProtoType > Ty)
Arrange the argument and result information for a value of the given freestanding function type.
Definition: CGCall.cpp:201
clang::QualType::getTypePtr
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6622
clang::RecordType::getDecl
RecordDecl * getDecl() const
Definition: Type.h:4826
clang::ReferenceType
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2880
clang::PointerType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2779
clang::CodeGen::CodeGenTypes::isZeroInitializable
bool isZeroInitializable(QualType T)
IsZeroInitializable - Return whether a type can be zero-initialized (in the C++ sense) with an LLVM z...
Definition: CodeGenTypes.cpp:930
clang::AtomicType
Definition: Type.h:6440
clang::CodeGen::CodeGenTypes::ComputeRecordLayout
std::unique_ptr< CGRecordLayout > ComputeRecordLayout(const RecordDecl *D, llvm::StructType *Ty)
Compute a new LLVM record layout object for the given record.
Definition: CGRecordLayoutBuilder.cpp:878
clang::TagDecl::isDependentType
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Definition: Decl.h:3579
clang::ArrayType::getElementType
QualType getElementType() const
Definition: Type.h:3033
clang::CodeGen::CodeGenTypeCache::Int8Ty
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Definition: CodeGenTypeCache.h:37
clang::NamedDecl::printQualifiedName
void printQualifiedName(raw_ostream &OS) const
Returns a human-readable qualified name for this declaration, like A::B::i, for i being member of nam...
Definition: Decl.cpp:1633
clang::Type::isIncompleteType
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2235
clang::TagDecl::printName
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition: Decl.cpp:4490
clang::ConstantMatrixType::getNumRows
unsigned getNumRows() const
Returns the number of rows in the matrix.
Definition: Type.h:3602
clang::Type::isCUDADeviceBuiltinSurfaceType
bool isCUDADeviceBuiltinSurfaceType() const
Check if the type is the CUDA device builtin surface type.
Definition: Type.cpp:4429
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3983
clang::CodeGen::CGCXXABI::isZeroInitializable
virtual bool isZeroInitializable(const MemberPointerType *MPT)
Return true if the given member pointer can be zero-initialized (in the C++ sense) with an LLVM zeroi...
Definition: CGCXXABI.cpp:116
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:764
clang::TargetInfo::useFP16ConversionIntrinsics
virtual bool useFP16ConversionIntrinsics() const
Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used to convert to and from __fp...
Definition: TargetInfo.h:931
RecordLayout.h
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:441