1. 有时需要在编译器中使用static profiling来获取程序的信息,比如指令的执行次数,各分支的执行频率等。[1]提出来用于估计分支频率的启发式,[2]综合了[1],提出了用于估计分支频率以及指令执行频率的静态方法。
2. 在llvm中,已经有现成的static profiling [3] 实现,该实现正是基于[1]和[2]。此外,该实现的作者的硕士论文[4]详细地讨论了基于llvm的profiling。但是,该实现并没有集成到release里面。所以,需要手动添加。根据本人经验,手动添加进llvm 2.8没有什么问题;但是对于llvm 2.9貌似有点问题。
参考:
[1] Thomas Ball and James R. Larus. 1993. Branch prediction for free. In Proceedings of the ACM SIGPLAN 1993 conference on Programming language design and implementation (PLDI '93).
[2] Youfeng Wu and James R. Larus. 1994. Static branch frequency and program profile analysis. In Proceedings of the 27th annual international symposium on Microarchitecture (MICRO 27).
[3] http://homepages.dcc.ufmg.br/~rimsa/tools/stprof-llvm.patch
[4] llvm.org/pubs/2010-04-NeustifterProfiling.pdf.