UniqueID.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/Support/FileSystem/UniqueID.h - UniqueID for files --*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file is cut out of llvm/Support/FileSystem.h to allow UniqueID to be
  15. // reused without bloating the includes.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_SUPPORT_FILESYSTEM_UNIQUEID_H
  19. #define LLVM_SUPPORT_FILESYSTEM_UNIQUEID_H
  20. #include "llvm/ADT/DenseMapInfo.h"
  21. #include "llvm/ADT/Hashing.h"
  22. #include <cstdint>
  23. #include <utility>
  24. namespace llvm {
  25. namespace sys {
  26. namespace fs {
  27. class UniqueID {
  28. uint64_t Device;
  29. uint64_t File;
  30. public:
  31. UniqueID() = default;
  32. UniqueID(uint64_t Device, uint64_t File) : Device(Device), File(File) {}
  33. bool operator==(const UniqueID &Other) const {
  34. return Device == Other.Device && File == Other.File;
  35. }
  36. bool operator!=(const UniqueID &Other) const { return !(*this == Other); }
  37. bool operator<(const UniqueID &Other) const {
  38. /// Don't use std::tie since it bloats the compile time of this header.
  39. if (Device < Other.Device)
  40. return true;
  41. if (Other.Device < Device)
  42. return false;
  43. return File < Other.File;
  44. }
  45. uint64_t getDevice() const { return Device; }
  46. uint64_t getFile() const { return File; }
  47. };
  48. } // end namespace fs
  49. } // end namespace sys
  50. // Support UniqueIDs as DenseMap keys.
  51. template <> struct DenseMapInfo<llvm::sys::fs::UniqueID> {
  52. static inline llvm::sys::fs::UniqueID getEmptyKey() {
  53. auto EmptyKey = DenseMapInfo<std::pair<uint64_t, uint64_t>>::getEmptyKey();
  54. return {EmptyKey.first, EmptyKey.second};
  55. }
  56. static inline llvm::sys::fs::UniqueID getTombstoneKey() {
  57. auto TombstoneKey =
  58. DenseMapInfo<std::pair<uint64_t, uint64_t>>::getTombstoneKey();
  59. return {TombstoneKey.first, TombstoneKey.second};
  60. }
  61. static hash_code getHashValue(const llvm::sys::fs::UniqueID &Tag) {
  62. return hash_value(std::make_pair(Tag.getDevice(), Tag.getFile()));
  63. }
  64. static bool isEqual(const llvm::sys::fs::UniqueID &LHS,
  65. const llvm::sys::fs::UniqueID &RHS) {
  66. return LHS == RHS;
  67. }
  68. };
  69. } // end namespace llvm
  70. #endif // LLVM_SUPPORT_FILESYSTEM_UNIQUEID_H
  71. #ifdef __GNUC__
  72. #pragma GCC diagnostic pop
  73. #endif