LTOCodeGenerator::LTOCodeGenerator()
: Context(getGlobalContext()), IRLinker(new Module("ld-temp.o", Context)) {
- initialize();
+ initializeLTOPasses();
}
LTOCodeGenerator::LTOCodeGenerator(std::unique_ptr<LLVMContext> Context)
: OwnedContext(std::move(Context)), Context(*OwnedContext),
- IRLinker(new Module("ld-temp.o", *OwnedContext)), OptLevel(2) {
- initialize();
-}
-
-void LTOCodeGenerator::initialize() {
- TargetMach = nullptr;
- EmitDwarfDebugInfo = false;
- ScopeRestrictionsDone = false;
- CodeModel = LTO_CODEGEN_PIC_MODEL_DEFAULT;
- DiagHandler = nullptr;
- DiagContext = nullptr;
- OwnedModule = nullptr;
- ShouldInternalize = true;
-
+ IRLinker(new Module("ld-temp.o", *OwnedContext)) {
initializeLTOPasses();
}
}
// write bitcode to it
- WriteBitcodeToFile(IRLinker.getModule(), Out.os(),
- /* ShouldPreserveUseListOrder */ true);
+ WriteBitcodeToFile(IRLinker.getModule(), Out.os(), ShouldEmbedUselists);
Out.os().close();
if (Out.os().has_error()) {
return true;
}
-const void *LTOCodeGenerator::compileOptimized(size_t *length,
- std::string &errMsg) {
+std::unique_ptr<MemoryBuffer>
+LTOCodeGenerator::compileOptimized(std::string &errMsg) {
const char *name;
if (!compileOptimizedToFile(&name, errMsg))
return nullptr;
sys::fs::remove(NativeObjectPath);
return nullptr;
}
- NativeObjectFile = std::move(*BufferOrErr);
// remove temp files
sys::fs::remove(NativeObjectPath);
- // return buffer, unless error
- if (!NativeObjectFile)
- return nullptr;
- *length = NativeObjectFile->getBufferSize();
- return NativeObjectFile->getBufferStart();
+ return std::move(*BufferOrErr);
}
return compileOptimizedToFile(name, errMsg);
}
-const void* LTOCodeGenerator::compile(size_t *length,
- bool disableInline,
- bool disableGVNLoadPRE,
- bool disableVectorization,
- std::string &errMsg) {
+std::unique_ptr<MemoryBuffer>
+LTOCodeGenerator::compile(bool disableInline, bool disableGVNLoadPRE,
+ bool disableVectorization, std::string &errMsg) {
if (!optimize(disableInline, disableGVNLoadPRE,
disableVectorization, errMsg))
return nullptr;
- return compileOptimized(length, errMsg);
+ return compileOptimized(errMsg);
}
bool LTOCodeGenerator::determineTarget(std::string &errMsg) {
passes.add(createVerifierPass());
// mark which symbols can not be internalized
- Mangler Mangler(TargetMach->getDataLayout());
+ Mangler Mangler;
std::vector<const char*> MustPreserveList;
SmallPtrSet<GlobalValue*, 8> AsmUsed;
std::vector<StringRef> Libcalls;
legacy::PassManager passes;
// Add an appropriate DataLayout instance for this module...
- mergedModule->setDataLayout(*TargetMach->getDataLayout());
+ mergedModule->setDataLayout(TargetMach->createDataLayout());
passes.add(
createTargetTransformInfoWrapperPass(TargetMach->getTargetIRAnalysis()));