llvm.org GIT mirror llvm / 656bb20
just finish MCizing FnStubInfo which cleans it up and simplifies it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93334 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
1 changed file(s) with 33 addition(s) and 48 deletion(s). Raw diff Collapse all Expand all
5858 class PPCAsmPrinter : public AsmPrinter {
5959 protected:
6060 struct FnStubInfo {
61 std::string StubName, LazyPtrName, AnonSymbolName;
62 MCSymbol *StubSym, *LazyPtrSym, *AnonSymbolSym;
61 MCSymbol *Stub, *LazyPtr, *AnonSymbol;
6362
6463 FnStubInfo() {
65 StubSym = LazyPtrSym = AnonSymbolSym = 0;
64 Stub = LazyPtr = AnonSymbol = 0;
6665 }
6766
68 void Init(const GlobalValue *GV, Mangler *Mang) {
67 void Init(const GlobalValue *GV, Mangler *Mang, MCContext &Ctx) {
6968 // Already initialized.
70 if (!StubName.empty()) return;
69 if (Stub != 0) return;
7170
7271 // Get the names.
73 StubName = Mang->getMangledName(GV, "$stub", true);
74 LazyPtrName = Mang->getMangledName(GV, "$lazy_ptr", true);
75 AnonSymbolName = Mang->getMangledName(GV, "$stub$tmp", true);
72 SmallString<128> TmpStr;
73 Mang->getNameWithPrefix(TmpStr, GV, true);
74 MakeSymbols(TmpStr, Ctx);
7675 }
7776
7877 void Init(StringRef GVName, Mangler *Mang, MCContext &Ctx) {
79 assert(!GVName.empty());
80 if (StubSym != 0) return; // Already initialized.
78 assert(!GVName.empty() && "external symbol name shouldn't be empty");
79 if (Stub != 0) return; // Already initialized.
8180 // Get the names for the external symbol name.
8281 SmallString<128> TmpStr;
83 Mang->getNameWithPrefix(TmpStr, GVName + "$stub", Mangler::Private);
84 StubSym = Ctx.GetOrCreateSymbol(TmpStr.str());
82 Mang->getNameWithPrefix(TmpStr, GVName, Mangler::Private);
83 MakeSymbols(TmpStr, Ctx);
84 }
85
86 void MakeSymbols(SmallString<128> &TmpStr, MCContext &Ctx) {
87 TmpStr += "$stub";
88 Stub = Ctx.GetOrCreateSymbol(TmpStr.str());
8589 TmpStr.erase(TmpStr.end()-5, TmpStr.end()); // Remove $stub
8690
8791 TmpStr += "$lazy_ptr";
88 LazyPtrSym = Ctx.GetOrCreateSymbol(TmpStr.str());
92 LazyPtr = Ctx.GetOrCreateSymbol(TmpStr.str());
8993 TmpStr.erase(TmpStr.end()-9, TmpStr.end()); // Remove $lazy_ptr
9094
9195 TmpStr += "$stub$tmp";
92 AnonSymbolSym = Ctx.GetOrCreateSymbol(TmpStr.str());
93 }
94
95 void printStub(raw_ostream &OS, const MCAsmInfo *MAI) const {
96 if (StubSym)
97 StubSym->print(OS, MAI);
98 else
99 OS << StubName;
100 }
101 void printLazyPtr(raw_ostream &OS, const MCAsmInfo *MAI) const {
102 if (LazyPtrSym)
103 LazyPtrSym->print(OS, MAI);
104 else
105 OS << LazyPtrName;
106 }
107 void printAnonSymbol(raw_ostream &OS, const MCAsmInfo *MAI) const {
108 if (AnonSymbolSym)
109 AnonSymbolSym->print(OS, MAI);
110 else
111 OS << AnonSymbolName;
96 AnonSymbol = Ctx.GetOrCreateSymbol(TmpStr.str());
11297 }
11398 };
11499
255240 if (GV->isDeclaration() || GV->isWeakForLinker()) {
256241 // Dynamically-resolved functions need a stub for the function.
257242 FnStubInfo &FnInfo = FnStubs[Mang->getMangledName(GV)];
258 FnInfo.Init(GV, Mang);
259 FnInfo.printStub(O, MAI);
243 FnInfo.Init(GV, Mang, OutContext);
244 FnInfo.Stub->print(O, MAI);
260245 return;
261246 }
262247 }
265250 Mang->getNameWithPrefix(MangledName, MO.getSymbolName());
266251 FnStubInfo &FnInfo = FnStubs[MangledName.str()];
267252 FnInfo.Init(MO.getSymbolName(), Mang, OutContext);
268 FnInfo.printStub(O, MAI);
253 FnInfo.Stub->print(O, MAI);
269254 return;
270255 }
271256 }
10751060 OutStreamer.SwitchSection(StubSection);
10761061 EmitAlignment(4);
10771062 const FnStubInfo &Info = I->second;
1078 Info.printStub(O, MAI);
1063 Info.Stub->print(O, MAI);
10791064 O << ":\n";
10801065 O << "\t.indirect_symbol " << I->getKeyData() << '\n';
10811066 O << "\tmflr r0\n";
10821067 O << "\tbcl 20,31,";
1083 Info.printAnonSymbol(O, MAI);
1068 Info.AnonSymbol->print(O, MAI);
10841069 O << '\n';
1085 Info.printAnonSymbol(O, MAI);
1070 Info.AnonSymbol->print(O, MAI);
10861071 O << ":\n";
10871072 O << "\tmflr r11\n";
10881073 O << "\taddis r11,r11,ha16(";
1089 Info.printLazyPtr(O, MAI);
1074 Info.LazyPtr->print(O, MAI);
10901075 O << '-';
1091 Info.printAnonSymbol(O, MAI);
1076 Info.AnonSymbol->print(O, MAI);
10921077 O << ")\n";
10931078 O << "\tmtlr r0\n";
10941079 O << (isPPC64 ? "\tldu" : "\tlwzu") << " r12,lo16(";
1095 Info.printLazyPtr(O, MAI);
1080 Info.LazyPtr->print(O, MAI);
10961081 O << '-';
1097 Info.printAnonSymbol(O, MAI);
1082 Info.AnonSymbol->print(O, MAI);
10981083 O << ")(r11)\n";
10991084 O << "\tmtctr r12\n";
11001085 O << "\tbctr\n";
11011086
11021087 OutStreamer.SwitchSection(LSPSection);
1103 Info.printLazyPtr(O, MAI);
1088 Info.LazyPtr->print(O, MAI);
11041089 O << ":\n";
11051090 O << "\t.indirect_symbol " << I->getKeyData() << '\n';
11061091 O << (isPPC64 ? "\t.quad" : "\t.long") << " dyld_stub_binding_helper\n";
11171102 OutStreamer.SwitchSection(StubSection);
11181103 EmitAlignment(4);
11191104 const FnStubInfo &Info = I->second;
1120 Info.printStub(O, MAI);
1105 Info.Stub->print(O, MAI);
11211106 O << ":\n";
11221107 O << "\t.indirect_symbol " << I->getKeyData() << '\n';
11231108 O << "\tlis r11,ha16(";
1124 Info.printLazyPtr(O, MAI);
1109 Info.LazyPtr->print(O, MAI);
11251110 O << ")\n";
11261111 O << (isPPC64 ? "\tldu" : "\tlwzu") << " r12,lo16(";
1127 Info.printLazyPtr(O, MAI);
1112 Info.LazyPtr->print(O, MAI);
11281113 O << ")(r11)\n";
11291114 O << "\tmtctr r12\n";
11301115 O << "\tbctr\n";
11311116 OutStreamer.SwitchSection(LSPSection);
1132 Info.printLazyPtr(O, MAI);
1117 Info.LazyPtr->print(O, MAI);
11331118 O << ":\n";
11341119 O << "\t.indirect_symbol " << I->getKeyData() << '\n';
11351120 O << (isPPC64 ? "\t.quad" : "\t.long") << " dyld_stub_binding_helper\n";