Skip to content

refactor: decompose oversized functions flagged by codecheck - #1494

Closed
jimmychou0 wants to merge 2 commits into
hw-native-sys:masterfrom
jimmychou0:zjm/codecheck-fix-5
Closed

refactor: decompose oversized functions flagged by codecheck#1494
jimmychou0 wants to merge 2 commits into
hw-native-sys:masterfrom
jimmychou0:zjm/codecheck-fix-5

Conversation

@jimmychou0

Copy link
Copy Markdown
Contributor

Summary

Decompose the ten functions the latest codecheck scan reports over the nbnc-50 / cyclomatic-complexity-20 limits (21 findings, all fixed; disposition table in codecheck-fix-5.csv). Every split is behavior-preserving — extraction of cohesive helpers, no logic changes.

Function Before → After Extraction
PTOResolveBufferSelect::getTilePointerStrides 59 → 32 fractal-dims + RowPlusOne-pad helpers
PTORemoveRedundantBarrier::runOnOperation 110 → 44 OpPipeTable, file-level sync classifiers, isRedundantBarrier (rules A/B/C)
PTOExpandSoftLib::materializeCall / runOnOperation 80 → 46 / 72 → 50 cloneRenamedSoftLibFunctions, replaceWithSoftLibCall, isSupportedIntegerVdiv
MemoryDependentAnalyzer::MemAlias 75 → 28 isLocalBufferAlias, rangesOverlapOrUnknown (folds the repeated empty/zero-size guards)
SyncMacroModel::getMGatherSyncMacroModel / getCollectiveCommSyncMacroModel 89 → 21 / 53 → 38 four build*Model helpers; addPingPongStagingPhases / addTReducePhases
PTOMaterializeTileOpSections::inferTileOpKind 77 → 28 classifyTileOpHelperOperation
VPTOStatefulStreamFusion::getLoopAddressCoefficient / parseStatefulStoreStream 61 → 22 / 52 → 45 computeCoefficientFromDef, isValidStreamFlush
PTOValidateVMIIR::verifyLayoutSemanticSupport (223) → 21 already split on master into a dispatcher; its derived GroupReduction verifier is now table-driven via member-function pointers (51 → ~28)
PTOModule::populatePTODialectBindings 1309 → 9 six semantic populate*Bindings sections + the existing submodule hook
ptoas_pipeline::runMainLoweringPipeline 99 → 39 populateMainLoweringPasses, finishVPTOMainPipeline

Test plan

  • 144 host, LLVM 19.1.7 assert build (GCC 13.3) on master b465f26b5: full build warning-free under -Werror.
  • CTest 73/73 (PTO/PTODSL + PTOBC + smoke) on the same base.
  • git diff --check clean; changed-code checker flags only known false positives on braced multi-line if conditions.

Split the ten functions the latest scan reports over the nbnc-50 /
cyclomatic-20 limits, keeping every transformation behavior-preserving:

- PTOResolveBufferSelect: getTilePointerStrides 59->32 (fractal dims +
  RowPlusOne pad helpers)
- PTORemoveRedundantBarrier: runOnOperation 110->44 (OpPipeTable, file-level
  sync classifiers, isRedundantBarrier rules A/B/C)
- PTOExpandSoftLib: materializeCall 80->46 and runOnOperation 72->50
  (cloneRenamedSoftLibFunctions, replaceWithSoftLibCall,
  isSupportedIntegerVdiv)
- MemoryDependentAnalyzer: MemAlias 75->28 (isLocalBufferAlias,
  rangesOverlapOrUnknown folding the repeated empty/zero-size guards)
- SyncMacroModel: getMGatherSyncMacroModel 89->21 (four build*Model
  helpers), getCollectiveCommSyncMacroModel 53->38
  (addPingPongStagingPhases/addTReducePhases)
- PTOMaterializeTileOpSections: inferTileOpKind 77->28
  (classifyTileOpHelperOperation)
- VPTOStatefulStreamFusion: getLoopAddressCoefficient 61->22
  (computeCoefficientFromDef), parseStatefulStoreStream 52->45
- PTOValidateVMIIR: verifyLayoutSemanticSupport was already split on
  master into a 15-line dispatcher; its derived GroupReduction verifier
  is table-driven via member-function pointers (51->~28)
- PTOModule: populatePTODialectBindings 1309->9 (six semantic
  populate*Binding sections plus the existing submodule hook)
- ptoas_pipeline: runMainLoweringPipeline 99->39
  (populateMainLoweringPasses, finishVPTOMainPipeline)

Validated on the 144 host (LLVM 19.1.7 assert build, GCC 13.3) on top of
master b465f26: full build warning-free under -Werror and CTest 73/73.
Self-review of the new diff lines against the EChecker rule set found
two regressions of the very rules this series fixes: the moved
coefficient lambda still used a default [&] capture (G.RES.06), and the
extracted classifyTileOpHelperOperation landed at 55 nbnc (huge_method).
Use an explicit capture list and split the restriction checks into
rejectForbiddenTileHelperOperation (25 nbnc), leaving the classifier at
30. CTest 73/73 on the 144 assert build.
@jimmychou0 jimmychou0 closed this Sep 9, 2026
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.

1 participant