<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 09/15/2017 04:21 PM, Adam Nemet via
      llvm-dev wrote:<br>
    </div>
    <blockquote
      cite="mid:C23E6C49-CB7C-4733-8144-2F573E6D4EE7@apple.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      For better readability we typically create remarks and call
      OptimizationRemarkEmitter::emit unconditionally.  E.g.:
      <div class="">
        <div class=""><br class="">
        </div>
        <div class="">
          <div class="">Transforms/IPO/Inliner.cpp:  
             ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "TooCostly",
            Call)</div>
          <div class="">Transforms/IPO/Inliner.cpp-             <<
            NV("Callee", Callee) << " not inlined into "</div>
          <div class="">Transforms/IPO/Inliner.cpp-             <<
            NV("Caller", Caller) << " because too costly to inline
            (cost="</div>
          <div class="">Transforms/IPO/Inliner.cpp-             <<
            NV("Cost", IC.getCost())</div>
          <div class="">Transforms/IPO/Inliner.cpp-             <<
            ", threshold=" << NV("Threshold", IC.getThreshold())
            << ")");</div>
        </div>
        <div class=""><br class="">
        </div>
        <div class="">Then inside ORE we return right away if the
          remarks for the given pass is not enabled.
          <div class=""><br class="">
          </div>
          <div class="">This is nice and concise however there is still
            some overhead involved in this if remarks are not enabled:</div>
          <div class=""><br class="">
          </div>
          <div class="">1. Constructing the remark object</div>
          <div class="">2. Computing and inserting the strings,
            named-value arguments</div>
        </div>
        <div class="">3. Performing the comparison between the pass name
          and the passes enabled by the user</div>
        <div class="">4. Virtual destructor</div>
        <div class=""><br class="">
        </div>
        <div class="">Now that Vivek added support for asking
          LLVMContext for what remarks are enabled by the user [1] we
          can improve this.  The idea is to allow ORE::emit to take a
          closure.  This delays all this work until we know remarks are
          enabled.  E.g. the above code with closure:</div>
        <div class=""><br class="">
        </div>
        <div class="">
          <div class="">    ORE.emit(<b class="">[&]() {</b></div>
          <div class="">      <b class="">return</b>
            OptimizationRemarkMissed(DEBUG_TYPE, "TooCostly", Call)</div>
          <div class="">             << NV("Callee", Callee)
            << " not inlined into "</div>
          <div class="">             << NV("Caller", Caller)
            << " because too costly to inline (cost="</div>
          <div class="">             << NV("Cost", IC.getCost())</div>
          <div class="">             << ", threshold=" <<
            NV("Threshold", IC.getThreshold()) << ")"<b class="">;</b></div>
          <div class=""><b class="">    }</b>);</div>
        </div>
        <div class=""><br class="">
        </div>
      </div>
    </blockquote>
    <br>
    Makes sense to me. This will also give us a more-natural way to deal
    with constructing remarks where the remark construction itself is
    potentially expensive (e.g., involves doing some extra analysis or
    traversing data structures).<br>
    <br>
     -Hal<br>
    <br>
    <blockquote
      cite="mid:C23E6C49-CB7C-4733-8144-2F573E6D4EE7@apple.com"
      type="cite">
      <div class="">
        <div class=""><br class="">
        </div>
        <div class="">I have a proof-of-concept implementation at <a
            moz-do-not-send="true"
            href="https://reviews.llvm.org/D37921" class="">https://reviews.llvm.org/D37921</a>.</div>
        <div class=""> </div>
        <div class="">The main change is that since in the lambda the
          remark is now returned by value, we need to preserve its type
          in the insertion operator.  This requires making the
          insertion operator generic.  I am also curious if people see
          C++ portability problems with the code.</div>
        <div class=""><br class="">
        </div>
        <div class="">Feedback welcome.</div>
        <div class=""><br class="">
        </div>
        <div class="">Adam</div>
        <div class=""><br class="">
        </div>
        <div class="">[1] <a moz-do-not-send="true"
            href="https://reviews.llvm.org/D33514" class="">https://reviews.llvm.org/D33514</a></div>
      </div>
      <div class=""><br class="">
      </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>
    <pre class="moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
  </body>
</html>