@@ -83,8 +83,6 @@ class PPCAsmPrinter : public AsmPrinter {
8383 const PPCSubtarget *Subtarget = nullptr ;
8484 StackMaps SM;
8585
86- virtual MCSymbol *getMCSymbolForTOCPseudoMO (const MachineOperand &MO);
87-
8886public:
8987 explicit PPCAsmPrinter (TargetMachine &TM,
9088 std::unique_ptr<MCStreamer> Streamer)
@@ -150,8 +148,6 @@ class PPCLinuxAsmPrinter : public PPCAsmPrinter {
150148class PPCAIXAsmPrinter : public PPCAsmPrinter {
151149private:
152150 static void ValidateGV (const GlobalVariable *GV);
153- protected:
154- MCSymbol *getMCSymbolForTOCPseudoMO (const MachineOperand &MO) override ;
155151
156152public:
157153 PPCAIXAsmPrinter (TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
@@ -161,8 +157,6 @@ class PPCAIXAsmPrinter : public PPCAsmPrinter {
161157
162158 void SetupMachineFunction (MachineFunction &MF) override ;
163159
164- const MCExpr *lowerConstant (const Constant *CV) override ;
165-
166160 void emitGlobalVariable (const GlobalVariable *GV) override ;
167161
168162 void emitFunctionDescriptor () override ;
@@ -494,16 +488,17 @@ void PPCAsmPrinter::EmitTlsCall(const MachineInstr *MI,
494488
495489// / Map a machine operand for a TOC pseudo-machine instruction to its
496490// / corresponding MCSymbol.
497- MCSymbol *PPCAsmPrinter::getMCSymbolForTOCPseudoMO (const MachineOperand &MO) {
491+ static MCSymbol *getMCSymbolForTOCPseudoMO (const MachineOperand &MO,
492+ AsmPrinter &AP) {
498493 switch (MO.getType ()) {
499494 case MachineOperand::MO_GlobalAddress:
500- return getSymbol (MO.getGlobal ());
495+ return AP. getSymbol (MO.getGlobal ());
501496 case MachineOperand::MO_ConstantPoolIndex:
502- return GetCPISymbol (MO.getIndex ());
497+ return AP. GetCPISymbol (MO.getIndex ());
503498 case MachineOperand::MO_JumpTableIndex:
504- return GetJTISymbol (MO.getIndex ());
499+ return AP. GetJTISymbol (MO.getIndex ());
505500 case MachineOperand::MO_BlockAddress:
506- return GetBlockAddressSymbol (MO.getBlockAddress ());
501+ return AP. GetBlockAddressSymbol (MO.getBlockAddress ());
507502 default :
508503 llvm_unreachable (" Unexpected operand type to get symbol." );
509504 }
@@ -664,7 +659,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
664659 " Invalid operand for LWZtoc." );
665660
666661 // Map the operand to its corresponding MCSymbol.
667- const MCSymbol *const MOSymbol = getMCSymbolForTOCPseudoMO (MO);
662+ const MCSymbol *const MOSymbol = getMCSymbolForTOCPseudoMO (MO, * this );
668663
669664 // Create a reference to the GOT entry for the symbol. The GOT entry will be
670665 // synthesized later.
@@ -723,7 +718,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
723718 // global address operand to be a reference to the TOC entry we will
724719 // synthesize later.
725720 MCSymbol *TOCEntry =
726- lookUpOrCreateTOCEntry (getMCSymbolForTOCPseudoMO (MO));
721+ lookUpOrCreateTOCEntry (getMCSymbolForTOCPseudoMO (MO, * this ));
727722
728723 const MCSymbolRefExpr::VariantKind VK =
729724 IsAIX ? MCSymbolRefExpr::VK_None : MCSymbolRefExpr::VK_PPC_TOC;
@@ -749,7 +744,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
749744 " Invalid operand for ADDIStocHA." );
750745
751746 // Map the machine operand to its corresponding MCSymbol.
752- MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO);
747+ MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO, * this );
753748
754749 // Always use TOC on AIX. Map the global address operand to be a reference
755750 // to the TOC entry we will synthesize later. 'TOCEntry' is a label used to
@@ -779,7 +774,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
779774 " Invalid operand for LWZtocL." );
780775
781776 // Map the machine operand to its corresponding MCSymbol.
782- MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO);
777+ MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO, * this );
783778
784779 // Always use TOC on AIX. Map the global address operand to be a reference
785780 // to the TOC entry we will synthesize later. 'TOCEntry' is a label used to
@@ -807,7 +802,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
807802 assert ((MO.isGlobal () || MO.isCPI () || MO.isJTI () || MO.isBlockAddress ()) &&
808803 " Invalid operand for ADDIStocHA8!" );
809804
810- const MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO);
805+ const MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO, * this );
811806
812807 const bool GlobalToc =
813808 MO.isGlobal () && Subtarget->isGVIndirectSymbol (MO.getGlobal ());
@@ -851,7 +846,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
851846 " LDtocL used on symbol that could be accessed directly is "
852847 " invalid. Must match ADDIStocHA8." ));
853848
854- const MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO);
849+ const MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO, * this );
855850
856851 if (!MO.isCPI () || TM.getCodeModel () == CodeModel::Large)
857852 MOSymbol = lookUpOrCreateTOCEntry (MOSymbol);
@@ -881,7 +876,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
881876 " Interposable definitions must use indirect access." ));
882877
883878 const MCExpr *Exp =
884- MCSymbolRefExpr::create (getMCSymbolForTOCPseudoMO (MO),
879+ MCSymbolRefExpr::create (getMCSymbolForTOCPseudoMO (MO, * this ),
885880 MCSymbolRefExpr::VK_PPC_TOC_LO, OutContext);
886881 TmpInst.getOperand (2 ) = MCOperand::createExpr (Exp);
887882 EmitToStreamer (*OutStreamer, TmpInst);
@@ -1599,18 +1594,6 @@ void PPCAIXAsmPrinter::ValidateGV(const GlobalVariable *GV) {
15991594 report_fatal_error (" COMDAT not yet supported by AIX." );
16001595}
16011596
1602- const MCExpr *PPCAIXAsmPrinter::lowerConstant (const Constant *CV) {
1603- if (const Function *F = dyn_cast<Function>(CV)) {
1604- MCSectionXCOFF *Csect = cast<MCSectionXCOFF>(
1605- F->isDeclaration ()
1606- ? getObjFileLowering ().getSectionForExternalReference (F, TM)
1607- : getObjFileLowering ().getSectionForFunctionDescriptor (F, TM));
1608-
1609- return MCSymbolRefExpr::create (Csect->getQualNameSymbol (), OutContext);
1610- }
1611- return PPCAsmPrinter::lowerConstant (CV);
1612- }
1613-
16141597static bool isSpecialLLVMGlobalArrayForStaticInit (const GlobalVariable *GV) {
16151598 return StringSwitch<bool >(GV->getName ())
16161599 .Cases (" llvm.global_ctors" , " llvm.global_dtors" , true )
@@ -1632,25 +1615,18 @@ void PPCAIXAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
16321615 GVSym->setStorageClass (
16331616 TargetLoweringObjectFileXCOFF::getStorageClassForGlobal (GV));
16341617
1635- SectionKind GVKind;
1636-
1637- // Create the containing csect and set it. We set it for externals as well,
1638- // since this may not have been set elsewhere depending on how they are used.
1639- MCSectionXCOFF *Csect = cast<MCSectionXCOFF>(
1640- GV->isDeclaration ()
1641- ? getObjFileLowering ().getSectionForExternalReference (GV, TM)
1642- : getObjFileLowering ().SectionForGlobal (
1643- GV, GVKind = getObjFileLowering ().getKindForGlobal (GV, TM),
1644- TM));
1645-
16461618 // External global variables are already handled.
16471619 if (GV->isDeclaration ())
16481620 return ;
16491621
1622+ SectionKind GVKind = getObjFileLowering ().getKindForGlobal (GV, TM);
16501623 if (!GVKind.isGlobalWriteableData () && !GVKind.isReadOnly ())
16511624 report_fatal_error (" Encountered a global variable kind that is "
16521625 " not supported yet." );
16531626
1627+ MCSectionXCOFF *Csect = cast<MCSectionXCOFF>(
1628+ getObjFileLowering ().SectionForGlobal (GV, GVKind, TM));
1629+
16541630 // Switch to the containing csect.
16551631 OutStreamer->SwitchSection (Csect);
16561632
@@ -1664,9 +1640,10 @@ void PPCAIXAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
16641640
16651641 if (GVKind.isBSSLocal ())
16661642 OutStreamer->emitXCOFFLocalCommonSymbol (
1667- GVSym, Size, Csect->getQualNameSymbol (), Align);
1643+ OutContext.getOrCreateSymbol (GVSym->getUnqualifiedName ()), Size,
1644+ GVSym, Align);
16681645 else
1669- OutStreamer->emitCommonSymbol (Csect-> getQualNameSymbol () , Size, Align);
1646+ OutStreamer->emitCommonSymbol (GVSym , Size, Align);
16701647 return ;
16711648 }
16721649
@@ -1733,55 +1710,6 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) {
17331710 }
17341711}
17351712
1736- MCSymbol *
1737- PPCAIXAsmPrinter::getMCSymbolForTOCPseudoMO (const MachineOperand &MO) {
1738- const GlobalObject *GO = nullptr ;
1739-
1740- // If the MO is a function or certain kind of globals, we want to make sure to
1741- // refer to the csect symbol, otherwise we can just do the default handling.
1742- if (MO.getType () != MachineOperand::MO_GlobalAddress ||
1743- !(GO = dyn_cast<const GlobalObject>(MO.getGlobal ())))
1744- return PPCAsmPrinter::getMCSymbolForTOCPseudoMO (MO);
1745-
1746- // Do an early error check for globals we don't support. This will go away
1747- // eventually.
1748- const auto *GV = dyn_cast<const GlobalVariable>(GO);
1749- if (GV) {
1750- ValidateGV (GV);
1751- }
1752-
1753- // If the global object is a global variable without initializer or is a
1754- // declaration of a function, then XSym is an external referenced symbol.
1755- // Hence we may need to explictly create a MCSectionXCOFF for it so that we
1756- // can return its symbol later.
1757- if (GO->isDeclaration ()) {
1758- return cast<MCSectionXCOFF>(
1759- getObjFileLowering ().getSectionForExternalReference (GO, TM))
1760- ->getQualNameSymbol ();
1761- }
1762-
1763- // Handle initialized global variables and defined functions.
1764- SectionKind GOKind = getObjFileLowering ().getKindForGlobal (GO, TM);
1765-
1766- if (GOKind.isText ()) {
1767- // If the MO is a function, we want to make sure to refer to the function
1768- // descriptor csect.
1769- return cast<MCSectionXCOFF>(
1770- getObjFileLowering ().getSectionForFunctionDescriptor (
1771- cast<const Function>(GO), TM))
1772- ->getQualNameSymbol ();
1773- } else if (GOKind.isCommon () || GOKind.isBSSLocal ()) {
1774- // If the operand is a common then we should refer to the csect symbol.
1775- return cast<MCSectionXCOFF>(
1776- getObjFileLowering ().SectionForGlobal (GO, GOKind, TM))
1777- ->getQualNameSymbol ();
1778- }
1779-
1780- // Other global variables are refered to by labels inside of a single csect,
1781- // so refer to the label directly.
1782- return getSymbol (GV);
1783- }
1784-
17851713// / createPPCAsmPrinterPass - Returns a pass that prints the PPC assembly code
17861714// / for a MachineFunction to the given output stream, in a format that the
17871715// / Darwin assembler can deal with.
0 commit comments