How to Get All Functions Module

Now, I try to build a CallGraph with some other information for a large C++ project by my IR PASS. When I traverse all functions in the module, like "for (Function &F : M) ". I noticed that the module only contains functions called, while other functions which not be called mostly not be traversed.

So my questions is how to get all functions contains which not be used in a large C++ project.

I’ve chatted with @G-MXD, adding some context here. What @G-MXD doing here is building the whole program Call Graph and doing the whole program analysis further. So she adopts the approach that builds llvm full lto pass plugin and registers it at the EP_FullLinkTimeOptimizationEarly point.

The reason why full lto will remove the unused functions here is that it trying to compute the dead symbols with the root set {main()} at the very beginning of the full lto plugin, i.e. before EP_FullLinkTimeOptimizationEarly. So the llvm full lto pass plugin cannot see the whole picture.

Maybe we can make the computeDeadSymbolsWithConstProp() more configurable to support the raw whole module IR.

Update. As the article “Linker garbage collection | MaskRay” points out, there is a flag -mllvm -compute-dead=true which can control the computeDeadSymbolsWithConstProp() function. So we can use -mllvm -compute-dead=false to get the raw whole IR.