FS#37877 - [llvm] view-cfg flag and others are broken

Attached to Project: Arch Linux
Opened by Dan Liew (delcypher) - Friday, 22 November 2013, 12:28 GMT
Last edited by Evangelos Foutras (foutrelis) - Tuesday, 09 September 2014, 12:04 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To Evangelos Foutras (foutrelis)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:
LLVM opt provides handy flags for viewing CFGs (-view-cfg) and Call graphs (-view-callgraph) of LLVM bitcode files. The packaged version of LLVM opt does not work (dot file is generated but viewer is not launched) because an appropriate viewer is not detected at configure time.


Additional info:
* llvm 3.3-1


Steps to reproduce:
1. Compile attached program to LLVM bitcode

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

2. Use opt to try and view CFG

$ opt -view-cfg -analyze hello.bc

Writing '/tmp/llvm_tolaIK/callgraph.dot'... done.
Printing analysis 'View call graph':
Pass::print not implemented for pass: 'View call graph'!

No viewing program will be launched.

I built my own copy of LLVM3.3 with (gv in my PATH) and that works fine. It seems the following programs are tried as viewers with the following order of precedence

- GraphViz (GraphViz) - I don't know what viewer this is, it's not in Arch repos
- xdot.py (xdot.py)
- GhostView (gv) - In Arch repos
- Dotty (dotty) - This tool seems broken. It won't render text correctly ( https://bugs.launchpad.net/ubuntu/+source/graphviz/+bug/1016777 )

See void llvm::DisplayGraph(const sys::Path &Filename, bool wait, GraphProgram::Name program) in lib/Support/GraphWriter.cpp for details on this.

Supporting one of these viewers would add extra dependencies that most people probably don't want. We could make "gv" an optional dependency though and make sure when LLVM3.3 is built gv and dot are in your PATH so that the package is configured to use ghostview and dot when trying to view graphs.

If the user doesn't have gv installed then they'll see

Writing '/tmp/llvm_r482Tr/callgraph.dot'... done.
Running '/usr/bin/dot' program... done.
Error: No such file or directory
Printing analysis 'View call graph':
Pass::print not implemented for pass: 'View call graph'!


This isn't particularly helpful, but it's better than no viewing support at all. Perhaps we could write a patch to improve the output if one the programs is missing and send that upstream?

   hello.c (0.4 KiB)
This task depends upon

Closed by  Evangelos Foutras (foutrelis)
Tuesday, 09 September 2014, 12:04 GMT
Reason for closing:  Fixed
Additional comments about closing:  llvm 3.5.0-1
Comment by Dan Liew (delcypher) - Friday, 22 November 2013, 12:44 GMT
Oh I thought I should mention that I tried out xdot.py, it's in the AUR ( https://aur.archlinux.org/packages/xdot-git/ ). It's a lot nicer to use than GhostView. If we do decide to support a graph viewer I would prefer it to be xdot.py although this would probably require xdot.py to get out of the AUR and end up in community if we want to make it an optional dependency.
Comment by Evangelos Foutras (foutrelis) - Sunday, 07 September 2014, 09:54 GMT
It should work with LLVM 3.5 (currently in [testing]) now that viewer detection is done at runtime.

I don't plan to add any optional dependencies though.

Loading...