change FnStubs from being a StringMap<std::string> to being a much

more efficient SmallPtrSet<MCSymbol*>.  This eliminates string
craziness and fixes CodeGen/X86/darwin-quote.ll with the new asmprinter.

Codegen is producing stubs in a nondeterminstic order, but it was doing
this before anyway.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81511 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-09-11 06:36:33 +00:00
parent 3e6bf2de16
commit 2a3c20bf26
3 changed files with 34 additions and 17 deletions

View File

@ -24,8 +24,10 @@
#include "llvm/Module.h"
#include "llvm/Type.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
@ -320,8 +322,9 @@ void X86ATTAsmPrinter::printSymbolOperand(const MachineOperand &MO) {
GVStubs[Name] = Mang->getMangledName(GV);
else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
HiddenGVStubs[Name] = Mang->getMangledName(GV);
else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
FnStubs[Name] = Mang->getMangledName(GV);
else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
FnStubs.insert(OutContext.GetOrCreateSymbol(Name));
}
// If the name begins with a dollar-sign, enclose it in parens. We do this
// to avoid having it look like an integer immediate to the assembler.
@ -336,8 +339,8 @@ void X86ATTAsmPrinter::printSymbolOperand(const MachineOperand &MO) {
case MachineOperand::MO_ExternalSymbol: {
std::string Name = Mang->makeNameProper(MO.getSymbolName());
if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
FnStubs[Name+"$stub"] = Name;
Name += "$stub";
FnStubs.insert(OutContext.GetOrCreateSymbol(Name));
}
// If the name begins with a dollar-sign, enclose it in parens. We do this
@ -881,10 +884,20 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
5, SectionKind::getMetadata());
OutStreamer.SwitchSection(TheSection);
for (StringMap<std::string>::iterator I = FnStubs.begin(),
E = FnStubs.end(); I != E; ++I)
O << I->getKeyData() << ":\n" << "\t.indirect_symbol " << I->second
<< "\n\thlt ; hlt ; hlt ; hlt ; hlt\n";
// FIXME: This iteration order is unstable!!
for (SmallPtrSet<MCSymbol*, 16>::iterator I = FnStubs.begin(),
E = FnStubs.end(); I != E; ++I) {
MCSymbol *Sym = *I;
Sym->print(O, MAI);
O << ":\n" << "\t.indirect_symbol ";
// Get the MCSymbol without the $stub suffix.
Sym = OutContext.GetOrCreateSymbol(StringRef(Sym->getName()).substr(0,
Sym->getName().size()-5));
Sym->print(O, MAI);
O << "\n\thlt ; hlt ; hlt ; hlt ; hlt\n";
}
O << '\n';
}

View File

@ -216,7 +216,8 @@ class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
void emitFunctionHeader(const MachineFunction &MF);
// Necessary for Darwin to print out the apprioriate types of linker stubs
StringMap<std::string> FnStubs, GVStubs, HiddenGVStubs;
StringMap<std::string> GVStubs, HiddenGVStubs;
SmallPtrSet<MCSymbol*, 16> FnStubs; // Darwin $stub stubs.
// Necessary for dllexport support
StringSet<> CygMingStubs, DLLExportedFns, DLLExportedGVs;

View File

@ -78,10 +78,12 @@ MCSymbol *X86ATTAsmPrinter::GetGlobalAddressSymbol(const MachineOperand &MO) {
Name += "$non_lazy_ptr";
HiddenGVStubs[Name.str()] = StringRef(Name.data(), Name.size()-13);
break;
case X86II::MO_DARWIN_STUB:
case X86II::MO_DARWIN_STUB: {
Name += "$stub";
FnStubs[Name.str()] = StringRef(Name.data(), Name.size()-5);
break;
MCSymbol *Sym = OutContext.GetOrCreateSymbol(Name.str());
FnStubs.insert(Sym);
return Sym;
}
// FIXME: These probably should be a modifier on the symbol or something??
case X86II::MO_TLSGD: Name += "@TLSGD"; break;
case X86II::MO_GOTTPOFF: Name += "@GOTTPOFF"; break;
@ -114,12 +116,13 @@ MCSymbol *X86ATTAsmPrinter::GetExternalSymbolSymbol(const MachineOperand &MO) {
Name.insert(Name.begin(), Prefix, Prefix+strlen(Prefix));
break;
}
case X86II::MO_DARWIN_STUB:
// Insert: FnStub["_foo$stub"] = "_foo";
case X86II::MO_DARWIN_STUB: {
Name += "$stub";
FnStubs[Name.str()] = StringRef(Name.data(), Name.size()-5);
break;
// FIXME: These probably should be a modifier on the symbol or something??
MCSymbol *Sym = OutContext.GetOrCreateSymbol(Name.str());
FnStubs.insert(Sym);
return Sym;
}
// FIXME: These probably should be a modifier on the symbol or something??
case X86II::MO_TLSGD: Name += "@TLSGD"; break;
case X86II::MO_GOTTPOFF: Name += "@GOTTPOFF"; break;
case X86II::MO_INDNTPOFF: Name += "@INDNTPOFF"; break;