LLVM 17.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"
7#include <cassert>
8
9namespace 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
38public:
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
This file defines the DenseMap class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * RHS
Value * LHS
uint32_t getOffset(const char *Str, unsigned Length)
Definition: DWPStringPool.h:41
DWPStringPool(MCStreamer &Out, MCSection *Sec)
Definition: DWPStringPool.h:39
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:207
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
Streaming machine code generation interface.
Definition: MCStreamer.h:212
virtual void switchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Length
Definition: DWP.cpp:406
hash_code hash_value(const FixedPointSemantics &Val)
Definition: APFixedPoint.h:128
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)