LLVM
15.0.0git
include
llvm
IR
ValueSymbolTable.h
Go to the documentation of this file.
1
//===- llvm/ValueSymbolTable.h - Implement a Value Symtab -------*- 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 implements the name/Value symbol table for LLVM.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_IR_VALUESYMBOLTABLE_H
14
#define LLVM_IR_VALUESYMBOLTABLE_H
15
16
#include "
llvm/ADT/StringMap.h
"
17
#include "
llvm/ADT/StringRef.h
"
18
#include "
llvm/IR/Value.h
"
19
#include <cstdint>
20
21
namespace
llvm
{
22
23
class
Argument;
24
class
BasicBlock
;
25
class
Function
;
26
class
GlobalAlias;
27
class
GlobalIFunc;
28
class
GlobalVariable;
29
class
Instruction;
30
template
<
unsigned
InternalLen>
class
SmallString;
31
template
<
typename
ValueSubClass>
class
SymbolTableListTraits;
32
33
/// This class provides a symbol table of name/value pairs. It is essentially
34
/// a std::map<std::string,Value*> but has a controlled interface provided by
35
/// LLVM as well as ensuring uniqueness of names.
36
///
37
class
ValueSymbolTable
{
38
friend
class
SymbolTableListTraits
<
Argument
>;
39
friend
class
SymbolTableListTraits
<
BasicBlock
>;
40
friend
class
SymbolTableListTraits
<
Function
>;
41
friend
class
SymbolTableListTraits
<
GlobalAlias
>;
42
friend
class
SymbolTableListTraits
<
GlobalIFunc
>;
43
friend
class
SymbolTableListTraits
<
GlobalVariable
>;
44
friend
class
SymbolTableListTraits
<
Instruction
>;
45
friend
class
Value
;
46
47
/// @name Types
48
/// @{
49
public
:
50
/// A mapping of names to values.
51
using
ValueMap
=
StringMap<Value*>
;
52
53
/// An iterator over a ValueMap.
54
using
iterator
=
ValueMap::iterator
;
55
56
/// A const_iterator over a ValueMap.
57
using
const_iterator
=
ValueMap::const_iterator
;
58
59
/// @}
60
/// @name Constructors
61
/// @{
62
63
ValueSymbolTable
(
int
MaxNameSize = -1) : vmap(0), MaxNameSize(MaxNameSize) {}
64
~ValueSymbolTable
();
65
66
/// @}
67
/// @name Accessors
68
/// @{
69
70
/// This method finds the value with the given \p Name in the
71
/// the symbol table.
72
/// @returns the value associated with the \p Name
73
/// Lookup a named Value.
74
Value
*
lookup
(
StringRef
Name
)
const
{
75
if
(MaxNameSize > -1 &&
Name
.size() > (
unsigned
)MaxNameSize)
76
Name
=
Name
.substr(0,
std::max
(1u, (
unsigned
)MaxNameSize));
77
78
return
vmap.
lookup
(
Name
);
79
}
80
81
/// @returns true iff the symbol table is empty
82
/// Determine if the symbol table is empty
83
inline
bool
empty
()
const
{
return
vmap.
empty
(); }
84
85
/// The number of name/type pairs is returned.
86
inline
unsigned
size
()
const
{
return
unsigned(vmap.
size
()); }
87
88
/// This function can be used from the debugger to display the
89
/// content of the symbol table while debugging.
90
/// Print out symbol table on stderr
91
void
dump
()
const
;
92
93
/// @}
94
/// @name Iteration
95
/// @{
96
97
/// Get an iterator that from the beginning of the symbol table.
98
inline
iterator
begin
() {
return
vmap.
begin
(); }
99
100
/// Get a const_iterator that from the beginning of the symbol table.
101
inline
const_iterator
begin
()
const
{
return
vmap.
begin
(); }
102
103
/// Get an iterator to the end of the symbol table.
104
inline
iterator
end
() {
return
vmap.
end
(); }
105
106
/// Get a const_iterator to the end of the symbol table.
107
inline
const_iterator
end
()
const
{
return
vmap.
end
(); }
108
109
/// @}
110
/// @name Mutators
111
/// @{
112
private
:
113
ValueName
*makeUniqueName(
Value
*V,
SmallString<256>
&UniqueName);
114
115
/// This method adds the provided value \p N to the symbol table. The Value
116
/// must have a name which is used to place the value in the symbol table.
117
/// If the inserted name conflicts, this renames the value.
118
/// Add a named value to the symbol table
119
void
reinsertValue(
Value
*V);
120
121
/// createValueName - This method attempts to create a value name and insert
122
/// it into the symbol table with the specified name. If it conflicts, it
123
/// auto-renames the name and returns that instead.
124
ValueName
*createValueName(
StringRef
Name
,
Value
*V);
125
126
/// This method removes a value from the symbol table. It leaves the
127
/// ValueName attached to the value, but it is no longer inserted in the
128
/// symtab.
129
void
removeValueName(
ValueName
*V);
130
131
/// @}
132
/// @name Internal Data
133
/// @{
134
135
ValueMap
vmap;
///< The map that holds the symbol table.
136
int
MaxNameSize;
///< The maximum size for each name. If the limit is
137
///< exceeded, the name is capped.
138
mutable
uint32_t
LastUnique = 0;
///< Counter for tracking unique names
139
140
/// @}
141
};
142
143
}
// end namespace llvm
144
145
#endif // LLVM_IR_VALUESYMBOLTABLE_H
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition:
Argument.h:28
llvm::ValueSymbolTable::ValueSymbolTable
ValueSymbolTable(int MaxNameSize=-1)
Definition:
ValueSymbolTable.h:63
llvm::ValueSymbolTable::empty
bool empty() const
Definition:
ValueSymbolTable.h:83
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:
AddressRanges.h:17
llvm::StringMapEntry
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition:
StringMapEntry.h:101
llvm::Function
Definition:
Function.h:60
StringRef.h
llvm::ValueSymbolTable::begin
iterator begin()
Get an iterator that from the beginning of the symbol table.
Definition:
ValueSymbolTable.h:98
llvm::GlobalVariable
Definition:
GlobalVariable.h:39
llvm::GlobalAlias
Definition:
GlobalAlias.h:28
llvm::StringMap::end
iterator end()
Definition:
StringMap.h:205
llvm::ValueSymbolTable::begin
const_iterator begin() const
Get a const_iterator that from the beginning of the symbol table.
Definition:
ValueSymbolTable.h:101
llvm::BasicBlock
LLVM Basic Block Representation.
Definition:
BasicBlock.h:55
llvm::StringMap< Value * >::iterator
StringMapIterator< Value * > iterator
Definition:
StringMap.h:202
llvm::ValueSymbolTable::end
iterator end()
Get an iterator to the end of the symbol table.
Definition:
ValueSymbolTable.h:104
llvm::StringMapConstIterator
Definition:
StringMap.h:26
llvm::Instruction
Definition:
Instruction.h:42
llvm::ValueSymbolTable::size
unsigned size() const
The number of name/type pairs is returned.
Definition:
ValueSymbolTable.h:86
StringMap.h
llvm::StringMap< Value * >
llvm::SmallString< 256 >
llvm::StringMapIterator
Definition:
StringMap.h:27
llvm::SymbolTableListTraits
Definition:
GlobalAlias.h:26
llvm::StringMap::lookup
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition:
StringMap.h:234
llvm::ValueSymbolTable::end
const_iterator end() const
Get a const_iterator to the end of the symbol table.
Definition:
ValueSymbolTable.h:107
llvm::StringMap::begin
iterator begin()
Definition:
StringMap.h:204
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition:
ISDOpcodes.h:71
llvm::StringMapImpl::size
unsigned size() const
Definition:
StringMap.h:95
llvm::ValueSymbolTable::~ValueSymbolTable
~ValueSymbolTable()
Definition:
ValueSymbolTable.cpp:33
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:
StringRef.h:58
llvm::ValueSymbolTable::dump
void dump() const
This function can be used from the debugger to display the content of the symbol table while debuggin...
Definition:
ValueSymbolTable.cpp:122
uint32_t
llvm::ValueMap
See the file comment.
Definition:
ValueMap.h:85
llvm::GraphProgram::Name
Name
Definition:
GraphWriter.h:50
llvm::StringMapImpl::empty
bool empty() const
Definition:
StringMap.h:94
llvm::ValueSymbolTable
This class provides a symbol table of name/value pairs.
Definition:
ValueSymbolTable.h:37
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition:
Alignment.h:340
llvm::ValueSymbolTable::lookup
Value * lookup(StringRef Name) const
This method finds the value with the given Name in the the symbol table.
Definition:
ValueSymbolTable.h:74
llvm::StringMap< Value * >::const_iterator
StringMapConstIterator< Value * > const_iterator
Definition:
StringMap.h:201
Value.h
llvm::GlobalIFunc
Definition:
GlobalIFunc.h:34
llvm::Value
LLVM Value Representation.
Definition:
Value.h:74
llvm::codeview::PublicSymFlags::Function
@ Function
Generated on Fri May 20 2022 08:03:41 for LLVM by
1.8.17