<div dir="ltr">The old version was counting the number of basic blocks by iterating through them, because the list doesn't keep the count of items in it. So the complexity was linear in the number of basic blocks.<div>The new version counts the number of instructions also by iterating them. So the complexity is linear in the number of instructions.</div><div>This effectively adds another pass over the whole program code, more specifically, over all the MachineInstr`s, because the above iteration is performed for each function. However, this pass is as light as possible because it doesn't do anything for each instruction except counting it.</div><div>I believe this pass is performed only when `-fxray-instrument` option is specified, because XRayInstrumentation::runOnMachineFunction() is only run in that case.</div><div><br></div><div>Cheers,</div><div>Serge</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 8 June 2017 at 14:41, Dean Michael Berris <span dir="ltr"><<a href="mailto:dean.berris@gmail.com" target="_blank">dean.berris@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Hi Serge,</div><div id="m_8244200997618729246AppleMailSignature"><br></div><div id="m_8244200997618729246AppleMailSignature">Yes I like option 1 as well, if size() isn't actually the machine instruction count. My only concern might be the cost of counting the instructions, but if it's only when XRay instrumentation is on then this should be fine.</div><div id="m_8244200997618729246AppleMailSignature"><br></div><div id="m_8244200997618729246AppleMailSignature">Let me have a look at the patch.</div><div id="m_8244200997618729246AppleMailSignature"><br></div><div id="m_8244200997618729246AppleMailSignature">Cheers<br><br>Sent from my iPhone</div><div><div class="h5"><div><br>On 8 Jun 2017, at 9:26 pm, Serge Rogatch via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div>Hi Dean,</div><div><br></div><div>I've noticed that XRay in llvm\lib\CodeGen\<wbr>XRayInstrumentation.cpp compares its threshold against Function::size() . However, Function::size() returns the number of basic blocks (as I understand, such as cycle bodies, if/else bodies, switch-case bodies, etc.), rather than the number of instructions.</div><div><br></div><div>Was your intent to count the instructions instead? The name of the parameter -fxray-instruction-threshold=N suggests this, as well as XRay documentation at <a href="http://llvm.org/docs/XRay.html" target="_blank">http://llvm.org/docs/XRay.html</a> .</div><div>If so, I see two options:</div><div>1. Count the number of MachineInstr`s in MachineFunction : this gives better  estimate for the number of assembly instructions on the target. So a user can check in disassembly that the threshold works more or less correctly.</div><div>2. Count the number of Instruction`s in a Function : AFAIK, this gives correct number of IR instructions, which the user can check in IR listing. However, this number may be far (several times for small functions) from the number of assembly instructions finally emitted.</div><div><br></div><div>My team is in favor of option 1 (proposed patch here <a href="https://reviews.llvm.org/D34027" target="_blank">https://reviews.llvm.org/<wbr>D34027</a> ), because we think that having the closer estimate for the number of assembly instructions emitted is more important than to have a clear definition of the metric.</div><div><br></div><div>What do you think?</div><div><br></div><div>Cheers,</div><div>Serge</div></div>
</div></blockquote></div></div><blockquote type="cite"><div><span>______________________________<wbr>_________________</span><br><span>LLVM Developers mailing list</span><br><span><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a></span><br><span><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a></span><br></div></blockquote></div></blockquote></div><br></div>