LLVM 20.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
18#include "llvm/ADT/Hashing.h"
19#include <cstdint>
20#include <utility>
21
22namespace llvm {
23namespace sys {
24namespace fs {
25
26class UniqueID {
27 uint64_t Device;
28 uint64_t File;
29
30public:
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.
55template <> 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
73 return LHS == RHS;
74 }
75};
76
77} // end namespace llvm
78
79#endif // LLVM_SUPPORT_FILESYSTEM_UNIQUEID_H
This file defines DenseMapInfo traits for DenseMap.
Value * RHS
Value * LHS
An opaque object representing a hash code.
Definition: Hashing.h:75
bool operator<(const UniqueID &Other) const
Definition: UniqueID.h:38
bool operator!=(const UniqueID &Other) const
Definition: UniqueID.h:37
uint64_t getDevice() const
Definition: UniqueID.h:47
uint64_t getFile() const
Definition: UniqueID.h:48
UniqueID(uint64_t Device, uint64_t File)
Definition: UniqueID.h:32
bool operator==(const UniqueID &Other) const
Definition: UniqueID.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
hash_code hash_value(const FixedPointSemantics &Val)
Definition: APFixedPoint.h:136
@ Other
Any other memory.
static bool isEqual(const llvm::sys::fs::UniqueID &LHS, const llvm::sys::fs::UniqueID &RHS)
Definition: UniqueID.h:71
static llvm::sys::fs::UniqueID getEmptyKey()
Definition: UniqueID.h:56
static llvm::sys::fs::UniqueID getTombstoneKey()
Definition: UniqueID.h:61
static hash_code getHashValue(const llvm::sys::fs::UniqueID &Tag)
Definition: UniqueID.h:67
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:52