LLVM API Documentation
00001 //===- IntervalPartition.cpp - Interval Partition module code -------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the definition of the IntervalPartition class, which 00011 // calculates and represent the interval partition of a function. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #include "llvm/Analysis/IntervalIterator.h" 00016 using namespace llvm; 00017 00018 static RegisterAnalysis<IntervalPartition> 00019 X("intervals", "Interval Partition Construction", true); 00020 00021 //===----------------------------------------------------------------------===// 00022 // IntervalPartition Implementation 00023 //===----------------------------------------------------------------------===// 00024 00025 // destroy - Reset state back to before function was analyzed 00026 void IntervalPartition::destroy() { 00027 for (unsigned i = 0, e = Intervals.size(); i != e; ++i) 00028 delete Intervals[i]; 00029 IntervalMap.clear(); 00030 RootInterval = 0; 00031 } 00032 00033 void IntervalPartition::print(std::ostream &O, const Module*) const { 00034 for(unsigned i = 0, e = Intervals.size(); i != e; ++i) 00035 Intervals[i]->print(O); 00036 } 00037 00038 // addIntervalToPartition - Add an interval to the internal list of intervals, 00039 // and then add mappings from all of the basic blocks in the interval to the 00040 // interval itself (in the IntervalMap). 00041 // 00042 void IntervalPartition::addIntervalToPartition(Interval *I) { 00043 Intervals.push_back(I); 00044 00045 // Add mappings for all of the basic blocks in I to the IntervalPartition 00046 for (Interval::node_iterator It = I->Nodes.begin(), End = I->Nodes.end(); 00047 It != End; ++It) 00048 IntervalMap.insert(std::make_pair(*It, I)); 00049 } 00050 00051 // updatePredecessors - Interval generation only sets the successor fields of 00052 // the interval data structures. After interval generation is complete, 00053 // run through all of the intervals and propagate successor info as 00054 // predecessor info. 00055 // 00056 void IntervalPartition::updatePredecessors(Interval *Int) { 00057 BasicBlock *Header = Int->getHeaderNode(); 00058 for (Interval::succ_iterator I = Int->Successors.begin(), 00059 E = Int->Successors.end(); I != E; ++I) 00060 getBlockInterval(*I)->Predecessors.push_back(Header); 00061 } 00062 00063 // IntervalPartition ctor - Build the first level interval partition for the 00064 // specified function... 00065 // 00066 bool IntervalPartition::runOnFunction(Function &F) { 00067 // Pass false to intervals_begin because we take ownership of it's memory 00068 function_interval_iterator I = intervals_begin(&F, false); 00069 assert(I != intervals_end(&F) && "No intervals in function!?!?!"); 00070 00071 addIntervalToPartition(RootInterval = *I); 00072 00073 ++I; // After the first one... 00074 00075 // Add the rest of the intervals to the partition. 00076 for (function_interval_iterator E = intervals_end(&F); I != E; ++I) 00077 addIntervalToPartition(*I); 00078 00079 // Now that we know all of the successor information, propagate this to the 00080 // predecessors for each block. 00081 for (unsigned i = 0, e = Intervals.size(); i != e; ++i) 00082 updatePredecessors(Intervals[i]); 00083 return false; 00084 } 00085 00086 00087 // IntervalPartition ctor - Build a reduced interval partition from an 00088 // existing interval graph. This takes an additional boolean parameter to 00089 // distinguish it from a copy constructor. Always pass in false for now. 00090 // 00091 IntervalPartition::IntervalPartition(IntervalPartition &IP, bool) { 00092 Interval *FunctionStart = IP.getRootInterval(); 00093 assert(FunctionStart && "Cannot operate on empty IntervalPartitions!"); 00094 00095 // Pass false to intervals_begin because we take ownership of it's memory 00096 interval_part_interval_iterator I = intervals_begin(IP, false); 00097 assert(I != intervals_end(IP) && "No intervals in interval partition!?!?!"); 00098 00099 addIntervalToPartition(RootInterval = *I); 00100 00101 ++I; // After the first one... 00102 00103 // Add the rest of the intervals to the partition. 00104 for (interval_part_interval_iterator E = intervals_end(IP); I != E; ++I) 00105 addIntervalToPartition(*I); 00106 00107 // Now that we know all of the successor information, propagate this to the 00108 // predecessors for each block. 00109 for (unsigned i = 0, e = Intervals.size(); i != e; ++i) 00110 updatePredecessors(Intervals[i]); 00111 } 00112