Alon Shaltiel (ashaltie) via llvm-dev
2016-Nov-14 17:18 UTC
[llvm-dev] getting the value back from metadata
Hello, I'm trying to extract the value out of my MDNode, but for some reason I can't. For example, if one part of the code gets an MDNode that was created as follows: Metadata* vals[2] { ValueAsMetadata::get(&F), ValueAsMetadata::get(ConstantInt::get(context, 135)) }; MDNode* mdnode = MDNode::get(context, vals); Is it possible to extract the value of the constant int (135 in this case)? I tried using MetaDataAsValue as follows: cast<ConstantInt>(MetadataAsValue::get(context, mdnode->getOperand(1)))->getZExtValue() but I get NULL... (although when pronting the MetadataAsValue I do see "i32 135") maybe the MDNode should be built in a different manner? Thanks! Alon -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161114/bcd300a0/attachment.html>
Mehdi Amini via llvm-dev
2016-Nov-14 19:07 UTC
[llvm-dev] getting the value back from metadata
> On Nov 14, 2016, at 9:18 AM, Alon Shaltiel (ashaltie) via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Hello, > I’m trying to extract the value out of my MDNode, but for some reason I can’t. > > For example, if one part of the code gets an MDNode that was created as follows: > Metadata* vals[2] > { ValueAsMetadata::get(&F), ValueAsMetadata::get(ConstantInt::get(context, 135)) }; > MDNode* mdnode = MDNode::get(context, vals); > > Is it possible to extract the value of the constant int (135 in this case)? > > I tried using MetaDataAsValue as follows: > cast<ConstantInt>(MetadataAsValue::get(context, > mdnode->getOperand(1)))->getZExtValue() >You should try mdconst::extract<ConstantInt> instead of cast<ConstantInt> (search in the codebase for example if needed). — Mehdi> > > > but I get NULL… (although when pronting the MetadataAsValue I do see “i32 135”) > > maybe the MDNode should be built in a different manner? > > Thanks! > Alon > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161114/f41eab9f/attachment.html>
Alon Shaltiel (ashaltie) via llvm-dev
2016-Nov-15 11:11 UTC
[llvm-dev] getting the value back from metadata
Thanks a lot! J From: mehdi.amini at apple.com [mailto:mehdi.amini at apple.com] Sent: Monday, November 14, 2016 9:07 PM To: Alon Shaltiel (ashaltie) Cc: llvm-dev at lists.llvm.org Subject: Re: [llvm-dev] getting the value back from metadata On Nov 14, 2016, at 9:18 AM, Alon Shaltiel (ashaltie) via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote: Hello, I’m trying to extract the value out of my MDNode, but for some reason I can’t. For example, if one part of the code gets an MDNode that was created as follows: Metadata* vals[2] { ValueAsMetadata::get(&F), ValueAsMetadata::get(ConstantInt::get(context, 135)) }; MDNode* mdnode = MDNode::get(context, vals); Is it possible to extract the value of the constant int (135 in this case)? I tried using MetaDataAsValue as follows: cast<ConstantInt>(MetadataAsValue::get(context, mdnode->getOperand(1)))->getZExtValue() You should try mdconst::extract<ConstantInt> instead of cast<ConstantInt> (search in the codebase for example if needed). — Mehdi but I get NULL… (although when pronting the MetadataAsValue I do see “i32 135”) maybe the MDNode should be built in a different manner? Thanks! Alon _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161115/f4967359/attachment-0001.html>
Maybe Matching Threads
- [LLVMdev] prevent frontend from emitting i64
- [LLVMdev] Crash on invalid during LLVMContext destruction MDNode::dropAllReferences
- [LLVMdev] prevent frontend from emitting i64
- [LLVMdev] Metadata in the backend
- [LLVMdev] [RFC] Separating Metadata from the Value hierarchy