LLVM  10.0.0
EnumeratedArray.h
Go to the documentation of this file.
1 //===- llvm/ADT/EnumeratedArray.h - Enumerated Array-------------*- 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 defines an array type that can be indexed using scoped enum values.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_ADT_ENUMERATEDARRAY_H
14 #define LLVM_ADT_ENUMERATEDARRAY_H
15 
16 #include <cassert>
17 
18 namespace llvm {
19 
20 template <typename ValueType, typename Enumeration,
21  Enumeration LargestEnum = Enumeration::Last, typename IndexType = int,
22  IndexType Size = 1 + static_cast<IndexType>(LargestEnum)>
24 public:
25  EnumeratedArray() = default;
27  for (IndexType IX = 0; IX < Size; ++IX) {
28  Underlying[IX] = V;
29  }
30  }
31  inline const ValueType &operator[](const Enumeration Index) const {
32  auto IX = static_cast<const IndexType>(Index);
33  assert(IX >= 0 && IX < Size && "Index is out of bounds.");
34  return Underlying[IX];
35  }
36  inline ValueType &operator[](const Enumeration Index) {
37  return const_cast<ValueType &>(
38  static_cast<const EnumeratedArray<ValueType, Enumeration, LargestEnum,
39  IndexType, Size> &>(*this)[Index]);
40  }
41 
42 private:
44 };
45 
46 } // namespace llvm
47 
48 #endif // LLVM_ADT_ENUMERATEDARRAY_H
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
This class represents lattice values for constants.
Definition: AllocatorList.h:23
const ValueType & operator[](const Enumeration Index) const
std::underlying_type< E >::type Underlying(E Val)
Check that Val is in range for E, and return Val cast to E&#39;s underlying type.
Definition: BitmaskEnum.h:90
EnumeratedArray(ValueType V)
ValueType & operator[](const Enumeration Index)
uint32_t Size
Definition: Profile.cpp:46
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:156