We can use llc to convert a.bc to a.s, and even visualize SelectionDAG on LLVM debug version:
1 2 3 4
$ llc a.bc -o a.s $ llc -view-xxxxxx-dags a.ll # "--help" to see all DAG generation options, # and the graph saved in "dot"
And to execute a.bc directly:
1 2
$ lli a.bc Max value is : 200
Actually the intermediate files can be converted to exetuable a.out by using clang directly:
1
$ clang a.s/a.c/a.xxx a.out
LLVM Graph Structure Generation
LLVM framework is so powerful, that it can automatically generate control flow graph, and we can visualize it easily. First we generate CFG using opt:
1 2 3 4 5
$ opt -enable-new-pm=0 -analyze -dot-cfg-only a.ll Writing '.main.dot'... Printing analysis 'Print CFG of function to 'dot' file (with no function bodies)' for function 'main': Writing '.max.dot'... Printing analysis 'Print CFG of function to 'dot' file (with no function bodies)' for function 'max':
$ opt -h|grep "\-cfg" --cfg-hide-cold-paths=<number> - Hide blocks with relative frequency below the given value --cfg-hide-deoptimize-paths - --cfg-hide-unreachable-paths - --dot-cfg-mssa=<file name for generated dot file> - file name for generated dot file --dot-cfg - Print CFG of function to 'dot' file --dot-cfg-only - Print CFG of function to 'dot' file (with no function bodies) --print-cfg-sccs - Print SCCs of each function CFG --view-cfg - View CFG of function --view-cfg-only - View CFG of function (with no function bodies) --wasm-cfg-sort - Reorders blocks in topological order --wasm-cfg-stackify - Insert BLOCK/LOOP/TRY markers for WebAssembly scopes
$ opt -h|grep callgraph --dot-callgraph - Print call graph to 'dot' file --print-callgraph - Print a call graph --print-callgraph-sccs - Print SCCs of the Call Graph --view-callgraph - View call graph