<div dir="ltr">This is only the IR if you don't call mem2reg, which does SSA conversion.<div><br></div><div>The IR you have listed operates on memory, and memory is not in SSA.  If you run mem2reg on it, you will see what John mentioned, and that is what most people would refer to.</div><div><br></div><div>The answer for memory operations is "no, you cannot find all the places a given memory is *actually* defined". You can use memorydependence and find the places it *may be defined*, but this may be a large set and include false positives"</div><div>The question of finding which memory locations are must-modified is statically undecidable :)</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 27, 2016 at 6:58 PM, Syed Rafiul Hussain 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">Thank you all for your reply.<br>
<br>
if(a>10)<br>
 b=10;<br>
else if (a<10)<br>
 b = 5;<br>
Here is the IR of the if-elseif:<br>
<br>
 56   %0 = load i32, i32* %a, align 4<br>
 57   %cmp = icmp sgt i32 %0, 10<br>
 58   br i1 %cmp, label %if.then, label %if.else<br>
 60 if.then:                                          ; preds = %entry<br>
 61   store i32 10, i32* %b, align 4<br>
 62   br label %if.end.4<br>
 63<br>
 64 if.else:                                          ; preds = %entry<br>
 65   %1 = load i32, i32* %a, align 4<br>
 66   %cmp2 = icmp slt i32 %1, 10<br>
 67   br i1 %cmp2, label %if.then.3, label %if.end<br>
 68<br>
 69 if.then.3:                                        ; preds = %if.else<br>
 70   store i32 5, i32* %b, align 4<br>
 71   br label %if.end<br>
 72<br>
 73 if.end:                                           ; preds =<br>
%if.then.3, %if.else<br>
 74   br label %if.end.4<br>
 75<br>
 76 if.end.4:                                         ; preds =<br>
%if.end, %if.then<br>
 77   %2 = load i32, i32* %a, align 4<br>
 78   %call5 = call dereferenceable(272) %"class.std::basic_ostream"*<br>
@_ZNSolsEi(%"class.std::basic_ostream"* @_ZSt4cout, i32 %2)<br>
 79   %3 = load i32, i32* %b, align 4<br>
 80   %call6 = call dereferenceable(272) %"class.std::basic_ostream"*<br>
@_ZNSolsEi(%"class.std::basic_ostream"* %call5, i32 %3)<br>
 81   ret i32 0<br>
<br>
<br>
at line 79 of the IR, I have found %b. Now I would like to find lines<br>
61 and 70 where %b has been assigned with some values using store<br>
instruction. Can I achieve this at IR level?<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Wed, Jan 27, 2016 at 9:15 PM, John Criswell <<a href="mailto:jtcriswel@gmail.com">jtcriswel@gmail.com</a>> wrote:<br>
> On 1/27/16 8:42 PM, Syed Rafiul Hussain via llvm-dev wrote:<br>
>><br>
>> Sorry, I should ask the following:<br>
>> finds all the instructions of a function where a particular variable is<br>
>> defined?<br>
>> Lets consider the following code snippet:<br>
>><br>
>> 1. void foo(){<br>
>> 2. int a, b;<br>
>> 3. if(a > 10)<br>
>> 4.   b = 10;<br>
>> 5. if(a<10)<br>
>> 6.   b = 5;<br>
>> 7. cout << b;<br>
>> 8. }<br>
>><br>
>> I would like to know the instructions where variable b can be be<br>
>> defined, i.e, in this case, the instructions 4 and 6.<br>
><br>
><br>
> The LLVM IR is not best suited for this.  During the conversion to SSA form,<br>
> the variable b will be replaced with several variables, each with a unique<br>
> definition.  A phi-node will merge the two b values at line 7.  If you use<br>
> clang -emit-llvm -S on this input file, you will see.<br>
><br>
> You may want to do your analysis on the AST generated by Clang; Clang ASTs<br>
> represent the original C code and its variables.<br>
><br>
> Regards,<br>
><br>
> John Criswell<br>
><br>
><br>
><br>
>><br>
>> On Wed, Jan 27, 2016 at 8:15 PM, Tim Northover <<a href="mailto:t.p.northover@gmail.com">t.p.northover@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> On 27 January 2016 at 17:08, Syed Rafiul Hussain via llvm-dev<br>
>>> <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
>>>><br>
>>>> I am wondering if there is anything like def-use chain which finds all<br>
>>>> the instructions of a function where a particular value is defined?<br>
>>><br>
>>> How do you mean? LLVM IR is in SSA form, which means that each Value<br>
>>> has precisely one definition (which may or may not be an instruction).<br>
>>> If you've got a "Value *V" in C++ you can just<br>
>>> "dyn_cast<Instruction>(V)" to find the instruction (again, if it<br>
>>> exists).<br>
>>><br>
>>> Cheers.<br>
>>><br>
>>> Tim.<br>
>><br>
>><br>
>><br>
><br>
><br>
> --<br>
> John Criswell<br>
> Assistant Professor<br>
> Department of Computer Science, University of Rochester<br>
> <a href="http://www.cs.rochester.edu/u/criswell" rel="noreferrer" target="_blank">http://www.cs.rochester.edu/u/criswell</a><br>
><br>
<br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Rafi<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<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/mailman/listinfo/llvm-dev</a><br>
</div></div></blockquote></div><br></div>