From 5e71839f7793b3ab94e928654a493cb3d7216176 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Fri, 6 Aug 2021 17:42:12 +0100 Subject: [PATCH] [MC] Add MCSubtargetInfo to MCAlignFragment In preparation for passing the MCSubtargetInfo (STI) through to writeNops so that it can use the STI in operation at the time, we need to record the STI in operation when a MCAlignFragment may write nops as padding. The STI is currently unused, a further patch will pass it through to writeNops. There are many places that can create an MCAlignFragment, in most cases we can find out the STI in operation at the time. In a few places this isn't possible as we are in initialisation or finalisation, or are emitting constant pools. When possible I've tried to find the most appropriate existing fragment to obtain the STI from, when none is available use the per module STI. For constant pools we don't actually need to use EmitCodeAlign as the constant pools are data anyway so falling through into it via an executable NOP is no better than falling through into data padding. This is a prerequisite for D45962 which uses the STI to emit the appropriate NOP for the STI. Which can differ per fragment. Note that involves an interface change to InitSections. It is now called initSections and requires a SubtargetInfo as a parameter. Differential Revision: https://reviews.llvm.org/D45961 --- clang/tools/driver/cc1as_main.cpp | 2 +- llvm/include/llvm/MC/MCELFStreamer.h | 2 +- llvm/include/llvm/MC/MCFragment.h | 10 +++++++++- llvm/include/llvm/MC/MCObjectStreamer.h | 2 +- llvm/include/llvm/MC/MCStreamer.h | 4 +++- llvm/include/llvm/MC/MCWinCOFFStreamer.h | 2 +- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 15 ++++++++++----- llvm/lib/MC/ConstantPools.cpp | 2 +- llvm/lib/MC/MCAsmStreamer.cpp | 3 ++- llvm/lib/MC/MCELFStreamer.cpp | 4 ++-- llvm/lib/MC/MCObjectStreamer.cpp | 3 ++- llvm/lib/MC/MCParser/AsmParser.cpp | 7 ++++--- llvm/lib/MC/MCParser/MasmParser.cpp | 4 ++-- llvm/lib/MC/MCStreamer.cpp | 3 ++- llvm/lib/MC/MCWinCOFFStreamer.cpp | 9 +++++---- llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 2 +- llvm/lib/Target/ARM/ARMAsmPrinter.cpp | 2 +- llvm/lib/Target/ARM/ARMMCInstLower.cpp | 2 +- llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp | 6 +++--- llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp | 2 +- llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp | 2 +- llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp | 12 +++++++----- llvm/lib/Target/Hexagon/HexagonTargetStreamer.h | 1 + llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp | 2 +- llvm/lib/Target/Mips/MipsAsmPrinter.cpp | 2 +- llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp | 2 +- llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFStreamer.cpp | 2 +- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 2 +- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp | 4 ++-- llvm/lib/Target/X86/X86MCInstLower.cpp | 10 +++++----- llvm/tools/llvm-mc/Disassembler.cpp | 2 +- llvm/tools/llvm-mc/llvm-mc.cpp | 2 +- llvm/tools/llvm-ml/Disassembler.cpp | 2 +- .../DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp | 2 +- 34 files changed, 78 insertions(+), 55 deletions(-) diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp index 086ce0e..6549b13 100644 --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -490,7 +490,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, T, Ctx, std::move(MAB), std::move(OW), std::move(CE), *STI, Opts.RelaxAll, Opts.IncrementalLinkerCompatible, /*DWARFMustBeAtTheEnd*/ true)); - Str.get()->InitSections(Opts.NoExecStack); + Str.get()->initSections(Opts.NoExecStack, *STI); } // When -fembed-bitcode is passed to clang_as, a 1-byte marker diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h index 8c1e22a..8f2b1768 100644 --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -39,7 +39,7 @@ public: /// \name MCStreamer Interface /// @{ - void InitSections(bool NoExecStack) override; + void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override; void changeSection(MCSection *Section, const MCExpr *Subsection) override; void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override; void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment *F, diff --git a/llvm/include/llvm/MC/MCFragment.h b/llvm/include/llvm/MC/MCFragment.h index f3a785f..d415e10 100644 --- a/llvm/include/llvm/MC/MCFragment.h +++ b/llvm/include/llvm/MC/MCFragment.h @@ -311,6 +311,9 @@ class MCAlignFragment : public MCFragment { /// cannot be satisfied in this width then this fragment is ignored. unsigned MaxBytesToEmit; + /// When emitting Nops some subtargets have specific nop encodings. + const MCSubtargetInfo *STI; + public: MCAlignFragment(unsigned Alignment, int64_t Value, unsigned ValueSize, unsigned MaxBytesToEmit, MCSection *Sec = nullptr) @@ -326,7 +329,12 @@ public: unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; } bool hasEmitNops() const { return EmitNops; } - void setEmitNops(bool Value) { EmitNops = Value; } + void setEmitNops(bool Value, const MCSubtargetInfo *STI) { + EmitNops = Value; + this->STI = STI; + } + + const MCSubtargetInfo *getSubtargetInfo() const { return STI; } static bool classof(const MCFragment *F) { return F->getKind() == MCFragment::FT_Align; diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h index dcdee2b..47bf347 100644 --- a/llvm/include/llvm/MC/MCObjectStreamer.h +++ b/llvm/include/llvm/MC/MCObjectStreamer.h @@ -137,7 +137,7 @@ public: void emitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0, unsigned ValueSize = 1, unsigned MaxBytesToEmit = 0) override; - void emitCodeAlignment(unsigned ByteAlignment, + void emitCodeAlignment(unsigned ByteAlignment, const MCSubtargetInfo *STI, unsigned MaxBytesToEmit = 0) override; void emitValueToOffset(const MCExpr *Offset, unsigned char Value, SMLoc Loc) override; diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h index 5f93f97..0189398 100644 --- a/llvm/include/llvm/MC/MCStreamer.h +++ b/llvm/include/llvm/MC/MCStreamer.h @@ -447,7 +447,7 @@ public: } /// Create the default sections and set the initial one. - virtual void InitSections(bool NoExecStack); + virtual void initSections(bool NoExecStack, const MCSubtargetInfo &STI); MCSymbol *endSection(MCSection *Section); @@ -833,10 +833,12 @@ public: /// /// \param ByteAlignment - The alignment to reach. This must be a power of /// two on some targets. + /// \param STI - The MCSubtargetInfo in operation when padding is emitted. /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If /// the alignment cannot be reached in this many bytes, no bytes are /// emitted. virtual void emitCodeAlignment(unsigned ByteAlignment, + const MCSubtargetInfo *STI, unsigned MaxBytesToEmit = 0); /// Emit some number of copies of \p Value until the byte offset \p diff --git a/llvm/include/llvm/MC/MCWinCOFFStreamer.h b/llvm/include/llvm/MC/MCWinCOFFStreamer.h index 53b2ef0..af1ed6f 100644 --- a/llvm/include/llvm/MC/MCWinCOFFStreamer.h +++ b/llvm/include/llvm/MC/MCWinCOFFStreamer.h @@ -39,7 +39,7 @@ public: /// \name MCStreamer interface /// \{ - void InitSections(bool NoExecStack) override; + void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override; void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override; void emitAssemblerFlag(MCAssemblerFlag Flag) override; void emitThumbFunc(MCSymbol *Func) override; diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index f17542d..bfadf65 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -275,7 +275,7 @@ bool AsmPrinter::doInitialization(Module &M) { const_cast(getObjFileLowering()) .getModuleMetadata(M); - OutStreamer->InitSections(false); + OutStreamer->initSections(false, *TM.getMCSubtargetInfo()); if (DisableDebugInfoPrinting) MMI->setDebugInfoAvailability(false); @@ -2454,9 +2454,14 @@ void AsmPrinter::emitAlignment(Align Alignment, const GlobalObject *GV) const { if (Alignment == Align(1)) return; // 1-byte aligned: no need to emit alignment. - if (getCurrentSection()->getKind().isText()) - OutStreamer->emitCodeAlignment(Alignment.value()); - else + if (getCurrentSection()->getKind().isText()) { + const MCSubtargetInfo *STI = nullptr; + if (this->MF) + STI = &getSubtargetInfo(); + else + STI = TM.getMCSubtargetInfo(); + OutStreamer->emitCodeAlignment(Alignment.value(), STI); + } else OutStreamer->emitValueToAlignment(Alignment.value()); } @@ -3537,7 +3542,7 @@ void AsmPrinter::emitXRayTable() { // pointers. This should work for both 32-bit and 64-bit platforms. if (FnSledIndex) { OutStreamer->SwitchSection(FnSledIndex); - OutStreamer->emitCodeAlignment(2 * WordSizeBytes); + OutStreamer->emitCodeAlignment(2 * WordSizeBytes, &getSubtargetInfo()); OutStreamer->emitSymbolValue(SledsStart, WordSizeBytes, false); OutStreamer->emitSymbolValue(SledsEnd, WordSizeBytes, false); OutStreamer->SwitchSection(PrevSection); diff --git a/llvm/lib/MC/ConstantPools.cpp b/llvm/lib/MC/ConstantPools.cpp index d419902..d8a08a4 100644 --- a/llvm/lib/MC/ConstantPools.cpp +++ b/llvm/lib/MC/ConstantPools.cpp @@ -28,7 +28,7 @@ void ConstantPool::emitEntries(MCStreamer &Streamer) { return; Streamer.emitDataRegion(MCDR_DataRegion); for (const ConstantPoolEntry &Entry : Entries) { - Streamer.emitCodeAlignment(Entry.Size); // align naturally + Streamer.emitValueToAlignment(Entry.Size); // align naturally Streamer.emitLabel(Entry.Label); Streamer.emitValue(Entry.Value, Entry.Size, Entry.Loc); } diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index 72f4ee3..506d03e 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -245,7 +245,7 @@ public: unsigned ValueSize = 1, unsigned MaxBytesToEmit = 0) override; - void emitCodeAlignment(unsigned ByteAlignment, + void emitCodeAlignment(unsigned ByteAlignment, const MCSubtargetInfo *STI, unsigned MaxBytesToEmit = 0) override; void emitValueToOffset(const MCExpr *Offset, @@ -1429,6 +1429,7 @@ void MCAsmStreamer::emitValueToAlignment(unsigned ByteAlignment, int64_t Value, } void MCAsmStreamer::emitCodeAlignment(unsigned ByteAlignment, + const MCSubtargetInfo *STI, unsigned MaxBytesToEmit) { // Emit with a text fill value. emitValueToAlignment(ByteAlignment, MAI->getTextAlignFillValue(), diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index 2371eab..fbd8b34 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -88,10 +88,10 @@ void MCELFStreamer::mergeFragment(MCDataFragment *DF, DF->getContents().append(EF->getContents().begin(), EF->getContents().end()); } -void MCELFStreamer::InitSections(bool NoExecStack) { +void MCELFStreamer::initSections(bool NoExecStack, const MCSubtargetInfo &STI) { MCContext &Ctx = getContext(); SwitchSection(Ctx.getObjectFileInfo()->getTextSection()); - emitCodeAlignment(Ctx.getObjectFileInfo()->getTextSectionAlignment()); + emitCodeAlignment(Ctx.getObjectFileInfo()->getTextSectionAlignment(), &STI); if (NoExecStack) SwitchSection(Ctx.getAsmInfo()->getNonexecutableStackSection(Ctx)); diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp index 2865a2a..d55ba44 100644 --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -609,9 +609,10 @@ void MCObjectStreamer::emitValueToAlignment(unsigned ByteAlignment, } void MCObjectStreamer::emitCodeAlignment(unsigned ByteAlignment, + const MCSubtargetInfo *STI, unsigned MaxBytesToEmit) { emitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit); - cast(getCurrentFragment())->setEmitNops(true); + cast(getCurrentFragment())->setEmitNops(true, STI); } void MCObjectStreamer::emitValueToOffset(const MCExpr *Offset, diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 6e93e3a..d5f01d6 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -950,7 +950,7 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) { // Create the initial section, if requested. if (!NoInitialTextSection) - Out.InitSections(false); + Out.initSections(false, getTargetParser().getSTI()); // Prime the lexer. Lex(); @@ -1066,7 +1066,7 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) { bool AsmParser::checkForValidSection() { if (!ParsingMSInlineAsm && !getStreamer().getCurrentSectionOnly()) { - Out.InitSections(false); + Out.initSections(false, getTargetParser().getSTI()); return Error(getTok().getLoc(), "expected section directive before assembly directive"); } @@ -3454,7 +3454,8 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) { bool UseCodeAlign = Section->UseCodeAlign(); if ((!HasFillExpr || Lexer.getMAI().getTextAlignFillValue() == FillExpr) && ValueSize == 1 && UseCodeAlign) { - getStreamer().emitCodeAlignment(Alignment, MaxBytesToFill); + getStreamer().emitCodeAlignment(Alignment, &getTargetParser().getSTI(), + MaxBytesToFill); } else { // FIXME: Target specific behavior about how the "extra" bytes are filled. getStreamer().emitValueToAlignment(Alignment, FillExpr, ValueSize, diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp index 7b4d6e5..f983bb3 100644 --- a/llvm/lib/MC/MCParser/MasmParser.cpp +++ b/llvm/lib/MC/MCParser/MasmParser.cpp @@ -1319,7 +1319,7 @@ bool MasmParser::enabledGenDwarfForAssembly() { bool MasmParser::Run(bool NoInitialTextSection, bool NoFinalize) { // Create the initial section, if requested. if (!NoInitialTextSection) - Out.InitSections(false); + Out.initSections(false, getTargetParser().getSTI()); // Prime the lexer. Lex(); @@ -1437,7 +1437,7 @@ bool MasmParser::Run(bool NoInitialTextSection, bool NoFinalize) { bool MasmParser::checkForValidSection() { if (!ParsingMSInlineAsm && !getStreamer().getCurrentSectionOnly()) { - Out.InitSections(false); + Out.initSections(false, getTargetParser().getSTI()); return Error(getTok().getLoc(), "expected section directive before assembly directive"); } diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index 99b1290d..607b22a 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -399,7 +399,7 @@ void MCStreamer::emitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) { } -void MCStreamer::InitSections(bool NoExecStack) { +void MCStreamer::initSections(bool NoExecStack, const MCSubtargetInfo &STI) { SwitchSection(getContext().getObjectFileInfo()->getTextSection()); } @@ -1200,6 +1200,7 @@ void MCStreamer::emitValueToAlignment(unsigned ByteAlignment, int64_t Value, unsigned ValueSize, unsigned MaxBytesToEmit) {} void MCStreamer::emitCodeAlignment(unsigned ByteAlignment, + const MCSubtargetInfo *STI, unsigned MaxBytesToEmit) {} void MCStreamer::emitValueToOffset(const MCExpr *Offset, unsigned char Value, SMLoc Loc) {} diff --git a/llvm/lib/MC/MCWinCOFFStreamer.cpp b/llvm/lib/MC/MCWinCOFFStreamer.cpp index 69dc71b..0dfe5a5 100644 --- a/llvm/lib/MC/MCWinCOFFStreamer.cpp +++ b/llvm/lib/MC/MCWinCOFFStreamer.cpp @@ -66,18 +66,19 @@ void MCWinCOFFStreamer::emitInstToData(const MCInst &Inst, DF->getContents().append(Code.begin(), Code.end()); } -void MCWinCOFFStreamer::InitSections(bool NoExecStack) { +void MCWinCOFFStreamer::initSections(bool NoExecStack, + const MCSubtargetInfo &STI) { // FIXME: this is identical to the ELF one. // This emulates the same behavior of GNU as. This makes it easier // to compare the output as the major sections are in the same order. SwitchSection(getContext().getObjectFileInfo()->getTextSection()); - emitCodeAlignment(4); + emitCodeAlignment(4, &STI); SwitchSection(getContext().getObjectFileInfo()->getDataSection()); - emitCodeAlignment(4); + emitCodeAlignment(4, &STI); SwitchSection(getContext().getObjectFileInfo()->getBSSSection()); - emitCodeAlignment(4); + emitCodeAlignment(4, &STI); SwitchSection(getContext().getObjectFileInfo()->getTextSection()); } diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp index 3ab9b25..dc0c680 100644 --- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp +++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp @@ -293,7 +293,7 @@ void AArch64AsmPrinter::emitSled(const MachineInstr &MI, SledKind Kind) { // ;DATA: higher 32 bits of the address of the trampoline // LDP X0, X30, [SP], #16 ; pop X0 and the link register from the stack // - OutStreamer->emitCodeAlignment(4); + OutStreamer->emitCodeAlignment(4, &getSubtargetInfo()); auto CurSled = OutContext.createTempSymbol("xray_sled_", true); OutStreamer->emitLabel(CurSled); auto Target = OutContext.createTempSymbol(); diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp index ba594b7..2a194ee 100644 --- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp @@ -1742,7 +1742,7 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) { // FIXME: Ideally we could vary the LDRB index based on the padding // between the sequence and jump table, however that relies on MCExprs // for load indexes which are currently not supported. - OutStreamer->emitCodeAlignment(4); + OutStreamer->emitCodeAlignment(4, &getSubtargetInfo()); EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr) .addReg(Idx) .addReg(Idx) diff --git a/llvm/lib/Target/ARM/ARMMCInstLower.cpp b/llvm/lib/Target/ARM/ARMMCInstLower.cpp index e4b0229..2030fab 100644 --- a/llvm/lib/Target/ARM/ARMMCInstLower.cpp +++ b/llvm/lib/Target/ARM/ARMMCInstLower.cpp @@ -194,7 +194,7 @@ void ARMAsmPrinter::EmitSled(const MachineInstr &MI, SledKind Kind) // BLX ip // POP{ r0, lr } // - OutStreamer->emitCodeAlignment(4); + OutStreamer->emitCodeAlignment(4, &getSubtargetInfo()); auto CurSled = OutContext.createTempSymbol("xray_sled_", true); OutStreamer->emitLabel(CurSled); auto Target = OutContext.createTempSymbol(); diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp index f0d3c46..13df286 100644 --- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -11778,13 +11778,13 @@ bool ARMAsmParser::parseDirectiveEven(SMLoc L) { return true; if (!Section) { - getStreamer().InitSections(false); + getStreamer().initSections(false, getSTI()); Section = getStreamer().getCurrentSectionOnly(); } assert(Section && "must have section to emit alignment"); if (Section->UseCodeAlign()) - getStreamer().emitCodeAlignment(2); + getStreamer().emitCodeAlignment(2, &getSTI()); else getStreamer().emitValueToAlignment(2); @@ -11986,7 +11986,7 @@ bool ARMAsmParser::parseDirectiveAlign(SMLoc L) { const MCSection *Section = getStreamer().getCurrentSectionOnly(); assert(Section && "must have section to emit alignment"); if (Section->UseCodeAlign()) - getStreamer().emitCodeAlignment(4, 0); + getStreamer().emitCodeAlignment(4, &getSTI(), 0); else getStreamer().emitValueToAlignment(4, 0, 1, 0); return false; diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index 12076b8..0bba2ad 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -1056,7 +1056,7 @@ inline void ARMELFStreamer::SwitchToEHSection(StringRef Prefix, // Switch to .ARM.extab or .ARM.exidx section SwitchSection(EHSection); - emitCodeAlignment(4); + emitValueToAlignment(4, 0, 1, 0); } inline void ARMELFStreamer::SwitchToExTabSection(const MCSymbol &FnStart) { diff --git a/llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp b/llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp index 7edc2a0..62d6175 100644 --- a/llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp +++ b/llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp @@ -1498,7 +1498,7 @@ int HexagonAsmParser::processInstruction(MCInst &Inst, MES->SwitchSection(mySection); unsigned byteSize = is32bit ? 4 : 8; - getStreamer().emitCodeAlignment(byteSize, byteSize); + getStreamer().emitCodeAlignment(byteSize, &getSTI(), byteSize); MCSymbol *Sym; diff --git a/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp b/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp index f3017d0..11eddef 100644 --- a/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp +++ b/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp @@ -179,7 +179,7 @@ bool HexagonAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, static MCSymbol *smallData(AsmPrinter &AP, const MachineInstr &MI, MCStreamer &OutStreamer, const MCOperand &Imm, - int AlignSize) { + int AlignSize, const MCSubtargetInfo& STI) { MCSymbol *Sym; int64_t Value; if (Imm.getExpr()->evaluateAsAbsolute(Value)) { @@ -209,7 +209,7 @@ static MCSymbol *smallData(AsmPrinter &AP, const MachineInstr &MI, OutStreamer.emitLabel(Sym); OutStreamer.emitSymbolAttribute(Sym, MCSA_Global); OutStreamer.emitIntValue(Value, AlignSize); - OutStreamer.emitCodeAlignment(AlignSize); + OutStreamer.emitCodeAlignment(AlignSize, &STI); } } else { assert(Imm.isExpr() && "Expected expression and found none"); @@ -237,7 +237,7 @@ static MCSymbol *smallData(AsmPrinter &AP, const MachineInstr &MI, OutStreamer.emitLabel(Sym); OutStreamer.emitSymbolAttribute(Sym, MCSA_Local); OutStreamer.emitValue(Imm.getExpr(), AlignSize); - OutStreamer.emitCodeAlignment(AlignSize); + OutStreamer.emitCodeAlignment(AlignSize, &STI); } } return Sym; @@ -328,7 +328,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst, const MCOperand &Imm = MappedInst.getOperand(1); MCSectionSubPair Current = OutStreamer->getCurrentSection(); - MCSymbol *Sym = smallData(*this, MI, *OutStreamer, Imm, 8); + MCSymbol *Sym = + smallData(*this, MI, *OutStreamer, Imm, 8, getSubtargetInfo()); OutStreamer->SwitchSection(Current.first, Current.second); MCInst TmpInst; @@ -345,7 +346,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst, if (!OutStreamer->hasRawTextSupport()) { MCOperand &Imm = MappedInst.getOperand(1); MCSectionSubPair Current = OutStreamer->getCurrentSection(); - MCSymbol *Sym = smallData(*this, MI, *OutStreamer, Imm, 4); + MCSymbol *Sym = + smallData(*this, MI, *OutStreamer, Imm, 4, getSubtargetInfo()); OutStreamer->SwitchSection(Current.first, Current.second); MCInst TmpInst; MCOperand &Reg = MappedInst.getOperand(0); diff --git a/llvm/lib/Target/Hexagon/HexagonTargetStreamer.h b/llvm/lib/Target/Hexagon/HexagonTargetStreamer.h index a5b14a7..a99aa4f 100644 --- a/llvm/lib/Target/Hexagon/HexagonTargetStreamer.h +++ b/llvm/lib/Target/Hexagon/HexagonTargetStreamer.h @@ -16,6 +16,7 @@ class HexagonTargetStreamer : public MCTargetStreamer { public: HexagonTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} virtual void emitCodeAlignment(unsigned ByteAlignment, + const MCSubtargetInfo *STI, unsigned MaxBytesToEmit = 0){}; virtual void emitFAlign(unsigned Size, unsigned MaxBytesToEmit){}; virtual void emitCommonSymbolSorted(MCSymbol *Symbol, uint64_t Size, diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp index 232d0eb..57cd016 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp @@ -902,7 +902,7 @@ void MipsTargetELFStreamer::finish() { if (Alignment) { OS.SwitchSection(&Section); if (Section.UseCodeAlign()) - OS.emitCodeAlignment(Alignment, Alignment); + OS.emitCodeAlignment(Alignment, &STI, Alignment); else OS.emitValueToAlignment(Alignment, 0, 1, Alignment); } diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp index b460bc7..ed17565 100644 --- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp +++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp @@ -1203,7 +1203,7 @@ void MipsAsmPrinter::EmitSled(const MachineInstr &MI, SledKind Kind) { // LD RA, 8(SP) // DADDIU SP, SP, 16 // - OutStreamer->emitCodeAlignment(4); + OutStreamer->emitCodeAlignment(4, &getSubtargetInfo()); auto CurSled = OutContext.createTempSymbol("xray_sled_", true); OutStreamer->emitLabel(CurSled); auto Target = OutContext.createTempSymbol(); diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp index aa402e0..0ca8587 100644 --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp @@ -56,7 +56,7 @@ void PPCELFStreamer::emitPrefixedInstruction(const MCInst &Inst, // all of the nops required as part of the alignment operation. In the cases // when no nops are added then The fragment is still created but it remains // empty. - emitCodeAlignment(64, 4); + emitCodeAlignment(64, &STI, 4); // Emit the instruction. // Since the previous emit created a new fragment then adding this instruction diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFStreamer.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFStreamer.cpp index abdd197..d1e7249 100644 --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFStreamer.cpp +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFStreamer.cpp @@ -45,7 +45,7 @@ void PPCXCOFFStreamer::emitPrefixedInstruction(const MCInst &Inst, // prefixed instruction. Align to 64 bytes if possible but add a maximum of 4 // bytes when trying to do that. If alignment requires adding more than 4 // bytes then the instruction won't be aligned. - emitCodeAlignment(64, 4); + emitCodeAlignment(64, &STI, 4); // Emit the instruction. // Since the previous emit created a new fragment then adding this instruction diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp index 77ff16e..d9edf14 100644 --- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -1494,7 +1494,7 @@ void PPCLinuxAsmPrinter::emitInstruction(const MachineInstr *MI) { // // Update compiler-rt/lib/xray/xray_powerpc64.cc accordingly when number // of instructions change. - OutStreamer->emitCodeAlignment(8); + OutStreamer->emitCodeAlignment(8, &getSubtargetInfo()); MCSymbol *BeginOfSled = OutContext.createTempSymbol(); OutStreamer->emitLabel(BeginOfSled); EmitToStreamer(*OutStreamer, RetInst); diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp index 04c0e23..f363a7f 100644 --- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -4894,11 +4894,11 @@ bool X86AsmParser::parseDirectiveEven(SMLoc L) { const MCSection *Section = getStreamer().getCurrentSectionOnly(); if (!Section) { - getStreamer().InitSections(false); + getStreamer().initSections(false, getSTI()); Section = getStreamer().getCurrentSectionOnly(); } if (Section->UseCodeAlign()) - getStreamer().emitCodeAlignment(2, 0); + getStreamer().emitCodeAlignment(2, &getSTI(), 0); else getStreamer().emitValueToAlignment(2, 0, 1, 0); return false; diff --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp index d49b99e..978fcbf 100644 --- a/llvm/lib/Target/X86/X86MCInstLower.cpp +++ b/llvm/lib/Target/X86/X86MCInstLower.cpp @@ -1718,7 +1718,7 @@ void X86AsmPrinter::LowerPATCHABLE_EVENT_CALL(const MachineInstr &MI, // First we emit the label and the jump. auto CurSled = OutContext.createTempSymbol("xray_event_sled_", true); OutStreamer->AddComment("# XRay Custom Event Log"); - OutStreamer->emitCodeAlignment(2); + OutStreamer->emitCodeAlignment(2, &getSubtargetInfo()); OutStreamer->emitLabel(CurSled); // Use a two-byte `jmp`. This version of JMP takes an 8-bit relative offset as @@ -1814,7 +1814,7 @@ void X86AsmPrinter::LowerPATCHABLE_TYPED_EVENT_CALL(const MachineInstr &MI, // First we emit the label and the jump. auto CurSled = OutContext.createTempSymbol("xray_typed_event_sled_", true); OutStreamer->AddComment("# XRay Typed Event Log"); - OutStreamer->emitCodeAlignment(2); + OutStreamer->emitCodeAlignment(2, &getSubtargetInfo()); OutStreamer->emitLabel(CurSled); // Use a two-byte `jmp`. This version of JMP takes an 8-bit relative offset as @@ -1916,7 +1916,7 @@ void X86AsmPrinter::LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI, // call // 5 bytes // auto CurSled = OutContext.createTempSymbol("xray_sled_", true); - OutStreamer->emitCodeAlignment(2); + OutStreamer->emitCodeAlignment(2, &getSubtargetInfo()); OutStreamer->emitLabel(CurSled); // Use a two-byte `jmp`. This version of JMP takes an 8-bit relative offset as @@ -1946,7 +1946,7 @@ void X86AsmPrinter::LowerPATCHABLE_RET(const MachineInstr &MI, // // This just makes sure that the alignment for the next instruction is 2. auto CurSled = OutContext.createTempSymbol("xray_sled_", true); - OutStreamer->emitCodeAlignment(2); + OutStreamer->emitCodeAlignment(2, &getSubtargetInfo()); OutStreamer->emitLabel(CurSled); unsigned OpCode = MI.getOperand(0).getImm(); MCInst Ret; @@ -1970,7 +1970,7 @@ void X86AsmPrinter::LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI, // the PATCHABLE_FUNCTION_ENTER case, followed by the lowering of the actual // tail call much like how we have it in PATCHABLE_RET. auto CurSled = OutContext.createTempSymbol("xray_sled_", true); - OutStreamer->emitCodeAlignment(2); + OutStreamer->emitCodeAlignment(2, &getSubtargetInfo()); OutStreamer->emitLabel(CurSled); auto Target = OutContext.createTempSymbol(); diff --git a/llvm/tools/llvm-mc/Disassembler.cpp b/llvm/tools/llvm-mc/Disassembler.cpp index 16ab995..b71b774 100644 --- a/llvm/tools/llvm-mc/Disassembler.cpp +++ b/llvm/tools/llvm-mc/Disassembler.cpp @@ -156,7 +156,7 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple, } // Set up initial section manually here - Streamer.InitSections(false); + Streamer.initSections(false, STI); bool ErrorOccurred = false; diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp index 24c601b..4a9fa7a 100644 --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -571,7 +571,7 @@ int main(int argc, char **argv) { MCOptions.MCIncrementalLinkerCompatible, /*DWARFMustBeAtTheEnd*/ false)); if (NoExecStack) - Str->InitSections(true); + Str->initSections(true, *STI); } // Use Assembler information for parsing. diff --git a/llvm/tools/llvm-ml/Disassembler.cpp b/llvm/tools/llvm-ml/Disassembler.cpp index 793128c..0e2b028 100644 --- a/llvm/tools/llvm-ml/Disassembler.cpp +++ b/llvm/tools/llvm-ml/Disassembler.cpp @@ -152,7 +152,7 @@ int Disassembler::disassemble(const Target &T, const std::string &TripleName, } // Set up initial section manually here - Streamer.InitSections(false); + Streamer.initSections(false, STI); bool ErrorOccurred = false; diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp index ead650b..fee968d 100644 --- a/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp @@ -128,7 +128,7 @@ SmallString<0> DWARFExpressionCopyBytesTest::emitObjFile(StringRef ExprBytes) { SmallString<0> Storage; raw_svector_ostream VecOS(Storage); StreamerContext C = createStreamer(VecOS); - C.Streamer->InitSections(false); + C.Streamer->initSections(false, *STI); MCSection *Section = C.MOFI->getTextSection(); Section->setHasInstructions(true); C.Streamer->SwitchSection(Section); -- 2.7.4