Hi,
How does LLVM identify induction variables of a loop?
Is the algorithm based on SSA graphs?
I have a complicated loop and I need to do some analysis around it.
Can anyone please point me to source of identification part?
Hi,
How does LLVM identify induction variables of a loop?
Is the algorithm based on SSA graphs?
I have a complicated loop and I need to do some analysis around it.
Can anyone please point me to source of identification part?
If you have a canonicalized IV, you can use Loop::getCanonicalInductionVariable() declared in “include/llvm/Analysis/LoopInfo.h”.
Otherwise you probably need to start from function simplifyLoopIVs() in “lib/Transforms/Utils/SimplifyIndVar.cpp”. This method looks at all phi nodes in the header of the loop, but later on in the process, it skips some of them. For example, when we reach SimplifyIndvar::simplifyUsers(), in the beginning of this function we check if the IV data type isSCEVable() or not. If not, we immediately return.
Hope that helps
Ehsan
Hi Madhur,
If you're looking to solely _analyze_ induction variables, maybe you
should try leveraging LLVM's "Scalar Evolution" framework? See
include/llvm/Analysis/ScalarEvolution.h for the docs or the
IndVarSimplify pass for examples.
Thanks,
-- Sanjoy
To be clear, I was suggesting to read the code in simplifyLoopIVs() in “lib/Transforms/Utils/SimplifyIndVar.cpp” to see how it identifies IVs. (as opposed to calling the function to change the code).
Thanks this helps!