taichi-dev/taichi

[ir] Annotate each IR with file:lineno:[line content]?

Open

#949 创建于 2020年5月11日

在 GitHub 查看
 (8 评论) (2 反应) (1 负责人)C++ (2,384 fork)batch import
feature requestgood first issueirwelcome contribution

仓库指标

Star
 (28,195 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Concisely describe the proposed feature

Much like tb info, It will be great that when printing the IRs, they are annotated with file:lineno + actual line content. E.g.

  <i32 x1> $0 = const [680]  # foo.py:12, x[i] = *
  <i32 x1> $1 = const [680]
  <i32 x1> $2 = const [1]
  <i32 x1> $3 = const [1]    # foo.py:13, y[i] = *
  <i32 x1> $4 = const [-1]
  <i32 x1> $5 = const [0]
  <i32 x1> $6 = const [0]
  <i32 x1> $7 = alloca       # foo.py:14, x[i] += y[i]
  <i32 x1> $8 = const [0]
  <i32 x1> $9 = const [1048576]
  ...

Currently when looking at IR, I have no idea where they come from...

Describe the solution you'd like (if any)

  • Add a new field to IRNode, something like file_lineno_content. Maybe it's fine to only have lineno? Since most of the time we use Taichi in a single file, and we can always find out the line content from the lineno
  • When doing transformations, make sure to propgate this info to the new IR stmts that will be inserted. This way even after optimizations, we at least have an idea of which Python code lead to them.
  • Since many IR nodes will share the same file:lineno info, it's probably better to do string interning, and store pointers to these linenos in each IR node?

Additional comments Add any other context or screenshots about the feature request here.

贡献者指南