libLTO: Allow LTOCodeGenerator to own a context

llvm-svn: 221726
This commit is contained in:
Duncan P. N. Exon Smith 2014-11-11 23:03:29 +00:00
parent 231bd088d8
commit de5e32b5b4
2 changed files with 21 additions and 4 deletions

View 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;

View 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();
}