blob: a4bb98334c29fb6c852d310d3c985363caf1337c [file] [log] [blame]
Chris Lattnerd213f0f2001-06-20 19:27:11 +00001//===- InductionVars.cpp - Induction Variable Cannonicalization code --------=//
2//
3// This file implements induction variable cannonicalization of loops.
4//
5// Specifically, after this executes, the following is true:
6// - There is a single induction variable for each loop (that used to contain
7// at least one induction variable)
8// - This induction variable starts at 0 and steps by 1 per iteration
9// - All other preexisting induction variables are adjusted to operate in
10// terms of this primary induction variable
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Analysis/Intervals.h"
15#include "llvm/Opt/AllOpts.h"
16#include "llvm/Assembly/Writer.h"
17
18static void PrintIntervalInfo(cfg::Interval *I) {
19 cerr << "-------------------------------------------------------------\n"
20 << "Interval Contents:\n";
21
22 // Print out all of the basic blocks in the interval...
23 copy(I->Nodes.begin(), I->Nodes.end(),
24 ostream_iterator<BasicBlock*>(cerr, "\n"));
25
26 cerr << "Interval Predecessors:\n";
27 copy(I->Predecessors.begin(), I->Predecessors.end(),
28 ostream_iterator<BasicBlock*>(cerr, "\n"));
29
30 cerr << "Interval Successors:\n";
31 copy(I->Successors.begin(), I->Successors.end(),
32 ostream_iterator<BasicBlock*>(cerr, "\n"));
33}
34
35// DoInductionVariableCannonicalize - Simplify induction variables in loops
36//
37bool DoInductionVariableCannonicalize(Method *M) {
38 cfg::IntervalPartition Intervals(M);
39
40 // This currently just prints out information about the interval structure
41 // of the method...
42 for_each(Intervals.begin(), Intervals.end(), PrintIntervalInfo);
43 return false;
44}