Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:49

0001 //===- IndexedValuesMap.h ---------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DWARFLINKER_INDEXEDVALUESMAP_H
0010 #define LLVM_DWARFLINKER_INDEXEDVALUESMAP_H
0011 
0012 #include "llvm/ADT/DenseMap.h"
0013 #include "llvm/ADT/SmallVector.h"
0014 #include <cstdint>
0015 #include <utility>
0016 
0017 namespace llvm {
0018 namespace dwarf_linker {
0019 
0020 /// This class stores values sequentually and assigns index to the each value.
0021 template <typename T> class IndexedValuesMap {
0022 public:
0023   uint64_t getValueIndex(T Value) {
0024     auto [It, Inserted] = ValueToIndexMap.try_emplace(Value, Values.size());
0025     if (Inserted)
0026       Values.push_back(Value);
0027     return It->second;
0028   }
0029 
0030   const SmallVector<T> &getValues() const { return Values; }
0031 
0032   void clear() {
0033     ValueToIndexMap.clear();
0034     Values.clear();
0035   }
0036 
0037   bool empty() { return Values.empty(); }
0038 
0039 protected:
0040   using ValueToIndexMapTy = DenseMap<T, uint64_t>;
0041   ValueToIndexMapTy ValueToIndexMap;
0042   SmallVector<T> Values;
0043 };
0044 
0045 } // end of namespace dwarf_linker
0046 } // end of namespace llvm
0047 
0048 #endif // LLVM_DWARFLINKER_INDEXEDVALUESMAP_H