Skip to content

Conversation

@prithayan
Copy link
Contributor

@prithayan prithayan commented Nov 7, 2025

This PR adds the HWConstProp pass that performs inter-module constant propagation across hardware module boundaries in the HW dialect.

The pass uses the Sparse Conditional Constant Propagation (SCCP) with lattice-based analysis
Key Steps:

  1. Initialization
    • Mark public module inputs as overdefined (can't be constant)
    • Discover constants from hw.constant operations
    • Mark external/generated module outputs as overdefined
    • Enqueue operations for propagation
  2. Propagation
    • Process operations from two queues (overdefined first, then constants)
    • Propagate constants through:
      • Module outputs → instance results
      • Instance inputs → module arguments
      • Combinational operations (fold when possible)
    • Use lattice meet: unknown ⊔ constant = constant, constant₁ ⊔ constant₂ = overdefined
  3. Cycle Handling
    • Mark remaining unknown values as overdefined
    • Re-propagate to fold newly-resolved constants
  4. Folding
    • Replace SSA values with discovered constants
    • Remove dead operations

@prithayan prithayan requested a review from darthscsi as a code owner November 7, 2025 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants