Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/IR/Metadata.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/IR/Metadata.h - Metadata definitions ----------------*- 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
/// @file
10
/// This file contains the declarations for metadata subclasses.
11
/// They represent the different flavors of metadata that live in LLVM.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_IR_METADATA_H
16
#define LLVM_IR_METADATA_H
17
18
#include "llvm/ADT/ArrayRef.h"
19
#include "llvm/ADT/DenseMap.h"
20
#include "llvm/ADT/DenseMapInfo.h"
21
#include "llvm/ADT/None.h"
22
#include "llvm/ADT/PointerUnion.h"
23
#include "llvm/ADT/STLExtras.h"
24
#include "llvm/ADT/SmallVector.h"
25
#include "llvm/ADT/StringRef.h"
26
#include "llvm/ADT/ilist_node.h"
27
#include "llvm/ADT/iterator_range.h"
28
#include "llvm/IR/Constant.h"
29
#include "llvm/IR/LLVMContext.h"
30
#include "llvm/IR/Value.h"
31
#include "llvm/Support/CBindingWrapping.h"
32
#include "llvm/Support/Casting.h"
33
#include "llvm/Support/ErrorHandling.h"
34
#include <cassert>
35
#include <cstddef>
36
#include <cstdint>
37
#include <iterator>
38
#include <memory>
39
#include <string>
40
#include <type_traits>
41
#include <utility>
42
43
namespace llvm {
44
45
class Module;
46
class ModuleSlotTracker;
47
class raw_ostream;
48
class Type;
49
50
enum LLVMConstants : uint32_t {
51
  DEBUG_METADATA_VERSION = 3 // Current debug info version number.
52
};
53
54
/// Root of the metadata hierarchy.
55
///
56
/// This is a root class for typeless data in the IR.
57
class Metadata {
58
  friend class ReplaceableMetadataImpl;
59
60
  /// RTTI.
61
  const unsigned char SubclassID;
62
63
protected:
64
  /// Active type of storage.
65
  enum StorageType { Uniqued, Distinct, Temporary };
66
67
  /// Storage flag for non-uniqued, otherwise unowned, metadata.
68
  unsigned char Storage : 7;
69
  // TODO: expose remaining bits to subclasses.
70
71
  unsigned char ImplicitCode : 1;
72
73
  unsigned short SubclassData16 = 0;
74
  unsigned SubclassData32 = 0;
75
76
public:
77
  enum MetadataKind {
78
#define HANDLE_METADATA_LEAF(CLASS) CLASS##Kind,
79
#include "llvm/IR/Metadata.def"
80
  };
81
82
protected:
83
  Metadata(unsigned ID, StorageType Storage)
84
6.03M
      : SubclassID(ID), Storage(Storage), ImplicitCode(false) {
85
6.03M
    static_assert(sizeof(*this) == 8, "Metadata fields poorly packed");
86
6.03M
  }
87
88
  ~Metadata() = default;
89
90
  /// Default handling of a changed operand, which asserts.
91
  ///
92
  /// If subclasses pass themselves in as owners to a tracking node reference,
93
  /// they must provide an implementation of this method.
94
0
  void handleChangedOperand(void *, Metadata *) {
95
0
    llvm_unreachable("Unimplemented in Metadata subclass");
96
0
  }
97
98
public:
99
1.29G
  unsigned getMetadataID() const { return SubclassID; }
100
101
  /// User-friendly dump.
102
  ///
103
  /// If \c M is provided, metadata nodes will be numbered canonically;
104
  /// otherwise, pointer addresses are substituted.
105
  ///
106
  /// Note: this uses an explicit overload instead of default arguments so that
107
  /// the nullptr version is easy to call from a debugger.
108
  ///
109
  /// @{
110
  void dump() const;
111
  void dump(const Module *M) const;
112
  /// @}
113
114
  /// Print.
115
  ///
116
  /// Prints definition of \c this.
117
  ///
118
  /// If \c M is provided, metadata nodes will be numbered canonically;
119
  /// otherwise, pointer addresses are substituted.
120
  /// @{
121
  void print(raw_ostream &OS, const Module *M = nullptr,
122
             bool IsForDebug = false) const;
123
  void print(raw_ostream &OS, ModuleSlotTracker &MST, const Module *M = nullptr,
124
             bool IsForDebug = false) const;
125
  /// @}
126
127
  /// Print as operand.
128
  ///
129
  /// Prints reference of \c this.
130
  ///
131
  /// If \c M is provided, metadata nodes will be numbered canonically;
132
  /// otherwise, pointer addresses are substituted.
133
  /// @{
134
  void printAsOperand(raw_ostream &OS, const Module *M = nullptr) const;
135
  void printAsOperand(raw_ostream &OS, ModuleSlotTracker &MST,
136
                      const Module *M = nullptr) const;
137
  /// @}
138
};
139
140
// Create wrappers for C Binding types (see CBindingWrapping.h).
141
DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef)
142
143
// Specialized opaque metadata conversions.
144
5
inline Metadata **unwrap(LLVMMetadataRef *MDs) {
145
5
  return reinterpret_cast<Metadata**>(MDs);
146
5
}
147
148
#define HANDLE_METADATA(CLASS) class CLASS;
149
#include "llvm/IR/Metadata.def"
150
151
// Provide specializations of isa so that we don't need definitions of
152
// subclasses to see if the metadata is a subclass.
153
#define HANDLE_METADATA_LEAF(CLASS)                                            \
154
  template <> struct isa_impl<CLASS, Metadata> {                               \
155
454M
    static inline bool doit(const Metadata &MD) {                              \
156
454M
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
454M
    }                                                                          \
llvm::isa_impl<llvm::MDString, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
63.2M
    static inline bool doit(const Metadata &MD) {                              \
156
63.2M
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
63.2M
    }                                                                          \
llvm::isa_impl<llvm::ConstantAsMetadata, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
60.1M
    static inline bool doit(const Metadata &MD) {                              \
156
60.1M
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
60.1M
    }                                                                          \
llvm::isa_impl<llvm::LocalAsMetadata, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
1.97M
    static inline bool doit(const Metadata &MD) {                              \
156
1.97M
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
1.97M
    }                                                                          \
llvm::isa_impl<llvm::DistinctMDOperandPlaceholder, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
328M
    static inline bool doit(const Metadata &MD) {                              \
156
328M
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
328M
    }                                                                          \
llvm::isa_impl<llvm::MDTuple, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
52.7k
    static inline bool doit(const Metadata &MD) {                              \
156
52.7k
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
52.7k
    }                                                                          \
llvm::isa_impl<llvm::DILocation, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
235k
    static inline bool doit(const Metadata &MD) {                              \
156
235k
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
235k
    }                                                                          \
llvm::isa_impl<llvm::DIExpression, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
419k
    static inline bool doit(const Metadata &MD) {                              \
156
419k
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
419k
    }                                                                          \
llvm::isa_impl<llvm::DIGlobalVariableExpression, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
5.12k
    static inline bool doit(const Metadata &MD) {                              \
156
5.12k
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
5.12k
    }                                                                          \
Unexecuted instantiation: llvm::isa_impl<llvm::GenericDINode, llvm::Metadata, void>::doit(llvm::Metadata const&)
Unexecuted instantiation: llvm::isa_impl<llvm::DISubrange, llvm::Metadata, void>::doit(llvm::Metadata const&)
Unexecuted instantiation: llvm::isa_impl<llvm::DIEnumerator, llvm::Metadata, void>::doit(llvm::Metadata const&)
llvm::isa_impl<llvm::DIBasicType, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
476
    static inline bool doit(const Metadata &MD) {                              \
156
476
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
476
    }                                                                          \
llvm::isa_impl<llvm::DIDerivedType, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
592
    static inline bool doit(const Metadata &MD) {                              \
156
592
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
592
    }                                                                          \
llvm::isa_impl<llvm::DICompositeType, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
14.0k
    static inline bool doit(const Metadata &MD) {                              \
156
14.0k
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
14.0k
    }                                                                          \
llvm::isa_impl<llvm::DISubroutineType, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
16.2k
    static inline bool doit(const Metadata &MD) {                              \
156
16.2k
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
16.2k
    }                                                                          \
llvm::isa_impl<llvm::DIFile, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
65.6k
    static inline bool doit(const Metadata &MD) {                              \
156
65.6k
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
65.6k
    }                                                                          \
llvm::isa_impl<llvm::DICompileUnit, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
13.5k
    static inline bool doit(const Metadata &MD) {                              \
156
13.5k
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
13.5k
    }                                                                          \
llvm::isa_impl<llvm::DISubprogram, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
128k
    static inline bool doit(const Metadata &MD) {                              \
156
128k
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
128k
    }                                                                          \
Unexecuted instantiation: llvm::isa_impl<llvm::DILexicalBlock, llvm::Metadata, void>::doit(llvm::Metadata const&)
Unexecuted instantiation: llvm::isa_impl<llvm::DILexicalBlockFile, llvm::Metadata, void>::doit(llvm::Metadata const&)
Unexecuted instantiation: llvm::isa_impl<llvm::DINamespace, llvm::Metadata, void>::doit(llvm::Metadata const&)
Unexecuted instantiation: llvm::isa_impl<llvm::DIModule, llvm::Metadata, void>::doit(llvm::Metadata const&)
Unexecuted instantiation: llvm::isa_impl<llvm::DITemplateTypeParameter, llvm::Metadata, void>::doit(llvm::Metadata const&)
Unexecuted instantiation: llvm::isa_impl<llvm::DITemplateValueParameter, llvm::Metadata, void>::doit(llvm::Metadata const&)
llvm::isa_impl<llvm::DIGlobalVariable, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
56
    static inline bool doit(const Metadata &MD) {                              \
156
56
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
56
    }                                                                          \
llvm::isa_impl<llvm::DILocalVariable, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
71.6k
    static inline bool doit(const Metadata &MD) {                              \
156
71.6k
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
71.6k
    }                                                                          \
llvm::isa_impl<llvm::DILabel, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
162
    static inline bool doit(const Metadata &MD) {                              \
156
162
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
162
    }                                                                          \
llvm::isa_impl<llvm::DIObjCProperty, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
29
    static inline bool doit(const Metadata &MD) {                              \
156
29
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
29
    }                                                                          \
llvm::isa_impl<llvm::DIImportedEntity, llvm::Metadata, void>::doit(llvm::Metadata const&)
Line
Count
Source
155
1.02k
    static inline bool doit(const Metadata &MD) {                              \
156
1.02k
      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
157
1.02k
    }                                                                          \
Unexecuted instantiation: llvm::isa_impl<llvm::DIMacro, llvm::Metadata, void>::doit(llvm::Metadata const&)
Unexecuted instantiation: llvm::isa_impl<llvm::DIMacroFile, llvm::Metadata, void>::doit(llvm::Metadata const&)
Unexecuted instantiation: llvm::isa_impl<llvm::DICommonBlock, llvm::Metadata, void>::doit(llvm::Metadata const&)
158
  };
159
#include "llvm/IR/Metadata.def"
160
161
6
inline raw_ostream &operator<<(raw_ostream &OS, const Metadata &MD) {
162
6
  MD.print(OS);
163
6
  return OS;
164
6
}
165
166
/// Metadata wrapper in the Value hierarchy.
167
///
168
/// A member of the \a Value hierarchy to represent a reference to metadata.
169
/// This allows, e.g., instrinsics to have metadata as operands.
170
///
171
/// Notably, this is the only thing in either hierarchy that is allowed to
172
/// reference \a LocalAsMetadata.
173
class MetadataAsValue : public Value {
174
  friend class ReplaceableMetadataImpl;
175
  friend class LLVMContextImpl;
176
177
  Metadata *MD;
178
179
  MetadataAsValue(Type *Ty, Metadata *MD);
180
181
  /// Drop use of metadata (during teardown).
182
21.4k
  void dropUse() { MD = nullptr; }
183
184
public:
185
  ~MetadataAsValue();
186
187
  static MetadataAsValue *get(LLVMContext &Context, Metadata *MD);
188
  static MetadataAsValue *getIfExists(LLVMContext &Context, Metadata *MD);
189
190
463k
  Metadata *getMetadata() const { return MD; }
191
192
12.4M
  static bool classof(const Value *V) {
193
12.4M
    return V->getValueID() == MetadataAsValueVal;
194
12.4M
  }
195
196
private:
197
  void handleChangedMetadata(Metadata *MD);
198
  void track();
199
  void untrack();
200
};
201
202
/// API for tracking metadata references through RAUW and deletion.
203
///
204
/// Shared API for updating \a Metadata pointers in subclasses that support
205
/// RAUW.
206
///
207
/// This API is not meant to be used directly.  See \a TrackingMDRef for a
208
/// user-friendly tracking reference.
209
class MetadataTracking {
210
public:
211
  /// Track the reference to metadata.
212
  ///
213
  /// Register \c MD with \c *MD, if the subclass supports tracking.  If \c *MD
214
  /// gets RAUW'ed, \c MD will be updated to the new address.  If \c *MD gets
215
  /// deleted, \c MD will be set to \c nullptr.
216
  ///
217
  /// If tracking isn't supported, \c *MD will not change.
218
  ///
219
  /// \return true iff tracking is supported by \c MD.
220
170M
  static bool track(Metadata *&MD) {
221
170M
    return track(&MD, *MD, static_cast<Metadata *>(nullptr));
222
170M
  }
223
224
  /// Track the reference to metadata for \a Metadata.
225
  ///
226
  /// As \a track(Metadata*&), but with support for calling back to \c Owner to
227
  /// tell it that its operand changed.  This could trigger \c Owner being
228
  /// re-uniqued.
229
7.47M
  static bool track(void *Ref, Metadata &MD, Metadata &Owner) {
230
7.47M
    return track(Ref, MD, &Owner);
231
7.47M
  }
232
233
  /// Track the reference to metadata for \a MetadataAsValue.
234
  ///
235
  /// As \a track(Metadata*&), but with support for calling back to \c Owner to
236
  /// tell it that its operand changed.  This could trigger \c Owner being
237
  /// re-uniqued.
238
58.6k
  static bool track(void *Ref, Metadata &MD, MetadataAsValue &Owner) {
239
58.6k
    return track(Ref, MD, &Owner);
240
58.6k
  }
241
242
  /// Stop tracking a reference to metadata.
243
  ///
244
  /// Stops \c *MD from tracking \c MD.
245
151M
  static void untrack(Metadata *&MD) { untrack(&MD, *MD); }
246
  static void untrack(void *Ref, Metadata &MD);
247
248
  /// Move tracking from one reference to another.
249
  ///
250
  /// Semantically equivalent to \c untrack(MD) followed by \c track(New),
251
  /// except that ownership callbacks are maintained.
252
  ///
253
  /// Note: it is an error if \c *MD does not equal \c New.
254
  ///
255
  /// \return true iff tracking is supported by \c MD.
256
123M
  static bool retrack(Metadata *&MD, Metadata *&New) {
257
123M
    return retrack(&MD, *MD, &New);
258
123M
  }
259
  static bool retrack(void *Ref, Metadata &MD, void *New);
260
261
  /// Check whether metadata is replaceable.
262
  static bool isReplaceable(const Metadata &MD);
263
264
  using OwnerTy = PointerUnion<MetadataAsValue *, Metadata *>;
265
266
private:
267
  /// Track a reference to metadata for an owner.
268
  ///
269
  /// Generalized version of tracking.
270
  static bool track(void *Ref, Metadata &MD, OwnerTy Owner);
271
};
272
273
/// Shared implementation of use-lists for replaceable metadata.
274
///
275
/// Most metadata cannot be RAUW'ed.  This is a shared implementation of
276
/// use-lists and associated API for the two that support it (\a ValueAsMetadata
277
/// and \a TempMDNode).
278
class ReplaceableMetadataImpl {
279
  friend class MetadataTracking;
280
281
public:
282
  using OwnerTy = MetadataTracking::OwnerTy;
283
284
private:
285
  LLVMContext &Context;
286
  uint64_t NextIndex = 0;
287
  SmallDenseMap<void *, std::pair<OwnerTy, uint64_t>, 4> UseMap;
288
289
public:
290
793k
  ReplaceableMetadataImpl(LLVMContext &Context) : Context(Context) {}
291
292
517k
  ~ReplaceableMetadataImpl() {
293
517k
    assert(UseMap.empty() && "Cannot destroy in-use replaceable metadata");
294
517k
  }
295
296
553k
  LLVMContext &getContext() const { return Context; }
297
298
  /// Replace all uses of this with MD.
299
  ///
300
  /// Replace all uses of this with \c MD, which is allowed to be null.
301
  void replaceAllUsesWith(Metadata *MD);
302
303
  /// Resolve all uses of this.
304
  ///
305
  /// Resolve all uses of this, turning off RAUW permanently.  If \c
306
  /// ResolveUsers, call \a MDNode::resolve() on any users whose last operand
307
  /// is resolved.
308
  void resolveAllUses(bool ResolveUsers = true);
309
310
private:
311
  void addRef(void *Ref, OwnerTy Owner);
312
  void dropRef(void *Ref);
313
  void moveRef(void *Ref, void *New, const Metadata &MD);
314
315
  /// Lazily construct RAUW support on MD.
316
  ///
317
  /// If this is an unresolved MDNode, RAUW support will be created on-demand.
318
  /// ValueAsMetadata always has RAUW support.
319
  static ReplaceableMetadataImpl *getOrCreate(Metadata &MD);
320
321
  /// Get RAUW support on MD, if it exists.
322
  static ReplaceableMetadataImpl *getIfExists(Metadata &MD);
323
324
  /// Check whether this node will support RAUW.
325
  ///
326
  /// Returns \c true unless getOrCreate() would return null.
327
  static bool isReplaceable(const Metadata &MD);
328
};
329
330
/// Value wrapper in the Metadata hierarchy.
331
///
332
/// This is a custom value handle that allows other metadata to refer to
333
/// classes in the Value hierarchy.
334
///
335
/// Because of full uniquing support, each value is only wrapped by a single \a
336
/// ValueAsMetadata object, so the lookup maps are far more efficient than
337
/// those using ValueHandleBase.
338
class ValueAsMetadata : public Metadata, ReplaceableMetadataImpl {
339
  friend class ReplaceableMetadataImpl;
340
  friend class LLVMContextImpl;
341
342
  Value *V;
343
344
  /// Drop users without RAUW (during teardown).
345
82.8k
  void dropUsers() {
346
82.8k
    ReplaceableMetadataImpl::resolveAllUses(/* ResolveUsers */ false);
347
82.8k
  }
348
349
protected:
350
  ValueAsMetadata(unsigned ID, Value *V)
351
382k
      : Metadata(ID, Uniqued), ReplaceableMetadataImpl(V->getContext()), V(V) {
352
382k
    assert(V && "Expected valid value");
353
382k
  }
354
355
105k
  ~ValueAsMetadata() = default;
356
357
public:
358
  static ValueAsMetadata *get(Value *V);
359
360
942k
  static ConstantAsMetadata *getConstant(Value *C) {
361
942k
    return cast<ConstantAsMetadata>(get(C));
362
942k
  }
363
364
599
  static LocalAsMetadata *getLocal(Value *Local) {
365
599
    return cast<LocalAsMetadata>(get(Local));
366
599
  }
367
368
  static ValueAsMetadata *getIfExists(Value *V);
369
370
0
  static ConstantAsMetadata *getConstantIfExists(Value *C) {
371
0
    return cast_or_null<ConstantAsMetadata>(getIfExists(C));
372
0
  }
373
374
5.22k
  static LocalAsMetadata *getLocalIfExists(Value *Local) {
375
5.22k
    return cast_or_null<LocalAsMetadata>(getIfExists(Local));
376
5.22k
  }
377
378
229M
  Value *getValue() const { return V; }
379
136
  Type *getType() const { return V->getType(); }
380
0
  LLVMContext &getContext() const { return V->getContext(); }
381
382
  static void handleDeletion(Value *V);
383
  static void handleRAUW(Value *From, Value *To);
384
385
protected:
386
  /// Handle collisions after \a Value::replaceAllUsesWith().
387
  ///
388
  /// RAUW isn't supported directly for \a ValueAsMetadata, but if the wrapped
389
  /// \a Value gets RAUW'ed and the target already exists, this is used to
390
  /// merge the two metadata nodes.
391
105k
  void replaceAllUsesWith(Metadata *MD) {
392
105k
    ReplaceableMetadataImpl::replaceAllUsesWith(MD);
393
105k
  }
394
395
public:
396
3.39M
  static bool classof(const Metadata *MD) {
397
3.39M
    return MD->getMetadataID() == LocalAsMetadataKind ||
398
3.39M
           
MD->getMetadataID() == ConstantAsMetadataKind3.29M
;
399
3.39M
  }
400
};
401
402
class ConstantAsMetadata : public ValueAsMetadata {
403
  friend class ValueAsMetadata;
404
405
  ConstantAsMetadata(Constant *C)
406
351k
      : ValueAsMetadata(ConstantAsMetadataKind, C) {}
407
408
public:
409
941k
  static ConstantAsMetadata *get(Constant *C) {
410
941k
    return ValueAsMetadata::getConstant(C);
411
941k
  }
412
413
0
  static ConstantAsMetadata *getIfExists(Constant *C) {
414
0
    return ValueAsMetadata::getConstantIfExists(C);
415
0
  }
416
417
229M
  Constant *getValue() const {
418
229M
    return cast<Constant>(ValueAsMetadata::getValue());
419
229M
  }
420
421
0
  static bool classof(const Metadata *MD) {
422
0
    return MD->getMetadataID() == ConstantAsMetadataKind;
423
0
  }
424
};
425
426
class LocalAsMetadata : public ValueAsMetadata {
427
  friend class ValueAsMetadata;
428
429
  LocalAsMetadata(Value *Local)
430
30.9k
      : ValueAsMetadata(LocalAsMetadataKind, Local) {
431
30.9k
    assert(!isa<Constant>(Local) && "Expected local value");
432
30.9k
  }
433
434
public:
435
599
  static LocalAsMetadata *get(Value *Local) {
436
599
    return ValueAsMetadata::getLocal(Local);
437
599
  }
438
439
5.22k
  static LocalAsMetadata *getIfExists(Value *Local) {
440
5.22k
    return ValueAsMetadata::getLocalIfExists(Local);
441
5.22k
  }
442
443
178k
  static bool classof(const Metadata *MD) {
444
178k
    return MD->getMetadataID() == LocalAsMetadataKind;
445
178k
  }
446
};
447
448
/// Transitional API for extracting constants from Metadata.
449
///
450
/// This namespace contains transitional functions for metadata that points to
451
/// \a Constants.
452
///
453
/// In prehistory -- when metadata was a subclass of \a Value -- \a MDNode
454
/// operands could refer to any \a Value.  There's was a lot of code like this:
455
///
456
/// \code
457
///     MDNode *N = ...;
458
///     auto *CI = dyn_cast<ConstantInt>(N->getOperand(2));
459
/// \endcode
460
///
461
/// Now that \a Value and \a Metadata are in separate hierarchies, maintaining
462
/// the semantics for \a isa(), \a cast(), \a dyn_cast() (etc.) requires three
463
/// steps: cast in the \a Metadata hierarchy, extraction of the \a Value, and
464
/// cast in the \a Value hierarchy.  Besides creating boiler-plate, this
465
/// requires subtle control flow changes.
466
///
467
/// The end-goal is to create a new type of metadata, called (e.g.) \a MDInt,
468
/// so that metadata can refer to numbers without traversing a bridge to the \a
469
/// Value hierarchy.  In this final state, the code above would look like this:
470
///
471
/// \code
472
///     MDNode *N = ...;
473
///     auto *MI = dyn_cast<MDInt>(N->getOperand(2));
474
/// \endcode
475
///
476
/// The API in this namespace supports the transition.  \a MDInt doesn't exist
477
/// yet, and even once it does, changing each metadata schema to use it is its
478
/// own mini-project.  In the meantime this API prevents us from introducing
479
/// complex and bug-prone control flow that will disappear in the end.  In
480
/// particular, the above code looks like this:
481
///
482
/// \code
483
///     MDNode *N = ...;
484
///     auto *CI = mdconst::dyn_extract<ConstantInt>(N->getOperand(2));
485
/// \endcode
486
///
487
/// The full set of provided functions includes:
488
///
489
///   mdconst::hasa                <=> isa
490
///   mdconst::extract             <=> cast
491
///   mdconst::extract_or_null     <=> cast_or_null
492
///   mdconst::dyn_extract         <=> dyn_cast
493
///   mdconst::dyn_extract_or_null <=> dyn_cast_or_null
494
///
495
/// The target of the cast must be a subclass of \a Constant.
496
namespace mdconst {
497
498
namespace detail {
499
500
template <class T> T &make();
501
template <class T, class Result> struct HasDereference {
502
  using Yes = char[1];
503
  using No = char[2];
504
  template <size_t N> struct SFINAE {};
505
506
  template <class U, class V>
507
  static Yes &hasDereference(SFINAE<sizeof(static_cast<V>(*make<U>()))> * = 0);
508
  template <class U, class V> static No &hasDereference(...);
509
510
  static const bool value =
511
      sizeof(hasDereference<T, Result>(nullptr)) == sizeof(Yes);
512
};
513
template <class V, class M> struct IsValidPointer {
514
  static const bool value = std::is_base_of<Constant, V>::value &&
515
                            HasDereference<M, const Metadata &>::value;
516
};
517
template <class V, class M> struct IsValidReference {
518
  static const bool value = std::is_base_of<Constant, V>::value &&
519
                            std::is_convertible<M, const Metadata &>::value;
520
};
521
522
} // end namespace detail
523
524
/// Check whether Metadata has a Value.
525
///
526
/// As an analogue to \a isa(), check whether \c MD has an \a Value inside of
527
/// type \c X.
528
template <class X, class Y>
529
inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, bool>::type
530
1.49k
hasa(Y &&MD) {
531
1.49k
  assert(MD && "Null pointer sent into hasa");
532
1.49k
  if (auto *V = dyn_cast<ConstantAsMetadata>(MD))
533
1.49k
    return isa<X>(V->getValue());
534
0
  return false;
535
0
}
536
template <class X, class Y>
537
inline
538
    typename std::enable_if<detail::IsValidReference<X, Y &>::value, bool>::type
539
    hasa(Y &MD) {
540
  return hasa(&MD);
541
}
542
543
/// Extract a Value from Metadata.
544
///
545
/// As an analogue to \a cast(), extract the \a Value subclass \c X from \c MD.
546
template <class X, class Y>
547
inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type
548
169M
extract(Y &&MD) {
549
169M
  return cast<X>(cast<ConstantAsMetadata>(MD)->getValue());
550
169M
}
std::__1::enable_if<detail::IsValidPointer<llvm::ConstantInt, llvm::MDOperand const&>::value, llvm::ConstantInt*>::type llvm::mdconst::extract<llvm::ConstantInt, llvm::MDOperand const&>(llvm::MDOperand const&&&)
Line
Count
Source
548
169M
extract(Y &&MD) {
549
169M
  return cast<X>(cast<ConstantAsMetadata>(MD)->getValue());
550
169M
}
std::__1::enable_if<detail::IsValidPointer<llvm::ConstantInt, llvm::Metadata* const&>::value, llvm::ConstantInt*>::type llvm::mdconst::extract<llvm::ConstantInt, llvm::Metadata* const&>(llvm::Metadata* const&&&)
Line
Count
Source
548
260
extract(Y &&MD) {
549
260
  return cast<X>(cast<ConstantAsMetadata>(MD)->getValue());
550
260
}
std::__1::enable_if<detail::IsValidPointer<llvm::ConstantFP, llvm::MDOperand const&>::value, llvm::ConstantFP*>::type llvm::mdconst::extract<llvm::ConstantFP, llvm::MDOperand const&>(llvm::MDOperand const&&&)
Line
Count
Source
548
90
extract(Y &&MD) {
549
90
  return cast<X>(cast<ConstantAsMetadata>(MD)->getValue());
550
90
}
std::__1::enable_if<detail::IsValidPointer<llvm::ConstantInt, llvm::Metadata*&>::value, llvm::ConstantInt*>::type llvm::mdconst::extract<llvm::ConstantInt, llvm::Metadata*&>(llvm::Metadata*&&&)
Line
Count
Source
548
10
extract(Y &&MD) {
549
10
  return cast<X>(cast<ConstantAsMetadata>(MD)->getValue());
550
10
}
551
template <class X, class Y>
552
inline
553
    typename std::enable_if<detail::IsValidReference<X, Y &>::value, X *>::type
554
    extract(Y &MD) {
555
  return extract(&MD);
556
}
557
558
/// Extract a Value from Metadata, allowing null.
559
///
560
/// As an analogue to \a cast_or_null(), extract the \a Value subclass \c X
561
/// from \c MD, allowing \c MD to be null.
562
template <class X, class Y>
563
inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type
564
74.8k
extract_or_null(Y &&MD) {
565
74.8k
  if (auto *V = cast_or_null<ConstantAsMetadata>(MD))
566
33.2k
    return cast<X>(V->getValue());
567
41.6k
  return nullptr;
568
41.6k
}
std::__1::enable_if<detail::IsValidPointer<llvm::ConstantInt, llvm::Metadata*>::value, llvm::ConstantInt*>::type llvm::mdconst::extract_or_null<llvm::ConstantInt, llvm::Metadata*>(llvm::Metadata*&&)
Line
Count
Source
564
74.4k
extract_or_null(Y &&MD) {
565
74.4k
  if (auto *V = cast_or_null<ConstantAsMetadata>(MD))
566
32.8k
    return cast<X>(V->getValue());
567
41.6k
  return nullptr;
568
41.6k
}
std::__1::enable_if<detail::IsValidPointer<llvm::Function, llvm::MDOperand const&>::value, llvm::Function*>::type llvm::mdconst::extract_or_null<llvm::Function, llvm::MDOperand const&>(llvm::MDOperand const&&&)
Line
Count
Source
564
2
extract_or_null(Y &&MD) {
565
2
  if (auto *V = cast_or_null<ConstantAsMetadata>(MD))
566
2
    return cast<X>(V->getValue());
567
0
  return nullptr;
568
0
}
std::__1::enable_if<detail::IsValidPointer<llvm::Constant, llvm::MDOperand const&>::value, llvm::Constant*>::type llvm::mdconst::extract_or_null<llvm::Constant, llvm::MDOperand const&>(llvm::MDOperand const&&&)
Line
Count
Source
564
418
extract_or_null(Y &&MD) {
565
418
  if (auto *V = cast_or_null<ConstantAsMetadata>(MD))
566
418
    return cast<X>(V->getValue());
567
0
  return nullptr;
568
0
}
569
570
/// Extract a Value from Metadata, if any.
571
///
572
/// As an analogue to \a dyn_cast_or_null(), extract the \a Value subclass \c X
573
/// from \c MD, return null if \c MD doesn't contain a \a Value or if the \a
574
/// Value it does contain is of the wrong subclass.
575
template <class X, class Y>
576
inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type
577
1.61M
dyn_extract(Y &&MD) {
578
1.61M
  if (auto *V = dyn_cast<ConstantAsMetadata>(MD))
579
1.61M
    return dyn_cast<X>(V->getValue());
580
35
  return nullptr;
581
35
}
std::__1::enable_if<detail::IsValidPointer<llvm::Function, llvm::MDOperand const&>::value, llvm::Function*>::type llvm::mdconst::dyn_extract<llvm::Function, llvm::MDOperand const&>(llvm::MDOperand const&&&)
Line
Count
Source
577
34
dyn_extract(Y &&MD) {
578
34
  if (auto *V = dyn_cast<ConstantAsMetadata>(MD))
579
34
    return dyn_cast<X>(V->getValue());
580
0
  return nullptr;
581
0
}
std::__1::enable_if<detail::IsValidPointer<llvm::ConstantInt, llvm::MDOperand const&>::value, llvm::ConstantInt*>::type llvm::mdconst::dyn_extract<llvm::ConstantInt, llvm::MDOperand const&>(llvm::MDOperand const&&&)
Line
Count
Source
577
1.60M
dyn_extract(Y &&MD) {
578
1.60M
  if (auto *V = dyn_cast<ConstantAsMetadata>(MD))
579
1.60M
    return dyn_cast<X>(V->getValue());
580
5
  return nullptr;
581
5
}
std::__1::enable_if<detail::IsValidPointer<llvm::ConstantInt, llvm::Metadata*&>::value, llvm::ConstantInt*>::type llvm::mdconst::dyn_extract<llvm::ConstantInt, llvm::Metadata*&>(llvm::Metadata*&&&)
Line
Count
Source
577
11.3k
dyn_extract(Y &&MD) {
578
11.3k
  if (auto *V = dyn_cast<ConstantAsMetadata>(MD))
579
11.2k
    return dyn_cast<X>(V->getValue());
580
26
  return nullptr;
581
26
}
std::__1::enable_if<detail::IsValidPointer<llvm::GlobalValue, llvm::Metadata*&>::value, llvm::GlobalValue*>::type llvm::mdconst::dyn_extract<llvm::GlobalValue, llvm::Metadata*&>(llvm::Metadata*&&&)
Line
Count
Source
577
30
dyn_extract(Y &&MD) {
578
30
  if (auto *V = dyn_cast<ConstantAsMetadata>(MD))
579
26
    return dyn_cast<X>(V->getValue());
580
4
  return nullptr;
581
4
}
582
583
/// Extract a Value from Metadata, if any, allowing null.
584
///
585
/// As an analogue to \a dyn_cast_or_null(), extract the \a Value subclass \c X
586
/// from \c MD, return null if \c MD doesn't contain a \a Value or if the \a
587
/// Value it does contain is of the wrong subclass, allowing \c MD to be null.
588
template <class X, class Y>
589
inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type
590
58.3M
dyn_extract_or_null(Y &&MD) {
591
58.3M
  if (auto *V = dyn_cast_or_null<ConstantAsMetadata>(MD))
592
58.3M
    return dyn_cast<X>(V->getValue());
593
44.2k
  return nullptr;
594
44.2k
}
std::__1::enable_if<detail::IsValidPointer<llvm::GlobalValue, llvm::MDOperand const&>::value, llvm::GlobalValue*>::type llvm::mdconst::dyn_extract_or_null<llvm::GlobalValue, llvm::MDOperand const&>(llvm::MDOperand const&&&)
Line
Count
Source
590
1.18k
dyn_extract_or_null(Y &&MD) {
591
1.18k
  if (auto *V = dyn_cast_or_null<ConstantAsMetadata>(MD))
592
1.17k
    return dyn_cast<X>(V->getValue());
593
10
  return nullptr;
594
10
}
std::__1::enable_if<detail::IsValidPointer<llvm::ConstantInt, llvm::MDOperand const&>::value, llvm::ConstantInt*>::type llvm::mdconst::dyn_extract_or_null<llvm::ConstantInt, llvm::MDOperand const&>(llvm::MDOperand const&&&)
Line
Count
Source
590
1.33M
dyn_extract_or_null(Y &&MD) {
591
1.33M
  if (auto *V = dyn_cast_or_null<ConstantAsMetadata>(MD))
592
1.33M
    return dyn_cast<X>(V->getValue());
593
4
  return nullptr;
594
4
}
std::__1::enable_if<detail::IsValidPointer<llvm::ConstantInt, llvm::Metadata*>::value, llvm::ConstantInt*>::type llvm::mdconst::dyn_extract_or_null<llvm::ConstantInt, llvm::Metadata*>(llvm::Metadata*&&)
Line
Count
Source
590
46.6k
dyn_extract_or_null(Y &&MD) {
591
46.6k
  if (auto *V = dyn_cast_or_null<ConstantAsMetadata>(MD))
592
2.46k
    return dyn_cast<X>(V->getValue());
593
44.2k
  return nullptr;
594
44.2k
}
std::__1::enable_if<detail::IsValidPointer<llvm::ConstantInt, llvm::Metadata*&>::value, llvm::ConstantInt*>::type llvm::mdconst::dyn_extract_or_null<llvm::ConstantInt, llvm::Metadata*&>(llvm::Metadata*&&&)
Line
Count
Source
590
57.0M
dyn_extract_or_null(Y &&MD) {
591
57.0M
  if (auto *V = dyn_cast_or_null<ConstantAsMetadata>(MD))
592
57.0M
    return dyn_cast<X>(V->getValue());
593
6
  return nullptr;
594
6
}
std::__1::enable_if<detail::IsValidPointer<llvm::ConstantFP, llvm::MDOperand const&>::value, llvm::ConstantFP*>::type llvm::mdconst::dyn_extract_or_null<llvm::ConstantFP, llvm::MDOperand const&>(llvm::MDOperand const&&&)
Line
Count
Source
590
415
dyn_extract_or_null(Y &&MD) {
591
415
  if (auto *V = dyn_cast_or_null<ConstantAsMetadata>(MD))
592
415
    return dyn_cast<X>(V->getValue());
593
0
  return nullptr;
594
0
}
595
596
} // end namespace mdconst
597
598
//===----------------------------------------------------------------------===//
599
/// A single uniqued string.
600
///
601
/// These are used to efficiently contain a byte sequence for metadata.
602
/// MDString is always unnamed.
603
class MDString : public Metadata {
604
  friend class StringMapEntry<MDString>;
605
606
  StringMapEntry<MDString> *Entry = nullptr;
607
608
439k
  MDString() : Metadata(MDStringKind, Uniqued) {}
609
610
public:
611
  MDString(const MDString &) = delete;
612
  MDString &operator=(MDString &&) = delete;
613
  MDString &operator=(const MDString &) = delete;
614
615
  static MDString *get(LLVMContext &Context, StringRef Str);
616
67.6k
  static MDString *get(LLVMContext &Context, const char *Str) {
617
67.6k
    return get(Context, Str ? StringRef(Str) : 
StringRef()0
);
618
67.6k
  }
619
620
  StringRef getString() const;
621
622
10.0k
  unsigned getLength() const { return (unsigned)getString().size(); }
623
624
  using iterator = StringRef::iterator;
625
626
  /// Pointer to the first byte of the string.
627
0
  iterator begin() const { return getString().begin(); }
628
629
  /// Pointer to one byte past the end of the string.
630
0
  iterator end() const { return getString().end(); }
631
632
0
  const unsigned char *bytes_begin() const { return getString().bytes_begin(); }
633
0
  const unsigned char *bytes_end() const { return getString().bytes_end(); }
634
635
  /// Methods for support type inquiry through isa, cast, and dyn_cast.
636
0
  static bool classof(const Metadata *MD) {
637
0
    return MD->getMetadataID() == MDStringKind;
638
0
  }
639
};
640
641
/// A collection of metadata nodes that might be associated with a
642
/// memory access used by the alias-analysis infrastructure.
643
struct AAMDNodes {
644
  explicit AAMDNodes(MDNode *T = nullptr, MDNode *S = nullptr,
645
                     MDNode *N = nullptr)
646
2.16G
      : TBAA(T), Scope(S), NoAlias(N) {}
647
648
2.71G
  bool operator==(const AAMDNodes &A) const {
649
2.71G
    return TBAA == A.TBAA && 
Scope == A.Scope2.67G
&&
NoAlias == A.NoAlias2.67G
;
650
2.71G
  }
651
652
2.59M
  bool operator!=(const AAMDNodes &A) const { return !(*this == A); }
653
654
5.00M
  explicit operator bool() const { return TBAA || 
Scope990k
||
NoAlias986k
; }
655
656
  /// The tag for type-based alias analysis.
657
  MDNode *TBAA;
658
659
  /// The tag for alias scope specification (used with noalias).
660
  MDNode *Scope;
661
662
  /// The tag specifying the noalias scope.
663
  MDNode *NoAlias;
664
665
  /// Given two sets of AAMDNodes that apply to the same pointer,
666
  /// give the best AAMDNodes that are compatible with both (i.e. a set of
667
  /// nodes whose allowable aliasing conclusions are a subset of those
668
  /// allowable by both of the inputs). However, for efficiency
669
  /// reasons, do not create any new MDNodes.
670
2.02M
  AAMDNodes intersect(const AAMDNodes &Other) {
671
2.02M
    AAMDNodes Result;
672
2.02M
    Result.TBAA = Other.TBAA == TBAA ? 
TBAA1.90M
:
nullptr118k
;
673
2.02M
    Result.Scope = Other.Scope == Scope ? 
Scope2.02M
:
nullptr1.89k
;
674
2.02M
    Result.NoAlias = Other.NoAlias == NoAlias ? 
NoAlias2.02M
:
nullptr3.01k
;
675
2.02M
    return Result;
676
2.02M
  }
677
};
678
679
// Specialize DenseMapInfo for AAMDNodes.
680
template<>
681
struct DenseMapInfo<AAMDNodes> {
682
24.5M
  static inline AAMDNodes getEmptyKey() {
683
24.5M
    return AAMDNodes(DenseMapInfo<MDNode *>::getEmptyKey(),
684
24.5M
                     nullptr, nullptr);
685
24.5M
  }
686
687
17.4M
  static inline AAMDNodes getTombstoneKey() {
688
17.4M
    return AAMDNodes(DenseMapInfo<MDNode *>::getTombstoneKey(),
689
17.4M
                     nullptr, nullptr);
690
17.4M
  }
691
692
524M
  static unsigned getHashValue(const AAMDNodes &Val) {
693
524M
    return DenseMapInfo<MDNode *>::getHashValue(Val.TBAA) ^
694
524M
           DenseMapInfo<MDNode *>::getHashValue(Val.Scope) ^
695
524M
           DenseMapInfo<MDNode *>::getHashValue(Val.NoAlias);
696
524M
  }
697
698
0
  static bool isEqual(const AAMDNodes &LHS, const AAMDNodes &RHS) {
699
0
    return LHS == RHS;
700
0
  }
701
};
702
703
/// Tracking metadata reference owned by Metadata.
704
///
705
/// Similar to \a TrackingMDRef, but it's expected to be owned by an instance
706
/// of \a Metadata, which has the option of registering itself for callbacks to
707
/// re-unique itself.
708
///
709
/// In particular, this is used by \a MDNode.
710
class MDOperand {
711
  Metadata *MD = nullptr;
712
713
public:
714
9.85M
  MDOperand() = default;
715
  MDOperand(MDOperand &&) = delete;
716
  MDOperand(const MDOperand &) = delete;
717
  MDOperand &operator=(MDOperand &&) = delete;
718
  MDOperand &operator=(const MDOperand &) = delete;
719
686k
  ~MDOperand() { untrack(); }
720
721
1.49G
  Metadata *get() const { return MD; }
722
483M
  operator Metadata *() const { return get(); }
723
0
  Metadata *operator->() const { return get(); }
724
6
  Metadata &operator*() const { return *get(); }
725
726
0
  void reset() {
727
0
    untrack();
728
0
    MD = nullptr;
729
0
  }
730
11.1M
  void reset(Metadata *MD, Metadata *Owner) {
731
11.1M
    untrack();
732
11.1M
    this->MD = MD;
733
11.1M
    track(Owner);
734
11.1M
  }
735
736
private:
737
11.1M
  void track(Metadata *Owner) {
738
11.1M
    if (MD) {
739
9.64M
      if (Owner)
740
7.47M
        MetadataTracking::track(this, *MD, *Owner);
741
2.17M
      else
742
2.17M
        MetadataTracking::track(MD);
743
9.64M
    }
744
11.1M
  }
745
746
11.8M
  void untrack() {
747
11.8M
    assert(static_cast<void *>(this) == &MD && "Expected same address");
748
11.8M
    if (MD)
749
753k
      MetadataTracking::untrack(MD);
750
11.8M
  }
751
};
752
753
template <> struct simplify_type<MDOperand> {
754
  using SimpleType = Metadata *;
755
756
0
  static SimpleType getSimplifiedValue(MDOperand &MD) { return MD.get(); }
757
};
758
759
template <> struct simplify_type<const MDOperand> {
760
  using SimpleType = Metadata *;
761
762
941M
  static SimpleType getSimplifiedValue(const MDOperand &MD) { return MD.get(); }
763
};
764
765
/// Pointer to the context, with optional RAUW support.
766
///
767
/// Either a raw (non-null) pointer to the \a LLVMContext, or an owned pointer
768
/// to \a ReplaceableMetadataImpl (which has a reference to \a LLVMContext).
769
class ContextAndReplaceableUses {
770
  PointerUnion<LLVMContext *, ReplaceableMetadataImpl *> Ptr;
771
772
public:
773
5.17M
  ContextAndReplaceableUses(LLVMContext &Context) : Ptr(&Context) {}
774
  ContextAndReplaceableUses(
775
      std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses)
776
      : Ptr(ReplaceableUses.release()) {
777
    assert(getReplaceableUses() && "Expected non-null replaceable uses");
778
  }
779
  ContextAndReplaceableUses() = delete;
780
  ContextAndReplaceableUses(ContextAndReplaceableUses &&) = delete;
781
  ContextAndReplaceableUses(const ContextAndReplaceableUses &) = delete;
782
  ContextAndReplaceableUses &operator=(ContextAndReplaceableUses &&) = delete;
783
  ContextAndReplaceableUses &
784
  operator=(const ContextAndReplaceableUses &) = delete;
785
595k
  ~ContextAndReplaceableUses() { delete getReplaceableUses(); }
786
787
0
  operator LLVMContext &() { return getContext(); }
788
789
  /// Whether this contains RAUW support.
790
15.6M
  bool hasReplaceableUses() const {
791
15.6M
    return Ptr.is<ReplaceableMetadataImpl *>();
792
15.6M
  }
793
794
10.1M
  LLVMContext &getContext() const {
795
10.1M
    if (hasReplaceableUses())
796
141k
      return getReplaceableUses()->getContext();
797
10.0M
    return *Ptr.get<LLVMContext *>();
798
10.0M
  }
799
800
3.37M
  ReplaceableMetadataImpl *getReplaceableUses() const {
801
3.37M
    if (hasReplaceableUses())
802
2.36M
      return Ptr.get<ReplaceableMetadataImpl *>();
803
1.00M
    return nullptr;
804
1.00M
  }
805
806
  /// Ensure that this has RAUW support, and then return it.
807
659k
  ReplaceableMetadataImpl *getOrCreateReplaceableUses() {
808
659k
    if (!hasReplaceableUses())
809
411k
      makeReplaceable(llvm::make_unique<ReplaceableMetadataImpl>(getContext()));
810
659k
    return getReplaceableUses();
811
659k
  }
812
813
  /// Assign RAUW support to this.
814
  ///
815
  /// Make this replaceable, taking ownership of \c ReplaceableUses (which must
816
  /// not be null).
817
  void
818
411k
  makeReplaceable(std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses) {
819
411k
    assert(ReplaceableUses && "Expected non-null replaceable uses");
820
411k
    assert(&ReplaceableUses->getContext() == &getContext() &&
821
411k
           "Expected same context");
822
411k
    delete getReplaceableUses();
823
411k
    Ptr = ReplaceableUses.release();
824
411k
  }
825
826
  /// Drop RAUW support.
827
  ///
828
  /// Cede ownership of RAUW support, returning it.
829
411k
  std::unique_ptr<ReplaceableMetadataImpl> takeReplaceableUses() {
830
411k
    assert(hasReplaceableUses() && "Expected to own replaceable uses");
831
411k
    std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses(
832
411k
        getReplaceableUses());
833
411k
    Ptr = &ReplaceableUses->getContext();
834
411k
    return ReplaceableUses;
835
411k
  }
836
};
837
838
struct TempMDNodeDeleter {
839
  inline void operator()(MDNode *Node) const;
840
};
841
842
#define HANDLE_MDNODE_LEAF(CLASS)                                              \
843
  using Temp##CLASS = std::unique_ptr<CLASS, TempMDNodeDeleter>;
