taichi-dev/taichi

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

Open

#949 opened on May 11, 2020

View on GitHub
 (8 comments) (2 reactions) (1 assignee)C++ (28,195 stars) (2,384 forks)batch import
feature requestgood first issueirwelcome contribution

Description

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.

Contributor guide