summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/FunctionIndexObjectFile.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2015-11-23 19:19:11 +0000
committerTeresa Johnson <tejohnson@google.com>2015-11-23 19:19:11 +0000
commit6b92316811e1d3be74ab0f535efcd3918853f2f6 (patch)
tree4c0376172206347c58f89ac2624c4f5b0713d49c /llvm/lib/Object/FunctionIndexObjectFile.cpp
parentd0430e85808b2ef6f71d0383b201d608b0d1955a (diff)
downloadbcm5719-llvm-6b92316811e1d3be74ab0f535efcd3918853f2f6.tar.gz
bcm5719-llvm-6b92316811e1d3be74ab0f535efcd3918853f2f6.zip
[ThinLTO] Deduplicate function index loading into shared helper (NFC)
Add a shared helper routine to read the function index from a file and create/return the function index object. Use it in llvm-link and llvm-lto. llvm-svn: 253903
Diffstat (limited to 'llvm/lib/Object/FunctionIndexObjectFile.cpp')
-rw-r--r--llvm/lib/Object/FunctionIndexObjectFile.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/Object/FunctionIndexObjectFile.cpp b/llvm/lib/Object/FunctionIndexObjectFile.cpp
index f4b2b5562a3..717c56bc901 100644
--- a/llvm/lib/Object/FunctionIndexObjectFile.cpp
+++ b/llvm/lib/Object/FunctionIndexObjectFile.cpp
@@ -120,3 +120,26 @@ std::error_code FunctionIndexObjectFile::findFunctionSummaryInMemBuffer(
return object_error::invalid_file_type;
}
}
+
+// Parse the function index out of an IR file and return the function
+// index object if found, or nullptr if not.
+ErrorOr<std::unique_ptr<FunctionInfoIndex>>
+llvm::getFunctionIndexForFile(StringRef Path,
+ DiagnosticHandlerFunction DiagnosticHandler,
+ const Module *ExportingModule) {
+ ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
+ MemoryBuffer::getFileOrSTDIN(Path);
+ std::error_code EC = FileOrErr.getError();
+ if (EC)
+ return EC;
+ MemoryBufferRef BufferRef = (FileOrErr.get())->getMemBufferRef();
+ ErrorOr<std::unique_ptr<object::FunctionIndexObjectFile>> ObjOrErr =
+ object::FunctionIndexObjectFile::create(BufferRef, DiagnosticHandler,
+ ExportingModule);
+ EC = ObjOrErr.getError();
+ if (EC)
+ return EC;
+
+ object::FunctionIndexObjectFile &Obj = **ObjOrErr;
+ return Obj.takeIndex();
+}
OpenPOWER on IntegriCloud