move FnStubs/GVSTubs/HiddenGVStub handling out of the X86 asmprinter

and use MachineModuleInfoMachO instead.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82022 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-09-16 06:25:03 +00:00
parent 29cf5557b2
commit dc62ea0f1c
7 changed files with 52 additions and 49 deletions

View File

@ -76,10 +76,11 @@ namespace llvm {
///
MachineLoopInfo *LI;
protected:
public:
/// MMI - If available, this is a pointer to the current MachineModuleInfo.
MachineModuleInfo *MMI;
protected:
/// DW - If available, this is a pointer to the current dwarf writer.
DwarfWriter *DW;

View File

@ -163,17 +163,17 @@ public:
/// backends that would like to do so.
///
template<typename Ty>
Ty *getObjFileInfo() {
Ty &getObjFileInfo() {
if (ObjFileMMI == 0)
ObjFileMMI = new Ty(*this);
assert((void*)dynamic_cast<Ty*>(ObjFileMMI) == (void*)ObjFileMMI &&
"Invalid concrete type or multiple inheritence for getInfo");
return static_cast<Ty*>(ObjFileMMI);
return *static_cast<Ty*>(ObjFileMMI);
}
template<typename Ty>
const Ty *getObjFileInfo() const {
const Ty &getObjFileInfo() const {
return const_cast<MachineModuleInfo*>(this)->getObjFileInfo<Ty>();
}

View File

@ -38,18 +38,19 @@ namespace llvm {
virtual void Anchor(); // Out of line virtual method.
public:
MachineModuleInfoMachO(const MachineModuleInfo &) {}
const MCSymbol *&getFnStubEntry(const MCSymbol *Sym) {
assert(Sym && "Key cannot be null");
return FnStubs[Sym];
}
const MCSymbol *&getGVStubsEntry(const MCSymbol *Sym) {
const MCSymbol *&getGVStubEntry(const MCSymbol *Sym) {
assert(Sym && "Key cannot be null");
return GVStubs[Sym];
}
const MCSymbol *&getHiddenGVStubsEntry(const MCSymbol *Sym) {
const MCSymbol *&getHiddenGVStubEntry(const MCSymbol *Sym) {
assert(Sym && "Key cannot be null");
return HiddenGVStubs[Sym];
}

View File

@ -31,6 +31,7 @@
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Mangler.h"
@ -320,7 +321,9 @@ void X86ATTAsmPrinter::printSymbolOperand(const MachineOperand &MO) {
Mang->getNameWithPrefix(NameStr, GV, true);
NameStr += "$non_lazy_ptr";
MCSymbol *Sym = OutContext.GetOrCreateSymbol(NameStr.str());
MCSymbol *&StubSym = GVStubs[Sym];
const MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym);
if (StubSym == 0) {
NameStr.clear();
Mang->getNameWithPrefix(NameStr, GV, false);
@ -331,7 +334,8 @@ void X86ATTAsmPrinter::printSymbolOperand(const MachineOperand &MO) {
Mang->getNameWithPrefix(NameStr, GV, true);
NameStr += "$non_lazy_ptr";
MCSymbol *Sym = OutContext.GetOrCreateSymbol(NameStr.str());
MCSymbol *&StubSym = HiddenGVStubs[Sym];
const MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getHiddenGVStubEntry(Sym);
if (StubSym == 0) {
NameStr.clear();
Mang->getNameWithPrefix(NameStr, GV, false);
@ -342,7 +346,8 @@ void X86ATTAsmPrinter::printSymbolOperand(const MachineOperand &MO) {
Mang->getNameWithPrefix(NameStr, GV, true);
NameStr += "$stub";
MCSymbol *Sym = OutContext.GetOrCreateSymbol(NameStr.str());
MCSymbol *&StubSym = FnStubs[Sym];
const MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
if (StubSym == 0) {
NameStr.clear();
Mang->getNameWithPrefix(NameStr, GV, false);
@ -364,7 +369,9 @@ void X86ATTAsmPrinter::printSymbolOperand(const MachineOperand &MO) {
std::string Name = Mang->makeNameProper(MO.getSymbolName());
if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
Name += "$stub";
MCSymbol *&StubSym = FnStubs[OutContext.GetOrCreateSymbol(Name)];
MCSymbol *Sym = OutContext.GetOrCreateSymbol(Name);
const MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
if (StubSym == 0) {
Name.erase(Name.end()-5, Name.end());
StubSym = OutContext.GetOrCreateSymbol(Name);
@ -872,28 +879,15 @@ void X86ATTAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
O << "\t.size\t" << name << ", " << Size << '\n';
}
static int SortSymbolPair(const void *LHS, const void *RHS) {
MCSymbol *LHSS = ((const std::pair<MCSymbol*, MCSymbol*>*)LHS)->first;
MCSymbol *RHSS = ((const std::pair<MCSymbol*, MCSymbol*>*)RHS)->first;
return LHSS->getName().compare(RHSS->getName());
}
/// GetSortedStubs - Return the entries from a DenseMap in a deterministic
/// sorted orer.
static std::vector<std::pair<MCSymbol*, MCSymbol*> >
GetSortedStubs(const DenseMap<MCSymbol*, MCSymbol*> &Map) {
assert(!Map.empty());
std::vector<std::pair<MCSymbol*, MCSymbol*> > List(Map.begin(), Map.end());
qsort(&List[0], List.size(), sizeof(List[0]), SortSymbolPair);
return List;
}
bool X86ATTAsmPrinter::doFinalization(Module &M) {
if (Subtarget->isTargetDarwin()) {
// All darwin targets use mach-o.
TargetLoweringObjectFileMachO &TLOFMacho =
static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
MachineModuleInfoMachO &MMIMacho =
MMI->getObjFileInfo<MachineModuleInfoMachO>();
// Add the (possibly multiple) personalities to the set of global value
// stubs. Only referenced functions get into the Personalities list.
if (!Subtarget->is64Bit()) {
@ -907,18 +901,18 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
Name += "$non_lazy_ptr";
MCSymbol *NLPName = OutContext.GetOrCreateSymbol(Name.str());
MCSymbol *&StubName = GVStubs[NLPName];
if (StubName != 0) continue;
const MCSymbol *&StubName = MMIMacho.getGVStubEntry(NLPName);
Name.clear();
Mang->getNameWithPrefix(Name, Personalities[i], false);
StubName = OutContext.GetOrCreateSymbol(Name.str());
}
}
// Output stubs for dynamically-linked functions
if (!FnStubs.empty()) {
// Output stubs for dynamically-linked functions.
MachineModuleInfoMachO::SymbolListTy Stubs;
Stubs = MMIMacho.GetFnStubList();
if (!Stubs.empty()) {
const MCSection *TheSection =
TLOFMacho.getMachOSection("__IMPORT", "__jump_table",
MCSectionMachO::S_SYMBOL_STUBS |
@ -927,8 +921,6 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
5, SectionKind::getMetadata());
OutStreamer.SwitchSection(TheSection);
std::vector<std::pair<MCSymbol*, MCSymbol*> > Stubs
= GetSortedStubs(FnStubs);
for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
Stubs[i].first->print(O, MAI);
O << ":\n" << "\t.indirect_symbol ";
@ -937,38 +929,40 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
O << "\n\thlt ; hlt ; hlt ; hlt ; hlt\n";
}
O << '\n';
Stubs.clear();
}
// Output stubs for external and common global variables.
if (!GVStubs.empty()) {
Stubs = MMIMacho.GetGVStubList();
if (!Stubs.empty()) {
const MCSection *TheSection =
TLOFMacho.getMachOSection("__IMPORT", "__pointers",
MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
SectionKind::getMetadata());
OutStreamer.SwitchSection(TheSection);
std::vector<std::pair<MCSymbol*, MCSymbol*> > Stubs
= GetSortedStubs(GVStubs);
for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
Stubs[i].first->print(O, MAI);
O << ":\n\t.indirect_symbol ";
Stubs[i].second->print(O, MAI);
O << "\n\t.long\t0\n";
}
Stubs.clear();
}
if (!HiddenGVStubs.empty()) {
Stubs = MMIMacho.GetHiddenGVStubList();
if (!Stubs.empty()) {
OutStreamer.SwitchSection(getObjFileLowering().getDataSection());
EmitAlignment(2);
std::vector<std::pair<MCSymbol*, MCSymbol*> > Stubs
= GetSortedStubs(HiddenGVStubs);
for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
Stubs[i].first->print(O, MAI);
O << ":\n" << MAI->getData32bitsDirective();
Stubs[i].second->print(O, MAI);
O << '\n';
}
Stubs.clear();
}
// Funny Darwin hack: This flag tells the linker that no global symbols

View File

@ -152,11 +152,6 @@ class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
void emitFunctionHeader(const MachineFunction &MF);
// Necessary for Darwin to print out the appropriate types of linker stubs.
DenseMap<MCSymbol*, MCSymbol*> FnStubs; // Darwin $stub stubs.
DenseMap<MCSymbol*, MCSymbol*> GVStubs; // Darwin $non_lazy_ptr stub.
DenseMap<MCSymbol*, MCSymbol*> HiddenGVStubs; // Darwin $non_lazy_ptr stub.
// Necessary for dllexport support
StringSet<> CygMingStubs, DLLExportedFns, DLLExportedGVs;

View File

@ -15,6 +15,7 @@
#include "X86MCInstLower.h"
#include "X86ATTAsmPrinter.h"
#include "X86MCAsmInfo.h"
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
@ -29,6 +30,11 @@ const X86Subtarget &X86MCInstLower::getSubtarget() const {
return AsmPrinter.getSubtarget();
}
MachineModuleInfoMachO &X86MCInstLower::getMachOMMI() const {
assert(getSubtarget().isTargetDarwin() &&"Can only get MachO info on darwin");
return AsmPrinter.MMI->getObjFileInfo<MachineModuleInfoMachO>();
}
MCSymbol *X86MCInstLower::GetPICBaseSymbol() const {
SmallString<60> Name;
@ -72,7 +78,8 @@ GetGlobalAddressSymbol(const MachineOperand &MO) const {
case X86II::MO_DARWIN_NONLAZY_PIC_BASE: {
Name += "$non_lazy_ptr";
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
MCSymbol *&StubSym = AsmPrinter.GVStubs[Sym];
const MCSymbol *&StubSym = getMachOMMI().getGVStubEntry(Sym);
if (StubSym == 0) {
Name.clear();
Mang->getNameWithPrefix(Name, GV, false);
@ -83,7 +90,7 @@ GetGlobalAddressSymbol(const MachineOperand &MO) const {
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: {
Name += "$non_lazy_ptr";
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
MCSymbol *&StubSym = AsmPrinter.HiddenGVStubs[Sym];
const MCSymbol *&StubSym = getMachOMMI().getHiddenGVStubEntry(Sym);
if (StubSym == 0) {
Name.clear();
Mang->getNameWithPrefix(Name, GV, false);
@ -94,7 +101,7 @@ GetGlobalAddressSymbol(const MachineOperand &MO) const {
case X86II::MO_DARWIN_STUB: {
Name += "$stub";
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
MCSymbol *&StubSym = AsmPrinter.FnStubs[Sym];
const MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym);
if (StubSym == 0) {
Name.clear();
Mang->getNameWithPrefix(Name, GV, false);
@ -138,7 +145,8 @@ GetExternalSymbolSymbol(const MachineOperand &MO) const {
case X86II::MO_DARWIN_STUB: {
Name += "$stub";
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
MCSymbol *&StubSym = AsmPrinter.FnStubs[Sym];
const MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym);
if (StubSym == 0) {
Name.erase(Name.end()-5, Name.end());
StubSym = Ctx.GetOrCreateSymbol(Name.str());

View File

@ -18,6 +18,7 @@ namespace llvm {
class MCOperand;
class MCSymbol;
class MachineInstr;
class MachineModuleInfoMachO;
class MachineOperand;
class Mangler;
class X86ATTAsmPrinter;
@ -43,6 +44,9 @@ public:
MCSymbol *GetJumpTableSymbol(const MachineOperand &MO) const;
MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO) const;
MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const;
private:
MachineModuleInfoMachO &getMachOMMI() const;
};
}