@@ -42,6 +42,21 @@ struct ConvertCIRToMLIRPass
4242 StringRef getArgument () const override { return " cir-to-mlir" ; }
4343};
4444
45+ // / Given a type convertor and a data layout, convert the given type to a type
46+ // / that is suitable for memory operations. For example, this can be used to
47+ // / lower cir.bool accesses to i8.
48+ static mlir::Type convertTypeForMemory (const mlir::TypeConverter &converter,
49+ mlir::Type type) {
50+ // TODO(cir): Handle other types similarly to clang's codegen
51+ // convertTypeForMemory
52+ if (isa<cir::BoolType>(type)) {
53+ // TODO: Use datalayout to get the size of bool
54+ return mlir::IntegerType::get (type.getContext (), 8 );
55+ }
56+
57+ return converter.convertType (type);
58+ }
59+
4560class CIRGlobalOpLowering : public mlir ::OpConversionPattern<cir::GlobalOp> {
4661public:
4762 using OpConversionPattern<cir::GlobalOp>::OpConversionPattern;
@@ -55,8 +70,8 @@ class CIRGlobalOpLowering : public mlir::OpConversionPattern<cir::GlobalOp> {
5570 mlir::OpBuilder b (moduleOp.getContext ());
5671
5772 const mlir::Type cirSymType = op.getSymType ();
58- assert (! cir::MissingFeatures::convertTypeForMemory ());
59- mlir::Type convertedType = getTypeConverter ()-> convertType ( cirSymType);
73+ mlir::Type convertedType =
74+ convertTypeForMemory (* getTypeConverter (), cirSymType);
6075 if (!convertedType)
6176 return mlir::failure ();
6277 auto memrefType = dyn_cast<mlir::MemRefType>(convertedType);
@@ -87,7 +102,7 @@ class CIRGlobalOpLowering : public mlir::OpConversionPattern<cir::GlobalOp> {
87102 }
88103
89104 // Add symbol visibility
90- assert (!cir::MissingFeatures::opGlobalLinkage ());
105+ assert (!cir::MissingFeatures::opGlobalMlirLinkage ());
91106 std::string symVisibility = " public" ;
92107
93108 assert (!cir::MissingFeatures::opGlobalConstant ());
@@ -112,8 +127,7 @@ void populateCIRToMLIRConversionPatterns(mlir::RewritePatternSet &patterns,
112127static mlir::TypeConverter prepareTypeConverter () {
113128 mlir::TypeConverter converter;
114129 converter.addConversion ([&](cir::PointerType type) -> mlir::Type {
115- assert (!cir::MissingFeatures::convertTypeForMemory ());
116- mlir::Type ty = converter.convertType (type.getPointee ());
130+ mlir::Type ty = convertTypeForMemory (converter, type.getPointee ());
117131 // FIXME: The pointee type might not be converted (e.g. struct)
118132 if (!ty)
119133 return nullptr ;
0 commit comments