LLVM Discussion Forums

Lowertollvm crashed in toy

Hello,I’m trying to make python API of toy toturial using boost python. It works well when create createLowerToAffinePass,but it crashed when I add createLowerToLLVMPass.The code is as following:(context is global and I register toy dialect before creating the MLIRContext as I’m been told in other thread I started)

void dumpMLIRLLVM(mlir::ModuleOp module)
{
    mlir::registerPassManagerCLOptions();
    mlir::PassManager pm(&context);
    // Apply any generic pass manager command line options and run the pipeline.
    applyPassManagerCLOptions(pm);
    pm.addPass(mlir::createInlinerPass());
    pm.addPass(mlir::createSymbolDCEPass());
    mlir::OpPassManager &optPM = pm.nest<mlir::FuncOp>();
    optPM.addPass(mlir::toy::createShapeInferencePass());
    optPM.addPass(mlir::createCanonicalizerPass());
    optPM.addPass(mlir::createCSEPass());
    pm.addPass(mlir::toy::createLowerToAffinePass());
    optPM.addPass(mlir::createCanonicalizerPass());
    optPM.addPass(mlir::createCSEPass());
    optPM.addPass(mlir::createLoopFusionPass());
    optPM.addPass(mlir::createMemRefDataFlowOptPass());

    std::cout<<"lower to affine success"<<std::endl;
    pm.addPass(mlir::toy::createLowerToLLVMPass());

    if (mlir::failed(pm.run(module))){
    std::cout<<"pm.run(module) failed"<<std::endl;
      return ;
    }
    module.dump();
}

Then I found it crashed in applyFullConversion(...) in ToyToLLVMLoweringPass::runOnOperation() in LowertoLLVM.cpp .I didn’t change LowertoLLVM.cpp at all
image
What might cause that situation ?How to solve that problem?

Can you provide more detail? When you say crashed do you mean that the pass failed, that you hit an assert, or something else? What is the input IR? Can you try some of the recommendations at https://mlir.llvm.org/getting_started/Debugging? In particular, a local crash reproducer would be helpful here as it will provide a minimal reproduction of what you’re seeing.

crashed means segmentation fault and input IR is toy Dialect (I write python API using boost python like toy.constant(), toy.add())

I am afraid that’s not enough for any of us to reproduce your problem. There’s not even evidence that the issue is with MLIR and not with your code or bindings. “toy dialect” isn’t a sufficient description of the input IR. It is customary to try and provide something that lets anyone just compile mlir from the main repository, call mlir-opt (or add +/-10 LoC somewhere) and see the problem. In this case, I suggest at least to (1) try minimizing the list of passes you run and still see the problem; (2) dump the module before the pass pipeline.

I also note that you might be misunderstanding how the pass manager works, looking at the code snippet you posted above. Passes are not actually executed until the run cal on the pass manager. The fact that the code prints lower to affine success does not mean the pass succeeded, only that creating a pass (allocation, really) and adding it to the pass manager (push_back on a vector) succeeded. So the issue may be absolutely any pass in the pipeline.