LLVM API Documentation
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_ANALYSIS_INTERVALPARTITION_H 00024 #define LLVM_ANALYSIS_INTERVALPARTITION_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, an 00037 // interval 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(nullptr) { 00052 initializeIntervalPartitionPass(*PassRegistry::getPassRegistry()); 00053 } 00054 00055 // run - Calculate the interval partition for this function 00056 bool runOnFunction(Function &F) override; 00057 00058 // IntervalPartition ctor - Build a reduced interval partition from an 00059 // existing interval graph. This takes an additional boolean parameter to 00060 // distinguish it from a copy constructor. Always pass in false for now. 00061 // 00062 IntervalPartition(IntervalPartition &I, bool); 00063 00064 // print - Show contents in human readable format... 00065 void print(raw_ostream &O, const Module* = nullptr) const override; 00066 00067 // getRootInterval() - Return the root interval that contains the starting 00068 // block of the function. 00069 inline Interval *getRootInterval() { return RootInterval; } 00070 00071 // isDegeneratePartition() - Returns true if the interval partition contains 00072 // a single interval, and thus cannot be simplified anymore. 00073 bool isDegeneratePartition() { return Intervals.size() == 1; } 00074 00075 // TODO: isIrreducible - look for triangle graph. 00076 00077 // getBlockInterval - Return the interval that a basic block exists in. 00078 inline Interval *getBlockInterval(BasicBlock *BB) { 00079 IntervalMapTy::iterator I = IntervalMap.find(BB); 00080 return I != IntervalMap.end() ? I->second : nullptr; 00081 } 00082 00083 // getAnalysisUsage - Implement the Pass API 00084 void getAnalysisUsage(AnalysisUsage &AU) const override { 00085 AU.setPreservesAll(); 00086 } 00087 00088 // Interface to Intervals vector... 00089 const std::vector<Interval*> &getIntervals() const { return Intervals; } 00090 00091 // releaseMemory - Reset state back to before function was analyzed 00092 void releaseMemory() override; 00093 00094 private: 00095 // addIntervalToPartition - Add an interval to the internal list of intervals, 00096 // and then add mappings from all of the basic blocks in the interval to the 00097 // interval itself (in the IntervalMap). 00098 // 00099 void addIntervalToPartition(Interval *I); 00100 00101 // updatePredecessors - Interval generation only sets the successor fields of 00102 // the interval data structures. After interval generation is complete, 00103 // run through all of the intervals and propagate successor info as 00104 // predecessor info. 00105 // 00106 void updatePredecessors(Interval *Int); 00107 }; 00108 00109 } // End llvm namespace 00110 00111 #endif