@@ -83,8 +83,6 @@ class PPCAsmPrinter : public AsmPrinter {
83
83
const PPCSubtarget *Subtarget = nullptr ;
84
84
StackMaps SM;
85
85
86
- virtual MCSymbol *getMCSymbolForTOCPseudoMO (const MachineOperand &MO);
87
-
88
86
public:
89
87
explicit PPCAsmPrinter (TargetMachine &TM,
90
88
std::unique_ptr<MCStreamer> Streamer)
@@ -150,8 +148,6 @@ class PPCLinuxAsmPrinter : public PPCAsmPrinter {
150
148
class PPCAIXAsmPrinter : public PPCAsmPrinter {
151
149
private:
152
150
static void ValidateGV (const GlobalVariable *GV);
153
- protected:
154
- MCSymbol *getMCSymbolForTOCPseudoMO (const MachineOperand &MO) override ;
155
151
156
152
public:
157
153
PPCAIXAsmPrinter (TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
@@ -161,8 +157,6 @@ class PPCAIXAsmPrinter : public PPCAsmPrinter {
161
157
162
158
void SetupMachineFunction (MachineFunction &MF) override ;
163
159
164
- const MCExpr *lowerConstant (const Constant *CV) override ;
165
-
166
160
void emitGlobalVariable (const GlobalVariable *GV) override ;
167
161
168
162
void emitFunctionDescriptor () override ;
@@ -494,16 +488,17 @@ void PPCAsmPrinter::EmitTlsCall(const MachineInstr *MI,
494
488
495
489
// / Map a machine operand for a TOC pseudo-machine instruction to its
496
490
// / corresponding MCSymbol.
497
- MCSymbol *PPCAsmPrinter::getMCSymbolForTOCPseudoMO (const MachineOperand &MO) {
491
+ static MCSymbol *getMCSymbolForTOCPseudoMO (const MachineOperand &MO,
492
+ AsmPrinter &AP) {
498
493
switch (MO.getType ()) {
499
494
case MachineOperand::MO_GlobalAddress:
500
- return getSymbol (MO.getGlobal ());
495
+ return AP. getSymbol (MO.getGlobal ());
501
496
case MachineOperand::MO_ConstantPoolIndex:
502
- return GetCPISymbol (MO.getIndex ());
497
+ return AP. GetCPISymbol (MO.getIndex ());
503
498
case MachineOperand::MO_JumpTableIndex:
504
- return GetJTISymbol (MO.getIndex ());
499
+ return AP. GetJTISymbol (MO.getIndex ());
505
500
case MachineOperand::MO_BlockAddress:
506
- return GetBlockAddressSymbol (MO.getBlockAddress ());
501
+ return AP. GetBlockAddressSymbol (MO.getBlockAddress ());
507
502
default :
508
503
llvm_unreachable (" Unexpected operand type to get symbol." );
509
504
}
@@ -664,7 +659,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
664
659
" Invalid operand for LWZtoc." );
665
660
666
661
// Map the operand to its corresponding MCSymbol.
667
- const MCSymbol *const MOSymbol = getMCSymbolForTOCPseudoMO (MO);
662
+ const MCSymbol *const MOSymbol = getMCSymbolForTOCPseudoMO (MO, * this );
668
663
669
664
// Create a reference to the GOT entry for the symbol. The GOT entry will be
670
665
// synthesized later.
@@ -723,7 +718,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
723
718
// global address operand to be a reference to the TOC entry we will
724
719
// synthesize later.
725
720
MCSymbol *TOCEntry =
726
- lookUpOrCreateTOCEntry (getMCSymbolForTOCPseudoMO (MO));
721
+ lookUpOrCreateTOCEntry (getMCSymbolForTOCPseudoMO (MO, * this ));
727
722
728
723
const MCSymbolRefExpr::VariantKind VK =
729
724
IsAIX ? MCSymbolRefExpr::VK_None : MCSymbolRefExpr::VK_PPC_TOC;
@@ -749,7 +744,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
749
744
" Invalid operand for ADDIStocHA." );
750
745
751
746
// Map the machine operand to its corresponding MCSymbol.
752
- MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO);
747
+ MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO, * this );
753
748
754
749
// Always use TOC on AIX. Map the global address operand to be a reference
755
750
// to the TOC entry we will synthesize later. 'TOCEntry' is a label used to
@@ -779,7 +774,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
779
774
" Invalid operand for LWZtocL." );
780
775
781
776
// Map the machine operand to its corresponding MCSymbol.
782
- MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO);
777
+ MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO, * this );
783
778
784
779
// Always use TOC on AIX. Map the global address operand to be a reference
785
780
// to the TOC entry we will synthesize later. 'TOCEntry' is a label used to
@@ -807,7 +802,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
807
802
assert ((MO.isGlobal () || MO.isCPI () || MO.isJTI () || MO.isBlockAddress ()) &&
808
803
" Invalid operand for ADDIStocHA8!" );
809
804
810
- const MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO);
805
+ const MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO, * this );
811
806
812
807
const bool GlobalToc =
813
808
MO.isGlobal () && Subtarget->isGVIndirectSymbol (MO.getGlobal ());
@@ -851,7 +846,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
851
846
" LDtocL used on symbol that could be accessed directly is "
852
847
" invalid. Must match ADDIStocHA8." ));
853
848
854
- const MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO);
849
+ const MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO (MO, * this );
855
850
856
851
if (!MO.isCPI () || TM.getCodeModel () == CodeModel::Large)
857
852
MOSymbol = lookUpOrCreateTOCEntry (MOSymbol);
@@ -881,7 +876,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
881
876
" Interposable definitions must use indirect access." ));
882
877
883
878
const MCExpr *Exp =
884
- MCSymbolRefExpr::create (getMCSymbolForTOCPseudoMO (MO),
879
+ MCSymbolRefExpr::create (getMCSymbolForTOCPseudoMO (MO, * this ),
885
880
MCSymbolRefExpr::VK_PPC_TOC_LO, OutContext);
886
881
TmpInst.getOperand (2 ) = MCOperand::createExpr (Exp);
887
882
EmitToStreamer (*OutStreamer, TmpInst);
@@ -1599,18 +1594,6 @@ void PPCAIXAsmPrinter::ValidateGV(const GlobalVariable *GV) {
1599
1594
report_fatal_error (" COMDAT not yet supported by AIX." );
1600
1595
}
1601
1596
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
-
1614
1597
static bool isSpecialLLVMGlobalArrayForStaticInit (const GlobalVariable *GV) {
1615
1598
return StringSwitch<bool >(GV->getName ())
1616
1599
.Cases (" llvm.global_ctors" , " llvm.global_dtors" , true )
@@ -1632,25 +1615,18 @@ void PPCAIXAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
1632
1615
GVSym->setStorageClass (
1633
1616
TargetLoweringObjectFileXCOFF::getStorageClassForGlobal (GV));
1634
1617
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
-
1646
1618
// External global variables are already handled.
1647
1619
if (GV->isDeclaration ())
1648
1620
return ;
1649
1621
1622
+ SectionKind GVKind = getObjFileLowering ().getKindForGlobal (GV, TM);
1650
1623
if (!GVKind.isGlobalWriteableData () && !GVKind.isReadOnly ())
1651
1624
report_fatal_error (" Encountered a global variable kind that is "
1652
1625
" not supported yet." );
1653
1626
1627
+ MCSectionXCOFF *Csect = cast<MCSectionXCOFF>(
1628
+ getObjFileLowering ().SectionForGlobal (GV, GVKind, TM));
1629
+
1654
1630
// Switch to the containing csect.
1655
1631
OutStreamer->SwitchSection (Csect);
1656
1632
@@ -1664,9 +1640,10 @@ void PPCAIXAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
1664
1640
1665
1641
if (GVKind.isBSSLocal ())
1666
1642
OutStreamer->emitXCOFFLocalCommonSymbol (
1667
- GVSym, Size, Csect->getQualNameSymbol (), Align);
1643
+ OutContext.getOrCreateSymbol (GVSym->getUnqualifiedName ()), Size,
1644
+ GVSym, Align);
1668
1645
else
1669
- OutStreamer->emitCommonSymbol (Csect-> getQualNameSymbol () , Size, Align);
1646
+ OutStreamer->emitCommonSymbol (GVSym , Size, Align);
1670
1647
return ;
1671
1648
}
1672
1649
@@ -1733,55 +1710,6 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) {
1733
1710
}
1734
1711
}
1735
1712
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
-
1785
1713
// / createPPCAsmPrinterPass - Returns a pass that prints the PPC assembly code
1786
1714
// / for a MachineFunction to the given output stream, in a format that the
1787
1715
// / Darwin assembler can deal with.
0 commit comments