<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt">Hi Duncan and John,<br><br>Thank your very much for the advice and help.<br><br>Yes, I have got the first part working following Duncan's advice.<br><br>I think I can also incorporate Alias Analysis (AA) in my code.<br><br>A bit of guidance on how the LLVM provided methods in AA have to be invoked so as to get the info on <br>the global being passed into the function as an argument or loaded from memory via an LLVM load instruction as John pointed out?<br><br>Thanks again.<br><br>Regards,<br>Yan Lin Aung<br><br><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <hr size="1">  <font face="Arial" size="2"> <b><span style="font-weight:bold;">From:</span></b> John Criswell
 <criswell@illinois.edu><br> <b><span style="font-weight: bold;">To:</span></b> Duncan Sands <baldrick@free.fr> <br><b><span style="font-weight: bold;">Cc:</span></b> llvmdev@cs.uiuc.edu <br> <b><span style="font-weight: bold;">Sent:</span></b> Friday, September 6, 2013 11:41 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [LLVMdev] Extracting the global variables accessed by individual function with function pass<br> </font> </div> <div class="y_msg_container"><br>On 9/2/13 6:15 AM, Duncan Sands wrote:<br>> Hi,<br>><br>>> Is there a way to dump the global variables, which are accessed <br>>> (read/written<br>>> to) by each function within the LLVM function pass?<br>>> Any pointers on how that info can be extracted in LLVM for each <br>>> function in the<br>>> application?<br>><br>> you will have to write your own pass to do this.  For each global, <br>> visit
 each<br>> of its uses (via use_begin, use_end).  If the use is a constant <br>> (isa<Constant>),<br>> visit each of its uses too (do this recursively until you aren't visiting<br>> constants any more).  If a use isn't a constant, check whether it's <br>> parent<br>> (getParent) is the function you are interested in.  The point of <br>> recursing on<br>> constant uses is that the global may be used in a constant expression <br>> (eg a<br>> constant bitcast) before actually being used by an instruction.<br><br>Note that this only finds globals that are directly accessed by the <br>function.  It won't find globals that are accessed by the function due <br>to the global being passed into the function as an argument or loaded <br>from memory via an LLVM load instruction.  To find those, you'll need to <br>use alias analysis or a points-to analysis.<br><br>-- John T.<br><br>><br>> Ciao,
 Duncan.<br>> _______________________________________________<br>> LLVM Developers mailing list<br>> <a ymailto="mailto:LLVMdev@cs.uiuc.edu" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br><br>_______________________________________________<br>LLVM Developers mailing list<br><a ymailto="mailto:LLVMdev@cs.uiuc.edu" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br><br><br></div> </div> </div>  </div></body></html>