2015-02-03 02:53:21 +08:00
|
|
|
//===- MetadataImpl.h - Helpers for implementing metadata -----------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08: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-03 02:53:21 +08: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 08:20:52 +08:00
|
|
|
#include "llvm/IR/Metadata.h"
|
2015-02-03 02:53:21 +08: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-04 01:26:41 +08: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-03 02:53:21 +08: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
|