LLVM  8.0.1
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 #include "llvm/Analysis/Interval.h"
18 #include "llvm/Pass.h"
19 #include <cassert>
20 #include <utility>
21 
22 using namespace llvm;
23 
24 char IntervalPartition::ID = 0;
25 
27  "Interval Partition Construction", true, true)
28 
29 //===----------------------------------------------------------------------===//
30 // IntervalPartition Implementation
31 //===----------------------------------------------------------------------===//
32 
33 // releaseMemory - Reset state back to before function was analyzed
34 void IntervalPartition::releaseMemory() {
35  for (unsigned i = 0, e = Intervals.size(); i != e; ++i)
36  delete Intervals[i];
38  Intervals.clear();
39  RootInterval = nullptr;
40 }
41 
43  for(unsigned i = 0, e = Intervals.size(); i != e; ++i)
44  Intervals[i]->print(O);
45 }
46 
47 // addIntervalToPartition - Add an interval to the internal list of intervals,
48 // and then add mappings from all of the basic blocks in the interval to the
49 // interval itself (in the IntervalMap).
50 void IntervalPartition::addIntervalToPartition(Interval *I) {
51  Intervals.push_back(I);
52 
53  // Add mappings for all of the basic blocks in I to the IntervalPartition
54  for (Interval::node_iterator It = I->Nodes.begin(), End = I->Nodes.end();
55  It != End; ++It)
56  IntervalMap.insert(std::make_pair(*It, I));
57 }
58 
59 // updatePredecessors - Interval generation only sets the successor fields of
60 // the interval data structures. After interval generation is complete,
61 // run through all of the intervals and propagate successor info as
62 // predecessor info.
63 void IntervalPartition::updatePredecessors(Interval *Int) {
64  BasicBlock *Header = Int->getHeaderNode();
65  for (BasicBlock *Successor : Int->Successors)
66  getBlockInterval(Successor)->Predecessors.push_back(Header);
67 }
68 
69 // IntervalPartition ctor - Build the first level interval partition for the
70 // specified function...
72  // Pass false to intervals_begin because we take ownership of it's memory
74  assert(I != intervals_end(&F) && "No intervals in function!?!?!");
75 
76  addIntervalToPartition(RootInterval = *I);
77 
78  ++I; // After the first one...
79 
80  // Add the rest of the intervals to the partition.
81  for (function_interval_iterator E = intervals_end(&F); I != E; ++I)
82  addIntervalToPartition(*I);
83 
84  // Now that we know all of the successor information, propagate this to the
85  // predecessors for each block.
86  for (unsigned i = 0, e = Intervals.size(); i != e; ++i)
87  updatePredecessors(Intervals[i]);
88  return false;
89 }
90 
91 // IntervalPartition ctor - Build a reduced interval partition from an
92 // existing interval graph. This takes an additional boolean parameter to
93 // distinguish it from a copy constructor. Always pass in false for now.
95  : FunctionPass(ID) {
96  assert(IP.getRootInterval() && "Cannot operate on empty IntervalPartitions!");
97 
98  // Pass false to intervals_begin because we take ownership of it's memory
100  assert(I != intervals_end(IP) && "No intervals in interval partition!?!?!");
101 
102  addIntervalToPartition(RootInterval = *I);
103 
104  ++I; // After the first one...
105 
106  // Add the rest of the intervals to the partition.
107  for (interval_part_interval_iterator E = intervals_end(IP); I != E; ++I)
108  addIntervalToPartition(*I);
109 
110  // Now that we know all of the successor information, propagate this to the
111  // predecessors for each block.
112  for (unsigned i = 0, e = Intervals.size(); i != e; ++i)
113  updatePredecessors(Intervals[i]);
114 }
function_interval_iterator intervals_end(Function *)
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
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:46
INITIALIZE_PASS(IntervalPartition, "intervals", "Interval Partition Construction", true, true) void IntervalPartition
F(f)
function_interval_iterator intervals_begin(Function *F, bool DeleteInts=true)
void clear()
clear - Remove all entries.
Definition: IntervalMap.h:1284
BasicBlock * getHeaderNode() const
Definition: Interval.h:52
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:58
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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:285
std::vector< BasicBlock * > Nodes
Nodes - The basic blocks in this interval.
Definition: Interval.h:55
void insert(KeyT a, KeyT b, ValT y)
insert - Add a mapping of [a;b] to y, coalesce with adjacent intervals.
Definition: IntervalMap.h:1083
std::vector< BasicBlock * > Predecessors
Predecessors - List of BasicBlocks that have this Interval&#39;s header block as one of their successors...
Definition: Interval.h:64
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:60
#define I(x, y, z)
Definition: MD5.cpp:58
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:46
Interval * getBlockInterval(BasicBlock *BB)