Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Analysis/IntervalPartition.cpp
Line
Count
Source (jump to first uncovered line)
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
14
#include "llvm/Analysis/IntervalPartition.h"
15
#include "llvm/Analysis/Interval.h"
16
#include "llvm/Analysis/IntervalIterator.h"
17
#include "llvm/Pass.h"
18
#include <cassert>
19
#include <utility>
20
21
using namespace llvm;
22
23
char IntervalPartition::ID = 0;
24
25
INITIALIZE_PASS(IntervalPartition, "intervals",
26
                "Interval Partition Construction", true, true)
27
28
//===----------------------------------------------------------------------===//
29
// IntervalPartition Implementation
30
//===----------------------------------------------------------------------===//
31
32
// releaseMemory - Reset state back to before function was analyzed
33
0
void IntervalPartition::releaseMemory() {
34
0
  for (unsigned i = 0, e = Intervals.size(); i != e; ++i)
35
0
    delete Intervals[i];
36
0
  IntervalMap.clear();
37
0
  Intervals.clear();
38
0
  RootInterval = nullptr;
39
0
}
40
41
0
void IntervalPartition::print(raw_ostream &O, const Module*) const {
42
0
  for(unsigned i = 0, e = Intervals.size(); i != e; ++i)
43
0
    Intervals[i]->print(O);
44
0
}
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
0
void IntervalPartition::addIntervalToPartition(Interval *I) {
50
0
  Intervals.push_back(I);
51
0
52
0
  // Add mappings for all of the basic blocks in I to the IntervalPartition
53
0
  for (Interval::node_iterator It = I->Nodes.begin(), End = I->Nodes.end();
54
0
       It != End; ++It)
55
0
    IntervalMap.insert(std::make_pair(*It, I));
56
0
}
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
0
void IntervalPartition::updatePredecessors(Interval *Int) {
63
0
  BasicBlock *Header = Int->getHeaderNode();
64
0
  for (BasicBlock *Successor : Int->Successors)
65
0
    getBlockInterval(Successor)->Predecessors.push_back(Header);
66
0
}
67
68
// IntervalPartition ctor - Build the first level interval partition for the
69
// specified function...
70
0
bool IntervalPartition::runOnFunction(Function &F) {
71
0
  // Pass false to intervals_begin because we take ownership of it's memory
72
0
  function_interval_iterator I = intervals_begin(&F, false);
73
0
  assert(I != intervals_end(&F) && "No intervals in function!?!?!");
74
0
75
0
  addIntervalToPartition(RootInterval = *I);
76
0
77
0
  ++I;  // After the first one...
78
0
79
0
  // Add the rest of the intervals to the partition.
80
0
  for (function_interval_iterator E = intervals_end(&F); I != E; ++I)
81
0
    addIntervalToPartition(*I);
82
0
83
0
  // Now that we know all of the successor information, propagate this to the
84
0
  // predecessors for each block.
85
0
  for (unsigned i = 0, e = Intervals.size(); i != e; ++i)
86
0
    updatePredecessors(Intervals[i]);
87
0
  return false;
88
0
}
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.
93
IntervalPartition::IntervalPartition(IntervalPartition &IP, bool)
94
0
  : FunctionPass(ID) {
95
0
  assert(IP.getRootInterval() && "Cannot operate on empty IntervalPartitions!");
96
0
97
0
  // Pass false to intervals_begin because we take ownership of it's memory
98
0
  interval_part_interval_iterator I = intervals_begin(IP, false);
99
0
  assert(I != intervals_end(IP) && "No intervals in interval partition!?!?!");
100
0
101
0
  addIntervalToPartition(RootInterval = *I);
102
0
103
0
  ++I;  // After the first one...
104
0
105
0
  // Add the rest of the intervals to the partition.
106
0
  for (interval_part_interval_iterator E = intervals_end(IP); I != E; ++I)
107
0
    addIntervalToPartition(*I);
108
0
109
0
  // Now that we know all of the successor information, propagate this to the
110
0
  // predecessors for each block.
111
0
  for (unsigned i = 0, e = Intervals.size(); i != e; ++i)
112
0
    updatePredecessors(Intervals[i]);
113
0
}