844
#define HANDLE_MDNODE_BRANCH(CLASS) HANDLE_MDNODE_LEAF(CLASS)
845
#include "llvm/IR/Metadata.def"
846
847
/// Metadata node.
848
///
849
/// Metadata nodes can be uniqued, like constants, or distinct.  Temporary
850
/// metadata nodes (with full support for RAUW) can be used to delay uniquing
851
/// until forward references are known.  The basic metadata node is an \a
852
/// MDTuple.
853
///
854
/// There is limited support for RAUW at construction time.  At construction
855
/// time, if any operand is a temporary node (or an unresolved uniqued node,
856
/// which indicates a transitive temporary operand), the node itself will be
857
/// unresolved.  As soon as all operands become resolved, it will drop RAUW
858
/// support permanently.
859
///
860
/// If an unresolved node is part of a cycle, \a resolveCycles() needs
861
/// to be called on some member of the cycle once all temporary nodes have been
862
/// replaced.
863
class MDNode : public Metadata {
864
  friend class ReplaceableMetadataImpl;
865
  friend class LLVMContextImpl;
866
867
  unsigned NumOperands;
868
  unsigned NumUnresolved;
869
870
  ContextAndReplaceableUses Context;
871
872
protected:
873
  MDNode(LLVMContext &Context, unsigned ID, StorageType Storage,
874
         ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None);
875
595k
  ~MDNode() = default;
876
877
  void *operator new(size_t Size, unsigned NumOps);
878
  void operator delete(void *Mem);
879
880
  /// Required by std, but never called.
881
0
  void operator delete(void *, unsigned) {
882
0
    llvm_unreachable("Constructor throws?");
883
0
  }
884
885
  /// Required by std, but never called.
886
0
  void operator delete(void *, unsigned, bool) {
887
0
    llvm_unreachable("Constructor throws?");
888
0
  }
889
890
  void dropAllReferences();
891
892
816M
  MDOperand *mutable_begin() { return mutable_end() - NumOperands; }
893
823M
  MDOperand *mutable_end() { return reinterpret_cast<MDOperand *>(this); }
894
895
  using mutable_op_range = iterator_range<MDOperand *>;
896
897
1.16k
  mutable_op_range mutable_operands() {
898
1.16k
    return mutable_op_range(mutable_begin(), mutable_end());
899
1.16k
  }
900
901
public:
902
  MDNode(const MDNode &) = delete;
903
  void operator=(const MDNode &) = delete;
904
  void *operator new(size_t) = delete;
905
906
  static inline MDTuple *get(LLVMContext &Context, ArrayRef<Metadata *> MDs);
907
  static inline MDTuple *getIfExists(LLVMContext &Context,
908
                                     ArrayRef<Metadata *> MDs);
909
  static inline MDTuple *getDistinct(LLVMContext &Context,
910
                                     ArrayRef<Metadata *> MDs);
911
  static inline TempMDTuple getTemporary(LLVMContext &Context,
912
                                         ArrayRef<Metadata *> MDs);
913
914
  /// Create a (temporary) clone of this.
915
  TempMDNode clone() const;
916
917
  /// Deallocate a node created by getTemporary.
918
  ///
919
  /// Calls \c replaceAllUsesWith(nullptr) before deleting, so any remaining
920
  /// references will be reset.
921
  static void deleteTemporary(MDNode *N);
922
923
9.77M
  LLVMContext &getContext() const { return Context.getContext(); }
924
925
  /// Replace a specific operand.
926
  void replaceOperandWith(unsigned I, Metadata *New);
927
928
  /// Check if node is fully resolved.
929
  ///
930
  /// If \a isTemporary(), this always returns \c false; if \a isDistinct(),
931
  /// this always returns \c true.
932
  ///
933
  /// If \a isUniqued(), returns \c true if this has already dropped RAUW
934
  /// support (because all operands are resolved).
935
  ///
936
  /// As forward declarations are resolved, their containers should get
937
  /// resolved automatically.  However, if this (or one of its operands) is
938
  /// involved in a cycle, \a resolveCycles() needs to be called explicitly.
939
457M
  bool isResolved() const { return !isTemporary() && 
!NumUnresolved456M
; }
940
941
16.5M
  bool isUniqued() const { return Storage == Uniqued; }
942
341k
  bool isDistinct() const { return Storage == Distinct; }
943
458M
  bool isTemporary() const { return Storage == Temporary; }
944
945
  /// RAUW a temporary.
946
  ///
947
  /// \pre \a isTemporary() must be \c true.
948
623k
  void replaceAllUsesWith(Metadata *MD) {
949
623k
    assert(isTemporary() && "Expected temporary node");
950
623k
    if (Context.hasReplaceableUses())
951
571k
      Context.getReplaceableUses()->replaceAllUsesWith(MD);
952
623k
  }
953
954
  /// Resolve cycles.
955
  ///
956
  /// Once all forward declarations have been resolved, force cycles to be
957
  /// resolved.
958
  ///
959
  /// \pre No operands (or operands' operands, etc.) have \a isTemporary().
960
  void resolveCycles();
961
962
  /// Resolve a unique, unresolved node.
963
  void resolve();
964
965
  /// Replace a temporary node with a permanent one.
966
  ///
967
  /// Try to create a uniqued version of \c N -- in place, if possible -- and
968
  /// return it.  If \c N cannot be uniqued, return a distinct node instead.
969
  template <class T>
970
  static typename std::enable_if<std::is_base_of<MDNode, T>::value, T *>::type
971
0
  replaceWithPermanent(std::unique_ptr<T, TempMDNodeDeleter> N) {
972
0
    return cast<T>(N.release()->replaceWithPermanentImpl());
973
0
  }
974
975
  /// Replace a temporary node with a uniqued one.
976
  ///
977
  /// Create a uniqued version of \c N -- in place, if possible -- and return
978
  /// it.  Takes ownership of the temporary node.
979
  ///
980
  /// \pre N does not self-reference.
981
  template <class T>
982
  static typename std::enable_if<std::is_base_of<MDNode, T>::value, T *>::type
983
2.72k
  replaceWithUniqued(std::unique_ptr<T, TempMDNodeDeleter> N) {
984
2.72k
    return cast<T>(N.release()->replaceWithUniquedImpl());
985
2.72k
  }
std::__1::enable_if<std::is_base_of<llvm::MDNode, llvm::DIType>::value, llvm::DIType*>::type llvm::MDNode::replaceWithUniqued<llvm::DIType>(std::__1::unique_ptr<llvm::DIType, llvm::TempMDNodeDeleter>)
Line
Count
Source
983
2.15k
  replaceWithUniqued(std::unique_ptr<T, TempMDNodeDeleter> N) {
984
2.15k
    return cast<T>(N.release()->replaceWithUniquedImpl());
985
2.15k
  }
std::__1::enable_if<std::is_base_of<llvm::MDNode, llvm::MDNode>::value, llvm::MDNode*>::type llvm::MDNode::replaceWithUniqued<llvm::MDNode>(std::__1::unique_ptr<llvm::MDNode, llvm::TempMDNodeDeleter>)
Line
Count
Source
983
575
  replaceWithUniqued(std::unique_ptr<T, TempMDNodeDeleter> N) {
984
575
    return cast<T>(N.release()->replaceWithUniquedImpl());
985
575
  }
986
987
  /// Replace a temporary node with a distinct one.
988
  ///
989
  /// Create a distinct version of \c N -- in place, if possible -- and return
990
  /// it.  Takes ownership of the temporary node.
991
  template <class T>
992
  static typename std::enable_if<std::is_base_of<MDNode, T>::value, T *>::type
993
1.17k
  replaceWithDistinct(std::unique_ptr<T, TempMDNodeDeleter> N) {
994
1.17k
    return cast<T>(N.release()->replaceWithDistinctImpl());
995
1.17k
  }
std::__1::enable_if<std::is_base_of<llvm::MDNode, llvm::DISubprogram>::value, llvm::DISubprogram*>::type llvm::MDNode::replaceWithDistinct<llvm::DISubprogram>(std::__1::unique_ptr<llvm::DISubprogram, llvm::TempMDNodeDeleter>)
Line
Count
Source
993
3
  replaceWithDistinct(std::unique_ptr<T, TempMDNodeDeleter> N) {
994
3
    return cast<T>(N.release()->replaceWithDistinctImpl());
995
3
  }
std::__1::enable_if<std::is_base_of<llvm::MDNode, llvm::MDNode>::value, llvm::MDNode*>::type llvm::MDNode::replaceWithDistinct<llvm::MDNode>(std::__1::unique_ptr<llvm::MDNode, llvm::TempMDNodeDeleter>)
Line
Count
Source
993
190
  replaceWithDistinct(std::unique_ptr<T, TempMDNodeDeleter> N) {
994
190
    return cast<T>(N.release()->replaceWithDistinctImpl());
995
190
  }
std::__1::enable_if<std::is_base_of<llvm::MDNode, llvm::DICompositeType>::value, llvm::DICompositeType*>::type llvm::MDNode::replaceWithDistinct<llvm::DICompositeType>(std::__1::unique_ptr<llvm::DICompositeType, llvm::TempMDNodeDeleter>)
Line
Count
Source
993
979
  replaceWithDistinct(std::unique_ptr<T, TempMDNodeDeleter> N) {
994
979
    return cast<T>(N.release()->replaceWithDistinctImpl());
995
979
  }
996
997
private:
998
  MDNode *replaceWithPermanentImpl();
999
  MDNode *replaceWithUniquedImpl();
1000
  MDNode *replaceWithDistinctImpl();
1001
1002
protected:
1003
  /// Set an operand.
1004
  ///
1005
  /// Sets the operand directly, without worrying about uniquing.
1006
  void setOperand(unsigned I, Metadata *New);
1007
1008
  void storeDistinctInContext();
1009
  template <class T, class StoreT>
1010
  static T *storeImpl(T *N, StorageType Storage, StoreT &Store);
1011
  template <class T> static T *storeImpl(T *N, StorageType Storage);
1012
1013
private:
1014
  void handleChangedOperand(void *Ref, Metadata *New);
1015
1016
  /// Drop RAUW support, if any.
1017
  void dropReplaceableUses();
1018
1019
  void resolveAfterOperandChange(Metadata *Old, Metadata *New);
1020
  void decrementUnresolvedOperandCount();
1021
  void countUnresolvedOperands();
1022
1023
  /// Mutate this to be "uniqued".
1024
  ///
1025
  /// Mutate this so that \a isUniqued().
1026
  /// \pre \a isTemporary().
1027
  /// \pre already added to uniquing set.
1028
  void makeUniqued();
1029
1030
  /// Mutate this to be "distinct".
1031
  ///
1032
  /// Mutate this so that \a isDistinct().
1033
  /// \pre \a isTemporary().
1034
  void makeDistinct();
1035
1036
  void deleteAsSubclass();
1037
  MDNode *uniquify();
1038
  void eraseFromStore();
1039
1040
  template <class NodeTy> struct HasCachedHash;
1041
  template <class NodeTy>
1042
50.3k
  static void dispatchRecalculateHash(NodeTy *N, std::true_type) {
1043
50.3k
    N->recalculateHash();
1044
50.3k
  }
void llvm::MDNode::dispatchRecalculateHash<llvm::MDTuple>(llvm::MDTuple*, std::__1::integral_constant<bool, true>)
Line
Count
Source
1042
50.2k
  static void dispatchRecalculateHash(NodeTy *N, std::true_type) {
1043
50.2k
    N->recalculateHash();
1044
50.2k
  }
void llvm::MDNode::dispatchRecalculateHash<llvm::GenericDINode>(llvm::GenericDINode*, std::__1::integral_constant<bool, true>)
Line
Count
Source
1042
15
  static void dispatchRecalculateHash(NodeTy *N, std::true_type) {
1043
15
    N->recalculateHash();
1044
15
  }
1045
  template <class NodeTy>
1046
12.6k
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DILocation>(llvm::DILocation*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
1.46k
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DIExpression>(llvm::DIExpression*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
1
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DIGlobalVariableExpression>(llvm::DIGlobalVariableExpression*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
1.07k
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DISubrange>(llvm::DISubrange*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
11
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DIEnumerator>(llvm::DIEnumerator*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
1
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DIBasicType>(llvm::DIBasicType*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
2
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DIDerivedType>(llvm::DIDerivedType*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
4.08k
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DICompositeType>(llvm::DICompositeType*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
1.29k
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DISubroutineType>(llvm::DISubroutineType*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
2.00k
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DIFile>(llvm::DIFile*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
1
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DISubprogram>(llvm::DISubprogram*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
571
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DILexicalBlock>(llvm::DILexicalBlock*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
1
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DILexicalBlockFile>(llvm::DILexicalBlockFile*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
68
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DINamespace>(llvm::DINamespace*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
13
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DIModule>(llvm::DIModule*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
1
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DITemplateTypeParameter>(llvm::DITemplateTypeParameter*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
12
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DITemplateValueParameter>(llvm::DITemplateValueParameter*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
25
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DIGlobalVariable>(llvm::DIGlobalVariable*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
652
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DILocalVariable>(llvm::DILocalVariable*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
1.15k
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DILabel>(llvm::DILabel*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
3
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DIObjCProperty>(llvm::DIObjCProperty*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
1
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DIImportedEntity>(llvm::DIImportedEntity*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
239
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
Unexecuted instantiation: void llvm::MDNode::dispatchRecalculateHash<llvm::DIMacro>(llvm::DIMacro*, std::__1::integral_constant<bool, false>)
void llvm::MDNode::dispatchRecalculateHash<llvm::DIMacroFile>(llvm::DIMacroFile*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
14
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchRecalculateHash<llvm::DICommonBlock>(llvm::DICommonBlock*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1046
4
  static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
1047
  template <class NodeTy>
1048
171k
  static void dispatchResetHash(NodeTy *N, std::true_type) {
1049
171k
    N->setHash(0);
1050
171k
  }
void llvm::MDNode::dispatchResetHash<llvm::MDTuple>(llvm::MDTuple*, std::__1::integral_constant<bool, true>)
Line
Count
Source
1048
171k
  static void dispatchResetHash(NodeTy *N, std::true_type) {
1049
171k
    N->setHash(0);
1050
171k
  }
void llvm::MDNode::dispatchResetHash<llvm::GenericDINode>(llvm::GenericDINode*, std::__1::integral_constant<bool, true>)
Line
Count
Source
1048
11
  static void dispatchResetHash(NodeTy *N, std::true_type) {
1049
11
    N->setHash(0);
1050
11
  }
1051
  template <class NodeTy>
1052
742k
  static void dispatchResetHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchResetHash<llvm::DILocation>(llvm::DILocation*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1052
608k
  static void dispatchResetHash(NodeTy *, std::false_type) {}
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DIExpression>(llvm::DIExpression*, std::__1::integral_constant<bool, false>)
void llvm::MDNode::dispatchResetHash<llvm::DIGlobalVariableExpression>(llvm::DIGlobalVariableExpression*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1052
122
  static void dispatchResetHash(NodeTy *, std::false_type) {}
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DISubrange>(llvm::DISubrange*, std::__1::integral_constant<bool, false>)
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DIEnumerator>(llvm::DIEnumerator*, std::__1::integral_constant<bool, false>)
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DIBasicType>(llvm::DIBasicType*, std::__1::integral_constant<bool, false>)
void llvm::MDNode::dispatchResetHash<llvm::DIDerivedType>(llvm::DIDerivedType*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1052
11
  static void dispatchResetHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchResetHash<llvm::DICompositeType>(llvm::DICompositeType*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1052
1.66k
  static void dispatchResetHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchResetHash<llvm::DISubroutineType>(llvm::DISubroutineType*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1052
3
  static void dispatchResetHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchResetHash<llvm::DIFile>(llvm::DIFile*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1052
38
  static void dispatchResetHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchResetHash<llvm::DICompileUnit>(llvm::DICompileUnit*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1052
6.64k
  static void dispatchResetHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchResetHash<llvm::DISubprogram>(llvm::DISubprogram*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1052
121k
  static void dispatchResetHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchResetHash<llvm::DILexicalBlock>(llvm::DILexicalBlock*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1052
2.15k
  static void dispatchResetHash(NodeTy *, std::false_type) {}
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DILexicalBlockFile>(llvm::DILexicalBlockFile*, std::__1::integral_constant<bool, false>)
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DINamespace>(llvm::DINamespace*, std::__1::integral_constant<bool, false>)
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DIModule>(llvm::DIModule*, std::__1::integral_constant<bool, false>)
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DITemplateTypeParameter>(llvm::DITemplateTypeParameter*, std::__1::integral_constant<bool, false>)
void llvm::MDNode::dispatchResetHash<llvm::DITemplateValueParameter>(llvm::DITemplateValueParameter*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1052
49
  static void dispatchResetHash(NodeTy *, std::false_type) {}
void llvm::MDNode::dispatchResetHash<llvm::DIGlobalVariable>(llvm::DIGlobalVariable*, std::__1::integral_constant<bool, false>)
Line
Count
Source
1052
1.36k
  static void dispatchResetHash(NodeTy *, std::false_type) {}
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DILocalVariable>(llvm::DILocalVariable*, std::__1::integral_constant<bool, false>)
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DILabel>(llvm::DILabel*, std::__1::integral_constant<bool, false>)
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DIObjCProperty>(llvm::DIObjCProperty*, std::__1::integral_constant<bool, false>)
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DIImportedEntity>(llvm::DIImportedEntity*, std::__1::integral_constant<bool, false>)
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DIMacro>(llvm::DIMacro*, std::__1::integral_constant<bool, false>)
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DIMacroFile>(llvm::DIMacroFile*, std::__1::integral_constant<bool, false>)
Unexecuted instantiation: void llvm::MDNode::dispatchResetHash<llvm::DICommonBlock>(llvm::DICommonBlock*, std::__1::integral_constant<bool, false>)
1053
1054
public:
1055
  using op_iterator = const MDOperand *;
1056
  using op_range = iterator_range<op_iterator>;
1057
1058
805M
  op_iterator op_begin() const {
1059
805M
    return const_cast<MDNode *>(this)->mutable_begin();
1060
805M
  }
1061
1062
6.93M
  op_iterator op_end() const {
1063
6.93M
    return const_cast<MDNode *>(this)->mutable_end();
1064
6.93M
  }
1065
1066
5.17M
  op_range operands() const { return op_range(op_begin(), op_end()); }
1067
1068
797M
  const MDOperand &getOperand(unsigned I) const {
1069
797M
    assert(I < NumOperands && "Out of range");
1070
797M
    return op_begin()[I];
1071
797M
  }
1072
1073
  /// Return number of MDNode operands.
1074
560M
  unsigned getNumOperands() const { return NumOperands; }
1075
1076
  /// Methods for support type inquiry through isa, cast, and dyn_cast:
1077
801M
  static bool classof(const Metadata *MD) {
1078
801M
    switch (MD->getMetadataID()) {
1079
801M
    default:
1080
78.9M
      return false;
1081
801M
#define HANDLE_MDNODE_LEAF(CLASS)                                              \
1082
801M
  case CLASS##Kind:                                                            \
1083
722M
    return true;
1084
801M
#include 
"llvm/IR/Metadata.def"290M
1085
801M
    }
1086
801M
  }
1087
1088
  /// Check whether MDNode is a vtable access.
1089
  bool isTBAAVtableAccess() const;
1090
1091
  /// Methods for metadata merging.
1092
  static MDNode *concatenate(MDNode *A, MDNode *B);
1093
  static MDNode *intersect(MDNode *A, MDNode *B);
1094
  static MDNode *getMostGenericTBAA(MDNode *A, MDNode *B);
1095
  static MDNode *getMostGenericFPMath(MDNode *A, MDNode *B);
1096
  static MDNode *getMostGenericRange(MDNode *A, MDNode *B);
1097
  static MDNode *getMostGenericAliasScope(MDNode *A, MDNode *B);
1098
  static MDNode *getMostGenericAlignmentOrDereferenceable(MDNode *A, MDNode *B);
1099
};
1100
1101
/// Tuple of metadata.
1102
///
1103
/// This is the simple \a MDNode arbitrary tuple.  Nodes are uniqued by
1104
/// default based on their operands.
1105
class MDTuple : public MDNode {
1106
  friend class LLVMContextImpl;
1107
  friend class MDNode;
1108
1109
  MDTuple(LLVMContext &C, StorageType Storage, unsigned Hash,
1110
          ArrayRef<Metadata *> Vals)
1111
1.16M
      : MDNode(C, MDTupleKind, Storage, Vals) {
1112
1.16M
    setHash(Hash);
1113
1.16M
  }
1114
1115
490k
  ~MDTuple() { dropAllReferences(); }
1116
1117
1.38M
  void setHash(unsigned Hash) { SubclassData32 = Hash; }
1118
  void recalculateHash();
1119
1120
  static MDTuple *getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
1121
                          StorageType Storage, bool ShouldCreate = true);
1122
1123
50
  TempMDTuple cloneImpl() const {
1124
50
    return getTemporary(getContext(),
1125
50
                        SmallVector<Metadata *, 4>(op_begin(), op_end()));
1126
50
  }
1127
1128
public:
1129
  /// Get the hash, if any.
1130
3.15M
  unsigned getHash() const { return SubclassData32; }
1131
1132
1.50M
  static MDTuple *get(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
1133
1.50M
    return getImpl(Context, MDs, Uniqued);
1134
1.50M
  }
1135
1136
  static MDTuple *getIfExists(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
1137
    return getImpl(Context, MDs, Uniqued, /* ShouldCreate */ false);
1138
  }
1139
1140
  /// Return a distinct node.
1141
  ///
1142
  /// Return a distinct node -- i.e., a node that is not uniqued.
1143
110k
  static MDTuple *getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
1144
110k
    return getImpl(Context, MDs, Distinct);
1145
110k
  }
1146
1147
  /// Return a temporary node.
1148
  ///
1149
  /// For use in constructing cyclic MDNode structures. A temporary MDNode is
1150
  /// not uniqued, may be RAUW'd, and must be manually deleted with
1151
  /// deleteTemporary.
1152
  static TempMDTuple getTemporary(LLVMContext &Context,
1153
363k
                                  ArrayRef<Metadata *> MDs) {
1154
363k
    return TempMDTuple(getImpl(Context, MDs, Temporary));
1155
363k
  }
1156
1157
  /// Return a (temporary) clone of this.
1158
0
  TempMDTuple clone() const { return cloneImpl(); }
1159
1160
46
  static bool classof(const Metadata *MD) {
1161
46
    return MD->getMetadataID() == MDTupleKind;
1162
46
  }
1163
};
1164
1165
1.35M
MDTuple *MDNode::get(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
1166
1.35M
  return MDTuple::get(Context, MDs);
1167
1.35M
}
1168
1169
MDTuple *MDNode::getIfExists(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
1170
  return MDTuple::getIfExists(Context, MDs);
1171
}
1172
1173
109k
MDTuple *MDNode::getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
1174
109k
  return MDTuple::getDistinct(Context, MDs);
1175
109k
}
1176
1177
TempMDTuple MDNode::getTemporary(LLVMContext &Context,
1178
146k
                                 ArrayRef<Metadata *> MDs) {
1179
146k
  return MDTuple::getTemporary(Context, MDs);
1180
146k
}
1181
1182
363k
void TempMDNodeDeleter::operator()(MDNode *Node) const {
1183
363k
  MDNode::deleteTemporary(Node);
1184
363k
}
1185
1186
/// Typed iterator through MDNode operands.
1187
///
1188
/// An iterator that transforms an \a MDNode::iterator into an iterator over a
1189
/// particular Metadata subclass.
1190
template <class T>
1191
class TypedMDOperandIterator
1192
    : public std::iterator<std::input_iterator_tag, T *, std::ptrdiff_t, void,
1193
                           T *> {
1194
  MDNode::op_iterator I = nullptr;
1195
1196
public:
1197
26.6k
  TypedMDOperandIterator() = default;
llvm::TypedMDOperandIterator<llvm::DINode>::TypedMDOperandIterator()
Line
Count
Source
1197
7.61k
  TypedMDOperandIterator() = default;
Unexecuted instantiation: llvm::TypedMDOperandIterator<llvm::DISubprogram>::TypedMDOperandIterator()
llvm::TypedMDOperandIterator<llvm::DIGlobalVariableExpression>::TypedMDOperandIterator()
Line
Count
Source
1197
520
  TypedMDOperandIterator() = default;
llvm::TypedMDOperandIterator<llvm::DICompositeType>::TypedMDOperandIterator()
Line
Count
Source
1197
82
  TypedMDOperandIterator() = default;
llvm::TypedMDOperandIterator<llvm::DIScope>::TypedMDOperandIterator()
Line
Count
Source
1197
5.90k
  TypedMDOperandIterator() = default;
llvm::TypedMDOperandIterator<llvm::DIImportedEntity>::TypedMDOperandIterator()
Line
Count
Source
1197
12.3k
  TypedMDOperandIterator() = default;
llvm::TypedMDOperandIterator<llvm::DITemplateParameter>::TypedMDOperandIterator()
Line
Count
Source
1197
170
  TypedMDOperandIterator() = default;
Unexecuted instantiation: llvm::TypedMDOperandIterator<llvm::DIMacroNode>::TypedMDOperandIterator()
1198
419k
  explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {}
llvm::TypedMDOperandIterator<llvm::DINode>::TypedMDOperandIterator(llvm::MDOperand const*)
Line
Count
Source
1198
404k
  explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {}
llvm::TypedMDOperandIterator<llvm::DISubprogram>::TypedMDOperandIterator(llvm::MDOperand const*)
Line
Count
Source
1198
7.28k
  explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {}
llvm::TypedMDOperandIterator<llvm::DIGlobalVariableExpression>::TypedMDOperandIterator(llvm::MDOperand const*)
Line
Count
Source
1198
3.07k
  explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {}
llvm::TypedMDOperandIterator<llvm::DICompositeType>::TypedMDOperandIterator(llvm::MDOperand const*)
Line
Count
Source
1198
1.59k
  explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {}
llvm::TypedMDOperandIterator<llvm::DIScope>::TypedMDOperandIterator(llvm::MDOperand const*)
Line
Count
Source
1198
1.50k
  explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {}
llvm::TypedMDOperandIterator<llvm::DIImportedEntity>::TypedMDOperandIterator(llvm::MDOperand const*)
Line
Count
Source
1198
1.78k
  explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {}
Unexecuted instantiation: llvm::TypedMDOperandIterator<llvm::DITemplateParameter>::TypedMDOperandIterator(llvm::MDOperand const*)
llvm::TypedMDOperandIterator<llvm::DIMacroNode>::TypedMDOperandIterator(llvm::MDOperand const*)
Line
Count
Source
1198
10
  explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {}
1199
1200
135k
  T *operator*() const { return cast_or_null<T>(*I); }
llvm::TypedMDOperandIterator<llvm::DINode>::operator*() const
Line
Count
Source
1200
13.8k
  T *operator*() const { return cast_or_null<T>(*I); }
llvm::TypedMDOperandIterator<llvm::DISubprogram>::operator*() const
Line
Count
Source
1200
118k
  T *operator*() const { return cast_or_null<T>(*I); }
llvm::TypedMDOperandIterator<llvm::DIGlobalVariableExpression>::operator*() const
Line
Count
Source
1200
2.04k
  T *operator*() const { return cast_or_null<T>(*I); }
llvm::TypedMDOperandIterator<llvm::DICompositeType>::operator*() const
Line
Count
Source
1200
93
  T *operator*() const { return cast_or_null<T>(*I); }
llvm::TypedMDOperandIterator<llvm::DIScope>::operator*() const
Line
Count
Source
1200
734
  T *operator*() const { return cast_or_null<T>(*I); }
llvm::TypedMDOperandIterator<llvm::DIImportedEntity>::operator*() const
Line
Count
Source
1200
486
  T *operator*() const { return cast_or_null<T>(*I); }
Unexecuted instantiation: llvm::TypedMDOperandIterator<llvm::DITemplateParameter>::operator*() const
llvm::TypedMDOperandIterator<llvm::DIMacroNode>::operator*() const
Line
Count
Source
1200
7
  T *operator*() const { return cast_or_null<T>(*I); }
1201
1202
135k
  TypedMDOperandIterator &operator++() {
1203
135k
    ++I;
1204
135k
    return *this;
1205
135k
  }
llvm::TypedMDOperandIterator<llvm::DINode>::operator++()
Line
Count
Source
1202
13.8k
  TypedMDOperandIterator &operator++() {
1203
13.8k
    ++I;
1204
13.8k
    return *this;
1205
13.8k
  }
llvm::TypedMDOperandIterator<llvm::DISubprogram>::operator++()
Line
Count
Source
1202
118k
  TypedMDOperandIterator &operator++() {
1203
118k
    ++I;
1204
118k
    return *this;
1205
118k
  }
llvm::TypedMDOperandIterator<llvm::DIGlobalVariableExpression>::operator++()
Line
Count
Source
1202
2.04k
  TypedMDOperandIterator &operator++() {
1203
2.04k
    ++I;
1204
2.04k
    return *this;
1205
2.04k
  }
llvm::TypedMDOperandIterator<llvm::DICompositeType>::operator++()
Line
Count
Source
1202
93
  TypedMDOperandIterator &operator++() {
1203
93
    ++I;
1204
93
    return *this;
1205
93
  }
llvm::TypedMDOperandIterator<llvm::DIScope>::operator++()
Line
Count
Source
1202
734
  TypedMDOperandIterator &operator++() {
1203
734
    ++I;
1204
734
    return *this;
1205
734
  }
llvm::TypedMDOperandIterator<llvm::DIImportedEntity>::operator++()
Line
Count
Source
1202
475
  TypedMDOperandIterator &operator++() {
1203
475
    ++I;
1204
475
    return *this;
1205
475
  }
Unexecuted instantiation: llvm::TypedMDOperandIterator<llvm::DITemplateParameter>::operator++()
llvm::TypedMDOperandIterator<llvm::DIMacroNode>::operator++()
Line
Count
Source
1202
7
  TypedMDOperandIterator &operator++() {
1203
7
    ++I;
1204
7
    return *this;
1205
7
  }
1206
1207
  TypedMDOperandIterator operator++(int) {
1208
    TypedMDOperandIterator Temp(*this);
1209
    ++I;
1210
    return Temp;
1211
  }
1212
1213
  bool operator==(const TypedMDOperandIterator &X) const { return I == X.I; }
1214
358k
  bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
llvm::TypedMDOperandIterator<llvm::DINode>::operator!=(llvm::TypedMDOperandIterator<llvm::DINode> const&) const
Line
Count
Source
1214
219k
  bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
llvm::TypedMDOperandIterator<llvm::DISubprogram>::operator!=(llvm::TypedMDOperandIterator<llvm::DISubprogram> const&) const
Line
Count
Source
1214
121k
  bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
llvm::TypedMDOperandIterator<llvm::DIGlobalVariableExpression>::operator!=(llvm::TypedMDOperandIterator<llvm::DIGlobalVariableExpression> const&) const
Line
Count
Source
1214
3.84k
  bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
llvm::TypedMDOperandIterator<llvm::DICompositeType>::operator!=(llvm::TypedMDOperandIterator<llvm::DICompositeType> const&) const
Line
Count
Source
1214
932
  bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
llvm::TypedMDOperandIterator<llvm::DIScope>::operator!=(llvm::TypedMDOperandIterator<llvm::DIScope> const&) const
Line
Count
Source
1214
4.43k
  bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
llvm::TypedMDOperandIterator<llvm::DIImportedEntity>::operator!=(llvm::TypedMDOperandIterator<llvm::DIImportedEntity> const&) const
Line
Count
Source
1214
7.55k
  bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
llvm::TypedMDOperandIterator<llvm::DITemplateParameter>::operator!=(llvm::TypedMDOperandIterator<llvm::DITemplateParameter> const&) const
Line
Count
Source
1214
85
  bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
llvm::TypedMDOperandIterator<llvm::DIMacroNode>::operator!=(llvm::TypedMDOperandIterator<llvm::DIMacroNode> const&) const
Line
Count
Source
1214
12
  bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
1215
};
1216
1217
/// Typed, array-like tuple of metadata.
1218
///
1219
/// This is a wrapper for \a MDTuple that makes it act like an array holding a
1220
/// particular type of metadata.
1221
template <class T> class MDTupleTypedArrayWrapper {
1222
  const MDTuple *N = nullptr;
1223
1224
public:
1225
123k
  MDTupleTypedArrayWrapper() = default;
llvm::MDTupleTypedArrayWrapper<llvm::DIMacroNode>::MDTupleTypedArrayWrapper()
Line
Count
Source
1225
22
  MDTupleTypedArrayWrapper() = default;
llvm::MDTupleTypedArrayWrapper<llvm::DINode>::MDTupleTypedArrayWrapper()
Line
Count
Source
1225
123k
  MDTupleTypedArrayWrapper() = default;
1226
1.00M
  MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
llvm::MDTupleTypedArrayWrapper<llvm::DINode>::MDTupleTypedArrayWrapper(llvm::MDTuple const*)
Line
Count
Source
1226
681k
  MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
llvm::MDTupleTypedArrayWrapper<llvm::DITemplateParameter>::MDTupleTypedArrayWrapper(llvm::MDTuple const*)
Line
Count
Source
1226
124k
  MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
llvm::MDTupleTypedArrayWrapper<llvm::DIType>::MDTupleTypedArrayWrapper(llvm::MDTuple const*)
Line
Count
Source
1226
121k
  MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
llvm::MDTupleTypedArrayWrapper<llvm::DICompositeType>::MDTupleTypedArrayWrapper(llvm::MDTuple const*)
Line
Count
Source
1226
21.0k
  MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
llvm::MDTupleTypedArrayWrapper<llvm::DIScope>::MDTupleTypedArrayWrapper(llvm::MDTuple const*)
Line
Count
Source
1226
14.7k
  MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
llvm::MDTupleTypedArrayWrapper<llvm::DIGlobalVariableExpression>::MDTupleTypedArrayWrapper(llvm::MDTuple const*)
Line
Count
Source
1226
14.8k
  MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
llvm::MDTupleTypedArrayWrapper<llvm::DIImportedEntity>::MDTupleTypedArrayWrapper(llvm::MDTuple const*)
Line
Count
Source
1226
13.8k
  MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
llvm::MDTupleTypedArrayWrapper<llvm::DIMacroNode>::MDTupleTypedArrayWrapper(llvm::MDTuple const*)
Line
Count
Source
1226
12.9k
  MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
llvm::MDTupleTypedArrayWrapper<llvm::DISubprogram>::MDTupleTypedArrayWrapper(llvm::MDTuple const*)
Line
Count
Source
1226
3.64k
  MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
1227
1228
  template <class U>
1229
  MDTupleTypedArrayWrapper(
1230
      const MDTupleTypedArrayWrapper<U> &Other,
1231
      typename std::enable_if<std::is_convertible<U *, T *>::value>::type * =
1232
          nullptr)
1233
3.65k
      : N(Other.get()) {}
llvm::MDTupleTypedArrayWrapper<llvm::DINode>::MDTupleTypedArrayWrapper<llvm::DITemplateParameter>(llvm::MDTupleTypedArrayWrapper<llvm::DITemplateParameter> const&, std::__1::enable_if<std::is_convertible<llvm::DITemplateParameter*, llvm::DINode*>::value, void>::type*)
Line
Count
Source
1233
2.21k
      : N(Other.get()) {}
llvm::MDTupleTypedArrayWrapper<llvm::DINode>::MDTupleTypedArrayWrapper<llvm::DIType>(llvm::MDTupleTypedArrayWrapper<llvm::DIType> const&, std::__1::enable_if<std::is_convertible<llvm::DIType*, llvm::DINode*>::value, void>::type*)
Line
Count
Source
1233
1.44k
      : N(Other.get()) {}
1234
1235
  template <class U>
1236
  explicit MDTupleTypedArrayWrapper(
1237
      const MDTupleTypedArrayWrapper<U> &Other,
1238
      typename std::enable_if<!std::is_convertible<U *, T *>::value>::type * =
1239
          nullptr)
1240
315
      : N(Other.get()) {}
1241
1242
12.4k
  explicit operator bool() const { return get(); }
llvm::MDTupleTypedArrayWrapper<llvm::DINode>::operator bool() const
Line
Count
Source
1242
9.81k
  explicit operator bool() const { return get(); }
llvm::MDTupleTypedArrayWrapper<llvm::DIMacroNode>::operator bool() const
Line
Count
Source
1242
2.66k
  explicit operator bool() const { return get(); }
1243
  explicit operator MDTuple *() const { return get(); }
1244
1245
903k
  MDTuple *get() const { return const_cast<MDTuple *>(N); }
llvm::MDTupleTypedArrayWrapper<llvm::DINode>::get() const
Line
Count
Source
1245
608k
  MDTuple *get() const { return const_cast<MDTuple *>(N); }
llvm::MDTupleTypedArrayWrapper<llvm::DITemplateParameter>::get() const
Line
Count
Source
1245
125k
  MDTuple *get() const { return const_cast<MDTuple *>(N); }
llvm::MDTupleTypedArrayWrapper<llvm::DICompositeType>::get() const
Line
Count
Source
1245
16.6k
  MDTuple *get() const { return const_cast<MDTuple *>(N); }
llvm::MDTupleTypedArrayWrapper<llvm::DIScope>::get() const
Line
Count
Source
1245
7.54k
  MDTuple *get() const { return const_cast<MDTuple *>(N); }
llvm::MDTupleTypedArrayWrapper<llvm::DIGlobalVariableExpression>::get() const
Line
Count
Source
1245
9.71k
  MDTuple *get() const { return const_cast<MDTuple *>(N); }
llvm::MDTupleTypedArrayWrapper<llvm::DIImportedEntity>::get() const
Line
Count
Source
1245
6.74k
  MDTuple *get() const { return const_cast<MDTuple *>(N); }
llvm::MDTupleTypedArrayWrapper<llvm::DIMacroNode>::get() const
Line
Count
Source
1245
7.48k
  MDTuple *get() const { return const_cast<MDTuple *>(N); }
llvm::MDTupleTypedArrayWrapper<llvm::DIType>::get() const
Line
Count
Source
1245
121k
  MDTuple *get() const { return const_cast<MDTuple *>(N); }
1246
18.5k
  MDTuple *operator->() const { return get(); }
llvm::MDTupleTypedArrayWrapper<llvm::DICompositeType>::operator->() const
Line
Count
Source
1246
8.39k
  MDTuple *operator->() const { return get(); }
llvm::MDTupleTypedArrayWrapper<llvm::DIScope>::operator->() const
Line
Count
Source
1246
2.96k
  MDTuple *operator->() const { return get(); }
llvm::MDTupleTypedArrayWrapper<llvm::DIGlobalVariableExpression>::operator->() const
Line
Count
Source
1246
4.93k
  MDTuple *operator->() const { return get(); }
llvm::MDTupleTypedArrayWrapper<llvm::DIImportedEntity>::operator->() const
Line
Count
Source
1246
2.13k
  MDTuple *operator->() const { return get(); }
llvm::MDTupleTypedArrayWrapper<llvm::DIMacroNode>::operator->() const
Line
Count
Source
1246
162
  MDTuple *operator->() const { return get(); }
1247
  MDTuple &operator*() const { return *get(); }
1248
1249
  // FIXME: Fix callers and remove condition on N.
1250
351
  unsigned size() const { return N ? 
N->getNumOperands()350
:
0u1
; }
1251
15.8k
  bool empty() const { return N ? 
N->getNumOperands() == 04.68k
:
true11.1k
; }
llvm::MDTupleTypedArrayWrapper<llvm::DICompositeType>::empty() const
Line
Count
Source
1251
3.53k
  bool empty() const { return N ? 
N->getNumOperands() == 03.46k
:
true71
; }
llvm::MDTupleTypedArrayWrapper<llvm::DIScope>::empty() const
Line
Count
Source
1251
3.50k
  bool empty() const { return N ? 
N->getNumOperands() == 0458
:
true3.04k
; }
llvm::MDTupleTypedArrayWrapper<llvm::DIGlobalVariableExpression>::empty() const
Line
Count
Source
1251
3.36k
  bool empty() const { return N ? 
N->getNumOperands() == 0752
:
true2.61k
; }
llvm::MDTupleTypedArrayWrapper<llvm::DIMacroNode>::empty() const
Line
Count
Source
1251
5.45k
  bool empty() const { return N ? 
N->getNumOperands() == 03
:
true5.45k
; }
1252
729
  T *operator[](unsigned I) const { return cast_or_null<T>(N->getOperand(I)); }
1253
1254
  // FIXME: Fix callers and remove condition on N.
1255
  using iterator = TypedMDOperandIterator<T>;
1256
1257
223k
  iterator begin() const { return N ? 
iterator(N->op_begin())209k
:
iterator()13.3k
; }
llvm::MDTupleTypedArrayWrapper<llvm::DINode>::begin() const
Line
Count
Source
1257
206k
  iterator begin() const { return N ? 
iterator(N->op_begin())202k
:
iterator()3.80k
; }
llvm::MDTupleTypedArrayWrapper<llvm::DISubprogram>::begin() const
Line
Count
Source
1257
3.64k
  iterator begin() const { return N ? iterator(N->op_begin()) : 
iterator()0
; }
llvm::MDTupleTypedArrayWrapper<llvm::DIGlobalVariableExpression>::begin() const
Line
Count
Source
1257
1.79k
  iterator begin() const { return N ? 
iterator(N->op_begin())1.53k
:
iterator()260
; }
llvm::MDTupleTypedArrayWrapper<llvm::DICompositeType>::begin() const
Line
Count
Source
1257
839
  iterator begin() const { return N ? 
iterator(N->op_begin())798
:
iterator()41
; }
llvm::MDTupleTypedArrayWrapper<llvm::DIScope>::begin() const
Line
Count
Source
1257
3.70k
  iterator begin() const { return N ? 
iterator(N->op_begin())753
:
iterator()2.95k
; }
llvm::MDTupleTypedArrayWrapper<llvm::DIImportedEntity>::begin() const
Line
Count
Source
1257
7.08k
  iterator begin() const { return N ? 
iterator(N->op_begin())891
:
iterator()6.19k
; }
llvm::MDTupleTypedArrayWrapper<llvm::DITemplateParameter>::begin() const
Line
Count
Source
1257
85
  iterator begin() const { return N ? 
iterator(N->op_begin())0
: iterator(); }
llvm::MDTupleTypedArrayWrapper<llvm::DIMacroNode>::begin() const
Line
Count
Source
1257
5
  iterator begin() const { return N ? iterator(N->op_begin()) : 
iterator()0
; }
1258
223k
  iterator end() const { return N ? 
iterator(N->op_end())209k
:
iterator()13.3k
; }
llvm::MDTupleTypedArrayWrapper<llvm::DINode>::end() const
Line
Count
Source
1258
206k
  iterator end() const { return N ? 
iterator(N->op_end())202k
:
iterator()3.80k
; }
llvm::MDTupleTypedArrayWrapper<llvm::DISubprogram>::end() const
Line
Count
Source
1258
3.64k
  iterator end() const { return N ? iterator(N->op_end()) : 
iterator()0
; }
llvm::MDTupleTypedArrayWrapper<llvm::DIGlobalVariableExpression>::end() const
Line
Count
Source
1258
1.79k
  iterator end() const { return N ? 
iterator(N->op_end())1.53k
:
iterator()260
; }
llvm::MDTupleTypedArrayWrapper<llvm::DICompositeType>::end() const
Line
Count
Source
1258
839
  iterator end() const { return N ? 
iterator(N->op_end())798
:
iterator()41
; }
llvm::MDTupleTypedArrayWrapper<llvm::DIScope>::end() const
Line
Count
Source
1258
3.70k
  iterator end() const { return N ? 
iterator(N->op_end())753
:
iterator()2.95k
; }
llvm::MDTupleTypedArrayWrapper<llvm::DIImportedEntity>::end() const
Line
Count
Source
1258
7.08k
  iterator end() const { return N ? 
iterator(N->op_end())891
:
iterator()6.19k
; }
llvm::MDTupleTypedArrayWrapper<llvm::DITemplateParameter>::end() const
Line
Count
Source
1258
85
  iterator end() const { return N ? 
iterator(N->op_end())0
: iterator(); }
llvm::MDTupleTypedArrayWrapper<llvm::DIMacroNode>::end() const
Line
Count
Source
1258
5
  iterator end() const { return N ? iterator(N->op_end()) : 
iterator()0
; }
1259
};
1260
1261
#define HANDLE_METADATA(CLASS)                                                 \
1262
  using CLASS##Array = MDTupleTypedArrayWrapper<CLASS>;
1263
#include "llvm/IR/Metadata.def"
1264
1265
/// Placeholder metadata for operands of distinct MDNodes.
1266
///
1267
/// This is a lightweight placeholder for an operand of a distinct node.  It's
1268
/// purpose is to help track forward references when creating a distinct node.
1269
/// This allows distinct nodes involved in a cycle to be constructed before
1270
/// their operands without requiring a heavyweight temporary node with
1271
/// full-blown RAUW support.
1272
///
1273
/// Each placeholder supports only a single MDNode user.  Clients should pass
1274
/// an ID, retrieved via \a getID(), to indicate the "real" operand that this
1275
/// should be replaced with.
1276
///
1277
/// While it would be possible to implement move operators, they would be
1278
/// fairly expensive.  Leave them unimplemented to discourage their use
1279
/// (clients can use std::deque, std::list, BumpPtrAllocator, etc.).
1280
class DistinctMDOperandPlaceholder : public Metadata {
1281
  friend class MetadataTracking;
1282
1283
  Metadata **Use = nullptr;
1284
1285
public:
1286
  explicit DistinctMDOperandPlaceholder(unsigned ID)
1287
38.4k
      : Metadata(DistinctMDOperandPlaceholderKind, Distinct) {
1288
38.4k
    SubclassData32 = ID;
1289
38.4k
  }
1290
1291
  DistinctMDOperandPlaceholder() = delete;
1292
  DistinctMDOperandPlaceholder(DistinctMDOperandPlaceholder &&) = delete;
1293
  DistinctMDOperandPlaceholder(const DistinctMDOperandPlaceholder &) = delete;
1294
1295
38.4k
  ~DistinctMDOperandPlaceholder() {
1296
38.4k
    if (Use)
1297
0
      *Use = nullptr;
1298
38.4k
  }
1299
1300
76.8k
  unsigned getID() const { return SubclassData32; }
1301
1302
  /// Replace the use of this with MD.
1303
38.4k
  void replaceUseWith(Metadata *MD) {
1304
38.4k
    if (!Use)
1305
10
      return;
1306
38.4k
    *Use = MD;
1307
38.4k
1308
38.4k
    if (*Use)
1309
38.4k
      MetadataTracking::track(*Use);
1310
38.4k
1311
38.4k
    Metadata *T = cast<Metadata>(this);
1312
38.4k
    MetadataTracking::untrack(T);
1313
38.4k
    assert(!Use && "Use is still being tracked despite being untracked!");
1314
38.4k
  }
1315
};
1316
1317
//===----------------------------------------------------------------------===//
1318
/// A tuple of MDNodes.
1319
///
1320
/// Despite its name, a NamedMDNode isn't itself an MDNode.
1321
///
1322
/// NamedMDNodes are named module-level entities that contain lists of MDNodes.
1323
///
1324
/// It is illegal for a NamedMDNode to appear as an operand of an MDNode.
1325
class NamedMDNode : public ilist_node<NamedMDNode> {
1326
  friend class LLVMContextImpl;
1327
  friend class Module;
1328
1329
  std::string Name;
1330
  Module *Parent = nullptr;
1331
  void *Operands; // SmallVector<TrackingMDRef, 4>
1332
1333
59.7k
  void setParent(Module *M) { Parent = M; }
1334
1335
  explicit NamedMDNode(const Twine &N);
1336
1337
  template<class T1, class T2>
1338
  class op_iterator_impl :
1339
      public std::iterator<std::bidirectional_iterator_tag, T2> {
1340
    friend class NamedMDNode;
1341
1342
    const NamedMDNode *Node = nullptr;
1343
    unsigned Idx = 0;
1344
1345
32.6M
    op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) {}
llvm::NamedMDNode::op_iterator_impl<llvm::MDNode*, llvm::MDNode>::op_iterator_impl(llvm::NamedMDNode const*, unsigned int)
Line
Count
Source
1345
15.2k
    op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) {}
llvm::NamedMDNode::op_iterator_impl<llvm::MDNode const*, llvm::MDNode>::op_iterator_impl(llvm::NamedMDNode const*, unsigned int)
Line
Count
Source
1345
32.6M
    op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) {}
1346
1347
  public:
1348
    op_iterator_impl() = default;
1349
1350
    bool operator==(const op_iterator_impl &o) const { return Idx == o.Idx; }
1351
73.4M
    bool operator!=(const op_iterator_impl &o) const { return Idx != o.Idx; }
llvm::NamedMDNode::op_iterator_impl<llvm::MDNode*, llvm::MDNode>::operator!=(llvm::NamedMDNode::op_iterator_impl<llvm::MDNode*, llvm::MDNode> const&) const
Line
Count
Source
1351
18.1k
    bool operator!=(const op_iterator_impl &o) const { return Idx != o.Idx; }
llvm::NamedMDNode::op_iterator_impl<llvm::MDNode const*, llvm::MDNode>::operator!=(llvm::NamedMDNode::op_iterator_impl<llvm::MDNode const*, llvm::MDNode> const&) const
Line
Count
Source
1351
73.4M
    bool operator!=(const op_iterator_impl &o) const { return Idx != o.Idx; }
1352
1353
57.1M
    op_iterator_impl &operator++() {
1354
57.1M
      ++Idx;
1355
57.1M
      return *this;
1356
57.1M
    }
llvm::NamedMDNode::op_iterator_impl<llvm::MDNode*, llvm::MDNode>::operator++()
Line
Count
Source
1353
10.8k
    op_iterator_impl &operator++() {
1354
10.8k
      ++Idx;
1355
10.8k
      return *this;
1356
10.8k
    }
llvm::NamedMDNode::op_iterator_impl<llvm::MDNode const*, llvm::MDNode>::operator++()
Line
Count
Source
1353
57.1M
    op_iterator_impl &operator++() {
1354
57.1M
      ++Idx;
1355
57.1M
      return *this;
1356
57.1M
    }
1357
1358
    op_iterator_impl operator++(int) {
1359
      op_iterator_impl tmp(*this);
1360
      operator++();
1361
      return tmp;
1362
    }
1363
1364
    op_iterator_impl &operator--() {
1365
      --Idx;
1366
      return *this;
1367
    }
1368
1369
    op_iterator_impl operator--(int) {
1370
      op_iterator_impl tmp(*this);
1371
      operator--();
1372
      return tmp;
1373
    }
1374
1375
57.1M
    T1 operator*() const { return Node->getOperand(Idx); }
llvm::NamedMDNode::op_iterator_impl<llvm::MDNode*, llvm::MDNode>::operator*() const
Line
Count
Source
1375
11.2k
    T1 operator*() const { return Node->getOperand(Idx); }
llvm::NamedMDNode::op_iterator_impl<llvm::MDNode const*, llvm::MDNode>::operator*() const
Line
Count
Source
1375
57.1M
    T1 operator*() const { return Node->getOperand(Idx); }
1376
  };
1377
1378
public:
1379
  NamedMDNode(const NamedMDNode &) = delete;
1380
  ~NamedMDNode();
1381
1382
  /// Drop all references and remove the node from parent module.
1383
  void eraseFromParent();
1384
1385
  /// Remove all uses and clear node vector.
1386
32.5k
  void dropAllReferences() { clearOperands(); }
1387
  /// Drop all references to this node's operands.
1388
  void clearOperands();
1389
1390
  /// Get the module that holds this named metadata collection.
1391
758
  inline Module *getParent() { return Parent; }
1392
9
  inline const Module *getParent() const { return Parent; }
1393
1394
  MDNode *getOperand(unsigned i) const;
1395
  unsigned getNumOperands() const;
1396
  void addOperand(MDNode *M);
1397
  void setOperand(unsigned I, MDNode *New);
1398
  StringRef getName() const;
1399
  void print(raw_ostream &ROS, bool IsForDebug = false) const;
1400
  void print(raw_ostream &ROS, ModuleSlotTracker &MST,
1401
             bool IsForDebug = false) const;
1402
  void dump() const;
1403
1404
  // ---------------------------------------------------------------------------
1405
  // Operand Iterator interface...
1406
  //
1407
  using op_iterator = op_iterator_impl<MDNode *, MDNode>;
1408
1409
7.64k
  op_iterator op_begin() { return op_iterator(this, 0); }
1410
7.64k
  op_iterator op_end()   { return op_iterator(this, getNumOperands()); }
1411
1412
  using const_op_iterator = op_iterator_impl<const MDNode *, MDNode>;
1413
1414
16.3M
  const_op_iterator op_begin() const { return const_op_iterator(this, 0); }
1415
16.3M
  const_op_iterator op_end()   const { return const_op_iterator(this, getNumOperands()); }
1416
1417
1.37k
  inline iterator_range<op_iterator>  operands() {
1418
1.37k
    return make_range(op_begin(), op_end());
1419
1.37k
  }
1420
16.3M
  inline iterator_range<const_op_iterator> operands() const {
1421
16.3M
    return make_range(op_begin(), op_end());
1422
16.3M
  }
1423
};
1424
1425
// Create wrappers for C Binding types (see CBindingWrapping.h).
1426
DEFINE_ISA_CONVERSION_FUNCTIONS(NamedMDNode, LLVMNamedMDNodeRef)
1427
1428
} // end namespace llvm
1429
1430
#endif // LLVM_IR_METADATA_H