1d9901ff5SDuncan P. N. Exon Smith //===- MetadataImpl.h - Helpers for implementing metadata -----------------===//
2d9901ff5SDuncan P. N. Exon Smith //
3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6d9901ff5SDuncan P. N. Exon Smith //
7d9901ff5SDuncan P. N. Exon Smith //===----------------------------------------------------------------------===//
8d9901ff5SDuncan P. N. Exon Smith //
9d9901ff5SDuncan P. N. Exon Smith // This file has private helpers for implementing metadata types.
10d9901ff5SDuncan P. N. Exon Smith //
11d9901ff5SDuncan P. N. Exon Smith //===----------------------------------------------------------------------===//
12d9901ff5SDuncan P. N. Exon Smith
13d9901ff5SDuncan P. N. Exon Smith #ifndef LLVM_IR_METADATAIMPL_H
14d9901ff5SDuncan P. N. Exon Smith #define LLVM_IR_METADATAIMPL_H
15d9901ff5SDuncan P. N. Exon Smith
16d9901ff5SDuncan P. N. Exon Smith #include "llvm/ADT/DenseSet.h"
17d9b46a18SGalina Kistanova #include "llvm/IR/Metadata.h"
18d9901ff5SDuncan P. N. Exon Smith
19d9901ff5SDuncan P. N. Exon Smith namespace llvm {
20d9901ff5SDuncan P. N. Exon Smith
21d9901ff5SDuncan P. N. Exon Smith template <class T, class InfoT>
getUniqued(DenseSet<T *,InfoT> & Store,const typename InfoT::KeyTy & Key)22d9901ff5SDuncan P. N. Exon Smith static T *getUniqued(DenseSet<T *, InfoT> &Store,
23d9901ff5SDuncan P. N. Exon Smith const typename InfoT::KeyTy &Key) {
24d9901ff5SDuncan P. N. Exon Smith auto I = Store.find_as(Key);
25d9901ff5SDuncan P. N. Exon Smith return I == Store.end() ? nullptr : *I;
26d9901ff5SDuncan P. N. Exon Smith }
27d9901ff5SDuncan P. N. Exon Smith
storeImpl(T * N,StorageType Storage)2855ca964eSDuncan P. N. Exon Smith template <class T> T *MDNode::storeImpl(T *N, StorageType Storage) {
2955ca964eSDuncan P. N. Exon Smith switch (Storage) {
3055ca964eSDuncan P. N. Exon Smith case Uniqued:
3155ca964eSDuncan P. N. Exon Smith llvm_unreachable("Cannot unique without a uniquing-store");
3255ca964eSDuncan P. N. Exon Smith case Distinct:
3355ca964eSDuncan P. N. Exon Smith N->storeDistinctInContext();
3455ca964eSDuncan P. N. Exon Smith break;
3555ca964eSDuncan P. N. Exon Smith case Temporary:
3655ca964eSDuncan P. N. Exon Smith break;
3755ca964eSDuncan P. N. Exon Smith }
3855ca964eSDuncan P. N. Exon Smith return N;
3955ca964eSDuncan P. N. Exon Smith }
4055ca964eSDuncan P. N. Exon Smith
41d9901ff5SDuncan P. N. Exon Smith template <class T, class StoreT>
storeImpl(T * N,StorageType Storage,StoreT & Store)42d9901ff5SDuncan P. N. Exon Smith T *MDNode::storeImpl(T *N, StorageType Storage, StoreT &Store) {
43d9901ff5SDuncan P. N. Exon Smith switch (Storage) {
44d9901ff5SDuncan P. N. Exon Smith case Uniqued:
45d9901ff5SDuncan P. N. Exon Smith Store.insert(N);
46d9901ff5SDuncan P. N. Exon Smith break;
47d9901ff5SDuncan P. N. Exon Smith case Distinct:
48d9901ff5SDuncan P. N. Exon Smith N->storeDistinctInContext();
49d9901ff5SDuncan P. N. Exon Smith break;
50d9901ff5SDuncan P. N. Exon Smith case Temporary:
51d9901ff5SDuncan P. N. Exon Smith break;
52d9901ff5SDuncan P. N. Exon Smith }
53d9901ff5SDuncan P. N. Exon Smith return N;
54d9901ff5SDuncan P. N. Exon Smith }
55d9901ff5SDuncan P. N. Exon Smith
56d9901ff5SDuncan P. N. Exon Smith } // end namespace llvm
57d9901ff5SDuncan P. N. Exon Smith
58d9901ff5SDuncan P. N. Exon Smith #endif
59