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.

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