mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
Convert to SymbolTable's new iteration interface.
llvm-svn: 13754
This commit is contained in:
parent
e6cf613d2a
commit
fec48b0d9d
@ -219,19 +219,18 @@ bool CBackendNameAllUsedStructs::run(Module &M) {
|
|||||||
// already named, and removing names for structure types that are not used.
|
// already named, and removing names for structure types that are not used.
|
||||||
//
|
//
|
||||||
SymbolTable &MST = M.getSymbolTable();
|
SymbolTable &MST = M.getSymbolTable();
|
||||||
if (MST.find(Type::TypeTy) != MST.end())
|
for (SymbolTable::type_iterator TI = MST.type_begin(), TE = MST.type_end();
|
||||||
for (SymbolTable::type_iterator I = MST.type_begin(Type::TypeTy),
|
TI != TE; ) {
|
||||||
E = MST.type_end(Type::TypeTy); I != E; ) {
|
SymbolTable::type_iterator I = TI++;
|
||||||
SymbolTable::type_iterator It = I++;
|
if (StructType *STy = dyn_cast<StructType>(I->second)) {
|
||||||
if (StructType *STy = dyn_cast<StructType>(It->second)) {
|
// If this is not used, remove it from the symbol table.
|
||||||
// If this is not used, remove it from the symbol table.
|
std::set<const Type *>::iterator UTI = UT.find(STy);
|
||||||
std::set<const Type *>::iterator UTI = UT.find(STy);
|
if (UTI == UT.end())
|
||||||
if (UTI == UT.end())
|
MST.remove(I->first, I->second);
|
||||||
MST.remove(It->first, It->second);
|
else
|
||||||
else
|
UT.erase(UTI);
|
||||||
UT.erase(UTI);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// UT now contains types that are not named. Loop over it, naming
|
// UT now contains types that are not named. Loop over it, naming
|
||||||
// structure types.
|
// structure types.
|
||||||
@ -291,7 +290,7 @@ std::ostream &CWriter::printType(std::ostream &Out, const Type *Ty,
|
|||||||
}
|
}
|
||||||
if (MTy->isVarArg()) {
|
if (MTy->isVarArg()) {
|
||||||
if (MTy->getNumParams())
|
if (MTy->getNumParams())
|
||||||
FunctionInnards << ", ...";
|
FunctionInnards << ", ...";
|
||||||
} else if (!MTy->getNumParams()) {
|
} else if (!MTy->getNumParams()) {
|
||||||
FunctionInnards << "void";
|
FunctionInnards << "void";
|
||||||
}
|
}
|
||||||
@ -865,12 +864,12 @@ void CWriter::printFloatingPointConstants(Function &F) {
|
|||||||
///
|
///
|
||||||
void CWriter::printModuleTypes(const SymbolTable &ST) {
|
void CWriter::printModuleTypes(const SymbolTable &ST) {
|
||||||
// If there are no type names, exit early.
|
// If there are no type names, exit early.
|
||||||
if (ST.find(Type::TypeTy) == ST.end())
|
if ( ! ST.hasTypes() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// We are only interested in the type plane of the symbol table...
|
// 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 I = ST.type_begin();
|
||||||
SymbolTable::type_const_iterator End = ST.type_end(Type::TypeTy);
|
SymbolTable::type_const_iterator End = ST.type_end();
|
||||||
|
|
||||||
// Print out forward declarations for structure types before anything else!
|
// Print out forward declarations for structure types before anything else!
|
||||||
Out << "/* Structure forward decls */\n";
|
Out << "/* Structure forward decls */\n";
|
||||||
@ -885,7 +884,7 @@ void CWriter::printModuleTypes(const SymbolTable &ST) {
|
|||||||
|
|
||||||
// Now we can print out typedefs...
|
// Now we can print out typedefs...
|
||||||
Out << "/* Typedefs */\n";
|
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<Type>(I->second);
|
const Type *Ty = cast<Type>(I->second);
|
||||||
std::string Name = "l_" + Mangler::makeNameProper(I->first);
|
std::string Name = "l_" + Mangler::makeNameProper(I->first);
|
||||||
Out << "typedef ";
|
Out << "typedef ";
|
||||||
@ -902,7 +901,7 @@ void CWriter::printModuleTypes(const SymbolTable &ST) {
|
|||||||
// printed in the correct order.
|
// printed in the correct order.
|
||||||
//
|
//
|
||||||
Out << "/* Structure contents */\n";
|
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<StructType>(I->second))
|
if (const StructType *STy = dyn_cast<StructType>(I->second))
|
||||||
// Only print out used types!
|
// Only print out used types!
|
||||||
printContainedStructs(STy, StructPrinted);
|
printContainedStructs(STy, StructPrinted);
|
||||||
@ -969,7 +968,7 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
|
|||||||
} else {
|
} else {
|
||||||
// Loop over the arguments, printing them...
|
// Loop over the arguments, printing them...
|
||||||
for (FunctionType::param_iterator I = FT->param_begin(),
|
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 << ", ";
|
if (I != FT->param_begin()) FunctionInnards << ", ";
|
||||||
printType(FunctionInnards, *I);
|
printType(FunctionInnards, *I);
|
||||||
}
|
}
|
||||||
@ -1510,3 +1509,5 @@ TargetMachine *llvm::allocateCTargetMachine(const Module &M,
|
|||||||
IntrinsicLowering *IL) {
|
IntrinsicLowering *IL) {
|
||||||
return new CTargetMachine(M, IL);
|
return new CTargetMachine(M, IL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vim: sw=2
|
||||||
|
@ -74,25 +74,24 @@ bool DTE::run(Module &M) {
|
|||||||
// Check the symbol table for superfluous type entries...
|
// Check the symbol table for superfluous type entries...
|
||||||
//
|
//
|
||||||
// Grab the 'type' plane of the module symbol...
|
// Grab the 'type' plane of the module symbol...
|
||||||
SymbolTable::iterator STI = ST.find(Type::TypeTy);
|
SymbolTable::type_iterator TI = ST.type_begin();
|
||||||
if (STI != ST.end()) {
|
while ( TI != ST.type_end() ) {
|
||||||
// Loop over all entries in the type plane...
|
// If this entry should be unconditionally removed, or if we detect that
|
||||||
SymbolTable::VarMap &Plane = STI->second;
|
// the type is not used, remove it.
|
||||||
for (SymbolTable::VarMap::iterator PI = Plane.begin(); PI != Plane.end();) {
|
const Type *RHS = TI->second;
|
||||||
// If this entry should be unconditionally removed, or if we detect that
|
if (ShouldNukeSymtabEntry(RHS) || !UsedTypes.count(RHS)) {
|
||||||
// the type is not used, remove it.
|
SymbolTable::type_iterator ToRemove = TI++;
|
||||||
const Type *RHS = cast<Type>(PI->second);
|
ST.remove(TI->second);
|
||||||
if (ShouldNukeSymtabEntry(RHS) || !UsedTypes.count(RHS)) {
|
++NumKilled;
|
||||||
Plane.erase(PI++);
|
Changed = true;
|
||||||
++NumKilled;
|
} else {
|
||||||
Changed = true;
|
++TI;
|
||||||
} else {
|
// We only need to leave one name for each type.
|
||||||
++PI;
|
UsedTypes.erase(RHS);
|
||||||
// We only need to leave one name for each type.
|
|
||||||
UsedTypes.erase(RHS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vim: sw=2
|
||||||
|
@ -269,16 +269,13 @@ void MutateStructTypes::processGlobals(Module &M) {
|
|||||||
// Remap the symbol table to refer to the types in a nice way
|
// Remap the symbol table to refer to the types in a nice way
|
||||||
//
|
//
|
||||||
SymbolTable &ST = M.getSymbolTable();
|
SymbolTable &ST = M.getSymbolTable();
|
||||||
SymbolTable::iterator I = ST.find(Type::TypeTy);
|
SymbolTable::type_iterator TI = ST.type_begin();
|
||||||
if (I != ST.end()) { // Get the type plane for Type's
|
SymbolTable::type_iterator TE = ST.type_end();
|
||||||
SymbolTable::VarMap &Plane = I->second;
|
for ( ; TI != TE; ++TI ) {
|
||||||
for (SymbolTable::type_iterator TI = Plane.begin(), TE = Plane.end();
|
// FIXME: This is gross, I'm reaching right into a symbol table and
|
||||||
TI != TE; ++TI) {
|
// mucking around with it's internals... but oh well.
|
||||||
// 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<Type*>(ConvertType(TI->second));
|
||||||
//
|
|
||||||
TI->second = (Value*)cast<Type>(ConvertType(cast<Type>(TI->second)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,3 +492,4 @@ bool MutateStructTypes::run(Module &M) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vim: sw=2
|
||||||
|
@ -33,11 +33,11 @@ Module *llvm::CloneModule(const Module *M) {
|
|||||||
|
|
||||||
// Copy all of the type symbol table entries over...
|
// Copy all of the type symbol table entries over...
|
||||||
const SymbolTable &SymTab = M->getSymbolTable();
|
const SymbolTable &SymTab = M->getSymbolTable();
|
||||||
SymbolTable::const_iterator TypeI = SymTab.find(Type::TypeTy);
|
SymbolTable::type_const_iterator TypeI = SymTab.type_begin();
|
||||||
if (TypeI != SymTab.end())
|
SymbolTable::type_const_iterator TypeE = SymTab.type_end();
|
||||||
for (SymbolTable::VarMap::const_iterator I = TypeI->second.begin(),
|
for ( ; TypeI != TypeE; ++TypeI ) {
|
||||||
E = TypeI->second.end(); I != E; ++I)
|
New->addTypeName(TypeI->first, TypeI->second);
|
||||||
New->addTypeName(I->first, cast<Type>(I->second));
|
}
|
||||||
|
|
||||||
// Create the value map that maps things from the old module over to the new
|
// Create the value map that maps things from the old module over to the new
|
||||||
// module.
|
// module.
|
||||||
@ -89,3 +89,5 @@ Module *llvm::CloneModule(const Module *M) {
|
|||||||
|
|
||||||
return New;
|
return New;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vim: sw=2
|
||||||
|
@ -105,19 +105,16 @@ static void fillTypeNameTable(const Module *M,
|
|||||||
std::map<const Type *, std::string> &TypeNames) {
|
std::map<const Type *, std::string> &TypeNames) {
|
||||||
if (!M) return;
|
if (!M) return;
|
||||||
const SymbolTable &ST = M->getSymbolTable();
|
const SymbolTable &ST = M->getSymbolTable();
|
||||||
SymbolTable::const_iterator PI = ST.find(Type::TypeTy);
|
SymbolTable::type_const_iterator TI = ST.type_begin();
|
||||||
if (PI != ST.end()) {
|
for (; TI != ST.type_end(); ++TI ) {
|
||||||
SymbolTable::type_const_iterator I = PI->second.begin();
|
// As a heuristic, don't insert pointer to primitive types, because
|
||||||
for (; I != PI->second.end(); ++I) {
|
// they are used too often to have a single useful name.
|
||||||
// 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<Type>(TI->second);
|
||||||
//
|
if (!isa<PointerType>(Ty) ||
|
||||||
const Type *Ty = cast<Type>(I->second);
|
!cast<PointerType>(Ty)->getElementType()->isPrimitiveType() ||
|
||||||
if (!isa<PointerType>(Ty) ||
|
isa<OpaqueType>(cast<PointerType>(Ty)->getElementType()))
|
||||||
!cast<PointerType>(Ty)->getElementType()->isPrimitiveType() ||
|
TypeNames.insert(std::make_pair(Ty, getLLVMName(TI->first)));
|
||||||
isa<OpaqueType>(cast<PointerType>(Ty)->getElementType()))
|
|
||||||
TypeNames.insert(std::make_pair(Ty, getLLVMName(I->first)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -605,26 +602,31 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// printSymbolTable - Run through symbol table looking for named constants
|
// printSymbolTable - Run through symbol table looking for constants
|
||||||
/// if a named constant is found, emit it's declaration...
|
// and types. Emit their declarations.
|
||||||
///
|
|
||||||
void AssemblyWriter::printSymbolTable(const SymbolTable &ST) {
|
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);
|
// Print the types.
|
||||||
SymbolTable::type_const_iterator End = ST.type_end(TI->first);
|
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) {
|
// Print the constants, in type plane order.
|
||||||
const Value *V = I->second;
|
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<Constant>(V)) {
|
if (const Constant *CPV = dyn_cast<Constant>(V)) {
|
||||||
printConstant(CPV);
|
printConstant(CPV);
|
||||||
} else if (const Type *Ty = dyn_cast<Type>(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 Value::dump() const { print(std::cerr); }
|
||||||
|
void Type::dump() const { print(std::cerr); }
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// CachedWriter Class Implementation
|
// CachedWriter Class Implementation
|
||||||
@ -1062,3 +1065,5 @@ void CachedWriter::setStream(std::ostream &os) {
|
|||||||
Out = &os;
|
Out = &os;
|
||||||
if (AW) AW->setStream(os);
|
if (AW) AW->setStream(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vim: sw=2
|
||||||
|
@ -248,18 +248,32 @@ void SlotCalculator::processModule() {
|
|||||||
// into the values table...
|
// into the values table...
|
||||||
//
|
//
|
||||||
void SlotCalculator::processSymbolTable(const SymbolTable *ST) {
|
void SlotCalculator::processSymbolTable(const SymbolTable *ST) {
|
||||||
for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I)
|
// Do the types first.
|
||||||
for (SymbolTable::type_const_iterator TI = I->second.begin(),
|
for (SymbolTable::type_const_iterator TI = ST->type_begin(),
|
||||||
TE = I->second.end(); TI != TE; ++TI)
|
TE = ST->type_end(); TI != TE; ++TI )
|
||||||
getOrCreateSlot(TI->second);
|
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) {
|
void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
|
||||||
for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I)
|
// Do the types first
|
||||||
for (SymbolTable::type_const_iterator TI = I->second.begin(),
|
for (SymbolTable::type_const_iterator TI = ST->type_begin(),
|
||||||
TE = I->second.end(); TI != TE; ++TI)
|
TE = ST->type_end(); TI != TE; ++TI )
|
||||||
if (isa<Constant>(TI->second) || isa<Type>(TI->second))
|
getOrCreateSlot(TI->second);
|
||||||
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<Constant>(VI->second))
|
||||||
|
getOrCreateSlot(VI->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -452,13 +466,19 @@ void SlotCalculator::buildCompactionTable(const Function *F) {
|
|||||||
getOrCreateCompactionTableSlot(VAN->getArgType());
|
getOrCreateCompactionTableSlot(VAN->getArgType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do the types in the symbol table
|
||||||
const SymbolTable &ST = F->getSymbolTable();
|
const SymbolTable &ST = F->getSymbolTable();
|
||||||
for (SymbolTable::const_iterator I = ST.begin(), E = ST.end(); I != E; ++I)
|
for (SymbolTable::type_const_iterator TI = ST.type_begin(),
|
||||||
for (SymbolTable::type_const_iterator TI = I->second.begin(),
|
TE = ST.type_end(); TI != TE; ++TI)
|
||||||
TE = I->second.end(); TI != TE; ++TI)
|
getOrCreateCompactionTableSlot(TI->second);
|
||||||
if (isa<Constant>(TI->second) || isa<Type>(TI->second) ||
|
|
||||||
isa<GlobalValue>(TI->second))
|
// Now do the constants and global values
|
||||||
getOrCreateCompactionTableSlot(TI->second);
|
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<Constant>(VI->second) || isa<GlobalValue>(VI->second))
|
||||||
|
getOrCreateCompactionTableSlot(VI->second);
|
||||||
|
|
||||||
// Now that we have all of the values in the table, and know what types are
|
// 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
|
// referenced, make sure that there is at least the zero initializer in any
|
||||||
|
@ -245,9 +245,9 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock*> &BBs) {
|
|||||||
BBs.clear();
|
BBs.clear();
|
||||||
for (unsigned i = 0, e = BlockInfo.size(); i != e; ++i) {
|
for (unsigned i = 0, e = BlockInfo.size(); i != e; ++i) {
|
||||||
SymbolTable &ST = BlockInfo[i].first->getSymbolTable();
|
SymbolTable &ST = BlockInfo[i].first->getSymbolTable();
|
||||||
SymbolTable::iterator I = ST.find(Type::LabelTy);
|
SymbolTable::plane_iterator PI = ST.find(Type::LabelTy);
|
||||||
if (I != ST.end() && I->second.count(BlockInfo[i].second))
|
if (PI != ST.plane_end() && PI->second.count(BlockInfo[i].second))
|
||||||
BBs.push_back(cast<BasicBlock>(I->second[BlockInfo[i].second]));
|
BBs.push_back(cast<BasicBlock>(PI->second[BlockInfo[i].second]));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user