Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:26

0001 //===- llvm/Support/FileSystem/UniqueID.h - UniqueID for files --*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file is cut out of llvm/Support/FileSystem.h to allow UniqueID to be
0010 // reused without bloating the includes.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_SUPPORT_FILESYSTEM_UNIQUEID_H
0015 #define LLVM_SUPPORT_FILESYSTEM_UNIQUEID_H
0016 
0017 #include "llvm/ADT/DenseMapInfo.h"
0018 #include "llvm/ADT/Hashing.h"
0019 #include <cstdint>
0020 #include <utility>
0021 
0022 namespace llvm {
0023 namespace sys {
0024 namespace fs {
0025 
0026 class UniqueID {
0027   uint64_t Device;
0028   uint64_t File;
0029 
0030 public:
0031   UniqueID() = default;
0032   UniqueID(uint64_t Device, uint64_t File) : Device(Device), File(File) {}
0033 
0034   bool operator==(const UniqueID &Other) const {
0035     return Device == Other.Device && File == Other.File;
0036   }
0037   bool operator!=(const UniqueID &Other) const { return !(*this == Other); }
0038   bool operator<(const UniqueID &Other) const {
0039     /// Don't use std::tie since it bloats the compile time of this header.
0040     if (Device < Other.Device)
0041       return true;
0042     if (Other.Device < Device)
0043       return false;
0044     return File < Other.File;
0045   }
0046 
0047   uint64_t getDevice() const { return Device; }
0048   uint64_t getFile() const { return File; }
0049 };
0050 
0051 } // end namespace fs
0052 } // end namespace sys
0053 
0054 // Support UniqueIDs as DenseMap keys.
0055 template <> struct DenseMapInfo<llvm::sys::fs::UniqueID> {
0056   static inline llvm::sys::fs::UniqueID getEmptyKey() {
0057     auto EmptyKey = DenseMapInfo<std::pair<uint64_t, uint64_t>>::getEmptyKey();
0058     return {EmptyKey.first, EmptyKey.second};
0059   }
0060 
0061   static inline llvm::sys::fs::UniqueID getTombstoneKey() {
0062     auto TombstoneKey =
0063         DenseMapInfo<std::pair<uint64_t, uint64_t>>::getTombstoneKey();
0064     return {TombstoneKey.first, TombstoneKey.second};
0065   }
0066 
0067   static hash_code getHashValue(const llvm::sys::fs::UniqueID &Tag) {
0068     return hash_value(std::make_pair(Tag.getDevice(), Tag.getFile()));
0069   }
0070 
0071   static bool isEqual(const llvm::sys::fs::UniqueID &LHS,
0072                       const llvm::sys::fs::UniqueID &RHS) {
0073     return LHS == RHS;
0074   }
0075 };
0076 
0077 } // end namespace llvm
0078 
0079 #endif // LLVM_SUPPORT_FILESYSTEM_UNIQUEID_H