1 //===- IntervalPartition.h - Interval partition Calculation ------*- C++ -*--=//
3 // This file contains the declaration of the cfg::IntervalPartition class, which
4 // calculates and represents the interval partition of a method, or a
5 // preexisting interval partition.
7 // In this way, the interval partition may be used to reduce a flow graph down
8 // to its degenerate single node interval partition (unless it is irreducible).
10 // TODO: The IntervalPartition class should take a bool parameter that tells
11 // whether it should add the "tails" of an interval to an interval itself or if
12 // they should be represented as distinct intervals.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_INTERVAL_PARTITION_H
17 #define LLVM_INTERVAL_PARTITION_H
19 #include "llvm/Analysis/Interval.h"
26 //===----------------------------------------------------------------------===//
28 // IntervalPartition - This class builds and holds an "interval partition" for
29 // a method. This partition divides the control flow graph into a set of
30 // maximal intervals, as defined with the properties above. Intuitively, a
31 // BasicBlock is a (possibly nonexistent) loop with a "tail" of non looping
32 // nodes following it.
34 class IntervalPartition : public std::vector<Interval*> {
35 typedef std::map<BasicBlock*, Interval*> IntervalMapTy;
36 IntervalMapTy IntervalMap;
38 typedef std::vector<Interval*> IntervalListTy;
39 Interval *RootInterval;
42 // IntervalPartition ctor - Build the partition for the specified method
43 IntervalPartition(Method *M);
45 // IntervalPartition ctor - Build a reduced interval partition from an
46 // existing interval graph. This takes an additional boolean parameter to
47 // distinguish it from a copy constructor. Always pass in false for now.
49 IntervalPartition(IntervalPartition &I, bool);
51 // Destructor - Free memory
54 // getRootInterval() - Return the root interval that contains the starting
55 // block of the method.
56 inline Interval *getRootInterval() { return RootInterval; }
58 // isDegeneratePartition() - Returns true if the interval partition contains
59 // a single interval, and thus cannot be simplified anymore.
60 bool isDegeneratePartition() { return size() == 1; }
62 // TODO: isIrreducible - look for triangle graph.
64 // getBlockInterval - Return the interval that a basic block exists in.
65 inline Interval *getBlockInterval(BasicBlock *BB) {
66 IntervalMapTy::iterator I = IntervalMap.find(BB);
67 return I != IntervalMap.end() ? I->second : 0;
71 // addIntervalToPartition - Add an interval to the internal list of intervals,
72 // and then add mappings from all of the basic blocks in the interval to the
73 // interval itself (in the IntervalMap).
75 void addIntervalToPartition(Interval *I);
77 // updatePredecessors - Interval generation only sets the successor fields of
78 // the interval data structures. After interval generation is complete,
79 // run through all of the intervals and propogate successor info as
82 void updatePredecessors(Interval *Int);
85 } // End namespace cfg