[llvm-dev] Writing a pass to retrieve instruction operand value

Ammar Naqvi via llvm-dev llvm-dev at lists.llvm.org
Mon Apr 25 21:25:52 PDT 2016


Hi Everyone,

I asked a question on the dev list related to the topic to which John
Criswell and Jeremy Lakeman kindly provided some valuable insight.

I'm still stuck on the issue and i'm hoping i didn't phrase the question
well enough.

I have a *foo.c* file that is :

*#include <stdio.h>*
*int foo(int a, int b){*

*  return a+b;*
*}*

*int main() {*
*int x=foo(3,1);  *
*printf("%d\n",x);*
*return 0;*
*}*

Now, i obtain the foo.bc/foo.ll file,
the code i'm interested in looks like:

*; Function Attrs: norecurse nounwind readnone uwtable*
*define i32 @addd(i32 %a, i32 %b) #0 {*
*entry:*
*  %add = add nsw i32 %b, %a*
*  ret i32 %add*
*}*

running the file with *lli* *foo.ll outputs *

*4*

Now we know that the values of %a and %b are 3 and 1 respectively, is there
any way i can retrieve these values by running foo.bc through a pass??

I know i->getOperand(0) would get me *i32 %a *
i->getOperand(1) would get me *i32 %b*

*How do i retrieve 3 and 1, the integer values that these operands hold ?*

Thanks in advance for any guidance and help! :)

Best Regards,
Ammar Naqvi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160425/0c48ca6a/attachment.html>


More information about the llvm-dev mailing list