LLVM  10.0.0svn
IntervalPartition.cpp
Go to the documentation of this file.
1 //===- IntervalPartition.cpp - Interval Partition module code -------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the definition of the IntervalPartition class, which
10 // calculates and represent the interval partition of a function.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/Analysis/Interval.h"
17 #include "llvm/Pass.h"
18 #include <cassert>
19 #include <utility>
20 
21 using namespace llvm;
22 
23 char IntervalPartition::ID = 0;
24 
26  "Interval Partition Construction", true, true)
27 
28 //===----------------------------------------------------------------------===//
29 // IntervalPartition Implementation
30 //===----------------------------------------------------------------------===//
31 
32 // releaseMemory - Reset state back to before function was analyzed
33 void IntervalPartition::releaseMemory() {
34  for (unsigned i = 0, e = Intervals.size(); i != e; ++i)
35  delete Intervals[i];
37  Intervals.clear();
38  RootInterval = nullptr;
39 }
40 
42  for(unsigned i = 0, e = Intervals.size(); i != e; ++i)
43  Intervals[i]->print(O);
44 }
45 
46 // addIntervalToPartition - Add an interval to the internal list of intervals,
47 // and then add mappings from all of the basic blocks in the interval to the
48 // interval itself (in the IntervalMap).
49 void IntervalPartition::addIntervalToPartition(Interval *I) {
50  Intervals.push_back(I);
51 
52  // Add mappings for all of the basic blocks in I to the IntervalPartition
53  for (Interval::node_iterator It = I->Nodes.begin(), End = I->Nodes.end();
54  It != End; ++It)
55  IntervalMap.insert(std::make_pair(*It, I));
56 }
57 
58 // updatePredecessors - Interval generation only sets the successor fields of
59 // the interval data structures. After interval generation is complete,
60 // run through all of the intervals and propagate successor info as
61 // predecessor info.
62 void IntervalPartition::updatePredecessors(Interval *Int) {
63  BasicBlock *Header = Int->getHeaderNode();
64  for (BasicBlock *Successor : Int->Successors)
65  getBlockInterval(Successor)->Predecessors.push_back(Header);
66 }
67 
68 // IntervalPartition ctor - Build the first level interval partition for the
69 // specified function...
71  // Pass false to intervals_begin because we take ownership of it's memory
73  assert(I != intervals_end(&F) && "No intervals in function!?!?!");
74 
75  addIntervalToPartition(RootInterval = *I);
76 
77  ++I; // After the first one...
78 
79  // Add the rest of the intervals to the partition.
80  for (function_interval_iterator E = intervals_end(&F); I != E; ++I)
81  addIntervalToPartition(*I);
82 
83  // Now that we know all of the successor information, propagate this to the
84  // predecessors for each block.
85  for (unsigned i = 0, e = Intervals.size(); i != e; ++i)
86  updatePredecessors(Intervals[i]);
87  return false;
88 }
89 
90 // IntervalPartition ctor - Build a reduced interval partition from an
91 // existing interval graph. This takes an additional boolean parameter to
92 // distinguish it from a copy constructor. Always pass in false for now.
94  : FunctionPass(ID) {
95  assert(IP.getRootInterval() && "Cannot operate on empty IntervalPartitions!");
96 
97  // Pass false to intervals_begin because we take ownership of it's memory
99  assert(I != intervals_end(IP) && "No intervals in interval partition!?!?!");
100 
101  addIntervalToPartition(RootInterval = *I);
102 
103  ++I; // After the first one...
104 
105  // Add the rest of the intervals to the partition.
106  for (interval_part_interval_iterator E = intervals_end(IP); I != E; ++I)
107  addIntervalToPartition(*I);
108 
109  // Now that we know all of the successor information, propagate this to the
110  // predecessors for each block.
111  for (unsigned i = 0, e = Intervals.size(); i != e; ++i)
112  updatePredecessors(Intervals[i]);
113 }
function_interval_iterator intervals_end(Function *)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
Interval Class - An Interval is a set of nodes defined such that every node in the interval has all o...
Definition: Interval.h:36
std::vector< BasicBlock * >::iterator node_iterator
Definition: Interval.h:45
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:1283
BasicBlock * getHeaderNode() const
Definition: Interval.h:51
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:57
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
constexpr double e
Definition: MathExtras.h:57
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:284
std::vector< BasicBlock * > Nodes
Nodes - The basic blocks in this interval.
Definition: Interval.h:54
void insert(KeyT a, KeyT b, ValT y)
insert - Add a mapping of [a;b] to y, coalesce with adjacent intervals.
Definition: IntervalMap.h:1082
std::vector< BasicBlock * > Predecessors
Predecessors - List of BasicBlocks that have this Interval&#39;s header block as one of their successors...
Definition: Interval.h:63
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:59
#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:45
Interval * getBlockInterval(BasicBlock *BB)