Closed Po-Chun-Chien closed 4 months ago
For handling btor2 arrays, you will need to use the array passes. The readme will be updated soon but here's the recommended passes to get you on your way:
btor2mlir-opt --btor-liveness --convert-btornd-to-llvm --convert-btor-to-memref --convert-memref-to-llvm --convert-arith-to-llvm --convert-btor-to-llvm --convert-std-to-llvm --convert-vector-to-llvm --resolve-casts file.mlir
Here is the breakdown:
--btor-liveness
: this pass will run our transformation from immutable to mutable writes based on a liveness analysis
--convert-btornd-to-llvm
: takes care of our non-deterministically assigned states and inputs
--convert-btor-to-memref --convert-memref-to-llvm
: converts arrays to their llvm equivalents
the rest of the passes are what you are familiar with from the bitvector cases
Hope this helps!
Hi, sorry for the late reply. I was caught up in other things.
With the additional command-line flags,
I was able to translate array_swap.btor2
into LLVM-IR.
However, I also encounter different problems with other Btor2 circuits.
The following were obtained from Btor2MLIR at commit 2e06dec3.
(I could not build the latest commit 45f1751e
due to /opt/btor2mlir/prevail does not contain a CMakeLists.txt file
)
Converting mann-2019/safe_linked_list_fifo_n2d4.{btor2 => mlir} ...
Running 'btor2mlir-translate --import-btor /benchmarks/array/btor2/mann-2019/safe_linked_list_fifo_n2d4.btor2 >/benchmarks/array/mlir/mann-2019/safe_linked_list_fifo_n2d4.mlir'
Converting mann-2019/safe_linked_list_fifo_n2d4.{mlir => mlir.opt} ...
Running 'btor2mlir-opt --btor-liveness --convert-btornd-to-llvm --convert-btor-to-memref --convert-memref-to-llvm --convert-arith-to-llvm --convert-btor-to-llvm --convert-std-to-llvm --convert-vector-to-llvm --resolve-casts /benchmarks/array/mlir/mann-2019/safe_linked_list_fifo_n2d4.mlir >/benchmarks/array/mlir/mann-2019/safe_linked_list_fifo_n2d4.mlir.opt'
/benchmarks/array/mlir/mann-2019/safe_linked_list_fifo_n2d4.mlir:132:12: error: operand #0 does not dominate this use
%237 = btor.read %235[%223] : !btor.array<<1>, <2>>, !btor.bv<2>
^
/benchmarks/array/mlir/mann-2019/safe_linked_list_fifo_n2d4.mlir:132:12: note: see current operation: %235 = "btor.read"(%275, %223) : (!btor.array<<1>, <2>>, !btor.bv<1>) -> !btor.bv<2>
/benchmarks/array/mlir/mann-2019/safe_linked_list_fifo_n2d4.mlir:128:12: note: operand defined here (op in the same block)
%233 = btor.write %232, %112[%222] : !btor.array<<1>, <2>>
^
Converting wolf-2018A/VexRiscv-regch0-15-p0-array.{btor2 => mlir} ...
Running 'btor2mlir-translate --import-btor /benchmarks/array/btor2/wolf-2018A/VexRiscv-regch0-15-p0-array.btor2 >/benchmarks/array/mlir/wolf-2018A/VexRiscv-regch0-15-p0-array.mlir'
Converting wolf-2018A/VexRiscv-regch0-15-p0-array.{mlir => mlir.opt} ...
Running 'btor2mlir-opt --btor-liveness --convert-btornd-to-llvm --convert-btor-to-memref --convert-memref-to-llvm --convert-arith-to-llvm --convert-btor-to-llvm --convert-std-to-llvm --convert-vector-to-llvm --resolve-casts /benchmarks/array/mlir/wolf-2018A/VexRiscv-regch0-15-p0-array.mlir >/benchmarks/array/mlir/wolf-2018A/VexRiscv-regch0-15-p0-array.mlir.opt'
Converting array type to mem cell
Converting array type to mem cell
/benchmarks/array/mlir/wolf-2018A/VexRiscv-regch0-15-p0-array.mlir:104:12: error: failed to legalize operation 'btor.nd_array' that was explicitly marked illegal
%100 = btor.nd_array 103 : !btor.array<<5>, <32>>
^
/benchmarks/array/mlir/wolf-2018A/VexRiscv-regch0-15-p0-array.mlir:104:12: note: see current operation: %680 = "btor.nd_array"() {id = 103 : ui64} : () -> !btor.array<<5>, <32>>
The following process hangs.
Converting wolf-2019A/picorv32_mutAX_mem-p0.{btor2 => mlir} ...
Running 'btor2mlir-translate --import-btor /benchmarks/array/btor2/wolf-2019A/picorv32_mutAX_mem-p0.btor2 >/benchmarks/array/mlir/wolf-2019A/picorv32_mutAX_mem-p0.mlir'
Converting wolf-2019A/picorv32_mutAX_mem-p0.{mlir => mlir.opt} ...
Running 'btor2mlir-opt --btor-liveness --convert-btornd-to-llvm --convert-btor-to-memref --convert-memref-to-llvm --convert-arith-to-llvm --convert-btor-to-llvm --convert-std-to-llvm --convert-vector-to-llvm --resolve-casts /benchmarks/array/mlir/wolf-2019A/picorv32_mutAX_mem-p0.mlir >/benchmarks/array/mlir/wolf-2019A/picorv32_mutAX_mem-p0.mlir.opt'
Converting array type to mem cell
Converting array type to mem cell
The commit you are using is the right one for your needs. I have taken a look at your examples and here are some ways forward:
--convert-btor-to-vector --convert-vector-to-llvm
right after --convert-btor-to-memref --convert-memref-to-llvm
(follow up https://github.com/agurfinkel/btor2mlir/issues/40)
I ran the below steps (using the commands from
get_cex_seahorn.sh
) to translate the Btor2 circuit array_swap.btor2 (obtained from HWMCC 2020 benchmark set) to the Btor2 dialect of LLVM. A docker image built from commit 3456250 was used.btor2mlir-translate --import-btor array_swap.btor2 >array_swap.mlir
btor2mlir-opt --convert-btornd-to-llvm --convert-btor-to-vector --convert-arith-to-llvm --convert-std-to-llvm --convert-btor-to-llvm --convert-vector-to-llvm array_swap.mlir >array_swap.mlir.opt
The 2nd step failed with the following messages:
I've also tried several different Btor2 tasks with
array
, they all failed with a similar error message.