MetadataImpl.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #ifndef LLVM_IR_METADATAIMPL_H
  13. #define LLVM_IR_METADATAIMPL_H
  14. #include "llvm/ADT/DenseSet.h"
  15. #include "llvm/IR/Metadata.h"
  16. namespace llvm {
  17. template <class T, class InfoT>
  18. static T *getUniqued(DenseSet<T *, InfoT> &Store,
  19. const typename InfoT::KeyTy &Key) {
  20. auto I = Store.find_as(Key);
  21. return I == Store.end() ? nullptr : *I;
  22. }
  23. template <class T> T *MDNode::storeImpl(T *N, StorageType Storage) {
  24. switch (Storage) {
  25. case Uniqued:
  26. llvm_unreachable("Cannot unique without a uniquing-store");
  27. case Distinct:
  28. N->storeDistinctInContext();
  29. break;
  30. case Temporary:
  31. break;
  32. }
  33. return N;
  34. }
  35. template <class T, class StoreT>
  36. T *MDNode::storeImpl(T *N, StorageType Storage, StoreT &Store) {
  37. switch (Storage) {
  38. case Uniqued:
  39. Store.insert(N);
  40. break;
  41. case Distinct:
  42. N->storeDistinctInContext();
  43. break;
  44. case Temporary:
  45. break;
  46. }
  47. return N;
  48. }
  49. } // end namespace llvm
  50. #endif