[llvm-dev] Dump LLVM StoreInst

Zhou Zhizhong via llvm-dev llvm-dev at lists.llvm.org
Fri Mar 9 20:25:05 PST 2018


Hi Craig,

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.

Actually it is how to get the value of the stored Instruction which stuck me. 

Eg. (I’ve modified the code below)

int b = 2, (below shows the correspond bitcode) 
store i32 2, i32* %b, align 4

v1 would dump the memory address of this value, through v1->getName() I was able to get the variable name which is b. They are close to what I want to achieve.


In the same time, consider c = b;  then the code becomes: 
%4 = load i32* %b , align 4 
store i32 %4, i32* %c, align 4

There is an intermediate register name %4 which I have no idea how to print it out.


Perhaps the most weird thing is this, I can dump inc this time although it was not named.
%5 = load i32* %i, align 4
%inc = add nsw i32 %5, 1
store i32 %inc, i32* %i, align 4


I’ve attached the related files in this gist.
https://gist.github.com/zzz686970/a147e894ff79c09069caf9704cbffbeb

Sorry don’t want to take too much of your time, but in summary my question would be:

1. How to print out values of my variable in llvm?
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.

Thanks,
Ethan

> On 10 Mar 2018, at 09:37, Craig Topper <craig.topper at gmail.com> wrote:
> 
> 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.
> 
> ~Craig
> 
> On Fri, Mar 9, 2018 at 9:18 AM, Zhou Zhizhong via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
> Hi,
> 
> 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.
> 
> if (isa<StoreInst>(I)){
>     Value* v = I.getOperand(0);
	   Value* v1 = I.getOperand(1);
>     Instruction* op1 = dyn_cast<Instruction>(v);
           errs() <<“v1:" << “\t” <<v1<< “,\t"<< v1->getName()<<“\n”;
         if(op1 != nullptr){
>     errs()<<“v:” <<“\t”<< v << “,\t" << v->getName()<<“,\t"<<op1<<\n”
         }
> }
> 
> Any suggestions on this?
> 
> Thanks,
> Ethan
> 
> 
> 
> 
> _______________________________________________
> 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 <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/20180310/227f5632/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-1.png
Type: image/png
Size: 51949 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180310/227f5632/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-2.png
Type: image/png
Size: 50074 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180310/227f5632/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-3.png
Type: image/png
Size: 53736 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180310/227f5632/attachment-0005.png>


More information about the llvm-dev mailing list