LLVM
20.0.0git
include
llvm
DebugInfo
LogicalView
Core
LVStringPool.h
Go to the documentation of this file.
1
//===-- LVStringPool.h ------------------------------------------*- 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
// This file defines the LVStringPool class, which is used to implement a
10
// basic string pool table.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSTRINGPOOL_H
15
#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSTRINGPOOL_H
16
17
#include "
llvm/ADT/StringMap.h
"
18
#include "
llvm/Support/Allocator.h
"
19
#include "
llvm/Support/Debug.h
"
20
#include "
llvm/Support/Format.h
"
21
#include "
llvm/Support/raw_ostream.h
"
22
#include <iomanip>
23
#include <vector>
24
25
namespace
llvm
{
26
namespace
logicalview {
27
28
class
LVStringPool
{
29
static
constexpr
size_t
BadIndex = std::numeric_limits<size_t>::max();
30
using
TableType
=
StringMap<size_t, BumpPtrAllocator>
;
31
using
ValueType =
TableType::value_type
;
32
BumpPtrAllocator
Allocator;
33
TableType
StringTable;
34
std::vector<ValueType *> Entries;
35
36
public
:
37
LVStringPool
() {
getIndex
(
""
); }
38
LVStringPool
(
LVStringPool
const
&other) =
delete
;
39
LVStringPool
(
LVStringPool
&&other) =
delete
;
40
~LVStringPool
() =
default
;
41
42
bool
isValidIndex
(
size_t
Index
)
const
{
return
Index
!= BadIndex; }
43
44
// Return number of strings in the pool. The empty string is allocated
45
// at the slot zero. We substract 1 to indicate the number of non empty
46
// strings.
47
size_t
getSize
()
const
{
return
Entries.size() - 1; }
48
49
// Return the index for the specified key, otherwise 'BadIndex'.
50
size_t
findIndex
(
StringRef
Key)
const
{
51
TableType::const_iterator
Iter =
StringTable
.find(Key);
52
if
(Iter !=
StringTable
.end())
53
return
Iter->second;
54
return
BadIndex;
55
}
56
57
// Return an index for the specified key.
58
size_t
getIndex
(
StringRef
Key) {
59
size_t
Index
=
findIndex
(Key);
60
if
(
isValidIndex
(
Index
))
61
return
Index
;
62
size_t
Value
= Entries.size();
63
ValueType *Entry =
ValueType::create
(Key,
Allocator
,
Value
);
64
StringTable
.insert(Entry);
65
Entries.push_back(Entry);
66
return
Value
;
67
}
68
69
// Given the index, return its corresponding string.
70
StringRef
getString
(
size_t
Index
)
const
{
71
return
(
Index
>= Entries.size()) ?
StringRef
() : Entries[
Index
]->getKey();
72
}
73
74
void
print
(
raw_ostream
&
OS
)
const
{
75
if
(!Entries.empty()) {
76
OS
<<
"\nString Pool:\n"
;
77
for
(
const
ValueType *Entry : Entries)
78
OS
<<
"Index: "
<< Entry->getValue() <<
", "
79
<<
"Key: '"
<< Entry->getKey() <<
"'\n"
;
80
}
81
}
82
83
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
84
void
dump
()
const
{
print
(
dbgs
()); }
85
#endif
86
};
87
88
}
// namespace logicalview
89
}
// end namespace llvm
90
91
#endif
// LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSTRINGPOOL_H
StringMap.h
This file defines the StringMap class.
Allocator.h
This file defines the BumpPtrAllocator interface.
Debug.h
Format.h
Allocator
Basic Register Allocator
Definition:
RegAllocBasic.cpp:143
OS
raw_pwrite_stream & OS
Definition:
SampleProfWriter.cpp:53
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition:
Allocator.h:66
llvm::StringMapConstIterator
Definition:
StringMap.h:479
llvm::StringMapEntry::create
static StringMapEntry * create(StringRef key, AllocatorTy &allocator, InitTy &&...initVals)
Create a StringMapEntry for the specified key construct the value using InitiVals.
Definition:
StringMapEntry.h:126
llvm::StringMap< size_t, BumpPtrAllocator >
llvm::StringMap< size_t, BumpPtrAllocator >::value_type
StringMapEntry< size_t > value_type
Definition:
StringMap.h:213
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:
StringRef.h:50
llvm::Value
LLVM Value Representation.
Definition:
Value.h:74
llvm::logicalview::LVStringPool
Definition:
LVStringPool.h:28
llvm::logicalview::LVStringPool::isValidIndex
bool isValidIndex(size_t Index) const
Definition:
LVStringPool.h:42
llvm::logicalview::LVStringPool::findIndex
size_t findIndex(StringRef Key) const
Definition:
LVStringPool.h:50
llvm::logicalview::LVStringPool::~LVStringPool
~LVStringPool()=default
llvm::logicalview::LVStringPool::LVStringPool
LVStringPool()
Definition:
LVStringPool.h:37
llvm::logicalview::LVStringPool::print
void print(raw_ostream &OS) const
Definition:
LVStringPool.h:74
llvm::logicalview::LVStringPool::dump
void dump() const
Definition:
LVStringPool.h:84
llvm::logicalview::LVStringPool::LVStringPool
LVStringPool(LVStringPool const &other)=delete
llvm::logicalview::LVStringPool::LVStringPool
LVStringPool(LVStringPool &&other)=delete
llvm::logicalview::LVStringPool::getString
StringRef getString(size_t Index) const
Definition:
LVStringPool.h:70
llvm::logicalview::LVStringPool::getIndex
size_t getIndex(StringRef Key)
Definition:
LVStringPool.h:58
llvm::logicalview::LVStringPool::getSize
size_t getSize() const
Definition:
LVStringPool.h:47
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:
raw_ostream.h:52
llvm::codeview::DebugSubsectionKind::StringTable
@ StringTable
llvm::dwarf::Index
Index
Definition:
Dwarf.h:875
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:
AddressRanges.h:18
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition:
Debug.cpp:163
raw_ostream.h
Generated on Wed Nov 20 2024 23:47:57 for LLVM by
1.9.6