Skip to content

refactor(conversion): add StackEffectConversion base for ForthToMemRef patterns - #133

Merged
tetsuo-cpp merged 1 commit into
canonfrom
claude/translation-pass-refactor-86af06
Oct 24, 2026
Merged

tetsuo-cpp merged 1 commit into
canonfrom
claude/translation-pass-refactor-86af06

Conversation

@tetsuo-cpp

Copy link
Copy Markdown
Owner

Closes #122. Follow-up to #17.

What changed

StackEffectConversion<ForthOp> unpacks the converted !forth.stack operand into (memref, SP), calls a virtual rewriteStack, and replaces the op with {memref, newSP}. Each pattern now holds only its stack logic.

Migrated: Constant, Dup, Drop, Swap, Over, Rot, Nip, Tuck, Pick, Roll, Not, ZeroEq, ParamRef, IToF, FToI, GlobalId, PushValue, and the BinaryArith, UnaryFloat, BinaryCmp, MemoryLoad, MemoryStore and Intrinsic templates.

PopOp and PopFlagOp stay on plain OpConversionPattern. They also replace an extra non-stack result (the value or the i1 flag), which a single-SP hook can't express. They still lose the forwarding constructor. StackOpConversion has no input stack and is unchanged. The issue proposed the name StackOpConversion for the base, but that name already belongs to the forth.stack pattern.

Net: 210 insertions, 301 deletions in ForthToMemRef.cpp.

Verification

  • check-warpforth: 134/134 pass, same as before the change.
  • Equivalence: before and after, I captured --convert-forth-to-memref output for every test/Conversion/ForthToMemRef/*.mlir, plus memref and full-pipeline PTX for every .forth file under test/ and gpu_test/. That's 236 outputs, and all are byte-identical (diff -r empty).
  • check-clang-tidy reports no new findings. The two existing llvm-prefer-static-over-anonymous-namespace errors on pushValue and getMemElemType predate this change.

…f patterns

Every stack-in, stack-out pattern repeated a forwarding constructor, the
OneToNOpAdaptor alias, the (memref, SP) unpack, and the
replaceOpWithMultiple epilogue. StackEffectConversion<ForthOp> owns that
plumbing; each pattern now implements rewriteStack and returns the new SP.

PopOp and PopFlagOp keep a plain matchAndRewrite because they replace an
extra non-stack result, but drop their forwarding constructors.

Closes #122.
@tetsuo-cpp
tetsuo-cpp enabled auto-merge (rebase) October 24, 2026 11:13
@tetsuo-cpp
tetsuo-cpp merged commit 804b7f9 into canon Oct 24, 2026
1 check passed
@tetsuo-cpp
tetsuo-cpp deleted the claude/translation-pass-refactor-86af06 branch October 24, 2026 11:19
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.

Finish ForthToMemRef pattern boilerplate reduction (follow-up to #17)

1 participant