Skip to content

[Feature] pto.tmrgsort format2 should support 2-way and 3-way merge (currently hardcoded to 4-way) #427

@luohuan19

Description

@luohuan19

Background

pto.tmrgsort currently has two formats:

  • format1: single-list intra-block merge, ins(src, blockLen)
  • format2: multi-list merge, hardcoded to exactly 4 sources, ins(src0, src1, src2, src3)

However, the underlying PTO-ISA TMRGSORT instruction supports 2-way, 3-way, and 4-way merges:

// 2-way
TMRGSORT(dst, executedNumList, tmp, src0, src1)
// 3-way
TMRGSORT(dst, executedNumList, tmp, src0, src1, src2)
// 4-way (currently supported)
TMRGSORT(dst, executedNumList, tmp, src0, src1, src2, src3)

Current Limitation

isFormat2() hardcodes a 4-source requirement (include/PTO/IR/PTOOps.td:3246):

bool isFormat2() { return getSrcs().size() == 4u && getDsts().size() == 2u && getExcuted(); }

The print function also hardcodes access to exactly 4 srcs (lib/PTO/IR/PTO.cpp:4521-4524).

Passing 2 or 3 sources triggers the catch-all verifier error:

tmrgsort expects format1 (1 src + blockLen + 1 dst) or format2 (4 srcs, outs dst, excuted)

Expected Behavior

format2 should accept 2, 3, or 4 sources. The isFormat2() predicate should be relaxed to srcs.size() >= 2 && srcs.size() <= 4.

Assembly format would become variadic:

// 2-way
pto.tmrgsort ins(%src0, %src1 {exhausted = false} : ...) outs(%dst, %tmp, %excuted : ...)

// 3-way
pto.tmrgsort ins(%src0, %src1, %src2 {exhausted = false} : ...) outs(%dst, %tmp, %excuted : ...)

Layers Requiring Changes

  • include/PTO/IR/PTOOps.td — relax isFormat2() predicate
  • lib/PTO/IR/PTO.cpp — update print, parse, and verify to handle variable-length srcs
  • lib/PTO/Transforms/PTOViewToMemref.cpp — update lowering patterns for variable-length srcs
  • docs/PTO_IR_manual.md — update format2 assembly format description and examples
  • test/ — add regression tests for 2-way and 3-way cases

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions