Skip to content

Commit db08afe

Browse files
authored
Add attribute conversion lowering to EmitC (#431)
1 parent 3787844 commit db08afe

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ class ArithConstantOpConversionPattern
3939
Type newTy = this->getTypeConverter()->convertType(arithConst.getType());
4040
if (!newTy)
4141
return rewriter.notifyMatchFailure(arithConst, "type conversion failed");
42-
rewriter.replaceOpWithNewOp<emitc::ConstantOp>(arithConst, newTy,
43-
adaptor.getValue());
42+
43+
auto newValueAttr =
44+
getTypeConverter()->convertTypeAttribute(newTy, adaptor.getValueAttr());
45+
46+
rewriter.replaceOpWithNewOp<emitc::ConstantOp>(
47+
arithConst, newTy,
48+
newValueAttr.has_value() ? newValueAttr.value() : adaptor.getValue());
49+
4450
return success();
4551
}
4652
};

mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,14 @@ struct ConvertGlobal final : public OpConversionPattern<memref::GlobalOp> {
9292
if (isa_and_present<UnitAttr>(initialValue))
9393
initialValue = {};
9494

95+
auto convertedInitialValue =
96+
getTypeConverter()->convertTypeAttribute(resultTy, initialValue);
97+
9598
rewriter.replaceOpWithNewOp<emitc::GlobalOp>(
96-
op, operands.getSymName(), resultTy, initialValue, externSpecifier,
97-
staticSpecifier, operands.getConstant());
99+
op, operands.getSymName(), resultTy,
100+
convertedInitialValue.has_value() ? convertedInitialValue.value()
101+
: initialValue,
102+
externSpecifier, staticSpecifier, operands.getConstant());
98103
return success();
99104
}
100105
};

0 commit comments

Comments
 (0)