Reference: https://www.jeremykun.com/2023/08/10/mlir-running-and-testing-a-lowering/
Note: Check Setup the Environment of MLIR for the environment setup.
1. Implementing a Lowering
Create a file “ctlz.mlir”:
func.func @main(%arg0: i32) -> i32 {
%0 = math.ctlz %arg0 : i32
func.return %0 : i32
}
Lower the math.ctlz
operation to the llvm.ctlz
operation with mlir-opt
:
mlir-opt --convert-math-to-funcs=convert-ctlz ./ctlz.mlir