[llvm-branch-commits] [llvm-branch] r109836 - in /llvm/branches/Apple/williamson: include/llvm/MC/MCStreamer.h include/llvm/Target/TargetRegistry.h lib/CodeGen/LLVMTargetMachine.cpp lib/MC/MCAsmStreamer.cpp lib/MC/MCObjectStreamer.cpp tools/llvm-mc/llvm-mc.cpp

Daniel Dunbar daniel at zuster.org
Thu Jul 29 18:12:25 PDT 2010


Author: ddunbar
Date: Thu Jul 29 20:12:25 2010
New Revision: 109836

URL: http://llvm.org/viewvc/llvm-project?rev=109836&view=rev
Log:
Merge r109767:
--
Author: Benjamin Kramer <benny.kra at googlemail.com>
Date:   Thu Jul 29 17:48:06 2010 +0000

    Plug the remaining MC leaks by giving MCObjectStreamer/MCAsmStreamer ownership of the TargetAsmBackend and the MCCodeEmitter.

Modified:
    llvm/branches/Apple/williamson/include/llvm/MC/MCStreamer.h
    llvm/branches/Apple/williamson/include/llvm/Target/TargetRegistry.h
    llvm/branches/Apple/williamson/lib/CodeGen/LLVMTargetMachine.cpp
    llvm/branches/Apple/williamson/lib/MC/MCAsmStreamer.cpp
    llvm/branches/Apple/williamson/lib/MC/MCObjectStreamer.cpp
    llvm/branches/Apple/williamson/tools/llvm-mc/llvm-mc.cpp

Modified: llvm/branches/Apple/williamson/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/williamson/include/llvm/MC/MCStreamer.h?rev=109836&r1=109835&r2=109836&view=diff
==============================================================================
--- llvm/branches/Apple/williamson/include/llvm/MC/MCStreamer.h (original)
+++ llvm/branches/Apple/williamson/include/llvm/MC/MCStreamer.h Thu Jul 29 20:12:25 2010
@@ -331,7 +331,7 @@
   /// InstPrint.
   ///
   /// \param CE - If given, a code emitter to use to show the instruction
-  /// encoding inline with the assembly.
+  /// encoding inline with the assembly. This method takes ownership of \arg CE.
   ///
   /// \param ShowInst - Whether to show the MCInst representation inline with
   /// the assembly.
@@ -343,12 +343,16 @@
 
   /// createMachOStreamer - Create a machine code streamer which will generate
   /// Mach-O format object files.
+  ///
+  /// Takes ownership of \arg TAB and \arg CE.
   MCStreamer *createMachOStreamer(MCContext &Ctx, TargetAsmBackend &TAB,
                                   raw_ostream &OS, MCCodeEmitter *CE,
                                   bool RelaxAll = false);
 
   /// createWinCOFFStreamer - Create a machine code streamer which will
   /// generate Microsoft COFF format object files.
+  ///
+  /// Takes ownership of \arg TAB and \arg CE.
   MCStreamer *createWinCOFFStreamer(MCContext &Ctx,
                                     TargetAsmBackend &TAB,
                                     MCCodeEmitter &CE, raw_ostream &OS);

Modified: llvm/branches/Apple/williamson/include/llvm/Target/TargetRegistry.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/williamson/include/llvm/Target/TargetRegistry.h?rev=109836&r1=109835&r2=109836&view=diff
==============================================================================
--- llvm/branches/Apple/williamson/include/llvm/Target/TargetRegistry.h (original)
+++ llvm/branches/Apple/williamson/include/llvm/Target/TargetRegistry.h Thu Jul 29 20:12:25 2010
@@ -278,9 +278,9 @@
     ///
     /// \arg TT - The target triple.
     /// \arg Ctx - The target context.
-    /// \arg TAB - The target assembler backend object.
+    /// \arg TAB - The target assembler backend object. Takes ownership.
     /// \arg _OS - The stream object.
-    /// \arg _Emitter - The target independent assembler object.
+    /// \arg _Emitter - The target independent assembler object.Takes ownership.
     /// \arg RelaxAll - Relax all fixups?
     MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
                                      TargetAsmBackend &TAB,

Modified: llvm/branches/Apple/williamson/lib/CodeGen/LLVMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/williamson/lib/CodeGen/LLVMTargetMachine.cpp?rev=109836&r1=109835&r2=109836&view=diff
==============================================================================
--- llvm/branches/Apple/williamson/lib/CodeGen/LLVMTargetMachine.cpp (original)
+++ llvm/branches/Apple/williamson/lib/CodeGen/LLVMTargetMachine.cpp Thu Jul 29 20:12:25 2010
@@ -139,8 +139,6 @@
       getTarget().createMCInstPrinter(MAI.getAssemblerDialect(), MAI);
 
     // Create a code emitter if asked to show the encoding.
