catalyst icon indicating copy to clipboard operation
catalyst copied to clipboard

Make it easier to modify and recompile IR

Open tzunghanjuang opened this issue 1 year ago • 1 comments

Context:

This PR introduces two new methods in frontend/catalyst/debug/compiler_functions.py.

  • get_pipeline_output(fn: QJIT, pass_name: str) -> str fetches the IR string after the given pipeline pass pass_name.
  • replace_ir(fn: QJIT, pass_name: str, new_ir: str) -> None overwrites the IR and specify a starting pass (exclusive) pass_name for the next compilation.

The possible options for pass_name are

  • MILR: mlir, HLOLoweringPass, QuantumCompilationPass, BufferizationPass, and MLIRToLLVMDialect
  • LLVM: llvm_ir, CoroOpt, O2Opt, Enzyme, and last

Note that last denotes the IR right before object file generation.

Changes:

  • QJIT now has an extra flag overwrite_ir to specify the new IR for compilation.
  • CompilerOptions now has an extra flag startAfterPass to specify the compilation start after the given pass.
  • CompilerOutput now has an extra flag reachTargetPass to indicate if the given pass is reached.
  • Update documentation Debugging Tips.

Limitations

  • To get IRs from get_pipeline_output, the function must be compiled with keep_intermediate=True
  • We must define a function first for recompilation.

Related GitHub Issues: [sc-67088]

tzunghanjuang avatar Jul 31 '24 21:07 tzunghanjuang