[llvm] r200011 - Move emitInlineAsmEnd to the AsmPrinter interface.

Rafael Espindola rafael.espindola at gmail.com
Fri Jan 24 07:47:54 PST 2014


Author: rafael
Date: Fri Jan 24 09:47:54 2014
New Revision: 200011

URL: http://llvm.org/viewvc/llvm-project?rev=200011&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
    llvm/trunk/include/llvm/MC/MCStreamer.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
    llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
    llvm/trunk/lib/Target/ARM/ARMAsmPrinter.h
    llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp

Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=200011&r1=200010&r2=200011&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Fri Jan 24 09:47:54 2014
@@ -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.

Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=200011&r1=200010&r2=200011&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Fri Jan 24 09:47:54 2014
@@ -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() {}
 

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp?rev=200011&r1=200010&r2=200011&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp Fri Jan 24 09:47:54 2014
@@ -84,7 +84,7 @@ void AsmPrinter::EmitInlineAsm(StringRef
   // system assembler does.
   if (OutStreamer.hasRawTextSupport()) {
     OutStreamer.EmitRawText(Str);
-    OutStreamer.EmitInlineAsmEnd(TM.getSubtarget<MCSubtargetInfo>(), 0);
+    emitInlineAsmEnd(TM.getSubtarget<MCSubtargetInfo>(), 0);
     return;
   }
 
@@ -124,7 +124,7 @@ void AsmPrinter::EmitInlineAsm(StringRef
     const_cast<MCSubtargetInfo*>(&TM.getSubtarget<MCSubtargetInfo>());
 
   // 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<MCTargetAsmParser>
@@ -138,7 +138,7 @@ void AsmPrinter::EmitInlineAsm(StringRef
   // 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(c
   return true;
 }
 
+void AsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
+                                  MCSubtargetInfo *EndInfo) const {}

Modified: llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp?rev=200011&r1=200010&r2=200011&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp Fri Jan 24 09:47:54 2014
@@ -438,6 +438,22 @@ bool ARMAsmPrinter::PrintAsmMemoryOperan
   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();

Modified: llvm/trunk/lib/Target/ARM/ARMAsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmPrinter.h?rev=200011&r1=200010&r2=200011&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMAsmPrinter.h (original)
+++ llvm/trunk/lib/Target/ARM/ARMAsmPrinter.h Fri Jan 24 09:47:54 2014
@@ -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;

Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp?rev=200011&r1=200010&r2=200011&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp (original)
+++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp Fri Jan 24 09:47:54 2014
@@ -104,25 +104,8 @@ static unsigned GetArchDefaultCPUArch(un
   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;





More information about the llvm-commits mailing list