taichi-dev/taichi

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

Open

#949 geöffnet am 11. Mai 2020

Auf GitHub ansehen
 (8 Kommentare) (2 Reaktionen) (1 zugewiesene Person)C++ (2.384 Forks)batch import
feature requestgood first issueirwelcome contribution

Repository-Metriken

Stars
 (28.195 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

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