xref: /llvm-project/bolt/include/bolt/Utils/NameShortener.h (revision fd38366e4525c5507bbb2a2fc1f7d113a964224e)
1 //===- bolt/Utils/NameShortener.h - Name shortener --------------*- 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 // Helper class for shortening names.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef BOLT_UTILS_NAME_SHORTENER_H
14 #define BOLT_UTILS_NAME_SHORTENER_H
15 
16 #include "llvm/ADT/StringMap.h"
17 
18 namespace llvm {
19 namespace bolt {
20 
21 class NameShortener {
22   StringMap<uint64_t> IDs;
23 
24 public:
getID(StringRef Name)25   uint64_t getID(StringRef Name) {
26     return IDs.insert({Name, IDs.size()}).first->getValue();
27   }
28 };
29 
30 } // namespace bolt
31 } // namespace llvm
32 
33 #endif
34