Custom Flow Graph representation and data extraction
clang -g -S -emit-llvm code.c -Xclang -disable-O0-optnone -o code.ll
path/to/opt -load /path/to/lib/LLVMFG.so -enable-new-pm=0 -printFGNL < code.ll > /dev/null
path/to/opt -load /path/to/lib/LLVMFG.so -enable-new-pm=0 -basic-aa -mem2reg -simplifycfg -loop-simplify -loop-rotate -simplifycfg -instcombine -indvars -da -analyze -printFG < code.ll > /dev/null
-
dot files that can be used to generate a picture of the FG of all the functions
-
files that contains information about the functions in the code
[node_id, llvm_inst_opcode, num_operands, operands_size, [operand0_type, operand1_type..], is_array, array_size, in_loop]
Loopid{
[loop_stride, trip_count, depth]
innerloopid{
[loop_stride, trip_count, depth]
[node_id, llvm_inst_opcode, num_operands, operands_size, [operand0_type, operand1_type..], is_array, array_size, in_loop]
[node_id, llvm_inst_opcode, num_operands, operands_size, [operand0_type, operand1_type..], is_array, array_size, in_loop]
...
end innerloopid}
[node_id, llvm_inst_opcode, num_operands, operands_size, [operand0_type, operand1_type..], is_array, array_size, in_loop]
[node_id, llvm_inst_opcode, num_operands, operands_size, [operand0_type, operand1_type..], is_array, array_size, in_loop]
...
...
end loopid}
NOTE: loop_stride, trip_count, depth are reliable only with additional pass (-basic-aa -mem2reg -simplifycfg -loop-simplify -loop-rotate -simplifycfg -instcombine -indvars -da -analyze)
FunctionName{
BB0[#nodes_in_bb0,in_loop_bb0,[(inst1:#inst1),(inst2:#inst2),..,(otherinst:0)]]
BB1[#nodes_in_bb1,in_loop_bb1,[(inst1:#inst1),(inst2:#inst2),..,(otherinst:0)]]
...
}
dot -Tpng mainFG.dot -o mainFG.png
- Green Box: Basic Blocks in a Loop
- Blue Box: Basic Blocks outside a Loop
- Red Box: Loop (Nested loops are darker)
- Red edge: Control Flow dependence
- Black edge: Data dependence
- Gold edge: Data dependence that refers to a function argument
- Gold dashed edge: Reference to the base address of an array/structure that is a function parameter
- Darkgreen dashed edge: Reference to the base address of an local array/structure
cat function_1_loopdata
Loop0 {
[3, 3, 1]
[119, 55, 2, 64, int, int, 0, -1, 1]
[120, 56, 4, 64, ptr, 0, -1, 1]
[121, 34, 3, 64, ptr, int, int, 0, -1, 1]
[122, 33, 2, 64, int, ptr, 0, -1, 1]
[123, 13, 2, 64, int, int, 0, -1, 1]
[124, 56, 4, 64, ptr, 0, -1, 1]
[125, 53, 2, 64, int, int, 0, -1, 1]
[126, 2, 3, 1, int, 0, -1, 1]
End Loop0 }
TODO:
- organize code in functions
- fix some bug that create wrong cdfg dot file
- ignore llvm debug instruction