LLVM  4.0.0
IntervalPartition.cpp
Go to the documentation of this file.
1 //===- IntervalPartition.cpp - Interval Partition module code -------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the definition of the IntervalPartition class, which
11 // calculates and represent the interval partition of a function.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 using namespace llvm;
17 
18 char IntervalPartition::ID = 0;
20  "Interval Partition Construction", true, true)
21 
22 //===----------------------------------------------------------------------===//
23 // IntervalPartition Implementation
24 //===----------------------------------------------------------------------===//
25 
26 // releaseMemory - Reset state back to before function was analyzed
27 void IntervalPartition::releaseMemory() {
28  for (unsigned i = 0, e = Intervals.size(); i != e; ++i)
29  delete Intervals[i];
31  Intervals.clear();
32  RootInterval = nullptr;
33 }
34 
36  for(unsigned i = 0, e = Intervals.size(); i != e; ++i)
37  Intervals[i]->print(O);
38 }
39 
40 // addIntervalToPartition - Add an interval to the internal list of intervals,
41 // and then add mappings from all of the basic blocks in the interval to the
42 // interval itself (in the IntervalMap).
43 //
44 void IntervalPartition::addIntervalToPartition(Interval *I) {
45  Intervals.push_back(I);
46 
47  // Add mappings for all of the basic blocks in I to the IntervalPartition
48  for (Interval::node_iterator It = I->Nodes.begin(), End = I->Nodes.end();
49  It != End; ++It)
50  IntervalMap.insert(std::make_pair(*It, I));
51 }
52 
53 // updatePredecessors - Interval generation only sets the successor fields of
54 // the interval data structures. After interval generation is complete,
55 // run through all of the intervals and propagate successor info as
56 // predecessor info.
57 //
58 void IntervalPartition::updatePredecessors(Interval *Int) {
59  BasicBlock *Header = Int->getHeaderNode();
60  for (BasicBlock *Successor : Int->Successors)
61  getBlockInterval(Successor)->Predecessors.push_back(Header);
62 }
63 
64 // IntervalPartition ctor - Build the first level interval partition for the
65 // specified function...
66 //
68  // Pass false to intervals_begin because we take ownership of it's memory
70  assert(I != intervals_end(&F) && "No intervals in function!?!?!");
71 
72  addIntervalToPartition(RootInterval = *I);
73 
74  ++I; // After the first one...
75 
76  // Add the rest of the intervals to the partition.
77  for (function_interval_iterator E = intervals_end(&F); I != E; ++I)
78  addIntervalToPartition(*I);
79 
80  // Now that we know all of the successor information, propagate this to the
81  // predecessors for each block.
82  for (unsigned i = 0, e = Intervals.size(); i != e; ++i)
83  updatePredecessors(Intervals[i]);
84  return false;
85 }
86 
87 
88 // IntervalPartition ctor - Build a reduced interval partition from an
89 // existing interval graph. This takes an additional boolean parameter to
90 // distinguish it from a copy constructor. Always pass in false for now.
91 //
93  : FunctionPass(ID) {
94  assert(IP.getRootInterval() && "Cannot operate on empty IntervalPartitions!");
95 
96  // Pass false to intervals_begin because we take ownership of it's memory
98  assert(I != intervals_end(IP) && "No intervals in interval partition!?!?!");
99 
100  addIntervalToPartition(RootInterval = *I);
101 
102  ++I; // After the first one...
103 
104  // Add the rest of the intervals to the partition.
105  for (interval_part_interval_iterator E = intervals_end(IP); I != E; ++I)
106  addIntervalToPartition(*I);
107 
108  // Now that we know all of the successor information, propagate this to the
109  // predecessors for each block.
110  for (unsigned i = 0, e = Intervals.size(); i != e; ++i)
111  updatePredecessors(Intervals[i]);
112 }
113 
function_interval_iterator intervals_end(Function *)
size_t i
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:52
Interval Class - An Interval is a set of nodes defined such that every node in the interval has all o...
Definition: Interval.h:37
std::vector< BasicBlock * >::iterator node_iterator
Definition: Interval.h:45
#define F(x, y, z)
Definition: MD5.cpp:51
function_interval_iterator intervals_begin(Function *F, bool DeleteInts=true)
void clear()
clear - Remove all entries.
Definition: IntervalMap.h:1273
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
void print(raw_ostream &O, const Module *=nullptr) const override
print - Print out the internal state of the pass.
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
static const unsigned End
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
std::vector< BasicBlock * > Nodes
Nodes - The basic blocks in this interval.
Definition: Interval.h:55
INITIALIZE_PASS(IntervalPartition,"intervals","Interval Partition Construction", true, true) void IntervalPartition
void insert(KeyT a, KeyT b, ValT y)
insert - Add a mapping of [a;b] to y, coalesce with adjacent intervals.
Definition: IntervalMap.h:1085
SI Fix CF Live Intervals
std::vector< BasicBlock * > Predecessors
Predecessors - List of BasicBlocks that have this Interval's header block as one of their successors...
Definition: Interval.h:66
BasicBlock * getHeaderNode() const
Definition: Interval.h:51
std::vector< BasicBlock * > Successors
Successors - List of BasicBlocks that are reachable directly from nodes in this interval, but are not in the interval themselves.
Definition: Interval.h:61
#define I(x, y, z)
Definition: MD5.cpp:54
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
Interval * getBlockInterval(BasicBlock *BB)