Coverage Report

Created: 2019-03-22 08:08

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/ADT/UniqueVector.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/ADT/UniqueVector.h ----------------------------------*- C++ -*-===//
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
#ifndef LLVM_ADT_UNIQUEVECTOR_H
10
#define LLVM_ADT_UNIQUEVECTOR_H
11
12
#include <cassert>
13
#include <cstddef>
14
#include <map>
15
#include <vector>
16
17
namespace llvm {
18
19
//===----------------------------------------------------------------------===//
20
/// UniqueVector - This class produces a sequential ID number (base 1) for each
21
/// unique entry that is added.  T is the type of entries in the vector. This
22
/// class should have an implementation of operator== and of operator<.
23
/// Entries can be fetched using operator[] with the entry ID.
24
template<class T> class UniqueVector {
25
public:
26
  using VectorType = typename std::vector<T>;
27
  using iterator = typename VectorType::iterator;
28
  using const_iterator = typename VectorType::const_iterator;
29
30
private:
31
  // Map - Used to handle the correspondence of entry to ID.
32
  std::map<T, unsigned> Map;
33
34
  // Vector - ID ordered vector of entries. Entries can be indexed by ID - 1.
35
  VectorType Vector;
36
37
public:
38
  /// insert - Append entry to the vector if it doesn't already exist.  Returns
39
  /// the entry's index + 1 to be used as a unique ID.
40
1.39M
  unsigned insert(const T &Entry) {
41
1.39M
    // Check if the entry is already in the map.
42
1.39M
    unsigned &Val = Map[Entry];
43
1.39M
44
1.39M
    // See if entry exists, if so return prior ID.
45
1.39M
    if (Val) 
return Val1.66k
;
46
1.38M
47
1.38M
    // Compute ID for entry.
48
1.38M
    Val = static_cast<unsigned>(Vector.size()) + 1;
49
1.38M
50
1.38M
    // Insert in vector.
51
1.38M
    Vector.push_back(Entry);
52
1.38M
    return Val;
53
1.38M
  }
llvm::UniqueVector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::insert(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
40
1.38M
  unsigned insert(const T &Entry) {
41
1.38M
    // Check if the entry is already in the map.
42
1.38M
    unsigned &Val = Map[Entry];
43
1.38M
44
1.38M
    // See if entry exists, if so return prior ID.
45
1.38M
    if (Val) 
return Val0
;
46
1.38M
47
1.38M
    // Compute ID for entry.
48
1.38M
    Val = static_cast<unsigned>(Vector.size()) + 1;
49
1.38M
50
1.38M
    // Insert in vector.
51
1.38M
    Vector.push_back(Entry);
52
1.38M
    return Val;
53
1.38M
  }
LiveDebugValues.cpp:llvm::UniqueVector<(anonymous namespace)::LiveDebugValues::VarLoc>::insert((anonymous namespace)::LiveDebugValues::VarLoc const&)
Line
Count
Source
40
1.89k
  unsigned insert(const T &Entry) {
41
1.89k
    // Check if the entry is already in the map.
42
1.89k
    unsigned &Val = Map[Entry];
43
1.89k
44
1.89k
    // See if entry exists, if so return prior ID.
45
1.89k
    if (Val) 
return Val1.10k
;
46
785
47
785
    // Compute ID for entry.
48
785
    Val = static_cast<unsigned>(Vector.size()) + 1;
49
785
50
785
    // Insert in vector.
51
785
    Vector.push_back(Entry);
52
785
    return Val;
53
785
  }
llvm::UniqueVector<llvm::Comdat const*>::insert(llvm::Comdat const* const&)
Line
Count
Source
40
2.75k
  unsigned insert(const T &Entry) {
41
2.75k
    // Check if the entry is already in the map.
42
2.75k
    unsigned &Val = Map[Entry];
43
2.75k
44
2.75k
    // See if entry exists, if so return prior ID.
45
2.75k
    if (Val) 
return Val557
;
46
2.19k
47
2.19k
    // Compute ID for entry.
48
2.19k
    Val = static_cast<unsigned>(Vector.size()) + 1;
49
2.19k
50
2.19k
    // Insert in vector.
51
2.19k
    Vector.push_back(Entry);
52
2.19k
    return Val;
53
2.19k
  }
54
55
  /// idFor - return the ID for an existing entry.  Returns 0 if the entry is
56
  /// not found.
57
2.76k
  unsigned idFor(const T &Entry) const {
58
2.76k
    // Search for entry in the map.
59
2.76k
    typename std::map<T, unsigned>::const_iterator MI = Map.find(Entry);
60
2.76k
61
2.76k
    // See if entry exists, if so return ID.
62
2.76k
    if (
MI != Map.end()2.76k
) return MI->second;
63
18.4E
64
18.4E
    // No luck.
65
18.4E
    return 0;
66
18.4E
  }
llvm::UniqueVector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::idFor(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const
Line
Count
Source
57
14
  unsigned idFor(const T &Entry) const {
58
14
    // Search for entry in the map.
59
14
    typename std::map<T, unsigned>::const_iterator MI = Map.find(Entry);
60
14
61
14
    // See if entry exists, if so return ID.
62
14
    if (MI != Map.end()) return MI->second;
63
0
64
0
    // No luck.
65
0
    return 0;
66
0
  }
llvm::UniqueVector<llvm::Comdat const*>::idFor(llvm::Comdat const* const&) const
Line
Count
Source
57
2.75k
  unsigned idFor(const T &Entry) const {
58
2.75k
    // Search for entry in the map.
59
2.75k
    typename std::map<T, unsigned>::const_iterator MI = Map.find(Entry);
60
2.75k
61
2.75k
    // See if entry exists, if so return ID.
62
2.75k
    if (
MI != Map.end()2.75k
) return MI->second;
63
18.4E
64
18.4E
    // No luck.
65
18.4E
    return 0;
66
18.4E
  }
67
68
  /// operator[] - Returns a reference to the entry with the specified ID.
69
46.5k
  const T &operator[](unsigned ID) const {
70
46.5k
    assert(ID-1 < size() && "ID is 0 or out of range!");
71
46.5k
    return Vector[ID - 1];
72
46.5k
  }
LiveDebugValues.cpp:llvm::UniqueVector<(anonymous namespace)::LiveDebugValues::VarLoc>::operator[](unsigned int) const
Line
Count
Source
69
46.5k
  const T &operator[](unsigned ID) const {
70
46.5k
    assert(ID-1 < size() && "ID is 0 or out of range!");
71
46.5k
    return Vector[ID - 1];
72
46.5k
  }
llvm::UniqueVector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::operator[](unsigned int) const
Line
Count
Source
69
14
  const T &operator[](unsigned ID) const {
70
14
    assert(ID-1 < size() && "ID is 0 or out of range!");
71
14
    return Vector[ID - 1];
72
14
  }
73
74
  /// Return an iterator to the start of the vector.
75
  iterator begin() { return Vector.begin(); }
76
77
  /// Return an iterator to the start of the vector.
78
4.73k
  const_iterator begin() const { return Vector.begin(); }
llvm::UniqueVector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::begin() const
Line
Count
Source
78
1
  const_iterator begin() const { return Vector.begin(); }
llvm::UniqueVector<llvm::Comdat const*>::begin() const
Line
Count
Source
78
4.73k
  const_iterator begin() const { return Vector.begin(); }
79
80
  /// Return an iterator to the end of the vector.
81
  iterator end() { return Vector.end(); }
82
83
  /// Return an iterator to the end of the vector.
84
4.73k
  const_iterator end() const { return Vector.end(); }
llvm::UniqueVector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::end() const
Line
Count
Source
84
1
  const_iterator end() const { return Vector.end(); }
llvm::UniqueVector<llvm::Comdat const*>::end() const
Line
Count
Source
84
4.73k
  const_iterator end() const { return Vector.end(); }
85
86
  /// size - Returns the number of entries in the vector.
87
0
  size_t size() const { return Vector.size(); }
88
89
  /// empty - Returns true if the vector is empty.
90
  bool empty() const { return Vector.empty(); }
91
92
  /// reset - Clears all the entries.
93
  void reset() {
94
    Map.clear();
95
    Vector.resize(0, 0);
96
  }
97
};
98
99
} // end namespace llvm
100
101
#endif // LLVM_ADT_UNIQUEVECTOR_H