1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

Refactor for clarity and efficiency.

The PPC GetSymbolFromOperand already prefixed stubs of MO_ExternalSymbol, so
this should be a nop.

llvm-svn: 196059
This commit is contained in:
Rafael Espindola 2013-12-02 03:26:43 +00:00
parent cf111ab2af
commit 3192965fa3

View File

@ -35,31 +35,34 @@ static MCSymbol *GetSymbolFromOperand(const MachineOperand &MO, AsmPrinter &AP){
MCContext &Ctx = AP.OutContext; MCContext &Ctx = AP.OutContext;
SmallString<128> Name; SmallString<128> Name;
StringRef Suffix;
if (MO.getTargetFlags() == PPCII::MO_DARWIN_STUB)
Suffix = "$stub";
else if (MO.getTargetFlags() & PPCII::MO_NLP_FLAG)
Suffix = "$non_lazy_ptr";
if (!Suffix.empty())
Name += AP.MAI->getPrivateGlobalPrefix();
unsigned PrefixLen = Name.size();
if (!MO.isGlobal()) { if (!MO.isGlobal()) {
assert(MO.isSymbol() && "Isn't a symbol reference"); assert(MO.isSymbol() && "Isn't a symbol reference");
AP.Mang->getNameWithPrefix(Name, MO.getSymbolName()); AP.Mang->getNameWithPrefix(Name, MO.getSymbolName());
} else { } else {
const GlobalValue *GV = MO.getGlobal(); const GlobalValue *GV = MO.getGlobal();
bool isImplicitlyPrivate = false; AP.Mang->getNameWithPrefix(Name, GV, false);
if (MO.getTargetFlags() == PPCII::MO_DARWIN_STUB ||
(MO.getTargetFlags() & PPCII::MO_NLP_FLAG))
isImplicitlyPrivate = true;
AP.Mang->getNameWithPrefix(Name, GV, isImplicitlyPrivate);
} }
unsigned OrigLen = Name.size() - PrefixLen;
Name += Suffix;
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
StringRef OrigName = StringRef(Name).substr(PrefixLen, OrigLen);
// If the target flags on the operand changes the name of the symbol, do that // If the target flags on the operand changes the name of the symbol, do that
// before we return the symbol. // before we return the symbol.
if (MO.getTargetFlags() == PPCII::MO_DARWIN_STUB) { if (MO.getTargetFlags() == PPCII::MO_DARWIN_STUB) {
Name += "$stub";
const char *PGP = AP.MAI->getPrivateGlobalPrefix();
const char *Prefix = "";
if (!Name.startswith(PGP)) {
// http://llvm.org/bugs/show_bug.cgi?id=15763
// all stubs and lazy_ptrs should be local symbols, which need leading 'L'
Prefix = PGP;
}
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Twine(Prefix) + Twine(Name));
MachineModuleInfoImpl::StubValueTy &StubSym = MachineModuleInfoImpl::StubValueTy &StubSym =
getMachOMMI(AP).getFnStubEntry(Sym); getMachOMMI(AP).getFnStubEntry(Sym);
if (StubSym.getPointer()) if (StubSym.getPointer())
@ -71,10 +74,9 @@ static MCSymbol *GetSymbolFromOperand(const MachineOperand &MO, AsmPrinter &AP){
StubValueTy(AP.getSymbol(MO.getGlobal()), StubValueTy(AP.getSymbol(MO.getGlobal()),
!MO.getGlobal()->hasInternalLinkage()); !MO.getGlobal()->hasInternalLinkage());
} else { } else {
Name.erase(Name.end()-5, Name.end());
StubSym = StubSym =
MachineModuleInfoImpl:: MachineModuleInfoImpl::
StubValueTy(Ctx.GetOrCreateSymbol(Name.str()), false); StubValueTy(Ctx.GetOrCreateSymbol(OrigName), false);
} }
return Sym; return Sym;
} }
@ -82,9 +84,6 @@ static MCSymbol *GetSymbolFromOperand(const MachineOperand &MO, AsmPrinter &AP){
// If the symbol reference is actually to a non_lazy_ptr, not to the symbol, // If the symbol reference is actually to a non_lazy_ptr, not to the symbol,
// then add the suffix. // then add the suffix.
if (MO.getTargetFlags() & PPCII::MO_NLP_FLAG) { if (MO.getTargetFlags() & PPCII::MO_NLP_FLAG) {
Name += "$non_lazy_ptr";
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
MachineModuleInfoMachO &MachO = getMachOMMI(AP); MachineModuleInfoMachO &MachO = getMachOMMI(AP);
MachineModuleInfoImpl::StubValueTy &StubSym = MachineModuleInfoImpl::StubValueTy &StubSym =
@ -100,7 +99,7 @@ static MCSymbol *GetSymbolFromOperand(const MachineOperand &MO, AsmPrinter &AP){
return Sym; return Sym;
} }
return Ctx.GetOrCreateSymbol(Name.str()); return Sym;
} }
static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol, static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol,