Help needed in analyzing liveness of variables with LLVM IR

Hi,

Thank you for your time in reading this. I need help in analyzing the live-in and live-out variables for few loops in the llvm IR. I want to figure out which is a live-variable at the end of the loop and what is live-in variable for the loop. I found that such provisions are available for machine instructions. But, I have to use this at IR level. I found few papers showing algorithms to construct such analysis but, it seems to me that this must be a problem encountered before and there should be at least similar functionalities in some of the analyses passes in the existing LLVM framework. It would be great if I can find some references or someone can give some suggestions.

If I cannot find some existing passes, I am also not sure about – how can I make use of Intrinsic::invariant_start or Intrinsic::lifetime_start for aforementioned purpose. Any help is highly appreciated. Thanks!

Best,
Shail

Adding llvm-dev.

I don’t know if this is readily available in LLVM but here is what you could do something like below.

worklist = NULL
for each loop L in function {

for each block B in L {
for each Inst I in B {

if (I.use_empty())
continue;

for each use of I {

B1 = I.getParent();

if (L.contains(B))
continue;

worklist.add(I)
break;
}
}
}
}

Similar thing seems to be in Transforms/Utils/LCSSA.cpp

+cfe dev