LLVM  16.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"
5 #include "llvm/MC/MCSection.h"
6 #include "llvm/MC/MCStreamer.h"
7 #include <cassert>
8 
9 namespace llvm {
11 
12  struct CStrDenseMapInfo {
13  static inline const char *getEmptyKey() {
14  return reinterpret_cast<const char *>(~static_cast<uintptr_t>(0));
15  }
16  static inline const char *getTombstoneKey() {
17  return reinterpret_cast<const char *>(~static_cast<uintptr_t>(1));
18  }
19  static unsigned getHashValue(const char *Val) {
20  assert(Val != getEmptyKey() && "Cannot hash the empty key!");
21  assert(Val != getTombstoneKey() && "Cannot hash the tombstone key!");
22  return (unsigned)hash_value(StringRef(Val));
23  }
24  static bool isEqual(const char *LHS, const char *RHS) {
25  if (RHS == getEmptyKey())
26  return LHS == getEmptyKey();
27  if (RHS == getTombstoneKey())
28  return LHS == getTombstoneKey();
29  return strcmp(LHS, RHS) == 0;
30  }
31  };
32 
33  MCStreamer &Out;
34  MCSection *Sec;
36  uint32_t Offset = 0;
37 
38 public:
39  DWPStringPool(MCStreamer &Out, MCSection *Sec) : Out(Out), Sec(Sec) {}
40 
41  uint32_t getOffset(const char *Str, unsigned Length) {
42  assert(strlen(Str) + 1 == Length && "Ensure length hint is correct");
43 
44  auto Pair = Pool.insert(std::make_pair(Str, Offset));
45  if (Pair.second) {
46  Out.switchSection(Sec);
47  Out.emitBytes(StringRef(Str, Length));
48  Offset += Length;
49  }
50 
51  return Pair.first->second;
52  }
53 };
54 } // namespace llvm
55 
56 #endif // LLVM_DWP_DWPSTRINGPOOL_H
llvm::DWPStringPool::getOffset
uint32_t getOffset(const char *Str, unsigned Length)
Definition: DWPStringPool.h:41
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::DWPStringPool::DWPStringPool
DWPStringPool(MCStreamer &Out, MCSection *Sec)
Definition: DWPStringPool.h:39
llvm::DWPStringPool
Definition: DWPStringPool.h:10
DenseMap.h
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::isEqual
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
Definition: GCNRegPressure.cpp:21
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:212
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::MCStreamer::switchSection
virtual void switchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:1234
llvm::DenseMap< const char *, uint32_t, CStrDenseMapInfo >
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSection.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
uint32_t
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
llvm::DenseMapBase::insert
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:207
llvm::hash_value
hash_code hash_value(const FixedPointSemantics &Val)
Definition: APFixedPoint.h:127
MCStreamer.h
llvm::MCStreamer::emitBytes
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:1212