[PATCH] D11822: Resurrect RegisterAsmStreamer

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 15:44:33 PDT 2015


arsenm created this revision.
arsenm added a reviewer: rafael.
arsenm added a subscriber: llvm-commits.

HSAIL needs to override this to avoid emission of any of the directives the standard MCAsmStreamer tries to emit, most notably anything indicating the start of a section.

http://reviews.llvm.org/D11822

Files:
  include/llvm/Support/TargetRegistry.h

Index: include/llvm/Support/TargetRegistry.h
===================================================================
--- include/llvm/Support/TargetRegistry.h
+++ include/llvm/Support/TargetRegistry.h
@@ -149,6 +149,15 @@
                                                raw_pwrite_stream &OS,
                                                MCCodeEmitter *Emitter);
 
+  typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
+                                           std::unique_ptr<formatted_raw_ostream> OS,
+                                           bool IsVerboseAsm,
+                                           bool UseDwarfDirectory,
+                                           MCInstPrinter *InstPrint,
+                                           MCCodeEmitter *CE,
+                                           MCAsmBackend *TAB,
+                                           bool ShowInst);
+
   typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
   typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
       MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
@@ -237,6 +246,10 @@
   ELFStreamerCtorTy ELFStreamerCtorFn;
   UnknownStreamerCtorTy UnknownStreamerCtorFn;
 
+  /// AsmStreamerCtorFn - Construction function for this target's
+  /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
+  AsmStreamerCtorTy AsmStreamerCtorFn;
+
   /// Construction function for this target's null TargetStreamer, if
   /// registered (default = nullptr).
   NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
@@ -260,7 +273,8 @@
 public:
   Target()
       : COFFStreamerCtorFn(nullptr), MachOStreamerCtorFn(nullptr),
-        ELFStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
+        ELFStreamerCtorFn(nullptr), AsmStreamerCtorFn(nullptr),
+        NullTargetStreamerCtorFn(nullptr),
         AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
         MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
 
@@ -485,9 +499,18 @@
                                 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
                                 MCAsmBackend *TAB, bool ShowInst) const {
     formatted_raw_ostream &OSRef = *OS;
-    MCStreamer *S = llvm::createAsmStreamer(Ctx, std::move(OS), IsVerboseAsm,
-                                            UseDwarfDirectory, InstPrint, CE,
-                                            TAB, ShowInst);
+
+    MCStreamer *S;
+    if (AsmStreamerCtorFn) {
+      S = AsmStreamerCtorFn(Ctx, std::move(OS), IsVerboseAsm,
+                            UseDwarfDirectory, InstPrint, CE,
+                            TAB, ShowInst);
+    } else {
+      S = llvm::createAsmStreamer(Ctx, std::move(OS), IsVerboseAsm,
+                                  UseDwarfDirectory, InstPrint, CE,
+                                  TAB, ShowInst);
+    }
+
     createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
     return S;
   }
@@ -826,6 +849,19 @@
     T.UnknownStreamerCtorFn = Fn;
   }
 
+  /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
+  /// for the given target.
+  ///
+  /// Clients are responsible for ensuring that registration doesn't occur
+  /// while another thread is attempting to access the registry. Typically
+  /// this is done by initializing all targets at program startup.
+  ///
+  /// @param T - The target being registered.
+  /// @param Fn - A function to construct an MCStreamer for the target.
+  static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
+    T.AsmStreamerCtorFn = Fn;
+  }
+
   static void RegisterNullTargetStreamer(Target &T,
                                          Target::NullTargetStreamerCtorTy Fn) {
     T.NullTargetStreamerCtorFn = Fn;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11822.31484.patch
Type: text/x-patch
Size: 3770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150806/899ceaf8/attachment.bin>


More information about the llvm-commits mailing list