Merge three loops into one.

llvm-svn: 3259
This commit is contained in:
Chris Lattner 2002-08-07 21:39:48 +00:00
parent e64e62eff9
commit c93df6bf22
1 changed files with 18 additions and 23 deletions
llvm/lib/Target/Sparc

View File

@ -777,31 +777,26 @@ void SparcModuleAsmPrinter::emitGlobalsAndConstants(const Module &M) {
hash_set<const Constant*> moduleConstants; hash_set<const Constant*> moduleConstants;
FoldConstants(M, moduleConstants); FoldConstants(M, moduleConstants);
// Now, emit the three data sections separately; the cost of I/O should // Output constants spilled to memory
// make up for the cost of extra passes over the globals list!
// Section 1 : Read-only data section (implies initialized)
enterSection(AsmPrinter::ReadOnlyData); enterSection(AsmPrinter::ReadOnlyData);
for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI) for (hash_set<const Constant*>::const_iterator I = moduleConstants.begin(),
if (GI->hasInitializer() && GI->isConstant())
printGlobalVariable(GI);
for (hash_set<const Constant*>::const_iterator
I = moduleConstants.begin(),
E = moduleConstants.end(); I != E; ++I) E = moduleConstants.end(); I != E; ++I)
printConstant(*I); printConstant(*I);
// Section 2 : Initialized read-write data section // Output global variables...
for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI) {
if (GI->hasInitializer() && GI->isConstant()) {
enterSection(AsmPrinter::ReadOnlyData); // read-only, initialized data
} else if (GI->hasInitializer() && !GI->isConstant()) { // read-write data
enterSection(AsmPrinter::ReadOnlyData); // read-only, initialized data
} else if (GI->hasInitializer() && !GI->isConstant()) { // read-write data
enterSection(AsmPrinter::InitRWData); enterSection(AsmPrinter::InitRWData);
for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI) } else {
if (GI->hasInitializer() && !GI->isConstant()) assert (!GI->hasInitializer() && "Unexpected global variable type found");
printGlobalVariable(GI); enterSection(AsmPrinter::UninitRWData); // Uninitialized data
}
// Section 3 : Uninitialized read-write data section
enterSection(AsmPrinter::UninitRWData);
for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI)
if (!GI->hasInitializer())
printGlobalVariable(GI); printGlobalVariable(GI);
}
toAsm << "\n"; toAsm << "\n";
} }