-    //
-    // FIXME: These are currently leaked.
     MCCodeEmitter *MCE = 0;
     if (ShowMCEncoding)
       MCE = getTarget().createCodeEmitter(*this, *Context);
@@ -154,8 +152,6 @@
   case CGFT_ObjectFile: {
     // Create the code emitter for the target if it exists.  If not, .o file
     // emission fails.
-    //
-    // FIXME: These are currently leaked.
     MCCodeEmitter *MCE = getTarget().createCodeEmitter(*this, *Context);
     TargetAsmBackend *TAB = getTarget().createAsmBackend(TargetTriple);
     if (MCE == 0 || TAB == 0)

Modified: llvm/branches/Apple/williamson/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/williamson/lib/MC/MCAsmStreamer.cpp?rev=109836&r1=109835&r2=109836&view=diff
==============================================================================
--- llvm/branches/Apple/williamson/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/branches/Apple/williamson/lib/MC/MCAsmStreamer.cpp Thu Jul 29 20:12:25 2010
@@ -31,7 +31,7 @@
   formatted_raw_ostream &OS;
   const MCAsmInfo &MAI;
   OwningPtr<MCInstPrinter> InstPrinter;
-  MCCodeEmitter *Emitter;
+  OwningPtr<MCCodeEmitter> Emitter;
   
   SmallString<128> CommentToEmit;
   raw_svector_ostream CommentStream;

Modified: llvm/branches/Apple/williamson/lib/MC/MCObjectStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/williamson/lib/MC/MCObjectStreamer.cpp?rev=109836&r1=109835&r2=109836&view=diff
==============================================================================
--- llvm/branches/Apple/williamson/lib/MC/MCObjectStreamer.cpp (original)
+++ llvm/branches/Apple/williamson/lib/MC/MCObjectStreamer.cpp Thu Jul 29 20:12:25 2010
@@ -11,7 +11,9 @@
 
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/MC/MCAssembler.h"
+#include "llvm/MC/MCCodeEmitter.h"
 #include "llvm/MC/MCExpr.h"
+#include "llvm/Target/TargetAsmBackend.h"
 using namespace llvm;
 
 MCObjectStreamer::MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB,
@@ -23,6 +25,8 @@
 }
 
 MCObjectStreamer::~MCObjectStreamer() {
+  delete &Assembler->getBackend();
+  delete &Assembler->getEmitter();
   delete Assembler;
 }
 

Modified: llvm/branches/Apple/williamson/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/williamson/tools/llvm-mc/llvm-mc.cpp?rev=109836&r1=109835&r2=109836&view=diff
==============================================================================
--- llvm/branches/Apple/williamson/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/branches/Apple/williamson/tools/llvm-mc/llvm-mc.cpp Thu Jul 29 20:12:25 2010
@@ -287,25 +287,24 @@
     return 1;
   }
 
-  OwningPtr<MCCodeEmitter> CE;
   OwningPtr<MCStreamer> Str;
-  OwningPtr<TargetAsmBackend> TAB;
 
   if (FileType == OFT_AssemblyFile) {
     MCInstPrinter *IP =
       TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI);
+    MCCodeEmitter *CE = 0;
     if (ShowEncoding)
-      CE.reset(TheTarget->createCodeEmitter(*TM, Ctx));
+      CE = TheTarget->createCodeEmitter(*TM, Ctx);
     Str.reset(createAsmStreamer(Ctx, *Out,TM->getTargetData()->isLittleEndian(),
-                                /*asmverbose*/true, IP, CE.get(), ShowInst));
+                                /*asmverbose*/true, IP, CE, ShowInst));
   } else if (FileType == OFT_Null) {
     Str.reset(createNullStreamer(Ctx));
   } else {
     assert(FileType == OFT_ObjectFile && "Invalid file type!");
-    CE.reset(TheTarget->createCodeEmitter(*TM, Ctx));
-    TAB.reset(TheTarget->createAsmBackend(TripleName));
+    MCCodeEmitter *CE = TheTarget->createCodeEmitter(*TM, Ctx);
+    TargetAsmBackend *TAB = TheTarget->createAsmBackend(TripleName);
     Str.reset(TheTarget->createObjectStreamer(TripleName, Ctx, *TAB,
-                                              *Out, CE.get(), RelaxAll));
+                                              *Out, CE, RelaxAll));
   }
 
   if (EnableLogging) {





More information about the llvm-branch-commits mailing list