LLVM API Documentation

ValueSymbolTable.h
Go to the documentation of this file.
00001 //===-- llvm/ValueSymbolTable.h - Implement a Value Symtab ------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the name/Value symbol table for LLVM.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_IR_VALUESYMBOLTABLE_H
00015 #define LLVM_IR_VALUESYMBOLTABLE_H
00016 
00017 #include "llvm/ADT/StringMap.h"
00018 #include "llvm/IR/Value.h"
00019 #include "llvm/Support/DataTypes.h"
00020 
00021 namespace llvm {
00022   template<typename ValueSubClass, typename ItemParentClass>
00023         class SymbolTableListTraits;
00024   class BasicBlock;
00025   class Function;
00026   class NamedMDNode;
00027   class Module;
00028   class StringRef;
00029 
00030 /// This class provides a symbol table of name/value pairs. It is essentially
00031 /// a std::map<std::string,Value*> but has a controlled interface provided by
00032 /// LLVM as well as ensuring uniqueness of names.
00033 ///
00034 class ValueSymbolTable {
00035   friend class Value;
00036   friend class SymbolTableListTraits<Argument, Function>;
00037   friend class SymbolTableListTraits<BasicBlock, Function>;
00038   friend class SymbolTableListTraits<Instruction, BasicBlock>;
00039   friend class SymbolTableListTraits<Function, Module>;
00040   friend class SymbolTableListTraits<GlobalVariable, Module>;
00041   friend class SymbolTableListTraits<GlobalAlias, Module>;
00042 /// @name Types
00043 /// @{
00044 public:
00045   /// @brief A mapping of names to values.
00046   typedef StringMap<Value*> ValueMap;
00047 
00048   /// @brief An iterator over a ValueMap.
00049   typedef ValueMap::iterator iterator;
00050 
00051   /// @brief A const_iterator over a ValueMap.
00052   typedef ValueMap::const_iterator const_iterator;
00053 
00054 /// @}
00055 /// @name Constructors
00056 /// @{
00057 public:
00058 
00059   ValueSymbolTable() : vmap(0), LastUnique(0) {}
00060   ~ValueSymbolTable();
00061 
00062 /// @}
00063 /// @name Accessors
00064 /// @{
00065 public:
00066 
00067   /// This method finds the value with the given \p Name in the
00068   /// the symbol table. 
00069   /// @returns the value associated with the \p Name
00070   /// @brief Lookup a named Value.
00071   Value *lookup(StringRef Name) const { return vmap.lookup(Name); }
00072 
00073   /// @returns true iff the symbol table is empty
00074   /// @brief Determine if the symbol table is empty
00075   inline bool empty() const { return vmap.empty(); }
00076 
00077   /// @brief The number of name/type pairs is returned.
00078   inline unsigned size() const { return unsigned(vmap.size()); }
00079 
00080   /// This function can be used from the debugger to display the
00081   /// content of the symbol table while debugging.
00082   /// @brief Print out symbol table on stderr
00083   void dump() const;
00084 
00085 /// @}
00086 /// @name Iteration
00087 /// @{
00088 public:
00089   /// @brief Get an iterator that from the beginning of the symbol table.
00090   inline iterator begin() { return vmap.begin(); }
00091 
00092   /// @brief Get a const_iterator that from the beginning of the symbol table.
00093   inline const_iterator begin() const { return vmap.begin(); }
00094 
00095   /// @brief Get an iterator to the end of the symbol table.
00096   inline iterator end() { return vmap.end(); }
00097 
00098   /// @brief Get a const_iterator to the end of the symbol table.
00099   inline const_iterator end() const { return vmap.end(); }
00100   
00101 /// @}
00102 /// @name Mutators
00103 /// @{
00104 private:
00105   /// This method adds the provided value \p N to the symbol table.  The Value
00106   /// must have a name which is used to place the value in the symbol table. 
00107   /// If the inserted name conflicts, this renames the value.
00108   /// @brief Add a named value to the symbol table
00109   void reinsertValue(Value *V);
00110     
00111   /// createValueName - This method attempts to create a value name and insert
00112   /// it into the symbol table with the specified name.  If it conflicts, it
00113   /// auto-renames the name and returns that instead.
00114   ValueName *createValueName(StringRef Name, Value *V);
00115   
00116   /// This method removes a value from the symbol table.  It leaves the
00117   /// ValueName attached to the value, but it is no longer inserted in the
00118   /// symtab.
00119   void removeValueName(ValueName *V);
00120   
00121 /// @}
00122 /// @name Internal Data
00123 /// @{
00124 private:
00125   ValueMap vmap;                    ///< The map that holds the symbol table.
00126   mutable uint32_t LastUnique; ///< Counter for tracking unique names
00127 
00128 /// @}
00129 };
00130 
00131 } // End llvm namespace
00132 
00133 #endif