1 //===--- CIRGenTypes.h - Type translation for CIR CodeGen -------*- C++ -*-===// 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 -> CIR type lowering. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENTYPES_H 14 #define LLVM_CLANG_LIB_CODEGEN_CODEGENTYPES_H 15 16 #include "clang/CIR/Dialect/IR/CIRTypes.h" 17 18 #include "llvm/ADT/SmallPtrSet.h" 19 20 namespace clang { 21 class ASTContext; 22 class FunctionType; 23 class QualType; 24 class Type; 25 } // namespace clang 26 27 namespace mlir { 28 class Type; 29 } 30 31 namespace clang::CIRGen { 32 33 class CIRGenBuilderTy; 34 class CIRGenModule; 35 36 /// This class organizes the cross-module state that is used while lowering 37 /// AST types to CIR types. 38 class CIRGenTypes { 39 CIRGenModule &cgm; 40 clang::ASTContext &astContext; 41 CIRGenBuilderTy &builder; 42 43 /// Heper for ConvertType. 44 mlir::Type ConvertFunctionTypeInternal(clang::QualType ft); 45 46 public: 47 CIRGenTypes(CIRGenModule &cgm); 48 ~CIRGenTypes(); 49 50 /// Utility to check whether a function type can be converted to a CIR type 51 /// (i.e. doesn't depend on an incomplete tag type). 52 bool isFuncTypeConvertible(const clang::FunctionType *ft); 53 bool isFuncParamTypeConvertible(clang::QualType type); 54 55 /// This map of clang::Type to mlir::Type (which includes CIR type) is a 56 /// cache of types that have already been processed. 57 using TypeCacheTy = llvm::DenseMap<const clang::Type *, mlir::Type>; 58 TypeCacheTy typeCache; 59 60 mlir::MLIRContext &getMLIRContext() const; 61 62 /// Convert a Clang type into a mlir::Type. 63 mlir::Type convertType(clang::QualType type); 64 }; 65 66 } // namespace clang::CIRGen 67 68 #endif 69