openqasm / qe-compiler

An MLIR based compiler dynamic circuit compiler for real-time control systems supporting OpenQASM 3
Other
38 stars 12 forks source link

Add Symbol Cache Analysis #301

Closed bcdonovan closed 3 months ago

bcdonovan commented 3 months ago

This PR adds a SymbolCacheAnalysis to standardizing the caching of symbols for Circuits, Sequences and other function like operations which follow a call_<name> by callee, <name> @callee pattern.

This analysis is intended to provide a standard way to cache the callee operations by name and by call_operation as a way to mitigate the performance issues associated with lookupNearestSymbolFrom.

The analysis will cache callee of the request type. For example:

auto &cache =
       getAnalysis<qssc::utils::SymbolCacheAnalysis>().addToCache<CircuitOp>();

Will cache all of the CircuitOps in the current passes operation.

Callee's ay be retrieved using:

cache.getOp<CircuitOp>(callCircuitOp);

Multiple operation types may be cached:

auto &cache =
       getAnalysis<qssc::utils::SymbolCacheAnalysis>().addToCache<CircuitOp>().addToCache<SequenceOp>();

The analysis pass will by default retain the callee name to operation map from pass to pass based on the Operation type. The analysis may be forced to reset and re-cache by calling invalidate:

auto &cache =
       getAnalysis<qssc::utils::SymbolCacheAnalysis>().invalidate().addToCache<CircuitOp>());