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"
31 //===----------------------------------------------------------------------===//
33 // IntervalPartition - This class builds and holds an "interval partition" for
34 // a function. This partition divides the control flow graph into a set of
35 // maximal intervals, as defined with the properties above. Intuitively, a
36 // BasicBlock is a (possibly nonexistent) loop with a "tail" of non looping
37 // nodes following it.
39 class IntervalPartition : public FunctionPass {
40 typedef std::map<BasicBlock*, Interval*> IntervalMapTy;
41 IntervalMapTy IntervalMap;
43 typedef std::vector<Interval*> IntervalListTy;
44 Interval *RootInterval;
45 std::vector<Interval*> Intervals;
48 IntervalPartition() : RootInterval(0) {}
50 // run - Calculate the interval partition for this function
51 virtual bool runOnFunction(Function &F);
53 // IntervalPartition ctor - Build a reduced interval partition from an
54 // existing interval graph. This takes an additional boolean parameter to
55 // distinguish it from a copy constructor. Always pass in false for now.
57 IntervalPartition(IntervalPartition &I, bool);
59 // Destructor - Free memory
60 ~IntervalPartition() { destroy(); }
62 // print - Show contents in human readable format...
63 virtual void print(std::ostream &O, const Module* = 0) const;
65 // getRootInterval() - Return the root interval that contains the starting
66 // block of the function.
67 inline Interval *getRootInterval() { return RootInterval; }
69 // isDegeneratePartition() - Returns true if the interval partition contains
70 // a single interval, and thus cannot be simplified anymore.
71 bool isDegeneratePartition() { return Intervals.size() == 1; }
73 // TODO: isIrreducible - look for triangle graph.
75 // getBlockInterval - Return the interval that a basic block exists in.
76 inline Interval *getBlockInterval(BasicBlock *BB) {
77 IntervalMapTy::iterator I = IntervalMap.find(BB);
78 return I != IntervalMap.end() ? I->second : 0;
81 // getAnalysisUsage - Implement the Pass API
82 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
86 // Interface to Intervals vector...
87 const std::vector<Interval*> &getIntervals() const { return Intervals; }
90 // destroy - Reset state back to before function was analyzed
93 // addIntervalToPartition - Add an interval to the internal list of intervals,
94 // and then add mappings from all of the basic blocks in the interval to the
95 // interval itself (in the IntervalMap).
97 void addIntervalToPartition(Interval *I);
99 // updatePredecessors - Interval generation only sets the successor fields of
100 // the interval data structures. After interval generation is complete,
101 // run through all of the intervals and propagate successor info as
104 void updatePredecessors(Interval *Int);
107 } // End llvm namespace