<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="">Thanks Lorenzo,<div class=""><br class=""></div><div class="">I was looking for a ‘one level deeper’ analysis of how this works.</div><div class=""><br class=""></div><div class="">The issue is this: either information is preserved across certain sorts of transformations or it is not.  If not, it either goes stale (problematic for anything that looks at it later) or is invalidated/removed.</div><div class=""><br class=""></div><div class="">The fundamental issue in IR design is factoring the representation of information from the code that needs to inspect and update it.  “Metadata” designs try to make it easy to add out of band information to the IR in various ways, with a goal of reducing the impact on the rest of the compiler.</div><div class=""><br class=""></div><div class="">However, I’ve never seen them work out well.  Either the data becomes stale, or you end up changing a lot of the compiler to support it.  Look at debug info metadata in LLVM for example, it has both problems :-).  This is why MLIR has moved to make source location information and attributes a first class part of the IR.</div><div class=""><br class=""></div><div class="">-Chris</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jul 29, 2020, at 12:33 AM, Lorenzo Casalino 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="">
  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" class="">
  
  <div class="">
    <blockquote type="cite" cite="mid:mailman.12136.1595898758.1392.llvm-dev@lists.llvm.org" class="">
      <blockquote type="cite" style="" class="">
        <pre class="moz-quote-pre" wrap="">On Jul 27, 2020, at 10:11 AM, David Greene via llvm-dev <a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org" moz-do-not-send="true"><llvm-dev@lists.llvm.org></a> wrote:

Son Tuan VU via llvm-dev <a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org" moz-do-not-send="true"><llvm-dev@lists.llvm.org></a> writes:

</pre>
        <blockquote type="cite" style="" class="">
          <pre class="moz-quote-pre" wrap="">Currently metadata (other than debug info) can be attached to IR
instructions but disappears during DAG selection.

My question is why we do not keep the metadata during code lowering and
then attach to MachineInstr, just as for IR instructions? Is there any
technical challenge, or is it only because nobody wants to do so?
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">I have wanted codegen metadata for a very long time so I'm interested to
hear the history behind this choice, and more importantly, whether
adding such capability would be generally acceptable to the community.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">The first questions need to be “what does it mean?”, “how does it work?”, and “what is it useful for?”.  It is hard to evaluate a proposal without that.</pre>
    </blockquote><p class=""><tt class="">Hi everyone,</tt></p><p class=""><tt class="">I'm trying to answer to each of these questions; it is likely
        the answers won't be<br class="">
        exhaustive, but I hope they will serve as a starting point for
        an interesting<br class="">
        proposal (from my point of view and the one of </tt><tt class="">Son
        Tuan VU and </tt><tt class="">David Greene):</tt></p><p class=""><tt class="">- "What does it mean?": it means to preserve specific
        information, represented as<br class="">
          metadata assigned to instructions, from the IR level, down to
        the codegen phases.</tt></p><p class=""><tt class="">- "How does it work?": metadata should be preserved during
        the several<br class="">
           back-end transformations; for instance, during the lowering
        phase, DAGCombine<br class="">
           performs several optimization to the IR, potentially
        combining several<br class="">
           instructions. The new instruction should, then, assigned with
        metadata obtained<br class="">
           as a proper combination of the original ones (e.g., a union
        of metadata<br class="">
           information).</tt></p><p class=""><tt class="">   It might be possible to have a dedicated data-structure
        for such metadata info,<br class="">
           and an instance of such structure assigned to each
        instruction.<br class="">
      </tt></p><p class=""><tt class="">- "What is it useful for?": I think it is quite
        context-specific; but,<br class="">
          in general, it is useful when some "higher-level"<br class="">
          information (e.g., that can</tt><tt class=""> be discovered only before
        the back-end<br class="">
          stage of the compiler) are required in the back-end to perform
        "semantic"-related<br class="">
          optimizations.<br class="">
        <br class="">
      </tt></p><p class=""><tt class="">To give an (quite generic) example where such codegen
        metadata may be useful: in the field<br class="">
        of "secure compilation", preservation of security properties
        during the compilation<br class="">
        phases is essential; such properties are specified in the
        high-level specifications of<br class="">
        the program, and may be expressed with IR metadata. The
        possibility to keep such IR<br class="">
        metadata in the codegen phases may allow preservation of
        properties that may be invalidated<br class="">
        by codegen phases.</tt></p><p class=""><tt class=""><br class="">
      </tt></p><p class=""><tt class="">Cheers,<br class="">
        -- Lorenzo<br class="">
      </tt></p>
    <blockquote type="cite" cite="mid:mailman.12136.1595898758.1392.llvm-dev@lists.llvm.org" class="">
      <pre class="moz-quote-pre" wrap="">Metadata isn’t free - it must be maintained or invalidated for it to be useful.  The details on that dramatically shape whether it can be used for any given purpose.

-Chris</pre>
    </blockquote>
  </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=""></div></body></html>