<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 1/26/18 1:04 AM, Linhai Song via
      llvm-dev wrote:<br>
    </div>
    <blockquote
cite="mid:CY4PR06MB23574B733B8B87BD2507EA1B81E00@CY4PR06MB2357.namprd06.prod.outlook.com"
      type="cite">
      <meta http-equiv="Context-Type" content="text/html;
        charset=iso-8859-1">
      <div id="divtagdefaultwrapper" dir="ltr">
        <p>Hello everyone,</p>
        <p><br>
        </p>
        <p>I am writing a pass to instrument program and count how many
          basic block executed. What I have tried is to instrument a
          local counter inside each function, add 1 to the local counter
          inside each basic block, and save the counter value to a
          global counter. The current runtime overhead is around 25%. Is
          there any way I can try to lower the overhead? Like keeping
          the local counter inside a register or applying the path
          profiling algorithm? <br>
        </p>
      </div>
    </blockquote>
    <br>
    By "local counter," I assume you mean that you created an alloca
    instruction that allocates memory and that you increment the value
    in this alloca'ed memory using a load, add, and store instruction. 
    Is that correct?<br>
    <br>
    If so, have you tried using the mem2reg pass to convert the local
    counter into a SSA virtual register?  That may speed it up a bit. 
    After that, other LLVM optimizations may be able to remove redundant
    instructions or combine additions.<br>
    <br>
    If that isn't enough, then you'll probably need to make your
    instrumentation smarter.  LLVM has passes that you can use to locate
    loops; if the loop has the right structure, you can increment the
    count at the end of the loop.  Likewise, if you can find control
    equivalent basic blocks, you only need to increment the counter in
    one of them.<br>
    <br>
    Regards,<br>
    <br>
    John Criswell<br>
    <br>
    <blockquote
cite="mid:CY4PR06MB23574B733B8B87BD2507EA1B81E00@CY4PR06MB2357.namprd06.prod.outlook.com"
      type="cite">
      <div id="divtagdefaultwrapper" dir="ltr">
        <p><br>
        </p>
        <p>Thanks a lot!</p>
        <p><br>
        </p>
        <p>Best,</p>
        <p><br>
        </p>
        <p>                         Linhai</p>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <br>
    <p><br>
    </p>
    <pre class="moz-signature" cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
  </body>
</html>