[PATCH] D80402: [NFC][XCOFF][AIX] Return function entry point symbol with dedicate function

Jason Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 21 13:32:54 PDT 2020


jasonliu created this revision.
jasonliu added reviewers: hubert.reinterpretcast, DiggerLin, daltenty.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Use getFunctionEntryPointSymbol whenever possible to enclose the implementation detail and reduce duplicate logic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80402

Files:
  llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
  llvm/include/llvm/Target/TargetLoweringObjectFile.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp


Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -2146,6 +2146,13 @@
   llvm_unreachable("Unknown linkage type!");
 }
 
+MCSymbol *TargetLoweringObjectFileXCOFF::getFunctionEntryPointSymbol(
+    const Function *F, const TargetMachine &TM) const {
+  SmallString<128> NameStr;
+  getNameWithPrefix(NameStr, F, TM);
+  return getContext().getOrCreateSymbol("." + NameStr);
+}
+
 MCSection *TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor(
     const Function *F, const TargetMachine &TM) const {
   SmallString<128> NameStr;
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1499,6 +1499,8 @@
   // Emit remaining GOT equivalent globals.
   emitGlobalGOTEquivs();
 
+  const TargetLoweringObjectFile &TLOF = getObjFileLowering();
+
   // Emit linkage(XCOFF) and visibility info for declarations
   for (const Function &F : M) {
     if (!F.isDeclarationForLinker())
@@ -1509,8 +1511,7 @@
     if (TM.getTargetTriple().isOSBinFormatXCOFF() && !F.isIntrinsic()) {
 
       // Get the function entry point symbol.
-      MCSymbol *FnEntryPointSym = OutContext.getOrCreateSymbol(
-          "." + cast<MCSymbolXCOFF>(Name)->getUnqualifiedName());
+      MCSymbol *FnEntryPointSym = TLOF.getFunctionEntryPointSymbol(&F, TM);
       if (cast<MCSymbolXCOFF>(FnEntryPointSym)->hasRepresentedCsectSet())
         // Emit linkage for the function entry point.
         emitLinkage(&F, FnEntryPointSym);
@@ -1532,8 +1533,6 @@
   if (remarks::RemarkStreamer *RS = M.getContext().getMainRemarkStreamer())
     emitRemarksSection(*RS);
 
-  const TargetLoweringObjectFile &TLOF = getObjFileLowering();
-
   TLOF.emitModuleMetadata(*OutStreamer, M);
 
   if (TM.getTargetTriple().isOSBinFormatELF()) {
@@ -1782,8 +1781,7 @@
                                " initalized first.");
 
     // Get the function entry point symbol.
-    CurrentFnSym = OutContext.getOrCreateSymbol(
-        "." + cast<MCSymbolXCOFF>(CurrentFnDescSym)->getUnqualifiedName());
+    CurrentFnSym = getObjFileLowering().getFunctionEntryPointSymbol(&F, TM);
   }
 
   CurrentFnSymForSize = CurrentFnSym;
Index: llvm/include/llvm/Target/TargetLoweringObjectFile.h
===================================================================
--- llvm/include/llvm/Target/TargetLoweringObjectFile.h
+++ llvm/include/llvm/Target/TargetLoweringObjectFile.h
@@ -244,6 +244,13 @@
     return nullptr;
   }
 
+  /// If supported, return the function entry point symbol.
+  /// Otherwise, returns nulltpr.
+  virtual MCSymbol *getFunctionEntryPointSymbol(const Function *F,
+                                                const TargetMachine &TM) const {
+    return nullptr;
+  }
+
 protected:
   virtual MCSection *SelectSectionForGlobal(const GlobalObject *GO,
                                             SectionKind Kind,
Index: llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
+++ llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
@@ -262,6 +262,9 @@
   /// For functions, this will always return a function descriptor symbol.
   MCSymbol *getTargetSymbol(const GlobalValue *GV,
                             const TargetMachine &TM) const override;
+
+  MCSymbol *getFunctionEntryPointSymbol(const Function *F,
+                                        const TargetMachine &TM) const override;
 };
 
 } // end namespace llvm


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80402.265585.patch
Type: text/x-patch
Size: 3782 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200521/9b3d1e49/attachment.bin>


More information about the llvm-commits mailing list