LLVM 23.0.0git
DWPStringPool.h
Go to the documentation of this file.
1#ifndef LLVM_DWP_DWPSTRINGPOOL_H
2#define LLVM_DWP_DWPSTRINGPOOL_H
3
4#include "llvm/ADT/DenseMap.h"
7#include <cassert>
8
9namespace llvm {
12 // Use StringRef keys instead of const char* to avoid redundant strlen
13 // on every hash computation and strcmp on every probe comparison.
15 uint64_t Offset = 0;
16
17public:
18 DWPStringPool(SmallVectorImpl<char> &Buffer) : Buffer(Buffer) {}
19
20 uint64_t getOffset(const char *Str, unsigned Length) {
21 assert(strlen(Str) + 1 == Length && "Ensure length hint is correct");
22
23 StringRef Key(Str, Length - 1);
24 auto Pair = Pool.insert(std::make_pair(Key, Offset));
25 if (Pair.second) {
26 Buffer.insert(Buffer.end(), Str, Str + Length);
27 Offset += Length;
28 }
29
30 return Pair.first->second;
31 }
32};
33} // namespace llvm
34
35#endif // LLVM_DWP_DWPSTRINGPOOL_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
This file defines the SmallVector class.
uint64_t getOffset(const char *Str, unsigned Length)
DWPStringPool(SmallVectorImpl< char > &Buffer)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
This is an optimization pass for GlobalISel generic memory operations.
@ Length
Definition DWP.cpp:557
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key