diff options
74 files changed, 1575 insertions, 2346 deletions
diff --git a/include/llvm/Bytecode/BytecodeHandler.h b/include/llvm/Bytecode/BytecodeHandler.h index a3e5bb7f1f..c3ddc62030 100644 --- a/include/llvm/Bytecode/BytecodeHandler.h +++ b/include/llvm/Bytecode/BytecodeHandler.h @@ -181,16 +181,14 @@ public: virtual void handleCompactionTableEnd() {} /// @brief Handle start of a symbol table - virtual void handleSymbolTableBegin( - Function* Func, ///< The function to which the ST belongs - SymbolTable* ST ///< The symbol table being filled + virtual void handleTypeSymbolTableBegin( + TypeSymbolTable* ST ///< The symbol table being filled ) {} - /// @brief Handle start of a symbol table plane - virtual void handleSymbolTablePlane( - unsigned TySlot, ///< The slotnum of the type plane - unsigned NumEntries, ///< Number of entries in the plane - const Type* Typ ///< The type of this type plane + /// @brief Handle start of a symbol table + virtual void handleValueSymbolTableBegin( + Function* Func, ///< The function to which the ST belongs or 0 for Mod + ValueSymbolTable* ST ///< The symbol table being filled ) {} /// @brief Handle a named type in the symbol table @@ -207,8 +205,11 @@ public: const std::string& name ///< Name of the value. ) {} - /// @brief Handle the end of a symbol table - virtual void handleSymbolTableEnd() {} + /// @brief Handle the end of a value symbol table + virtual void handleTypeSymbolTableEnd() {} + + /// @brief Handle the end of a type symbol table + virtual void handleValueSymbolTableEnd() {} /// @brief Handle the beginning of a function body virtual void handleFunctionBegin( @@ -233,6 +234,7 @@ public: unsigned Opcode, ///< Opcode of the instruction const Type* iType, ///< Instruction type std::vector<unsigned>& Operands, ///< Vector of slot # operands + Instruction *Inst, ///< The resulting instruction unsigned Length ///< Length of instruction in bc bytes ) { return false; } diff --git a/include/llvm/Function.h b/include/llvm/Function.h index f2a56ac17d..4cfb6761cc 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -63,7 +63,7 @@ private: BasicBlockListType BasicBlocks; // The basic blocks ArgumentListType ArgumentList; // The formal arguments - SymbolTable *SymTab; + ValueSymbolTable *SymTab; unsigned CallingConvention; friend class SymbolTableListTraits<Function, Module, Module>; @@ -156,8 +156,8 @@ public: /// getSymbolTable() - Return the symbol table... /// - inline SymbolTable &getValueSymbolTable() { return *SymTab; } - inline const SymbolTable &getValueSymbolTable() const { return *SymTab; } + inline ValueSymbolTable &getValueSymbolTable() { return *SymTab; } + inline const ValueSymbolTable &getValueSymbolTable() const { return *SymTab; } //===--------------------------------------------------------------------===// diff --git a/include/llvm/LinkAllPasses.h b/include/llvm/LinkAllPasses.h index 01e049938d..1b9322049e 100644 --- a/include/llvm/LinkAllPasses.h +++ b/include/llvm/LinkAllPasses.h @@ -64,7 +64,6 @@ namespace { (void) llvm::createEmitFunctionTablePass(); (void) llvm::createFunctionInliningPass(); (void) llvm::createFunctionProfilerPass(); - (void) llvm::createFunctionResolvingPass(); (void) llvm::createGCSEPass(); (void) llvm::createGlobalDCEPass(); (void) llvm::createGlobalOptimizerPass(); diff --git a/include/llvm/Module.h b/include/llvm/Module.h index 7470debcda..6992563abd 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -23,8 +23,6 @@ namespace llvm { class GlobalVariable; class GlobalValueRefMap; // Used by ConstantVals.cpp class FunctionType; -class SymbolTable; -class TypeSymbolTable; template<> struct ilist_traits<Function> : public SymbolTableListTraits<Function, Module, Module> { @@ -91,7 +89,7 @@ private: FunctionListType FunctionList; ///< The Functions in the module LibraryListType LibraryList; ///< The Libraries needed by the module std::string GlobalScopeAsm; ///< Inline Asm at global scope. - SymbolTable *ValSymTab; ///< Symbol table for values + ValueSymbolTable *ValSymTab; ///< Symbol table for values TypeSymbolTable *TypeSymTab; ///< Symbol table for types std::string ModuleID; ///< Human readable identifier for the module std::string TargetTriple; ///< Platform target triple Module compiled on @@ -178,17 +176,19 @@ public: /// getFunction - Look up the specified function in the module symbol table. /// If it does not exist, return null. - Function *getFunction(const std::string &Name, const FunctionType *Ty); + Function *getFunction(const std::string &Name) const; /// getMainFunction - This function looks up main efficiently. This is such a /// common case, that it is a method in Module. If main cannot be found, a /// null pointer is returned. - Function *getMainFunction(); + Function *getMainFunction() { return getFunction("main"); } /// getNamedFunction - Return the first function in the module with the /// specified name, of arbitrary type. This method returns null if a function /// with the specified name is not found. - Function *getNamedFunction(const std::string &Name) const; + Function *getNamedFunction(const std::string &Name) const { + return getFunction(Name); + } /// @} /// @name Global Variable Accessors @@ -200,13 +200,15 @@ public: /// the top-level PointerType, which represents the address of the global. /// If AllowInternal is set to true, this function will return types that /// have InternalLinkage. By default, these types are not returned. - GlobalVariable *getGlobalVariable(const std::string &Name, const Type *Ty, - bool AllowInternal = false); + GlobalVariable *getGlobalVariable(const std::string &Name, + bool AllowInternal = false) const; /// getNamedGlobal - Return the first global variable in the module with the /// specified name, of arbitrary type. This method returns null if a global /// with the specified name is not found. - GlobalVariable *getNamedGlobal(const std::string &Name) const; + GlobalVariable *getNamedGlobal(const std::string &Name) const { + return getGlobalVariable(Name, true); + } /// @} /// @name Type Accessors @@ -238,9 +240,9 @@ public: /// Get the Module's list of functions. FunctionListType &getFunctionList() { return FunctionList; } /// Get the symbol table of global variable and function identifiers - const SymbolTable &getValueSymbolTable() const { return *ValSymTab; } + const ValueSymbolTable &getValueSymbolTable() const { return *ValSymTab; } /// Get the Module's symbol table of global variable and function identifiers. - SymbolTable &getValueSymbolTable() { return *ValSymTab; } + ValueSymbolTable &getValueSymbolTable() { return *ValSymTab; } /// Get the symbol table of types const TypeSymbolTable &getTypeSymbolTable() const { return *TypeSymTab; } /// Get the Module's symbol table of types diff --git a/include/llvm/SymbolTable.h b/include/llvm/SymbolTable.h deleted file mode 100644 index 6451f9c8e2..0000000000 --- a/include/llvm/SymbolTable.h +++ /dev/null @@ -1,257 +0,0 @@ -//===-- llvm/SymbolTable.h - Implement a type plane'd symtab ----*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file was developed by the LLVM research group and re-written by Reid -// Spencer. It is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements the main symbol table for LLVM. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_SYMBOL_TABLE_H -#define LLVM_SYMBOL_TABLE_H - -#include "llvm/Value.h" -#include "llvm/Support/DataTypes.h" -#include <map> - -namespace llvm { - -/// 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. -class SymbolTable : public AbstractTypeUser { - -/// @name Types -/// @{ -public: - /// @brief A mapping of names to values. - typedef std::map<const std::string, Value *> ValueMap; - - /// @brief An iterator over a ValueMap. - typedef ValueMap::iterator value_iterator; - - /// @brief A const_iterator over a ValueMap. - typedef ValueMap::const_iterator value_const_iterator; - - /// @brief A mapping of types to names to values (type planes). - typedef std::map<const Type *, ValueMap> PlaneMap; - - /// @brief An iterator over the type planes. - typedef PlaneMap::iterator plane_iterator; - - /// @brief A const_iterator over the type planes - typedef PlaneMap::const_iterator plane_const_iterator; - -/// @} -/// @name Constructors -/// @{ -public: - - SymbolTable() : LastUnique(0) {} - ~SymbolTable(); - -/// @} -/// @name Accessors -/// @{ -public: - - /// This method finds the value with the given \p name in the - /// type plane \p 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 \p name in type plane \p Ty. - /// @brief Lookup a named, typed value. - Value *lookup(const Type *Ty, const std::string &name) const; - - /// @returns true iff the type map and the type plane are both not - /// empty. - /// @brief Determine if the symbol table is empty - inline bool isEmpty() const { return pmap.empty(); } - - /// 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. - /// @brief Get a name unique to this symbol table - std::string getUniqueName(const Type *Ty, - const std::string &BaseName) const; - - /// 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: - - /// 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. - inline plane_iterator plane_begin() { return pmap.begin(); } - - /// 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. - inline plane_const_iterator plane_begin() const { return pmap.begin(); } - - /// Get an iterator at the end of the type planes. This serves as - /// the marker for end of iteration over the type planes. - inline plane_iterator plane_end() { return pmap.end(); } - - /// Get a const_iterator at the end of the type planes. This serves as - /// the marker for end of iteration over the type planes. - inline plane_const_iterator plane_end() const { return pmap.end(); } - - /// 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. - inline value_iterator value_begin(const Type *Typ) { - assert(Typ && "Can't get value iterator with null type!"); - return pmap.find(Typ)->second.begin(); - } - - /// 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. - inline value_const_iterator value_begin(const Type *Typ) const { - assert(Typ && "Can't get value iterator with null type!"); - return pmap.find(Typ)->second.begin(); - } - - /// 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. - inline value_iterator value_end(const Type *Typ) { - assert(Typ && "Can't get value iterator with null type!"); - return pmap.find(Typ)->second.end(); - } - - /// 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. - inline value_const_iterator value_end(const Type *Typ) const { - assert(Typ && "Can't get value iterator with null type!"); - return pmap.find(Typ)->second.end(); - } - - /// This method returns a plane_const_iterator for iteration over - /// the type planes starting at a specific plane, given by \p Ty. - /// @brief Find a type plane. - inline plane_const_iterator find(const Type* Typ) const { - assert(Typ && "Can't find type plane with null type!"); - return pmap.find(Typ); - } - - /// This method returns a plane_iterator for iteration over the - /// type planes starting at a specific plane, given by \p Ty. - /// @brief Find a type plane. - inline plane_iterator find(const Type* Typ) { - assert(Typ && "Can't find type plane with null type!"); - return pmap.find(Typ); - } - - -/// @} -/// @name Mutators -/// @{ -public: - - /// This method will strip the symbol table of its names leaving the type and - /// values. - /// @brief Strip the symbol table. - bool strip(); - -/// @} -/// @name Mutators used by Value::setName and other LLVM internals. -/// @{ -public: - - /// This method adds the provided value \p 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. - /// @brief Add a named value to the symbol table - inline void insert(Value *Val) { - assert(Val && "Can't insert null type into symbol table!"); - assert(Val->hasName() && "Value must be named to go into symbol table!"); - insertEntry(Val->getName(), Val->getType(), Val); - } - - /// This method removes a named value from the symbol table. The type and name - /// of the Value are extracted from \p 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. - /// @brief Remove a named value from the symbol table. - void remove(Value* Val); - - /// changeName - Given a value with a non-empty name, remove its existing - /// entry from the symbol table and insert a new one for Name. This is - /// equivalent to doing "remove(V), V->Name = Name, insert(V)", but is faster, - /// and will not temporarily remove the symbol table plane if V is the last - /// value in the symtab with that name (which could invalidate iterators to - /// that plane). - void changeName(Value *V, const std::string &Name); - -/// @} -/// @name Internal Methods -/// @{ -private: - /// @brief Insert a value into the symbol table with the specified name. - void insertEntry(const std::string &Name, const Type *Ty, Value *V); - - /// This function is called when one of the types in the type plane - /// is refined. - virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy); - - /// This function markes a type as being concrete (defined). - virtual void typeBecameConcrete(const DerivedType *AbsTy); - -/// @} -/// @name Internal Data -/// @{ -private: - - /// This is the main content of the symbol table. I |