Coverage Report

Created: 2017-10-03 07:32

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