LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

llvm::SymbolTable Class Reference

#include <SymbolTable.h>

Inheritance diagram for llvm::SymbolTable:

Inheritance graph
[legend]
Collaboration diagram for llvm::SymbolTable:

Collaboration graph
[legend]
List of all members.

Public Types

Types
typedef std::map< const std::string,
const Type * > 
TypeMap
 A mapping of names to types.
typedef TypeMap::iterator type_iterator
 An iterator over the TypeMap.
typedef TypeMap::const_iterator type_const_iterator
 A const_iterator over the TypeMap.
typedef std::map< const std::string,
Value * > 
ValueMap
 A mapping of names to values.
typedef ValueMap::iterator value_iterator
 An iterator over a ValueMap.
typedef ValueMap::const_iterator value_const_iterator
 A const_iterator over a ValueMap.
typedef std::map< const Type *,
ValueMap
PlaneMap
 A mapping of types to names to values (type planes).
typedef PlaneMap::iterator plane_iterator
 An iterator over the type planes.
typedef PlaneMap::const_iterator plane_const_iterator
 A const_iterator over the type planes.

Public Member Functions

Constructors
 SymbolTable ()
 ~SymbolTable ()
Accessors
Valuelookup (const Type *Ty, const std::string &name) const
 Lookup a named, typed value.
TypelookupType (const std::string &name) const
 Lookup a type by name.
bool hasTypes () const
 Determine if there are types in the symbol table.
bool isEmpty () const
 Determine if the symbol table is empty.
unsigned type_size (const Type *TypeID) const
 Get the size of a type plane.
unsigned num_types () const
 The number of name/type pairs is returned.
std::string get_name (const Value *Val) const
 Return the name of a value.
std::string get_name (const Type *Ty) const
 Return the name of a type.
std::string getUniqueName (const Type *Ty, const std::string &BaseName) const
 Get a name unique to this symbol table.
void dump () const
 Print out symbol table on stderr.
Mutators
void insert (Value *Val)
 Add a named value to the symbol table.
void insert (const std::string &Name, Value *Val)
 Insert a constant or type.
void insert (const std::string &Name, const Type *Typ)
 Insert a type under a new name.
void remove (Value *Val)
 Remove a named value from the symbol table.
void remove (const Type *Typ)
 Remove a named type from the symbol table.
Valueremove (const std::string &Name, Value *Val)
 Remove a constant or type from the symbol table.
Typeremove (type_iterator TI)
Valuevalue_remove (const value_iterator &It)
 Remove a specific value given by an iterator.
bool strip ()
 Strip the symbol table.
void clear ()
 Empty the symbol table completely.
Iteration
plane_iterator plane_begin ()
plane_const_iterator plane_begin () const
plane_iterator plane_end ()
plane_const_iterator plane_end () const
value_iterator value_begin (const Type *Typ)
value_const_iterator value_begin (const Type *Typ) const
value_iterator value_end (const Type *Typ)
value_const_iterator value_end (const Type *Typ) const
type_iterator type_begin ()
 Get an iterator to the start of the name/Type map.
type_const_iterator type_begin () const
 Get a const_iterator to the start of the name/Type map.
type_iterator type_end ()
type_const_iterator type_end () const
plane_const_iterator find (const Type *Typ) const
 Find a type plane.
plane_iterator find (const Type *Typ)
 Find a type plane.
const ValueMapfindPlane (const Type *Typ) const
 Find a type plane.

Detailed Description

This class provides a symbol table of name/value pairs that is broken up by type. For each Type* there is a "plane" of name/value pairs in the symbol table. Identical types may have overlapping symbol names as long as they are distinct. The SymbolTable also tracks, separately, a map of name/type pairs. This allows types to be named. Types are treated distinctly from Values.

The SymbolTable provides several utility functions for answering common questions about its contents as well as an iterator interface for directly iterating over the contents. To reduce confusion, the terms "type", "value", and "plane" are used consistently. For example, There is a TypeMap typedef that is the mapping of names to Types. Similarly there is a ValueMap typedef that is the mapping of names to Values. Finally, there is a PlaneMap typedef that is the mapping of types to planes of ValueMap. This is the basic structure of the symbol table. When you call type_begin() you're asking for an iterator at the start of the TypeMap. When you call plane_begin(), you're asking for an iterator at the start of the PlaneMap. Finally, when you call value_begin(), you're asking for an iterator at the start of a ValueMap for a specific type plane.

