Skip to content

cleancode(pto): clean up static-analysis warnings and decompose large verifiers - #1371

Merged
zhangstevenunity merged 7 commits into
hw-native-sys:mainfrom
FangRui0:codecheck
Aug 31, 2026
Merged

cleancode(pto): clean up static-analysis warnings and decompose large verifiers#1371
zhangstevenunity merged 7 commits into
hw-native-sys:mainfrom
FangRui0:codecheck

Conversation

@FangRui0

@FangRui0 FangRui0 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Clean up static-analysis findings in the PTO IR layer without altering
any behavior. Two independent, behavior-preserving efforts:

1. General lint cleanup

Address safe and moderate lint findings:

  • add missing braces, fix lambda default capture, order includes
  • replace forward declarations with the corresponding includes where
    no include cycle exists
  • drop the redundant ASSERT macro in favor of assert
  • replace magic numbers with named constants (kBitsPerByte,
    kMaxSupportedBitWidth, kNumVPTOSchedulingClasses, existing kValueN)

False-positive findings are intentionally left in place: CAPI export
markers, self-referential forward declarations, and forward decls that
break header include cycles.

2. huge_method decomposition (25 verifiers, 5 batches)

Mechanically split the largest Op::verify() methods in PTO.cpp into
focused file-scope static helpers, each under the 50 nbnc-line
huge_method threshold. Behavior-preserving extraction only: check order,
error strings, and magic numbers are all preserved verbatim. No ODS /
API / semantic changes — pure C++ verifier refactor.

Batch Verifiers decomposed
A TMovOp, TExtractOp, TGatherOp, TInsertOp, TQuantMxOp
B TScatterOp, SubViewOp, TQuantOp, TTransOp, TPReluOp
C TMrgSortOp, TCvtOp, TSelSOp, TConcatOp, TRemOp
D TGatherBOp, TRemSOp, TPowOp, TPowSOp, TSelOp
E TPartMulOp, TRowExpandAddOp, TXorOp, TRowExpandOp, TPartAddOp

Verification

Each batch was verified on the remote LLVM 19 toolchain: libPTOIR.a
compiles clean, and the pto lit suite is identical before/after every
batch (697/700 pass; the same 3 pre-existing failures in
struct_escape_return_invalid, struct_escape_yield_invalid, and
plan_memory_fusion_region_alias are environmental and unrelated to
these changes). Identical failure sets across all batches = zero
regressions.

@FangRui0

Copy link
Copy Markdown
Contributor Author

/run a3

@FangRui0 FangRui0 changed the title style(pto): clean up static-analysis warnings style(pto): clean up static-analysis warnings and decompose large verifiers Aug 29, 2026
@FangRui0 FangRui0 changed the title style(pto): clean up static-analysis warnings and decompose large verifiers cleancode(pto): clean up static-analysis warnings and decompose large verifiers Aug 29, 2026
@reedhecre

Copy link
Copy Markdown

已接收 /run a3,A3 板测器会处理这条请求。

页面会自动刷新,可以直接看当前阶段、排队情况和最近结果。

@reedhecre

Copy link
Copy Markdown

A3 板测完成(有跳过)

Address safe and moderate lint findings without altering behavior:
- add missing braces, fix lambda default capture, order includes
- replace forward declarations with the corresponding includes where
  no include cycle exists
- drop the redundant ASSERT macro in favor of assert
- replace magic numbers with named constants (kBitsPerByte,
  kMaxSupportedBitWidth, kNumVPTOSchedulingClasses, existing kValueN)

False-positive findings are intentionally left in place: CAPI export
markers, self-referential forward declarations, and forward decls that
break header include cycles.
Mechanically split the five largest Op::verify() methods in PTO.cpp into
file-scope static helpers, each under the 50 nbnc-line huge_method
threshold. Behavior-preserving extraction only: check order, error
strings, and magic numbers are all preserved verbatim.

Verifiers decomposed: TMovOp, TExtractOp, TGatherOp, TInsertOp, TQuantMxOp.

Verified on remote LLVM 19 toolchain: libPTOIR.a compiles clean under
strict -Werror, and the pto lit suite is identical before/after this
change (697/700 pass; the same 3 pre-existing failures in struct_escape
and plan_memory_fusion are unrelated to these verifiers).
…warnings

Mechanically extract TScatterOp, SubViewOp, TQuantOp, TTransOp, and
TPReluOp verify() methods into focused file-scope static helpers, each
under 50 nbnc lines. Behavior-preserving: error strings, magic numbers,
and check ordering are all preserved verbatim.
…warnings

Mechanically extract TMrgSortOp, TCvtOp, TSelSOp, TConcatOp, and TRemOp
verify() methods into focused file-scope static helpers, each under 50
nbnc lines. Behavior-preserving: error strings, magic numbers, and check
ordering are all preserved verbatim.
…warnings

Mechanically extract TGatherBOp, TRemSOp, TPowOp, TPowSOp, and TSelOp
verify() methods into focused file-scope static helpers, each under 50
nbnc lines. Behavior-preserving: error strings, magic numbers, and check
ordering are all preserved verbatim.
…warnings

Mechanically extract file-scope static helpers from the following
Op::verify() methods, preserving all error strings, magic numbers, and
check ordering (behavior-preserving):

- TPartMulOp    -> verifyTPartMulA2A3/A5
- TRowExpandAddOp -> verifyTRowExpandAddCore/Src1/ByArch
- TXorOp        -> verifyTXorA2A3/A5
- TRowExpandOp  -> verifyTRowExpandCommon
- TPartAddOp    -> verifyTPartAddA2A3/A5
The verifier decomposition dropped the braces on many single-statement
if bodies to shave lines toward the huge_method threshold, which
violates G.FMT.11-CPP (if/for/while bodies must be braced). Re-add
braces to every control body the decomposition introduced (~292 if
bodies), leaving pre-existing untouched code alone.

Purely structural: no logic change. Remote build is clean and the pto
lit suite is unchanged (697/700; same 3 pre-existing environmental
failures).
@zhangstevenunity
zhangstevenunity merged commit 1857cb5 into hw-native-sys:main Aug 31, 2026
14 of 15 checks passed
@reedhecre

Copy link
Copy Markdown

A3 板测完成(有跳过)

  • 触发方式:merged
  • 源码提交:1857cb5db90e
  • 结果汇总:OK 323 / FAIL 0 / SKIP 29
  • 日志:/home/zhongxuan/ptoas-board-monitor/runtime/logs/20260831_001324_merged_pr1371.log
  • 结果 TSV:/home/zhongxuan/ptoas-board-monitor/runtime/logs/20260831_001324_merged_pr1371.tsv

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.

3 participants