LLVM: include/llvm/Support/VersionTuple.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_SUPPORT_VERSIONTUPLE_H
15#define LLVM_SUPPORT_VERSIONTUPLE_H
16
19#include
20#include
21#include
22
23namespace llvm {
24template <typename HasherT, llvm::endianness Endianness> class HashBuilder;
25class raw_ostream;
26class StringRef;
27
28
30 unsigned Major : 32;
31
32 unsigned Minor : 31;
33 unsigned HasMinor : 1;
34
35 unsigned Subminor : 31;
36 unsigned HasSubminor : 1;
37
38 unsigned Build : 31;
39 unsigned HasBuild : 1;
40
41public:
43 : Major(0), Minor(0), HasMinor(false), Subminor(0), HasSubminor(false),
44 Build(0), HasBuild(false) {}
45
47 : Major(Major), Minor(0), HasMinor(false), Subminor(0),
48 HasSubminor(false), Build(0), HasBuild(false) {}
49
50 explicit constexpr VersionTuple(unsigned Major, unsigned Minor)
51 : Major(Major), Minor(Minor), HasMinor(true), Subminor(0),
52 HasSubminor(false), Build(0), HasBuild(false) {}
53
54 explicit constexpr VersionTuple(unsigned Major, unsigned Minor,
55 unsigned Subminor)
56 : Major(Major), Minor(Minor), HasMinor(true), Subminor(Subminor),
57 HasSubminor(true), Build(0), HasBuild(false) {}
58
59 explicit constexpr VersionTuple(unsigned Major, unsigned Minor,
60 unsigned Subminor, unsigned Build)
61 : Major(Major), Minor(Minor), HasMinor(true), Subminor(Subminor),
62 HasSubminor(true), Build(Build), HasBuild(true) {}
63
64
65
67 return Major == 0 && Minor == 0 && Subminor == 0 && Build == 0;
68 }
69
70
71 unsigned getMajor() const { return Major; }
72
73
74 std::optional getMinor() const {
75 if (!HasMinor)
76 return std::nullopt;
77 return Minor;
78 }
79
80
82 if (!HasSubminor)
83 return std::nullopt;
84 return Subminor;
85 }
86
87
88 std::optional getBuild() const {
89 if (!HasBuild)
90 return std::nullopt;
91 return Build;
92 }
93
94
96 if (HasBuild)
98 return *this;
99 }
100
101
102
104 return VersionTuple(NewMajor, Minor, Subminor, Build);
105 }
106
107
110 if (Result.Build == 0) {
111 Result.HasBuild = false;
112 if (Result.Subminor == 0) {
113 Result.HasSubminor = false;
114 if (Result.Minor == 0)
115 Result.HasMinor = false;
116 }
117 }
118 return Result;
119 }
120
121
122
124 return X.Major == Y.Major && X.Minor == Y.Minor &&
125 X.Subminor == Y.Subminor && X.Build == Y.Build;
126 }
127
128
129
130
131
134 }
135
136
137
138
139
141 return std::tie(X.Major, X.Minor, X.Subminor, X.Build) <
142 std::tie(Y.Major, Y.Minor, Y.Subminor, Y.Build);
143 }
144
145
146
147
148
151 }
152
153
154
155
156
157
160 }
161
162
163
164
165
166
169 }
170
172 return hash_combine(VT.Major, VT.Minor, VT.Subminor, VT.Build);
173 }
174
175 template <typename HasherT, llvm::endianness Endianness>
178 HBuilder.add(VT.Major, VT.Minor, VT.Subminor, VT.Build);
179 }
180
181
183
184
185
186
188};
189
190
191raw_ostream &operator<<(raw_ostream &Out, const VersionTuple &V);
192
193
198 }
200 unsigned Result = Value.getMajor();
201 if (auto Minor = Value.getMinor())
203 if (auto Subminor = Value.getSubminor())
205 if (auto Build = Value.getBuild())
207
208 return Result;
209 }
210
213 }
214};
215
216}
217#endif
This file defines DenseMapInfo traits for DenseMap.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
Interface to help hash various types through a hasher type.
std::enable_if_t< hashbuilder_detail::IsHashableData< T >::value, HashBuilder & > add(T Value)
Implement hashing for hashable data types, e.g. integral or enum values.
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
Represents a version number in the form major[.minor[.subminor[.build]]].
constexpr VersionTuple(unsigned Major)
friend bool operator<=(const VersionTuple &X, const VersionTuple &Y)
Determine whether one version number precedes or is equivalent to another.
std::optional< unsigned > getBuild() const
Retrieve the build version number, if provided.
constexpr VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor, unsigned Build)
constexpr VersionTuple(unsigned Major, unsigned Minor, unsigned Subminor)
friend bool operator!=(const VersionTuple &X, const VersionTuple &Y)
Determine if two version numbers are not equivalent.
friend bool operator<(const VersionTuple &X, const VersionTuple &Y)
Determine whether one version number precedes another.
friend bool operator>=(const VersionTuple &X, const VersionTuple &Y)
Determine whether one version number follows or is equivalent to another.
constexpr VersionTuple(unsigned Major, unsigned Minor)
unsigned getMajor() const
Retrieve the major version number.
friend hash_code hash_value(const VersionTuple &VT)
bool tryParse(StringRef string)
Try to parse the given string as a version number.
std::string getAsString() const
Retrieve a string representation of the version number.
VersionTuple normalize() const
Return a version tuple that contains only components that are non-zero.
std::optional< unsigned > getSubminor() const
Retrieve the subminor version number, if provided.
VersionTuple withMajorReplaced(unsigned NewMajor) const
Return a version tuple that contains a different major version but everything else is the same.
bool empty() const
Determine whether this version information is empty (e.g., all version components are zero).
VersionTuple withoutBuild() const
Return a version tuple that contains only the first 3 version components.
friend bool operator==(const VersionTuple &X, const VersionTuple &Y)
Determine if two version numbers are equivalent.
std::optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
friend bool operator>(const VersionTuple &X, const VersionTuple &Y)
Determine whether one version number follows another.
friend void addHash(HashBuilder< HasherT, Endianness > &HBuilder, const VersionTuple &VT)
An opaque object representing a hash code.
unsigned combineHashValue(unsigned a, unsigned b)
Simplistic combination of 32-bit hash values into 32-bit hash values.
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
static VersionTuple getEmptyKey()
static bool isEqual(const VersionTuple &LHS, const VersionTuple &RHS)
static VersionTuple getTombstoneKey()
static unsigned getHashValue(const VersionTuple &Value)
An information struct used to provide DenseMap with the various necessary components for a given valu...