qir-alliance / qcor

C++ compiler for heterogeneous quantum-classical computing built on Clang and XACC
http://docs.aide-qc.org
MIT License
97 stars 39 forks source link

Update QASM3 loop handler to use MLIR Affine Dialect #172

Closed 1tnguyen closed 3 years ago

1tnguyen commented 3 years ago

This will enable the built-in MLIR loop unrolling pass.

1tnguyen commented 3 years ago

Unrolling affine for loops is not enough for circuit optimization. Need a way to consolidate SSA values created by q.extract.

e.g.,

affine.for %arg0 = 0 to 8 step 4 {
      %2 = q.extract(%0, %c0_i64) : !quantum.Qubit
      %3 = qvs.x(%2) : !quantum.Qubit
      %4 = q.extract(%0, %c0_i64) : !quantum.Qubit
      %5 = qvs.x(%4) : !quantum.Qubit
      %6 = q.extract(%0, %c0_i64) : !quantum.Qubit
      %7 = qvs.x(%6) : !quantum.Qubit
      %8 = q.extract(%0, %c0_i64) : !quantum.Qubit
      %9 = qvs.x(%8) : !quantum.Qubit
 }