LLVM API Documentation

IntervalPartition.h

Go to the documentation of this file.
00001 //===- IntervalPartition.h - Interval partition Calculation -----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains the declaration of the IntervalPartition class, which
00011 // calculates and represents the interval partition of a function, or a
00012 // preexisting interval partition.
00013 //
00014 // In this way, the interval partition may be used to reduce a flow graph down
00015 // to its degenerate single node interval partition (unless it is irreducible).
00016 //
00017 // TODO: The IntervalPartition class should take a bool parameter that tells
00018 // whether it should add the "tails" of an interval to an interval itself or if
00019 // they should be represented as distinct intervals.
00020 //
00021 //===----------------------------------------------------------------------===//
00022 
00023 #ifndef LLVM_INTERVAL_PARTITION_H
00024 #define LLVM_INTERVAL_PARTITION_H
00025 
00026 #include "llvm/Analysis/Interval.h"
00027 #include "llvm/Pass.h"
00028 #include <map>
00029 
00030 namespace llvm {
00031 
00032 //===----------------------------------------------------------------------===//
00033 //
00034 // IntervalPartition - This class builds and holds an "interval partition" for
00035 // a function.  This partition divides the control flow graph into a set of
00036 // maximal intervals, as defined with the properties above.  Intuitively, a
00037 // BasicBlock is a (possibly nonexistent) loop with a "tail" of non looping
00038 // nodes following it.
00039 //
00040 class IntervalPartition : public FunctionPass {
00041   typedef std::map<BasicBlock*, Interval*> IntervalMapTy;
00042   IntervalMapTy IntervalMap;
00043 
00044   typedef std::vector<Interval*> IntervalListTy;
00045   Interval *RootInterval;
00046   std::vector<Interval*> Intervals;
00047 
00048 public:
00049   static char ID; // Pass identification, replacement for typeid
00050 
00051   IntervalPartition() : FunctionPass(&ID), RootInterval(0) {}
00052 
00053   // run - Calculate the interval partition for this function
00054   virtual bool runOnFunction(Function &F);
00055 
00056   // IntervalPartition ctor - Build a reduced interval partition from an
00057   // existing interval graph.  This takes an additional boolean parameter to
00058   // distinguish it from a copy constructor.  Always pass in false for now.
00059   //
00060   IntervalPartition(IntervalPartition &I, bool);
00061 
00062   // print - Show contents in human readable format...
00063   virtual void print(std::ostream &O, const Module* = 0) const;
00064   void print(std::ostream *O, const Module* M = 0) const {
00065     if (O) print(*O, M);
00066   }
00067 
00068   // getRootInterval() - Return the root interval that contains the starting
00069   // block of the function.
00070   inline Interval *getRootInterval() { return RootInterval; }
00071 
00072   // isDegeneratePartition() - Returns true if the interval partition contains
00073   // a single interval, and thus cannot be simplified anymore.
00074   bool isDegeneratePartition() { return Intervals.size() == 1; }
00075 
00076   // TODO: isIrreducible - look for triangle graph.
00077 
00078   // getBlockInterval - Return the interval that a basic block exists in.
00079   inline Interval *getBlockInterval(BasicBlock *BB) {
00080     IntervalMapTy::iterator I = IntervalMap.find(BB);
00081     return I != IntervalMap.end() ? I->second : 0;
00082   }
00083 
00084   // getAnalysisUsage - Implement the Pass API
00085   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
00086     AU.setPreservesAll();
00087   }
00088 
00089   // Interface to Intervals vector...
00090   const std::vector<Interval*> &getIntervals() const { return Intervals; }
00091 
00092   // releaseMemory - Reset state back to before function was analyzed
00093   void releaseMemory();
00094 
00095 private:
00096   // addIntervalToPartition - Add an interval to the internal list of intervals,
00097   // and then add mappings from all of the basic blocks in the interval to the
00098   // interval itself (in the IntervalMap).
00099   //
00100   void addIntervalToPartition(Interval *I);
00101 
00102   // updatePredecessors - Interval generation only sets the successor fields of
00103   // the interval data structures.  After interval generation is complete,
00104   // run through all of the intervals and propagate successor info as
00105   // predecessor info.
00106   //
00107   void updatePredecessors(Interval *Int);
00108 };
00109 
00110 } // End llvm namespace
00111 
00112 #endif