Definition at line 44 of file SymbolTable.h.


Member Typedef Documentation

typedef PlaneMap::const_iterator llvm::SymbolTable::plane_const_iterator
 

A const_iterator over the type planes.

Definition at line 75 of file SymbolTable.h.

typedef PlaneMap::iterator llvm::SymbolTable::plane_iterator
 

An iterator over the type planes.

Definition at line 72 of file SymbolTable.h.

typedef std::map<const Type *, ValueMap> llvm::SymbolTable::PlaneMap
 

A mapping of types to names to values (type planes).

Definition at line 69 of file SymbolTable.h.

typedef TypeMap::const_iterator llvm::SymbolTable::type_const_iterator
 

A const_iterator over the TypeMap.

Definition at line 57 of file SymbolTable.h.

typedef TypeMap::iterator llvm::SymbolTable::type_iterator
 

An iterator over the TypeMap.

Definition at line 54 of file SymbolTable.h.

typedef std::map<const std::string, const Type*> llvm::SymbolTable::TypeMap
 

A mapping of names to types.

Definition at line 51 of file SymbolTable.h.

typedef ValueMap::const_iterator llvm::SymbolTable::value_const_iterator
 

A const_iterator over a ValueMap.

Definition at line 66 of file SymbolTable.h.

typedef ValueMap::iterator llvm::SymbolTable::value_iterator
 

An iterator over a ValueMap.

Definition at line 63 of file SymbolTable.h.

typedef std::map<const std::string, Value *> llvm::SymbolTable::ValueMap
 

A mapping of names to values.

Definition at line 60 of file SymbolTable.h.


Constructor & Destructor Documentation

llvm::SymbolTable::SymbolTable  )  [inline]
 

Definition at line 82 of file SymbolTable.h.

SymbolTable::~SymbolTable  ) 
 

Definition at line 27 of file SymbolTable.cpp.


Member Function Documentation

void llvm::SymbolTable::clear  )  [inline]
 

Empty the symbol table completely.

Definition at line 226 of file SymbolTable.h.

References llvm::TypeMap< ValType, TypeClass >::clear().

void SymbolTable::dump  )  const [virtual]
 

Print out symbol table on stderr.

This function can be used from the debugger to display the content of the symbol table while debugging.

Implements llvm::AbstractTypeUser.

Definition at line 494 of file SymbolTable.cpp.

References DumpPlane(), and DumpTypes().

plane_iterator llvm::SymbolTable::find const Type Typ  )  [inline]
 

Find a type plane.

This method returns a plane_iterator for iteration over the type planes starting at a specific plane, given by Ty.

Definition at line 308 of file SymbolTable.h.

plane_const_iterator llvm::SymbolTable::find const Type Typ  )  const [inline]
 

Find a type plane.

This method returns a plane_const_iterator for iteration over the type planes starting at a specific plane, given by Ty.

Definition at line 300 of file SymbolTable.h.

Referenced by llvm::Function::renameLocalSymbols().

const ValueMap* llvm::SymbolTable::findPlane const Type Typ  )  const [inline]
 

Find a type plane.

This method returns a ValueMap* for a specific type plane. This interface is deprecated and may go away in the future.

Deprecated:

Definition at line 317 of file SymbolTable.h.

References I.

std::string SymbolTable::get_name const Type Ty  )  const
 

Return the name of a type.

Finds the type Ty in the symbol table and returns its name.

Definition at line 284 of file SymbolTable.cpp.

std::string SymbolTable::get_name const Value Val  )  const
 

Return the name of a value.

Finds the value val in the symbol table and returns its name. Only the type plane associated with the type of val is searched.

Definition at line 268 of file SymbolTable.cpp.

References llvm::Value::getType(), value_begin(), and value_end().

std::string SymbolTable::getUniqueName const Type Ty,
const std::string &  BaseName
const
 

Get a name unique to this symbol table.

Given a base name, return a string that is either equal to it or derived from it that does not already occur in the symbol table for the specified type.

Definition at line 57 of file SymbolTable.cpp.

References llvm::utostr().

bool llvm::SymbolTable::hasTypes  )  const [inline]
 

