Running Toy tutorial tests

I’m currently attempting to run the Toy tutorial tests. I’m using toyc-ch2 to convert the code from the .toy format to the .mlir representation. However, when trying to convert from .mlir to .ll using the following command:

mlir-opt --convert-scf-to-cf --convert-cf-to-llvm --convert-func-to-llvm \
         --convert-arith-to-llvm --expand-strided-metadata --normalize-memrefs \
         --memref-expand --fold-memref-alias-ops --finalize-memref-to-llvm \
         --reconcile-unrealized-casts input.mlir | mlir-translate --mlir-to-llvmir > tmp.ll

I encounter an error as shown in the screenshot, indicating that .mlir is not recognizing the Toy dialect. How can I resolve this issue? Please correct my sentences.

You can’t do that, in chapter 5 the lowering from Toy down to affine is introduced with toyc-ch5 -emit=mlir-affine (which you will be able to process with mlir-opt) and further to LLVM in chapter 6 with toyc-ch6 -emit=llvm

Okay, thank you. I understand better now. I am able to generate the .ll file. However, I noticed that there is already a pre-built toyc-ch7 executable located in the build/bin directory of the llvm-project. According to the documentation, it is possible to build toyc-ch7 ourselves. Therefore, I created a new build directory at /llvm-project/mlir/examples/toy/Ch7/. However, I’m unsure about which commands to run. I tried the following commands:

1) cmake -G Ninja -DLLVM_DIR=/home/aymaen/llvm-project/build/lib/cmake/llvm/  -DMLIR_DIR=/home/aymaen/llvm-project/build/lib/cmake/mlir/
2) ninja toyc-ch7

But it returns an error saying “unknown target ‘toyc-ch7’”. If possible, could you please provide more specific instructions on how to build this executable?

I don’t quite get what your cmake invocation is supposed to do actually? What is your CMakeLists.txt looking like?
It does not seems you’re following the instructions from Getting Started - MLIR

In fact, I’m just asking how did you generate the toyc-ch7. I’m in /mlir/examples/toy/Ch7, and this’s the CmakeLists.txt llvm-project/CMakeLists.txt at main · llvm/llvm-project · GitHub. I just want to understand the process of generation of toyc-ch7, because I see it as a target in this CmakeLists.txt, but how to do the generation?

You just follow Getting Started - MLIR ; there is nothing special as the instructions here are including building the examples.