Skip to content

fix(ir): make parser arch context-scoped and add issue487 lit regression#490

Merged
zhangstevenunity merged 1 commit intohw-native-sys:mainfrom
Zhendong404:fix/issue-487-parser-arch-context
Apr 15, 2026
Merged

fix(ir): make parser arch context-scoped and add issue487 lit regression#490
zhangstevenunity merged 1 commit intohw-native-sys:mainfrom
Zhendong404:fix/issue-487-parser-arch-context

Conversation

@Zhendong404
Copy link
Copy Markdown
Contributor

Summary

This PR fixes parser-arch propagation for verifier fallback by replacing TLS parser-arch state with MLIRContext-scoped state.

Why

getVerifierTargetArch() can run during parse-time verification, and verifier may process IsolatedFromAbove children in parallel. TLS parser-arch is not shared across worker threads, which can cause A5 inputs to be mis-verified as A2/A3.

Using context-scoped arch state makes parser fallback deterministic across threads for the same MLIRContext.

Test

  • Build:
    • cmake --build build --target ptoas -j 8
  • Regression checks:
    • build/tools/ptoas/ptoas --pto-arch=a5 test/basic/issue487_tsel_i8_parser_arch_scope.pto -o - 2>&1 | FileCheck test/basic/issue487_tsel_i8_parser_arch_scope.pto --check-prefix=A5
    • build/tools/ptoas/ptoas --pto-arch=a3 test/basic/issue487_tsel_i8_parser_arch_scope.pto -o - 2>&1 | FileCheck test/basic/issue487_tsel_i8_parser_arch_scope.pto --check-prefix=A3

Closes #487

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 transitions the PTO parser's target architecture tracking from a thread-local variable to a context-aware mechanism using a global map and mutex. This change allows different MLIRContext instances to maintain their own architecture settings. A new test case was added to verify the parser-scope architecture fallback. Feedback suggests replacing the global map and mutex with an MLIRContext extension to avoid synchronization bottlenecks and potential memory leaks, aligning better with MLIR's architecture.

Comment on lines +24 to +26
std::mutex parserTargetArchMutex;
std::unordered_map<const MLIRContext *, PTOParserTargetArch>
parserTargetArchByContext;
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 a global map and mutex to store context-scoped state is generally discouraged in MLIR. It introduces a global synchronization bottleneck that can impact performance during parallel verification and risks memory leaks if MLIRContext objects are destroyed without explicitly clearing the map.

A more idiomatic and efficient approach is to use an MLIRContext extension. Extensions are owned by the context, ensuring their lifetime is correctly managed, and they avoid global locks for lookup.

Example implementation:

class PTOParserArchExtension : public MLIRContext::Extension {
public:
  using Extension::Extension;
  PTOParserTargetArch arch = PTOParserTargetArch::Unspecified;
};

// In get/set functions:
context->getOrCreateExtension<PTOParserArchExtension>().arch = arch;

@reedhecre
Copy link
Copy Markdown

Codex Review

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

Summary

未检查到 PR #490 存在问题

Findings

No issues found.

@zhangstevenunity zhangstevenunity merged commit 3372b65 into hw-native-sys:main Apr 15, 2026
11 checks passed
@reedhecre
Copy link
Copy Markdown

A3 板测完成(有跳过)

  • 触发方式:merged
  • 源码提交:3372b658f03e
  • 结果汇总:OK 184 / FAIL 0 / SKIP 1
  • 日志:/home/zhongxuan/ptoas-board-monitor/runtime/logs/20260415_174705_merged_pr490.log
  • 结果 TSV:/home/zhongxuan/ptoas-board-monitor/runtime/logs/20260415_174705_merged_pr490.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.

[Bug] --pto-arch=a5 may mis-verify pto.tsel(i8) as A2/A3 during parse-time verifier

3 participants