From b0d78d0192c66f71ae71dbb7c655a31b29360717 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 24 Jan 2014 15:47:54 +0000 Subject: [PATCH] Move emitInlineAsmEnd to the AsmPrinter interface. There is no inline asm in a .s file. Therefore, there should be no logic to handle it in the streamer. Inline asm only exists in bitcode files, so the logic can live in the (long misnamed) AsmPrinter class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200011 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/AsmPrinter.h | 10 +++++++++ include/llvm/MC/MCStreamer.h | 21 ------------------- .../AsmPrinter/AsmPrinterInlineAsm.cpp | 8 ++++--- lib/Target/ARM/ARMAsmPrinter.cpp | 16 ++++++++++++++ lib/Target/ARM/ARMAsmPrinter.h | 3 +++ .../ARM/MCTargetDesc/ARMELFStreamer.cpp | 17 --------------- 6 files changed, 34 insertions(+), 41 deletions(-) diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index c22d1ea306d..85f4130a2fa 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -45,6 +45,7 @@ namespace llvm { class MCInstrInfo; class MCSection; class MCStreamer; + class MCSubtargetInfo; class MCSymbol; class MDNode; class DwarfDebug; @@ -461,6 +462,15 @@ namespace llvm { unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS); + /// Let the target do anything it needs to do after emitting inlineasm. + /// This callback can be used restore the original mode in case the + /// inlineasm contains directives to switch modes. + /// \p StartInfo - the original subtarget info before inline asm + /// \p EndInfo - the final subtarget info after parsing the inline asm, + /// or NULL if the value is unknown. + virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, + MCSubtargetInfo *EndInfo) const; + private: /// Private state for PrintSpecial() // Assign a unique ID to this machine instruction. diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h index 1538a411492..eb68be77c2d 100644 --- a/include/llvm/MC/MCStreamer.h +++ b/include/llvm/MC/MCStreamer.h @@ -75,15 +75,6 @@ public: // Allow a target to add behavior to the EmitLabel of MCStreamer. virtual void emitLabel(MCSymbol *Symbol); - - /// Let the target do anything it needs to do after emitting inlineasm. - /// This callback can be used restore the original mode in case the - /// inlineasm contains directives to switch modes. - /// \p StartInfo - the original subtarget info before inline asm - /// \p EndInfo - the final subtarget info after parsing the inline asm, - // or NULL if the value is unknown. - virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, - MCSubtargetInfo *EndInfo) {} }; // FIXME: declared here because it is used from @@ -114,8 +105,6 @@ public: virtual void emitArch(unsigned Arch) = 0; virtual void finishAttributeSection() = 0; virtual void emitInst(uint32_t Inst, char Suffix = '\0') = 0; - virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, - MCSubtargetInfo *EndInfo); }; /// MCStreamer - Streaming machine code generation interface. This interface @@ -689,16 +678,6 @@ public: /// indicated by the hasRawTextSupport() predicate. By default this aborts. void EmitRawText(const Twine &String); - /// EmitInlineAsmEnd - Used to perform any cleanup needed after emitting - /// inline assembly. Provides the start and end subtarget info values. - /// The end subtarget info may be NULL if it is not know, for example, when - /// emitting the inline assembly as raw text. - virtual void EmitInlineAsmEnd(const MCSubtargetInfo &StartInfo, - MCSubtargetInfo *EndInfo) { - if (TargetStreamer) - TargetStreamer->emitInlineAsmEnd(StartInfo, EndInfo); - } - /// Flush - Causes any cached state to be written out. virtual void Flush() {} diff --git a/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp index d679bff4cb5..aece69bca63 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp @@ -84,7 +84,7 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode, // system assembler does. if (OutStreamer.hasRawTextSupport()) { OutStreamer.EmitRawText(Str); - OutStreamer.EmitInlineAsmEnd(TM.getSubtarget(), 0); + emitInlineAsmEnd(TM.getSubtarget(), 0); return; } @@ -124,7 +124,7 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode, const_cast(&TM.getSubtarget()); // Preserve a copy of the original STI because the parser may modify it. - // The target can restore the original state in EmitInlineAsmEnd(). + // The target can restore the original state in emitInlineAsmEnd(). MCSubtargetInfo STIOrig = *STI; OwningPtr @@ -138,7 +138,7 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode, // Don't implicitly switch to the text section before the asm. int Res = Parser->Run(/*NoInitialTextSection*/ true, /*NoFinalize*/ true); - OutStreamer.EmitInlineAsmEnd(STIOrig, STI); + emitInlineAsmEnd(STIOrig, STI); if (Res && !HasDiagHandler) report_fatal_error("Error parsing inline asm\n"); } @@ -549,3 +549,5 @@ bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, return true; } +void AsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, + MCSubtargetInfo *EndInfo) const {} diff --git a/lib/Target/ARM/ARMAsmPrinter.cpp b/lib/Target/ARM/ARMAsmPrinter.cpp index 965d93c1f4b..325f3553854 100644 --- a/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/ARMAsmPrinter.cpp @@ -438,6 +438,22 @@ bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, return false; } +static bool isThumb(const MCSubtargetInfo& STI) { + return (STI.getFeatureBits() & ARM::ModeThumb) != 0; +} + +void ARMAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, + MCSubtargetInfo *EndInfo) const { + // If either end mode is unknown (EndInfo == NULL) or different than + // the start mode, then restore the start mode. + const bool WasThumb = isThumb(StartInfo); + if (EndInfo == NULL || WasThumb != isThumb(*EndInfo)) { + OutStreamer.EmitAssemblerFlag(WasThumb ? MCAF_Code16 : MCAF_Code32); + if (EndInfo) + EndInfo->ToggleFeature(ARM::ModeThumb); + } +} + void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) { if (Subtarget->isTargetMachO()) { Reloc::Model RelocM = TM.getRelocationModel(); diff --git a/lib/Target/ARM/ARMAsmPrinter.h b/lib/Target/ARM/ARMAsmPrinter.h index d7136505e49..a2cda3b95d4 100644 --- a/lib/Target/ARM/ARMAsmPrinter.h +++ b/lib/Target/ARM/ARMAsmPrinter.h @@ -63,6 +63,9 @@ public: unsigned AsmVariant, const char *ExtraCode, raw_ostream &O) LLVM_OVERRIDE; + virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, + MCSubtargetInfo *EndInfo) const LLVM_OVERRIDE; + void EmitJumpTable(const MachineInstr *MI); void EmitJump2Table(const MachineInstr *MI); virtual void EmitInstruction(const MachineInstr *MI) LLVM_OVERRIDE; diff --git a/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index e9ffc5890ad..8e224780d83 100644 --- a/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -104,25 +104,8 @@ static unsigned GetArchDefaultCPUArch(unsigned ID) { return 0; } -static bool isThumb(const MCSubtargetInfo& STI) { - return (STI.getFeatureBits() & ARM::ModeThumb) != 0; -} - void ARMTargetStreamer::anchor() {} -void ARMTargetStreamer::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, - MCSubtargetInfo *EndInfo) { - // If either end mode is unknown (EndInfo == NULL) or different than - // the start mode, then restore the start mode. - const bool WasThumb = isThumb(StartInfo); - if (EndInfo == NULL || WasThumb != isThumb(*EndInfo)) { - assert(Streamer); - Streamer->EmitAssemblerFlag(WasThumb ? MCAF_Code16 : MCAF_Code32); - if (EndInfo) - EndInfo->ToggleFeature(ARM::ModeThumb); - } -} - namespace { class ARMELFStreamer; -- 2.34.1