1 | //===-- NumberedValues.h - --------------------------------------*- 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 | #ifndef LLVM_ASMPARSER_NUMBEREDVALUES_H |
10 | #define LLVM_ASMPARSER_NUMBEREDVALUES_H |
11 | |
12 | #include "llvm/ADT/DenseMap.h" |
13 | |
14 | namespace llvm { |
15 | |
16 | /// Mapping from value ID to value, which also remembers what the next unused |
17 | /// ID is. |
18 | template <class T> class NumberedValues { |
19 | DenseMap<unsigned, T> Vals; |
20 | unsigned NextUnusedID = 0; |
21 | |
22 | public: |
23 | unsigned getNext() const { return NextUnusedID; } |
24 | T get(unsigned ID) const { return Vals.lookup(ID); } |
25 | void add(unsigned ID, T V) { |
26 | assert(ID >= NextUnusedID && "Invalid value ID" ); |
27 | Vals.insert({ID, V}); |
28 | NextUnusedID = ID + 1; |
29 | } |
30 | }; |
31 | |
32 | } // end namespace llvm |
33 | |
34 | #endif |
35 | |