[LTO] Switch Module to std::unique_ptr<>.
authorDavide Italiano <davide@freebsd.org>
Mon, 11 Apr 2016 22:39:51 +0000 (22:39 +0000)
committerDavide Italiano <davide@freebsd.org>
Mon, 11 Apr 2016 22:39:51 +0000 (22:39 +0000)
Differential Revision:   http://reviews.llvm.org/D18994

llvm-svn: 266009

lld/ELF/LTO.cpp
lld/ELF/LTO.h

index bd3c215..9da0ebe 100644 (file)
@@ -140,23 +140,23 @@ static void internalize(GlobalValue &GV) {
 // and return the resulting ObjectFile.
 std::unique_ptr<InputFile> BitcodeCompiler::compile() {
   for (const auto &Name : InternalizedSyms) {
-    GlobalValue *GV = Combined.getNamedValue(Name.first());
+    GlobalValue *GV = Combined->getNamedValue(Name.first());
     assert(GV);
     internalize(*GV);
   }
 
   if (Config->SaveTemps)
-    saveBCFile(Combined, ".lto.bc");
+    saveBCFile(*Combined, ".lto.bc");
 
   std::unique_ptr<TargetMachine> TM(getTargetMachine());
-  runLTOPasses(Combined, *TM);
+  runLTOPasses(*Combined, *TM);
 
   raw_svector_ostream OS(OwningData);
   legacy::PassManager CodeGenPasses;
   if (TM->addPassesToEmitFile(CodeGenPasses, OS,
                               TargetMachine::CGFT_ObjectFile))
     fatal("failed to setup codegen");
-  CodeGenPasses.run(Combined);
+  CodeGenPasses.run(*Combined);
   MB = MemoryBuffer::getMemBuffer(OwningData,
                                   "LLD-INTERNAL-combined-lto-object", false);
   if (Config->SaveTemps)
@@ -165,7 +165,7 @@ std::unique_ptr<InputFile> BitcodeCompiler::compile() {
 }
 
 TargetMachine *BitcodeCompiler::getTargetMachine() {
-  StringRef TripleStr = Combined.getTargetTriple();
+  StringRef TripleStr = Combined->getTargetTriple();
   std::string Msg;
   const Target *T = TargetRegistry::lookupTarget(TripleStr, Msg);
   if (!T)
index 909e5c9..88ee79d 100644 (file)
@@ -39,12 +39,15 @@ public:
   void add(BitcodeFile &F);
   std::unique_ptr<InputFile> compile();
 
+  BitcodeCompiler()
+      : Combined(new llvm::Module("ld-temp.o", Context)), Mover(*Combined) {}
+
 private:
   llvm::TargetMachine *getTargetMachine();
 
   llvm::LLVMContext Context;
-  llvm::Module Combined{"ld-temp.o", Context};
-  llvm::IRMover Mover{Combined};
+  std::unique_ptr<llvm::Module> Combined;
+  llvm::IRMover Mover;
   SmallString<0> OwningData;
   std::unique_ptr<MemoryBuffer> MB;
   llvm::StringSet<> InternalizedSyms;