<div dir="ltr"><div dir="ltr">Hi,<div>Thanks for the help, I am now able to run passes from my tool, however, I primarily wanted to use Alias Analysis for getting the Alias Sets for the following problem:</div><div>Sample C program:</div><div><br></div>int f1(int a, int b){return a+b;}<br>int f2(int a, int b){return a-b;}<br>int f3(int a, int b){return a*b;}<br><br>int main(){<br> int c;<br> int (*f_ptr)(int, int);</div><div dir="ltr"><br> if(c==10) f_ptr = f1;<br> else f_ptr = f2;</div><div dir="ltr"><br> c = f_ptr(c, 20);<br> assert(c == 30);<br> <br> f_ptr = f3;<br> c = f_ptr(c, 20);<br> assert(c == 10);</div><div dir="ltr"><br> return 0;</div><div dir="ltr">}</div><div>What I want is just before the first assert call, what are the functions that f_ptr can possibly point to(f1 or f2 in this case), and similarly just before the second assert what are the functions it can point to(always f3) in this case.</div><div>Basically, at any given point in the program, I want to find what are the possible functions that a particular function pointer could point to.</div><div>I was hoping AliasSetTrackers would give this answer but that doesn't seem to be the case.</div><div>The following are the results of opt -print-alias-sets:</div><div><br></div><div>Alias sets for function 'f1':<br>Alias Set Tracker: 2 alias sets for 2 pointer values.<br> AliasSet[0x557db2e4b7f0, 1] must alias, Mod/Ref Pointers: (i32* %a.addr, LocationSize::precise(4))<br> AliasSet[0x557db2e4b920, 1] must alias, Mod/Ref Pointers: (i32* %b.addr, LocationSize::precise(4))<br><br>Alias sets for function 'f2':<br>Alias Set Tracker: 2 alias sets for 2 pointer values.<br> AliasSet[0x557db2e4b7f0, 1] must alias, Mod/Ref Pointers: (i32* %a.addr, LocationSize::precise(4))<br> AliasSet[0x557db2e49b90, 1] must alias, Mod/Ref Pointers: (i32* %b.addr, LocationSize::precise(4))<br><br>Alias sets for function 'main':<br>Alias Set Tracker: 4 alias sets for 3 pointer values.<br> AliasSet[0x557db2e4b7f0, 1] must alias, Mod Pointers: (i32* %retval, LocationSize::precise(4))<br> AliasSet[0x557db2e4b920, 1] must alias, Mod/Ref Pointers: (i32* %c, LocationSize::precise(4))<br> AliasSet[0x557db2e58710, 1] must alias, Mod/Ref Pointers: (i32 (i32, i32)** %f_ptr, LocationSize::precise(8))<br> AliasSet[0x557db2e58760, 1] may alias, Mod/Ref <br> 4 Unknown instructions: i32 %call, i32 %call1, i32 %call2, i32 %call5<br></div><div><br></div><div>Is it possible to do what I am trying using Alias Sets, if not is there something else built into llvm which would help me do the same?</div><div><br></div><div>Thanks,</div><div>Akash Banerjee.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jul 22, 2019 at 4:56 PM Philip Pfaffe <<a href="mailto:philip.pfaffe@gmail.com">philip.pfaffe@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Akash,<div><br></div><div>this isn't exactly documented, but you can refer to the implementation in the opt tool (see NewPMDriver.cpp). The problem is that you're missing a full stack of analysis managers.</div><div><br></div><div>Cheers,</div><div>Philip</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jul 22, 2019 at 11:56 AM Akash Banerjee via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi all,<div>I am trying to use LLVM's AliasAnalysis pass, but from a standalone tool that uses llvm libraries.</div><div><br></div><div>The following is the code snippet I am currently using.</div><div><font face="courier new, monospace">PassBuilder PB;<br></font></div><div><font face="courier new, monospace">auto mod_manager = ModuleAnalysisManager { };<br></font></div><div><font face="courier new, monospace">PB.registerModuleAnalyses(mod_manager);<br></font></div><div><font face="courier new, monospace">AAResults& AAR = mod_manager.getResult<AAManager>(*M);</font></div><div><br></div><div>But the code fails at .getResult with the following error:</div><div><font face="courier new, monospace">/llvm/include/llvm/IR/PassManager.h:778: typename PassT::Result& llvm::AnalysisManager<IRUnitT, ExtraArgTs>::getResult(IRUnitT&, ExtraArgTs ...) [with PassT = llvm::AAManager; IRUnitT = llvm::Module; ExtraArgTs = {}; typename PassT::Result = llvm::AAResults]: Assertion `AnalysisPasses.count(PassT::ID()) && "This analysis pass was not registered prior to being queried"' failed.<br>Aborted (core dumped)</font><br></div><div><font face="courier new, monospace"><br></font></div><div><font face="arial, sans-serif">Please point me towards some documentation that explains how to run llvm passes from a standalone project.</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Thanks,</font></div><div><font face="arial, sans-serif">Akash Banerjee</font></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
</blockquote></div></div>