Hi Mehdi,
Thanks for replying.
When having the error, I was trying to replace that myToy::Traverse with two other operations, using codes below.
I was declaring two passes here to replace the myToy::Traverse with myToy::Rep1 and myToy::Rep2.
Does it look like there’s something wrong in the replacement?
void ConversionNo1Pass::runOnOperation() {
RewritePatternSet patterns(&getContext());
patterns.add<TraverseOpLowering>(patterns.getContext());
ConversionTarget target(getContext());
target.addIllegalOp<mlir::myToy::Traverse>();
target.markUnknownOpDynamicallyLegal([](Operation *){return true; });
if (failed(
applyPartialConversion(getOperation(), target, std::move(patterns))))
signalPassFailure();
}
Here the Rep1 and Rep2 operations are supposed to replace the Traverse one:
void ConversionNo2Pass::runOnOperation() {
RewritePatternSet patterns(&getContext());
patterns.add<Rep1OpLowering, Rep2OpLowering,Test01OpLowering, Test02OpLowering, Test03OpLowering>(patterns.getContext());
ConversionTarget target(getContext());
target.addIllegalOp<mlir::myToy::Rep1Op, mlir::myToy::Rep2Op, mlir::myToy::Test01Op, mlir::myToy::Test02Op, mlir::myToy::Test03Op>();
target.markUnknownOpDynamicallyLegal([](Operation *){return true; });
if (failed(
applyPartialConversion(getOperation(), target, std::move(patterns))))
signalPassFailure();
}
At the end of TraverseLowering, I had let it create the Rep1 and Rep2 operations:
auto rep1 = rewriter.create<myToy::Rep1Op>(loc, rep1_dict, ValueRange{});
auto rep2 = rewriter.create<myToy::Rep2Op>(loc, rep2_dict, ValueRange{});
rewriter.eraseOp(traverseOp);
return success();
}
};
With some inspection, I found that the “Failed to legalize…” error was produced at following step:
mlir::PassManager pm(module.get()->getName());
if (mlir::failed(mlir::applyPassManagerCLOptions(pm)))
return 4;
pm.addPass(mlir::myToy::createConversionPass());
if (mlir::failed(pm.run(*module)))
return 4;
However my program eventually produced segment fault and stopped at the pm.run(*module) step here:
mlir::PassManager pm(module.get()->getName());
if (mlir::failed(mlir::applyPassManagerCLOptions(pm)))
return FAIL;
pm.addPass(mlir::myToy::createConversionNo2ConversionPass());
pm.addPass(mlir::myToy::createLowerToStdPass());
pm.addNestedPass<mlir::LLVM::LLVMFuncOp>(mlir::LLVM::createDIScopeForLLVMFuncOpPass());
if (mlir::failed(pm.run(*module)))
return FAIL;