clang: lib/CIR/CodeGen/CIRGenTypes.cpp Source File (original) (raw)
2
4
8
9#include
10
11using namespace clang;
13
15 : cgm(genModule), astContext(genModule.getASTContext()),
16 builder(cgm.getBuilder()) {}
17
19
21 return *builder.getContext();
22}
23
24
25
26
27
29
30
32
33
36 return true;
37
38
39 return ->isIncompleteType();
40}
41
42
43
44
45
46
49 return false;
50
51 if (const auto *fpt = dyn_cast(ft))
52 for (unsigned i = 0, e = fpt->getNumParams(); i != e; i++)
54 return false;
55
56 return true;
57}
58
59mlir::Type CIRGenTypes::ConvertFunctionTypeInternal(QualType qft) {
62
63
64
67 qft);
69 }
70
71
72
73
74
75 if (const auto *fpt = dyn_cast(ft)) {
77 for (unsigned i = 0; i < fpt->getNumParams(); ++i) {
78 mlirParamTypes.push_back(convertType(fpt->getParamType(i)));
79 }
80 return cir::FuncType::get(
81 mlirParamTypes, convertType(fpt->getReturnType().getUnqualifiedType()),
82 fpt->isVariadic());
83 }
86}
87
90 const Type *ty = type.getTypePtr();
91
92
93 TypeCacheTy::iterator tci = typeCache.find(ty);
95 return tci->second;
96
97
98
99
100 mlir::Type resultType = nullptr;
102 case Type::Builtin: {
103 switch (cast(ty)->getKind()) {
104
105
106 case BuiltinType::Void:
107 resultType = cgm.VoidTy;
108 break;
109
110
111 case BuiltinType::Char_S:
112 case BuiltinType::Int:
113 case BuiltinType::Int128:
114 case BuiltinType::Long:
115 case BuiltinType::LongLong:
116 case BuiltinType::SChar:
117 case BuiltinType::Short:
118 case BuiltinType::WChar_S:
119 resultType =
121 true);
122 break;
123
124 case BuiltinType::Char8:
125 case BuiltinType::Char16:
126 case BuiltinType::Char32:
127 case BuiltinType::Char_U:
128 case BuiltinType::UChar:
129 case BuiltinType::UInt:
130 case BuiltinType::UInt128:
131 case BuiltinType::ULong:
132 case BuiltinType::ULongLong:
133 case BuiltinType::UShort:
134 case BuiltinType::WChar_U:
135 resultType =
137 false);
138 break;
139
140
141 case BuiltinType::Float16:
142 resultType = cgm.FP16Ty;
143 break;
144 case BuiltinType::Half:
145 if (astContext.getLangOpts().NativeHalfType ||
147 resultType = cgm.FP16Ty;
148 } else {
151 }
152 break;
153 case BuiltinType::BFloat16:
155 break;
156 case BuiltinType::Float:
158 &llvm::APFloat::IEEEsingle() &&
159 "ClangIR NYI: 'float' in a format other than IEEE 32-bit");
160 resultType = cgm.FloatTy;
161 break;
162 case BuiltinType::Double:
164 &llvm::APFloat::IEEEdouble() &&
165 "ClangIR NYI: 'double' in a format other than IEEE 64-bit");
167 break;
168 case BuiltinType::LongDouble:
169 resultType =
171 break;
172 case BuiltinType::Float128:
173 resultType = cgm.FP128Ty;
174 break;
175 case BuiltinType::Ibm128:
178 break;
179
180 default:
183 break;
184 }
185 break;
186 }
187
188 case Type::Pointer: {
189 const PointerType *ptrTy = cast(ty);
192
193 mlir::Type pointeeType = convertType(elemTy);
194
195 resultType = builder.getPointerTo(pointeeType);
196 break;
197 }
198
199 case Type::FunctionNoProto:
200 case Type::FunctionProto:
201 resultType = ConvertFunctionTypeInternal(type);
202 break;
203
204 case Type::BitInt: {
205 const auto *bitIntTy = cast(type);
206 if (bitIntTy->getNumBits() > cir::IntType::maxBitwidth()) {
209 } else {
210 resultType = cir::IntType::get(&getMLIRContext(), bitIntTy->getNumBits(),
211 bitIntTy->isSigned());
212 }
213 break;
214 }
215
216 default:
219 break;
220 }
221
222 assert(resultType && "Type conversion not yet implemented");
223
225 return resultType;
226}
Defines the clang::ASTContext interface.
static Decl::Kind getKind(const Decl *D)
C Language Family Type Representation.
cir::PointerType getPointerTo(mlir::Type ty)
const llvm::fltSemantics & getFloatTypeSemantics(QualType T) const
Return the APFloat 'semantics' for the specified scalar floating point type.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
const LangOptions & getLangOpts() const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
const TargetInfo & getTargetInfo() const
cir::LongDoubleType getLongDoubleTy(const llvm::fltSemantics &format) const
This class organizes the cross-function state that is used while generating CIR code.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
bool isFuncTypeConvertible(const clang::FunctionType *ft)
Utility to check whether a function type can be converted to a CIR type (i.e.
CIRGenTypes(CIRGenModule &cgm)
mlir::MLIRContext & getMLIRContext() const
bool isFuncParamTypeConvertible(clang::QualType type)
Return true if the specified type in a function parameter or result position can be converted to a CI...
mlir::Type convertType(clang::QualType type)
Convert a Clang type into a mlir::Type.
FunctionType - C99 6.7.5.3 - Function Declarators.
QualType getReturnType() const
A pointer to member type per C++ 8.3.3 - Pointers to members.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Encodes a location in the source.
virtual bool useFP16ConversionIntrinsics() const
Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used to convert to and from __fp...
The base class of the type hierarchy.
bool isConstantMatrixType() const
TypeClass getTypeClass() const
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< TagType > tagType
Matches tag types (record and enum types).
The JSON file list parser is used to communicate input to InstallAPI.