[llvm-commits] [llvm] r82022 - in /llvm/trunk: include/llvm/CodeGen/AsmPrinter.h include/llvm/CodeGen/MachineModuleInfo.h include/llvm/CodeGen/MachineModuleInfoImpls.h lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h lib/Target/X86/AsmPrinter/X86MCInstLower.cpp lib/Target/X86/AsmPrinter/X86MCInstLower.h
Chris Lattner
sabre at nondot.org
Tue Sep 15 23:25:04 PDT 2009
Author: lattner
Date: Wed Sep 16 01:25:03 2009
New Revision: 82022
URL: http://llvm.org/viewvc/llvm-project?rev=82022&view=rev
Log:
move FnStubs/GVSTubs/HiddenGVStub handling out of the X86 asmprinter
and use MachineModuleInfoMachO instead.
Modified:
llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h
llvm/trunk/include/llvm/CodeGen/MachineModuleInfoImpls.h
llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h
llvm/trunk/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp
llvm/trunk/lib/Target/X86/AsmPrinter/X86MCInstLower.h
Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=82022&r1=82021&r2=82022&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Wed Sep 16 01:25:03 2009
@@ -76,10 +76,11 @@
///
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;
Modified: llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h?rev=82022&r1=82021&r2=82022&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h Wed Sep 16 01:25:03 2009
@@ -163,17 +163,17 @@
/// 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>();
}
Modified: llvm/trunk/include/llvm/CodeGen/MachineModuleInfoImpls.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineModuleInfoImpls.h?rev=82022&r1=82021&r2=82022&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineModuleInfoImpls.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineModuleInfoImpls.h Wed Sep 16 01:25:03 2009
@@ -38,18 +38,19 @@
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];
}
Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=82022&r1=82021&r2=82022&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Wed Sep 16 01:25:03 2009
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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
Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h?rev=82022&r1=82021&r2=82022&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h Wed Sep 16 01:25:03 2009
@@ -152,11 +152,6 @@
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;
Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp?rev=82022&r1=82021&r2=82022&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp Wed Sep 16 01:25:03 2009
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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());
Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86MCInstLower.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86MCInstLower.h?rev=82022&r1=82021&r2=82022&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86MCInstLower.h (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86MCInstLower.h Wed Sep 16 01:25:03 2009
@@ -18,6 +18,7 @@
class MCOperand;
class MCSymbol;
class MachineInstr;
+ class MachineModuleInfoMachO;
class MachineOperand;
class Mangler;
class X86ATTAsmPrinter;
@@ -43,6 +44,9 @@
MCSymbol *GetJumpTableSymbol(const MachineOperand &MO) const;
MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO) const;
MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const;
+
+private:
+ MachineModuleInfoMachO &getMachOMMI() const;
};
}
More information about the llvm-commits
mailing list