qe-compiler icon indicating copy to clipboard operation
qe-compiler copied to clipboard

Revise SSA transformation for OpenQASM 3 variables

Open mhillenbrand opened this issue 2 years ago • 0 comments

Description

qss-compiler expresses variable references and assignments in OpenQASM 3 source code as MLIR operations that directly reflect these references and assignments in the initial MLIR -- that is, the initial MLIR uses memory semantics for variables. For later optimization, it is beneficial to resolve these operations with memory semantics such that the use of a variable directly uses the SSA value that has been assigned to the variable at that point.

Currently, the compiler uses the pass VariableElimination towards that goal. That pass takes a detour through the affine dialect and its scalar replacement pass. As a downside, that approach currently cannot resolve variable memory semantics around control flow.

We should revise the VariableElimination pass to fully resolve the OpenQASM 3 variable operations into SSA form.

Tasks

  • Identify test cases first.
  • Revise the VariableElimination pass.

Acceptance Criteria

  • New test cases check corner cases.

Proposal

  • The transformation could be integrated into quirgen. Yet, it should remain its own pass to facilitate debugging and unit testing.
  • Consider Marc M. Brandis, Hanspeter Mössenböck

Notes

  • The paper Marc M. Brandis, Hanspeter Mössenböck: Single-pass generation of static single-assignment form for structured languages describes an algorithm for transforming structured control flow into SSA form in a single pass and may serve as a starting point. The algorithm generates "classical SSA" with phi nodes, while MLIR has block and region arguments (and yield values), so there's some transformation required.

mhillenbrand avatar Feb 09 '23 08:02 mhillenbrand