Determine if there are types in the symbol table.

Returns:
true iff the type map is not empty.

Definition at line 108 of file SymbolTable.h.

void llvm::SymbolTable::insert const std::string &  Name,
const Type Typ
[inline]
 

Insert a type under a new name.

Inserts a type into the symbol table with the specified name. There can be a many-to-one mapping between names and types. This method allows a type with an existing entry in the symbol table to get a new name.

Definition at line 177 of file SymbolTable.h.

void llvm::SymbolTable::insert const std::string &  Name,
Value Val
[inline]
 

Insert a constant or type.

Inserts a constant into the symbol table with the specified name. There can be a many to one mapping between names and constants.

Definition at line 165 of file SymbolTable.h.

void llvm::SymbolTable::insert Value Val  )  [inline]
 

Add a named value to the symbol table.

This method adds the provided value N to the symbol table. The Value must have both a name and a type which are extracted and used to place the value in the correct type plane under the value's name.

Definition at line 156 of file SymbolTable.h.

References llvm::Value::getName(), llvm::Value::getType(), and llvm::Value::hasName().

Referenced by llvm::Module::addTypeName(), llvm::BytecodeReader::ParseSymbolTable(), ResolveTypes(), llvm::Instruction::setName(), llvm::GlobalVariable::setName(), llvm::Function::setName(), llvm::Argument::setName(), llvm::Constant::setName(), llvm::BasicBlock::setName(), and llvm::SymbolTableListTraits< ValueSubClass, ItemParentClass, SymTabClass, SubClass >::setParent().

bool llvm::SymbolTable::isEmpty  )  const [inline]
 

Determine if the symbol table is empty.

Returns:
true iff the type map and the type plane are both not empty.

Definition at line 113 of file SymbolTable.h.

Value * SymbolTable::lookup const Type Ty,
const std::string &  name
const
 

Lookup a named, typed value.

This method finds the value with the given name in the type plane Ty and returns it. This method will not find any Types, only Values. Use lookupType to find Types by name.

Returns:
null on failure, otherwise the Value associated with the name in type plane Ty.

Definition at line 75 of file SymbolTable.cpp.

Referenced by ForceRenaming(), llvm::Module::getFunction(), llvm::Module::getOrInsertFunction(), lookupInSymbolTable(), and setValueName().

Type * SymbolTable::lookupType const std::string &  name  )  const
 

Lookup a type by name.

This method finds the type with the given name in the type map and returns it.

Returns:
null if the name is not found, otherwise the Type associated with the name.

Definition at line 87 of file SymbolTable.cpp.

Referenced by llvm::Module::addTypeName(), llvm::Module::getTypeByName(), and LinkTypes().

unsigned llvm::SymbolTable::num_types  )  const [inline]
 

The number of name/type pairs is returned.

Definition at line 122 of file SymbolTable.h.

plane_const_iterator llvm::SymbolTable::plane_begin  )  const [inline]
 

Get a const_iterator that starts at the beginning of the type planes. The iterator will iterate over the Type/ValueMap pairs in the type planes.

Definition at line 241 of file SymbolTable.h.

plane_iterator llvm::SymbolTable::plane_begin  )  [inline]
 

Get an iterator that starts at the beginning of the type planes. The iterator will iterate over the Type/ValueMap pairs in the type planes.

Definition at line 236 of file SymbolTable.h.

Referenced by llvm::Function::renameLocalSymbols().

plane_const_iterator llvm::SymbolTable::plane_end  )  const [inline]
 

Get a const_iterator at the end of the type planes. This serves as the marker for end of iteration over the type planes.

Definition at line 249 of file SymbolTable.h.

plane_iterator llvm::SymbolTable::plane_end  )  [inline]
 

Get an iterator at the end of the type planes. This serves as the marker for end of iteration over the type planes.

Definition at line 245 of file SymbolTable.h.

Referenced by llvm::Function::renameLocalSymbols().

Type* llvm::SymbolTable::remove type_iterator  TI  )  [inline]
 

Remove a type at the specified position in the symbol table.

Returns:
the removed Type.

Definition at line 209 of file SymbolTable.h.

Value* llvm::SymbolTable::remove const std::string &  Name,
Value Val
[inline]
 

Remove a constant or type from the symbol table.

Remove a constant or type with the specified name from the symbol table.

Returns:
the removed Value.

Definition at line 201 of file SymbolTable.h.

References llvm::Value::getType().

void SymbolTable::remove const Type Typ  ) 
 

Remove a named type from the symbol table.

This method removes a named type from the symbol table. The name of the type is extracted from T and used to look up the Type in the type map. If the Type is not in the symbol table, this method silently ignores the request.

Definition at line 141 of file SymbolTable.cpp.

References type_begin(), and type_end().

void SymbolTable::remove Value Val  ) 
 

Remove a named value from the symbol table.

This method removes a named value from the symbol table. The type and name of the Value are extracted from N and used to lookup the Value in the correct type plane. If the Value is not in the symbol table, this method silently ignores the request.

Definition at line 95 of file SymbolTable.cpp.

References llvm::Value::getName(), llvm::Value::getType(), and llvm::Value::hasName().

Referenced by llvm::Instruction::setName(), llvm::GlobalVariable::setName(), llvm::Function::setName(), llvm::Argument::setName(), llvm::BasicBlock::setName(), llvm::SymbolTableListTraits< ValueSubClass, ItemParentClass, SymTabClass, SubClass >::setParent(), and strip().

bool SymbolTable::strip  ) 
 

Strip the symbol table.

This method will strip the symbol table of its names leaving the type and values.

Definition at line 301 of file SymbolTable.cpp.

References B, I, remove(), and llvm::Value::setName().

type_const_iterator llvm::SymbolTable::type_begin  )  const [inline]
 

Get a const_iterator to the start of the name/Type map.

Definition at line 287 of file SymbolTable.h.

type_iterator llvm::SymbolTable::type_begin  )  [inline]
 

Get an iterator to the start of the name/Type map.

Definition at line 284 of file SymbolTable.h.

Referenced by llvm::CloneModule(), fillTypeNameTable(), llvm::Module::getTypeName(), LinkTypes(), and remove().

type_const_iterator llvm::SymbolTable::type_end  )  const [inline]
 

Get a const-iterator to the end of the name/Type map. This serves as the marker for end of iteration of the types.

Definition at line 295 of file SymbolTable.h.

type_iterator llvm::SymbolTable::type_end  )  [inline]
 

Get an iterator to the end of the name/Type map. This serves as the marker for end of iteration of the types.

Definition at line 291 of file SymbolTable.h.

Referenced by llvm::CloneModule(), fillTypeNameTable(), llvm::Module::getTypeName(), LinkTypes(), and remove().

unsigned SymbolTable::type_size const Type TypeID  )  const
 

Get the size of a type plane.

The plane associated with the TypeID parameter is found and the number of entries in the plane is returned.

Returns:
Number of entries in the specified type plane or 0.

Definition at line 260 of file SymbolTable.cpp.

value_const_iterator llvm::SymbolTable::value_begin const Type Typ  )  const [inline]
 

Get a const_iterator that starts at the beginning of a type plane. The iterator will iterate over the name/value pairs in the type plane.

Note:
The type plane must already exist before using this.

Definition at line 262 of file SymbolTable.h.

value_iterator llvm::SymbolTable::value_begin const Type Typ  )  [inline]
 

Get an iterator that starts at the beginning of a type plane. The iterator will iterate over the name/value pairs in the type plane.

Note:
The type plane must already exist before using this.

Definition at line 254 of file SymbolTable.h.

Referenced by get_name().

value_const_iterator llvm::SymbolTable::value_end const Type Typ  )  const [inline]
 

Get a const_iterator to the end of a type plane. This serves as the marker for end of iteration of the type plane.

Note:
The type plane must already exist before using this.

Definition at line 278 of file SymbolTable.h.

value_iterator llvm::SymbolTable::value_end const Type Typ  )  [inline]
 

Get an iterator to the end of a type plane. This serves as the marker for end of iteration of the type plane.

Note:
The type plane must already exist before using this.

Definition at line 270 of file SymbolTable.h.

Referenced by get_name().

Value* llvm::SymbolTable::value_remove const value_iterator It  )  [inline]
 

Remove a specific value given by an iterator.

Removes a specific value from the symbol table.

Returns:
the removed value.

Definition at line 216 of file SymbolTable.h.


The documentation for this class was generated from the following files: