LLVM  8.0.1
ValueSymbolTable.h
Go to the documentation of this file.
1 //===- llvm/ValueSymbolTable.h - Implement a Value Symtab -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the name/Value symbol table for LLVM.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_IR_VALUESYMBOLTABLE_H
15 #define LLVM_IR_VALUESYMBOLTABLE_H
16 
17 #include "llvm/ADT/StringMap.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/IR/Value.h"
20 #include <cstdint>
21 
22 namespace llvm {
23 
24 class Argument;
25 class BasicBlock;
26 class Function;
27 class GlobalAlias;
28 class GlobalIFunc;
29 class GlobalVariable;
30 class Instruction;
31 template <unsigned InternalLen> class SmallString;
32 template <typename ValueSubClass> class SymbolTableListTraits;
33 
34 /// This class provides a symbol table of name/value pairs. It is essentially
35 /// a std::map<std::string,Value*> but has a controlled interface provided by
36 /// LLVM as well as ensuring uniqueness of names.
37 ///
46  friend class Value;
47 
48 /// @name Types
49 /// @{
50 public:
51  /// A mapping of names to values.
53 
54  /// An iterator over a ValueMap.
56 
57  /// A const_iterator over a ValueMap.
59 
60 /// @}
61 /// @name Constructors
62 /// @{
63 
64  ValueSymbolTable() : vmap(0) {}
66 
67 /// @}
68 /// @name Accessors
69 /// @{
70 
71  /// This method finds the value with the given \p Name in the
72  /// the symbol table.
73  /// @returns the value associated with the \p Name
74  /// Lookup a named Value.
75  Value *lookup(StringRef Name) const { return vmap.lookup(Name); }
76 
77  /// @returns true iff the symbol table is empty
78  /// Determine if the symbol table is empty
79  inline bool empty() const { return vmap.empty(); }
80 
81  /// The number of name/type pairs is returned.
82  inline unsigned size() const { return unsigned(vmap.size()); }
83 
84  /// This function can be used from the debugger to display the
85  /// content of the symbol table while debugging.
86  /// Print out symbol table on stderr
87  void dump() const;
88 
89 /// @}
90 /// @name Iteration
91 /// @{
92 
93  /// Get an iterator that from the beginning of the symbol table.
94  inline iterator begin() { return vmap.begin(); }
95 
96  /// Get a const_iterator that from the beginning of the symbol table.
97  inline const_iterator begin() const { return vmap.begin(); }
98 
99  /// Get an iterator to the end of the symbol table.
100  inline iterator end() { return vmap.end(); }
101 
102  /// Get a const_iterator to the end of the symbol table.
103  inline const_iterator end() const { return vmap.end(); }
104 
105  /// @}
106  /// @name Mutators
107  /// @{
108 private:
109  ValueName *makeUniqueName(Value *V, SmallString<256> &UniqueName);
110 
111  /// This method adds the provided value \p N to the symbol table. The Value
112  /// must have a name which is used to place the value in the symbol table.
113  /// If the inserted name conflicts, this renames the value.
114  /// Add a named value to the symbol table
115  void reinsertValue(Value *V);
116 
117  /// createValueName - This method attempts to create a value name and insert
118  /// it into the symbol table with the specified name. If it conflicts, it
119  /// auto-renames the name and returns that instead.
120  ValueName *createValueName(StringRef Name, Value *V);
121 
122  /// This method removes a value from the symbol table. It leaves the
123  /// ValueName attached to the value, but it is no longer inserted in the
124  /// symtab.
125  void removeValueName(ValueName *V);
126 
127  /// @}
128  /// @name Internal Data
129  /// @{
130 
131  ValueMap vmap; ///< The map that holds the symbol table.
132  mutable uint32_t LastUnique = 0; ///< Counter for tracking unique names
133 
134 /// @}
135 };
136 
137 } // end namespace llvm
138 
139 #endif // LLVM_IR_VALUESYMBOLTABLE_H
This class provides a symbol table of name/value pairs.
This class represents an incoming formal argument to a Function.
Definition: Argument.h:30
iterator begin()
Get an iterator that from the beginning of the symbol table.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:126
Various leaf nodes.
Definition: ISDOpcodes.h:60
amdgpu Simplify well known AMD library false Value Value const Twine & Name
unsigned size() const
Definition: StringMap.h:112
unsigned size() const
The number of name/type pairs is returned.
iterator end()
Get an iterator to the end of the symbol table.
const_iterator end() const
Get a const_iterator to the end of the symbol table.
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
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:347
const_iterator begin() const
Get a const_iterator that from the beginning of the symbol table.
StringMapIterator< ValueTy > iterator
Definition: StringMap.h:313
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:220
iterator begin()
Definition: StringMap.h:315
void dump() const
This function can be used from the debugger to display the content of the symbol table while debuggin...
Value * lookup(StringRef Name) const
This method finds the value with the given Name in the the symbol table.
bool empty() const
Definition: StringMap.h:111
LLVM Value Representation.
Definition: Value.h:73
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
StringMapConstIterator< ValueTy > const_iterator
Definition: StringMap.h:312
iterator end()
Definition: StringMap.h:318