<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 14, 2016, at 9:18 AM, Alon Shaltiel (ashaltie) via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="color: rgb(0, 32, 96);" class="">Hello,<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="color: rgb(0, 32, 96);" class="">I’m trying to extract the value out of my MDNode, but for some reason I can’t.<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="color: rgb(0, 32, 96);" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="color: rgb(0, 32, 96);" class="">For example, if one part of the code gets an MDNode that was created as follows:<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 9.5pt; font-family: Consolas; color: rgb(43, 145, 175); background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">Metadata</span><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">* vals[2] =<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">       {<span class="Apple-converted-space"> </span></span><span style="font-size: 9.5pt; font-family: Consolas; color: rgb(43, 145, 175); background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">ValueAsMetadata</span><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">::get(&</span><span style="font-size: 9.5pt; font-family: Consolas; color: gray; background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">F</span><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">),<span class="Apple-converted-space"> </span></span><span style="font-size: 9.5pt; font-family: Consolas; color: rgb(43, 145, 175); background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">ValueAsMetadata</span><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">::get(</span><span style="font-size: 9.5pt; font-family: Consolas; color: rgb(43, 145, 175); background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">ConstantInt</span><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">::get(</span><span style="font-size: 9.5pt; font-family: Consolas; color: gray; background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">context</span><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">, 135)) };<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 9.5pt; font-family: Consolas; color: rgb(43, 145, 175); background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">MDNode</span><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">* mdnode =<span class="Apple-converted-space"> </span></span><span style="font-size: 9.5pt; font-family: Consolas; color: rgb(43, 145, 175); background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">MDNode</span><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">::get(</span><span style="font-size: 9.5pt; font-family: Consolas; color: gray; background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">context</span><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">, vals);</span><span style="font-size: 9.5pt; font-family: Consolas;" class=""><o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="color: rgb(0, 32, 96);" class=""><o:p class=""> </o:p></span></div><table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="730" style="width: 437.9pt;"><tbody class=""><tr style="height: 146.4pt;" class=""><td style="padding: 0in; height: 146.4pt;" class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="color: rgb(0, 32, 96);" class="">Is it possible to<span class="Apple-converted-space"> </span></span><span style="font-size: 12pt; font-family: 'Times New Roman', serif; color: rgb(0, 32, 96);" class="">extract the value of the constant int (135 in this case)?<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 12pt; font-family: 'Times New Roman', serif; color: rgb(0, 32, 96);" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 12pt; font-family: 'Times New Roman', serif; color: rgb(0, 32, 96);" class="">I tried using MetaDataAsValue as follows:<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">cast<</span><span style="font-size: 9.5pt; font-family: Consolas; color: rgb(43, 145, 175); background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">ConstantInt</span><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">>(</span><span style="font-size: 9.5pt; font-family: Consolas; color: rgb(43, 145, 175); background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">MetadataAsValue</span><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">::get(context,<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 9.5pt; font-family: Consolas; background-color: white;" class="">                                 mdnode->getOperand(1)))->getZExtValue()</span><span style="font-size: 12pt; font-family: 'Times New Roman', serif; color: rgb(0, 32, 96);" class=""><o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 12pt; font-family: 'Times New Roman', serif; color: rgb(0, 32, 96);" class=""><o:p class=""> </o:p></span></div></td></tr></tbody></table></div></div></blockquote><font face="Times New Roman, serif" size="3" color="#002060" class=""><div><font color="#002060" face="Times New Roman, serif" size="3" class=""><br class=""></font></div><div><font color="#002060" face="Times New Roman, serif" size="3" class="">You should try </font>mdconst::extract<ConstantInt> instead of cast<ConstantInt> (search in the codebase for example if needed).</div><div><br class=""></div><div>— </div><div>Mehdi</div><div><br class=""></div><br class=""></font><blockquote type="cite" class=""><div class=""><div class="WordSection1" style="page: WordSection1; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""><table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="730" style="width: 437.9pt;"><tbody class=""><tr style="height: 146.4pt;" class=""><td style="padding: 0in; height: 146.4pt;" class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 12pt; font-family: 'Times New Roman', serif; color: rgb(0, 32, 96);" class=""><o:p class=""><br class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 12pt; font-family: 'Times New Roman', serif; color: rgb(0, 32, 96);" class=""><o:p class=""><br class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 12pt; font-family: 'Times New Roman', serif; color: rgb(0, 32, 96);" class="">but I get NULL… (although when pronting the MetadataAsValue I do see “<b class="">i32 135</b>”)<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 12pt; font-family: 'Times New Roman', serif; color: rgb(0, 32, 96);" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 12pt; font-family: 'Times New Roman', serif; color: rgb(0, 32, 96);" class="">maybe the MDNode should be built in a different manner?<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 12pt; font-family: 'Times New Roman', serif; color: rgb(0, 32, 96);" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 12pt; font-family: 'Times New Roman', serif; color: rgb(0, 32, 96);" class="">Thanks!<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 12pt; font-family: 'Times New Roman', serif; color: rgb(0, 32, 96);" class="">Alon<o:p class=""></o:p></span></div></td></tr></tbody></table><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-GB" style="color: rgb(0, 32, 96);" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">LLVM Developers mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:llvm-dev@lists.llvm.org" style="color: purple; text-decoration: underline; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">llvm-dev@lists.llvm.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" style="color: purple; text-decoration: underline; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></div></blockquote></div><br class=""></body></html>