Skip to content

Commit

Permalink
Add attribute conversion lowering to EmitC
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaAMD committed Dec 20, 2024
1 parent 5084ab1 commit 87fe125
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 8 additions & 2 deletions mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ class ArithConstantOpConversionPattern
Type newTy = this->getTypeConverter()->convertType(arithConst.getType());
if (!newTy)
return rewriter.notifyMatchFailure(arithConst, "type conversion failed");
rewriter.replaceOpWithNewOp<emitc::ConstantOp>(arithConst, newTy,
adaptor.getValue());

auto newValueAttr =
getTypeConverter()->convertTypeAttribute(newTy, adaptor.getValueAttr());

rewriter.replaceOpWithNewOp<emitc::ConstantOp>(
arithConst, newTy,
newValueAttr.has_value() ? newValueAttr.value() : adaptor.getValue());

return success();
}
};
Expand Down
9 changes: 7 additions & 2 deletions mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,14 @@ struct ConvertGlobal final : public OpConversionPattern<memref::GlobalOp> {
if (isa_and_present<UnitAttr>(initialValue))
initialValue = {};

auto convertedInitialValue =
getTypeConverter()->convertTypeAttribute(resultTy, initialValue);

rewriter.replaceOpWithNewOp<emitc::GlobalOp>(
op, operands.getSymName(), resultTy, initialValue, externSpecifier,
staticSpecifier, operands.getConstant());
op, operands.getSymName(), resultTy,
convertedInitialValue.has_value() ? convertedInitialValue.value()
: initialValue,
externSpecifier, staticSpecifier, operands.getConstant());
return success();
}
};
Expand Down

0 comments on commit 87fe125

Please sign in to comment.