Akash Banerjee via llvm-dev
2019-Jul-22 09:55 UTC
[llvm-dev] Run llvm pass from standalone project
Hi all, I am trying to use LLVM's AliasAnalysis pass, but from a standalone tool that uses llvm libraries. The following is the code snippet I am currently using. PassBuilder PB; auto mod_manager = ModuleAnalysisManager { }; PB.registerModuleAnalyses(mod_manager); AAResults& AAR = mod_manager.getResult<AAManager>(*M); But the code fails at .getResult with the following error: /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. Aborted (core dumped) Please point me towards some documentation that explains how to run llvm passes from a standalone project. Thanks, Akash Banerjee -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190722/5e72868a/attachment.html>
Philip Pfaffe via llvm-dev
2019-Jul-22 11:26 UTC
[llvm-dev] Run llvm pass from standalone project
Hi Akash, 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. Cheers, Philip On Mon, Jul 22, 2019 at 11:56 AM Akash Banerjee via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi all, > I am trying to use LLVM's AliasAnalysis pass, but from a standalone tool > that uses llvm libraries. > > The following is the code snippet I am currently using. > PassBuilder PB; > auto mod_manager = ModuleAnalysisManager { }; > PB.registerModuleAnalyses(mod_manager); > AAResults& AAR = mod_manager.getResult<AAManager>(*M); > > But the code fails at .getResult with the following error: > /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. > Aborted (core dumped) > > Please point me towards some documentation that explains how to run llvm > passes from a standalone project. > > Thanks, > Akash Banerjee > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190722/167a8e7c/attachment.html>
Akash Banerjee via llvm-dev
2019-Aug-01 17:10 UTC
[llvm-dev] Run llvm pass from standalone project
Hi, 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: Sample C program: int f1(int a, int b){return a+b;} int f2(int a, int b){return a-b;} int f3(int a, int b){return a*b;} int main(){ int c; int (*f_ptr)(int, int); if(c==10) f_ptr = f1; else f_ptr = f2; c = f_ptr(c, 20); assert(c == 30); f_ptr = f3; c = f_ptr(c, 20); assert(c == 10); return 0; } 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. 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. I was hoping AliasSetTrackers would give this answer but that doesn't seem to be the case. The following are the results of opt -print-alias-sets: Alias sets for function 'f1': Alias Set Tracker: 2 alias sets for 2 pointer values. AliasSet[0x557db2e4b7f0, 1] must alias, Mod/Ref Pointers: (i32* %a.addr, LocationSize::precise(4)) AliasSet[0x557db2e4b920, 1] must alias, Mod/Ref Pointers: (i32* %b.addr, LocationSize::precise(4)) Alias sets for function 'f2': Alias Set Tracker: 2 alias sets for 2 pointer values. AliasSet[0x557db2e4b7f0, 1] must alias, Mod/Ref Pointers: (i32* %a.addr, LocationSize::precise(4)) AliasSet[0x557db2e49b90, 1] must alias, Mod/Ref Pointers: (i32* %b.addr, LocationSize::precise(4)) Alias sets for function 'main': Alias Set Tracker: 4 alias sets for 3 pointer values. AliasSet[0x557db2e4b7f0, 1] must alias, Mod Pointers: (i32* %retval, LocationSize::precise(4)) AliasSet[0x557db2e4b920, 1] must alias, Mod/Ref Pointers: (i32* %c, LocationSize::precise(4)) AliasSet[0x557db2e58710, 1] must alias, Mod/Ref Pointers: (i32 (i32, i32)** %f_ptr, LocationSize::precise(8)) AliasSet[0x557db2e58760, 1] may alias, Mod/Ref 4 Unknown instructions: i32 %call, i32 %call1, i32 %call2, i32 %call5 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? Thanks, Akash Banerjee. On Mon, Jul 22, 2019 at 4:56 PM Philip Pfaffe <philip.pfaffe at gmail.com> wrote:> Hi Akash, > > 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. > > Cheers, > Philip > > On Mon, Jul 22, 2019 at 11:56 AM Akash Banerjee via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> Hi all, >> I am trying to use LLVM's AliasAnalysis pass, but from a standalone tool >> that uses llvm libraries. >> >> The following is the code snippet I am currently using. >> PassBuilder PB; >> auto mod_manager = ModuleAnalysisManager { }; >> PB.registerModuleAnalyses(mod_manager); >> AAResults& AAR = mod_manager.getResult<AAManager>(*M); >> >> But the code fails at .getResult with the following error: >> /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. >> Aborted (core dumped) >> >> Please point me towards some documentation that explains how to run llvm >> passes from a standalone project. >> >> Thanks, >> Akash Banerjee >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190801/8c021756/attachment-0001.html>