Zhoulai
2015-May-20 18:05 UTC
[LLVMdev] Tell whether an llvm::BranchInst* may depend on the function parameters?
Hi, I have a naive question in using LLVM. Given an llvm::Function*, and an llvm::BranchInst* of the function, is their a simple, off-the-shelf procedure in LLVM for me to determine whether there is dependency between the branch instruction and the function's input parameters? For example: *void foo(int n){* * i=0; * * if (i<=n){ //B1* * i++;* * }* * int j=0* * if (j<=2*j){ //B2* * j++;* * }* * if (i+j>=1){ //B3* * return;* * }* *return;* *}* Here, the first branch B1 depends on the input 'n'; the second branch B2 does not depends on 'n'; and the third B3 depends (indirectly) on input 'n' as it uses 'i'. Such static analysis can quickly become complicated, but maybe LLVM provides a simple, conservative solution for us. Can anyone tell me the right LLVM API to use. A simple example of the use would be the most helpful. Thanks in advance. Zhoulai -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150520/d330bda7/attachment.html>
John Criswell
2015-May-20 19:42 UTC
[LLVMdev] Tell whether an llvm::BranchInst* may depend on the function parameters?
On 5/20/15 1:05 PM, Zhoulai wrote:> Hi, > > I have a naive question in using LLVM. > > Given an llvm::Function*, and an llvm::BranchInst* of the function, is > their a simple, off-the-shelf procedure in LLVM for me to determine > whether there is dependency between the branch instruction and the > function’s input parameters? For example:For data-dependences through SSA virtual registers, all you need to do is follow the def-use chain of the function parameter to see if it is used by a branch instruction. For control-dependence, I think there's a Reverse Dominance Frontier analysis pass that you can use to determine if a branch is control-dependent on a value. You might need to do some work to handle indirect control dependences (the branch control-depends on a value which control-depends on the function parameter), but that is easy enough to do. If the value of the BranchInst is loaded from memory, then you've got a much more difficult task. In that case, you'd need to use an AliasAnalysis pass combined with your own reaching-definitions data-flow analysis to determine that the Function parameter is stored into memory and can potentially reach the use in the BranchInst. Regards, John Criswell> > /void foo(int n){/ > / i=0; / > / if (i<=n){ //B1/ > / i++;/ > / }/ > / int j=0/ > / if (j<=2*j){ //B2/ > / j++;/ > / }/ > / if (i+j>=1){ //B3/ > / return;/ > / }/ > /return;/ > /}/ > > Here, the first branch B1 depends on the input ’n’; the second branch > B2 does not depends on ’n’; and the third B3 depends (indirectly) on > input ’n’ as it uses ‘i’. > > Such static analysis can quickly become complicated, but maybe LLVM > provides a simple, conservative solution for us. Can anyone tell me > the right LLVM API to use. A simple example of the use would be the > most helpful. > > Thanks in advance. > Zhoulai > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-- John Criswell Assistant Professor Department of Computer Science, University of Rochester http://www.cs.rochester.edu/u/criswell -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150520/3745408f/attachment.html>