Merged
feat(IR): frontend pass output new format IR #5459
feat(IR): frontend pass output new format IR #5459
Merged
Jie YinAdd on Aug 15
Jie Yin
Jie YinCollaborators
Aug 15

feat(IR): frontend pass output new format IR

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for Jie Yin's contribution.)
Jie YinJie YinCollaborators
Aug 15 Created pull request, commit 29fe9bf1
atomgit-bot
atomgit-bot
Aug 15 Comments:

变更摘要

该 PR 主要将前端 pass 输出的 IR 从旧的类 Python 文本格式切换到新的文本 IR 格式(如 function foo incast(...) outcast() ...),并为 Python 侧的 ir.Function 绑定新的字符串表示。核心实现位于 io_text_dumper.cpp / io_text_loader.cpp:文本输出器支持可选字段的空值处理,文本加载器同步支持解析可选字段;同时通过 io_text.h 的 TextDump 暴露 Function.__str__。此外,大量 IR 相关测试从内联旧格式 IR 字符串迁移为读取 .pypto 黄金文件,并更新了对应的断言与快照。

主要改动

  • 新增 Function 的 Python 字符串表示:在 python/src/bindings/ir/ir.cpp 中引入 ir/transforms/io_text.h,并为 Function 类绑定 __str__,使其通过 TextDump(self) 输出新的文本 IR。
  • 文本输出器支持可选字段:io_text_dumper.cpp 中 VisitType_ 仅在 tv.ptr.has_value() 时输出指针表达式;VisitStmt_ 对 IfStmt 在 elseBody_ 缺失时输出空 {},避免直接访问空 optional。
  • 文本加载器支持可选字段解析:io_text_loader.cpp 使用 CheckToken(LexerTokenKind::PunComma, true) 判断是否存在指针表达式,并据此构造带指针或 TensorView 的两种形态。
  • merge pass 测试迁移到 .pypto 黄金文件:test_merge_pass/*.py 移除内联的旧格式 IR 字符串,改为通过 Path 读取同目录下的 *.pypto 文件,并新增多个新格式黄金文件。
  • 更新测试断言与快照:test_ir.py、test_infer_pass.py、test_pil.py、test_enum_kwarg_resolution.py、test_tiling.py 等测试的期望输出改为新格式,例如 "= continue" 变为 "continue %loop_idx_"、"tiling[0]" 变为 "getitem(%tiling, 0)"。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Aug 15 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
Jie YinJie YinCollaborators
Aug 15 Modify description of pull request
CANN-robotCANN-robotCollaborators
Aug 15 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 15 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
For more, you also can visit HICANN


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/pypto ✅ tsungl4, congqiannan (2/2) ✅ congqiannan (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

yinjie27_, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
Aug 15 Set xinweiliu,cam_bxh,dai-zhentao,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,congqiannan,zhangyuebing,tsungl4,gaoxingwang,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
10 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Aug 15 Added label: cann-cla/yes
Jie Yin
Jie YinCollaborators
Aug 15 Comments:

compile

likedislike
Jie YinJie YinCollaborators
Aug 15 Pre merge succeeded (commit_id: cb032101b275a9a67d28ac4f8431b54c3134e50b)
CANN-robotCANN-robotCollaborators
Aug 15 Added label: ci-pipeline-running
CANN-robot
CANN-robotCollaborators
Aug 15 Comments:

流水线任务触发成功
任务链接 [abcc826d29d344d19345a54fcea721bb][流水线指导]

likedislike
CANN-robot
CANN-robotCollaborators
Aug 15 Comments:

流水线任务触发成功
任务链接 [446549dce7b74a31bb93be4173421ebc][流水线指导]

任务名称状态日志下载链接
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
codecheck_codestyle ⚠️ WARNING >>>>>
codecheck_precommit ✅ SUCCESS >>>>>
StaticCheck_md ✅ SUCCESS

[2026-08-15 17:30:02]    CI执行结束

likedislike
CANN-robot
CANN-robotCollaborators
Aug 15 Comments:

流水线任务触发成功
任务链接 [abcc826d29d344d19345a54fcea721bb][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
pre_comment ❌ FAILED >>>>>
likedislike
CANN-robot
CANN-robotCollaborators
Aug 15 Comments:

流水线任务触发成功
任务链接 [193fab9091bc40298e673a4ace2b39c8][流水线指导]

任务名称状态日志下载链接
get_pr_file ✅ SUCCESS
static-check ✅ SUCCESS
compile ❌ FAILED
likedislike
CANN-robotCANN-robotCollaborators
Aug 15 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Aug 15 Added label: ci-pipeline-failed
Jie YinJie YinCollaborators
Aug 15 Associated issue: [Task|任务跟踪]: 新IR适配
CANN-robotCANN-robotCollaborators
Aug 15 Removed label: ci-pipeline-failed
CANN-robotCANN-robotCollaborators
Aug 15 Added label: ci-pipeline-running
CANN-robot
CANN-robotCollaborators
Aug 15 Comments:

流水线任务触发成功
任务链接 [e8baeb67c6e944ca8348722986062a3f][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
UT_Test_Py3_ninja_simulation ✅ SUCCESS
UT_Test_Py3_ninja ✅ SUCCESS
UT_Test_Cpp_make_gnu_part_1 ✅ SUCCESS
UT_Test_Cpp_make_gnu_part_2 ✅ SUCCESS
UT_Test_Cpp_make_gnu_part_3 ✅ SUCCESS
UT_Test_Cpp_make_clang_part1 ✅ SUCCESS
UT_Test_Cpp_make_clang_part2 ✅ SUCCESS
UT_Test_Cpp_make_clang_part3 ✅ SUCCESS
UT_Test_kirinx90 ✅ SUCCESS
UT_Test_kirin9030 ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>

[2026-08-15 18:05:28]    CI执行结束

likedislike
CANN-robot
CANN-robotCollaborators
Aug 15 Comments:

流水线任务触发成功
任务链接 [193fab9091bc40298e673a4ace2b39c8][流水线指导]

任务名称状态日志下载链接
get_pr_file ✅ SUCCESS
static-check ✅ SUCCESS
compile ✅ SUCCESS

[2026-08-15 18:06:07]    CI执行结束

likedislike
CANN-robotCANN-robotCollaborators
Aug 15 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Aug 15 Added label: ci-pipeline-passed
congqiannan
congqiannanCollaborators
Aug 15 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 15 Added label: approved
lidongsheng
lidongshengCollaborators
Aug 15 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Aug 15 Added label: lgtm
CANN-robotCANN-robotCollaborators
Aug 15 Merged pull request