[llvm-dev] getting the value back from metadata

Alon Shaltiel (ashaltie) via llvm-dev
Tue, 15 Nov 2016 11:11:20 -0000

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>