<div dir="ltr">If you just want to print %2 and not the whole instruction, I think you can use I.printAsOperand(errs())</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div>
<br><div class="gmail_quote">On Sat, Apr 7, 2018 at 11:43 AM, Zhizhong via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><span style="font-size:11px">Hi all,</span><div><span style="font-size:11px"><br></span></div><div><span style="font-size:11px">Consider a simple ll code:</span></div><div><span style="font-size:11px">%2 = load i32* %y, align 4</span></div><div><span style="font-size:11px"><br></span></div><div><span style="font-size:11px">I intend to get the memory address of %2.</span></div><div><span style="font-size:11px">if(isa<loadInst>(I)){</span></div><div><span style="font-size:11px"><span class="m_924545003168138244Apple-tab-span" style="white-space:pre-wrap">  </span>// variable name:y</span></div><div><span style="font-size:11px"><span class="m_924545003168138244Apple-tab-span" style="white-space:pre-wrap">        </span>value v = I.getOperand(0);</span></div><div><span style="font-size:11px"><span class="m_924545003168138244Apple-tab-span" style="white-space:pre-wrap">        </span>// ? I shows the entire instruction, not %2, then I.getName() would print an empty space which is %2, but I can’t get the memory when dereferencing it</span></div><div><span style="font-size:11px"><span class="m_924545003168138244Apple-tab-span" style="white-space:pre-wrap">  </span>errs()<< *&(I.getName())<<"\n”;</span></div><div><span style="font-size:11px">}</span></div><div><span style="font-size:11px"><br></span></div><div><span style="font-size:11px">error: taking the address of an temporary object of type llvm::stringRef.</span></div><div><span style="font-size:11px"><br></span></div><div><span style="font-size:11px">Please suggest what should I use to get the actual address of the register name %2.</span></div><div><span style="font-size:11px"><br></span></div><div><span style="font-size:11px">Thanks,</span></div><div><span style="font-size:11px">Ethan</span></div></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>