clang  20.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 "CGHLSLRuntime.h"
17 #include "CGOpenCLRuntime.h"
18 #include "CGRecordLayout.h"
19 #include "TargetInfo.h"
20 #include "clang/AST/ASTContext.h"
21 #include "clang/AST/DeclCXX.h"
22 #include "clang/AST/DeclObjC.h"
23 #include "clang/AST/Expr.h"
24 #include "clang/AST/RecordLayout.h"
26 #include "llvm/IR/DataLayout.h"
27 #include "llvm/IR/DerivedTypes.h"
28 #include "llvm/IR/Module.h"
29 
30 using namespace clang;
31 using namespace CodeGen;
32 
34  : CGM(cgm), Context(cgm.getContext()), TheModule(cgm.getModule()),
35  Target(cgm.getTarget()), TheCXXABI(cgm.getCXXABI()),
36  TheABIInfo(cgm.getTargetCodeGenInfo().getABIInfo()) {
37  SkippedLayout = false;
38  LongDoubleReferenced = false;
39 }
40 
42  for (llvm::FoldingSet<CGFunctionInfo>::iterator
43  I = FunctionInfos.begin(), E = FunctionInfos.end(); I != E; )
44  delete &*I++;
45 }
46 
48  return CGM.getCodeGenOpts();
49 }
50 
52  llvm::StructType *Ty,
53  StringRef suffix) {
55  llvm::raw_svector_ostream OS(TypeName);
56  OS << RD->getKindName() << '.';
57 
58  // FIXME: We probably want to make more tweaks to the printing policy. For
59  // example, we should probably enable PrintCanonicalTypes and
60  // FullyQualifiedNames.
62  Policy.SuppressInlineNamespace = false;
63 
64  // Name the codegen type after the typedef name
65  // if there is no tag type name available
66  if (RD->getIdentifier()) {
67  // FIXME: We should not have to check for a null decl context here.
68  // Right now we do it because the implicit Obj-C decls don't have one.
69  if (RD->getDeclContext())
70  RD->printQualifiedName(OS, Policy);
71  else
72  RD->printName(OS, Policy);
73  } else if (const TypedefNameDecl *TDD = RD->getTypedefNameForAnonDecl()) {
74  // FIXME: We should not have to check for a null decl context here.
75  // Right now we do it because the implicit Obj-C decls don't have one.
76  if (TDD->getDeclContext())
77  TDD->printQualifiedName(OS, Policy);
78  else
79  TDD->printName(OS);
80  } else
81  OS << "anon";
82 
83  if (!suffix.empty())
84  OS << suffix;
85 
86  Ty->setName(OS.str());
87 }
88 
89 /// ConvertTypeForMem - Convert type T into a llvm::Type. This differs from
90 /// ConvertType in that it is used to convert to the memory representation for
91 /// a type. For example, the scalar representation for _Bool is i1, but the
92 /// memory representation is usually i8 or i32, depending on the target.
93 ///
94 /// We generally assume that the alloc size of this type under the LLVM
95 /// data layout is the same as the size of the AST type. The alignment
96 /// does not have to match: Clang should always use explicit alignments
97 /// and packed structs as necessary to produce the layout it needs.
98 /// But the size does need to be exactly right or else things like struct
99 /// layout will break.
101  if (T->isConstantMatrixType()) {
102  const Type *Ty = Context.getCanonicalType(T).getTypePtr();
103  const ConstantMatrixType *MT = cast<ConstantMatrixType>(Ty);
104  return llvm::ArrayType::get(ConvertType(MT->getElementType()),
105  MT->getNumRows() * MT->getNumColumns());
106  }
107 
108  llvm::Type *R = ConvertType(T);
109 
110  // Check for the boolean vector case.
111  if (T->isExtVectorBoolType()) {
112  auto *FixedVT = cast<llvm::FixedVectorType>(R);
113  // Pad to at least one byte.
114  uint64_t BytePadded = std::max<uint64_t>(FixedVT->getNumElements(), 8);
115  return llvm::IntegerType::get(FixedVT->getContext(), BytePadded);
116  }
117 
118  // If T is _Bool or a _BitInt type, ConvertType will produce an IR type
119  // with the exact semantic bit-width of the AST type; for example,
120  // _BitInt(17) will turn into i17. In memory, however, we need to store
121  // such values extended to their full storage size as decided by AST
122  // layout; this is an ABI requirement. Ideally, we would always use an
123  // integer type that's just the bit-size of the AST type; for example, if
124  // sizeof(_BitInt(17)) == 4, _BitInt(17) would turn into i32. That is what's
125  // returned by convertTypeForLoadStore. However, that type does not
126  // always satisfy the size requirement on memory representation types
127  // describe above. For example, a 32-bit platform might reasonably set
128  // sizeof(_BitInt(65)) == 12, but i96 is likely to have to have an alloc size
129  // of 16 bytes in the LLVM data layout. In these cases, we simply return
130  // a byte array of the appropriate size.
131  if (T->isBitIntType()) {
133  return llvm::ArrayType::get(CGM.Int8Ty,
134  Context.getTypeSizeInChars(T).getQuantity());
135  return llvm::IntegerType::get(getLLVMContext(),
136  (unsigned)Context.getTypeSize(T));
137  }
138 
139  if (R->isIntegerTy(1))
140  return llvm::IntegerType::get(getLLVMContext(),
141  (unsigned)Context.getTypeSize(T));
142 
143  // Else, don't map it.
144  return R;
145 }
146 
148  llvm::Type *LLVMTy) {
149  if (!LLVMTy)
150  LLVMTy = ConvertType(ASTTy);
151 
152  CharUnits ASTSize = Context.getTypeSizeInChars(ASTTy);
153  CharUnits LLVMSize =
155  return ASTSize != LLVMSize;
156 }
157 
159  llvm::Type *LLVMTy) {
160  if (!LLVMTy)
161  LLVMTy = ConvertType(T);
162 
163  if (T->isBitIntType())
164  return llvm::Type::getIntNTy(
165  getLLVMContext(), Context.getTypeSizeInChars(T).getQuantity() * 8);
166 
167  if (LLVMTy->isIntegerTy(1))
168  return llvm::IntegerType::get(getLLVMContext(),
169  (unsigned)Context.getTypeSize(T));
170 
171  if (T->isExtVectorBoolType())
172  return ConvertTypeForMem(T);
173 
174  return LLVMTy;
175 }
176 
177 /// isRecordLayoutComplete - Return true if the specified type is already
178 /// completely laid out.
180  llvm::DenseMap<const Type*, llvm::StructType *>::const_iterator I =
181  RecordDeclTypes.find(Ty);
182  return I != RecordDeclTypes.end() && !I->second->isOpaque();
183 }
184 
185 /// isFuncParamTypeConvertible - Return true if the specified type in a
186 /// function parameter or result position can be converted to an IR type at this
187 /// point. This boils down to being whether it is complete.
188 
190  // Some ABIs cannot have their member pointers represented in IR unless
191  // certain circumstances have been reached.
192  if (const auto *MPT = Ty->getAs<MemberPointerType>())
194 
195  // If this isn't a tagged type, we can convert it!
196  const TagType *TT = Ty->getAs<TagType>();
197  if (!TT) return true;
198 
199  // Incomplete types cannot be converted.
200  // Incomplete types cannot be converted.
201  return !TT->isIncompleteType();
202 }
203 
204 
205 /// Code to verify a given function type is complete, i.e. the return type
206 /// and all of the parameter types are complete. Also check to see if we are in
207 /// a RS_StructPointer context, and if so whether any struct types have been
208 /// pended. If so, we don't want to ask the ABI lowering code to handle a type
209 /// that cannot be converted to an IR type.
212  return false;
213 
214  if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT))
215  for (unsigned i = 0, e = FPT->getNumParams(); i != e; i++)
216  if (!isFuncParamTypeConvertible(FPT->getParamType(i)))
217  return false;
218 
219  return true;
220 }
221 
222 /// UpdateCompletedType - When we find the full definition for a TagDecl,
223 /// replace the 'opaque' type we previously made for it if applicable.
225  // If this is an enum being completed, then we flush all non-struct types from
226  // the cache. This allows function types and other things that may be derived
227  // from the enum to be recomputed.
228  if (const EnumDecl *ED = dyn_cast<EnumDecl>(TD)) {
229  // Only flush the cache if we've actually already converted this type.
230  if (TypeCache.count(ED->getTypeForDecl())) {
231  // Okay, we formed some types based on this. We speculated that the enum
232  // would be lowered to i32, so we only need to flush the cache if this
233  // didn't happen.
234  if (!ConvertType(ED->getIntegerType())->isIntegerTy(32))
235  TypeCache.clear();
236  }
237  // If this is the SYCL aspect enum it is saved for later processing.
238  if (const auto *Attr = ED->getAttr<SYCLTypeAttr>())
239  if (Attr->getType() == SYCLTypeAttr::SYCLType::aspect)
240  CGM.setAspectsEnumDecl(ED);
241  // If necessary, provide the full definition of a type only used with a
242  // declaration so far.
243  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
244  DI->completeType(ED);
245  return;
246  }
247 
248  // If we completed a RecordDecl that we previously used and converted to an
249  // anonymous type, then go ahead and complete it now.
250  const RecordDecl *RD = cast<RecordDecl>(TD);
251  if (RD->isDependentType()) return;
252 
253  // Only complete it if we converted it already. If we haven't converted it
254  // yet, we'll just do it lazily.
255  if (RecordDeclTypes.count(Context.getTagDeclType(RD).getTypePtr()))
257 
258  // If necessary, provide the full definition of a type only used with a
259  // declaration so far.
260  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
261  DI->completeType(RD);
262 }
263 
265  QualType T = Context.getRecordType(RD);
266  T = Context.getCanonicalType(T);
267 
268  const Type *Ty = T.getTypePtr();
269  if (RecordsWithOpaqueMemberPointers.count(Ty)) {
270  TypeCache.clear();
271  RecordsWithOpaqueMemberPointers.clear();
272  }
273 }
274 
275 static llvm::Type *getTypeForFormat(llvm::LLVMContext &VMContext,
276  const llvm::fltSemantics &format,
277  bool UseNativeHalf = false) {
278  if (&format == &llvm::APFloat::IEEEhalf()) {
279  if (UseNativeHalf)
280  return llvm::Type::getHalfTy(VMContext);
281  else
282  return llvm::Type::getInt16Ty(VMContext);
283  }
284  if (&format == &llvm::APFloat::BFloat())
285  return llvm::Type::getBFloatTy(VMContext);
286  if (&format == &llvm::APFloat::IEEEsingle())
287  return llvm::Type::getFloatTy(VMContext);
288  if (&format == &llvm::APFloat::IEEEdouble())
289  return llvm::Type::getDoubleTy(VMContext);
290  if (&format == &llvm::APFloat::IEEEquad())
291  return llvm::Type::getFP128Ty(VMContext);
292  if (&format == &llvm::APFloat::PPCDoubleDouble())
293  return llvm::Type::getPPC_FP128Ty(VMContext);
294  if (&format == &llvm::APFloat::x87DoubleExtended())
295  return llvm::Type::getX86_FP80Ty(VMContext);
296  llvm_unreachable("Unknown float format!");
297 }
298 
299 llvm::Type *CodeGenTypes::ConvertFunctionTypeInternal(QualType QFT) {
300  assert(QFT.isCanonical());
301  const FunctionType *FT = cast<FunctionType>(QFT.getTypePtr());
302  // First, check whether we can build the full function type. If the
303  // function type depends on an incomplete type (e.g. a struct or enum), we
304  // cannot lower the function type.
305  if (!isFuncTypeConvertible(FT)) {
306  // This function's type depends on an incomplete tag type.
307 
308  // Force conversion of all the relevant record types, to make sure
309  // we re-convert the FunctionType when appropriate.
310  if (const RecordType *RT = FT->getReturnType()->getAs<RecordType>())
311  ConvertRecordDeclType(RT->getDecl());
312  if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT))
313  for (unsigned i = 0, e = FPT->getNumParams(); i != e; i++)
314  if (const RecordType *RT = FPT->getParamType(i)->getAs<RecordType>())
315  ConvertRecordDeclType(RT->getDecl());
316 
317  SkippedLayout = true;
318 
319  // Return a placeholder type.
320  return llvm::StructType::get(getLLVMContext());
321  }
322 
323  // The function type can be built; call the appropriate routines to
324  // build it.
325  const CGFunctionInfo *FI;
326  if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT)) {
329  } else {
330  const FunctionNoProtoType *FNPT = cast<FunctionNoProtoType>(FT);
333  }
334 
335  llvm::Type *ResultType = nullptr;
336  // If there is something higher level prodding our CGFunctionInfo, then
337  // don't recurse into it again.
338  if (FunctionsBeingProcessed.count(FI)) {
339 
340  ResultType = llvm::StructType::get(getLLVMContext());
341  SkippedLayout = true;
342  } else {
343 
344  // Otherwise, we're good to go, go ahead and convert it.
345  ResultType = GetFunctionType(*FI);
346  }
347 
348  return ResultType;
349 }
350 
351 template <bool NeedTypeInterpret = false>
352 llvm::Type *getJointMatrixINTELExtType(llvm::Type *CompTy,
353  ArrayRef<TemplateArgument> TemplateArgs,
354  const unsigned Val = 0) {
355  // TODO: we should actually have exactly 5 template parameters: 1 for
356  // type and 4 for type parameters. But in previous version of the SPIR-V
357  // spec we have Layout matrix type parameter, that was later removed.
358  // Once we update to the newest version of the spec - this should be updated.
359  assert((TemplateArgs.size() == 5 || TemplateArgs.size() == 6) &&
360  "Wrong JointMatrixINTEL template parameters number");
361  // This is required to represent optional 'Component Type Interpretation'
362  // parameter
363  std::vector<unsigned> Params;
364  for (size_t I = 1; I != TemplateArgs.size(); ++I) {
365  assert(TemplateArgs[I].getKind() == TemplateArgument::Integral &&
366  "Wrong JointMatrixINTEL template parameter");
367  Params.push_back(TemplateArgs[I].getAsIntegral().getExtValue());
368  }
369  // Don't add type interpretation for legacy matrices.
370  // Legacy matrices has 5 template parameters, while new representation
371  // has 6.
372  if (NeedTypeInterpret && TemplateArgs.size() != 5)
373  Params.push_back(Val);
374 
375  return llvm::TargetExtType::get(CompTy->getContext(),
376  "spirv.JointMatrixINTEL", {CompTy}, Params);
377 }
378 
379 llvm::Type *
381  ArrayRef<TemplateArgument> TemplateArgs) {
382  assert(TemplateArgs.size() == 5 &&
383  "Wrong CooperativeMatrixKHR template parameters number");
384  std::vector<unsigned> Params;
385  for (size_t I = 1; I != TemplateArgs.size(); ++I) {
386  assert(TemplateArgs[I].getKind() == TemplateArgument::Integral &&
387  "Wrong CooperativeMatrixKHR template parameter");
388  Params.push_back(TemplateArgs[I].getAsIntegral().getExtValue());
389  }
390 
391  return llvm::TargetExtType::get(
392  CompTy->getContext(), "spirv.CooperativeMatrixKHR", {CompTy}, Params);
393 }
394 
395 /// ConvertSYCLJointMatrixINTELType - Convert SYCL joint_matrix type
396 /// which is represented as a pointer to a structure to LLVM extension type
397 /// with the parameters that follow SPIR-V JointMatrixINTEL type.
398 /// The expected representation is:
399 /// target("spirv.JointMatrixINTEL", %element_type, %rows%, %cols%, %scope%,
400 /// %use%, (optional) %element_type_interpretation%)
402  auto *TemplateDecl = cast<ClassTemplateSpecializationDecl>(RD);
403  ArrayRef<TemplateArgument> TemplateArgs =
404  TemplateDecl->getTemplateArgs().asArray();
405  assert(TemplateArgs[0].getKind() == TemplateArgument::Type &&
406  "1st JointMatrixINTEL template parameter must be type");
407  llvm::Type *CompTy = ConvertType(TemplateArgs[0].getAsType());
408 
409  // Per JointMatrixINTEL spec the type can have an optional
410  // 'Component Type Interpretation' parameter. We should emit it in case
411  // if on SYCL level joint matrix accepts 'bfloat16' or 'tf32' objects as
412  // matrix's components. Yet 'bfloat16' should be represented as 'int16' and
413  // 'tf32' as 'float' types.
414  if (CompTy->isStructTy()) {
415  StringRef LlvmTyName = CompTy->getStructName();
416  // Emit half/int16/float for sycl[::*]::{half,bfloat16,tf32}
417  if (LlvmTyName.starts_with("class.sycl::") ||
418  LlvmTyName.starts_with("class.__sycl_internal::"))
419  LlvmTyName = LlvmTyName.rsplit("::").second;
420  if (LlvmTyName == "half") {
421  CompTy = llvm::Type::getHalfTy(getLLVMContext());
422  return getJointMatrixINTELExtType(CompTy, TemplateArgs);
423  } else if (LlvmTyName == "tf32") {
424  CompTy = llvm::Type::getFloatTy(getLLVMContext());
425  // 'tf32' interpretation is mapped to '0'
426  return getJointMatrixINTELExtType<true>(CompTy, TemplateArgs, 0);
427  } else if (LlvmTyName == "bfloat16") {
428  CompTy = llvm::Type::getInt16Ty(getLLVMContext());
429  // 'bfloat16' interpretation is mapped to '1'
430  return getJointMatrixINTELExtType<true>(CompTy, TemplateArgs, 1);
431  } else {
432  llvm_unreachable("Wrong matrix base type!");
433  }
434  }
435  return getJointMatrixINTELExtType(CompTy, TemplateArgs);
436 }
437 
438 /// ConvertSPVCooperativeMatrixType - Convert SYCL joint_matrix type
439 /// which is represented as a pointer to a structure to LLVM extension type
440 /// with the parameters that follow SPIR-V CooperativeMatrixKHR type.
441 /// The expected representation is:
442 /// target("spirv.CooperativeMatrixKHR", %element_type, %scope%, %rows%, %cols%,
443 /// %use%)
445  auto *TemplateDecl = cast<ClassTemplateSpecializationDecl>(RD);
446  ArrayRef<TemplateArgument> TemplateArgs =
447  TemplateDecl->getTemplateArgs().asArray();
448  assert(TemplateArgs[0].getKind() == TemplateArgument::Type &&
449  "1st CooperativeMatrixKHR template parameter must be type");
450  llvm::Type *CompTy = ConvertType(TemplateArgs[0].getAsType());
451 
452  if (CompTy->isStructTy()) {
453  StringRef LlvmTyName = CompTy->getStructName();
454  // Emit half/int16/float for sycl[::*]::{half,bfloat16,tf32}
455  if (LlvmTyName.starts_with("class.sycl::") ||
456  LlvmTyName.starts_with("class.__sycl_internal::"))
457  LlvmTyName = LlvmTyName.rsplit("::").second;
458  if (LlvmTyName == "half") {
459  CompTy = llvm::Type::getHalfTy(getLLVMContext());
460  } else if (LlvmTyName == "tf32") {
461  CompTy = llvm::Type::getFloatTy(getLLVMContext());
462  } else if (LlvmTyName == "bfloat16") {
463  CompTy = llvm::Type::getInt16Ty(getLLVMContext());
464  } else {
465  llvm_unreachable("Wrong matrix base type!");
466  }
467  }
468  return getCooperativeMatrixKHRExtType(CompTy, TemplateArgs);
469 }
470 
471 /// ConvertType - Convert the specified type to its LLVM form.
473  T = Context.getCanonicalType(T);
474 
475  const Type *Ty = T.getTypePtr();
476 
477  // For the device-side compilation, CUDA device builtin surface/texture types
478  // may be represented in different types.
479  if (Context.getLangOpts().CUDAIsDevice) {
481  if (auto *Ty = CGM.getTargetCodeGenInfo()
483  return Ty;
484  } else if (T->isCUDADeviceBuiltinTextureType()) {
485  if (auto *Ty = CGM.getTargetCodeGenInfo()
487  return Ty;
488  }
489  }
490 
491  // RecordTypes are cached and processed specially.
492  if (const RecordType *RT = dyn_cast<RecordType>(Ty))
493  return ConvertRecordDeclType(RT->getDecl());
494 
495  llvm::Type *CachedType = nullptr;
496  auto TCI = TypeCache.find(Ty);
497  if (TCI != TypeCache.end())
498  CachedType = TCI->second;
499  // With expensive checks, check that the type we compute matches the
500  // cached type.
501 #ifndef EXPENSIVE_CHECKS
502  if (CachedType)
503  return CachedType;
504 #endif
505 
506  // If we don't have it in the cache, convert it now.
507  llvm::Type *ResultType = nullptr;
508  switch (Ty->getTypeClass()) {
509  case Type::Record: // Handled above.
510 #define TYPE(Class, Base)
511 #define ABSTRACT_TYPE(Class, Base)
512 #define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
513 #define DEPENDENT_TYPE(Class, Base) case Type::Class:
514 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
515 #include "clang/AST/TypeNodes.inc"
516  llvm_unreachable("Non-canonical or dependent types aren't possible.");
517 
518  case Type::Builtin: {
519  switch (cast<BuiltinType>(Ty)->getKind()) {
520  case BuiltinType::Void:
521  case BuiltinType::ObjCId:
522  case BuiltinType::ObjCClass:
523  case BuiltinType::ObjCSel:
524  // LLVM void type can only be used as the result of a function call. Just
525  // map to the same as char.
526  ResultType = llvm::Type::getInt8Ty(getLLVMContext());
527  break;
528 
529  case BuiltinType::Bool:
530  // Note that we always return bool as i1 for use as a scalar type.
531  ResultType = llvm::Type::getInt1Ty(getLLVMContext());
532  break;
533 
534  case BuiltinType::Char_S:
535  case BuiltinType::Char_U:
536  case BuiltinType::SChar:
537  case BuiltinType::UChar:
538  case BuiltinType::Short:
539  case BuiltinType::UShort:
540  case BuiltinType::Int:
541  case BuiltinType::UInt:
542  case BuiltinType::Long:
543  case BuiltinType::ULong:
544  case BuiltinType::LongLong:
545  case BuiltinType::ULongLong:
546  case BuiltinType::WChar_S:
547  case BuiltinType::WChar_U:
548  case BuiltinType::Char8:
549  case BuiltinType::Char16:
550  case BuiltinType::Char32:
551  case BuiltinType::ShortAccum:
552  case BuiltinType::Accum:
553  case BuiltinType::LongAccum:
554  case BuiltinType::UShortAccum:
555  case BuiltinType::UAccum:
556  case BuiltinType::ULongAccum:
557  case BuiltinType::ShortFract:
558  case BuiltinType::Fract:
559  case BuiltinType::LongFract:
560  case BuiltinType::UShortFract:
561  case BuiltinType::UFract:
562  case BuiltinType::ULongFract:
563  case BuiltinType::SatShortAccum:
564  case BuiltinType::SatAccum:
565  case BuiltinType::SatLongAccum:
566  case BuiltinType::SatUShortAccum:
567  case BuiltinType::SatUAccum:
568  case BuiltinType::SatULongAccum:
569  case BuiltinType::SatShortFract:
570  case BuiltinType::SatFract:
571  case BuiltinType::SatLongFract:
572  case BuiltinType::SatUShortFract:
573  case BuiltinType::SatUFract:
574  case BuiltinType::SatULongFract:
575  ResultType = llvm::IntegerType::get(getLLVMContext(),
576  static_cast<unsigned>(Context.getTypeSize(T)));
577  break;
578 
579  case BuiltinType::Float16:
580  ResultType =
582  /* UseNativeHalf = */ true);
583  break;
584 
585  case BuiltinType::Half:
586  // Half FP can either be storage-only (lowered to i16) or native.
587  ResultType = getTypeForFormat(
589  Context.getLangOpts().NativeHalfType ||
591  break;
592  case BuiltinType::LongDouble:
593  LongDoubleReferenced = true;
594  [[fallthrough]];
595  case BuiltinType::BFloat16:
596  case BuiltinType::Float:
597  case BuiltinType::Double:
598  case BuiltinType::Float128:
599  case BuiltinType::Ibm128:
600  ResultType = getTypeForFormat(getLLVMContext(),
601  Context.getFloatTypeSemantics(T),
602  /* UseNativeHalf = */ false);
603  break;
604 
605  case BuiltinType::NullPtr:
606  // Model std::nullptr_t as i8*
607  ResultType = llvm::PointerType::getUnqual(getLLVMContext());
608  break;
609 
610  case BuiltinType::UInt128:
611  case BuiltinType::Int128:
612  ResultType = llvm::IntegerType::get(getLLVMContext(), 128);
613  break;
614 
615 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
616  case BuiltinType::Id:
617 #include "clang/Basic/OpenCLImageTypes.def"
618 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
619  case BuiltinType::Sampled##Id:
620 #define IMAGE_WRITE_TYPE(Type, Id, Ext)
621 #define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
622 #include "clang/Basic/OpenCLImageTypes.def"
623 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
624  case BuiltinType::Id:
625 #include "clang/Basic/OpenCLExtensionTypes.def"
626  case BuiltinType::OCLSampler:
627  case BuiltinType::OCLEvent:
628  case BuiltinType::OCLClkEvent:
629  case BuiltinType::OCLQueue:
630  case BuiltinType::OCLReserveID:
631  ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty);
632  break;
633  case BuiltinType::SveInt8:
634  case BuiltinType::SveUint8:
635  case BuiltinType::SveInt8x2:
636  case BuiltinType::SveUint8x2:
637  case BuiltinType::SveInt8x3:
638  case BuiltinType::SveUint8x3:
639  case BuiltinType::SveInt8x4:
640  case BuiltinType::SveUint8x4:
641  case BuiltinType::SveInt16:
642  case BuiltinType::SveUint16:
643  case BuiltinType::SveInt16x2:
644  case BuiltinType::SveUint16x2:
645  case BuiltinType::SveInt16x3:
646  case BuiltinType::SveUint16x3:
647  case BuiltinType::SveInt16x4:
648  case BuiltinType::SveUint16x4:
649  case BuiltinType::SveInt32:
650  case BuiltinType::SveUint32:
651  case BuiltinType::SveInt32x2:
652  case BuiltinType::SveUint32x2:
653  case BuiltinType::SveInt32x3:
654  case BuiltinType::SveUint32x3:
655  case BuiltinType::SveInt32x4:
656  case BuiltinType::SveUint32x4:
657  case BuiltinType::SveInt64:
658  case BuiltinType::SveUint64:
659  case BuiltinType::SveInt64x2:
660  case BuiltinType::SveUint64x2:
661  case BuiltinType::SveInt64x3:
662  case BuiltinType::SveUint64x3:
663  case BuiltinType::SveInt64x4:
664  case BuiltinType::SveUint64x4:
665  case BuiltinType::SveBool:
666  case BuiltinType::SveBoolx2:
667  case BuiltinType::SveBoolx4:
668  case BuiltinType::SveFloat16:
669  case BuiltinType::SveFloat16x2:
670  case BuiltinType::SveFloat16x3:
671  case BuiltinType::SveFloat16x4:
672  case BuiltinType::SveFloat32:
673  case BuiltinType::SveFloat32x2:
674  case BuiltinType::SveFloat32x3:
675  case BuiltinType::SveFloat32x4:
676  case BuiltinType::SveFloat64:
677  case BuiltinType::SveFloat64x2:
678  case BuiltinType::SveFloat64x3:
679  case BuiltinType::SveFloat64x4:
680  case BuiltinType::SveBFloat16:
681  case BuiltinType::SveBFloat16x2:
682  case BuiltinType::SveBFloat16x3:
683  case BuiltinType::SveBFloat16x4: {
685  Context.getBuiltinVectorTypeInfo(cast<BuiltinType>(Ty));
686  return llvm::ScalableVectorType::get(ConvertType(Info.ElementType),
687  Info.EC.getKnownMinValue() *
688  Info.NumVectors);
689  }
690  case BuiltinType::SveCount:
691  return llvm::TargetExtType::get(getLLVMContext(), "aarch64.svcount");
692 #define PPC_VECTOR_TYPE(Name, Id, Size) \
693  case BuiltinType::Id: \
694  ResultType = \
695  llvm::FixedVectorType::get(ConvertType(Context.BoolTy), Size); \
696  break;
697 #include "clang/Basic/PPCTypes.def"
698 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
699 #include "clang/Basic/RISCVVTypes.def"
700  {
702  Context.getBuiltinVectorTypeInfo(cast<BuiltinType>(Ty));
703  // Tuple types are expressed as aggregregate types of the same scalable
704  // vector type (e.g. vint32m1x2_t is two vint32m1_t, which is {<vscale x
705  // 2 x i32>, <vscale x 2 x i32>}).
706  if (Info.NumVectors != 1) {
707  llvm::Type *EltTy = llvm::ScalableVectorType::get(
708  ConvertType(Info.ElementType), Info.EC.getKnownMinValue());
710  return llvm::StructType::get(getLLVMContext(), EltTys);
711  }
712  return llvm::ScalableVectorType::get(ConvertType(Info.ElementType),
713  Info.EC.getKnownMinValue());
714  }
715 #define WASM_REF_TYPE(Name, MangledName, Id, SingletonId, AS) \
716  case BuiltinType::Id: { \
717  if (BuiltinType::Id == BuiltinType::WasmExternRef) \
718  ResultType = CGM.getTargetCodeGenInfo().getWasmExternrefReferenceType(); \
719  else \
720  llvm_unreachable("Unexpected wasm reference builtin type!"); \
721  } break;
722 #include "clang/Basic/WebAssemblyReferenceTypes.def"
723 #define AMDGPU_OPAQUE_PTR_TYPE(Name, MangledName, AS, Width, Align, Id, \
724  SingletonId) \
725  case BuiltinType::Id: \
726  return llvm::PointerType::get(getLLVMContext(), AS);
727 #include "clang/Basic/AMDGPUTypes.def"
728 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
729 #include "clang/Basic/HLSLIntangibleTypes.def"
730  ResultType = CGM.getHLSLRuntime().convertHLSLSpecificType(Ty);
731  break;
732  case BuiltinType::Dependent:
733 #define BUILTIN_TYPE(Id, SingletonId)
734 #define PLACEHOLDER_TYPE(Id, SingletonId) \
735  case BuiltinType::Id:
736 #include "clang/AST/BuiltinTypes.def"
737  llvm_unreachable("Unexpected placeholder builtin type!");
738  }
739  break;
740  }
741  case Type::Auto:
742  case Type::DeducedTemplateSpecialization:
743  llvm_unreachable("Unexpected undeduced type!");
744  case Type::Complex: {
745  llvm::Type *EltTy = ConvertType(cast<ComplexType>(Ty)->getElementType());
746  ResultType = llvm::StructType::get(EltTy, EltTy);
747  break;
748  }
749  case Type::LValueReference:
750  case Type::RValueReference: {
751  const ReferenceType *RTy = cast<ReferenceType>(Ty);
752  QualType ETy = RTy->getPointeeType();
753  unsigned AS = getTargetAddressSpace(ETy);
754  ResultType = llvm::PointerType::get(getLLVMContext(), AS);
755 
756  break;
757  }
758  case Type::Pointer: {
759  const PointerType *PTy = cast<PointerType>(Ty);
760  QualType ETy = PTy->getPointeeType();
761 
762  if (CGM.getTriple().isSPIRV() || CGM.getTriple().isSPIR()) {
763  const Type *ClangETy = ETy.getTypePtrOrNull();
764  if (ClangETy && ClangETy->isStructureOrClassType()) {
765  RecordDecl *RD = ClangETy->getAsCXXRecordDecl();
766  if (RD && RD->getQualifiedNameAsString() ==
767  "__spv::__spirv_JointMatrixINTEL") {
768  ResultType = ConvertSYCLJointMatrixINTELType(RD);
769  break;
770  } else if (RD && RD->getQualifiedNameAsString() ==
771  "__spv::__spirv_CooperativeMatrixKHR") {
772  ResultType = ConvertSPVCooperativeMatrixType(RD);
773  break;
774  } else if (RD && RD->getQualifiedNameAsString() ==
775  "__spv::__spirv_TaskSequenceINTEL") {
776  ResultType = llvm::TargetExtType::get(getLLVMContext(),
777  "spirv.TaskSequenceINTEL");
778  break;
779  }
780  }
781  }
782 
783  unsigned AS = getTargetAddressSpace(ETy);
784  ResultType = llvm::PointerType::get(getLLVMContext(), AS);
785 
786  break;
787  }
788 
789  case Type::VariableArray: {
790  const VariableArrayType *A = cast<VariableArrayType>(Ty);
791  assert(A->getIndexTypeCVRQualifiers() == 0 &&
792  "FIXME: We only handle trivial array types so far!");
793  // VLAs resolve to the innermost element type; this matches
794  // the return of alloca, and there isn't any obviously better choice.
795  ResultType = ConvertTypeForMem(A->getElementType());
796  break;
797  }
798  case Type::IncompleteArray: {
799  const IncompleteArrayType *A = cast<IncompleteArrayType>(Ty);
800  assert(A->getIndexTypeCVRQualifiers() == 0 &&
801  "FIXME: We only handle trivial array types so far!");
802  // int X[] -> [0 x int], unless the element type is not sized. If it is
803  // unsized (e.g. an incomplete struct) just use [0 x i8].
804  ResultType = ConvertTypeForMem(A->getElementType());
805  if (!ResultType->isSized()) {
806  SkippedLayout = true;
807  ResultType = llvm::Type::getInt8Ty(getLLVMContext());
808  }
809  ResultType = llvm::ArrayType::get(ResultType, 0);
810  break;
811  }
812  case Type::ArrayParameter:
813  case Type::ConstantArray: {
814  const ConstantArrayType *A = cast<ConstantArrayType>(Ty);
815  llvm::Type *EltTy = ConvertTypeForMem(A->getElementType());
816 
817  // Lower arrays of undefined struct type to arrays of i8 just to have a
818  // concrete type.
819  if (!EltTy->isSized()) {
820  SkippedLayout = true;
821  EltTy = llvm::Type::getInt8Ty(getLLVMContext());
822  }
823 
824  ResultType = llvm::ArrayType::get(EltTy, A->getZExtSize());
825  break;
826  }
827  case Type::ExtVector:
828  case Type::Vector: {
829  const auto *VT = cast<VectorType>(Ty);
830  // An ext_vector_type of Bool is really a vector of bits.
831  llvm::Type *IRElemTy = VT->isExtVectorBoolType()
832  ? llvm::Type::getInt1Ty(getLLVMContext())
833  : ConvertType(VT->getElementType());
834  ResultType = llvm::FixedVectorType::get(IRElemTy, VT->getNumElements());
835  break;
836  }
837  case Type::ConstantMatrix: {
838  const ConstantMatrixType *MT = cast<ConstantMatrixType>(Ty);
839  ResultType =
840  llvm::FixedVectorType::get(ConvertType(MT->getElementType()),
841  MT->getNumRows() * MT->getNumColumns());
842  break;
843  }
844  case Type::FunctionNoProto:
845  case Type::FunctionProto:
846  ResultType = ConvertFunctionTypeInternal(T);
847  break;
848  case Type::ObjCObject:
849  ResultType = ConvertType(cast<ObjCObjectType>(Ty)->getBaseType());
850  break;
851 
852  case Type::ObjCInterface: {
853  // Objective-C interfaces are always opaque (outside of the
854  // runtime, which can do whatever it likes); we never refine
855  // these.
856  llvm::Type *&T = InterfaceTypes[cast<ObjCInterfaceType>(Ty)];
857  if (!T)
859  ResultType = T;
860  break;
861  }
862 
863  case Type::ObjCObjectPointer: {
864  ResultType = llvm::PointerType::getUnqual(getLLVMContext());
865  break;
866  }
867 
868  case Type::Enum: {
869  const EnumDecl *ED = cast<EnumType>(Ty)->getDecl();
870  if (ED->isCompleteDefinition() || ED->isFixed())
871  return ConvertType(ED->getIntegerType());
872  // Return a placeholder 'i32' type. This can be changed later when the
873  // type is defined (see UpdateCompletedType), but is likely to be the
874  // "right" answer.
875  ResultType = llvm::Type::getInt32Ty(getLLVMContext());
876  break;
877  }
878 
879  case Type::BlockPointer: {
880  const QualType FTy = cast<BlockPointerType>(Ty)->getPointeeType();
881  // Block pointers lower to function type. For function type,
882  // getTargetAddressSpace() returns default address space for
883  // function pointer i.e. program address space. Therefore, for block
884  // pointers, it is important to pass the pointee AST address space when
885  // calling getTargetAddressSpace(), to ensure that we get the LLVM IR
886  // address space for data pointers and not function pointers.
887  unsigned AS = Context.getTargetAddressSpace(FTy.getAddressSpace());
888  ResultType = llvm::PointerType::get(getLLVMContext(), AS);
889  break;
890  }
891 
892  case Type::MemberPointer: {
893  auto *MPTy = cast<MemberPointerType>(Ty);
894  if (!getCXXABI().isMemberPointerConvertible(MPTy)) {
895  auto *C = MPTy->getClass();
896  auto Insertion = RecordsWithOpaqueMemberPointers.insert({C, nullptr});
897  if (Insertion.second)
898  Insertion.first->second = llvm::StructType::create(getLLVMContext());
899  ResultType = Insertion.first->second;
900  } else {
901  ResultType = getCXXABI().ConvertMemberPointerType(MPTy);
902  }
903  break;
904  }
905 
906  case Type::Atomic: {
907  QualType valueType = cast<AtomicType>(Ty)->getValueType();
908  ResultType = ConvertTypeForMem(valueType);
909 
910  // Pad out to the inflated size if necessary.
911  uint64_t valueSize = Context.getTypeSize(valueType);
912  uint64_t atomicSize = Context.getTypeSize(Ty);
913  if (valueSize != atomicSize) {
914  assert(valueSize < atomicSize);
915  llvm::Type *elts[] = {
916  ResultType,
917  llvm::ArrayType::get(CGM.Int8Ty, (atomicSize - valueSize) / 8)
918  };
919  ResultType =
920  llvm::StructType::get(getLLVMContext(), llvm::ArrayRef(elts));
921  }
922  break;
923  }
924  case Type::Pipe: {
925  ResultType = CGM.getOpenCLRuntime().getPipeType(cast<PipeType>(Ty));
926  break;
927  }
928  case Type::BitInt: {
929  const auto &EIT = cast<BitIntType>(Ty);
930  ResultType = llvm::Type::getIntNTy(getLLVMContext(), EIT->getNumBits());
931  break;
932  }
933  }
934 
935  assert(ResultType && "Didn't convert a type?");
936  assert((!CachedType || CachedType == ResultType) &&
937  "Cached type doesn't match computed type");
938  TypeCache[Ty] = ResultType;
939  return ResultType;
940 }
941 
943  return isPaddedAtomicType(type->castAs<AtomicType>());
944 }
945 
947  return Context.getTypeSize(type) != Context.getTypeSize(type->getValueType());
948 }
949 
950 /// ConvertRecordDeclType - Lay out a tagged decl type like struct or union.
951 llvm::StructType *CodeGenTypes::ConvertRecordDeclType(const RecordDecl *RD) {
952  // TagDecl's are not necessarily unique, instead use the (clang)
953  // type connected to the decl.
954  const Type *Key = Context.getTagDeclType(RD).getTypePtr();
955 
956  llvm::StructType *&Entry = RecordDeclTypes[Key];
957 
958  // If we don't have a StructType at all yet, create the forward declaration.
959  if (!Entry) {
961  addRecordTypeName(RD, Entry, "");
962  if (RD->hasAttr<SYCLUsesAspectsAttr>())
963  CGM.addTypeWithAspects(Entry->getName(), RD);
964  }
965  llvm::StructType *Ty = Entry;
966 
967  // If this is still a forward declaration, or the LLVM type is already
968  // complete, there's nothing more to do.
969  RD = RD->getDefinition();
970  if (!RD || !RD->isCompleteDefinition() || !Ty->isOpaque())
971  return Ty;
972 
973  // Force conversion of non-virtual base classes recursively.
974  if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(RD)) {
975  for (const auto &I : CRD->bases()) {
976  if (I.isVirtual()) continue;
977  ConvertRecordDeclType(I.getType()->castAs<RecordType>()->getDecl());
978  }
979  }
980 
981  // Layout fields.
982  std::unique_ptr<CGRecordLayout> Layout = ComputeRecordLayout(RD, Ty);
983  CGRecordLayouts[Key] = std::move(Layout);
984 
985  // If this struct blocked a FunctionType conversion, then recompute whatever
986  // was derived from that.
987  // FIXME: This is hugely overconservative.
988  if (SkippedLayout)
989  TypeCache.clear();
990 
991  return Ty;
992 }
993 
994 /// getCGRecordLayout - Return record layout info for the given record decl.
995 const CGRecordLayout &
997  const Type *Key = Context.getTagDeclType(RD).getTypePtr();
998 
999  auto I = CGRecordLayouts.find(Key);
1000  if (I != CGRecordLayouts.end())
1001  return *I->second;
1002  // Compute the type information.
1004 
1005  // Now try again.
1006  I = CGRecordLayouts.find(Key);
1007 
1008  assert(I != CGRecordLayouts.end() &&
1009  "Unable to find record layout information for type");
1010  return *I->second;
1011 }
1012 
1014  assert((T->isAnyPointerType() || T->isBlockPointerType()) && "Invalid type");
1015  return isZeroInitializable(T);
1016 }
1017 
1019  if (T->getAs<PointerType>())
1020  return Context.getTargetNullPointerValue(T) == 0;
1021 
1022  if (const auto *AT = Context.getAsArrayType(T)) {
1023  if (isa<IncompleteArrayType>(AT))
1024  return true;
1025  if (const auto *CAT = dyn_cast<ConstantArrayType>(AT))
1026  if (Context.getConstantArrayElementCount(CAT) == 0)
1027  return true;
1028  T = Context.getBaseElementType(T);
1029  }
1030 
1031  // Records are non-zero-initializable if they contain any
1032  // non-zero-initializable subobjects.
1033  if (const RecordType *RT = T->getAs<RecordType>()) {
1034  const RecordDecl *RD = RT->getDecl();
1035  return isZeroInitializable(RD);
1036  }
1037 
1038  // We have to ask the ABI about member pointers.
1039  if (const MemberPointerType *MPT = T->getAs<MemberPointerType>())
1040  return getCXXABI().isZeroInitializable(MPT);
1041 
1042  // Everything else is okay.
1043  return true;
1044 }
1045 
1048 }
1049 
1051  // Return the address space for the type. If the type is a
1052  // function type without an address space qualifier, the
1053  // program address space is used. Otherwise, the target picks
1054  // the best address space based on the type information
1055  return T->isFunctionType() && !T.hasAddressSpace()
1056  ? getDataLayout().getProgramAddressSpace()
1057  : getContext().getTargetAddressSpace(T.getAddressSpace());
1058 }
Defines the clang::ASTContext interface.
Expr * E
static llvm::Type * getTypeForFormat(llvm::LLVMContext &VMContext, const llvm::fltSemantics &format, bool UseNativeHalf=false)
llvm::Type * getCooperativeMatrixKHRExtType(llvm::Type *CompTy, ArrayRef< TemplateArgument > TemplateArgs)
llvm::Type * getJointMatrixINTELExtType(llvm::Type *CompTy, ArrayRef< TemplateArgument > TemplateArgs, const unsigned Val=0)
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1171
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
llvm::MachO::Target Target
Definition: MachO.h:51
llvm::MachO::Record Record
Definition: MachO.h:31
static CharUnits getTypeAllocSize(CodeGenModule &CGM, llvm::Type *type)
BuiltinVectorTypeInfo getBuiltinVectorTypeInfo(const BuiltinType *VecTy) const
Returns the element type, element count and number of vectors (in case of tuple) for a builtin vector...
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:713
const llvm::fltSemantics & getFloatTypeSemantics(QualType T) const
Return the APFloat 'semantics' for the specified scalar floating point type.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
QualType getRecordType(const RecordDecl *Decl) const
uint64_t getTargetNullPointerValue(QualType QT) const
Get target-dependent integer value for null pointer which is used for constant folding.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2633
const LangOptions & getLangOpts() const
Definition: ASTContext.h:797
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2399
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:779
uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const
Return number of constant array elements.
unsigned getTargetAddressSpace(LangAS AS) const
QualType getElementType() const
Definition: Type.h:3588
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:3598
Attr - This represents one attribute.
Definition: Attr.h:46
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Represents a canonical, potentially-qualified type.
Definition: CanonicalType.h:65
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
Definition: CanonicalType.h:83
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:185
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition: CharUnits.h:63
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
virtual bool isMemberPointerConvertible(const MemberPointerType *MPT) const
Return whether or not a member pointers type is convertible to an IR type.
Definition: CGCXXABI.h:213
virtual llvm::Type * ConvertMemberPointerType(const MemberPointerType *MPT)
Find the LLVM type used to represent the given member pointer type.
Definition: CGCXXABI.cpp:43
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:123
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:58
CGFunctionInfo - Class to encapsulate the information about a function definition.
llvm::Type * convertHLSLSpecificType(const Type *T)
virtual llvm::Type * getPipeType(const PipeType *T, StringRef Name, llvm::Type *&PipeTy)
virtual llvm::Type * convertOpenCLSpecificType(const Type *T)
CGRecordLayout - This class handles struct and union layout info while lowering AST types to LLVM typ...
bool isZeroInitializable() const
Check whether this struct can be C++ zero-initialized with a zeroinitializer.
This class organizes the cross-function state that is used while generating LLVM code.
bool isPaddedAtomicType(QualType type)
void setAspectsEnumDecl(const EnumDecl *ED)
const llvm::Triple & getTriple() const
CGOpenCLRuntime & getOpenCLRuntime()
Return a reference to the configured OpenCL runtime.
CGDebugInfo * getModuleDebugInfo()
CGHLSLRuntime & getHLSLRuntime()
Return a reference to the configured HLSL runtime.
const TargetCodeGenInfo & getTargetCodeGenInfo()
const CodeGenOptions & getCodeGenOpts() const
void addTypeWithAspects(StringRef TypeName, const RecordDecl *RD)
CodeGenTypes(CodeGenModule &cgm)
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
bool isPointerZeroInitializable(QualType T)
Check if the pointer type can be zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
const CodeGenOptions & getCodeGenOpts() const
const CGFunctionInfo & arrangeFreeFunctionType(CanQual< FunctionProtoType > Ty)
Arrange the argument and result information for a value of the given freestanding function type.
Definition: CGCall.cpp:208
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
Definition: CGCall.cpp:1616
bool isFuncTypeConvertible(const FunctionType *FT)
isFuncTypeConvertible - Utility to check whether a function type can be converted to an LLVM type (i....
const llvm::DataLayout & getDataLayout() const
Definition: CodeGenTypes.h:104
std::unique_ptr< CGRecordLayout > ComputeRecordLayout(const RecordDecl *D, llvm::StructType *Ty)
Compute a new LLVM record layout object for the given record.
llvm::Type * convertTypeForLoadStore(QualType T, llvm::Type *LLVMTy=nullptr)
Given that T is a scalar type, return the IR type that should be used for load and store operations.
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
unsigned getTargetAddressSpace(QualType T) const
llvm::StructType * ConvertRecordDeclType(const RecordDecl *TD)
ConvertRecordDeclType - Lay out a tagged decl type like struct or union.
void RefreshTypeCacheForClass(const CXXRecordDecl *RD)
Remove stale types from the type cache when an inheritance model gets assigned to a class.
bool isRecordLayoutComplete(const Type *Ty) const
isRecordLayoutComplete - Return true if the specified type is already completely laid out.
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
void UpdateCompletedType(const TagDecl *TD)
UpdateCompletedType - When we find the full definition for a TagDecl, replace the 'opaque' type we pr...
llvm::Type * ConvertSPVCooperativeMatrixType(RecordDecl *RD)
ConvertSPVCooperativeMatrixType - Convert SYCL joint_matrix type which is represented as a pointer to...
bool typeRequiresSplitIntoByteArray(QualType ASTTy, llvm::Type *LLVMTy=nullptr)
Check whether the given type needs to be laid out in memory using an opaque byte-array type because i...
ASTContext & getContext() const
Definition: CodeGenTypes.h:108
bool isFuncParamTypeConvertible(QualType Ty)
isFuncParamTypeConvertible - Return true if the specified type in a function parameter or result posi...
llvm::Type * ConvertSYCLJointMatrixINTELType(RecordDecl *RD)
ConvertSYCLJointMatrixINTELType - Convert SYCL joint_matrix type which is represented as a pointer to...
bool isZeroInitializable(QualType T)
IsZeroInitializable - Return whether a type can be zero-initialized (in the C++ sense) with an LLVM z...
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...
CGCXXABI & getCXXABI() const
Definition: CodeGenTypes.h:111
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenTypes.h:112
virtual llvm::Type * getCUDADeviceBuiltinSurfaceDeviceType() const
Return the device-side type for the CUDA device builtin surface type.
Definition: TargetInfo.h:385
virtual llvm::Type * getCUDADeviceBuiltinTextureDeviceType() const
Return the device-side type for the CUDA device builtin texture type.
Definition: TargetInfo.h:390
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3614
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
Definition: Type.h:3690
Represents a concrete matrix type with constant number of rows and columns.
Definition: Type.h:4229
unsigned getNumColumns() const
Returns the number of columns in the matrix.
Definition: Type.h:4250
unsigned getNumRows() const
Returns the number of rows in the matrix.
Definition: Type.h:4247
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:523
bool hasAttr() const
Definition: DeclBase.h:584
DeclContext * getDeclContext()
Definition: DeclBase.h:455
Represents an enum.
Definition: Decl.h:3845
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition: Decl.h:4059
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:4005
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4678
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5012
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:4318
QualType getReturnType() const
Definition: Type.h:4640
Represents a C array with an unspecified size.
Definition: Type.h:3761
QualType getElementType() const
Returns type of the elements being stored in the matrix.
Definition: Type.h:4207
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3518
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
std::string getQualifiedNameAsString(bool WithGlobalNsPrefix=false) const
Definition: Decl.cpp:1668
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:1676
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3197
QualType getPointeeType() const
Definition: Type.h:3207
A (possibly-)qualified type.
Definition: Type.h:941
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7760
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:7886
bool isCanonical() const
Definition: Type.h:7817
const Type * getTypePtrOrNull() const
Definition: Type.h:7764
Represents a struct/union/class.
Definition: Decl.h:4146
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4337
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5975
RecordDecl * getDecl() const
Definition: Type.h:5985
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3438
QualType getPointeeType() const
Definition: Type.h:3456
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3562
StringRef getKindName() const
Definition: Decl.h:3753
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3665
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition: Decl.cpp:4806
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3790
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Definition: Decl.h:3716
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:992
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:394
The base class of the type hierarchy.
Definition: Type.h:1829
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1882
bool isBlockPointerType() const
Definition: Type.h:8027
bool isConstantMatrixType() const
Definition: Type.h:8147
bool isCUDADeviceBuiltinSurfaceType() const
Check if the type is the CUDA device builtin surface type.
Definition: Type.cpp:5005
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:705
bool isExtVectorBoolType() const
Definition: Type.h:8133
bool isBitIntType() const
Definition: Type.h:8269
bool isCUDADeviceBuiltinTextureType() const
Check if the type is the CUDA device builtin texture type.
Definition: Type.cpp:5012
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2362
bool isFunctionType() const
Definition: Type.h:8009
bool isStructureOrClassType() const
Definition: Type.cpp:657
bool isAnyPointerType() const
Definition: Type.h:8021
TypeClass getTypeClass() const
Definition: Type.h:2334
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8568
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3410
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3805
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
unsigned long uint64_t
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
unsigned SuppressInlineNamespace
Suppress printing parts of scope specifiers that correspond to inline namespaces, where the name is u...