<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; "><div id=":zt" class="kf" style="padding-left: 5px; padding-right: 5px; ">
<div class="km" style="margin-left: 1em; "><div id=":zu" class="kd" style="padding-left: 5px; color: rgb(119, 119, 119); "><span style="color: rgb(0, 0, 0);" dir="ltr" id=":13f">Hello all,<br><br>I am a LLVM newer who</span><span style="color: rgb(0, 0, 0);"> want to obtain the use-def chain for all instruction of a sample code, for this purpose i use the following code.</span><br>
</div></div></div></span></span><br><div style="margin-left: 40px;">///////////////sample code://///////////////////////<br>#include <stdlib.h><br>#include <stdio.h><br>#include <time.h><br> <br>#define ARRAY_SIZE 5<br>
<br><br>int main() {<br> int x, y, holder;<br> int k,z,f,i;<br> z=0;<br> f=0;<br> k=0;<br> <br> for(x = 0; x < ARRAY_SIZE; x++)<br> for(y = 0; y < ARRAY_SIZE-1; y++)<br> if(x+y>10) {<br> holder = x+y;<br>
k=z+1;<br> f=k+x;<br> if (i>k)<br> i=i+1;<br> }<br>// return 1;<br><br>}<br><br>////////////////////////pass code://///////////////////////////////<br> virtual bool runOnFunction(Function &F) {<br>
std::vector<Instruction*> worklist;<br> <br> for(inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I){<br> worklist.push_back(&*I);<br> }<br> <br> <br>
for(std::vector<Instruction*>::iterator iter = worklist.begin(); iter != worklist.end(); ++iter){<br> Instruction* instr = *iter;<br> errs() << "def: " <<*instr << "\n";<br>
for(Value::use_iterator i = instr->use_begin(), ie = instr->use_end(); i!=ie; ++i){<br> Value *v = *i;<br> Instruction *vi = dyn_cast<Instruction>(*i);<br>
errs() << "\t\t" << *vi << "\n";<br> }<br> }<br><br> return false;<br> }<br><br>//////////////output///////////////<br>def: ret void<br>
<br><br>but my output isn't my aim, <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; ">can anyone help me?<br>
<br>Thanks<br></span></span><br><br></div>