Make the C++ LTO API easier to use from C++ clients.

Start using C++ types such as StringRef and MemoryBuffer in the C++ LTO
API. In doing so, clarify the ownership of the native object file: the caller
now owns it, not the LTOCodeGenerator. The C libLTO library has been modified
to use a derived class of LTOCodeGenerator that owns the object file.

Differential Revision: http://reviews.llvm.org/D10114

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238776 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Peter Collingbourne
2015-06-01 20:08:30 +00:00
parent 9be6a55ba0
commit 3fcf5a99cb
4 changed files with 49 additions and 37 deletions

View File

@ -250,8 +250,8 @@ bool LTOCodeGenerator::compileOptimizedToFile(const char **name,
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;
@ -264,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);
}
@ -289,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<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) {