Coverage Report

Created: 2019-02-20 07:29

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/PBQP/CostAllocator.h
Line
Count
Source
1
//===- CostAllocator.h - PBQP Cost Allocator --------------------*- 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
// Defines classes conforming to the PBQP cost value manager concept.
10
//
11
// Cost value managers are memory managers for PBQP cost values (vectors and
12
// matrices). Since PBQP graphs can grow very large (E.g. hundreds of thousands
13
// of edges on the largest function in SPEC2006).
14
//
15
//===----------------------------------------------------------------------===//
16
17
#ifndef LLVM_CODEGEN_PBQP_COSTALLOCATOR_H
18
#define LLVM_CODEGEN_PBQP_COSTALLOCATOR_H
19
20
#include "llvm/ADT/DenseSet.h"
21
#include <algorithm>
22
#include <cstdint>
23
#include <memory>
24
25
namespace llvm {
26
namespace PBQP {
27
28
template <typename ValueT> class ValuePool {
29
public:
30
  using PoolRef = std::shared_ptr<const ValueT>;
31
32
private:
33
  class PoolEntry : public std::enable_shared_from_this<PoolEntry> {
34
  public:
35
    template <typename ValueKeyT>
36
    PoolEntry(ValuePool &Pool, ValueKeyT Value)
37
202
        : Pool(Pool), Value(std::move(Value)) {}
llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntry::PoolEntry<llvm::PBQP::Matrix>(llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >&, llvm::PBQP::Matrix)
Line
Count
Source
37
43
        : Pool(Pool), Value(std::move(Value)) {}
llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntry::PoolEntry<llvm::PBQP::Vector>(llvm::PBQP::ValuePool<llvm::PBQP::Vector>&, llvm::PBQP::Vector)
Line
Count
Source
37
135
        : Pool(Pool), Value(std::move(Value)) {}
llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntry::PoolEntry<llvm::PBQP::RegAlloc::AllowedRegVector>(llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>&, llvm::PBQP::RegAlloc::AllowedRegVector)
Line
Count
Source
37
24
        : Pool(Pool), Value(std::move(Value)) {}
38
39
202
    ~PoolEntry() { Pool.removeEntry(this); }
llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntry::~PoolEntry()
Line
Count
Source
39
43
    ~PoolEntry() { Pool.removeEntry(this); }
llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntry::~PoolEntry()
Line
Count
Source
39
135
    ~PoolEntry() { Pool.removeEntry(this); }
llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntry::~PoolEntry()
Line
Count
Source
39
24
    ~PoolEntry() { Pool.removeEntry(this); }
40
41
2.39k
    const ValueT &getValue() const { return Value; }
llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntry::getValue() const
Line
Count
Source
41
526
    const ValueT &getValue() const { return Value; }
llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntry::getValue() const
Line
Count
Source
41
1.46k
    const ValueT &getValue() const { return Value; }
llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntry::getValue() const
Line
Count
Source
41
402
    const ValueT &getValue() const { return Value; }
42
43
  private:
44
    ValuePool &Pool;
45
    ValueT Value;
46
  };
47
48
  class PoolEntryDSInfo {
49
  public:
50
5.52k
    static inline PoolEntry *getEmptyKey() { return nullptr; }
llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntryDSInfo::getEmptyKey()
Line
Count
Source
50
1.33k
    static inline PoolEntry *getEmptyKey() { return nullptr; }
llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntryDSInfo::getEmptyKey()
Line
Count
Source
50
3.11k
    static inline PoolEntry *getEmptyKey() { return nullptr; }
llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntryDSInfo::getEmptyKey()
Line
Count
Source
50
1.07k
    static inline PoolEntry *getEmptyKey() { return nullptr; }
51
52
3.16k
    static inline PoolEntry *getTombstoneKey() {
53
3.16k
      return reinterpret_cast<PoolEntry *>(static_cast<uintptr_t>(1));
54
3.16k
    }
llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntryDSInfo::getTombstoneKey()
Line
Count
Source
52
687
    static inline PoolEntry *getTombstoneKey() {
53
687
      return reinterpret_cast<PoolEntry *>(static_cast<uintptr_t>(1));
54
687
    }
llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntryDSInfo::getTombstoneKey()
Line
Count
Source
52
2.00k
    static inline PoolEntry *getTombstoneKey() {
53
2.00k
      return reinterpret_cast<PoolEntry *>(static_cast<uintptr_t>(1));
54
2.00k
    }
llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntryDSInfo::getTombstoneKey()
Line
Count
Source
52
474
    static inline PoolEntry *getTombstoneKey() {
53
474
      return reinterpret_cast<PoolEntry *>(static_cast<uintptr_t>(1));
54
474
    }
55
56
    template <typename ValueKeyT>
57
1.00k
    static unsigned getHashValue(const ValueKeyT &C) {
58
1.00k
      return hash_value(C);
59
1.00k
    }
unsigned int llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntryDSInfo::getHashValue<llvm::PBQP::Matrix>(llvm::PBQP::Matrix const&)
Line
Count
Source
57
120
    static unsigned getHashValue(const ValueKeyT &C) {
58
120
      return hash_value(C);
59
120
    }
unsigned int llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntryDSInfo::getHashValue<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >(llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> const&)
Line
Count
Source
57
86
    static unsigned getHashValue(const ValueKeyT &C) {
58
86
      return hash_value(C);
59
86
    }
unsigned int llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntryDSInfo::getHashValue<llvm::PBQP::Vector>(llvm::PBQP::Vector const&)
Line
Count
Source
57
605
    static unsigned getHashValue(const ValueKeyT &C) {
58
605
      return hash_value(C);
59
605
    }
unsigned int llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntryDSInfo::getHashValue<llvm::PBQP::RegAlloc::AllowedRegVector>(llvm::PBQP::RegAlloc::AllowedRegVector const&)
Line
Count
Source
57
193
    static unsigned getHashValue(const ValueKeyT &C) {
58
193
      return hash_value(C);
59
193
    }
60
61
404
    static unsigned getHashValue(PoolEntry *P) {
62
404
      return getHashValue(P->getValue());
63
404
    }
llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntryDSInfo::getHashValue(llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntry*)
Line
Count
Source
61
86
    static unsigned getHashValue(PoolEntry *P) {
62
86
      return getHashValue(P->getValue());
63
86
    }
llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntryDSInfo::getHashValue(llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntry*)
Line
Count
Source
61
270
    static unsigned getHashValue(PoolEntry *P) {
62
270
      return getHashValue(P->getValue());
63
270
    }
llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntryDSInfo::getHashValue(llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntry*)
Line
Count
Source
61
48
    static unsigned getHashValue(PoolEntry *P) {
62
48
      return getHashValue(P->getValue());
63
48
    }
64
65
    static unsigned getHashValue(const PoolEntry *P) {
66
      return getHashValue(P->getValue());
67
    }
68
69
    template <typename ValueKeyT1, typename ValueKeyT2>
70
720
    static bool isEqual(const ValueKeyT1 &C1, const ValueKeyT2 &C2) {
71
720
      return C1 == C2;
72
720
    }
bool llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntryDSInfo::isEqual<llvm::PBQP::Matrix, llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >(llvm::PBQP::Matrix const&, llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> const&)
Line
Count
Source
70
112
    static bool isEqual(const ValueKeyT1 &C1, const ValueKeyT2 &C2) {
71
112
      return C1 == C2;
72
112
    }
bool llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntryDSInfo::isEqual<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata>, llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >(llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> const&, llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> const&)
Line
Count
Source
70
47
    static bool isEqual(const ValueKeyT1 &C1, const ValueKeyT2 &C2) {
71
47
      return C1 == C2;
72
47
    }
bool llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntryDSInfo::isEqual<llvm::PBQP::Vector, llvm::PBQP::Vector>(llvm::PBQP::Vector const&, llvm::PBQP::Vector const&)
Line
Count
Source
70
408
    static bool isEqual(const ValueKeyT1 &C1, const ValueKeyT2 &C2) {
71
408
      return C1 == C2;
72
408
    }
bool llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntryDSInfo::isEqual<llvm::PBQP::RegAlloc::AllowedRegVector, llvm::PBQP::RegAlloc::AllowedRegVector>(llvm::PBQP::RegAlloc::AllowedRegVector const&, llvm::PBQP::RegAlloc::AllowedRegVector const&)
Line
Count
Source
70
153
    static bool isEqual(const ValueKeyT1 &C1, const ValueKeyT2 &C2) {
71
153
      return C1 == C2;
72
153
    }
73
74
    template <typename ValueKeyT>
75
1.32k
    static bool isEqual(const ValueKeyT &C, PoolEntry *P) {
76
1.32k
      if (P == getEmptyKey() || 
P == getTombstoneKey()842
)
77
600
        return false;
78
720
      return isEqual(C, P->getValue());
79
720
    }
bool llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntryDSInfo::isEqual<llvm::PBQP::Matrix>(llvm::PBQP::Matrix const&, llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntry*)
Line
Count
Source
75
148
    static bool isEqual(const ValueKeyT &C, PoolEntry *P) {
76
148
      if (P == getEmptyKey() || 
P == getTombstoneKey()112
)
77
36
        return false;
78
112
      return isEqual(C, P->getValue());
79
112
    }
bool llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntryDSInfo::isEqual<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >(llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> const&, llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntry*)
Line
Count
Source
75
154
    static bool isEqual(const ValueKeyT &C, PoolEntry *P) {
76
154
      if (P == getEmptyKey() || 
P == getTombstoneKey()79
)
77
107
        return false;
78
47
      return isEqual(C, P->getValue());
79
47
    }
bool llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntryDSInfo::isEqual<llvm::PBQP::Vector>(llvm::PBQP::Vector const&, llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntry*)
Line
Count
Source
75
825
    static bool isEqual(const ValueKeyT &C, PoolEntry *P) {
76
825
      if (P == getEmptyKey() || 
P == getTombstoneKey()498
)
77
417
        return false;
78
408
      return isEqual(C, P->getValue());
79
408
    }
bool llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntryDSInfo::isEqual<llvm::PBQP::RegAlloc::AllowedRegVector>(llvm::PBQP::RegAlloc::AllowedRegVector const&, llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntry*)
Line
Count
Source
75
193
    static bool isEqual(const ValueKeyT &C, PoolEntry *P) {
76
193
      if (P == getEmptyKey() || 
P == getTombstoneKey()153
)
77
40
        return false;
78
153
      return isEqual(C, P->getValue());
79
153
    }
80
81
2.94k
    static bool isEqual(PoolEntry *P1, PoolEntry *P2) {
82
2.94k
      if (P1 == getEmptyKey() || 
P1 == getTombstoneKey()1.09k
)
83
2.30k
        return P1 == P2;
84
648
      return isEqual(P1->getValue(), P2);
85
648
    }
llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntryDSInfo::isEqual(llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntry*, llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntry*)
Line
Count
Source
81
767
    static bool isEqual(PoolEntry *P1, PoolEntry *P2) {
82
767
      if (P1 == getEmptyKey() || 
P1 == getTombstoneKey()240
)
83
613
        return P1 == P2;
84
154
      return isEqual(P1->getValue(), P2);
85
154
    }
llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntryDSInfo::isEqual(llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntry*, llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntry*)
Line
Count
Source
81
1.53k
    static bool isEqual(PoolEntry *P1, PoolEntry *P2) {
82
1.53k
      if (P1 == getEmptyKey() || 
P1 == getTombstoneKey()760
)
83
1.08k
        return P1 == P2;
84
446
      return isEqual(P1->getValue(), P2);
85
446
    }
llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntryDSInfo::isEqual(llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntry*, llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntry*)
Line
Count
Source
81
648
    static bool isEqual(PoolEntry *P1, PoolEntry *P2) {
82
648
      if (P1 == getEmptyKey() || 
P1 == getTombstoneKey()96
)
83
600
        return P1 == P2;
84
48
      return isEqual(P1->getValue(), P2);
85
48
    }
86
  };
87
88
  using EntrySetT = DenseSet<PoolEntry *, PoolEntryDSInfo>;
89
90
  EntrySetT EntrySet;
91
92
202
  void removeEntry(PoolEntry *P) { EntrySet.erase(P); }
llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::removeEntry(llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::PoolEntry*)
Line
Count
Source
92
43
  void removeEntry(PoolEntry *P) { EntrySet.erase(P); }
llvm::PBQP::ValuePool<llvm::PBQP::Vector>::removeEntry(llvm::PBQP::ValuePool<llvm::PBQP::Vector>::PoolEntry*)
Line
Count
Source
92
135
  void removeEntry(PoolEntry *P) { EntrySet.erase(P); }
llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::removeEntry(llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::PoolEntry*)
Line
Count
Source
92
24
  void removeEntry(PoolEntry *P) { EntrySet.erase(P); }
93
94
public:
95
623
  template <typename ValueKeyT> PoolRef getValue(ValueKeyT ValueKey) {
96
623
    typename EntrySetT::iterator I = EntrySet.find_as(ValueKey);
97
623
98
623
    if (I != EntrySet.end())
99
421
      return PoolRef((*I)->shared_from_this(), &(*I)->getValue());
100
202
101
202
    auto P = std::make_shared<PoolEntry>(*this, std::move(ValueKey));
102
202
    EntrySet.insert(P.get());
103
202
    return PoolRef(std::move(P), &P->getValue());
104
202
  }
std::__1::shared_ptr<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> const> llvm::PBQP::ValuePool<llvm::PBQP::MDMatrix<llvm::PBQP::RegAlloc::MatrixMetadata> >::getValue<llvm::PBQP::Matrix>(llvm::PBQP::Matrix)
Line
Count
Source
95
127
  template <typename ValueKeyT> PoolRef getValue(ValueKeyT ValueKey) {
96
127
    typename EntrySetT::iterator I = EntrySet.find_as(ValueKey);
97
127
98
127
    if (I != EntrySet.end())
99
84
      return PoolRef((*I)->shared_from_this(), &(*I)->getValue());
100
43
101
43
    auto P = std::make_shared<PoolEntry>(*this, std::move(ValueKey));
102
43
    EntrySet.insert(P.get());
103
43
    return PoolRef(std::move(P), &P->getValue());
104
43
  }
std::__1::shared_ptr<llvm::PBQP::Vector const> llvm::PBQP::ValuePool<llvm::PBQP::Vector>::getValue<llvm::PBQP::Vector>(llvm::PBQP::Vector)
Line
Count
Source
95
343
  template <typename ValueKeyT> PoolRef getValue(ValueKeyT ValueKey) {
96
343
    typename EntrySetT::iterator I = EntrySet.find_as(ValueKey);
97
343
98
343
    if (I != EntrySet.end())
99
208
      return PoolRef((*I)->shared_from_this(), &(*I)->getValue());
100
135
101
135
    auto P = std::make_shared<PoolEntry>(*this, std::move(ValueKey));
102
135
    EntrySet.insert(P.get());
103
135
    return PoolRef(std::move(P), &P->getValue());
104
135
  }
std::__1::shared_ptr<llvm::PBQP::RegAlloc::AllowedRegVector const> llvm::PBQP::ValuePool<llvm::PBQP::RegAlloc::AllowedRegVector>::getValue<llvm::PBQP::RegAlloc::AllowedRegVector>(llvm::PBQP::RegAlloc::AllowedRegVector)
Line
Count
Source
95
153
  template <typename ValueKeyT> PoolRef getValue(ValueKeyT ValueKey) {
96
153
    typename EntrySetT::iterator I = EntrySet.find_as(ValueKey);
97
153
98
153
    if (I != EntrySet.end())
99
129
      return PoolRef((*I)->shared_from_this(), &(*I)->getValue());
100
24
101
24
    auto P = std::make_shared<PoolEntry>(*this, std::move(ValueKey));
102
24
    EntrySet.insert(P.get());
103
24
    return PoolRef(std::move(P), &P->getValue());
104
24
  }
105
};
106
107
template <typename VectorT, typename MatrixT> class PoolCostAllocator {
108
private:
109
  using VectorCostPool = ValuePool<VectorT>;
110
  using MatrixCostPool = ValuePool<MatrixT>;
111
112
public:
113
  using Vector = VectorT;
114
  using Matrix = MatrixT;
115
  using VectorPtr = typename VectorCostPool::PoolRef;
116
  using MatrixPtr = typename MatrixCostPool::PoolRef;
117
118
343
  template <typename VectorKeyT> VectorPtr getVector(VectorKeyT v) {
119
343
    return VectorPool.getValue(std::move(v));
120
343
  }
121
122
127
  template <typename MatrixKeyT> MatrixPtr getMatrix(MatrixKeyT m) {
123
127
    return MatrixPool.getValue(std::move(m));
124
127
  }
125
126
private:
127
  VectorCostPool VectorPool;
128
  MatrixCostPool MatrixPool;
129
};
130
131
} // end namespace PBQP
132
} // end namespace llvm
133
134
#endif // LLVM_CODEGEN_PBQP_COSTALLOCATOR_H