diff options
Diffstat (limited to 'llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp')
| -rw-r--r-- | llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 88 |
1 files changed, 59 insertions, 29 deletions
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp index 780981806996..22f35c8fa8d3 100644 --- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -34,6 +34,7 @@ #include "llvm/BinaryFormat/ELF.h" #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/CodeGen/MachineBasicBlock.h" +#include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineModuleInfoImpls.h" @@ -254,6 +255,8 @@ public: void emitFunctionBodyEnd() override; + void emitPGORefs(); + void emitEndOfAsmFile(Module &) override; void emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const override; @@ -879,7 +882,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) { // Print MO for better readability if (isVerbose()) - OutStreamer->GetCommentOS() << MO << '\n'; + OutStreamer->getCommentOS() << MO << '\n'; EmitToStreamer(*OutStreamer, TmpInst); return; } @@ -950,7 +953,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) { // Print MO for better readability if (isVerbose() && IsAIX) - OutStreamer->GetCommentOS() << MO << '\n'; + OutStreamer->getCommentOS() << MO << '\n'; EmitToStreamer(*OutStreamer, TmpInst); return; } @@ -1582,7 +1585,7 @@ void PPCLinuxAsmPrinter::emitStartOfAsmFile(Module &M) { if (M.getPICLevel() == PICLevel::SmallPIC) return AsmPrinter::emitStartOfAsmFile(M); - OutStreamer->SwitchSection(OutContext.getELFSection( + OutStreamer->switchSection(OutContext.getELFSection( ".got2", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC)); MCSymbol *TOCSym = OutContext.getOrCreateSymbol(Twine(".LTOC")); @@ -1599,7 +1602,7 @@ void PPCLinuxAsmPrinter::emitStartOfAsmFile(Module &M) { OutStreamer->emitAssignment(TOCSym, tocExpr); - OutStreamer->SwitchSection(getObjFileLowering().getTextSection()); + OutStreamer->switchSection(getObjFileLowering().getTextSection()); } void PPCLinuxAsmPrinter::emitFunctionEntryLabel() { @@ -1657,7 +1660,7 @@ void PPCLinuxAsmPrinter::emitFunctionEntryLabel() { MCSectionSubPair Current = OutStreamer->getCurrentSection(); MCSectionELF *Section = OutStreamer->getContext().getELFSection( ".opd", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC); - OutStreamer->SwitchSection(Section); + OutStreamer->switchSection(Section); OutStreamer->emitLabel(CurrentFnSym); OutStreamer->emitValueToAlignment(8); MCSymbol *Symbol1 = CurrentFnSymForSize; @@ -1672,7 +1675,7 @@ void PPCLinuxAsmPrinter::emitFunctionEntryLabel() { 8/*size*/); // Emit a null environment pointer. OutStreamer->emitIntValue(0, 8 /* size */); - OutStreamer->SwitchSection(Current.first, Current.second); + OutStreamer->switchSection(Current.first, Current.second); } void PPCLinuxAsmPrinter::emitEndOfAsmFile(Module &M) { @@ -1689,7 +1692,7 @@ void PPCLinuxAsmPrinter::emitEndOfAsmFile(Module &M) { const char *Name = isPPC64 ? ".toc" : ".got2"; MCSectionELF *Section = OutContext.getELFSection( Name, ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC); - OutStreamer->SwitchSection(Section); + OutStreamer->switchSection(Section); if (!isPPC64) OutStreamer->emitValueToAlignment(4); @@ -1895,10 +1898,15 @@ void PPCAIXAsmPrinter::emitLinkage(const GlobalValue *GV, MCSymbolAttr VisibilityAttr = MCSA_Invalid; if (!TM.getIgnoreXCOFFVisibility()) { + if (GV->hasDLLExportStorageClass() && !GV->hasDefaultVisibility()) + report_fatal_error( + "Cannot not be both dllexport and non-default visibility"); switch (GV->getVisibility()) { - // TODO: "exported" and "internal" Visibility needs to go here. + // TODO: "internal" Visibility needs to go here. case GlobalValue::DefaultVisibility: + if (GV->hasDLLExportStorageClass()) + VisibilityAttr = MAI->getExportedVisibilityAttr(); break; case GlobalValue::HiddenVisibility: VisibilityAttr = MAI->getHiddenVisibilityAttr(); @@ -1956,7 +1964,7 @@ void PPCAIXAsmPrinter::emitFunctionBodyEnd() { if (!TargetLoweringObjectFileXCOFF::ShouldEmitEHBlock(MF) && (getNumberOfVRSaved() > 0)) { // Emit dummy EH Info Table. - OutStreamer->SwitchSection(getObjFileLowering().getCompactUnwindSection()); + OutStreamer->switchSection(getObjFileLowering().getCompactUnwindSection()); MCSymbol *EHInfoLabel = TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol(MF); OutStreamer->emitLabel(EHInfoLabel); @@ -1971,7 +1979,7 @@ void PPCAIXAsmPrinter::emitFunctionBodyEnd() { OutStreamer->emitIntValue(0, PointerSize); OutStreamer->emitIntValue(0, PointerSize); - OutStreamer->SwitchSection(MF->getSection()); + OutStreamer->switchSection(MF->getSection()); } } @@ -2382,9 +2390,9 @@ void PPCAIXAsmPrinter::emitGlobalVariableHelper(const GlobalVariable *GV) { // Print GV in verbose mode if (isVerbose()) { if (GV->hasInitializer()) { - GV->printAsOperand(OutStreamer->GetCommentOS(), + GV->printAsOperand(OutStreamer->getCommentOS(), /*PrintType=*/false, GV->getParent()); - OutStreamer->GetCommentOS() << '\n'; + OutStreamer->getCommentOS() << '\n'; } } @@ -2392,14 +2400,14 @@ void PPCAIXAsmPrinter::emitGlobalVariableHelper(const GlobalVariable *GV) { getObjFileLowering().SectionForGlobal(GV, GVKind, TM)); // Switch to the containing csect. - OutStreamer->SwitchSection(Csect); + OutStreamer->switchSection(Csect); const DataLayout &DL = GV->getParent()->getDataLayout(); // Handle common and zero-initialized local symbols. if (GV->hasCommonLinkage() || GVKind.isBSSLocal() || GVKind.isThreadBSSLocal()) { - Align Alignment = GV->getAlign().getValueOr(DL.getPreferredAlign(GV)); + Align Alignment = GV->getAlign().value_or(DL.getPreferredAlign(GV)); uint64_t Size = DL.getTypeAllocSize(GV->getValueType()); GVSym->setStorageClass( TargetLoweringObjectFileXCOFF::getStorageClassForGlobal(GV)); @@ -2424,9 +2432,8 @@ void PPCAIXAsmPrinter::emitGlobalVariableHelper(const GlobalVariable *GV) { } // Emit aliasing label for global variable. - llvm::for_each(GOAliasMap[GV], [this](const GlobalAlias *Alias) { + for (const GlobalAlias *Alias : GOAliasMap[GV]) OutStreamer->emitLabel(getSymbol(Alias)); - }); emitGlobalConstant(GV->getParent()->getDataLayout(), GV->getInitializer()); } @@ -2437,14 +2444,12 @@ void PPCAIXAsmPrinter::emitFunctionDescriptor() { MCSectionSubPair Current = OutStreamer->getCurrentSection(); // Emit function descriptor. - OutStreamer->SwitchSection( + OutStreamer->switchSection( cast<MCSymbolXCOFF>(CurrentFnDescSym)->getRepresentedCsect()); // Emit aliasing label for function descriptor csect. - llvm::for_each(GOAliasMap[&MF->getFunction()], - [this](const GlobalAlias *Alias) { - OutStreamer->emitLabel(getSymbol(Alias)); - }); + for (const GlobalAlias *Alias : GOAliasMap[&MF->getFunction()]) + OutStreamer->emitLabel(getSymbol(Alias)); // Emit function entry point address. OutStreamer->emitValue(MCSymbolRefExpr::create(CurrentFnSym, OutContext), @@ -2458,7 +2463,7 @@ void PPCAIXAsmPrinter::emitFunctionDescriptor() { // Emit a null environment pointer. OutStreamer->emitIntValue(0, PointerSize); - OutStreamer->SwitchSection(Current.first, Current.second); + OutStreamer->switchSection(Current.first, Current.second); } void PPCAIXAsmPrinter::emitFunctionEntryLabel() { @@ -2468,11 +2473,34 @@ void PPCAIXAsmPrinter::emitFunctionEntryLabel() { PPCAsmPrinter::emitFunctionEntryLabel(); // Emit aliasing label for function entry point label. - llvm::for_each( - GOAliasMap[&MF->getFunction()], [this](const GlobalAlias *Alias) { - OutStreamer->emitLabel( - getObjFileLowering().getFunctionEntryPointSymbol(Alias, TM)); - }); + for (const GlobalAlias *Alias : GOAliasMap[&MF->getFunction()]) + OutStreamer->emitLabel( + getObjFileLowering().getFunctionEntryPointSymbol(Alias, TM)); +} + +void PPCAIXAsmPrinter::emitPGORefs() { + if (OutContext.hasXCOFFSection( + "__llvm_prf_cnts", + XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD))) { + MCSection *CntsSection = OutContext.getXCOFFSection( + "__llvm_prf_cnts", SectionKind::getData(), + XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD), + /*MultiSymbolsAllowed*/ true); + + OutStreamer->switchSection(CntsSection); + if (OutContext.hasXCOFFSection( + "__llvm_prf_data", + XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD))) + OutStreamer->emitXCOFFRefDirective("__llvm_prf_data[RW]"); + if (OutContext.hasXCOFFSection( + "__llvm_prf_names", + XCOFF::CsectProperties(XCOFF::XMC_RO, XCOFF::XTY_SD))) + OutStreamer->emitXCOFFRefDirective("__llvm_prf_names[RO]"); + if (OutContext.hasXCOFFSection( + "__llvm_prf_vnds", + XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD))) + OutStreamer->emitXCOFFRefDirective("__llvm_prf_vnds[RW]"); + } } void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) { @@ -2481,8 +2509,10 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) { if (M.empty() && TOCDataGlobalVars.empty()) return; + emitPGORefs(); + // Switch to section to emit TOC base. - OutStreamer->SwitchSection(getObjFileLowering().getTOCBaseSection()); + OutStreamer->switchSection(getObjFileLowering().getTOCBaseSection()); PPCTargetStreamer *TS = static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer()); @@ -2504,7 +2534,7 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) { TCEntry = cast<MCSectionXCOFF>( getObjFileLowering().getSectionForTOCEntry(I.first.first, TM)); } - OutStreamer->SwitchSection(TCEntry); + OutStreamer->switchSection(TCEntry); OutStreamer->emitLabel(I.second); if (TS != nullptr) |
