Skip to content

Commit 8d9ff23

Browse files
committed
[NFC][XCOFF][AIX] Return function entry point symbol with dedicate function
Use getFunctionEntryPointSymbol whenever possible to enclose the implementation detail and reduce duplicate logic. Differential Revision: https://reviews.llvm.org/D80402
1 parent d37ce53 commit 8d9ff23

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ class TargetLoweringObjectFileXCOFF : public TargetLoweringObjectFile {
262262
/// For functions, this will always return a function descriptor symbol.
263263
MCSymbol *getTargetSymbol(const GlobalValue *GV,
264264
const TargetMachine &TM) const override;
265+
266+
MCSymbol *getFunctionEntryPointSymbol(const Function *F,
267+
const TargetMachine &TM) const override;
265268
};
266269

267270
} // end namespace llvm

llvm/include/llvm/Target/TargetLoweringObjectFile.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
245245
return nullptr;
246246
}
247247

248+
/// If supported, return the function entry point symbol.
249+
/// Otherwise, returns nulltpr.
250+
virtual MCSymbol *getFunctionEntryPointSymbol(const Function *F,
251+
const TargetMachine &TM) const {
252+
return nullptr;
253+
}
254+
248255
protected:
249256
virtual MCSection *SelectSectionForGlobal(const GlobalObject *GO,
250257
SectionKind Kind,

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,8 @@ bool AsmPrinter::doFinalization(Module &M) {
15031503
// Emit remaining GOT equivalent globals.
15041504
emitGlobalGOTEquivs();
15051505

1506+
const TargetLoweringObjectFile &TLOF = getObjFileLowering();
1507+
15061508
// Emit linkage(XCOFF) and visibility info for declarations
15071509
for (const Function &F : M) {
15081510
if (!F.isDeclarationForLinker())
@@ -1513,8 +1515,7 @@ bool AsmPrinter::doFinalization(Module &M) {
15131515
if (TM.getTargetTriple().isOSBinFormatXCOFF() && !F.isIntrinsic()) {
15141516

15151517
// Get the function entry point symbol.
1516-
MCSymbol *FnEntryPointSym = OutContext.getOrCreateSymbol(
1517-
"." + cast<MCSymbolXCOFF>(Name)->getUnqualifiedName());
1518+
MCSymbol *FnEntryPointSym = TLOF.getFunctionEntryPointSymbol(&F, TM);
15181519
if (cast<MCSymbolXCOFF>(FnEntryPointSym)->hasRepresentedCsectSet())
15191520
// Emit linkage for the function entry point.
15201521
emitLinkage(&F, FnEntryPointSym);
@@ -1536,8 +1537,6 @@ bool AsmPrinter::doFinalization(Module &M) {
15361537
if (remarks::RemarkStreamer *RS = M.getContext().getMainRemarkStreamer())
15371538
emitRemarksSection(*RS);
15381539

1539-
const TargetLoweringObjectFile &TLOF = getObjFileLowering();
1540-
15411540
TLOF.emitModuleMetadata(*OutStreamer, M);
15421541

15431542
if (TM.getTargetTriple().isOSBinFormatELF()) {
@@ -1786,8 +1785,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
17861785
" initalized first.");
17871786

17881787
// Get the function entry point symbol.
1789-
CurrentFnSym = OutContext.getOrCreateSymbol(
1790-
"." + cast<MCSymbolXCOFF>(CurrentFnDescSym)->getUnqualifiedName());
1788+
CurrentFnSym = getObjFileLowering().getFunctionEntryPointSymbol(&F, TM);
17911789
}
17921790

17931791
CurrentFnSymForSize = CurrentFnSym;

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,14 @@ XCOFF::StorageClass TargetLoweringObjectFileXCOFF::getStorageClassForGlobal(
21502150
llvm_unreachable("Unknown linkage type!");
21512151
}
21522152

2153+
MCSymbol *TargetLoweringObjectFileXCOFF::getFunctionEntryPointSymbol(
2154+
const Function *F, const TargetMachine &TM) const {
2155+
SmallString<128> NameStr;
2156+
NameStr.push_back('.');
2157+
getNameWithPrefix(NameStr, F, TM);
2158+
return getContext().getOrCreateSymbol(NameStr);
2159+
}
2160+
21532161
MCSection *TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor(
21542162
const Function *F, const TargetMachine &TM) const {
21552163
SmallString<128> NameStr;

0 commit comments

Comments
 (0)