clang 20.0.0git
CIRGenTypes.cpp
Go to the documentation of this file.
1#include "CIRGenTypes.h"
2
3#include "CIRGenModule.h"
4
6#include "clang/AST/Type.h"
7
8using namespace clang;
9using namespace clang::CIRGen;
10
12 : cgm(genModule), astContext(genModule.getASTContext()),
13 builder(cgm.getBuilder()) {}
14
16
17mlir::MLIRContext &CIRGenTypes::getMLIRContext() const {
18 return *builder.getContext();
19}
20
22 type = astContext.getCanonicalType(type);
23 const Type *ty = type.getTypePtr();
24
25 // Has the type already been processed?
26 TypeCacheTy::iterator tci = typeCache.find(ty);
27 if (tci != typeCache.end())
28 return tci->second;
29
30 // For types that haven't been implemented yet or are otherwise unsupported,
31 // report an error and return 'int'.
32
33 mlir::Type resultType = nullptr;
34 switch (ty->getTypeClass()) {
35 case Type::Builtin: {
36 switch (cast<BuiltinType>(ty)->getKind()) {
37 // Signed integral types.
38 case BuiltinType::Char_S:
39 case BuiltinType::Int:
40 case BuiltinType::Int128:
41 case BuiltinType::Long:
42 case BuiltinType::LongLong:
43 case BuiltinType::SChar:
44 case BuiltinType::Short:
45 case BuiltinType::WChar_S:
46 resultType =
47 cir::IntType::get(&getMLIRContext(), astContext.getTypeSize(ty),
48 /*isSigned=*/true);
49 break;
50 // Unsigned integral types.
51 case BuiltinType::Char8:
52 case BuiltinType::Char16:
53 case BuiltinType::Char32:
54 case BuiltinType::Char_U:
55 case BuiltinType::UChar:
56 case BuiltinType::UInt:
57 case BuiltinType::UInt128:
58 case BuiltinType::ULong:
59 case BuiltinType::ULongLong:
60 case BuiltinType::UShort:
61 case BuiltinType::WChar_U:
62 resultType =
63 cir::IntType::get(&getMLIRContext(), astContext.getTypeSize(ty),
64 /*isSigned=*/false);
65 break;
66 default:
67 cgm.errorNYI(SourceLocation(), "processing of built-in type", type);
68 resultType = cgm.SInt32Ty;
69 break;
70 }
71 break;
72 }
73 case Type::BitInt: {
74 const auto *bitIntTy = cast<BitIntType>(type);
75 if (bitIntTy->getNumBits() > cir::IntType::maxBitwidth()) {
76 cgm.errorNYI(SourceLocation(), "large _BitInt type", type);
77 resultType = cgm.SInt32Ty;
78 } else {
79 resultType = cir::IntType::get(&getMLIRContext(), bitIntTy->getNumBits(),
80 bitIntTy->isSigned());
81 }
82 break;
83 }
84 default:
85 cgm.errorNYI(SourceLocation(), "processing of type", type);
86 resultType = cgm.SInt32Ty;
87 break;
88 }
89
90 assert(resultType && "Type conversion not yet implemented");
91
92 typeCache[ty] = resultType;
93 return resultType;
94}
Defines the clang::ASTContext interface.
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1172
C Language Family Type Representation.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2716
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2482
This class organizes the cross-function state that is used while generating CIR code.
Definition: CIRGenModule.h:39
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
CIRGenTypes(CIRGenModule &cgm)
Definition: CIRGenTypes.cpp:11
mlir::MLIRContext & getMLIRContext() const
Definition: CIRGenTypes.cpp:17
mlir::Type convertType(clang::QualType type)
Convert a Clang type into a mlir::Type.
Definition: CIRGenTypes.cpp:21
A (possibly-)qualified type.
Definition: Type.h:929
Encodes a location in the source.
The base class of the type hierarchy.
Definition: Type.h:1828
TypeClass getTypeClass() const
Definition: Type.h:2341
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
The JSON file list parser is used to communicate input to InstallAPI.