Skip to content

Expand post-lowering optimization pipeline (inline, CSE, LICM, DCE) #62

Description

@tetsuo-cpp

Summary

Grow buildWarpForthPipeline beyond a single canonicalizer pass so user words and lowered stack/memory IR get the GPU-relevant opts they need.

Motivation

Current pipeline (lib/Conversion/Passes.cpp):

  1. convert-forth-to-memref
  2. convert-forth-to-gpu
  3. canonicalizer only
  4. NVVM attach → GPU→NVVM → math→LLVM → NVVM→LLVM → binary

User-defined words lower to func.func + func.call. On GPU, small helper words should almost always be inlined. Without CSE/LICM/DCE after stack materialization, redundant address math and dead stack traffic survive into PTX.

Proposed passes (order sketch)

After Forth→GPU (and ideally after stack flattening if/when that lands):

  1. Inliner — always-inline (or aggressively inline) private word functions into the kernel
  2. CSE
  3. Canonicalizer (already present; may run more than once)
  4. LICM / loop-invariant code motion where profitable
  5. DCE / SCCP as appropriate
  6. Then existing NVVM/LLVM lowering

Make the set overridable via pass-manager CLI options for experiments (warpforth-opt already registers MLIR passes).

Acceptance criteria

  • Small user words are inlined into main in default pipeline IR dumps
  • Documented pass list in README or architecture notes
  • LIT tests showing inlining and at least one CSE/LICM win on a reduced example
  • No compile-time regression on existing check-warpforth suite
  • Pipeline remains debuggable: ability to stop before/after opt stages (see also dump stages on warpforthc)

Related

  • Stack flattening (promoted SSA makes these opts much more effective)
  • Loop unrolling hints (Loop unrolling hints #12)
  • Configurable GPU arch (separate issue)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions