make MachineModuleInfoMachO hold non-const MCSymbol*'s instead

of const ones.  non-const ones aren't very useful, because you can't
even, say, emit them.

llvm-svn: 95205
This commit is contained in:
Chris Lattner 2010-02-03 06:18:30 +00:00
parent 78c8eaa4cb
commit 082f484074
7 changed files with 32 additions and 34 deletions

View File

@ -25,39 +25,38 @@ namespace llvm {
class MachineModuleInfoMachO : public MachineModuleInfoImpl { class MachineModuleInfoMachO : public MachineModuleInfoImpl {
/// FnStubs - Darwin '$stub' stubs. The key is something like "Lfoo$stub", /// FnStubs - Darwin '$stub' stubs. The key is something like "Lfoo$stub",
/// the value is something like "_foo". /// the value is something like "_foo".
DenseMap<const MCSymbol*, const MCSymbol*> FnStubs; DenseMap<MCSymbol*, MCSymbol*> FnStubs;
/// GVStubs - Darwin '$non_lazy_ptr' stubs. The key is something like /// GVStubs - Darwin '$non_lazy_ptr' stubs. The key is something like
/// "Lfoo$non_lazy_ptr", the value is something like "_foo". /// "Lfoo$non_lazy_ptr", the value is something like "_foo".
DenseMap<const MCSymbol*, const MCSymbol*> GVStubs; DenseMap<MCSymbol*, MCSymbol*> GVStubs;
/// HiddenGVStubs - Darwin '$non_lazy_ptr' stubs. The key is something like /// HiddenGVStubs - Darwin '$non_lazy_ptr' stubs. The key is something like
/// "Lfoo$non_lazy_ptr", the value is something like "_foo". Unlike GVStubs /// "Lfoo$non_lazy_ptr", the value is something like "_foo". Unlike GVStubs
/// these are for things with hidden visibility. /// these are for things with hidden visibility.
DenseMap<const MCSymbol*, const MCSymbol*> HiddenGVStubs; DenseMap<MCSymbol*, MCSymbol*> HiddenGVStubs;
virtual void Anchor(); // Out of line virtual method. virtual void Anchor(); // Out of line virtual method.
public: public:
MachineModuleInfoMachO(const MachineModuleInfo &) {} MachineModuleInfoMachO(const MachineModuleInfo &) {}
const MCSymbol *&getFnStubEntry(const MCSymbol *Sym) { MCSymbol *&getFnStubEntry(MCSymbol *Sym) {
assert(Sym && "Key cannot be null"); assert(Sym && "Key cannot be null");
return FnStubs[Sym]; return FnStubs[Sym];
} }
const MCSymbol *&getGVStubEntry(const MCSymbol *Sym) { MCSymbol *&getGVStubEntry(MCSymbol *Sym) {
assert(Sym && "Key cannot be null"); assert(Sym && "Key cannot be null");
return GVStubs[Sym]; return GVStubs[Sym];
} }
const MCSymbol *&getHiddenGVStubEntry(const MCSymbol *Sym) { MCSymbol *&getHiddenGVStubEntry(MCSymbol *Sym) {
assert(Sym && "Key cannot be null"); assert(Sym && "Key cannot be null");
return HiddenGVStubs[Sym]; return HiddenGVStubs[Sym];
} }
/// Accessor methods to return the set of stubs in sorted order. /// Accessor methods to return the set of stubs in sorted order.
typedef std::vector<std::pair<const MCSymbol*, const MCSymbol*> > typedef std::vector<std::pair<MCSymbol*, MCSymbol*> > SymbolListTy;
SymbolListTy;
SymbolListTy GetFnStubList() const { SymbolListTy GetFnStubList() const {
return GetSortedStubs(FnStubs); return GetSortedStubs(FnStubs);
@ -71,7 +70,7 @@ namespace llvm {
private: private:
static SymbolListTy static SymbolListTy
GetSortedStubs(const DenseMap<const MCSymbol*, const MCSymbol*> &Map); GetSortedStubs(const DenseMap<MCSymbol*, MCSymbol*> &Map);
}; };
} // end namespace llvm } // end namespace llvm

View File

@ -26,17 +26,17 @@ void MachineModuleInfoMachO::Anchor() {}
static int SortSymbolPair(const void *LHS, const void *RHS) { static int SortSymbolPair(const void *LHS, const void *RHS) {
const MCSymbol *LHSS = const MCSymbol *LHSS =
((const std::pair<const MCSymbol*, const MCSymbol*>*)LHS)->first; ((const std::pair<MCSymbol*, MCSymbol*>*)LHS)->first;
const MCSymbol *RHSS = const MCSymbol *RHSS =
((const std::pair<const MCSymbol*, const MCSymbol*>*)RHS)->first; ((const std::pair<MCSymbol*, MCSymbol*>*)RHS)->first;
return LHSS->getName().compare(RHSS->getName()); return LHSS->getName().compare(RHSS->getName());
} }
/// GetSortedStubs - Return the entries from a DenseMap in a deterministic /// GetSortedStubs - Return the entries from a DenseMap in a deterministic
/// sorted orer. /// sorted orer.
MachineModuleInfoMachO::SymbolListTy MachineModuleInfoMachO::SymbolListTy
MachineModuleInfoMachO::GetSortedStubs(const DenseMap<const MCSymbol*, MachineModuleInfoMachO::GetSortedStubs(const DenseMap<MCSymbol*,
const MCSymbol*> &Map) { MCSymbol*> &Map) {
MachineModuleInfoMachO::SymbolListTy List(Map.begin(), Map.end()); MachineModuleInfoMachO::SymbolListTy List(Map.begin(), Map.end());
if (!List.empty()) if (!List.empty())
qsort(&List[0], List.size(), sizeof(List[0]), SortSymbolPair); qsort(&List[0], List.size(), sizeof(List[0]), SortSymbolPair);

View File

@ -200,7 +200,7 @@ namespace {
MachineModuleInfoMachO &MMIMachO = MachineModuleInfoMachO &MMIMachO =
MMI->getObjFileInfo<MachineModuleInfoMachO>(); MMI->getObjFileInfo<MachineModuleInfoMachO>();
const MCSymbol *&StubSym = MCSymbol *&StubSym =
GV->hasHiddenVisibility() ? MMIMachO.getHiddenGVStubEntry(Sym) : GV->hasHiddenVisibility() ? MMIMachO.getHiddenGVStubEntry(Sym) :
MMIMachO.getGVStubEntry(Sym); MMIMachO.getGVStubEntry(Sym);
if (StubSym == 0) if (StubSym == 0)

View File

@ -198,7 +198,7 @@ namespace {
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.
MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub"); MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub");
const MCSymbol *&StubSym = MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
if (StubSym == 0) if (StubSym == 0)
StubSym = GetGlobalValueSymbol(GV); StubSym = GetGlobalValueSymbol(GV);
@ -211,8 +211,8 @@ namespace {
TempNameStr += StringRef(MO.getSymbolName()); TempNameStr += StringRef(MO.getSymbolName());
TempNameStr += StringRef("$stub"); TempNameStr += StringRef("$stub");
const MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str()); MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str());
const MCSymbol *&StubSym = MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
if (StubSym == 0) if (StubSym == 0)
StubSym = GetExternalSymbolSymbol(MO.getSymbolName()); StubSym = GetExternalSymbolSymbol(MO.getSymbolName());
@ -401,10 +401,10 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
return; return;
} }
const MCSymbol *NLPSym = MCSymbol *NLPSym =
OutContext.GetOrCreateSymbol(StringRef(MAI->getGlobalPrefix())+ OutContext.GetOrCreateSymbol(StringRef(MAI->getGlobalPrefix())+
MO.getSymbolName()+"$non_lazy_ptr"); MO.getSymbolName()+"$non_lazy_ptr");
const MCSymbol *&StubSym = MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(NLPSym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(NLPSym);
if (StubSym == 0) if (StubSym == 0)
StubSym = GetExternalSymbolSymbol(MO.getSymbolName()); StubSym = GetExternalSymbolSymbol(MO.getSymbolName());
@ -422,7 +422,7 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
(GV->isDeclaration() || GV->isWeakForLinker())) { (GV->isDeclaration() || GV->isWeakForLinker())) {
if (!GV->hasHiddenVisibility()) { if (!GV->hasHiddenVisibility()) {
SymToPrint = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); SymToPrint = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
const MCSymbol *&StubSym = MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(SymToPrint); MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(SymToPrint);
if (StubSym == 0) if (StubSym == 0)
StubSym = GetGlobalValueSymbol(GV); StubSym = GetGlobalValueSymbol(GV);
@ -430,7 +430,7 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
GV->hasAvailableExternallyLinkage()) { GV->hasAvailableExternallyLinkage()) {
SymToPrint = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); SymToPrint = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
const MCSymbol *&StubSym = MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>(). MMI->getObjFileInfo<MachineModuleInfoMachO>().
getHiddenGVStubEntry(SymToPrint); getHiddenGVStubEntry(SymToPrint);
if (StubSym == 0) if (StubSym == 0)
@ -780,9 +780,8 @@ bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
for (std::vector<Function *>::const_iterator I = Personalities.begin(), for (std::vector<Function *>::const_iterator I = Personalities.begin(),
E = Personalities.end(); I != E; ++I) { E = Personalities.end(); I != E; ++I) {
if (*I) { if (*I) {
const MCSymbol *NLPSym = MCSymbol *NLPSym = GetSymbolWithGlobalValueBase(*I, "$non_lazy_ptr");
GetSymbolWithGlobalValueBase(*I, "$non_lazy_ptr"); MCSymbol *&StubSym = MMIMacho.getGVStubEntry(NLPSym);
const MCSymbol *&StubSym = MMIMacho.getGVStubEntry(NLPSym);
StubSym = GetGlobalValueSymbol(*I); StubSym = GetGlobalValueSymbol(*I);
} }
} }

View File

@ -132,20 +132,20 @@ void X86AsmPrinter::printSymbolOperand(const MachineOperand &MO) {
MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) { MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) {
MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
const MCSymbol *&StubSym = MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym);
if (StubSym == 0) if (StubSym == 0)
StubSym = GetGlobalValueSymbol(GV); StubSym = GetGlobalValueSymbol(GV);
} else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE){ } else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE){
MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
const MCSymbol *&StubSym = MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getHiddenGVStubEntry(Sym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getHiddenGVStubEntry(Sym);
if (StubSym == 0) if (StubSym == 0)
StubSym = GetGlobalValueSymbol(GV); StubSym = GetGlobalValueSymbol(GV);
} else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) { } else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub"); MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub");
const MCSymbol *&StubSym = MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
if (StubSym == 0) if (StubSym == 0)
StubSym = GetGlobalValueSymbol(GV); StubSym = GetGlobalValueSymbol(GV);
@ -167,8 +167,8 @@ void X86AsmPrinter::printSymbolOperand(const MachineOperand &MO) {
TempNameStr += StringRef(MO.getSymbolName()); TempNameStr += StringRef(MO.getSymbolName());
TempNameStr += StringRef("$stub"); TempNameStr += StringRef("$stub");
const MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str()); MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str());
const MCSymbol *&StubSym = MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
if (StubSym == 0) { if (StubSym == 0) {
TempNameStr.erase(TempNameStr.end()-5, TempNameStr.end()); TempNameStr.erase(TempNameStr.end()-5, TempNameStr.end());

View File

@ -82,7 +82,7 @@ GetGlobalAddressSymbol(const MachineOperand &MO) const {
Name += "$non_lazy_ptr"; Name += "$non_lazy_ptr";
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str()); MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
const MCSymbol *&StubSym = getMachOMMI().getGVStubEntry(Sym); MCSymbol *&StubSym = getMachOMMI().getGVStubEntry(Sym);
if (StubSym == 0) if (StubSym == 0)
StubSym = AsmPrinter.GetGlobalValueSymbol(GV); StubSym = AsmPrinter.GetGlobalValueSymbol(GV);
return Sym; return Sym;
@ -90,7 +90,7 @@ GetGlobalAddressSymbol(const MachineOperand &MO) const {
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: { case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: {
Name += "$non_lazy_ptr"; Name += "$non_lazy_ptr";
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str()); MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
const MCSymbol *&StubSym = getMachOMMI().getHiddenGVStubEntry(Sym); MCSymbol *&StubSym = getMachOMMI().getHiddenGVStubEntry(Sym);
if (StubSym == 0) if (StubSym == 0)
StubSym = AsmPrinter.GetGlobalValueSymbol(GV); StubSym = AsmPrinter.GetGlobalValueSymbol(GV);
return Sym; return Sym;
@ -98,7 +98,7 @@ GetGlobalAddressSymbol(const MachineOperand &MO) const {
case X86II::MO_DARWIN_STUB: { case X86II::MO_DARWIN_STUB: {
Name += "$stub"; Name += "$stub";
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str()); MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
const MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym); MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym);
if (StubSym == 0) if (StubSym == 0)
StubSym = AsmPrinter.GetGlobalValueSymbol(GV); StubSym = AsmPrinter.GetGlobalValueSymbol(GV);
return Sym; return Sym;
@ -139,7 +139,7 @@ GetExternalSymbolSymbol(const MachineOperand &MO) const {
case X86II::MO_DARWIN_STUB: { case X86II::MO_DARWIN_STUB: {
Name += "$stub"; Name += "$stub";
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str()); MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
const MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym); MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym);
if (StubSym == 0) { if (StubSym == 0) {
Name.erase(Name.end()-5, Name.end()); Name.erase(Name.end()-5, Name.end());

View File

@ -35,7 +35,7 @@ getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
// Add information about the stub reference to MachOMMI so that the stub gets // Add information about the stub reference to MachOMMI so that the stub gets
// emitted by the asmprinter. // emitted by the asmprinter.
MCSymbol *Sym = getContext().GetOrCreateSymbol(Name.str()); MCSymbol *Sym = getContext().GetOrCreateSymbol(Name.str());
const MCSymbol *&StubSym = MachOMMI.getGVStubEntry(Sym); MCSymbol *&StubSym = MachOMMI.getGVStubEntry(Sym);
if (StubSym == 0) { if (StubSym == 0) {
Name.clear(); Name.clear();
Mang->getNameWithPrefix(Name, GV, false); Mang->getNameWithPrefix(Name, GV, false);