diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index 222fc82d197..dd133c9cbf9 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -219,19 +219,18 @@ bool CBackendNameAllUsedStructs::run(Module &M) { // already named, and removing names for structure types that are not used. // SymbolTable &MST = M.getSymbolTable(); - if (MST.find(Type::TypeTy) != MST.end()) - for (SymbolTable::type_iterator I = MST.type_begin(Type::TypeTy), - E = MST.type_end(Type::TypeTy); I != E; ) { - SymbolTable::type_iterator It = I++; - if (StructType *STy = dyn_cast(It->second)) { - // If this is not used, remove it from the symbol table. - std::set::iterator UTI = UT.find(STy); - if (UTI == UT.end()) - MST.remove(It->first, It->second); - else - UT.erase(UTI); - } + for (SymbolTable::type_iterator TI = MST.type_begin(), TE = MST.type_end(); + TI != TE; ) { + SymbolTable::type_iterator I = TI++; + if (StructType *STy = dyn_cast(I->second)) { + // If this is not used, remove it from the symbol table. + std::set::iterator UTI = UT.find(STy); + if (UTI == UT.end()) + MST.remove(I->first, I->second); + else + UT.erase(UTI); } + } // UT now contains types that are not named. Loop over it, naming // structure types. @@ -291,7 +290,7 @@ std::ostream &CWriter::printType(std::ostream &Out, const Type *Ty, } if (MTy->isVarArg()) { if (MTy->getNumParams()) - FunctionInnards << ", ..."; + FunctionInnards << ", ..."; } else if (!MTy->getNumParams()) { FunctionInnards << "void"; } @@ -865,12 +864,12 @@ void CWriter::printFloatingPointConstants(Function &F) { /// void CWriter::printModuleTypes(const SymbolTable &ST) { // If there are no type names, exit early. - if (ST.find(Type::TypeTy) == ST.end()) + if ( ! ST.hasTypes() ) return; // We are only interested in the type plane of the symbol table... - SymbolTable::type_const_iterator I = ST.type_begin(Type::TypeTy); - SymbolTable::type_const_iterator End = ST.type_end(Type::TypeTy); + SymbolTable::type_const_iterator I = ST.type_begin(); + SymbolTable::type_const_iterator End = ST.type_end(); // Print out forward declarations for structure types before anything else! Out << "/* Structure forward decls */\n"; @@ -885,7 +884,7 @@ void CWriter::printModuleTypes(const SymbolTable &ST) { // Now we can print out typedefs... Out << "/* Typedefs */\n"; - for (I = ST.type_begin(Type::TypeTy); I != End; ++I) { + for (I = ST.type_begin(); I != End; ++I) { const Type *Ty = cast(I->second); std::string Name = "l_" + Mangler::makeNameProper(I->first); Out << "typedef "; @@ -902,7 +901,7 @@ void CWriter::printModuleTypes(const SymbolTable &ST) { // printed in the correct order. // Out << "/* Structure contents */\n"; - for (I = ST.type_begin(Type::TypeTy); I != End; ++I) + for (I = ST.type_begin(); I != End; ++I) if (const StructType *STy = dyn_cast(I->second)) // Only print out used types! printContainedStructs(STy, StructPrinted); @@ -969,7 +968,7 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) { } else { // Loop over the arguments, printing them... for (FunctionType::param_iterator I = FT->param_begin(), - E = FT->param_end(); I != E; ++I) { + E = FT->param_end(); I != E; ++I) { if (I != FT->param_begin()) FunctionInnards << ", "; printType(FunctionInnards, *I); } @@ -1510,3 +1509,5 @@ TargetMachine *llvm::allocateCTargetMachine(const Module &M, IntrinsicLowering *IL) { return new CTargetMachine(M, IL); } + +// vim: sw=2 diff --git a/lib/Transforms/IPO/DeadTypeElimination.cpp b/lib/Transforms/IPO/DeadTypeElimination.cpp index c3a9f6edc5b..28e5dca9f0b 100644 --- a/lib/Transforms/IPO/DeadTypeElimination.cpp +++ b/lib/Transforms/IPO/DeadTypeElimination.cpp @@ -74,25 +74,24 @@ bool DTE::run(Module &M) { // Check the symbol table for superfluous type entries... // // Grab the 'type' plane of the module symbol... - SymbolTable::iterator STI = ST.find(Type::TypeTy); - if (STI != ST.end()) { - // Loop over all entries in the type plane... - SymbolTable::VarMap &Plane = STI->second; - for (SymbolTable::VarMap::iterator PI = Plane.begin(); PI != Plane.end();) { - // If this entry should be unconditionally removed, or if we detect that - // the type is not used, remove it. - const Type *RHS = cast(PI->second); - if (ShouldNukeSymtabEntry(RHS) || !UsedTypes.count(RHS)) { - Plane.erase(PI++); - ++NumKilled; - Changed = true; - } else { - ++PI; - // We only need to leave one name for each type. - UsedTypes.erase(RHS); - } + SymbolTable::type_iterator TI = ST.type_begin(); + while ( TI != ST.type_end() ) { + // If this entry should be unconditionally removed, or if we detect that + // the type is not used, remove it. + const Type *RHS = TI->second; + if (ShouldNukeSymtabEntry(RHS) || !UsedTypes.count(RHS)) { + SymbolTable::type_iterator ToRemove = TI++; + ST.remove(TI->second); + ++NumKilled; + Changed = true; + } else { + ++TI; + // We only need to leave one name for each type. + UsedTypes.erase(RHS); } } return Changed; } + +// vim: sw=2 diff --git a/lib/Transforms/IPO/MutateStructTypes.cpp b/lib/Transforms/IPO/MutateStructTypes.cpp index ad18bae42a5..38f9445218c 100644 --- a/lib/Transforms/IPO/MutateStructTypes.cpp +++ b/lib/Transforms/IPO/MutateStructTypes.cpp @@ -269,16 +269,13 @@ void MutateStructTypes::processGlobals(Module &M) { // Remap the symbol table to refer to the types in a nice way // SymbolTable &ST = M.getSymbolTable(); - SymbolTable::iterator I = ST.find(Type::TypeTy); - if (I != ST.end()) { // Get the type plane for Type's - SymbolTable::VarMap &Plane = I->second; - for (SymbolTable::type_iterator TI = Plane.begin(), TE = Plane.end(); - TI != TE; ++TI) { - // FIXME: This is gross, I'm reaching right into a symbol table and - // mucking around with it's internals... but oh well. - // - TI->second = (Value*)cast(ConvertType(cast(TI->second))); - } + SymbolTable::type_iterator TI = ST.type_begin(); + SymbolTable::type_iterator TE = ST.type_end(); + for ( ; TI != TE; ++TI ) { + // FIXME: This is gross, I'm reaching right into a symbol table and + // mucking around with it's internals... but oh well. + // + TI->second = const_cast(ConvertType(TI->second)); } } @@ -495,3 +492,4 @@ bool MutateStructTypes::run(Module &M) { return true; } +// vim: sw=2 diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp index f8ee99b3069..d98848aa7c2 100644 --- a/lib/Transforms/Utils/CloneModule.cpp +++ b/lib/Transforms/Utils/CloneModule.cpp @@ -33,11 +33,11 @@ Module *llvm::CloneModule(const Module *M) { // Copy all of the type symbol table entries over... const SymbolTable &SymTab = M->getSymbolTable(); - SymbolTable::const_iterator TypeI = SymTab.find(Type::TypeTy); - if (TypeI != SymTab.end()) - for (SymbolTable::VarMap::const_iterator I = TypeI->second.begin(), - E = TypeI->second.end(); I != E; ++I) - New->addTypeName(I->first, cast(I->second)); + 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); + } // Create the value map that maps things from the old module over to the new // module. @@ -89,3 +89,5 @@ Module *llvm::CloneModule(const Module *M) { return New; } + +// vim: sw=2 diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 533274a6d83..bb30570395a 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -105,19 +105,16 @@ static void fillTypeNameTable(const Module *M, std::map &TypeNames) { if (!M) return; const SymbolTable &ST = M->getSymbolTable(); - SymbolTable::const_iterator PI = ST.find(Type::TypeTy); - if (PI != ST.end()) { - SymbolTable::type_const_iterator I = PI->second.begin(); - for (; I != PI->second.end(); ++I) { - // As a heuristic, don't insert pointer to primitive types, because - // they are used too often to have a single useful name. - // - const Type *Ty = cast(I->second); - if (!isa(Ty) || - !cast(Ty)->getElementType()->isPrimitiveType() || - isa(cast(Ty)->getElementType())) - TypeNames.insert(std::make_pair(Ty, getLLVMName(I->first))); - } + SymbolTable::type_const_iterator TI = ST.type_begin(); + for (; TI != ST.type_end(); ++TI ) { + // As a heuristic, don't insert pointer to primitive types, because + // they are used too often to have a single useful name. + // + const Type *Ty = cast(TI->second); + if (!isa(Ty) || + !cast(Ty)->getElementType()->isPrimitiveType() || + isa(cast(Ty)->getElementType())) + TypeNames.insert(std::make_pair(Ty, getLLVMName(TI->first))); } } @@ -605,26 +602,31 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) { } -/// printSymbolTable - Run through symbol table looking for named constants -/// if a named constant is found, emit it's declaration... -/// +// printSymbolTable - Run through symbol table looking for constants +// and types. Emit their declarations. void AssemblyWriter::printSymbolTable(const SymbolTable &ST) { - for (SymbolTable::const_iterator TI = ST.begin(); TI != ST.end(); ++TI) { - SymbolTable::type_const_iterator I = ST.type_begin(TI->first); - SymbolTable::type_const_iterator End = ST.type_end(TI->first); + + // Print the types. + for (SymbolTable::type_const_iterator TI = ST.type_begin(); + TI != ST.type_end(); ++TI ) { + *Out << "\t" << getLLVMName(TI->first) << " = type "; + + // Make sure we print out at least one level of the type structure, so + // that we do not get %FILE = type %FILE + // + printTypeAtLeastOneLevel(TI->second) << "\n"; + } - for (; I != End; ++I) { - const Value *V = I->second; + // Print the constants, in type plane order. + for (SymbolTable::plane_const_iterator PI = ST.plane_begin(); + PI != ST.plane_end(); ++PI ) { + SymbolTable::value_const_iterator VI = ST.value_begin(PI->first); + SymbolTable::value_const_iterator VE = ST.value_end(PI->first); + + for (; VI != VE; ++VI) { + const Value *V = VI->second; if (const Constant *CPV = dyn_cast(V)) { printConstant(CPV); - } else if (const Type *Ty = dyn_cast(V)) { - assert(Ty->getType() == Type::TypeTy && TI->first == Type::TypeTy); - *Out << "\t" << getLLVMName(I->first) << " = type "; - - // Make sure we print out at least one level of the type structure, so - // that we do not get %FILE = type %FILE - // - printTypeAtLeastOneLevel(Ty) << "\n"; } } } @@ -1014,6 +1016,7 @@ void Argument::print(std::ostream &o) const { } void Value::dump() const { print(std::cerr); } +void Type::dump() const { print(std::cerr); } //===----------------------------------------------------------------------===// // CachedWriter Class Implementation @@ -1062,3 +1065,5 @@ void CachedWriter::setStream(std::ostream &os) { Out = &os; if (AW) AW->setStream(os); } + +// vim: sw=2 diff --git a/lib/VMCore/SlotCalculator.cpp b/lib/VMCore/SlotCalculator.cpp index 35490532795..ec5a837cf90 100644 --- a/lib/VMCore/SlotCalculator.cpp +++ b/lib/VMCore/SlotCalculator.cpp @@ -248,18 +248,32 @@ void SlotCalculator::processModule() { // into the values table... // void SlotCalculator::processSymbolTable(const SymbolTable *ST) { - for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I) - for (SymbolTable::type_const_iterator TI = I->second.begin(), - TE = I->second.end(); TI != TE; ++TI) - getOrCreateSlot(TI->second); + // 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. + 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(), + VE = PI->second.end(); VI != VE; ++VI) + getOrCreateSlot(VI->second); } void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) { - for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I) - for (SymbolTable::type_const_iterator TI = I->second.begin(), - TE = I->second.end(); TI != TE; ++TI) - if (isa(TI->second) || isa(TI->second)) - getOrCreateSlot(TI->second); + // 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) + for (SymbolTable::value_const_iterator VI = PI->second.begin(), + VE = PI->second.end(); VI != VE; ++VI) + if (isa(VI->second)) + getOrCreateSlot(VI->second); } @@ -452,13 +466,19 @@ void SlotCalculator::buildCompactionTable(const Function *F) { getOrCreateCompactionTableSlot(VAN->getArgType()); } + // Do the types in the symbol table const SymbolTable &ST = F->getSymbolTable(); - for (SymbolTable::const_iterator I = ST.begin(), E = ST.end(); I != E; ++I) - for (SymbolTable::type_const_iterator TI = I->second.begin(), - TE = I->second.end(); TI != TE; ++TI) - if (isa(TI->second) || isa(TI->second) || - isa(TI->second)) - getOrCreateCompactionTableSlot(TI->second); + 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 + 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(), + VE = PI->second.end(); VI != VE; ++VI) + if (isa(VI->second) || isa(VI->second)) + getOrCreateCompactionTableSlot(VI->second); // Now that we have all of the values in the table, and know what types are // referenced, make sure that there is at least the zero initializer in any diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp index 2be8cd0244b..90e2edcfdaa 100644 --- a/tools/bugpoint/CrashDebugger.cpp +++ b/tools/bugpoint/CrashDebugger.cpp @@ -245,9 +245,9 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector &BBs) { BBs.clear(); for (unsigned i = 0, e = BlockInfo.size(); i != e; ++i) { SymbolTable &ST = BlockInfo[i].first->getSymbolTable(); - SymbolTable::iterator I = ST.find(Type::LabelTy); - if (I != ST.end() && I->second.count(BlockInfo[i].second)) - BBs.push_back(cast(I->second[BlockInfo[i].second])); + SymbolTable::plane_iterator PI = ST.find(Type::LabelTy); + if (PI != ST.plane_end() && PI->second.count(BlockInfo[i].second)) + BBs.push_back(cast(PI->second[BlockInfo[i].second])); } return true; }