The opt compiler can dump its IR in text format at various points between optimization passes. Reading a control flow graph (CFG) as straight-line text, rather than as a graph, is not ideal.
The attached patch, authored by Aritra Sengupta and refactored by me, enables generating a representation of the CFG. It adds two new opt compiler options:
VISUALIZE_IR – if enabled, any time the IR would be dumped as text, it will instead be written as a .graph file
VISUALIZE_IR_DIRECTORY – the directory to write .graph files to ("." by default)
The implementation generates .graph files whose names include class and method info, as well as a timestamp in an effort to get name uniqueness from run to run.
The .graph files can be viewed or converted to other formats like PDF by using Graphviz tools such as dot and dotty.