Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/IR/TrackingMDRef.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/IR/TrackingMDRef.h - Tracking Metadata references ---*- 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
// References to metadata that track RAUW.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_IR_TRACKINGMDREF_H
14
#define LLVM_IR_TRACKINGMDREF_H
15
16
#include "llvm/IR/Metadata.h"
17
#include <algorithm>
18
#include <cassert>
19
20
namespace llvm {
21
22
/// Tracking metadata reference.
23
///
24
/// This class behaves like \a TrackingVH, but for metadata.
25
class TrackingMDRef {
26
  Metadata *MD = nullptr;
27
28
public:
29
299M
  TrackingMDRef() = default;
30
25.0M
  explicit TrackingMDRef(Metadata *MD) : MD(MD) { track(); }
31
32
139M
  TrackingMDRef(TrackingMDRef &&X) : MD(X.MD) { retrack(X); }
33
731M
  TrackingMDRef(const TrackingMDRef &X) : MD(X.MD) { track(); }
34
35
518M
  TrackingMDRef &operator=(TrackingMDRef &&X) {
36
518M
    if (&X == this)
37
0
      return *this;
38
518M
39
518M
    untrack();
40
518M
    MD = X.MD;
41
518M
    retrack(X);
42
518M
    return *this;
43
518M
  }
44
45
53.5M
  TrackingMDRef &operator=(const TrackingMDRef &X) {
46
53.5M
    if (&X == this)
47
978
      return *this;
48
53.5M
49
53.5M
    untrack();
50
53.5M
    MD = X.MD;
51
53.5M
    track();
52
53.5M
    return *this;
53
53.5M
  }
54
55
1.06G
  ~TrackingMDRef() { untrack(); }
56
57
900M
  Metadata *get() const { return MD; }
58
8.90M
  operator Metadata *() const { return get(); }
59
0
  Metadata *operator->() const { return get(); }
60
0
  Metadata &operator*() const { return *get(); }
61
62
  void reset() {
63
    untrack();
64
    MD = nullptr;
65
  }
66
584k
  void reset(Metadata *MD) {
67
584k
    untrack();
68
584k
    this->MD = MD;
69
584k
    track();
70
584k
  }
71
72
  /// Check whether this has a trivial destructor.
73
  ///
74
  /// If \c MD isn't replaceable, the destructor will be a no-op.
75
0
  bool hasTrivialDestructor() const {
76
0
    return !MD || !MetadataTracking::isReplaceable(*MD);
77
0
  }
78
79
3.11M
  bool operator==(const TrackingMDRef &X) const { return MD == X.MD; }
80
4.81M
  bool operator!=(const TrackingMDRef &X) const { return MD != X.MD; }
81
82
private:
83
811M
  void track() {
84
811M
    if (MD)
85
168M
      MetadataTracking::track(MD);
86
811M
  }
87
88
1.63G
  void untrack() {
89
1.63G
    if (MD)
90
151M
      MetadataTracking::untrack(MD);
91
1.63G
  }
92
93
658M
  void retrack(TrackingMDRef &X) {
94
658M
    assert(MD == X.MD && "Expected values to match");
95
658M
    if (X.MD) {
96
123M
      MetadataTracking::retrack(X.MD, MD);
97
123M
      X.MD = nullptr;
98
123M
    }
99
658M
  }
100
};
101
102
/// Typed tracking ref.
103
///
104
/// Track refererences of a particular type.  It's useful to use this for \a
105
/// MDNode and \a ValueAsMetadata.
106
template <class T> class TypedTrackingMDRef {
107
  TrackingMDRef Ref;
108
109
public:
110
299M
  TypedTrackingMDRef() = default;
llvm::TypedTrackingMDRef<llvm::MDNode>::TypedTrackingMDRef()
Line
Count
Source
110
299M
  TypedTrackingMDRef() = default;
llvm::TypedTrackingMDRef<llvm::DIDerivedType>::TypedTrackingMDRef()
Line
Count
Source
110
90
  TypedTrackingMDRef() = default;
111
24.4M
  explicit TypedTrackingMDRef(T *MD) : Ref(static_cast<Metadata *>(MD)) {}
llvm::TypedTrackingMDRef<llvm::MDNode>::TypedTrackingMDRef(llvm::MDNode*)
Line
Count
Source
111
24.3M
  explicit TypedTrackingMDRef(T *MD) : Ref(static_cast<Metadata *>(MD)) {}
llvm::TypedTrackingMDRef<llvm::DICompositeType>::TypedTrackingMDRef(llvm::DICompositeType*)
Line
Count
Source
111
3.31k
  explicit TypedTrackingMDRef(T *MD) : Ref(static_cast<Metadata *>(MD)) {}
llvm::TypedTrackingMDRef<llvm::DIScope>::TypedTrackingMDRef(llvm::DIScope*)
Line
Count
Source
111
119k
  explicit TypedTrackingMDRef(T *MD) : Ref(static_cast<Metadata *>(MD)) {}
112
113
139M
  TypedTrackingMDRef(TypedTrackingMDRef &&X) : Ref(std::move(X.Ref)) {}
llvm::TypedTrackingMDRef<llvm::MDNode>::TypedTrackingMDRef(llvm::TypedTrackingMDRef<llvm::MDNode>&&)
Line
Count
Source
113
139M
  TypedTrackingMDRef(TypedTrackingMDRef &&X) : Ref(std::move(X.Ref)) {}
Unexecuted instantiation: llvm::TypedTrackingMDRef<llvm::DIDerivedType>::TypedTrackingMDRef(llvm::TypedTrackingMDRef<llvm::DIDerivedType>&&)
114
731M
  TypedTrackingMDRef(const TypedTrackingMDRef &X) : Ref(X.Ref) {}
llvm::TypedTrackingMDRef<llvm::MDNode>::TypedTrackingMDRef(llvm::TypedTrackingMDRef<llvm::MDNode> const&)
Line
Count
Source
114
731M
  TypedTrackingMDRef(const TypedTrackingMDRef &X) : Ref(X.Ref) {}
llvm::TypedTrackingMDRef<llvm::DIScope>::TypedTrackingMDRef(llvm::TypedTrackingMDRef<llvm::DIScope> const&)
Line
Count
Source
114
595
  TypedTrackingMDRef(const TypedTrackingMDRef &X) : Ref(X.Ref) {}
115
116
518M
  TypedTrackingMDRef &operator=(TypedTrackingMDRef &&X) {
117
518M
    Ref = std::move(X.Ref);
118
518M
    return *this;
119
518M
  }
120
121
53.5M
  TypedTrackingMDRef &operator=(const TypedTrackingMDRef &X) {
122
53.5M
    Ref = X.Ref;
123
53.5M
    return *this;
124
53.5M
  }
125
126
834M
  T *get() const { return (T *)Ref.get(); }
llvm::TypedTrackingMDRef<llvm::MDNode>::get() const
Line
Count
Source
126
822M
  T *get() const { return (T *)Ref.get(); }
llvm::TypedTrackingMDRef<llvm::DICompositeType>::get() const
Line
Count
Source
126
5.60k
  T *get() const { return (T *)Ref.get(); }
llvm::TypedTrackingMDRef<llvm::DIDerivedType>::get() const
Line
Count
Source
126
14
  T *get() const { return (T *)Ref.get(); }
llvm::TypedTrackingMDRef<llvm::DIScope>::get() const
Line
Count
Source
126
12.6M
  T *get() const { return (T *)Ref.get(); }
127
769M
  operator T *() const { return get(); }
llvm::TypedTrackingMDRef<llvm::MDNode>::operator llvm::MDNode*() const
Line
Count
Source
127
762M
  operator T *() const { return get(); }
llvm::TypedTrackingMDRef<llvm::DIScope>::operator llvm::DIScope*() const
Line
Count
Source
127
6.38M
  operator T *() const { return get(); }
llvm::TypedTrackingMDRef<llvm::DIDerivedType>::operator llvm::DIDerivedType*() const
Line
Count
Source
127
14
  operator T *() const { return get(); }
128
77.5k
  T *operator->() const { return get(); }
llvm::TypedTrackingMDRef<llvm::MDNode>::operator->() const
Line
Count
Source
128
75.2k
  T *operator->() const { return get(); }
llvm::TypedTrackingMDRef<llvm::DICompositeType>::operator->() const
Line
Count
Source
128
2.28k
  T *operator->() const { return get(); }
129
  T &operator*() const { return *get(); }
130
131
3.11M
  bool operator==(const TypedTrackingMDRef &X) const { return Ref == X.Ref; }
132
4.81M
  bool operator!=(const TypedTrackingMDRef &X) const { return Ref != X.Ref; }
133
134
  void reset() { Ref.reset(); }
135
320k
  void reset(T *MD) { Ref.reset(static_cast<Metadata *>(MD)); }
llvm::TypedTrackingMDRef<llvm::MDNode>::reset(llvm::MDNode*)
Line
Count
Source
135
320k
  void reset(T *MD) { Ref.reset(static_cast<Metadata *>(MD)); }
llvm::TypedTrackingMDRef<llvm::DIDerivedType>::reset(llvm::DIDerivedType*)
Line
Count
Source
135
116
  void reset(T *MD) { Ref.reset(static_cast<Metadata *>(MD)); }
136
137
  /// Check whether this has a trivial destructor.
138
0
  bool hasTrivialDestructor() const { return Ref.hasTrivialDestructor(); }
139
};
140
141
using TrackingMDNodeRef = TypedTrackingMDRef<MDNode>;
142
using TrackingValueAsMetadataRef = TypedTrackingMDRef<ValueAsMetadata>;
143
144
// Expose the underlying metadata to casting.
145
template <> struct simplify_type<TrackingMDRef> {
146
  using SimpleType = Metadata *;
147
148
3.95k
  static SimpleType getSimplifiedValue(TrackingMDRef &MD) { return MD.get(); }
149
};
150
151
template <> struct simplify_type<const TrackingMDRef> {
152
  using SimpleType = Metadata *;
153
154
2.74k
  static SimpleType getSimplifiedValue(const TrackingMDRef &MD) {
155
2.74k
    return MD.get();
156
2.74k
  }
157
};
158
159
template <class T> struct simplify_type<TypedTrackingMDRef<T>> {
160
  using SimpleType = T *;
161
162
6.33M
  static SimpleType getSimplifiedValue(TypedTrackingMDRef<T> &MD) {
163
6.33M
    return MD.get();
164
6.33M
  }
llvm::simplify_type<llvm::TypedTrackingMDRef<llvm::MDNode> >::getSimplifiedValue(llvm::TypedTrackingMDRef<llvm::MDNode>&)
Line
Count
Source
162
27.0k
  static SimpleType getSimplifiedValue(TypedTrackingMDRef<T> &MD) {
163
27.0k
    return MD.get();
164
27.0k
  }
llvm::simplify_type<llvm::TypedTrackingMDRef<llvm::DIScope> >::getSimplifiedValue(llvm::TypedTrackingMDRef<llvm::DIScope>&)
Line
Count
Source
162
6.30M
  static SimpleType getSimplifiedValue(TypedTrackingMDRef<T> &MD) {
163
6.30M
    return MD.get();
164
6.30M
  }
165
};
166
167
template <class T> struct simplify_type<const TypedTrackingMDRef<T>> {
168
  using SimpleType = T *;
169
170
314
  static SimpleType getSimplifiedValue(const TypedTrackingMDRef<T> &MD) {
171
314
    return MD.get();
172
314
  }
173
};
174
175
} // end namespace llvm
176
177
#endif // LLVM_IR_TRACKINGMDREF_H