<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Sep 30, 2020, at 5:44 PM, Stefanos Baziotis via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class="">Hi everybody,<br class=""><br class="">I'm trying to get loop hotness data across a suite (e.g. the llvm test-suite). Ideally,<br class="">this would be a list that for each loop would list how many times it was entered and what<br class="">was its iteration count (at least the latter). The closest thing I could come up with is:<br class="">- clang -fprofile-instr-generate (without opts) to get a .profraw<br class="">- Get the .profdata<br class="">- Give that back to clang with -fprofile-instr-use and generate .ll<br class="">- I note that here we get "branch_weights" stats, so if a branch is a back-edge,<br class="">it basically gives us the iteration count. For example, check the bottom of this file: <a href="https://pastebin.com/ZnQqJdTN" class="">https://pastebin.com/ZnQqJdTN</a> which was created with the procedure above.<br class="">- Then, create a custom pass that goes through every loop and gathers this "branch_weights" data.<br class=""></div></div></div></blockquote><div>I second on this approach</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><br class="">I feel like this is both not very accurate and overly complicated for something that I<br class="">guess a lot of people probably have needed to gather in the past. Is there an easier<br class="">solution?<br class=""></div></div></div></blockquote><div>I don’t think PGO-based approach is very cumbersome. And it’s a lot more accurate than pure static approach. In case you don’t know, LLVM Test Suite has native support to build different stages of PGO program by toggling some cmake variable.</div><div>If I remember correctly, here are the steps:</div><div>1. Set cmake variable TEST_SUITE_PROFILE_GENERATE=ON, TEST_SUITE_IR_PGO=ON</div><div>2. `ninja all` + `llvm-lit -sv .` to build  and collect profile data</div><div>3. Modify variables in CMakeCache: TEST_SUITE_PROFILE_GENERATE=OFF, TEST_SUITE_PROFILE_USE=ON</div><div>4. ninja all</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><br class="">Thanks,<br class="">Stefanos</div></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></body></html>