1//===- MetadataImpl.h - Helpers for implementing metadata -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file has private helpers for implementing metadata types.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_IR_METADATAIMPL_H
14#define LLVM_IR_METADATAIMPL_H
15
16#include "llvm/ADT/DenseSet.h"
17#include "llvm/IR/Metadata.h"
18
19namespace llvm {
20
21template <class T, class InfoT>
22static T *getUniqued(DenseSet<T *, InfoT> &Store,
23 const typename InfoT::KeyTy &Key) {
24 auto I = Store.find_as(Key);
25 return I == Store.end() ? nullptr : *I;
26}
27
28template <class T> T *MDNode::storeImpl(T *N, StorageType Storage) {
29 switch (Storage) {
30 case Uniqued:
31 llvm_unreachable("Cannot unique without a uniquing-store");
32 case Distinct:
33 N->storeDistinctInContext();
34 break;
35 case Temporary:
36 N->getContext().pImpl->TemporaryMDNodes.insert(N);
37 break;
38 }
39 return N;
40}
41
42template <class T, class StoreT>
43T *MDNode::storeImpl(T *N, StorageType Storage, StoreT &Store) {
44 switch (Storage) {
45 case Uniqued:
46 Store.insert(N);
47 break;
48 case Distinct:
49 N->storeDistinctInContext();
50 break;
51 case Temporary:
52 N->getContext().pImpl->TemporaryMDNodes.insert(N);
53 break;
54 }
55 return N;
56}
57
58} // end namespace llvm
59
60#endif
61