[clang] [CIR] Infrastructure: class CIRGenBuilderTy; cache CIR types (PR #119037)
David Olsen via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 6 14:36:17 PST 2024
================
@@ -9,22 +9,32 @@ using namespace clang;
using namespace clang::CIRGen;
CIRGenTypes::CIRGenTypes(CIRGenModule &genModule)
- : cgm(genModule), context(genModule.getASTContext()) {}
+ : cgm(genModule), context(genModule.getASTContext()),
+ builder(cgm.getBuilder()) {}
CIRGenTypes::~CIRGenTypes() {}
+mlir::MLIRContext &CIRGenTypes::getMLIRContext() const {
+ return *builder.getContext();
+}
+
mlir::Type CIRGenTypes::convertType(QualType type) {
type = context.getCanonicalType(type);
const Type *ty = type.getTypePtr();
+ // Has the type already been processed?
+ TypeCacheTy::iterator tci = typeCache.find(ty);
+ if (tci != typeCache.end())
+ return tci->second;
+
// For types that haven't been implemented yet or are otherwise unsupported,
// report an error and return 'int'.
mlir::Type resultType = nullptr;
switch (ty->getTypeClass()) {
case Type::Builtin: {
switch (cast<BuiltinType>(ty)->getKind()) {
- // Signed types.
+ // Signed integral types.
----------------
dkolsen-pgi wrote:
I thought about it briefly, but decided that the code complexity was not worth the benefit. The `typeCache` being added in this commit means each `cir::IntType` will be duplicated only once or twice, not lots of times. So the benefits of using `cgm.SInt*` are minimal.
https://github.com/llvm/llvm-project/pull/119037
More information about the cfe-commits
mailing list