1//===-- OMPVersion.h - OpenMP version definition ------------------ 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 contains the core set of OpenMP definitions and declarations.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_FRONTEND_OPENMP_OMPVERSION_H
14#define LLVM_FRONTEND_OPENMP_OMPVERSION_H
15
16#include "llvm/ADT/DenseMapInfo.h"
17
18namespace llvm {
19namespace omp {
20struct Version {
21 using value_type = unsigned;
22 constexpr explicit Version(value_type Ver = 0) : V(Ver) {}
23 constexpr explicit operator value_type() const { return V; }
24 constexpr explicit operator bool() const { return V != 0; }
25
26 friend constexpr bool operator<(Version A, Version B);
27 friend constexpr bool operator==(Version A, Version B);
28
29private:
30 value_type V;
31};
32
33inline constexpr bool operator==(Version A, Version B) { return A.V == B.V; }
34inline constexpr bool operator!=(Version A, Version B) { return !(A == B); }
35inline constexpr bool operator<(Version A, Version B) { return A.V < B.V; }
36inline constexpr bool operator<=(Version A, Version B) {
37 return A < B || A == B;
38}
39inline constexpr bool operator>(Version A, Version B) { return !(A <= B); }
40inline constexpr bool operator>=(Version A, Version B) { return !(A < B); }
41
42inline constexpr bool operator==(Version A, int B) { return A == Version(B); }
43inline constexpr bool operator!=(Version A, int B) { return A != Version(B); }
44inline constexpr bool operator<(Version A, int B) { return A < Version(B); }
45inline constexpr bool operator<=(Version A, int B) { return A <= Version(B); }
46inline constexpr bool operator>(Version A, int B) { return A > Version(B); }
47inline constexpr bool operator>=(Version A, int B) { return A >= Version(B); }
48} // namespace omp
49
50template <> struct DenseMapInfo<omp::Version> {
51 static unsigned getHashValue(omp::Version V) {
52 using UnderlyingTy = omp::Version::value_type;
53 return DenseMapInfo<UnderlyingTy>::getHashValue(
54 Val: static_cast<UnderlyingTy>(V));
55 }
56 static bool isEqual(omp::Version LHS, omp::Version RHS) { return LHS == RHS; }
57};
58} // namespace llvm
59
60#endif // LLVM_FRONTEND_OPENMP_OMPVERSION_H
61