2006-01-10 09:51:48 +00:00
|
|
|
//===-- llvm/ValueSymbolTable.h - Implement a Value Symtab ------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-01-10 09:51:48 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the name/Value symbol table for LLVM.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_VALUE_SYMBOL_TABLE_H
|
|
|
|
#define LLVM_VALUE_SYMBOL_TABLE_H
|
|
|
|
|
|
|
|
#include "llvm/Value.h"
|
2007-02-12 05:18:08 +00:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2009-10-26 01:35:46 +00:00
|
|
|
#include "llvm/System/DataTypes.h"
|
2010-01-12 18:34:06 +00:00
|
|
|
#include "llvm/ADT/ilist_node.h"
|
2006-01-10 09:51:48 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2007-04-17 03:26:42 +00:00
|
|
|
template<typename ValueSubClass, typename ItemParentClass>
|
2007-02-07 06:06:24 +00:00
|
|
|
class SymbolTableListTraits;
|
|
|
|
class BasicBlock;
|
|
|
|
class Function;
|
2009-07-29 17:16:17 +00:00
|
|
|
class NamedMDNode;
|
2007-02-07 06:06:24 +00:00
|
|
|
class Module;
|
2009-07-23 18:52:12 +00:00
|
|
|
class StringRef;
|
2010-01-07 19:39:36 +00:00
|
|
|
|
2006-01-10 09:51:48 +00:00
|
|
|
/// This class provides a symbol table of name/value pairs. It is essentially
|
|
|
|
/// a std::map<std::string,Value*> but has a controlled interface provided by
|
|
|
|
/// LLVM as well as ensuring uniqueness of names.
|
|
|
|
///
|
|
|
|
class ValueSymbolTable {
|
2007-02-07 06:06:24 +00:00
|
|
|
friend class Value;
|
2007-04-17 03:26:42 +00:00
|
|
|
friend class SymbolTableListTraits<Argument, Function>;
|
|
|
|
friend class SymbolTableListTraits<BasicBlock, Function>;
|
|
|
|
friend class SymbolTableListTraits<Instruction, BasicBlock>;
|
|
|
|
friend class SymbolTableListTraits<Function, Module>;
|
|
|
|
friend class SymbolTableListTraits<GlobalVariable, Module>;
|
2007-04-25 14:27:10 +00:00
|
|
|
friend class SymbolTableListTraits<GlobalAlias, Module>;
|
2006-01-10 09:51:48 +00:00
|
|
|
/// @name Types
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
/// @brief A mapping of names to values.
|
2009-08-04 23:07:12 +00:00
|
|
|
typedef StringMap<Value*> ValueMap;
|
2006-01-10 09:51:48 +00:00
|
|
|
|
|
|
|
/// @brief An iterator over a ValueMap.
|
|
|
|
typedef ValueMap::iterator iterator;
|
|
|
|
|
|
|
|
/// @brief A const_iterator over a ValueMap.
|
|
|
|
typedef ValueMap::const_iterator const_iterator;
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Constructors
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
|
2007-04-04 00:30:49 +00:00
|
|
|
ValueSymbolTable() : vmap(0), LastUnique(0) {}
|
2006-01-10 09:51:48 +00:00
|
|
|
~ValueSymbolTable();
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Accessors
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
|
2009-07-23 18:52:12 +00:00
|
|
|
/// This method finds the value with the given \p Name in the
|
2006-01-10 09:51:48 +00:00
|
|
|
/// the symbol table.
|
2009-07-23 18:52:12 +00:00
|
|
|
/// @returns the value associated with the \p Name
|
2006-01-10 09:51:48 +00:00
|
|
|
/// @brief Lookup a named Value.
|
2009-11-06 10:58:06 +00:00
|
|
|
Value *lookup(StringRef Name) const { return vmap.lookup(Name); }
|
2006-01-10 09:51:48 +00:00
|
|
|
|
|
|
|
/// @returns true iff the symbol table is empty
|
|
|
|
/// @brief Determine if the symbol table is empty
|
|
|
|
inline bool empty() const { return vmap.empty(); }
|
|
|
|
|
|
|
|
/// @brief The number of name/type pairs is returned.
|
|
|
|
inline unsigned size() const { return unsigned(vmap.size()); }
|
|
|
|
|
|
|
|
/// This function can be used from the debugger to display the
|
|
|
|
/// content of the symbol table while debugging.
|
|
|
|
/// @brief Print out symbol table on stderr
|
|
|
|
void dump() const;
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Iteration
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
/// @brief Get an iterator that from the beginning of the symbol table.
|
|
|
|
inline iterator begin() { return vmap.begin(); }
|
|
|
|
|
|
|
|
/// @brief Get a const_iterator that from the beginning of the symbol table.
|
|
|
|
inline const_iterator begin() const { return vmap.begin(); }
|
|
|
|
|
|
|
|
/// @brief Get an iterator to the end of the symbol table.
|
|
|
|
inline iterator end() { return vmap.end(); }
|
|
|
|
|
|
|
|
/// @brief Get a const_iterator to the end of the symbol table.
|
|
|
|
inline const_iterator end() const { return vmap.end(); }
|
2007-02-12 05:18:08 +00:00
|
|
|
|
2006-01-10 09:51:48 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Mutators
|
|
|
|
/// @{
|
2007-02-07 06:06:24 +00:00
|
|
|
private:
|
2006-01-10 09:51:48 +00:00
|
|
|
/// This method adds the provided value \p N to the symbol table. The Value
|
|
|
|
/// must have a name which is used to place the value in the symbol table.
|
2007-02-12 05:18:08 +00:00
|
|
|
/// If the inserted name conflicts, this renames the value.
|
2006-01-10 09:51:48 +00:00
|
|
|
/// @brief Add a named value to the symbol table
|
2007-02-12 05:18:08 +00:00
|
|
|
void reinsertValue(Value *V);
|
|
|
|
|
|
|
|
/// createValueName - This method attempts to create a value name and insert
|
|
|
|
/// it into the symbol table with the specified name. If it conflicts, it
|
|
|
|
/// auto-renames the name and returns that instead.
|
2009-11-06 10:58:06 +00:00
|
|
|
ValueName *createValueName(StringRef Name, Value *V);
|
2007-02-12 05:18:08 +00:00
|
|
|
|
|
|
|
/// This method removes a value from the symbol table. It leaves the
|
|
|
|
/// ValueName attached to the value, but it is no longer inserted in the
|
|
|
|
/// symtab.
|
|
|
|
void removeValueName(ValueName *V);
|
2007-02-07 06:13:49 +00:00
|
|
|
|
2006-01-10 09:51:48 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Internal Data
|
|
|
|
/// @{
|
|
|
|
private:
|
|
|
|
ValueMap vmap; ///< The map that holds the symbol table.
|
2006-05-31 20:40:36 +00:00
|
|
|
mutable uint32_t LastUnique; ///< Counter for tracking unique names
|
2006-01-10 09:51:48 +00:00
|
|
|
|
|
|
|
/// @}
|
|
|
|
};
|
|
|
|
|
2010-01-07 19:39:36 +00:00
|
|
|
/// This class provides a symbol table of name/NamedMDNode pairs. It is
|
|
|
|
/// essentially a StringMap wrapper.
|
|
|
|
|
|
|
|
class MDSymbolTable {
|
2010-01-12 18:34:06 +00:00
|
|
|
friend class SymbolTableListTraits<NamedMDNode, Module>;
|
2010-01-07 19:39:36 +00:00
|
|
|
/// @name Types
|
|
|
|
/// @{
|
2010-01-09 01:44:59 +00:00
|
|
|
private:
|
2010-01-07 19:39:36 +00:00
|
|
|
/// @brief A mapping of names to metadata
|
|
|
|
typedef StringMap<NamedMDNode*> MDMap;
|
|
|
|
|
2010-01-09 01:44:59 +00:00
|
|
|
public:
|
2010-01-07 19:39:36 +00:00
|
|
|
/// @brief An iterator over a ValueMap.
|
|
|
|
typedef MDMap::iterator iterator;
|
|
|
|
|
|
|
|
/// @brief A const_iterator over a ValueMap.
|
|
|
|
typedef MDMap::const_iterator const_iterator;
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Constructors
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
|
2010-01-09 01:44:59 +00:00
|
|
|
MDSymbolTable(const MDNode &); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const MDSymbolTable &); // DO NOT IMPLEMENT
|
2010-01-07 19:39:36 +00:00
|
|
|
MDSymbolTable() : mmap(0) {}
|
|
|
|
~MDSymbolTable();
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Accessors
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// This method finds the value with the given \p Name in the
|
|
|
|
/// the symbol table.
|
|
|
|
/// @returns the NamedMDNode associated with the \p Name
|
|
|
|
/// @brief Lookup a named Value.
|
|
|
|
NamedMDNode *lookup(StringRef Name) const { return mmap.lookup(Name); }
|
|
|
|
|
|
|
|
/// @returns true iff the symbol table is empty
|
|
|
|
/// @brief Determine if the symbol table is empty
|
|
|
|
inline bool empty() const { return mmap.empty(); }
|
|
|
|
|
|
|
|
/// @brief The number of name/type pairs is returned.
|
|
|
|
inline unsigned size() const { return unsigned(mmap.size()); }
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Iteration
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
/// @brief Get an iterator that from the beginning of the symbol table.
|
|
|
|
inline iterator begin() { return mmap.begin(); }
|
|
|
|
|
|
|
|
/// @brief Get a const_iterator that from the beginning of the symbol table.
|
|
|
|
inline const_iterator begin() const { return mmap.begin(); }
|
|
|
|
|
|
|
|
/// @brief Get an iterator to the end of the symbol table.
|
|
|
|
inline iterator end() { return mmap.end(); }
|
|
|
|
|
|
|
|
/// @brief Get a const_iterator to the end of the symbol table.
|
|
|
|
inline const_iterator end() const { return mmap.end(); }
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Mutators
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
/// insert - The method inserts a new entry into the stringmap.
|
|
|
|
void insert(StringRef Name, NamedMDNode *Node) {
|
|
|
|
(void) mmap.GetOrCreateValue(Name, Node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This method removes a NamedMDNode from the symbol table.
|
|
|
|
void remove(StringRef Name) { mmap.erase(Name); }
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Internal Data
|
|
|
|
/// @{
|
|
|
|
private:
|
|
|
|
MDMap mmap; ///< The map that holds the symbol table.
|
|
|
|
/// @}
|
|
|
|
};
|
|
|
|
|
2006-01-10 09:51:48 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|