convert FnStubs to using a more structured form, eliminating

a couple instances of printSuffixedName (in favor of having
the mangler do stuff).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75729 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-07-15 02:28:57 +00:00
parent b7b179ead9
commit 9ec8facd10

View File

@ -53,7 +53,29 @@ STATISTIC(EmittedInsts, "Number of machine instrs printed");
namespace { namespace {
class VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter { class VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter {
protected: protected:
StringSet<> FnStubs; struct FnStubInfo {
std::string Stub, LazyPtr, AnonSymbol;
FnStubInfo() {}
void Init(const GlobalValue *GV, Mangler *Mang) {
// Already initialized.
if (!Stub.empty()) return;
Stub = Mang->getMangledName(GV, "$stub", true);
LazyPtr = Mang->getMangledName(GV, "$lazy_ptr", true);
AnonSymbol = Mang->getMangledName(GV, "$stub$tmp", true);
}
void Init(const std::string &GV, Mangler *Mang) {
// Already initialized.
if (!Stub.empty()) return;
Stub = Mang->makeNameProper(GV+"$stub", true);
LazyPtr = Mang->makeNameProper(GV+"$lazy_ptr", true);
AnonSymbol = Mang->makeNameProper(GV+"$stub$tmp", true);
}
};
StringMap<FnStubInfo> FnStubs;
StringMap<std::string> GVStubs, HiddenGVStubs; StringMap<std::string> GVStubs, HiddenGVStubs;
const PPCSubtarget &Subtarget; const PPCSubtarget &Subtarget;
public: public:
@ -192,16 +214,16 @@ namespace {
GlobalValue *GV = MO.getGlobal(); GlobalValue *GV = MO.getGlobal();
if (GV->isDeclaration() || GV->isWeakForLinker()) { if (GV->isDeclaration() || GV->isWeakForLinker()) {
// Dynamically-resolved functions need a stub for the function. // Dynamically-resolved functions need a stub for the function.
std::string Name = Mang->getMangledName(GV); FnStubInfo &FnInfo = FnStubs[Mang->getMangledName(GV)];
FnStubs.insert(Name); FnInfo.Init(GV, Mang);
printSuffixedName(Name, "$stub"); O << FnInfo.Stub;
return; return;
} }
} }
if (MO.getType() == MachineOperand::MO_ExternalSymbol) { if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName(); FnStubInfo &FnInfo =FnStubs[Mang->makeNameProper(MO.getSymbolName())];
FnStubs.insert(Name); FnInfo.Init(MO.getSymbolName(), Mang);
printSuffixedName(Name, "$stub"); O << FnInfo.Stub;
return; return;
} }
} }
@ -963,7 +985,7 @@ bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
if (TM.getRelocationModel() == Reloc::PIC_ && !FnStubs.empty()) { if (TM.getRelocationModel() == Reloc::PIC_ && !FnStubs.empty()) {
SwitchToTextSection("\t.section __TEXT,__picsymbolstub1,symbol_stubs," SwitchToTextSection("\t.section __TEXT,__picsymbolstub1,symbol_stubs,"
"pure_instructions,32"); "pure_instructions,32");
for (StringSet<>::iterator I = FnStubs.begin(), E = FnStubs.end(); for (StringMap<FnStubInfo>::iterator I = FnStubs.begin(), E = FnStubs.end();
I != E; ++I) { I != E; ++I) {
EmitAlignment(4); EmitAlignment(4);
const char *p = I->getKeyData(); const char *p = I->getKeyData();
@ -1018,7 +1040,7 @@ bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
} else if (!FnStubs.empty()) { } else if (!FnStubs.empty()) {
SwitchToTextSection("\t.section __TEXT,__symbol_stub1,symbol_stubs," SwitchToTextSection("\t.section __TEXT,__symbol_stub1,symbol_stubs,"
"pure_instructions,16"); "pure_instructions,16");
for (StringSet<>::iterator I = FnStubs.begin(), E = FnStubs.end(); for (StringMap<FnStubInfo>::iterator I = FnStubs.begin(), E = FnStubs.end();
I != E; ++I) { I != E; ++I) {
EmitAlignment(4); EmitAlignment(4);
const char *p = I->getKeyData(); const char *p = I->getKeyData();