Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / lib / DWARFLinkerParallel / IndexedValuesMap.h
blob0dc8de860a42e848928dee026974d5de6843549e
1 //===- IndexedValuesMap.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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_DWARFLINKERPARALLEL_INDEXEDVALUESMAP_H
10 #define LLVM_LIB_DWARFLINKERPARALLEL_INDEXEDVALUESMAP_H
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include <cstdint>
15 #include <utility>
17 namespace llvm {
18 namespace dwarflinker_parallel {
20 template <typename T> class IndexedValuesMap {
21 public:
22 uint64_t getValueIndex(T Value) {
23 typename ValueToIndexMapTy::iterator It = ValueToIndexMap.find(Value);
24 if (It == ValueToIndexMap.end()) {
25 It = ValueToIndexMap.insert(std::make_pair(Value, Values.size())).first;
26 Values.push_back(Value);
28 return It->second;
31 const SmallVector<T> &getValues() { return Values; }
33 void clear() {
34 ValueToIndexMap.clear();
35 Values.clear();
38 bool empty() { return Values.empty(); }
40 protected:
41 using ValueToIndexMapTy = DenseMap<T, uint64_t>;
42 ValueToIndexMapTy ValueToIndexMap;
43 SmallVector<T> Values;
46 } // end of namespace dwarflinker_parallel
47 } // end namespace llvm
49 #endif // LLVM_LIB_DWARFLINKERPARALLEL_INDEXEDVALUESMAP_H