[Mlir-commits] [mlir] [mlir][spirv][cf] legalize block arguments when convert cf to spirv (PR #71288)
Jakub Kuderski
llvmlistbot at llvm.org
Sat Nov 4 16:02:40 PDT 2023
================
@@ -28,20 +28,23 @@
using namespace mlir;
-/// Checks that the target block arguments are legal.
-static LogicalResult checkBlockArguments(Block &block, Operation *op,
- PatternRewriter &rewriter,
- const TypeConverter &converter) {
- for (BlockArgument arg : block.getArguments()) {
- if (!converter.isLegal(arg.getType())) {
- return rewriter.notifyMatchFailure(
- op,
- llvm::formatv(
- "failed to match, destination argument not legalized (found {0})",
- arg));
- }
+/// Legailze target block arguments.
+static void legalizeBlockArguments(Block &block,
+ const TypeConverter &converter) {
+ auto builder = OpBuilder::atBlockBegin(&block);
+ for (unsigned i = 0; i < block.getNumArguments(); ++i) {
+ const auto arg = block.getArgument(i);
+ if (converter.isLegal(arg.getType()))
+ continue;
+ unsigned argNum = arg.getArgNumber();
+ Location loc = arg.getLoc();
+ Type ty = arg.getType();
+ Type newTy = converter.convertType(ty);
+ Value newArg = block.insertArgument(argNum, newTy, loc);
+ auto cast = builder.create<UnrealizedConversionCastOp>(loc, ty, newArg);
----------------
kuhar wrote:
Shouldn't we use something that relies on the 'source materialization' registered in the type converter? (`materializeSourceConversion`?)
https://github.com/llvm/llvm-project/pull/71288
More information about the Mlir-commits
mailing list