X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=lib%2FLTO%2FLTOCodeGenerator.cpp;h=716d66abf1c2c7cd04642182292e46d37384d57b;hb=6948897e478cbd66626159776a8017b3c18579b9;hp=b4a70119cc2c8d4066dc61f2aef23ec11a909d4b;hpb=c3b0732900953dc4d8f68ce41da35f4760933bb3;p=android-x86%2Fexternal-llvm.git diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index b4a70119cc2..716d66abf1c 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -65,24 +65,12 @@ const char* LTOCodeGenerator::getVersionString() { LTOCodeGenerator::LTOCodeGenerator() : Context(getGlobalContext()), IRLinker(new Module("ld-temp.o", Context)) { - initialize(); + initializeLTOPasses(); } LTOCodeGenerator::LTOCodeGenerator(std::unique_ptr 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; - + IRLinker(new Module("ld-temp.o", *OwnedContext)) { initializeLTOPasses(); } @@ -214,8 +202,7 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, } // 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()) { @@ -263,8 +250,8 @@ bool LTOCodeGenerator::compileOptimizedToFile(const char **name, return true; } -const void *LTOCodeGenerator::compileOptimized(size_t *length, - std::string &errMsg) { +std::unique_ptr +LTOCodeGenerator::compileOptimized(std::string &errMsg) { const char *name; if (!compileOptimizedToFile(&name, errMsg)) return nullptr; @@ -277,16 +264,11 @@ const void *LTOCodeGenerator::compileOptimized(size_t *length, 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); } @@ -302,16 +284,14 @@ bool LTOCodeGenerator::compile_to_file(const char **name, return compileOptimizedToFile(name, errMsg); } -const void* LTOCodeGenerator::compile(size_t *length, - bool disableInline, - bool disableGVNLoadPRE, - bool disableVectorization, - std::string &errMsg) { +std::unique_ptr +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) { @@ -464,7 +444,7 @@ static void accumulateAndSortLibcalls(std::vector &Libcalls, } void LTOCodeGenerator::applyScopeRestrictions() { - if (ScopeRestrictionsDone) + if (ScopeRestrictionsDone || !ShouldInternalize) return; Module *mergedModule = IRLinker.getModule();