@@ -42,6 +42,21 @@ struct ConvertCIRToMLIRPass
42
42
StringRef getArgument () const override { return " cir-to-mlir" ; }
43
43
};
44
44
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
+
45
60
class CIRGlobalOpLowering : public mlir ::OpConversionPattern<cir::GlobalOp> {
46
61
public:
47
62
using OpConversionPattern<cir::GlobalOp>::OpConversionPattern;
@@ -55,8 +70,8 @@ class CIRGlobalOpLowering : public mlir::OpConversionPattern<cir::GlobalOp> {
55
70
mlir::OpBuilder b (moduleOp.getContext ());
56
71
57
72
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);
60
75
if (!convertedType)
61
76
return mlir::failure ();
62
77
auto memrefType = dyn_cast<mlir::MemRefType>(convertedType);
@@ -87,7 +102,7 @@ class CIRGlobalOpLowering : public mlir::OpConversionPattern<cir::GlobalOp> {
87
102
}
88
103
89
104
// Add symbol visibility
90
- assert (!cir::MissingFeatures::opGlobalLinkage ());
105
+ assert (!cir::MissingFeatures::opGlobalMlirLinkage ());
91
106
std::string symVisibility = " public" ;
92
107
93
108
assert (!cir::MissingFeatures::opGlobalConstant ());
@@ -112,8 +127,7 @@ void populateCIRToMLIRConversionPatterns(mlir::RewritePatternSet &patterns,
112
127
static mlir::TypeConverter prepareTypeConverter () {
113
128
mlir::TypeConverter converter;
114
129
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 ());
117
131
// FIXME: The pointee type might not be converted (e.g. struct)
118
132
if (!ty)
119
133
return nullptr ;
0 commit comments