0

While trying to see the SelectionDag nodes generated during the instruction selection phase using LLVM (built from sources with debug mode enabled), I am using the below command which is not creating Graphviz DOT file.

llc -view-isel-dags sum.bc

Instead it is creating sum.s file. Is there something I'm missing here?

sum.c

int sum(int x, int y) {
  return x+y;
}

sum.bc

$ clang -emit-llvm sum.c -c -o sum.bc

LLVM information

$ llc -help-hidden | grep 'view-isel' -view-isel-dags - Pop up a window to show isel dags as they are selected

$ llvm-config --build-mode
Debug
compor
  • 2,239
  • 1
  • 19
  • 29
harry
  • 970
  • 6
  • 25
  • 1
    Usually the `-view` options create a DOT file in `/tmp` and directly open it in a GraphViz viewer. So, you can find the `.dot` file under `/tmp`. Looking at `SelectionDAGISel.cpp` it does not offer an option for just creating a `.dot` file. The `.s` is a product of the `llc` commands, since it lowers the IR to a specific assembly. – compor Aug 28 '18 at 10:25
  • Thanks for your quick reply. Ain't find the `.dot` file under `/tmp`. – harry Aug 28 '18 at 11:23
  • When issuing that command, I'm getting `Writing '/tmp/dag.compute_rhs-22fa16.dot'... done.` output lines. Don't you get anything similar? – compor Aug 28 '18 at 11:32
  • No, nothing is printing to the terminal. – harry Aug 28 '18 at 11:35
  • does `llc -help-hidden | grep 'view-isel'` return anything? Also, what does `llvm-config --build-mode` print? Can you please amend your question with this info, to avoid long discussion in the comments? – compor Aug 28 '18 at 11:40
  • Thanks, updated the question. – harry Aug 28 '18 at 11:48
  • I can't think of anything else that might affect this, apart from the actual `sum.bc` file. What is the initial source and how do you obtain the bitcode file? Again, amend the question please. Thanks – compor Aug 28 '18 at 12:01
  • Please repeat the steps, but in order to emit the bitcode use this command instead: `clang -O1 -Xclang -disable-llvm-passes -emit-llvm sum.c -c -o sum.bc` – compor Aug 30 '18 at 09:57
  • Thank you, updated answer. Let me know what you think. – harry Aug 30 '18 at 10:43
  • I suspect that the problem was that the `sum` function had the `optnone` attribute (you can search for that in the `.ll` file). This option disables any optimizations taking place over that function. The previous command I posted outputs IR without that option. After that, I was able to get the graph without any other changes. – compor Aug 30 '18 at 10:47
  • I guess you are right. But the option how does disable llvm passes enable optimization passes. Command is bit confusing. Could you please elaborate? – harry Aug 30 '18 at 11:02
  • That option does not annotate the function with the `optnone` attribute. After that you can use `opt` to run `-O2` or any optimization and also get the `fast-isel` DAGs in graphviz. – compor Aug 30 '18 at 11:05
  • Got it. Thank you so much – harry Aug 30 '18 at 11:07

1 Answers1

2

Guess the problem is with fast instruction selection which is enabled by default.

$ llc -debug sum.ll

Skipping pass 'X86 DAG->DAG Instruction Selection' on function sum

Changing optimization level for Function sum Before: -O2 ; After: -O0

FastISel is enabled

Disabling fastIsel resolved this problem.

$ llc -fast-isel=false -view-dag-combine1-dags sum.ll

harry
  • 970
  • 6
  • 25