Skip to content

fix: add pto.tfillpad_inplace; stop tfillpad from auto-lowering to TFILLPAD_INPLACE#473

Open
FangRui0 wants to merge 1 commit intohw-native-sys:mainfrom
FangRui0:add_op2
Open

fix: add pto.tfillpad_inplace; stop tfillpad from auto-lowering to TFILLPAD_INPLACE#473
FangRui0 wants to merge 1 commit intohw-native-sys:mainfrom
FangRui0:add_op2

Conversation

@FangRui0
Copy link
Copy Markdown
Contributor

Issue #470
TFILLPAD_INPLACE requires same backing storage with distinct src/dst valid-region semantics; same SSA tfillpad must use TFILLPAD. Add explicit tfillpad_inplace op and lowering to TFILLPAD_INPLACE.

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 the TFillPadInplaceOp operation to explicitly handle in-place fill padding, separating this logic from the standard TFillPadOp. The changes include the ODS definition, verifier implementation, and lowering patterns to EmitC. Review feedback identifies a critical syntax error in the new EmitC lowering pattern where a return statement and closing braces are missing. Additionally, improvements are suggested to use the more idiomatic replaceOpWithNewOp in conversion patterns and to move IRRewriter instantiation outside of loops to improve performance.

Comment on lines +6717 to 6728
LogicalResult matchAndRewrite(pto::TFillPadInplaceOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
auto loc = op.getLoc();

Value src = peelUnrealized(adaptor.getSrc());
Value dst = peelUnrealized(adaptor.getDst());

rewriter.create<emitc::CallOpaqueOp>(
loc, TypeRange{}, "TFILLPAD_INPLACE",
/*args=*/ArrayAttr{}, /*templateArgs=*/ArrayAttr{},
/*operands=*/ValueRange{dst, src});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The matchAndRewrite implementation for PTOFillPadInplaceToEmitC is incomplete. It is missing the return statement and the closing braces for both the function and the struct. This will cause a compilation error. Additionally, using replaceOpWithNewOp is preferred.

  LogicalResult matchAndRewrite(pto::TFillPadInplaceOp op, OpAdaptor adaptor,
                                ConversionPatternRewriter &rewriter) const override {
    auto loc = op.getLoc();

    Value src = peelUnrealized(adaptor.getSrc());
    Value dst = peelUnrealized(adaptor.getDst());

    rewriter.replaceOpWithNewOp<emitc::CallOpaqueOp>(
        op, TypeRange{}, "TFILLPAD_INPLACE",
        /*args=*/ArrayAttr{}, /*templateArgs=*/ArrayAttr{},
        /*operands=*/ValueRange{dst, src});

    return success();
  }
};

Comment on lines 6700 to +6706
rewriter.create<emitc::CallOpaqueOp>(
loc, TypeRange{}, callee,
loc, TypeRange{}, "TFILLPAD",
/*args=*/ArrayAttr{}, /*templateArgs=*/ArrayAttr{},
/*operands=*/ValueRange{dst, src});

rewriter.eraseOp(op);
return success();
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

Using replaceOpWithNewOp is more idiomatic in MLIR conversion patterns than manually creating an operation and then erasing the original one. It ensures that the conversion driver is correctly notified of the replacement.

Suggested change
rewriter.create<emitc::CallOpaqueOp>(
loc, TypeRange{}, callee,
loc, TypeRange{}, "TFILLPAD",
/*args=*/ArrayAttr{}, /*templateArgs=*/ArrayAttr{},
/*operands=*/ValueRange{dst, src});
rewriter.eraseOp(op);
return success();
rewriter.replaceOpWithNewOp<emitc::CallOpaqueOp>(
op, TypeRange{}, "TFILLPAD",
/*args=*/ArrayAttr{}, /*templateArgs=*/ArrayAttr{},
/*operands=*/ValueRange{dst, src});
return success();

Comment on lines +2321 to +2322
for (auto op : fillpadInplaceOps) {
IRRewriter rewriter(ctx);
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

Instantiating an IRRewriter inside a loop is inefficient. It is better to create the rewriter once outside the loop and update its insertion point for each operation.

Suggested change
for (auto op : fillpadInplaceOps) {
IRRewriter rewriter(ctx);
IRRewriter rewriter(ctx);
for (auto op : fillpadInplaceOps) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

…ILLPAD_INPLACE

Issue hw-native-sys#470: TFILLPAD_INPLACE requires same backing storage with distinct
src/dst valid-region semantics; same SSA tfillpad must use TFILLPAD.
Add explicit tfillpad_inplace op and lowering to TFILLPAD_INPLACE.

Made-with: Cursor
@FangRui0
Copy link
Copy Markdown
Contributor Author

/run a3

@reedhecre
Copy link
Copy Markdown

A3 板测失败

日志尾部


===== STAGE check-python-deps @ 2026-04-14 11:40:06 =====
/usr/bin/python3 - <<'PY'
import numpy, pybind11
print('numpy', numpy.__version__)
print('pybind11', pybind11.__version__)
PY
numpy 2.2.6
pybind11 2.13.6
===== END STAGE check-python-deps rc=0 @ 2026-04-14 11:40:06 =====

===== STAGE check-mlir-python @ 2026-04-14 11:40:06 =====
/usr/bin/python3 - <<'PY'
from mlir.ir import Context
ctx = Context()
print('mlir_python_ok')
PY
mlir_python_ok
===== END STAGE check-mlir-python rc=0 @ 2026-04-14 11:40:07 =====

===== STAGE fetch-source @ 2026-04-14 11:40:07 =====
set -euo pipefail
git clone --branch main --single-branch --no-tags https://github.com/hw-native-sys/PTOAS.git /home/zhongxuan/ptoas-board-monitor/runtime/runs/20260414_114004_manual_pr473/repo
Cloning into '/home/zhongxuan/ptoas-board-monitor/runtime/runs/20260414_114004_manual_pr473/repo'...
fatal: unable to access 'https://github.com/hw-native-sys/PTOAS.git/': OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0
===== END STAGE fetch-source rc=128 @ 2026-04-14 11:41:37 =====

@FangRui0
Copy link
Copy Markdown
Contributor Author

/run a3

@reedhecre
Copy link
Copy Markdown

A3 板测完成(有跳过)

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