libLTO: Allow LTOCodeGenerator to own a context
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 11 Nov 2014 23:03:29 +0000 (23:03 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 11 Nov 2014 23:03:29 +0000 (23:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221726 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/LTO/LTOCodeGenerator.h
lib/LTO/LTOCodeGenerator.cpp

index 5894308b266e45c69dae50524762cbca04beed1b..f93f013b7c608a5a333cd51062f09a7c0919a152 100644 (file)
@@ -61,6 +61,7 @@ struct LTOCodeGenerator {
   static const char *getVersionString();
 
   LTOCodeGenerator();
+  LTOCodeGenerator(std::unique_ptr<LLVMContext> Context);
   ~LTOCodeGenerator();
 
   // Merge given module, return true on success.
@@ -137,6 +138,8 @@ private:
 
   typedef StringMap<uint8_t> StringSet;
 
+  void initialize();
+  std::unique_ptr<LLVMContext> OwnedContext;
   LLVMContext &Context;
   Linker IRLinker;
   TargetMachine *TargetMach;
index 4911a260d7933ae8843ce2fa1c48e3a4eb4d576a..31ab3401c9dc8a8c6cd0761667cbb0c4ff0bd005 100644 (file)
@@ -64,10 +64,24 @@ const char* LTOCodeGenerator::getVersionString() {
 }
 
 LTOCodeGenerator::LTOCodeGenerator()
-    : Context(getGlobalContext()), IRLinker(new Module("ld-temp.o", Context)),
-      TargetMach(nullptr), EmitDwarfDebugInfo(false),
-      ScopeRestrictionsDone(false), CodeModel(LTO_CODEGEN_PIC_MODEL_DEFAULT),
-      DiagHandler(nullptr), DiagContext(nullptr) {
+    : Context(getGlobalContext()), IRLinker(new Module("ld-temp.o", Context)) {
+  initialize();
+}
+
+LTOCodeGenerator::LTOCodeGenerator(std::unique_ptr<LLVMContext> Context)
+    : OwnedContext(std::move(Context)), Context(*OwnedContext),
+      IRLinker(new Module("ld-temp.o", *OwnedContext)) {
+  initialize();
+}
+
+void LTOCodeGenerator::initialize() {
+  TargetMach = nullptr;
+  EmitDwarfDebugInfo = false;
+  ScopeRestrictionsDone = false;
+  CodeModel = LTO_CODEGEN_PIC_MODEL_DEFAULT;
+  DiagHandler = nullptr;
+  DiagContext = nullptr;
+
   initializeLTOPasses();
 }