LLVM  14.0.0git
UniqueID.h
Go to the documentation of this file.
1 //===- llvm/Support/FileSystem/UniqueID.h - UniqueID for files --*- C++ -*-===//
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 is cut out of llvm/Support/FileSystem.h to allow UniqueID to be
10 // reused without bloating the includes.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_SUPPORT_FILESYSTEM_UNIQUEID_H
15 #define LLVM_SUPPORT_FILESYSTEM_UNIQUEID_H
16 
17 #include "llvm/ADT/DenseMapInfo.h"
18 #include "llvm/ADT/Hashing.h"
19 #include <cstdint>
20 #include <utility>
21 
22 namespace llvm {
23 namespace sys {
24 namespace fs {
25 
26 class UniqueID {
27  uint64_t Device;
28  uint64_t File;
29 
30 public:
31  UniqueID() = default;
32  UniqueID(uint64_t Device, uint64_t File) : Device(Device), File(File) {}
33 
34  bool operator==(const UniqueID &Other) const {
35  return Device == Other.Device && File == Other.File;
36  }
37  bool operator!=(const UniqueID &Other) const { return !(*this == Other); }
38  bool operator<(const UniqueID &Other) const {
39  /// Don't use std::tie since it bloats the compile time of this header.
40  if (Device < Other.Device)
41  return true;
42  if (Other.Device < Device)
43  return false;
44  return File < Other.File;
45  }
46 
47  uint64_t getDevice() const { return Device; }
48  uint64_t getFile() const { return File; }
49 };
50 
51 } // end namespace fs
52 } // end namespace sys
53 
54 // Support UniqueIDs as DenseMap keys.
55 template <> struct DenseMapInfo<llvm::sys::fs::UniqueID> {
57  auto EmptyKey = DenseMapInfo<std::pair<uint64_t, uint64_t>>::getEmptyKey();
58  return {EmptyKey.first, EmptyKey.second};
59  }
60 
62  auto TombstoneKey =
64  return {TombstoneKey.first, TombstoneKey.second};
65  }
66 
68  return hash_value(std::make_pair(Tag.getDevice(), Tag.getFile()));
69  }
70 
71  static bool isEqual(const llvm::sys::fs::UniqueID &LHS,
72  const llvm::sys::fs::UniqueID &RHS) {
73  return LHS == RHS;
74  }
75 };
76 
77 } // end namespace llvm
78 
79 #endif // LLVM_SUPPORT_FILESYSTEM_UNIQUEID_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::sys::fs::UniqueID::UniqueID
UniqueID(uint64_t Device, uint64_t File)
Definition: UniqueID.h:32
llvm::DenseMapInfo< llvm::sys::fs::UniqueID >::isEqual
static bool isEqual(const llvm::sys::fs::UniqueID &LHS, const llvm::sys::fs::UniqueID &RHS)
Definition: UniqueID.h:71
Hashing.h
llvm::hash_value
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition: APFloat.cpp:4821
llvm::DenseMapInfo
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: APInt.h:34
llvm::sys::fs::UniqueID::getFile
uint64_t getFile() const
Definition: UniqueID.h:48
llvm::sys::fs::UniqueID
Definition: UniqueID.h:26
uint64_t
llvm::sys::fs::UniqueID::UniqueID
UniqueID()=default
llvm::sys::fs::UniqueID::operator<
bool operator<(const UniqueID &Other) const
Definition: UniqueID.h:38
llvm::DenseMapInfo< llvm::sys::fs::UniqueID >::getTombstoneKey
static llvm::sys::fs::UniqueID getTombstoneKey()
Definition: UniqueID.h:61
llvm::DenseMapInfo< llvm::sys::fs::UniqueID >::getHashValue
static hash_code getHashValue(const llvm::sys::fs::UniqueID &Tag)
Definition: UniqueID.h:67
llvm::DenseMapInfo< llvm::sys::fs::UniqueID >::getEmptyKey
static llvm::sys::fs::UniqueID getEmptyKey()
Definition: UniqueID.h:56
llvm::sys::fs::UniqueID::operator==
bool operator==(const UniqueID &Other) const
Definition: UniqueID.h:34
llvm::sys::fs::UniqueID::getDevice
uint64_t getDevice() const
Definition: UniqueID.h:47
llvm::sys::fs::UniqueID::operator!=
bool operator!=(const UniqueID &Other) const
Definition: UniqueID.h:37
DenseMapInfo.h
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1191
llvm::hash_code
An opaque object representing a hash code.
Definition: Hashing.h:73