MetadataImpl.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //===- MetadataImpl.h - Helpers for implementing metadata -----------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file has private helpers for implementing metadata types.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_IR_METADATAIMPL_H
  14. #define LLVM_IR_METADATAIMPL_H
  15. #include "llvm/ADT/DenseSet.h"
  16. #include "llvm/IR/Metadata.h"
  17. namespace llvm {
  18. template <class T, class InfoT>
  19. static T *getUniqued(DenseSet<T *, InfoT> &Store,
  20. const typename InfoT::KeyTy &Key) {
  21. auto I = Store.find_as(Key);
  22. return I == Store.end() ? nullptr : *I;
  23. }
  24. template <class T, class StoreT>
  25. T *MDNode::storeImpl(T *N, StorageType Storage, StoreT &Store) {
  26. switch (Storage) {
  27. case Uniqued:
  28. Store.insert(N);
  29. break;
  30. case Distinct:
  31. N->storeDistinctInContext();
  32. break;
  33. case Temporary:
  34. break;
  35. }
  36. return N;
  37. }
  38. } // end namespace llvm
  39. #endif