Skip to content

Add tmp support for tci/trowexpandadd and printFormat for tprint#724

Open
FangRui0 wants to merge 2 commits into
hw-native-sys:mainfrom
FangRui0:align_args2
Open

Add tmp support for tci/trowexpandadd and printFormat for tprint#724
FangRui0 wants to merge 2 commits into
hw-native-sys:mainfrom
FangRui0:align_args2

Conversation

@FangRui0
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an optional scratch tile buffer (tmp) to the pto.trowexpandadd and pto.tci operations, and adds an optional printFormat attribute to pto.tprint to control formatting width and precision. It updates the corresponding assembly formats, verifiers, and EmitC/Memref conversion passes. The reviewer feedback focuses on code simplification and correctness: specifically, using the ODS-generated getPrintFormat() helper to avoid manual attribute null-checks, and conditionally returning a null ArrayAttr for pto.tprint when the default format is used to prevent EmitC from generating empty template brackets (TPRINT<>).

templateArgVec.push_back(
emitc::OpaqueAttr::get(ctx, printFormatTok(printFormat)));
}
ArrayAttr templateArgs = rewriter.getArrayAttr(templateArgVec);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When printFormat is 0 (the default), templateArgVec is empty. Using rewriter.getArrayAttr(templateArgVec) creates an empty ArrayAttr (i.e., []), which causes EmitC to generate empty template brackets TPRINT<> in the output C++ code.

To avoid generating empty template brackets for the default case, we can conditionally return a null ArrayAttr when the vector is empty, matching the pattern used for MGather above. This also means we don't need to relax the LIT test assertions with {{(<.*>)?}}.

Suggested change
ArrayAttr templateArgs = rewriter.getArrayAttr(templateArgVec);
ArrayAttr templateArgs =
templateArgVec.empty() ? ArrayAttr{} : rewriter.getArrayAttr(templateArgVec);

Comment thread lib/PTO/IR/PTO.cpp
Comment on lines +9805 to +9806
auto printFormatAttr = getPrintFormatAttr();
int64_t printFormat = printFormatAttr ? printFormatAttr.getInt() : 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since printFormat is defined as a DefaultValuedOptionalAttr, ODS automatically generates a getPrintFormat() helper method that handles the default value and returns the underlying integer type directly. We can use this helper to simplify the code and avoid manual null-checking of the attribute.

Suggested change
auto printFormatAttr = getPrintFormatAttr();
int64_t printFormat = printFormatAttr ? printFormatAttr.getInt() : 0;
int64_t printFormat = getPrintFormat();

Comment on lines +10709 to +10711
int64_t printFormat = 0;
if (auto formatAttr = op.getPrintFormatAttr())
printFormat = formatAttr.getInt();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similarly, we can use the ODS-generated getPrintFormat() helper here to simplify the code and avoid manual null-checking of the attribute.

Suggested change
int64_t printFormat = 0;
if (auto formatAttr = op.getPrintFormatAttr())
printFormat = formatAttr.getInt();
int64_t printFormat = op.getPrintFormat();

@reedhecre
Copy link
Copy Markdown

reedhecre commented May 28, 2026

Codex Review

该评论由 review 机器人自动更新。

Summary

检查到 3 个问题:tfillpad.padValue 在标准管线里会失效/触发校验失败,mgather/mscatter 的显式 coalesce 缺少模式一致性校验,tcidescending 旧文本语法被破坏。

Findings

  1. P1 `tfillpad` 的 `padValue` 新属性在标准 lowering 管线中不可用 lib/PTO/IR/PTO.cpp:6000

PTOViewToMemrefPass 会把 padValue 原样带到 memref 版 pto.tfillpad,但这里仍然要求只要带了 padValuedst 就必须还是 tile_bufptoas 的标准管线会先跑 createPTOViewToMemrefPass(),因此用户一旦使用新的 {padValue = ...} 形式,pass 之后生成的 memref 版 op 在默认 verifier 下就会报 expects dst to be tile_buf when padValue is specified。即使关闭 verifier,后面的 EmitC lowering 也只在 dst 仍是 TileBufType 时才会发出 TFILLPAD<PadValue>,所以这个新属性会被静默丢掉。

  1. P2 `mgather` / `mscatter` 的显式 `coalesce` 模式没有和 idx 形状做一致性校验 lib/PTO/IR/PTO.cpp:3401

这个 PR 新增了显式 coalesce 属性,但 verifier 仍然只检查“idx 形状是否属于 row/elem 任一合法形式”的并集条件,并不会检查它是否和显式 coalesce=row/elem 一致。与此同时,EmitC lowering 会直接信任该属性并覆盖旧的 shape 推断。结果是像 coalesce = elem 配行模式 [1, R] / [R, 1] idx,或 coalesce = row 配全尺寸 elem-mode idx,都会通过验证,然后被 lower 成 MGATHER/MSCATTER<Coalesce::...> 的错误模板实例,语义和 idx 的布局/valid_shape 不再匹配。

  1. P3 `tci` 的新自定义 parser 破坏了已有 `descending` 文本语法的兼容性 lib/PTO/IR/PTO.cpp:4623

在这次修改之前,pto.tci 的属性字典位于 ins(...) 内部,所以已有 IR 可以写成 pto.tci ins(%s {descending = true} : i32) outs(...)。新的 parser 只会在 outs(...) 之后读取 attr-dict,没有兼容旧写法。这样任何已有的、带 descending 的 textual IR 在升级后都会直接 parse 失败,这和本 PR 只是新增可选 tmp 支持无关,属于不必要的兼容性回退。

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