Hello,<br>we figured out our problem: we were not grabbing the right context.<br>Here is a snippet of code that works for us, in case somebody would like to know:<br><br> //iterate over instructions<br><br> ConstantInt *CI = ConstantInt::get(getGlobalContext(), APInt(8, n));<br>
SmallVector<Value*, 1> V;<br>
V.push_back(CI);<br>
MDNode *Node = MDNode::get(Ins->getContext(), V.data(), V.size()); <br><br> Inst->setMetadata("mydata", Node);<br><br>Cheers,<br>Oksana<br><br><div class="gmail_quote">On Thu, Dec 22, 2011 at 8:14 AM, John Criswell <span dir="ltr"><<a href="mailto:criswell@illinois.edu">criswell@illinois.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><div class="im">
On 12/21/11 11:24 PM, Oksana Tkachuk wrote:
<blockquote type="cite">
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>
</blockquote>
<br></div>
If you look at PoolMDPass::runOnModule(), you'll see that the
MDNodes are stored in a container (ValueToPoolNodes) and that they
are added as operands to a NamedMDNode. I think you have to make
your MDNodes operands of a NamedMDNode in order to get them to work
properly.<br>
<br>
-- John T.<br>
<br>
<blockquote type="cite"><div><div></div><div class="h5"><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" target="_blank">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>> 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>
<a href="Tel:886-2-2788-3799" target="_blank">Tel:886-2-2788-3799</a> #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>
<br>
<fieldset></fieldset>
<br>
</div></div><pre>_______________________________________________
LLVM Developers mailing list
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
</blockquote>
<br>
</div>
</blockquote></div><br>