<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 18, 2015 at 4:45 PM, Peter Collingbourne <span dir="ltr"><<a href="mailto:peter@pcc.me.uk" target="_blank">peter@pcc.me.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: pcc<br>
Date: Wed Feb 18 18:45:02 2015<br>
New Revision: 229797<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=229797&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=229797&view=rev</a><br>
Log:<br>
Introduce Target::createNullTargetStreamer and use it from IRObjectFile.<br>
<br>
A null MCTargetStreamer allows IRObjectFile to ignore target-specific<br>
directives. Previously we were crashing.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D7711" target="_blank">http://reviews.llvm.org/D7711</a><br>
<br>
Added:<br>
    llvm/trunk/test/LTO/ARM/inline-asm.ll<br>
Modified:<br>
    llvm/trunk/include/llvm/Support/TargetRegistry.h<br>
    llvm/trunk/lib/Object/IRObjectFile.cpp<br>
    llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp<br>
    llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp<br>
    llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h<br>
<br>
Modified: llvm/trunk/include/llvm/Support/TargetRegistry.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TargetRegistry.h?rev=229797&r1=229796&r2=229797&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TargetRegistry.h?rev=229797&r1=229796&r2=229797&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/TargetRegistry.h (original)<br>
+++ llvm/trunk/include/llvm/Support/TargetRegistry.h Wed Feb 18 18:45:02 2015<br>
@@ -47,6 +47,7 @@ namespace llvm {<br>
   class MCRelocationInfo;<br>
   class MCTargetAsmParser;<br>
   class MCTargetOptions;<br>
+  class MCTargetStreamer;<br>
   class TargetMachine;<br>
   class TargetOptions;<br>
   class raw_ostream;<br>
@@ -139,6 +140,7 @@ namespace llvm {<br>
                                              MCAsmBackend *TAB,<br>
                                              bool ShowInst);<br>
     typedef MCStreamer *(*NullStreamerCtorTy)(MCContext &Ctx);<br>
+    typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);<br>
     typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,<br>
                                                         MCContext &Ctx);<br>
     typedef MCSymbolizer *(*MCSymbolizerCtorTy)(<br>
@@ -227,6 +229,10 @@ namespace llvm {<br>
     /// (default = llvm::createNullStreamer).<br>
     NullStreamerCtorTy NullStreamerCtorFn;<br>
<br>
+    /// Construction function for this target's null TargetStreamer, if<br>
+    /// registered (default = nullptr).<br>
+    NullTargetStreamerCtorTy NullTargetStreamerCtorFn;<br>
+<br>
     /// MCRelocationInfoCtorFn - Construction function for this target's<br>
     /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)<br>
     MCRelocationInfoCtorTy MCRelocationInfoCtorFn;<br>
@@ -453,6 +459,12 @@ namespace llvm {<br>
       return llvm::createNullStreamer(Ctx);<br>
     }<br>
<br>
+    MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {<br></blockquote><div><br>Could/should this (& NullTargetStreamerCtorFn) return by unique_ptr instead?<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      if (NullTargetStreamerCtorFn)<br>
+        return NullTargetStreamerCtorFn(S);<br>
+      return nullptr;<br>
+    }<br>
+<br>
     /// createMCRelocationInfo - Create a target specific MCRelocationInfo.<br>
     ///<br>
     /// \param TT The target triple.<br>
@@ -783,6 +795,11 @@ namespace llvm {<br>
       T.NullStreamerCtorFn = Fn;<br>
     }<br>
<br>
+    static void<br>
+    RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {<br>
+      T.NullTargetStreamerCtorFn = Fn;<br>
+    }<br>
+<br>
     /// RegisterMCRelocationInfo - Register an MCRelocationInfo<br>
     /// implementation for the given target.<br>
     ///<br>
<br>
Modified: llvm/trunk/lib/Object/IRObjectFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/IRObjectFile.cpp?rev=229797&r1=229796&r2=229797&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/IRObjectFile.cpp?rev=229797&r1=229796&r2=229797&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Object/IRObjectFile.cpp (original)<br>
+++ llvm/trunk/lib/Object/IRObjectFile.cpp Wed Feb 18 18:45:02 2015<br>
@@ -73,6 +73,7 @@ IRObjectFile::IRObjectFile(MemoryBufferR<br>
   MCContext MCCtx(MAI.get(), MRI.get(), &MOFI);<br>
   MOFI.InitMCObjectFileInfo(Triple, Reloc::Default, CodeModel::Default, MCCtx);<br>
   std::unique_ptr<RecordStreamer> Streamer(new RecordStreamer(MCCtx));<br>
+  T->createNullTargetStreamer(*Streamer);<br>
<br>
   std::unique_ptr<MemoryBuffer> Buffer(MemoryBuffer::getMemBuffer(InlineAsm));<br>
   SourceMgr SrcMgr;<br>
<br>
Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp?rev=229797&r1=229796&r2=229797&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp?rev=229797&r1=229796&r2=229797&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp (original)<br>
+++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp Wed Feb 18 18:45:02 2015<br>
@@ -1360,6 +1360,10 @@ MCStreamer *createARMNullStreamer(MCCont<br>
   return S;<br>
 }<br>
<br>
+MCTargetStreamer *createARMNullTargetStreamer(MCStreamer &S) {<br>
+  return new ARMTargetStreamer(S);<br>
+}<br>
+<br>
 MCELFStreamer *createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB,<br>
                                     raw_ostream &OS, MCCodeEmitter *Emitter,<br>
                                     bool RelaxAll, bool IsThumb) {<br>
<br>
Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp?rev=229797&r1=229796&r2=229797&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp?rev=229797&r1=229796&r2=229797&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp (original)<br>
+++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp Wed Feb 18 18:45:02 2015<br>
@@ -461,6 +461,16 @@ extern "C" void LLVMInitializeARMTargetM<br>
   TargetRegistry::RegisterNullStreamer(TheThumbLETarget, createARMNullStreamer);<br>
   TargetRegistry::RegisterNullStreamer(TheThumbBETarget, createARMNullStreamer);<br>
<br>
+  // Register the null TargetStreamer.<br>
+  TargetRegistry::RegisterNullTargetStreamer(TheARMLETarget,<br>
+                                             createARMNullTargetStreamer);<br>
+  TargetRegistry::RegisterNullTargetStreamer(TheARMBETarget,<br>
+                                             createARMNullTargetStreamer);<br>
+  TargetRegistry::RegisterNullTargetStreamer(TheThumbLETarget,<br>
+                                             createARMNullTargetStreamer);<br>
+  TargetRegistry::RegisterNullTargetStreamer(TheThumbBETarget,<br>
+                                             createARMNullTargetStreamer);<br>
+<br>
   // Register the MCInstPrinter.<br>
   TargetRegistry::RegisterMCInstPrinter(TheARMLETarget, createARMMCInstPrinter);<br>
   TargetRegistry::RegisterMCInstPrinter(TheARMBETarget, createARMMCInstPrinter);<br>
<br>
Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h?rev=229797&r1=229796&r2=229797&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h?rev=229797&r1=229796&r2=229797&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h (original)<br>
+++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h Wed Feb 18 18:45:02 2015<br>
@@ -29,6 +29,7 @@ class MCRegisterInfo;<br>
 class MCSubtargetInfo;<br>
 class MCStreamer;<br>
 class MCRelocationInfo;<br>
+class MCTargetStreamer;<br>
 class StringRef;<br>
 class Target;<br>
 class raw_ostream;<br>
@@ -53,6 +54,8 @@ MCStreamer *createMCAsmStreamer(MCContex<br>
<br>
 MCStreamer *createARMNullStreamer(MCContext &Ctx);<br>
<br>
+MCTargetStreamer *createARMNullTargetStreamer(MCStreamer &S);<br>
+<br>
 MCCodeEmitter *createARMLEMCCodeEmitter(const MCInstrInfo &MCII,<br>
                                         const MCRegisterInfo &MRI,<br>
                                         const MCSubtargetInfo &STI,<br>
<br>
Added: llvm/trunk/test/LTO/ARM/inline-asm.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/ARM/inline-asm.ll?rev=229797&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/ARM/inline-asm.ll?rev=229797&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/LTO/ARM/inline-asm.ll (added)<br>
+++ llvm/trunk/test/LTO/ARM/inline-asm.ll Wed Feb 18 18:45:02 2015<br>
@@ -0,0 +1,9 @@<br>
+; Check that we don't crash on target-specific inline asm directives.<br>
+;<br>
+; RUN: llvm-as < %s > %t<br>
+; RUN: llvm-lto -o /dev/null %t -mcpu armv4t<br>
+<br>
+target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"<br>
+target triple = "armv4t-unknown-linux"<br>
+<br>
+module asm ".fnstart"<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>