LLVM  15.0.0git
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 /// \file
10 /// This file defines an array type that can be indexed using scoped enum
11 /// values.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_ADT_ENUMERATEDARRAY_H
16 #define LLVM_ADT_ENUMERATEDARRAY_H
17 
18 #include <cassert>
19 
20 namespace llvm {
21 
22 template <typename ValueType, typename Enumeration,
23  Enumeration LargestEnum = Enumeration::Last, typename IndexType = int,
24  IndexType Size = 1 + static_cast<IndexType>(LargestEnum)>
26 public:
27  EnumeratedArray() = default;
29  for (IndexType IX = 0; IX < Size; ++IX) {
30  Underlying[IX] = V;
31  }
32  }
33  inline const ValueType &operator[](const Enumeration Index) const {
34  auto IX = static_cast<const IndexType>(Index);
35  assert(IX >= 0 && IX < Size && "Index is out of bounds.");
36  return Underlying[IX];
37  }
38  inline ValueType &operator[](const Enumeration Index) {
39  return const_cast<ValueType &>(
40  static_cast<const EnumeratedArray<ValueType, Enumeration, LargestEnum,
41  IndexType, Size> &>(*this)[Index]);
42  }
43  inline IndexType size() { return Size; }
44 
45 private:
46  ValueType Underlying[Size];
47 };
48 
49 } // namespace llvm
50 
51 #endif // LLVM_ADT_ENUMERATEDARRAY_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:76
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::EnumeratedArray::operator[]
const ValueType & operator[](const Enumeration Index) const
Definition: EnumeratedArray.h:33
int
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
Definition: README.txt:536
llvm::EnumeratedArray
Definition: EnumeratedArray.h:25
llvm::EnumeratedArray::operator[]
ValueType & operator[](const Enumeration Index)
Definition: EnumeratedArray.h:38
llvm::BitmaskEnumDetail::Underlying
constexpr std::underlying_type_t< E > Underlying(E Val)
Check that Val is in range for E, and return Val cast to E's underlying type.
Definition: BitmaskEnum.h:90
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ValueType
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
Definition: ScheduleDAGInstrs.h:106
llvm::PointerUnion< const Value *, const PseudoSourceValue * >
llvm::EnumeratedArray::EnumeratedArray
EnumeratedArray(ValueType V)
Definition: EnumeratedArray.h:28
llvm::EnumeratedArray::size
IndexType size()
Definition: EnumeratedArray.h:43