Move emitInlineAsmEnd to the AsmPrinter interface.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 24 Jan 2014 15:47:54 +0000 (15:47 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 24 Jan 2014 15:47:54 +0000 (15:47 +0000)
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
include/llvm/MC/MCStreamer.h
lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
lib/Target/ARM/ARMAsmPrinter.cpp
lib/Target/ARM/ARMAsmPrinter.h
lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp

index c22d1ea306d8d2b6abd1e1fd27ffca1a6166ff3f..85f4130a2fa3243587f2c1857346a24b96490813 100644 (file)
@@ -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.
index 1538a411492059c886b6b32415e05c43a5ee85c8..eb68be77c2d036758e4c3df0761b62618f8b2f96 100644 (file)
@@ -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() {}
 
index d679bff4cb59ec5c9b3952659519cbf261226d2f..aece69bca632547a635d72619a195aafe8a7979e 100644 (file)
@@ -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<MCSubtargetInfo>(), 0);
+    emitInlineAsmEnd(TM.getSubtarget<MCSubtargetInfo>(), 0);
     return;
   }
 
@@ -124,7 +124,7 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode,
     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 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 {}
index 965d93c1f4b7b1243967d90a632a82c9d2b35542..325f3553854dfd851c90a4ea770dd140c8138240 100644 (file)
@@ -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();
index d7136505e491fb5b9040539baef3ef507b91e1f8..a2cda3b95d470edaaece66253fbce71145ec9ee9 100644 (file)
@@ -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;
index e9ffc5890ad74a910dab6f17b892f4cb19a3c98d..8e224780d8399c61b44808b6fa9ea5e05f0cf9ab 100644 (file)
@@ -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;