Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my opinion:</p> <h3>1. Is metadata the right mechanism to use?</h3> <p>If your "other tool" is not a pass in itself, then yes, I think metadata is the best approach - keeps everything in the IR, easy to identify by eye, simple to manually add for testing, and - perhaps most importantly - does not collide with anything else, as long as you don't reuse existing metadata kinds.</p> <p>However, if your "other tool" is a pass by itself, there's an alternative: you can make one pass dependent on the other, and than use information from the earlier directly in the later pass. The advantage is that you don't have to modify the IR.</p> <h3>2. How to use a custom metadata node?</h3> <p>Use the <code>char*</code> variant of <code>setMetadata</code>, like so:</p> <pre><code>LLVMContext&amp; C = Inst-&gt;getContext(); MDNode* N = MDNode::get(C, MDString::get(C, "my md string content")); Inst-&gt;setMetadata("my.md.name", N); </code></pre> <p>And if it's the first time the string is used in a <code>setMetadata</code>, it will automatically register <code>my.md.name</code> as a new kind in the module (it's actually consistent in the entire context, I believe). You can later on retrieve the string by using:</p> <pre><code>cast&lt;MDString&gt;(Inst-&gt;getMetadata("my.md.name")-&gt;getOperand(0))-&gt;getString(); </code></pre> <p>If you want to invoke <code>getMetadata</code> or <code>setMetadata</code> repeatedly from the same scope, though, you can also use <code>Module::getMDKindID</code> to just get the actual kind used, and use the variations of these methods that use the kind value.</p> <p>Finally, be aware that you can limit the metadata node scope to be inside a function - use the <code>MDNode::get(..., ..., true)</code> variant for that - though I never used it myself.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload