ModuleBlockID = 1, ///< Module block that contains other blocks.
FunctionBlockID = 2, ///< Function block identifier
ConstantPoolBlockID = 3, ///< Constant pool identifier
- SymbolTableBlockID = 4, ///< Symbol table identifier
+ ValueSymbolTableBlockID= 4, ///< Value Symbol table identifier
ModuleGlobalInfoBlockID= 5, ///< Module global info identifier
GlobalTypePlaneBlockID = 6, ///< Global type plan identifier
InstructionListBlockID = 7, ///< All instructions in a function
/// instructions to be encoded more efficiently because VBR takes fewer
/// bytes with smaller values.
/// @brief Value Compaction Table Block
- CompactionTableBlockID = 0x08,
+ CompactionTableBlockID = 8,
+ TypeSymbolTableBlockID = 9, ///< Value Symbol table identifier
// Not a block id, just used to count them
NumberOfBlockIDs
};
/// getSymbolTable() - Return the symbol table...
///
- inline SymbolTable &getSymbolTable() { return *SymTab; }
- inline const SymbolTable &getSymbolTable() const { return *SymTab; }
+ inline SymbolTable &getValueSymbolTable() { return *SymTab; }
+ inline const SymbolTable &getValueSymbolTable() const { return *SymTab; }
//===--------------------------------------------------------------------===//
class GlobalValueRefMap; // Used by ConstantVals.cpp
class FunctionType;
class SymbolTable;
+class TypeSymbolTable;
template<> struct ilist_traits<Function>
: public SymbolTableListTraits<Function, Module, Module> {
FunctionListType FunctionList; ///< The Functions in the module
LibraryListType LibraryList; ///< The Libraries needed by the module
std::string GlobalScopeAsm; ///< Inline Asm at global scope.
- SymbolTable *SymTab; ///< Symbol Table for the module
+ SymbolTable *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
std::string DataLayout; ///< Target data description
/// Get the Module's list of functions.
FunctionListType &getFunctionList() { return FunctionList; }
/// Get the symbol table of global variable and function identifiers
- const SymbolTable &getSymbolTable() const { return *SymTab; }
+ const SymbolTable &getValueSymbolTable() const { return *ValSymTab; }
/// Get the Module's symbol table of global variable and function identifiers.
- SymbolTable &getSymbolTable() { return *SymTab; }
+ SymbolTable &getValueSymbolTable() { return *ValSymTab; }
+ /// Get the symbol table of types
+ const TypeSymbolTable &getTypeSymbolTable() const { return *TypeSymTab; }
+ /// Get the Module's symbol table of types
+ TypeSymbolTable &getTypeSymbolTable() { return *TypeSymTab; }
/// @}
/// @name Global Variable Iteration
/// @name Types
/// @{
public:
-
- /// @brief A mapping of names to types.
- typedef std::map<const std::string, const Type*> TypeMap;
-
- /// @brief An iterator over the TypeMap.
- typedef TypeMap::iterator type_iterator;
-
- /// @brief A const_iterator over the TypeMap.
- typedef TypeMap::const_iterator type_const_iterator;
-
/// @brief A mapping of names to values.
typedef std::map<const std::string, Value *> ValueMap;
/// @brief Lookup a named, typed value.
Value *lookup(const Type *Ty, const std::string &name) const;
- /// This method finds the type with the given \p name in the
- /// type map and returns it.
- /// @returns null if the name is not found, otherwise the Type
- /// associated with the \p name.
- /// @brief Lookup a type by name.
- Type* lookupType(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() && tmap.empty(); }
-
- /// @brief The number of name/type pairs is returned.
- inline unsigned num_types() const { return unsigned(tmap.size()); }
+ 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
return pmap.find(Typ)->second.end();
}
- /// Get an iterator to the start of the name/Type map.
- inline type_iterator type_begin() { return tmap.begin(); }
-
- /// @brief Get a const_iterator to the start of the name/Type map.
- inline type_const_iterator type_begin() const { return tmap.begin(); }
-
- /// Get an iterator to the end of the name/Type map. This serves as the
- /// marker for end of iteration of the types.
- inline type_iterator type_end() { return tmap.end(); }
-
- /// Get a const-iterator to the end of the name/Type map. This serves
- /// as the marker for end of iteration of the types.
- inline type_const_iterator type_end() const { return tmap.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.
/// @brief Strip the symbol table.
bool strip();
- /// 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.
- /// @brief Insert a type under a new name.
- void insert(const std::string &Name, const Type *Typ);
-
- /// Remove a type at the specified position in the symbol table.
- /// @returns the removed Type.
- Type* remove(type_iterator TI);
-
/// @}
/// @name Mutators used by Value::setName and other LLVM internals.
/// @{
/// @brief The mapping of types to names to values.
PlaneMap pmap;
- /// This is the type plane. It is separated from the pmap
- /// because the elements of the map are name/Type pairs not
- /// name/Value pairs and Type is not a Value.
- TypeMap tmap;
-
/// This value is used to retain the last unique value used
/// by getUniqueName to generate unique names.
mutable uint32_t LastUnique;
-
/// @}
};
/// Remove a type at the specified position in the symbol table.
/// @returns the removed Type.
/// @returns the Type that was erased from the symbol table.
- Type* erase(iterator TI);
+ Type* remove(iterator TI);
/// Remove a specific Type from the symbol table. This isn't fast, linear
/// search, O(n), algorithm.
/// @returns true if the erase was successful (TI was found)
- bool erase(Type* TI);
+ bool remove(Type* TI);
/// Rename a type. This ain't fast, we have to linearly search for it first.
/// @returns true if the rename was successful (type was found)
static Value *lookupInSymbolTable(const Type *Ty, const std::string &Name) {
SymbolTable &SymTab =
- inFunctionScope() ? CurFun.CurrentFunction->getSymbolTable() :
- CurModule.CurrentModule->getSymbolTable();
+ inFunctionScope() ? CurFun.CurrentFunction->getValueSymbolTable() :
+ CurModule.CurrentModule->getValueSymbolTable();
return SymTab.lookup(Ty, Name);
}
case ValID::NameVal: // Is it a named definition?
Name = ID.Name;
if (Value *N = CurFun.CurrentFunction->
- getSymbolTable().lookup(Type::LabelTy, Name))
+ getValueSymbolTable().lookup(Type::LabelTy, Name))
BB = cast<BasicBlock>(N);
break;
}
}
assert(inFunctionScope() && "Must be in function scope!");
- SymbolTable &ST = CurFun.CurrentFunction->getSymbolTable();
+ SymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
if (ST.lookup(V->getType(), Name)) {
GenerateError("Redefinition of value '" + Name + "' of type '" +
V->getType()->getDescription() + "'!");
static Value *lookupInSymbolTable(const Type *Ty, const std::string &Name) {
SymbolTable &SymTab =
- inFunctionScope() ? CurFun.CurrentFunction->getSymbolTable() :
- CurModule.CurrentModule->getSymbolTable();
+ inFunctionScope() ? CurFun.CurrentFunction->getValueSymbolTable() :
+ CurModule.CurrentModule->getValueSymbolTable();
return SymTab.lookup(Ty, Name);
}
case ValID::NameVal: // Is it a named definition?
Name = ID.Name;
if (Value *N = CurFun.CurrentFunction->
- getSymbolTable().lookup(Type::LabelTy, Name))
+ getValueSymbolTable().lookup(Type::LabelTy, Name))
BB = cast<BasicBlock>(N);
break;
}
}
assert(inFunctionScope() && "Must be in function scope!");
- SymbolTable &ST = CurFun.CurrentFunction->getSymbolTable();
+ SymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
if (ST.lookup(V->getType(), Name)) {
GenerateError("Redefinition of value '" + Name + "' of type '" +
V->getType()->getDescription() + "'!");
static Value *lookupInSymbolTable(const Type *Ty, const std::string &Name) {
SymbolTable &SymTab =
- inFunctionScope() ? CurFun.CurrentFunction->getSymbolTable() :
- CurModule.CurrentModule->getSymbolTable();
+ inFunctionScope() ? CurFun.CurrentFunction->getValueSymbolTable() :
+ CurModule.CurrentModule->getValueSymbolTable();
return SymTab.lookup(Ty, Name);
}
case ValID::NameVal: // Is it a named definition?
Name = ID.Name;
if (Value *N = CurFun.CurrentFunction->
- getSymbolTable().lookup(Type::LabelTy, Name))
+ getValueSymbolTable().lookup(Type::LabelTy, Name))
BB = cast<BasicBlock>(N);
break;
}
}
assert(inFunctionScope() && "Must be in function scope!");
- SymbolTable &ST = CurFun.CurrentFunction->getSymbolTable();
+ SymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
if (ST.lookup(V->getType(), Name)) {
GenerateError("Redefinition of value '" + Name + "' of type '" +
V->getType()->getDescription() + "'!");
bca.BlockSizes[BytecodeFormat::ModuleBlockID] = theSize;
bca.BlockSizes[BytecodeFormat::FunctionBlockID] = 0;
bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID] = 0;
- bca.BlockSizes[BytecodeFormat::SymbolTableBlockID] = 0;
+ bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID] = 0;
bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID] = 0;
bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID] = 0;
bca.BlockSizes[BytecodeFormat::InstructionListBlockID] = 0;
bca.BlockSizes[BytecodeFormat::CompactionTableBlockID] = 0;
+ bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID] = 0;
}
virtual void handleFinish() {
print(Out, "Compaction Table Bytes",
double(bca.BlockSizes[BytecodeFormat::CompactionTableBlockID]),
double(bca.byteSize));
- print(Out, "Symbol Table Bytes",
- double(bca.BlockSizes[BytecodeFormat::SymbolTableBlockID]),
+ print(Out, "Value Symbol Table Bytes",
+ double(bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID]),
+ double(bca.byteSize));
+ print(Out, "Type Symbol Table Bytes",
+ double(bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID]),
double(bca.byteSize));
print(Out, "Alignment Bytes",
double(bca.numAlignment), double(bca.byteSize));
#include "llvm/InlineAsm.h"
#include "llvm/Instructions.h"
#include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
#include "llvm/Bytecode/Format.h"
#include "llvm/Config/alloca.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
return BlockNo;
}
-/// Parse a symbol table. This works for both module level and function
+/// Parse a type symbol table.
+void BytecodeReader::ParseTypeSymbolTable(TypeSymbolTable *TST) {
+ // Type Symtab block header: [num entries]
+ unsigned NumEntries = read_vbr_uint();
+ for (unsigned i = 0; i < NumEntries; ++i) {
+ // Symtab entry: [type slot #][name]
+ unsigned slot = read_vbr_uint();
+ std::string Name = read_str();
+ const Type* T = getType(slot);
+ TST->insert(Name, T);
+ }
+}
+
+/// Parse a value symbol table. This works for both module level and function
/// level symbol tables. For function level symbol tables, the CurrentFunction
/// parameter must be non-zero and the ST parameter must correspond to
/// CurrentFunction's symbol table. For Module level symbol tables, the
/// CurrentFunction argument must be zero.
-void BytecodeReader::ParseSymbolTable(Function *CurrentFunction,
- SymbolTable *ST) {
+void BytecodeReader::ParseValueSymbolTable(Function *CurrentFunction,
+ SymbolTable *ST) {
+
if (Handler) Handler->handleSymbolTableBegin(CurrentFunction,ST);
// Allow efficient basic block lookup by number.
E = CurrentFunction->end(); I != E; ++I)
BBMap.push_back(I);
- // Symtab block header: [num entries]
- unsigned NumEntries = read_vbr_uint();
- for (unsigned i = 0; i < NumEntries; ++i) {
- // Symtab entry: [def slot #][name]
- unsigned slot = read_vbr_uint();
- std::string Name = read_str();
- const Type* T = getType(slot);
- ST->insert(Name, T);
- }
-
while (moreInBlock()) {
// Symtab block header: [num entries][type id number]
unsigned NumEntries = read_vbr_uint();
break;
}
- case BytecodeFormat::SymbolTableBlockID:
- ParseSymbolTable(F, &F->getSymbolTable());
+ case BytecodeFormat::ValueSymbolTableBlockID:
+ ParseValueSymbolTable(F, &F->getValueSymbolTable());
+ break;
+
+ case BytecodeFormat::TypeSymbolTableBlockID:
+ error("Functions don't have type symbol tables");
break;
default:
ParseFunctionLazily();
break;
- case BytecodeFormat::SymbolTableBlockID:
- ParseSymbolTable(0, &TheModule->getSymbolTable());
+ case BytecodeFormat::ValueSymbolTableBlockID:
+ ParseValueSymbolTable(0, &TheModule->getValueSymbolTable());
+ break;
+
+ case BytecodeFormat::TypeSymbolTableBlockID:
+ ParseTypeSymbolTable(&TheModule->getTypeSymbolTable());
break;
default:
namespace llvm {
class BytecodeHandler; ///< Forward declare the handler interface
+class TypeSymbolTable; ///< Forward declare
/// This class defines the interface for parsing a buffer of bytecode. The
/// parser itself takes no action except to call the various functions of
/// @brief Parse the ModuleGlobalInfo block
void ParseModuleGlobalInfo();
- /// @brief Parse a symbol table
- void ParseSymbolTable( Function* Func, SymbolTable *ST);
+ /// @brief Parse a value symbol table
+ void ParseTypeSymbolTable(TypeSymbolTable *ST);
+
+ /// @brief Parse a value symbol table
+ void ParseValueSymbolTable(Function* Func, SymbolTable *ST);
/// @brief Parse functions lazily.
void ParseFunctionLazily();
#include "llvm/Instructions.h"
#include "llvm/Module.h"
#include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
#include "llvm/Type.h"
#include "llvm/Analysis/ConstantsScanner.h"
#include "llvm/ADT/PostOrderIterator.h"
}
getOrCreateSlot(I->getType());
}
- processSymbolTableConstants(&F->getSymbolTable());
+ processSymbolTableConstants(&F->getValueSymbolTable());
}
// Insert constants that are named at module level into the slot pool so that
// the module symbol table can refer to them...
SC_DEBUG("Inserting SymbolTable values:\n");
- processSymbolTable(&TheModule->getSymbolTable());
+ processTypeSymbolTable(&TheModule->getTypeSymbolTable());
+ processValueSymbolTable(&TheModule->getValueSymbolTable());
// Now that we have collected together all of the information relevant to the
// module, compactify the type table if it is particularly big and outputting
SC_DEBUG("end processModule!\n");
}
+// processTypeSymbolTable - Insert all of the type sin the specified symbol
+// table.
+void SlotCalculator::processTypeSymbolTable(const TypeSymbolTable *ST) {
+ for (TypeSymbolTable::const_iterator TI = ST->begin(), TE = ST->end();
+ TI != TE; ++TI )
+ getOrCreateSlot(TI->second);
+}
+
// processSymbolTable - Insert all of the values in the specified symbol table
// into the values table...
//
-void SlotCalculator::processSymbolTable(const SymbolTable *ST) {
- // Do the types first.
- for (SymbolTable::type_const_iterator TI = ST->type_begin(),
- TE = ST->type_end(); TI != TE; ++TI )
- getOrCreateSlot(TI->second);
-
- // Now do the values.
+void SlotCalculator::processValueSymbolTable(const SymbolTable *ST) {
for (SymbolTable::plane_const_iterator PI = ST->plane_begin(),
PE = ST->plane_end(); PI != PE; ++PI)
for (SymbolTable::value_const_iterator VI = PI->second.begin(),
}
void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
- // Do the types first
- for (SymbolTable::type_const_iterator TI = ST->type_begin(),
- TE = ST->type_end(); TI != TE; ++TI )
- getOrCreateSlot(TI->second);
-
// Now do the constant values in all planes
for (SymbolTable::plane_const_iterator PI = ST->plane_begin(),
PE = ST->plane_end(); PI != PE; ++PI)
// symbol table references to constants not in the output. Scan for these
// constants now.
//
- processSymbolTableConstants(&F->getSymbolTable());
+ processSymbolTableConstants(&F->getValueSymbolTable());
}
SC_DEBUG("Inserting Instructions:\n");
getOrCreateCompactionTableSlot(I->getOperand(op));
}
- // Do the types in the symbol table
- const SymbolTable &ST = F->getSymbolTable();
- for (SymbolTable::type_const_iterator TI = ST.type_begin(),
- TE = ST.type_end(); TI != TE; ++TI)
- getOrCreateCompactionTableSlot(TI->second);
-
// Now do the constants and global values
+ const SymbolTable &ST = F->getValueSymbolTable();
for (SymbolTable::plane_const_iterator PI = ST.plane_begin(),
PE = ST.plane_end(); PI != PE; ++PI)
for (SymbolTable::value_const_iterator VI = PI->second.begin(),
class Module;
class Function;
class SymbolTable;
+class TypeSymbolTable;
class ConstantArray;
class SlotCalculator {
// processSymbolTable - Insert all of the values in the specified symbol table
// into the values table...
//
- void processSymbolTable(const SymbolTable *ST);
+ void processTypeSymbolTable(const TypeSymbolTable *ST);
+ void processValueSymbolTable(const SymbolTable *ST);
void processSymbolTableConstants(const SymbolTable *ST);
void buildCompactionTable(const Function *F);
#include "llvm/Instructions.h"
#include "llvm/Module.h"
#include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/Compressor.h"
#include "llvm/Support/MathExtras.h"
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
outputFunction(I);
- // If needed, output the symbol table for the module...
- outputSymbolTable(M->getSymbolTable());
+ // Output the symbole table for types
+ outputTypeSymbolTable(M->getTypeSymbolTable());
+
+ // Output the symbol table for values
+ outputValueSymbolTable(M->getValueSymbolTable());
}
void BytecodeWriter::outputTypes(unsigned TypeNum) {
outputInstructions(F);
// If needed, output the symbol table for the function...
- outputSymbolTable(F->getSymbolTable());
+ outputValueSymbolTable(F->getValueSymbolTable());
Table.purgeFunction();
}
}
}
-void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
- // Do not output the Bytecode block for an empty symbol table, it just wastes
+void BytecodeWriter::outputTypeSymbolTable(const TypeSymbolTable &TST) {
+ // Do not output the block for an empty symbol table, it just wastes
// space!
- if (MST.isEmpty()) return;
+ if (TST.empty()) return;
- BytecodeBlock SymTabBlock(BytecodeFormat::SymbolTableBlockID, *this,
+ // Create a header for the symbol table
+ BytecodeBlock SymTabBlock(BytecodeFormat::TypeSymbolTableBlockID, *this,
true/*ElideIfEmpty*/);
-
// Write the number of types
- output_vbr(MST.num_types());
+ output_vbr(TST.size());
// Write each of the types
- for (SymbolTable::type_const_iterator TI = MST.type_begin(),
- TE = MST.type_end(); TI != TE; ++TI) {
+ for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end();
+ TI != TE; ++TI) {
// Symtab entry:[def slot #][name]
output_typeid((unsigned)Table.getSlot(TI->second));
output(TI->first);
}
+}
+
+void BytecodeWriter::outputValueSymbolTable(const SymbolTable &MST) {
+ // Do not output the Bytecode block for an empty symbol table, it just wastes
+ // space!
+ if (MST.isEmpty()) return;
+
+ BytecodeBlock SymTabBlock(BytecodeFormat::ValueSymbolTableBlockID, *this,
+ true/*ElideIfEmpty*/);
// Now do each of the type planes in order.
for (SymbolTable::plane_const_iterator PI = MST.plane_begin(),
namespace llvm {
class InlineAsm;
+ class TypeSymbolTable;
class BytecodeWriter {
std::vector<unsigned char> &Out;
unsigned Type) ;
void outputModuleInfoBlock(const Module *C);
- void outputSymbolTable(const SymbolTable &ST);
+ void outputTypeSymbolTable(const TypeSymbolTable &TST);
+ void outputValueSymbolTable(const SymbolTable &ST);
void outputTypes(unsigned StartNo);
void outputConstantsInPlane(const std::vector<const Value*> &Plane,
unsigned StartNo);
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
#include "llvm/Instructions.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/Streams.h"
// false - No errors.
//
static bool ResolveTypes(const Type *DestTy, const Type *SrcTy,
- SymbolTable *DestST, const std::string &Name) {
+ TypeSymbolTable *DestST, const std::string &Name) {
if (DestTy == SrcTy) return false; // If already equal, noop
// Does the type already exist in the module?
// are compatible.
static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
const PATypeHolder &SrcTy,
- SymbolTable *DestST, const std::string &Name,
+ TypeSymbolTable *DestST,
+ const std::string &Name,
std::vector<std::pair<PATypeHolder, PATypeHolder> > &Pointers) {
const Type *SrcTyT = SrcTy.get();
const Type *DestTyT = DestTy.get();
static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
const PATypeHolder &SrcTy,
- SymbolTable *DestST, const std::string &Name){
+ TypeSymbolTable *DestST,
+ const std::string &Name){
std::vector<std::pair<PATypeHolder, PATypeHolder> > PointerTypes;
return RecursiveResolveTypesI(DestTy, SrcTy, DestST, Name, PointerTypes);
}
// types are named in the src module that are not named in the Dst module.
// Make sure there are no type name conflicts.
static bool LinkTypes(Module *Dest, const Module *Src, std::string *Err) {
- SymbolTable *DestST = &Dest->getSymbolTable();
- const SymbolTable *SrcST = &Src->getSymbolTable();
+ TypeSymbolTable *DestST = &Dest->getTypeSymbolTable();
+ const TypeSymbolTable *SrcST = &Src->getTypeSymbolTable();
// Look for a type plane for Type's...
- SymbolTable::type_const_iterator TI = SrcST->type_begin();
- SymbolTable::type_const_iterator TE = SrcST->type_end();
+ TypeSymbolTable::const_iterator TI = SrcST->begin();
+ TypeSymbolTable::const_iterator TE = SrcST->end();
if (TI == TE) return false; // No named types, do nothing.
// Some types cannot be resolved immediately because they depend on other
const Type *RHS = TI->second;
// Check to see if this type name is already in the dest module...
- Type *Entry = DestST->lookupType(Name);
+ Type *Entry = DestST->lookup(Name);
if (ResolveTypes(Entry, RHS, DestST, Name)) {
// They look different, save the types 'till later to resolve.
// Try direct resolution by name...
for (unsigned i = 0; i != DelayedTypesToResolve.size(); ++i) {
const std::string &Name = DelayedTypesToResolve[i];
- Type *T1 = SrcST->lookupType(Name);
- Type *T2 = DestST->lookupType(Name);
+ Type *T1 = SrcST->lookup(Name);
+ Type *T2 = DestST->lookup(Name);
if (!ResolveTypes(T2, T1, DestST, Name)) {
// We are making progress!
DelayedTypesToResolve.erase(DelayedTypesToResolve.begin()+i);
// two types: { int* } and { opaque* }
for (unsigned i = 0, e = DelayedTypesToResolve.size(); i != e; ++i) {
const std::string &Name = DelayedTypesToResolve[i];
- PATypeHolder T1(SrcST->lookupType(Name));
- PATypeHolder T2(DestST->lookupType(Name));
+ PATypeHolder T1(SrcST->lookup(Name));
+ PATypeHolder T2(DestST->lookup(Name));
if (!RecursiveResolveTypes(T2, T1, DestST, Name)) {
// We are making progress!
/// through the trouble to force this back.
static void ForceRenaming(GlobalValue *GV, const std::string &Name) {
assert(GV->getName() != Name && "Can't force rename to self");
- SymbolTable &ST = GV->getParent()->getSymbolTable();
+ SymbolTable &ST = GV->getParent()->getValueSymbolTable();
// If there is a conflict, rename the conflict.
Value *ConflictVal = ST.lookup(GV->getType(), Name);
std::string *Err) {
// We will need a module level symbol table if the src module has a module
// level symbol table...
- SymbolTable *ST = (SymbolTable*)&Dest->getSymbolTable();
+ TypeSymbolTable *TST = &Dest->getTypeSymbolTable();
// Loop over all of the globals in the src module, mapping them over as we go
for (Module::global_iterator I = Src->global_begin(), E = Src->global_end();
DGV = dyn_cast<GlobalVariable>(EGV->second);
if (DGV)
// If types don't agree due to opaque types, try to resolve them.
- RecursiveResolveTypes(SGV->getType(), DGV->getType(),ST, "");
+ RecursiveResolveTypes(SGV->getType(), DGV->getType(), TST, "");
}
if (DGV && DGV->hasInternalLinkage())
//
static bool LinkFunctionProtos(Module *Dest, const Module *Src,
std::map<const Value*, Value*> &ValueMap,
- std::map<std::string, GlobalValue*> &GlobalsByName,
+ std::map<std::string,
+ GlobalValue*> &GlobalsByName,
std::string *Err) {
- SymbolTable *ST = (SymbolTable*)&Dest->getSymbolTable();
+ TypeSymbolTable *TST = &Dest->getTypeSymbolTable();
// Loop over all of the functions in the src module, mapping them over as we
// go
GlobalsByName.find(SF->getName());
if (EF != GlobalsByName.end())
DF = dyn_cast<Function>(EF->second);
- if (DF && RecursiveResolveTypes(SF->getType(), DF->getType(), ST, ""))
+ if (DF && RecursiveResolveTypes(SF->getType(), DF->getType(), TST, ""))
DF = 0; // FIXME: gross.
}
}
#include "llvm/Pass.h"
#include "llvm/PassManager.h"
#include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
#include "llvm/Intrinsics.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/InlineAsm.h"
void lowerIntrinsics(Function &F);
void printModule(Module *M);
- void printModuleTypes(const SymbolTable &ST);
+ void printModuleTypes(const TypeSymbolTable &ST);
void printContainedStructs(const Type *Ty, std::set<const StructType *> &);
void printFloatingPointConstants(Function &F);
void printFunctionSignature(const Function *F, bool Prototype);
// Loop over the module symbol table, removing types from UT that are
// already named, and removing names for types that are not used.
//
- SymbolTable &MST = M.getSymbolTable();
- for (SymbolTable::type_iterator TI = MST.type_begin(), TE = MST.type_end();
+ TypeSymbolTable &TST = M.getTypeSymbolTable();
+ for (TypeSymbolTable::iterator TI = TST.begin(), TE = TST.end();
TI != TE; ) {
- SymbolTable::type_iterator I = TI++;
+ TypeSymbolTable::iterator I = TI++;
// If this is not used, remove it from the symbol table.
std::set<const Type *>::iterator UTI = UT.find(I->second);
if (UTI == UT.end())
- MST.remove(I);
+ TST.remove(I);
else
UT.erase(UTI); // Only keep one name for this type.
}
//
// Loop over the symbol table, emitting all named constants...
- printModuleTypes(M.getSymbolTable());
+ printModuleTypes(M.getTypeSymbolTable());
// Global variable declarations...
if (!M.global_empty()) {
/// printSymbolTable - Run through symbol table looking for type names. If a
/// type name is found, emit its declaration...
///
-void CWriter::printModuleTypes(const SymbolTable &ST) {
+void CWriter::printModuleTypes(const TypeSymbolTable &TST) {
Out << "/* Helper union for bitcasts */\n";
Out << "typedef union {\n";
Out << " unsigned int Int32;\n";
Out << "} llvmBitCastUnion;\n";
// We are only interested in the type plane of the symbol table.
- SymbolTable::type_const_iterator I = ST.type_begin();
- SymbolTable::type_const_iterator End = ST.type_end();
+ TypeSymbolTable::const_iterator I = TST.begin();
+ TypeSymbolTable::const_iterator End = TST.end();
// If there are no type names, exit early.
if (I == End) return;
// Now we can print out typedefs...
Out << "/* Typedefs */\n";
- for (I = ST.type_begin(); I != End; ++I) {
+ for (I = TST.begin(); I != End; ++I) {
const Type *Ty = cast<Type>(I->second);
std::string Name = "l_" + Mang->makeNameProper(I->first);
Out << "typedef ";
// printed in the correct order.
//
Out << "/* Structure contents */\n";
- for (I = ST.type_begin(); I != End; ++I)
+ for (I = TST.begin(); I != End; ++I)
if (const StructType *STy = dyn_cast<StructType>(I->second))
// Only print out used types!
printContainedStructs(STy, StructPrinted);
#include "llvm/Pass.h"
#include "llvm/PassManager.h"
#include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
#include "llvm/Intrinsics.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/InlineAsm.h"
void lowerIntrinsics(Function &F);
void printModule(Module *M);
- void printModuleTypes(const SymbolTable &ST);
+ void printModuleTypes(const TypeSymbolTable &ST);
void printContainedStructs(const Type *Ty, std::set<const StructType *> &);
void printFloatingPointConstants(Function &F);
void printFunctionSignature(const Function *F, bool Prototype);
// Loop over the module symbol table, removing types from UT that are
// already named, and removing names for types that are not used.
//
- SymbolTable &MST = M.getSymbolTable();
- for (SymbolTable::type_iterator TI = MST.type_begin(), TE = MST.type_end();
+ TypeSymbolTable &TST = M.getTypeSymbolTable();
+ for (TypeSymbolTable::iterator TI = TST.begin(), TE = TST.end();
TI != TE; ) {
- SymbolTable::type_iterator I = TI++;
+ TypeSymbolTable::iterator I = TI++;
// If this is not used, remove it from the symbol table.
std::set<const Type *>::iterator UTI = UT.find(I->second);
if (UTI == UT.end())
- MST.remove(I);
+ TST.remove(I);
else
UT.erase(UTI); // Only keep one name for this type.
}
//
// Loop over the symbol table, emitting all named constants...
- printModuleTypes(M.getSymbolTable());
+ printModuleTypes(M.getTypeSymbolTable());
// Global variable declarations...
if (!M.global_empty()) {
/// printSymbolTable - Run through symbol table looking for type names. If a
/// type name is found, emit its declaration...
///
-void CWriter::printModuleTypes(const SymbolTable &ST) {
+void CWriter::printModuleTypes(const TypeSymbolTable &TST) {
Out << "/* Helper union for bitcasts */\n";
Out << "typedef union {\n";
Out << " unsigned int Int32;\n";
Out << "} llvmBitCastUnion;\n";
// We are only interested in the type plane of the symbol table.
- SymbolTable::type_const_iterator I = ST.type_begin();
- SymbolTable::type_const_iterator End = ST.type_end();
+ TypeSymbolTable::const_iterator I = TST.begin();
+ TypeSymbolTable::const_iterator End = TST.end();
// If there are no type names, exit early.
if (I == End) return;
// Now we can print out typedefs...
Out << "/* Typedefs */\n";
- for (I = ST.type_begin(); I != End; ++I) {
+ for (I = TST.begin(); I != End; ++I) {
const Type *Ty = cast<Type>(I->second);
std::string Name = "l_" + Mang->makeNameProper(I->first);
Out << "typedef ";
// printed in the correct order.
//
Out << "/* Structure contents */\n";
- for (I = ST.type_begin(); I != End; ++I)
+ for (I = TST.begin(); I != End; ++I)
if (const StructType *STy = dyn_cast<StructType>(I->second))
// Only print out used types!
printContainedStructs(STy, StructPrinted);
#include "llvm/Transforms/IPO.h"
#include "llvm/Analysis/FindUsedTypes.h"
#include "llvm/Module.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
#include "llvm/DerivedTypes.h"
#include "llvm/ADT/Statistic.h"
using namespace llvm;
bool DTE::runOnModule(Module &M) {
bool Changed = false;
- SymbolTable &ST = M.getSymbolTable();
+ TypeSymbolTable &ST = M.getTypeSymbolTable();
std::set<const Type *> UsedTypes = getAnalysis<FindUsedTypes>().getTypes();
// Check the symbol table for superfluous type entries...
//
// Grab the 'type' plane of the module symbol...
- SymbolTable::type_iterator TI = ST.type_begin();
- while ( TI != ST.type_end() ) {
+ TypeSymbolTable::iterator TI = ST.begin();
+ TypeSymbolTable::iterator TE = ST.end();
+ while ( TI != TE ) {
// If this entry should be unconditionally removed, or if we detect that
// the type is not used, remove it.
const Type *RHS = TI->second;
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
using namespace llvm;
namespace {
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
if (I->hasInternalLinkage())
I->setName(""); // Internal symbols can't participate in linkage
- I->getSymbolTable().strip();
+ I->getValueSymbolTable().strip();
}
// Remove all names from types.
- SymbolTable &SymTab = M.getSymbolTable();
- while (SymTab.type_begin() != SymTab.type_end())
- SymTab.remove(SymTab.type_begin());
+ M.getTypeSymbolTable().strip();
}
// Strip debug info in the module if it exists. To do this, we remove
#include "llvm/Module.h"
#include "llvm/DerivedTypes.h"
#include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
#include "llvm/Constant.h"
#include "ValueMapper.h"
using namespace llvm;
New->setModuleInlineAsm(M->getModuleInlineAsm());
// Copy all of the type symbol table entries over.
- const SymbolTable &SymTab = M->getSymbolTable();
- SymbolTable::type_const_iterator TypeI = SymTab.type_begin();
- SymbolTable::type_const_iterator TypeE = SymTab.type_end();
- for (; TypeI != TypeE; ++TypeI)
- New->addTypeName(TypeI->first, TypeI->second);
+ const TypeSymbolTable &TST = M->getTypeSymbolTable();
+ for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end();
+ TI != TE; ++TI)
+ New->addTypeName(TI->first, TI->second);
// Copy all of the dependent libraries over.
for (Module::lib_iterator I = M->lib_begin(), E = M->lib_end(); I != E; ++I)
#include "llvm/Instructions.h"
#include "llvm/Module.h"
#include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CFG.h"
static void fillTypeNameTable(const Module *M,
std::map<const Type *, std::string> &TypeNames) {
if (!M) return;
- const SymbolTable &ST = M->getSymbolTable();
- SymbolTable::type_const_iterator TI = ST.type_begin();
- for (; TI != ST.type_end(); ++TI) {
+ const TypeSymbolTable &ST = M->getTypeSymbolTable();
+ TypeSymbolTable::const_iterator TI = ST.begin();
+ for (; TI != ST.end(); ++TI) {
// As a heuristic, don't insert pointer to primitive types, because
// they are used too often to have a single useful name.
//
private:
void printModule(const Module *M);
- void printSymbolTable(const SymbolTable &ST);
+ void printTypeSymbolTable(const TypeSymbolTable &ST);
+ void printValueSymbolTable(const SymbolTable &ST);
void printConstant(const Constant *CPV);
void printGlobal(const GlobalVariable *GV);
void printFunction(const Function *F);
}
// Loop over the symbol table, emitting all named constants.
- printSymbolTable(M->getSymbolTable());
+ printTypeSymbolTable(M->getTypeSymbolTable());
+ printValueSymbolTable(M->getValueSymbolTable());
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I)
Out << "\n";
}
-
-// printSymbolTable - Run through symbol table looking for constants
-// and types. Emit their declarations.
-void AssemblyWriter::printSymbolTable(const SymbolTable &ST) {
-
+void AssemblyWriter::printTypeSymbolTable(const TypeSymbolTable &ST) {
// Print the types.
- for (SymbolTable::type_const_iterator TI = ST.type_begin();
- TI != ST.type_end(); ++TI) {
+ for (TypeSymbolTable::const_iterator TI = ST.begin(), TE = ST.end();
+ TI != TE; ++TI) {
Out << "\t" << getLLVMName(TI->first) << " = type ";
// Make sure we print out at least one level of the type structure, so
//
printTypeAtLeastOneLevel(TI->second) << "\n";
}
+}
+
+// printSymbolTable - Run through symbol table looking for constants
+// and types. Emit their declarations.
+void AssemblyWriter::printValueSymbolTable(const SymbolTable &ST) {
// Print the constants, in type plane order.
for (SymbolTable::plane_const_iterator PI = ST.plane_begin();
/// required before printing out to a textual form, to ensure that there is no
/// ambiguity when parsing.
void Function::renameLocalSymbols() {
- SymbolTable &LST = getSymbolTable(); // Local Symtab
- SymbolTable &GST = getParent()->getSymbolTable(); // Global Symtab
+ SymbolTable &LST = getValueSymbolTable(); // Local Symtab
+ SymbolTable &GST = getParent()->getValueSymbolTable(); // Global Symtab
for (SymbolTable::plane_iterator LPI = LST.plane_begin(), E = LST.plane_end();
LPI != E; ++LPI)
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/LeakDetector.h"
#include "SymbolTableListTraitsImpl.h"
+#include "llvm/TypeSymbolTable.h"
#include <algorithm>
#include <cstdarg>
#include <cstdlib>
FunctionList.setParent(this);
GlobalList.setItemParent(this);
GlobalList.setParent(this);
- SymTab = new SymbolTable();
+ ValSymTab = new SymbolTable();
+ TypeSymTab = new TypeSymbolTable();
}
Module::~Module() {
FunctionList.clear();
FunctionList.setParent(0);
LibraryList.clear();
- delete SymTab;
+ delete ValSymTab;
+ delete TypeSymTab;
}
// Module::dump() - Allow printing from debugger
//
Function *Module::getOrInsertFunction(const std::string &Name,
const FunctionType *Ty) {
- SymbolTable &SymTab = getSymbolTable();
+ SymbolTable &SymTab = getValueSymbolTable();
// See if we have a definitions for the specified function already...
if (Value *V = SymTab.lookup(PointerType::get(Ty), Name)) {
// If it does not exist, return null.
//
Function *Module::getFunction(const std::string &Name, const FunctionType *Ty) {
- SymbolTable &SymTab = getSymbolTable();
+ SymbolTable &SymTab = getValueSymbolTable();
return cast_or_null<Function>(SymTab.lookup(PointerType::get(Ty), Name));
}
///
GlobalVariable *Module::getGlobalVariable(const std::string &Name,
const Type *Ty, bool AllowInternal) {
- if (Value *V = getSymbolTable().lookup(PointerType::get(Ty), Name)) {
+ if (Value *V = getValueSymbolTable().lookup(PointerType::get(Ty), Name)) {
GlobalVariable *Result = cast<GlobalVariable>(V);
if (AllowInternal || !Result->hasInternalLinkage())
return Result;
// table is not modified.
//
bool Module::addTypeName(const std::string &Name, const Type *Ty) {
- SymbolTable &ST = getSymbolTable();
+ TypeSymbolTable &ST = getTypeSymbolTable();
- if (ST.lookupType(Name)) return true; // Already in symtab...
+ if (ST.lookup(Name)) return true; // Already in symtab...
// Not in symbol table? Set the name with the Symtab as an argument so the
// type knows what to update...
/// getTypeByName - Return the type with the specified name in this module, or
/// null if there is none by that name.
const Type *Module::getTypeByName(const std::string &Name) const {
- const SymbolTable &ST = getSymbolTable();
- return cast_or_null<Type>(ST.lookupType(Name));
+ const TypeSymbolTable &ST = getTypeSymbolTable();
+ return cast_or_null<Type>(ST.lookup(Name));
}
// getTypeName - If there is at least one entry in the symbol table for the
// specified type, return it.
//
std::string Module::getTypeName(const Type *Ty) const {
- const SymbolTable &ST = getSymbolTable();
+ const TypeSymbolTable &ST = getTypeSymbolTable();
- SymbolTable::type_const_iterator TI = ST.type_begin();
- SymbolTable::type_const_iterator TE = ST.type_end();
+ TypeSymbolTable::const_iterator TI = ST.begin();
+ TypeSymbolTable::const_iterator TE = ST.end();
if ( TI == TE ) return ""; // No names for types
while (TI != TE && TI->second != Ty)
#define DEBUG_ABSTYPE 0
SymbolTable::~SymbolTable() {
- // Drop all abstract type references in the type plane...
- for (type_iterator TI = tmap.begin(), TE = tmap.end(); TI != TE; ++TI) {
- if (TI->second->isAbstract()) // If abstract, drop the reference...
- cast<DerivedType>(TI->second)->removeAbstractTypeUser(this);
- }
-
// TODO: FIXME: BIG ONE: This doesn't unreference abstract types for the
// planes that could still have entries!
}
-// lookup a type by name - returns null on failure
-Type* SymbolTable::lookupType(const std::string& Name) const {
- type_const_iterator TI = tmap.find(Name);
- if (TI != tmap.end())
- return const_cast<Type*>(TI->second);
- return 0;
-}
-
/// 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
}
}
-// remove - Remove a type from the symbol table...
-Type* SymbolTable::remove(type_iterator Entry) {
- assert(Entry != tmap.end() && "Invalid entry to remove!");
-
- const Type* Result = Entry->second;
-
-#if DEBUG_SYMBOL_TABLE
- dump();
- DOUT << " Removing type: " << Entry->first << "\n";
-#endif
-
- tmap.erase(Entry);
-
- // If we are removing an abstract type, remove the symbol table from it's use
- // list...
- if (Result->isAbstract()) {
-#if DEBUG_ABSTYPE
- DOUT << "Removing abstract type from symtab"
- << Result->getDescription() << "\n";
-#endif
- cast<DerivedType>(Result)->removeAbstractTypeUser(this);
- }
-
- return const_cast<Type*>(Result);
-}
-
// insertEntry - Insert a value into the symbol table with the specified name.
void SymbolTable::insertEntry(const std::string &Name, const Type *VTy,
}
-// insertEntry - Insert a type into the symbol table with the specified
-// name...
-//
-void SymbolTable::insert(const std::string& Name, const Type* T) {
- assert(T && "Can't insert null type into symbol table!");
-
- // Check to see if there is a naming conflict. If so, rename this type!
- std::string UniqueName = Name;
- if (lookupType(Name))
- UniqueName = getUniqueName(T, Name);
-
-#if DEBUG_SYMBOL_TABLE
- dump();
- DOUT << " Inserting type: " << UniqueName << ": "
- << T->getDescription() << "\n";
-#endif
-
- // Insert the tmap entry
- tmap.insert(make_pair(UniqueName, T));
-
- // If we are adding an abstract type, add the symbol table to it's use list.
- if (T->isAbstract()) {
- cast<DerivedType>(T)->addAbstractTypeUser(this);
-#if DEBUG_ABSTYPE
- DOUT << "Added abstract type to ST: " << T->getDescription() << "\n";
-#endif
- }
-}
// Strip the symbol table of its names.
bool SymbolTable::strip() {
}
}
- for (type_iterator TI = tmap.begin(); TI != tmap.end(); ) {
- remove(TI++);
- RemovedSymbol = true;
- }
-
return RemovedSymbol;
}
// Remove the plane that is no longer used
pmap.erase(PI);
}
-
- // Loop over all of the types in the symbol table, replacing any references
- // to OldType with references to NewType. Note that there may be multiple
- // occurrences, and although we only need to remove one at a time, it's
- // faster to remove them all in one pass.
- //
- for (type_iterator I = type_begin(), E = type_end(); I != E; ++I) {
- if (I->second == (Type*)OldType) { // FIXME when Types aren't const.
-#if DEBUG_ABSTYPE
- DOUT << "Removing type " << OldType->getDescription() << "\n";
-#endif
- OldType->removeAbstractTypeUser(this);
-
- I->second = (Type*)NewType; // TODO FIXME when types aren't const
- if (NewType->isAbstract()) {
-#if DEBUG_ABSTYPE
- DOUT << "Added type " << NewType->getDescription() << "\n";
-#endif
- cast<DerivedType>(NewType)->addAbstractTypeUser(this);
- }
- }
- }
}
// plane is a use of the abstract type which must be dropped.
if (PI != pmap.end())
AbsTy->removeAbstractTypeUser(this);
-
- // Loop over all of the types in the symbol table, dropping any abstract
- // type user entries for AbsTy which occur because there are names for the
- // type.
- for (type_iterator TI = type_begin(), TE = type_end(); TI != TE; ++TI)
- if (TI->second == (Type*)AbsTy) // FIXME when Types aren't const.
- AbsTy->removeAbstractTypeUser(this);
}
static void DumpVal(const std::pair<const std::string, Value *> &V) {
for_each(P.second.begin(), P.second.end(), DumpVal);
}
-static void DumpTypes(const std::pair<const std::string, const Type*>& T ) {
- DOUT << " '" << T.first << "' = ";
- T.second->dump();
- DOUT << "\n";
-}
-
void SymbolTable::dump() const {
DOUT << "Symbol table dump:\n Plane:";
for_each(pmap.begin(), pmap.end(), DumpPlane);
- DOUT << " Types: ";
- for_each(tmap.begin(), tmap.end(), DumpTypes);
}
// vim: sw=2 ai
// Remove all of the items from the old symtab..
if (SymTabObject && !List.empty()) {
- SymbolTable &SymTab = SymTabObject->getSymbolTable();
+ SymbolTable &SymTab = SymTabObject->getValueSymbolTable();
for (typename iplist<ValueSubClass>::iterator I = List.begin();
I != List.end(); ++I)
if (I->hasName()) SymTab.remove(I);
// Add all of the items to the new symtab...
if (SymTabObject && !List.empty()) {
- SymbolTable &SymTab = SymTabObject->getSymbolTable();
+ SymbolTable &SymTab = SymTabObject->getValueSymbolTable();
for (typename iplist<ValueSubClass>::iterator I = List.begin();
I != List.end(); ++I)
if (I->hasName()) SymTab.insert(I);
assert(V->getParent() == 0 && "Value already in a container!!");
V->setParent(ItemParent);
if (V->hasName() && SymTabObject)
- SymTabObject->getSymbolTable().insert(V);
+ SymTabObject->getValueSymbolTable().insert(V);
}
template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
::removeNodeFromList(ValueSubClass *V) {
V->setParent(0);
if (V->hasName() && SymTabObject)
- SymTabObject->getSymbolTable().remove(V);
+ SymTabObject->getValueSymbolTable().remove(V);
}
template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
ValueSubClass &V = *first;
bool HasName = V.hasName();
if (OldSTO && HasName)
- OldSTO->getSymbolTable().remove(&V);
+ OldSTO->getValueSymbolTable().remove(&V);
V.setParent(NewIP);
if (NewSTO && HasName)
- NewSTO->getSymbolTable().insert(&V);
+ NewSTO->getValueSymbolTable().insert(&V);
}
} else {
// Just transferring between blocks in the same function, simply update the
}
// Erase a specific type from the symbol table
-bool TypeSymbolTable::erase(Type *N) {
+bool TypeSymbolTable::remove(Type *N) {
for (iterator TI = tmap.begin(), TE = tmap.end(); TI != TE; ++TI) {
if (TI->second == N) {
- this->erase(TI);
+ this->remove(TI);
return true;
}
}
}
// remove - Remove a type from the symbol table...
-Type* TypeSymbolTable::erase(iterator Entry) {
+Type* TypeSymbolTable::remove(iterator Entry) {
assert(Entry != tmap.end() && "Invalid entry to remove!");
const Type* Result = Entry->second;
bool TypeSymbolTable::strip() {
bool RemovedSymbol = false;
for (iterator TI = tmap.begin(); TI != tmap.end(); ) {
- erase(TI++);
+ remove(TI++);
RemovedSymbol = true;
}
if (Instruction *I = dyn_cast<Instruction>(this)) {
if (BasicBlock *P = I->getParent())
if (Function *PP = P->getParent())
- ST = &PP->getSymbolTable();
+ ST = &PP->getValueSymbolTable();
} else if (BasicBlock *BB = dyn_cast<BasicBlock>(this)) {
- if (Function *P = BB->getParent()) ST = &P->getSymbolTable();
+ if (Function *P = BB->getParent()) ST = &P->getValueSymbolTable();
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(this)) {
- if (Module *P = GV->getParent()) ST = &P->getSymbolTable();
+ if (Module *P = GV->getParent()) ST = &P->getValueSymbolTable();
} else if (Argument *A = dyn_cast<Argument>(this)) {
- if (Function *P = A->getParent()) ST = &P->getSymbolTable();
+ if (Function *P = A->getParent()) ST = &P->getValueSymbolTable();
} else {
assert(isa<Constant>(this) && "Unknown value type!");
return; // no name is setable for this.
bool doInitialization(Module &M) {
Mod = &M;
- verifySymbolTable(M.getSymbolTable());
+ verifyTypeSymbolTable(M.getTypeSymbolTable());
+ verifyValueSymbolTable(M.getValueSymbolTable());
// If this is a real pass, in a pass manager, we must abort before
// returning back to the pass manager, or else the pass manager may try to
// Verification methods...
- void verifySymbolTable(SymbolTable &ST);
+ void verifyTypeSymbolTable(TypeSymbolTable &ST);
+ void verifyValueSymbolTable(SymbolTable &ST);
void visitGlobalValue(GlobalValue &GV);
void visitGlobalVariable(GlobalVariable &GV);
void visitFunction(Function &F);
visitGlobalValue(GV);
}
+void Verifier::verifyTypeSymbolTable(TypeSymbolTable &ST) {
+}
// verifySymbolTable - Verify that a function or module symbol table is ok
//
-void Verifier::verifySymbolTable(SymbolTable &ST) {
+void Verifier::verifyValueSymbolTable(SymbolTable &ST) {
// Loop over all of the values in all type planes in the symbol table.
for (SymbolTable::plane_const_iterator PI = ST.plane_begin(),
Assert1(F.getName().substr(0, 5) != "llvm.",
"llvm intrinsics cannot be defined!", &F);
- verifySymbolTable(F.getSymbolTable());
+ verifyValueSymbolTable(F.getValueSymbolTable());
// Check the entry node
BasicBlock *Entry = &F.getEntryBlock();
// module, and that they don't include any deleted blocks.
BBs.clear();
for (unsigned i = 0, e = BlockInfo.size(); i != e; ++i) {
- SymbolTable &ST = BlockInfo[i].first->getSymbolTable();
+ SymbolTable &ST = BlockInfo[i].first->getValueSymbolTable();
SymbolTable::plane_iterator PI = ST.find(Type::LabelTy);
if (PI != ST.plane_end() && PI->second.count(BlockInfo[i].second))
BBs.push_back(cast<BasicBlock>(PI->second[BlockInfo[i].second]));
#include "llvm/Instructions.h"
#include "llvm/Module.h"
#include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CommandLine.h"
// Mode::getTypeName function which will return an empty string, not a null
// pointer if the name is not found.
inline const std::string*
-findTypeName(const SymbolTable& ST, const Type* Ty)
+findTypeName(const TypeSymbolTable& ST, const Type* Ty)
{
- SymbolTable::type_const_iterator TI = ST.type_begin();
- SymbolTable::type_const_iterator TE = ST.type_end();
+ TypeSymbolTable::const_iterator TI = ST.begin();
+ TypeSymbolTable::const_iterator TE = ST.end();
for (;TI != TE; ++TI)
if (TI->second == Ty)
return &(TI->first);
}
// See if the type has a name in the symboltable and build accordingly
- const std::string* tName = findTypeName(TheModule->getSymbolTable(), Ty);
+ const std::string* tName = findTypeName(TheModule->getTypeSymbolTable(), Ty);
std::string name;
if (tName)
name = std::string(prefix) + *tName;
// If the type had a name, make sure we recreate it.
const std::string* progTypeName =
- findTypeName(TheModule->getSymbolTable(),Ty);
+ findTypeName(TheModule->getTypeSymbolTable(),Ty);
if (progTypeName)
Out << "mod->addTypeName(\"" << *progTypeName << "\", "
<< typeName << ");";
CppWriter::printTypes(const Module* M) {
// Walk the symbol table and print out all its types
- const SymbolTable& symtab = M->getSymbolTable();
- for (SymbolTable::type_const_iterator TI = symtab.type_begin(),
- TE = symtab.type_end(); TI != TE; ++TI) {
+ const TypeSymbolTable& symtab = M->getTypeSymbolTable();
+ for (TypeSymbolTable::const_iterator TI = symtab.begin(), TE = symtab.end();
+ TI != TE; ++TI) {
// For primitive types and types already defined, just add a name
TypeMap::const_iterator TNI = TypeNames.find(TI->second);