Hello, Thank you very much for the pointers. I am are able to create new MDNodes, filled with some constants, and attach them to llvm instructions. However, the metadata map is not getting updated as expected. For example, instead of the expected new entry !n = metadata !{some values} we are getting !n = metadata !{null} Do you know what might be wrong? Do we need to enter the MDNodes into the map explicitly? Thank you, Oksana On Tue, Dec 20, 2011 at 7:25 PM, 陳韋任 <chenwj at iis.sinica.edu.tw> wrote:> > Dear llvm-ers, > > I am trying to attach a customized metadata to llvm instructions. > > Let's say, I want to attach some number to each instruction. > > I am trying to use > > > > void Instruction::setMetadata(unsigned KindID, MDNode* Node) > > > > but I am not sure how to create a brand new instance of an MDNode. > > Do you have any code samples demonstrating how to do that? > > > > Due to some tool dependencies, I am using LLVM 2.7 > > `grep -r MDNode` in $LLVM_SOURCE may give you some examples. I don't > know if > there is a doxygen for LLVM 2.7, but you can see include/llvm/Metadata.h > and > unittests/VMCore/MetadataTest.cpp to know how to create a MDNode. Below is > code > snipt taken form MetadataTest.cpp. > > --- > MDString *s1 = MDString::get(Context, StringRef(&x[0], 3)); > MDString *s2 = MDString::get(Context, StringRef(&y[0], 3)); > ConstantInt *CI = ConstantInt::get(getGlobalContext(), APInt(8, 0)); > > std::vector<Value *> V; > V.push_back(s1); > V.push_back(CI); > V.push_back(s2); > > MDNode *n1 = MDNode::get(Context, &V[0], 3); > --- > > HTH, > chenwj > > -- > Wei-Ren Chen (陳韋任) > Computer Systems Lab, Institute of Information Science, > Academia Sinica, Taiwan (R.O.C.) > Tel:886-2-2788-3799 #1667 > Homepage: http://people.cs.nctu.edu.tw/~chenwj >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111221/eb8cf76b/attachment.html>
> I am are able to create new MDNodes, filled with some constants, and attach > them > to llvm instructions. However, the metadata map is not getting updated as > expected. > For example, instead of the expected new entry > > !n = metadata !{some values} > > we are getting > > !n = metadata !{null} > > Do you know what might be wrong? Do we need to enter the MDNodes into the > map explicitly?Maybe you can give us code snipt which you use to attach MDNode? Regards, chenwj -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj
On 12/21/11 11:24 PM, Oksana Tkachuk wrote:> Hello, > Thank you very much for the pointers. > I am are able to create new MDNodes, filled with some constants, and > attach them > to llvm instructions. However, the metadata map is not getting updated > as expected. > For example, instead of the expected new entryIf 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. -- John T.> > !n = metadata !{some values} > > we are getting > > !n = metadata !{null} > > Do you know what might be wrong? Do we need to enter the MDNodes into > the map explicitly? > > Thank you, > Oksana > > > On Tue, Dec 20, 2011 at 7:25 PM, ??? <chenwj at iis.sinica.edu.tw > <mailto:chenwj at iis.sinica.edu.tw>> wrote: > > > Dear llvm-ers, > > I am trying to attach a customized metadata to llvm instructions. > > Let's say, I want to attach some number to each instruction. > > I am trying to use > > > > void Instruction::setMetadata(unsigned KindID, MDNode* Node) > > > > but I am not sure how to create a brand new instance of an MDNode. > > Do you have any code samples demonstrating how to do that? > > > > Due to some tool dependencies, I am using LLVM 2.7 > > `grep -r MDNode` in $LLVM_SOURCE may give you some examples. I > don't know if > there is a doxygen for LLVM 2.7, but you can see > include/llvm/Metadata.h and > unittests/VMCore/MetadataTest.cpp to know how to create a MDNode. > Below is code > snipt taken form MetadataTest.cpp. > > --- > MDString *s1 = MDString::get(Context, StringRef(&x[0], 3)); > MDString *s2 = MDString::get(Context, StringRef(&y[0], 3)); > ConstantInt *CI = ConstantInt::get(getGlobalContext(), APInt(8, 0)); > > std::vector<Value *> V; > V.push_back(s1); > V.push_back(CI); > V.push_back(s2); > > MDNode *n1 = MDNode::get(Context, &V[0], 3); > --- > > HTH, > chenwj > > -- > Wei-Ren Chen (???) > Computer Systems Lab, Institute of Information Science, > Academia Sinica, Taiwan (R.O.C.) > Tel:886-2-2788-3799 #1667 > Homepage: http://people.cs.nctu.edu.tw/~chenwj > <http://people.cs.nctu.edu.tw/%7Echenwj> > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111222/f030d31a/attachment.html>
Hello, we figured out our problem: we were not grabbing the right context. Here is a snippet of code that works for us, in case somebody would like to know: //iterate over instructions ConstantInt *CI = ConstantInt::get(getGlobalContext(), APInt(8, n)); SmallVector<Value*, 1> V; V.push_back(CI); MDNode *Node = MDNode::get(Ins->getContext(), V.data(), V.size()); Inst->setMetadata("mydata", Node); Cheers, Oksana On Thu, Dec 22, 2011 at 8:14 AM, John Criswell <criswell at illinois.edu>wrote:> On 12/21/11 11:24 PM, Oksana Tkachuk wrote: > > Hello, > Thank you very much for the pointers. > I am are able to create new MDNodes, filled with some constants, and > attach them > to llvm instructions. However, the metadata map is not getting updated as > expected. > For example, instead of the expected new entry > > > 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. > > -- John T. > > > !n = metadata !{some values} > > we are getting > > !n = metadata !{null} > > Do you know what might be wrong? Do we need to enter the MDNodes into the > map explicitly? > > Thank you, > Oksana > > > On Tue, Dec 20, 2011 at 7:25 PM, 陳韋任 <chenwj at iis.sinica.edu.tw> wrote: > >> > Dear llvm-ers, >> > I am trying to attach a customized metadata to llvm instructions. >> > Let's say, I want to attach some number to each instruction. >> > I am trying to use >> > >> > void Instruction::setMetadata(unsigned KindID, MDNode* Node) >> > >> > but I am not sure how to create a brand new instance of an MDNode. >> > Do you have any code samples demonstrating how to do that? >> > >> > Due to some tool dependencies, I am using LLVM 2.7 >> >> `grep -r MDNode` in $LLVM_SOURCE may give you some examples. I don't >> know if >> there is a doxygen for LLVM 2.7, but you can see include/llvm/Metadata.h >> and >> unittests/VMCore/MetadataTest.cpp to know how to create a MDNode. Below >> is code >> snipt taken form MetadataTest.cpp. >> >> --- >> MDString *s1 = MDString::get(Context, StringRef(&x[0], 3)); >> MDString *s2 = MDString::get(Context, StringRef(&y[0], 3)); >> ConstantInt *CI = ConstantInt::get(getGlobalContext(), APInt(8, 0)); >> >> std::vector<Value *> V; >> V.push_back(s1); >> V.push_back(CI); >> V.push_back(s2); >> >> MDNode *n1 = MDNode::get(Context, &V[0], 3); >> --- >> >> HTH, >> chenwj >> >> -- >> Wei-Ren Chen (陳韋任) >> Computer Systems Lab, Institute of Information Science, >> Academia Sinica, Taiwan (R.O.C.) >> Tel:886-2-2788-3799 #1667 >> Homepage: http://people.cs.nctu.edu.tw/~chenwj >> > > > > _______________________________________________ > LLVM Developers mailing listLLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.eduhttp://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111223/c683df33/attachment.html>