1 //===-- llvm/ValueSymbolTable.h - Implement a Value Symtab ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer based on the original SymbolTable.h
6 // written by the LLVM research group and re-written by Reid Spencer.
7 // It is distributed under the University of Illinois Open Source License.
8 // See LICENSE.TXT for details.
10 //===----------------------------------------------------------------------===//
12 // This file implements the name/Value symbol table for LLVM.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_VALUE_SYMBOL_TABLE_H
17 #define LLVM_VALUE_SYMBOL_TABLE_H
19 #include "llvm/Value.h"
24 /// This class provides a symbol table of name/value pairs. It is essentially
25 /// a std::map<std::string,Value*> but has a controlled interface provided by
26 /// LLVM as well as ensuring uniqueness of names.
28 class ValueSymbolTable {
34 /// @brief A mapping of names to values.
35 typedef std::map<const std::string, Value *> ValueMap;
37 /// @brief An iterator over a ValueMap.
38 typedef ValueMap::iterator iterator;
40 /// @brief A const_iterator over a ValueMap.
41 typedef ValueMap::const_iterator const_iterator;
44 /// @name Constructors
48 ValueSymbolTable() : LastUnique(0) {}
56 /// This method finds the value with the given \p name in the
58 /// @returns the value associated with the \p name
59 /// @brief Lookup a named Value.
60 Value *lookup(const std::string &name) const;
62 /// @returns true iff the symbol table is empty
63 /// @brief Determine if the symbol table is empty
64 inline bool empty() const { return vmap.empty(); }
66 /// @brief The number of name/type pairs is returned.
67 inline unsigned size() const { return unsigned(vmap.size()); }
69 /// Given a base name, return a string that is either equal to it or
70 /// derived from it that does not already occur in the symbol table
71 /// for the specified type.
72 /// @brief Get a name unique to this symbol table
73 std::string getUniqueName(const std::string &BaseName) const;
75 /// This function can be used from the debugger to display the
76 /// content of the symbol table while debugging.
77 /// @brief Print out symbol table on stderr
85 /// @brief Get an iterator that from the beginning of the symbol table.
86 inline iterator begin() { return vmap.begin(); }
88 /// @brief Get a const_iterator that from the beginning of the symbol table.
89 inline const_iterator begin() const { return vmap.begin(); }
91 /// @brief Get an iterator to the end of the symbol table.
92 inline iterator end() { return vmap.end(); }
94 /// @brief Get a const_iterator to the end of the symbol table.
95 inline const_iterator end() const { return vmap.end(); }
102 /// This method will strip the symbol table of its names.
103 /// @brief Strip the symbol table.
106 /// This method adds the provided value \p N to the symbol table. The Value
107 /// must have a name which is used to place the value in the symbol table.
108 /// @brief Add a named value to the symbol table
109 void insert(Value *Val);
111 /// This method removes a value from the symbol table. The name of the
112 /// Value is extracted from \p Val and used to lookup the Value in the
113 /// symbol table. If the Value is not in the symbol table, this method
115 /// @returns true if \p Val was successfully erased, false otherwise
116 /// @brief Remove a value from the symbol table.
117 bool erase(Value* Val);
119 /// Given a value with a non-empty name, remove its existing
120 /// entry from the symbol table and insert a new one for Name. This is
121 /// equivalent to doing "remove(V), V->Name = Name, insert(V)".
122 /// @brief Rename a value in the symbol table
123 bool rename(Value *V, const std::string &Name);
126 /// @name Internal Data
129 ValueMap vmap; ///< The map that holds the symbol table.
130 mutable uint32_t LastUnique; ///< Counter for tracking unique names
136 } // End llvm namespace