1 //===- IntervalPartition.h - Interval partition Calculation -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the IntervalPartition class, which
11 // calculates and represents the interval partition of a function, or a
12 // preexisting interval partition.
14 // In this way, the interval partition may be used to reduce a flow graph down
15 // to its degenerate single node interval partition (unless it is irreducible).
17 // TODO: The IntervalPartition class should take a bool parameter that tells
18 // whether it should add the "tails" of an interval to an interval itself or if
19 // they should be represented as distinct intervals.
21 //===----------------------------------------------------------------------===//
23 #ifndef LLVM_INTERVAL_PARTITION_H
24 #define LLVM_INTERVAL_PARTITION_H
26 #include "llvm/Analysis/Interval.h"
27 #include "llvm/Pass.h"
29 //===----------------------------------------------------------------------===//
31 // IntervalPartition - This class builds and holds an "interval partition" for
32 // a function. This partition divides the control flow graph into a set of
33 // maximal intervals, as defined with the properties above. Intuitively, a
34 // BasicBlock is a (possibly nonexistent) loop with a "tail" of non looping
35 // nodes following it.
37 class IntervalPartition : public FunctionPass {
38 typedef std::map<BasicBlock*, Interval*> IntervalMapTy;
39 IntervalMapTy IntervalMap;
41 typedef std::vector<Interval*> IntervalListTy;
42 Interval *RootInterval;
43 std::vector<Interval*> Intervals;
46 IntervalPartition() : RootInterval(0) {}
48 // run - Calculate the interval partition for this function
49 virtual bool runOnFunction(Function &F);
51 // IntervalPartition ctor - Build a reduced interval partition from an
52 // existing interval graph. This takes an additional boolean parameter to
53 // distinguish it from a copy constructor. Always pass in false for now.
55 IntervalPartition(IntervalPartition &I, bool);
57 // Destructor - Free memory
58 ~IntervalPartition() { destroy(); }
60 // print - Show contents in human readable format...
61 virtual void print(std::ostream &O) const;
63 // getRootInterval() - Return the root interval that contains the starting
64 // block of the function.
65 inline Interval *getRootInterval() { return RootInterval; }
67 // isDegeneratePartition() - Returns true if the interval partition contains
68 // a single interval, and thus cannot be simplified anymore.
69 bool isDegeneratePartition() { return Intervals.size() == 1; }
71 // TODO: isIrreducible - look for triangle graph.
73 // getBlockInterval - Return the interval that a basic block exists in.
74 inline Interval *getBlockInterval(BasicBlock *BB) {
75 IntervalMapTy::iterator I = IntervalMap.find(BB);
76 return I != IntervalMap.end() ? I->second : 0;
79 // getAnalysisUsage - Implement the Pass API
80 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
84 // Interface to Intervals vector...
85 const std::vector<Interval*> &getIntervals() const { return Intervals; }
88 // destroy - Reset state back to before function was analyzed
91 // addIntervalToPartition - Add an interval to the internal list of intervals,
92 // and then add mappings from all of the basic blocks in the interval to the
93 // interval itself (in the IntervalMap).
95 void addIntervalToPartition(Interval *I);
97 // updatePredecessors - Interval generation only sets the successor fields of
98 // the interval data structures. After interval generation is complete,
99 // run through all of the intervals and propagate successor info as
102 void updatePredecessors(Interval *Int);