[llvm-dev] getting the value back from metadata

Alon Shaltiel (ashaltie) via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 15 03:11:20 PST 2016

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:


   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:



You should try mdconst::extract<ConstantInt> instead of cast<ConstantInt> (search in the codebase for example if needed).



but I get NULL… (although when pronting the MetadataAsValue I do see “i32 135”)

maybe the MDNode should be built in a different manner?



LLVM Developers mailing list
llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161115/f4967359/attachment-0001.html>

More information about the llvm-dev mailing list