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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 00:45:19 +00:00
|
|
|
#ifndef LLVM_IR_VALUESYMBOLTABLE_H
|
|
|
|
#define LLVM_IR_VALUESYMBOLTABLE_H
|
2006-01-10 09:51:48 +00:00
|
|
|
|
2015-11-22 00:16:24 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2007-02-12 05:18:08 +00:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Value.h"
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2006-01-10 09:51:48 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2015-10-07 20:05:10 +00:00
|
|
|
template <typename ValueSubClass> class SymbolTableListTraits;
|
2007-02-07 06:06:24 +00:00
|
|
|
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;
|
2015-10-07 20:05:10 +00:00
|
|
|
friend class SymbolTableListTraits<Argument>;
|
|
|
|
friend class SymbolTableListTraits<BasicBlock>;
|
|
|
|
friend class SymbolTableListTraits<Instruction>;
|
|
|
|
friend class SymbolTableListTraits<Function>;
|
|
|
|
friend class SymbolTableListTraits<GlobalVariable>;
|
|
|
|
friend class SymbolTableListTraits<GlobalAlias>;
|
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
|
2015-09-22 11:14:12 +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
|
|
|
|
2012-09-27 10:14:43 +00:00
|
|
|
/// @returns true iff the symbol table is empty
|
2006-01-10 09:51:48 +00:00
|
|
|
/// @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(); }
|
2015-09-22 11:14:12 +00:00
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Mutators
|
|
|
|
/// @{
|
2007-02-07 06:06:24 +00:00
|
|
|
private:
|
2015-11-22 00:16:24 +00:00
|
|
|
ValueName *makeUniqueName(Value *V, SmallString<256> &UniqueName);
|
|
|
|
|
2006-01-10 09:51:48 +00:00
|
|
|
/// This method adds the provided value \p N to the symbol table. The Value
|
2015-09-22 11:14:12 +00:00
|
|
|
/// 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);
|
2015-09-22 11:14:39 +00:00
|
|
|
|
2007-02-12 05:18:08 +00:00
|
|
|
/// 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);
|
2015-09-22 11:14:39 +00:00
|
|
|
|
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);
|
2015-09-22 11:14:12 +00:00
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// @name Internal Data
|
|
|
|
/// @{
|
2006-01-10 09:51:48 +00:00
|
|
|
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
|
|
|
|
|
|
|
/// @}
|
|
|
|
};
|
|
|
|
|
2015-06-23 09:49:53 +00:00
|
|
|
} // End llvm namespace
|
2006-01-10 09:51:48 +00:00
|
|
|
|
|
|
|
#endif
|