<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Craig,<div class=""><br class=""></div><div class="">Sorry for my typos, yes you are right the print variables and ‘-' are wrong, and thanks for the useful tip for checking dyn_cast result before using it.</div><div class=""><br class=""></div><div class="">Actually it is how to get the value of the stored Instruction which stuck me. </div><div class=""><br class=""></div><div class="">Eg. (I’ve modified the code below)</div><div class=""><br class=""></div><div class=""><b class="">int b = 2</b>, (below shows the correspond bitcode) </div><div class=""><b class=""><font color="#ff40ff" class="">store i32 2, i32* %b, align 4</font></b></div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">v1</b> would dump the memory address of this value, through <b class="">v1->getName()</b> I was able to get the variable name which is <b class="">b.</b> They are close to what I want to achieve.</div><div class=""><img apple-inline="yes" id="6DA681DD-FE3D-4625-8855-725668CDB938" width="320" height="77" src="cid:F324750F-7EAD-4AB7-800E-997FEE0D23F5@comp.nus.edu.sg" class=""></div><div class=""><br class=""></div><div class="">In the same time, consider <b class="">c = b</b>;  then the code becomes: </div><div class=""><b class="">%4 = load i32* %b , align 4 </b></div><div class=""><b class=""><font color="#ff40ff" class="">store i32 %4, i32* %c, align 4</font></b></div><div class=""><br class=""></div><div class="">There is an intermediate register name <b class="">%4 </b>which I have no idea how to print it out.</div><div class=""><img apple-inline="yes" id="85BB37A2-103B-47E7-9155-1C862919DA5C" width="320" height="72" src="cid:663806F3-670C-43DF-BE74-0CE4AC25A3C3@comp.nus.edu.sg" class=""></div><div class=""><br class=""></div><div class="">Perhaps the most weird thing is this, I can dump inc this time although it was not named.</div><div class=""><b class="">%5 = load i32* %i, align 4</b></div><div class=""><b class="">%inc = add nsw i32 %5, 1</b></div><div class=""><b class=""><font color="#ff40ff" class="">store i32 %inc, i32* %i, align 4</font></b></div><div class=""><img apple-inline="yes" id="F10E2706-7C85-4EC8-8B3D-96A1C4BF19C5" width="320" height="66" src="cid:6B1374EA-AC03-4571-A914-3435091C0909@comp.nus.edu.sg" class=""></div><div class=""><br class=""></div><div class="">I’ve attached the related files in this gist.</div><div class=""><a href="https://gist.github.com/zzz686970/a147e894ff79c09069caf9704cbffbeb" class="">https://gist.github.com/zzz686970/a147e894ff79c09069caf9704cbffbeb</a></div><div class=""><br class=""></div><div class="">Sorry don’t want to take too much of your time, but in summary my question would be:</div><div class=""><br class=""></div><div class="">1. How to print out values of my variable in llvm?</div><div class="">2. In terms of intermediate register names, is there a way to print out them too? If not, maybe I can print the memory address, but it may not help me track the updated values.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Ethan</div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 10 Mar 2018, at 09:37, Craig Topper <<a href="mailto:craig.topper@gmail.com" class="">craig.topper@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div dir="ltr" class="">The code you've pasted there is inconsistent in variable names. Your created an instruction called 'op1' but your print uses 'v1'. What should be an '->' is just a '-'. You also have a variable in your print called 'op' but that's not declared in your code. Also the result of dyn_cast should always be checked for null before using the result.</div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div>
<br class=""><div class="gmail_quote">On Fri, Mar 9, 2018 at 9:18 AM, Zhou Zhizhong via llvm-dev <span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br class="">
<br class="">
I’m writing a loop-free LLVM pass, my thought is to track if the value inside the loop is changed, so I look up the Instruction StoreInst first and try to get its value in a set. I checked getValueOperand(), getValueName() in the API document but unfortunately they failed the compilation.<br class="">
<br class="">
if (isa<StoreInst>(I)){<br class="">
    Value* v = I.getOperand(0);<br class=""></blockquote></div></div></div></blockquote><span class="Apple-tab-span" style="white-space:pre"> </span>  <font color="#942192" class=""> Value* v1 = I.getOperand(1);</font><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    Instruction* op1 = dyn_cast<Instruction>(v);<br class=""></blockquote></div></div></div></blockquote> <font color="#942192" class="">          errs() <<“v1:" << “\t” <<v1<< “,\t"<< v1->getName()<<“\n”;</font><br class=""><font color="#942192" class="">         if(op1 != nullptr){<br class=""></font><blockquote type="cite" class=""><div class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><font color="#942192" class="">
    errs()<<“v:” <<“\t”<< v << “,\t" << v->getName()<<“,\t"<<op1<<\n”</font></blockquote></div></div></div></blockquote><font color="#942192" class="">         }</font><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
}<br class="">
<br class="">
Any suggestions on this?<br class="">
<br class="">
Thanks,<br class="">
Ethan<br class="">
<br class="">
<br class="">
<br class="">
<br class="">______________________________<wbr class="">_________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/llvm-dev</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></body></html>