bool addModule(struct LTOModule *);
// Set the destination module.
- void setModule(struct LTOModule *);
+ void setModule(std::unique_ptr<LTOModule> M);
void setTargetOptions(TargetOptions options);
void setDebugInfo(lto_debug_model);
typedef StringMap<uint8_t> StringSet;
- void destroyMergedModule();
std::unique_ptr<LLVMContext> OwnedContext;
LLVMContext &Context;
+ std::unique_ptr<Module> MergedModule;
Linker IRLinker;
std::unique_ptr<TargetMachine> TargetMach;
bool EmitDwarfDebugInfo = false;
unsigned OptLevel = 2;
lto_diagnostic_handler_t DiagHandler = nullptr;
void *DiagContext = nullptr;
- LTOModule *OwnedModule = nullptr;
bool ShouldInternalize = true;
bool ShouldEmbedUselists = false;
};
}
LTOCodeGenerator::LTOCodeGenerator()
- : Context(getGlobalContext()), IRLinker(new Module("ld-temp.o", Context)) {
+ : Context(getGlobalContext()),
+ MergedModule(new Module("ld-temp.o", Context)),
+ IRLinker(MergedModule.get()) {
initializeLTOPasses();
}
LTOCodeGenerator::LTOCodeGenerator(std::unique_ptr<LLVMContext> Context)
: OwnedContext(std::move(Context)), Context(*OwnedContext),
- IRLinker(new Module("ld-temp.o", *OwnedContext)) {
+ MergedModule(new Module("ld-temp.o", *OwnedContext)),
+ IRLinker(MergedModule.get()) {
initializeLTOPasses();
}
-void LTOCodeGenerator::destroyMergedModule() {
- if (OwnedModule) {
- assert(IRLinker.getModule() == &OwnedModule->getModule() &&
- "The linker's module should be the same as the owned module");
- delete OwnedModule;
- OwnedModule = nullptr;
- } else if (IRLinker.getModule())
- IRLinker.deleteModule();
-}
-
-LTOCodeGenerator::~LTOCodeGenerator() {
- destroyMergedModule();
-}
+LTOCodeGenerator::~LTOCodeGenerator() {}
// Initialize LTO passes. Please keep this funciton in sync with
// PassManagerBuilder::populateLTOPassManager(), and make sure all LTO
return !ret;
}
-void LTOCodeGenerator::setModule(LTOModule *Mod) {
+void LTOCodeGenerator::setModule(std::unique_ptr<LTOModule> Mod) {
assert(&Mod->getModule().getContext() == &Context &&
"Expected module in same context");
- // Delete the old merged module.
- destroyMergedModule();
AsmUndefinedRefs.clear();
- OwnedModule = Mod;
- IRLinker.setModule(&Mod->getModule());
+ MergedModule = Mod->takeModule();
+ IRLinker.setModule(MergedModule.get());
const std::vector<const char*> &Undefs = Mod->getAsmUndefinedRefs();
for (int I = 0, E = Undefs.size(); I != E; ++I)
}
// write bitcode to it
- WriteBitcodeToFile(IRLinker.getModule(), Out.os(), ShouldEmbedUselists);
+ WriteBitcodeToFile(MergedModule.get(), Out.os(), ShouldEmbedUselists);
Out.os().close();
if (Out.os().has_error()) {
if (TargetMach)
return true;
- std::string TripleStr = IRLinker.getModule()->getTargetTriple();
+ std::string TripleStr = MergedModule->getTargetTriple();
if (TripleStr.empty()) {
TripleStr = sys::getDefaultTargetTriple();
- IRLinker.getModule()->setTargetTriple(TripleStr);
+ MergedModule->setTargetTriple(TripleStr);
}
llvm::Triple Triple(TripleStr);
void LTOCodeGenerator::applyScopeRestrictions() {
if (ScopeRestrictionsDone || !ShouldInternalize)
return;
- Module *MergedModule = IRLinker.getModule();
// Start off with a verification pass.
legacy::PassManager passes;
if (!this->determineTarget(errMsg))
return false;
- Module *MergedModule = IRLinker.getModule();
-
// Mark which symbols can not be internalized
this->applyScopeRestrictions();
if (!this->determineTarget(errMsg))
return false;
- Module *MergedModule = IRLinker.getModule();
-
legacy::PassManager codeGenPasses;
// If the bitcode files contain ARC code and were compiled with optimization,