[llvm-dev] loop induction variables at IR level
Sanjoy Das via llvm-dev
llvm-dev at lists.llvm.org
Sun Jul 2 15:07:17 PDT 2017
Hi Archa,
On Sat, Jul 1, 2017 at 9:27 AM, Archa . via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> My understanding of induction variable is that it drives the loop with fixed
> increment and by comparing it based on a condition (Hope I understood it
It's a bit more general than that, but overall you have the right idea.
> right). I want to extract and print this variable and what it is compared
> to.
>
> I have been trying to understand the ScalarEvolution and SCEVexpander
To only detect and analyze induction variables, using ScalarEvolution
is sufficient (you don't need SCEVExpander). You have to get hold of
a ScalarEvolution object (see the implementation of
IndVarSimplifyLegacyPass or IndVarSimplifyPass on how to do that) and
use the ScalarEvolution::getSCEV method to translate an llvm::Value*
to an llvm::SCEV*. If the llvm::SCEV* you get back is an
llvm::SCEVAddRecExpr* (you can check this by dyn_cast<> or isa<>) then
the llvm::Value* is an induction variable.
Thanks!
-- Sanjoy
More information about the llvm-dev
mailing list