2015-02-02 19:53:21 +01:00
|
|
|
//===- MetadataImpl.h - Helpers for implementing metadata -----------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-02-02 19:53:21 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file has private helpers for implementing metadata types.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_IR_METADATAIMPL_H
|
|
|
|
#define LLVM_IR_METADATAIMPL_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2015-02-04 01:20:52 +01:00
|
|
|
#include "llvm/IR/Metadata.h"
|
2015-02-02 19:53:21 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
template <class T, class InfoT>
|
|
|
|
static T *getUniqued(DenseSet<T *, InfoT> &Store,
|
|
|
|
const typename InfoT::KeyTy &Key) {
|
|
|
|
auto I = Store.find_as(Key);
|
|
|
|
return I == Store.end() ? nullptr : *I;
|
|
|
|
}
|
|
|
|
|
2015-08-03 19:26:41 +02:00
|
|
|
template <class T> T *MDNode::storeImpl(T *N, StorageType Storage) {
|
|
|
|
switch (Storage) {
|
|
|
|
case Uniqued:
|
|
|
|
llvm_unreachable("Cannot unique without a uniquing-store");
|
|
|
|
case Distinct:
|
|
|
|
N->storeDistinctInContext();
|
|
|
|
break;
|
|
|
|
case Temporary:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return N;
|
|
|
|
}
|
|
|
|
|
2015-02-02 19:53:21 +01:00
|
|
|
template <class T, class StoreT>
|
|
|
|
T *MDNode::storeImpl(T *N, StorageType Storage, StoreT &Store) {
|
|
|
|
switch (Storage) {
|
|
|
|
case Uniqued:
|
|
|
|
Store.insert(N);
|
|
|
|
break;
|
|
|
|
case Distinct:
|
|
|
|
N->storeDistinctInContext();
|
|
|
|
break;
|
|
|
|
case Temporary:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return N;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|