mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-26 07:29:55 +00:00
Convert GVStubs and HiddenGVStubs to work more like the X86 backend, this
eliminates a bunch of uses of "printSuffixedName" and "getGlobalLinkName". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75719 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ea56f109db
commit
8f831cbf0d
@ -53,7 +53,8 @@ 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, GVStubs, HiddenGVStubs;
|
StringSet<> FnStubs;
|
||||||
|
StringMap<std::string> GVStubs, HiddenGVStubs;
|
||||||
const PPCSubtarget &Subtarget;
|
const PPCSubtarget &Subtarget;
|
||||||
public:
|
public:
|
||||||
explicit PPCAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
explicit PPCAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
|
||||||
@ -363,37 +364,38 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
|
|||||||
O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
|
O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
|
||||||
<< '_' << MO.getIndex();
|
<< '_' << MO.getIndex();
|
||||||
return;
|
return;
|
||||||
case MachineOperand::MO_ExternalSymbol:
|
case MachineOperand::MO_ExternalSymbol: {
|
||||||
// Computing the address of an external symbol, not calling it.
|
// Computing the address of an external symbol, not calling it.
|
||||||
if (TM.getRelocationModel() != Reloc::Static) {
|
|
||||||
std::string Name(TAI->getGlobalPrefix());
|
std::string Name(TAI->getGlobalPrefix());
|
||||||
Name += MO.getSymbolName();
|
Name += MO.getSymbolName();
|
||||||
GVStubs.insert(Name);
|
|
||||||
printSuffixedName(Name, "$non_lazy_ptr");
|
if (TM.getRelocationModel() != Reloc::Static) {
|
||||||
|
GVStubs[Name] = Name+"$non_lazy_ptr";
|
||||||
|
Name += "$non_lazy_ptr";
|
||||||
|
}
|
||||||
|
O << Name;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
O << TAI->getGlobalPrefix() << MO.getSymbolName();
|
|
||||||
return;
|
|
||||||
case MachineOperand::MO_GlobalAddress: {
|
case MachineOperand::MO_GlobalAddress: {
|
||||||
// Computing the address of a global symbol, not calling it.
|
// Computing the address of a global symbol, not calling it.
|
||||||
GlobalValue *GV = MO.getGlobal();
|
GlobalValue *GV = MO.getGlobal();
|
||||||
std::string Name = Mang->getMangledName(GV);
|
std::string Name;
|
||||||
|
|
||||||
// External or weakly linked global variables need non-lazily-resolved stubs
|
// External or weakly linked global variables need non-lazily-resolved stubs
|
||||||
if (TM.getRelocationModel() != Reloc::Static) {
|
if (TM.getRelocationModel() != Reloc::Static &&
|
||||||
if (GV->isDeclaration() || GV->isWeakForLinker()) {
|
(GV->isDeclaration() || GV->isWeakForLinker())) {
|
||||||
if (!GV->hasHiddenVisibility()) {
|
if (!GV->hasHiddenVisibility()) {
|
||||||
GVStubs.insert(Name);
|
Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
|
||||||
printSuffixedName(Name, "$non_lazy_ptr");
|
GVStubs[Mang->getMangledName(GV)] = Name;
|
||||||
} else if (GV->isDeclaration() || GV->hasCommonLinkage() ||
|
} else if (GV->isDeclaration() || GV->hasCommonLinkage() ||
|
||||||
GV->hasAvailableExternallyLinkage()) {
|
GV->hasAvailableExternallyLinkage()) {
|
||||||
HiddenGVStubs.insert(Name);
|
Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
|
||||||
printSuffixedName(Name, "$non_lazy_ptr");
|
HiddenGVStubs[Mang->getMangledName(GV)] = Name;
|
||||||
} else {
|
} else {
|
||||||
O << Name;
|
Name = Mang->getMangledName(GV);
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Name = Mang->getMangledName(GV);
|
||||||
}
|
}
|
||||||
O << Name;
|
O << Name;
|
||||||
|
|
||||||
@ -411,14 +413,16 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
|
|||||||
///
|
///
|
||||||
void PPCAsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
|
void PPCAsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
|
||||||
std::string Name;
|
std::string Name;
|
||||||
getGlobalLinkName(GV, Name);
|
|
||||||
if (TM.getRelocationModel() != Reloc::Static) {
|
if (TM.getRelocationModel() != Reloc::Static) {
|
||||||
|
Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
|
||||||
|
|
||||||
if (GV->hasHiddenVisibility())
|
if (GV->hasHiddenVisibility())
|
||||||
HiddenGVStubs.insert(Name);
|
HiddenGVStubs[Mang->getMangledName(GV)] = Name;
|
||||||
else
|
else
|
||||||
GVStubs.insert(Name);
|
GVStubs[Mang->getMangledName(GV)] = Name;
|
||||||
printSuffixedName(Name, "$non_lazy_ptr");
|
} else {
|
||||||
return;
|
Name = Mang->getMangledName(GV);
|
||||||
}
|
}
|
||||||
O << Name;
|
O << Name;
|
||||||
}
|
}
|
||||||
@ -964,10 +968,10 @@ 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 (StringSet<>::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();
|
||||||
bool hasQuote = p[0]=='\"';
|
bool hasQuote = p[0]=='\"';
|
||||||
printSuffixedName(p, "$stub");
|
printSuffixedName(p, "$stub");
|
||||||
O << ":\n";
|
O << ":\n";
|
||||||
@ -1019,10 +1023,10 @@ 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 (StringSet<>::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();
|
||||||
printSuffixedName(p, "$stub");
|
printSuffixedName(p, "$stub");
|
||||||
O << ":\n";
|
O << ":\n";
|
||||||
O << "\t.indirect_symbol " << p << '\n';
|
O << "\t.indirect_symbol " << p << '\n';
|
||||||
@ -1055,39 +1059,31 @@ bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
|
|||||||
// Only referenced functions get into the Personalities list.
|
// Only referenced functions get into the Personalities list.
|
||||||
const std::vector<Function *> &Personalities = MMI->getPersonalities();
|
const std::vector<Function *> &Personalities = MMI->getPersonalities();
|
||||||
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) GVStubs.insert("_" + (*I)->getName());
|
if (*I)
|
||||||
|
GVStubs[Mang->getMangledName(*I)] =
|
||||||
|
Mang->getMangledName(*I, "$non_lazy_ptr", true);;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output stubs for external and common global variables.
|
// Output stubs for external and common global variables.
|
||||||
if (!GVStubs.empty()) {
|
if (!GVStubs.empty()) {
|
||||||
SwitchToDataSection(".non_lazy_symbol_pointer");
|
SwitchToDataSection(".non_lazy_symbol_pointer");
|
||||||
for (StringSet<>::iterator i = GVStubs.begin(), e = GVStubs.end();
|
for (StringMap<std::string>::iterator I = GVStubs.begin(),
|
||||||
i != e; ++i) {
|
E = GVStubs.end(); I != E; ++I) {
|
||||||
std::string p = i->getKeyData();
|
O << I->second << ":\n";
|
||||||
printSuffixedName(p, "$non_lazy_ptr");
|
O << "\t.indirect_symbol " << I->getKeyData() << '\n';
|
||||||
O << ":\n";
|
O << (isPPC64 ? "\t.quad\t0\n" : "\t.long\t0\n");
|
||||||
O << "\t.indirect_symbol " << p << '\n';
|
|
||||||
if (isPPC64)
|
|
||||||
O << "\t.quad\t0\n";
|
|
||||||
else
|
|
||||||
O << "\t.long\t0\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!HiddenGVStubs.empty()) {
|
if (!HiddenGVStubs.empty()) {
|
||||||
SwitchToSection(TAI->getDataSection());
|
SwitchToSection(TAI->getDataSection());
|
||||||
for (StringSet<>::iterator i = HiddenGVStubs.begin(), e = HiddenGVStubs.end();
|
|
||||||
i != e; ++i) {
|
|
||||||
std::string p = i->getKeyData();
|
|
||||||
EmitAlignment(isPPC64 ? 3 : 2);
|
EmitAlignment(isPPC64 ? 3 : 2);
|
||||||
printSuffixedName(p, "$non_lazy_ptr");
|
for (StringMap<std::string>::iterator I = HiddenGVStubs.begin(),
|
||||||
O << ":\n";
|
E = HiddenGVStubs.end(); I != E; ++I) {
|
||||||
if (isPPC64)
|
O << I->second << ":\n";
|
||||||
O << "\t.quad\t";
|
O << (isPPC64 ? "\t.quad\t" : "\t.long\t") << I->getKeyData() << '\n';
|
||||||
else
|
|
||||||
O << "\t.long\t";
|
|
||||||
O << p << '\n';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user