LLVM  14.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 // 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  inline IndexType size() { return Size; }
42 
43 private:
45 };
46 
47 } // namespace llvm
48 
49 #endif // LLVM_ADT_ENUMERATEDARRAY_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::BitmaskEnumDetail::Underlying
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
llvm::EnumeratedArray::operator[]
const ValueType & operator[](const Enumeration Index) const
Definition: EnumeratedArray.h:31
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:23
llvm::EnumeratedArray::operator[]
ValueType & operator[](const Enumeration Index)
Definition: EnumeratedArray.h:36
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
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:26
llvm::EnumeratedArray::size
IndexType size()
Definition: EnumeratedArray.h:41