Hello,<br>Thank you very much for the pointers.<br>I am are able to create new MDNodes, filled with some constants, and attach them<br>to llvm instructions. However, the metadata map is not getting updated as expected.<br>
For example, instead of the expected new entry<br><br>!n = metadata !{some values}<br><br>we are getting<br><br>!n = metadata !{null}<br><br>Do you know what might be wrong? Do we need to enter the MDNodes into the map explicitly?<br>
<br>Thank you,<br>Oksana<br><br><br><div class="gmail_quote">On Tue, Dec 20, 2011 at 7:25 PM, 陳韋任 <span dir="ltr"><<a href="mailto:chenwj@iis.sinica.edu.tw">chenwj@iis.sinica.edu.tw</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div class="h5">> Dear llvm-ers,<br>
> I am trying to attach a customized metadata to llvm instructions.<br>
> Let's say, I want to attach some number to each instruction.<br>
> I am trying to use<br>
><br>
> void Instruction::setMetadata(unsigned KindID, MDNode* Node)<br>
><br>
> but I am not sure how to create a brand new instance of an MDNode.<br>
> Do you have any code samples demonstrating how to do that?<br>
><br>
> Due to some tool dependencies, I am using LLVM 2.7<br>
<br>
</div></div>  `grep -r MDNode` in $LLVM_SOURCE may give you some examples.  I don't know if<br>
there is a doxygen for LLVM 2.7, but you can see include/llvm/Metadata.h and<br>
unittests/VMCore/MetadataTest.cpp to know how to create a MDNode. Below is code<br>
snipt taken form MetadataTest.cpp.<br>
<br>
---<br>
  MDString *s1 = MDString::get(Context, StringRef(&x[0], 3));<br>
  MDString *s2 = MDString::get(Context, StringRef(&y[0], 3));<br>
  ConstantInt *CI = ConstantInt::get(getGlobalContext(), APInt(8, 0));<br>
<br>
  std::vector<Value *> V;<br>
  V.push_back(s1);<br>
  V.push_back(CI);<br>
  V.push_back(s2);<br>
<br>
  MDNode *n1 = MDNode::get(Context, &V[0], 3);<br>
---<br>
<br>
HTH,<br>
chenwj<br>
<font color="#888888"><br>
--<br>
Wei-Ren Chen (陳韋任)<br>
Computer Systems Lab, Institute of Information Science,<br>
Academia Sinica, Taiwan (R.O.C.)<br>
Tel:886-2-2788-3799 #1667<br>
Homepage: <a href="http://people.cs.nctu.edu.tw/%7Echenwj" target="_blank">http://people.cs.nctu.edu.tw/~chenwj</a><br>
</font></blockquote></div><br>